]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.1-3.18.8-201502271843.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.1-3.18.8-201502271843.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 0b3f8a1..2b1f2b6 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380 -HOSTCXXFLAGS = -O2
381 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387 @@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391 -PHONY += scripts_basic
392 -scripts_basic:
393 +PHONY += scripts_basic gcc-plugins
394 +scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398 @@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402 +ifndef DISABLE_PAX_PLUGINS
403 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405 +else
406 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407 +endif
408 +ifneq ($(PLUGINCC),)
409 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411 +endif
412 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
413 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415 +endif
416 +ifdef CONFIG_KALLOCSTAT_PLUGIN
417 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418 +endif
419 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423 +endif
424 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428 +endif
429 +endif
430 +ifdef CONFIG_CHECKER_PLUGIN
431 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433 +endif
434 +endif
435 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436 +ifdef CONFIG_PAX_SIZE_OVERFLOW
437 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438 +endif
439 +ifdef CONFIG_PAX_LATENT_ENTROPY
440 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441 +endif
442 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444 +endif
445 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451 +ifeq ($(KBUILD_EXTMOD),)
452 +gcc-plugins:
453 + $(Q)$(MAKE) $(build)=tools/gcc
454 +else
455 +gcc-plugins: ;
456 +endif
457 +else
458 +gcc-plugins:
459 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
461 +else
462 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463 +endif
464 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465 +endif
466 +endif
467 +
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471 @@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475 -KBUILD_AFLAGS += -Wa,-gdwarf-2
476 +KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480 @@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489 @@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498 @@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502 -$(vmlinux-dirs): prepare scripts
503 +$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507 @@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521 @@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530 @@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534 -modules_prepare: prepare scripts
535 +modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539 @@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543 - signing_key.x509.signer include/linux/version.h
544 + signing_key.x509.signer include/linux/version.h \
545 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547 + tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551 @@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560 @@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569 @@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573 -%.s: %.c prepare scripts FORCE
574 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576 +%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580 -%.o: %.c prepare scripts FORCE
581 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583 +%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587 -%.s: %.S prepare scripts FORCE
588 +%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590 -%.o: %.S prepare scripts FORCE
591 +%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595 @@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599 -%/: prepare scripts FORCE
600 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602 +%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606 -%.ko: prepare scripts FORCE
607 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609 +%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614 index 8f8eafb..3405f46 100644
615 --- a/arch/alpha/include/asm/atomic.h
616 +++ b/arch/alpha/include/asm/atomic.h
617 @@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621 +#define atomic64_read_unchecked(v) atomic64_read(v)
622 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
627 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
629 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630 +
631 #endif /* _ALPHA_ATOMIC_H */
632 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633 index ad368a9..fbe0f25 100644
634 --- a/arch/alpha/include/asm/cache.h
635 +++ b/arch/alpha/include/asm/cache.h
636 @@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640 +#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644 -# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650 -# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659 index 968d999..d36b2df 100644
660 --- a/arch/alpha/include/asm/elf.h
661 +++ b/arch/alpha/include/asm/elf.h
662 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666 +#ifdef CONFIG_PAX_ASLR
667 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668 +
669 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671 +#endif
672 +
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677 index aab14a0..b4fa3e7 100644
678 --- a/arch/alpha/include/asm/pgalloc.h
679 +++ b/arch/alpha/include/asm/pgalloc.h
680 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684 +static inline void
685 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686 +{
687 + pgd_populate(mm, pgd, pmd);
688 +}
689 +
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694 index d8f9b7e..f6222fa 100644
695 --- a/arch/alpha/include/asm/pgtable.h
696 +++ b/arch/alpha/include/asm/pgtable.h
697 @@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 +
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +#else
707 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
708 +# define PAGE_COPY_NOEXEC PAGE_COPY
709 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
710 +#endif
711 +
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716 index 2fd00b7..cfd5069 100644
717 --- a/arch/alpha/kernel/module.c
718 +++ b/arch/alpha/kernel/module.c
719 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723 - gp = (u64)me->module_core + me->core_size - 0x8000;
724 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729 index f9c732e..78fbb0f 100644
730 --- a/arch/alpha/kernel/osf_sys.c
731 +++ b/arch/alpha/kernel/osf_sys.c
732 @@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737 - unsigned long limit)
738 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739 + unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746 @@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750 + info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754 @@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758 +#ifdef CONFIG_PAX_RANDMMAP
759 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760 +#endif
761 +
762 if (addr) {
763 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771 - len, limit);
772 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773 +
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784 index 9d0ac09..479a962 100644
785 --- a/arch/alpha/mm/fault.c
786 +++ b/arch/alpha/mm/fault.c
787 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791 +#ifdef CONFIG_PAX_PAGEEXEC
792 +/*
793 + * PaX: decide what to do with offenders (regs->pc = fault address)
794 + *
795 + * returns 1 when task should be killed
796 + * 2 when patched PLT trampoline was detected
797 + * 3 when unpatched PLT trampoline was detected
798 + */
799 +static int pax_handle_fetch_fault(struct pt_regs *regs)
800 +{
801 +
802 +#ifdef CONFIG_PAX_EMUPLT
803 + int err;
804 +
805 + do { /* PaX: patched PLT emulation #1 */
806 + unsigned int ldah, ldq, jmp;
807 +
808 + err = get_user(ldah, (unsigned int *)regs->pc);
809 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811 +
812 + if (err)
813 + break;
814 +
815 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817 + jmp == 0x6BFB0000U)
818 + {
819 + unsigned long r27, addr;
820 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822 +
823 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824 + err = get_user(r27, (unsigned long *)addr);
825 + if (err)
826 + break;
827 +
828 + regs->r27 = r27;
829 + regs->pc = r27;
830 + return 2;
831 + }
832 + } while (0);
833 +
834 + do { /* PaX: patched PLT emulation #2 */
835 + unsigned int ldah, lda, br;
836 +
837 + err = get_user(ldah, (unsigned int *)regs->pc);
838 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
839 + err |= get_user(br, (unsigned int *)(regs->pc+8));
840 +
841 + if (err)
842 + break;
843 +
844 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
846 + (br & 0xFFE00000U) == 0xC3E00000U)
847 + {
848 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851 +
852 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854 + return 2;
855 + }
856 + } while (0);
857 +
858 + do { /* PaX: unpatched PLT emulation */
859 + unsigned int br;
860 +
861 + err = get_user(br, (unsigned int *)regs->pc);
862 +
863 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864 + unsigned int br2, ldq, nop, jmp;
865 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866 +
867 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868 + err = get_user(br2, (unsigned int *)addr);
869 + err |= get_user(ldq, (unsigned int *)(addr+4));
870 + err |= get_user(nop, (unsigned int *)(addr+8));
871 + err |= get_user(jmp, (unsigned int *)(addr+12));
872 + err |= get_user(resolver, (unsigned long *)(addr+16));
873 +
874 + if (err)
875 + break;
876 +
877 + if (br2 == 0xC3600000U &&
878 + ldq == 0xA77B000CU &&
879 + nop == 0x47FF041FU &&
880 + jmp == 0x6B7B0000U)
881 + {
882 + regs->r28 = regs->pc+4;
883 + regs->r27 = addr+16;
884 + regs->pc = resolver;
885 + return 3;
886 + }
887 + }
888 + } while (0);
889 +#endif
890 +
891 + return 1;
892 +}
893 +
894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895 +{
896 + unsigned long i;
897 +
898 + printk(KERN_ERR "PAX: bytes at PC: ");
899 + for (i = 0; i < 5; i++) {
900 + unsigned int c;
901 + if (get_user(c, (unsigned int *)pc+i))
902 + printk(KERN_CONT "???????? ");
903 + else
904 + printk(KERN_CONT "%08x ", c);
905 + }
906 + printk("\n");
907 +}
908 +#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912 @@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916 - if (!(vma->vm_flags & VM_EXEC))
917 + if (!(vma->vm_flags & VM_EXEC)) {
918 +
919 +#ifdef CONFIG_PAX_PAGEEXEC
920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921 + goto bad_area;
922 +
923 + up_read(&mm->mmap_sem);
924 + switch (pax_handle_fetch_fault(regs)) {
925 +
926 +#ifdef CONFIG_PAX_EMUPLT
927 + case 2:
928 + case 3:
929 + return;
930 +#endif
931 +
932 + }
933 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934 + do_group_exit(SIGKILL);
935 +#else
936 goto bad_area;
937 +#endif
938 +
939 + }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944 index 89c4b5c..847a7be 100644
945 --- a/arch/arm/Kconfig
946 +++ b/arch/arm/Kconfig
947 @@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951 - depends on MMU
952 + depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956 @@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960 + depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965 index e22c119..eaa807d 100644
966 --- a/arch/arm/include/asm/atomic.h
967 +++ b/arch/arm/include/asm/atomic.h
968 @@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972 +#ifdef CONFIG_GENERIC_ATOMIC64
973 +#include <asm-generic/atomic64.h>
974 +#endif
975 +
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980 +#ifdef CONFIG_THUMB2_KERNEL
981 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982 +#else
983 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984 +#endif
985 +
986 +#define _ASM_EXTABLE(from, to) \
987 +" .pushsection __ex_table,\"a\"\n"\
988 +" .align 3\n" \
989 +" .long " #from ", " #to"\n" \
990 +" .popsection"
991 +
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999 +{
1000 + return ACCESS_ONCE(v->counter);
1001 +}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004 +{
1005 + v->counter = i;
1006 +}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010 @@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014 -#define ATOMIC_OP(op, c_op, asm_op) \
1015 -static inline void atomic_##op(int i, atomic_t *v) \
1016 +#ifdef CONFIG_PAX_REFCOUNT
1017 +#define __OVERFLOW_POST \
1018 + " bvc 3f\n" \
1019 + "2: " REFCOUNT_TRAP_INSN "\n"\
1020 + "3:\n"
1021 +#define __OVERFLOW_POST_RETURN \
1022 + " bvc 3f\n" \
1023 +" mov %0, %1\n" \
1024 + "2: " REFCOUNT_TRAP_INSN "\n"\
1025 + "3:\n"
1026 +#define __OVERFLOW_EXTABLE \
1027 + "4:\n" \
1028 + _ASM_EXTABLE(2b, 4b)
1029 +#else
1030 +#define __OVERFLOW_POST
1031 +#define __OVERFLOW_POST_RETURN
1032 +#define __OVERFLOW_EXTABLE
1033 +#endif
1034 +
1035 +#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042 - __asm__ __volatile__("@ atomic_" #op "\n" \
1043 + __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046 + post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049 -" bne 1b" \
1050 +" bne 1b\n" \
1051 + extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1059 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060 + __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061 +
1062 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067 @@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071 - __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072 + __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075 + post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078 -" bne 1b" \
1079 +" bne 1b\n" \
1080 + extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084 @@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090 +
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094 @@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098 -" beq 2f\n"
1099 -" add %1, %0, %6\n"
1100 +" beq 4f\n"
1101 +" adds %1, %0, %6\n"
1102 +
1103 +#ifdef CONFIG_PAX_REFCOUNT
1104 +" bvc 3f\n"
1105 +"2: " REFCOUNT_TRAP_INSN "\n"
1106 +"3:\n"
1107 +#endif
1108 +
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112 -"2:"
1113 +"4:"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122 @@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127 +{
1128 + unsigned long oldval, res;
1129 +
1130 + smp_mb();
1131 +
1132 + do {
1133 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134 + "ldrex %1, [%3]\n"
1135 + "mov %0, #0\n"
1136 + "teq %1, %4\n"
1137 + "strexeq %0, %5, [%3]\n"
1138 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140 + : "cc");
1141 + } while (res);
1142 +
1143 + smp_mb();
1144 +
1145 + return oldval;
1146 +}
1147 +
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154 -#define ATOMIC_OP(op, c_op, asm_op) \
1155 -static inline void atomic_##op(int i, atomic_t *v) \
1156 +#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161 @@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1167 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168 + __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169 +
1170 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175 @@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181 +
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185 @@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190 +{
1191 + return atomic_cmpxchg((atomic_t *)v, old, new);
1192 +}
1193 +
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197 @@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201 +#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203 +#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207 +{
1208 + return xchg(&v->counter, new);
1209 +}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213 +{
1214 + atomic_add_unchecked(1, v);
1215 +}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218 +{
1219 + atomic_sub_unchecked(1, v);
1220 +}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224 +{
1225 + return atomic_add_return_unchecked(1, v) == 0;
1226 +}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230 +{
1231 + return atomic_add_return_unchecked(1, v);
1232 +}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236 @@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +typedef struct {
1242 + long long counter;
1243 +} atomic64_unchecked_t;
1244 +#else
1245 +typedef atomic64_t atomic64_unchecked_t;
1246 +#endif
1247 +
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251 @@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256 +{
1257 + long long result;
1258 +
1259 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260 +" ldrd %0, %H0, [%1]"
1261 + : "=&r" (result)
1262 + : "r" (&v->counter), "Qo" (v->counter)
1263 + );
1264 +
1265 + return result;
1266 +}
1267 +
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271 @@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275 +
1276 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277 +{
1278 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279 +" strd %2, %H2, [%1]"
1280 + : "=Qo" (v->counter)
1281 + : "r" (&v->counter), "r" (i)
1282 + );
1283 +}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287 @@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292 +{
1293 + long long result;
1294 +
1295 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296 +" ldrexd %0, %H0, [%1]"
1297 + : "=&r" (result)
1298 + : "r" (&v->counter), "Qo" (v->counter)
1299 + );
1300 +
1301 + return result;
1302 +}
1303 +
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307 @@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311 +
1312 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313 +{
1314 + long long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%2]\n"
1319 +" strexd %0, %3, %H3, [%2]\n"
1320 +" teq %0, #0\n"
1321 +" bne 1b"
1322 + : "=&r" (tmp), "=Qo" (v->counter)
1323 + : "r" (&v->counter), "r" (i)
1324 + : "cc");
1325 +}
1326 #endif
1327
1328 -#define ATOMIC64_OP(op, op1, op2) \
1329 -static inline void atomic64_##op(long long i, atomic64_t *v) \
1330 +#undef __OVERFLOW_POST_RETURN
1331 +#define __OVERFLOW_POST_RETURN \
1332 + " bvc 3f\n" \
1333 +" mov %0, %1\n" \
1334 +" mov %H0, %H1\n" \
1335 + "2: " REFCOUNT_TRAP_INSN "\n"\
1336 + "3:\n"
1337 +
1338 +#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339 +static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345 - __asm__ __volatile__("@ atomic64_" #op "\n" \
1346 + __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350 + post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353 -" bne 1b" \
1354 +" bne 1b\n" \
1355 + extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361 -#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362 -static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363 +#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364 + __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365 +
1366 +#define __ATOMIC64_OP_RETURN(op, suffix, op1, op2, post_op, extable) \
1367 +static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371 @@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375 - __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376 + __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380 + post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383 -" bne 1b" \
1384 +" bne 1b\n" \
1385 + extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389 @@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393 +#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394 + __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395 +
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399 @@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403 +#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405 +#undef __ATOMIC64_OP
1406 +#undef __OVERFLOW_EXTABLE
1407 +#undef __OVERFLOW_POST_RETURN
1408 +#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412 @@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417 + long long new)
1418 +{
1419 + long long oldval;
1420 + unsigned long res;
1421 +
1422 + smp_mb();
1423 +
1424 + do {
1425 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426 + "ldrexd %1, %H1, [%3]\n"
1427 + "mov %0, #0\n"
1428 + "teq %1, %4\n"
1429 + "teqeq %H1, %H4\n"
1430 + "strexdeq %0, %5, %H5, [%3]"
1431 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432 + : "r" (&ptr->counter), "r" (old), "r" (new)
1433 + : "cc");
1434 + } while (res);
1435 +
1436 + smp_mb();
1437 +
1438 + return oldval;
1439 +}
1440 +
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444 @@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448 - unsigned long tmp;
1449 + u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455 -"1: ldrexd %0, %H0, [%3]\n"
1456 -" subs %Q0, %Q0, #1\n"
1457 -" sbc %R0, %R0, #0\n"
1458 +"1: ldrexd %1, %H1, [%3]\n"
1459 +" subs %Q0, %Q1, #1\n"
1460 +" sbcs %R0, %R1, #0\n"
1461 +
1462 +#ifdef CONFIG_PAX_REFCOUNT
1463 +" bvc 3f\n"
1464 +" mov %Q0, %Q1\n"
1465 +" mov %R0, %R1\n"
1466 +"2: " REFCOUNT_TRAP_INSN "\n"
1467 +"3:\n"
1468 +#endif
1469 +
1470 " teq %R0, #0\n"
1471 -" bmi 2f\n"
1472 +" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476 -"2:"
1477 +"4:\n"
1478 +
1479 +#ifdef CONFIG_PAX_REFCOUNT
1480 + _ASM_EXTABLE(2b, 4b)
1481 +#endif
1482 +
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486 @@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490 -" beq 2f\n"
1491 +" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493 -" adc %R0, %R0, %R6\n"
1494 +" adcs %R0, %R0, %R6\n"
1495 +
1496 +#ifdef CONFIG_PAX_REFCOUNT
1497 +" bvc 3f\n"
1498 +"2: " REFCOUNT_TRAP_INSN "\n"
1499 +"3:\n"
1500 +#endif
1501 +
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505 -"2:"
1506 +"4:\n"
1507 +
1508 +#ifdef CONFIG_PAX_REFCOUNT
1509 + _ASM_EXTABLE(2b, 4b)
1510 +#endif
1511 +
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515 @@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530 index c6a3e73..35cca85 100644
1531 --- a/arch/arm/include/asm/barrier.h
1532 +++ b/arch/arm/include/asm/barrier.h
1533 @@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537 - ACCESS_ONCE(*p) = (v); \
1538 + ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543 index 75fe66b..ba3dee4 100644
1544 --- a/arch/arm/include/asm/cache.h
1545 +++ b/arch/arm/include/asm/cache.h
1546 @@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550 +#include <linux/const.h>
1551 +
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558 @@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566 index 10e78d0..dc8505d 100644
1567 --- a/arch/arm/include/asm/cacheflush.h
1568 +++ b/arch/arm/include/asm/cacheflush.h
1569 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573 -};
1574 +} __no_const;
1575
1576 /*
1577 * Select the calling method
1578 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579 index 5233151..87a71fa 100644
1580 --- a/arch/arm/include/asm/checksum.h
1581 +++ b/arch/arm/include/asm/checksum.h
1582 @@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588 +
1589 +static inline __wsum
1590 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591 +{
1592 + __wsum ret;
1593 + pax_open_userland();
1594 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595 + pax_close_userland();
1596 + return ret;
1597 +}
1598 +
1599 +
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604 index abb2c37..96db950 100644
1605 --- a/arch/arm/include/asm/cmpxchg.h
1606 +++ b/arch/arm/include/asm/cmpxchg.h
1607 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611 +#define xchg_unchecked(ptr,x) \
1612 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617 index 6ddbe44..b5e38b1 100644
1618 --- a/arch/arm/include/asm/domain.h
1619 +++ b/arch/arm/include/asm/domain.h
1620 @@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624 -#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626 +#define DOMAIN_USERCLIENT 1
1627 +#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629 +#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631 +
1632 +#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634 +#define DOMAIN_KERNEXEC 3
1635 +#else
1636 +#define DOMAIN_MANAGER 1
1637 +#endif
1638 +
1639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1640 +#define DOMAIN_USERCLIENT 0
1641 +#define DOMAIN_UDEREF 1
1642 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1643 +#else
1644 +#define DOMAIN_USERCLIENT 1
1645 +#define DOMAIN_VECTORS DOMAIN_USER
1646 +#endif
1647 +#define DOMAIN_KERNELCLIENT 1
1648 +
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655 -#ifdef CONFIG_CPU_USE_DOMAINS
1656 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664 -#define modify_domain(dom,type) \
1665 - do { \
1666 - struct thread_info *thread = current_thread_info(); \
1667 - unsigned int domain = thread->cpu_domain; \
1668 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669 - thread->cpu_domain = domain | domain_val(dom, type); \
1670 - set_domain(thread->cpu_domain); \
1671 - } while (0)
1672 -
1673 +extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678 index afb9caf..9a0bac0 100644
1679 --- a/arch/arm/include/asm/elf.h
1680 +++ b/arch/arm/include/asm/elf.h
1681 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687 +
1688 +#ifdef CONFIG_PAX_ASLR
1689 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690 +
1691 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693 +#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701 -struct mm_struct;
1702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703 -#define arch_randomize_brk arch_randomize_brk
1704 -
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709 index de53547..52b9a28 100644
1710 --- a/arch/arm/include/asm/fncpy.h
1711 +++ b/arch/arm/include/asm/fncpy.h
1712 @@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716 + pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718 + pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723 index 53e69da..3fdc896 100644
1724 --- a/arch/arm/include/asm/futex.h
1725 +++ b/arch/arm/include/asm/futex.h
1726 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730 + pax_open_userland();
1731 +
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739 + pax_close_userland();
1740 +
1741 *uval = val;
1742 return ret;
1743 }
1744 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748 + pax_open_userland();
1749 +
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757 + pax_close_userland();
1758 +
1759 *uval = val;
1760 return ret;
1761 }
1762 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766 + pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774 + pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779 index 83eb2f7..ed77159 100644
1780 --- a/arch/arm/include/asm/kmap_types.h
1781 +++ b/arch/arm/include/asm/kmap_types.h
1782 @@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786 -#define KM_TYPE_NR 16
1787 +#define KM_TYPE_NR 17
1788
1789 #endif
1790 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791 index 9e614a1..3302cca 100644
1792 --- a/arch/arm/include/asm/mach/dma.h
1793 +++ b/arch/arm/include/asm/mach/dma.h
1794 @@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798 -};
1799 +} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804 index f98c7f3..e5c626d 100644
1805 --- a/arch/arm/include/asm/mach/map.h
1806 +++ b/arch/arm/include/asm/mach/map.h
1807 @@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811 - MT_UNCACHED = 4,
1812 - MT_CACHECLEAN,
1813 - MT_MINICLEAN,
1814 + MT_UNCACHED_RW = 4,
1815 + MT_CACHECLEAN_RO,
1816 + MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819 - MT_MEMORY_RWX,
1820 + __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822 - MT_ROM,
1823 - MT_MEMORY_RWX_NONCACHED,
1824 + MT_MEMORY_RX,
1825 + MT_ROM_RX,
1826 + MT_MEMORY_RW_NONCACHED,
1827 + MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829 - MT_MEMORY_RWX_ITCM,
1830 + MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index 891a56b..48f337e 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index f027941..f36ce30 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 9fd61c7..f8f1cff 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index a31ecdad..95e98d4 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003 @@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017 index 3b30062..01a5f9d 100644
2018 --- a/arch/arm/include/asm/pgtable.h
2019 +++ b/arch/arm/include/asm/pgtable.h
2020 @@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024 +#define ktla_ktva(addr) (addr)
2025 +#define ktva_ktla(addr) (addr)
2026 +
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030 @@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034 +extern pteval_t __supported_pte_mask;
2035 +extern pmdval_t __supported_pmd_mask;
2036 +
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046 +
2047 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048 +#include <asm/domain.h>
2049 +#include <linux/thread_info.h>
2050 +#include <linux/preempt.h>
2051 +
2052 +static inline int test_domain(int domain, int domaintype)
2053 +{
2054 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055 +}
2056 +#endif
2057 +
2058 +#ifdef CONFIG_PAX_KERNEXEC
2059 +static inline unsigned long pax_open_kernel(void) {
2060 +#ifdef CONFIG_ARM_LPAE
2061 + /* TODO */
2062 +#else
2063 + preempt_disable();
2064 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066 +#endif
2067 + return 0;
2068 +}
2069 +
2070 +static inline unsigned long pax_close_kernel(void) {
2071 +#ifdef CONFIG_ARM_LPAE
2072 + /* TODO */
2073 +#else
2074 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077 + preempt_enable_no_resched();
2078 +#endif
2079 + return 0;
2080 +}
2081 +#else
2082 +static inline unsigned long pax_open_kernel(void) { return 0; }
2083 +static inline unsigned long pax_close_kernel(void) { return 0; }
2084 +#endif
2085 +
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093 - * as well as any architecture dependent bits like global/ASID and SMP
2094 - * shared mapping bits.
2095 + * as well as any architecture dependent bits like global/ASID, PXN,
2096 + * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100 @@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104 - L_PTE_NONE | L_PTE_VALID;
2105 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110 index c25ef3e..735f14b 100644
2111 --- a/arch/arm/include/asm/psci.h
2112 +++ b/arch/arm/include/asm/psci.h
2113 @@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117 -};
2118 +} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123 index 18f5a55..5072a40 100644
2124 --- a/arch/arm/include/asm/smp.h
2125 +++ b/arch/arm/include/asm/smp.h
2126 @@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130 -};
2131 +} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136 index ce73ab6..7310f8a 100644
2137 --- a/arch/arm/include/asm/thread_info.h
2138 +++ b/arch/arm/include/asm/thread_info.h
2139 @@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157 +/* within 8 bits of TIF_SYSCALL_TRACE
2158 + * to meet flexible second operand requirements
2159 + */
2160 +#define TIF_GRSEC_SETXID 12
2161 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179 index 5f833f7..76e6644 100644
2180 --- a/arch/arm/include/asm/tls.h
2181 +++ b/arch/arm/include/asm/tls.h
2182 @@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186 +#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194 + pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196 + pax_close_kernel();
2197 #endif
2198 }
2199
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 4767eb9..bf00668 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index a88671c..1cc895e 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 2f5555d..d493c91 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: str r4, [sp, #S_PC] @ retry current instruction
2605 +4: pax_close_userland
2606 + str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610 @@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index 6bb09d4..113e875 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index 4176df7..a901f8d 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770 @@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index b37752a..ff5cb72 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 664eee8..f470938 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 6a4dffe..4a86a70 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index fe972a2..a772d83 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932 -/* If possible, provide a placement hint at a random offset from the
2933 - * stack for the signal page.
2934 - */
2935 -static unsigned long sigpage_addr(const struct mm_struct *mm,
2936 - unsigned int npages)
2937 -{
2938 - unsigned long offset;
2939 - unsigned long first;
2940 - unsigned long last;
2941 - unsigned long addr;
2942 - unsigned int slots;
2943 -
2944 - first = PAGE_ALIGN(mm->start_stack);
2945 -
2946 - last = TASK_SIZE - (npages << PAGE_SHIFT);
2947 -
2948 - /* No room after stack? */
2949 - if (first > last)
2950 - return 0;
2951 -
2952 - /* Just enough room? */
2953 - if (first == last)
2954 - return first;
2955 -
2956 - slots = ((last - first) >> PAGE_SHIFT) + 1;
2957 -
2958 - offset = get_random_int() % slots;
2959 -
2960 - addr = first + (offset << PAGE_SHIFT);
2961 -
2962 - return addr;
2963 -}
2964 -
2965 -static struct page *signal_page;
2966 -extern struct page *get_signal_page(void);
2967 -
2968 -static const struct vm_special_mapping sigpage_mapping = {
2969 - .name = "[sigpage]",
2970 - .pages = &signal_page,
2971 -};
2972 -
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976 - struct vm_area_struct *vma;
2977 - unsigned long addr;
2978 - unsigned long hint;
2979 - int ret = 0;
2980 -
2981 - if (!signal_page)
2982 - signal_page = get_signal_page();
2983 - if (!signal_page)
2984 - return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987 - hint = sigpage_addr(mm, 1);
2988 - addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989 - if (IS_ERR_VALUE(addr)) {
2990 - ret = addr;
2991 - goto up_fail;
2992 - }
2993 -
2994 - vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996 - &sigpage_mapping);
2997 -
2998 - if (IS_ERR(vma)) {
2999 - ret = PTR_ERR(vma);
3000 - goto up_fail;
3001 - }
3002 -
3003 - mm->context.sigpage = addr;
3004 -
3005 - up_fail:
3006 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008 - return ret;
3009 + return 0;
3010 }
3011 #endif
3012 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013 index f73891b..cf3004e 100644
3014 --- a/arch/arm/kernel/psci.c
3015 +++ b/arch/arm/kernel/psci.c
3016 @@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020 -struct psci_operations psci_ops;
3021 +struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026 index ef9119f..31995a3 100644
3027 --- a/arch/arm/kernel/ptrace.c
3028 +++ b/arch/arm/kernel/ptrace.c
3029 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033 +#ifdef CONFIG_GRKERNSEC_SETXID
3034 +extern void gr_delayed_cred_worker(void);
3035 +#endif
3036 +
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041 +#ifdef CONFIG_GRKERNSEC_SETXID
3042 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043 + gr_delayed_cred_worker();
3044 +#endif
3045 +
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050 index 306e1ac..1b477ed 100644
3051 --- a/arch/arm/kernel/setup.c
3052 +++ b/arch/arm/kernel/setup.c
3053 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057 +pteval_t __supported_pte_mask __read_only;
3058 +pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061 -struct processor processor __read_mostly;
3062 +struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3066 +struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069 -struct cpu_user_fns cpu_user __read_mostly;
3070 +struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073 -struct cpu_cache_fns cpu_cache __read_mostly;
3074 +struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077 -struct outer_cache_fns outer_cache __read_mostly;
3078 +struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082 @@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086 - (mmfr0 & 0x000000f0) >= 0x00000030)
3087 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091 + __supported_pte_mask |= L_PTE_PXN;
3092 + __supported_pmd_mask |= PMD_PXNTABLE;
3093 + }
3094 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099 index bd19834..e4d8c66 100644
3100 --- a/arch/arm/kernel/signal.c
3101 +++ b/arch/arm/kernel/signal.c
3102 @@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106 -static unsigned long signal_return_offset;
3107 -
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115 - retcode = mm->context.sigpage + signal_return_offset +
3116 - (idx << 2) + thumb;
3117 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125 -
3126 -struct page *get_signal_page(void)
3127 -{
3128 - unsigned long ptr;
3129 - unsigned offset;
3130 - struct page *page;
3131 - void *addr;
3132 -
3133 - page = alloc_pages(GFP_KERNEL, 0);
3134 -
3135 - if (!page)
3136 - return NULL;
3137 -
3138 - addr = page_address(page);
3139 -
3140 - /* Give the signal return code some randomness */
3141 - offset = 0x200 + (get_random_int() & 0x7fc);
3142 - signal_return_offset = offset;
3143 -
3144 - /*
3145 - * Copy signal return handlers into the vector page, and
3146 - * set sigreturn to be a pointer to these.
3147 - */
3148 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149 -
3150 - ptr = (unsigned long)addr + offset;
3151 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152 -
3153 - return page;
3154 -}
3155 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156 index a8e32aa..b2f7198 100644
3157 --- a/arch/arm/kernel/smp.c
3158 +++ b/arch/arm/kernel/smp.c
3159 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163 -static struct smp_operations smp_ops;
3164 +static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169 index 7a3be1d..b00c7de 100644
3170 --- a/arch/arm/kernel/tcm.c
3171 +++ b/arch/arm/kernel/tcm.c
3172 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176 - .type = MT_MEMORY_RWX_ITCM,
3177 + .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181 @@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185 + pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187 + pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192 index 9f5d818..e013427 100644
3193 --- a/arch/arm/kernel/traps.c
3194 +++ b/arch/arm/kernel/traps.c
3195 @@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204 @@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208 +extern void gr_handle_kernel_exploit(void);
3209 +
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213 @@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217 +
3218 + gr_handle_kernel_exploit();
3219 +
3220 if (signr)
3221 do_exit(signr);
3222 }
3223 @@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228 +
3229 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3230 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231 +#endif
3232 +
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237 index 8e95aa4..595dfc8 100644
3238 --- a/arch/arm/kernel/vmlinux.lds.S
3239 +++ b/arch/arm/kernel/vmlinux.lds.S
3240 @@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244 -
3245 +
3246 +#ifdef CONFIG_PAX_KERNEXEC
3247 +#include <asm/pgtable.h>
3248 +#endif
3249 +
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253 @@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257 - defined(CONFIG_GENERIC_BUG)
3258 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262 @@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266 +
3267 +#ifdef CONFIG_PAX_KERNEXEC
3268 + . = ALIGN(1<<SECTION_SHIFT);
3269 +#endif
3270 +
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274 @@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278 + _etext = .; /* End of text section */
3279 +
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283 @@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287 - _etext = .; /* End of text and rodata section */
3288 +#ifdef CONFIG_PAX_KERNEXEC
3289 + . = ALIGN(1<<SECTION_SHIFT);
3290 +#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294 @@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298 +
3299 +#ifdef CONFIG_PAX_KERNEXEC
3300 + . = ALIGN(1<<SECTION_SHIFT);
3301 +#endif
3302 +
3303 __data_loc = .;
3304 #endif
3305
3306 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307 index 9e193c8..3560fe6 100644
3308 --- a/arch/arm/kvm/arm.c
3309 +++ b/arch/arm/kvm/arm.c
3310 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319 @@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328 @@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332 - atomic64_inc(&kvm_vmid_gen);
3333 + atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337 @@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346 @@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350 -int kvm_arch_init(void *opaque)
3351 +int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356 index 14a0d98..7771a7d 100644
3357 --- a/arch/arm/lib/clear_user.S
3358 +++ b/arch/arm/lib/clear_user.S
3359 @@ -12,14 +12,14 @@
3360
3361 .text
3362
3363 -/* Prototype: int __clear_user(void *addr, size_t sz)
3364 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371 -WEAK(__clear_user)
3372 +WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380 -ENDPROC(__clear_user)
3381 +ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386 index 66a477a..bee61d3 100644
3387 --- a/arch/arm/lib/copy_from_user.S
3388 +++ b/arch/arm/lib/copy_from_user.S
3389 @@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3394 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398 @@ -84,11 +84,11 @@
3399
3400 .text
3401
3402 -ENTRY(__copy_from_user)
3403 +ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407 -ENDPROC(__copy_from_user)
3408 +ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413 index 6ee2f67..d1cce76 100644
3414 --- a/arch/arm/lib/copy_page.S
3415 +++ b/arch/arm/lib/copy_page.S
3416 @@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420 +#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425 index d066df6..df28194 100644
3426 --- a/arch/arm/lib/copy_to_user.S
3427 +++ b/arch/arm/lib/copy_to_user.S
3428 @@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3433 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437 @@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441 -WEAK(__copy_to_user)
3442 +WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446 -ENDPROC(__copy_to_user)
3447 +ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452 index 7d08b43..f7ca7ea 100644
3453 --- a/arch/arm/lib/csumpartialcopyuser.S
3454 +++ b/arch/arm/lib/csumpartialcopyuser.S
3455 @@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467 index 312d43e..21d2322 100644
3468 --- a/arch/arm/lib/delay.c
3469 +++ b/arch/arm/lib/delay.c
3470 @@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474 -struct arm_delay_ops arm_delay_ops = {
3475 +struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480 index 3e58d71..029817c 100644
3481 --- a/arch/arm/lib/uaccess_with_memcpy.c
3482 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3483 @@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3488 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492 @@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496 -unsigned long __clear_user(void __user *addr, unsigned long n)
3497 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502 index 9610792..4dfb851 100644
3503 --- a/arch/arm/mach-at91/setup.c
3504 +++ b/arch/arm/mach-at91/setup.c
3505 @@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509 - desc->type = MT_MEMORY_RWX_NONCACHED;
3510 + desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515 index 7f352de..6dc0929 100644
3516 --- a/arch/arm/mach-keystone/keystone.c
3517 +++ b/arch/arm/mach-keystone/keystone.c
3518 @@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522 -static struct notifier_block platform_nb;
3523 +static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528 index 2ffccd4..69ffe115 100644
3529 --- a/arch/arm/mach-mvebu/coherency.c
3530 +++ b/arch/arm/mach-mvebu/coherency.c
3531 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544 - mtype = MT_UNCACHED;
3545 + mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550 index 97767a2..9233746 100644
3551 --- a/arch/arm/mach-omap2/board-n8x0.c
3552 +++ b/arch/arm/mach-omap2/board-n8x0.c
3553 @@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557 -struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558 +struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563 index 5fa3755..1e8c247 100644
3564 --- a/arch/arm/mach-omap2/gpmc.c
3565 +++ b/arch/arm/mach-omap2/gpmc.c
3566 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570 -static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578 +static struct irq_chip gpmc_irq_chip = {
3579 + .name = "gpmc",
3580 + .irq_startup = gpmc_irq_noop_ret,
3581 + .irq_enable = gpmc_irq_enable,
3582 + .irq_disable = gpmc_irq_disable,
3583 + .irq_shutdown = gpmc_irq_noop,
3584 + .irq_ack = gpmc_irq_noop,
3585 + .irq_mask = gpmc_irq_noop,
3586 + .irq_unmask = gpmc_irq_noop,
3587 +
3588 +};
3589 +
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597 - gpmc_irq_chip.name = "gpmc";
3598 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605 -
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610 index 6944ae3..bc587ca 100644
3611 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613 @@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617 -};
3618 +} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622 @@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626 -struct cpu_pm_ops omap_pm_ops = {
3627 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632 index f961c46..4a453dc 100644
3633 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635 @@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639 -static struct notifier_block __refdata irq_hotplug_notifier = {
3640 +static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645 index 8c58b71..95b655f 100644
3646 --- a/arch/arm/mach-omap2/omap_device.c
3647 +++ b/arch/arm/mach-omap2/omap_device.c
3648 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652 - void *pdata, int pdata_len)
3653 + const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661 - int oh_cnt, void *pdata,
3662 + int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667 index 78c02b3..c94109a 100644
3668 --- a/arch/arm/mach-omap2/omap_device.h
3669 +++ b/arch/arm/mach-omap2/omap_device.h
3670 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674 - struct omap_hwmod *oh, void *pdata,
3675 + struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680 - void *pdata, int pdata_len);
3681 + const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686 index 716247e..8df346d 100644
3687 --- a/arch/arm/mach-omap2/omap_hwmod.c
3688 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3689 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693 -};
3694 +} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697 -static struct omap_hwmod_soc_ops soc_ops;
3698 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703 index 95fee54..cfa9cf1 100644
3704 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706 @@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710 +#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719 + pax_open_kernel();
3720 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721 + pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726 index ff0a68c..b312aa0 100644
3727 --- a/arch/arm/mach-omap2/wd_timer.c
3728 +++ b/arch/arm/mach-omap2/wd_timer.c
3729 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733 - struct omap_wd_timer_platform_data pdata;
3734 + static struct omap_wd_timer_platform_data pdata = {
3735 + .read_reset_sources = prm_read_reset_sources
3736 + };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744 - pdata.read_reset_sources = prm_read_reset_sources;
3745 -
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750 index b30bf5c..d0825bf 100644
3751 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757 - ACCESS_ONCE(abort_flag) = true;
3758 + ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763 index 2dea8b5..6499da2 100644
3764 --- a/arch/arm/mach-ux500/setup.h
3765 +++ b/arch/arm/mach-ux500/setup.h
3766 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770 -#define __MEM_DEV_DESC(x, sz) { \
3771 - .virtual = IO_ADDRESS(x), \
3772 - .pfn = __phys_to_pfn(x), \
3773 - .length = sz, \
3774 - .type = MT_MEMORY_RWX, \
3775 -}
3776 -
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781 index 7eb94e6..799ad3e 100644
3782 --- a/arch/arm/mm/Kconfig
3783 +++ b/arch/arm/mm/Kconfig
3784 @@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804 - depends on MMU
3805 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813 - by ROP (return orientated programming) authors when creating
3814 + by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819 index 83792f4..c25d36b 100644
3820 --- a/arch/arm/mm/alignment.c
3821 +++ b/arch/arm/mm/alignment.c
3822 @@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826 + pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839 + pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 @@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 @@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871 + pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875 @@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879 + pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884 index 5e65ca8..879e7b3 100644
3885 --- a/arch/arm/mm/cache-l2x0.c
3886 +++ b/arch/arm/mm/cache-l2x0.c
3887 @@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891 -};
3892 +} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897 index 4370933..e77848e 100644
3898 --- a/arch/arm/mm/context.c
3899 +++ b/arch/arm/mm/context.c
3900 @@ -43,7 +43,7 @@
3901 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3902
3903 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3904 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3905 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3906 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3907
3908 static DEFINE_PER_CPU(atomic64_t, active_asids);
3909 @@ -178,7 +178,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3910 {
3911 static u32 cur_idx = 1;
3912 u64 asid = atomic64_read(&mm->context.id);
3913 - u64 generation = atomic64_read(&asid_generation);
3914 + u64 generation = atomic64_read_unchecked(&asid_generation);
3915
3916 if (asid != 0 && is_reserved_asid(asid)) {
3917 /*
3918 @@ -199,7 +199,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3919 */
3920 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3921 if (asid == NUM_USER_ASIDS) {
3922 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3923 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3924 &asid_generation);
3925 flush_context(cpu);
3926 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3927 @@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3928 cpu_set_reserved_ttbr0();
3929
3930 asid = atomic64_read(&mm->context.id);
3931 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3932 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3933 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3934 goto switch_mm_fastpath;
3935
3936 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3937 /* Check that our ASID belongs to the current generation. */
3938 asid = atomic64_read(&mm->context.id);
3939 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3940 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3941 asid = new_context(mm, cpu);
3942 atomic64_set(&mm->context.id, asid);
3943 }
3944 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3945 index eb8830a..e8ff52e 100644
3946 --- a/arch/arm/mm/fault.c
3947 +++ b/arch/arm/mm/fault.c
3948 @@ -25,6 +25,7 @@
3949 #include <asm/system_misc.h>
3950 #include <asm/system_info.h>
3951 #include <asm/tlbflush.h>
3952 +#include <asm/sections.h>
3953
3954 #include "fault.h"
3955
3956 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3957 if (fixup_exception(regs))
3958 return;
3959
3960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3961 + if (addr < TASK_SIZE) {
3962 + if (current->signal->curr_ip)
3963 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + else
3966 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968 + }
3969 +#endif
3970 +
3971 +#ifdef CONFIG_PAX_KERNEXEC
3972 + if ((fsr & FSR_WRITE) &&
3973 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3974 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3975 + {
3976 + if (current->signal->curr_ip)
3977 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3978 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979 + else
3980 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3981 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3982 + }
3983 +#endif
3984 +
3985 /*
3986 * No handler, we'll have to terminate things with extreme prejudice.
3987 */
3988 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3989 }
3990 #endif
3991
3992 +#ifdef CONFIG_PAX_PAGEEXEC
3993 + if (fsr & FSR_LNX_PF) {
3994 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3995 + do_group_exit(SIGKILL);
3996 + }
3997 +#endif
3998 +
3999 tsk->thread.address = addr;
4000 tsk->thread.error_code = fsr;
4001 tsk->thread.trap_no = 14;
4002 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4003 }
4004 #endif /* CONFIG_MMU */
4005
4006 +#ifdef CONFIG_PAX_PAGEEXEC
4007 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4008 +{
4009 + long i;
4010 +
4011 + printk(KERN_ERR "PAX: bytes at PC: ");
4012 + for (i = 0; i < 20; i++) {
4013 + unsigned char c;
4014 + if (get_user(c, (__force unsigned char __user *)pc+i))
4015 + printk(KERN_CONT "?? ");
4016 + else
4017 + printk(KERN_CONT "%02x ", c);
4018 + }
4019 + printk("\n");
4020 +
4021 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4022 + for (i = -1; i < 20; i++) {
4023 + unsigned long c;
4024 + if (get_user(c, (__force unsigned long __user *)sp+i))
4025 + printk(KERN_CONT "???????? ");
4026 + else
4027 + printk(KERN_CONT "%08lx ", c);
4028 + }
4029 + printk("\n");
4030 +}
4031 +#endif
4032 +
4033 /*
4034 * First Level Translation Fault Handler
4035 *
4036 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4037 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4038 struct siginfo info;
4039
4040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4041 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4042 + if (current->signal->curr_ip)
4043 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4044 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045 + else
4046 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4047 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4048 + goto die;
4049 + }
4050 +#endif
4051 +
4052 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4053 return;
4054
4055 +die:
4056 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4057 inf->name, fsr, addr);
4058
4059 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4060 ifsr_info[nr].name = name;
4061 }
4062
4063 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4064 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4065 +
4066 asmlinkage void __exception
4067 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4068 {
4069 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4070 struct siginfo info;
4071 + unsigned long pc = instruction_pointer(regs);
4072 +
4073 + if (user_mode(regs)) {
4074 + unsigned long sigpage = current->mm->context.sigpage;
4075 +
4076 + if (sigpage <= pc && pc < sigpage + 7*4) {
4077 + if (pc < sigpage + 3*4)
4078 + sys_sigreturn(regs);
4079 + else
4080 + sys_rt_sigreturn(regs);
4081 + return;
4082 + }
4083 + if (pc == 0xffff0f60UL) {
4084 + /*
4085 + * PaX: __kuser_cmpxchg64 emulation
4086 + */
4087 + // TODO
4088 + //regs->ARM_pc = regs->ARM_lr;
4089 + //return;
4090 + }
4091 + if (pc == 0xffff0fa0UL) {
4092 + /*
4093 + * PaX: __kuser_memory_barrier emulation
4094 + */
4095 + // dmb(); implied by the exception
4096 + regs->ARM_pc = regs->ARM_lr;
4097 + return;
4098 + }
4099 + if (pc == 0xffff0fc0UL) {
4100 + /*
4101 + * PaX: __kuser_cmpxchg emulation
4102 + */
4103 + // TODO
4104 + //long new;
4105 + //int op;
4106 +
4107 + //op = FUTEX_OP_SET << 28;
4108 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4109 + //regs->ARM_r0 = old != new;
4110 + //regs->ARM_pc = regs->ARM_lr;
4111 + //return;
4112 + }
4113 + if (pc == 0xffff0fe0UL) {
4114 + /*
4115 + * PaX: __kuser_get_tls emulation
4116 + */
4117 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4118 + regs->ARM_pc = regs->ARM_lr;
4119 + return;
4120 + }
4121 + }
4122 +
4123 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4124 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4125 + if (current->signal->curr_ip)
4126 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4127 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4128 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4129 + else
4130 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4131 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4132 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4133 + goto die;
4134 + }
4135 +#endif
4136 +
4137 +#ifdef CONFIG_PAX_REFCOUNT
4138 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4139 +#ifdef CONFIG_THUMB2_KERNEL
4140 + unsigned short bkpt;
4141 +
4142 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4143 +#else
4144 + unsigned int bkpt;
4145 +
4146 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4147 +#endif
4148 + current->thread.error_code = ifsr;
4149 + current->thread.trap_no = 0;
4150 + pax_report_refcount_overflow(regs);
4151 + fixup_exception(regs);
4152 + return;
4153 + }
4154 + }
4155 +#endif
4156
4157 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4158 return;
4159
4160 +die:
4161 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4162 inf->name, ifsr, addr);
4163
4164 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4165 index cf08bdf..772656c 100644
4166 --- a/arch/arm/mm/fault.h
4167 +++ b/arch/arm/mm/fault.h
4168 @@ -3,6 +3,7 @@
4169
4170 /*
4171 * Fault status register encodings. We steal bit 31 for our own purposes.
4172 + * Set when the FSR value is from an instruction fault.
4173 */
4174 #define FSR_LNX_PF (1 << 31)
4175 #define FSR_WRITE (1 << 11)
4176 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4177 }
4178 #endif
4179
4180 +/* valid for LPAE and !LPAE */
4181 +static inline int is_xn_fault(unsigned int fsr)
4182 +{
4183 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4184 +}
4185 +
4186 +static inline int is_domain_fault(unsigned int fsr)
4187 +{
4188 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4189 +}
4190 +
4191 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4192 unsigned long search_exception_table(unsigned long addr);
4193
4194 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4195 index 9481f85..6dae261 100644
4196 --- a/arch/arm/mm/init.c
4197 +++ b/arch/arm/mm/init.c
4198 @@ -31,6 +31,8 @@
4199 #include <asm/setup.h>
4200 #include <asm/tlb.h>
4201 #include <asm/fixmap.h>
4202 +#include <asm/system_info.h>
4203 +#include <asm/cp15.h>
4204
4205 #include <asm/mach/arch.h>
4206 #include <asm/mach/map.h>
4207 @@ -619,7 +621,46 @@ void free_initmem(void)
4208 {
4209 #ifdef CONFIG_HAVE_TCM
4210 extern char __tcm_start, __tcm_end;
4211 +#endif
4212
4213 +#ifdef CONFIG_PAX_KERNEXEC
4214 + unsigned long addr;
4215 + pgd_t *pgd;
4216 + pud_t *pud;
4217 + pmd_t *pmd;
4218 + int cpu_arch = cpu_architecture();
4219 + unsigned int cr = get_cr();
4220 +
4221 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4222 + /* make pages tables, etc before .text NX */
4223 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4224 + pgd = pgd_offset_k(addr);
4225 + pud = pud_offset(pgd, addr);
4226 + pmd = pmd_offset(pud, addr);
4227 + __section_update(pmd, addr, PMD_SECT_XN);
4228 + }
4229 + /* make init NX */
4230 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4231 + pgd = pgd_offset_k(addr);
4232 + pud = pud_offset(pgd, addr);
4233 + pmd = pmd_offset(pud, addr);
4234 + __section_update(pmd, addr, PMD_SECT_XN);
4235 + }
4236 + /* make kernel code/rodata RX */
4237 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4238 + pgd = pgd_offset_k(addr);
4239 + pud = pud_offset(pgd, addr);
4240 + pmd = pmd_offset(pud, addr);
4241 +#ifdef CONFIG_ARM_LPAE
4242 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4243 +#else
4244 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4245 +#endif
4246 + }
4247 + }
4248 +#endif
4249 +
4250 +#ifdef CONFIG_HAVE_TCM
4251 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4252 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4253 #endif
4254 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4255 index d1e5ad7..84dcbf2 100644
4256 --- a/arch/arm/mm/ioremap.c
4257 +++ b/arch/arm/mm/ioremap.c
4258 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4259 unsigned int mtype;
4260
4261 if (cached)
4262 - mtype = MT_MEMORY_RWX;
4263 + mtype = MT_MEMORY_RX;
4264 else
4265 - mtype = MT_MEMORY_RWX_NONCACHED;
4266 + mtype = MT_MEMORY_RX_NONCACHED;
4267
4268 return __arm_ioremap_caller(phys_addr, size, mtype,
4269 __builtin_return_address(0));
4270 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4271 index 5e85ed3..b10a7ed 100644
4272 --- a/arch/arm/mm/mmap.c
4273 +++ b/arch/arm/mm/mmap.c
4274 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4275 struct vm_area_struct *vma;
4276 int do_align = 0;
4277 int aliasing = cache_is_vipt_aliasing();
4278 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4279 struct vm_unmapped_area_info info;
4280
4281 /*
4282 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4283 if (len > TASK_SIZE)
4284 return -ENOMEM;
4285
4286 +#ifdef CONFIG_PAX_RANDMMAP
4287 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4288 +#endif
4289 +
4290 if (addr) {
4291 if (do_align)
4292 addr = COLOUR_ALIGN(addr, pgoff);
4293 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4294 addr = PAGE_ALIGN(addr);
4295
4296 vma = find_vma(mm, addr);
4297 - if (TASK_SIZE - len >= addr &&
4298 - (!vma || addr + len <= vma->vm_start))
4299 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4300 return addr;
4301 }
4302
4303 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4304 info.high_limit = TASK_SIZE;
4305 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4306 info.align_offset = pgoff << PAGE_SHIFT;
4307 + info.threadstack_offset = offset;
4308 return vm_unmapped_area(&info);
4309 }
4310
4311 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4312 unsigned long addr = addr0;
4313 int do_align = 0;
4314 int aliasing = cache_is_vipt_aliasing();
4315 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4316 struct vm_unmapped_area_info info;
4317
4318 /*
4319 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4320 return addr;
4321 }
4322
4323 +#ifdef CONFIG_PAX_RANDMMAP
4324 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4325 +#endif
4326 +
4327 /* requesting a specific address */
4328 if (addr) {
4329 if (do_align)
4330 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4331 else
4332 addr = PAGE_ALIGN(addr);
4333 vma = find_vma(mm, addr);
4334 - if (TASK_SIZE - len >= addr &&
4335 - (!vma || addr + len <= vma->vm_start))
4336 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4337 return addr;
4338 }
4339
4340 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4341 info.high_limit = mm->mmap_base;
4342 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4343 info.align_offset = pgoff << PAGE_SHIFT;
4344 + info.threadstack_offset = offset;
4345 addr = vm_unmapped_area(&info);
4346
4347 /*
4348 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4349 {
4350 unsigned long random_factor = 0UL;
4351
4352 +#ifdef CONFIG_PAX_RANDMMAP
4353 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4354 +#endif
4355 +
4356 /* 8 bits of randomness in 20 address space bits */
4357 if ((current->flags & PF_RANDOMIZE) &&
4358 !(current->personality & ADDR_NO_RANDOMIZE))
4359 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4360
4361 if (mmap_is_legacy()) {
4362 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4363 +
4364 +#ifdef CONFIG_PAX_RANDMMAP
4365 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4366 + mm->mmap_base += mm->delta_mmap;
4367 +#endif
4368 +
4369 mm->get_unmapped_area = arch_get_unmapped_area;
4370 } else {
4371 mm->mmap_base = mmap_base(random_factor);
4372 +
4373 +#ifdef CONFIG_PAX_RANDMMAP
4374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4375 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4376 +#endif
4377 +
4378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4379 }
4380 }
4381 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4382 index 9f98cec..115fcb6 100644
4383 --- a/arch/arm/mm/mmu.c
4384 +++ b/arch/arm/mm/mmu.c
4385 @@ -40,6 +40,22 @@
4386 #include "mm.h"
4387 #include "tcm.h"
4388
4389 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4390 +void modify_domain(unsigned int dom, unsigned int type)
4391 +{
4392 + struct thread_info *thread = current_thread_info();
4393 + unsigned int domain = thread->cpu_domain;
4394 + /*
4395 + * DOMAIN_MANAGER might be defined to some other value,
4396 + * use the arch-defined constant
4397 + */
4398 + domain &= ~domain_val(dom, 3);
4399 + thread->cpu_domain = domain | domain_val(dom, type);
4400 + set_domain(thread->cpu_domain);
4401 +}
4402 +EXPORT_SYMBOL(modify_domain);
4403 +#endif
4404 +
4405 /*
4406 * empty_zero_page is a special page that is used for
4407 * zero-initialized data and COW.
4408 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4409 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4410 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4411
4412 -static struct mem_type mem_types[] = {
4413 +#ifdef CONFIG_PAX_KERNEXEC
4414 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4415 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4416 +#else
4417 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4418 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4419 +#endif
4420 +
4421 +static struct mem_type mem_types[] __read_only = {
4422 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4423 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4424 L_PTE_SHARED,
4425 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4426 .prot_sect = PROT_SECT_DEVICE,
4427 .domain = DOMAIN_IO,
4428 },
4429 - [MT_UNCACHED] = {
4430 + [MT_UNCACHED_RW] = {
4431 .prot_pte = PROT_PTE_DEVICE,
4432 .prot_l1 = PMD_TYPE_TABLE,
4433 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4434 .domain = DOMAIN_IO,
4435 },
4436 - [MT_CACHECLEAN] = {
4437 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4438 + [MT_CACHECLEAN_RO] = {
4439 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4440 .domain = DOMAIN_KERNEL,
4441 },
4442 #ifndef CONFIG_ARM_LPAE
4443 - [MT_MINICLEAN] = {
4444 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4445 + [MT_MINICLEAN_RO] = {
4446 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4447 .domain = DOMAIN_KERNEL,
4448 },
4449 #endif
4450 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4451 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4452 L_PTE_RDONLY,
4453 .prot_l1 = PMD_TYPE_TABLE,
4454 - .domain = DOMAIN_USER,
4455 + .domain = DOMAIN_VECTORS,
4456 },
4457 [MT_HIGH_VECTORS] = {
4458 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4459 L_PTE_USER | L_PTE_RDONLY,
4460 .prot_l1 = PMD_TYPE_TABLE,
4461 - .domain = DOMAIN_USER,
4462 + .domain = DOMAIN_VECTORS,
4463 },
4464 - [MT_MEMORY_RWX] = {
4465 + [__MT_MEMORY_RWX] = {
4466 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4470 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4471 .domain = DOMAIN_KERNEL,
4472 },
4473 - [MT_ROM] = {
4474 - .prot_sect = PMD_TYPE_SECT,
4475 + [MT_MEMORY_RX] = {
4476 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4477 + .prot_l1 = PMD_TYPE_TABLE,
4478 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4479 + .domain = DOMAIN_KERNEL,
4480 + },
4481 + [MT_ROM_RX] = {
4482 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485 - [MT_MEMORY_RWX_NONCACHED] = {
4486 + [MT_MEMORY_RW_NONCACHED] = {
4487 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4488 L_PTE_MT_BUFFERABLE,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493 + [MT_MEMORY_RX_NONCACHED] = {
4494 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4495 + L_PTE_MT_BUFFERABLE,
4496 + .prot_l1 = PMD_TYPE_TABLE,
4497 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4498 + .domain = DOMAIN_KERNEL,
4499 + },
4500 [MT_MEMORY_RW_DTCM] = {
4501 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4502 L_PTE_XN,
4503 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4504 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4505 .domain = DOMAIN_KERNEL,
4506 },
4507 - [MT_MEMORY_RWX_ITCM] = {
4508 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4509 + [MT_MEMORY_RX_ITCM] = {
4510 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4511 .prot_l1 = PMD_TYPE_TABLE,
4512 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4513 .domain = DOMAIN_KERNEL,
4514 },
4515 [MT_MEMORY_RW_SO] = {
4516 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4517 * Mark cache clean areas and XIP ROM read only
4518 * from SVC mode and no access from userspace.
4519 */
4520 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4523 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4524 +#ifdef CONFIG_PAX_KERNEXEC
4525 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4526 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4527 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4528 +#endif
4529 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4530 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4531 #endif
4532
4533 /*
4534 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4535 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4536 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4537 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4538 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4539 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4540 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4541 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4542 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4543 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4544 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4545 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4546 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4547 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4548 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4549 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4550 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4551 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4552 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4553 }
4554 }
4555
4556 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4557 if (cpu_arch >= CPU_ARCH_ARMv6) {
4558 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4559 /* Non-cacheable Normal is XCB = 001 */
4560 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4561 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4562 + PMD_SECT_BUFFERED;
4563 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4564 PMD_SECT_BUFFERED;
4565 } else {
4566 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4567 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4568 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4569 + PMD_SECT_TEX(1);
4570 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4571 PMD_SECT_TEX(1);
4572 }
4573 } else {
4574 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4575 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4576 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4577 }
4578
4579 #ifdef CONFIG_ARM_LPAE
4580 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4581 vecs_pgprot |= PTE_EXT_AF;
4582 #endif
4583
4584 + user_pgprot |= __supported_pte_mask;
4585 +
4586 for (i = 0; i < 16; i++) {
4587 pteval_t v = pgprot_val(protection_map[i]);
4588 protection_map[i] = __pgprot(v | user_pgprot);
4589 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4590
4591 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4592 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4593 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4594 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4595 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4596 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4597 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4598 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4599 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4600 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4601 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4602 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4603 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4604 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4605 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4606 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4607
4608 switch (cp->pmd) {
4609 case PMD_SECT_WT:
4610 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4611 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4612 break;
4613 case PMD_SECT_WB:
4614 case PMD_SECT_WBWA:
4615 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4616 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4617 break;
4618 }
4619 pr_info("Memory policy: %sData cache %s\n",
4620 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4621 return;
4622 }
4623
4624 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4625 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4626 md->virtual >= PAGE_OFFSET &&
4627 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4628 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4629 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4630 * called function. This means you can't use any function or debugging
4631 * method which may touch any device, otherwise the kernel _will_ crash.
4632 */
4633 +
4634 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4635 +
4636 static void __init devicemaps_init(const struct machine_desc *mdesc)
4637 {
4638 struct map_desc map;
4639 unsigned long addr;
4640 - void *vectors;
4641
4642 - /*
4643 - * Allocate the vector page early.
4644 - */
4645 - vectors = early_alloc(PAGE_SIZE * 2);
4646 -
4647 - early_trap_init(vectors);
4648 + early_trap_init(&vectors);
4649
4650 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4651 pmd_clear(pmd_off_k(addr));
4652 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4654 map.virtual = MODULES_VADDR;
4655 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4656 - map.type = MT_ROM;
4657 + map.type = MT_ROM_RX;
4658 create_mapping(&map);
4659 #endif
4660
4661 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4662 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4663 map.virtual = FLUSH_BASE;
4664 map.length = SZ_1M;
4665 - map.type = MT_CACHECLEAN;
4666 + map.type = MT_CACHECLEAN_RO;
4667 create_mapping(&map);
4668 #endif
4669 #ifdef FLUSH_BASE_MINICACHE
4670 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4671 map.virtual = FLUSH_BASE_MINICACHE;
4672 map.length = SZ_1M;
4673 - map.type = MT_MINICLEAN;
4674 + map.type = MT_MINICLEAN_RO;
4675 create_mapping(&map);
4676 #endif
4677
4678 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4679 * location (0xffff0000). If we aren't using high-vectors, also
4680 * create a mapping at the low-vectors virtual address.
4681 */
4682 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4683 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4684 map.virtual = 0xffff0000;
4685 map.length = PAGE_SIZE;
4686 #ifdef CONFIG_KUSER_HELPERS
4687 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4688 static void __init map_lowmem(void)
4689 {
4690 struct memblock_region *reg;
4691 +#ifndef CONFIG_PAX_KERNEXEC
4692 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4693 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4694 +#endif
4695
4696 /* Map all the lowmem memory banks. */
4697 for_each_memblock(memory, reg) {
4698 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4699 if (start >= end)
4700 break;
4701
4702 +#ifdef CONFIG_PAX_KERNEXEC
4703 + map.pfn = __phys_to_pfn(start);
4704 + map.virtual = __phys_to_virt(start);
4705 + map.length = end - start;
4706 +
4707 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4708 + struct map_desc kernel;
4709 + struct map_desc initmap;
4710 +
4711 + /* when freeing initmem we will make this RW */
4712 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4713 + initmap.virtual = (unsigned long)__init_begin;
4714 + initmap.length = _sdata - __init_begin;
4715 + initmap.type = __MT_MEMORY_RWX;
4716 + create_mapping(&initmap);
4717 +
4718 + /* when freeing initmem we will make this RX */
4719 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4720 + kernel.virtual = (unsigned long)_stext;
4721 + kernel.length = __init_begin - _stext;
4722 + kernel.type = __MT_MEMORY_RWX;
4723 + create_mapping(&kernel);
4724 +
4725 + if (map.virtual < (unsigned long)_stext) {
4726 + map.length = (unsigned long)_stext - map.virtual;
4727 + map.type = __MT_MEMORY_RWX;
4728 + create_mapping(&map);
4729 + }
4730 +
4731 + map.pfn = __phys_to_pfn(__pa(_sdata));
4732 + map.virtual = (unsigned long)_sdata;
4733 + map.length = end - __pa(_sdata);
4734 + }
4735 +
4736 + map.type = MT_MEMORY_RW;
4737 + create_mapping(&map);
4738 +#else
4739 if (end < kernel_x_start || start >= kernel_x_end) {
4740 map.pfn = __phys_to_pfn(start);
4741 map.virtual = __phys_to_virt(start);
4742 map.length = end - start;
4743 - map.type = MT_MEMORY_RWX;
4744 + map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747 } else {
4748 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4749 map.pfn = __phys_to_pfn(kernel_x_start);
4750 map.virtual = __phys_to_virt(kernel_x_start);
4751 map.length = kernel_x_end - kernel_x_start;
4752 - map.type = MT_MEMORY_RWX;
4753 + map.type = __MT_MEMORY_RWX;
4754
4755 create_mapping(&map);
4756
4757 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4758 create_mapping(&map);
4759 }
4760 }
4761 +#endif
4762 }
4763 }
4764
4765 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4766 index e1268f9..a9755a7 100644
4767 --- a/arch/arm/net/bpf_jit_32.c
4768 +++ b/arch/arm/net/bpf_jit_32.c
4769 @@ -20,6 +20,7 @@
4770 #include <asm/cacheflush.h>
4771 #include <asm/hwcap.h>
4772 #include <asm/opcodes.h>
4773 +#include <asm/pgtable.h>
4774
4775 #include "bpf_jit_32.h"
4776
4777 @@ -71,7 +72,11 @@ struct jit_ctx {
4778 #endif
4779 };
4780
4781 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4782 +int bpf_jit_enable __read_only;
4783 +#else
4784 int bpf_jit_enable __read_mostly;
4785 +#endif
4786
4787 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4788 {
4789 @@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4790 {
4791 u32 *ptr;
4792 /* We are guaranteed to have aligned memory. */
4793 + pax_open_kernel();
4794 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4795 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4796 + pax_close_kernel();
4797 }
4798
4799 static void build_prologue(struct jit_ctx *ctx)
4800 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4801 index 5b217f4..c23f40e 100644
4802 --- a/arch/arm/plat-iop/setup.c
4803 +++ b/arch/arm/plat-iop/setup.c
4804 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4805 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4806 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4807 .length = IOP3XX_PERIPHERAL_SIZE,
4808 - .type = MT_UNCACHED,
4809 + .type = MT_UNCACHED_RW,
4810 },
4811 };
4812
4813 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4814 index a5bc92d..0bb4730 100644
4815 --- a/arch/arm/plat-omap/sram.c
4816 +++ b/arch/arm/plat-omap/sram.c
4817 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4818 * Looks like we need to preserve some bootloader code at the
4819 * beginning of SRAM for jumping to flash for reboot to work...
4820 */
4821 + pax_open_kernel();
4822 memset_io(omap_sram_base + omap_sram_skip, 0,
4823 omap_sram_size - omap_sram_skip);
4824 + pax_close_kernel();
4825 }
4826 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4827 index ce6d763..cfea917 100644
4828 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4829 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4830 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4831 int (*started)(unsigned ch);
4832 int (*flush)(unsigned ch);
4833 int (*stop)(unsigned ch);
4834 -};
4835 +} __no_const;
4836
4837 extern void *samsung_dmadev_get_ops(void);
4838 extern void *s3c_dma_get_ops(void);
4839 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4840 index 6389d60..b5d3bdd 100644
4841 --- a/arch/arm64/include/asm/barrier.h
4842 +++ b/arch/arm64/include/asm/barrier.h
4843 @@ -41,7 +41,7 @@
4844 do { \
4845 compiletime_assert_atomic_type(*p); \
4846 barrier(); \
4847 - ACCESS_ONCE(*p) = (v); \
4848 + ACCESS_ONCE_RW(*p) = (v); \
4849 } while (0)
4850
4851 #define smp_load_acquire(p) \
4852 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4853 index 3bf8f4e..5dd5491 100644
4854 --- a/arch/arm64/include/asm/uaccess.h
4855 +++ b/arch/arm64/include/asm/uaccess.h
4856 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4857 flag; \
4858 })
4859
4860 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4861 #define access_ok(type, addr, size) __range_ok(addr, size)
4862 #define user_addr_max get_fs
4863
4864 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4865 index c3a58a1..78fbf54 100644
4866 --- a/arch/avr32/include/asm/cache.h
4867 +++ b/arch/avr32/include/asm/cache.h
4868 @@ -1,8 +1,10 @@
4869 #ifndef __ASM_AVR32_CACHE_H
4870 #define __ASM_AVR32_CACHE_H
4871
4872 +#include <linux/const.h>
4873 +
4874 #define L1_CACHE_SHIFT 5
4875 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4876 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 /*
4879 * Memory returned by kmalloc() may be used for DMA, so we must make
4880 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4881 index d232888..87c8df1 100644
4882 --- a/arch/avr32/include/asm/elf.h
4883 +++ b/arch/avr32/include/asm/elf.h
4884 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4885 the loader. We need to make sure that it is out of the way of the program
4886 that it will "exec", and that there is sufficient room for the brk. */
4887
4888 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4889 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4890
4891 +#ifdef CONFIG_PAX_ASLR
4892 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4893 +
4894 +#define PAX_DELTA_MMAP_LEN 15
4895 +#define PAX_DELTA_STACK_LEN 15
4896 +#endif
4897
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this CPU supports. This could be done in user space,
4900 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4901 index 479330b..53717a8 100644
4902 --- a/arch/avr32/include/asm/kmap_types.h
4903 +++ b/arch/avr32/include/asm/kmap_types.h
4904 @@ -2,9 +2,9 @@
4905 #define __ASM_AVR32_KMAP_TYPES_H
4906
4907 #ifdef CONFIG_DEBUG_HIGHMEM
4908 -# define KM_TYPE_NR 29
4909 +# define KM_TYPE_NR 30
4910 #else
4911 -# define KM_TYPE_NR 14
4912 +# define KM_TYPE_NR 15
4913 #endif
4914
4915 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4916 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4917 index d223a8b..69c5210 100644
4918 --- a/arch/avr32/mm/fault.c
4919 +++ b/arch/avr32/mm/fault.c
4920 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4921
4922 int exception_trace = 1;
4923
4924 +#ifdef CONFIG_PAX_PAGEEXEC
4925 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4926 +{
4927 + unsigned long i;
4928 +
4929 + printk(KERN_ERR "PAX: bytes at PC: ");
4930 + for (i = 0; i < 20; i++) {
4931 + unsigned char c;
4932 + if (get_user(c, (unsigned char *)pc+i))
4933 + printk(KERN_CONT "???????? ");
4934 + else
4935 + printk(KERN_CONT "%02x ", c);
4936 + }
4937 + printk("\n");
4938 +}
4939 +#endif
4940 +
4941 /*
4942 * This routine handles page faults. It determines the address and the
4943 * problem, and then passes it off to one of the appropriate routines.
4944 @@ -178,6 +195,16 @@ bad_area:
4945 up_read(&mm->mmap_sem);
4946
4947 if (user_mode(regs)) {
4948 +
4949 +#ifdef CONFIG_PAX_PAGEEXEC
4950 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4951 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4952 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4953 + do_group_exit(SIGKILL);
4954 + }
4955 + }
4956 +#endif
4957 +
4958 if (exception_trace && printk_ratelimit())
4959 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4960 "sp %08lx ecr %lu\n",
4961 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4962 index 568885a..f8008df 100644
4963 --- a/arch/blackfin/include/asm/cache.h
4964 +++ b/arch/blackfin/include/asm/cache.h
4965 @@ -7,6 +7,7 @@
4966 #ifndef __ARCH_BLACKFIN_CACHE_H
4967 #define __ARCH_BLACKFIN_CACHE_H
4968
4969 +#include <linux/const.h>
4970 #include <linux/linkage.h> /* for asmlinkage */
4971
4972 /*
4973 @@ -14,7 +15,7 @@
4974 * Blackfin loads 32 bytes for cache
4975 */
4976 #define L1_CACHE_SHIFT 5
4977 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4980
4981 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4982 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4983 index aea2718..3639a60 100644
4984 --- a/arch/cris/include/arch-v10/arch/cache.h
4985 +++ b/arch/cris/include/arch-v10/arch/cache.h
4986 @@ -1,8 +1,9 @@
4987 #ifndef _ASM_ARCH_CACHE_H
4988 #define _ASM_ARCH_CACHE_H
4989
4990 +#include <linux/const.h>
4991 /* Etrax 100LX have 32-byte cache-lines. */
4992 -#define L1_CACHE_BYTES 32
4993 #define L1_CACHE_SHIFT 5
4994 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4995
4996 #endif /* _ASM_ARCH_CACHE_H */
4997 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4998 index 7caf25d..ee65ac5 100644
4999 --- a/arch/cris/include/arch-v32/arch/cache.h
5000 +++ b/arch/cris/include/arch-v32/arch/cache.h
5001 @@ -1,11 +1,12 @@
5002 #ifndef _ASM_CRIS_ARCH_CACHE_H
5003 #define _ASM_CRIS_ARCH_CACHE_H
5004
5005 +#include <linux/const.h>
5006 #include <arch/hwregs/dma.h>
5007
5008 /* A cache-line is 32 bytes. */
5009 -#define L1_CACHE_BYTES 32
5010 #define L1_CACHE_SHIFT 5
5011 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5012
5013 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5014
5015 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5016 index 102190a..5334cea 100644
5017 --- a/arch/frv/include/asm/atomic.h
5018 +++ b/arch/frv/include/asm/atomic.h
5019 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5020 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5021 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5022
5023 +#define atomic64_read_unchecked(v) atomic64_read(v)
5024 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5025 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5026 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5027 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5028 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5029 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5030 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5031 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5032 +
5033 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5034 {
5035 int c, old;
5036 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5037 index 2797163..c2a401df9 100644
5038 --- a/arch/frv/include/asm/cache.h
5039 +++ b/arch/frv/include/asm/cache.h
5040 @@ -12,10 +12,11 @@
5041 #ifndef __ASM_CACHE_H
5042 #define __ASM_CACHE_H
5043
5044 +#include <linux/const.h>
5045
5046 /* bytes per L1 cache line */
5047 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5048 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5049 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5050
5051 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5052 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5053 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5054 index 43901f2..0d8b865 100644
5055 --- a/arch/frv/include/asm/kmap_types.h
5056 +++ b/arch/frv/include/asm/kmap_types.h
5057 @@ -2,6 +2,6 @@
5058 #ifndef _ASM_KMAP_TYPES_H
5059 #define _ASM_KMAP_TYPES_H
5060
5061 -#define KM_TYPE_NR 17
5062 +#define KM_TYPE_NR 18
5063
5064 #endif
5065 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5066 index 836f147..4cf23f5 100644
5067 --- a/arch/frv/mm/elf-fdpic.c
5068 +++ b/arch/frv/mm/elf-fdpic.c
5069 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5070 {
5071 struct vm_area_struct *vma;
5072 struct vm_unmapped_area_info info;
5073 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5074
5075 if (len > TASK_SIZE)
5076 return -ENOMEM;
5077 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5078 if (addr) {
5079 addr = PAGE_ALIGN(addr);
5080 vma = find_vma(current->mm, addr);
5081 - if (TASK_SIZE - len >= addr &&
5082 - (!vma || addr + len <= vma->vm_start))
5083 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5084 goto success;
5085 }
5086
5087 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5088 info.high_limit = (current->mm->start_stack - 0x00200000);
5089 info.align_mask = 0;
5090 info.align_offset = 0;
5091 + info.threadstack_offset = offset;
5092 addr = vm_unmapped_area(&info);
5093 if (!(addr & ~PAGE_MASK))
5094 goto success;
5095 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5096 index 2635117..fa223cb 100644
5097 --- a/arch/hexagon/include/asm/cache.h
5098 +++ b/arch/hexagon/include/asm/cache.h
5099 @@ -21,9 +21,11 @@
5100 #ifndef __ASM_CACHE_H
5101 #define __ASM_CACHE_H
5102
5103 +#include <linux/const.h>
5104 +
5105 /* Bytes per L1 cache line */
5106 -#define L1_CACHE_SHIFT (5)
5107 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5108 +#define L1_CACHE_SHIFT 5
5109 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5110
5111 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5112 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5113 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5114 index c84c88b..2a6e1ba 100644
5115 --- a/arch/ia64/Kconfig
5116 +++ b/arch/ia64/Kconfig
5117 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5118 config KEXEC
5119 bool "kexec system call"
5120 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5121 + depends on !GRKERNSEC_KMEM
5122 help
5123 kexec is a system call that implements the ability to shutdown your
5124 current kernel, and to start another kernel. It is like a reboot
5125 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5126 index 5441b14..039a446 100644
5127 --- a/arch/ia64/Makefile
5128 +++ b/arch/ia64/Makefile
5129 @@ -99,5 +99,6 @@ endef
5130 archprepare: make_nr_irqs_h FORCE
5131 PHONY += make_nr_irqs_h FORCE
5132
5133 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5134 make_nr_irqs_h: FORCE
5135 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5136 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5137 index 0bf0350..2ad1957 100644
5138 --- a/arch/ia64/include/asm/atomic.h
5139 +++ b/arch/ia64/include/asm/atomic.h
5140 @@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5141 #define atomic64_inc(v) atomic64_add(1, (v))
5142 #define atomic64_dec(v) atomic64_sub(1, (v))
5143
5144 +#define atomic64_read_unchecked(v) atomic64_read(v)
5145 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5146 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5147 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5148 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5149 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5150 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5151 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5152 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5153 +
5154 #endif /* _ASM_IA64_ATOMIC_H */
5155 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5156 index a48957c..e097b56 100644
5157 --- a/arch/ia64/include/asm/barrier.h
5158 +++ b/arch/ia64/include/asm/barrier.h
5159 @@ -67,7 +67,7 @@
5160 do { \
5161 compiletime_assert_atomic_type(*p); \
5162 barrier(); \
5163 - ACCESS_ONCE(*p) = (v); \
5164 + ACCESS_ONCE_RW(*p) = (v); \
5165 } while (0)
5166
5167 #define smp_load_acquire(p) \
5168 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5169 index 988254a..e1ee885 100644
5170 --- a/arch/ia64/include/asm/cache.h
5171 +++ b/arch/ia64/include/asm/cache.h
5172 @@ -1,6 +1,7 @@
5173 #ifndef _ASM_IA64_CACHE_H
5174 #define _ASM_IA64_CACHE_H
5175
5176 +#include <linux/const.h>
5177
5178 /*
5179 * Copyright (C) 1998-2000 Hewlett-Packard Co
5180 @@ -9,7 +10,7 @@
5181
5182 /* Bytes per L1 (data) cache line. */
5183 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5184 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5185 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5186
5187 #ifdef CONFIG_SMP
5188 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5189 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5190 index 5a83c5c..4d7f553 100644
5191 --- a/arch/ia64/include/asm/elf.h
5192 +++ b/arch/ia64/include/asm/elf.h
5193 @@ -42,6 +42,13 @@
5194 */
5195 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5196
5197 +#ifdef CONFIG_PAX_ASLR
5198 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5199 +
5200 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5201 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5202 +#endif
5203 +
5204 #define PT_IA_64_UNWIND 0x70000001
5205
5206 /* IA-64 relocations: */
5207 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5208 index 5767cdf..7462574 100644
5209 --- a/arch/ia64/include/asm/pgalloc.h
5210 +++ b/arch/ia64/include/asm/pgalloc.h
5211 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5212 pgd_val(*pgd_entry) = __pa(pud);
5213 }
5214
5215 +static inline void
5216 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5217 +{
5218 + pgd_populate(mm, pgd_entry, pud);
5219 +}
5220 +
5221 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5222 {
5223 return quicklist_alloc(0, GFP_KERNEL, NULL);
5224 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5225 pud_val(*pud_entry) = __pa(pmd);
5226 }
5227
5228 +static inline void
5229 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5230 +{
5231 + pud_populate(mm, pud_entry, pmd);
5232 +}
5233 +
5234 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5235 {
5236 return quicklist_alloc(0, GFP_KERNEL, NULL);
5237 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5238 index 7935115..c0eca6a 100644
5239 --- a/arch/ia64/include/asm/pgtable.h
5240 +++ b/arch/ia64/include/asm/pgtable.h
5241 @@ -12,7 +12,7 @@
5242 * David Mosberger-Tang <davidm@hpl.hp.com>
5243 */
5244
5245 -
5246 +#include <linux/const.h>
5247 #include <asm/mman.h>
5248 #include <asm/page.h>
5249 #include <asm/processor.h>
5250 @@ -142,6 +142,17 @@
5251 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5252 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5253 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5254 +
5255 +#ifdef CONFIG_PAX_PAGEEXEC
5256 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5257 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5258 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5259 +#else
5260 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5261 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5262 +# define PAGE_COPY_NOEXEC PAGE_COPY
5263 +#endif
5264 +
5265 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5266 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5267 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5268 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5269 index 45698cd..e8e2dbc 100644
5270 --- a/arch/ia64/include/asm/spinlock.h
5271 +++ b/arch/ia64/include/asm/spinlock.h
5272 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5273 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5274
5275 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5276 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5277 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5278 }
5279
5280 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5281 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5282 index 449c8c0..3d4b1e9 100644
5283 --- a/arch/ia64/include/asm/uaccess.h
5284 +++ b/arch/ia64/include/asm/uaccess.h
5285 @@ -70,6 +70,7 @@
5286 && ((segment).seg == KERNEL_DS.seg \
5287 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5288 })
5289 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5290 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5291
5292 /*
5293 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5294 static inline unsigned long
5295 __copy_to_user (void __user *to, const void *from, unsigned long count)
5296 {
5297 + if (count > INT_MAX)
5298 + return count;
5299 +
5300 + if (!__builtin_constant_p(count))
5301 + check_object_size(from, count, true);
5302 +
5303 return __copy_user(to, (__force void __user *) from, count);
5304 }
5305
5306 static inline unsigned long
5307 __copy_from_user (void *to, const void __user *from, unsigned long count)
5308 {
5309 + if (count > INT_MAX)
5310 + return count;
5311 +
5312 + if (!__builtin_constant_p(count))
5313 + check_object_size(to, count, false);
5314 +
5315 return __copy_user((__force void __user *) to, from, count);
5316 }
5317
5318 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5319 ({ \
5320 void __user *__cu_to = (to); \
5321 const void *__cu_from = (from); \
5322 - long __cu_len = (n); \
5323 + unsigned long __cu_len = (n); \
5324 \
5325 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5326 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5327 + if (!__builtin_constant_p(n)) \
5328 + check_object_size(__cu_from, __cu_len, true); \
5329 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5330 + } \
5331 __cu_len; \
5332 })
5333
5334 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5335 ({ \
5336 void *__cu_to = (to); \
5337 const void __user *__cu_from = (from); \
5338 - long __cu_len = (n); \
5339 + unsigned long __cu_len = (n); \
5340 \
5341 __chk_user_ptr(__cu_from); \
5342 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5343 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5344 + if (!__builtin_constant_p(n)) \
5345 + check_object_size(__cu_to, __cu_len, false); \
5346 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5347 + } \
5348 __cu_len; \
5349 })
5350
5351 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5352 index 24603be..948052d 100644
5353 --- a/arch/ia64/kernel/module.c
5354 +++ b/arch/ia64/kernel/module.c
5355 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5356 void
5357 module_free (struct module *mod, void *module_region)
5358 {
5359 - if (mod && mod->arch.init_unw_table &&
5360 - module_region == mod->module_init) {
5361 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5362 unw_remove_unwind_table(mod->arch.init_unw_table);
5363 mod->arch.init_unw_table = NULL;
5364 }
5365 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5366 }
5367
5368 static inline int
5369 +in_init_rx (const struct module *mod, uint64_t addr)
5370 +{
5371 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5372 +}
5373 +
5374 +static inline int
5375 +in_init_rw (const struct module *mod, uint64_t addr)
5376 +{
5377 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5378 +}
5379 +
5380 +static inline int
5381 in_init (const struct module *mod, uint64_t addr)
5382 {
5383 - return addr - (uint64_t) mod->module_init < mod->init_size;
5384 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5385 +}
5386 +
5387 +static inline int
5388 +in_core_rx (const struct module *mod, uint64_t addr)
5389 +{
5390 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5391 +}
5392 +
5393 +static inline int
5394 +in_core_rw (const struct module *mod, uint64_t addr)
5395 +{
5396 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5397 }
5398
5399 static inline int
5400 in_core (const struct module *mod, uint64_t addr)
5401 {
5402 - return addr - (uint64_t) mod->module_core < mod->core_size;
5403 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5404 }
5405
5406 static inline int
5407 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5408 break;
5409
5410 case RV_BDREL:
5411 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5412 + if (in_init_rx(mod, val))
5413 + val -= (uint64_t) mod->module_init_rx;
5414 + else if (in_init_rw(mod, val))
5415 + val -= (uint64_t) mod->module_init_rw;
5416 + else if (in_core_rx(mod, val))
5417 + val -= (uint64_t) mod->module_core_rx;
5418 + else if (in_core_rw(mod, val))
5419 + val -= (uint64_t) mod->module_core_rw;
5420 break;
5421
5422 case RV_LTV:
5423 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5424 * addresses have been selected...
5425 */
5426 uint64_t gp;
5427 - if (mod->core_size > MAX_LTOFF)
5428 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5429 /*
5430 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5431 * at the end of the module.
5432 */
5433 - gp = mod->core_size - MAX_LTOFF / 2;
5434 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5435 else
5436 - gp = mod->core_size / 2;
5437 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5438 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5439 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5440 mod->arch.gp = gp;
5441 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5442 }
5443 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5444 index c39c3cd..3c77738 100644
5445 --- a/arch/ia64/kernel/palinfo.c
5446 +++ b/arch/ia64/kernel/palinfo.c
5447 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5448 return NOTIFY_OK;
5449 }
5450
5451 -static struct notifier_block __refdata palinfo_cpu_notifier =
5452 +static struct notifier_block palinfo_cpu_notifier =
5453 {
5454 .notifier_call = palinfo_cpu_callback,
5455 .priority = 0,
5456 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5457 index 41e33f8..65180b2a 100644
5458 --- a/arch/ia64/kernel/sys_ia64.c
5459 +++ b/arch/ia64/kernel/sys_ia64.c
5460 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5461 unsigned long align_mask = 0;
5462 struct mm_struct *mm = current->mm;
5463 struct vm_unmapped_area_info info;
5464 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5465
5466 if (len > RGN_MAP_LIMIT)
5467 return -ENOMEM;
5468 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5469 if (REGION_NUMBER(addr) == RGN_HPAGE)
5470 addr = 0;
5471 #endif
5472 +
5473 +#ifdef CONFIG_PAX_RANDMMAP
5474 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5475 + addr = mm->free_area_cache;
5476 + else
5477 +#endif
5478 +
5479 if (!addr)
5480 addr = TASK_UNMAPPED_BASE;
5481
5482 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5483 info.high_limit = TASK_SIZE;
5484 info.align_mask = align_mask;
5485 info.align_offset = 0;
5486 + info.threadstack_offset = offset;
5487 return vm_unmapped_area(&info);
5488 }
5489
5490 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5491 index 84f8a52..7c76178 100644
5492 --- a/arch/ia64/kernel/vmlinux.lds.S
5493 +++ b/arch/ia64/kernel/vmlinux.lds.S
5494 @@ -192,7 +192,7 @@ SECTIONS {
5495 /* Per-cpu data: */
5496 . = ALIGN(PERCPU_PAGE_SIZE);
5497 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5498 - __phys_per_cpu_start = __per_cpu_load;
5499 + __phys_per_cpu_start = per_cpu_load;
5500 /*
5501 * ensure percpu data fits
5502 * into percpu page size
5503 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5504 index ba5ba7a..36e9d3a 100644
5505 --- a/arch/ia64/mm/fault.c
5506 +++ b/arch/ia64/mm/fault.c
5507 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5508 return pte_present(pte);
5509 }
5510
5511 +#ifdef CONFIG_PAX_PAGEEXEC
5512 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5513 +{
5514 + unsigned long i;
5515 +
5516 + printk(KERN_ERR "PAX: bytes at PC: ");
5517 + for (i = 0; i < 8; i++) {
5518 + unsigned int c;
5519 + if (get_user(c, (unsigned int *)pc+i))
5520 + printk(KERN_CONT "???????? ");
5521 + else
5522 + printk(KERN_CONT "%08x ", c);
5523 + }
5524 + printk("\n");
5525 +}
5526 +#endif
5527 +
5528 # define VM_READ_BIT 0
5529 # define VM_WRITE_BIT 1
5530 # define VM_EXEC_BIT 2
5531 @@ -151,8 +168,21 @@ retry:
5532 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5533 goto bad_area;
5534
5535 - if ((vma->vm_flags & mask) != mask)
5536 + if ((vma->vm_flags & mask) != mask) {
5537 +
5538 +#ifdef CONFIG_PAX_PAGEEXEC
5539 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5540 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5541 + goto bad_area;
5542 +
5543 + up_read(&mm->mmap_sem);
5544 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5545 + do_group_exit(SIGKILL);
5546 + }
5547 +#endif
5548 +
5549 goto bad_area;
5550 + }
5551
5552 /*
5553 * If for any reason at all we couldn't handle the fault, make
5554 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5555 index 76069c1..c2aa816 100644
5556 --- a/arch/ia64/mm/hugetlbpage.c
5557 +++ b/arch/ia64/mm/hugetlbpage.c
5558 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5559 unsigned long pgoff, unsigned long flags)
5560 {
5561 struct vm_unmapped_area_info info;
5562 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5563
5564 if (len > RGN_MAP_LIMIT)
5565 return -ENOMEM;
5566 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5567 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5568 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5569 info.align_offset = 0;
5570 + info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5575 index 6b33457..88b5124 100644
5576 --- a/arch/ia64/mm/init.c
5577 +++ b/arch/ia64/mm/init.c
5578 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5579 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5580 vma->vm_end = vma->vm_start + PAGE_SIZE;
5581 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5582 +
5583 +#ifdef CONFIG_PAX_PAGEEXEC
5584 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5585 + vma->vm_flags &= ~VM_EXEC;
5586 +
5587 +#ifdef CONFIG_PAX_MPROTECT
5588 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5589 + vma->vm_flags &= ~VM_MAYEXEC;
5590 +#endif
5591 +
5592 + }
5593 +#endif
5594 +
5595 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5596 down_write(&current->mm->mmap_sem);
5597 if (insert_vm_struct(current->mm, vma)) {
5598 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5599 gate_vma.vm_start = FIXADDR_USER_START;
5600 gate_vma.vm_end = FIXADDR_USER_END;
5601 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5602 - gate_vma.vm_page_prot = __P101;
5603 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5604
5605 return 0;
5606 }
5607 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5608 index 40b3ee9..8c2c112 100644
5609 --- a/arch/m32r/include/asm/cache.h
5610 +++ b/arch/m32r/include/asm/cache.h
5611 @@ -1,8 +1,10 @@
5612 #ifndef _ASM_M32R_CACHE_H
5613 #define _ASM_M32R_CACHE_H
5614
5615 +#include <linux/const.h>
5616 +
5617 /* L1 cache line size */
5618 #define L1_CACHE_SHIFT 4
5619 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5620 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5621
5622 #endif /* _ASM_M32R_CACHE_H */
5623 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5624 index 82abd15..d95ae5d 100644
5625 --- a/arch/m32r/lib/usercopy.c
5626 +++ b/arch/m32r/lib/usercopy.c
5627 @@ -14,6 +14,9 @@
5628 unsigned long
5629 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5630 {
5631 + if ((long)n < 0)
5632 + return n;
5633 +
5634 prefetch(from);
5635 if (access_ok(VERIFY_WRITE, to, n))
5636 __copy_user(to,from,n);
5637 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5638 unsigned long
5639 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5640 {
5641 + if ((long)n < 0)
5642 + return n;
5643 +
5644 prefetchw(to);
5645 if (access_ok(VERIFY_READ, from, n))
5646 __copy_user_zeroing(to,from,n);
5647 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5648 index 0395c51..5f26031 100644
5649 --- a/arch/m68k/include/asm/cache.h
5650 +++ b/arch/m68k/include/asm/cache.h
5651 @@ -4,9 +4,11 @@
5652 #ifndef __ARCH_M68K_CACHE_H
5653 #define __ARCH_M68K_CACHE_H
5654
5655 +#include <linux/const.h>
5656 +
5657 /* bytes per L1 cache line */
5658 #define L1_CACHE_SHIFT 4
5659 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5661
5662 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5663
5664 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5665 index c7591e8..ecef036 100644
5666 --- a/arch/metag/include/asm/barrier.h
5667 +++ b/arch/metag/include/asm/barrier.h
5668 @@ -89,7 +89,7 @@ static inline void fence(void)
5669 do { \
5670 compiletime_assert_atomic_type(*p); \
5671 smp_mb(); \
5672 - ACCESS_ONCE(*p) = (v); \
5673 + ACCESS_ONCE_RW(*p) = (v); \
5674 } while (0)
5675
5676 #define smp_load_acquire(p) \
5677 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5678 index 3c32075..ae0ae75 100644
5679 --- a/arch/metag/mm/hugetlbpage.c
5680 +++ b/arch/metag/mm/hugetlbpage.c
5681 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5682 info.high_limit = TASK_SIZE;
5683 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5684 info.align_offset = 0;
5685 + info.threadstack_offset = 0;
5686 return vm_unmapped_area(&info);
5687 }
5688
5689 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5690 index 4efe96a..60e8699 100644
5691 --- a/arch/microblaze/include/asm/cache.h
5692 +++ b/arch/microblaze/include/asm/cache.h
5693 @@ -13,11 +13,12 @@
5694 #ifndef _ASM_MICROBLAZE_CACHE_H
5695 #define _ASM_MICROBLAZE_CACHE_H
5696
5697 +#include <linux/const.h>
5698 #include <asm/registers.h>
5699
5700 #define L1_CACHE_SHIFT 5
5701 /* word-granular cache in microblaze */
5702 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5703 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5704
5705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5706
5707 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5708 index 9536ef9..9333776 100644
5709 --- a/arch/mips/Kconfig
5710 +++ b/arch/mips/Kconfig
5711 @@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5712
5713 config KEXEC
5714 bool "Kexec system call"
5715 + depends on !GRKERNSEC_KMEM
5716 help
5717 kexec is a system call that implements the ability to shutdown your
5718 current kernel, and to start another kernel. It is like a reboot
5719 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5720 index 02f2444..506969c 100644
5721 --- a/arch/mips/cavium-octeon/dma-octeon.c
5722 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5723 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5724 if (dma_release_from_coherent(dev, order, vaddr))
5725 return;
5726
5727 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5728 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5729 }
5730
5731 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5732 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5733 index 6dd6bfc..903b0d6 100644
5734 --- a/arch/mips/include/asm/atomic.h
5735 +++ b/arch/mips/include/asm/atomic.h
5736 @@ -21,15 +21,39 @@
5737 #include <asm/cmpxchg.h>
5738 #include <asm/war.h>
5739
5740 +#ifdef CONFIG_GENERIC_ATOMIC64
5741 +#include <asm-generic/atomic64.h>
5742 +#endif
5743 +
5744 #define ATOMIC_INIT(i) { (i) }
5745
5746 +#ifdef CONFIG_64BIT
5747 +#define _ASM_EXTABLE(from, to) \
5748 +" .section __ex_table,\"a\"\n" \
5749 +" .dword " #from ", " #to"\n" \
5750 +" .previous\n"
5751 +#else
5752 +#define _ASM_EXTABLE(from, to) \
5753 +" .section __ex_table,\"a\"\n" \
5754 +" .word " #from ", " #to"\n" \
5755 +" .previous\n"
5756 +#endif
5757 +
5758 /*
5759 * atomic_read - read atomic variable
5760 * @v: pointer of type atomic_t
5761 *
5762 * Atomically reads the value of @v.
5763 */
5764 -#define atomic_read(v) ACCESS_ONCE((v)->counter)
5765 +static inline int atomic_read(const atomic_t *v)
5766 +{
5767 + return ACCESS_ONCE(v->counter);
5768 +}
5769 +
5770 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5771 +{
5772 + return ACCESS_ONCE(v->counter);
5773 +}
5774
5775 /*
5776 * atomic_set - set atomic variable
5777 @@ -38,47 +62,77 @@
5778 *
5779 * Atomically sets the value of @v to @i.
5780 */
5781 -#define atomic_set(v, i) ((v)->counter = (i))
5782 +static inline void atomic_set(atomic_t *v, int i)
5783 +{
5784 + v->counter = i;
5785 +}
5786
5787 -#define ATOMIC_OP(op, c_op, asm_op) \
5788 -static __inline__ void atomic_##op(int i, atomic_t * v) \
5789 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5790 +{
5791 + v->counter = i;
5792 +}
5793 +
5794 +#ifdef CONFIG_PAX_REFCOUNT
5795 +#define __OVERFLOW_POST \
5796 + " b 4f \n" \
5797 + " .set noreorder \n" \
5798 + "3: b 5f \n" \
5799 + " move %0, %1 \n" \
5800 + " .set reorder \n"
5801 +#define __OVERFLOW_EXTABLE \
5802 + "3:\n" \
5803 + _ASM_EXTABLE(2b, 3b)
5804 +#else
5805 +#define __OVERFLOW_POST
5806 +#define __OVERFLOW_EXTABLE
5807 +#endif
5808 +
5809 +#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5810 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5811 { \
5812 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5813 int temp; \
5814 \
5815 __asm__ __volatile__( \
5816 - " .set arch=r4000 \n" \
5817 - "1: ll %0, %1 # atomic_" #op " \n" \
5818 - " " #asm_op " %0, %2 \n" \
5819 + " .set mips3 \n" \
5820 + "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5821 + "2: " #asm_op " %0, %2 \n" \
5822 " sc %0, %1 \n" \
5823 " beqzl %0, 1b \n" \
5824 + extable \
5825 " .set mips0 \n" \
5826 : "=&r" (temp), "+m" (v->counter) \
5827 : "Ir" (i)); \
5828 } else if (kernel_uses_llsc) { \
5829 int temp; \
5830 \
5831 - do { \
5832 - __asm__ __volatile__( \
5833 - " .set arch=r4000 \n" \
5834 - " ll %0, %1 # atomic_" #op "\n" \
5835 - " " #asm_op " %0, %2 \n" \
5836 - " sc %0, %1 \n" \
5837 - " .set mips0 \n" \
5838 - : "=&r" (temp), "+m" (v->counter) \
5839 - : "Ir" (i)); \
5840 - } while (unlikely(!temp)); \
5841 + __asm__ __volatile__( \
5842 + " .set mips3 \n" \
5843 + " ll %0, %1 # atomic_" #op #suffix "\n" \
5844 + "2: " #asm_op " %0, %2 \n" \
5845 + " sc %0, %1 \n" \
5846 + " beqz %0, 1b \n" \
5847 + extable \
5848 + " .set mips0 \n" \
5849 + : "=&r" (temp), "+m" (v->counter) \
5850 + : "Ir" (i)); \
5851 } else { \
5852 unsigned long flags; \
5853 \
5854 raw_local_irq_save(flags); \
5855 - v->counter c_op i; \
5856 + __asm__ __volatile__( \
5857 + "2: " #asm_op " %0, %1 \n" \
5858 + extable \
5859 + : "+r" (v->counter) : "Ir" (i)); \
5860 raw_local_irq_restore(flags); \
5861 } \
5862 } \
5863
5864 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5865 -static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5866 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5867 + __ATOMIC_OP(op, _unchecked, asm_op)
5868 +
5869 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5870 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5871 { \
5872 int result; \
5873 \
5874 @@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5875 int temp; \
5876 \
5877 __asm__ __volatile__( \
5878 - " .set arch=r4000 \n" \
5879 - "1: ll %1, %2 # atomic_" #op "_return \n" \
5880 - " " #asm_op " %0, %1, %3 \n" \
5881 + " .set mips3 \n" \
5882 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5883 + "2: " #asm_op " %0, %1, %3 \n" \
5884 " sc %0, %2 \n" \
5885 " beqzl %0, 1b \n" \
5886 - " " #asm_op " %0, %1, %3 \n" \
5887 + post_op \
5888 + extable \
5889 + "4: " #asm_op " %0, %1, %3 \n" \
5890 + "5: \n" \
5891 " .set mips0 \n" \
5892 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5893 : "Ir" (i)); \
5894 } else if (kernel_uses_llsc) { \
5895 int temp; \
5896 \
5897 - do { \
5898 - __asm__ __volatile__( \
5899 - " .set arch=r4000 \n" \
5900 - " ll %1, %2 # atomic_" #op "_return \n" \
5901 - " " #asm_op " %0, %1, %3 \n" \
5902 - " sc %0, %2 \n" \
5903 - " .set mips0 \n" \
5904 - : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5905 - : "Ir" (i)); \
5906 - } while (unlikely(!result)); \
5907 + __asm__ __volatile__( \
5908 + " .set mips3 \n" \
5909 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5910 + "2: " #asm_op " %0, %1, %3 \n" \
5911 + " sc %0, %2 \n" \
5912 + " beqz %0, 1b \n" \
5913 + post_op \
5914 + extable \
5915 + "4: " #asm_op " %0, %1, %3 \n" \
5916 + "5: \n" \
5917 + " .set mips0 \n" \
5918 + : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5919 + : "Ir" (i)); \
5920 \
5921 result = temp; result c_op i; \
5922 } else { \
5923 unsigned long flags; \
5924 \
5925 raw_local_irq_save(flags); \
5926 - result = v->counter; \
5927 - result c_op i; \
5928 - v->counter = result; \
5929 + __asm__ __volatile__( \
5930 + " lw %0, %1 \n" \
5931 + "2: " #asm_op " %0, %1, %2 \n" \
5932 + " sw %0, %1 \n" \
5933 + "3: \n" \
5934 + extable \
5935 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5936 raw_local_irq_restore(flags); \
5937 } \
5938 \
5939 @@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5940 return result; \
5941 }
5942
5943 -#define ATOMIC_OPS(op, c_op, asm_op) \
5944 - ATOMIC_OP(op, c_op, asm_op) \
5945 - ATOMIC_OP_RETURN(op, c_op, asm_op)
5946 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5947 + __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5948
5949 -ATOMIC_OPS(add, +=, addu)
5950 -ATOMIC_OPS(sub, -=, subu)
5951 +#define ATOMIC_OPS(op, asm_op) \
5952 + ATOMIC_OP(op, asm_op) \
5953 + ATOMIC_OP_RETURN(op, asm_op)
5954 +
5955 +ATOMIC_OPS(add, add)
5956 +ATOMIC_OPS(sub, sub)
5957
5958 #undef ATOMIC_OPS
5959 #undef ATOMIC_OP_RETURN
5960 +#undef __ATOMIC_OP_RETURN
5961 #undef ATOMIC_OP
5962 +#undef __ATOMIC_OP
5963
5964 /*
5965 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5966 @@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5967 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5968 * The function returns the old value of @v minus @i.
5969 */
5970 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5971 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5972 {
5973 int result;
5974
5975 @@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5976 return result;
5977 }
5978
5979 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5980 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5981 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5982 +{
5983 + return cmpxchg(&v->counter, old, new);
5984 +}
5985 +
5986 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5987 + int new)
5988 +{
5989 + return cmpxchg(&(v->counter), old, new);
5990 +}
5991 +
5992 +static inline int atomic_xchg(atomic_t *v, int new)
5993 +{
5994 + return xchg(&v->counter, new);
5995 +}
5996 +
5997 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5998 +{
5999 + return xchg(&(v->counter), new);
6000 +}
6001
6002 /**
6003 * __atomic_add_unless - add unless the number is a given value
6004 @@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005
6006 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6007 #define atomic_inc_return(v) atomic_add_return(1, (v))
6008 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6009 +{
6010 + return atomic_add_return_unchecked(1, v);
6011 +}
6012
6013 /*
6014 * atomic_sub_and_test - subtract value from variable and test result
6015 @@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * other cases.
6017 */
6018 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6019 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6020 +{
6021 + return atomic_add_return_unchecked(1, v) == 0;
6022 +}
6023
6024 /*
6025 * atomic_dec_and_test - decrement by 1 and test
6026 @@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * Atomically increments @v by 1.
6028 */
6029 #define atomic_inc(v) atomic_add(1, (v))
6030 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6031 +{
6032 + atomic_add_unchecked(1, v);
6033 +}
6034
6035 /*
6036 * atomic_dec - decrement and test
6037 @@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6038 * Atomically decrements @v by 1.
6039 */
6040 #define atomic_dec(v) atomic_sub(1, (v))
6041 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6042 +{
6043 + atomic_sub_unchecked(1, v);
6044 +}
6045
6046 /*
6047 * atomic_add_negative - add and test if negative
6048 @@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6049 * @v: pointer of type atomic64_t
6050 *
6051 */
6052 -#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6053 +static inline long atomic64_read(const atomic64_t *v)
6054 +{
6055 + return ACCESS_ONCE(v->counter);
6056 +}
6057 +
6058 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6059 +{
6060 + return ACCESS_ONCE(v->counter);
6061 +}
6062
6063 /*
6064 * atomic64_set - set atomic variable
6065 * @v: pointer of type atomic64_t
6066 * @i: required value
6067 */
6068 -#define atomic64_set(v, i) ((v)->counter = (i))
6069 +static inline void atomic64_set(atomic64_t *v, long i)
6070 +{
6071 + v->counter = i;
6072 +}
6073
6074 -#define ATOMIC64_OP(op, c_op, asm_op) \
6075 -static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6076 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6077 +{
6078 + v->counter = i;
6079 +}
6080 +
6081 +#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6082 +static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6083 { \
6084 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6085 long temp; \
6086 \
6087 __asm__ __volatile__( \
6088 - " .set arch=r4000 \n" \
6089 - "1: lld %0, %1 # atomic64_" #op " \n" \
6090 - " " #asm_op " %0, %2 \n" \
6091 + " .set mips3 \n" \
6092 + "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6093 + "2: " #asm_op " %0, %2 \n" \
6094 " scd %0, %1 \n" \
6095 " beqzl %0, 1b \n" \
6096 + extable \
6097 " .set mips0 \n" \
6098 : "=&r" (temp), "+m" (v->counter) \
6099 : "Ir" (i)); \
6100 } else if (kernel_uses_llsc) { \
6101 long temp; \
6102 \
6103 - do { \
6104 - __asm__ __volatile__( \
6105 - " .set arch=r4000 \n" \
6106 - " lld %0, %1 # atomic64_" #op "\n" \
6107 - " " #asm_op " %0, %2 \n" \
6108 - " scd %0, %1 \n" \
6109 - " .set mips0 \n" \
6110 - : "=&r" (temp), "+m" (v->counter) \
6111 - : "Ir" (i)); \
6112 - } while (unlikely(!temp)); \
6113 + __asm__ __volatile__( \
6114 + " .set mips3 \n" \
6115 + " lld %0, %1 # atomic64_" #op #suffix "\n" \
6116 + "2: " #asm_op " %0, %2 \n" \
6117 + " scd %0, %1 \n" \
6118 + " beqz %0, 1b \n" \
6119 + extable \
6120 + " .set mips0 \n" \
6121 + : "=&r" (temp), "+m" (v->counter) \
6122 + : "Ir" (i)); \
6123 } else { \
6124 unsigned long flags; \
6125 \
6126 raw_local_irq_save(flags); \
6127 - v->counter c_op i; \
6128 + __asm__ __volatile__( \
6129 + "2: " #asm_op " %0, %1 \n" \
6130 + extable \
6131 + : "+r" (v->counter) : "Ir" (i)); \
6132 raw_local_irq_restore(flags); \
6133 } \
6134 } \
6135
6136 -#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6137 -static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6138 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6139 + __ATOMIC64_OP(op, _unchecked, asm_op)
6140 +
6141 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6142 +static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6143 { \
6144 long result; \
6145 \
6146 @@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6147 long temp; \
6148 \
6149 __asm__ __volatile__( \
6150 - " .set arch=r4000 \n" \
6151 + " .set mips3 \n" \
6152 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6153 - " " #asm_op " %0, %1, %3 \n" \
6154 + "2: " #asm_op " %0, %1, %3 \n" \
6155 " scd %0, %2 \n" \
6156 " beqzl %0, 1b \n" \
6157 - " " #asm_op " %0, %1, %3 \n" \
6158 + post_op \
6159 + extable \
6160 + "4: " #asm_op " %0, %1, %3 \n" \
6161 + "5: \n" \
6162 " .set mips0 \n" \
6163 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6164 : "Ir" (i)); \
6165 } else if (kernel_uses_llsc) { \
6166 long temp; \
6167 \
6168 - do { \
6169 - __asm__ __volatile__( \
6170 - " .set arch=r4000 \n" \
6171 - " lld %1, %2 # atomic64_" #op "_return\n" \
6172 - " " #asm_op " %0, %1, %3 \n" \
6173 - " scd %0, %2 \n" \
6174 - " .set mips0 \n" \
6175 - : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6176 - : "Ir" (i), "m" (v->counter) \
6177 - : "memory"); \
6178 - } while (unlikely(!result)); \
6179 + __asm__ __volatile__( \
6180 + " .set mips3 \n" \
6181 + "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6182 + "2: " #asm_op " %0, %1, %3 \n" \
6183 + " scd %0, %2 \n" \
6184 + " beqz %0, 1b \n" \
6185 + post_op \
6186 + extable \
6187 + "4: " #asm_op " %0, %1, %3 \n" \
6188 + "5: \n" \
6189 + " .set mips0 \n" \
6190 + : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6191 + : "Ir" (i), "m" (v->counter) \
6192 + : "memory"); \
6193 \
6194 result = temp; result c_op i; \
6195 } else { \
6196 unsigned long flags; \
6197 \
6198 raw_local_irq_save(flags); \
6199 - result = v->counter; \
6200 - result c_op i; \
6201 - v->counter = result; \
6202 + __asm__ __volatile__( \
6203 + " ld %0, %1 \n" \
6204 + "2: " #asm_op " %0, %1, %2 \n" \
6205 + " sd %0, %1 \n" \
6206 + "3: \n" \
6207 + extable \
6208 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6209 raw_local_irq_restore(flags); \
6210 } \
6211 \
6212 @@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6213 return result; \
6214 }
6215
6216 -#define ATOMIC64_OPS(op, c_op, asm_op) \
6217 - ATOMIC64_OP(op, c_op, asm_op) \
6218 - ATOMIC64_OP_RETURN(op, c_op, asm_op)
6219 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6220 + __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6221
6222 -ATOMIC64_OPS(add, +=, daddu)
6223 -ATOMIC64_OPS(sub, -=, dsubu)
6224 +#define ATOMIC64_OPS(op, asm_op) \
6225 + ATOMIC64_OP(op, asm_op) \
6226 + ATOMIC64_OP_RETURN(op, asm_op)
6227 +
6228 +ATOMIC64_OPS(add, dadd)
6229 +ATOMIC64_OPS(sub, dsub)
6230
6231 #undef ATOMIC64_OPS
6232 #undef ATOMIC64_OP_RETURN
6233 +#undef __ATOMIC64_OP_RETURN
6234 #undef ATOMIC64_OP
6235 +#undef __ATOMIC64_OP
6236 +#undef __OVERFLOW_EXTABLE
6237 +#undef __OVERFLOW_POST
6238
6239 /*
6240 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6241 @@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6242 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6243 * The function returns the old value of @v minus @i.
6244 */
6245 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6246 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6247 {
6248 long result;
6249
6250 @@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6251 return result;
6252 }
6253
6254 -#define atomic64_cmpxchg(v, o, n) \
6255 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6256 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6257 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6258 +{
6259 + return cmpxchg(&v->counter, old, new);
6260 +}
6261 +
6262 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6263 + long new)
6264 +{
6265 + return cmpxchg(&(v->counter), old, new);
6266 +}
6267 +
6268 +static inline long atomic64_xchg(atomic64_t *v, long new)
6269 +{
6270 + return xchg(&v->counter, new);
6271 +}
6272 +
6273 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6274 +{
6275 + return xchg(&(v->counter), new);
6276 +}
6277
6278 /**
6279 * atomic64_add_unless - add unless the number is a given value
6280 @@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6281
6282 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6283 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6284 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6285
6286 /*
6287 * atomic64_sub_and_test - subtract value from variable and test result
6288 @@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6289 * other cases.
6290 */
6291 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6292 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6293
6294 /*
6295 * atomic64_dec_and_test - decrement by 1 and test
6296 @@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6297 * Atomically increments @v by 1.
6298 */
6299 #define atomic64_inc(v) atomic64_add(1, (v))
6300 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6301
6302 /*
6303 * atomic64_dec - decrement and test
6304 @@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6305 * Atomically decrements @v by 1.
6306 */
6307 #define atomic64_dec(v) atomic64_sub(1, (v))
6308 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6309
6310 /*
6311 * atomic64_add_negative - add and test if negative
6312 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6313 index d0101dd..266982c 100644
6314 --- a/arch/mips/include/asm/barrier.h
6315 +++ b/arch/mips/include/asm/barrier.h
6316 @@ -184,7 +184,7 @@
6317 do { \
6318 compiletime_assert_atomic_type(*p); \
6319 smp_mb(); \
6320 - ACCESS_ONCE(*p) = (v); \
6321 + ACCESS_ONCE_RW(*p) = (v); \
6322 } while (0)
6323
6324 #define smp_load_acquire(p) \
6325 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6326 index b4db69f..8f3b093 100644
6327 --- a/arch/mips/include/asm/cache.h
6328 +++ b/arch/mips/include/asm/cache.h
6329 @@ -9,10 +9,11 @@
6330 #ifndef _ASM_CACHE_H
6331 #define _ASM_CACHE_H
6332
6333 +#include <linux/const.h>
6334 #include <kmalloc.h>
6335
6336 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6337 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6338 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6339
6340 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6341 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6342 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6343 index 1d38fe0..9beabc9 100644
6344 --- a/arch/mips/include/asm/elf.h
6345 +++ b/arch/mips/include/asm/elf.h
6346 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6347 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6348 #endif
6349
6350 +#ifdef CONFIG_PAX_ASLR
6351 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6352 +
6353 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6354 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6355 +#endif
6356 +
6357 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6358 struct linux_binprm;
6359 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6360 int uses_interp);
6361
6362 -struct mm_struct;
6363 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6364 -#define arch_randomize_brk arch_randomize_brk
6365 -
6366 #endif /* _ASM_ELF_H */
6367 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6368 index c1f6afa..38cc6e9 100644
6369 --- a/arch/mips/include/asm/exec.h
6370 +++ b/arch/mips/include/asm/exec.h
6371 @@ -12,6 +12,6 @@
6372 #ifndef _ASM_EXEC_H
6373 #define _ASM_EXEC_H
6374
6375 -extern unsigned long arch_align_stack(unsigned long sp);
6376 +#define arch_align_stack(x) ((x) & ~0xfUL)
6377
6378 #endif /* _ASM_EXEC_H */
6379 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6380 index 9e8ef59..1139d6b 100644
6381 --- a/arch/mips/include/asm/hw_irq.h
6382 +++ b/arch/mips/include/asm/hw_irq.h
6383 @@ -10,7 +10,7 @@
6384
6385 #include <linux/atomic.h>
6386
6387 -extern atomic_t irq_err_count;
6388 +extern atomic_unchecked_t irq_err_count;
6389
6390 /*
6391 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6392 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6393 index 46dfc3c..a16b13a 100644
6394 --- a/arch/mips/include/asm/local.h
6395 +++ b/arch/mips/include/asm/local.h
6396 @@ -12,15 +12,25 @@ typedef struct
6397 atomic_long_t a;
6398 } local_t;
6399
6400 +typedef struct {
6401 + atomic_long_unchecked_t a;
6402 +} local_unchecked_t;
6403 +
6404 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6405
6406 #define local_read(l) atomic_long_read(&(l)->a)
6407 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6408 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6409 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6410
6411 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6412 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6413 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6414 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6415 #define local_inc(l) atomic_long_inc(&(l)->a)
6416 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6417 #define local_dec(l) atomic_long_dec(&(l)->a)
6418 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6419
6420 /*
6421 * Same as above, but return the result value
6422 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6423 return result;
6424 }
6425
6426 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6427 +{
6428 + unsigned long result;
6429 +
6430 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6431 + unsigned long temp;
6432 +
6433 + __asm__ __volatile__(
6434 + " .set mips3 \n"
6435 + "1:" __LL "%1, %2 # local_add_return \n"
6436 + " addu %0, %1, %3 \n"
6437 + __SC "%0, %2 \n"
6438 + " beqzl %0, 1b \n"
6439 + " addu %0, %1, %3 \n"
6440 + " .set mips0 \n"
6441 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6442 + : "Ir" (i), "m" (l->a.counter)
6443 + : "memory");
6444 + } else if (kernel_uses_llsc) {
6445 + unsigned long temp;
6446 +
6447 + __asm__ __volatile__(
6448 + " .set mips3 \n"
6449 + "1:" __LL "%1, %2 # local_add_return \n"
6450 + " addu %0, %1, %3 \n"
6451 + __SC "%0, %2 \n"
6452 + " beqz %0, 1b \n"
6453 + " addu %0, %1, %3 \n"
6454 + " .set mips0 \n"
6455 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6456 + : "Ir" (i), "m" (l->a.counter)
6457 + : "memory");
6458 + } else {
6459 + unsigned long flags;
6460 +
6461 + local_irq_save(flags);
6462 + result = l->a.counter;
6463 + result += i;
6464 + l->a.counter = result;
6465 + local_irq_restore(flags);
6466 + }
6467 +
6468 + return result;
6469 +}
6470 +
6471 static __inline__ long local_sub_return(long i, local_t * l)
6472 {
6473 unsigned long result;
6474 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6475
6476 #define local_cmpxchg(l, o, n) \
6477 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6478 +#define local_cmpxchg_unchecked(l, o, n) \
6479 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6480 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6481
6482 /**
6483 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6484 index 3be8180..c4798d5 100644
6485 --- a/arch/mips/include/asm/page.h
6486 +++ b/arch/mips/include/asm/page.h
6487 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6488 #ifdef CONFIG_CPU_MIPS32
6489 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6490 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6491 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6492 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6493 #else
6494 typedef struct { unsigned long long pte; } pte_t;
6495 #define pte_val(x) ((x).pte)
6496 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6497 index b336037..5b874cc 100644
6498 --- a/arch/mips/include/asm/pgalloc.h
6499 +++ b/arch/mips/include/asm/pgalloc.h
6500 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6501 {
6502 set_pud(pud, __pud((unsigned long)pmd));
6503 }
6504 +
6505 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6506 +{
6507 + pud_populate(mm, pud, pmd);
6508 +}
6509 #endif
6510
6511 /*
6512 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6513 index d6d1928..ce4f822 100644
6514 --- a/arch/mips/include/asm/pgtable.h
6515 +++ b/arch/mips/include/asm/pgtable.h
6516 @@ -20,6 +20,9 @@
6517 #include <asm/io.h>
6518 #include <asm/pgtable-bits.h>
6519
6520 +#define ktla_ktva(addr) (addr)
6521 +#define ktva_ktla(addr) (addr)
6522 +
6523 struct mm_struct;
6524 struct vm_area_struct;
6525
6526 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6527 index 7de8658..c109224 100644
6528 --- a/arch/mips/include/asm/thread_info.h
6529 +++ b/arch/mips/include/asm/thread_info.h
6530 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6531 #define TIF_SECCOMP 4 /* secure computing */
6532 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6533 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6534 +/* li takes a 32bit immediate */
6535 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6536 +
6537 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6538 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6539 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6540 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6541 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6542 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6543 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6544 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6545
6546 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6547 _TIF_SYSCALL_AUDIT | \
6548 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6549 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6550 + _TIF_GRSEC_SETXID)
6551
6552 /* work to do in syscall_trace_leave() */
6553 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6554 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6555 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6556
6557 /* work to do on interrupt/exception return */
6558 #define _TIF_WORK_MASK \
6559 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6560 /* work to do on any return to u-space */
6561 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6562 _TIF_WORK_SYSCALL_EXIT | \
6563 - _TIF_SYSCALL_TRACEPOINT)
6564 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6565
6566 /*
6567 * We stash processor id into a COP0 register to retrieve it fast
6568 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6569 index 22a5624..7c96295 100644
6570 --- a/arch/mips/include/asm/uaccess.h
6571 +++ b/arch/mips/include/asm/uaccess.h
6572 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6573 __ok == 0; \
6574 })
6575
6576 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6577 #define access_ok(type, addr, size) \
6578 likely(__access_ok((addr), (size), __access_mask))
6579
6580 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6581 index 1188e00..41cf144 100644
6582 --- a/arch/mips/kernel/binfmt_elfn32.c
6583 +++ b/arch/mips/kernel/binfmt_elfn32.c
6584 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6585 #undef ELF_ET_DYN_BASE
6586 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6587
6588 +#ifdef CONFIG_PAX_ASLR
6589 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6590 +
6591 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6592 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6593 +#endif
6594 +
6595 #include <asm/processor.h>
6596 #include <linux/module.h>
6597 #include <linux/elfcore.h>
6598 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6599 index 9287678..f870e47 100644
6600 --- a/arch/mips/kernel/binfmt_elfo32.c
6601 +++ b/arch/mips/kernel/binfmt_elfo32.c
6602 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6603 #undef ELF_ET_DYN_BASE
6604 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6605
6606 +#ifdef CONFIG_PAX_ASLR
6607 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6608 +
6609 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6610 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6611 +#endif
6612 +
6613 #include <asm/processor.h>
6614
6615 #include <linux/module.h>
6616 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6617 index 50b3648..c2f3cec 100644
6618 --- a/arch/mips/kernel/i8259.c
6619 +++ b/arch/mips/kernel/i8259.c
6620 @@ -201,7 +201,7 @@ spurious_8259A_irq:
6621 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6622 spurious_irq_mask |= irqmask;
6623 }
6624 - atomic_inc(&irq_err_count);
6625 + atomic_inc_unchecked(&irq_err_count);
6626 /*
6627 * Theoretically we do not have to handle this IRQ,
6628 * but in Linux this does not cause problems and is
6629 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6630 index 44a1f79..2bd6aa3 100644
6631 --- a/arch/mips/kernel/irq-gt641xx.c
6632 +++ b/arch/mips/kernel/irq-gt641xx.c
6633 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6634 }
6635 }
6636
6637 - atomic_inc(&irq_err_count);
6638 + atomic_inc_unchecked(&irq_err_count);
6639 }
6640
6641 void __init gt641xx_irq_init(void)
6642 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6643 index d2bfbc2..a8eacd2 100644
6644 --- a/arch/mips/kernel/irq.c
6645 +++ b/arch/mips/kernel/irq.c
6646 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6647 printk("unexpected IRQ # %d\n", irq);
6648 }
6649
6650 -atomic_t irq_err_count;
6651 +atomic_unchecked_t irq_err_count;
6652
6653 int arch_show_interrupts(struct seq_file *p, int prec)
6654 {
6655 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6656 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6657 return 0;
6658 }
6659
6660 asmlinkage void spurious_interrupt(void)
6661 {
6662 - atomic_inc(&irq_err_count);
6663 + atomic_inc_unchecked(&irq_err_count);
6664 }
6665
6666 void __init init_IRQ(void)
6667 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
6668 #endif
6669 }
6670
6671 +
6672 #ifdef DEBUG_STACKOVERFLOW
6673 +extern void gr_handle_kernel_exploit(void);
6674 +
6675 static inline void check_stack_overflow(void)
6676 {
6677 unsigned long sp;
6678 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6679 printk("do_IRQ: stack overflow: %ld\n",
6680 sp - sizeof(struct thread_info));
6681 dump_stack();
6682 + gr_handle_kernel_exploit();
6683 }
6684 }
6685 #else
6686 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6687 index 0614717..002fa43 100644
6688 --- a/arch/mips/kernel/pm-cps.c
6689 +++ b/arch/mips/kernel/pm-cps.c
6690 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6691 nc_core_ready_count = nc_addr;
6692
6693 /* Ensure ready_count is zero-initialised before the assembly runs */
6694 - ACCESS_ONCE(*nc_core_ready_count) = 0;
6695 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6696 coupled_barrier(&per_cpu(pm_barrier, core), online);
6697
6698 /* Run the generated entry code */
6699 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6700 index 636b074..8fbb91f 100644
6701 --- a/arch/mips/kernel/process.c
6702 +++ b/arch/mips/kernel/process.c
6703 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6704 out:
6705 return pc;
6706 }
6707 -
6708 -/*
6709 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6710 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6711 - */
6712 -unsigned long arch_align_stack(unsigned long sp)
6713 -{
6714 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6715 - sp -= get_random_int() & ~PAGE_MASK;
6716 -
6717 - return sp & ALMASK;
6718 -}
6719 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6720 index 9d1487d..10c5da5 100644
6721 --- a/arch/mips/kernel/ptrace.c
6722 +++ b/arch/mips/kernel/ptrace.c
6723 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6724 return ret;
6725 }
6726
6727 +#ifdef CONFIG_GRKERNSEC_SETXID
6728 +extern void gr_delayed_cred_worker(void);
6729 +#endif
6730 +
6731 /*
6732 * Notification of system call entry/exit
6733 * - triggered by current->work.syscall_trace
6734 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6735 tracehook_report_syscall_entry(regs))
6736 ret = -1;
6737
6738 +#ifdef CONFIG_GRKERNSEC_SETXID
6739 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6740 + gr_delayed_cred_worker();
6741 +#endif
6742 +
6743 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6744 trace_sys_enter(regs, regs->regs[2]);
6745
6746 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6747 index 07fc524..b9d7f28 100644
6748 --- a/arch/mips/kernel/reset.c
6749 +++ b/arch/mips/kernel/reset.c
6750 @@ -13,6 +13,7 @@
6751 #include <linux/reboot.h>
6752
6753 #include <asm/reboot.h>
6754 +#include <asm/bug.h>
6755
6756 /*
6757 * Urgs ... Too many MIPS machines to handle this in a generic way.
6758 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6759 {
6760 if (_machine_restart)
6761 _machine_restart(command);
6762 + BUG();
6763 }
6764
6765 void machine_halt(void)
6766 {
6767 if (_machine_halt)
6768 _machine_halt();
6769 + BUG();
6770 }
6771
6772 void machine_power_off(void)
6773 {
6774 if (pm_power_off)
6775 pm_power_off();
6776 + BUG();
6777 }
6778 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6779 index 2242bdd..b284048 100644
6780 --- a/arch/mips/kernel/sync-r4k.c
6781 +++ b/arch/mips/kernel/sync-r4k.c
6782 @@ -18,8 +18,8 @@
6783 #include <asm/mipsregs.h>
6784
6785 static atomic_t count_start_flag = ATOMIC_INIT(0);
6786 -static atomic_t count_count_start = ATOMIC_INIT(0);
6787 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6788 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6789 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6790 static atomic_t count_reference = ATOMIC_INIT(0);
6791
6792 #define COUNTON 100
6793 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6794
6795 for (i = 0; i < NR_LOOPS; i++) {
6796 /* slaves loop on '!= 2' */
6797 - while (atomic_read(&count_count_start) != 1)
6798 + while (atomic_read_unchecked(&count_count_start) != 1)
6799 mb();
6800 - atomic_set(&count_count_stop, 0);
6801 + atomic_set_unchecked(&count_count_stop, 0);
6802 smp_wmb();
6803
6804 /* this lets the slaves write their count register */
6805 - atomic_inc(&count_count_start);
6806 + atomic_inc_unchecked(&count_count_start);
6807
6808 /*
6809 * Everyone initialises count in the last loop:
6810 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6811 /*
6812 * Wait for all slaves to leave the synchronization point:
6813 */
6814 - while (atomic_read(&count_count_stop) != 1)
6815 + while (atomic_read_unchecked(&count_count_stop) != 1)
6816 mb();
6817 - atomic_set(&count_count_start, 0);
6818 + atomic_set_unchecked(&count_count_start, 0);
6819 smp_wmb();
6820 - atomic_inc(&count_count_stop);
6821 + atomic_inc_unchecked(&count_count_stop);
6822 }
6823 /* Arrange for an interrupt in a short while */
6824 write_c0_compare(read_c0_count() + COUNTON);
6825 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6826 initcount = atomic_read(&count_reference);
6827
6828 for (i = 0; i < NR_LOOPS; i++) {
6829 - atomic_inc(&count_count_start);
6830 - while (atomic_read(&count_count_start) != 2)
6831 + atomic_inc_unchecked(&count_count_start);
6832 + while (atomic_read_unchecked(&count_count_start) != 2)
6833 mb();
6834
6835 /*
6836 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6837 if (i == NR_LOOPS-1)
6838 write_c0_count(initcount);
6839
6840 - atomic_inc(&count_count_stop);
6841 - while (atomic_read(&count_count_stop) != 2)
6842 + atomic_inc_unchecked(&count_count_stop);
6843 + while (atomic_read_unchecked(&count_count_stop) != 2)
6844 mb();
6845 }
6846 /* Arrange for an interrupt in a short while */
6847 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6848 index d255a2a..916271c 100644
6849 --- a/arch/mips/kernel/traps.c
6850 +++ b/arch/mips/kernel/traps.c
6851 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6852 siginfo_t info;
6853
6854 prev_state = exception_enter();
6855 - die_if_kernel("Integer overflow", regs);
6856 + if (unlikely(!user_mode(regs))) {
6857 +
6858 +#ifdef CONFIG_PAX_REFCOUNT
6859 + if (fixup_exception(regs)) {
6860 + pax_report_refcount_overflow(regs);
6861 + exception_exit(prev_state);
6862 + return;
6863 + }
6864 +#endif
6865 +
6866 + die("Integer overflow", regs);
6867 + }
6868
6869 info.si_code = FPE_INTOVF;
6870 info.si_signo = SIGFPE;
6871 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6872 index e3b21e5..ea5ff7c 100644
6873 --- a/arch/mips/kvm/mips.c
6874 +++ b/arch/mips/kvm/mips.c
6875 @@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6876 return r;
6877 }
6878
6879 -int kvm_arch_init(void *opaque)
6880 +int kvm_arch_init(const void *opaque)
6881 {
6882 if (kvm_mips_callbacks) {
6883 kvm_err("kvm: module already exists\n");
6884 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6885 index 70ab5d6..62940fe 100644
6886 --- a/arch/mips/mm/fault.c
6887 +++ b/arch/mips/mm/fault.c
6888 @@ -28,6 +28,23 @@
6889 #include <asm/highmem.h> /* For VMALLOC_END */
6890 #include <linux/kdebug.h>
6891
6892 +#ifdef CONFIG_PAX_PAGEEXEC
6893 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6894 +{
6895 + unsigned long i;
6896 +
6897 + printk(KERN_ERR "PAX: bytes at PC: ");
6898 + for (i = 0; i < 5; i++) {
6899 + unsigned int c;
6900 + if (get_user(c, (unsigned int *)pc+i))
6901 + printk(KERN_CONT "???????? ");
6902 + else
6903 + printk(KERN_CONT "%08x ", c);
6904 + }
6905 + printk("\n");
6906 +}
6907 +#endif
6908 +
6909 /*
6910 * This routine handles page faults. It determines the address,
6911 * and the problem, and then passes it off to one of the appropriate
6912 @@ -201,6 +218,14 @@ bad_area:
6913 bad_area_nosemaphore:
6914 /* User mode accesses just cause a SIGSEGV */
6915 if (user_mode(regs)) {
6916 +
6917 +#ifdef CONFIG_PAX_PAGEEXEC
6918 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6919 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6920 + do_group_exit(SIGKILL);
6921 + }
6922 +#endif
6923 +
6924 tsk->thread.cp0_badvaddr = address;
6925 tsk->thread.error_code = write;
6926 #if 0
6927 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6928 index f1baadd..5472dca 100644
6929 --- a/arch/mips/mm/mmap.c
6930 +++ b/arch/mips/mm/mmap.c
6931 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6932 struct vm_area_struct *vma;
6933 unsigned long addr = addr0;
6934 int do_color_align;
6935 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6936 struct vm_unmapped_area_info info;
6937
6938 if (unlikely(len > TASK_SIZE))
6939 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6940 do_color_align = 1;
6941
6942 /* requesting a specific address */
6943 +
6944 +#ifdef CONFIG_PAX_RANDMMAP
6945 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6946 +#endif
6947 +
6948 if (addr) {
6949 if (do_color_align)
6950 addr = COLOUR_ALIGN(addr, pgoff);
6951 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6952 addr = PAGE_ALIGN(addr);
6953
6954 vma = find_vma(mm, addr);
6955 - if (TASK_SIZE - len >= addr &&
6956 - (!vma || addr + len <= vma->vm_start))
6957 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6958 return addr;
6959 }
6960
6961 info.length = len;
6962 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6963 info.align_offset = pgoff << PAGE_SHIFT;
6964 + info.threadstack_offset = offset;
6965
6966 if (dir == DOWN) {
6967 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6968 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6969 {
6970 unsigned long random_factor = 0UL;
6971
6972 +#ifdef CONFIG_PAX_RANDMMAP
6973 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6974 +#endif
6975 +
6976 if (current->flags & PF_RANDOMIZE) {
6977 random_factor = get_random_int();
6978 random_factor = random_factor << PAGE_SHIFT;
6979 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6980
6981 if (mmap_is_legacy()) {
6982 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6983 +
6984 +#ifdef CONFIG_PAX_RANDMMAP
6985 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6986 + mm->mmap_base += mm->delta_mmap;
6987 +#endif
6988 +
6989 mm->get_unmapped_area = arch_get_unmapped_area;
6990 } else {
6991 mm->mmap_base = mmap_base(random_factor);
6992 +
6993 +#ifdef CONFIG_PAX_RANDMMAP
6994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6995 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6996 +#endif
6997 +
6998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6999 }
7000 }
7001
7002 -static inline unsigned long brk_rnd(void)
7003 -{
7004 - unsigned long rnd = get_random_int();
7005 -
7006 - rnd = rnd << PAGE_SHIFT;
7007 - /* 8MB for 32bit, 256MB for 64bit */
7008 - if (TASK_IS_32BIT_ADDR)
7009 - rnd = rnd & 0x7ffffful;
7010 - else
7011 - rnd = rnd & 0xffffffful;
7012 -
7013 - return rnd;
7014 -}
7015 -
7016 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7017 -{
7018 - unsigned long base = mm->brk;
7019 - unsigned long ret;
7020 -
7021 - ret = PAGE_ALIGN(base + brk_rnd());
7022 -
7023 - if (ret < mm->brk)
7024 - return mm->brk;
7025 -
7026 - return ret;
7027 -}
7028 -
7029 int __virt_addr_valid(const volatile void *kaddr)
7030 {
7031 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7032 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7033 index 59cccd9..f39ac2f 100644
7034 --- a/arch/mips/pci/pci-octeon.c
7035 +++ b/arch/mips/pci/pci-octeon.c
7036 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7037
7038
7039 static struct pci_ops octeon_pci_ops = {
7040 - octeon_read_config,
7041 - octeon_write_config,
7042 + .read = octeon_read_config,
7043 + .write = octeon_write_config,
7044 };
7045
7046 static struct resource octeon_pci_mem_resource = {
7047 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7048 index 5e36c33..eb4a17b 100644
7049 --- a/arch/mips/pci/pcie-octeon.c
7050 +++ b/arch/mips/pci/pcie-octeon.c
7051 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7052 }
7053
7054 static struct pci_ops octeon_pcie0_ops = {
7055 - octeon_pcie0_read_config,
7056 - octeon_pcie0_write_config,
7057 + .read = octeon_pcie0_read_config,
7058 + .write = octeon_pcie0_write_config,
7059 };
7060
7061 static struct resource octeon_pcie0_mem_resource = {
7062 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7063 };
7064
7065 static struct pci_ops octeon_pcie1_ops = {
7066 - octeon_pcie1_read_config,
7067 - octeon_pcie1_write_config,
7068 + .read = octeon_pcie1_read_config,
7069 + .write = octeon_pcie1_write_config,
7070 };
7071
7072 static struct resource octeon_pcie1_mem_resource = {
7073 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7074 };
7075
7076 static struct pci_ops octeon_dummy_ops = {
7077 - octeon_dummy_read_config,
7078 - octeon_dummy_write_config,
7079 + .read = octeon_dummy_read_config,
7080 + .write = octeon_dummy_write_config,
7081 };
7082
7083 static struct resource octeon_dummy_mem_resource = {
7084 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7085 index a2358b4..7cead4f 100644
7086 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7087 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7088 @@ -187,9 +187,9 @@ void
7089 cont_nmi_dump(void)
7090 {
7091 #ifndef REAL_NMI_SIGNAL
7092 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7093 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7094
7095 - atomic_inc(&nmied_cpus);
7096 + atomic_inc_unchecked(&nmied_cpus);
7097 #endif
7098 /*
7099 * Only allow 1 cpu to proceed
7100 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7101 udelay(10000);
7102 }
7103 #else
7104 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7105 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7106 #endif
7107
7108 /*
7109 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7110 index a046b30..6799527 100644
7111 --- a/arch/mips/sni/rm200.c
7112 +++ b/arch/mips/sni/rm200.c
7113 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7114 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7115 spurious_irq_mask |= irqmask;
7116 }
7117 - atomic_inc(&irq_err_count);
7118 + atomic_inc_unchecked(&irq_err_count);
7119 /*
7120 * Theoretically we do not have to handle this IRQ,
7121 * but in Linux this does not cause problems and is
7122 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7123 index 41e873b..34d33a7 100644
7124 --- a/arch/mips/vr41xx/common/icu.c
7125 +++ b/arch/mips/vr41xx/common/icu.c
7126 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7127
7128 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7129
7130 - atomic_inc(&irq_err_count);
7131 + atomic_inc_unchecked(&irq_err_count);
7132
7133 return -1;
7134 }
7135 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7136 index ae0e4ee..e8f0692 100644
7137 --- a/arch/mips/vr41xx/common/irq.c
7138 +++ b/arch/mips/vr41xx/common/irq.c
7139 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7140 irq_cascade_t *cascade;
7141
7142 if (irq >= NR_IRQS) {
7143 - atomic_inc(&irq_err_count);
7144 + atomic_inc_unchecked(&irq_err_count);
7145 return;
7146 }
7147
7148 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7149 ret = cascade->get_irq(irq);
7150 irq = ret;
7151 if (ret < 0)
7152 - atomic_inc(&irq_err_count);
7153 + atomic_inc_unchecked(&irq_err_count);
7154 else
7155 irq_dispatch(irq);
7156 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7157 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7158 index 967d144..db12197 100644
7159 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7160 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7161 @@ -11,12 +11,14 @@
7162 #ifndef _ASM_PROC_CACHE_H
7163 #define _ASM_PROC_CACHE_H
7164
7165 +#include <linux/const.h>
7166 +
7167 /* L1 cache */
7168
7169 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7170 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7171 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7172 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7173 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7174 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7175
7176 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7177 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7178 index bcb5df2..84fabd2 100644
7179 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7180 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7181 @@ -16,13 +16,15 @@
7182 #ifndef _ASM_PROC_CACHE_H
7183 #define _ASM_PROC_CACHE_H
7184
7185 +#include <linux/const.h>
7186 +
7187 /*
7188 * L1 cache
7189 */
7190 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7191 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7192 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7193 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7194 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7195 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7196
7197 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7198 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7199 index 4ce7a01..449202a 100644
7200 --- a/arch/openrisc/include/asm/cache.h
7201 +++ b/arch/openrisc/include/asm/cache.h
7202 @@ -19,11 +19,13 @@
7203 #ifndef __ASM_OPENRISC_CACHE_H
7204 #define __ASM_OPENRISC_CACHE_H
7205
7206 +#include <linux/const.h>
7207 +
7208 /* FIXME: How can we replace these with values from the CPU...
7209 * they shouldn't be hard-coded!
7210 */
7211
7212 -#define L1_CACHE_BYTES 16
7213 #define L1_CACHE_SHIFT 4
7214 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7215
7216 #endif /* __ASM_OPENRISC_CACHE_H */
7217 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7218 index 226f8ca..9d9b87d 100644
7219 --- a/arch/parisc/include/asm/atomic.h
7220 +++ b/arch/parisc/include/asm/atomic.h
7221 @@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7222 return dec;
7223 }
7224
7225 +#define atomic64_read_unchecked(v) atomic64_read(v)
7226 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7227 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7228 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7229 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7230 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7231 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7232 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7233 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7234 +
7235 #endif /* !CONFIG_64BIT */
7236
7237
7238 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7239 index 47f11c7..3420df2 100644
7240 --- a/arch/parisc/include/asm/cache.h
7241 +++ b/arch/parisc/include/asm/cache.h
7242 @@ -5,6 +5,7 @@
7243 #ifndef __ARCH_PARISC_CACHE_H
7244 #define __ARCH_PARISC_CACHE_H
7245
7246 +#include <linux/const.h>
7247
7248 /*
7249 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7250 @@ -15,13 +16,13 @@
7251 * just ruin performance.
7252 */
7253 #ifdef CONFIG_PA20
7254 -#define L1_CACHE_BYTES 64
7255 #define L1_CACHE_SHIFT 6
7256 #else
7257 -#define L1_CACHE_BYTES 32
7258 #define L1_CACHE_SHIFT 5
7259 #endif
7260
7261 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7262 +
7263 #ifndef __ASSEMBLY__
7264
7265 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7266 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7267 index 3391d06..c23a2cc 100644
7268 --- a/arch/parisc/include/asm/elf.h
7269 +++ b/arch/parisc/include/asm/elf.h
7270 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7271
7272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7273
7274 +#ifdef CONFIG_PAX_ASLR
7275 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7276 +
7277 +#define PAX_DELTA_MMAP_LEN 16
7278 +#define PAX_DELTA_STACK_LEN 16
7279 +#endif
7280 +
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. This could be done in user space,
7283 but it's not easy, and we've already done it here. */
7284 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7285 index f213f5b..0af3e8e 100644
7286 --- a/arch/parisc/include/asm/pgalloc.h
7287 +++ b/arch/parisc/include/asm/pgalloc.h
7288 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7289 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7290 }
7291
7292 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7293 +{
7294 + pgd_populate(mm, pgd, pmd);
7295 +}
7296 +
7297 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7298 {
7299 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7300 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7301 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7302 #define pmd_free(mm, x) do { } while (0)
7303 #define pgd_populate(mm, pmd, pte) BUG()
7304 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7305
7306 #endif
7307
7308 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7309 index 22b89d1..ce34230 100644
7310 --- a/arch/parisc/include/asm/pgtable.h
7311 +++ b/arch/parisc/include/asm/pgtable.h
7312 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7313 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7314 #define PAGE_COPY PAGE_EXECREAD
7315 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7316 +
7317 +#ifdef CONFIG_PAX_PAGEEXEC
7318 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7319 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7320 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7321 +#else
7322 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7323 +# define PAGE_COPY_NOEXEC PAGE_COPY
7324 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7325 +#endif
7326 +
7327 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7328 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7329 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7330 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7331 index a5cb070..8604ddc 100644
7332 --- a/arch/parisc/include/asm/uaccess.h
7333 +++ b/arch/parisc/include/asm/uaccess.h
7334 @@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7335 const void __user *from,
7336 unsigned long n)
7337 {
7338 - int sz = __compiletime_object_size(to);
7339 + size_t sz = __compiletime_object_size(to);
7340 int ret = -EFAULT;
7341
7342 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7343 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7344 ret = __copy_from_user(to, from, n);
7345 else
7346 copy_from_user_overflow();
7347 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7348 index 50dfafc..b9fc230 100644
7349 --- a/arch/parisc/kernel/module.c
7350 +++ b/arch/parisc/kernel/module.c
7351 @@ -98,16 +98,38 @@
7352
7353 /* three functions to determine where in the module core
7354 * or init pieces the location is */
7355 +static inline int in_init_rx(struct module *me, void *loc)
7356 +{
7357 + return (loc >= me->module_init_rx &&
7358 + loc < (me->module_init_rx + me->init_size_rx));
7359 +}
7360 +
7361 +static inline int in_init_rw(struct module *me, void *loc)
7362 +{
7363 + return (loc >= me->module_init_rw &&
7364 + loc < (me->module_init_rw + me->init_size_rw));
7365 +}
7366 +
7367 static inline int in_init(struct module *me, void *loc)
7368 {
7369 - return (loc >= me->module_init &&
7370 - loc <= (me->module_init + me->init_size));
7371 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7372 +}
7373 +
7374 +static inline int in_core_rx(struct module *me, void *loc)
7375 +{
7376 + return (loc >= me->module_core_rx &&
7377 + loc < (me->module_core_rx + me->core_size_rx));
7378 +}
7379 +
7380 +static inline int in_core_rw(struct module *me, void *loc)
7381 +{
7382 + return (loc >= me->module_core_rw &&
7383 + loc < (me->module_core_rw + me->core_size_rw));
7384 }
7385
7386 static inline int in_core(struct module *me, void *loc)
7387 {
7388 - return (loc >= me->module_core &&
7389 - loc <= (me->module_core + me->core_size));
7390 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7391 }
7392
7393 static inline int in_local(struct module *me, void *loc)
7394 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7395 }
7396
7397 /* align things a bit */
7398 - me->core_size = ALIGN(me->core_size, 16);
7399 - me->arch.got_offset = me->core_size;
7400 - me->core_size += gots * sizeof(struct got_entry);
7401 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7402 + me->arch.got_offset = me->core_size_rw;
7403 + me->core_size_rw += gots * sizeof(struct got_entry);
7404
7405 - me->core_size = ALIGN(me->core_size, 16);
7406 - me->arch.fdesc_offset = me->core_size;
7407 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7408 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7409 + me->arch.fdesc_offset = me->core_size_rw;
7410 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7411
7412 me->arch.got_max = gots;
7413 me->arch.fdesc_max = fdescs;
7414 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7415
7416 BUG_ON(value == 0);
7417
7418 - got = me->module_core + me->arch.got_offset;
7419 + got = me->module_core_rw + me->arch.got_offset;
7420 for (i = 0; got[i].addr; i++)
7421 if (got[i].addr == value)
7422 goto out;
7423 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7424 #ifdef CONFIG_64BIT
7425 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7426 {
7427 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7428 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7429
7430 if (!value) {
7431 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7432 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7433
7434 /* Create new one */
7435 fdesc->addr = value;
7436 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7437 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7438 return (Elf_Addr)fdesc;
7439 }
7440 #endif /* CONFIG_64BIT */
7441 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7442
7443 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7444 end = table + sechdrs[me->arch.unwind_section].sh_size;
7445 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7446 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7447
7448 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7449 me->arch.unwind_section, table, end, gp);
7450 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7451 index e1ffea2..46ed66e 100644
7452 --- a/arch/parisc/kernel/sys_parisc.c
7453 +++ b/arch/parisc/kernel/sys_parisc.c
7454 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7455 unsigned long task_size = TASK_SIZE;
7456 int do_color_align, last_mmap;
7457 struct vm_unmapped_area_info info;
7458 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7459
7460 if (len > task_size)
7461 return -ENOMEM;
7462 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7463 goto found_addr;
7464 }
7465
7466 +#ifdef CONFIG_PAX_RANDMMAP
7467 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7468 +#endif
7469 +
7470 if (addr) {
7471 if (do_color_align && last_mmap)
7472 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7473 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7474 info.high_limit = mmap_upper_limit();
7475 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7476 info.align_offset = shared_align_offset(last_mmap, pgoff);
7477 + info.threadstack_offset = offset;
7478 addr = vm_unmapped_area(&info);
7479
7480 found_addr:
7481 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7482 unsigned long addr = addr0;
7483 int do_color_align, last_mmap;
7484 struct vm_unmapped_area_info info;
7485 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7486
7487 #ifdef CONFIG_64BIT
7488 /* This should only ever run for 32-bit processes. */
7489 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7490 }
7491
7492 /* requesting a specific address */
7493 +#ifdef CONFIG_PAX_RANDMMAP
7494 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7495 +#endif
7496 +
7497 if (addr) {
7498 if (do_color_align && last_mmap)
7499 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7500 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7501 info.high_limit = mm->mmap_base;
7502 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7503 info.align_offset = shared_align_offset(last_mmap, pgoff);
7504 + info.threadstack_offset = offset;
7505 addr = vm_unmapped_area(&info);
7506 if (!(addr & ~PAGE_MASK))
7507 goto found_addr;
7508 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7509 mm->mmap_legacy_base = mmap_legacy_base();
7510 mm->mmap_base = mmap_upper_limit();
7511
7512 +#ifdef CONFIG_PAX_RANDMMAP
7513 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7514 + mm->mmap_legacy_base += mm->delta_mmap;
7515 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7516 + }
7517 +#endif
7518 +
7519 if (mmap_is_legacy()) {
7520 mm->mmap_base = mm->mmap_legacy_base;
7521 mm->get_unmapped_area = arch_get_unmapped_area;
7522 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7523 index 47ee620..1107387 100644
7524 --- a/arch/parisc/kernel/traps.c
7525 +++ b/arch/parisc/kernel/traps.c
7526 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7527
7528 down_read(&current->mm->mmap_sem);
7529 vma = find_vma(current->mm,regs->iaoq[0]);
7530 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7531 - && (vma->vm_flags & VM_EXEC)) {
7532 -
7533 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7534 fault_address = regs->iaoq[0];
7535 fault_space = regs->iasq[0];
7536
7537 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7538 index e5120e6..8ddb5cc 100644
7539 --- a/arch/parisc/mm/fault.c
7540 +++ b/arch/parisc/mm/fault.c
7541 @@ -15,6 +15,7 @@
7542 #include <linux/sched.h>
7543 #include <linux/interrupt.h>
7544 #include <linux/module.h>
7545 +#include <linux/unistd.h>
7546
7547 #include <asm/uaccess.h>
7548 #include <asm/traps.h>
7549 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7550 static unsigned long
7551 parisc_acctyp(unsigned long code, unsigned int inst)
7552 {
7553 - if (code == 6 || code == 16)
7554 + if (code == 6 || code == 7 || code == 16)
7555 return VM_EXEC;
7556
7557 switch (inst & 0xf0000000) {
7558 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7559 }
7560 #endif
7561
7562 +#ifdef CONFIG_PAX_PAGEEXEC
7563 +/*
7564 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7565 + *
7566 + * returns 1 when task should be killed
7567 + * 2 when rt_sigreturn trampoline was detected
7568 + * 3 when unpatched PLT trampoline was detected
7569 + */
7570 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7571 +{
7572 +
7573 +#ifdef CONFIG_PAX_EMUPLT
7574 + int err;
7575 +
7576 + do { /* PaX: unpatched PLT emulation */
7577 + unsigned int bl, depwi;
7578 +
7579 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7580 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7581 +
7582 + if (err)
7583 + break;
7584 +
7585 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7586 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7587 +
7588 + err = get_user(ldw, (unsigned int *)addr);
7589 + err |= get_user(bv, (unsigned int *)(addr+4));
7590 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7591 +
7592 + if (err)
7593 + break;
7594 +
7595 + if (ldw == 0x0E801096U &&
7596 + bv == 0xEAC0C000U &&
7597 + ldw2 == 0x0E881095U)
7598 + {
7599 + unsigned int resolver, map;
7600 +
7601 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7602 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7603 + if (err)
7604 + break;
7605 +
7606 + regs->gr[20] = instruction_pointer(regs)+8;
7607 + regs->gr[21] = map;
7608 + regs->gr[22] = resolver;
7609 + regs->iaoq[0] = resolver | 3UL;
7610 + regs->iaoq[1] = regs->iaoq[0] + 4;
7611 + return 3;
7612 + }
7613 + }
7614 + } while (0);
7615 +#endif
7616 +
7617 +#ifdef CONFIG_PAX_EMUTRAMP
7618 +
7619 +#ifndef CONFIG_PAX_EMUSIGRT
7620 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7621 + return 1;
7622 +#endif
7623 +
7624 + do { /* PaX: rt_sigreturn emulation */
7625 + unsigned int ldi1, ldi2, bel, nop;
7626 +
7627 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7628 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7629 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7630 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7631 +
7632 + if (err)
7633 + break;
7634 +
7635 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7636 + ldi2 == 0x3414015AU &&
7637 + bel == 0xE4008200U &&
7638 + nop == 0x08000240U)
7639 + {
7640 + regs->gr[25] = (ldi1 & 2) >> 1;
7641 + regs->gr[20] = __NR_rt_sigreturn;
7642 + regs->gr[31] = regs->iaoq[1] + 16;
7643 + regs->sr[0] = regs->iasq[1];
7644 + regs->iaoq[0] = 0x100UL;
7645 + regs->iaoq[1] = regs->iaoq[0] + 4;
7646 + regs->iasq[0] = regs->sr[2];
7647 + regs->iasq[1] = regs->sr[2];
7648 + return 2;
7649 + }
7650 + } while (0);
7651 +#endif
7652 +
7653 + return 1;
7654 +}
7655 +
7656 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7657 +{
7658 + unsigned long i;
7659 +
7660 + printk(KERN_ERR "PAX: bytes at PC: ");
7661 + for (i = 0; i < 5; i++) {
7662 + unsigned int c;
7663 + if (get_user(c, (unsigned int *)pc+i))
7664 + printk(KERN_CONT "???????? ");
7665 + else
7666 + printk(KERN_CONT "%08x ", c);
7667 + }
7668 + printk("\n");
7669 +}
7670 +#endif
7671 +
7672 int fixup_exception(struct pt_regs *regs)
7673 {
7674 const struct exception_table_entry *fix;
7675 @@ -234,8 +345,33 @@ retry:
7676
7677 good_area:
7678
7679 - if ((vma->vm_flags & acc_type) != acc_type)
7680 + if ((vma->vm_flags & acc_type) != acc_type) {
7681 +
7682 +#ifdef CONFIG_PAX_PAGEEXEC
7683 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7684 + (address & ~3UL) == instruction_pointer(regs))
7685 + {
7686 + up_read(&mm->mmap_sem);
7687 + switch (pax_handle_fetch_fault(regs)) {
7688 +
7689 +#ifdef CONFIG_PAX_EMUPLT
7690 + case 3:
7691 + return;
7692 +#endif
7693 +
7694 +#ifdef CONFIG_PAX_EMUTRAMP
7695 + case 2:
7696 + return;
7697 +#endif
7698 +
7699 + }
7700 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7701 + do_group_exit(SIGKILL);
7702 + }
7703 +#endif
7704 +
7705 goto bad_area;
7706 + }
7707
7708 /*
7709 * If for any reason at all we couldn't handle the fault, make
7710 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7711 index 88eace4..4ba2591 100644
7712 --- a/arch/powerpc/Kconfig
7713 +++ b/arch/powerpc/Kconfig
7714 @@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7715 config KEXEC
7716 bool "kexec system call"
7717 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7718 + depends on !GRKERNSEC_KMEM
7719 help
7720 kexec is a system call that implements the ability to shutdown your
7721 current kernel, and to start another kernel. It is like a reboot
7722 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7723 index 512d278..d31fadd 100644
7724 --- a/arch/powerpc/include/asm/atomic.h
7725 +++ b/arch/powerpc/include/asm/atomic.h
7726 @@ -12,6 +12,11 @@
7727
7728 #define ATOMIC_INIT(i) { (i) }
7729
7730 +#define _ASM_EXTABLE(from, to) \
7731 +" .section __ex_table,\"a\"\n" \
7732 + PPC_LONG" " #from ", " #to"\n" \
7733 +" .previous\n"
7734 +
7735 static __inline__ int atomic_read(const atomic_t *v)
7736 {
7737 int t;
7738 @@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7739 return t;
7740 }
7741
7742 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7743 +{
7744 + int t;
7745 +
7746 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7747 +
7748 + return t;
7749 +}
7750 +
7751 static __inline__ void atomic_set(atomic_t *v, int i)
7752 {
7753 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7754 }
7755
7756 -#define ATOMIC_OP(op, asm_op) \
7757 -static __inline__ void atomic_##op(int a, atomic_t *v) \
7758 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7759 +{
7760 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7761 +}
7762 +
7763 +#ifdef CONFIG_PAX_REFCOUNT
7764 +#define __REFCOUNT_OP(op) op##o.
7765 +#define __OVERFLOW_PRE \
7766 + " mcrxr cr0\n"
7767 +#define __OVERFLOW_POST \
7768 + " bf 4*cr0+so, 3f\n" \
7769 + "2: .long 0x00c00b00\n" \
7770 + "3:\n"
7771 +#define __OVERFLOW_EXTABLE \
7772 + "\n4:\n"
7773 + _ASM_EXTABLE(2b, 4b)
7774 +#else
7775 +#define __REFCOUNT_OP(op) op
7776 +#define __OVERFLOW_PRE
7777 +#define __OVERFLOW_POST
7778 +#define __OVERFLOW_EXTABLE
7779 +#endif
7780 +
7781 +#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7782 +static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7783 { \
7784 int t; \
7785 \
7786 __asm__ __volatile__( \
7787 -"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7788 +"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7789 + pre_op \
7790 #asm_op " %0,%2,%0\n" \
7791 + post_op \
7792 PPC405_ERR77(0,%3) \
7793 " stwcx. %0,0,%3 \n" \
7794 " bne- 1b\n" \
7795 + extable \
7796 : "=&r" (t), "+m" (v->counter) \
7797 : "r" (a), "r" (&v->counter) \
7798 : "cc"); \
7799 } \
7800
7801 -#define ATOMIC_OP_RETURN(op, asm_op) \
7802 -static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7803 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7804 + __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7805 +
7806 +#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7807 +static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7808 { \
7809 int t; \
7810 \
7811 __asm__ __volatile__( \
7812 PPC_ATOMIC_ENTRY_BARRIER \
7813 -"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7814 +"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7815 + pre_op \
7816 #asm_op " %0,%1,%0\n" \
7817 + post_op \
7818 PPC405_ERR77(0,%2) \
7819 " stwcx. %0,0,%2 \n" \
7820 " bne- 1b\n" \
7821 + extable \
7822 PPC_ATOMIC_EXIT_BARRIER \
7823 : "=&r" (t) \
7824 : "r" (a), "r" (&v->counter) \
7825 @@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7826 return t; \
7827 }
7828
7829 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7830 + __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7831 +
7832 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7833
7834 ATOMIC_OPS(add, add)
7835 @@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7836
7837 #undef ATOMIC_OPS
7838 #undef ATOMIC_OP_RETURN
7839 +#undef __ATOMIC_OP_RETURN
7840 #undef ATOMIC_OP
7841 +#undef __ATOMIC_OP
7842
7843 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7844
7845 -static __inline__ void atomic_inc(atomic_t *v)
7846 -{
7847 - int t;
7848 +/*
7849 + * atomic_inc - increment atomic variable
7850 + * @v: pointer of type atomic_t
7851 + *
7852 + * Automatically increments @v by 1
7853 + */
7854 +#define atomic_inc(v) atomic_add(1, (v))
7855 +#define atomic_inc_return(v) atomic_add_return(1, (v))
7856
7857 - __asm__ __volatile__(
7858 -"1: lwarx %0,0,%2 # atomic_inc\n\
7859 - addic %0,%0,1\n"
7860 - PPC405_ERR77(0,%2)
7861 -" stwcx. %0,0,%2 \n\
7862 - bne- 1b"
7863 - : "=&r" (t), "+m" (v->counter)
7864 - : "r" (&v->counter)
7865 - : "cc", "xer");
7866 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7867 +{
7868 + atomic_add_unchecked(1, v);
7869 }
7870
7871 -static __inline__ int atomic_inc_return(atomic_t *v)
7872 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7873 {
7874 - int t;
7875 -
7876 - __asm__ __volatile__(
7877 - PPC_ATOMIC_ENTRY_BARRIER
7878 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
7879 - addic %0,%0,1\n"
7880 - PPC405_ERR77(0,%1)
7881 -" stwcx. %0,0,%1 \n\
7882 - bne- 1b"
7883 - PPC_ATOMIC_EXIT_BARRIER
7884 - : "=&r" (t)
7885 - : "r" (&v->counter)
7886 - : "cc", "xer", "memory");
7887 -
7888 - return t;
7889 + return atomic_add_return_unchecked(1, v);
7890 }
7891
7892 /*
7893 @@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7894 */
7895 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7896
7897 -static __inline__ void atomic_dec(atomic_t *v)
7898 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7899 {
7900 - int t;
7901 -
7902 - __asm__ __volatile__(
7903 -"1: lwarx %0,0,%2 # atomic_dec\n\
7904 - addic %0,%0,-1\n"
7905 - PPC405_ERR77(0,%2)\
7906 -" stwcx. %0,0,%2\n\
7907 - bne- 1b"
7908 - : "=&r" (t), "+m" (v->counter)
7909 - : "r" (&v->counter)
7910 - : "cc", "xer");
7911 + return atomic_add_return_unchecked(1, v) == 0;
7912 }
7913
7914 -static __inline__ int atomic_dec_return(atomic_t *v)
7915 +/*
7916 + * atomic_dec - decrement atomic variable
7917 + * @v: pointer of type atomic_t
7918 + *
7919 + * Atomically decrements @v by 1
7920 + */
7921 +#define atomic_dec(v) atomic_sub(1, (v))
7922 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
7923 +
7924 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7925 {
7926 - int t;
7927 -
7928 - __asm__ __volatile__(
7929 - PPC_ATOMIC_ENTRY_BARRIER
7930 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
7931 - addic %0,%0,-1\n"
7932 - PPC405_ERR77(0,%1)
7933 -" stwcx. %0,0,%1\n\
7934 - bne- 1b"
7935 - PPC_ATOMIC_EXIT_BARRIER
7936 - : "=&r" (t)
7937 - : "r" (&v->counter)
7938 - : "cc", "xer", "memory");
7939 -
7940 - return t;
7941 + atomic_sub_unchecked(1, v);
7942 }
7943
7944 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7945 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7946
7947 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7948 +{
7949 + return cmpxchg(&(v->counter), old, new);
7950 +}
7951 +
7952 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7953 +{
7954 + return xchg(&(v->counter), new);
7955 +}
7956 +
7957 /**
7958 * __atomic_add_unless - add unless the number is a given value
7959 * @v: pointer of type atomic_t
7960 @@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7961 PPC_ATOMIC_ENTRY_BARRIER
7962 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7963 cmpw 0,%0,%3 \n\
7964 - beq- 2f \n\
7965 - add %0,%2,%0 \n"
7966 + beq- 2f \n"
7967 +
7968 +#ifdef CONFIG_PAX_REFCOUNT
7969 +" mcrxr cr0\n"
7970 +" addo. %0,%2,%0\n"
7971 +" bf 4*cr0+so, 4f\n"
7972 +"3:.long " "0x00c00b00""\n"
7973 +"4:\n"
7974 +#else
7975 + "add %0,%2,%0 \n"
7976 +#endif
7977 +
7978 PPC405_ERR77(0,%2)
7979 " stwcx. %0,0,%1 \n\
7980 bne- 1b \n"
7981 +"5:"
7982 +
7983 +#ifdef CONFIG_PAX_REFCOUNT
7984 + _ASM_EXTABLE(3b, 5b)
7985 +#endif
7986 +
7987 PPC_ATOMIC_EXIT_BARRIER
7988 " subf %0,%2,%0 \n\
7989 2:"
7990 @@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7991 }
7992 #define atomic_dec_if_positive atomic_dec_if_positive
7993
7994 +#define smp_mb__before_atomic_dec() smp_mb()
7995 +#define smp_mb__after_atomic_dec() smp_mb()
7996 +#define smp_mb__before_atomic_inc() smp_mb()
7997 +#define smp_mb__after_atomic_inc() smp_mb()
7998 +
7999 #ifdef __powerpc64__
8000
8001 #define ATOMIC64_INIT(i) { (i) }
8002 @@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8003 return t;
8004 }
8005
8006 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8007 +{
8008 + long t;
8009 +
8010 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8011 +
8012 + return t;
8013 +}
8014 +
8015 static __inline__ void atomic64_set(atomic64_t *v, long i)
8016 {
8017 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8018 }
8019
8020 -#define ATOMIC64_OP(op, asm_op) \
8021 -static __inline__ void atomic64_##op(long a, atomic64_t *v) \
8022 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8023 +{
8024 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8025 +}
8026 +
8027 +#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
8028 +static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
8029 { \
8030 long t; \
8031 \
8032 __asm__ __volatile__( \
8033 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8034 + pre_op \
8035 #asm_op " %0,%2,%0\n" \
8036 + post_op \
8037 " stdcx. %0,0,%3 \n" \
8038 " bne- 1b\n" \
8039 + extable \
8040 : "=&r" (t), "+m" (v->counter) \
8041 : "r" (a), "r" (&v->counter) \
8042 : "cc"); \
8043 }
8044
8045 -#define ATOMIC64_OP_RETURN(op, asm_op) \
8046 -static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8047 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8048 + __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8049 +
8050 +#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8051 +static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8052 { \
8053 long t; \
8054 \
8055 __asm__ __volatile__( \
8056 PPC_ATOMIC_ENTRY_BARRIER \
8057 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8058 + pre_op \
8059 #asm_op " %0,%1,%0\n" \
8060 + post_op \
8061 " stdcx. %0,0,%2 \n" \
8062 " bne- 1b\n" \
8063 + extable \
8064 PPC_ATOMIC_EXIT_BARRIER \
8065 : "=&r" (t) \
8066 : "r" (a), "r" (&v->counter) \
8067 @@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8068 return t; \
8069 }
8070
8071 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8072 + __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8073 +
8074 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8075
8076 ATOMIC64_OPS(add, add)
8077 @@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8078
8079 #undef ATOMIC64_OPS
8080 #undef ATOMIC64_OP_RETURN
8081 +#undef __ATOMIC64_OP_RETURN
8082 #undef ATOMIC64_OP
8083 +#undef __ATOMIC64_OP
8084 +#undef __OVERFLOW_EXTABLE
8085 +#undef __OVERFLOW_POST
8086 +#undef __OVERFLOW_PRE
8087 +#undef __REFCOUNT_OP
8088
8089 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8090
8091 -static __inline__ void atomic64_inc(atomic64_t *v)
8092 -{
8093 - long t;
8094 +/*
8095 + * atomic64_inc - increment atomic variable
8096 + * @v: pointer of type atomic64_t
8097 + *
8098 + * Automatically increments @v by 1
8099 + */
8100 +#define atomic64_inc(v) atomic64_add(1, (v))
8101 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8102
8103 - __asm__ __volatile__(
8104 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8105 - addic %0,%0,1\n\
8106 - stdcx. %0,0,%2 \n\
8107 - bne- 1b"
8108 - : "=&r" (t), "+m" (v->counter)
8109 - : "r" (&v->counter)
8110 - : "cc", "xer");
8111 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8112 +{
8113 + atomic64_add_unchecked(1, v);
8114 }
8115
8116 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8117 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8118 {
8119 - long t;
8120 -
8121 - __asm__ __volatile__(
8122 - PPC_ATOMIC_ENTRY_BARRIER
8123 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8124 - addic %0,%0,1\n\
8125 - stdcx. %0,0,%1 \n\
8126 - bne- 1b"
8127 - PPC_ATOMIC_EXIT_BARRIER
8128 - : "=&r" (t)
8129 - : "r" (&v->counter)
8130 - : "cc", "xer", "memory");
8131 -
8132 - return t;
8133 + return atomic64_add_return_unchecked(1, v);
8134 }
8135
8136 /*
8137 @@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8138 */
8139 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8140
8141 -static __inline__ void atomic64_dec(atomic64_t *v)
8142 +/*
8143 + * atomic64_dec - decrement atomic variable
8144 + * @v: pointer of type atomic64_t
8145 + *
8146 + * Atomically decrements @v by 1
8147 + */
8148 +#define atomic64_dec(v) atomic64_sub(1, (v))
8149 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8150 +
8151 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8152 {
8153 - long t;
8154 -
8155 - __asm__ __volatile__(
8156 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8157 - addic %0,%0,-1\n\
8158 - stdcx. %0,0,%2\n\
8159 - bne- 1b"
8160 - : "=&r" (t), "+m" (v->counter)
8161 - : "r" (&v->counter)
8162 - : "cc", "xer");
8163 -}
8164 -
8165 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8166 -{
8167 - long t;
8168 -
8169 - __asm__ __volatile__(
8170 - PPC_ATOMIC_ENTRY_BARRIER
8171 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8172 - addic %0,%0,-1\n\
8173 - stdcx. %0,0,%1\n\
8174 - bne- 1b"
8175 - PPC_ATOMIC_EXIT_BARRIER
8176 - : "=&r" (t)
8177 - : "r" (&v->counter)
8178 - : "cc", "xer", "memory");
8179 -
8180 - return t;
8181 + atomic64_sub_unchecked(1, v);
8182 }
8183
8184 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8185 @@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8186 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8187 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8188
8189 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8190 +{
8191 + return cmpxchg(&(v->counter), old, new);
8192 +}
8193 +
8194 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8195 +{
8196 + return xchg(&(v->counter), new);
8197 +}
8198 +
8199 /**
8200 * atomic64_add_unless - add unless the number is a given value
8201 * @v: pointer of type atomic64_t
8202 @@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8203
8204 __asm__ __volatile__ (
8205 PPC_ATOMIC_ENTRY_BARRIER
8206 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8207 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8208 cmpd 0,%0,%3 \n\
8209 - beq- 2f \n\
8210 - add %0,%2,%0 \n"
8211 + beq- 2f \n"
8212 +
8213 +#ifdef CONFIG_PAX_REFCOUNT
8214 +" mcrxr cr0\n"
8215 +" addo. %0,%2,%0\n"
8216 +" bf 4*cr0+so, 4f\n"
8217 +"3:.long " "0x00c00b00""\n"
8218 +"4:\n"
8219 +#else
8220 + "add %0,%2,%0 \n"
8221 +#endif
8222 +
8223 " stdcx. %0,0,%1 \n\
8224 bne- 1b \n"
8225 PPC_ATOMIC_EXIT_BARRIER
8226 +"5:"
8227 +
8228 +#ifdef CONFIG_PAX_REFCOUNT
8229 + _ASM_EXTABLE(3b, 5b)
8230 +#endif
8231 +
8232 " subf %0,%2,%0 \n\
8233 2:"
8234 : "=&r" (t)
8235 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8236 index bab79a1..4a3eabc 100644
8237 --- a/arch/powerpc/include/asm/barrier.h
8238 +++ b/arch/powerpc/include/asm/barrier.h
8239 @@ -73,7 +73,7 @@
8240 do { \
8241 compiletime_assert_atomic_type(*p); \
8242 __lwsync(); \
8243 - ACCESS_ONCE(*p) = (v); \
8244 + ACCESS_ONCE_RW(*p) = (v); \
8245 } while (0)
8246
8247 #define smp_load_acquire(p) \
8248 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8249 index 34a05a1..a1f2c67 100644
8250 --- a/arch/powerpc/include/asm/cache.h
8251 +++ b/arch/powerpc/include/asm/cache.h
8252 @@ -4,6 +4,7 @@
8253 #ifdef __KERNEL__
8254
8255 #include <asm/reg.h>
8256 +#include <linux/const.h>
8257
8258 /* bytes per L1 cache line */
8259 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8260 @@ -23,7 +24,7 @@
8261 #define L1_CACHE_SHIFT 7
8262 #endif
8263
8264 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8265 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8266
8267 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8268
8269 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8270 index 888d8f3..66f581c 100644
8271 --- a/arch/powerpc/include/asm/elf.h
8272 +++ b/arch/powerpc/include/asm/elf.h
8273 @@ -28,8 +28,19 @@
8274 the loader. We need to make sure that it is out of the way of the program
8275 that it will "exec", and that there is sufficient room for the brk. */
8276
8277 -extern unsigned long randomize_et_dyn(unsigned long base);
8278 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8279 +#define ELF_ET_DYN_BASE (0x20000000)
8280 +
8281 +#ifdef CONFIG_PAX_ASLR
8282 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8283 +
8284 +#ifdef __powerpc64__
8285 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8286 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8287 +#else
8288 +#define PAX_DELTA_MMAP_LEN 15
8289 +#define PAX_DELTA_STACK_LEN 15
8290 +#endif
8291 +#endif
8292
8293 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8294
8295 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8296 (0x7ff >> (PAGE_SHIFT - 12)) : \
8297 (0x3ffff >> (PAGE_SHIFT - 12)))
8298
8299 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8300 -#define arch_randomize_brk arch_randomize_brk
8301 -
8302 -
8303 #ifdef CONFIG_SPU_BASE
8304 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8305 #define NT_SPU 1
8306 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8307 index 8196e9c..d83a9f3 100644
8308 --- a/arch/powerpc/include/asm/exec.h
8309 +++ b/arch/powerpc/include/asm/exec.h
8310 @@ -4,6 +4,6 @@
8311 #ifndef _ASM_POWERPC_EXEC_H
8312 #define _ASM_POWERPC_EXEC_H
8313
8314 -extern unsigned long arch_align_stack(unsigned long sp);
8315 +#define arch_align_stack(x) ((x) & ~0xfUL)
8316
8317 #endif /* _ASM_POWERPC_EXEC_H */
8318 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8319 index 5acabbd..7ea14fa 100644
8320 --- a/arch/powerpc/include/asm/kmap_types.h
8321 +++ b/arch/powerpc/include/asm/kmap_types.h
8322 @@ -10,7 +10,7 @@
8323 * 2 of the License, or (at your option) any later version.
8324 */
8325
8326 -#define KM_TYPE_NR 16
8327 +#define KM_TYPE_NR 17
8328
8329 #endif /* __KERNEL__ */
8330 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8331 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8332 index b8da913..c02b593 100644
8333 --- a/arch/powerpc/include/asm/local.h
8334 +++ b/arch/powerpc/include/asm/local.h
8335 @@ -9,21 +9,65 @@ typedef struct
8336 atomic_long_t a;
8337 } local_t;
8338
8339 +typedef struct
8340 +{
8341 + atomic_long_unchecked_t a;
8342 +} local_unchecked_t;
8343 +
8344 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8345
8346 #define local_read(l) atomic_long_read(&(l)->a)
8347 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8348 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8349 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8350
8351 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8352 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8353 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8354 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8355 #define local_inc(l) atomic_long_inc(&(l)->a)
8356 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8357 #define local_dec(l) atomic_long_dec(&(l)->a)
8358 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8359
8360 static __inline__ long local_add_return(long a, local_t *l)
8361 {
8362 long t;
8363
8364 __asm__ __volatile__(
8365 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8366 +
8367 +#ifdef CONFIG_PAX_REFCOUNT
8368 +" mcrxr cr0\n"
8369 +" addo. %0,%1,%0\n"
8370 +" bf 4*cr0+so, 3f\n"
8371 +"2:.long " "0x00c00b00""\n"
8372 +#else
8373 +" add %0,%1,%0\n"
8374 +#endif
8375 +
8376 +"3:\n"
8377 + PPC405_ERR77(0,%2)
8378 + PPC_STLCX "%0,0,%2 \n\
8379 + bne- 1b"
8380 +
8381 +#ifdef CONFIG_PAX_REFCOUNT
8382 +"\n4:\n"
8383 + _ASM_EXTABLE(2b, 4b)
8384 +#endif
8385 +
8386 + : "=&r" (t)
8387 + : "r" (a), "r" (&(l->a.counter))
8388 + : "cc", "memory");
8389 +
8390 + return t;
8391 +}
8392 +
8393 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8394 +{
8395 + long t;
8396 +
8397 + __asm__ __volatile__(
8398 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8399 add %0,%1,%0\n"
8400 PPC405_ERR77(0,%2)
8401 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8402
8403 #define local_cmpxchg(l, o, n) \
8404 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8405 +#define local_cmpxchg_unchecked(l, o, n) \
8406 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8407 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8408
8409 /**
8410 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8411 index 8565c25..2865190 100644
8412 --- a/arch/powerpc/include/asm/mman.h
8413 +++ b/arch/powerpc/include/asm/mman.h
8414 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8415 }
8416 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8417
8418 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8419 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8420 {
8421 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8422 }
8423 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8424 index 26fe1ae..987ffc5 100644
8425 --- a/arch/powerpc/include/asm/page.h
8426 +++ b/arch/powerpc/include/asm/page.h
8427 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8428 * and needs to be executable. This means the whole heap ends
8429 * up being executable.
8430 */
8431 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8432 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8433 +#define VM_DATA_DEFAULT_FLAGS32 \
8434 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8435 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8436
8437 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8438 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8439 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8440 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8441 #endif
8442
8443 +#define ktla_ktva(addr) (addr)
8444 +#define ktva_ktla(addr) (addr)
8445 +
8446 #ifndef CONFIG_PPC_BOOK3S_64
8447 /*
8448 * Use the top bit of the higher-level page table entries to indicate whether
8449 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8450 index d908a46..3753f71 100644
8451 --- a/arch/powerpc/include/asm/page_64.h
8452 +++ b/arch/powerpc/include/asm/page_64.h
8453 @@ -172,15 +172,18 @@ do { \
8454 * stack by default, so in the absence of a PT_GNU_STACK program header
8455 * we turn execute permission off.
8456 */
8457 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8458 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8459 +#define VM_STACK_DEFAULT_FLAGS32 \
8460 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8461 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8462
8463 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8464 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8465
8466 +#ifndef CONFIG_PAX_PAGEEXEC
8467 #define VM_STACK_DEFAULT_FLAGS \
8468 (is_32bit_task() ? \
8469 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8470 +#endif
8471
8472 #include <asm-generic/getorder.h>
8473
8474 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8475 index 4b0be20..c15a27d 100644
8476 --- a/arch/powerpc/include/asm/pgalloc-64.h
8477 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8478 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8479 #ifndef CONFIG_PPC_64K_PAGES
8480
8481 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8482 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8483
8484 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8485 {
8486 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8487 pud_set(pud, (unsigned long)pmd);
8488 }
8489
8490 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8491 +{
8492 + pud_populate(mm, pud, pmd);
8493 +}
8494 +
8495 #define pmd_populate(mm, pmd, pte_page) \
8496 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8497 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8498 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8499 #endif
8500
8501 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8502 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8503
8504 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8505 pte_t *pte)
8506 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8507 index 316f9a5..ba05c77 100644
8508 --- a/arch/powerpc/include/asm/pgtable.h
8509 +++ b/arch/powerpc/include/asm/pgtable.h
8510 @@ -2,6 +2,7 @@
8511 #define _ASM_POWERPC_PGTABLE_H
8512 #ifdef __KERNEL__
8513
8514 +#include <linux/const.h>
8515 #ifndef __ASSEMBLY__
8516 #include <linux/mmdebug.h>
8517 #include <linux/mmzone.h>
8518 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8519 index 4aad413..85d86bf 100644
8520 --- a/arch/powerpc/include/asm/pte-hash32.h
8521 +++ b/arch/powerpc/include/asm/pte-hash32.h
8522 @@ -21,6 +21,7 @@
8523 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8524 #define _PAGE_USER 0x004 /* usermode access allowed */
8525 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8526 +#define _PAGE_EXEC _PAGE_GUARDED
8527 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8528 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8529 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8530 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8531 index a68ee15..552d213 100644
8532 --- a/arch/powerpc/include/asm/reg.h
8533 +++ b/arch/powerpc/include/asm/reg.h
8534 @@ -253,6 +253,7 @@
8535 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8536 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8537 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8538 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8539 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8540 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8541 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8542 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8543 index 5a6614a..d89995d1 100644
8544 --- a/arch/powerpc/include/asm/smp.h
8545 +++ b/arch/powerpc/include/asm/smp.h
8546 @@ -51,7 +51,7 @@ struct smp_ops_t {
8547 int (*cpu_disable)(void);
8548 void (*cpu_die)(unsigned int nr);
8549 int (*cpu_bootable)(unsigned int nr);
8550 -};
8551 +} __no_const;
8552
8553 extern void smp_send_debugger_break(void);
8554 extern void start_secondary_resume(void);
8555 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8556 index 4dbe072..b803275 100644
8557 --- a/arch/powerpc/include/asm/spinlock.h
8558 +++ b/arch/powerpc/include/asm/spinlock.h
8559 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8560 __asm__ __volatile__(
8561 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8562 __DO_SIGN_EXTEND
8563 -" addic. %0,%0,1\n\
8564 - ble- 2f\n"
8565 +
8566 +#ifdef CONFIG_PAX_REFCOUNT
8567 +" mcrxr cr0\n"
8568 +" addico. %0,%0,1\n"
8569 +" bf 4*cr0+so, 3f\n"
8570 +"2:.long " "0x00c00b00""\n"
8571 +#else
8572 +" addic. %0,%0,1\n"
8573 +#endif
8574 +
8575 +"3:\n"
8576 + "ble- 4f\n"
8577 PPC405_ERR77(0,%1)
8578 " stwcx. %0,0,%1\n\
8579 bne- 1b\n"
8580 PPC_ACQUIRE_BARRIER
8581 -"2:" : "=&r" (tmp)
8582 +"4:"
8583 +
8584 +#ifdef CONFIG_PAX_REFCOUNT
8585 + _ASM_EXTABLE(2b,4b)
8586 +#endif
8587 +
8588 + : "=&r" (tmp)
8589 : "r" (&rw->lock)
8590 : "cr0", "xer", "memory");
8591
8592 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8593 __asm__ __volatile__(
8594 "# read_unlock\n\t"
8595 PPC_RELEASE_BARRIER
8596 -"1: lwarx %0,0,%1\n\
8597 - addic %0,%0,-1\n"
8598 +"1: lwarx %0,0,%1\n"
8599 +
8600 +#ifdef CONFIG_PAX_REFCOUNT
8601 +" mcrxr cr0\n"
8602 +" addico. %0,%0,-1\n"
8603 +" bf 4*cr0+so, 3f\n"
8604 +"2:.long " "0x00c00b00""\n"
8605 +#else
8606 +" addic. %0,%0,-1\n"
8607 +#endif
8608 +
8609 +"3:\n"
8610 PPC405_ERR77(0,%1)
8611 " stwcx. %0,0,%1\n\
8612 bne- 1b"
8613 +
8614 +#ifdef CONFIG_PAX_REFCOUNT
8615 +"\n4:\n"
8616 + _ASM_EXTABLE(2b, 4b)
8617 +#endif
8618 +
8619 : "=&r"(tmp)
8620 : "r"(&rw->lock)
8621 : "cr0", "xer", "memory");
8622 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8623 index b034ecd..af7e31f 100644
8624 --- a/arch/powerpc/include/asm/thread_info.h
8625 +++ b/arch/powerpc/include/asm/thread_info.h
8626 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8627 #if defined(CONFIG_PPC64)
8628 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8629 #endif
8630 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8631 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8632
8633 /* as above, but as bit values */
8634 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8635 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8636 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8637 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8638 #define _TIF_NOHZ (1<<TIF_NOHZ)
8639 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8640 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8641 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8642 - _TIF_NOHZ)
8643 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8644
8645 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8646 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8647 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8648 index 9485b43..3bd3c16 100644
8649 --- a/arch/powerpc/include/asm/uaccess.h
8650 +++ b/arch/powerpc/include/asm/uaccess.h
8651 @@ -58,6 +58,7 @@
8652
8653 #endif
8654
8655 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8656 #define access_ok(type, addr, size) \
8657 (__chk_user_ptr(addr), \
8658 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8659 @@ -318,52 +319,6 @@ do { \
8660 extern unsigned long __copy_tofrom_user(void __user *to,
8661 const void __user *from, unsigned long size);
8662
8663 -#ifndef __powerpc64__
8664 -
8665 -static inline unsigned long copy_from_user(void *to,
8666 - const void __user *from, unsigned long n)
8667 -{
8668 - unsigned long over;
8669 -
8670 - if (access_ok(VERIFY_READ, from, n))
8671 - return __copy_tofrom_user((__force void __user *)to, from, n);
8672 - if ((unsigned long)from < TASK_SIZE) {
8673 - over = (unsigned long)from + n - TASK_SIZE;
8674 - return __copy_tofrom_user((__force void __user *)to, from,
8675 - n - over) + over;
8676 - }
8677 - return n;
8678 -}
8679 -
8680 -static inline unsigned long copy_to_user(void __user *to,
8681 - const void *from, unsigned long n)
8682 -{
8683 - unsigned long over;
8684 -
8685 - if (access_ok(VERIFY_WRITE, to, n))
8686 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8687 - if ((unsigned long)to < TASK_SIZE) {
8688 - over = (unsigned long)to + n - TASK_SIZE;
8689 - return __copy_tofrom_user(to, (__force void __user *)from,
8690 - n - over) + over;
8691 - }
8692 - return n;
8693 -}
8694 -
8695 -#else /* __powerpc64__ */
8696 -
8697 -#define __copy_in_user(to, from, size) \
8698 - __copy_tofrom_user((to), (from), (size))
8699 -
8700 -extern unsigned long copy_from_user(void *to, const void __user *from,
8701 - unsigned long n);
8702 -extern unsigned long copy_to_user(void __user *to, const void *from,
8703 - unsigned long n);
8704 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8705 - unsigned long n);
8706 -
8707 -#endif /* __powerpc64__ */
8708 -
8709 static inline unsigned long __copy_from_user_inatomic(void *to,
8710 const void __user *from, unsigned long n)
8711 {
8712 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8713 if (ret == 0)
8714 return 0;
8715 }
8716 +
8717 + if (!__builtin_constant_p(n))
8718 + check_object_size(to, n, false);
8719 +
8720 return __copy_tofrom_user((__force void __user *)to, from, n);
8721 }
8722
8723 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8724 if (ret == 0)
8725 return 0;
8726 }
8727 +
8728 + if (!__builtin_constant_p(n))
8729 + check_object_size(from, n, true);
8730 +
8731 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8732 }
8733
8734 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8735 return __copy_to_user_inatomic(to, from, size);
8736 }
8737
8738 +#ifndef __powerpc64__
8739 +
8740 +static inline unsigned long __must_check copy_from_user(void *to,
8741 + const void __user *from, unsigned long n)
8742 +{
8743 + unsigned long over;
8744 +
8745 + if ((long)n < 0)
8746 + return n;
8747 +
8748 + if (access_ok(VERIFY_READ, from, n)) {
8749 + if (!__builtin_constant_p(n))
8750 + check_object_size(to, n, false);
8751 + return __copy_tofrom_user((__force void __user *)to, from, n);
8752 + }
8753 + if ((unsigned long)from < TASK_SIZE) {
8754 + over = (unsigned long)from + n - TASK_SIZE;
8755 + if (!__builtin_constant_p(n - over))
8756 + check_object_size(to, n - over, false);
8757 + return __copy_tofrom_user((__force void __user *)to, from,
8758 + n - over) + over;
8759 + }
8760 + return n;
8761 +}
8762 +
8763 +static inline unsigned long __must_check copy_to_user(void __user *to,
8764 + const void *from, unsigned long n)
8765 +{
8766 + unsigned long over;
8767 +
8768 + if ((long)n < 0)
8769 + return n;
8770 +
8771 + if (access_ok(VERIFY_WRITE, to, n)) {
8772 + if (!__builtin_constant_p(n))
8773 + check_object_size(from, n, true);
8774 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8775 + }
8776 + if ((unsigned long)to < TASK_SIZE) {
8777 + over = (unsigned long)to + n - TASK_SIZE;
8778 + if (!__builtin_constant_p(n))
8779 + check_object_size(from, n - over, true);
8780 + return __copy_tofrom_user(to, (__force void __user *)from,
8781 + n - over) + over;
8782 + }
8783 + return n;
8784 +}
8785 +
8786 +#else /* __powerpc64__ */
8787 +
8788 +#define __copy_in_user(to, from, size) \
8789 + __copy_tofrom_user((to), (from), (size))
8790 +
8791 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8792 +{
8793 + if ((long)n < 0 || n > INT_MAX)
8794 + return n;
8795 +
8796 + if (!__builtin_constant_p(n))
8797 + check_object_size(to, n, false);
8798 +
8799 + if (likely(access_ok(VERIFY_READ, from, n)))
8800 + n = __copy_from_user(to, from, n);
8801 + else
8802 + memset(to, 0, n);
8803 + return n;
8804 +}
8805 +
8806 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8807 +{
8808 + if ((long)n < 0 || n > INT_MAX)
8809 + return n;
8810 +
8811 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8812 + if (!__builtin_constant_p(n))
8813 + check_object_size(from, n, true);
8814 + n = __copy_to_user(to, from, n);
8815 + }
8816 + return n;
8817 +}
8818 +
8819 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8820 + unsigned long n);
8821 +
8822 +#endif /* __powerpc64__ */
8823 +
8824 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8825
8826 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8827 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8828 index 502cf69..822e63b 100644
8829 --- a/arch/powerpc/kernel/Makefile
8830 +++ b/arch/powerpc/kernel/Makefile
8831 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8832 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8833 endif
8834
8835 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8836 +
8837 obj-y := cputable.o ptrace.o syscalls.o \
8838 irq.o align.o signal_32.o pmc.o vdso.o \
8839 process.o systbl.o idle.o \
8840 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8841 index 3e68d1c..72a5ee6 100644
8842 --- a/arch/powerpc/kernel/exceptions-64e.S
8843 +++ b/arch/powerpc/kernel/exceptions-64e.S
8844 @@ -1010,6 +1010,7 @@ storage_fault_common:
8845 std r14,_DAR(r1)
8846 std r15,_DSISR(r1)
8847 addi r3,r1,STACK_FRAME_OVERHEAD
8848 + bl save_nvgprs
8849 mr r4,r14
8850 mr r5,r15
8851 ld r14,PACA_EXGEN+EX_R14(r13)
8852 @@ -1018,8 +1019,7 @@ storage_fault_common:
8853 cmpdi r3,0
8854 bne- 1f
8855 b ret_from_except_lite
8856 -1: bl save_nvgprs
8857 - mr r5,r3
8858 +1: mr r5,r3
8859 addi r3,r1,STACK_FRAME_OVERHEAD
8860 ld r4,_DAR(r1)
8861 bl bad_page_fault
8862 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8863 index 72e783e..fe058e2 100644
8864 --- a/arch/powerpc/kernel/exceptions-64s.S
8865 +++ b/arch/powerpc/kernel/exceptions-64s.S
8866 @@ -1588,10 +1588,10 @@ handle_page_fault:
8867 11: ld r4,_DAR(r1)
8868 ld r5,_DSISR(r1)
8869 addi r3,r1,STACK_FRAME_OVERHEAD
8870 + bl save_nvgprs
8871 bl do_page_fault
8872 cmpdi r3,0
8873 beq+ 12f
8874 - bl save_nvgprs
8875 mr r5,r3
8876 addi r3,r1,STACK_FRAME_OVERHEAD
8877 lwz r4,_DAR(r1)
8878 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8879 index c143835..5a9697f 100644
8880 --- a/arch/powerpc/kernel/irq.c
8881 +++ b/arch/powerpc/kernel/irq.c
8882 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8883 }
8884 #endif
8885
8886 +extern void gr_handle_kernel_exploit(void);
8887 +
8888 static inline void check_stack_overflow(void)
8889 {
8890 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8891 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8892 pr_err("do_IRQ: stack overflow: %ld\n",
8893 sp - sizeof(struct thread_info));
8894 dump_stack();
8895 + gr_handle_kernel_exploit();
8896 }
8897 #endif
8898 }
8899 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8900 index c94d2e0..992a9ce 100644
8901 --- a/arch/powerpc/kernel/module_32.c
8902 +++ b/arch/powerpc/kernel/module_32.c
8903 @@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8904 me->arch.core_plt_section = i;
8905 }
8906 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8907 - pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8908 + pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8909 return -ENOEXEC;
8910 }
8911
8912 @@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8913
8914 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8915 /* Init, or core PLT? */
8916 - if (location >= mod->module_core
8917 - && location < mod->module_core + mod->core_size)
8918 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8919 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8920 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8921 - else
8922 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8923 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8924 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8925 + else {
8926 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8927 + return ~0UL;
8928 + }
8929
8930 /* Find this entry, or if that fails, the next avail. entry */
8931 while (entry->jump[0]) {
8932 @@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8933 }
8934 #ifdef CONFIG_DYNAMIC_FTRACE
8935 module->arch.tramp =
8936 - do_plt_call(module->module_core,
8937 + do_plt_call(module->module_core_rx,
8938 (unsigned long)ftrace_caller,
8939 sechdrs, module);
8940 #endif
8941 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8942 index 923cd2d..ae782a9 100644
8943 --- a/arch/powerpc/kernel/process.c
8944 +++ b/arch/powerpc/kernel/process.c
8945 @@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8946 * Lookup NIP late so we have the best change of getting the
8947 * above info out without failing
8948 */
8949 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8950 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8951 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8952 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8953 #endif
8954 show_stack(current, (unsigned long *) regs->gpr[1]);
8955 if (!user_mode(regs))
8956 @@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8957 newsp = stack[0];
8958 ip = stack[STACK_FRAME_LR_SAVE];
8959 if (!firstframe || ip != lr) {
8960 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8961 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8962 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8963 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8964 - printk(" (%pS)",
8965 + printk(" (%pA)",
8966 (void *)current->ret_stack[curr_frame].ret);
8967 curr_frame--;
8968 }
8969 @@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8970 struct pt_regs *regs = (struct pt_regs *)
8971 (sp + STACK_FRAME_OVERHEAD);
8972 lr = regs->link;
8973 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8974 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8975 regs->trap, (void *)regs->nip, (void *)lr);
8976 firstframe = 1;
8977 }
8978 @@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8979 mtspr(SPRN_CTRLT, ctrl);
8980 }
8981 #endif /* CONFIG_PPC64 */
8982 -
8983 -unsigned long arch_align_stack(unsigned long sp)
8984 -{
8985 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8986 - sp -= get_random_int() & ~PAGE_MASK;
8987 - return sp & ~0xf;
8988 -}
8989 -
8990 -static inline unsigned long brk_rnd(void)
8991 -{
8992 - unsigned long rnd = 0;
8993 -
8994 - /* 8MB for 32bit, 1GB for 64bit */
8995 - if (is_32bit_task())
8996 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8997 - else
8998 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8999 -
9000 - return rnd << PAGE_SHIFT;
9001 -}
9002 -
9003 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9004 -{
9005 - unsigned long base = mm->brk;
9006 - unsigned long ret;
9007 -
9008 -#ifdef CONFIG_PPC_STD_MMU_64
9009 - /*
9010 - * If we are using 1TB segments and we are allowed to randomise
9011 - * the heap, we can put it above 1TB so it is backed by a 1TB
9012 - * segment. Otherwise the heap will be in the bottom 1TB
9013 - * which always uses 256MB segments and this may result in a
9014 - * performance penalty.
9015 - */
9016 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9017 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9018 -#endif
9019 -
9020 - ret = PAGE_ALIGN(base + brk_rnd());
9021 -
9022 - if (ret < mm->brk)
9023 - return mm->brk;
9024 -
9025 - return ret;
9026 -}
9027 -
9028 -unsigned long randomize_et_dyn(unsigned long base)
9029 -{
9030 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9031 -
9032 - if (ret < base)
9033 - return base;
9034 -
9035 - return ret;
9036 -}
9037 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9038 index f21897b..28c0428 100644
9039 --- a/arch/powerpc/kernel/ptrace.c
9040 +++ b/arch/powerpc/kernel/ptrace.c
9041 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9042 return ret;
9043 }
9044
9045 +#ifdef CONFIG_GRKERNSEC_SETXID
9046 +extern void gr_delayed_cred_worker(void);
9047 +#endif
9048 +
9049 /*
9050 * We must return the syscall number to actually look up in the table.
9051 * This can be -1L to skip running any syscall at all.
9052 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9053
9054 secure_computing_strict(regs->gpr[0]);
9055
9056 +#ifdef CONFIG_GRKERNSEC_SETXID
9057 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9058 + gr_delayed_cred_worker();
9059 +#endif
9060 +
9061 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9062 tracehook_report_syscall_entry(regs))
9063 /*
9064 @@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9065 {
9066 int step;
9067
9068 +#ifdef CONFIG_GRKERNSEC_SETXID
9069 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9070 + gr_delayed_cred_worker();
9071 +#endif
9072 +
9073 audit_syscall_exit(regs);
9074
9075 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9076 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9077 index b171001..4ac7ac5 100644
9078 --- a/arch/powerpc/kernel/signal_32.c
9079 +++ b/arch/powerpc/kernel/signal_32.c
9080 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9081 /* Save user registers on the stack */
9082 frame = &rt_sf->uc.uc_mcontext;
9083 addr = frame;
9084 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9085 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9086 sigret = 0;
9087 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9088 } else {
9089 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9090 index 2cb0c94..c0c0bc9 100644
9091 --- a/arch/powerpc/kernel/signal_64.c
9092 +++ b/arch/powerpc/kernel/signal_64.c
9093 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9094 current->thread.fp_state.fpscr = 0;
9095
9096 /* Set up to return from userspace. */
9097 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9098 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9099 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9100 } else {
9101 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9102 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9103 index 0dc43f9..a885d33 100644
9104 --- a/arch/powerpc/kernel/traps.c
9105 +++ b/arch/powerpc/kernel/traps.c
9106 @@ -36,6 +36,7 @@
9107 #include <linux/debugfs.h>
9108 #include <linux/ratelimit.h>
9109 #include <linux/context_tracking.h>
9110 +#include <linux/uaccess.h>
9111
9112 #include <asm/emulated_ops.h>
9113 #include <asm/pgtable.h>
9114 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9115 return flags;
9116 }
9117
9118 +extern void gr_handle_kernel_exploit(void);
9119 +
9120 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9121 int signr)
9122 {
9123 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9124 panic("Fatal exception in interrupt");
9125 if (panic_on_oops)
9126 panic("Fatal exception");
9127 +
9128 + gr_handle_kernel_exploit();
9129 +
9130 do_exit(signr);
9131 }
9132
9133 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9134 enum ctx_state prev_state = exception_enter();
9135 unsigned int reason = get_reason(regs);
9136
9137 +#ifdef CONFIG_PAX_REFCOUNT
9138 + unsigned int bkpt;
9139 + const struct exception_table_entry *entry;
9140 +
9141 + if (reason & REASON_ILLEGAL) {
9142 + /* Check if PaX bad instruction */
9143 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9144 + current->thread.trap_nr = 0;
9145 + pax_report_refcount_overflow(regs);
9146 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9147 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9148 + regs->nip = entry->fixup;
9149 + return;
9150 + }
9151 + /* fixup_exception() could not handle */
9152 + goto bail;
9153 + }
9154 + }
9155 +#endif
9156 +
9157 /* We can now get here via a FP Unavailable exception if the core
9158 * has no FPU, in that case the reason flags will be 0 */
9159
9160 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9161 index f174351..5722009 100644
9162 --- a/arch/powerpc/kernel/vdso.c
9163 +++ b/arch/powerpc/kernel/vdso.c
9164 @@ -35,6 +35,7 @@
9165 #include <asm/vdso.h>
9166 #include <asm/vdso_datapage.h>
9167 #include <asm/setup.h>
9168 +#include <asm/mman.h>
9169
9170 #undef DEBUG
9171
9172 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9173 vdso_base = VDSO32_MBASE;
9174 #endif
9175
9176 - current->mm->context.vdso_base = 0;
9177 + current->mm->context.vdso_base = ~0UL;
9178
9179 /* vDSO has a problem and was disabled, just don't "enable" it for the
9180 * process
9181 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9182 vdso_base = get_unmapped_area(NULL, vdso_base,
9183 (vdso_pages << PAGE_SHIFT) +
9184 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9185 - 0, 0);
9186 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9187 if (IS_ERR_VALUE(vdso_base)) {
9188 rc = vdso_base;
9189 goto fail_mmapsem;
9190 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9191 index c1f8f53..71a3b96 100644
9192 --- a/arch/powerpc/kvm/powerpc.c
9193 +++ b/arch/powerpc/kvm/powerpc.c
9194 @@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9195 }
9196 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9197
9198 -int kvm_arch_init(void *opaque)
9199 +int kvm_arch_init(const void *opaque)
9200 {
9201 return 0;
9202 }
9203 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9204 index 5eea6f3..5d10396 100644
9205 --- a/arch/powerpc/lib/usercopy_64.c
9206 +++ b/arch/powerpc/lib/usercopy_64.c
9207 @@ -9,22 +9,6 @@
9208 #include <linux/module.h>
9209 #include <asm/uaccess.h>
9210
9211 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9212 -{
9213 - if (likely(access_ok(VERIFY_READ, from, n)))
9214 - n = __copy_from_user(to, from, n);
9215 - else
9216 - memset(to, 0, n);
9217 - return n;
9218 -}
9219 -
9220 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9221 -{
9222 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9223 - n = __copy_to_user(to, from, n);
9224 - return n;
9225 -}
9226 -
9227 unsigned long copy_in_user(void __user *to, const void __user *from,
9228 unsigned long n)
9229 {
9230 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9231 return n;
9232 }
9233
9234 -EXPORT_SYMBOL(copy_from_user);
9235 -EXPORT_SYMBOL(copy_to_user);
9236 EXPORT_SYMBOL(copy_in_user);
9237
9238 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9239 index f06b56b..ffb2fb4 100644
9240 --- a/arch/powerpc/mm/fault.c
9241 +++ b/arch/powerpc/mm/fault.c
9242 @@ -33,6 +33,10 @@
9243 #include <linux/ratelimit.h>
9244 #include <linux/context_tracking.h>
9245 #include <linux/hugetlb.h>
9246 +#include <linux/slab.h>
9247 +#include <linux/pagemap.h>
9248 +#include <linux/compiler.h>
9249 +#include <linux/unistd.h>
9250
9251 #include <asm/firmware.h>
9252 #include <asm/page.h>
9253 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9254 }
9255 #endif
9256
9257 +#ifdef CONFIG_PAX_PAGEEXEC
9258 +/*
9259 + * PaX: decide what to do with offenders (regs->nip = fault address)
9260 + *
9261 + * returns 1 when task should be killed
9262 + */
9263 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9264 +{
9265 + return 1;
9266 +}
9267 +
9268 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9269 +{
9270 + unsigned long i;
9271 +
9272 + printk(KERN_ERR "PAX: bytes at PC: ");
9273 + for (i = 0; i < 5; i++) {
9274 + unsigned int c;
9275 + if (get_user(c, (unsigned int __user *)pc+i))
9276 + printk(KERN_CONT "???????? ");
9277 + else
9278 + printk(KERN_CONT "%08x ", c);
9279 + }
9280 + printk("\n");
9281 +}
9282 +#endif
9283 +
9284 /*
9285 * Check whether the instruction at regs->nip is a store using
9286 * an update addressing form which will update r1.
9287 @@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9288 * indicate errors in DSISR but can validly be set in SRR1.
9289 */
9290 if (trap == 0x400)
9291 - error_code &= 0x48200000;
9292 + error_code &= 0x58200000;
9293 else
9294 is_write = error_code & DSISR_ISSTORE;
9295 #else
9296 @@ -390,7 +421,7 @@ good_area:
9297 * "undefined". Of those that can be set, this is the only
9298 * one which seems bad.
9299 */
9300 - if (error_code & 0x10000000)
9301 + if (error_code & DSISR_GUARDED)
9302 /* Guarded storage error. */
9303 goto bad_area;
9304 #endif /* CONFIG_8xx */
9305 @@ -405,7 +436,7 @@ good_area:
9306 * processors use the same I/D cache coherency mechanism
9307 * as embedded.
9308 */
9309 - if (error_code & DSISR_PROTFAULT)
9310 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9311 goto bad_area;
9312 #endif /* CONFIG_PPC_STD_MMU */
9313
9314 @@ -497,6 +528,23 @@ bad_area:
9315 bad_area_nosemaphore:
9316 /* User mode accesses cause a SIGSEGV */
9317 if (user_mode(regs)) {
9318 +
9319 +#ifdef CONFIG_PAX_PAGEEXEC
9320 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9321 +#ifdef CONFIG_PPC_STD_MMU
9322 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9323 +#else
9324 + if (is_exec && regs->nip == address) {
9325 +#endif
9326 + switch (pax_handle_fetch_fault(regs)) {
9327 + }
9328 +
9329 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9330 + do_group_exit(SIGKILL);
9331 + }
9332 + }
9333 +#endif
9334 +
9335 _exception(SIGSEGV, regs, code, address);
9336 goto bail;
9337 }
9338 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9339 index cb8bdbe..cde4bc7 100644
9340 --- a/arch/powerpc/mm/mmap.c
9341 +++ b/arch/powerpc/mm/mmap.c
9342 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9343 return sysctl_legacy_va_layout;
9344 }
9345
9346 -static unsigned long mmap_rnd(void)
9347 +static unsigned long mmap_rnd(struct mm_struct *mm)
9348 {
9349 unsigned long rnd = 0;
9350
9351 +#ifdef CONFIG_PAX_RANDMMAP
9352 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9353 +#endif
9354 +
9355 if (current->flags & PF_RANDOMIZE) {
9356 /* 8MB for 32bit, 1GB for 64bit */
9357 if (is_32bit_task())
9358 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9359 return rnd << PAGE_SHIFT;
9360 }
9361
9362 -static inline unsigned long mmap_base(void)
9363 +static inline unsigned long mmap_base(struct mm_struct *mm)
9364 {
9365 unsigned long gap = rlimit(RLIMIT_STACK);
9366
9367 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9368 else if (gap > MAX_GAP)
9369 gap = MAX_GAP;
9370
9371 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9372 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9373 }
9374
9375 /*
9376 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9377 */
9378 if (mmap_is_legacy()) {
9379 mm->mmap_base = TASK_UNMAPPED_BASE;
9380 +
9381 +#ifdef CONFIG_PAX_RANDMMAP
9382 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9383 + mm->mmap_base += mm->delta_mmap;
9384 +#endif
9385 +
9386 mm->get_unmapped_area = arch_get_unmapped_area;
9387 } else {
9388 - mm->mmap_base = mmap_base();
9389 + mm->mmap_base = mmap_base(mm);
9390 +
9391 +#ifdef CONFIG_PAX_RANDMMAP
9392 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9393 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9394 +#endif
9395 +
9396 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9397 }
9398 }
9399 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9400 index ded0ea1..f213a9b 100644
9401 --- a/arch/powerpc/mm/slice.c
9402 +++ b/arch/powerpc/mm/slice.c
9403 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9404 if ((mm->task_size - len) < addr)
9405 return 0;
9406 vma = find_vma(mm, addr);
9407 - return (!vma || (addr + len) <= vma->vm_start);
9408 + return check_heap_stack_gap(vma, addr, len, 0);
9409 }
9410
9411 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9412 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9413 info.align_offset = 0;
9414
9415 addr = TASK_UNMAPPED_BASE;
9416 +
9417 +#ifdef CONFIG_PAX_RANDMMAP
9418 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9419 + addr += mm->delta_mmap;
9420 +#endif
9421 +
9422 while (addr < TASK_SIZE) {
9423 info.low_limit = addr;
9424 if (!slice_scan_available(addr, available, 1, &addr))
9425 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9426 if (fixed && addr > (mm->task_size - len))
9427 return -ENOMEM;
9428
9429 +#ifdef CONFIG_PAX_RANDMMAP
9430 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9431 + addr = 0;
9432 +#endif
9433 +
9434 /* If hint, make sure it matches our alignment restrictions */
9435 if (!fixed && addr) {
9436 addr = _ALIGN_UP(addr, 1ul << pshift);
9437 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9438 index 4278acf..67fd0e6 100644
9439 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9440 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9441 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9442 }
9443
9444 static struct pci_ops scc_pciex_pci_ops = {
9445 - scc_pciex_read_config,
9446 - scc_pciex_write_config,
9447 + .read = scc_pciex_read_config,
9448 + .write = scc_pciex_write_config,
9449 };
9450
9451 static void pciex_clear_intr_all(unsigned int __iomem *base)
9452 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9453 index d966bbe..372124a 100644
9454 --- a/arch/powerpc/platforms/cell/spufs/file.c
9455 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9456 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9457 return VM_FAULT_NOPAGE;
9458 }
9459
9460 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9461 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9462 unsigned long address,
9463 - void *buf, int len, int write)
9464 + void *buf, size_t len, int write)
9465 {
9466 struct spu_context *ctx = vma->vm_file->private_data;
9467 unsigned long offset = address - vma->vm_start;
9468 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9469 index fa934fe..c296056 100644
9470 --- a/arch/s390/include/asm/atomic.h
9471 +++ b/arch/s390/include/asm/atomic.h
9472 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9473 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9474 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9475
9476 +#define atomic64_read_unchecked(v) atomic64_read(v)
9477 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9478 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9479 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9480 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9481 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9482 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9483 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9484 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9485 +
9486 #endif /* __ARCH_S390_ATOMIC__ */
9487 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9488 index b5dce65..8aca09a 100644
9489 --- a/arch/s390/include/asm/barrier.h
9490 +++ b/arch/s390/include/asm/barrier.h
9491 @@ -39,7 +39,7 @@
9492 do { \
9493 compiletime_assert_atomic_type(*p); \
9494 barrier(); \
9495 - ACCESS_ONCE(*p) = (v); \
9496 + ACCESS_ONCE_RW(*p) = (v); \
9497 } while (0)
9498
9499 #define smp_load_acquire(p) \
9500 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9501 index 4d7ccac..d03d0ad 100644
9502 --- a/arch/s390/include/asm/cache.h
9503 +++ b/arch/s390/include/asm/cache.h
9504 @@ -9,8 +9,10 @@
9505 #ifndef __ARCH_S390_CACHE_H
9506 #define __ARCH_S390_CACHE_H
9507
9508 -#define L1_CACHE_BYTES 256
9509 +#include <linux/const.h>
9510 +
9511 #define L1_CACHE_SHIFT 8
9512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9513 #define NET_SKB_PAD 32
9514
9515 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9516 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9517 index f6e43d3..5f57681 100644
9518 --- a/arch/s390/include/asm/elf.h
9519 +++ b/arch/s390/include/asm/elf.h
9520 @@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9521 the loader. We need to make sure that it is out of the way of the program
9522 that it will "exec", and that there is sufficient room for the brk. */
9523
9524 -extern unsigned long randomize_et_dyn(unsigned long base);
9525 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9526 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9527 +
9528 +#ifdef CONFIG_PAX_ASLR
9529 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9530 +
9531 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9532 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9533 +#endif
9534
9535 /* This yields a mask that user programs can use to figure out what
9536 instruction set this CPU supports. */
9537 @@ -223,9 +229,6 @@ struct linux_binprm;
9538 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9539 int arch_setup_additional_pages(struct linux_binprm *, int);
9540
9541 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9542 -#define arch_randomize_brk arch_randomize_brk
9543 -
9544 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9545
9546 #endif
9547 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9548 index c4a93d6..4d2a9b4 100644
9549 --- a/arch/s390/include/asm/exec.h
9550 +++ b/arch/s390/include/asm/exec.h
9551 @@ -7,6 +7,6 @@
9552 #ifndef __ASM_EXEC_H
9553 #define __ASM_EXEC_H
9554
9555 -extern unsigned long arch_align_stack(unsigned long sp);
9556 +#define arch_align_stack(x) ((x) & ~0xfUL)
9557
9558 #endif /* __ASM_EXEC_H */
9559 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9560 index cd4c68e..6764641 100644
9561 --- a/arch/s390/include/asm/uaccess.h
9562 +++ b/arch/s390/include/asm/uaccess.h
9563 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9564 __range_ok((unsigned long)(addr), (size)); \
9565 })
9566
9567 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9568 #define access_ok(type, addr, size) __access_ok(addr, size)
9569
9570 /*
9571 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9572 copy_to_user(void __user *to, const void *from, unsigned long n)
9573 {
9574 might_fault();
9575 +
9576 + if ((long)n < 0)
9577 + return n;
9578 +
9579 return __copy_to_user(to, from, n);
9580 }
9581
9582 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9583 static inline unsigned long __must_check
9584 copy_from_user(void *to, const void __user *from, unsigned long n)
9585 {
9586 - unsigned int sz = __compiletime_object_size(to);
9587 + size_t sz = __compiletime_object_size(to);
9588
9589 might_fault();
9590 - if (unlikely(sz != -1 && sz < n)) {
9591 +
9592 + if ((long)n < 0)
9593 + return n;
9594 +
9595 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9596 copy_from_user_overflow();
9597 return n;
9598 }
9599 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9600 index b89b591..fd9609d 100644
9601 --- a/arch/s390/kernel/module.c
9602 +++ b/arch/s390/kernel/module.c
9603 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9604
9605 /* Increase core size by size of got & plt and set start
9606 offsets for got and plt. */
9607 - me->core_size = ALIGN(me->core_size, 4);
9608 - me->arch.got_offset = me->core_size;
9609 - me->core_size += me->arch.got_size;
9610 - me->arch.plt_offset = me->core_size;
9611 - me->core_size += me->arch.plt_size;
9612 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9613 + me->arch.got_offset = me->core_size_rw;
9614 + me->core_size_rw += me->arch.got_size;
9615 + me->arch.plt_offset = me->core_size_rx;
9616 + me->core_size_rx += me->arch.plt_size;
9617 return 0;
9618 }
9619
9620 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9621 if (info->got_initialized == 0) {
9622 Elf_Addr *gotent;
9623
9624 - gotent = me->module_core + me->arch.got_offset +
9625 + gotent = me->module_core_rw + me->arch.got_offset +
9626 info->got_offset;
9627 *gotent = val;
9628 info->got_initialized = 1;
9629 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9630 rc = apply_rela_bits(loc, val, 0, 64, 0);
9631 else if (r_type == R_390_GOTENT ||
9632 r_type == R_390_GOTPLTENT) {
9633 - val += (Elf_Addr) me->module_core - loc;
9634 + val += (Elf_Addr) me->module_core_rw - loc;
9635 rc = apply_rela_bits(loc, val, 1, 32, 1);
9636 }
9637 break;
9638 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9639 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9640 if (info->plt_initialized == 0) {
9641 unsigned int *ip;
9642 - ip = me->module_core + me->arch.plt_offset +
9643 + ip = me->module_core_rx + me->arch.plt_offset +
9644 info->plt_offset;
9645 #ifndef CONFIG_64BIT
9646 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9647 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9648 val - loc + 0xffffUL < 0x1ffffeUL) ||
9649 (r_type == R_390_PLT32DBL &&
9650 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9651 - val = (Elf_Addr) me->module_core +
9652 + val = (Elf_Addr) me->module_core_rx +
9653 me->arch.plt_offset +
9654 info->plt_offset;
9655 val += rela->r_addend - loc;
9656 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9657 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9658 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9659 val = val + rela->r_addend -
9660 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9661 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9662 if (r_type == R_390_GOTOFF16)
9663 rc = apply_rela_bits(loc, val, 0, 16, 0);
9664 else if (r_type == R_390_GOTOFF32)
9665 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9666 break;
9667 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9668 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9669 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9670 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9671 rela->r_addend - loc;
9672 if (r_type == R_390_GOTPC)
9673 rc = apply_rela_bits(loc, val, 1, 32, 0);
9674 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9675 index ed84cc2..c05a9d2 100644
9676 --- a/arch/s390/kernel/process.c
9677 +++ b/arch/s390/kernel/process.c
9678 @@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9679 }
9680 return 0;
9681 }
9682 -
9683 -unsigned long arch_align_stack(unsigned long sp)
9684 -{
9685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9686 - sp -= get_random_int() & ~PAGE_MASK;
9687 - return sp & ~0xf;
9688 -}
9689 -
9690 -static inline unsigned long brk_rnd(void)
9691 -{
9692 - /* 8MB for 32bit, 1GB for 64bit */
9693 - if (is_32bit_task())
9694 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9695 - else
9696 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9697 -}
9698 -
9699 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9700 -{
9701 - unsigned long ret;
9702 -
9703 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9704 - return (ret > mm->brk) ? ret : mm->brk;
9705 -}
9706 -
9707 -unsigned long randomize_et_dyn(unsigned long base)
9708 -{
9709 - unsigned long ret;
9710 -
9711 - if (!(current->flags & PF_RANDOMIZE))
9712 - return base;
9713 - ret = PAGE_ALIGN(base + brk_rnd());
9714 - return (ret > base) ? ret : base;
9715 -}
9716 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9717 index 9b436c2..54fbf0a 100644
9718 --- a/arch/s390/mm/mmap.c
9719 +++ b/arch/s390/mm/mmap.c
9720 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9721 */
9722 if (mmap_is_legacy()) {
9723 mm->mmap_base = mmap_base_legacy();
9724 +
9725 +#ifdef CONFIG_PAX_RANDMMAP
9726 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9727 + mm->mmap_base += mm->delta_mmap;
9728 +#endif
9729 +
9730 mm->get_unmapped_area = arch_get_unmapped_area;
9731 } else {
9732 mm->mmap_base = mmap_base();
9733 +
9734 +#ifdef CONFIG_PAX_RANDMMAP
9735 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9736 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9737 +#endif
9738 +
9739 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9740 }
9741 }
9742 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9743 */
9744 if (mmap_is_legacy()) {
9745 mm->mmap_base = mmap_base_legacy();
9746 +
9747 +#ifdef CONFIG_PAX_RANDMMAP
9748 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9749 + mm->mmap_base += mm->delta_mmap;
9750 +#endif
9751 +
9752 mm->get_unmapped_area = s390_get_unmapped_area;
9753 } else {
9754 mm->mmap_base = mmap_base();
9755 +
9756 +#ifdef CONFIG_PAX_RANDMMAP
9757 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9758 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9759 +#endif
9760 +
9761 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9762 }
9763 }
9764 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9765 index ae3d59f..f65f075 100644
9766 --- a/arch/score/include/asm/cache.h
9767 +++ b/arch/score/include/asm/cache.h
9768 @@ -1,7 +1,9 @@
9769 #ifndef _ASM_SCORE_CACHE_H
9770 #define _ASM_SCORE_CACHE_H
9771
9772 +#include <linux/const.h>
9773 +
9774 #define L1_CACHE_SHIFT 4
9775 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9776 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9777
9778 #endif /* _ASM_SCORE_CACHE_H */
9779 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9780 index f9f3cd5..58ff438 100644
9781 --- a/arch/score/include/asm/exec.h
9782 +++ b/arch/score/include/asm/exec.h
9783 @@ -1,6 +1,6 @@
9784 #ifndef _ASM_SCORE_EXEC_H
9785 #define _ASM_SCORE_EXEC_H
9786
9787 -extern unsigned long arch_align_stack(unsigned long sp);
9788 +#define arch_align_stack(x) (x)
9789
9790 #endif /* _ASM_SCORE_EXEC_H */
9791 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9792 index a1519ad3..e8ac1ff 100644
9793 --- a/arch/score/kernel/process.c
9794 +++ b/arch/score/kernel/process.c
9795 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9796
9797 return task_pt_regs(task)->cp0_epc;
9798 }
9799 -
9800 -unsigned long arch_align_stack(unsigned long sp)
9801 -{
9802 - return sp;
9803 -}
9804 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9805 index ef9e555..331bd29 100644
9806 --- a/arch/sh/include/asm/cache.h
9807 +++ b/arch/sh/include/asm/cache.h
9808 @@ -9,10 +9,11 @@
9809 #define __ASM_SH_CACHE_H
9810 #ifdef __KERNEL__
9811
9812 +#include <linux/const.h>
9813 #include <linux/init.h>
9814 #include <cpu/cache.h>
9815
9816 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9817 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9818
9819 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9820
9821 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9822 index 6777177..cb5e44f 100644
9823 --- a/arch/sh/mm/mmap.c
9824 +++ b/arch/sh/mm/mmap.c
9825 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9826 struct mm_struct *mm = current->mm;
9827 struct vm_area_struct *vma;
9828 int do_colour_align;
9829 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9830 struct vm_unmapped_area_info info;
9831
9832 if (flags & MAP_FIXED) {
9833 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9834 if (filp || (flags & MAP_SHARED))
9835 do_colour_align = 1;
9836
9837 +#ifdef CONFIG_PAX_RANDMMAP
9838 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9839 +#endif
9840 +
9841 if (addr) {
9842 if (do_colour_align)
9843 addr = COLOUR_ALIGN(addr, pgoff);
9844 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9845 addr = PAGE_ALIGN(addr);
9846
9847 vma = find_vma(mm, addr);
9848 - if (TASK_SIZE - len >= addr &&
9849 - (!vma || addr + len <= vma->vm_start))
9850 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9851 return addr;
9852 }
9853
9854 info.flags = 0;
9855 info.length = len;
9856 - info.low_limit = TASK_UNMAPPED_BASE;
9857 + info.low_limit = mm->mmap_base;
9858 info.high_limit = TASK_SIZE;
9859 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9860 info.align_offset = pgoff << PAGE_SHIFT;
9861 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9862 struct mm_struct *mm = current->mm;
9863 unsigned long addr = addr0;
9864 int do_colour_align;
9865 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9866 struct vm_unmapped_area_info info;
9867
9868 if (flags & MAP_FIXED) {
9869 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9870 if (filp || (flags & MAP_SHARED))
9871 do_colour_align = 1;
9872
9873 +#ifdef CONFIG_PAX_RANDMMAP
9874 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9875 +#endif
9876 +
9877 /* requesting a specific address */
9878 if (addr) {
9879 if (do_colour_align)
9880 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9881 addr = PAGE_ALIGN(addr);
9882
9883 vma = find_vma(mm, addr);
9884 - if (TASK_SIZE - len >= addr &&
9885 - (!vma || addr + len <= vma->vm_start))
9886 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9887 return addr;
9888 }
9889
9890 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9891 VM_BUG_ON(addr != -ENOMEM);
9892 info.flags = 0;
9893 info.low_limit = TASK_UNMAPPED_BASE;
9894 +
9895 +#ifdef CONFIG_PAX_RANDMMAP
9896 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9897 + info.low_limit += mm->delta_mmap;
9898 +#endif
9899 +
9900 info.high_limit = TASK_SIZE;
9901 addr = vm_unmapped_area(&info);
9902 }
9903 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9904 index 4082749..fd97781 100644
9905 --- a/arch/sparc/include/asm/atomic_64.h
9906 +++ b/arch/sparc/include/asm/atomic_64.h
9907 @@ -15,18 +15,38 @@
9908 #define ATOMIC64_INIT(i) { (i) }
9909
9910 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9911 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9912 +{
9913 + return ACCESS_ONCE(v->counter);
9914 +}
9915 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9916 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9917 +{
9918 + return ACCESS_ONCE(v->counter);
9919 +}
9920
9921 #define atomic_set(v, i) (((v)->counter) = i)
9922 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9923 +{
9924 + v->counter = i;
9925 +}
9926 #define atomic64_set(v, i) (((v)->counter) = i)
9927 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9928 +{
9929 + v->counter = i;
9930 +}
9931
9932 -#define ATOMIC_OP(op) \
9933 -void atomic_##op(int, atomic_t *); \
9934 -void atomic64_##op(long, atomic64_t *);
9935 +#define __ATOMIC_OP(op, suffix) \
9936 +void atomic_##op##suffix(int, atomic##suffix##_t *); \
9937 +void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9938
9939 -#define ATOMIC_OP_RETURN(op) \
9940 -int atomic_##op##_return(int, atomic_t *); \
9941 -long atomic64_##op##_return(long, atomic64_t *);
9942 +#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9943 +
9944 +#define __ATOMIC_OP_RETURN(op, suffix) \
9945 +int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9946 +long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9947 +
9948 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9949
9950 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9951
9952 @@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9953
9954 #undef ATOMIC_OPS
9955 #undef ATOMIC_OP_RETURN
9956 +#undef __ATOMIC_OP_RETURN
9957 #undef ATOMIC_OP
9958 +#undef __ATOMIC_OP
9959
9960 #define atomic_dec_return(v) atomic_sub_return(1, v)
9961 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9962
9963 #define atomic_inc_return(v) atomic_add_return(1, v)
9964 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9965 +{
9966 + return atomic_add_return_unchecked(1, v);
9967 +}
9968 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9969 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9970 +{
9971 + return atomic64_add_return_unchecked(1, v);
9972 +}
9973
9974 /*
9975 * atomic_inc_and_test - increment and test
9976 @@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9977 * other cases.
9978 */
9979 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9980 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9981 +{
9982 + return atomic_inc_return_unchecked(v) == 0;
9983 +}
9984 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9985
9986 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9987 @@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9988 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9989
9990 #define atomic_inc(v) atomic_add(1, v)
9991 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9992 +{
9993 + atomic_add_unchecked(1, v);
9994 +}
9995 #define atomic64_inc(v) atomic64_add(1, v)
9996 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9997 +{
9998 + atomic64_add_unchecked(1, v);
9999 +}
10000
10001 #define atomic_dec(v) atomic_sub(1, v)
10002 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10003 +{
10004 + atomic_sub_unchecked(1, v);
10005 +}
10006 #define atomic64_dec(v) atomic64_sub(1, v)
10007 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10008 +{
10009 + atomic64_sub_unchecked(1, v);
10010 +}
10011
10012 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10013 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10014
10015 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10016 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10017 +{
10018 + return cmpxchg(&v->counter, old, new);
10019 +}
10020 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10021 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10022 +{
10023 + return xchg(&v->counter, new);
10024 +}
10025
10026 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10027 {
10028 - int c, old;
10029 + int c, old, new;
10030 c = atomic_read(v);
10031 for (;;) {
10032 - if (unlikely(c == (u)))
10033 + if (unlikely(c == u))
10034 break;
10035 - old = atomic_cmpxchg((v), c, c + (a));
10036 +
10037 + asm volatile("addcc %2, %0, %0\n"
10038 +
10039 +#ifdef CONFIG_PAX_REFCOUNT
10040 + "tvs %%icc, 6\n"
10041 +#endif
10042 +
10043 + : "=r" (new)
10044 + : "0" (c), "ir" (a)
10045 + : "cc");
10046 +
10047 + old = atomic_cmpxchg(v, c, new);
10048 if (likely(old == c))
10049 break;
10050 c = old;
10051 @@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10052 #define atomic64_cmpxchg(v, o, n) \
10053 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10054 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10055 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10056 +{
10057 + return xchg(&v->counter, new);
10058 +}
10059
10060 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10061 {
10062 - long c, old;
10063 + long c, old, new;
10064 c = atomic64_read(v);
10065 for (;;) {
10066 - if (unlikely(c == (u)))
10067 + if (unlikely(c == u))
10068 break;
10069 - old = atomic64_cmpxchg((v), c, c + (a));
10070 +
10071 + asm volatile("addcc %2, %0, %0\n"
10072 +
10073 +#ifdef CONFIG_PAX_REFCOUNT
10074 + "tvs %%xcc, 6\n"
10075 +#endif
10076 +
10077 + : "=r" (new)
10078 + : "0" (c), "ir" (a)
10079 + : "cc");
10080 +
10081 + old = atomic64_cmpxchg(v, c, new);
10082 if (likely(old == c))
10083 break;
10084 c = old;
10085 }
10086 - return c != (u);
10087 + return c != u;
10088 }
10089
10090 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10091 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10092 index 305dcc3..7835030 100644
10093 --- a/arch/sparc/include/asm/barrier_64.h
10094 +++ b/arch/sparc/include/asm/barrier_64.h
10095 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10096 do { \
10097 compiletime_assert_atomic_type(*p); \
10098 barrier(); \
10099 - ACCESS_ONCE(*p) = (v); \
10100 + ACCESS_ONCE_RW(*p) = (v); \
10101 } while (0)
10102
10103 #define smp_load_acquire(p) \
10104 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10105 index 5bb6991..5c2132e 100644
10106 --- a/arch/sparc/include/asm/cache.h
10107 +++ b/arch/sparc/include/asm/cache.h
10108 @@ -7,10 +7,12 @@
10109 #ifndef _SPARC_CACHE_H
10110 #define _SPARC_CACHE_H
10111
10112 +#include <linux/const.h>
10113 +
10114 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10115
10116 #define L1_CACHE_SHIFT 5
10117 -#define L1_CACHE_BYTES 32
10118 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10119
10120 #ifdef CONFIG_SPARC32
10121 #define SMP_CACHE_BYTES_SHIFT 5
10122 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10123 index a24e41f..47677ff 100644
10124 --- a/arch/sparc/include/asm/elf_32.h
10125 +++ b/arch/sparc/include/asm/elf_32.h
10126 @@ -114,6 +114,13 @@ typedef struct {
10127
10128 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10129
10130 +#ifdef CONFIG_PAX_ASLR
10131 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10132 +
10133 +#define PAX_DELTA_MMAP_LEN 16
10134 +#define PAX_DELTA_STACK_LEN 16
10135 +#endif
10136 +
10137 /* This yields a mask that user programs can use to figure out what
10138 instruction set this cpu supports. This can NOT be done in userspace
10139 on Sparc. */
10140 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10141 index 370ca1e..d4f4a98 100644
10142 --- a/arch/sparc/include/asm/elf_64.h
10143 +++ b/arch/sparc/include/asm/elf_64.h
10144 @@ -189,6 +189,13 @@ typedef struct {
10145 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10146 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10147
10148 +#ifdef CONFIG_PAX_ASLR
10149 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10150 +
10151 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10152 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10153 +#endif
10154 +
10155 extern unsigned long sparc64_elf_hwcap;
10156 #define ELF_HWCAP sparc64_elf_hwcap
10157
10158 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10159 index a3890da..f6a408e 100644
10160 --- a/arch/sparc/include/asm/pgalloc_32.h
10161 +++ b/arch/sparc/include/asm/pgalloc_32.h
10162 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10163 }
10164
10165 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10166 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10167
10168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10169 unsigned long address)
10170 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10171 index 5e31871..13469c6 100644
10172 --- a/arch/sparc/include/asm/pgalloc_64.h
10173 +++ b/arch/sparc/include/asm/pgalloc_64.h
10174 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10175 }
10176
10177 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10178 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10179
10180 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10181 {
10182 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10183 }
10184
10185 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10186 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10187
10188 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10189 {
10190 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10191 index 59ba6f6..4518128 100644
10192 --- a/arch/sparc/include/asm/pgtable.h
10193 +++ b/arch/sparc/include/asm/pgtable.h
10194 @@ -5,4 +5,8 @@
10195 #else
10196 #include <asm/pgtable_32.h>
10197 #endif
10198 +
10199 +#define ktla_ktva(addr) (addr)
10200 +#define ktva_ktla(addr) (addr)
10201 +
10202 #endif
10203 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10204 index b9b91ae..950b91e 100644
10205 --- a/arch/sparc/include/asm/pgtable_32.h
10206 +++ b/arch/sparc/include/asm/pgtable_32.h
10207 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10208 #define PAGE_SHARED SRMMU_PAGE_SHARED
10209 #define PAGE_COPY SRMMU_PAGE_COPY
10210 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10211 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10212 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10213 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10214 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10215
10216 /* Top-level page directory - dummy used by init-mm.
10217 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10218
10219 /* xwr */
10220 #define __P000 PAGE_NONE
10221 -#define __P001 PAGE_READONLY
10222 -#define __P010 PAGE_COPY
10223 -#define __P011 PAGE_COPY
10224 +#define __P001 PAGE_READONLY_NOEXEC
10225 +#define __P010 PAGE_COPY_NOEXEC
10226 +#define __P011 PAGE_COPY_NOEXEC
10227 #define __P100 PAGE_READONLY
10228 #define __P101 PAGE_READONLY
10229 #define __P110 PAGE_COPY
10230 #define __P111 PAGE_COPY
10231
10232 #define __S000 PAGE_NONE
10233 -#define __S001 PAGE_READONLY
10234 -#define __S010 PAGE_SHARED
10235 -#define __S011 PAGE_SHARED
10236 +#define __S001 PAGE_READONLY_NOEXEC
10237 +#define __S010 PAGE_SHARED_NOEXEC
10238 +#define __S011 PAGE_SHARED_NOEXEC
10239 #define __S100 PAGE_READONLY
10240 #define __S101 PAGE_READONLY
10241 #define __S110 PAGE_SHARED
10242 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10243 index 79da178..c2eede8 100644
10244 --- a/arch/sparc/include/asm/pgtsrmmu.h
10245 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10246 @@ -115,6 +115,11 @@
10247 SRMMU_EXEC | SRMMU_REF)
10248 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10249 SRMMU_EXEC | SRMMU_REF)
10250 +
10251 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10252 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10253 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10254 +
10255 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10256 SRMMU_DIRTY | SRMMU_REF)
10257
10258 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10259 index 29d64b1..4272fe8 100644
10260 --- a/arch/sparc/include/asm/setup.h
10261 +++ b/arch/sparc/include/asm/setup.h
10262 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10263 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10264
10265 /* init_64.c */
10266 -extern atomic_t dcpage_flushes;
10267 -extern atomic_t dcpage_flushes_xcall;
10268 +extern atomic_unchecked_t dcpage_flushes;
10269 +extern atomic_unchecked_t dcpage_flushes_xcall;
10270
10271 extern int sysctl_tsb_ratio;
10272 #endif
10273 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10274 index 9689176..63c18ea 100644
10275 --- a/arch/sparc/include/asm/spinlock_64.h
10276 +++ b/arch/sparc/include/asm/spinlock_64.h
10277 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10278
10279 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10280
10281 -static void inline arch_read_lock(arch_rwlock_t *lock)
10282 +static inline void arch_read_lock(arch_rwlock_t *lock)
10283 {
10284 unsigned long tmp1, tmp2;
10285
10286 __asm__ __volatile__ (
10287 "1: ldsw [%2], %0\n"
10288 " brlz,pn %0, 2f\n"
10289 -"4: add %0, 1, %1\n"
10290 +"4: addcc %0, 1, %1\n"
10291 +
10292 +#ifdef CONFIG_PAX_REFCOUNT
10293 +" tvs %%icc, 6\n"
10294 +#endif
10295 +
10296 " cas [%2], %0, %1\n"
10297 " cmp %0, %1\n"
10298 " bne,pn %%icc, 1b\n"
10299 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10300 " .previous"
10301 : "=&r" (tmp1), "=&r" (tmp2)
10302 : "r" (lock)
10303 - : "memory");
10304 + : "memory", "cc");
10305 }
10306
10307 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10308 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10309 {
10310 int tmp1, tmp2;
10311
10312 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10313 "1: ldsw [%2], %0\n"
10314 " brlz,a,pn %0, 2f\n"
10315 " mov 0, %0\n"
10316 -" add %0, 1, %1\n"
10317 +" addcc %0, 1, %1\n"
10318 +
10319 +#ifdef CONFIG_PAX_REFCOUNT
10320 +" tvs %%icc, 6\n"
10321 +#endif
10322 +
10323 " cas [%2], %0, %1\n"
10324 " cmp %0, %1\n"
10325 " bne,pn %%icc, 1b\n"
10326 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10327 return tmp1;
10328 }
10329
10330 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10331 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10332 {
10333 unsigned long tmp1, tmp2;
10334
10335 __asm__ __volatile__(
10336 "1: lduw [%2], %0\n"
10337 -" sub %0, 1, %1\n"
10338 +" subcc %0, 1, %1\n"
10339 +
10340 +#ifdef CONFIG_PAX_REFCOUNT
10341 +" tvs %%icc, 6\n"
10342 +#endif
10343 +
10344 " cas [%2], %0, %1\n"
10345 " cmp %0, %1\n"
10346 " bne,pn %%xcc, 1b\n"
10347 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10348 : "memory");
10349 }
10350
10351 -static void inline arch_write_lock(arch_rwlock_t *lock)
10352 +static inline void arch_write_lock(arch_rwlock_t *lock)
10353 {
10354 unsigned long mask, tmp1, tmp2;
10355
10356 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10357 : "memory");
10358 }
10359
10360 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10361 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10362 {
10363 __asm__ __volatile__(
10364 " stw %%g0, [%0]"
10365 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10366 : "memory");
10367 }
10368
10369 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10370 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10371 {
10372 unsigned long mask, tmp1, tmp2, result;
10373
10374 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10375 index 025c984..a216504 100644
10376 --- a/arch/sparc/include/asm/thread_info_32.h
10377 +++ b/arch/sparc/include/asm/thread_info_32.h
10378 @@ -49,6 +49,8 @@ struct thread_info {
10379 unsigned long w_saved;
10380
10381 struct restart_block restart_block;
10382 +
10383 + unsigned long lowest_stack;
10384 };
10385
10386 /*
10387 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10388 index 798f027..b009941 100644
10389 --- a/arch/sparc/include/asm/thread_info_64.h
10390 +++ b/arch/sparc/include/asm/thread_info_64.h
10391 @@ -63,6 +63,8 @@ struct thread_info {
10392 struct pt_regs *kern_una_regs;
10393 unsigned int kern_una_insn;
10394
10395 + unsigned long lowest_stack;
10396 +
10397 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10398 __attribute__ ((aligned(64)));
10399 };
10400 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10401 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10402 /* flag bit 4 is available */
10403 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10404 -/* flag bit 6 is available */
10405 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10406 #define TIF_32BIT 7 /* 32-bit binary */
10407 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10408 #define TIF_SECCOMP 9 /* secure computing */
10409 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10410 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10411 +
10412 /* NOTE: Thread flags >= 12 should be ones we have no interest
10413 * in using in assembly, else we can't use the mask as
10414 * an immediate value in instructions such as andcc.
10415 @@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10416 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10417 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10418 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10419 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10420
10421 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10422 _TIF_DO_NOTIFY_RESUME_MASK | \
10423 _TIF_NEED_RESCHED)
10424 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10425
10426 +#define _TIF_WORK_SYSCALL \
10427 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10428 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10429 +
10430 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10431
10432 /*
10433 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10434 index bd56c28..4b63d83 100644
10435 --- a/arch/sparc/include/asm/uaccess.h
10436 +++ b/arch/sparc/include/asm/uaccess.h
10437 @@ -1,5 +1,6 @@
10438 #ifndef ___ASM_SPARC_UACCESS_H
10439 #define ___ASM_SPARC_UACCESS_H
10440 +
10441 #if defined(__sparc__) && defined(__arch64__)
10442 #include <asm/uaccess_64.h>
10443 #else
10444 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10445 index 9634d08..f55fe4f 100644
10446 --- a/arch/sparc/include/asm/uaccess_32.h
10447 +++ b/arch/sparc/include/asm/uaccess_32.h
10448 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10449
10450 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10451 {
10452 - if (n && __access_ok((unsigned long) to, n))
10453 + if ((long)n < 0)
10454 + return n;
10455 +
10456 + if (n && __access_ok((unsigned long) to, n)) {
10457 + if (!__builtin_constant_p(n))
10458 + check_object_size(from, n, true);
10459 return __copy_user(to, (__force void __user *) from, n);
10460 - else
10461 + } else
10462 return n;
10463 }
10464
10465 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10466 {
10467 + if ((long)n < 0)
10468 + return n;
10469 +
10470 + if (!__builtin_constant_p(n))
10471 + check_object_size(from, n, true);
10472 +
10473 return __copy_user(to, (__force void __user *) from, n);
10474 }
10475
10476 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10477 {
10478 - if (n && __access_ok((unsigned long) from, n))
10479 + if ((long)n < 0)
10480 + return n;
10481 +
10482 + if (n && __access_ok((unsigned long) from, n)) {
10483 + if (!__builtin_constant_p(n))
10484 + check_object_size(to, n, false);
10485 return __copy_user((__force void __user *) to, from, n);
10486 - else
10487 + } else
10488 return n;
10489 }
10490
10491 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10492 {
10493 + if ((long)n < 0)
10494 + return n;
10495 +
10496 return __copy_user((__force void __user *) to, from, n);
10497 }
10498
10499 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10500 index c990a5e..f17b9c1 100644
10501 --- a/arch/sparc/include/asm/uaccess_64.h
10502 +++ b/arch/sparc/include/asm/uaccess_64.h
10503 @@ -10,6 +10,7 @@
10504 #include <linux/compiler.h>
10505 #include <linux/string.h>
10506 #include <linux/thread_info.h>
10507 +#include <linux/kernel.h>
10508 #include <asm/asi.h>
10509 #include <asm/spitfire.h>
10510 #include <asm-generic/uaccess-unaligned.h>
10511 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10512 static inline unsigned long __must_check
10513 copy_from_user(void *to, const void __user *from, unsigned long size)
10514 {
10515 - unsigned long ret = ___copy_from_user(to, from, size);
10516 + unsigned long ret;
10517
10518 + if ((long)size < 0 || size > INT_MAX)
10519 + return size;
10520 +
10521 + if (!__builtin_constant_p(size))
10522 + check_object_size(to, size, false);
10523 +
10524 + ret = ___copy_from_user(to, from, size);
10525 if (unlikely(ret))
10526 ret = copy_from_user_fixup(to, from, size);
10527
10528 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10529 static inline unsigned long __must_check
10530 copy_to_user(void __user *to, const void *from, unsigned long size)
10531 {
10532 - unsigned long ret = ___copy_to_user(to, from, size);
10533 + unsigned long ret;
10534
10535 + if ((long)size < 0 || size > INT_MAX)
10536 + return size;
10537 +
10538 + if (!__builtin_constant_p(size))
10539 + check_object_size(from, size, true);
10540 +
10541 + ret = ___copy_to_user(to, from, size);
10542 if (unlikely(ret))
10543 ret = copy_to_user_fixup(to, from, size);
10544 return ret;
10545 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10546 index 7cf9c6e..6206648 100644
10547 --- a/arch/sparc/kernel/Makefile
10548 +++ b/arch/sparc/kernel/Makefile
10549 @@ -4,7 +4,7 @@
10550 #
10551
10552 asflags-y := -ansi
10553 -ccflags-y := -Werror
10554 +#ccflags-y := -Werror
10555
10556 extra-y := head_$(BITS).o
10557
10558 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10559 index 50e7b62..79fae35 100644
10560 --- a/arch/sparc/kernel/process_32.c
10561 +++ b/arch/sparc/kernel/process_32.c
10562 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10563
10564 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10565 r->psr, r->pc, r->npc, r->y, print_tainted());
10566 - printk("PC: <%pS>\n", (void *) r->pc);
10567 + printk("PC: <%pA>\n", (void *) r->pc);
10568 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10569 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10570 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10571 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10572 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10573 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10574 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10575 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10576
10577 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10578 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10579 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10580 rw = (struct reg_window32 *) fp;
10581 pc = rw->ins[7];
10582 printk("[%08lx : ", pc);
10583 - printk("%pS ] ", (void *) pc);
10584 + printk("%pA ] ", (void *) pc);
10585 fp = rw->ins[6];
10586 } while (++count < 16);
10587 printk("\n");
10588 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10589 index 0be7bf9..2b1cba8 100644
10590 --- a/arch/sparc/kernel/process_64.c
10591 +++ b/arch/sparc/kernel/process_64.c
10592 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10593 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10594 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10595 if (regs->tstate & TSTATE_PRIV)
10596 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10597 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10598 }
10599
10600 void show_regs(struct pt_regs *regs)
10601 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10602
10603 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10604 regs->tpc, regs->tnpc, regs->y, print_tainted());
10605 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10606 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10607 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10608 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10609 regs->u_regs[3]);
10610 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10611 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10612 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10613 regs->u_regs[15]);
10614 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10615 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10616 show_regwindow(regs);
10617 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10618 }
10619 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10620 ((tp && tp->task) ? tp->task->pid : -1));
10621
10622 if (gp->tstate & TSTATE_PRIV) {
10623 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10624 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10625 (void *) gp->tpc,
10626 (void *) gp->o7,
10627 (void *) gp->i7,
10628 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10629 index 79cc0d1..ec62734 100644
10630 --- a/arch/sparc/kernel/prom_common.c
10631 +++ b/arch/sparc/kernel/prom_common.c
10632 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10633
10634 unsigned int prom_early_allocated __initdata;
10635
10636 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10637 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10638 .nextprop = prom_common_nextprop,
10639 .getproplen = prom_getproplen,
10640 .getproperty = prom_getproperty,
10641 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10642 index 9ddc492..27a5619 100644
10643 --- a/arch/sparc/kernel/ptrace_64.c
10644 +++ b/arch/sparc/kernel/ptrace_64.c
10645 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10646 return ret;
10647 }
10648
10649 +#ifdef CONFIG_GRKERNSEC_SETXID
10650 +extern void gr_delayed_cred_worker(void);
10651 +#endif
10652 +
10653 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10654 {
10655 int ret = 0;
10656 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10657 if (test_thread_flag(TIF_NOHZ))
10658 user_exit();
10659
10660 +#ifdef CONFIG_GRKERNSEC_SETXID
10661 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10662 + gr_delayed_cred_worker();
10663 +#endif
10664 +
10665 if (test_thread_flag(TIF_SYSCALL_TRACE))
10666 ret = tracehook_report_syscall_entry(regs);
10667
10668 @@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10669 if (test_thread_flag(TIF_NOHZ))
10670 user_exit();
10671
10672 +#ifdef CONFIG_GRKERNSEC_SETXID
10673 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10674 + gr_delayed_cred_worker();
10675 +#endif
10676 +
10677 audit_syscall_exit(regs);
10678
10679 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10680 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10681 index da6f1a7..e5dea8f 100644
10682 --- a/arch/sparc/kernel/smp_64.c
10683 +++ b/arch/sparc/kernel/smp_64.c
10684 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10685 return;
10686
10687 #ifdef CONFIG_DEBUG_DCFLUSH
10688 - atomic_inc(&dcpage_flushes);
10689 + atomic_inc_unchecked(&dcpage_flushes);
10690 #endif
10691
10692 this_cpu = get_cpu();
10693 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10694 xcall_deliver(data0, __pa(pg_addr),
10695 (u64) pg_addr, cpumask_of(cpu));
10696 #ifdef CONFIG_DEBUG_DCFLUSH
10697 - atomic_inc(&dcpage_flushes_xcall);
10698 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10699 #endif
10700 }
10701 }
10702 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10703 preempt_disable();
10704
10705 #ifdef CONFIG_DEBUG_DCFLUSH
10706 - atomic_inc(&dcpage_flushes);
10707 + atomic_inc_unchecked(&dcpage_flushes);
10708 #endif
10709 data0 = 0;
10710 pg_addr = page_address(page);
10711 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10712 xcall_deliver(data0, __pa(pg_addr),
10713 (u64) pg_addr, cpu_online_mask);
10714 #ifdef CONFIG_DEBUG_DCFLUSH
10715 - atomic_inc(&dcpage_flushes_xcall);
10716 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10717 #endif
10718 }
10719 __local_flush_dcache_page(page);
10720 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10721 index 646988d..b88905f 100644
10722 --- a/arch/sparc/kernel/sys_sparc_32.c
10723 +++ b/arch/sparc/kernel/sys_sparc_32.c
10724 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10725 if (len > TASK_SIZE - PAGE_SIZE)
10726 return -ENOMEM;
10727 if (!addr)
10728 - addr = TASK_UNMAPPED_BASE;
10729 + addr = current->mm->mmap_base;
10730
10731 info.flags = 0;
10732 info.length = len;
10733 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10734 index c85403d..6af95c9 100644
10735 --- a/arch/sparc/kernel/sys_sparc_64.c
10736 +++ b/arch/sparc/kernel/sys_sparc_64.c
10737 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10738 struct vm_area_struct * vma;
10739 unsigned long task_size = TASK_SIZE;
10740 int do_color_align;
10741 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10742 struct vm_unmapped_area_info info;
10743
10744 if (flags & MAP_FIXED) {
10745 /* We do not accept a shared mapping if it would violate
10746 * cache aliasing constraints.
10747 */
10748 - if ((flags & MAP_SHARED) &&
10749 + if ((filp || (flags & MAP_SHARED)) &&
10750 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10751 return -EINVAL;
10752 return addr;
10753 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10754 if (filp || (flags & MAP_SHARED))
10755 do_color_align = 1;
10756
10757 +#ifdef CONFIG_PAX_RANDMMAP
10758 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10759 +#endif
10760 +
10761 if (addr) {
10762 if (do_color_align)
10763 addr = COLOR_ALIGN(addr, pgoff);
10764 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10765 addr = PAGE_ALIGN(addr);
10766
10767 vma = find_vma(mm, addr);
10768 - if (task_size - len >= addr &&
10769 - (!vma || addr + len <= vma->vm_start))
10770 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10771 return addr;
10772 }
10773
10774 info.flags = 0;
10775 info.length = len;
10776 - info.low_limit = TASK_UNMAPPED_BASE;
10777 + info.low_limit = mm->mmap_base;
10778 info.high_limit = min(task_size, VA_EXCLUDE_START);
10779 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10780 info.align_offset = pgoff << PAGE_SHIFT;
10781 + info.threadstack_offset = offset;
10782 addr = vm_unmapped_area(&info);
10783
10784 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10785 VM_BUG_ON(addr != -ENOMEM);
10786 info.low_limit = VA_EXCLUDE_END;
10787 +
10788 +#ifdef CONFIG_PAX_RANDMMAP
10789 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10790 + info.low_limit += mm->delta_mmap;
10791 +#endif
10792 +
10793 info.high_limit = task_size;
10794 addr = vm_unmapped_area(&info);
10795 }
10796 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10797 unsigned long task_size = STACK_TOP32;
10798 unsigned long addr = addr0;
10799 int do_color_align;
10800 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10801 struct vm_unmapped_area_info info;
10802
10803 /* This should only ever run for 32-bit processes. */
10804 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10805 /* We do not accept a shared mapping if it would violate
10806 * cache aliasing constraints.
10807 */
10808 - if ((flags & MAP_SHARED) &&
10809 + if ((filp || (flags & MAP_SHARED)) &&
10810 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10811 return -EINVAL;
10812 return addr;
10813 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10814 if (filp || (flags & MAP_SHARED))
10815 do_color_align = 1;
10816
10817 +#ifdef CONFIG_PAX_RANDMMAP
10818 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10819 +#endif
10820 +
10821 /* requesting a specific address */
10822 if (addr) {
10823 if (do_color_align)
10824 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10825 addr = PAGE_ALIGN(addr);
10826
10827 vma = find_vma(mm, addr);
10828 - if (task_size - len >= addr &&
10829 - (!vma || addr + len <= vma->vm_start))
10830 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10831 return addr;
10832 }
10833
10834 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10835 info.high_limit = mm->mmap_base;
10836 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10837 info.align_offset = pgoff << PAGE_SHIFT;
10838 + info.threadstack_offset = offset;
10839 addr = vm_unmapped_area(&info);
10840
10841 /*
10842 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10843 VM_BUG_ON(addr != -ENOMEM);
10844 info.flags = 0;
10845 info.low_limit = TASK_UNMAPPED_BASE;
10846 +
10847 +#ifdef CONFIG_PAX_RANDMMAP
10848 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10849 + info.low_limit += mm->delta_mmap;
10850 +#endif
10851 +
10852 info.high_limit = STACK_TOP32;
10853 addr = vm_unmapped_area(&info);
10854 }
10855 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10856 EXPORT_SYMBOL(get_fb_unmapped_area);
10857
10858 /* Essentially the same as PowerPC. */
10859 -static unsigned long mmap_rnd(void)
10860 +static unsigned long mmap_rnd(struct mm_struct *mm)
10861 {
10862 unsigned long rnd = 0UL;
10863
10864 +#ifdef CONFIG_PAX_RANDMMAP
10865 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10866 +#endif
10867 +
10868 if (current->flags & PF_RANDOMIZE) {
10869 unsigned long val = get_random_int();
10870 if (test_thread_flag(TIF_32BIT))
10871 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10872
10873 void arch_pick_mmap_layout(struct mm_struct *mm)
10874 {
10875 - unsigned long random_factor = mmap_rnd();
10876 + unsigned long random_factor = mmap_rnd(mm);
10877 unsigned long gap;
10878
10879 /*
10880 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10881 gap == RLIM_INFINITY ||
10882 sysctl_legacy_va_layout) {
10883 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10884 +
10885 +#ifdef CONFIG_PAX_RANDMMAP
10886 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10887 + mm->mmap_base += mm->delta_mmap;
10888 +#endif
10889 +
10890 mm->get_unmapped_area = arch_get_unmapped_area;
10891 } else {
10892 /* We know it's 32-bit */
10893 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10894 gap = (task_size / 6 * 5);
10895
10896 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10897 +
10898 +#ifdef CONFIG_PAX_RANDMMAP
10899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10901 +#endif
10902 +
10903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10904 }
10905 }
10906 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10907 index 33a17e7..d87fb1f 100644
10908 --- a/arch/sparc/kernel/syscalls.S
10909 +++ b/arch/sparc/kernel/syscalls.S
10910 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10911 #endif
10912 .align 32
10913 1: ldx [%g6 + TI_FLAGS], %l5
10914 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10915 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10916 be,pt %icc, rtrap
10917 nop
10918 call syscall_trace_leave
10919 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10920
10921 srl %i3, 0, %o3 ! IEU0
10922 srl %i2, 0, %o2 ! IEU0 Group
10923 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10924 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10925 bne,pn %icc, linux_syscall_trace32 ! CTI
10926 mov %i0, %l5 ! IEU1
10927 5: call %l7 ! CTI Group brk forced
10928 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10929
10930 mov %i3, %o3 ! IEU1
10931 mov %i4, %o4 ! IEU0 Group
10932 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10933 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10934 bne,pn %icc, linux_syscall_trace ! CTI Group
10935 mov %i0, %l5 ! IEU0
10936 2: call %l7 ! CTI Group brk forced
10937 @@ -223,7 +223,7 @@ ret_sys_call:
10938
10939 cmp %o0, -ERESTART_RESTARTBLOCK
10940 bgeu,pn %xcc, 1f
10941 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10942 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10943 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10944
10945 2:
10946 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10947 index 6fd386c5..6907d81 100644
10948 --- a/arch/sparc/kernel/traps_32.c
10949 +++ b/arch/sparc/kernel/traps_32.c
10950 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10951 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10952 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10953
10954 +extern void gr_handle_kernel_exploit(void);
10955 +
10956 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10957 {
10958 static int die_counter;
10959 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10960 count++ < 30 &&
10961 (((unsigned long) rw) >= PAGE_OFFSET) &&
10962 !(((unsigned long) rw) & 0x7)) {
10963 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10964 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10965 (void *) rw->ins[7]);
10966 rw = (struct reg_window32 *)rw->ins[6];
10967 }
10968 }
10969 printk("Instruction DUMP:");
10970 instruction_dump ((unsigned long *) regs->pc);
10971 - if(regs->psr & PSR_PS)
10972 + if(regs->psr & PSR_PS) {
10973 + gr_handle_kernel_exploit();
10974 do_exit(SIGKILL);
10975 + }
10976 do_exit(SIGSEGV);
10977 }
10978
10979 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10980 index 981a769..d906eda 100644
10981 --- a/arch/sparc/kernel/traps_64.c
10982 +++ b/arch/sparc/kernel/traps_64.c
10983 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10984 i + 1,
10985 p->trapstack[i].tstate, p->trapstack[i].tpc,
10986 p->trapstack[i].tnpc, p->trapstack[i].tt);
10987 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10988 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10989 }
10990 }
10991
10992 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10993
10994 lvl -= 0x100;
10995 if (regs->tstate & TSTATE_PRIV) {
10996 +
10997 +#ifdef CONFIG_PAX_REFCOUNT
10998 + if (lvl == 6)
10999 + pax_report_refcount_overflow(regs);
11000 +#endif
11001 +
11002 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11003 die_if_kernel(buffer, regs);
11004 }
11005 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11006 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11007 {
11008 char buffer[32];
11009 -
11010 +
11011 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11012 0, lvl, SIGTRAP) == NOTIFY_STOP)
11013 return;
11014
11015 +#ifdef CONFIG_PAX_REFCOUNT
11016 + if (lvl == 6)
11017 + pax_report_refcount_overflow(regs);
11018 +#endif
11019 +
11020 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11021
11022 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11023 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11024 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11025 printk("%s" "ERROR(%d): ",
11026 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11027 - printk("TPC<%pS>\n", (void *) regs->tpc);
11028 + printk("TPC<%pA>\n", (void *) regs->tpc);
11029 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11030 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11031 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11032 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11033 smp_processor_id(),
11034 (type & 0x1) ? 'I' : 'D',
11035 regs->tpc);
11036 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11037 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11038 panic("Irrecoverable Cheetah+ parity error.");
11039 }
11040
11041 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11042 smp_processor_id(),
11043 (type & 0x1) ? 'I' : 'D',
11044 regs->tpc);
11045 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11046 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11047 }
11048
11049 struct sun4v_error_entry {
11050 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11051 /*0x38*/u64 reserved_5;
11052 };
11053
11054 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11055 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11056 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11057 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11058
11059 static const char *sun4v_err_type_to_str(u8 type)
11060 {
11061 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11062 }
11063
11064 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11065 - int cpu, const char *pfx, atomic_t *ocnt)
11066 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11067 {
11068 u64 *raw_ptr = (u64 *) ent;
11069 u32 attrs;
11070 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11071
11072 show_regs(regs);
11073
11074 - if ((cnt = atomic_read(ocnt)) != 0) {
11075 - atomic_set(ocnt, 0);
11076 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11077 + atomic_set_unchecked(ocnt, 0);
11078 wmb();
11079 printk("%s: Queue overflowed %d times.\n",
11080 pfx, cnt);
11081 @@ -2048,7 +2059,7 @@ out:
11082 */
11083 void sun4v_resum_overflow(struct pt_regs *regs)
11084 {
11085 - atomic_inc(&sun4v_resum_oflow_cnt);
11086 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11087 }
11088
11089 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11090 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11091 /* XXX Actually even this can make not that much sense. Perhaps
11092 * XXX we should just pull the plug and panic directly from here?
11093 */
11094 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11095 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11096 }
11097
11098 static void sun4v_tlb_error(struct pt_regs *regs)
11099 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11100
11101 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11102 regs->tpc, tl);
11103 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11104 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11105 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11106 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11107 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11108 (void *) regs->u_regs[UREG_I7]);
11109 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11110 "pte[%lx] error[%lx]\n",
11111 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11112
11113 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11114 regs->tpc, tl);
11115 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11116 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11117 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11118 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11119 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11120 (void *) regs->u_regs[UREG_I7]);
11121 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11122 "pte[%lx] error[%lx]\n",
11123 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11124 fp = (unsigned long)sf->fp + STACK_BIAS;
11125 }
11126
11127 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11128 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11129 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11130 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11131 int index = tsk->curr_ret_stack;
11132 if (tsk->ret_stack && index >= graph) {
11133 pc = tsk->ret_stack[index - graph].ret;
11134 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11135 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11136 graph++;
11137 }
11138 }
11139 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11140 return (struct reg_window *) (fp + STACK_BIAS);
11141 }
11142
11143 +extern void gr_handle_kernel_exploit(void);
11144 +
11145 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11146 {
11147 static int die_counter;
11148 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11149 while (rw &&
11150 count++ < 30 &&
11151 kstack_valid(tp, (unsigned long) rw)) {
11152 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11153 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11154 (void *) rw->ins[7]);
11155
11156 rw = kernel_stack_up(rw);
11157 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11158 }
11159 user_instruction_dump ((unsigned int __user *) regs->tpc);
11160 }
11161 - if (regs->tstate & TSTATE_PRIV)
11162 + if (regs->tstate & TSTATE_PRIV) {
11163 + gr_handle_kernel_exploit();
11164 do_exit(SIGKILL);
11165 + }
11166 do_exit(SIGSEGV);
11167 }
11168 EXPORT_SYMBOL(die_if_kernel);
11169 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11170 index 62098a8..547ab2c 100644
11171 --- a/arch/sparc/kernel/unaligned_64.c
11172 +++ b/arch/sparc/kernel/unaligned_64.c
11173 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11174 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11175
11176 if (__ratelimit(&ratelimit)) {
11177 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11178 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11179 regs->tpc, (void *) regs->tpc);
11180 }
11181 }
11182 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11183 index 3269b02..64f5231 100644
11184 --- a/arch/sparc/lib/Makefile
11185 +++ b/arch/sparc/lib/Makefile
11186 @@ -2,7 +2,7 @@
11187 #
11188
11189 asflags-y := -ansi -DST_DIV0=0x02
11190 -ccflags-y := -Werror
11191 +#ccflags-y := -Werror
11192
11193 lib-$(CONFIG_SPARC32) += ashrdi3.o
11194 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11195 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11196 index 05dac43..76f8ed4 100644
11197 --- a/arch/sparc/lib/atomic_64.S
11198 +++ b/arch/sparc/lib/atomic_64.S
11199 @@ -15,11 +15,22 @@
11200 * a value and does the barriers.
11201 */
11202
11203 -#define ATOMIC_OP(op) \
11204 -ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11205 +#ifdef CONFIG_PAX_REFCOUNT
11206 +#define __REFCOUNT_OP(op) op##cc
11207 +#define __OVERFLOW_IOP tvs %icc, 6;
11208 +#define __OVERFLOW_XOP tvs %xcc, 6;
11209 +#else
11210 +#define __REFCOUNT_OP(op) op
11211 +#define __OVERFLOW_IOP
11212 +#define __OVERFLOW_XOP
11213 +#endif
11214 +
11215 +#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11216 +ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11217 BACKOFF_SETUP(%o2); \
11218 1: lduw [%o1], %g1; \
11219 - op %g1, %o0, %g7; \
11220 + asm_op %g1, %o0, %g7; \
11221 + post_op \
11222 cas [%o1], %g1, %g7; \
11223 cmp %g1, %g7; \
11224 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11225 @@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11226 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11227 ENDPROC(atomic_##op); \
11228
11229 -#define ATOMIC_OP_RETURN(op) \
11230 -ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11231 +#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11232 + __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11233 +
11234 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11235 +ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11236 BACKOFF_SETUP(%o2); \
11237 1: lduw [%o1], %g1; \
11238 - op %g1, %o0, %g7; \
11239 + asm_op %g1, %o0, %g7; \
11240 + post_op \
11241 cas [%o1], %g1, %g7; \
11242 cmp %g1, %g7; \
11243 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11244 @@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11245 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11246 ENDPROC(atomic_##op##_return);
11247
11248 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11249 + __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11250 +
11251 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11252
11253 ATOMIC_OPS(add)
11254 @@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11255
11256 #undef ATOMIC_OPS
11257 #undef ATOMIC_OP_RETURN
11258 +#undef __ATOMIC_OP_RETURN
11259 #undef ATOMIC_OP
11260 +#undef __ATOMIC_OP
11261
11262 -#define ATOMIC64_OP(op) \
11263 -ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11264 +#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11265 +ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11266 BACKOFF_SETUP(%o2); \
11267 1: ldx [%o1], %g1; \
11268 - op %g1, %o0, %g7; \
11269 + asm_op %g1, %o0, %g7; \
11270 + post_op \
11271 casx [%o1], %g1, %g7; \
11272 cmp %g1, %g7; \
11273 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11274 @@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11275 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11276 ENDPROC(atomic64_##op); \
11277
11278 -#define ATOMIC64_OP_RETURN(op) \
11279 -ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11280 +#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11281 + __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11282 +
11283 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11284 +ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11285 BACKOFF_SETUP(%o2); \
11286 1: ldx [%o1], %g1; \
11287 - op %g1, %o0, %g7; \
11288 + asm_op %g1, %o0, %g7; \
11289 + post_op \
11290 casx [%o1], %g1, %g7; \
11291 cmp %g1, %g7; \
11292 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11293 @@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11294 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11295 ENDPROC(atomic64_##op##_return);
11296
11297 +#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11298 +i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11299 +
11300 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11301
11302 ATOMIC64_OPS(add)
11303 @@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11304
11305 #undef ATOMIC64_OPS
11306 #undef ATOMIC64_OP_RETURN
11307 +#undef __ATOMIC64_OP_RETURN
11308 #undef ATOMIC64_OP
11309 +#undef __ATOMIC64_OP
11310 +#undef __OVERFLOW_XOP
11311 +#undef __OVERFLOW_IOP
11312 +#undef __REFCOUNT_OP
11313
11314 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11315 BACKOFF_SETUP(%o2)
11316 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11317 index 1d649a9..fbc5bfc 100644
11318 --- a/arch/sparc/lib/ksyms.c
11319 +++ b/arch/sparc/lib/ksyms.c
11320 @@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11321 /* Atomic counter implementation. */
11322 #define ATOMIC_OP(op) \
11323 EXPORT_SYMBOL(atomic_##op); \
11324 -EXPORT_SYMBOL(atomic64_##op);
11325 +EXPORT_SYMBOL(atomic_##op##_unchecked); \
11326 +EXPORT_SYMBOL(atomic64_##op); \
11327 +EXPORT_SYMBOL(atomic64_##op##_unchecked);
11328
11329 #define ATOMIC_OP_RETURN(op) \
11330 EXPORT_SYMBOL(atomic_##op##_return); \
11331 @@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11332 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11333
11334 ATOMIC_OPS(add)
11335 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11336 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11337 ATOMIC_OPS(sub)
11338
11339 #undef ATOMIC_OPS
11340 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11341 index 30c3ecc..736f015 100644
11342 --- a/arch/sparc/mm/Makefile
11343 +++ b/arch/sparc/mm/Makefile
11344 @@ -2,7 +2,7 @@
11345 #
11346
11347 asflags-y := -ansi
11348 -ccflags-y := -Werror
11349 +#ccflags-y := -Werror
11350
11351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11352 obj-y += fault_$(BITS).o
11353 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11354 index 70d8171..274c6c0 100644
11355 --- a/arch/sparc/mm/fault_32.c
11356 +++ b/arch/sparc/mm/fault_32.c
11357 @@ -21,6 +21,9 @@
11358 #include <linux/perf_event.h>
11359 #include <linux/interrupt.h>
11360 #include <linux/kdebug.h>
11361 +#include <linux/slab.h>
11362 +#include <linux/pagemap.h>
11363 +#include <linux/compiler.h>
11364
11365 #include <asm/page.h>
11366 #include <asm/pgtable.h>
11367 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11368 return safe_compute_effective_address(regs, insn);
11369 }
11370
11371 +#ifdef CONFIG_PAX_PAGEEXEC
11372 +#ifdef CONFIG_PAX_DLRESOLVE
11373 +static void pax_emuplt_close(struct vm_area_struct *vma)
11374 +{
11375 + vma->vm_mm->call_dl_resolve = 0UL;
11376 +}
11377 +
11378 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11379 +{
11380 + unsigned int *kaddr;
11381 +
11382 + vmf->page = alloc_page(GFP_HIGHUSER);
11383 + if (!vmf->page)
11384 + return VM_FAULT_OOM;
11385 +
11386 + kaddr = kmap(vmf->page);
11387 + memset(kaddr, 0, PAGE_SIZE);
11388 + kaddr[0] = 0x9DE3BFA8U; /* save */
11389 + flush_dcache_page(vmf->page);
11390 + kunmap(vmf->page);
11391 + return VM_FAULT_MAJOR;
11392 +}
11393 +
11394 +static const struct vm_operations_struct pax_vm_ops = {
11395 + .close = pax_emuplt_close,
11396 + .fault = pax_emuplt_fault
11397 +};
11398 +
11399 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11400 +{
11401 + int ret;
11402 +
11403 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11404 + vma->vm_mm = current->mm;
11405 + vma->vm_start = addr;
11406 + vma->vm_end = addr + PAGE_SIZE;
11407 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11408 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11409 + vma->vm_ops = &pax_vm_ops;
11410 +
11411 + ret = insert_vm_struct(current->mm, vma);
11412 + if (ret)
11413 + return ret;
11414 +
11415 + ++current->mm->total_vm;
11416 + return 0;
11417 +}
11418 +#endif
11419 +
11420 +/*
11421 + * PaX: decide what to do with offenders (regs->pc = fault address)
11422 + *
11423 + * returns 1 when task should be killed
11424 + * 2 when patched PLT trampoline was detected
11425 + * 3 when unpatched PLT trampoline was detected
11426 + */
11427 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11428 +{
11429 +
11430 +#ifdef CONFIG_PAX_EMUPLT
11431 + int err;
11432 +
11433 + do { /* PaX: patched PLT emulation #1 */
11434 + unsigned int sethi1, sethi2, jmpl;
11435 +
11436 + err = get_user(sethi1, (unsigned int *)regs->pc);
11437 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11438 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11439 +
11440 + if (err)
11441 + break;
11442 +
11443 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11444 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11445 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11446 + {
11447 + unsigned int addr;
11448 +
11449 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11450 + addr = regs->u_regs[UREG_G1];
11451 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11452 + regs->pc = addr;
11453 + regs->npc = addr+4;
11454 + return 2;
11455 + }
11456 + } while (0);
11457 +
11458 + do { /* PaX: patched PLT emulation #2 */
11459 + unsigned int ba;
11460 +
11461 + err = get_user(ba, (unsigned int *)regs->pc);
11462 +
11463 + if (err)
11464 + break;
11465 +
11466 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11467 + unsigned int addr;
11468 +
11469 + if ((ba & 0xFFC00000U) == 0x30800000U)
11470 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11471 + else
11472 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11473 + regs->pc = addr;
11474 + regs->npc = addr+4;
11475 + return 2;
11476 + }
11477 + } while (0);
11478 +
11479 + do { /* PaX: patched PLT emulation #3 */
11480 + unsigned int sethi, bajmpl, nop;
11481 +
11482 + err = get_user(sethi, (unsigned int *)regs->pc);
11483 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11484 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11485 +
11486 + if (err)
11487 + break;
11488 +
11489 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11490 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11491 + nop == 0x01000000U)
11492 + {
11493 + unsigned int addr;
11494 +
11495 + addr = (sethi & 0x003FFFFFU) << 10;
11496 + regs->u_regs[UREG_G1] = addr;
11497 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11498 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11499 + else
11500 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11501 + regs->pc = addr;
11502 + regs->npc = addr+4;
11503 + return 2;
11504 + }
11505 + } while (0);
11506 +
11507 + do { /* PaX: unpatched PLT emulation step 1 */
11508 + unsigned int sethi, ba, nop;
11509 +
11510 + err = get_user(sethi, (unsigned int *)regs->pc);
11511 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11512 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11513 +
11514 + if (err)
11515 + break;
11516 +
11517 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519 + nop == 0x01000000U)
11520 + {
11521 + unsigned int addr, save, call;
11522 +
11523 + if ((ba & 0xFFC00000U) == 0x30800000U)
11524 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11525 + else
11526 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11527 +
11528 + err = get_user(save, (unsigned int *)addr);
11529 + err |= get_user(call, (unsigned int *)(addr+4));
11530 + err |= get_user(nop, (unsigned int *)(addr+8));
11531 + if (err)
11532 + break;
11533 +
11534 +#ifdef CONFIG_PAX_DLRESOLVE
11535 + if (save == 0x9DE3BFA8U &&
11536 + (call & 0xC0000000U) == 0x40000000U &&
11537 + nop == 0x01000000U)
11538 + {
11539 + struct vm_area_struct *vma;
11540 + unsigned long call_dl_resolve;
11541 +
11542 + down_read(&current->mm->mmap_sem);
11543 + call_dl_resolve = current->mm->call_dl_resolve;
11544 + up_read(&current->mm->mmap_sem);
11545 + if (likely(call_dl_resolve))
11546 + goto emulate;
11547 +
11548 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11549 +
11550 + down_write(&current->mm->mmap_sem);
11551 + if (current->mm->call_dl_resolve) {
11552 + call_dl_resolve = current->mm->call_dl_resolve;
11553 + up_write(&current->mm->mmap_sem);
11554 + if (vma)
11555 + kmem_cache_free(vm_area_cachep, vma);
11556 + goto emulate;
11557 + }
11558 +
11559 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11560 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11561 + up_write(&current->mm->mmap_sem);
11562 + if (vma)
11563 + kmem_cache_free(vm_area_cachep, vma);
11564 + return 1;
11565 + }
11566 +
11567 + if (pax_insert_vma(vma, call_dl_resolve)) {
11568 + up_write(&current->mm->mmap_sem);
11569 + kmem_cache_free(vm_area_cachep, vma);
11570 + return 1;
11571 + }
11572 +
11573 + current->mm->call_dl_resolve = call_dl_resolve;
11574 + up_write(&current->mm->mmap_sem);
11575 +
11576 +emulate:
11577 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11578 + regs->pc = call_dl_resolve;
11579 + regs->npc = addr+4;
11580 + return 3;
11581 + }
11582 +#endif
11583 +
11584 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11585 + if ((save & 0xFFC00000U) == 0x05000000U &&
11586 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11587 + nop == 0x01000000U)
11588 + {
11589 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11590 + regs->u_regs[UREG_G2] = addr + 4;
11591 + addr = (save & 0x003FFFFFU) << 10;
11592 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11593 + regs->pc = addr;
11594 + regs->npc = addr+4;
11595 + return 3;
11596 + }
11597 + }
11598 + } while (0);
11599 +
11600 + do { /* PaX: unpatched PLT emulation step 2 */
11601 + unsigned int save, call, nop;
11602 +
11603 + err = get_user(save, (unsigned int *)(regs->pc-4));
11604 + err |= get_user(call, (unsigned int *)regs->pc);
11605 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11606 + if (err)
11607 + break;
11608 +
11609 + if (save == 0x9DE3BFA8U &&
11610 + (call & 0xC0000000U) == 0x40000000U &&
11611 + nop == 0x01000000U)
11612 + {
11613 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11614 +
11615 + regs->u_regs[UREG_RETPC] = regs->pc;
11616 + regs->pc = dl_resolve;
11617 + regs->npc = dl_resolve+4;
11618 + return 3;
11619 + }
11620 + } while (0);
11621 +#endif
11622 +
11623 + return 1;
11624 +}
11625 +
11626 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11627 +{
11628 + unsigned long i;
11629 +
11630 + printk(KERN_ERR "PAX: bytes at PC: ");
11631 + for (i = 0; i < 8; i++) {
11632 + unsigned int c;
11633 + if (get_user(c, (unsigned int *)pc+i))
11634 + printk(KERN_CONT "???????? ");
11635 + else
11636 + printk(KERN_CONT "%08x ", c);
11637 + }
11638 + printk("\n");
11639 +}
11640 +#endif
11641 +
11642 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11643 int text_fault)
11644 {
11645 @@ -226,6 +500,24 @@ good_area:
11646 if (!(vma->vm_flags & VM_WRITE))
11647 goto bad_area;
11648 } else {
11649 +
11650 +#ifdef CONFIG_PAX_PAGEEXEC
11651 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11652 + up_read(&mm->mmap_sem);
11653 + switch (pax_handle_fetch_fault(regs)) {
11654 +
11655 +#ifdef CONFIG_PAX_EMUPLT
11656 + case 2:
11657 + case 3:
11658 + return;
11659 +#endif
11660 +
11661 + }
11662 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11663 + do_group_exit(SIGKILL);
11664 + }
11665 +#endif
11666 +
11667 /* Allow reads even for write-only mappings */
11668 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11669 goto bad_area;
11670 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11671 index 4798232..f76e3aa 100644
11672 --- a/arch/sparc/mm/fault_64.c
11673 +++ b/arch/sparc/mm/fault_64.c
11674 @@ -22,6 +22,9 @@
11675 #include <linux/kdebug.h>
11676 #include <linux/percpu.h>
11677 #include <linux/context_tracking.h>
11678 +#include <linux/slab.h>
11679 +#include <linux/pagemap.h>
11680 +#include <linux/compiler.h>
11681
11682 #include <asm/page.h>
11683 #include <asm/pgtable.h>
11684 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11685 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11686 regs->tpc);
11687 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11688 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11689 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11690 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11691 dump_stack();
11692 unhandled_fault(regs->tpc, current, regs);
11693 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11694 show_regs(regs);
11695 }
11696
11697 +#ifdef CONFIG_PAX_PAGEEXEC
11698 +#ifdef CONFIG_PAX_DLRESOLVE
11699 +static void pax_emuplt_close(struct vm_area_struct *vma)
11700 +{
11701 + vma->vm_mm->call_dl_resolve = 0UL;
11702 +}
11703 +
11704 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11705 +{
11706 + unsigned int *kaddr;
11707 +
11708 + vmf->page = alloc_page(GFP_HIGHUSER);
11709 + if (!vmf->page)
11710 + return VM_FAULT_OOM;
11711 +
11712 + kaddr = kmap(vmf->page);
11713 + memset(kaddr, 0, PAGE_SIZE);
11714 + kaddr[0] = 0x9DE3BFA8U; /* save */
11715 + flush_dcache_page(vmf->page);
11716 + kunmap(vmf->page);
11717 + return VM_FAULT_MAJOR;
11718 +}
11719 +
11720 +static const struct vm_operations_struct pax_vm_ops = {
11721 + .close = pax_emuplt_close,
11722 + .fault = pax_emuplt_fault
11723 +};
11724 +
11725 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11726 +{
11727 + int ret;
11728 +
11729 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11730 + vma->vm_mm = current->mm;
11731 + vma->vm_start = addr;
11732 + vma->vm_end = addr + PAGE_SIZE;
11733 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11734 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11735 + vma->vm_ops = &pax_vm_ops;
11736 +
11737 + ret = insert_vm_struct(current->mm, vma);
11738 + if (ret)
11739 + return ret;
11740 +
11741 + ++current->mm->total_vm;
11742 + return 0;
11743 +}
11744 +#endif
11745 +
11746 +/*
11747 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11748 + *
11749 + * returns 1 when task should be killed
11750 + * 2 when patched PLT trampoline was detected
11751 + * 3 when unpatched PLT trampoline was detected
11752 + */
11753 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11754 +{
11755 +
11756 +#ifdef CONFIG_PAX_EMUPLT
11757 + int err;
11758 +
11759 + do { /* PaX: patched PLT emulation #1 */
11760 + unsigned int sethi1, sethi2, jmpl;
11761 +
11762 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11763 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11764 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11765 +
11766 + if (err)
11767 + break;
11768 +
11769 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11770 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11771 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11772 + {
11773 + unsigned long addr;
11774 +
11775 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11776 + addr = regs->u_regs[UREG_G1];
11777 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11778 +
11779 + if (test_thread_flag(TIF_32BIT))
11780 + addr &= 0xFFFFFFFFUL;
11781 +
11782 + regs->tpc = addr;
11783 + regs->tnpc = addr+4;
11784 + return 2;
11785 + }
11786 + } while (0);
11787 +
11788 + do { /* PaX: patched PLT emulation #2 */
11789 + unsigned int ba;
11790 +
11791 + err = get_user(ba, (unsigned int *)regs->tpc);
11792 +
11793 + if (err)
11794 + break;
11795 +
11796 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11797 + unsigned long addr;
11798 +
11799 + if ((ba & 0xFFC00000U) == 0x30800000U)
11800 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11801 + else
11802 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11803 +
11804 + if (test_thread_flag(TIF_32BIT))
11805 + addr &= 0xFFFFFFFFUL;
11806 +
11807 + regs->tpc = addr;
11808 + regs->tnpc = addr+4;
11809 + return 2;
11810 + }
11811 + } while (0);
11812 +
11813 + do { /* PaX: patched PLT emulation #3 */
11814 + unsigned int sethi, bajmpl, nop;
11815 +
11816 + err = get_user(sethi, (unsigned int *)regs->tpc);
11817 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11818 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11819 +
11820 + if (err)
11821 + break;
11822 +
11823 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11824 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11825 + nop == 0x01000000U)
11826 + {
11827 + unsigned long addr;
11828 +
11829 + addr = (sethi & 0x003FFFFFU) << 10;
11830 + regs->u_regs[UREG_G1] = addr;
11831 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11832 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11833 + else
11834 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11835 +
11836 + if (test_thread_flag(TIF_32BIT))
11837 + addr &= 0xFFFFFFFFUL;
11838 +
11839 + regs->tpc = addr;
11840 + regs->tnpc = addr+4;
11841 + return 2;
11842 + }
11843 + } while (0);
11844 +
11845 + do { /* PaX: patched PLT emulation #4 */
11846 + unsigned int sethi, mov1, call, mov2;
11847 +
11848 + err = get_user(sethi, (unsigned int *)regs->tpc);
11849 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11850 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11851 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11852 +
11853 + if (err)
11854 + break;
11855 +
11856 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857 + mov1 == 0x8210000FU &&
11858 + (call & 0xC0000000U) == 0x40000000U &&
11859 + mov2 == 0x9E100001U)
11860 + {
11861 + unsigned long addr;
11862 +
11863 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11864 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11865 +
11866 + if (test_thread_flag(TIF_32BIT))
11867 + addr &= 0xFFFFFFFFUL;
11868 +
11869 + regs->tpc = addr;
11870 + regs->tnpc = addr+4;
11871 + return 2;
11872 + }
11873 + } while (0);
11874 +
11875 + do { /* PaX: patched PLT emulation #5 */
11876 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11877 +
11878 + err = get_user(sethi, (unsigned int *)regs->tpc);
11879 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11880 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11881 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11882 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11883 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11884 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11885 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11886 +
11887 + if (err)
11888 + break;
11889 +
11890 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11891 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11892 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11893 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11894 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11895 + sllx == 0x83287020U &&
11896 + jmpl == 0x81C04005U &&
11897 + nop == 0x01000000U)
11898 + {
11899 + unsigned long addr;
11900 +
11901 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11902 + regs->u_regs[UREG_G1] <<= 32;
11903 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11904 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11905 + regs->tpc = addr;
11906 + regs->tnpc = addr+4;
11907 + return 2;
11908 + }
11909 + } while (0);
11910 +
11911 + do { /* PaX: patched PLT emulation #6 */
11912 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11913 +
11914 + err = get_user(sethi, (unsigned int *)regs->tpc);
11915 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11916 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11917 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11918 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11919 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11920 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11921 +
11922 + if (err)
11923 + break;
11924 +
11925 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11926 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11927 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11928 + sllx == 0x83287020U &&
11929 + (or & 0xFFFFE000U) == 0x8A116000U &&
11930 + jmpl == 0x81C04005U &&
11931 + nop == 0x01000000U)
11932 + {
11933 + unsigned long addr;
11934 +
11935 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11936 + regs->u_regs[UREG_G1] <<= 32;
11937 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11938 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11939 + regs->tpc = addr;
11940 + regs->tnpc = addr+4;
11941 + return 2;
11942 + }
11943 + } while (0);
11944 +
11945 + do { /* PaX: unpatched PLT emulation step 1 */
11946 + unsigned int sethi, ba, nop;
11947 +
11948 + err = get_user(sethi, (unsigned int *)regs->tpc);
11949 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11950 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11951 +
11952 + if (err)
11953 + break;
11954 +
11955 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11956 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11957 + nop == 0x01000000U)
11958 + {
11959 + unsigned long addr;
11960 + unsigned int save, call;
11961 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11962 +
11963 + if ((ba & 0xFFC00000U) == 0x30800000U)
11964 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11965 + else
11966 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11967 +
11968 + if (test_thread_flag(TIF_32BIT))
11969 + addr &= 0xFFFFFFFFUL;
11970 +
11971 + err = get_user(save, (unsigned int *)addr);
11972 + err |= get_user(call, (unsigned int *)(addr+4));
11973 + err |= get_user(nop, (unsigned int *)(addr+8));
11974 + if (err)
11975 + break;
11976 +
11977 +#ifdef CONFIG_PAX_DLRESOLVE
11978 + if (save == 0x9DE3BFA8U &&
11979 + (call & 0xC0000000U) == 0x40000000U &&
11980 + nop == 0x01000000U)
11981 + {
11982 + struct vm_area_struct *vma;
11983 + unsigned long call_dl_resolve;
11984 +
11985 + down_read(&current->mm->mmap_sem);
11986 + call_dl_resolve = current->mm->call_dl_resolve;
11987 + up_read(&current->mm->mmap_sem);
11988 + if (likely(call_dl_resolve))
11989 + goto emulate;
11990 +
11991 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11992 +
11993 + down_write(&current->mm->mmap_sem);
11994 + if (current->mm->call_dl_resolve) {
11995 + call_dl_resolve = current->mm->call_dl_resolve;
11996 + up_write(&current->mm->mmap_sem);
11997 + if (vma)
11998 + kmem_cache_free(vm_area_cachep, vma);
11999 + goto emulate;
12000 + }
12001 +
12002 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12003 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12004 + up_write(&current->mm->mmap_sem);
12005 + if (vma)
12006 + kmem_cache_free(vm_area_cachep, vma);
12007 + return 1;
12008 + }
12009 +
12010 + if (pax_insert_vma(vma, call_dl_resolve)) {
12011 + up_write(&current->mm->mmap_sem);
12012 + kmem_cache_free(vm_area_cachep, vma);
12013 + return 1;
12014 + }
12015 +
12016 + current->mm->call_dl_resolve = call_dl_resolve;
12017 + up_write(&current->mm->mmap_sem);
12018 +
12019 +emulate:
12020 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12021 + regs->tpc = call_dl_resolve;
12022 + regs->tnpc = addr+4;
12023 + return 3;
12024 + }
12025 +#endif
12026 +
12027 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12028 + if ((save & 0xFFC00000U) == 0x05000000U &&
12029 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12030 + nop == 0x01000000U)
12031 + {
12032 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033 + regs->u_regs[UREG_G2] = addr + 4;
12034 + addr = (save & 0x003FFFFFU) << 10;
12035 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12036 +
12037 + if (test_thread_flag(TIF_32BIT))
12038 + addr &= 0xFFFFFFFFUL;
12039 +
12040 + regs->tpc = addr;
12041 + regs->tnpc = addr+4;
12042 + return 3;
12043 + }
12044 +
12045 + /* PaX: 64-bit PLT stub */
12046 + err = get_user(sethi1, (unsigned int *)addr);
12047 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12048 + err |= get_user(or1, (unsigned int *)(addr+8));
12049 + err |= get_user(or2, (unsigned int *)(addr+12));
12050 + err |= get_user(sllx, (unsigned int *)(addr+16));
12051 + err |= get_user(add, (unsigned int *)(addr+20));
12052 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12053 + err |= get_user(nop, (unsigned int *)(addr+28));
12054 + if (err)
12055 + break;
12056 +
12057 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12058 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12059 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12060 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12061 + sllx == 0x89293020U &&
12062 + add == 0x8A010005U &&
12063 + jmpl == 0x89C14000U &&
12064 + nop == 0x01000000U)
12065 + {
12066 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12067 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12068 + regs->u_regs[UREG_G4] <<= 32;
12069 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12070 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12071 + regs->u_regs[UREG_G4] = addr + 24;
12072 + addr = regs->u_regs[UREG_G5];
12073 + regs->tpc = addr;
12074 + regs->tnpc = addr+4;
12075 + return 3;
12076 + }
12077 + }
12078 + } while (0);
12079 +
12080 +#ifdef CONFIG_PAX_DLRESOLVE
12081 + do { /* PaX: unpatched PLT emulation step 2 */
12082 + unsigned int save, call, nop;
12083 +
12084 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12085 + err |= get_user(call, (unsigned int *)regs->tpc);
12086 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12087 + if (err)
12088 + break;
12089 +
12090 + if (save == 0x9DE3BFA8U &&
12091 + (call & 0xC0000000U) == 0x40000000U &&
12092 + nop == 0x01000000U)
12093 + {
12094 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12095 +
12096 + if (test_thread_flag(TIF_32BIT))
12097 + dl_resolve &= 0xFFFFFFFFUL;
12098 +
12099 + regs->u_regs[UREG_RETPC] = regs->tpc;
12100 + regs->tpc = dl_resolve;
12101 + regs->tnpc = dl_resolve+4;
12102 + return 3;
12103 + }
12104 + } while (0);
12105 +#endif
12106 +
12107 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12108 + unsigned int sethi, ba, nop;
12109 +
12110 + err = get_user(sethi, (unsigned int *)regs->tpc);
12111 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12112 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12113 +
12114 + if (err)
12115 + break;
12116 +
12117 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12118 + (ba & 0xFFF00000U) == 0x30600000U &&
12119 + nop == 0x01000000U)
12120 + {
12121 + unsigned long addr;
12122 +
12123 + addr = (sethi & 0x003FFFFFU) << 10;
12124 + regs->u_regs[UREG_G1] = addr;
12125 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12126 +
12127 + if (test_thread_flag(TIF_32BIT))
12128 + addr &= 0xFFFFFFFFUL;
12129 +
12130 + regs->tpc = addr;
12131 + regs->tnpc = addr+4;
12132 + return 2;
12133 + }
12134 + } while (0);
12135 +
12136 +#endif
12137 +
12138 + return 1;
12139 +}
12140 +
12141 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12142 +{
12143 + unsigned long i;
12144 +
12145 + printk(KERN_ERR "PAX: bytes at PC: ");
12146 + for (i = 0; i < 8; i++) {
12147 + unsigned int c;
12148 + if (get_user(c, (unsigned int *)pc+i))
12149 + printk(KERN_CONT "???????? ");
12150 + else
12151 + printk(KERN_CONT "%08x ", c);
12152 + }
12153 + printk("\n");
12154 +}
12155 +#endif
12156 +
12157 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12158 {
12159 enum ctx_state prev_state = exception_enter();
12160 @@ -353,6 +816,29 @@ retry:
12161 if (!vma)
12162 goto bad_area;
12163
12164 +#ifdef CONFIG_PAX_PAGEEXEC
12165 + /* PaX: detect ITLB misses on non-exec pages */
12166 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12167 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12168 + {
12169 + if (address != regs->tpc)
12170 + goto good_area;
12171 +
12172 + up_read(&mm->mmap_sem);
12173 + switch (pax_handle_fetch_fault(regs)) {
12174 +
12175 +#ifdef CONFIG_PAX_EMUPLT
12176 + case 2:
12177 + case 3:
12178 + return;
12179 +#endif
12180 +
12181 + }
12182 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12183 + do_group_exit(SIGKILL);
12184 + }
12185 +#endif
12186 +
12187 /* Pure DTLB misses do not tell us whether the fault causing
12188 * load/store/atomic was a write or not, it only says that there
12189 * was no match. So in such a case we (carefully) read the
12190 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12191 index d329537..2c3746a 100644
12192 --- a/arch/sparc/mm/hugetlbpage.c
12193 +++ b/arch/sparc/mm/hugetlbpage.c
12194 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12195 unsigned long addr,
12196 unsigned long len,
12197 unsigned long pgoff,
12198 - unsigned long flags)
12199 + unsigned long flags,
12200 + unsigned long offset)
12201 {
12202 + struct mm_struct *mm = current->mm;
12203 unsigned long task_size = TASK_SIZE;
12204 struct vm_unmapped_area_info info;
12205
12206 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12207
12208 info.flags = 0;
12209 info.length = len;
12210 - info.low_limit = TASK_UNMAPPED_BASE;
12211 + info.low_limit = mm->mmap_base;
12212 info.high_limit = min(task_size, VA_EXCLUDE_START);
12213 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12214 info.align_offset = 0;
12215 + info.threadstack_offset = offset;
12216 addr = vm_unmapped_area(&info);
12217
12218 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12219 VM_BUG_ON(addr != -ENOMEM);
12220 info.low_limit = VA_EXCLUDE_END;
12221 +
12222 +#ifdef CONFIG_PAX_RANDMMAP
12223 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12224 + info.low_limit += mm->delta_mmap;
12225 +#endif
12226 +
12227 info.high_limit = task_size;
12228 addr = vm_unmapped_area(&info);
12229 }
12230 @@ -55,7 +64,8 @@ static unsigned long
12231 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12232 const unsigned long len,
12233 const unsigned long pgoff,
12234 - const unsigned long flags)
12235 + const unsigned long flags,
12236 + const unsigned long offset)
12237 {
12238 struct mm_struct *mm = current->mm;
12239 unsigned long addr = addr0;
12240 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12241 info.high_limit = mm->mmap_base;
12242 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12243 info.align_offset = 0;
12244 + info.threadstack_offset = offset;
12245 addr = vm_unmapped_area(&info);
12246
12247 /*
12248 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12249 VM_BUG_ON(addr != -ENOMEM);
12250 info.flags = 0;
12251 info.low_limit = TASK_UNMAPPED_BASE;
12252 +
12253 +#ifdef CONFIG_PAX_RANDMMAP
12254 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12255 + info.low_limit += mm->delta_mmap;
12256 +#endif
12257 +
12258 info.high_limit = STACK_TOP32;
12259 addr = vm_unmapped_area(&info);
12260 }
12261 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12262 struct mm_struct *mm = current->mm;
12263 struct vm_area_struct *vma;
12264 unsigned long task_size = TASK_SIZE;
12265 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12266
12267 if (test_thread_flag(TIF_32BIT))
12268 task_size = STACK_TOP32;
12269 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12270 return addr;
12271 }
12272
12273 +#ifdef CONFIG_PAX_RANDMMAP
12274 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12275 +#endif
12276 +
12277 if (addr) {
12278 addr = ALIGN(addr, HPAGE_SIZE);
12279 vma = find_vma(mm, addr);
12280 - if (task_size - len >= addr &&
12281 - (!vma || addr + len <= vma->vm_start))
12282 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12283 return addr;
12284 }
12285 if (mm->get_unmapped_area == arch_get_unmapped_area)
12286 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12287 - pgoff, flags);
12288 + pgoff, flags, offset);
12289 else
12290 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12291 - pgoff, flags);
12292 + pgoff, flags, offset);
12293 }
12294
12295 pte_t *huge_pte_alloc(struct mm_struct *mm,
12296 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12297 index 2d91c62..17a8fff 100644
12298 --- a/arch/sparc/mm/init_64.c
12299 +++ b/arch/sparc/mm/init_64.c
12300 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12301 int num_kernel_image_mappings;
12302
12303 #ifdef CONFIG_DEBUG_DCFLUSH
12304 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12305 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12306 #ifdef CONFIG_SMP
12307 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12308 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12309 #endif
12310 #endif
12311
12312 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12313 {
12314 BUG_ON(tlb_type == hypervisor);
12315 #ifdef CONFIG_DEBUG_DCFLUSH
12316 - atomic_inc(&dcpage_flushes);
12317 + atomic_inc_unchecked(&dcpage_flushes);
12318 #endif
12319
12320 #ifdef DCACHE_ALIASING_POSSIBLE
12321 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12322
12323 #ifdef CONFIG_DEBUG_DCFLUSH
12324 seq_printf(m, "DCPageFlushes\t: %d\n",
12325 - atomic_read(&dcpage_flushes));
12326 + atomic_read_unchecked(&dcpage_flushes));
12327 #ifdef CONFIG_SMP
12328 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12329 - atomic_read(&dcpage_flushes_xcall));
12330 + atomic_read_unchecked(&dcpage_flushes_xcall));
12331 #endif /* CONFIG_SMP */
12332 #endif /* CONFIG_DEBUG_DCFLUSH */
12333 }
12334 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12335 index 7cca418..53fc030 100644
12336 --- a/arch/tile/Kconfig
12337 +++ b/arch/tile/Kconfig
12338 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12339
12340 config KEXEC
12341 bool "kexec system call"
12342 + depends on !GRKERNSEC_KMEM
12343 ---help---
12344 kexec is a system call that implements the ability to shutdown your
12345 current kernel, and to start another kernel. It is like a reboot
12346 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12347 index 7b11c5f..755a026 100644
12348 --- a/arch/tile/include/asm/atomic_64.h
12349 +++ b/arch/tile/include/asm/atomic_64.h
12350 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12351
12352 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12353
12354 +#define atomic64_read_unchecked(v) atomic64_read(v)
12355 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12356 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12357 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12358 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12359 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12360 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12361 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12362 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12363 +
12364 /* Define this to indicate that cmpxchg is an efficient operation. */
12365 #define __HAVE_ARCH_CMPXCHG
12366
12367 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12368 index 6160761..00cac88 100644
12369 --- a/arch/tile/include/asm/cache.h
12370 +++ b/arch/tile/include/asm/cache.h
12371 @@ -15,11 +15,12 @@
12372 #ifndef _ASM_TILE_CACHE_H
12373 #define _ASM_TILE_CACHE_H
12374
12375 +#include <linux/const.h>
12376 #include <arch/chip.h>
12377
12378 /* bytes per L1 data cache line */
12379 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12380 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12381 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12382
12383 /* bytes per L2 cache line */
12384 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12385 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12386 index b6cde32..c0cb736 100644
12387 --- a/arch/tile/include/asm/uaccess.h
12388 +++ b/arch/tile/include/asm/uaccess.h
12389 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12390 const void __user *from,
12391 unsigned long n)
12392 {
12393 - int sz = __compiletime_object_size(to);
12394 + size_t sz = __compiletime_object_size(to);
12395
12396 - if (likely(sz == -1 || sz >= n))
12397 + if (likely(sz == (size_t)-1 || sz >= n))
12398 n = _copy_from_user(to, from, n);
12399 else
12400 copy_from_user_overflow();
12401 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12402 index e514899..f8743c4 100644
12403 --- a/arch/tile/mm/hugetlbpage.c
12404 +++ b/arch/tile/mm/hugetlbpage.c
12405 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12406 info.high_limit = TASK_SIZE;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409 + info.threadstack_offset = 0;
12410 return vm_unmapped_area(&info);
12411 }
12412
12413 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12414 info.high_limit = current->mm->mmap_base;
12415 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12416 info.align_offset = 0;
12417 + info.threadstack_offset = 0;
12418 addr = vm_unmapped_area(&info);
12419
12420 /*
12421 diff --git a/arch/um/Makefile b/arch/um/Makefile
12422 index e4b1a96..16162f8 100644
12423 --- a/arch/um/Makefile
12424 +++ b/arch/um/Makefile
12425 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12428
12429 +ifdef CONSTIFY_PLUGIN
12430 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12431 +endif
12432 +
12433 #This will adjust *FLAGS accordingly to the platform.
12434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12435
12436 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12437 index 19e1bdd..3665b77 100644
12438 --- a/arch/um/include/asm/cache.h
12439 +++ b/arch/um/include/asm/cache.h
12440 @@ -1,6 +1,7 @@
12441 #ifndef __UM_CACHE_H
12442 #define __UM_CACHE_H
12443
12444 +#include <linux/const.h>
12445
12446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12448 @@ -12,6 +13,6 @@
12449 # define L1_CACHE_SHIFT 5
12450 #endif
12451
12452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12454
12455 #endif
12456 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12457 index 2e0a6b1..a64d0f5 100644
12458 --- a/arch/um/include/asm/kmap_types.h
12459 +++ b/arch/um/include/asm/kmap_types.h
12460 @@ -8,6 +8,6 @@
12461
12462 /* No more #include "asm/arch/kmap_types.h" ! */
12463
12464 -#define KM_TYPE_NR 14
12465 +#define KM_TYPE_NR 15
12466
12467 #endif
12468 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12469 index 71c5d13..4c7b9f1 100644
12470 --- a/arch/um/include/asm/page.h
12471 +++ b/arch/um/include/asm/page.h
12472 @@ -14,6 +14,9 @@
12473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12474 #define PAGE_MASK (~(PAGE_SIZE-1))
12475
12476 +#define ktla_ktva(addr) (addr)
12477 +#define ktva_ktla(addr) (addr)
12478 +
12479 #ifndef __ASSEMBLY__
12480
12481 struct page;
12482 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12483 index 0032f92..cd151e0 100644
12484 --- a/arch/um/include/asm/pgtable-3level.h
12485 +++ b/arch/um/include/asm/pgtable-3level.h
12486 @@ -58,6 +58,7 @@
12487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12488 #define pud_populate(mm, pud, pmd) \
12489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12490 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12491
12492 #ifdef CONFIG_64BIT
12493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12494 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12495 index f17bca8..48adb87 100644
12496 --- a/arch/um/kernel/process.c
12497 +++ b/arch/um/kernel/process.c
12498 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12499 return 2;
12500 }
12501
12502 -/*
12503 - * Only x86 and x86_64 have an arch_align_stack().
12504 - * All other arches have "#define arch_align_stack(x) (x)"
12505 - * in their asm/exec.h
12506 - * As this is included in UML from asm-um/system-generic.h,
12507 - * we can use it to behave as the subarch does.
12508 - */
12509 -#ifndef arch_align_stack
12510 -unsigned long arch_align_stack(unsigned long sp)
12511 -{
12512 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12513 - sp -= get_random_int() % 8192;
12514 - return sp & ~0xf;
12515 -}
12516 -#endif
12517 -
12518 unsigned long get_wchan(struct task_struct *p)
12519 {
12520 unsigned long stack_page, sp, ip;
12521 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12522 index ad8f795..2c7eec6 100644
12523 --- a/arch/unicore32/include/asm/cache.h
12524 +++ b/arch/unicore32/include/asm/cache.h
12525 @@ -12,8 +12,10 @@
12526 #ifndef __UNICORE_CACHE_H__
12527 #define __UNICORE_CACHE_H__
12528
12529 -#define L1_CACHE_SHIFT (5)
12530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531 +#include <linux/const.h>
12532 +
12533 +#define L1_CACHE_SHIFT 5
12534 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12535
12536 /*
12537 * Memory returned by kmalloc() may be used for DMA, so we must make
12538 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12539 index 3635fff..c1f9fab 100644
12540 --- a/arch/x86/Kconfig
12541 +++ b/arch/x86/Kconfig
12542 @@ -129,7 +129,7 @@ config X86
12543 select RTC_LIB
12544 select HAVE_DEBUG_STACKOVERFLOW
12545 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12546 - select HAVE_CC_STACKPROTECTOR
12547 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12548 select GENERIC_CPU_AUTOPROBE
12549 select HAVE_ARCH_AUDITSYSCALL
12550 select ARCH_SUPPORTS_ATOMIC_RMW
12551 @@ -262,7 +262,7 @@ config X86_HT
12552
12553 config X86_32_LAZY_GS
12554 def_bool y
12555 - depends on X86_32 && !CC_STACKPROTECTOR
12556 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12557
12558 config ARCH_HWEIGHT_CFLAGS
12559 string
12560 @@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12561
12562 menuconfig HYPERVISOR_GUEST
12563 bool "Linux guest support"
12564 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12565 ---help---
12566 Say Y here to enable options for running Linux under various hyper-
12567 visors. This option enables basic hypervisor detection and platform
12568 @@ -977,6 +978,7 @@ config VM86
12569
12570 config X86_16BIT
12571 bool "Enable support for 16-bit segments" if EXPERT
12572 + depends on !GRKERNSEC
12573 default y
12574 ---help---
12575 This option is required by programs like Wine to run 16-bit
12576 @@ -1132,6 +1134,7 @@ choice
12577
12578 config NOHIGHMEM
12579 bool "off"
12580 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12581 ---help---
12582 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12583 However, the address space of 32-bit x86 processors is only 4
12584 @@ -1168,6 +1171,7 @@ config NOHIGHMEM
12585
12586 config HIGHMEM4G
12587 bool "4GB"
12588 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12589 ---help---
12590 Select this if you have a 32-bit processor and between 1 and 4
12591 gigabytes of physical RAM.
12592 @@ -1220,7 +1224,7 @@ config PAGE_OFFSET
12593 hex
12594 default 0xB0000000 if VMSPLIT_3G_OPT
12595 default 0x80000000 if VMSPLIT_2G
12596 - default 0x78000000 if VMSPLIT_2G_OPT
12597 + default 0x70000000 if VMSPLIT_2G_OPT
12598 default 0x40000000 if VMSPLIT_1G
12599 default 0xC0000000
12600 depends on X86_32
12601 @@ -1635,6 +1639,7 @@ source kernel/Kconfig.hz
12602
12603 config KEXEC
12604 bool "kexec system call"
12605 + depends on !GRKERNSEC_KMEM
12606 ---help---
12607 kexec is a system call that implements the ability to shutdown your
12608 current kernel, and to start another kernel. It is like a reboot
12609 @@ -1820,7 +1825,9 @@ config X86_NEED_RELOCS
12610
12611 config PHYSICAL_ALIGN
12612 hex "Alignment value to which kernel should be aligned"
12613 - default "0x200000"
12614 + default "0x1000000"
12615 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12616 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12617 range 0x2000 0x1000000 if X86_32
12618 range 0x200000 0x1000000 if X86_64
12619 ---help---
12620 @@ -1903,6 +1910,7 @@ config COMPAT_VDSO
12621 def_bool n
12622 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12623 depends on X86_32 || IA32_EMULATION
12624 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12625 ---help---
12626 Certain buggy versions of glibc will crash if they are
12627 presented with a 32-bit vDSO that is not mapped at the address
12628 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12629 index 6983314..54ad7e8 100644
12630 --- a/arch/x86/Kconfig.cpu
12631 +++ b/arch/x86/Kconfig.cpu
12632 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12633
12634 config X86_F00F_BUG
12635 def_bool y
12636 - depends on M586MMX || M586TSC || M586 || M486
12637 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12638
12639 config X86_INVD_BUG
12640 def_bool y
12641 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12642
12643 config X86_ALIGNMENT_16
12644 def_bool y
12645 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12646 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12647
12648 config X86_INTEL_USERCOPY
12649 def_bool y
12650 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12651 # generates cmov.
12652 config X86_CMOV
12653 def_bool y
12654 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12655 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12656
12657 config X86_MINIMUM_CPU_FAMILY
12658 int
12659 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12660 index 61bd2ad..50b625d 100644
12661 --- a/arch/x86/Kconfig.debug
12662 +++ b/arch/x86/Kconfig.debug
12663 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12664 config DEBUG_RODATA
12665 bool "Write protect kernel read-only data structures"
12666 default y
12667 - depends on DEBUG_KERNEL
12668 + depends on DEBUG_KERNEL && BROKEN
12669 ---help---
12670 Mark the kernel read-only data as write-protected in the pagetables,
12671 in order to catch accidental (and incorrect) writes to such const
12672 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12673
12674 config DEBUG_SET_MODULE_RONX
12675 bool "Set loadable kernel module data as NX and text as RO"
12676 - depends on MODULES
12677 + depends on MODULES && BROKEN
12678 ---help---
12679 This option helps catch unintended modifications to loadable
12680 kernel module's text and read-only data. It also prevents execution
12681 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12682 index 920e616..ac3d4df 100644
12683 --- a/arch/x86/Makefile
12684 +++ b/arch/x86/Makefile
12685 @@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12686 # CPU-specific tuning. Anything which can be shared with UML should go here.
12687 include $(srctree)/arch/x86/Makefile_32.cpu
12688 KBUILD_CFLAGS += $(cflags-y)
12689 -
12690 - # temporary until string.h is fixed
12691 - KBUILD_CFLAGS += -ffreestanding
12692 else
12693 BITS := 64
12694 UTS_MACHINE := x86_64
12695 @@ -107,6 +104,9 @@ else
12696 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12697 endif
12698
12699 +# temporary until string.h is fixed
12700 +KBUILD_CFLAGS += -ffreestanding
12701 +
12702 # Make sure compiler does not have buggy stack-protector support.
12703 ifdef CONFIG_CC_STACKPROTECTOR
12704 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12705 @@ -180,6 +180,7 @@ archheaders:
12706 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12707
12708 archprepare:
12709 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12710 ifeq ($(CONFIG_KEXEC_FILE),y)
12711 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12712 endif
12713 @@ -263,3 +264,9 @@ define archhelp
12714 echo ' FDARGS="..." arguments for the booted kernel'
12715 echo ' FDINITRD=file initrd for the booted kernel'
12716 endef
12717 +
12718 +define OLD_LD
12719 +
12720 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12721 +*** Please upgrade your binutils to 2.18 or newer
12722 +endef
12723 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12724 index 3db07f3..9d81d0f 100644
12725 --- a/arch/x86/boot/Makefile
12726 +++ b/arch/x86/boot/Makefile
12727 @@ -56,6 +56,9 @@ clean-files += cpustr.h
12728 # ---------------------------------------------------------------------------
12729
12730 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12731 +ifdef CONSTIFY_PLUGIN
12732 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12733 +endif
12734 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12735 GCOV_PROFILE := n
12736
12737 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12738 index 878e4b9..20537ab 100644
12739 --- a/arch/x86/boot/bitops.h
12740 +++ b/arch/x86/boot/bitops.h
12741 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12742 u8 v;
12743 const u32 *p = (const u32 *)addr;
12744
12745 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12746 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12747 return v;
12748 }
12749
12750 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12751
12752 static inline void set_bit(int nr, void *addr)
12753 {
12754 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12755 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12756 }
12757
12758 #endif /* BOOT_BITOPS_H */
12759 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12760 index bd49ec6..94c7f58 100644
12761 --- a/arch/x86/boot/boot.h
12762 +++ b/arch/x86/boot/boot.h
12763 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12764 static inline u16 ds(void)
12765 {
12766 u16 seg;
12767 - asm("movw %%ds,%0" : "=rm" (seg));
12768 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12769 return seg;
12770 }
12771
12772 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12773 index 6a1a845..0ad2dae 100644
12774 --- a/arch/x86/boot/compressed/Makefile
12775 +++ b/arch/x86/boot/compressed/Makefile
12776 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12777 KBUILD_CFLAGS += -mno-mmx -mno-sse
12778 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12779 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12780 +ifdef CONSTIFY_PLUGIN
12781 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12782 +endif
12783
12784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12785 GCOV_PROFILE := n
12786 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12787 index a53440e..c3dbf1e 100644
12788 --- a/arch/x86/boot/compressed/efi_stub_32.S
12789 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12790 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12791 * parameter 2, ..., param n. To make things easy, we save the return
12792 * address of efi_call_phys in a global variable.
12793 */
12794 - popl %ecx
12795 - movl %ecx, saved_return_addr(%edx)
12796 - /* get the function pointer into ECX*/
12797 - popl %ecx
12798 - movl %ecx, efi_rt_function_ptr(%edx)
12799 + popl saved_return_addr(%edx)
12800 + popl efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 3. Call the physical function.
12804 */
12805 - call *%ecx
12806 + call *efi_rt_function_ptr(%edx)
12807
12808 /*
12809 * 4. Balance the stack. And because EAX contain the return value,
12810 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12811 1: popl %edx
12812 subl $1b, %edx
12813
12814 - movl efi_rt_function_ptr(%edx), %ecx
12815 - pushl %ecx
12816 + pushl efi_rt_function_ptr(%edx)
12817
12818 /*
12819 * 10. Push the saved return address onto the stack and return.
12820 */
12821 - movl saved_return_addr(%edx), %ecx
12822 - pushl %ecx
12823 - ret
12824 + jmpl *saved_return_addr(%edx)
12825 ENDPROC(efi_call_phys)
12826 .previous
12827
12828 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12829 index 1d7fbbc..36ecd58 100644
12830 --- a/arch/x86/boot/compressed/head_32.S
12831 +++ b/arch/x86/boot/compressed/head_32.S
12832 @@ -140,10 +140,10 @@ preferred_addr:
12833 addl %eax, %ebx
12834 notl %eax
12835 andl %eax, %ebx
12836 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12837 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12838 jge 1f
12839 #endif
12840 - movl $LOAD_PHYSICAL_ADDR, %ebx
12841 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12842 1:
12843
12844 /* Target address to relocate to for decompression */
12845 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12846 index 6b1766c..ad465c9 100644
12847 --- a/arch/x86/boot/compressed/head_64.S
12848 +++ b/arch/x86/boot/compressed/head_64.S
12849 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12850 addl %eax, %ebx
12851 notl %eax
12852 andl %eax, %ebx
12853 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12854 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12855 jge 1f
12856 #endif
12857 - movl $LOAD_PHYSICAL_ADDR, %ebx
12858 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12859 1:
12860
12861 /* Target address to relocate to for decompression */
12862 @@ -322,10 +322,10 @@ preferred_addr:
12863 addq %rax, %rbp
12864 notq %rax
12865 andq %rax, %rbp
12866 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12867 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12868 jge 1f
12869 #endif
12870 - movq $LOAD_PHYSICAL_ADDR, %rbp
12871 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12872 1:
12873
12874 /* Target address to relocate to for decompression */
12875 @@ -434,8 +434,8 @@ gdt:
12876 .long gdt
12877 .word 0
12878 .quad 0x0000000000000000 /* NULL descriptor */
12879 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12880 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12881 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12882 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12883 .quad 0x0080890000000000 /* TS descriptor */
12884 .quad 0x0000000000000000 /* TS continued */
12885 gdt_end:
12886 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12887 index 0c33a7c..be226ed 100644
12888 --- a/arch/x86/boot/compressed/misc.c
12889 +++ b/arch/x86/boot/compressed/misc.c
12890 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12891 * Calculate the delta between where vmlinux was linked to load
12892 * and where it was actually loaded.
12893 */
12894 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12895 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12896 if (!delta) {
12897 debug_putstr("No relocation needed... ");
12898 return;
12899 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12900 Elf32_Ehdr ehdr;
12901 Elf32_Phdr *phdrs, *phdr;
12902 #endif
12903 - void *dest;
12904 + void *dest, *prev;
12905 int i;
12906
12907 memcpy(&ehdr, output, sizeof(ehdr));
12908 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12909 case PT_LOAD:
12910 #ifdef CONFIG_RELOCATABLE
12911 dest = output;
12912 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12913 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12914 #else
12915 dest = (void *)(phdr->p_paddr);
12916 #endif
12917 memcpy(dest,
12918 output + phdr->p_offset,
12919 phdr->p_filesz);
12920 + if (i)
12921 + memset(prev, 0xff, dest - prev);
12922 + prev = dest + phdr->p_filesz;
12923 break;
12924 default: /* Ignore other PT_* */ break;
12925 }
12926 @@ -404,7 +407,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12927 error("Destination address too large");
12928 #endif
12929 #ifndef CONFIG_RELOCATABLE
12930 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12931 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12932 error("Wrong destination address");
12933 #endif
12934
12935 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12936 index 1fd7d57..0f7d096 100644
12937 --- a/arch/x86/boot/cpucheck.c
12938 +++ b/arch/x86/boot/cpucheck.c
12939 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12940 u32 ecx = MSR_K7_HWCR;
12941 u32 eax, edx;
12942
12943 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12944 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12945 eax &= ~(1 << 15);
12946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12948
12949 get_cpuflags(); /* Make sure it really did something */
12950 err = check_cpuflags();
12951 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12952 u32 ecx = MSR_VIA_FCR;
12953 u32 eax, edx;
12954
12955 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12956 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12957 eax |= (1<<1)|(1<<7);
12958 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12959 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12960
12961 set_bit(X86_FEATURE_CX8, cpu.flags);
12962 err = check_cpuflags();
12963 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12964 u32 eax, edx;
12965 u32 level = 1;
12966
12967 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12968 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12969 - asm("cpuid"
12970 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972 + asm volatile("cpuid"
12973 : "+a" (level), "=d" (cpu.flags[0])
12974 : : "ecx", "ebx");
12975 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12976 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12977
12978 err = check_cpuflags();
12979 } else if (err == 0x01 &&
12980 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12981 index 16ef025..91e033b 100644
12982 --- a/arch/x86/boot/header.S
12983 +++ b/arch/x86/boot/header.S
12984 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12985 # single linked list of
12986 # struct setup_data
12987
12988 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12989 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12990
12991 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12992 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12993 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12994 +#else
12995 #define VO_INIT_SIZE (VO__end - VO__text)
12996 +#endif
12997 #if ZO_INIT_SIZE > VO_INIT_SIZE
12998 #define INIT_SIZE ZO_INIT_SIZE
12999 #else
13000 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13001 index db75d07..8e6d0af 100644
13002 --- a/arch/x86/boot/memory.c
13003 +++ b/arch/x86/boot/memory.c
13004 @@ -19,7 +19,7 @@
13005
13006 static int detect_memory_e820(void)
13007 {
13008 - int count = 0;
13009 + unsigned int count = 0;
13010 struct biosregs ireg, oreg;
13011 struct e820entry *desc = boot_params.e820_map;
13012 static struct e820entry buf; /* static so it is zeroed */
13013 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13014 index ba3e100..6501b8f 100644
13015 --- a/arch/x86/boot/video-vesa.c
13016 +++ b/arch/x86/boot/video-vesa.c
13017 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13018
13019 boot_params.screen_info.vesapm_seg = oreg.es;
13020 boot_params.screen_info.vesapm_off = oreg.di;
13021 + boot_params.screen_info.vesapm_size = oreg.cx;
13022 }
13023
13024 /*
13025 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13026 index 43eda28..5ab5fdb 100644
13027 --- a/arch/x86/boot/video.c
13028 +++ b/arch/x86/boot/video.c
13029 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13030 static unsigned int get_entry(void)
13031 {
13032 char entry_buf[4];
13033 - int i, len = 0;
13034 + unsigned int i, len = 0;
13035 int key;
13036 unsigned int v;
13037
13038 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13039 index 9105655..41779c1 100644
13040 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13041 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13042 @@ -8,6 +8,8 @@
13043 * including this sentence is retained in full.
13044 */
13045
13046 +#include <asm/alternative-asm.h>
13047 +
13048 .extern crypto_ft_tab
13049 .extern crypto_it_tab
13050 .extern crypto_fl_tab
13051 @@ -70,6 +72,8 @@
13052 je B192; \
13053 leaq 32(r9),r9;
13054
13055 +#define ret pax_force_retaddr; ret
13056 +
13057 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13058 movq r1,r2; \
13059 movq r3,r4; \
13060 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13061 index 477e9d7..c92c7d8 100644
13062 --- a/arch/x86/crypto/aesni-intel_asm.S
13063 +++ b/arch/x86/crypto/aesni-intel_asm.S
13064 @@ -31,6 +31,7 @@
13065
13066 #include <linux/linkage.h>
13067 #include <asm/inst.h>
13068 +#include <asm/alternative-asm.h>
13069
13070 #ifdef __x86_64__
13071 .data
13072 @@ -205,7 +206,7 @@ enc: .octa 0x2
13073 * num_initial_blocks = b mod 4
13074 * encrypt the initial num_initial_blocks blocks and apply ghash on
13075 * the ciphertext
13076 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13077 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13078 * are clobbered
13079 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13080 */
13081 @@ -214,8 +215,8 @@ enc: .octa 0x2
13082 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13083 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13084 mov arg7, %r10 # %r10 = AAD
13085 - mov arg8, %r12 # %r12 = aadLen
13086 - mov %r12, %r11
13087 + mov arg8, %r15 # %r15 = aadLen
13088 + mov %r15, %r11
13089 pxor %xmm\i, %xmm\i
13090 _get_AAD_loop\num_initial_blocks\operation:
13091 movd (%r10), \TMP1
13092 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13093 psrldq $4, %xmm\i
13094 pxor \TMP1, %xmm\i
13095 add $4, %r10
13096 - sub $4, %r12
13097 + sub $4, %r15
13098 jne _get_AAD_loop\num_initial_blocks\operation
13099 cmp $16, %r11
13100 je _get_AAD_loop2_done\num_initial_blocks\operation
13101 - mov $16, %r12
13102 + mov $16, %r15
13103 _get_AAD_loop2\num_initial_blocks\operation:
13104 psrldq $4, %xmm\i
13105 - sub $4, %r12
13106 - cmp %r11, %r12
13107 + sub $4, %r15
13108 + cmp %r11, %r15
13109 jne _get_AAD_loop2\num_initial_blocks\operation
13110 _get_AAD_loop2_done\num_initial_blocks\operation:
13111 movdqa SHUF_MASK(%rip), %xmm14
13112 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13113 * num_initial_blocks = b mod 4
13114 * encrypt the initial num_initial_blocks blocks and apply ghash on
13115 * the ciphertext
13116 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13117 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13118 * are clobbered
13119 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13120 */
13121 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13122 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13123 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13124 mov arg7, %r10 # %r10 = AAD
13125 - mov arg8, %r12 # %r12 = aadLen
13126 - mov %r12, %r11
13127 + mov arg8, %r15 # %r15 = aadLen
13128 + mov %r15, %r11
13129 pxor %xmm\i, %xmm\i
13130 _get_AAD_loop\num_initial_blocks\operation:
13131 movd (%r10), \TMP1
13132 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13133 psrldq $4, %xmm\i
13134 pxor \TMP1, %xmm\i
13135 add $4, %r10
13136 - sub $4, %r12
13137 + sub $4, %r15
13138 jne _get_AAD_loop\num_initial_blocks\operation
13139 cmp $16, %r11
13140 je _get_AAD_loop2_done\num_initial_blocks\operation
13141 - mov $16, %r12
13142 + mov $16, %r15
13143 _get_AAD_loop2\num_initial_blocks\operation:
13144 psrldq $4, %xmm\i
13145 - sub $4, %r12
13146 - cmp %r11, %r12
13147 + sub $4, %r15
13148 + cmp %r11, %r15
13149 jne _get_AAD_loop2\num_initial_blocks\operation
13150 _get_AAD_loop2_done\num_initial_blocks\operation:
13151 movdqa SHUF_MASK(%rip), %xmm14
13152 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13153 *
13154 *****************************************************************************/
13155 ENTRY(aesni_gcm_dec)
13156 - push %r12
13157 + push %r15
13158 push %r13
13159 push %r14
13160 mov %rsp, %r14
13161 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13162 */
13163 sub $VARIABLE_OFFSET, %rsp
13164 and $~63, %rsp # align rsp to 64 bytes
13165 - mov %arg6, %r12
13166 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13167 + mov %arg6, %r15
13168 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13169 movdqa SHUF_MASK(%rip), %xmm2
13170 PSHUFB_XMM %xmm2, %xmm13
13171
13172 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13173 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13174 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13175 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13176 - mov %r13, %r12
13177 - and $(3<<4), %r12
13178 + mov %r13, %r15
13179 + and $(3<<4), %r15
13180 jz _initial_num_blocks_is_0_decrypt
13181 - cmp $(2<<4), %r12
13182 + cmp $(2<<4), %r15
13183 jb _initial_num_blocks_is_1_decrypt
13184 je _initial_num_blocks_is_2_decrypt
13185 _initial_num_blocks_is_3_decrypt:
13186 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13187 sub $16, %r11
13188 add %r13, %r11
13189 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13190 - lea SHIFT_MASK+16(%rip), %r12
13191 - sub %r13, %r12
13192 + lea SHIFT_MASK+16(%rip), %r15
13193 + sub %r13, %r15
13194 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13195 # (%r13 is the number of bytes in plaintext mod 16)
13196 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13197 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13198 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13199
13200 movdqa %xmm1, %xmm2
13201 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13202 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13203 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13204 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13205 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13206 pand %xmm1, %xmm2
13207 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13208 sub $1, %r13
13209 jne _less_than_8_bytes_left_decrypt
13210 _multiple_of_16_bytes_decrypt:
13211 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13212 - shl $3, %r12 # convert into number of bits
13213 - movd %r12d, %xmm15 # len(A) in %xmm15
13214 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13215 + shl $3, %r15 # convert into number of bits
13216 + movd %r15d, %xmm15 # len(A) in %xmm15
13217 shl $3, %arg4 # len(C) in bits (*128)
13218 MOVQ_R64_XMM %arg4, %xmm1
13219 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13220 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13221 mov %r14, %rsp
13222 pop %r14
13223 pop %r13
13224 - pop %r12
13225 + pop %r15
13226 + pax_force_retaddr
13227 ret
13228 ENDPROC(aesni_gcm_dec)
13229
13230 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13231 * poly = x^128 + x^127 + x^126 + x^121 + 1
13232 ***************************************************************************/
13233 ENTRY(aesni_gcm_enc)
13234 - push %r12
13235 + push %r15
13236 push %r13
13237 push %r14
13238 mov %rsp, %r14
13239 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13240 #
13241 sub $VARIABLE_OFFSET, %rsp
13242 and $~63, %rsp
13243 - mov %arg6, %r12
13244 - movdqu (%r12), %xmm13
13245 + mov %arg6, %r15
13246 + movdqu (%r15), %xmm13
13247 movdqa SHUF_MASK(%rip), %xmm2
13248 PSHUFB_XMM %xmm2, %xmm13
13249
13250 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13251 movdqa %xmm13, HashKey(%rsp)
13252 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13253 and $-16, %r13
13254 - mov %r13, %r12
13255 + mov %r13, %r15
13256
13257 # Encrypt first few blocks
13258
13259 - and $(3<<4), %r12
13260 + and $(3<<4), %r15
13261 jz _initial_num_blocks_is_0_encrypt
13262 - cmp $(2<<4), %r12
13263 + cmp $(2<<4), %r15
13264 jb _initial_num_blocks_is_1_encrypt
13265 je _initial_num_blocks_is_2_encrypt
13266 _initial_num_blocks_is_3_encrypt:
13267 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13268 sub $16, %r11
13269 add %r13, %r11
13270 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13271 - lea SHIFT_MASK+16(%rip), %r12
13272 - sub %r13, %r12
13273 + lea SHIFT_MASK+16(%rip), %r15
13274 + sub %r13, %r15
13275 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13276 # (%r13 is the number of bytes in plaintext mod 16)
13277 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13278 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13279 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13280 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13281 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13282 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13283 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13284 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13285 movdqa SHUF_MASK(%rip), %xmm10
13286 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13287 sub $1, %r13
13288 jne _less_than_8_bytes_left_encrypt
13289 _multiple_of_16_bytes_encrypt:
13290 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13291 - shl $3, %r12
13292 - movd %r12d, %xmm15 # len(A) in %xmm15
13293 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13294 + shl $3, %r15
13295 + movd %r15d, %xmm15 # len(A) in %xmm15
13296 shl $3, %arg4 # len(C) in bits (*128)
13297 MOVQ_R64_XMM %arg4, %xmm1
13298 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13299 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13300 mov %r14, %rsp
13301 pop %r14
13302 pop %r13
13303 - pop %r12
13304 + pop %r15
13305 + pax_force_retaddr
13306 ret
13307 ENDPROC(aesni_gcm_enc)
13308
13309 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13310 pxor %xmm1, %xmm0
13311 movaps %xmm0, (TKEYP)
13312 add $0x10, TKEYP
13313 + pax_force_retaddr
13314 ret
13315 ENDPROC(_key_expansion_128)
13316 ENDPROC(_key_expansion_256a)
13317 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13318 shufps $0b01001110, %xmm2, %xmm1
13319 movaps %xmm1, 0x10(TKEYP)
13320 add $0x20, TKEYP
13321 + pax_force_retaddr
13322 ret
13323 ENDPROC(_key_expansion_192a)
13324
13325 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13326
13327 movaps %xmm0, (TKEYP)
13328 add $0x10, TKEYP
13329 + pax_force_retaddr
13330 ret
13331 ENDPROC(_key_expansion_192b)
13332
13333 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13334 pxor %xmm1, %xmm2
13335 movaps %xmm2, (TKEYP)
13336 add $0x10, TKEYP
13337 + pax_force_retaddr
13338 ret
13339 ENDPROC(_key_expansion_256b)
13340
13341 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13342 #ifndef __x86_64__
13343 popl KEYP
13344 #endif
13345 + pax_force_retaddr
13346 ret
13347 ENDPROC(aesni_set_key)
13348
13349 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13350 popl KLEN
13351 popl KEYP
13352 #endif
13353 + pax_force_retaddr
13354 ret
13355 ENDPROC(aesni_enc)
13356
13357 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13358 AESENC KEY STATE
13359 movaps 0x70(TKEYP), KEY
13360 AESENCLAST KEY STATE
13361 + pax_force_retaddr
13362 ret
13363 ENDPROC(_aesni_enc1)
13364
13365 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13366 AESENCLAST KEY STATE2
13367 AESENCLAST KEY STATE3
13368 AESENCLAST KEY STATE4
13369 + pax_force_retaddr
13370 ret
13371 ENDPROC(_aesni_enc4)
13372
13373 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13374 popl KLEN
13375 popl KEYP
13376 #endif
13377 + pax_force_retaddr
13378 ret
13379 ENDPROC(aesni_dec)
13380
13381 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13382 AESDEC KEY STATE
13383 movaps 0x70(TKEYP), KEY
13384 AESDECLAST KEY STATE
13385 + pax_force_retaddr
13386 ret
13387 ENDPROC(_aesni_dec1)
13388
13389 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13390 AESDECLAST KEY STATE2
13391 AESDECLAST KEY STATE3
13392 AESDECLAST KEY STATE4
13393 + pax_force_retaddr
13394 ret
13395 ENDPROC(_aesni_dec4)
13396
13397 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13398 popl KEYP
13399 popl LEN
13400 #endif
13401 + pax_force_retaddr
13402 ret
13403 ENDPROC(aesni_ecb_enc)
13404
13405 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13406 popl KEYP
13407 popl LEN
13408 #endif
13409 + pax_force_retaddr
13410 ret
13411 ENDPROC(aesni_ecb_dec)
13412
13413 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13414 popl LEN
13415 popl IVP
13416 #endif
13417 + pax_force_retaddr
13418 ret
13419 ENDPROC(aesni_cbc_enc)
13420
13421 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13422 popl LEN
13423 popl IVP
13424 #endif
13425 + pax_force_retaddr
13426 ret
13427 ENDPROC(aesni_cbc_dec)
13428
13429 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13430 mov $1, TCTR_LOW
13431 MOVQ_R64_XMM TCTR_LOW INC
13432 MOVQ_R64_XMM CTR TCTR_LOW
13433 + pax_force_retaddr
13434 ret
13435 ENDPROC(_aesni_inc_init)
13436
13437 @@ -2579,6 +2598,7 @@ _aesni_inc:
13438 .Linc_low:
13439 movaps CTR, IV
13440 PSHUFB_XMM BSWAP_MASK IV
13441 + pax_force_retaddr
13442 ret
13443 ENDPROC(_aesni_inc)
13444
13445 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13446 .Lctr_enc_ret:
13447 movups IV, (IVP)
13448 .Lctr_enc_just_ret:
13449 + pax_force_retaddr
13450 ret
13451 ENDPROC(aesni_ctr_enc)
13452
13453 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13454 pxor INC, STATE4
13455 movdqu STATE4, 0x70(OUTP)
13456
13457 + pax_force_retaddr
13458 ret
13459 ENDPROC(aesni_xts_crypt8)
13460
13461 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13462 index 246c670..466e2d6 100644
13463 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13464 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465 @@ -21,6 +21,7 @@
13466 */
13467
13468 #include <linux/linkage.h>
13469 +#include <asm/alternative-asm.h>
13470
13471 .file "blowfish-x86_64-asm.S"
13472 .text
13473 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13474 jnz .L__enc_xor;
13475
13476 write_block();
13477 + pax_force_retaddr
13478 ret;
13479 .L__enc_xor:
13480 xor_block();
13481 + pax_force_retaddr
13482 ret;
13483 ENDPROC(__blowfish_enc_blk)
13484
13485 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13486
13487 movq %r11, %rbp;
13488
13489 + pax_force_retaddr
13490 ret;
13491 ENDPROC(blowfish_dec_blk)
13492
13493 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13494
13495 popq %rbx;
13496 popq %rbp;
13497 + pax_force_retaddr
13498 ret;
13499
13500 .L__enc_xor4:
13501 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13502
13503 popq %rbx;
13504 popq %rbp;
13505 + pax_force_retaddr
13506 ret;
13507 ENDPROC(__blowfish_enc_blk_4way)
13508
13509 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13510 popq %rbx;
13511 popq %rbp;
13512
13513 + pax_force_retaddr
13514 ret;
13515 ENDPROC(blowfish_dec_blk_4way)
13516 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13517 index ce71f92..1dce7ec 100644
13518 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13519 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520 @@ -16,6 +16,7 @@
13521 */
13522
13523 #include <linux/linkage.h>
13524 +#include <asm/alternative-asm.h>
13525
13526 #define CAMELLIA_TABLE_BYTE_LEN 272
13527
13528 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13529 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13530 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13531 %rcx, (%r9));
13532 + pax_force_retaddr
13533 ret;
13534 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13535
13536 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13537 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13538 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13539 %rax, (%r9));
13540 + pax_force_retaddr
13541 ret;
13542 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13543
13544 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13545 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13546 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13547
13548 + pax_force_retaddr
13549 ret;
13550
13551 .align 8
13552 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13553 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13554 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13555
13556 + pax_force_retaddr
13557 ret;
13558
13559 .align 8
13560 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13561 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13562 %xmm8, %rsi);
13563
13564 + pax_force_retaddr
13565 ret;
13566 ENDPROC(camellia_ecb_enc_16way)
13567
13568 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13569 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13570 %xmm8, %rsi);
13571
13572 + pax_force_retaddr
13573 ret;
13574 ENDPROC(camellia_ecb_dec_16way)
13575
13576 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13577 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13578 %xmm8, %rsi);
13579
13580 + pax_force_retaddr
13581 ret;
13582 ENDPROC(camellia_cbc_dec_16way)
13583
13584 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13585 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13586 %xmm8, %rsi);
13587
13588 + pax_force_retaddr
13589 ret;
13590 ENDPROC(camellia_ctr_16way)
13591
13592 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13593 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13594 %xmm8, %rsi);
13595
13596 + pax_force_retaddr
13597 ret;
13598 ENDPROC(camellia_xts_crypt_16way)
13599
13600 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13601 index 0e0b886..5a3123c 100644
13602 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13603 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604 @@ -11,6 +11,7 @@
13605 */
13606
13607 #include <linux/linkage.h>
13608 +#include <asm/alternative-asm.h>
13609
13610 #define CAMELLIA_TABLE_BYTE_LEN 272
13611
13612 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13613 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13614 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13615 %rcx, (%r9));
13616 + pax_force_retaddr
13617 ret;
13618 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13619
13620 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13621 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13622 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13623 %rax, (%r9));
13624 + pax_force_retaddr
13625 ret;
13626 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13627
13628 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13629 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13630 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13631
13632 + pax_force_retaddr
13633 ret;
13634
13635 .align 8
13636 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13637 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13638 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13639
13640 + pax_force_retaddr
13641 ret;
13642
13643 .align 8
13644 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13645
13646 vzeroupper;
13647
13648 + pax_force_retaddr
13649 ret;
13650 ENDPROC(camellia_ecb_enc_32way)
13651
13652 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13653
13654 vzeroupper;
13655
13656 + pax_force_retaddr
13657 ret;
13658 ENDPROC(camellia_ecb_dec_32way)
13659
13660 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13661
13662 vzeroupper;
13663
13664 + pax_force_retaddr
13665 ret;
13666 ENDPROC(camellia_cbc_dec_32way)
13667
13668 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13669
13670 vzeroupper;
13671
13672 + pax_force_retaddr
13673 ret;
13674 ENDPROC(camellia_ctr_32way)
13675
13676 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13677
13678 vzeroupper;
13679
13680 + pax_force_retaddr
13681 ret;
13682 ENDPROC(camellia_xts_crypt_32way)
13683
13684 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13685 index 310319c..db3d7b5 100644
13686 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13687 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688 @@ -21,6 +21,7 @@
13689 */
13690
13691 #include <linux/linkage.h>
13692 +#include <asm/alternative-asm.h>
13693
13694 .file "camellia-x86_64-asm_64.S"
13695 .text
13696 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13697 enc_outunpack(mov, RT1);
13698
13699 movq RRBP, %rbp;
13700 + pax_force_retaddr
13701 ret;
13702
13703 .L__enc_xor:
13704 enc_outunpack(xor, RT1);
13705
13706 movq RRBP, %rbp;
13707 + pax_force_retaddr
13708 ret;
13709 ENDPROC(__camellia_enc_blk)
13710
13711 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13712 dec_outunpack();
13713
13714 movq RRBP, %rbp;
13715 + pax_force_retaddr
13716 ret;
13717 ENDPROC(camellia_dec_blk)
13718
13719 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13720
13721 movq RRBP, %rbp;
13722 popq %rbx;
13723 + pax_force_retaddr
13724 ret;
13725
13726 .L__enc2_xor:
13727 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13728
13729 movq RRBP, %rbp;
13730 popq %rbx;
13731 + pax_force_retaddr
13732 ret;
13733 ENDPROC(__camellia_enc_blk_2way)
13734
13735 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13736
13737 movq RRBP, %rbp;
13738 movq RXOR, %rbx;
13739 + pax_force_retaddr
13740 ret;
13741 ENDPROC(camellia_dec_blk_2way)
13742 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13743 index c35fd5d..2d8c7db 100644
13744 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13745 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746 @@ -24,6 +24,7 @@
13747 */
13748
13749 #include <linux/linkage.h>
13750 +#include <asm/alternative-asm.h>
13751
13752 .file "cast5-avx-x86_64-asm_64.S"
13753
13754 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13755 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13756 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13757
13758 + pax_force_retaddr
13759 ret;
13760 ENDPROC(__cast5_enc_blk16)
13761
13762 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13763 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13764 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13765
13766 + pax_force_retaddr
13767 ret;
13768
13769 .L__skip_dec:
13770 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13771 vmovdqu RR4, (6*4*4)(%r11);
13772 vmovdqu RL4, (7*4*4)(%r11);
13773
13774 + pax_force_retaddr
13775 ret;
13776 ENDPROC(cast5_ecb_enc_16way)
13777
13778 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13779 vmovdqu RR4, (6*4*4)(%r11);
13780 vmovdqu RL4, (7*4*4)(%r11);
13781
13782 + pax_force_retaddr
13783 ret;
13784 ENDPROC(cast5_ecb_dec_16way)
13785
13786 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13787 * %rdx: src
13788 */
13789
13790 - pushq %r12;
13791 + pushq %r14;
13792
13793 movq %rsi, %r11;
13794 - movq %rdx, %r12;
13795 + movq %rdx, %r14;
13796
13797 vmovdqu (0*16)(%rdx), RL1;
13798 vmovdqu (1*16)(%rdx), RR1;
13799 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13800 call __cast5_dec_blk16;
13801
13802 /* xor with src */
13803 - vmovq (%r12), RX;
13804 + vmovq (%r14), RX;
13805 vpshufd $0x4f, RX, RX;
13806 vpxor RX, RR1, RR1;
13807 - vpxor 0*16+8(%r12), RL1, RL1;
13808 - vpxor 1*16+8(%r12), RR2, RR2;
13809 - vpxor 2*16+8(%r12), RL2, RL2;
13810 - vpxor 3*16+8(%r12), RR3, RR3;
13811 - vpxor 4*16+8(%r12), RL3, RL3;
13812 - vpxor 5*16+8(%r12), RR4, RR4;
13813 - vpxor 6*16+8(%r12), RL4, RL4;
13814 + vpxor 0*16+8(%r14), RL1, RL1;
13815 + vpxor 1*16+8(%r14), RR2, RR2;
13816 + vpxor 2*16+8(%r14), RL2, RL2;
13817 + vpxor 3*16+8(%r14), RR3, RR3;
13818 + vpxor 4*16+8(%r14), RL3, RL3;
13819 + vpxor 5*16+8(%r14), RR4, RR4;
13820 + vpxor 6*16+8(%r14), RL4, RL4;
13821
13822 vmovdqu RR1, (0*16)(%r11);
13823 vmovdqu RL1, (1*16)(%r11);
13824 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13825 vmovdqu RR4, (6*16)(%r11);
13826 vmovdqu RL4, (7*16)(%r11);
13827
13828 - popq %r12;
13829 + popq %r14;
13830
13831 + pax_force_retaddr
13832 ret;
13833 ENDPROC(cast5_cbc_dec_16way)
13834
13835 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13836 * %rcx: iv (big endian, 64bit)
13837 */
13838
13839 - pushq %r12;
13840 + pushq %r14;
13841
13842 movq %rsi, %r11;
13843 - movq %rdx, %r12;
13844 + movq %rdx, %r14;
13845
13846 vpcmpeqd RTMP, RTMP, RTMP;
13847 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13848 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13849 call __cast5_enc_blk16;
13850
13851 /* dst = src ^ iv */
13852 - vpxor (0*16)(%r12), RR1, RR1;
13853 - vpxor (1*16)(%r12), RL1, RL1;
13854 - vpxor (2*16)(%r12), RR2, RR2;
13855 - vpxor (3*16)(%r12), RL2, RL2;
13856 - vpxor (4*16)(%r12), RR3, RR3;
13857 - vpxor (5*16)(%r12), RL3, RL3;
13858 - vpxor (6*16)(%r12), RR4, RR4;
13859 - vpxor (7*16)(%r12), RL4, RL4;
13860 + vpxor (0*16)(%r14), RR1, RR1;
13861 + vpxor (1*16)(%r14), RL1, RL1;
13862 + vpxor (2*16)(%r14), RR2, RR2;
13863 + vpxor (3*16)(%r14), RL2, RL2;
13864 + vpxor (4*16)(%r14), RR3, RR3;
13865 + vpxor (5*16)(%r14), RL3, RL3;
13866 + vpxor (6*16)(%r14), RR4, RR4;
13867 + vpxor (7*16)(%r14), RL4, RL4;
13868 vmovdqu RR1, (0*16)(%r11);
13869 vmovdqu RL1, (1*16)(%r11);
13870 vmovdqu RR2, (2*16)(%r11);
13871 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13872 vmovdqu RR4, (6*16)(%r11);
13873 vmovdqu RL4, (7*16)(%r11);
13874
13875 - popq %r12;
13876 + popq %r14;
13877
13878 + pax_force_retaddr
13879 ret;
13880 ENDPROC(cast5_ctr_16way)
13881 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13882 index e3531f8..e123f35 100644
13883 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13884 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885 @@ -24,6 +24,7 @@
13886 */
13887
13888 #include <linux/linkage.h>
13889 +#include <asm/alternative-asm.h>
13890 #include "glue_helper-asm-avx.S"
13891
13892 .file "cast6-avx-x86_64-asm_64.S"
13893 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13894 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13895 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13896
13897 + pax_force_retaddr
13898 ret;
13899 ENDPROC(__cast6_enc_blk8)
13900
13901 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13902 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13903 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13904
13905 + pax_force_retaddr
13906 ret;
13907 ENDPROC(__cast6_dec_blk8)
13908
13909 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13910
13911 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13912
13913 + pax_force_retaddr
13914 ret;
13915 ENDPROC(cast6_ecb_enc_8way)
13916
13917 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13918
13919 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13920
13921 + pax_force_retaddr
13922 ret;
13923 ENDPROC(cast6_ecb_dec_8way)
13924
13925 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13926 * %rdx: src
13927 */
13928
13929 - pushq %r12;
13930 + pushq %r14;
13931
13932 movq %rsi, %r11;
13933 - movq %rdx, %r12;
13934 + movq %rdx, %r14;
13935
13936 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13937
13938 call __cast6_dec_blk8;
13939
13940 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13941 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942
13943 - popq %r12;
13944 + popq %r14;
13945
13946 + pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_cbc_dec_8way)
13949
13950 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13951 * %rcx: iv (little endian, 128bit)
13952 */
13953
13954 - pushq %r12;
13955 + pushq %r14;
13956
13957 movq %rsi, %r11;
13958 - movq %rdx, %r12;
13959 + movq %rdx, %r14;
13960
13961 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13962 RD2, RX, RKR, RKM);
13963
13964 call __cast6_enc_blk8;
13965
13966 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13967 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968
13969 - popq %r12;
13970 + popq %r14;
13971
13972 + pax_force_retaddr
13973 ret;
13974 ENDPROC(cast6_ctr_8way)
13975
13976 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13977 /* dst <= regs xor IVs(in dst) */
13978 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13979
13980 + pax_force_retaddr
13981 ret;
13982 ENDPROC(cast6_xts_enc_8way)
13983
13984 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13985 /* dst <= regs xor IVs(in dst) */
13986 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13987
13988 + pax_force_retaddr
13989 ret;
13990 ENDPROC(cast6_xts_dec_8way)
13991 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13992 index 26d49eb..c0a8c84 100644
13993 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13994 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995 @@ -45,6 +45,7 @@
13996
13997 #include <asm/inst.h>
13998 #include <linux/linkage.h>
13999 +#include <asm/alternative-asm.h>
14000
14001 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14002
14003 @@ -309,6 +310,7 @@ do_return:
14004 popq %rsi
14005 popq %rdi
14006 popq %rbx
14007 + pax_force_retaddr
14008 ret
14009
14010 ################################################################
14011 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14012 index 5d1e007..098cb4f 100644
14013 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14014 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015 @@ -18,6 +18,7 @@
14016
14017 #include <linux/linkage.h>
14018 #include <asm/inst.h>
14019 +#include <asm/alternative-asm.h>
14020
14021 .data
14022
14023 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14024 psrlq $1, T2
14025 pxor T2, T1
14026 pxor T1, DATA
14027 + pax_force_retaddr
14028 ret
14029 ENDPROC(__clmul_gf128mul_ble)
14030
14031 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14032 call __clmul_gf128mul_ble
14033 PSHUFB_XMM BSWAP DATA
14034 movups DATA, (%rdi)
14035 + pax_force_retaddr
14036 ret
14037 ENDPROC(clmul_ghash_mul)
14038
14039 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14040 PSHUFB_XMM BSWAP DATA
14041 movups DATA, (%rdi)
14042 .Lupdate_just_ret:
14043 + pax_force_retaddr
14044 ret
14045 ENDPROC(clmul_ghash_update)
14046 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14047 index 9279e0b..c4b3d2c 100644
14048 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14049 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050 @@ -1,4 +1,5 @@
14051 #include <linux/linkage.h>
14052 +#include <asm/alternative-asm.h>
14053
14054 # enter salsa20_encrypt_bytes
14055 ENTRY(salsa20_encrypt_bytes)
14056 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14057 add %r11,%rsp
14058 mov %rdi,%rax
14059 mov %rsi,%rdx
14060 + pax_force_retaddr
14061 ret
14062 # bytesatleast65:
14063 ._bytesatleast65:
14064 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14065 add %r11,%rsp
14066 mov %rdi,%rax
14067 mov %rsi,%rdx
14068 + pax_force_retaddr
14069 ret
14070 ENDPROC(salsa20_keysetup)
14071
14072 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14073 add %r11,%rsp
14074 mov %rdi,%rax
14075 mov %rsi,%rdx
14076 + pax_force_retaddr
14077 ret
14078 ENDPROC(salsa20_ivsetup)
14079 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14080 index 2f202f4..d9164d6 100644
14081 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14082 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083 @@ -24,6 +24,7 @@
14084 */
14085
14086 #include <linux/linkage.h>
14087 +#include <asm/alternative-asm.h>
14088 #include "glue_helper-asm-avx.S"
14089
14090 .file "serpent-avx-x86_64-asm_64.S"
14091 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14092 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14093 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14094
14095 + pax_force_retaddr
14096 ret;
14097 ENDPROC(__serpent_enc_blk8_avx)
14098
14099 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14100 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14101 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14102
14103 + pax_force_retaddr
14104 ret;
14105 ENDPROC(__serpent_dec_blk8_avx)
14106
14107 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14108
14109 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14110
14111 + pax_force_retaddr
14112 ret;
14113 ENDPROC(serpent_ecb_enc_8way_avx)
14114
14115 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14116
14117 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14118
14119 + pax_force_retaddr
14120 ret;
14121 ENDPROC(serpent_ecb_dec_8way_avx)
14122
14123 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14124
14125 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14126
14127 + pax_force_retaddr
14128 ret;
14129 ENDPROC(serpent_cbc_dec_8way_avx)
14130
14131 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14132
14133 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14134
14135 + pax_force_retaddr
14136 ret;
14137 ENDPROC(serpent_ctr_8way_avx)
14138
14139 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14140 /* dst <= regs xor IVs(in dst) */
14141 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142
14143 + pax_force_retaddr
14144 ret;
14145 ENDPROC(serpent_xts_enc_8way_avx)
14146
14147 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14150
14151 + pax_force_retaddr
14152 ret;
14153 ENDPROC(serpent_xts_dec_8way_avx)
14154 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14155 index b222085..abd483c 100644
14156 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14157 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14158 @@ -15,6 +15,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162 +#include <asm/alternative-asm.h>
14163 #include "glue_helper-asm-avx2.S"
14164
14165 .file "serpent-avx2-asm_64.S"
14166 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14167 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14168 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14169
14170 + pax_force_retaddr
14171 ret;
14172 ENDPROC(__serpent_enc_blk16)
14173
14174 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14175 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14176 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14177
14178 + pax_force_retaddr
14179 ret;
14180 ENDPROC(__serpent_dec_blk16)
14181
14182 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14183
14184 vzeroupper;
14185
14186 + pax_force_retaddr
14187 ret;
14188 ENDPROC(serpent_ecb_enc_16way)
14189
14190 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14191
14192 vzeroupper;
14193
14194 + pax_force_retaddr
14195 ret;
14196 ENDPROC(serpent_ecb_dec_16way)
14197
14198 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14199
14200 vzeroupper;
14201
14202 + pax_force_retaddr
14203 ret;
14204 ENDPROC(serpent_cbc_dec_16way)
14205
14206 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14207
14208 vzeroupper;
14209
14210 + pax_force_retaddr
14211 ret;
14212 ENDPROC(serpent_ctr_16way)
14213
14214 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14215
14216 vzeroupper;
14217
14218 + pax_force_retaddr
14219 ret;
14220 ENDPROC(serpent_xts_enc_16way)
14221
14222 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14223
14224 vzeroupper;
14225
14226 + pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_xts_dec_16way)
14229 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14230 index acc066c..1559cc4 100644
14231 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14232 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233 @@ -25,6 +25,7 @@
14234 */
14235
14236 #include <linux/linkage.h>
14237 +#include <asm/alternative-asm.h>
14238
14239 .file "serpent-sse2-x86_64-asm_64.S"
14240 .text
14241 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14242 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14243 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14244
14245 + pax_force_retaddr
14246 ret;
14247
14248 .L__enc_xor8:
14249 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14250 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14251
14252 + pax_force_retaddr
14253 ret;
14254 ENDPROC(__serpent_enc_blk_8way)
14255
14256 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14257 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14258 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14259
14260 + pax_force_retaddr
14261 ret;
14262 ENDPROC(serpent_dec_blk_8way)
14263 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14264 index a410950..9dfe7ad 100644
14265 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14266 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14267 @@ -29,6 +29,7 @@
14268 */
14269
14270 #include <linux/linkage.h>
14271 +#include <asm/alternative-asm.h>
14272
14273 #define CTX %rdi // arg1
14274 #define BUF %rsi // arg2
14275 @@ -75,9 +76,9 @@
14276
14277 push %rbx
14278 push %rbp
14279 - push %r12
14280 + push %r14
14281
14282 - mov %rsp, %r12
14283 + mov %rsp, %r14
14284 sub $64, %rsp # allocate workspace
14285 and $~15, %rsp # align stack
14286
14287 @@ -99,11 +100,12 @@
14288 xor %rax, %rax
14289 rep stosq
14290
14291 - mov %r12, %rsp # deallocate workspace
14292 + mov %r14, %rsp # deallocate workspace
14293
14294 - pop %r12
14295 + pop %r14
14296 pop %rbp
14297 pop %rbx
14298 + pax_force_retaddr
14299 ret
14300
14301 ENDPROC(\name)
14302 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14303 index 642f156..51a513c 100644
14304 --- a/arch/x86/crypto/sha256-avx-asm.S
14305 +++ b/arch/x86/crypto/sha256-avx-asm.S
14306 @@ -49,6 +49,7 @@
14307
14308 #ifdef CONFIG_AS_AVX
14309 #include <linux/linkage.h>
14310 +#include <asm/alternative-asm.h>
14311
14312 ## assume buffers not aligned
14313 #define VMOVDQ vmovdqu
14314 @@ -460,6 +461,7 @@ done_hash:
14315 popq %r13
14316 popq %rbp
14317 popq %rbx
14318 + pax_force_retaddr
14319 ret
14320 ENDPROC(sha256_transform_avx)
14321
14322 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14323 index 9e86944..3795e6a 100644
14324 --- a/arch/x86/crypto/sha256-avx2-asm.S
14325 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14326 @@ -50,6 +50,7 @@
14327
14328 #ifdef CONFIG_AS_AVX2
14329 #include <linux/linkage.h>
14330 +#include <asm/alternative-asm.h>
14331
14332 ## assume buffers not aligned
14333 #define VMOVDQ vmovdqu
14334 @@ -720,6 +721,7 @@ done_hash:
14335 popq %r12
14336 popq %rbp
14337 popq %rbx
14338 + pax_force_retaddr
14339 ret
14340 ENDPROC(sha256_transform_rorx)
14341
14342 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14343 index f833b74..8c62a9e 100644
14344 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14345 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14346 @@ -47,6 +47,7 @@
14347 ########################################################################
14348
14349 #include <linux/linkage.h>
14350 +#include <asm/alternative-asm.h>
14351
14352 ## assume buffers not aligned
14353 #define MOVDQ movdqu
14354 @@ -471,6 +472,7 @@ done_hash:
14355 popq %rbp
14356 popq %rbx
14357
14358 + pax_force_retaddr
14359 ret
14360 ENDPROC(sha256_transform_ssse3)
14361
14362 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14363 index 974dde9..a823ff9 100644
14364 --- a/arch/x86/crypto/sha512-avx-asm.S
14365 +++ b/arch/x86/crypto/sha512-avx-asm.S
14366 @@ -49,6 +49,7 @@
14367
14368 #ifdef CONFIG_AS_AVX
14369 #include <linux/linkage.h>
14370 +#include <asm/alternative-asm.h>
14371
14372 .text
14373
14374 @@ -364,6 +365,7 @@ updateblock:
14375 mov frame_RSPSAVE(%rsp), %rsp
14376
14377 nowork:
14378 + pax_force_retaddr
14379 ret
14380 ENDPROC(sha512_transform_avx)
14381
14382 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14383 index 568b961..ed20c37 100644
14384 --- a/arch/x86/crypto/sha512-avx2-asm.S
14385 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14386 @@ -51,6 +51,7 @@
14387
14388 #ifdef CONFIG_AS_AVX2
14389 #include <linux/linkage.h>
14390 +#include <asm/alternative-asm.h>
14391
14392 .text
14393
14394 @@ -678,6 +679,7 @@ done_hash:
14395
14396 # Restore Stack Pointer
14397 mov frame_RSPSAVE(%rsp), %rsp
14398 + pax_force_retaddr
14399 ret
14400 ENDPROC(sha512_transform_rorx)
14401
14402 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14403 index fb56855..6edd768 100644
14404 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14405 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14406 @@ -48,6 +48,7 @@
14407 ########################################################################
14408
14409 #include <linux/linkage.h>
14410 +#include <asm/alternative-asm.h>
14411
14412 .text
14413
14414 @@ -363,6 +364,7 @@ updateblock:
14415 mov frame_RSPSAVE(%rsp), %rsp
14416
14417 nowork:
14418 + pax_force_retaddr
14419 ret
14420 ENDPROC(sha512_transform_ssse3)
14421
14422 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14423 index 0505813..b067311 100644
14424 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14425 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426 @@ -24,6 +24,7 @@
14427 */
14428
14429 #include <linux/linkage.h>
14430 +#include <asm/alternative-asm.h>
14431 #include "glue_helper-asm-avx.S"
14432
14433 .file "twofish-avx-x86_64-asm_64.S"
14434 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14435 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14436 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14437
14438 + pax_force_retaddr
14439 ret;
14440 ENDPROC(__twofish_enc_blk8)
14441
14442 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14443 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14444 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14445
14446 + pax_force_retaddr
14447 ret;
14448 ENDPROC(__twofish_dec_blk8)
14449
14450 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14451
14452 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14453
14454 + pax_force_retaddr
14455 ret;
14456 ENDPROC(twofish_ecb_enc_8way)
14457
14458 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14459
14460 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14461
14462 + pax_force_retaddr
14463 ret;
14464 ENDPROC(twofish_ecb_dec_8way)
14465
14466 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14467 * %rdx: src
14468 */
14469
14470 - pushq %r12;
14471 + pushq %r14;
14472
14473 movq %rsi, %r11;
14474 - movq %rdx, %r12;
14475 + movq %rdx, %r14;
14476
14477 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14478
14479 call __twofish_dec_blk8;
14480
14481 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14482 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483
14484 - popq %r12;
14485 + popq %r14;
14486
14487 + pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_cbc_dec_8way)
14490
14491 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14492 * %rcx: iv (little endian, 128bit)
14493 */
14494
14495 - pushq %r12;
14496 + pushq %r14;
14497
14498 movq %rsi, %r11;
14499 - movq %rdx, %r12;
14500 + movq %rdx, %r14;
14501
14502 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14503 RD2, RX0, RX1, RY0);
14504
14505 call __twofish_enc_blk8;
14506
14507 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14508 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14509
14510 - popq %r12;
14511 + popq %r14;
14512
14513 + pax_force_retaddr
14514 ret;
14515 ENDPROC(twofish_ctr_8way)
14516
14517 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14518 /* dst <= regs xor IVs(in dst) */
14519 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14520
14521 + pax_force_retaddr
14522 ret;
14523 ENDPROC(twofish_xts_enc_8way)
14524
14525 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14526 /* dst <= regs xor IVs(in dst) */
14527 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14528
14529 + pax_force_retaddr
14530 ret;
14531 ENDPROC(twofish_xts_dec_8way)
14532 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14533 index 1c3b7ce..02f578d 100644
14534 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14535 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536 @@ -21,6 +21,7 @@
14537 */
14538
14539 #include <linux/linkage.h>
14540 +#include <asm/alternative-asm.h>
14541
14542 .file "twofish-x86_64-asm-3way.S"
14543 .text
14544 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14545 popq %r13;
14546 popq %r14;
14547 popq %r15;
14548 + pax_force_retaddr
14549 ret;
14550
14551 .L__enc_xor3:
14552 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14553 popq %r13;
14554 popq %r14;
14555 popq %r15;
14556 + pax_force_retaddr
14557 ret;
14558 ENDPROC(__twofish_enc_blk_3way)
14559
14560 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14561 popq %r13;
14562 popq %r14;
14563 popq %r15;
14564 + pax_force_retaddr
14565 ret;
14566 ENDPROC(twofish_dec_blk_3way)
14567 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14568 index a039d21..524b8b2 100644
14569 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14570 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571 @@ -22,6 +22,7 @@
14572
14573 #include <linux/linkage.h>
14574 #include <asm/asm-offsets.h>
14575 +#include <asm/alternative-asm.h>
14576
14577 #define a_offset 0
14578 #define b_offset 4
14579 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14580
14581 popq R1
14582 movq $1,%rax
14583 + pax_force_retaddr
14584 ret
14585 ENDPROC(twofish_enc_blk)
14586
14587 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14588
14589 popq R1
14590 movq $1,%rax
14591 + pax_force_retaddr
14592 ret
14593 ENDPROC(twofish_dec_blk)
14594 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14595 index df91466..74b31cb 100644
14596 --- a/arch/x86/ia32/ia32_aout.c
14597 +++ b/arch/x86/ia32/ia32_aout.c
14598 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14599 unsigned long dump_start, dump_size;
14600 struct user32 dump;
14601
14602 + memset(&dump, 0, sizeof(dump));
14603 +
14604 fs = get_fs();
14605 set_fs(KERNEL_DS);
14606 has_dumped = 1;
14607 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14608 index f9e181a..300544c 100644
14609 --- a/arch/x86/ia32/ia32_signal.c
14610 +++ b/arch/x86/ia32/ia32_signal.c
14611 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14612 if (__get_user(set.sig[0], &frame->sc.oldmask)
14613 || (_COMPAT_NSIG_WORDS > 1
14614 && __copy_from_user((((char *) &set.sig) + 4),
14615 - &frame->extramask,
14616 + frame->extramask,
14617 sizeof(frame->extramask))))
14618 goto badframe;
14619
14620 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14621 sp -= frame_size;
14622 /* Align the stack pointer according to the i386 ABI,
14623 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14624 - sp = ((sp + 4) & -16ul) - 4;
14625 + sp = ((sp - 12) & -16ul) - 4;
14626 return (void __user *) sp;
14627 }
14628
14629 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14630 } else {
14631 /* Return stub is in 32bit vsyscall page */
14632 if (current->mm->context.vdso)
14633 - restorer = current->mm->context.vdso +
14634 - selected_vdso32->sym___kernel_sigreturn;
14635 + restorer = (void __force_user *)(current->mm->context.vdso +
14636 + selected_vdso32->sym___kernel_sigreturn);
14637 else
14638 - restorer = &frame->retcode;
14639 + restorer = frame->retcode;
14640 }
14641
14642 put_user_try {
14643 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14644 * These are actually not used anymore, but left because some
14645 * gdb versions depend on them as a marker.
14646 */
14647 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14648 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14649 } put_user_catch(err);
14650
14651 if (err)
14652 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14653 0xb8,
14654 __NR_ia32_rt_sigreturn,
14655 0x80cd,
14656 - 0,
14657 + 0
14658 };
14659
14660 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14661 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14662
14663 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14664 restorer = ksig->ka.sa.sa_restorer;
14665 + else if (current->mm->context.vdso)
14666 + /* Return stub is in 32bit vsyscall page */
14667 + restorer = (void __force_user *)(current->mm->context.vdso +
14668 + selected_vdso32->sym___kernel_rt_sigreturn);
14669 else
14670 - restorer = current->mm->context.vdso +
14671 - selected_vdso32->sym___kernel_rt_sigreturn;
14672 + restorer = frame->retcode;
14673 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14674
14675 /*
14676 * Not actually used anymore, but left because some gdb
14677 * versions need it.
14678 */
14679 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14680 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14681 } put_user_catch(err);
14682
14683 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14684 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14685 index ffe7122..899bad3 100644
14686 --- a/arch/x86/ia32/ia32entry.S
14687 +++ b/arch/x86/ia32/ia32entry.S
14688 @@ -15,8 +15,10 @@
14689 #include <asm/irqflags.h>
14690 #include <asm/asm.h>
14691 #include <asm/smap.h>
14692 +#include <asm/pgtable.h>
14693 #include <linux/linkage.h>
14694 #include <linux/err.h>
14695 +#include <asm/alternative-asm.h>
14696
14697 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14698 #include <linux/elf-em.h>
14699 @@ -62,12 +64,12 @@
14700 */
14701 .macro LOAD_ARGS32 offset, _r9=0
14702 .if \_r9
14703 - movl \offset+16(%rsp),%r9d
14704 + movl \offset+R9(%rsp),%r9d
14705 .endif
14706 - movl \offset+40(%rsp),%ecx
14707 - movl \offset+48(%rsp),%edx
14708 - movl \offset+56(%rsp),%esi
14709 - movl \offset+64(%rsp),%edi
14710 + movl \offset+RCX(%rsp),%ecx
14711 + movl \offset+RDX(%rsp),%edx
14712 + movl \offset+RSI(%rsp),%esi
14713 + movl \offset+RDI(%rsp),%edi
14714 movl %eax,%eax /* zero extension */
14715 .endm
14716
14717 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14718 ENDPROC(native_irq_enable_sysexit)
14719 #endif
14720
14721 + .macro pax_enter_kernel_user
14722 + pax_set_fptr_mask
14723 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14724 + call pax_enter_kernel_user
14725 +#endif
14726 + .endm
14727 +
14728 + .macro pax_exit_kernel_user
14729 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14730 + call pax_exit_kernel_user
14731 +#endif
14732 +#ifdef CONFIG_PAX_RANDKSTACK
14733 + pushq %rax
14734 + pushq %r11
14735 + call pax_randomize_kstack
14736 + popq %r11
14737 + popq %rax
14738 +#endif
14739 + .endm
14740 +
14741 + .macro pax_erase_kstack
14742 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14743 + call pax_erase_kstack
14744 +#endif
14745 + .endm
14746 +
14747 /*
14748 * 32bit SYSENTER instruction entry.
14749 *
14750 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14751 CFI_REGISTER rsp,rbp
14752 SWAPGS_UNSAFE_STACK
14753 movq PER_CPU_VAR(kernel_stack), %rsp
14754 - addq $(KERNEL_STACK_OFFSET),%rsp
14755 - /*
14756 - * No need to follow this irqs on/off section: the syscall
14757 - * disabled irqs, here we enable it straight after entry:
14758 - */
14759 - ENABLE_INTERRUPTS(CLBR_NONE)
14760 movl %ebp,%ebp /* zero extension */
14761 pushq_cfi $__USER32_DS
14762 /*CFI_REL_OFFSET ss,0*/
14763 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14764 CFI_REL_OFFSET rsp,0
14765 pushfq_cfi
14766 /*CFI_REL_OFFSET rflags,0*/
14767 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14768 - CFI_REGISTER rip,r10
14769 + orl $X86_EFLAGS_IF,(%rsp)
14770 + GET_THREAD_INFO(%r11)
14771 + movl TI_sysenter_return(%r11), %r11d
14772 + CFI_REGISTER rip,r11
14773 pushq_cfi $__USER32_CS
14774 /*CFI_REL_OFFSET cs,0*/
14775 movl %eax, %eax
14776 - pushq_cfi %r10
14777 + pushq_cfi %r11
14778 CFI_REL_OFFSET rip,0
14779 pushq_cfi %rax
14780 cld
14781 SAVE_ARGS 0,1,0
14782 + pax_enter_kernel_user
14783 +
14784 +#ifdef CONFIG_PAX_RANDKSTACK
14785 + pax_erase_kstack
14786 +#endif
14787 +
14788 + /*
14789 + * No need to follow this irqs on/off section: the syscall
14790 + * disabled irqs, here we enable it straight after entry:
14791 + */
14792 + ENABLE_INTERRUPTS(CLBR_NONE)
14793 /* no need to do an access_ok check here because rbp has been
14794 32bit zero extended */
14795 +
14796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14797 + addq pax_user_shadow_base,%rbp
14798 + ASM_PAX_OPEN_USERLAND
14799 +#endif
14800 +
14801 ASM_STAC
14802 1: movl (%rbp),%ebp
14803 _ASM_EXTABLE(1b,ia32_badarg)
14804 ASM_CLAC
14805
14806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14807 + ASM_PAX_CLOSE_USERLAND
14808 +#endif
14809 +
14810 /*
14811 * Sysenter doesn't filter flags, so we need to clear NT
14812 * ourselves. To save a few cycles, we can check whether
14813 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14814 jnz sysenter_fix_flags
14815 sysenter_flags_fixed:
14816
14817 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14818 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14819 + GET_THREAD_INFO(%r11)
14820 + orl $TS_COMPAT,TI_status(%r11)
14821 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14822 CFI_REMEMBER_STATE
14823 jnz sysenter_tracesys
14824 cmpq $(IA32_NR_syscalls-1),%rax
14825 @@ -172,15 +218,18 @@ sysenter_do_call:
14826 sysenter_dispatch:
14827 call *ia32_sys_call_table(,%rax,8)
14828 movq %rax,RAX-ARGOFFSET(%rsp)
14829 + GET_THREAD_INFO(%r11)
14830 DISABLE_INTERRUPTS(CLBR_NONE)
14831 TRACE_IRQS_OFF
14832 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14833 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14834 jnz sysexit_audit
14835 sysexit_from_sys_call:
14836 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14837 + pax_exit_kernel_user
14838 + pax_erase_kstack
14839 + andl $~TS_COMPAT,TI_status(%r11)
14840 /* clear IF, that popfq doesn't enable interrupts early */
14841 - andl $~0x200,EFLAGS-R11(%rsp)
14842 - movl RIP-R11(%rsp),%edx /* User %eip */
14843 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14844 + movl RIP(%rsp),%edx /* User %eip */
14845 CFI_REGISTER rip,rdx
14846 RESTORE_ARGS 0,24,0,0,0,0
14847 xorq %r8,%r8
14848 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
14849 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14850 movl %eax,%edi /* 1st arg: syscall number */
14851 call __audit_syscall_entry
14852 +
14853 + pax_erase_kstack
14854 +
14855 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14856 cmpq $(IA32_NR_syscalls-1),%rax
14857 ja ia32_badsys
14858 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
14859 .endm
14860
14861 .macro auditsys_exit exit
14862 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14863 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14864 jnz ia32_ret_from_sys_call
14865 TRACE_IRQS_ON
14866 ENABLE_INTERRUPTS(CLBR_NONE)
14867 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
14868 1: setbe %al /* 1 if error, 0 if not */
14869 movzbl %al,%edi /* zero-extend that into %edi */
14870 call __audit_syscall_exit
14871 + GET_THREAD_INFO(%r11)
14872 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14873 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14874 DISABLE_INTERRUPTS(CLBR_NONE)
14875 TRACE_IRQS_OFF
14876 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14877 + testl %edi,TI_flags(%r11)
14878 jz \exit
14879 CLEAR_RREGS -ARGOFFSET
14880 jmp int_with_check
14881 @@ -253,7 +306,7 @@ sysenter_fix_flags:
14882
14883 sysenter_tracesys:
14884 #ifdef CONFIG_AUDITSYSCALL
14885 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14886 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14887 jz sysenter_auditsys
14888 #endif
14889 SAVE_REST
14890 @@ -265,6 +318,9 @@ sysenter_tracesys:
14891 RESTORE_REST
14892 cmpq $(IA32_NR_syscalls-1),%rax
14893 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14894 +
14895 + pax_erase_kstack
14896 +
14897 jmp sysenter_do_call
14898 CFI_ENDPROC
14899 ENDPROC(ia32_sysenter_target)
14900 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14901 ENTRY(ia32_cstar_target)
14902 CFI_STARTPROC32 simple
14903 CFI_SIGNAL_FRAME
14904 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14905 + CFI_DEF_CFA rsp,0
14906 CFI_REGISTER rip,rcx
14907 /*CFI_REGISTER rflags,r11*/
14908 SWAPGS_UNSAFE_STACK
14909 movl %esp,%r8d
14910 CFI_REGISTER rsp,r8
14911 movq PER_CPU_VAR(kernel_stack),%rsp
14912 + SAVE_ARGS 8*6,0,0
14913 + pax_enter_kernel_user
14914 +
14915 +#ifdef CONFIG_PAX_RANDKSTACK
14916 + pax_erase_kstack
14917 +#endif
14918 +
14919 /*
14920 * No need to follow this irqs on/off section: the syscall
14921 * disabled irqs and here we enable it straight after entry:
14922 */
14923 ENABLE_INTERRUPTS(CLBR_NONE)
14924 - SAVE_ARGS 8,0,0
14925 movl %eax,%eax /* zero extension */
14926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14927 movq %rcx,RIP-ARGOFFSET(%rsp)
14928 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14929 /* no need to do an access_ok check here because r8 has been
14930 32bit zero extended */
14931 /* hardware stack frame is complete now */
14932 +
14933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14934 + ASM_PAX_OPEN_USERLAND
14935 + movq pax_user_shadow_base,%r8
14936 + addq RSP-ARGOFFSET(%rsp),%r8
14937 +#endif
14938 +
14939 ASM_STAC
14940 1: movl (%r8),%r9d
14941 _ASM_EXTABLE(1b,ia32_badarg)
14942 ASM_CLAC
14943 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14944 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14945 +
14946 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14947 + ASM_PAX_CLOSE_USERLAND
14948 +#endif
14949 +
14950 + GET_THREAD_INFO(%r11)
14951 + orl $TS_COMPAT,TI_status(%r11)
14952 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14953 CFI_REMEMBER_STATE
14954 jnz cstar_tracesys
14955 cmpq $IA32_NR_syscalls-1,%rax
14956 @@ -335,13 +410,16 @@ cstar_do_call:
14957 cstar_dispatch:
14958 call *ia32_sys_call_table(,%rax,8)
14959 movq %rax,RAX-ARGOFFSET(%rsp)
14960 + GET_THREAD_INFO(%r11)
14961 DISABLE_INTERRUPTS(CLBR_NONE)
14962 TRACE_IRQS_OFF
14963 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14964 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14965 jnz sysretl_audit
14966 sysretl_from_sys_call:
14967 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14968 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14969 + pax_exit_kernel_user
14970 + pax_erase_kstack
14971 + andl $~TS_COMPAT,TI_status(%r11)
14972 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14973 movl RIP-ARGOFFSET(%rsp),%ecx
14974 CFI_REGISTER rip,rcx
14975 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14976 @@ -368,7 +446,7 @@ sysretl_audit:
14977
14978 cstar_tracesys:
14979 #ifdef CONFIG_AUDITSYSCALL
14980 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14981 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14982 jz cstar_auditsys
14983 #endif
14984 xchgl %r9d,%ebp
14985 @@ -382,11 +460,19 @@ cstar_tracesys:
14986 xchgl %ebp,%r9d
14987 cmpq $(IA32_NR_syscalls-1),%rax
14988 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14989 +
14990 + pax_erase_kstack
14991 +
14992 jmp cstar_do_call
14993 END(ia32_cstar_target)
14994
14995 ia32_badarg:
14996 ASM_CLAC
14997 +
14998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14999 + ASM_PAX_CLOSE_USERLAND
15000 +#endif
15001 +
15002 movq $-EFAULT,%rax
15003 jmp ia32_sysret
15004 CFI_ENDPROC
15005 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15006 CFI_REL_OFFSET rip,RIP-RIP
15007 PARAVIRT_ADJUST_EXCEPTION_FRAME
15008 SWAPGS
15009 - /*
15010 - * No need to follow this irqs on/off section: the syscall
15011 - * disabled irqs and here we enable it straight after entry:
15012 - */
15013 - ENABLE_INTERRUPTS(CLBR_NONE)
15014 movl %eax,%eax
15015 pushq_cfi %rax
15016 cld
15017 /* note the registers are not zero extended to the sf.
15018 this could be a problem. */
15019 SAVE_ARGS 0,1,0
15020 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15021 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15022 + pax_enter_kernel_user
15023 +
15024 +#ifdef CONFIG_PAX_RANDKSTACK
15025 + pax_erase_kstack
15026 +#endif
15027 +
15028 + /*
15029 + * No need to follow this irqs on/off section: the syscall
15030 + * disabled irqs and here we enable it straight after entry:
15031 + */
15032 + ENABLE_INTERRUPTS(CLBR_NONE)
15033 + GET_THREAD_INFO(%r11)
15034 + orl $TS_COMPAT,TI_status(%r11)
15035 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15036 jnz ia32_tracesys
15037 cmpq $(IA32_NR_syscalls-1),%rax
15038 ja ia32_badsys
15039 @@ -458,6 +551,9 @@ ia32_tracesys:
15040 RESTORE_REST
15041 cmpq $(IA32_NR_syscalls-1),%rax
15042 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15043 +
15044 + pax_erase_kstack
15045 +
15046 jmp ia32_do_call
15047 END(ia32_syscall)
15048
15049 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15050 index 8e0ceec..af13504 100644
15051 --- a/arch/x86/ia32/sys_ia32.c
15052 +++ b/arch/x86/ia32/sys_ia32.c
15053 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15054 */
15055 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15056 {
15057 - typeof(ubuf->st_uid) uid = 0;
15058 - typeof(ubuf->st_gid) gid = 0;
15059 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15060 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15061 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15062 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15063 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15064 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15065 index 372231c..51b537d 100644
15066 --- a/arch/x86/include/asm/alternative-asm.h
15067 +++ b/arch/x86/include/asm/alternative-asm.h
15068 @@ -18,6 +18,45 @@
15069 .endm
15070 #endif
15071
15072 +#ifdef KERNEXEC_PLUGIN
15073 + .macro pax_force_retaddr_bts rip=0
15074 + btsq $63,\rip(%rsp)
15075 + .endm
15076 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15077 + .macro pax_force_retaddr rip=0, reload=0
15078 + btsq $63,\rip(%rsp)
15079 + .endm
15080 + .macro pax_force_fptr ptr
15081 + btsq $63,\ptr
15082 + .endm
15083 + .macro pax_set_fptr_mask
15084 + .endm
15085 +#endif
15086 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15087 + .macro pax_force_retaddr rip=0, reload=0
15088 + .if \reload
15089 + pax_set_fptr_mask
15090 + .endif
15091 + orq %r12,\rip(%rsp)
15092 + .endm
15093 + .macro pax_force_fptr ptr
15094 + orq %r12,\ptr
15095 + .endm
15096 + .macro pax_set_fptr_mask
15097 + movabs $0x8000000000000000,%r12
15098 + .endm
15099 +#endif
15100 +#else
15101 + .macro pax_force_retaddr rip=0, reload=0
15102 + .endm
15103 + .macro pax_force_fptr ptr
15104 + .endm
15105 + .macro pax_force_retaddr_bts rip=0
15106 + .endm
15107 + .macro pax_set_fptr_mask
15108 + .endm
15109 +#endif
15110 +
15111 .macro altinstruction_entry orig alt feature orig_len alt_len
15112 .long \orig - .
15113 .long \alt - .
15114 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15115 index 473bdbe..b1e3377 100644
15116 --- a/arch/x86/include/asm/alternative.h
15117 +++ b/arch/x86/include/asm/alternative.h
15118 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15119 ".pushsection .discard,\"aw\",@progbits\n" \
15120 DISCARD_ENTRY(1) \
15121 ".popsection\n" \
15122 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15123 + ".pushsection .altinstr_replacement, \"a\"\n" \
15124 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15125 ".popsection"
15126
15127 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15128 DISCARD_ENTRY(1) \
15129 DISCARD_ENTRY(2) \
15130 ".popsection\n" \
15131 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15132 + ".pushsection .altinstr_replacement, \"a\"\n" \
15133 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15134 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15135 ".popsection"
15136 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15137 index 465b309..ab7e51f 100644
15138 --- a/arch/x86/include/asm/apic.h
15139 +++ b/arch/x86/include/asm/apic.h
15140 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15141
15142 #ifdef CONFIG_X86_LOCAL_APIC
15143
15144 -extern unsigned int apic_verbosity;
15145 +extern int apic_verbosity;
15146 extern int local_apic_timer_c2_ok;
15147
15148 extern int disable_apic;
15149 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15150 index 20370c6..a2eb9b0 100644
15151 --- a/arch/x86/include/asm/apm.h
15152 +++ b/arch/x86/include/asm/apm.h
15153 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15154 __asm__ __volatile__(APM_DO_ZERO_SEGS
15155 "pushl %%edi\n\t"
15156 "pushl %%ebp\n\t"
15157 - "lcall *%%cs:apm_bios_entry\n\t"
15158 + "lcall *%%ss:apm_bios_entry\n\t"
15159 "setc %%al\n\t"
15160 "popl %%ebp\n\t"
15161 "popl %%edi\n\t"
15162 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15163 __asm__ __volatile__(APM_DO_ZERO_SEGS
15164 "pushl %%edi\n\t"
15165 "pushl %%ebp\n\t"
15166 - "lcall *%%cs:apm_bios_entry\n\t"
15167 + "lcall *%%ss:apm_bios_entry\n\t"
15168 "setc %%bl\n\t"
15169 "popl %%ebp\n\t"
15170 "popl %%edi\n\t"
15171 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15172 index 5e5cd12..3d18208 100644
15173 --- a/arch/x86/include/asm/atomic.h
15174 +++ b/arch/x86/include/asm/atomic.h
15175 @@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15176 }
15177
15178 /**
15179 + * atomic_read_unchecked - read atomic variable
15180 + * @v: pointer of type atomic_unchecked_t
15181 + *
15182 + * Atomically reads the value of @v.
15183 + */
15184 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15185 +{
15186 + return ACCESS_ONCE((v)->counter);
15187 +}
15188 +
15189 +/**
15190 * atomic_set - set atomic variable
15191 * @v: pointer of type atomic_t
15192 * @i: required value
15193 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15194 }
15195
15196 /**
15197 + * atomic_set_unchecked - set atomic variable
15198 + * @v: pointer of type atomic_unchecked_t
15199 + * @i: required value
15200 + *
15201 + * Atomically sets the value of @v to @i.
15202 + */
15203 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15204 +{
15205 + v->counter = i;
15206 +}
15207 +
15208 +/**
15209 * atomic_add - add integer to atomic variable
15210 * @i: integer value to add
15211 * @v: pointer of type atomic_t
15212 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15213 */
15214 static inline void atomic_add(int i, atomic_t *v)
15215 {
15216 - asm volatile(LOCK_PREFIX "addl %1,%0"
15217 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15218 +
15219 +#ifdef CONFIG_PAX_REFCOUNT
15220 + "jno 0f\n"
15221 + LOCK_PREFIX "subl %1,%0\n"
15222 + "int $4\n0:\n"
15223 + _ASM_EXTABLE(0b, 0b)
15224 +#endif
15225 +
15226 + : "+m" (v->counter)
15227 + : "ir" (i));
15228 +}
15229 +
15230 +/**
15231 + * atomic_add_unchecked - add integer to atomic variable
15232 + * @i: integer value to add
15233 + * @v: pointer of type atomic_unchecked_t
15234 + *
15235 + * Atomically adds @i to @v.
15236 + */
15237 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15238 +{
15239 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15240 : "+m" (v->counter)
15241 : "ir" (i));
15242 }
15243 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15244 */
15245 static inline void atomic_sub(int i, atomic_t *v)
15246 {
15247 - asm volatile(LOCK_PREFIX "subl %1,%0"
15248 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15249 +
15250 +#ifdef CONFIG_PAX_REFCOUNT
15251 + "jno 0f\n"
15252 + LOCK_PREFIX "addl %1,%0\n"
15253 + "int $4\n0:\n"
15254 + _ASM_EXTABLE(0b, 0b)
15255 +#endif
15256 +
15257 + : "+m" (v->counter)
15258 + : "ir" (i));
15259 +}
15260 +
15261 +/**
15262 + * atomic_sub_unchecked - subtract integer from atomic variable
15263 + * @i: integer value to subtract
15264 + * @v: pointer of type atomic_unchecked_t
15265 + *
15266 + * Atomically subtracts @i from @v.
15267 + */
15268 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15269 +{
15270 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15271 : "+m" (v->counter)
15272 : "ir" (i));
15273 }
15274 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15275 */
15276 static inline int atomic_sub_and_test(int i, atomic_t *v)
15277 {
15278 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15279 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15280 }
15281
15282 /**
15283 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15284 */
15285 static inline void atomic_inc(atomic_t *v)
15286 {
15287 - asm volatile(LOCK_PREFIX "incl %0"
15288 + asm volatile(LOCK_PREFIX "incl %0\n"
15289 +
15290 +#ifdef CONFIG_PAX_REFCOUNT
15291 + "jno 0f\n"
15292 + LOCK_PREFIX "decl %0\n"
15293 + "int $4\n0:\n"
15294 + _ASM_EXTABLE(0b, 0b)
15295 +#endif
15296 +
15297 + : "+m" (v->counter));
15298 +}
15299 +
15300 +/**
15301 + * atomic_inc_unchecked - increment atomic variable
15302 + * @v: pointer of type atomic_unchecked_t
15303 + *
15304 + * Atomically increments @v by 1.
15305 + */
15306 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15307 +{
15308 + asm volatile(LOCK_PREFIX "incl %0\n"
15309 : "+m" (v->counter));
15310 }
15311
15312 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15313 */
15314 static inline void atomic_dec(atomic_t *v)
15315 {
15316 - asm volatile(LOCK_PREFIX "decl %0"
15317 + asm volatile(LOCK_PREFIX "decl %0\n"
15318 +
15319 +#ifdef CONFIG_PAX_REFCOUNT
15320 + "jno 0f\n"
15321 + LOCK_PREFIX "incl %0\n"
15322 + "int $4\n0:\n"
15323 + _ASM_EXTABLE(0b, 0b)
15324 +#endif
15325 +
15326 + : "+m" (v->counter));
15327 +}
15328 +
15329 +/**
15330 + * atomic_dec_unchecked - decrement atomic variable
15331 + * @v: pointer of type atomic_unchecked_t
15332 + *
15333 + * Atomically decrements @v by 1.
15334 + */
15335 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15336 +{
15337 + asm volatile(LOCK_PREFIX "decl %0\n"
15338 : "+m" (v->counter));
15339 }
15340
15341 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15342 */
15343 static inline int atomic_dec_and_test(atomic_t *v)
15344 {
15345 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15346 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15347 }
15348
15349 /**
15350 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15351 */
15352 static inline int atomic_inc_and_test(atomic_t *v)
15353 {
15354 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15355 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15356 +}
15357 +
15358 +/**
15359 + * atomic_inc_and_test_unchecked - increment and test
15360 + * @v: pointer of type atomic_unchecked_t
15361 + *
15362 + * Atomically increments @v by 1
15363 + * and returns true if the result is zero, or false for all
15364 + * other cases.
15365 + */
15366 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15367 +{
15368 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15369 }
15370
15371 /**
15372 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15373 */
15374 static inline int atomic_add_negative(int i, atomic_t *v)
15375 {
15376 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15377 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15378 }
15379
15380 /**
15381 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15382 *
15383 * Atomically adds @i to @v and returns @i + @v
15384 */
15385 -static inline int atomic_add_return(int i, atomic_t *v)
15386 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15387 +{
15388 + return i + xadd_check_overflow(&v->counter, i);
15389 +}
15390 +
15391 +/**
15392 + * atomic_add_return_unchecked - add integer and return
15393 + * @i: integer value to add
15394 + * @v: pointer of type atomic_unchecked_t
15395 + *
15396 + * Atomically adds @i to @v and returns @i + @v
15397 + */
15398 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15399 {
15400 return i + xadd(&v->counter, i);
15401 }
15402 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15403 *
15404 * Atomically subtracts @i from @v and returns @v - @i
15405 */
15406 -static inline int atomic_sub_return(int i, atomic_t *v)
15407 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15408 {
15409 return atomic_add_return(-i, v);
15410 }
15411
15412 #define atomic_inc_return(v) (atomic_add_return(1, v))
15413 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15414 +{
15415 + return atomic_add_return_unchecked(1, v);
15416 +}
15417 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15418
15419 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15420 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15421 +{
15422 + return cmpxchg(&v->counter, old, new);
15423 +}
15424 +
15425 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15426 {
15427 return cmpxchg(&v->counter, old, new);
15428 }
15429 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15430 return xchg(&v->counter, new);
15431 }
15432
15433 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15434 +{
15435 + return xchg(&v->counter, new);
15436 +}
15437 +
15438 /**
15439 * __atomic_add_unless - add unless the number is already a given value
15440 * @v: pointer of type atomic_t
15441 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15442 * Atomically adds @a to @v, so long as @v was not already @u.
15443 * Returns the old value of @v.
15444 */
15445 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15446 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15447 {
15448 - int c, old;
15449 + int c, old, new;
15450 c = atomic_read(v);
15451 for (;;) {
15452 - if (unlikely(c == (u)))
15453 + if (unlikely(c == u))
15454 break;
15455 - old = atomic_cmpxchg((v), c, c + (a));
15456 +
15457 + asm volatile("addl %2,%0\n"
15458 +
15459 +#ifdef CONFIG_PAX_REFCOUNT
15460 + "jno 0f\n"
15461 + "subl %2,%0\n"
15462 + "int $4\n0:\n"
15463 + _ASM_EXTABLE(0b, 0b)
15464 +#endif
15465 +
15466 + : "=r" (new)
15467 + : "0" (c), "ir" (a));
15468 +
15469 + old = atomic_cmpxchg(v, c, new);
15470 if (likely(old == c))
15471 break;
15472 c = old;
15473 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15474 }
15475
15476 /**
15477 + * atomic_inc_not_zero_hint - increment if not null
15478 + * @v: pointer of type atomic_t
15479 + * @hint: probable value of the atomic before the increment
15480 + *
15481 + * This version of atomic_inc_not_zero() gives a hint of probable
15482 + * value of the atomic. This helps processor to not read the memory
15483 + * before doing the atomic read/modify/write cycle, lowering
15484 + * number of bus transactions on some arches.
15485 + *
15486 + * Returns: 0 if increment was not done, 1 otherwise.
15487 + */
15488 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15489 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15490 +{
15491 + int val, c = hint, new;
15492 +
15493 + /* sanity test, should be removed by compiler if hint is a constant */
15494 + if (!hint)
15495 + return __atomic_add_unless(v, 1, 0);
15496 +
15497 + do {
15498 + asm volatile("incl %0\n"
15499 +
15500 +#ifdef CONFIG_PAX_REFCOUNT
15501 + "jno 0f\n"
15502 + "decl %0\n"
15503 + "int $4\n0:\n"
15504 + _ASM_EXTABLE(0b, 0b)
15505 +#endif
15506 +
15507 + : "=r" (new)
15508 + : "0" (c));
15509 +
15510 + val = atomic_cmpxchg(v, c, new);
15511 + if (val == c)
15512 + return 1;
15513 + c = val;
15514 + } while (c);
15515 +
15516 + return 0;
15517 +}
15518 +
15519 +/**
15520 * atomic_inc_short - increment of a short integer
15521 * @v: pointer to type int
15522 *
15523 @@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15524 }
15525
15526 /* These are x86-specific, used by some header files */
15527 -#define atomic_clear_mask(mask, addr) \
15528 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15529 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15530 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15531 +{
15532 + asm volatile(LOCK_PREFIX "andl %1,%0"
15533 + : "+m" (v->counter)
15534 + : "r" (~(mask))
15535 + : "memory");
15536 +}
15537
15538 -#define atomic_set_mask(mask, addr) \
15539 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15540 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15541 - : "memory")
15542 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15543 +{
15544 + asm volatile(LOCK_PREFIX "andl %1,%0"
15545 + : "+m" (v->counter)
15546 + : "r" (~(mask))
15547 + : "memory");
15548 +}
15549 +
15550 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15551 +{
15552 + asm volatile(LOCK_PREFIX "orl %1,%0"
15553 + : "+m" (v->counter)
15554 + : "r" (mask)
15555 + : "memory");
15556 +}
15557 +
15558 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15559 +{
15560 + asm volatile(LOCK_PREFIX "orl %1,%0"
15561 + : "+m" (v->counter)
15562 + : "r" (mask)
15563 + : "memory");
15564 +}
15565
15566 #ifdef CONFIG_X86_32
15567 # include <asm/atomic64_32.h>
15568 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15569 index b154de7..bf18a5a 100644
15570 --- a/arch/x86/include/asm/atomic64_32.h
15571 +++ b/arch/x86/include/asm/atomic64_32.h
15572 @@ -12,6 +12,14 @@ typedef struct {
15573 u64 __aligned(8) counter;
15574 } atomic64_t;
15575
15576 +#ifdef CONFIG_PAX_REFCOUNT
15577 +typedef struct {
15578 + u64 __aligned(8) counter;
15579 +} atomic64_unchecked_t;
15580 +#else
15581 +typedef atomic64_t atomic64_unchecked_t;
15582 +#endif
15583 +
15584 #define ATOMIC64_INIT(val) { (val) }
15585
15586 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15587 @@ -37,21 +45,31 @@ typedef struct {
15588 ATOMIC64_DECL_ONE(sym##_386)
15589
15590 ATOMIC64_DECL_ONE(add_386);
15591 +ATOMIC64_DECL_ONE(add_unchecked_386);
15592 ATOMIC64_DECL_ONE(sub_386);
15593 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15594 ATOMIC64_DECL_ONE(inc_386);
15595 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15596 ATOMIC64_DECL_ONE(dec_386);
15597 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15598 #endif
15599
15600 #define alternative_atomic64(f, out, in...) \
15601 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15602
15603 ATOMIC64_DECL(read);
15604 +ATOMIC64_DECL(read_unchecked);
15605 ATOMIC64_DECL(set);
15606 +ATOMIC64_DECL(set_unchecked);
15607 ATOMIC64_DECL(xchg);
15608 ATOMIC64_DECL(add_return);
15609 +ATOMIC64_DECL(add_return_unchecked);
15610 ATOMIC64_DECL(sub_return);
15611 +ATOMIC64_DECL(sub_return_unchecked);
15612 ATOMIC64_DECL(inc_return);
15613 +ATOMIC64_DECL(inc_return_unchecked);
15614 ATOMIC64_DECL(dec_return);
15615 +ATOMIC64_DECL(dec_return_unchecked);
15616 ATOMIC64_DECL(dec_if_positive);
15617 ATOMIC64_DECL(inc_not_zero);
15618 ATOMIC64_DECL(add_unless);
15619 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15620 }
15621
15622 /**
15623 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15624 + * @p: pointer to type atomic64_unchecked_t
15625 + * @o: expected value
15626 + * @n: new value
15627 + *
15628 + * Atomically sets @v to @n if it was equal to @o and returns
15629 + * the old value.
15630 + */
15631 +
15632 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15633 +{
15634 + return cmpxchg64(&v->counter, o, n);
15635 +}
15636 +
15637 +/**
15638 * atomic64_xchg - xchg atomic64 variable
15639 * @v: pointer to type atomic64_t
15640 * @n: value to assign
15641 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15642 }
15643
15644 /**
15645 + * atomic64_set_unchecked - set atomic64 variable
15646 + * @v: pointer to type atomic64_unchecked_t
15647 + * @n: value to assign
15648 + *
15649 + * Atomically sets the value of @v to @n.
15650 + */
15651 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15652 +{
15653 + unsigned high = (unsigned)(i >> 32);
15654 + unsigned low = (unsigned)i;
15655 + alternative_atomic64(set, /* no output */,
15656 + "S" (v), "b" (low), "c" (high)
15657 + : "eax", "edx", "memory");
15658 +}
15659 +
15660 +/**
15661 * atomic64_read - read atomic64 variable
15662 * @v: pointer to type atomic64_t
15663 *
15664 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15665 }
15666
15667 /**
15668 + * atomic64_read_unchecked - read atomic64 variable
15669 + * @v: pointer to type atomic64_unchecked_t
15670 + *
15671 + * Atomically reads the value of @v and returns it.
15672 + */
15673 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15674 +{
15675 + long long r;
15676 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15677 + return r;
15678 + }
15679 +
15680 +/**
15681 * atomic64_add_return - add and return
15682 * @i: integer value to add
15683 * @v: pointer to type atomic64_t
15684 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15685 return i;
15686 }
15687
15688 +/**
15689 + * atomic64_add_return_unchecked - add and return
15690 + * @i: integer value to add
15691 + * @v: pointer to type atomic64_unchecked_t
15692 + *
15693 + * Atomically adds @i to @v and returns @i + *@v
15694 + */
15695 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15696 +{
15697 + alternative_atomic64(add_return_unchecked,
15698 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15699 + ASM_NO_INPUT_CLOBBER("memory"));
15700 + return i;
15701 +}
15702 +
15703 /*
15704 * Other variants with different arithmetic operators:
15705 */
15706 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15707 return a;
15708 }
15709
15710 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15711 +{
15712 + long long a;
15713 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15714 + "S" (v) : "memory", "ecx");
15715 + return a;
15716 +}
15717 +
15718 static inline long long atomic64_dec_return(atomic64_t *v)
15719 {
15720 long long a;
15721 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15722 }
15723
15724 /**
15725 + * atomic64_add_unchecked - add integer to atomic64 variable
15726 + * @i: integer value to add
15727 + * @v: pointer to type atomic64_unchecked_t
15728 + *
15729 + * Atomically adds @i to @v.
15730 + */
15731 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15732 +{
15733 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15734 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15735 + ASM_NO_INPUT_CLOBBER("memory"));
15736 + return i;
15737 +}
15738 +
15739 +/**
15740 * atomic64_sub - subtract the atomic64 variable
15741 * @i: integer value to subtract
15742 * @v: pointer to type atomic64_t
15743 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15744 index f8d273e..02f39f3 100644
15745 --- a/arch/x86/include/asm/atomic64_64.h
15746 +++ b/arch/x86/include/asm/atomic64_64.h
15747 @@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15748 }
15749
15750 /**
15751 + * atomic64_read_unchecked - read atomic64 variable
15752 + * @v: pointer of type atomic64_unchecked_t
15753 + *
15754 + * Atomically reads the value of @v.
15755 + * Doesn't imply a read memory barrier.
15756 + */
15757 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15758 +{
15759 + return ACCESS_ONCE((v)->counter);
15760 +}
15761 +
15762 +/**
15763 * atomic64_set - set atomic64 variable
15764 * @v: pointer to type atomic64_t
15765 * @i: required value
15766 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15767 }
15768
15769 /**
15770 + * atomic64_set_unchecked - set atomic64 variable
15771 + * @v: pointer to type atomic64_unchecked_t
15772 + * @i: required value
15773 + *
15774 + * Atomically sets the value of @v to @i.
15775 + */
15776 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15777 +{
15778 + v->counter = i;
15779 +}
15780 +
15781 +/**
15782 * atomic64_add - add integer to atomic64 variable
15783 * @i: integer value to add
15784 * @v: pointer to type atomic64_t
15785 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15786 */
15787 static inline void atomic64_add(long i, atomic64_t *v)
15788 {
15789 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15790 +
15791 +#ifdef CONFIG_PAX_REFCOUNT
15792 + "jno 0f\n"
15793 + LOCK_PREFIX "subq %1,%0\n"
15794 + "int $4\n0:\n"
15795 + _ASM_EXTABLE(0b, 0b)
15796 +#endif
15797 +
15798 + : "=m" (v->counter)
15799 + : "er" (i), "m" (v->counter));
15800 +}
15801 +
15802 +/**
15803 + * atomic64_add_unchecked - add integer to atomic64 variable
15804 + * @i: integer value to add
15805 + * @v: pointer to type atomic64_unchecked_t
15806 + *
15807 + * Atomically adds @i to @v.
15808 + */
15809 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15810 +{
15811 asm volatile(LOCK_PREFIX "addq %1,%0"
15812 : "=m" (v->counter)
15813 : "er" (i), "m" (v->counter));
15814 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15815 */
15816 static inline void atomic64_sub(long i, atomic64_t *v)
15817 {
15818 - asm volatile(LOCK_PREFIX "subq %1,%0"
15819 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15820 +
15821 +#ifdef CONFIG_PAX_REFCOUNT
15822 + "jno 0f\n"
15823 + LOCK_PREFIX "addq %1,%0\n"
15824 + "int $4\n0:\n"
15825 + _ASM_EXTABLE(0b, 0b)
15826 +#endif
15827 +
15828 + : "=m" (v->counter)
15829 + : "er" (i), "m" (v->counter));
15830 +}
15831 +
15832 +/**
15833 + * atomic64_sub_unchecked - subtract the atomic64 variable
15834 + * @i: integer value to subtract
15835 + * @v: pointer to type atomic64_unchecked_t
15836 + *
15837 + * Atomically subtracts @i from @v.
15838 + */
15839 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15840 +{
15841 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15842 : "=m" (v->counter)
15843 : "er" (i), "m" (v->counter));
15844 }
15845 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15846 */
15847 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15848 {
15849 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15850 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15851 }
15852
15853 /**
15854 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15855 */
15856 static inline void atomic64_inc(atomic64_t *v)
15857 {
15858 + asm volatile(LOCK_PREFIX "incq %0\n"
15859 +
15860 +#ifdef CONFIG_PAX_REFCOUNT
15861 + "jno 0f\n"
15862 + LOCK_PREFIX "decq %0\n"
15863 + "int $4\n0:\n"
15864 + _ASM_EXTABLE(0b, 0b)
15865 +#endif
15866 +
15867 + : "=m" (v->counter)
15868 + : "m" (v->counter));
15869 +}
15870 +
15871 +/**
15872 + * atomic64_inc_unchecked - increment atomic64 variable
15873 + * @v: pointer to type atomic64_unchecked_t
15874 + *
15875 + * Atomically increments @v by 1.
15876 + */
15877 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15878 +{
15879 asm volatile(LOCK_PREFIX "incq %0"
15880 : "=m" (v->counter)
15881 : "m" (v->counter));
15882 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15883 */
15884 static inline void atomic64_dec(atomic64_t *v)
15885 {
15886 - asm volatile(LOCK_PREFIX "decq %0"
15887 + asm volatile(LOCK_PREFIX "decq %0\n"
15888 +
15889 +#ifdef CONFIG_PAX_REFCOUNT
15890 + "jno 0f\n"
15891 + LOCK_PREFIX "incq %0\n"
15892 + "int $4\n0:\n"
15893 + _ASM_EXTABLE(0b, 0b)
15894 +#endif
15895 +
15896 + : "=m" (v->counter)
15897 + : "m" (v->counter));
15898 +}
15899 +
15900 +/**
15901 + * atomic64_dec_unchecked - decrement atomic64 variable
15902 + * @v: pointer to type atomic64_t
15903 + *
15904 + * Atomically decrements @v by 1.
15905 + */
15906 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15907 +{
15908 + asm volatile(LOCK_PREFIX "decq %0\n"
15909 : "=m" (v->counter)
15910 : "m" (v->counter));
15911 }
15912 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15913 */
15914 static inline int atomic64_dec_and_test(atomic64_t *v)
15915 {
15916 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15917 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15918 }
15919
15920 /**
15921 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15922 */
15923 static inline int atomic64_inc_and_test(atomic64_t *v)
15924 {
15925 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15926 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15927 }
15928
15929 /**
15930 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15931 */
15932 static inline int atomic64_add_negative(long i, atomic64_t *v)
15933 {
15934 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15935 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15936 }
15937
15938 /**
15939 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15940 */
15941 static inline long atomic64_add_return(long i, atomic64_t *v)
15942 {
15943 + return i + xadd_check_overflow(&v->counter, i);
15944 +}
15945 +
15946 +/**
15947 + * atomic64_add_return_unchecked - add and return
15948 + * @i: integer value to add
15949 + * @v: pointer to type atomic64_unchecked_t
15950 + *
15951 + * Atomically adds @i to @v and returns @i + @v
15952 + */
15953 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15954 +{
15955 return i + xadd(&v->counter, i);
15956 }
15957
15958 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15959 }
15960
15961 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15962 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15963 +{
15964 + return atomic64_add_return_unchecked(1, v);
15965 +}
15966 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15967
15968 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15969 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15970 return cmpxchg(&v->counter, old, new);
15971 }
15972
15973 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15974 +{
15975 + return cmpxchg(&v->counter, old, new);
15976 +}
15977 +
15978 static inline long atomic64_xchg(atomic64_t *v, long new)
15979 {
15980 return xchg(&v->counter, new);
15981 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15982 */
15983 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15984 {
15985 - long c, old;
15986 + long c, old, new;
15987 c = atomic64_read(v);
15988 for (;;) {
15989 - if (unlikely(c == (u)))
15990 + if (unlikely(c == u))
15991 break;
15992 - old = atomic64_cmpxchg((v), c, c + (a));
15993 +
15994 + asm volatile("add %2,%0\n"
15995 +
15996 +#ifdef CONFIG_PAX_REFCOUNT
15997 + "jno 0f\n"
15998 + "sub %2,%0\n"
15999 + "int $4\n0:\n"
16000 + _ASM_EXTABLE(0b, 0b)
16001 +#endif
16002 +
16003 + : "=r" (new)
16004 + : "0" (c), "ir" (a));
16005 +
16006 + old = atomic64_cmpxchg(v, c, new);
16007 if (likely(old == c))
16008 break;
16009 c = old;
16010 }
16011 - return c != (u);
16012 + return c != u;
16013 }
16014
16015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16016 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16017 index 0f4460b..fa1ee19 100644
16018 --- a/arch/x86/include/asm/barrier.h
16019 +++ b/arch/x86/include/asm/barrier.h
16020 @@ -107,7 +107,7 @@
16021 do { \
16022 compiletime_assert_atomic_type(*p); \
16023 smp_mb(); \
16024 - ACCESS_ONCE(*p) = (v); \
16025 + ACCESS_ONCE_RW(*p) = (v); \
16026 } while (0)
16027
16028 #define smp_load_acquire(p) \
16029 @@ -124,7 +124,7 @@ do { \
16030 do { \
16031 compiletime_assert_atomic_type(*p); \
16032 barrier(); \
16033 - ACCESS_ONCE(*p) = (v); \
16034 + ACCESS_ONCE_RW(*p) = (v); \
16035 } while (0)
16036
16037 #define smp_load_acquire(p) \
16038 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16039 index cfe3b95..d01b118 100644
16040 --- a/arch/x86/include/asm/bitops.h
16041 +++ b/arch/x86/include/asm/bitops.h
16042 @@ -50,7 +50,7 @@
16043 * a mask operation on a byte.
16044 */
16045 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16046 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16047 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16048 #define CONST_MASK(nr) (1 << ((nr) & 7))
16049
16050 /**
16051 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16052 */
16053 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16054 {
16055 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16056 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16057 }
16058
16059 /**
16060 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16061 */
16062 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16063 {
16064 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16065 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16066 }
16067
16068 /**
16069 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16070 */
16071 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16072 {
16073 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16074 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16075 }
16076
16077 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16078 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16079 *
16080 * Undefined if no bit exists, so code should check against 0 first.
16081 */
16082 -static inline unsigned long __ffs(unsigned long word)
16083 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16084 {
16085 asm("rep; bsf %1,%0"
16086 : "=r" (word)
16087 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16088 *
16089 * Undefined if no zero exists, so code should check against ~0UL first.
16090 */
16091 -static inline unsigned long ffz(unsigned long word)
16092 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16093 {
16094 asm("rep; bsf %1,%0"
16095 : "=r" (word)
16096 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16097 *
16098 * Undefined if no set bit exists, so code should check against 0 first.
16099 */
16100 -static inline unsigned long __fls(unsigned long word)
16101 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16102 {
16103 asm("bsr %1,%0"
16104 : "=r" (word)
16105 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16106 * set bit if value is nonzero. The last (most significant) bit is
16107 * at position 32.
16108 */
16109 -static inline int fls(int x)
16110 +static inline int __intentional_overflow(-1) fls(int x)
16111 {
16112 int r;
16113
16114 @@ -476,7 +476,7 @@ static inline int fls(int x)
16115 * at position 64.
16116 */
16117 #ifdef CONFIG_X86_64
16118 -static __always_inline int fls64(__u64 x)
16119 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16120 {
16121 int bitpos = -1;
16122 /*
16123 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16124 index 4fa687a..60f2d39 100644
16125 --- a/arch/x86/include/asm/boot.h
16126 +++ b/arch/x86/include/asm/boot.h
16127 @@ -6,10 +6,15 @@
16128 #include <uapi/asm/boot.h>
16129
16130 /* Physical address where kernel should be loaded. */
16131 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16132 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16133 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16134 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16135
16136 +#ifndef __ASSEMBLY__
16137 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16138 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16139 +#endif
16140 +
16141 /* Minimum kernel alignment, as a power of two */
16142 #ifdef CONFIG_X86_64
16143 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16144 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16145 index 48f99f1..d78ebf9 100644
16146 --- a/arch/x86/include/asm/cache.h
16147 +++ b/arch/x86/include/asm/cache.h
16148 @@ -5,12 +5,13 @@
16149
16150 /* L1 cache line size */
16151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16152 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16153 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16154
16155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16156 +#define __read_only __attribute__((__section__(".data..read_only")))
16157
16158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16159 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16160 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16161
16162 #ifdef CONFIG_X86_VSMP
16163 #ifdef CONFIG_SMP
16164 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16165 index 9863ee3..4a1f8e1 100644
16166 --- a/arch/x86/include/asm/cacheflush.h
16167 +++ b/arch/x86/include/asm/cacheflush.h
16168 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16169 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16170
16171 if (pg_flags == _PGMT_DEFAULT)
16172 - return -1;
16173 + return ~0UL;
16174 else if (pg_flags == _PGMT_WC)
16175 return _PAGE_CACHE_WC;
16176 else if (pg_flags == _PGMT_UC_MINUS)
16177 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16178 index 76659b6..72b8439 100644
16179 --- a/arch/x86/include/asm/calling.h
16180 +++ b/arch/x86/include/asm/calling.h
16181 @@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16182 #define RSP 152
16183 #define SS 160
16184
16185 -#define ARGOFFSET R11
16186 -#define SWFRAME ORIG_RAX
16187 +#define ARGOFFSET R15
16188
16189 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16190 - subq $9*8+\addskip, %rsp
16191 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16192 - movq_cfi rdi, 8*8
16193 - movq_cfi rsi, 7*8
16194 - movq_cfi rdx, 6*8
16195 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16196 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16197 + movq_cfi rdi, RDI
16198 + movq_cfi rsi, RSI
16199 + movq_cfi rdx, RDX
16200
16201 .if \save_rcx
16202 - movq_cfi rcx, 5*8
16203 + movq_cfi rcx, RCX
16204 .endif
16205
16206 .if \rax_enosys
16207 - movq $-ENOSYS, 4*8(%rsp)
16208 + movq $-ENOSYS, RAX(%rsp)
16209 .else
16210 - movq_cfi rax, 4*8
16211 + movq_cfi rax, RAX
16212 .endif
16213
16214 .if \save_r891011
16215 - movq_cfi r8, 3*8
16216 - movq_cfi r9, 2*8
16217 - movq_cfi r10, 1*8
16218 - movq_cfi r11, 0*8
16219 + movq_cfi r8, R8
16220 + movq_cfi r9, R9
16221 + movq_cfi r10, R10
16222 + movq_cfi r11, R11
16223 .endif
16224
16225 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16226 + movq_cfi r12, R12
16227 +#endif
16228 +
16229 .endm
16230
16231 -#define ARG_SKIP (9*8)
16232 +#define ARG_SKIP ORIG_RAX
16233
16234 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16235 rstor_r8910=1, rstor_rdx=1
16236 +
16237 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16238 + movq_cfi_restore R12, r12
16239 +#endif
16240 +
16241 .if \rstor_r11
16242 - movq_cfi_restore 0*8, r11
16243 + movq_cfi_restore R11, r11
16244 .endif
16245
16246 .if \rstor_r8910
16247 - movq_cfi_restore 1*8, r10
16248 - movq_cfi_restore 2*8, r9
16249 - movq_cfi_restore 3*8, r8
16250 + movq_cfi_restore R10, r10
16251 + movq_cfi_restore R9, r9
16252 + movq_cfi_restore R8, r8
16253 .endif
16254
16255 .if \rstor_rax
16256 - movq_cfi_restore 4*8, rax
16257 + movq_cfi_restore RAX, rax
16258 .endif
16259
16260 .if \rstor_rcx
16261 - movq_cfi_restore 5*8, rcx
16262 + movq_cfi_restore RCX, rcx
16263 .endif
16264
16265 .if \rstor_rdx
16266 - movq_cfi_restore 6*8, rdx
16267 + movq_cfi_restore RDX, rdx
16268 .endif
16269
16270 - movq_cfi_restore 7*8, rsi
16271 - movq_cfi_restore 8*8, rdi
16272 + movq_cfi_restore RSI, rsi
16273 + movq_cfi_restore RDI, rdi
16274
16275 - .if ARG_SKIP+\addskip > 0
16276 - addq $ARG_SKIP+\addskip, %rsp
16277 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16278 + .if ORIG_RAX+\addskip > 0
16279 + addq $ORIG_RAX+\addskip, %rsp
16280 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16281 .endif
16282 .endm
16283
16284 - .macro LOAD_ARGS offset, skiprax=0
16285 - movq \offset(%rsp), %r11
16286 - movq \offset+8(%rsp), %r10
16287 - movq \offset+16(%rsp), %r9
16288 - movq \offset+24(%rsp), %r8
16289 - movq \offset+40(%rsp), %rcx
16290 - movq \offset+48(%rsp), %rdx
16291 - movq \offset+56(%rsp), %rsi
16292 - movq \offset+64(%rsp), %rdi
16293 + .macro LOAD_ARGS skiprax=0
16294 + movq R11(%rsp), %r11
16295 + movq R10(%rsp), %r10
16296 + movq R9(%rsp), %r9
16297 + movq R8(%rsp), %r8
16298 + movq RCX(%rsp), %rcx
16299 + movq RDX(%rsp), %rdx
16300 + movq RSI(%rsp), %rsi
16301 + movq RDI(%rsp), %rdi
16302 .if \skiprax
16303 .else
16304 - movq \offset+72(%rsp), %rax
16305 + movq ORIG_RAX(%rsp), %rax
16306 .endif
16307 .endm
16308
16309 -#define REST_SKIP (6*8)
16310 -
16311 .macro SAVE_REST
16312 - subq $REST_SKIP, %rsp
16313 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16314 - movq_cfi rbx, 5*8
16315 - movq_cfi rbp, 4*8
16316 - movq_cfi r12, 3*8
16317 - movq_cfi r13, 2*8
16318 - movq_cfi r14, 1*8
16319 - movq_cfi r15, 0*8
16320 + movq_cfi rbx, RBX
16321 + movq_cfi rbp, RBP
16322 +
16323 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16324 + movq_cfi r12, R12
16325 +#endif
16326 +
16327 + movq_cfi r13, R13
16328 + movq_cfi r14, R14
16329 + movq_cfi r15, R15
16330 .endm
16331
16332 .macro RESTORE_REST
16333 - movq_cfi_restore 0*8, r15
16334 - movq_cfi_restore 1*8, r14
16335 - movq_cfi_restore 2*8, r13
16336 - movq_cfi_restore 3*8, r12
16337 - movq_cfi_restore 4*8, rbp
16338 - movq_cfi_restore 5*8, rbx
16339 - addq $REST_SKIP, %rsp
16340 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16341 + movq_cfi_restore R15, r15
16342 + movq_cfi_restore R14, r14
16343 + movq_cfi_restore R13, r13
16344 +
16345 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16346 + movq_cfi_restore R12, r12
16347 +#endif
16348 +
16349 + movq_cfi_restore RBP, rbp
16350 + movq_cfi_restore RBX, rbx
16351 .endm
16352
16353 .macro SAVE_ALL
16354 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16355 index f50de69..2b0a458 100644
16356 --- a/arch/x86/include/asm/checksum_32.h
16357 +++ b/arch/x86/include/asm/checksum_32.h
16358 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16359 int len, __wsum sum,
16360 int *src_err_ptr, int *dst_err_ptr);
16361
16362 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16363 + int len, __wsum sum,
16364 + int *src_err_ptr, int *dst_err_ptr);
16365 +
16366 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16367 + int len, __wsum sum,
16368 + int *src_err_ptr, int *dst_err_ptr);
16369 +
16370 /*
16371 * Note: when you get a NULL pointer exception here this means someone
16372 * passed in an incorrect kernel address to one of these functions.
16373 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16374
16375 might_sleep();
16376 stac();
16377 - ret = csum_partial_copy_generic((__force void *)src, dst,
16378 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16379 len, sum, err_ptr, NULL);
16380 clac();
16381
16382 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16383 might_sleep();
16384 if (access_ok(VERIFY_WRITE, dst, len)) {
16385 stac();
16386 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16387 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16388 len, sum, NULL, err_ptr);
16389 clac();
16390 return ret;
16391 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16392 index 99c105d7..2f667ac 100644
16393 --- a/arch/x86/include/asm/cmpxchg.h
16394 +++ b/arch/x86/include/asm/cmpxchg.h
16395 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16396 __compiletime_error("Bad argument size for cmpxchg");
16397 extern void __xadd_wrong_size(void)
16398 __compiletime_error("Bad argument size for xadd");
16399 +extern void __xadd_check_overflow_wrong_size(void)
16400 + __compiletime_error("Bad argument size for xadd_check_overflow");
16401 extern void __add_wrong_size(void)
16402 __compiletime_error("Bad argument size for add");
16403 +extern void __add_check_overflow_wrong_size(void)
16404 + __compiletime_error("Bad argument size for add_check_overflow");
16405
16406 /*
16407 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16408 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16409 __ret; \
16410 })
16411
16412 +#ifdef CONFIG_PAX_REFCOUNT
16413 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16414 + ({ \
16415 + __typeof__ (*(ptr)) __ret = (arg); \
16416 + switch (sizeof(*(ptr))) { \
16417 + case __X86_CASE_L: \
16418 + asm volatile (lock #op "l %0, %1\n" \
16419 + "jno 0f\n" \
16420 + "mov %0,%1\n" \
16421 + "int $4\n0:\n" \
16422 + _ASM_EXTABLE(0b, 0b) \
16423 + : "+r" (__ret), "+m" (*(ptr)) \
16424 + : : "memory", "cc"); \
16425 + break; \
16426 + case __X86_CASE_Q: \
16427 + asm volatile (lock #op "q %q0, %1\n" \
16428 + "jno 0f\n" \
16429 + "mov %0,%1\n" \
16430 + "int $4\n0:\n" \
16431 + _ASM_EXTABLE(0b, 0b) \
16432 + : "+r" (__ret), "+m" (*(ptr)) \
16433 + : : "memory", "cc"); \
16434 + break; \
16435 + default: \
16436 + __ ## op ## _check_overflow_wrong_size(); \
16437 + } \
16438 + __ret; \
16439 + })
16440 +#else
16441 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16442 +#endif
16443 +
16444 /*
16445 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16446 * Since this is generally used to protect other memory information, we
16447 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16448 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16449 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16450
16451 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16452 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16453 +
16454 #define __add(ptr, inc, lock) \
16455 ({ \
16456 __typeof__ (*(ptr)) __ret = (inc); \
16457 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16458 index 59c6c40..5e0b22c 100644
16459 --- a/arch/x86/include/asm/compat.h
16460 +++ b/arch/x86/include/asm/compat.h
16461 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16462 typedef u32 compat_uint_t;
16463 typedef u32 compat_ulong_t;
16464 typedef u64 __attribute__((aligned(4))) compat_u64;
16465 -typedef u32 compat_uptr_t;
16466 +typedef u32 __user compat_uptr_t;
16467
16468 struct compat_timespec {
16469 compat_time_t tv_sec;
16470 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16471 index 0bb1335..8f1aec7 100644
16472 --- a/arch/x86/include/asm/cpufeature.h
16473 +++ b/arch/x86/include/asm/cpufeature.h
16474 @@ -207,7 +207,7 @@
16475 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16476 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16477 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16478 -
16479 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16480
16481 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16482 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16483 @@ -215,7 +215,7 @@
16484 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16485 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16486 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16487 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16488 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16489 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16490 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16491 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16492 @@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16493 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16494 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16495 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16496 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16497
16498 #if __GNUC__ >= 4
16499 extern void warn_pre_alternatives(void);
16500 @@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16501
16502 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16503 t_warn:
16504 - warn_pre_alternatives();
16505 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16506 + warn_pre_alternatives();
16507 return false;
16508 #endif
16509
16510 @@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16511 ".section .discard,\"aw\",@progbits\n"
16512 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16513 ".previous\n"
16514 - ".section .altinstr_replacement,\"ax\"\n"
16515 + ".section .altinstr_replacement,\"a\"\n"
16516 "3: movb $1,%0\n"
16517 "4:\n"
16518 ".previous\n"
16519 @@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16520 " .byte 2b - 1b\n" /* src len */
16521 " .byte 4f - 3f\n" /* repl len */
16522 ".previous\n"
16523 - ".section .altinstr_replacement,\"ax\"\n"
16524 + ".section .altinstr_replacement,\"a\"\n"
16525 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16526 "4:\n"
16527 ".previous\n"
16528 @@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16529 ".section .discard,\"aw\",@progbits\n"
16530 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16531 ".previous\n"
16532 - ".section .altinstr_replacement,\"ax\"\n"
16533 + ".section .altinstr_replacement,\"a\"\n"
16534 "3: movb $0,%0\n"
16535 "4:\n"
16536 ".previous\n"
16537 @@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16538 ".section .discard,\"aw\",@progbits\n"
16539 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16540 ".previous\n"
16541 - ".section .altinstr_replacement,\"ax\"\n"
16542 + ".section .altinstr_replacement,\"a\"\n"
16543 "5: movb $1,%0\n"
16544 "6:\n"
16545 ".previous\n"
16546 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16547 index a94b82e..59ecefa 100644
16548 --- a/arch/x86/include/asm/desc.h
16549 +++ b/arch/x86/include/asm/desc.h
16550 @@ -4,6 +4,7 @@
16551 #include <asm/desc_defs.h>
16552 #include <asm/ldt.h>
16553 #include <asm/mmu.h>
16554 +#include <asm/pgtable.h>
16555
16556 #include <linux/smp.h>
16557 #include <linux/percpu.h>
16558 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16559
16560 desc->type = (info->read_exec_only ^ 1) << 1;
16561 desc->type |= info->contents << 2;
16562 + desc->type |= info->seg_not_present ^ 1;
16563
16564 desc->s = 1;
16565 desc->dpl = 0x3;
16566 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16567 }
16568
16569 extern struct desc_ptr idt_descr;
16570 -extern gate_desc idt_table[];
16571 -extern struct desc_ptr debug_idt_descr;
16572 -extern gate_desc debug_idt_table[];
16573 -
16574 -struct gdt_page {
16575 - struct desc_struct gdt[GDT_ENTRIES];
16576 -} __attribute__((aligned(PAGE_SIZE)));
16577 -
16578 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16579 +extern gate_desc idt_table[IDT_ENTRIES];
16580 +extern const struct desc_ptr debug_idt_descr;
16581 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16582
16583 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16584 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16585 {
16586 - return per_cpu(gdt_page, cpu).gdt;
16587 + return cpu_gdt_table[cpu];
16588 }
16589
16590 #ifdef CONFIG_X86_64
16591 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16592 unsigned long base, unsigned dpl, unsigned flags,
16593 unsigned short seg)
16594 {
16595 - gate->a = (seg << 16) | (base & 0xffff);
16596 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16597 + gate->gate.offset_low = base;
16598 + gate->gate.seg = seg;
16599 + gate->gate.reserved = 0;
16600 + gate->gate.type = type;
16601 + gate->gate.s = 0;
16602 + gate->gate.dpl = dpl;
16603 + gate->gate.p = 1;
16604 + gate->gate.offset_high = base >> 16;
16605 }
16606
16607 #endif
16608 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16609
16610 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16611 {
16612 + pax_open_kernel();
16613 memcpy(&idt[entry], gate, sizeof(*gate));
16614 + pax_close_kernel();
16615 }
16616
16617 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16618 {
16619 + pax_open_kernel();
16620 memcpy(&ldt[entry], desc, 8);
16621 + pax_close_kernel();
16622 }
16623
16624 static inline void
16625 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16626 default: size = sizeof(*gdt); break;
16627 }
16628
16629 + pax_open_kernel();
16630 memcpy(&gdt[entry], desc, size);
16631 + pax_close_kernel();
16632 }
16633
16634 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16635 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16636
16637 static inline void native_load_tr_desc(void)
16638 {
16639 + pax_open_kernel();
16640 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16641 + pax_close_kernel();
16642 }
16643
16644 static inline void native_load_gdt(const struct desc_ptr *dtr)
16645 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16646 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16647 unsigned int i;
16648
16649 + pax_open_kernel();
16650 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16651 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16652 + pax_close_kernel();
16653 }
16654
16655 /* This intentionally ignores lm, since 32-bit apps don't have that field. */
16656 @@ -295,7 +308,7 @@ static inline void load_LDT(mm_context_t *pc)
16657 preempt_enable();
16658 }
16659
16660 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16661 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16662 {
16663 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16664 }
16665 @@ -319,7 +332,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16666 }
16667
16668 #ifdef CONFIG_X86_64
16669 -static inline void set_nmi_gate(int gate, void *addr)
16670 +static inline void set_nmi_gate(int gate, const void *addr)
16671 {
16672 gate_desc s;
16673
16674 @@ -329,14 +342,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16675 #endif
16676
16677 #ifdef CONFIG_TRACING
16678 -extern struct desc_ptr trace_idt_descr;
16679 -extern gate_desc trace_idt_table[];
16680 +extern const struct desc_ptr trace_idt_descr;
16681 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16682 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16683 {
16684 write_idt_entry(trace_idt_table, entry, gate);
16685 }
16686
16687 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16688 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16689 unsigned dpl, unsigned ist, unsigned seg)
16690 {
16691 gate_desc s;
16692 @@ -356,7 +369,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16693 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16694 #endif
16695
16696 -static inline void _set_gate(int gate, unsigned type, void *addr,
16697 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16698 unsigned dpl, unsigned ist, unsigned seg)
16699 {
16700 gate_desc s;
16701 @@ -379,9 +392,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16702 #define set_intr_gate(n, addr) \
16703 do { \
16704 BUG_ON((unsigned)n > 0xFF); \
16705 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16706 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16707 __KERNEL_CS); \
16708 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16709 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16710 0, 0, __KERNEL_CS); \
16711 } while (0)
16712
16713 @@ -409,19 +422,19 @@ static inline void alloc_system_vector(int vector)
16714 /*
16715 * This routine sets up an interrupt gate at directory privilege level 3.
16716 */
16717 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16718 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16719 {
16720 BUG_ON((unsigned)n > 0xFF);
16721 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16722 }
16723
16724 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16725 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16726 {
16727 BUG_ON((unsigned)n > 0xFF);
16728 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16729 }
16730
16731 -static inline void set_trap_gate(unsigned int n, void *addr)
16732 +static inline void set_trap_gate(unsigned int n, const void *addr)
16733 {
16734 BUG_ON((unsigned)n > 0xFF);
16735 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16736 @@ -430,16 +443,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16737 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16738 {
16739 BUG_ON((unsigned)n > 0xFF);
16740 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16741 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16742 }
16743
16744 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16745 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16746 {
16747 BUG_ON((unsigned)n > 0xFF);
16748 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16749 }
16750
16751 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16752 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16753 {
16754 BUG_ON((unsigned)n > 0xFF);
16755 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16756 @@ -511,4 +524,17 @@ static inline void load_current_idt(void)
16757 else
16758 load_idt((const struct desc_ptr *)&idt_descr);
16759 }
16760 +
16761 +#ifdef CONFIG_X86_32
16762 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16763 +{
16764 + struct desc_struct d;
16765 +
16766 + if (likely(limit))
16767 + limit = (limit - 1UL) >> PAGE_SHIFT;
16768 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16769 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16770 +}
16771 +#endif
16772 +
16773 #endif /* _ASM_X86_DESC_H */
16774 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16775 index 278441f..b95a174 100644
16776 --- a/arch/x86/include/asm/desc_defs.h
16777 +++ b/arch/x86/include/asm/desc_defs.h
16778 @@ -31,6 +31,12 @@ struct desc_struct {
16779 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16780 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16781 };
16782 + struct {
16783 + u16 offset_low;
16784 + u16 seg;
16785 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16786 + unsigned offset_high: 16;
16787 + } gate;
16788 };
16789 } __attribute__((packed));
16790
16791 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16792 index ced283a..ffe04cc 100644
16793 --- a/arch/x86/include/asm/div64.h
16794 +++ b/arch/x86/include/asm/div64.h
16795 @@ -39,7 +39,7 @@
16796 __mod; \
16797 })
16798
16799 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16800 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16801 {
16802 union {
16803 u64 v64;
16804 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16805 index ca3347a..1a5082a 100644
16806 --- a/arch/x86/include/asm/elf.h
16807 +++ b/arch/x86/include/asm/elf.h
16808 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16809
16810 #include <asm/vdso.h>
16811
16812 -#ifdef CONFIG_X86_64
16813 -extern unsigned int vdso64_enabled;
16814 -#endif
16815 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16816 extern unsigned int vdso32_enabled;
16817 #endif
16818 @@ -249,7 +246,25 @@ extern int force_personality32;
16819 the loader. We need to make sure that it is out of the way of the program
16820 that it will "exec", and that there is sufficient room for the brk. */
16821
16822 +#ifdef CONFIG_PAX_SEGMEXEC
16823 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16824 +#else
16825 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16826 +#endif
16827 +
16828 +#ifdef CONFIG_PAX_ASLR
16829 +#ifdef CONFIG_X86_32
16830 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16831 +
16832 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16833 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16834 +#else
16835 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16836 +
16837 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16838 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16839 +#endif
16840 +#endif
16841
16842 /* This yields a mask that user programs can use to figure out what
16843 instruction set this CPU supports. This could be done in user space,
16844 @@ -298,17 +313,13 @@ do { \
16845
16846 #define ARCH_DLINFO \
16847 do { \
16848 - if (vdso64_enabled) \
16849 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16850 - (unsigned long __force)current->mm->context.vdso); \
16851 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16852 } while (0)
16853
16854 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16855 #define ARCH_DLINFO_X32 \
16856 do { \
16857 - if (vdso64_enabled) \
16858 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16859 - (unsigned long __force)current->mm->context.vdso); \
16860 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16861 } while (0)
16862
16863 #define AT_SYSINFO 32
16864 @@ -323,10 +334,10 @@ else \
16865
16866 #endif /* !CONFIG_X86_32 */
16867
16868 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16869 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16870
16871 #define VDSO_ENTRY \
16872 - ((unsigned long)current->mm->context.vdso + \
16873 + (current->mm->context.vdso + \
16874 selected_vdso32->sym___kernel_vsyscall)
16875
16876 struct linux_binprm;
16877 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16878 int uses_interp);
16879 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16880
16881 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16882 -#define arch_randomize_brk arch_randomize_brk
16883 -
16884 /*
16885 * True on X86_32 or when emulating IA32 on X86_64
16886 */
16887 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16888 index 77a99ac..39ff7f5 100644
16889 --- a/arch/x86/include/asm/emergency-restart.h
16890 +++ b/arch/x86/include/asm/emergency-restart.h
16891 @@ -1,6 +1,6 @@
16892 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16893 #define _ASM_X86_EMERGENCY_RESTART_H
16894
16895 -extern void machine_emergency_restart(void);
16896 +extern void machine_emergency_restart(void) __noreturn;
16897
16898 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16899 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16900 index 1c7eefe..d0e4702 100644
16901 --- a/arch/x86/include/asm/floppy.h
16902 +++ b/arch/x86/include/asm/floppy.h
16903 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16904 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16905 } fd_routine[] = {
16906 {
16907 - request_dma,
16908 - free_dma,
16909 - get_dma_residue,
16910 - dma_mem_alloc,
16911 - hard_dma_setup
16912 + ._request_dma = request_dma,
16913 + ._free_dma = free_dma,
16914 + ._get_dma_residue = get_dma_residue,
16915 + ._dma_mem_alloc = dma_mem_alloc,
16916 + ._dma_setup = hard_dma_setup
16917 },
16918 {
16919 - vdma_request_dma,
16920 - vdma_nop,
16921 - vdma_get_dma_residue,
16922 - vdma_mem_alloc,
16923 - vdma_dma_setup
16924 + ._request_dma = vdma_request_dma,
16925 + ._free_dma = vdma_nop,
16926 + ._get_dma_residue = vdma_get_dma_residue,
16927 + ._dma_mem_alloc = vdma_mem_alloc,
16928 + ._dma_setup = vdma_dma_setup
16929 }
16930 };
16931
16932 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16933 index e97622f..d0ba77a 100644
16934 --- a/arch/x86/include/asm/fpu-internal.h
16935 +++ b/arch/x86/include/asm/fpu-internal.h
16936 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16937 #define user_insn(insn, output, input...) \
16938 ({ \
16939 int err; \
16940 + pax_open_userland(); \
16941 asm volatile(ASM_STAC "\n" \
16942 - "1:" #insn "\n\t" \
16943 + "1:" \
16944 + __copyuser_seg \
16945 + #insn "\n\t" \
16946 "2: " ASM_CLAC "\n" \
16947 ".section .fixup,\"ax\"\n" \
16948 "3: movl $-1,%[err]\n" \
16949 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16950 _ASM_EXTABLE(1b, 3b) \
16951 : [err] "=r" (err), output \
16952 : "0"(0), input); \
16953 + pax_close_userland(); \
16954 err; \
16955 })
16956
16957 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16958 "fnclex\n\t"
16959 "emms\n\t"
16960 "fildl %P[addr]" /* set F?P to defined value */
16961 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16962 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16963 }
16964
16965 return fpu_restore_checking(&tsk->thread.fpu);
16966 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16967 index b4c1f54..e290c08 100644
16968 --- a/arch/x86/include/asm/futex.h
16969 +++ b/arch/x86/include/asm/futex.h
16970 @@ -12,6 +12,7 @@
16971 #include <asm/smap.h>
16972
16973 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16974 + typecheck(u32 __user *, uaddr); \
16975 asm volatile("\t" ASM_STAC "\n" \
16976 "1:\t" insn "\n" \
16977 "2:\t" ASM_CLAC "\n" \
16978 @@ -20,15 +21,16 @@
16979 "\tjmp\t2b\n" \
16980 "\t.previous\n" \
16981 _ASM_EXTABLE(1b, 3b) \
16982 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16983 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16984 : "i" (-EFAULT), "0" (oparg), "1" (0))
16985
16986 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16987 + typecheck(u32 __user *, uaddr); \
16988 asm volatile("\t" ASM_STAC "\n" \
16989 "1:\tmovl %2, %0\n" \
16990 "\tmovl\t%0, %3\n" \
16991 "\t" insn "\n" \
16992 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16993 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16994 "\tjnz\t1b\n" \
16995 "3:\t" ASM_CLAC "\n" \
16996 "\t.section .fixup,\"ax\"\n" \
16997 @@ -38,7 +40,7 @@
16998 _ASM_EXTABLE(1b, 4b) \
16999 _ASM_EXTABLE(2b, 4b) \
17000 : "=&a" (oldval), "=&r" (ret), \
17001 - "+m" (*uaddr), "=&r" (tem) \
17002 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17003 : "r" (oparg), "i" (-EFAULT), "1" (0))
17004
17005 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17006 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17007
17008 pagefault_disable();
17009
17010 + pax_open_userland();
17011 switch (op) {
17012 case FUTEX_OP_SET:
17013 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17014 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17015 break;
17016 case FUTEX_OP_ADD:
17017 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17018 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17019 uaddr, oparg);
17020 break;
17021 case FUTEX_OP_OR:
17022 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17023 default:
17024 ret = -ENOSYS;
17025 }
17026 + pax_close_userland();
17027
17028 pagefault_enable();
17029
17030 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17031 index 4615906..788c817 100644
17032 --- a/arch/x86/include/asm/hw_irq.h
17033 +++ b/arch/x86/include/asm/hw_irq.h
17034 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17035 extern void enable_IO_APIC(void);
17036
17037 /* Statistics */
17038 -extern atomic_t irq_err_count;
17039 -extern atomic_t irq_mis_count;
17040 +extern atomic_unchecked_t irq_err_count;
17041 +extern atomic_unchecked_t irq_mis_count;
17042
17043 /* EISA */
17044 extern void eisa_set_level_irq(unsigned int irq);
17045 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17046 index ccffa53..3c90c87 100644
17047 --- a/arch/x86/include/asm/i8259.h
17048 +++ b/arch/x86/include/asm/i8259.h
17049 @@ -62,7 +62,7 @@ struct legacy_pic {
17050 void (*init)(int auto_eoi);
17051 int (*irq_pending)(unsigned int irq);
17052 void (*make_irq)(unsigned int irq);
17053 -};
17054 +} __do_const;
17055
17056 extern struct legacy_pic *legacy_pic;
17057 extern struct legacy_pic null_legacy_pic;
17058 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17059 index b8237d8..3e8864e 100644
17060 --- a/arch/x86/include/asm/io.h
17061 +++ b/arch/x86/include/asm/io.h
17062 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17063 "m" (*(volatile type __force *)addr) barrier); }
17064
17065 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17066 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17067 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17068 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17069 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17070
17071 build_mmio_read(__readb, "b", unsigned char, "=q", )
17072 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17073 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17074 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17075 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17076
17077 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17078 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17079 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17080 * this function
17081 */
17082
17083 -static inline phys_addr_t virt_to_phys(volatile void *address)
17084 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17085 {
17086 return __pa(address);
17087 }
17088 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17089 return ioremap_nocache(offset, size);
17090 }
17091
17092 -extern void iounmap(volatile void __iomem *addr);
17093 +extern void iounmap(const volatile void __iomem *addr);
17094
17095 extern void set_iounmap_nonlazy(void);
17096
17097 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17098
17099 #include <linux/vmalloc.h>
17100
17101 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17102 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17103 +{
17104 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17105 +}
17106 +
17107 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17108 +{
17109 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17110 +}
17111 +
17112 /*
17113 * Convert a virtual cached pointer to an uncached pointer
17114 */
17115 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17116 index 0a8b519..80e7d5b 100644
17117 --- a/arch/x86/include/asm/irqflags.h
17118 +++ b/arch/x86/include/asm/irqflags.h
17119 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17120 sti; \
17121 sysexit
17122
17123 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17124 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17125 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17126 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17127 +
17128 #else
17129 #define INTERRUPT_RETURN iret
17130 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17131 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17132 index 4421b5d..8543006 100644
17133 --- a/arch/x86/include/asm/kprobes.h
17134 +++ b/arch/x86/include/asm/kprobes.h
17135 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17136 #define RELATIVEJUMP_SIZE 5
17137 #define RELATIVECALL_OPCODE 0xe8
17138 #define RELATIVE_ADDR_SIZE 4
17139 -#define MAX_STACK_SIZE 64
17140 -#define MIN_STACK_SIZE(ADDR) \
17141 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17142 - THREAD_SIZE - (unsigned long)(ADDR))) \
17143 - ? (MAX_STACK_SIZE) \
17144 - : (((unsigned long)current_thread_info()) + \
17145 - THREAD_SIZE - (unsigned long)(ADDR)))
17146 +#define MAX_STACK_SIZE 64UL
17147 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17148
17149 #define flush_insn_slot(p) do { } while (0)
17150
17151 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17152 index 6ed0c30..74fb6c3 100644
17153 --- a/arch/x86/include/asm/kvm_host.h
17154 +++ b/arch/x86/include/asm/kvm_host.h
17155 @@ -51,6 +51,7 @@
17156 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17157
17158 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17159 +#define CR3_PCID_INVD (1UL << 63)
17160 #define CR4_RESERVED_BITS \
17161 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17162 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17163 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17164 index 4ad6560..75c7bdd 100644
17165 --- a/arch/x86/include/asm/local.h
17166 +++ b/arch/x86/include/asm/local.h
17167 @@ -10,33 +10,97 @@ typedef struct {
17168 atomic_long_t a;
17169 } local_t;
17170
17171 +typedef struct {
17172 + atomic_long_unchecked_t a;
17173 +} local_unchecked_t;
17174 +
17175 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17176
17177 #define local_read(l) atomic_long_read(&(l)->a)
17178 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17179 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17180 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17181
17182 static inline void local_inc(local_t *l)
17183 {
17184 - asm volatile(_ASM_INC "%0"
17185 + asm volatile(_ASM_INC "%0\n"
17186 +
17187 +#ifdef CONFIG_PAX_REFCOUNT
17188 + "jno 0f\n"
17189 + _ASM_DEC "%0\n"
17190 + "int $4\n0:\n"
17191 + _ASM_EXTABLE(0b, 0b)
17192 +#endif
17193 +
17194 + : "+m" (l->a.counter));
17195 +}
17196 +
17197 +static inline void local_inc_unchecked(local_unchecked_t *l)
17198 +{
17199 + asm volatile(_ASM_INC "%0\n"
17200 : "+m" (l->a.counter));
17201 }
17202
17203 static inline void local_dec(local_t *l)
17204 {
17205 - asm volatile(_ASM_DEC "%0"
17206 + asm volatile(_ASM_DEC "%0\n"
17207 +
17208 +#ifdef CONFIG_PAX_REFCOUNT
17209 + "jno 0f\n"
17210 + _ASM_INC "%0\n"
17211 + "int $4\n0:\n"
17212 + _ASM_EXTABLE(0b, 0b)
17213 +#endif
17214 +
17215 + : "+m" (l->a.counter));
17216 +}
17217 +
17218 +static inline void local_dec_unchecked(local_unchecked_t *l)
17219 +{
17220 + asm volatile(_ASM_DEC "%0\n"
17221 : "+m" (l->a.counter));
17222 }
17223
17224 static inline void local_add(long i, local_t *l)
17225 {
17226 - asm volatile(_ASM_ADD "%1,%0"
17227 + asm volatile(_ASM_ADD "%1,%0\n"
17228 +
17229 +#ifdef CONFIG_PAX_REFCOUNT
17230 + "jno 0f\n"
17231 + _ASM_SUB "%1,%0\n"
17232 + "int $4\n0:\n"
17233 + _ASM_EXTABLE(0b, 0b)
17234 +#endif
17235 +
17236 + : "+m" (l->a.counter)
17237 + : "ir" (i));
17238 +}
17239 +
17240 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17241 +{
17242 + asm volatile(_ASM_ADD "%1,%0\n"
17243 : "+m" (l->a.counter)
17244 : "ir" (i));
17245 }
17246
17247 static inline void local_sub(long i, local_t *l)
17248 {
17249 - asm volatile(_ASM_SUB "%1,%0"
17250 + asm volatile(_ASM_SUB "%1,%0\n"
17251 +
17252 +#ifdef CONFIG_PAX_REFCOUNT
17253 + "jno 0f\n"
17254 + _ASM_ADD "%1,%0\n"
17255 + "int $4\n0:\n"
17256 + _ASM_EXTABLE(0b, 0b)
17257 +#endif
17258 +
17259 + : "+m" (l->a.counter)
17260 + : "ir" (i));
17261 +}
17262 +
17263 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17264 +{
17265 + asm volatile(_ASM_SUB "%1,%0\n"
17266 : "+m" (l->a.counter)
17267 : "ir" (i));
17268 }
17269 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17270 */
17271 static inline int local_sub_and_test(long i, local_t *l)
17272 {
17273 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17274 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17275 }
17276
17277 /**
17278 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17279 */
17280 static inline int local_dec_and_test(local_t *l)
17281 {
17282 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17283 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17284 }
17285
17286 /**
17287 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17288 */
17289 static inline int local_inc_and_test(local_t *l)
17290 {
17291 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17292 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17293 }
17294
17295 /**
17296 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17297 */
17298 static inline int local_add_negative(long i, local_t *l)
17299 {
17300 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17301 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17302 }
17303
17304 /**
17305 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17306 static inline long local_add_return(long i, local_t *l)
17307 {
17308 long __i = i;
17309 + asm volatile(_ASM_XADD "%0, %1\n"
17310 +
17311 +#ifdef CONFIG_PAX_REFCOUNT
17312 + "jno 0f\n"
17313 + _ASM_MOV "%0,%1\n"
17314 + "int $4\n0:\n"
17315 + _ASM_EXTABLE(0b, 0b)
17316 +#endif
17317 +
17318 + : "+r" (i), "+m" (l->a.counter)
17319 + : : "memory");
17320 + return i + __i;
17321 +}
17322 +
17323 +/**
17324 + * local_add_return_unchecked - add and return
17325 + * @i: integer value to add
17326 + * @l: pointer to type local_unchecked_t
17327 + *
17328 + * Atomically adds @i to @l and returns @i + @l
17329 + */
17330 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17331 +{
17332 + long __i = i;
17333 asm volatile(_ASM_XADD "%0, %1;"
17334 : "+r" (i), "+m" (l->a.counter)
17335 : : "memory");
17336 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17337
17338 #define local_cmpxchg(l, o, n) \
17339 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17340 +#define local_cmpxchg_unchecked(l, o, n) \
17341 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17342 /* Always has a lock prefix */
17343 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17344
17345 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17346 new file mode 100644
17347 index 0000000..2bfd3ba
17348 --- /dev/null
17349 +++ b/arch/x86/include/asm/mman.h
17350 @@ -0,0 +1,15 @@
17351 +#ifndef _X86_MMAN_H
17352 +#define _X86_MMAN_H
17353 +
17354 +#include <uapi/asm/mman.h>
17355 +
17356 +#ifdef __KERNEL__
17357 +#ifndef __ASSEMBLY__
17358 +#ifdef CONFIG_X86_32
17359 +#define arch_mmap_check i386_mmap_check
17360 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17361 +#endif
17362 +#endif
17363 +#endif
17364 +
17365 +#endif /* X86_MMAN_H */
17366 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17367 index 876e74e..e20bfb1 100644
17368 --- a/arch/x86/include/asm/mmu.h
17369 +++ b/arch/x86/include/asm/mmu.h
17370 @@ -9,7 +9,7 @@
17371 * we put the segment information here.
17372 */
17373 typedef struct {
17374 - void *ldt;
17375 + struct desc_struct *ldt;
17376 int size;
17377
17378 #ifdef CONFIG_X86_64
17379 @@ -18,7 +18,19 @@ typedef struct {
17380 #endif
17381
17382 struct mutex lock;
17383 - void __user *vdso;
17384 + unsigned long vdso;
17385 +
17386 +#ifdef CONFIG_X86_32
17387 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17388 + unsigned long user_cs_base;
17389 + unsigned long user_cs_limit;
17390 +
17391 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17392 + cpumask_t cpu_user_cs_mask;
17393 +#endif
17394 +
17395 +#endif
17396 +#endif
17397 } mm_context_t;
17398
17399 #ifdef CONFIG_SMP
17400 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17401 index 166af2a..648c200 100644
17402 --- a/arch/x86/include/asm/mmu_context.h
17403 +++ b/arch/x86/include/asm/mmu_context.h
17404 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17405
17406 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17407 {
17408 +
17409 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17410 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17411 + unsigned int i;
17412 + pgd_t *pgd;
17413 +
17414 + pax_open_kernel();
17415 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17416 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17417 + set_pgd_batched(pgd+i, native_make_pgd(0));
17418 + pax_close_kernel();
17419 + }
17420 +#endif
17421 +
17422 #ifdef CONFIG_SMP
17423 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17424 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17425 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17426 struct task_struct *tsk)
17427 {
17428 unsigned cpu = smp_processor_id();
17429 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17430 + int tlbstate = TLBSTATE_OK;
17431 +#endif
17432
17433 if (likely(prev != next)) {
17434 #ifdef CONFIG_SMP
17435 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17436 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17437 +#endif
17438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17439 this_cpu_write(cpu_tlbstate.active_mm, next);
17440 #endif
17441 cpumask_set_cpu(cpu, mm_cpumask(next));
17442
17443 /* Re-load page tables */
17444 +#ifdef CONFIG_PAX_PER_CPU_PGD
17445 + pax_open_kernel();
17446 +
17447 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17448 + if (static_cpu_has(X86_FEATURE_PCID))
17449 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17450 + else
17451 +#endif
17452 +
17453 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17454 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17455 + pax_close_kernel();
17456 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17457 +
17458 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17459 + if (static_cpu_has(X86_FEATURE_PCID)) {
17460 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17461 + u64 descriptor[2];
17462 + descriptor[0] = PCID_USER;
17463 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17464 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17465 + descriptor[0] = PCID_KERNEL;
17466 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17467 + }
17468 + } else {
17469 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17470 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17471 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17472 + else
17473 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17474 + }
17475 + } else
17476 +#endif
17477 +
17478 + load_cr3(get_cpu_pgd(cpu, kernel));
17479 +#else
17480 load_cr3(next->pgd);
17481 +#endif
17482 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17483
17484 /* Stop flush ipis for the previous mm */
17485 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17486 /* Load the LDT, if the LDT is different: */
17487 if (unlikely(prev->context.ldt != next->context.ldt))
17488 load_LDT_nolock(&next->context);
17489 +
17490 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17491 + if (!(__supported_pte_mask & _PAGE_NX)) {
17492 + smp_mb__before_atomic();
17493 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17494 + smp_mb__after_atomic();
17495 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17496 + }
17497 +#endif
17498 +
17499 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17500 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17501 + prev->context.user_cs_limit != next->context.user_cs_limit))
17502 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17503 +#ifdef CONFIG_SMP
17504 + else if (unlikely(tlbstate != TLBSTATE_OK))
17505 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17506 +#endif
17507 +#endif
17508 +
17509 }
17510 + else {
17511 +
17512 +#ifdef CONFIG_PAX_PER_CPU_PGD
17513 + pax_open_kernel();
17514 +
17515 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17516 + if (static_cpu_has(X86_FEATURE_PCID))
17517 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17518 + else
17519 +#endif
17520 +
17521 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17522 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17523 + pax_close_kernel();
17524 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17525 +
17526 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17527 + if (static_cpu_has(X86_FEATURE_PCID)) {
17528 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17529 + u64 descriptor[2];
17530 + descriptor[0] = PCID_USER;
17531 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17532 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17533 + descriptor[0] = PCID_KERNEL;
17534 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17535 + }
17536 + } else {
17537 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17538 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17539 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17540 + else
17541 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17542 + }
17543 + } else
17544 +#endif
17545 +
17546 + load_cr3(get_cpu_pgd(cpu, kernel));
17547 +#endif
17548 +
17549 #ifdef CONFIG_SMP
17550 - else {
17551 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17552 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17553
17554 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17555 * tlb flush IPI delivery. We must reload CR3
17556 * to make sure to use no freed page tables.
17557 */
17558 +
17559 +#ifndef CONFIG_PAX_PER_CPU_PGD
17560 load_cr3(next->pgd);
17561 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17562 +#endif
17563 +
17564 load_LDT_nolock(&next->context);
17565 +
17566 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17567 + if (!(__supported_pte_mask & _PAGE_NX))
17568 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17569 +#endif
17570 +
17571 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17572 +#ifdef CONFIG_PAX_PAGEEXEC
17573 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17574 +#endif
17575 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17576 +#endif
17577 +
17578 }
17579 +#endif
17580 }
17581 -#endif
17582 }
17583
17584 #define activate_mm(prev, next) \
17585 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17586 index e3b7819..b257c64 100644
17587 --- a/arch/x86/include/asm/module.h
17588 +++ b/arch/x86/include/asm/module.h
17589 @@ -5,6 +5,7 @@
17590
17591 #ifdef CONFIG_X86_64
17592 /* X86_64 does not define MODULE_PROC_FAMILY */
17593 +#define MODULE_PROC_FAMILY ""
17594 #elif defined CONFIG_M486
17595 #define MODULE_PROC_FAMILY "486 "
17596 #elif defined CONFIG_M586
17597 @@ -57,8 +58,20 @@
17598 #error unknown processor family
17599 #endif
17600
17601 -#ifdef CONFIG_X86_32
17602 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17603 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17604 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17605 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17606 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17607 +#else
17608 +#define MODULE_PAX_KERNEXEC ""
17609 #endif
17610
17611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17612 +#define MODULE_PAX_UDEREF "UDEREF "
17613 +#else
17614 +#define MODULE_PAX_UDEREF ""
17615 +#endif
17616 +
17617 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17618 +
17619 #endif /* _ASM_X86_MODULE_H */
17620 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17621 index 5f2fc44..106caa6 100644
17622 --- a/arch/x86/include/asm/nmi.h
17623 +++ b/arch/x86/include/asm/nmi.h
17624 @@ -36,26 +36,35 @@ enum {
17625
17626 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17627
17628 +struct nmiaction;
17629 +
17630 +struct nmiwork {
17631 + const struct nmiaction *action;
17632 + u64 max_duration;
17633 + struct irq_work irq_work;
17634 +};
17635 +
17636 struct nmiaction {
17637 struct list_head list;
17638 nmi_handler_t handler;
17639 - u64 max_duration;
17640 - struct irq_work irq_work;
17641 unsigned long flags;
17642 const char *name;
17643 -};
17644 + struct nmiwork *work;
17645 +} __do_const;
17646
17647 #define register_nmi_handler(t, fn, fg, n, init...) \
17648 ({ \
17649 - static struct nmiaction init fn##_na = { \
17650 + static struct nmiwork fn##_nw; \
17651 + static const struct nmiaction init fn##_na = { \
17652 .handler = (fn), \
17653 .name = (n), \
17654 .flags = (fg), \
17655 + .work = &fn##_nw, \
17656 }; \
17657 __register_nmi_handler((t), &fn##_na); \
17658 })
17659
17660 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17661 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17662
17663 void unregister_nmi_handler(unsigned int, const char *);
17664
17665 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17666 index 802dde3..9183e68 100644
17667 --- a/arch/x86/include/asm/page.h
17668 +++ b/arch/x86/include/asm/page.h
17669 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17670 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17671
17672 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17673 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17674
17675 #define __boot_va(x) __va(x)
17676 #define __boot_pa(x) __pa(x)
17677 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17678 * virt_to_page(kaddr) returns a valid pointer if and only if
17679 * virt_addr_valid(kaddr) returns true.
17680 */
17681 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17682 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17683 extern bool __virt_addr_valid(unsigned long kaddr);
17684 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17685
17686 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17687 +#define virt_to_page(kaddr) \
17688 + ({ \
17689 + const void *__kaddr = (const void *)(kaddr); \
17690 + BUG_ON(!virt_addr_valid(__kaddr)); \
17691 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17692 + })
17693 +#else
17694 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17695 +#endif
17696 +
17697 #endif /* __ASSEMBLY__ */
17698
17699 #include <asm-generic/memory_model.h>
17700 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17701 index f408caf..4a0455e 100644
17702 --- a/arch/x86/include/asm/page_64.h
17703 +++ b/arch/x86/include/asm/page_64.h
17704 @@ -7,9 +7,9 @@
17705
17706 /* duplicated to the one in bootmem.h */
17707 extern unsigned long max_pfn;
17708 -extern unsigned long phys_base;
17709 +extern const unsigned long phys_base;
17710
17711 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17712 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17713 {
17714 unsigned long y = x - __START_KERNEL_map;
17715
17716 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17717 index cd6e1610..70f4418 100644
17718 --- a/arch/x86/include/asm/paravirt.h
17719 +++ b/arch/x86/include/asm/paravirt.h
17720 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17721 return (pmd_t) { ret };
17722 }
17723
17724 -static inline pmdval_t pmd_val(pmd_t pmd)
17725 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17726 {
17727 pmdval_t ret;
17728
17729 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17730 val);
17731 }
17732
17733 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17734 +{
17735 + pgdval_t val = native_pgd_val(pgd);
17736 +
17737 + if (sizeof(pgdval_t) > sizeof(long))
17738 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17739 + val, (u64)val >> 32);
17740 + else
17741 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17742 + val);
17743 +}
17744 +
17745 static inline void pgd_clear(pgd_t *pgdp)
17746 {
17747 set_pgd(pgdp, __pgd(0));
17748 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17749 pv_mmu_ops.set_fixmap(idx, phys, flags);
17750 }
17751
17752 +#ifdef CONFIG_PAX_KERNEXEC
17753 +static inline unsigned long pax_open_kernel(void)
17754 +{
17755 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17756 +}
17757 +
17758 +static inline unsigned long pax_close_kernel(void)
17759 +{
17760 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17761 +}
17762 +#else
17763 +static inline unsigned long pax_open_kernel(void) { return 0; }
17764 +static inline unsigned long pax_close_kernel(void) { return 0; }
17765 +#endif
17766 +
17767 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17768
17769 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17770 @@ -906,7 +933,7 @@ extern void default_banner(void);
17771
17772 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17773 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17774 -#define PARA_INDIRECT(addr) *%cs:addr
17775 +#define PARA_INDIRECT(addr) *%ss:addr
17776 #endif
17777
17778 #define INTERRUPT_RETURN \
17779 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17780 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17781 CLBR_NONE, \
17782 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17783 +
17784 +#define GET_CR0_INTO_RDI \
17785 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17786 + mov %rax,%rdi
17787 +
17788 +#define SET_RDI_INTO_CR0 \
17789 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17790 +
17791 +#define GET_CR3_INTO_RDI \
17792 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17793 + mov %rax,%rdi
17794 +
17795 +#define SET_RDI_INTO_CR3 \
17796 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17797 +
17798 #endif /* CONFIG_X86_32 */
17799
17800 #endif /* __ASSEMBLY__ */
17801 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17802 index 7549b8b..f0edfda 100644
17803 --- a/arch/x86/include/asm/paravirt_types.h
17804 +++ b/arch/x86/include/asm/paravirt_types.h
17805 @@ -84,7 +84,7 @@ struct pv_init_ops {
17806 */
17807 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17808 unsigned long addr, unsigned len);
17809 -};
17810 +} __no_const __no_randomize_layout;
17811
17812
17813 struct pv_lazy_ops {
17814 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17815 void (*enter)(void);
17816 void (*leave)(void);
17817 void (*flush)(void);
17818 -};
17819 +} __no_randomize_layout;
17820
17821 struct pv_time_ops {
17822 unsigned long long (*sched_clock)(void);
17823 unsigned long long (*steal_clock)(int cpu);
17824 unsigned long (*get_tsc_khz)(void);
17825 -};
17826 +} __no_const __no_randomize_layout;
17827
17828 struct pv_cpu_ops {
17829 /* hooks for various privileged instructions */
17830 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17831
17832 void (*start_context_switch)(struct task_struct *prev);
17833 void (*end_context_switch)(struct task_struct *next);
17834 -};
17835 +} __no_const __no_randomize_layout;
17836
17837 struct pv_irq_ops {
17838 /*
17839 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17840 #ifdef CONFIG_X86_64
17841 void (*adjust_exception_frame)(void);
17842 #endif
17843 -};
17844 +} __no_randomize_layout;
17845
17846 struct pv_apic_ops {
17847 #ifdef CONFIG_X86_LOCAL_APIC
17848 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17849 unsigned long start_eip,
17850 unsigned long start_esp);
17851 #endif
17852 -};
17853 +} __no_const __no_randomize_layout;
17854
17855 struct pv_mmu_ops {
17856 unsigned long (*read_cr2)(void);
17857 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17858 struct paravirt_callee_save make_pud;
17859
17860 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17861 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17862 #endif /* PAGETABLE_LEVELS == 4 */
17863 #endif /* PAGETABLE_LEVELS >= 3 */
17864
17865 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17866 an mfn. We can tell which is which from the index. */
17867 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17868 phys_addr_t phys, pgprot_t flags);
17869 -};
17870 +
17871 +#ifdef CONFIG_PAX_KERNEXEC
17872 + unsigned long (*pax_open_kernel)(void);
17873 + unsigned long (*pax_close_kernel)(void);
17874 +#endif
17875 +
17876 +} __no_randomize_layout;
17877
17878 struct arch_spinlock;
17879 #ifdef CONFIG_SMP
17880 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17881 struct pv_lock_ops {
17882 struct paravirt_callee_save lock_spinning;
17883 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17884 -};
17885 +} __no_randomize_layout;
17886
17887 /* This contains all the paravirt structures: we get a convenient
17888 * number for each function using the offset which we use to indicate
17889 - * what to patch. */
17890 + * what to patch.
17891 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17892 + */
17893 +
17894 struct paravirt_patch_template {
17895 struct pv_init_ops pv_init_ops;
17896 struct pv_time_ops pv_time_ops;
17897 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17898 struct pv_apic_ops pv_apic_ops;
17899 struct pv_mmu_ops pv_mmu_ops;
17900 struct pv_lock_ops pv_lock_ops;
17901 -};
17902 +} __no_randomize_layout;
17903
17904 extern struct pv_info pv_info;
17905 extern struct pv_init_ops pv_init_ops;
17906 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17907 index c4412e9..90e88c5 100644
17908 --- a/arch/x86/include/asm/pgalloc.h
17909 +++ b/arch/x86/include/asm/pgalloc.h
17910 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17911 pmd_t *pmd, pte_t *pte)
17912 {
17913 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17914 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17915 +}
17916 +
17917 +static inline void pmd_populate_user(struct mm_struct *mm,
17918 + pmd_t *pmd, pte_t *pte)
17919 +{
17920 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17921 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17922 }
17923
17924 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17925
17926 #ifdef CONFIG_X86_PAE
17927 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17928 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17929 +{
17930 + pud_populate(mm, pudp, pmd);
17931 +}
17932 #else /* !CONFIG_X86_PAE */
17933 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17934 {
17935 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17936 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17937 }
17938 +
17939 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17940 +{
17941 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17942 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17943 +}
17944 #endif /* CONFIG_X86_PAE */
17945
17946 #if PAGETABLE_LEVELS > 3
17947 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17948 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17949 }
17950
17951 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17952 +{
17953 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17954 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17955 +}
17956 +
17957 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17958 {
17959 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17960 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17961 index 206a87f..1623b06 100644
17962 --- a/arch/x86/include/asm/pgtable-2level.h
17963 +++ b/arch/x86/include/asm/pgtable-2level.h
17964 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17965
17966 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17967 {
17968 + pax_open_kernel();
17969 *pmdp = pmd;
17970 + pax_close_kernel();
17971 }
17972
17973 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17974 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17975 index 81bb91b..9392125 100644
17976 --- a/arch/x86/include/asm/pgtable-3level.h
17977 +++ b/arch/x86/include/asm/pgtable-3level.h
17978 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17979
17980 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17981 {
17982 + pax_open_kernel();
17983 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17984 + pax_close_kernel();
17985 }
17986
17987 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17988 {
17989 + pax_open_kernel();
17990 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17991 + pax_close_kernel();
17992 }
17993
17994 /*
17995 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17996 index aa97a07..5c53c32 100644
17997 --- a/arch/x86/include/asm/pgtable.h
17998 +++ b/arch/x86/include/asm/pgtable.h
17999 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18000
18001 #ifndef __PAGETABLE_PUD_FOLDED
18002 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18003 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18004 #define pgd_clear(pgd) native_pgd_clear(pgd)
18005 #endif
18006
18007 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18008
18009 #define arch_end_context_switch(prev) do {} while(0)
18010
18011 +#define pax_open_kernel() native_pax_open_kernel()
18012 +#define pax_close_kernel() native_pax_close_kernel()
18013 #endif /* CONFIG_PARAVIRT */
18014
18015 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18016 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18017 +
18018 +#ifdef CONFIG_PAX_KERNEXEC
18019 +static inline unsigned long native_pax_open_kernel(void)
18020 +{
18021 + unsigned long cr0;
18022 +
18023 + preempt_disable();
18024 + barrier();
18025 + cr0 = read_cr0() ^ X86_CR0_WP;
18026 + BUG_ON(cr0 & X86_CR0_WP);
18027 + write_cr0(cr0);
18028 + barrier();
18029 + return cr0 ^ X86_CR0_WP;
18030 +}
18031 +
18032 +static inline unsigned long native_pax_close_kernel(void)
18033 +{
18034 + unsigned long cr0;
18035 +
18036 + barrier();
18037 + cr0 = read_cr0() ^ X86_CR0_WP;
18038 + BUG_ON(!(cr0 & X86_CR0_WP));
18039 + write_cr0(cr0);
18040 + barrier();
18041 + preempt_enable_no_resched();
18042 + return cr0 ^ X86_CR0_WP;
18043 +}
18044 +#else
18045 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18046 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18047 +#endif
18048 +
18049 /*
18050 * The following only work if pte_present() is true.
18051 * Undefined behaviour if not..
18052 */
18053 +static inline int pte_user(pte_t pte)
18054 +{
18055 + return pte_val(pte) & _PAGE_USER;
18056 +}
18057 +
18058 static inline int pte_dirty(pte_t pte)
18059 {
18060 return pte_flags(pte) & _PAGE_DIRTY;
18061 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18062 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18063 }
18064
18065 +static inline unsigned long pgd_pfn(pgd_t pgd)
18066 +{
18067 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18068 +}
18069 +
18070 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18071
18072 static inline int pmd_large(pmd_t pte)
18073 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18074 return pte_clear_flags(pte, _PAGE_RW);
18075 }
18076
18077 +static inline pte_t pte_mkread(pte_t pte)
18078 +{
18079 + return __pte(pte_val(pte) | _PAGE_USER);
18080 +}
18081 +
18082 static inline pte_t pte_mkexec(pte_t pte)
18083 {
18084 - return pte_clear_flags(pte, _PAGE_NX);
18085 +#ifdef CONFIG_X86_PAE
18086 + if (__supported_pte_mask & _PAGE_NX)
18087 + return pte_clear_flags(pte, _PAGE_NX);
18088 + else
18089 +#endif
18090 + return pte_set_flags(pte, _PAGE_USER);
18091 +}
18092 +
18093 +static inline pte_t pte_exprotect(pte_t pte)
18094 +{
18095 +#ifdef CONFIG_X86_PAE
18096 + if (__supported_pte_mask & _PAGE_NX)
18097 + return pte_set_flags(pte, _PAGE_NX);
18098 + else
18099 +#endif
18100 + return pte_clear_flags(pte, _PAGE_USER);
18101 }
18102
18103 static inline pte_t pte_mkdirty(pte_t pte)
18104 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18105 #endif
18106
18107 #ifndef __ASSEMBLY__
18108 +
18109 +#ifdef CONFIG_PAX_PER_CPU_PGD
18110 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18111 +enum cpu_pgd_type {kernel = 0, user = 1};
18112 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18113 +{
18114 + return cpu_pgd[cpu][type];
18115 +}
18116 +#endif
18117 +
18118 #include <linux/mm_types.h>
18119 #include <linux/mmdebug.h>
18120 #include <linux/log2.h>
18121 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18122 * Currently stuck as a macro due to indirect forward reference to
18123 * linux/mmzone.h's __section_mem_map_addr() definition:
18124 */
18125 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18126 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18127
18128 /* Find an entry in the second-level page table.. */
18129 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18130 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18131 * Currently stuck as a macro due to indirect forward reference to
18132 * linux/mmzone.h's __section_mem_map_addr() definition:
18133 */
18134 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18135 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18136
18137 /* to find an entry in a page-table-directory. */
18138 static inline unsigned long pud_index(unsigned long address)
18139 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18140
18141 static inline int pgd_bad(pgd_t pgd)
18142 {
18143 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18144 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18145 }
18146
18147 static inline int pgd_none(pgd_t pgd)
18148 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18149 * pgd_offset() returns a (pgd_t *)
18150 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18151 */
18152 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18153 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18154 +
18155 +#ifdef CONFIG_PAX_PER_CPU_PGD
18156 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18157 +#endif
18158 +
18159 /*
18160 * a shortcut which implies the use of the kernel's pgd, instead
18161 * of a process's
18162 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18163 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18164 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18165
18166 +#ifdef CONFIG_X86_32
18167 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18168 +#else
18169 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18170 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18171 +
18172 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18173 +#ifdef __ASSEMBLY__
18174 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18175 +#else
18176 +extern unsigned long pax_user_shadow_base;
18177 +extern pgdval_t clone_pgd_mask;
18178 +#endif
18179 +#endif
18180 +
18181 +#endif
18182 +
18183 #ifndef __ASSEMBLY__
18184
18185 extern int direct_gbpages;
18186 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18187 * dst and src can be on the same page, but the range must not overlap,
18188 * and must not cross a page boundary.
18189 */
18190 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18191 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18192 {
18193 - memcpy(dst, src, count * sizeof(pgd_t));
18194 + pax_open_kernel();
18195 + while (count--)
18196 + *dst++ = *src++;
18197 + pax_close_kernel();
18198 }
18199
18200 +#ifdef CONFIG_PAX_PER_CPU_PGD
18201 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18202 +#endif
18203 +
18204 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18205 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18206 +#else
18207 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18208 +#endif
18209 +
18210 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18211 static inline int page_level_shift(enum pg_level level)
18212 {
18213 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18214 index b6c0b40..3535d47 100644
18215 --- a/arch/x86/include/asm/pgtable_32.h
18216 +++ b/arch/x86/include/asm/pgtable_32.h
18217 @@ -25,9 +25,6 @@
18218 struct mm_struct;
18219 struct vm_area_struct;
18220
18221 -extern pgd_t swapper_pg_dir[1024];
18222 -extern pgd_t initial_page_table[1024];
18223 -
18224 static inline void pgtable_cache_init(void) { }
18225 static inline void check_pgt_cache(void) { }
18226 void paging_init(void);
18227 @@ -45,6 +42,12 @@ void paging_init(void);
18228 # include <asm/pgtable-2level.h>
18229 #endif
18230
18231 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18232 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18233 +#ifdef CONFIG_X86_PAE
18234 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18235 +#endif
18236 +
18237 #if defined(CONFIG_HIGHPTE)
18238 #define pte_offset_map(dir, address) \
18239 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18240 @@ -59,12 +62,17 @@ void paging_init(void);
18241 /* Clear a kernel PTE and flush it from the TLB */
18242 #define kpte_clear_flush(ptep, vaddr) \
18243 do { \
18244 + pax_open_kernel(); \
18245 pte_clear(&init_mm, (vaddr), (ptep)); \
18246 + pax_close_kernel(); \
18247 __flush_tlb_one((vaddr)); \
18248 } while (0)
18249
18250 #endif /* !__ASSEMBLY__ */
18251
18252 +#define HAVE_ARCH_UNMAPPED_AREA
18253 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18254 +
18255 /*
18256 * kern_addr_valid() is (1) for FLATMEM and (0) for
18257 * SPARSEMEM and DISCONTIGMEM
18258 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18259 index ed5903b..c7fe163 100644
18260 --- a/arch/x86/include/asm/pgtable_32_types.h
18261 +++ b/arch/x86/include/asm/pgtable_32_types.h
18262 @@ -8,7 +8,7 @@
18263 */
18264 #ifdef CONFIG_X86_PAE
18265 # include <asm/pgtable-3level_types.h>
18266 -# define PMD_SIZE (1UL << PMD_SHIFT)
18267 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18268 # define PMD_MASK (~(PMD_SIZE - 1))
18269 #else
18270 # include <asm/pgtable-2level_types.h>
18271 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18272 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18273 #endif
18274
18275 +#ifdef CONFIG_PAX_KERNEXEC
18276 +#ifndef __ASSEMBLY__
18277 +extern unsigned char MODULES_EXEC_VADDR[];
18278 +extern unsigned char MODULES_EXEC_END[];
18279 +#endif
18280 +#include <asm/boot.h>
18281 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18282 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18283 +#else
18284 +#define ktla_ktva(addr) (addr)
18285 +#define ktva_ktla(addr) (addr)
18286 +#endif
18287 +
18288 #define MODULES_VADDR VMALLOC_START
18289 #define MODULES_END VMALLOC_END
18290 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18291 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18292 index 4572b2f..4430113 100644
18293 --- a/arch/x86/include/asm/pgtable_64.h
18294 +++ b/arch/x86/include/asm/pgtable_64.h
18295 @@ -16,11 +16,16 @@
18296
18297 extern pud_t level3_kernel_pgt[512];
18298 extern pud_t level3_ident_pgt[512];
18299 +extern pud_t level3_vmalloc_start_pgt[512];
18300 +extern pud_t level3_vmalloc_end_pgt[512];
18301 +extern pud_t level3_vmemmap_pgt[512];
18302 +extern pud_t level2_vmemmap_pgt[512];
18303 extern pmd_t level2_kernel_pgt[512];
18304 extern pmd_t level2_fixmap_pgt[512];
18305 -extern pmd_t level2_ident_pgt[512];
18306 +extern pmd_t level2_ident_pgt[512*2];
18307 extern pte_t level1_fixmap_pgt[512];
18308 -extern pgd_t init_level4_pgt[];
18309 +extern pte_t level1_vsyscall_pgt[512];
18310 +extern pgd_t init_level4_pgt[512];
18311
18312 #define swapper_pg_dir init_level4_pgt
18313
18314 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18315
18316 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18317 {
18318 + pax_open_kernel();
18319 *pmdp = pmd;
18320 + pax_close_kernel();
18321 }
18322
18323 static inline void native_pmd_clear(pmd_t *pmd)
18324 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18325
18326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18327 {
18328 + pax_open_kernel();
18329 *pudp = pud;
18330 + pax_close_kernel();
18331 }
18332
18333 static inline void native_pud_clear(pud_t *pud)
18334 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18335
18336 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18337 {
18338 + pax_open_kernel();
18339 + *pgdp = pgd;
18340 + pax_close_kernel();
18341 +}
18342 +
18343 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18344 +{
18345 *pgdp = pgd;
18346 }
18347
18348 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18349 index 7166e25..baaa6fe 100644
18350 --- a/arch/x86/include/asm/pgtable_64_types.h
18351 +++ b/arch/x86/include/asm/pgtable_64_types.h
18352 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18353 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18354 #define MODULES_END _AC(0xffffffffff000000, UL)
18355 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18356 +#define MODULES_EXEC_VADDR MODULES_VADDR
18357 +#define MODULES_EXEC_END MODULES_END
18358 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18359 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18360
18361 +#define ktla_ktva(addr) (addr)
18362 +#define ktva_ktla(addr) (addr)
18363 +
18364 #define EARLY_DYNAMIC_PAGE_TABLES 64
18365
18366 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18367 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18368 index 0778964..0e94758 100644
18369 --- a/arch/x86/include/asm/pgtable_types.h
18370 +++ b/arch/x86/include/asm/pgtable_types.h
18371 @@ -110,8 +110,10 @@
18372
18373 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18374 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18375 -#else
18376 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18377 #define _PAGE_NX (_AT(pteval_t, 0))
18378 +#else
18379 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18380 #endif
18381
18382 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18383 @@ -150,6 +152,9 @@
18384 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18385 _PAGE_ACCESSED)
18386
18387 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18388 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18389 +
18390 #define __PAGE_KERNEL_EXEC \
18391 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18392 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18393 @@ -160,7 +165,7 @@
18394 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18395 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18396 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18397 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18398 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18399 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18400 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18401 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18402 @@ -217,7 +222,7 @@
18403 #ifdef CONFIG_X86_64
18404 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18405 #else
18406 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18407 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18408 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18409 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18410 #endif
18411 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18412 {
18413 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18414 }
18415 +#endif
18416
18417 +#if PAGETABLE_LEVELS == 3
18418 +#include <asm-generic/pgtable-nopud.h>
18419 +#endif
18420 +
18421 +#if PAGETABLE_LEVELS == 2
18422 +#include <asm-generic/pgtable-nopmd.h>
18423 +#endif
18424 +
18425 +#ifndef __ASSEMBLY__
18426 #if PAGETABLE_LEVELS > 3
18427 typedef struct { pudval_t pud; } pud_t;
18428
18429 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18430 return pud.pud;
18431 }
18432 #else
18433 -#include <asm-generic/pgtable-nopud.h>
18434 -
18435 static inline pudval_t native_pud_val(pud_t pud)
18436 {
18437 return native_pgd_val(pud.pgd);
18438 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18439 return pmd.pmd;
18440 }
18441 #else
18442 -#include <asm-generic/pgtable-nopmd.h>
18443 -
18444 static inline pmdval_t native_pmd_val(pmd_t pmd)
18445 {
18446 return native_pgd_val(pmd.pud.pgd);
18447 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18448
18449 extern pteval_t __supported_pte_mask;
18450 extern void set_nx(void);
18451 -extern int nx_enabled;
18452
18453 #define pgprot_writecombine pgprot_writecombine
18454 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18455 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18456 index 4008734..48f0d81 100644
18457 --- a/arch/x86/include/asm/preempt.h
18458 +++ b/arch/x86/include/asm/preempt.h
18459 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18460 */
18461 static __always_inline bool __preempt_count_dec_and_test(void)
18462 {
18463 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18464 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18465 }
18466
18467 /*
18468 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18469 index eb71ec7..f06532a 100644
18470 --- a/arch/x86/include/asm/processor.h
18471 +++ b/arch/x86/include/asm/processor.h
18472 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18473 /* Index into per_cpu list: */
18474 u16 cpu_index;
18475 u32 microcode;
18476 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18477 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18478
18479 #define X86_VENDOR_INTEL 0
18480 #define X86_VENDOR_CYRIX 1
18481 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18482 : "memory");
18483 }
18484
18485 +/* invpcid (%rdx),%rax */
18486 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18487 +
18488 +#define INVPCID_SINGLE_ADDRESS 0UL
18489 +#define INVPCID_SINGLE_CONTEXT 1UL
18490 +#define INVPCID_ALL_GLOBAL 2UL
18491 +#define INVPCID_ALL_NONGLOBAL 3UL
18492 +
18493 +#define PCID_KERNEL 0UL
18494 +#define PCID_USER 1UL
18495 +#define PCID_NOFLUSH (1UL << 63)
18496 +
18497 static inline void load_cr3(pgd_t *pgdir)
18498 {
18499 - write_cr3(__pa(pgdir));
18500 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18501 }
18502
18503 #ifdef CONFIG_X86_32
18504 @@ -282,7 +294,7 @@ struct tss_struct {
18505
18506 } ____cacheline_aligned;
18507
18508 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18509 +extern struct tss_struct init_tss[NR_CPUS];
18510
18511 /*
18512 * Save the original ist values for checking stack pointers during debugging
18513 @@ -478,6 +490,7 @@ struct thread_struct {
18514 unsigned short ds;
18515 unsigned short fsindex;
18516 unsigned short gsindex;
18517 + unsigned short ss;
18518 #endif
18519 #ifdef CONFIG_X86_32
18520 unsigned long ip;
18521 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18522 extern unsigned long mmu_cr4_features;
18523 extern u32 *trampoline_cr4_features;
18524
18525 -static inline void set_in_cr4(unsigned long mask)
18526 -{
18527 - unsigned long cr4;
18528 -
18529 - mmu_cr4_features |= mask;
18530 - if (trampoline_cr4_features)
18531 - *trampoline_cr4_features = mmu_cr4_features;
18532 - cr4 = read_cr4();
18533 - cr4 |= mask;
18534 - write_cr4(cr4);
18535 -}
18536 -
18537 -static inline void clear_in_cr4(unsigned long mask)
18538 -{
18539 - unsigned long cr4;
18540 -
18541 - mmu_cr4_features &= ~mask;
18542 - if (trampoline_cr4_features)
18543 - *trampoline_cr4_features = mmu_cr4_features;
18544 - cr4 = read_cr4();
18545 - cr4 &= ~mask;
18546 - write_cr4(cr4);
18547 -}
18548 +extern void set_in_cr4(unsigned long mask);
18549 +extern void clear_in_cr4(unsigned long mask);
18550
18551 typedef struct {
18552 unsigned long seg;
18553 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18554 */
18555 #define TASK_SIZE PAGE_OFFSET
18556 #define TASK_SIZE_MAX TASK_SIZE
18557 +
18558 +#ifdef CONFIG_PAX_SEGMEXEC
18559 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18560 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18561 +#else
18562 #define STACK_TOP TASK_SIZE
18563 -#define STACK_TOP_MAX STACK_TOP
18564 +#endif
18565 +
18566 +#define STACK_TOP_MAX TASK_SIZE
18567
18568 #define INIT_THREAD { \
18569 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18570 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18571 .vm86_info = NULL, \
18572 .sysenter_cs = __KERNEL_CS, \
18573 .io_bitmap_ptr = NULL, \
18574 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18575 */
18576 #define INIT_TSS { \
18577 .x86_tss = { \
18578 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18579 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18580 .ss0 = __KERNEL_DS, \
18581 .ss1 = __KERNEL_CS, \
18582 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18583 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18584 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18585
18586 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18587 -#define KSTK_TOP(info) \
18588 -({ \
18589 - unsigned long *__ptr = (unsigned long *)(info); \
18590 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18591 -})
18592 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18593
18594 /*
18595 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18596 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18597 #define task_pt_regs(task) \
18598 ({ \
18599 struct pt_regs *__regs__; \
18600 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18601 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18602 __regs__ - 1; \
18603 })
18604
18605 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18606 /*
18607 * User space process size. 47bits minus one guard page.
18608 */
18609 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18610 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18611
18612 /* This decides where the kernel will search for a free chunk of vm
18613 * space during mmap's.
18614 */
18615 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18616 - 0xc0000000 : 0xFFFFe000)
18617 + 0xc0000000 : 0xFFFFf000)
18618
18619 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18620 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18621 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18622 #define STACK_TOP_MAX TASK_SIZE_MAX
18623
18624 #define INIT_THREAD { \
18625 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18626 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18627 }
18628
18629 #define INIT_TSS { \
18630 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18631 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18632 }
18633
18634 /*
18635 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18636 */
18637 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18638
18639 +#ifdef CONFIG_PAX_SEGMEXEC
18640 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18641 +#endif
18642 +
18643 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18644
18645 /* Get/set a process' ability to use the timestamp counter instruction */
18646 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18647 return 0;
18648 }
18649
18650 -extern unsigned long arch_align_stack(unsigned long sp);
18651 +#define arch_align_stack(x) ((x) & ~0xfUL)
18652 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18653
18654 void default_idle(void);
18655 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18656 #define xen_set_default_idle 0
18657 #endif
18658
18659 -void stop_this_cpu(void *dummy);
18660 +void stop_this_cpu(void *dummy) __noreturn;
18661 void df_debug(struct pt_regs *regs, long error_code);
18662 #endif /* _ASM_X86_PROCESSOR_H */
18663 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18664 index 86fc2bb..bd5049a 100644
18665 --- a/arch/x86/include/asm/ptrace.h
18666 +++ b/arch/x86/include/asm/ptrace.h
18667 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18668 }
18669
18670 /*
18671 - * user_mode_vm(regs) determines whether a register set came from user mode.
18672 + * user_mode(regs) determines whether a register set came from user mode.
18673 * This is true if V8086 mode was enabled OR if the register set was from
18674 * protected mode with RPL-3 CS value. This tricky test checks that with
18675 * one comparison. Many places in the kernel can bypass this full check
18676 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18677 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18678 + * be used.
18679 */
18680 -static inline int user_mode(struct pt_regs *regs)
18681 +static inline int user_mode_novm(struct pt_regs *regs)
18682 {
18683 #ifdef CONFIG_X86_32
18684 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18685 #else
18686 - return !!(regs->cs & 3);
18687 + return !!(regs->cs & SEGMENT_RPL_MASK);
18688 #endif
18689 }
18690
18691 -static inline int user_mode_vm(struct pt_regs *regs)
18692 +static inline int user_mode(struct pt_regs *regs)
18693 {
18694 #ifdef CONFIG_X86_32
18695 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18696 USER_RPL;
18697 #else
18698 - return user_mode(regs);
18699 + return user_mode_novm(regs);
18700 #endif
18701 }
18702
18703 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18704 #ifdef CONFIG_X86_64
18705 static inline bool user_64bit_mode(struct pt_regs *regs)
18706 {
18707 + unsigned long cs = regs->cs & 0xffff;
18708 #ifndef CONFIG_PARAVIRT
18709 /*
18710 * On non-paravirt systems, this is the only long mode CPL 3
18711 * selector. We do not allow long mode selectors in the LDT.
18712 */
18713 - return regs->cs == __USER_CS;
18714 + return cs == __USER_CS;
18715 #else
18716 /* Headers are too twisted for this to go in paravirt.h. */
18717 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18718 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18719 #endif
18720 }
18721
18722 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18723 * Traps from the kernel do not save sp and ss.
18724 * Use the helper function to retrieve sp.
18725 */
18726 - if (offset == offsetof(struct pt_regs, sp) &&
18727 - regs->cs == __KERNEL_CS)
18728 - return kernel_stack_pointer(regs);
18729 + if (offset == offsetof(struct pt_regs, sp)) {
18730 + unsigned long cs = regs->cs & 0xffff;
18731 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18732 + return kernel_stack_pointer(regs);
18733 + }
18734 #endif
18735 return *(unsigned long *)((unsigned long)regs + offset);
18736 }
18737 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18738 index ae0e241..e80b10b 100644
18739 --- a/arch/x86/include/asm/qrwlock.h
18740 +++ b/arch/x86/include/asm/qrwlock.h
18741 @@ -7,8 +7,8 @@
18742 #define queue_write_unlock queue_write_unlock
18743 static inline void queue_write_unlock(struct qrwlock *lock)
18744 {
18745 - barrier();
18746 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18747 + barrier();
18748 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18749 }
18750 #endif
18751
18752 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18753 index 9c6b890..5305f53 100644
18754 --- a/arch/x86/include/asm/realmode.h
18755 +++ b/arch/x86/include/asm/realmode.h
18756 @@ -22,16 +22,14 @@ struct real_mode_header {
18757 #endif
18758 /* APM/BIOS reboot */
18759 u32 machine_real_restart_asm;
18760 -#ifdef CONFIG_X86_64
18761 u32 machine_real_restart_seg;
18762 -#endif
18763 };
18764
18765 /* This must match data at trampoline_32/64.S */
18766 struct trampoline_header {
18767 #ifdef CONFIG_X86_32
18768 u32 start;
18769 - u16 gdt_pad;
18770 + u16 boot_cs;
18771 u16 gdt_limit;
18772 u32 gdt_base;
18773 #else
18774 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18775 index a82c4f1..ac45053 100644
18776 --- a/arch/x86/include/asm/reboot.h
18777 +++ b/arch/x86/include/asm/reboot.h
18778 @@ -6,13 +6,13 @@
18779 struct pt_regs;
18780
18781 struct machine_ops {
18782 - void (*restart)(char *cmd);
18783 - void (*halt)(void);
18784 - void (*power_off)(void);
18785 + void (* __noreturn restart)(char *cmd);
18786 + void (* __noreturn halt)(void);
18787 + void (* __noreturn power_off)(void);
18788 void (*shutdown)(void);
18789 void (*crash_shutdown)(struct pt_regs *);
18790 - void (*emergency_restart)(void);
18791 -};
18792 + void (* __noreturn emergency_restart)(void);
18793 +} __no_const;
18794
18795 extern struct machine_ops machine_ops;
18796
18797 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18798 index 8f7866a..e442f20 100644
18799 --- a/arch/x86/include/asm/rmwcc.h
18800 +++ b/arch/x86/include/asm/rmwcc.h
18801 @@ -3,7 +3,34 @@
18802
18803 #ifdef CC_HAVE_ASM_GOTO
18804
18805 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18806 +#ifdef CONFIG_PAX_REFCOUNT
18807 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18808 +do { \
18809 + asm_volatile_goto (fullop \
18810 + ";jno 0f\n" \
18811 + fullantiop \
18812 + ";int $4\n0:\n" \
18813 + _ASM_EXTABLE(0b, 0b) \
18814 + ";j" cc " %l[cc_label]" \
18815 + : : "m" (var), ## __VA_ARGS__ \
18816 + : "memory" : cc_label); \
18817 + return 0; \
18818 +cc_label: \
18819 + return 1; \
18820 +} while (0)
18821 +#else
18822 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18823 +do { \
18824 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18825 + : : "m" (var), ## __VA_ARGS__ \
18826 + : "memory" : cc_label); \
18827 + return 0; \
18828 +cc_label: \
18829 + return 1; \
18830 +} while (0)
18831 +#endif
18832 +
18833 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18834 do { \
18835 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18836 : : "m" (var), ## __VA_ARGS__ \
18837 @@ -13,15 +40,46 @@ cc_label: \
18838 return 1; \
18839 } while (0)
18840
18841 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18842 - __GEN_RMWcc(op " " arg0, var, cc)
18843 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18844 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18845
18846 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18847 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18848 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18849 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18850 +
18851 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18852 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18853 +
18854 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18855 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18856
18857 #else /* !CC_HAVE_ASM_GOTO */
18858
18859 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18860 +#ifdef CONFIG_PAX_REFCOUNT
18861 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18862 +do { \
18863 + char c; \
18864 + asm volatile (fullop \
18865 + ";jno 0f\n" \
18866 + fullantiop \
18867 + ";int $4\n0:\n" \
18868 + _ASM_EXTABLE(0b, 0b) \
18869 + "; set" cc " %1" \
18870 + : "+m" (var), "=qm" (c) \
18871 + : __VA_ARGS__ : "memory"); \
18872 + return c != 0; \
18873 +} while (0)
18874 +#else
18875 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18876 +do { \
18877 + char c; \
18878 + asm volatile (fullop "; set" cc " %1" \
18879 + : "+m" (var), "=qm" (c) \
18880 + : __VA_ARGS__ : "memory"); \
18881 + return c != 0; \
18882 +} while (0)
18883 +#endif
18884 +
18885 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18886 do { \
18887 char c; \
18888 asm volatile (fullop "; set" cc " %1" \
18889 @@ -30,11 +88,17 @@ do { \
18890 return c != 0; \
18891 } while (0)
18892
18893 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18894 - __GEN_RMWcc(op " " arg0, var, cc)
18895 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18896 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18897 +
18898 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18899 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18900 +
18901 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18902 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18903
18904 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18905 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18906 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18907 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18908
18909 #endif /* CC_HAVE_ASM_GOTO */
18910
18911 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18912 index cad82c9..2e5c5c1 100644
18913 --- a/arch/x86/include/asm/rwsem.h
18914 +++ b/arch/x86/include/asm/rwsem.h
18915 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18916 {
18917 asm volatile("# beginning down_read\n\t"
18918 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18919 +
18920 +#ifdef CONFIG_PAX_REFCOUNT
18921 + "jno 0f\n"
18922 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18923 + "int $4\n0:\n"
18924 + _ASM_EXTABLE(0b, 0b)
18925 +#endif
18926 +
18927 /* adds 0x00000001 */
18928 " jns 1f\n"
18929 " call call_rwsem_down_read_failed\n"
18930 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18931 "1:\n\t"
18932 " mov %1,%2\n\t"
18933 " add %3,%2\n\t"
18934 +
18935 +#ifdef CONFIG_PAX_REFCOUNT
18936 + "jno 0f\n"
18937 + "sub %3,%2\n"
18938 + "int $4\n0:\n"
18939 + _ASM_EXTABLE(0b, 0b)
18940 +#endif
18941 +
18942 " jle 2f\n\t"
18943 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18944 " jnz 1b\n\t"
18945 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18946 long tmp;
18947 asm volatile("# beginning down_write\n\t"
18948 LOCK_PREFIX " xadd %1,(%2)\n\t"
18949 +
18950 +#ifdef CONFIG_PAX_REFCOUNT
18951 + "jno 0f\n"
18952 + "mov %1,(%2)\n"
18953 + "int $4\n0:\n"
18954 + _ASM_EXTABLE(0b, 0b)
18955 +#endif
18956 +
18957 /* adds 0xffff0001, returns the old value */
18958 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18959 /* was the active mask 0 before? */
18960 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18961 long tmp;
18962 asm volatile("# beginning __up_read\n\t"
18963 LOCK_PREFIX " xadd %1,(%2)\n\t"
18964 +
18965 +#ifdef CONFIG_PAX_REFCOUNT
18966 + "jno 0f\n"
18967 + "mov %1,(%2)\n"
18968 + "int $4\n0:\n"
18969 + _ASM_EXTABLE(0b, 0b)
18970 +#endif
18971 +
18972 /* subtracts 1, returns the old value */
18973 " jns 1f\n\t"
18974 " call call_rwsem_wake\n" /* expects old value in %edx */
18975 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18976 long tmp;
18977 asm volatile("# beginning __up_write\n\t"
18978 LOCK_PREFIX " xadd %1,(%2)\n\t"
18979 +
18980 +#ifdef CONFIG_PAX_REFCOUNT
18981 + "jno 0f\n"
18982 + "mov %1,(%2)\n"
18983 + "int $4\n0:\n"
18984 + _ASM_EXTABLE(0b, 0b)
18985 +#endif
18986 +
18987 /* subtracts 0xffff0001, returns the old value */
18988 " jns 1f\n\t"
18989 " call call_rwsem_wake\n" /* expects old value in %edx */
18990 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18991 {
18992 asm volatile("# beginning __downgrade_write\n\t"
18993 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18994 +
18995 +#ifdef CONFIG_PAX_REFCOUNT
18996 + "jno 0f\n"
18997 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18998 + "int $4\n0:\n"
18999 + _ASM_EXTABLE(0b, 0b)
19000 +#endif
19001 +
19002 /*
19003 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19004 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19005 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19006 */
19007 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19008 {
19009 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19010 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19011 +
19012 +#ifdef CONFIG_PAX_REFCOUNT
19013 + "jno 0f\n"
19014 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19015 + "int $4\n0:\n"
19016 + _ASM_EXTABLE(0b, 0b)
19017 +#endif
19018 +
19019 : "+m" (sem->count)
19020 : "er" (delta));
19021 }
19022 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19023 */
19024 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19025 {
19026 - return delta + xadd(&sem->count, delta);
19027 + return delta + xadd_check_overflow(&sem->count, delta);
19028 }
19029
19030 #endif /* __KERNEL__ */
19031 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19032 index 6f1c3a8..7744f19 100644
19033 --- a/arch/x86/include/asm/segment.h
19034 +++ b/arch/x86/include/asm/segment.h
19035 @@ -64,10 +64,15 @@
19036 * 26 - ESPFIX small SS
19037 * 27 - per-cpu [ offset to per-cpu data area ]
19038 * 28 - stack_canary-20 [ for stack protector ]
19039 - * 29 - unused
19040 - * 30 - unused
19041 + * 29 - PCI BIOS CS
19042 + * 30 - PCI BIOS DS
19043 * 31 - TSS for double fault handler
19044 */
19045 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19046 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19047 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19048 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19049 +
19050 #define GDT_ENTRY_TLS_MIN 6
19051 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19052
19053 @@ -79,6 +84,8 @@
19054
19055 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19056
19057 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19058 +
19059 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19060
19061 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19062 @@ -104,6 +111,12 @@
19063 #define __KERNEL_STACK_CANARY 0
19064 #endif
19065
19066 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19067 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19068 +
19069 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19070 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19071 +
19072 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19073
19074 /*
19075 @@ -141,7 +154,7 @@
19076 */
19077
19078 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19079 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19080 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19081
19082
19083 #else
19084 @@ -165,6 +178,8 @@
19085 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19086 #define __USER32_DS __USER_DS
19087
19088 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19089 +
19090 #define GDT_ENTRY_TSS 8 /* needs two entries */
19091 #define GDT_ENTRY_LDT 10 /* needs two entries */
19092 #define GDT_ENTRY_TLS_MIN 12
19093 @@ -173,6 +188,8 @@
19094 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19095 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19096
19097 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19098 +
19099 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19100 #define FS_TLS 0
19101 #define GS_TLS 1
19102 @@ -180,12 +197,14 @@
19103 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19104 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19105
19106 -#define GDT_ENTRIES 16
19107 +#define GDT_ENTRIES 17
19108
19109 #endif
19110
19111 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19112 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19113 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19114 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19115 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19116 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19117 #ifndef CONFIG_PARAVIRT
19118 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19119 {
19120 unsigned long __limit;
19121 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19122 - return __limit + 1;
19123 + return __limit;
19124 }
19125
19126 #endif /* !__ASSEMBLY__ */
19127 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19128 index 8d3120f..352b440 100644
19129 --- a/arch/x86/include/asm/smap.h
19130 +++ b/arch/x86/include/asm/smap.h
19131 @@ -25,11 +25,40 @@
19132
19133 #include <asm/alternative-asm.h>
19134
19135 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19136 +#define ASM_PAX_OPEN_USERLAND \
19137 + 661: jmp 663f; \
19138 + .pushsection .altinstr_replacement, "a" ; \
19139 + 662: pushq %rax; nop; \
19140 + .popsection ; \
19141 + .pushsection .altinstructions, "a" ; \
19142 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19143 + .popsection ; \
19144 + call __pax_open_userland; \
19145 + popq %rax; \
19146 + 663:
19147 +
19148 +#define ASM_PAX_CLOSE_USERLAND \
19149 + 661: jmp 663f; \
19150 + .pushsection .altinstr_replacement, "a" ; \
19151 + 662: pushq %rax; nop; \
19152 + .popsection; \
19153 + .pushsection .altinstructions, "a" ; \
19154 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19155 + .popsection; \
19156 + call __pax_close_userland; \
19157 + popq %rax; \
19158 + 663:
19159 +#else
19160 +#define ASM_PAX_OPEN_USERLAND
19161 +#define ASM_PAX_CLOSE_USERLAND
19162 +#endif
19163 +
19164 #ifdef CONFIG_X86_SMAP
19165
19166 #define ASM_CLAC \
19167 661: ASM_NOP3 ; \
19168 - .pushsection .altinstr_replacement, "ax" ; \
19169 + .pushsection .altinstr_replacement, "a" ; \
19170 662: __ASM_CLAC ; \
19171 .popsection ; \
19172 .pushsection .altinstructions, "a" ; \
19173 @@ -38,7 +67,7 @@
19174
19175 #define ASM_STAC \
19176 661: ASM_NOP3 ; \
19177 - .pushsection .altinstr_replacement, "ax" ; \
19178 + .pushsection .altinstr_replacement, "a" ; \
19179 662: __ASM_STAC ; \
19180 .popsection ; \
19181 .pushsection .altinstructions, "a" ; \
19182 @@ -56,6 +85,37 @@
19183
19184 #include <asm/alternative.h>
19185
19186 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19187 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19188 +
19189 +extern void __pax_open_userland(void);
19190 +static __always_inline unsigned long pax_open_userland(void)
19191 +{
19192 +
19193 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19194 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19195 + :
19196 + : [open] "i" (__pax_open_userland)
19197 + : "memory", "rax");
19198 +#endif
19199 +
19200 + return 0;
19201 +}
19202 +
19203 +extern void __pax_close_userland(void);
19204 +static __always_inline unsigned long pax_close_userland(void)
19205 +{
19206 +
19207 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19208 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19209 + :
19210 + : [close] "i" (__pax_close_userland)
19211 + : "memory", "rax");
19212 +#endif
19213 +
19214 + return 0;
19215 +}
19216 +
19217 #ifdef CONFIG_X86_SMAP
19218
19219 static __always_inline void clac(void)
19220 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19221 index 8cd1cc3..827e09e 100644
19222 --- a/arch/x86/include/asm/smp.h
19223 +++ b/arch/x86/include/asm/smp.h
19224 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19225 /* cpus sharing the last level cache: */
19226 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19227 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19228 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19229 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19230
19231 static inline struct cpumask *cpu_sibling_mask(int cpu)
19232 {
19233 @@ -78,7 +78,7 @@ struct smp_ops {
19234
19235 void (*send_call_func_ipi)(const struct cpumask *mask);
19236 void (*send_call_func_single_ipi)(int cpu);
19237 -};
19238 +} __no_const;
19239
19240 /* Globals due to paravirt */
19241 extern void set_cpu_sibling_map(int cpu);
19242 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19243 extern int safe_smp_processor_id(void);
19244
19245 #elif defined(CONFIG_X86_64_SMP)
19246 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19247 -
19248 -#define stack_smp_processor_id() \
19249 -({ \
19250 - struct thread_info *ti; \
19251 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19252 - ti->cpu; \
19253 -})
19254 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19255 +#define stack_smp_processor_id() raw_smp_processor_id()
19256 #define safe_smp_processor_id() smp_processor_id()
19257
19258 #endif
19259 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19260 index 6a99859..03cb807 100644
19261 --- a/arch/x86/include/asm/stackprotector.h
19262 +++ b/arch/x86/include/asm/stackprotector.h
19263 @@ -47,7 +47,7 @@
19264 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19265 */
19266 #define GDT_STACK_CANARY_INIT \
19267 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19268 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19269
19270 /*
19271 * Initialize the stackprotector canary value.
19272 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19273
19274 static inline void load_stack_canary_segment(void)
19275 {
19276 -#ifdef CONFIG_X86_32
19277 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19278 asm volatile ("mov %0, %%gs" : : "r" (0));
19279 #endif
19280 }
19281 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19282 index 70bbe39..4ae2bd4 100644
19283 --- a/arch/x86/include/asm/stacktrace.h
19284 +++ b/arch/x86/include/asm/stacktrace.h
19285 @@ -11,28 +11,20 @@
19286
19287 extern int kstack_depth_to_print;
19288
19289 -struct thread_info;
19290 +struct task_struct;
19291 struct stacktrace_ops;
19292
19293 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19294 - unsigned long *stack,
19295 - unsigned long bp,
19296 - const struct stacktrace_ops *ops,
19297 - void *data,
19298 - unsigned long *end,
19299 - int *graph);
19300 +typedef unsigned long walk_stack_t(struct task_struct *task,
19301 + void *stack_start,
19302 + unsigned long *stack,
19303 + unsigned long bp,
19304 + const struct stacktrace_ops *ops,
19305 + void *data,
19306 + unsigned long *end,
19307 + int *graph);
19308
19309 -extern unsigned long
19310 -print_context_stack(struct thread_info *tinfo,
19311 - unsigned long *stack, unsigned long bp,
19312 - const struct stacktrace_ops *ops, void *data,
19313 - unsigned long *end, int *graph);
19314 -
19315 -extern unsigned long
19316 -print_context_stack_bp(struct thread_info *tinfo,
19317 - unsigned long *stack, unsigned long bp,
19318 - const struct stacktrace_ops *ops, void *data,
19319 - unsigned long *end, int *graph);
19320 +extern walk_stack_t print_context_stack;
19321 +extern walk_stack_t print_context_stack_bp;
19322
19323 /* Generic stack tracer with callbacks */
19324
19325 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19326 void (*address)(void *data, unsigned long address, int reliable);
19327 /* On negative return stop dumping */
19328 int (*stack)(void *data, char *name);
19329 - walk_stack_t walk_stack;
19330 + walk_stack_t *walk_stack;
19331 };
19332
19333 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19334 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19335 index d7f3b3b..3cc39f1 100644
19336 --- a/arch/x86/include/asm/switch_to.h
19337 +++ b/arch/x86/include/asm/switch_to.h
19338 @@ -108,7 +108,7 @@ do { \
19339 "call __switch_to\n\t" \
19340 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19341 __switch_canary \
19342 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19343 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19344 "movq %%rax,%%rdi\n\t" \
19345 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19346 "jnz ret_from_fork\n\t" \
19347 @@ -119,7 +119,7 @@ do { \
19348 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19349 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19350 [_tif_fork] "i" (_TIF_FORK), \
19351 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19352 + [thread_info] "m" (current_tinfo), \
19353 [current_task] "m" (current_task) \
19354 __switch_canary_iparam \
19355 : "memory", "cc" __EXTRA_CLOBBER)
19356 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19357 index 547e344..6be1175 100644
19358 --- a/arch/x86/include/asm/thread_info.h
19359 +++ b/arch/x86/include/asm/thread_info.h
19360 @@ -24,7 +24,6 @@ struct exec_domain;
19361 #include <linux/atomic.h>
19362
19363 struct thread_info {
19364 - struct task_struct *task; /* main task structure */
19365 struct exec_domain *exec_domain; /* execution domain */
19366 __u32 flags; /* low level flags */
19367 __u32 status; /* thread synchronous flags */
19368 @@ -33,13 +32,13 @@ struct thread_info {
19369 mm_segment_t addr_limit;
19370 struct restart_block restart_block;
19371 void __user *sysenter_return;
19372 + unsigned long lowest_stack;
19373 unsigned int sig_on_uaccess_error:1;
19374 unsigned int uaccess_err:1; /* uaccess failed */
19375 };
19376
19377 -#define INIT_THREAD_INFO(tsk) \
19378 +#define INIT_THREAD_INFO \
19379 { \
19380 - .task = &tsk, \
19381 .exec_domain = &default_exec_domain, \
19382 .flags = 0, \
19383 .cpu = 0, \
19384 @@ -50,7 +49,7 @@ struct thread_info {
19385 }, \
19386 }
19387
19388 -#define init_thread_info (init_thread_union.thread_info)
19389 +#define init_thread_info (init_thread_union.stack)
19390 #define init_stack (init_thread_union.stack)
19391
19392 #else /* !__ASSEMBLY__ */
19393 @@ -91,6 +90,7 @@ struct thread_info {
19394 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19395 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19396 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19397 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19398
19399 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19400 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19401 @@ -115,17 +115,18 @@ struct thread_info {
19402 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19403 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19404 #define _TIF_X32 (1 << TIF_X32)
19405 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19406
19407 /* work to do in syscall_trace_enter() */
19408 #define _TIF_WORK_SYSCALL_ENTRY \
19409 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19410 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19411 - _TIF_NOHZ)
19412 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19413
19414 /* work to do in syscall_trace_leave() */
19415 #define _TIF_WORK_SYSCALL_EXIT \
19416 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19417 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19418 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19419
19420 /* work to do on interrupt/exception return */
19421 #define _TIF_WORK_MASK \
19422 @@ -136,7 +137,7 @@ struct thread_info {
19423 /* work to do on any return to user space */
19424 #define _TIF_ALLWORK_MASK \
19425 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19426 - _TIF_NOHZ)
19427 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19428
19429 /* Only used for 64 bit */
19430 #define _TIF_DO_NOTIFY_MASK \
19431 @@ -151,7 +152,6 @@ struct thread_info {
19432 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19433
19434 #define STACK_WARN (THREAD_SIZE/8)
19435 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19436
19437 /*
19438 * macros/functions for gaining access to the thread information structure
19439 @@ -162,26 +162,18 @@ struct thread_info {
19440
19441 DECLARE_PER_CPU(unsigned long, kernel_stack);
19442
19443 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19444 +
19445 static inline struct thread_info *current_thread_info(void)
19446 {
19447 - struct thread_info *ti;
19448 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19449 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19450 - return ti;
19451 + return this_cpu_read_stable(current_tinfo);
19452 }
19453
19454 #else /* !__ASSEMBLY__ */
19455
19456 /* how to get the thread information struct from ASM */
19457 #define GET_THREAD_INFO(reg) \
19458 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19459 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19460 -
19461 -/*
19462 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19463 - * a certain register (to be used in assembler memory operands).
19464 - */
19465 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19466 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19467
19468 #endif
19469
19470 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19471 extern void arch_task_cache_init(void);
19472 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19473 extern void arch_release_task_struct(struct task_struct *tsk);
19474 +
19475 +#define __HAVE_THREAD_FUNCTIONS
19476 +#define task_thread_info(task) (&(task)->tinfo)
19477 +#define task_stack_page(task) ((task)->stack)
19478 +#define setup_thread_stack(p, org) do {} while (0)
19479 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19480 +
19481 #endif
19482 #endif /* _ASM_X86_THREAD_INFO_H */
19483 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19484 index 04905bf..1178cdf 100644
19485 --- a/arch/x86/include/asm/tlbflush.h
19486 +++ b/arch/x86/include/asm/tlbflush.h
19487 @@ -17,18 +17,44 @@
19488
19489 static inline void __native_flush_tlb(void)
19490 {
19491 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19492 + u64 descriptor[2];
19493 +
19494 + descriptor[0] = PCID_KERNEL;
19495 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19496 + return;
19497 + }
19498 +
19499 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19500 + if (static_cpu_has(X86_FEATURE_PCID)) {
19501 + unsigned int cpu = raw_get_cpu();
19502 +
19503 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19504 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19505 + raw_put_cpu_no_resched();
19506 + return;
19507 + }
19508 +#endif
19509 +
19510 native_write_cr3(native_read_cr3());
19511 }
19512
19513 static inline void __native_flush_tlb_global_irq_disabled(void)
19514 {
19515 - unsigned long cr4;
19516 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19517 + u64 descriptor[2];
19518
19519 - cr4 = native_read_cr4();
19520 - /* clear PGE */
19521 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19522 - /* write old PGE again and flush TLBs */
19523 - native_write_cr4(cr4);
19524 + descriptor[0] = PCID_KERNEL;
19525 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19526 + } else {
19527 + unsigned long cr4;
19528 +
19529 + cr4 = native_read_cr4();
19530 + /* clear PGE */
19531 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19532 + /* write old PGE again and flush TLBs */
19533 + native_write_cr4(cr4);
19534 + }
19535 }
19536
19537 static inline void __native_flush_tlb_global(void)
19538 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19539
19540 static inline void __native_flush_tlb_single(unsigned long addr)
19541 {
19542 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19543 + u64 descriptor[2];
19544 +
19545 + descriptor[0] = PCID_KERNEL;
19546 + descriptor[1] = addr;
19547 +
19548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19549 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19550 + if (addr < TASK_SIZE_MAX)
19551 + descriptor[1] += pax_user_shadow_base;
19552 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19553 + }
19554 +
19555 + descriptor[0] = PCID_USER;
19556 + descriptor[1] = addr;
19557 +#endif
19558 +
19559 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19560 + return;
19561 + }
19562 +
19563 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19564 + if (static_cpu_has(X86_FEATURE_PCID)) {
19565 + unsigned int cpu = raw_get_cpu();
19566 +
19567 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19568 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19569 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19570 + raw_put_cpu_no_resched();
19571 +
19572 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19573 + addr += pax_user_shadow_base;
19574 + }
19575 +#endif
19576 +
19577 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19578 }
19579
19580 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19581 index 0d592e0..526f797 100644
19582 --- a/arch/x86/include/asm/uaccess.h
19583 +++ b/arch/x86/include/asm/uaccess.h
19584 @@ -7,6 +7,7 @@
19585 #include <linux/compiler.h>
19586 #include <linux/thread_info.h>
19587 #include <linux/string.h>
19588 +#include <linux/spinlock.h>
19589 #include <asm/asm.h>
19590 #include <asm/page.h>
19591 #include <asm/smap.h>
19592 @@ -29,7 +30,12 @@
19593
19594 #define get_ds() (KERNEL_DS)
19595 #define get_fs() (current_thread_info()->addr_limit)
19596 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19597 +void __set_fs(mm_segment_t x);
19598 +void set_fs(mm_segment_t x);
19599 +#else
19600 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19601 +#endif
19602
19603 #define segment_eq(a, b) ((a).seg == (b).seg)
19604
19605 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19606 * checks that the pointer is in the user space range - after calling
19607 * this function, memory access functions may still return -EFAULT.
19608 */
19609 -#define access_ok(type, addr, size) \
19610 - likely(!__range_not_ok(addr, size, user_addr_max()))
19611 +extern int _cond_resched(void);
19612 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19613 +#define access_ok(type, addr, size) \
19614 +({ \
19615 + unsigned long __size = size; \
19616 + unsigned long __addr = (unsigned long)addr; \
19617 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19618 + if (__ret_ao && __size) { \
19619 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19620 + unsigned long __end_ao = __addr + __size - 1; \
19621 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19622 + while (__addr_ao <= __end_ao) { \
19623 + char __c_ao; \
19624 + __addr_ao += PAGE_SIZE; \
19625 + if (__size > PAGE_SIZE) \
19626 + _cond_resched(); \
19627 + if (__get_user(__c_ao, (char __user *)__addr)) \
19628 + break; \
19629 + if (type != VERIFY_WRITE) { \
19630 + __addr = __addr_ao; \
19631 + continue; \
19632 + } \
19633 + if (__put_user(__c_ao, (char __user *)__addr)) \
19634 + break; \
19635 + __addr = __addr_ao; \
19636 + } \
19637 + } \
19638 + } \
19639 + __ret_ao; \
19640 +})
19641
19642 /*
19643 * The exception table consists of pairs of addresses relative to the
19644 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19645 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19646 __chk_user_ptr(ptr); \
19647 might_fault(); \
19648 + pax_open_userland(); \
19649 asm volatile("call __get_user_%P3" \
19650 : "=a" (__ret_gu), "=r" (__val_gu) \
19651 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19652 (x) = (__typeof__(*(ptr))) __val_gu; \
19653 + pax_close_userland(); \
19654 __ret_gu; \
19655 })
19656
19657 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19658 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19659 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19660
19661 -
19662 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19663 +#define __copyuser_seg "gs;"
19664 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19665 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19666 +#else
19667 +#define __copyuser_seg
19668 +#define __COPYUSER_SET_ES
19669 +#define __COPYUSER_RESTORE_ES
19670 +#endif
19671
19672 #ifdef CONFIG_X86_32
19673 #define __put_user_asm_u64(x, addr, err, errret) \
19674 asm volatile(ASM_STAC "\n" \
19675 - "1: movl %%eax,0(%2)\n" \
19676 - "2: movl %%edx,4(%2)\n" \
19677 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19678 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19679 "3: " ASM_CLAC "\n" \
19680 ".section .fixup,\"ax\"\n" \
19681 "4: movl %3,%0\n" \
19682 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19683
19684 #define __put_user_asm_ex_u64(x, addr) \
19685 asm volatile(ASM_STAC "\n" \
19686 - "1: movl %%eax,0(%1)\n" \
19687 - "2: movl %%edx,4(%1)\n" \
19688 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19689 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19690 "3: " ASM_CLAC "\n" \
19691 _ASM_EXTABLE_EX(1b, 2b) \
19692 _ASM_EXTABLE_EX(2b, 3b) \
19693 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19694 __typeof__(*(ptr)) __pu_val; \
19695 __chk_user_ptr(ptr); \
19696 might_fault(); \
19697 - __pu_val = x; \
19698 + __pu_val = (x); \
19699 + pax_open_userland(); \
19700 switch (sizeof(*(ptr))) { \
19701 case 1: \
19702 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19703 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19704 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19705 break; \
19706 } \
19707 + pax_close_userland(); \
19708 __ret_pu; \
19709 })
19710
19711 @@ -355,8 +401,10 @@ do { \
19712 } while (0)
19713
19714 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19715 +do { \
19716 + pax_open_userland(); \
19717 asm volatile(ASM_STAC "\n" \
19718 - "1: mov"itype" %2,%"rtype"1\n" \
19719 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19720 "2: " ASM_CLAC "\n" \
19721 ".section .fixup,\"ax\"\n" \
19722 "3: mov %3,%0\n" \
19723 @@ -364,8 +412,10 @@ do { \
19724 " jmp 2b\n" \
19725 ".previous\n" \
19726 _ASM_EXTABLE(1b, 3b) \
19727 - : "=r" (err), ltype(x) \
19728 - : "m" (__m(addr)), "i" (errret), "0" (err))
19729 + : "=r" (err), ltype (x) \
19730 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19731 + pax_close_userland(); \
19732 +} while (0)
19733
19734 #define __get_user_size_ex(x, ptr, size) \
19735 do { \
19736 @@ -389,7 +439,7 @@ do { \
19737 } while (0)
19738
19739 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19740 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19741 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19742 "2:\n" \
19743 _ASM_EXTABLE_EX(1b, 2b) \
19744 : ltype(x) : "m" (__m(addr)))
19745 @@ -406,13 +456,24 @@ do { \
19746 int __gu_err; \
19747 unsigned long __gu_val; \
19748 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19749 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19750 + (x) = (__typeof__(*(ptr)))__gu_val; \
19751 __gu_err; \
19752 })
19753
19754 /* FIXME: this hack is definitely wrong -AK */
19755 struct __large_struct { unsigned long buf[100]; };
19756 -#define __m(x) (*(struct __large_struct __user *)(x))
19757 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19758 +#define ____m(x) \
19759 +({ \
19760 + unsigned long ____x = (unsigned long)(x); \
19761 + if (____x < pax_user_shadow_base) \
19762 + ____x += pax_user_shadow_base; \
19763 + (typeof(x))____x; \
19764 +})
19765 +#else
19766 +#define ____m(x) (x)
19767 +#endif
19768 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19769
19770 /*
19771 * Tell gcc we read from memory instead of writing: this is because
19772 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19773 * aliasing issues.
19774 */
19775 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19776 +do { \
19777 + pax_open_userland(); \
19778 asm volatile(ASM_STAC "\n" \
19779 - "1: mov"itype" %"rtype"1,%2\n" \
19780 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19781 "2: " ASM_CLAC "\n" \
19782 ".section .fixup,\"ax\"\n" \
19783 "3: mov %3,%0\n" \
19784 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19785 ".previous\n" \
19786 _ASM_EXTABLE(1b, 3b) \
19787 : "=r"(err) \
19788 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19789 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19790 + pax_close_userland(); \
19791 +} while (0)
19792
19793 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19794 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19795 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19796 "2:\n" \
19797 _ASM_EXTABLE_EX(1b, 2b) \
19798 : : ltype(x), "m" (__m(addr)))
19799 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19800 */
19801 #define uaccess_try do { \
19802 current_thread_info()->uaccess_err = 0; \
19803 + pax_open_userland(); \
19804 stac(); \
19805 barrier();
19806
19807 #define uaccess_catch(err) \
19808 clac(); \
19809 + pax_close_userland(); \
19810 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19811 } while (0)
19812
19813 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19814 * On error, the variable @x is set to zero.
19815 */
19816
19817 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19818 +#define __get_user(x, ptr) get_user((x), (ptr))
19819 +#else
19820 #define __get_user(x, ptr) \
19821 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19822 +#endif
19823
19824 /**
19825 * __put_user: - Write a simple value into user space, with less checking.
19826 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19827 * Returns zero on success, or -EFAULT on error.
19828 */
19829
19830 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19831 +#define __put_user(x, ptr) put_user((x), (ptr))
19832 +#else
19833 #define __put_user(x, ptr) \
19834 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19835 +#endif
19836
19837 #define __get_user_unaligned __get_user
19838 #define __put_user_unaligned __put_user
19839 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19840 #define get_user_ex(x, ptr) do { \
19841 unsigned long __gue_val; \
19842 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19843 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19844 + (x) = (__typeof__(*(ptr)))__gue_val; \
19845 } while (0)
19846
19847 #define put_user_try uaccess_try
19848 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19849 __typeof__(ptr) __uval = (uval); \
19850 __typeof__(*(ptr)) __old = (old); \
19851 __typeof__(*(ptr)) __new = (new); \
19852 + pax_open_userland(); \
19853 switch (size) { \
19854 case 1: \
19855 { \
19856 asm volatile("\t" ASM_STAC "\n" \
19857 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19858 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19859 "2:\t" ASM_CLAC "\n" \
19860 "\t.section .fixup, \"ax\"\n" \
19861 "3:\tmov %3, %0\n" \
19862 "\tjmp 2b\n" \
19863 "\t.previous\n" \
19864 _ASM_EXTABLE(1b, 3b) \
19865 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19866 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19867 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19868 : "memory" \
19869 ); \
19870 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19871 case 2: \
19872 { \
19873 asm volatile("\t" ASM_STAC "\n" \
19874 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19875 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19876 "2:\t" ASM_CLAC "\n" \
19877 "\t.section .fixup, \"ax\"\n" \
19878 "3:\tmov %3, %0\n" \
19879 "\tjmp 2b\n" \
19880 "\t.previous\n" \
19881 _ASM_EXTABLE(1b, 3b) \
19882 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19883 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19884 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19885 : "memory" \
19886 ); \
19887 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19888 case 4: \
19889 { \
19890 asm volatile("\t" ASM_STAC "\n" \
19891 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19892 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19893 "2:\t" ASM_CLAC "\n" \
19894 "\t.section .fixup, \"ax\"\n" \
19895 "3:\tmov %3, %0\n" \
19896 "\tjmp 2b\n" \
19897 "\t.previous\n" \
19898 _ASM_EXTABLE(1b, 3b) \
19899 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19900 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19901 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19902 : "memory" \
19903 ); \
19904 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19905 __cmpxchg_wrong_size(); \
19906 \
19907 asm volatile("\t" ASM_STAC "\n" \
19908 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19909 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19910 "2:\t" ASM_CLAC "\n" \
19911 "\t.section .fixup, \"ax\"\n" \
19912 "3:\tmov %3, %0\n" \
19913 "\tjmp 2b\n" \
19914 "\t.previous\n" \
19915 _ASM_EXTABLE(1b, 3b) \
19916 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19917 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19918 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19919 : "memory" \
19920 ); \
19921 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19922 default: \
19923 __cmpxchg_wrong_size(); \
19924 } \
19925 + pax_close_userland(); \
19926 *__uval = __old; \
19927 __ret; \
19928 })
19929 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19930
19931 #define ARCH_HAS_NOCACHE_UACCESS 1
19932
19933 -#ifdef CONFIG_X86_32
19934 -# include <asm/uaccess_32.h>
19935 -#else
19936 -# include <asm/uaccess_64.h>
19937 -#endif
19938 -
19939 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19940 - unsigned n);
19941 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19942 - unsigned n);
19943 -
19944 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19945 # define copy_user_diag __compiletime_error
19946 #else
19947 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19948 extern void copy_user_diag("copy_from_user() buffer size is too small")
19949 copy_from_user_overflow(void);
19950 extern void copy_user_diag("copy_to_user() buffer size is too small")
19951 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19952 +copy_to_user_overflow(void);
19953
19954 #undef copy_user_diag
19955
19956 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19957
19958 extern void
19959 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19960 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19961 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19962 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19963
19964 #else
19965 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19966
19967 #endif
19968
19969 +#ifdef CONFIG_X86_32
19970 +# include <asm/uaccess_32.h>
19971 +#else
19972 +# include <asm/uaccess_64.h>
19973 +#endif
19974 +
19975 static inline unsigned long __must_check
19976 copy_from_user(void *to, const void __user *from, unsigned long n)
19977 {
19978 - int sz = __compiletime_object_size(to);
19979 + size_t sz = __compiletime_object_size(to);
19980
19981 might_fault();
19982
19983 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19984 * case, and do only runtime checking for non-constant sizes.
19985 */
19986
19987 - if (likely(sz < 0 || sz >= n))
19988 - n = _copy_from_user(to, from, n);
19989 - else if(__builtin_constant_p(n))
19990 - copy_from_user_overflow();
19991 - else
19992 - __copy_from_user_overflow(sz, n);
19993 + if (likely(sz != (size_t)-1 && sz < n)) {
19994 + if(__builtin_constant_p(n))
19995 + copy_from_user_overflow();
19996 + else
19997 + __copy_from_user_overflow(sz, n);
19998 + } else if (access_ok(VERIFY_READ, from, n))
19999 + n = __copy_from_user(to, from, n);
20000 + else if ((long)n > 0)
20001 + memset(to, 0, n);
20002
20003 return n;
20004 }
20005 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 static inline unsigned long __must_check
20007 copy_to_user(void __user *to, const void *from, unsigned long n)
20008 {
20009 - int sz = __compiletime_object_size(from);
20010 + size_t sz = __compiletime_object_size(from);
20011
20012 might_fault();
20013
20014 /* See the comment in copy_from_user() above. */
20015 - if (likely(sz < 0 || sz >= n))
20016 - n = _copy_to_user(to, from, n);
20017 - else if(__builtin_constant_p(n))
20018 - copy_to_user_overflow();
20019 - else
20020 - __copy_to_user_overflow(sz, n);
20021 + if (likely(sz != (size_t)-1 && sz < n)) {
20022 + if(__builtin_constant_p(n))
20023 + copy_to_user_overflow();
20024 + else
20025 + __copy_to_user_overflow(sz, n);
20026 + } else if (access_ok(VERIFY_WRITE, to, n))
20027 + n = __copy_to_user(to, from, n);
20028
20029 return n;
20030 }
20031 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20032 index 3c03a5d..1071638 100644
20033 --- a/arch/x86/include/asm/uaccess_32.h
20034 +++ b/arch/x86/include/asm/uaccess_32.h
20035 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20036 static __always_inline unsigned long __must_check
20037 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20038 {
20039 + if ((long)n < 0)
20040 + return n;
20041 +
20042 + check_object_size(from, n, true);
20043 +
20044 if (__builtin_constant_p(n)) {
20045 unsigned long ret;
20046
20047 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20048 __copy_to_user(void __user *to, const void *from, unsigned long n)
20049 {
20050 might_fault();
20051 +
20052 return __copy_to_user_inatomic(to, from, n);
20053 }
20054
20055 static __always_inline unsigned long
20056 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20057 {
20058 + if ((long)n < 0)
20059 + return n;
20060 +
20061 /* Avoid zeroing the tail if the copy fails..
20062 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20063 * but as the zeroing behaviour is only significant when n is not
20064 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20065 __copy_from_user(void *to, const void __user *from, unsigned long n)
20066 {
20067 might_fault();
20068 +
20069 + if ((long)n < 0)
20070 + return n;
20071 +
20072 + check_object_size(to, n, false);
20073 +
20074 if (__builtin_constant_p(n)) {
20075 unsigned long ret;
20076
20077 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20078 const void __user *from, unsigned long n)
20079 {
20080 might_fault();
20081 +
20082 + if ((long)n < 0)
20083 + return n;
20084 +
20085 if (__builtin_constant_p(n)) {
20086 unsigned long ret;
20087
20088 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20089 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20090 unsigned long n)
20091 {
20092 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20093 + if ((long)n < 0)
20094 + return n;
20095 +
20096 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20097 }
20098
20099 #endif /* _ASM_X86_UACCESS_32_H */
20100 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20101 index 12a26b9..206c200 100644
20102 --- a/arch/x86/include/asm/uaccess_64.h
20103 +++ b/arch/x86/include/asm/uaccess_64.h
20104 @@ -10,6 +10,9 @@
20105 #include <asm/alternative.h>
20106 #include <asm/cpufeature.h>
20107 #include <asm/page.h>
20108 +#include <asm/pgtable.h>
20109 +
20110 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20111
20112 /*
20113 * Copy To/From Userspace
20114 @@ -17,14 +20,14 @@
20115
20116 /* Handles exceptions in both to and from, but doesn't do access_ok */
20117 __must_check unsigned long
20118 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20119 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20120 __must_check unsigned long
20121 -copy_user_generic_string(void *to, const void *from, unsigned len);
20122 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20123 __must_check unsigned long
20124 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20125 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20126
20127 static __always_inline __must_check unsigned long
20128 -copy_user_generic(void *to, const void *from, unsigned len)
20129 +copy_user_generic(void *to, const void *from, unsigned long len)
20130 {
20131 unsigned ret;
20132
20133 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20134 }
20135
20136 __must_check unsigned long
20137 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20138 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20139
20140 static __always_inline __must_check
20141 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20142 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20143 {
20144 - int ret = 0;
20145 + size_t sz = __compiletime_object_size(dst);
20146 + unsigned ret = 0;
20147 +
20148 + if (size > INT_MAX)
20149 + return size;
20150 +
20151 + check_object_size(dst, size, false);
20152 +
20153 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20154 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20155 + return size;
20156 +#endif
20157 +
20158 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20159 + if(__builtin_constant_p(size))
20160 + copy_from_user_overflow();
20161 + else
20162 + __copy_from_user_overflow(sz, size);
20163 + return size;
20164 + }
20165
20166 if (!__builtin_constant_p(size))
20167 - return copy_user_generic(dst, (__force void *)src, size);
20168 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20169 switch (size) {
20170 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20171 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20172 ret, "b", "b", "=q", 1);
20173 return ret;
20174 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20175 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20176 ret, "w", "w", "=r", 2);
20177 return ret;
20178 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20179 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20180 ret, "l", "k", "=r", 4);
20181 return ret;
20182 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20183 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20184 ret, "q", "", "=r", 8);
20185 return ret;
20186 case 10:
20187 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20188 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20189 ret, "q", "", "=r", 10);
20190 if (unlikely(ret))
20191 return ret;
20192 __get_user_asm(*(u16 *)(8 + (char *)dst),
20193 - (u16 __user *)(8 + (char __user *)src),
20194 + (const u16 __user *)(8 + (const char __user *)src),
20195 ret, "w", "w", "=r", 2);
20196 return ret;
20197 case 16:
20198 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20199 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20200 ret, "q", "", "=r", 16);
20201 if (unlikely(ret))
20202 return ret;
20203 __get_user_asm(*(u64 *)(8 + (char *)dst),
20204 - (u64 __user *)(8 + (char __user *)src),
20205 + (const u64 __user *)(8 + (const char __user *)src),
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 default:
20209 - return copy_user_generic(dst, (__force void *)src, size);
20210 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20211 }
20212 }
20213
20214 static __always_inline __must_check
20215 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20216 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20217 {
20218 might_fault();
20219 return __copy_from_user_nocheck(dst, src, size);
20220 }
20221
20222 static __always_inline __must_check
20223 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20224 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20225 {
20226 - int ret = 0;
20227 + size_t sz = __compiletime_object_size(src);
20228 + unsigned ret = 0;
20229 +
20230 + if (size > INT_MAX)
20231 + return size;
20232 +
20233 + check_object_size(src, size, true);
20234 +
20235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20236 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20237 + return size;
20238 +#endif
20239 +
20240 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20241 + if(__builtin_constant_p(size))
20242 + copy_to_user_overflow();
20243 + else
20244 + __copy_to_user_overflow(sz, size);
20245 + return size;
20246 + }
20247
20248 if (!__builtin_constant_p(size))
20249 - return copy_user_generic((__force void *)dst, src, size);
20250 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20251 switch (size) {
20252 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20253 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20254 ret, "b", "b", "iq", 1);
20255 return ret;
20256 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20257 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20258 ret, "w", "w", "ir", 2);
20259 return ret;
20260 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20261 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20262 ret, "l", "k", "ir", 4);
20263 return ret;
20264 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20265 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20266 ret, "q", "", "er", 8);
20267 return ret;
20268 case 10:
20269 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20270 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20271 ret, "q", "", "er", 10);
20272 if (unlikely(ret))
20273 return ret;
20274 asm("":::"memory");
20275 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20276 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20277 ret, "w", "w", "ir", 2);
20278 return ret;
20279 case 16:
20280 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20281 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20282 ret, "q", "", "er", 16);
20283 if (unlikely(ret))
20284 return ret;
20285 asm("":::"memory");
20286 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20287 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 default:
20291 - return copy_user_generic((__force void *)dst, src, size);
20292 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20293 }
20294 }
20295
20296 static __always_inline __must_check
20297 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20298 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20299 {
20300 might_fault();
20301 return __copy_to_user_nocheck(dst, src, size);
20302 }
20303
20304 static __always_inline __must_check
20305 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20306 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20307 {
20308 - int ret = 0;
20309 + unsigned ret = 0;
20310
20311 might_fault();
20312 +
20313 + if (size > INT_MAX)
20314 + return size;
20315 +
20316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20317 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20318 + return size;
20319 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20320 + return size;
20321 +#endif
20322 +
20323 if (!__builtin_constant_p(size))
20324 - return copy_user_generic((__force void *)dst,
20325 - (__force void *)src, size);
20326 + return copy_user_generic((__force_kernel void *)____m(dst),
20327 + (__force_kernel const void *)____m(src), size);
20328 switch (size) {
20329 case 1: {
20330 u8 tmp;
20331 - __get_user_asm(tmp, (u8 __user *)src,
20332 + __get_user_asm(tmp, (const u8 __user *)src,
20333 ret, "b", "b", "=q", 1);
20334 if (likely(!ret))
20335 __put_user_asm(tmp, (u8 __user *)dst,
20336 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20337 }
20338 case 2: {
20339 u16 tmp;
20340 - __get_user_asm(tmp, (u16 __user *)src,
20341 + __get_user_asm(tmp, (const u16 __user *)src,
20342 ret, "w", "w", "=r", 2);
20343 if (likely(!ret))
20344 __put_user_asm(tmp, (u16 __user *)dst,
20345 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20346
20347 case 4: {
20348 u32 tmp;
20349 - __get_user_asm(tmp, (u32 __user *)src,
20350 + __get_user_asm(tmp, (const u32 __user *)src,
20351 ret, "l", "k", "=r", 4);
20352 if (likely(!ret))
20353 __put_user_asm(tmp, (u32 __user *)dst,
20354 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20355 }
20356 case 8: {
20357 u64 tmp;
20358 - __get_user_asm(tmp, (u64 __user *)src,
20359 + __get_user_asm(tmp, (const u64 __user *)src,
20360 ret, "q", "", "=r", 8);
20361 if (likely(!ret))
20362 __put_user_asm(tmp, (u64 __user *)dst,
20363 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20364 return ret;
20365 }
20366 default:
20367 - return copy_user_generic((__force void *)dst,
20368 - (__force void *)src, size);
20369 + return copy_user_generic((__force_kernel void *)____m(dst),
20370 + (__force_kernel const void *)____m(src), size);
20371 }
20372 }
20373
20374 -static __must_check __always_inline int
20375 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20376 +static __must_check __always_inline unsigned long
20377 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20378 {
20379 return __copy_from_user_nocheck(dst, src, size);
20380 }
20381
20382 -static __must_check __always_inline int
20383 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20384 +static __must_check __always_inline unsigned long
20385 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20386 {
20387 return __copy_to_user_nocheck(dst, src, size);
20388 }
20389
20390 -extern long __copy_user_nocache(void *dst, const void __user *src,
20391 - unsigned size, int zerorest);
20392 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20393 + unsigned long size, int zerorest);
20394
20395 -static inline int
20396 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20397 +static inline unsigned long
20398 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20399 {
20400 might_fault();
20401 +
20402 + if (size > INT_MAX)
20403 + return size;
20404 +
20405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20406 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20407 + return size;
20408 +#endif
20409 +
20410 return __copy_user_nocache(dst, src, size, 1);
20411 }
20412
20413 -static inline int
20414 +static inline unsigned long
20415 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20416 - unsigned size)
20417 + unsigned long size)
20418 {
20419 + if (size > INT_MAX)
20420 + return size;
20421 +
20422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20423 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20424 + return size;
20425 +#endif
20426 +
20427 return __copy_user_nocache(dst, src, size, 0);
20428 }
20429
20430 unsigned long
20431 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20432 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20433
20434 #endif /* _ASM_X86_UACCESS_64_H */
20435 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20436 index 5b238981..77fdd78 100644
20437 --- a/arch/x86/include/asm/word-at-a-time.h
20438 +++ b/arch/x86/include/asm/word-at-a-time.h
20439 @@ -11,7 +11,7 @@
20440 * and shift, for example.
20441 */
20442 struct word_at_a_time {
20443 - const unsigned long one_bits, high_bits;
20444 + unsigned long one_bits, high_bits;
20445 };
20446
20447 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20448 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20449 index e45e4da..44e8572 100644
20450 --- a/arch/x86/include/asm/x86_init.h
20451 +++ b/arch/x86/include/asm/x86_init.h
20452 @@ -129,7 +129,7 @@ struct x86_init_ops {
20453 struct x86_init_timers timers;
20454 struct x86_init_iommu iommu;
20455 struct x86_init_pci pci;
20456 -};
20457 +} __no_const;
20458
20459 /**
20460 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20461 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20462 void (*setup_percpu_clockev)(void);
20463 void (*early_percpu_clock_init)(void);
20464 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20465 -};
20466 +} __no_const;
20467
20468 struct timespec;
20469
20470 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20471 void (*save_sched_clock_state)(void);
20472 void (*restore_sched_clock_state)(void);
20473 void (*apic_post_init)(void);
20474 -};
20475 +} __no_const;
20476
20477 struct pci_dev;
20478 struct msi_msg;
20479 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20480 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20481 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20482 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20483 -};
20484 +} __no_const;
20485
20486 struct IO_APIC_route_entry;
20487 struct io_apic_irq_attr;
20488 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20489 unsigned int destination, int vector,
20490 struct io_apic_irq_attr *attr);
20491 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20492 -};
20493 +} __no_const;
20494
20495 extern struct x86_init_ops x86_init;
20496 extern struct x86_cpuinit_ops x86_cpuinit;
20497 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20498 index f58ef6c..a2abc78 100644
20499 --- a/arch/x86/include/asm/xen/page.h
20500 +++ b/arch/x86/include/asm/xen/page.h
20501 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20502 extern struct page *m2p_find_override(unsigned long mfn);
20503 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20504
20505 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20506 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20507 {
20508 unsigned long mfn;
20509
20510 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20511 index 7e7a79a..0824666 100644
20512 --- a/arch/x86/include/asm/xsave.h
20513 +++ b/arch/x86/include/asm/xsave.h
20514 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20515 if (unlikely(err))
20516 return -EFAULT;
20517
20518 + pax_open_userland();
20519 __asm__ __volatile__(ASM_STAC "\n"
20520 - "1:"XSAVE"\n"
20521 + "1:"
20522 + __copyuser_seg
20523 + XSAVE"\n"
20524 "2: " ASM_CLAC "\n"
20525 xstate_fault
20526 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20527 : "memory");
20528 + pax_close_userland();
20529 return err;
20530 }
20531
20532 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20533 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20534 {
20535 int err = 0;
20536 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20537 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20538 u32 lmask = mask;
20539 u32 hmask = mask >> 32;
20540
20541 + pax_open_userland();
20542 __asm__ __volatile__(ASM_STAC "\n"
20543 - "1:"XRSTOR"\n"
20544 + "1:"
20545 + __copyuser_seg
20546 + XRSTOR"\n"
20547 "2: " ASM_CLAC "\n"
20548 xstate_fault
20549 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20550 : "memory"); /* memory required? */
20551 + pax_close_userland();
20552 return err;
20553 }
20554
20555 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20556 index d993e33..8db1b18 100644
20557 --- a/arch/x86/include/uapi/asm/e820.h
20558 +++ b/arch/x86/include/uapi/asm/e820.h
20559 @@ -58,7 +58,7 @@ struct e820map {
20560 #define ISA_START_ADDRESS 0xa0000
20561 #define ISA_END_ADDRESS 0x100000
20562
20563 -#define BIOS_BEGIN 0x000a0000
20564 +#define BIOS_BEGIN 0x000c0000
20565 #define BIOS_END 0x00100000
20566
20567 #define BIOS_ROM_BASE 0xffe00000
20568 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20569 index 7b0a55a..ad115bf 100644
20570 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20571 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20572 @@ -49,7 +49,6 @@
20573 #define EFLAGS 144
20574 #define RSP 152
20575 #define SS 160
20576 -#define ARGOFFSET R11
20577 #endif /* __ASSEMBLY__ */
20578
20579 /* top of stack page */
20580 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20581 index 8f1e774..9b4c381 100644
20582 --- a/arch/x86/kernel/Makefile
20583 +++ b/arch/x86/kernel/Makefile
20584 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20585 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20586 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20587 obj-y += probe_roms.o
20588 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20589 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20590 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20591 obj-$(CONFIG_X86_64) += mcount_64.o
20592 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20593 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20594 index a142e77..6222cdd 100644
20595 --- a/arch/x86/kernel/acpi/boot.c
20596 +++ b/arch/x86/kernel/acpi/boot.c
20597 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20598 * If your system is blacklisted here, but you find that acpi=force
20599 * works for you, please contact linux-acpi@vger.kernel.org
20600 */
20601 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20602 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20603 /*
20604 * Boxes that need ACPI disabled
20605 */
20606 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20607 };
20608
20609 /* second table for DMI checks that should run after early-quirks */
20610 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20611 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20612 /*
20613 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20614 * which includes some code which overrides all temperature
20615 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20616 index 3136820..e2c6577 100644
20617 --- a/arch/x86/kernel/acpi/sleep.c
20618 +++ b/arch/x86/kernel/acpi/sleep.c
20619 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20620 #else /* CONFIG_64BIT */
20621 #ifdef CONFIG_SMP
20622 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20623 +
20624 + pax_open_kernel();
20625 early_gdt_descr.address =
20626 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20627 + pax_close_kernel();
20628 +
20629 initial_gs = per_cpu_offset(smp_processor_id());
20630 #endif
20631 initial_code = (unsigned long)wakeup_long64;
20632 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20633 index 665c6b7..eae4d56 100644
20634 --- a/arch/x86/kernel/acpi/wakeup_32.S
20635 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20636 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20637 # and restore the stack ... but you need gdt for this to work
20638 movl saved_context_esp, %esp
20639
20640 - movl %cs:saved_magic, %eax
20641 - cmpl $0x12345678, %eax
20642 + cmpl $0x12345678, saved_magic
20643 jne bogus_magic
20644
20645 # jump to place where we left off
20646 - movl saved_eip, %eax
20647 - jmp *%eax
20648 + jmp *(saved_eip)
20649
20650 bogus_magic:
20651 jmp bogus_magic
20652 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20653 index 703130f..27a155d 100644
20654 --- a/arch/x86/kernel/alternative.c
20655 +++ b/arch/x86/kernel/alternative.c
20656 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20657 */
20658 for (a = start; a < end; a++) {
20659 instr = (u8 *)&a->instr_offset + a->instr_offset;
20660 +
20661 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20662 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20663 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20664 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20665 +#endif
20666 +
20667 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20668 BUG_ON(a->replacementlen > a->instrlen);
20669 BUG_ON(a->instrlen > sizeof(insnbuf));
20670 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20671 add_nops(insnbuf + a->replacementlen,
20672 a->instrlen - a->replacementlen);
20673
20674 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20675 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20676 + instr = ktva_ktla(instr);
20677 +#endif
20678 +
20679 text_poke_early(instr, insnbuf, a->instrlen);
20680 }
20681 }
20682 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20683 for (poff = start; poff < end; poff++) {
20684 u8 *ptr = (u8 *)poff + *poff;
20685
20686 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20687 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20688 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20689 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690 +#endif
20691 +
20692 if (!*poff || ptr < text || ptr >= text_end)
20693 continue;
20694 /* turn DS segment override prefix into lock prefix */
20695 - if (*ptr == 0x3e)
20696 + if (*ktla_ktva(ptr) == 0x3e)
20697 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20698 }
20699 mutex_unlock(&text_mutex);
20700 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20701 for (poff = start; poff < end; poff++) {
20702 u8 *ptr = (u8 *)poff + *poff;
20703
20704 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20705 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20706 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20707 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20708 +#endif
20709 +
20710 if (!*poff || ptr < text || ptr >= text_end)
20711 continue;
20712 /* turn lock prefix into DS segment override prefix */
20713 - if (*ptr == 0xf0)
20714 + if (*ktla_ktva(ptr) == 0xf0)
20715 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20716 }
20717 mutex_unlock(&text_mutex);
20718 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20719
20720 BUG_ON(p->len > MAX_PATCH_LEN);
20721 /* prep the buffer with the original instructions */
20722 - memcpy(insnbuf, p->instr, p->len);
20723 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20724 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20725 (unsigned long)p->instr, p->len);
20726
20727 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20728 if (!uniproc_patched || num_possible_cpus() == 1)
20729 free_init_pages("SMP alternatives",
20730 (unsigned long)__smp_locks,
20731 - (unsigned long)__smp_locks_end);
20732 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20733 #endif
20734
20735 apply_paravirt(__parainstructions, __parainstructions_end);
20736 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20737 * instructions. And on the local CPU you need to be protected again NMI or MCE
20738 * handlers seeing an inconsistent instruction while you patch.
20739 */
20740 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20741 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20742 size_t len)
20743 {
20744 unsigned long flags;
20745 local_irq_save(flags);
20746 - memcpy(addr, opcode, len);
20747 +
20748 + pax_open_kernel();
20749 + memcpy(ktla_ktva(addr), opcode, len);
20750 sync_core();
20751 + pax_close_kernel();
20752 +
20753 local_irq_restore(flags);
20754 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20755 that causes hangs on some VIA CPUs. */
20756 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20757 */
20758 void *text_poke(void *addr, const void *opcode, size_t len)
20759 {
20760 - unsigned long flags;
20761 - char *vaddr;
20762 + unsigned char *vaddr = ktla_ktva(addr);
20763 struct page *pages[2];
20764 - int i;
20765 + size_t i;
20766
20767 if (!core_kernel_text((unsigned long)addr)) {
20768 - pages[0] = vmalloc_to_page(addr);
20769 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20770 + pages[0] = vmalloc_to_page(vaddr);
20771 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20772 } else {
20773 - pages[0] = virt_to_page(addr);
20774 + pages[0] = virt_to_page(vaddr);
20775 WARN_ON(!PageReserved(pages[0]));
20776 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20777 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20778 }
20779 BUG_ON(!pages[0]);
20780 - local_irq_save(flags);
20781 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20782 - if (pages[1])
20783 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20784 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20785 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20786 - clear_fixmap(FIX_TEXT_POKE0);
20787 - if (pages[1])
20788 - clear_fixmap(FIX_TEXT_POKE1);
20789 - local_flush_tlb();
20790 - sync_core();
20791 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20792 - that causes hangs on some VIA CPUs. */
20793 + text_poke_early(addr, opcode, len);
20794 for (i = 0; i < len; i++)
20795 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20796 - local_irq_restore(flags);
20797 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20798 return addr;
20799 }
20800
20801 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20802 if (likely(!bp_patching_in_progress))
20803 return 0;
20804
20805 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20806 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20807 return 0;
20808
20809 /* set up the specified breakpoint handler */
20810 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20811 */
20812 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20813 {
20814 - unsigned char int3 = 0xcc;
20815 + const unsigned char int3 = 0xcc;
20816
20817 bp_int3_handler = handler;
20818 bp_int3_addr = (u8 *)addr + sizeof(int3);
20819 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20820 index ba6cc04..06fd971 100644
20821 --- a/arch/x86/kernel/apic/apic.c
20822 +++ b/arch/x86/kernel/apic/apic.c
20823 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20824 /*
20825 * Debug level, exported for io_apic.c
20826 */
20827 -unsigned int apic_verbosity;
20828 +int apic_verbosity;
20829
20830 int pic_mode;
20831
20832 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20833 apic_write(APIC_ESR, 0);
20834 v = apic_read(APIC_ESR);
20835 ack_APIC_irq();
20836 - atomic_inc(&irq_err_count);
20837 + atomic_inc_unchecked(&irq_err_count);
20838
20839 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20840 smp_processor_id(), v);
20841 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20842 index de918c4..32eed23 100644
20843 --- a/arch/x86/kernel/apic/apic_flat_64.c
20844 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20845 @@ -154,7 +154,7 @@ static int flat_probe(void)
20846 return 1;
20847 }
20848
20849 -static struct apic apic_flat = {
20850 +static struct apic apic_flat __read_only = {
20851 .name = "flat",
20852 .probe = flat_probe,
20853 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20854 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20855 return 0;
20856 }
20857
20858 -static struct apic apic_physflat = {
20859 +static struct apic apic_physflat __read_only = {
20860
20861 .name = "physical flat",
20862 .probe = physflat_probe,
20863 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20864 index b205cdb..d8503ff 100644
20865 --- a/arch/x86/kernel/apic/apic_noop.c
20866 +++ b/arch/x86/kernel/apic/apic_noop.c
20867 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20868 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20869 }
20870
20871 -struct apic apic_noop = {
20872 +struct apic apic_noop __read_only = {
20873 .name = "noop",
20874 .probe = noop_probe,
20875 .acpi_madt_oem_check = NULL,
20876 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20877 index c4a8d63..fe893ac 100644
20878 --- a/arch/x86/kernel/apic/bigsmp_32.c
20879 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20880 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20881 return dmi_bigsmp;
20882 }
20883
20884 -static struct apic apic_bigsmp = {
20885 +static struct apic apic_bigsmp __read_only = {
20886
20887 .name = "bigsmp",
20888 .probe = probe_bigsmp,
20889 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20890 index 1183d54..6158e47 100644
20891 --- a/arch/x86/kernel/apic/io_apic.c
20892 +++ b/arch/x86/kernel/apic/io_apic.c
20893 @@ -1230,7 +1230,7 @@ out:
20894 }
20895 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20896
20897 -void lock_vector_lock(void)
20898 +void lock_vector_lock(void) __acquires(vector_lock)
20899 {
20900 /* Used to the online set of cpus does not change
20901 * during assign_irq_vector.
20902 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20903 raw_spin_lock(&vector_lock);
20904 }
20905
20906 -void unlock_vector_lock(void)
20907 +void unlock_vector_lock(void) __releases(vector_lock)
20908 {
20909 raw_spin_unlock(&vector_lock);
20910 }
20911 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20912 ack_APIC_irq();
20913 }
20914
20915 -atomic_t irq_mis_count;
20916 +atomic_unchecked_t irq_mis_count;
20917
20918 #ifdef CONFIG_GENERIC_PENDING_IRQ
20919 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20920 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20921 * at the cpu.
20922 */
20923 if (!(v & (1 << (i & 0x1f)))) {
20924 - atomic_inc(&irq_mis_count);
20925 + atomic_inc_unchecked(&irq_mis_count);
20926
20927 eoi_ioapic_irq(irq, cfg);
20928 }
20929 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20930 index bda4886..f9c7195 100644
20931 --- a/arch/x86/kernel/apic/probe_32.c
20932 +++ b/arch/x86/kernel/apic/probe_32.c
20933 @@ -72,7 +72,7 @@ static int probe_default(void)
20934 return 1;
20935 }
20936
20937 -static struct apic apic_default = {
20938 +static struct apic apic_default __read_only = {
20939
20940 .name = "default",
20941 .probe = probe_default,
20942 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20943 index e658f21..b695a1a 100644
20944 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20945 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20946 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20947 return notifier_from_errno(err);
20948 }
20949
20950 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20951 +static struct notifier_block x2apic_cpu_notifier = {
20952 .notifier_call = update_clusterinfo,
20953 };
20954
20955 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20956 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20957 }
20958
20959 -static struct apic apic_x2apic_cluster = {
20960 +static struct apic apic_x2apic_cluster __read_only = {
20961
20962 .name = "cluster x2apic",
20963 .probe = x2apic_cluster_probe,
20964 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20965 index 6fae733..5ca17af 100644
20966 --- a/arch/x86/kernel/apic/x2apic_phys.c
20967 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20968 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20969 return apic == &apic_x2apic_phys;
20970 }
20971
20972 -static struct apic apic_x2apic_phys = {
20973 +static struct apic apic_x2apic_phys __read_only = {
20974
20975 .name = "physical x2apic",
20976 .probe = x2apic_phys_probe,
20977 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20978 index 8e9dcfd..c61b3e4 100644
20979 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20980 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20981 @@ -348,7 +348,7 @@ static int uv_probe(void)
20982 return apic == &apic_x2apic_uv_x;
20983 }
20984
20985 -static struct apic __refdata apic_x2apic_uv_x = {
20986 +static struct apic apic_x2apic_uv_x __read_only = {
20987
20988 .name = "UV large system",
20989 .probe = uv_probe,
20990 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20991 index 5848744..56cb598 100644
20992 --- a/arch/x86/kernel/apm_32.c
20993 +++ b/arch/x86/kernel/apm_32.c
20994 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20995 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20996 * even though they are called in protected mode.
20997 */
20998 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20999 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21000 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21001
21002 static const char driver_version[] = "1.16ac"; /* no spaces */
21003 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21004 BUG_ON(cpu != 0);
21005 gdt = get_cpu_gdt_table(cpu);
21006 save_desc_40 = gdt[0x40 / 8];
21007 +
21008 + pax_open_kernel();
21009 gdt[0x40 / 8] = bad_bios_desc;
21010 + pax_close_kernel();
21011
21012 apm_irq_save(flags);
21013 APM_DO_SAVE_SEGS;
21014 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21015 &call->esi);
21016 APM_DO_RESTORE_SEGS;
21017 apm_irq_restore(flags);
21018 +
21019 + pax_open_kernel();
21020 gdt[0x40 / 8] = save_desc_40;
21021 + pax_close_kernel();
21022 +
21023 put_cpu();
21024
21025 return call->eax & 0xff;
21026 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21027 BUG_ON(cpu != 0);
21028 gdt = get_cpu_gdt_table(cpu);
21029 save_desc_40 = gdt[0x40 / 8];
21030 +
21031 + pax_open_kernel();
21032 gdt[0x40 / 8] = bad_bios_desc;
21033 + pax_close_kernel();
21034
21035 apm_irq_save(flags);
21036 APM_DO_SAVE_SEGS;
21037 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21038 &call->eax);
21039 APM_DO_RESTORE_SEGS;
21040 apm_irq_restore(flags);
21041 +
21042 + pax_open_kernel();
21043 gdt[0x40 / 8] = save_desc_40;
21044 + pax_close_kernel();
21045 +
21046 put_cpu();
21047 return error;
21048 }
21049 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21050 * code to that CPU.
21051 */
21052 gdt = get_cpu_gdt_table(0);
21053 +
21054 + pax_open_kernel();
21055 set_desc_base(&gdt[APM_CS >> 3],
21056 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21057 set_desc_base(&gdt[APM_CS_16 >> 3],
21058 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21059 set_desc_base(&gdt[APM_DS >> 3],
21060 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21061 + pax_close_kernel();
21062
21063 proc_create("apm", 0, NULL, &apm_file_ops);
21064
21065 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21066 index 9f6b934..cf5ffb3 100644
21067 --- a/arch/x86/kernel/asm-offsets.c
21068 +++ b/arch/x86/kernel/asm-offsets.c
21069 @@ -32,6 +32,8 @@ void common(void) {
21070 OFFSET(TI_flags, thread_info, flags);
21071 OFFSET(TI_status, thread_info, status);
21072 OFFSET(TI_addr_limit, thread_info, addr_limit);
21073 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21074 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21075
21076 BLANK();
21077 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21078 @@ -52,8 +54,26 @@ void common(void) {
21079 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21080 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21081 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21082 +
21083 +#ifdef CONFIG_PAX_KERNEXEC
21084 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21085 #endif
21086
21087 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21088 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21089 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21090 +#ifdef CONFIG_X86_64
21091 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21092 +#endif
21093 +#endif
21094 +
21095 +#endif
21096 +
21097 + BLANK();
21098 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21099 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21100 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21101 +
21102 #ifdef CONFIG_XEN
21103 BLANK();
21104 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21105 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21106 index e7c798b..2b2019b 100644
21107 --- a/arch/x86/kernel/asm-offsets_64.c
21108 +++ b/arch/x86/kernel/asm-offsets_64.c
21109 @@ -77,6 +77,7 @@ int main(void)
21110 BLANK();
21111 #undef ENTRY
21112
21113 + DEFINE(TSS_size, sizeof(struct tss_struct));
21114 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21115 BLANK();
21116
21117 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21118 index 80091ae..0c5184f 100644
21119 --- a/arch/x86/kernel/cpu/Makefile
21120 +++ b/arch/x86/kernel/cpu/Makefile
21121 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21122 CFLAGS_REMOVE_perf_event.o = -pg
21123 endif
21124
21125 -# Make sure load_percpu_segment has no stackprotector
21126 -nostackp := $(call cc-option, -fno-stack-protector)
21127 -CFLAGS_common.o := $(nostackp)
21128 -
21129 obj-y := intel_cacheinfo.o scattered.o topology.o
21130 obj-y += common.o
21131 obj-y += rdrand.o
21132 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21133 index 813d29d..6e542d4 100644
21134 --- a/arch/x86/kernel/cpu/amd.c
21135 +++ b/arch/x86/kernel/cpu/amd.c
21136 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21137 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21138 {
21139 /* AMD errata T13 (order #21922) */
21140 - if ((c->x86 == 6)) {
21141 + if (c->x86 == 6) {
21142 /* Duron Rev A0 */
21143 if (c->x86_model == 3 && c->x86_mask == 0)
21144 size = 64;
21145 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21146 index cfa9b5b..19b5084 100644
21147 --- a/arch/x86/kernel/cpu/common.c
21148 +++ b/arch/x86/kernel/cpu/common.c
21149 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21150
21151 static const struct cpu_dev *this_cpu = &default_cpu;
21152
21153 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21154 -#ifdef CONFIG_X86_64
21155 - /*
21156 - * We need valid kernel segments for data and code in long mode too
21157 - * IRET will check the segment types kkeil 2000/10/28
21158 - * Also sysret mandates a special GDT layout
21159 - *
21160 - * TLS descriptors are currently at a different place compared to i386.
21161 - * Hopefully nobody expects them at a fixed place (Wine?)
21162 - */
21163 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21164 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21165 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21166 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21167 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21168 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21169 -#else
21170 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21171 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21172 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21173 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21174 - /*
21175 - * Segments used for calling PnP BIOS have byte granularity.
21176 - * They code segments and data segments have fixed 64k limits,
21177 - * the transfer segment sizes are set at run time.
21178 - */
21179 - /* 32-bit code */
21180 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21181 - /* 16-bit code */
21182 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21183 - /* 16-bit data */
21184 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21185 - /* 16-bit data */
21186 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21187 - /* 16-bit data */
21188 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21189 - /*
21190 - * The APM segments have byte granularity and their bases
21191 - * are set at run time. All have 64k limits.
21192 - */
21193 - /* 32-bit code */
21194 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21195 - /* 16-bit code */
21196 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21197 - /* data */
21198 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21199 -
21200 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21201 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21202 - GDT_STACK_CANARY_INIT
21203 -#endif
21204 -} };
21205 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21206 -
21207 static int __init x86_xsave_setup(char *s)
21208 {
21209 if (strlen(s))
21210 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21211 }
21212 }
21213
21214 +#ifdef CONFIG_X86_64
21215 +static __init int setup_disable_pcid(char *arg)
21216 +{
21217 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21218 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21219 +
21220 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21221 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21222 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21223 +#endif
21224 +
21225 + return 1;
21226 +}
21227 +__setup("nopcid", setup_disable_pcid);
21228 +
21229 +static void setup_pcid(struct cpuinfo_x86 *c)
21230 +{
21231 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21232 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21233 +
21234 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21235 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21236 + pax_open_kernel();
21237 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21238 + pax_close_kernel();
21239 + printk("PAX: slow and weak UDEREF enabled\n");
21240 + } else
21241 + printk("PAX: UDEREF disabled\n");
21242 +#endif
21243 +
21244 + return;
21245 + }
21246 +
21247 + printk("PAX: PCID detected\n");
21248 + set_in_cr4(X86_CR4_PCIDE);
21249 +
21250 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21251 + pax_open_kernel();
21252 + clone_pgd_mask = ~(pgdval_t)0UL;
21253 + pax_close_kernel();
21254 + if (pax_user_shadow_base)
21255 + printk("PAX: weak UDEREF enabled\n");
21256 + else {
21257 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21258 + printk("PAX: strong UDEREF enabled\n");
21259 + }
21260 +#endif
21261 +
21262 + if (cpu_has(c, X86_FEATURE_INVPCID))
21263 + printk("PAX: INVPCID detected\n");
21264 +}
21265 +#endif
21266 +
21267 /*
21268 * Some CPU features depend on higher CPUID levels, which may not always
21269 * be available due to CPUID level capping or broken virtualization
21270 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21271 {
21272 struct desc_ptr gdt_descr;
21273
21274 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21275 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21276 gdt_descr.size = GDT_SIZE - 1;
21277 load_gdt(&gdt_descr);
21278 /* Reload the per-cpu base */
21279 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21280 setup_smep(c);
21281 setup_smap(c);
21282
21283 +#ifdef CONFIG_X86_64
21284 + setup_pcid(c);
21285 +#endif
21286 +
21287 /*
21288 * The vendor-specific functions might have changed features.
21289 * Now we do "generic changes."
21290 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21291 /* Filter out anything that depends on CPUID levels we don't have */
21292 filter_cpuid_features(c, true);
21293
21294 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21295 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21296 +#endif
21297 +
21298 /* If the model name is still unset, do table lookup. */
21299 if (!c->x86_model_id[0]) {
21300 const char *p;
21301 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21302 void enable_sep_cpu(void)
21303 {
21304 int cpu = get_cpu();
21305 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21306 + struct tss_struct *tss = init_tss + cpu;
21307
21308 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21309 put_cpu();
21310 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21311 }
21312 __setup("clearcpuid=", setup_disablecpuid);
21313
21314 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21315 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21316 +
21317 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21318 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21319 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21320 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21321
21322 #ifdef CONFIG_X86_64
21323 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21324 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21325 - (unsigned long) debug_idt_table };
21326 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21327 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21328
21329 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21330 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21331 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21332 */
21333 load_ucode_ap();
21334
21335 - t = &per_cpu(init_tss, cpu);
21336 + t = init_tss + cpu;
21337 oist = &per_cpu(orig_ist, cpu);
21338
21339 #ifdef CONFIG_NUMA
21340 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21341 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21342 barrier();
21343
21344 - x86_configure_nx();
21345 enable_x2apic();
21346
21347 /*
21348 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21349 {
21350 int cpu = smp_processor_id();
21351 struct task_struct *curr = current;
21352 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21353 + struct tss_struct *t = init_tss + cpu;
21354 struct thread_struct *thread = &curr->thread;
21355
21356 wait_for_master_cpu(cpu);
21357 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21358 index c703507..28535e3 100644
21359 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21360 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21361 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21362 };
21363
21364 #ifdef CONFIG_AMD_NB
21365 +static struct attribute *default_attrs_amd_nb[] = {
21366 + &type.attr,
21367 + &level.attr,
21368 + &coherency_line_size.attr,
21369 + &physical_line_partition.attr,
21370 + &ways_of_associativity.attr,
21371 + &number_of_sets.attr,
21372 + &size.attr,
21373 + &shared_cpu_map.attr,
21374 + &shared_cpu_list.attr,
21375 + NULL,
21376 + NULL,
21377 + NULL,
21378 + NULL
21379 +};
21380 +
21381 static struct attribute **amd_l3_attrs(void)
21382 {
21383 static struct attribute **attrs;
21384 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21385
21386 n = ARRAY_SIZE(default_attrs);
21387
21388 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21389 - n += 2;
21390 -
21391 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21392 - n += 1;
21393 -
21394 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21395 - if (attrs == NULL)
21396 - return attrs = default_attrs;
21397 -
21398 - for (n = 0; default_attrs[n]; n++)
21399 - attrs[n] = default_attrs[n];
21400 + attrs = default_attrs_amd_nb;
21401
21402 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21403 attrs[n++] = &cache_disable_0.attr;
21404 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21405 .default_attrs = default_attrs,
21406 };
21407
21408 +#ifdef CONFIG_AMD_NB
21409 +static struct kobj_type ktype_cache_amd_nb = {
21410 + .sysfs_ops = &sysfs_ops,
21411 + .default_attrs = default_attrs_amd_nb,
21412 +};
21413 +#endif
21414 +
21415 static struct kobj_type ktype_percpu_entry = {
21416 .sysfs_ops = &sysfs_ops,
21417 };
21418 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21419 return retval;
21420 }
21421
21422 +#ifdef CONFIG_AMD_NB
21423 + amd_l3_attrs();
21424 +#endif
21425 +
21426 for (i = 0; i < num_cache_leaves; i++) {
21427 + struct kobj_type *ktype;
21428 +
21429 this_object = INDEX_KOBJECT_PTR(cpu, i);
21430 this_object->cpu = cpu;
21431 this_object->index = i;
21432
21433 this_leaf = CPUID4_INFO_IDX(cpu, i);
21434
21435 - ktype_cache.default_attrs = default_attrs;
21436 + ktype = &ktype_cache;
21437 #ifdef CONFIG_AMD_NB
21438 if (this_leaf->base.nb)
21439 - ktype_cache.default_attrs = amd_l3_attrs();
21440 + ktype = &ktype_cache_amd_nb;
21441 #endif
21442 retval = kobject_init_and_add(&(this_object->kobj),
21443 - &ktype_cache,
21444 + ktype,
21445 per_cpu(ici_cache_kobject, cpu),
21446 "index%1lu", i);
21447 if (unlikely(retval)) {
21448 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21449 index 61a9668ce..b446a37 100644
21450 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21451 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21452 @@ -45,6 +45,7 @@
21453 #include <asm/processor.h>
21454 #include <asm/mce.h>
21455 #include <asm/msr.h>
21456 +#include <asm/local.h>
21457
21458 #include "mce-internal.h"
21459
21460 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21461 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21462 m->cs, m->ip);
21463
21464 - if (m->cs == __KERNEL_CS)
21465 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21466 print_symbol("{%s}", m->ip);
21467 pr_cont("\n");
21468 }
21469 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21470
21471 #define PANIC_TIMEOUT 5 /* 5 seconds */
21472
21473 -static atomic_t mce_paniced;
21474 +static atomic_unchecked_t mce_paniced;
21475
21476 static int fake_panic;
21477 -static atomic_t mce_fake_paniced;
21478 +static atomic_unchecked_t mce_fake_paniced;
21479
21480 /* Panic in progress. Enable interrupts and wait for final IPI */
21481 static void wait_for_panic(void)
21482 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21483 /*
21484 * Make sure only one CPU runs in machine check panic
21485 */
21486 - if (atomic_inc_return(&mce_paniced) > 1)
21487 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21488 wait_for_panic();
21489 barrier();
21490
21491 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21492 console_verbose();
21493 } else {
21494 /* Don't log too much for fake panic */
21495 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21496 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21497 return;
21498 }
21499 /* First print corrected ones that are still unlogged */
21500 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21501 if (!fake_panic) {
21502 if (panic_timeout == 0)
21503 panic_timeout = mca_cfg.panic_timeout;
21504 - panic(msg);
21505 + panic("%s", msg);
21506 } else
21507 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21508 }
21509 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21510 * might have been modified by someone else.
21511 */
21512 rmb();
21513 - if (atomic_read(&mce_paniced))
21514 + if (atomic_read_unchecked(&mce_paniced))
21515 wait_for_panic();
21516 if (!mca_cfg.monarch_timeout)
21517 goto out;
21518 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21519 }
21520
21521 /* Call the installed machine check handler for this CPU setup. */
21522 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21523 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21524 unexpected_machine_check;
21525
21526 /*
21527 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21528 return;
21529 }
21530
21531 + pax_open_kernel();
21532 machine_check_vector = do_machine_check;
21533 + pax_close_kernel();
21534
21535 __mcheck_cpu_init_generic();
21536 __mcheck_cpu_init_vendor(c);
21537 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21538 */
21539
21540 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21541 -static int mce_chrdev_open_count; /* #times opened */
21542 +static local_t mce_chrdev_open_count; /* #times opened */
21543 static int mce_chrdev_open_exclu; /* already open exclusive? */
21544
21545 static int mce_chrdev_open(struct inode *inode, struct file *file)
21546 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21547 spin_lock(&mce_chrdev_state_lock);
21548
21549 if (mce_chrdev_open_exclu ||
21550 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21551 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21552 spin_unlock(&mce_chrdev_state_lock);
21553
21554 return -EBUSY;
21555 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21556
21557 if (file->f_flags & O_EXCL)
21558 mce_chrdev_open_exclu = 1;
21559 - mce_chrdev_open_count++;
21560 + local_inc(&mce_chrdev_open_count);
21561
21562 spin_unlock(&mce_chrdev_state_lock);
21563
21564 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21565 {
21566 spin_lock(&mce_chrdev_state_lock);
21567
21568 - mce_chrdev_open_count--;
21569 + local_dec(&mce_chrdev_open_count);
21570 mce_chrdev_open_exclu = 0;
21571
21572 spin_unlock(&mce_chrdev_state_lock);
21573 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21574
21575 for (i = 0; i < mca_cfg.banks; i++) {
21576 struct mce_bank *b = &mce_banks[i];
21577 - struct device_attribute *a = &b->attr;
21578 + device_attribute_no_const *a = &b->attr;
21579
21580 sysfs_attr_init(&a->attr);
21581 a->attr.name = b->attrname;
21582 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21583 static void mce_reset(void)
21584 {
21585 cpu_missing = 0;
21586 - atomic_set(&mce_fake_paniced, 0);
21587 + atomic_set_unchecked(&mce_fake_paniced, 0);
21588 atomic_set(&mce_executing, 0);
21589 atomic_set(&mce_callin, 0);
21590 atomic_set(&global_nwo, 0);
21591 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21592 index a304298..49b6d06 100644
21593 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21594 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21595 @@ -10,6 +10,7 @@
21596 #include <asm/processor.h>
21597 #include <asm/mce.h>
21598 #include <asm/msr.h>
21599 +#include <asm/pgtable.h>
21600
21601 /* By default disabled */
21602 int mce_p5_enabled __read_mostly;
21603 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21604 if (!cpu_has(c, X86_FEATURE_MCE))
21605 return;
21606
21607 + pax_open_kernel();
21608 machine_check_vector = pentium_machine_check;
21609 + pax_close_kernel();
21610 /* Make sure the vector pointer is visible before we enable MCEs: */
21611 wmb();
21612
21613 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21614 index 7dc5564..1273569 100644
21615 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21616 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21617 @@ -9,6 +9,7 @@
21618 #include <asm/processor.h>
21619 #include <asm/mce.h>
21620 #include <asm/msr.h>
21621 +#include <asm/pgtable.h>
21622
21623 /* Machine check handler for WinChip C6: */
21624 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21625 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21626 {
21627 u32 lo, hi;
21628
21629 + pax_open_kernel();
21630 machine_check_vector = winchip_machine_check;
21631 + pax_close_kernel();
21632 /* Make sure the vector pointer is visible before we enable MCEs: */
21633 wmb();
21634
21635 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21636 index 36a8361..e7058c2 100644
21637 --- a/arch/x86/kernel/cpu/microcode/core.c
21638 +++ b/arch/x86/kernel/cpu/microcode/core.c
21639 @@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21640 return NOTIFY_OK;
21641 }
21642
21643 -static struct notifier_block __refdata mc_cpu_notifier = {
21644 +static struct notifier_block mc_cpu_notifier = {
21645 .notifier_call = mc_cpu_callback,
21646 };
21647
21648 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21649 index c6826d1..8dc677e 100644
21650 --- a/arch/x86/kernel/cpu/microcode/intel.c
21651 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21652 @@ -196,6 +196,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
21653 struct microcode_header_intel mc_header;
21654 unsigned int mc_size;
21655
21656 + if (leftover < sizeof(mc_header)) {
21657 + pr_err("error! Truncated header in microcode data file\n");
21658 + break;
21659 + }
21660 +
21661 if (get_ucode_data(&mc_header, ucode_ptr, sizeof(mc_header)))
21662 break;
21663
21664 @@ -293,13 +298,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21665
21666 static int get_ucode_user(void *to, const void *from, size_t n)
21667 {
21668 - return copy_from_user(to, from, n);
21669 + return copy_from_user(to, (const void __force_user *)from, n);
21670 }
21671
21672 static enum ucode_state
21673 request_microcode_user(int cpu, const void __user *buf, size_t size)
21674 {
21675 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21676 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21677 }
21678
21679 static void microcode_fini_cpu(int cpu)
21680 diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
21681 index ec9df6f..420eb93 100644
21682 --- a/arch/x86/kernel/cpu/microcode/intel_early.c
21683 +++ b/arch/x86/kernel/cpu/microcode/intel_early.c
21684 @@ -321,7 +321,11 @@ get_matching_model_microcode(int cpu, unsigned long start,
21685 unsigned int mc_saved_count = mc_saved_data->mc_saved_count;
21686 int i;
21687
21688 - while (leftover) {
21689 + while (leftover && mc_saved_count < ARRAY_SIZE(mc_saved_tmp)) {
21690 +
21691 + if (leftover < sizeof(mc_header))
21692 + break;
21693 +
21694 mc_header = (struct microcode_header_intel *)ucode_ptr;
21695
21696 mc_size = get_totalsize(mc_header);
21697 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21698 index ea5f363..cb0e905 100644
21699 --- a/arch/x86/kernel/cpu/mtrr/main.c
21700 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21701 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21702 u64 size_or_mask, size_and_mask;
21703 static bool mtrr_aps_delayed_init;
21704
21705 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21706 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21707
21708 const struct mtrr_ops *mtrr_if;
21709
21710 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21711 index df5e41f..816c719 100644
21712 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21713 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21714 @@ -25,7 +25,7 @@ struct mtrr_ops {
21715 int (*validate_add_page)(unsigned long base, unsigned long size,
21716 unsigned int type);
21717 int (*have_wrcomb)(void);
21718 -};
21719 +} __do_const;
21720
21721 extern int generic_get_free_region(unsigned long base, unsigned long size,
21722 int replace_reg);
21723 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21724 index 143e5f5..5825081 100644
21725 --- a/arch/x86/kernel/cpu/perf_event.c
21726 +++ b/arch/x86/kernel/cpu/perf_event.c
21727 @@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21728
21729 }
21730
21731 -static struct attribute_group x86_pmu_format_group = {
21732 +static attribute_group_no_const x86_pmu_format_group = {
21733 .name = "format",
21734 .attrs = NULL,
21735 };
21736 @@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21737 NULL,
21738 };
21739
21740 -static struct attribute_group x86_pmu_events_group = {
21741 +static attribute_group_no_const x86_pmu_events_group = {
21742 .name = "events",
21743 .attrs = events_attr,
21744 };
21745 @@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21746 if (idx > GDT_ENTRIES)
21747 return 0;
21748
21749 - desc = raw_cpu_ptr(gdt_page.gdt);
21750 + desc = get_cpu_gdt_table(smp_processor_id());
21751 }
21752
21753 return get_desc_base(desc + idx);
21754 @@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21755 break;
21756
21757 perf_callchain_store(entry, frame.return_address);
21758 - fp = frame.next_frame;
21759 + fp = (const void __force_user *)frame.next_frame;
21760 }
21761 }
21762
21763 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21764 index 639d128..e92d7e5 100644
21765 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21766 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21767 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21768 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21769 {
21770 struct attribute **attrs;
21771 - struct attribute_group *attr_group;
21772 + attribute_group_no_const *attr_group;
21773 int i = 0, j;
21774
21775 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21776 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21777 index 498b6d9..4126515 100644
21778 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21779 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21780 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21781 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21782
21783 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21784 - u64 capabilities;
21785 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21786
21787 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21788 - x86_pmu.intel_cap.capabilities = capabilities;
21789 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21790 + x86_pmu.intel_cap.capabilities = capabilities;
21791 }
21792
21793 intel_ds_init();
21794 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21795 index 8c25674..30aa32e 100644
21796 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21797 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21798 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21799 NULL,
21800 };
21801
21802 -static struct attribute_group rapl_pmu_events_group = {
21803 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21804 .name = "events",
21805 .attrs = NULL, /* patched at runtime */
21806 };
21807 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21808 index e98f68c..1992b15 100644
21809 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21810 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21811 @@ -737,7 +737,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21812 static int __init uncore_type_init(struct intel_uncore_type *type)
21813 {
21814 struct intel_uncore_pmu *pmus;
21815 - struct attribute_group *attr_group;
21816 + attribute_group_no_const *attr_group;
21817 struct attribute **attrs;
21818 int i, j;
21819
21820 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21821 index 863d9b0..6289b63 100644
21822 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21823 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21824 @@ -114,7 +114,7 @@ struct intel_uncore_box {
21825 struct uncore_event_desc {
21826 struct kobj_attribute attr;
21827 const char *config;
21828 -};
21829 +} __do_const;
21830
21831 ssize_t uncore_event_show(struct kobject *kobj,
21832 struct kobj_attribute *attr, char *buf);
21833 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21834 index 3225ae6c..ee3c6db 100644
21835 --- a/arch/x86/kernel/cpuid.c
21836 +++ b/arch/x86/kernel/cpuid.c
21837 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21838 return notifier_from_errno(err);
21839 }
21840
21841 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21842 +static struct notifier_block cpuid_class_cpu_notifier =
21843 {
21844 .notifier_call = cpuid_class_cpu_callback,
21845 };
21846 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21847 index f5ab56d..d3b201a 100644
21848 --- a/arch/x86/kernel/crash.c
21849 +++ b/arch/x86/kernel/crash.c
21850 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21851 #ifdef CONFIG_X86_32
21852 struct pt_regs fixed_regs;
21853
21854 - if (!user_mode_vm(regs)) {
21855 + if (!user_mode(regs)) {
21856 crash_fixup_ss_esp(&fixed_regs, regs);
21857 regs = &fixed_regs;
21858 }
21859 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21860 index afa64ad..dce67dd 100644
21861 --- a/arch/x86/kernel/crash_dump_64.c
21862 +++ b/arch/x86/kernel/crash_dump_64.c
21863 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21864 return -ENOMEM;
21865
21866 if (userbuf) {
21867 - if (copy_to_user(buf, vaddr + offset, csize)) {
21868 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21869 iounmap(vaddr);
21870 return -EFAULT;
21871 }
21872 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21873 index f6dfd93..892ade4 100644
21874 --- a/arch/x86/kernel/doublefault.c
21875 +++ b/arch/x86/kernel/doublefault.c
21876 @@ -12,7 +12,7 @@
21877
21878 #define DOUBLEFAULT_STACKSIZE (1024)
21879 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21880 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21881 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21882
21883 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21884
21885 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21886 unsigned long gdt, tss;
21887
21888 native_store_gdt(&gdt_desc);
21889 - gdt = gdt_desc.address;
21890 + gdt = (unsigned long)gdt_desc.address;
21891
21892 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21893
21894 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21895 /* 0x2 bit is always set */
21896 .flags = X86_EFLAGS_SF | 0x2,
21897 .sp = STACK_START,
21898 - .es = __USER_DS,
21899 + .es = __KERNEL_DS,
21900 .cs = __KERNEL_CS,
21901 .ss = __KERNEL_DS,
21902 - .ds = __USER_DS,
21903 + .ds = __KERNEL_DS,
21904 .fs = __KERNEL_PERCPU,
21905
21906 .__cr3 = __pa_nodebug(swapper_pg_dir),
21907 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21908 index b74ebc7..2c95874 100644
21909 --- a/arch/x86/kernel/dumpstack.c
21910 +++ b/arch/x86/kernel/dumpstack.c
21911 @@ -2,6 +2,9 @@
21912 * Copyright (C) 1991, 1992 Linus Torvalds
21913 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21914 */
21915 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21916 +#define __INCLUDED_BY_HIDESYM 1
21917 +#endif
21918 #include <linux/kallsyms.h>
21919 #include <linux/kprobes.h>
21920 #include <linux/uaccess.h>
21921 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21922
21923 void printk_address(unsigned long address)
21924 {
21925 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21926 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21927 }
21928
21929 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21930 static void
21931 print_ftrace_graph_addr(unsigned long addr, void *data,
21932 const struct stacktrace_ops *ops,
21933 - struct thread_info *tinfo, int *graph)
21934 + struct task_struct *task, int *graph)
21935 {
21936 - struct task_struct *task;
21937 unsigned long ret_addr;
21938 int index;
21939
21940 if (addr != (unsigned long)return_to_handler)
21941 return;
21942
21943 - task = tinfo->task;
21944 index = task->curr_ret_stack;
21945
21946 if (!task->ret_stack || index < *graph)
21947 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21948 static inline void
21949 print_ftrace_graph_addr(unsigned long addr, void *data,
21950 const struct stacktrace_ops *ops,
21951 - struct thread_info *tinfo, int *graph)
21952 + struct task_struct *task, int *graph)
21953 { }
21954 #endif
21955
21956 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21957 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21958 */
21959
21960 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21961 - void *p, unsigned int size, void *end)
21962 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21963 {
21964 - void *t = tinfo;
21965 if (end) {
21966 if (p < end && p >= (end-THREAD_SIZE))
21967 return 1;
21968 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21969 }
21970
21971 unsigned long
21972 -print_context_stack(struct thread_info *tinfo,
21973 +print_context_stack(struct task_struct *task, void *stack_start,
21974 unsigned long *stack, unsigned long bp,
21975 const struct stacktrace_ops *ops, void *data,
21976 unsigned long *end, int *graph)
21977 {
21978 struct stack_frame *frame = (struct stack_frame *)bp;
21979
21980 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21981 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21982 unsigned long addr;
21983
21984 addr = *stack;
21985 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21986 } else {
21987 ops->address(data, addr, 0);
21988 }
21989 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21990 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21991 }
21992 stack++;
21993 }
21994 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21995 EXPORT_SYMBOL_GPL(print_context_stack);
21996
21997 unsigned long
21998 -print_context_stack_bp(struct thread_info *tinfo,
21999 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22000 unsigned long *stack, unsigned long bp,
22001 const struct stacktrace_ops *ops, void *data,
22002 unsigned long *end, int *graph)
22003 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22004 struct stack_frame *frame = (struct stack_frame *)bp;
22005 unsigned long *ret_addr = &frame->return_address;
22006
22007 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22008 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22009 unsigned long addr = *ret_addr;
22010
22011 if (!__kernel_text_address(addr))
22012 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22013 ops->address(data, addr, 1);
22014 frame = frame->next_frame;
22015 ret_addr = &frame->return_address;
22016 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22017 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22018 }
22019
22020 return (unsigned long)frame;
22021 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22022 static void print_trace_address(void *data, unsigned long addr, int reliable)
22023 {
22024 touch_nmi_watchdog();
22025 - printk(data);
22026 + printk("%s", (char *)data);
22027 printk_stack_address(addr, reliable);
22028 }
22029
22030 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22031 EXPORT_SYMBOL_GPL(oops_begin);
22032 NOKPROBE_SYMBOL(oops_begin);
22033
22034 +extern void gr_handle_kernel_exploit(void);
22035 +
22036 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22037 {
22038 if (regs && kexec_should_crash(current))
22039 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22040 panic("Fatal exception in interrupt");
22041 if (panic_on_oops)
22042 panic("Fatal exception");
22043 - do_exit(signr);
22044 +
22045 + gr_handle_kernel_exploit();
22046 +
22047 + do_group_exit(signr);
22048 }
22049 NOKPROBE_SYMBOL(oops_end);
22050
22051 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22052 print_modules();
22053 show_regs(regs);
22054 #ifdef CONFIG_X86_32
22055 - if (user_mode_vm(regs)) {
22056 + if (user_mode(regs)) {
22057 sp = regs->sp;
22058 ss = regs->ss & 0xffff;
22059 } else {
22060 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22061 unsigned long flags = oops_begin();
22062 int sig = SIGSEGV;
22063
22064 - if (!user_mode_vm(regs))
22065 + if (!user_mode(regs))
22066 report_bug(regs->ip, regs);
22067
22068 if (__die(str, regs, err))
22069 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22070 index 5abd4cd..c65733b 100644
22071 --- a/arch/x86/kernel/dumpstack_32.c
22072 +++ b/arch/x86/kernel/dumpstack_32.c
22073 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22074 bp = stack_frame(task, regs);
22075
22076 for (;;) {
22077 - struct thread_info *context;
22078 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22079 void *end_stack;
22080
22081 end_stack = is_hardirq_stack(stack, cpu);
22082 if (!end_stack)
22083 end_stack = is_softirq_stack(stack, cpu);
22084
22085 - context = task_thread_info(task);
22086 - bp = ops->walk_stack(context, stack, bp, ops, data,
22087 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22088 end_stack, &graph);
22089
22090 /* Stop if not on irq stack */
22091 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22092 int i;
22093
22094 show_regs_print_info(KERN_EMERG);
22095 - __show_regs(regs, !user_mode_vm(regs));
22096 + __show_regs(regs, !user_mode(regs));
22097
22098 /*
22099 * When in-kernel, we also print out the stack and code at the
22100 * time of the fault..
22101 */
22102 - if (!user_mode_vm(regs)) {
22103 + if (!user_mode(regs)) {
22104 unsigned int code_prologue = code_bytes * 43 / 64;
22105 unsigned int code_len = code_bytes;
22106 unsigned char c;
22107 u8 *ip;
22108 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22109
22110 pr_emerg("Stack:\n");
22111 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22112
22113 pr_emerg("Code:");
22114
22115 - ip = (u8 *)regs->ip - code_prologue;
22116 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22117 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22118 /* try starting at IP */
22119 - ip = (u8 *)regs->ip;
22120 + ip = (u8 *)regs->ip + cs_base;
22121 code_len = code_len - code_prologue + 1;
22122 }
22123 for (i = 0; i < code_len; i++, ip++) {
22124 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22125 pr_cont(" Bad EIP value.");
22126 break;
22127 }
22128 - if (ip == (u8 *)regs->ip)
22129 + if (ip == (u8 *)regs->ip + cs_base)
22130 pr_cont(" <%02x>", c);
22131 else
22132 pr_cont(" %02x", c);
22133 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22134 {
22135 unsigned short ud2;
22136
22137 + ip = ktla_ktva(ip);
22138 if (ip < PAGE_OFFSET)
22139 return 0;
22140 if (probe_kernel_address((unsigned short *)ip, ud2))
22141 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22142
22143 return ud2 == 0x0b0f;
22144 }
22145 +
22146 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22147 +void pax_check_alloca(unsigned long size)
22148 +{
22149 + unsigned long sp = (unsigned long)&sp, stack_left;
22150 +
22151 + /* all kernel stacks are of the same size */
22152 + stack_left = sp & (THREAD_SIZE - 1);
22153 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22154 +}
22155 +EXPORT_SYMBOL(pax_check_alloca);
22156 +#endif
22157 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22158 index ff86f19..73eabf4 100644
22159 --- a/arch/x86/kernel/dumpstack_64.c
22160 +++ b/arch/x86/kernel/dumpstack_64.c
22161 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22162 const struct stacktrace_ops *ops, void *data)
22163 {
22164 const unsigned cpu = get_cpu();
22165 - struct thread_info *tinfo;
22166 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22167 unsigned long dummy;
22168 unsigned used = 0;
22169 int graph = 0;
22170 int done = 0;
22171 + void *stack_start;
22172
22173 if (!task)
22174 task = current;
22175 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22176 * current stack address. If the stacks consist of nested
22177 * exceptions
22178 */
22179 - tinfo = task_thread_info(task);
22180 while (!done) {
22181 unsigned long *stack_end;
22182 enum stack_type stype;
22183 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22184 if (ops->stack(data, id) < 0)
22185 break;
22186
22187 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22188 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22189 data, stack_end, &graph);
22190 ops->stack(data, "<EOE>");
22191 /*
22192 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22193 * second-to-last pointer (index -2 to end) in the
22194 * exception stack:
22195 */
22196 + if ((u16)stack_end[-1] != __KERNEL_DS)
22197 + goto out;
22198 stack = (unsigned long *) stack_end[-2];
22199 done = 0;
22200 break;
22201 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22202
22203 if (ops->stack(data, "IRQ") < 0)
22204 break;
22205 - bp = ops->walk_stack(tinfo, stack, bp,
22206 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22207 ops, data, stack_end, &graph);
22208 /*
22209 * We link to the next stack (which would be
22210 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22211 /*
22212 * This handles the process stack:
22213 */
22214 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22215 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22216 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22217 +out:
22218 put_cpu();
22219 }
22220 EXPORT_SYMBOL(dump_trace);
22221 @@ -344,8 +347,55 @@ int is_valid_bugaddr(unsigned long ip)
22222 {
22223 unsigned short ud2;
22224
22225 - if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
22226 + if (probe_kernel_address((unsigned short *)ip, ud2))
22227 return 0;
22228
22229 return ud2 == 0x0b0f;
22230 }
22231 +
22232 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22233 +void pax_check_alloca(unsigned long size)
22234 +{
22235 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22236 + unsigned cpu, used;
22237 + char *id;
22238 +
22239 + /* check the process stack first */
22240 + stack_start = (unsigned long)task_stack_page(current);
22241 + stack_end = stack_start + THREAD_SIZE;
22242 + if (likely(stack_start <= sp && sp < stack_end)) {
22243 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22244 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22245 + return;
22246 + }
22247 +
22248 + cpu = get_cpu();
22249 +
22250 + /* check the irq stacks */
22251 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22252 + stack_start = stack_end - IRQ_STACK_SIZE;
22253 + if (stack_start <= sp && sp < stack_end) {
22254 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22255 + put_cpu();
22256 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22257 + return;
22258 + }
22259 +
22260 + /* check the exception stacks */
22261 + used = 0;
22262 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22263 + stack_start = stack_end - EXCEPTION_STKSZ;
22264 + if (stack_end && stack_start <= sp && sp < stack_end) {
22265 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22266 + put_cpu();
22267 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22268 + return;
22269 + }
22270 +
22271 + put_cpu();
22272 +
22273 + /* unknown stack */
22274 + BUG();
22275 +}
22276 +EXPORT_SYMBOL(pax_check_alloca);
22277 +#endif
22278 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22279 index 49f8864..1cc6d07 100644
22280 --- a/arch/x86/kernel/e820.c
22281 +++ b/arch/x86/kernel/e820.c
22282 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22283
22284 static void early_panic(char *msg)
22285 {
22286 - early_printk(msg);
22287 - panic(msg);
22288 + early_printk("%s", msg);
22289 + panic("%s", msg);
22290 }
22291
22292 static int userdef __initdata;
22293 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22294 index 01d1c18..8073693 100644
22295 --- a/arch/x86/kernel/early_printk.c
22296 +++ b/arch/x86/kernel/early_printk.c
22297 @@ -7,6 +7,7 @@
22298 #include <linux/pci_regs.h>
22299 #include <linux/pci_ids.h>
22300 #include <linux/errno.h>
22301 +#include <linux/sched.h>
22302 #include <asm/io.h>
22303 #include <asm/processor.h>
22304 #include <asm/fcntl.h>
22305 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22306 index 344b63f..55adf14 100644
22307 --- a/arch/x86/kernel/entry_32.S
22308 +++ b/arch/x86/kernel/entry_32.S
22309 @@ -177,13 +177,154 @@
22310 /*CFI_REL_OFFSET gs, PT_GS*/
22311 .endm
22312 .macro SET_KERNEL_GS reg
22313 +
22314 +#ifdef CONFIG_CC_STACKPROTECTOR
22315 movl $(__KERNEL_STACK_CANARY), \reg
22316 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22317 + movl $(__USER_DS), \reg
22318 +#else
22319 + xorl \reg, \reg
22320 +#endif
22321 +
22322 movl \reg, %gs
22323 .endm
22324
22325 #endif /* CONFIG_X86_32_LAZY_GS */
22326
22327 -.macro SAVE_ALL
22328 +.macro pax_enter_kernel
22329 +#ifdef CONFIG_PAX_KERNEXEC
22330 + call pax_enter_kernel
22331 +#endif
22332 +.endm
22333 +
22334 +.macro pax_exit_kernel
22335 +#ifdef CONFIG_PAX_KERNEXEC
22336 + call pax_exit_kernel
22337 +#endif
22338 +.endm
22339 +
22340 +#ifdef CONFIG_PAX_KERNEXEC
22341 +ENTRY(pax_enter_kernel)
22342 +#ifdef CONFIG_PARAVIRT
22343 + pushl %eax
22344 + pushl %ecx
22345 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22346 + mov %eax, %esi
22347 +#else
22348 + mov %cr0, %esi
22349 +#endif
22350 + bts $16, %esi
22351 + jnc 1f
22352 + mov %cs, %esi
22353 + cmp $__KERNEL_CS, %esi
22354 + jz 3f
22355 + ljmp $__KERNEL_CS, $3f
22356 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22357 +2:
22358 +#ifdef CONFIG_PARAVIRT
22359 + mov %esi, %eax
22360 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22361 +#else
22362 + mov %esi, %cr0
22363 +#endif
22364 +3:
22365 +#ifdef CONFIG_PARAVIRT
22366 + popl %ecx
22367 + popl %eax
22368 +#endif
22369 + ret
22370 +ENDPROC(pax_enter_kernel)
22371 +
22372 +ENTRY(pax_exit_kernel)
22373 +#ifdef CONFIG_PARAVIRT
22374 + pushl %eax
22375 + pushl %ecx
22376 +#endif
22377 + mov %cs, %esi
22378 + cmp $__KERNEXEC_KERNEL_CS, %esi
22379 + jnz 2f
22380 +#ifdef CONFIG_PARAVIRT
22381 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22382 + mov %eax, %esi
22383 +#else
22384 + mov %cr0, %esi
22385 +#endif
22386 + btr $16, %esi
22387 + ljmp $__KERNEL_CS, $1f
22388 +1:
22389 +#ifdef CONFIG_PARAVIRT
22390 + mov %esi, %eax
22391 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22392 +#else
22393 + mov %esi, %cr0
22394 +#endif
22395 +2:
22396 +#ifdef CONFIG_PARAVIRT
22397 + popl %ecx
22398 + popl %eax
22399 +#endif
22400 + ret
22401 +ENDPROC(pax_exit_kernel)
22402 +#endif
22403 +
22404 + .macro pax_erase_kstack
22405 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22406 + call pax_erase_kstack
22407 +#endif
22408 + .endm
22409 +
22410 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22411 +/*
22412 + * ebp: thread_info
22413 + */
22414 +ENTRY(pax_erase_kstack)
22415 + pushl %edi
22416 + pushl %ecx
22417 + pushl %eax
22418 +
22419 + mov TI_lowest_stack(%ebp), %edi
22420 + mov $-0xBEEF, %eax
22421 + std
22422 +
22423 +1: mov %edi, %ecx
22424 + and $THREAD_SIZE_asm - 1, %ecx
22425 + shr $2, %ecx
22426 + repne scasl
22427 + jecxz 2f
22428 +
22429 + cmp $2*16, %ecx
22430 + jc 2f
22431 +
22432 + mov $2*16, %ecx
22433 + repe scasl
22434 + jecxz 2f
22435 + jne 1b
22436 +
22437 +2: cld
22438 + or $2*4, %edi
22439 + mov %esp, %ecx
22440 + sub %edi, %ecx
22441 +
22442 + cmp $THREAD_SIZE_asm, %ecx
22443 + jb 3f
22444 + ud2
22445 +3:
22446 +
22447 + shr $2, %ecx
22448 + rep stosl
22449 +
22450 + mov TI_task_thread_sp0(%ebp), %edi
22451 + sub $128, %edi
22452 + mov %edi, TI_lowest_stack(%ebp)
22453 +
22454 + popl %eax
22455 + popl %ecx
22456 + popl %edi
22457 + ret
22458 +ENDPROC(pax_erase_kstack)
22459 +#endif
22460 +
22461 +.macro __SAVE_ALL _DS
22462 cld
22463 PUSH_GS
22464 pushl_cfi %fs
22465 @@ -206,7 +347,7 @@
22466 CFI_REL_OFFSET ecx, 0
22467 pushl_cfi %ebx
22468 CFI_REL_OFFSET ebx, 0
22469 - movl $(__USER_DS), %edx
22470 + movl $\_DS, %edx
22471 movl %edx, %ds
22472 movl %edx, %es
22473 movl $(__KERNEL_PERCPU), %edx
22474 @@ -214,6 +355,15 @@
22475 SET_KERNEL_GS %edx
22476 .endm
22477
22478 +.macro SAVE_ALL
22479 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22480 + __SAVE_ALL __KERNEL_DS
22481 + pax_enter_kernel
22482 +#else
22483 + __SAVE_ALL __USER_DS
22484 +#endif
22485 +.endm
22486 +
22487 .macro RESTORE_INT_REGS
22488 popl_cfi %ebx
22489 CFI_RESTORE ebx
22490 @@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22491 popfl_cfi
22492 jmp syscall_exit
22493 CFI_ENDPROC
22494 -END(ret_from_fork)
22495 +ENDPROC(ret_from_fork)
22496
22497 ENTRY(ret_from_kernel_thread)
22498 CFI_STARTPROC
22499 @@ -340,7 +490,15 @@ ret_from_intr:
22500 andl $SEGMENT_RPL_MASK, %eax
22501 #endif
22502 cmpl $USER_RPL, %eax
22503 +
22504 +#ifdef CONFIG_PAX_KERNEXEC
22505 + jae resume_userspace
22506 +
22507 + pax_exit_kernel
22508 + jmp resume_kernel
22509 +#else
22510 jb resume_kernel # not returning to v8086 or userspace
22511 +#endif
22512
22513 ENTRY(resume_userspace)
22514 LOCKDEP_SYS_EXIT
22515 @@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22516 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22517 # int/exception return?
22518 jne work_pending
22519 - jmp restore_all
22520 -END(ret_from_exception)
22521 + jmp restore_all_pax
22522 +ENDPROC(ret_from_exception)
22523
22524 #ifdef CONFIG_PREEMPT
22525 ENTRY(resume_kernel)
22526 @@ -365,7 +523,7 @@ need_resched:
22527 jz restore_all
22528 call preempt_schedule_irq
22529 jmp need_resched
22530 -END(resume_kernel)
22531 +ENDPROC(resume_kernel)
22532 #endif
22533 CFI_ENDPROC
22534
22535 @@ -395,30 +553,45 @@ sysenter_past_esp:
22536 /*CFI_REL_OFFSET cs, 0*/
22537 /*
22538 * Push current_thread_info()->sysenter_return to the stack.
22539 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22540 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22541 */
22542 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22543 + pushl_cfi $0
22544 CFI_REL_OFFSET eip, 0
22545
22546 pushl_cfi %eax
22547 SAVE_ALL
22548 + GET_THREAD_INFO(%ebp)
22549 + movl TI_sysenter_return(%ebp),%ebp
22550 + movl %ebp,PT_EIP(%esp)
22551 ENABLE_INTERRUPTS(CLBR_NONE)
22552
22553 /*
22554 * Load the potential sixth argument from user stack.
22555 * Careful about security.
22556 */
22557 + movl PT_OLDESP(%esp),%ebp
22558 +
22559 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22560 + mov PT_OLDSS(%esp),%ds
22561 +1: movl %ds:(%ebp),%ebp
22562 + push %ss
22563 + pop %ds
22564 +#else
22565 cmpl $__PAGE_OFFSET-3,%ebp
22566 jae syscall_fault
22567 ASM_STAC
22568 1: movl (%ebp),%ebp
22569 ASM_CLAC
22570 +#endif
22571 +
22572 movl %ebp,PT_EBP(%esp)
22573 _ASM_EXTABLE(1b,syscall_fault)
22574
22575 GET_THREAD_INFO(%ebp)
22576
22577 +#ifdef CONFIG_PAX_RANDKSTACK
22578 + pax_erase_kstack
22579 +#endif
22580 +
22581 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22582 jnz sysenter_audit
22583 sysenter_do_call:
22584 @@ -434,12 +607,24 @@ sysenter_after_call:
22585 testl $_TIF_ALLWORK_MASK, %ecx
22586 jne sysexit_audit
22587 sysenter_exit:
22588 +
22589 +#ifdef CONFIG_PAX_RANDKSTACK
22590 + pushl_cfi %eax
22591 + movl %esp, %eax
22592 + call pax_randomize_kstack
22593 + popl_cfi %eax
22594 +#endif
22595 +
22596 + pax_erase_kstack
22597 +
22598 /* if something modifies registers it must also disable sysexit */
22599 movl PT_EIP(%esp), %edx
22600 movl PT_OLDESP(%esp), %ecx
22601 xorl %ebp,%ebp
22602 TRACE_IRQS_ON
22603 1: mov PT_FS(%esp), %fs
22604 +2: mov PT_DS(%esp), %ds
22605 +3: mov PT_ES(%esp), %es
22606 PTGS_TO_GS
22607 ENABLE_INTERRUPTS_SYSEXIT
22608
22609 @@ -453,6 +638,9 @@ sysenter_audit:
22610 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22611 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22612 call __audit_syscall_entry
22613 +
22614 + pax_erase_kstack
22615 +
22616 popl_cfi %ecx /* get that remapped edx off the stack */
22617 popl_cfi %ecx /* get that remapped esi off the stack */
22618 movl PT_EAX(%esp),%eax /* reload syscall number */
22619 @@ -479,10 +667,16 @@ sysexit_audit:
22620
22621 CFI_ENDPROC
22622 .pushsection .fixup,"ax"
22623 -2: movl $0,PT_FS(%esp)
22624 +4: movl $0,PT_FS(%esp)
22625 + jmp 1b
22626 +5: movl $0,PT_DS(%esp)
22627 + jmp 1b
22628 +6: movl $0,PT_ES(%esp)
22629 jmp 1b
22630 .popsection
22631 - _ASM_EXTABLE(1b,2b)
22632 + _ASM_EXTABLE(1b,4b)
22633 + _ASM_EXTABLE(2b,5b)
22634 + _ASM_EXTABLE(3b,6b)
22635 PTGS_TO_GS_EX
22636 ENDPROC(ia32_sysenter_target)
22637
22638 @@ -493,6 +687,11 @@ ENTRY(system_call)
22639 pushl_cfi %eax # save orig_eax
22640 SAVE_ALL
22641 GET_THREAD_INFO(%ebp)
22642 +
22643 +#ifdef CONFIG_PAX_RANDKSTACK
22644 + pax_erase_kstack
22645 +#endif
22646 +
22647 # system call tracing in operation / emulation
22648 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22649 jnz syscall_trace_entry
22650 @@ -512,6 +711,15 @@ syscall_exit:
22651 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22652 jne syscall_exit_work
22653
22654 +restore_all_pax:
22655 +
22656 +#ifdef CONFIG_PAX_RANDKSTACK
22657 + movl %esp, %eax
22658 + call pax_randomize_kstack
22659 +#endif
22660 +
22661 + pax_erase_kstack
22662 +
22663 restore_all:
22664 TRACE_IRQS_IRET
22665 restore_all_notrace:
22666 @@ -566,14 +774,34 @@ ldt_ss:
22667 * compensating for the offset by changing to the ESPFIX segment with
22668 * a base address that matches for the difference.
22669 */
22670 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22671 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22672 mov %esp, %edx /* load kernel esp */
22673 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22674 mov %dx, %ax /* eax: new kernel esp */
22675 sub %eax, %edx /* offset (low word is 0) */
22676 +#ifdef CONFIG_SMP
22677 + movl PER_CPU_VAR(cpu_number), %ebx
22678 + shll $PAGE_SHIFT_asm, %ebx
22679 + addl $cpu_gdt_table, %ebx
22680 +#else
22681 + movl $cpu_gdt_table, %ebx
22682 +#endif
22683 shr $16, %edx
22684 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22685 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22686 +
22687 +#ifdef CONFIG_PAX_KERNEXEC
22688 + mov %cr0, %esi
22689 + btr $16, %esi
22690 + mov %esi, %cr0
22691 +#endif
22692 +
22693 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22694 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22695 +
22696 +#ifdef CONFIG_PAX_KERNEXEC
22697 + bts $16, %esi
22698 + mov %esi, %cr0
22699 +#endif
22700 +
22701 pushl_cfi $__ESPFIX_SS
22702 pushl_cfi %eax /* new kernel esp */
22703 /* Disable interrupts, but do not irqtrace this section: we
22704 @@ -603,20 +831,18 @@ work_resched:
22705 movl TI_flags(%ebp), %ecx
22706 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22707 # than syscall tracing?
22708 - jz restore_all
22709 + jz restore_all_pax
22710 testb $_TIF_NEED_RESCHED, %cl
22711 jnz work_resched
22712
22713 work_notifysig: # deal with pending signals and
22714 # notify-resume requests
22715 + movl %esp, %eax
22716 #ifdef CONFIG_VM86
22717 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22718 - movl %esp, %eax
22719 jne work_notifysig_v86 # returning to kernel-space or
22720 # vm86-space
22721 1:
22722 -#else
22723 - movl %esp, %eax
22724 #endif
22725 TRACE_IRQS_ON
22726 ENABLE_INTERRUPTS(CLBR_NONE)
22727 @@ -637,7 +863,7 @@ work_notifysig_v86:
22728 movl %eax, %esp
22729 jmp 1b
22730 #endif
22731 -END(work_pending)
22732 +ENDPROC(work_pending)
22733
22734 # perform syscall exit tracing
22735 ALIGN
22736 @@ -645,11 +871,14 @@ syscall_trace_entry:
22737 movl $-ENOSYS,PT_EAX(%esp)
22738 movl %esp, %eax
22739 call syscall_trace_enter
22740 +
22741 + pax_erase_kstack
22742 +
22743 /* What it returned is what we'll actually use. */
22744 cmpl $(NR_syscalls), %eax
22745 jnae syscall_call
22746 jmp syscall_exit
22747 -END(syscall_trace_entry)
22748 +ENDPROC(syscall_trace_entry)
22749
22750 # perform syscall exit tracing
22751 ALIGN
22752 @@ -662,26 +891,30 @@ syscall_exit_work:
22753 movl %esp, %eax
22754 call syscall_trace_leave
22755 jmp resume_userspace
22756 -END(syscall_exit_work)
22757 +ENDPROC(syscall_exit_work)
22758 CFI_ENDPROC
22759
22760 RING0_INT_FRAME # can't unwind into user space anyway
22761 syscall_fault:
22762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22763 + push %ss
22764 + pop %ds
22765 +#endif
22766 ASM_CLAC
22767 GET_THREAD_INFO(%ebp)
22768 movl $-EFAULT,PT_EAX(%esp)
22769 jmp resume_userspace
22770 -END(syscall_fault)
22771 +ENDPROC(syscall_fault)
22772
22773 syscall_badsys:
22774 movl $-ENOSYS,%eax
22775 jmp syscall_after_call
22776 -END(syscall_badsys)
22777 +ENDPROC(syscall_badsys)
22778
22779 sysenter_badsys:
22780 movl $-ENOSYS,%eax
22781 jmp sysenter_after_call
22782 -END(sysenter_badsys)
22783 +ENDPROC(sysenter_badsys)
22784 CFI_ENDPROC
22785
22786 .macro FIXUP_ESPFIX_STACK
22787 @@ -694,8 +927,15 @@ END(sysenter_badsys)
22788 */
22789 #ifdef CONFIG_X86_ESPFIX32
22790 /* fixup the stack */
22791 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22792 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22793 +#ifdef CONFIG_SMP
22794 + movl PER_CPU_VAR(cpu_number), %ebx
22795 + shll $PAGE_SHIFT_asm, %ebx
22796 + addl $cpu_gdt_table, %ebx
22797 +#else
22798 + movl $cpu_gdt_table, %ebx
22799 +#endif
22800 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22801 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22802 shl $16, %eax
22803 addl %esp, %eax /* the adjusted stack pointer */
22804 pushl_cfi $__KERNEL_DS
22805 @@ -751,7 +991,7 @@ vector=vector+1
22806 .endr
22807 2: jmp common_interrupt
22808 .endr
22809 -END(irq_entries_start)
22810 +ENDPROC(irq_entries_start)
22811
22812 .previous
22813 END(interrupt)
22814 @@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22815 pushl_cfi $do_coprocessor_error
22816 jmp error_code
22817 CFI_ENDPROC
22818 -END(coprocessor_error)
22819 +ENDPROC(coprocessor_error)
22820
22821 ENTRY(simd_coprocessor_error)
22822 RING0_INT_FRAME
22823 @@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22824 .section .altinstructions,"a"
22825 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22826 .previous
22827 -.section .altinstr_replacement,"ax"
22828 +.section .altinstr_replacement,"a"
22829 663: pushl $do_simd_coprocessor_error
22830 664:
22831 .previous
22832 @@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22833 #endif
22834 jmp error_code
22835 CFI_ENDPROC
22836 -END(simd_coprocessor_error)
22837 +ENDPROC(simd_coprocessor_error)
22838
22839 ENTRY(device_not_available)
22840 RING0_INT_FRAME
22841 @@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22842 pushl_cfi $do_device_not_available
22843 jmp error_code
22844 CFI_ENDPROC
22845 -END(device_not_available)
22846 +ENDPROC(device_not_available)
22847
22848 #ifdef CONFIG_PARAVIRT
22849 ENTRY(native_iret)
22850 iret
22851 _ASM_EXTABLE(native_iret, iret_exc)
22852 -END(native_iret)
22853 +ENDPROC(native_iret)
22854
22855 ENTRY(native_irq_enable_sysexit)
22856 sti
22857 sysexit
22858 -END(native_irq_enable_sysexit)
22859 +ENDPROC(native_irq_enable_sysexit)
22860 #endif
22861
22862 ENTRY(overflow)
22863 @@ -860,7 +1100,7 @@ ENTRY(overflow)
22864 pushl_cfi $do_overflow
22865 jmp error_code
22866 CFI_ENDPROC
22867 -END(overflow)
22868 +ENDPROC(overflow)
22869
22870 ENTRY(bounds)
22871 RING0_INT_FRAME
22872 @@ -869,7 +1109,7 @@ ENTRY(bounds)
22873 pushl_cfi $do_bounds
22874 jmp error_code
22875 CFI_ENDPROC
22876 -END(bounds)
22877 +ENDPROC(bounds)
22878
22879 ENTRY(invalid_op)
22880 RING0_INT_FRAME
22881 @@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22882 pushl_cfi $do_invalid_op
22883 jmp error_code
22884 CFI_ENDPROC
22885 -END(invalid_op)
22886 +ENDPROC(invalid_op)
22887
22888 ENTRY(coprocessor_segment_overrun)
22889 RING0_INT_FRAME
22890 @@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22891 pushl_cfi $do_coprocessor_segment_overrun
22892 jmp error_code
22893 CFI_ENDPROC
22894 -END(coprocessor_segment_overrun)
22895 +ENDPROC(coprocessor_segment_overrun)
22896
22897 ENTRY(invalid_TSS)
22898 RING0_EC_FRAME
22899 @@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22900 pushl_cfi $do_invalid_TSS
22901 jmp error_code
22902 CFI_ENDPROC
22903 -END(invalid_TSS)
22904 +ENDPROC(invalid_TSS)
22905
22906 ENTRY(segment_not_present)
22907 RING0_EC_FRAME
22908 @@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22909 pushl_cfi $do_segment_not_present
22910 jmp error_code
22911 CFI_ENDPROC
22912 -END(segment_not_present)
22913 +ENDPROC(segment_not_present)
22914
22915 ENTRY(stack_segment)
22916 RING0_EC_FRAME
22917 @@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22918 pushl_cfi $do_stack_segment
22919 jmp error_code
22920 CFI_ENDPROC
22921 -END(stack_segment)
22922 +ENDPROC(stack_segment)
22923
22924 ENTRY(alignment_check)
22925 RING0_EC_FRAME
22926 @@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22927 pushl_cfi $do_alignment_check
22928 jmp error_code
22929 CFI_ENDPROC
22930 -END(alignment_check)
22931 +ENDPROC(alignment_check)
22932
22933 ENTRY(divide_error)
22934 RING0_INT_FRAME
22935 @@ -928,7 +1168,7 @@ ENTRY(divide_error)
22936 pushl_cfi $do_divide_error
22937 jmp error_code
22938 CFI_ENDPROC
22939 -END(divide_error)
22940 +ENDPROC(divide_error)
22941
22942 #ifdef CONFIG_X86_MCE
22943 ENTRY(machine_check)
22944 @@ -938,7 +1178,7 @@ ENTRY(machine_check)
22945 pushl_cfi machine_check_vector
22946 jmp error_code
22947 CFI_ENDPROC
22948 -END(machine_check)
22949 +ENDPROC(machine_check)
22950 #endif
22951
22952 ENTRY(spurious_interrupt_bug)
22953 @@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22954 pushl_cfi $do_spurious_interrupt_bug
22955 jmp error_code
22956 CFI_ENDPROC
22957 -END(spurious_interrupt_bug)
22958 +ENDPROC(spurious_interrupt_bug)
22959
22960 #ifdef CONFIG_XEN
22961 /* Xen doesn't set %esp to be precisely what the normal sysenter
22962 @@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22963
22964 ENTRY(mcount)
22965 ret
22966 -END(mcount)
22967 +ENDPROC(mcount)
22968
22969 ENTRY(ftrace_caller)
22970 pushl %eax
22971 @@ -1084,7 +1324,7 @@ ftrace_graph_call:
22972 .globl ftrace_stub
22973 ftrace_stub:
22974 ret
22975 -END(ftrace_caller)
22976 +ENDPROC(ftrace_caller)
22977
22978 ENTRY(ftrace_regs_caller)
22979 pushf /* push flags before compare (in cs location) */
22980 @@ -1182,7 +1422,7 @@ trace:
22981 popl %ecx
22982 popl %eax
22983 jmp ftrace_stub
22984 -END(mcount)
22985 +ENDPROC(mcount)
22986 #endif /* CONFIG_DYNAMIC_FTRACE */
22987 #endif /* CONFIG_FUNCTION_TRACER */
22988
22989 @@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
22990 popl %ecx
22991 popl %eax
22992 ret
22993 -END(ftrace_graph_caller)
22994 +ENDPROC(ftrace_graph_caller)
22995
22996 .globl return_to_handler
22997 return_to_handler:
22998 @@ -1261,15 +1501,18 @@ error_code:
22999 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23000 REG_TO_PTGS %ecx
23001 SET_KERNEL_GS %ecx
23002 - movl $(__USER_DS), %ecx
23003 + movl $(__KERNEL_DS), %ecx
23004 movl %ecx, %ds
23005 movl %ecx, %es
23006 +
23007 + pax_enter_kernel
23008 +
23009 TRACE_IRQS_OFF
23010 movl %esp,%eax # pt_regs pointer
23011 call *%edi
23012 jmp ret_from_exception
23013 CFI_ENDPROC
23014 -END(page_fault)
23015 +ENDPROC(page_fault)
23016
23017 /*
23018 * Debug traps and NMI can happen at the one SYSENTER instruction
23019 @@ -1312,7 +1555,7 @@ debug_stack_correct:
23020 call do_debug
23021 jmp ret_from_exception
23022 CFI_ENDPROC
23023 -END(debug)
23024 +ENDPROC(debug)
23025
23026 /*
23027 * NMI is doubly nasty. It can happen _while_ we're handling
23028 @@ -1352,6 +1595,9 @@ nmi_stack_correct:
23029 xorl %edx,%edx # zero error code
23030 movl %esp,%eax # pt_regs pointer
23031 call do_nmi
23032 +
23033 + pax_exit_kernel
23034 +
23035 jmp restore_all_notrace
23036 CFI_ENDPROC
23037
23038 @@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23039 FIXUP_ESPFIX_STACK # %eax == %esp
23040 xorl %edx,%edx # zero error code
23041 call do_nmi
23042 +
23043 + pax_exit_kernel
23044 +
23045 RESTORE_REGS
23046 lss 12+4(%esp), %esp # back to espfix stack
23047 CFI_ADJUST_CFA_OFFSET -24
23048 jmp irq_return
23049 #endif
23050 CFI_ENDPROC
23051 -END(nmi)
23052 +ENDPROC(nmi)
23053
23054 ENTRY(int3)
23055 RING0_INT_FRAME
23056 @@ -1408,14 +1657,14 @@ ENTRY(int3)
23057 call do_int3
23058 jmp ret_from_exception
23059 CFI_ENDPROC
23060 -END(int3)
23061 +ENDPROC(int3)
23062
23063 ENTRY(general_protection)
23064 RING0_EC_FRAME
23065 pushl_cfi $do_general_protection
23066 jmp error_code
23067 CFI_ENDPROC
23068 -END(general_protection)
23069 +ENDPROC(general_protection)
23070
23071 #ifdef CONFIG_KVM_GUEST
23072 ENTRY(async_page_fault)
23073 @@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23074 pushl_cfi $do_async_page_fault
23075 jmp error_code
23076 CFI_ENDPROC
23077 -END(async_page_fault)
23078 +ENDPROC(async_page_fault)
23079 #endif
23080
23081 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23082 index c0226ab..0d1dc48 100644
23083 --- a/arch/x86/kernel/entry_64.S
23084 +++ b/arch/x86/kernel/entry_64.S
23085 @@ -59,6 +59,8 @@
23086 #include <asm/smap.h>
23087 #include <asm/pgtable_types.h>
23088 #include <linux/err.h>
23089 +#include <asm/pgtable.h>
23090 +#include <asm/alternative-asm.h>
23091
23092 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23093 #include <linux/elf-em.h>
23094 @@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23095 ENDPROC(native_usergs_sysret64)
23096 #endif /* CONFIG_PARAVIRT */
23097
23098 + .macro ljmpq sel, off
23099 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23100 + .byte 0x48; ljmp *1234f(%rip)
23101 + .pushsection .rodata
23102 + .align 16
23103 + 1234: .quad \off; .word \sel
23104 + .popsection
23105 +#else
23106 + pushq $\sel
23107 + pushq $\off
23108 + lretq
23109 +#endif
23110 + .endm
23111 +
23112 + .macro pax_enter_kernel
23113 + pax_set_fptr_mask
23114 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23115 + call pax_enter_kernel
23116 +#endif
23117 + .endm
23118 +
23119 + .macro pax_exit_kernel
23120 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23121 + call pax_exit_kernel
23122 +#endif
23123 +
23124 + .endm
23125 +
23126 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23127 +ENTRY(pax_enter_kernel)
23128 + pushq %rdi
23129 +
23130 +#ifdef CONFIG_PARAVIRT
23131 + PV_SAVE_REGS(CLBR_RDI)
23132 +#endif
23133 +
23134 +#ifdef CONFIG_PAX_KERNEXEC
23135 + GET_CR0_INTO_RDI
23136 + bts $16,%rdi
23137 + jnc 3f
23138 + mov %cs,%edi
23139 + cmp $__KERNEL_CS,%edi
23140 + jnz 2f
23141 +1:
23142 +#endif
23143 +
23144 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23145 + 661: jmp 111f
23146 + .pushsection .altinstr_replacement, "a"
23147 + 662: ASM_NOP2
23148 + .popsection
23149 + .pushsection .altinstructions, "a"
23150 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23151 + .popsection
23152 + GET_CR3_INTO_RDI
23153 + cmp $0,%dil
23154 + jnz 112f
23155 + mov $__KERNEL_DS,%edi
23156 + mov %edi,%ss
23157 + jmp 111f
23158 +112: cmp $1,%dil
23159 + jz 113f
23160 + ud2
23161 +113: sub $4097,%rdi
23162 + bts $63,%rdi
23163 + SET_RDI_INTO_CR3
23164 + mov $__UDEREF_KERNEL_DS,%edi
23165 + mov %edi,%ss
23166 +111:
23167 +#endif
23168 +
23169 +#ifdef CONFIG_PARAVIRT
23170 + PV_RESTORE_REGS(CLBR_RDI)
23171 +#endif
23172 +
23173 + popq %rdi
23174 + pax_force_retaddr
23175 + retq
23176 +
23177 +#ifdef CONFIG_PAX_KERNEXEC
23178 +2: ljmpq __KERNEL_CS,1b
23179 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23180 +4: SET_RDI_INTO_CR0
23181 + jmp 1b
23182 +#endif
23183 +ENDPROC(pax_enter_kernel)
23184 +
23185 +ENTRY(pax_exit_kernel)
23186 + pushq %rdi
23187 +
23188 +#ifdef CONFIG_PARAVIRT
23189 + PV_SAVE_REGS(CLBR_RDI)
23190 +#endif
23191 +
23192 +#ifdef CONFIG_PAX_KERNEXEC
23193 + mov %cs,%rdi
23194 + cmp $__KERNEXEC_KERNEL_CS,%edi
23195 + jz 2f
23196 + GET_CR0_INTO_RDI
23197 + bts $16,%rdi
23198 + jnc 4f
23199 +1:
23200 +#endif
23201 +
23202 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23203 + 661: jmp 111f
23204 + .pushsection .altinstr_replacement, "a"
23205 + 662: ASM_NOP2
23206 + .popsection
23207 + .pushsection .altinstructions, "a"
23208 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23209 + .popsection
23210 + mov %ss,%edi
23211 + cmp $__UDEREF_KERNEL_DS,%edi
23212 + jnz 111f
23213 + GET_CR3_INTO_RDI
23214 + cmp $0,%dil
23215 + jz 112f
23216 + ud2
23217 +112: add $4097,%rdi
23218 + bts $63,%rdi
23219 + SET_RDI_INTO_CR3
23220 + mov $__KERNEL_DS,%edi
23221 + mov %edi,%ss
23222 +111:
23223 +#endif
23224 +
23225 +#ifdef CONFIG_PARAVIRT
23226 + PV_RESTORE_REGS(CLBR_RDI);
23227 +#endif
23228 +
23229 + popq %rdi
23230 + pax_force_retaddr
23231 + retq
23232 +
23233 +#ifdef CONFIG_PAX_KERNEXEC
23234 +2: GET_CR0_INTO_RDI
23235 + btr $16,%rdi
23236 + jnc 4f
23237 + ljmpq __KERNEL_CS,3f
23238 +3: SET_RDI_INTO_CR0
23239 + jmp 1b
23240 +4: ud2
23241 + jmp 4b
23242 +#endif
23243 +ENDPROC(pax_exit_kernel)
23244 +#endif
23245 +
23246 + .macro pax_enter_kernel_user
23247 + pax_set_fptr_mask
23248 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23249 + call pax_enter_kernel_user
23250 +#endif
23251 + .endm
23252 +
23253 + .macro pax_exit_kernel_user
23254 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23255 + call pax_exit_kernel_user
23256 +#endif
23257 +#ifdef CONFIG_PAX_RANDKSTACK
23258 + pushq %rax
23259 + pushq %r11
23260 + call pax_randomize_kstack
23261 + popq %r11
23262 + popq %rax
23263 +#endif
23264 + .endm
23265 +
23266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23267 +ENTRY(pax_enter_kernel_user)
23268 + pushq %rdi
23269 + pushq %rbx
23270 +
23271 +#ifdef CONFIG_PARAVIRT
23272 + PV_SAVE_REGS(CLBR_RDI)
23273 +#endif
23274 +
23275 + 661: jmp 111f
23276 + .pushsection .altinstr_replacement, "a"
23277 + 662: ASM_NOP2
23278 + .popsection
23279 + .pushsection .altinstructions, "a"
23280 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23281 + .popsection
23282 + GET_CR3_INTO_RDI
23283 + cmp $1,%dil
23284 + jnz 4f
23285 + sub $4097,%rdi
23286 + bts $63,%rdi
23287 + SET_RDI_INTO_CR3
23288 + jmp 3f
23289 +111:
23290 +
23291 + GET_CR3_INTO_RDI
23292 + mov %rdi,%rbx
23293 + add $__START_KERNEL_map,%rbx
23294 + sub phys_base(%rip),%rbx
23295 +
23296 +#ifdef CONFIG_PARAVIRT
23297 + cmpl $0, pv_info+PARAVIRT_enabled
23298 + jz 1f
23299 + pushq %rdi
23300 + i = 0
23301 + .rept USER_PGD_PTRS
23302 + mov i*8(%rbx),%rsi
23303 + mov $0,%sil
23304 + lea i*8(%rbx),%rdi
23305 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23306 + i = i + 1
23307 + .endr
23308 + popq %rdi
23309 + jmp 2f
23310 +1:
23311 +#endif
23312 +
23313 + i = 0
23314 + .rept USER_PGD_PTRS
23315 + movb $0,i*8(%rbx)
23316 + i = i + 1
23317 + .endr
23318 +
23319 +2: SET_RDI_INTO_CR3
23320 +
23321 +#ifdef CONFIG_PAX_KERNEXEC
23322 + GET_CR0_INTO_RDI
23323 + bts $16,%rdi
23324 + SET_RDI_INTO_CR0
23325 +#endif
23326 +
23327 +3:
23328 +
23329 +#ifdef CONFIG_PARAVIRT
23330 + PV_RESTORE_REGS(CLBR_RDI)
23331 +#endif
23332 +
23333 + popq %rbx
23334 + popq %rdi
23335 + pax_force_retaddr
23336 + retq
23337 +4: ud2
23338 +ENDPROC(pax_enter_kernel_user)
23339 +
23340 +ENTRY(pax_exit_kernel_user)
23341 + pushq %rdi
23342 + pushq %rbx
23343 +
23344 +#ifdef CONFIG_PARAVIRT
23345 + PV_SAVE_REGS(CLBR_RDI)
23346 +#endif
23347 +
23348 + GET_CR3_INTO_RDI
23349 + 661: jmp 1f
23350 + .pushsection .altinstr_replacement, "a"
23351 + 662: ASM_NOP2
23352 + .popsection
23353 + .pushsection .altinstructions, "a"
23354 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23355 + .popsection
23356 + cmp $0,%dil
23357 + jnz 3f
23358 + add $4097,%rdi
23359 + bts $63,%rdi
23360 + SET_RDI_INTO_CR3
23361 + jmp 2f
23362 +1:
23363 +
23364 + mov %rdi,%rbx
23365 +
23366 +#ifdef CONFIG_PAX_KERNEXEC
23367 + GET_CR0_INTO_RDI
23368 + btr $16,%rdi
23369 + jnc 3f
23370 + SET_RDI_INTO_CR0
23371 +#endif
23372 +
23373 + add $__START_KERNEL_map,%rbx
23374 + sub phys_base(%rip),%rbx
23375 +
23376 +#ifdef CONFIG_PARAVIRT
23377 + cmpl $0, pv_info+PARAVIRT_enabled
23378 + jz 1f
23379 + i = 0
23380 + .rept USER_PGD_PTRS
23381 + mov i*8(%rbx),%rsi
23382 + mov $0x67,%sil
23383 + lea i*8(%rbx),%rdi
23384 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23385 + i = i + 1
23386 + .endr
23387 + jmp 2f
23388 +1:
23389 +#endif
23390 +
23391 + i = 0
23392 + .rept USER_PGD_PTRS
23393 + movb $0x67,i*8(%rbx)
23394 + i = i + 1
23395 + .endr
23396 +2:
23397 +
23398 +#ifdef CONFIG_PARAVIRT
23399 + PV_RESTORE_REGS(CLBR_RDI)
23400 +#endif
23401 +
23402 + popq %rbx
23403 + popq %rdi
23404 + pax_force_retaddr
23405 + retq
23406 +3: ud2
23407 +ENDPROC(pax_exit_kernel_user)
23408 +#endif
23409 +
23410 + .macro pax_enter_kernel_nmi
23411 + pax_set_fptr_mask
23412 +
23413 +#ifdef CONFIG_PAX_KERNEXEC
23414 + GET_CR0_INTO_RDI
23415 + bts $16,%rdi
23416 + jc 110f
23417 + SET_RDI_INTO_CR0
23418 + or $2,%ebx
23419 +110:
23420 +#endif
23421 +
23422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23423 + 661: jmp 111f
23424 + .pushsection .altinstr_replacement, "a"
23425 + 662: ASM_NOP2
23426 + .popsection
23427 + .pushsection .altinstructions, "a"
23428 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23429 + .popsection
23430 + GET_CR3_INTO_RDI
23431 + cmp $0,%dil
23432 + jz 111f
23433 + sub $4097,%rdi
23434 + or $4,%ebx
23435 + bts $63,%rdi
23436 + SET_RDI_INTO_CR3
23437 + mov $__UDEREF_KERNEL_DS,%edi
23438 + mov %edi,%ss
23439 +111:
23440 +#endif
23441 + .endm
23442 +
23443 + .macro pax_exit_kernel_nmi
23444 +#ifdef CONFIG_PAX_KERNEXEC
23445 + btr $1,%ebx
23446 + jnc 110f
23447 + GET_CR0_INTO_RDI
23448 + btr $16,%rdi
23449 + SET_RDI_INTO_CR0
23450 +110:
23451 +#endif
23452 +
23453 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23454 + btr $2,%ebx
23455 + jnc 111f
23456 + GET_CR3_INTO_RDI
23457 + add $4097,%rdi
23458 + bts $63,%rdi
23459 + SET_RDI_INTO_CR3
23460 + mov $__KERNEL_DS,%edi
23461 + mov %edi,%ss
23462 +111:
23463 +#endif
23464 + .endm
23465 +
23466 + .macro pax_erase_kstack
23467 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23468 + call pax_erase_kstack
23469 +#endif
23470 + .endm
23471 +
23472 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23473 +ENTRY(pax_erase_kstack)
23474 + pushq %rdi
23475 + pushq %rcx
23476 + pushq %rax
23477 + pushq %r11
23478 +
23479 + GET_THREAD_INFO(%r11)
23480 + mov TI_lowest_stack(%r11), %rdi
23481 + mov $-0xBEEF, %rax
23482 + std
23483 +
23484 +1: mov %edi, %ecx
23485 + and $THREAD_SIZE_asm - 1, %ecx
23486 + shr $3, %ecx
23487 + repne scasq
23488 + jecxz 2f
23489 +
23490 + cmp $2*8, %ecx
23491 + jc 2f
23492 +
23493 + mov $2*8, %ecx
23494 + repe scasq
23495 + jecxz 2f
23496 + jne 1b
23497 +
23498 +2: cld
23499 + or $2*8, %rdi
23500 + mov %esp, %ecx
23501 + sub %edi, %ecx
23502 +
23503 + cmp $THREAD_SIZE_asm, %rcx
23504 + jb 3f
23505 + ud2
23506 +3:
23507 +
23508 + shr $3, %ecx
23509 + rep stosq
23510 +
23511 + mov TI_task_thread_sp0(%r11), %rdi
23512 + sub $256, %rdi
23513 + mov %rdi, TI_lowest_stack(%r11)
23514 +
23515 + popq %r11
23516 + popq %rax
23517 + popq %rcx
23518 + popq %rdi
23519 + pax_force_retaddr
23520 + ret
23521 +ENDPROC(pax_erase_kstack)
23522 +#endif
23523
23524 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23525 #ifdef CONFIG_TRACE_IRQFLAGS
23526 @@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23527 .endm
23528
23529 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23530 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23531 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23532 jnc 1f
23533 TRACE_IRQS_ON_DEBUG
23534 1:
23535 @@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23536 movq \tmp,R11+\offset(%rsp)
23537 .endm
23538
23539 - .macro FAKE_STACK_FRAME child_rip
23540 - /* push in order ss, rsp, eflags, cs, rip */
23541 - xorl %eax, %eax
23542 - pushq_cfi $__KERNEL_DS /* ss */
23543 - /*CFI_REL_OFFSET ss,0*/
23544 - pushq_cfi %rax /* rsp */
23545 - CFI_REL_OFFSET rsp,0
23546 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23547 - /*CFI_REL_OFFSET rflags,0*/
23548 - pushq_cfi $__KERNEL_CS /* cs */
23549 - /*CFI_REL_OFFSET cs,0*/
23550 - pushq_cfi \child_rip /* rip */
23551 - CFI_REL_OFFSET rip,0
23552 - pushq_cfi %rax /* orig rax */
23553 - .endm
23554 -
23555 - .macro UNFAKE_STACK_FRAME
23556 - addq $8*6, %rsp
23557 - CFI_ADJUST_CFA_OFFSET -(6*8)
23558 - .endm
23559 -
23560 /*
23561 * initial frame state for interrupts (and exceptions without error code)
23562 */
23563 @@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23564 /* save partial stack frame */
23565 .macro SAVE_ARGS_IRQ
23566 cld
23567 - /* start from rbp in pt_regs and jump over */
23568 - movq_cfi rdi, (RDI-RBP)
23569 - movq_cfi rsi, (RSI-RBP)
23570 - movq_cfi rdx, (RDX-RBP)
23571 - movq_cfi rcx, (RCX-RBP)
23572 - movq_cfi rax, (RAX-RBP)
23573 - movq_cfi r8, (R8-RBP)
23574 - movq_cfi r9, (R9-RBP)
23575 - movq_cfi r10, (R10-RBP)
23576 - movq_cfi r11, (R11-RBP)
23577 + /* start from r15 in pt_regs and jump over */
23578 + movq_cfi rdi, RDI
23579 + movq_cfi rsi, RSI
23580 + movq_cfi rdx, RDX
23581 + movq_cfi rcx, RCX
23582 + movq_cfi rax, RAX
23583 + movq_cfi r8, R8
23584 + movq_cfi r9, R9
23585 + movq_cfi r10, R10
23586 + movq_cfi r11, R11
23587 + movq_cfi r12, R12
23588
23589 /* Save rbp so that we can unwind from get_irq_regs() */
23590 - movq_cfi rbp, 0
23591 + movq_cfi rbp, RBP
23592
23593 /* Save previous stack value */
23594 movq %rsp, %rsi
23595
23596 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23597 - testl $3, CS-RBP(%rsi)
23598 + movq %rsp,%rdi /* arg1 for handler */
23599 + testb $3, CS(%rsi)
23600 je 1f
23601 SWAPGS
23602 /*
23603 @@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23604 0x06 /* DW_OP_deref */, \
23605 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23606 0x22 /* DW_OP_plus */
23607 +
23608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23609 + testb $3, CS(%rdi)
23610 + jnz 1f
23611 + pax_enter_kernel
23612 + jmp 2f
23613 +1: pax_enter_kernel_user
23614 +2:
23615 +#else
23616 + pax_enter_kernel
23617 +#endif
23618 +
23619 /* We entered an interrupt context - irqs are off: */
23620 TRACE_IRQS_OFF
23621 .endm
23622 @@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23623 js 1f /* negative -> in kernel */
23624 SWAPGS
23625 xorl %ebx,%ebx
23626 -1: ret
23627 +1:
23628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23629 + testb $3, CS+8(%rsp)
23630 + jnz 1f
23631 + pax_enter_kernel
23632 + jmp 2f
23633 +1: pax_enter_kernel_user
23634 +2:
23635 +#else
23636 + pax_enter_kernel
23637 +#endif
23638 + pax_force_retaddr
23639 + ret
23640 CFI_ENDPROC
23641 -END(save_paranoid)
23642 +ENDPROC(save_paranoid)
23643 +
23644 +ENTRY(save_paranoid_nmi)
23645 + XCPT_FRAME 1 RDI+8
23646 + cld
23647 + movq_cfi rdi, RDI+8
23648 + movq_cfi rsi, RSI+8
23649 + movq_cfi rdx, RDX+8
23650 + movq_cfi rcx, RCX+8
23651 + movq_cfi rax, RAX+8
23652 + movq_cfi r8, R8+8
23653 + movq_cfi r9, R9+8
23654 + movq_cfi r10, R10+8
23655 + movq_cfi r11, R11+8
23656 + movq_cfi rbx, RBX+8
23657 + movq_cfi rbp, RBP+8
23658 + movq_cfi r12, R12+8
23659 + movq_cfi r13, R13+8
23660 + movq_cfi r14, R14+8
23661 + movq_cfi r15, R15+8
23662 + movl $1,%ebx
23663 + movl $MSR_GS_BASE,%ecx
23664 + rdmsr
23665 + testl %edx,%edx
23666 + js 1f /* negative -> in kernel */
23667 + SWAPGS
23668 + xorl %ebx,%ebx
23669 +1: pax_enter_kernel_nmi
23670 + pax_force_retaddr
23671 + ret
23672 + CFI_ENDPROC
23673 +ENDPROC(save_paranoid_nmi)
23674
23675 /*
23676 * A newly forked process directly context switches into this address.
23677 @@ -331,7 +793,7 @@ ENTRY(ret_from_fork)
23678
23679 RESTORE_REST
23680
23681 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23682 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23683 jz 1f
23684
23685 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23686 @@ -341,15 +803,13 @@ ENTRY(ret_from_fork)
23687 jmp ret_from_sys_call # go to the SYSRET fastpath
23688
23689 1:
23690 - subq $REST_SKIP, %rsp # leave space for volatiles
23691 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23692 movq %rbp, %rdi
23693 call *%rbx
23694 movl $0, RAX(%rsp)
23695 RESTORE_REST
23696 jmp int_ret_from_sys_call
23697 CFI_ENDPROC
23698 -END(ret_from_fork)
23699 +ENDPROC(ret_from_fork)
23700
23701 /*
23702 * System call entry. Up to 6 arguments in registers are supported.
23703 @@ -386,7 +846,7 @@ END(ret_from_fork)
23704 ENTRY(system_call)
23705 CFI_STARTPROC simple
23706 CFI_SIGNAL_FRAME
23707 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23708 + CFI_DEF_CFA rsp,0
23709 CFI_REGISTER rip,rcx
23710 /*CFI_REGISTER rflags,r11*/
23711 SWAPGS_UNSAFE_STACK
23712 @@ -399,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23713
23714 movq %rsp,PER_CPU_VAR(old_rsp)
23715 movq PER_CPU_VAR(kernel_stack),%rsp
23716 + SAVE_ARGS 8*6, 0, rax_enosys=1
23717 + pax_enter_kernel_user
23718 +
23719 +#ifdef CONFIG_PAX_RANDKSTACK
23720 + pax_erase_kstack
23721 +#endif
23722 +
23723 /*
23724 * No need to follow this irqs off/on section - it's straight
23725 * and short:
23726 */
23727 ENABLE_INTERRUPTS(CLBR_NONE)
23728 - SAVE_ARGS 8, 0, rax_enosys=1
23729 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23730 movq %rcx,RIP-ARGOFFSET(%rsp)
23731 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23732 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23733 + GET_THREAD_INFO(%rcx)
23734 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23735 jnz tracesys
23736 system_call_fastpath:
23737 #if __SYSCALL_MASK == ~0
23738 @@ -432,10 +899,13 @@ sysret_check:
23739 LOCKDEP_SYS_EXIT
23740 DISABLE_INTERRUPTS(CLBR_NONE)
23741 TRACE_IRQS_OFF
23742 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23743 + GET_THREAD_INFO(%rcx)
23744 + movl TI_flags(%rcx),%edx
23745 andl %edi,%edx
23746 jnz sysret_careful
23747 CFI_REMEMBER_STATE
23748 + pax_exit_kernel_user
23749 + pax_erase_kstack
23750 /*
23751 * sysretq will re-enable interrupts:
23752 */
23753 @@ -494,12 +964,15 @@ sysret_audit:
23754
23755 /* Do syscall tracing */
23756 tracesys:
23757 - leaq -REST_SKIP(%rsp), %rdi
23758 + movq %rsp, %rdi
23759 movq $AUDIT_ARCH_X86_64, %rsi
23760 call syscall_trace_enter_phase1
23761 test %rax, %rax
23762 jnz tracesys_phase2 /* if needed, run the slow path */
23763 - LOAD_ARGS 0 /* else restore clobbered regs */
23764 +
23765 + pax_erase_kstack
23766 +
23767 + LOAD_ARGS /* else restore clobbered regs */
23768 jmp system_call_fastpath /* and return to the fast path */
23769
23770 tracesys_phase2:
23771 @@ -510,12 +983,14 @@ tracesys_phase2:
23772 movq %rax,%rdx
23773 call syscall_trace_enter_phase2
23774
23775 + pax_erase_kstack
23776 +
23777 /*
23778 * Reload arg registers from stack in case ptrace changed them.
23779 * We don't reload %rax because syscall_trace_entry_phase2() returned
23780 * the value it wants us to use in the table lookup.
23781 */
23782 - LOAD_ARGS ARGOFFSET, 1
23783 + LOAD_ARGS 1
23784 RESTORE_REST
23785 #if __SYSCALL_MASK == ~0
23786 cmpq $__NR_syscall_max,%rax
23787 @@ -545,7 +1020,9 @@ GLOBAL(int_with_check)
23788 andl %edi,%edx
23789 jnz int_careful
23790 andl $~TS_COMPAT,TI_status(%rcx)
23791 - jmp retint_swapgs
23792 + pax_exit_kernel_user
23793 + pax_erase_kstack
23794 + jmp retint_swapgs_pax
23795
23796 /* Either reschedule or signal or syscall exit tracking needed. */
23797 /* First do a reschedule test. */
23798 @@ -591,7 +1068,7 @@ int_restore_rest:
23799 TRACE_IRQS_OFF
23800 jmp int_with_check
23801 CFI_ENDPROC
23802 -END(system_call)
23803 +ENDPROC(system_call)
23804
23805 .macro FORK_LIKE func
23806 ENTRY(stub_\func)
23807 @@ -604,9 +1081,10 @@ ENTRY(stub_\func)
23808 DEFAULT_FRAME 0 8 /* offset 8: return address */
23809 call sys_\func
23810 RESTORE_TOP_OF_STACK %r11, 8
23811 - ret $REST_SKIP /* pop extended registers */
23812 + pax_force_retaddr
23813 + ret
23814 CFI_ENDPROC
23815 -END(stub_\func)
23816 +ENDPROC(stub_\func)
23817 .endm
23818
23819 .macro FIXED_FRAME label,func
23820 @@ -616,9 +1094,10 @@ ENTRY(\label)
23821 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23822 call \func
23823 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23824 + pax_force_retaddr
23825 ret
23826 CFI_ENDPROC
23827 -END(\label)
23828 +ENDPROC(\label)
23829 .endm
23830
23831 FORK_LIKE clone
23832 @@ -626,19 +1105,6 @@ END(\label)
23833 FORK_LIKE vfork
23834 FIXED_FRAME stub_iopl, sys_iopl
23835
23836 -ENTRY(ptregscall_common)
23837 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23838 - RESTORE_TOP_OF_STACK %r11, 8
23839 - movq_cfi_restore R15+8, r15
23840 - movq_cfi_restore R14+8, r14
23841 - movq_cfi_restore R13+8, r13
23842 - movq_cfi_restore R12+8, r12
23843 - movq_cfi_restore RBP+8, rbp
23844 - movq_cfi_restore RBX+8, rbx
23845 - ret $REST_SKIP /* pop extended registers */
23846 - CFI_ENDPROC
23847 -END(ptregscall_common)
23848 -
23849 ENTRY(stub_execve)
23850 CFI_STARTPROC
23851 addq $8, %rsp
23852 @@ -650,7 +1116,7 @@ ENTRY(stub_execve)
23853 RESTORE_REST
23854 jmp int_ret_from_sys_call
23855 CFI_ENDPROC
23856 -END(stub_execve)
23857 +ENDPROC(stub_execve)
23858
23859 /*
23860 * sigreturn is special because it needs to restore all registers on return.
23861 @@ -667,7 +1133,7 @@ ENTRY(stub_rt_sigreturn)
23862 RESTORE_REST
23863 jmp int_ret_from_sys_call
23864 CFI_ENDPROC
23865 -END(stub_rt_sigreturn)
23866 +ENDPROC(stub_rt_sigreturn)
23867
23868 #ifdef CONFIG_X86_X32_ABI
23869 ENTRY(stub_x32_rt_sigreturn)
23870 @@ -681,7 +1147,7 @@ ENTRY(stub_x32_rt_sigreturn)
23871 RESTORE_REST
23872 jmp int_ret_from_sys_call
23873 CFI_ENDPROC
23874 -END(stub_x32_rt_sigreturn)
23875 +ENDPROC(stub_x32_rt_sigreturn)
23876
23877 ENTRY(stub_x32_execve)
23878 CFI_STARTPROC
23879 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_execve)
23880 RESTORE_REST
23881 jmp int_ret_from_sys_call
23882 CFI_ENDPROC
23883 -END(stub_x32_execve)
23884 +ENDPROC(stub_x32_execve)
23885
23886 #endif
23887
23888 @@ -732,7 +1198,7 @@ vector=vector+1
23889 2: jmp common_interrupt
23890 .endr
23891 CFI_ENDPROC
23892 -END(irq_entries_start)
23893 +ENDPROC(irq_entries_start)
23894
23895 .previous
23896 END(interrupt)
23897 @@ -749,8 +1215,8 @@ END(interrupt)
23898 /* 0(%rsp): ~(interrupt number) */
23899 .macro interrupt func
23900 /* reserve pt_regs for scratch regs and rbp */
23901 - subq $ORIG_RAX-RBP, %rsp
23902 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23903 + subq $ORIG_RAX, %rsp
23904 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23905 SAVE_ARGS_IRQ
23906 call \func
23907 .endm
23908 @@ -773,14 +1239,14 @@ ret_from_intr:
23909
23910 /* Restore saved previous stack */
23911 popq %rsi
23912 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23913 - leaq ARGOFFSET-RBP(%rsi), %rsp
23914 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23915 + movq %rsi, %rsp
23916 CFI_DEF_CFA_REGISTER rsp
23917 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23918 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23919
23920 exit_intr:
23921 GET_THREAD_INFO(%rcx)
23922 - testl $3,CS-ARGOFFSET(%rsp)
23923 + testb $3,CS-ARGOFFSET(%rsp)
23924 je retint_kernel
23925
23926 /* Interrupt came from user space */
23927 @@ -802,12 +1268,35 @@ retint_swapgs: /* return to user-space */
23928 * The iretq could re-enable interrupts:
23929 */
23930 DISABLE_INTERRUPTS(CLBR_ANY)
23931 + pax_exit_kernel_user
23932 +retint_swapgs_pax:
23933 TRACE_IRQS_IRETQ
23934 SWAPGS
23935 jmp restore_args
23936
23937 retint_restore_args: /* return to kernel space */
23938 DISABLE_INTERRUPTS(CLBR_ANY)
23939 + pax_exit_kernel
23940 +
23941 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23942 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23943 + * namely calling EFI runtime services with a phys mapping. We're
23944 + * starting off with NOPs and patch in the real instrumentation
23945 + * (BTS/OR) before starting any userland process; even before starting
23946 + * up the APs.
23947 + */
23948 + .pushsection .altinstr_replacement, "a"
23949 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23950 + 602:
23951 + .popsection
23952 + 603: .fill 602b-601b, 1, 0x90
23953 + .pushsection .altinstructions, "a"
23954 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23955 + .popsection
23956 +#else
23957 + pax_force_retaddr (RIP-ARGOFFSET)
23958 +#endif
23959 +
23960 /*
23961 * The iretq could re-enable interrupts:
23962 */
23963 @@ -845,15 +1334,15 @@ native_irq_return_ldt:
23964 SWAPGS
23965 movq PER_CPU_VAR(espfix_waddr),%rdi
23966 movq %rax,(0*8)(%rdi) /* RAX */
23967 - movq (2*8)(%rsp),%rax /* RIP */
23968 + movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23969 movq %rax,(1*8)(%rdi)
23970 - movq (3*8)(%rsp),%rax /* CS */
23971 + movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23972 movq %rax,(2*8)(%rdi)
23973 - movq (4*8)(%rsp),%rax /* RFLAGS */
23974 + movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23975 movq %rax,(3*8)(%rdi)
23976 - movq (6*8)(%rsp),%rax /* SS */
23977 + movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23978 movq %rax,(5*8)(%rdi)
23979 - movq (5*8)(%rsp),%rax /* RSP */
23980 + movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23981 movq %rax,(4*8)(%rdi)
23982 andl $0xffff0000,%eax
23983 popq_cfi %rdi
23984 @@ -907,7 +1396,7 @@ ENTRY(retint_kernel)
23985 jmp exit_intr
23986 #endif
23987 CFI_ENDPROC
23988 -END(common_interrupt)
23989 +ENDPROC(common_interrupt)
23990
23991 /*
23992 * APIC interrupts.
23993 @@ -921,7 +1410,7 @@ ENTRY(\sym)
23994 interrupt \do_sym
23995 jmp ret_from_intr
23996 CFI_ENDPROC
23997 -END(\sym)
23998 +ENDPROC(\sym)
23999 .endm
24000
24001 #ifdef CONFIG_TRACING
24002 @@ -994,7 +1483,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24003 /*
24004 * Exception entry points.
24005 */
24006 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24007 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24008
24009 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24010 ENTRY(\sym)
24011 @@ -1045,6 +1534,12 @@ ENTRY(\sym)
24012 .endif
24013
24014 .if \shift_ist != -1
24015 +#ifdef CONFIG_SMP
24016 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24017 + lea init_tss(%r13), %r13
24018 +#else
24019 + lea init_tss(%rip), %r13
24020 +#endif
24021 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24022 .endif
24023
24024 @@ -1061,7 +1556,7 @@ ENTRY(\sym)
24025 .endif
24026
24027 CFI_ENDPROC
24028 -END(\sym)
24029 +ENDPROC(\sym)
24030 .endm
24031
24032 #ifdef CONFIG_TRACING
24033 @@ -1102,9 +1597,10 @@ gs_change:
24034 2: mfence /* workaround */
24035 SWAPGS
24036 popfq_cfi
24037 + pax_force_retaddr
24038 ret
24039 CFI_ENDPROC
24040 -END(native_load_gs_index)
24041 +ENDPROC(native_load_gs_index)
24042
24043 _ASM_EXTABLE(gs_change,bad_gs)
24044 .section .fixup,"ax"
24045 @@ -1132,9 +1628,10 @@ ENTRY(do_softirq_own_stack)
24046 CFI_DEF_CFA_REGISTER rsp
24047 CFI_ADJUST_CFA_OFFSET -8
24048 decl PER_CPU_VAR(irq_count)
24049 + pax_force_retaddr
24050 ret
24051 CFI_ENDPROC
24052 -END(do_softirq_own_stack)
24053 +ENDPROC(do_softirq_own_stack)
24054
24055 #ifdef CONFIG_XEN
24056 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24057 @@ -1172,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24058 decl PER_CPU_VAR(irq_count)
24059 jmp error_exit
24060 CFI_ENDPROC
24061 -END(xen_do_hypervisor_callback)
24062 +ENDPROC(xen_do_hypervisor_callback)
24063
24064 /*
24065 * Hypervisor uses this for application faults while it executes.
24066 @@ -1231,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
24067 SAVE_ALL
24068 jmp error_exit
24069 CFI_ENDPROC
24070 -END(xen_failsafe_callback)
24071 +ENDPROC(xen_failsafe_callback)
24072
24073 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24074 xen_hvm_callback_vector xen_evtchn_do_upcall
24075 @@ -1278,18 +1775,33 @@ ENTRY(paranoid_exit)
24076 DEFAULT_FRAME
24077 DISABLE_INTERRUPTS(CLBR_NONE)
24078 TRACE_IRQS_OFF_DEBUG
24079 - testl %ebx,%ebx /* swapgs needed? */
24080 + testl $1,%ebx /* swapgs needed? */
24081 jnz paranoid_restore
24082 - testl $3,CS(%rsp)
24083 + testb $3,CS(%rsp)
24084 jnz paranoid_userspace
24085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24086 + pax_exit_kernel
24087 + TRACE_IRQS_IRETQ 0
24088 + SWAPGS_UNSAFE_STACK
24089 + RESTORE_ALL 8
24090 + pax_force_retaddr_bts
24091 + jmp irq_return
24092 +#endif
24093 paranoid_swapgs:
24094 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24095 + pax_exit_kernel_user
24096 +#else
24097 + pax_exit_kernel
24098 +#endif
24099 TRACE_IRQS_IRETQ 0
24100 SWAPGS_UNSAFE_STACK
24101 RESTORE_ALL 8
24102 jmp irq_return
24103 paranoid_restore:
24104 + pax_exit_kernel
24105 TRACE_IRQS_IRETQ_DEBUG 0
24106 RESTORE_ALL 8
24107 + pax_force_retaddr_bts
24108 jmp irq_return
24109 paranoid_userspace:
24110 GET_THREAD_INFO(%rcx)
24111 @@ -1318,7 +1830,7 @@ paranoid_schedule:
24112 TRACE_IRQS_OFF
24113 jmp paranoid_userspace
24114 CFI_ENDPROC
24115 -END(paranoid_exit)
24116 +ENDPROC(paranoid_exit)
24117
24118 /*
24119 * Exception entry point. This expects an error code/orig_rax on the stack.
24120 @@ -1345,12 +1857,23 @@ ENTRY(error_entry)
24121 movq %r14, R14+8(%rsp)
24122 movq %r15, R15+8(%rsp)
24123 xorl %ebx,%ebx
24124 - testl $3,CS+8(%rsp)
24125 + testb $3,CS+8(%rsp)
24126 je error_kernelspace
24127 error_swapgs:
24128 SWAPGS
24129 error_sti:
24130 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24131 + testb $3, CS+8(%rsp)
24132 + jnz 1f
24133 + pax_enter_kernel
24134 + jmp 2f
24135 +1: pax_enter_kernel_user
24136 +2:
24137 +#else
24138 + pax_enter_kernel
24139 +#endif
24140 TRACE_IRQS_OFF
24141 + pax_force_retaddr
24142 ret
24143
24144 /*
24145 @@ -1385,7 +1908,7 @@ error_bad_iret:
24146 decl %ebx /* Return to usergs */
24147 jmp error_sti
24148 CFI_ENDPROC
24149 -END(error_entry)
24150 +ENDPROC(error_entry)
24151
24152
24153 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24154 @@ -1396,7 +1919,7 @@ ENTRY(error_exit)
24155 DISABLE_INTERRUPTS(CLBR_NONE)
24156 TRACE_IRQS_OFF
24157 GET_THREAD_INFO(%rcx)
24158 - testl %eax,%eax
24159 + testl $1,%eax
24160 jne retint_kernel
24161 LOCKDEP_SYS_EXIT_IRQ
24162 movl TI_flags(%rcx),%edx
24163 @@ -1405,7 +1928,7 @@ ENTRY(error_exit)
24164 jnz retint_careful
24165 jmp retint_swapgs
24166 CFI_ENDPROC
24167 -END(error_exit)
24168 +ENDPROC(error_exit)
24169
24170 /*
24171 * Test if a given stack is an NMI stack or not.
24172 @@ -1463,9 +1986,11 @@ ENTRY(nmi)
24173 * If %cs was not the kernel segment, then the NMI triggered in user
24174 * space, which means it is definitely not nested.
24175 */
24176 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24177 + je 1f
24178 cmpl $__KERNEL_CS, 16(%rsp)
24179 jne first_nmi
24180 -
24181 +1:
24182 /*
24183 * Check the special variable on the stack to see if NMIs are
24184 * executing.
24185 @@ -1499,8 +2024,7 @@ nested_nmi:
24186
24187 1:
24188 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24189 - leaq -1*8(%rsp), %rdx
24190 - movq %rdx, %rsp
24191 + subq $8, %rsp
24192 CFI_ADJUST_CFA_OFFSET 1*8
24193 leaq -10*8(%rsp), %rdx
24194 pushq_cfi $__KERNEL_DS
24195 @@ -1518,6 +2042,7 @@ nested_nmi_out:
24196 CFI_RESTORE rdx
24197
24198 /* No need to check faults here */
24199 +# pax_force_retaddr_bts
24200 INTERRUPT_RETURN
24201
24202 CFI_RESTORE_STATE
24203 @@ -1614,13 +2139,13 @@ end_repeat_nmi:
24204 subq $ORIG_RAX-R15, %rsp
24205 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24206 /*
24207 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24208 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24209 * as we should not be calling schedule in NMI context.
24210 * Even with normal interrupts enabled. An NMI should not be
24211 * setting NEED_RESCHED or anything that normal interrupts and
24212 * exceptions might do.
24213 */
24214 - call save_paranoid
24215 + call save_paranoid_nmi
24216 DEFAULT_FRAME 0
24217
24218 /*
24219 @@ -1630,9 +2155,9 @@ end_repeat_nmi:
24220 * NMI itself takes a page fault, the page fault that was preempted
24221 * will read the information from the NMI page fault and not the
24222 * origin fault. Save it off and restore it if it changes.
24223 - * Use the r12 callee-saved register.
24224 + * Use the r13 callee-saved register.
24225 */
24226 - movq %cr2, %r12
24227 + movq %cr2, %r13
24228
24229 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24230 movq %rsp,%rdi
24231 @@ -1641,29 +2166,34 @@ end_repeat_nmi:
24232
24233 /* Did the NMI take a page fault? Restore cr2 if it did */
24234 movq %cr2, %rcx
24235 - cmpq %rcx, %r12
24236 + cmpq %rcx, %r13
24237 je 1f
24238 - movq %r12, %cr2
24239 + movq %r13, %cr2
24240 1:
24241
24242 - testl %ebx,%ebx /* swapgs needed? */
24243 + testl $1,%ebx /* swapgs needed? */
24244 jnz nmi_restore
24245 nmi_swapgs:
24246 SWAPGS_UNSAFE_STACK
24247 nmi_restore:
24248 + pax_exit_kernel_nmi
24249 /* Pop the extra iret frame at once */
24250 RESTORE_ALL 6*8
24251 + testb $3, 8(%rsp)
24252 + jnz 1f
24253 + pax_force_retaddr_bts
24254 +1:
24255
24256 /* Clear the NMI executing stack variable */
24257 movq $0, 5*8(%rsp)
24258 jmp irq_return
24259 CFI_ENDPROC
24260 -END(nmi)
24261 +ENDPROC(nmi)
24262
24263 ENTRY(ignore_sysret)
24264 CFI_STARTPROC
24265 mov $-ENOSYS,%eax
24266 sysret
24267 CFI_ENDPROC
24268 -END(ignore_sysret)
24269 +ENDPROC(ignore_sysret)
24270
24271 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24272 index 94d857f..5bce89c 100644
24273 --- a/arch/x86/kernel/espfix_64.c
24274 +++ b/arch/x86/kernel/espfix_64.c
24275 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24276 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24277 static void *espfix_pages[ESPFIX_MAX_PAGES];
24278
24279 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24280 - __aligned(PAGE_SIZE);
24281 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24282
24283 static unsigned int page_random, slot_random;
24284
24285 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24286 void __init init_espfix_bsp(void)
24287 {
24288 pgd_t *pgd_p;
24289 - pteval_t ptemask;
24290 -
24291 - ptemask = __supported_pte_mask;
24292 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24293
24294 /* Install the espfix pud into the kernel page directory */
24295 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24296 + pgd_p = &init_level4_pgt[index];
24297 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24298
24299 +#ifdef CONFIG_PAX_PER_CPU_PGD
24300 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24301 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24302 +#endif
24303 +
24304 /* Randomize the locations */
24305 init_espfix_random();
24306
24307 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24308 set_pte(&pte_p[n*PTE_STRIDE], pte);
24309
24310 /* Job is done for this CPU and any CPU which shares this page */
24311 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24312 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24313
24314 unlock_done:
24315 mutex_unlock(&espfix_init_mutex);
24316 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24317 index 3386dc9..28bdf81 100644
24318 --- a/arch/x86/kernel/ftrace.c
24319 +++ b/arch/x86/kernel/ftrace.c
24320 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24321 * kernel identity mapping to modify code.
24322 */
24323 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24324 - ip = (unsigned long)__va(__pa_symbol(ip));
24325 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24326
24327 return ip;
24328 }
24329 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24330 {
24331 unsigned char replaced[MCOUNT_INSN_SIZE];
24332
24333 + ip = ktla_ktva(ip);
24334 +
24335 /*
24336 * Note: Due to modules and __init, code can
24337 * disappear and change, we need to protect against faulting
24338 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24339 unsigned char old[MCOUNT_INSN_SIZE];
24340 int ret;
24341
24342 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24343 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24344
24345 ftrace_update_func = ip;
24346 /* Make sure the breakpoints see the ftrace_update_func update */
24347 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24348 unsigned char replaced[MCOUNT_INSN_SIZE];
24349 unsigned char brk = BREAKPOINT_INSTRUCTION;
24350
24351 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24352 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24353 return -EFAULT;
24354
24355 /* Make sure it is what we expect it to be */
24356 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24357 index eda1a86..8f6df48 100644
24358 --- a/arch/x86/kernel/head64.c
24359 +++ b/arch/x86/kernel/head64.c
24360 @@ -67,12 +67,12 @@ again:
24361 pgd = *pgd_p;
24362
24363 /*
24364 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24365 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24366 + * The use of __early_va rather than __va here is critical:
24367 + * __va would point us back into the dynamic
24368 * range and we might end up looping forever...
24369 */
24370 if (pgd)
24371 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24372 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24373 else {
24374 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24375 reset_early_page_tables();
24376 @@ -82,13 +82,13 @@ again:
24377 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24378 for (i = 0; i < PTRS_PER_PUD; i++)
24379 pud_p[i] = 0;
24380 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24381 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24382 }
24383 pud_p += pud_index(address);
24384 pud = *pud_p;
24385
24386 if (pud)
24387 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24388 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24389 else {
24390 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24391 reset_early_page_tables();
24392 @@ -98,7 +98,7 @@ again:
24393 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24394 for (i = 0; i < PTRS_PER_PMD; i++)
24395 pmd_p[i] = 0;
24396 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24397 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24398 }
24399 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24400 pmd_p[pmd_index(address)] = pmd;
24401 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24402 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24403 early_printk("Kernel alive\n");
24404
24405 - clear_page(init_level4_pgt);
24406 /* set init_level4_pgt kernel high mapping*/
24407 init_level4_pgt[511] = early_level4_pgt[511];
24408
24409 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24410 index f36bd42..0ab4474 100644
24411 --- a/arch/x86/kernel/head_32.S
24412 +++ b/arch/x86/kernel/head_32.S
24413 @@ -26,6 +26,12 @@
24414 /* Physical address */
24415 #define pa(X) ((X) - __PAGE_OFFSET)
24416
24417 +#ifdef CONFIG_PAX_KERNEXEC
24418 +#define ta(X) (X)
24419 +#else
24420 +#define ta(X) ((X) - __PAGE_OFFSET)
24421 +#endif
24422 +
24423 /*
24424 * References to members of the new_cpu_data structure.
24425 */
24426 @@ -55,11 +61,7 @@
24427 * and small than max_low_pfn, otherwise will waste some page table entries
24428 */
24429
24430 -#if PTRS_PER_PMD > 1
24431 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24432 -#else
24433 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24434 -#endif
24435 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24436
24437 /* Number of possible pages in the lowmem region */
24438 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24439 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24440 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24441
24442 /*
24443 + * Real beginning of normal "text" segment
24444 + */
24445 +ENTRY(stext)
24446 +ENTRY(_stext)
24447 +
24448 +/*
24449 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24450 * %esi points to the real-mode code as a 32-bit pointer.
24451 * CS and DS must be 4 GB flat segments, but we don't depend on
24452 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24453 * can.
24454 */
24455 __HEAD
24456 +
24457 +#ifdef CONFIG_PAX_KERNEXEC
24458 + jmp startup_32
24459 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24460 +.fill PAGE_SIZE-5,1,0xcc
24461 +#endif
24462 +
24463 ENTRY(startup_32)
24464 movl pa(stack_start),%ecx
24465
24466 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24467 2:
24468 leal -__PAGE_OFFSET(%ecx),%esp
24469
24470 +#ifdef CONFIG_SMP
24471 + movl $pa(cpu_gdt_table),%edi
24472 + movl $__per_cpu_load,%eax
24473 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24474 + rorl $16,%eax
24475 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24476 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24477 + movl $__per_cpu_end - 1,%eax
24478 + subl $__per_cpu_start,%eax
24479 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24480 +#endif
24481 +
24482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24483 + movl $NR_CPUS,%ecx
24484 + movl $pa(cpu_gdt_table),%edi
24485 +1:
24486 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24487 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24488 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24489 + addl $PAGE_SIZE_asm,%edi
24490 + loop 1b
24491 +#endif
24492 +
24493 +#ifdef CONFIG_PAX_KERNEXEC
24494 + movl $pa(boot_gdt),%edi
24495 + movl $__LOAD_PHYSICAL_ADDR,%eax
24496 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24497 + rorl $16,%eax
24498 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24499 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24500 + rorl $16,%eax
24501 +
24502 + ljmp $(__BOOT_CS),$1f
24503 +1:
24504 +
24505 + movl $NR_CPUS,%ecx
24506 + movl $pa(cpu_gdt_table),%edi
24507 + addl $__PAGE_OFFSET,%eax
24508 +1:
24509 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24510 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24511 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24512 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24513 + rorl $16,%eax
24514 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24515 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24516 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24517 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24518 + rorl $16,%eax
24519 + addl $PAGE_SIZE_asm,%edi
24520 + loop 1b
24521 +#endif
24522 +
24523 /*
24524 * Clear BSS first so that there are no surprises...
24525 */
24526 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24527 movl %eax, pa(max_pfn_mapped)
24528
24529 /* Do early initialization of the fixmap area */
24530 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24531 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24532 +#ifdef CONFIG_COMPAT_VDSO
24533 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24534 +#else
24535 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24536 +#endif
24537 #else /* Not PAE */
24538
24539 page_pde_offset = (__PAGE_OFFSET >> 20);
24540 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24541 movl %eax, pa(max_pfn_mapped)
24542
24543 /* Do early initialization of the fixmap area */
24544 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24545 - movl %eax,pa(initial_page_table+0xffc)
24546 +#ifdef CONFIG_COMPAT_VDSO
24547 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24548 +#else
24549 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24550 +#endif
24551 #endif
24552
24553 #ifdef CONFIG_PARAVIRT
24554 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24555 cmpl $num_subarch_entries, %eax
24556 jae bad_subarch
24557
24558 - movl pa(subarch_entries)(,%eax,4), %eax
24559 - subl $__PAGE_OFFSET, %eax
24560 - jmp *%eax
24561 + jmp *pa(subarch_entries)(,%eax,4)
24562
24563 bad_subarch:
24564 WEAK(lguest_entry)
24565 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24566 __INITDATA
24567
24568 subarch_entries:
24569 - .long default_entry /* normal x86/PC */
24570 - .long lguest_entry /* lguest hypervisor */
24571 - .long xen_entry /* Xen hypervisor */
24572 - .long default_entry /* Moorestown MID */
24573 + .long ta(default_entry) /* normal x86/PC */
24574 + .long ta(lguest_entry) /* lguest hypervisor */
24575 + .long ta(xen_entry) /* Xen hypervisor */
24576 + .long ta(default_entry) /* Moorestown MID */
24577 num_subarch_entries = (. - subarch_entries) / 4
24578 .previous
24579 #else
24580 @@ -354,6 +426,7 @@ default_entry:
24581 movl pa(mmu_cr4_features),%eax
24582 movl %eax,%cr4
24583
24584 +#ifdef CONFIG_X86_PAE
24585 testb $X86_CR4_PAE, %al # check if PAE is enabled
24586 jz enable_paging
24587
24588 @@ -382,6 +455,9 @@ default_entry:
24589 /* Make changes effective */
24590 wrmsr
24591
24592 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24593 +#endif
24594 +
24595 enable_paging:
24596
24597 /*
24598 @@ -449,14 +525,20 @@ is486:
24599 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24600 movl %eax,%ss # after changing gdt.
24601
24602 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24603 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24604 movl %eax,%ds
24605 movl %eax,%es
24606
24607 movl $(__KERNEL_PERCPU), %eax
24608 movl %eax,%fs # set this cpu's percpu
24609
24610 +#ifdef CONFIG_CC_STACKPROTECTOR
24611 movl $(__KERNEL_STACK_CANARY),%eax
24612 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24613 + movl $(__USER_DS),%eax
24614 +#else
24615 + xorl %eax,%eax
24616 +#endif
24617 movl %eax,%gs
24618
24619 xorl %eax,%eax # Clear LDT
24620 @@ -512,8 +594,11 @@ setup_once:
24621 * relocation. Manually set base address in stack canary
24622 * segment descriptor.
24623 */
24624 - movl $gdt_page,%eax
24625 + movl $cpu_gdt_table,%eax
24626 movl $stack_canary,%ecx
24627 +#ifdef CONFIG_SMP
24628 + addl $__per_cpu_load,%ecx
24629 +#endif
24630 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24631 shrl $16, %ecx
24632 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24633 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24634 cmpl $2,(%esp) # X86_TRAP_NMI
24635 je is_nmi # Ignore NMI
24636
24637 - cmpl $2,%ss:early_recursion_flag
24638 + cmpl $1,%ss:early_recursion_flag
24639 je hlt_loop
24640 incl %ss:early_recursion_flag
24641
24642 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24643 pushl (20+6*4)(%esp) /* trapno */
24644 pushl $fault_msg
24645 call printk
24646 -#endif
24647 call dump_stack
24648 +#endif
24649 hlt_loop:
24650 hlt
24651 jmp hlt_loop
24652 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24653 /* This is the default interrupt "handler" :-) */
24654 ALIGN
24655 ignore_int:
24656 - cld
24657 #ifdef CONFIG_PRINTK
24658 + cmpl $2,%ss:early_recursion_flag
24659 + je hlt_loop
24660 + incl %ss:early_recursion_flag
24661 + cld
24662 pushl %eax
24663 pushl %ecx
24664 pushl %edx
24665 @@ -617,9 +705,6 @@ ignore_int:
24666 movl $(__KERNEL_DS),%eax
24667 movl %eax,%ds
24668 movl %eax,%es
24669 - cmpl $2,early_recursion_flag
24670 - je hlt_loop
24671 - incl early_recursion_flag
24672 pushl 16(%esp)
24673 pushl 24(%esp)
24674 pushl 32(%esp)
24675 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24676 /*
24677 * BSS section
24678 */
24679 -__PAGE_ALIGNED_BSS
24680 - .align PAGE_SIZE
24681 #ifdef CONFIG_X86_PAE
24682 +.section .initial_pg_pmd,"a",@progbits
24683 initial_pg_pmd:
24684 .fill 1024*KPMDS,4,0
24685 #else
24686 +.section .initial_page_table,"a",@progbits
24687 ENTRY(initial_page_table)
24688 .fill 1024,4,0
24689 #endif
24690 +.section .initial_pg_fixmap,"a",@progbits
24691 initial_pg_fixmap:
24692 .fill 1024,4,0
24693 +.section .empty_zero_page,"a",@progbits
24694 ENTRY(empty_zero_page)
24695 .fill 4096,1,0
24696 +.section .swapper_pg_dir,"a",@progbits
24697 ENTRY(swapper_pg_dir)
24698 +#ifdef CONFIG_X86_PAE
24699 + .fill 4,8,0
24700 +#else
24701 .fill 1024,4,0
24702 +#endif
24703
24704 /*
24705 * This starts the data section.
24706 */
24707 #ifdef CONFIG_X86_PAE
24708 -__PAGE_ALIGNED_DATA
24709 - /* Page-aligned for the benefit of paravirt? */
24710 - .align PAGE_SIZE
24711 +.section .initial_page_table,"a",@progbits
24712 ENTRY(initial_page_table)
24713 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24714 # if KPMDS == 3
24715 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24716 # error "Kernel PMDs should be 1, 2 or 3"
24717 # endif
24718 .align PAGE_SIZE /* needs to be page-sized too */
24719 +
24720 +#ifdef CONFIG_PAX_PER_CPU_PGD
24721 +ENTRY(cpu_pgd)
24722 + .rept 2*NR_CPUS
24723 + .fill 4,8,0
24724 + .endr
24725 +#endif
24726 +
24727 #endif
24728
24729 .data
24730 .balign 4
24731 ENTRY(stack_start)
24732 - .long init_thread_union+THREAD_SIZE
24733 + .long init_thread_union+THREAD_SIZE-8
24734
24735 __INITRODATA
24736 int_msg:
24737 @@ -727,7 +825,7 @@ fault_msg:
24738 * segment size, and 32-bit linear address value:
24739 */
24740
24741 - .data
24742 +.section .rodata,"a",@progbits
24743 .globl boot_gdt_descr
24744 .globl idt_descr
24745
24746 @@ -736,7 +834,7 @@ fault_msg:
24747 .word 0 # 32 bit align gdt_desc.address
24748 boot_gdt_descr:
24749 .word __BOOT_DS+7
24750 - .long boot_gdt - __PAGE_OFFSET
24751 + .long pa(boot_gdt)
24752
24753 .word 0 # 32-bit align idt_desc.address
24754 idt_descr:
24755 @@ -747,7 +845,7 @@ idt_descr:
24756 .word 0 # 32 bit align gdt_desc.address
24757 ENTRY(early_gdt_descr)
24758 .word GDT_ENTRIES*8-1
24759 - .long gdt_page /* Overwritten for secondary CPUs */
24760 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24761
24762 /*
24763 * The boot_gdt must mirror the equivalent in setup.S and is
24764 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24765 .align L1_CACHE_BYTES
24766 ENTRY(boot_gdt)
24767 .fill GDT_ENTRY_BOOT_CS,8,0
24768 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24769 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24770 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24771 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24772 +
24773 + .align PAGE_SIZE_asm
24774 +ENTRY(cpu_gdt_table)
24775 + .rept NR_CPUS
24776 + .quad 0x0000000000000000 /* NULL descriptor */
24777 + .quad 0x0000000000000000 /* 0x0b reserved */
24778 + .quad 0x0000000000000000 /* 0x13 reserved */
24779 + .quad 0x0000000000000000 /* 0x1b reserved */
24780 +
24781 +#ifdef CONFIG_PAX_KERNEXEC
24782 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24783 +#else
24784 + .quad 0x0000000000000000 /* 0x20 unused */
24785 +#endif
24786 +
24787 + .quad 0x0000000000000000 /* 0x28 unused */
24788 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24789 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24790 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24791 + .quad 0x0000000000000000 /* 0x4b reserved */
24792 + .quad 0x0000000000000000 /* 0x53 reserved */
24793 + .quad 0x0000000000000000 /* 0x5b reserved */
24794 +
24795 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24796 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24797 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24798 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24799 +
24800 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24801 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24802 +
24803 + /*
24804 + * Segments used for calling PnP BIOS have byte granularity.
24805 + * The code segments and data segments have fixed 64k limits,
24806 + * the transfer segment sizes are set at run time.
24807 + */
24808 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24809 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24810 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24811 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24812 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24813 +
24814 + /*
24815 + * The APM segments have byte granularity and their bases
24816 + * are set at run time. All have 64k limits.
24817 + */
24818 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24819 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24820 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24821 +
24822 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24823 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24824 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24825 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24826 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24827 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24828 +
24829 + /* Be sure this is zeroed to avoid false validations in Xen */
24830 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24831 + .endr
24832 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24833 index a468c0a..8b5a879 100644
24834 --- a/arch/x86/kernel/head_64.S
24835 +++ b/arch/x86/kernel/head_64.S
24836 @@ -20,6 +20,8 @@
24837 #include <asm/processor-flags.h>
24838 #include <asm/percpu.h>
24839 #include <asm/nops.h>
24840 +#include <asm/cpufeature.h>
24841 +#include <asm/alternative-asm.h>
24842
24843 #ifdef CONFIG_PARAVIRT
24844 #include <asm/asm-offsets.h>
24845 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24846 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24847 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24848 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24849 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24850 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24851 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24852 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24853 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24854 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24855
24856 .text
24857 __HEAD
24858 @@ -89,11 +97,24 @@ startup_64:
24859 * Fixup the physical addresses in the page table
24860 */
24861 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24862 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24863 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24864 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24865 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24866 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24867
24868 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24869 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24870 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24871 +#ifndef CONFIG_XEN
24872 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24873 +#endif
24874 +
24875 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24876 +
24877 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24878 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24879
24880 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24881 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24882
24883 /*
24884 * Set up the identity mapping for the switchover. These
24885 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24886 * after the boot processor executes this code.
24887 */
24888
24889 + orq $-1, %rbp
24890 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24891 1:
24892
24893 - /* Enable PAE mode and PGE */
24894 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24895 + /* Enable PAE mode and PSE/PGE */
24896 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24897 movq %rcx, %cr4
24898
24899 /* Setup early boot stage 4 level pagetables. */
24900 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24901 movl $MSR_EFER, %ecx
24902 rdmsr
24903 btsl $_EFER_SCE, %eax /* Enable System Call */
24904 - btl $20,%edi /* No Execute supported? */
24905 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24906 jnc 1f
24907 btsl $_EFER_NX, %eax
24908 + cmpq $-1, %rbp
24909 + je 1f
24910 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24911 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24912 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24913 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24914 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24915 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24916 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24917 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24918 1: wrmsr /* Make changes effective */
24919
24920 /* Setup cr0 */
24921 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24922 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24923 * address given in m16:64.
24924 */
24925 + pax_set_fptr_mask
24926 movq initial_code(%rip),%rax
24927 pushq $0 # fake return address to stop unwinder
24928 pushq $__KERNEL_CS # set correct cs
24929 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24930 .quad INIT_PER_CPU_VAR(irq_stack_union)
24931
24932 GLOBAL(stack_start)
24933 - .quad init_thread_union+THREAD_SIZE-8
24934 + .quad init_thread_union+THREAD_SIZE-16
24935 .word 0
24936 __FINITDATA
24937
24938 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24939 call dump_stack
24940 #ifdef CONFIG_KALLSYMS
24941 leaq early_idt_ripmsg(%rip),%rdi
24942 - movq 40(%rsp),%rsi # %rip again
24943 + movq 88(%rsp),%rsi # %rip again
24944 call __print_symbol
24945 #endif
24946 #endif /* EARLY_PRINTK */
24947 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24948 early_recursion_flag:
24949 .long 0
24950
24951 + .section .rodata,"a",@progbits
24952 #ifdef CONFIG_EARLY_PRINTK
24953 early_idt_msg:
24954 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24955 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24956 NEXT_PAGE(early_dynamic_pgts)
24957 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24958
24959 - .data
24960 + .section .rodata,"a",@progbits
24961
24962 -#ifndef CONFIG_XEN
24963 NEXT_PAGE(init_level4_pgt)
24964 - .fill 512,8,0
24965 -#else
24966 -NEXT_PAGE(init_level4_pgt)
24967 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24968 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24969 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24970 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24971 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24972 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24973 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24974 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24975 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24976 .org init_level4_pgt + L4_START_KERNEL*8, 0
24977 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24978 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24979
24980 +#ifdef CONFIG_PAX_PER_CPU_PGD
24981 +NEXT_PAGE(cpu_pgd)
24982 + .rept 2*NR_CPUS
24983 + .fill 512,8,0
24984 + .endr
24985 +#endif
24986 +
24987 NEXT_PAGE(level3_ident_pgt)
24988 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24989 +#ifdef CONFIG_XEN
24990 .fill 511, 8, 0
24991 +#else
24992 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24993 + .fill 510,8,0
24994 +#endif
24995 +
24996 +NEXT_PAGE(level3_vmalloc_start_pgt)
24997 + .fill 512,8,0
24998 +
24999 +NEXT_PAGE(level3_vmalloc_end_pgt)
25000 + .fill 512,8,0
25001 +
25002 +NEXT_PAGE(level3_vmemmap_pgt)
25003 + .fill L3_VMEMMAP_START,8,0
25004 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25005 +
25006 NEXT_PAGE(level2_ident_pgt)
25007 - /* Since I easily can, map the first 1G.
25008 + /* Since I easily can, map the first 2G.
25009 * Don't set NX because code runs from these pages.
25010 */
25011 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25012 -#endif
25013 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25014
25015 NEXT_PAGE(level3_kernel_pgt)
25016 .fill L3_START_KERNEL,8,0
25017 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25018 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25019 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25020
25021 +NEXT_PAGE(level2_vmemmap_pgt)
25022 + .fill 512,8,0
25023 +
25024 NEXT_PAGE(level2_kernel_pgt)
25025 /*
25026 * 512 MB kernel mapping. We spend a full page on this pagetable
25027 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25028 NEXT_PAGE(level2_fixmap_pgt)
25029 .fill 506,8,0
25030 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25031 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25032 - .fill 5,8,0
25033 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25034 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25035 + .fill 4,8,0
25036
25037 NEXT_PAGE(level1_fixmap_pgt)
25038 .fill 512,8,0
25039
25040 +NEXT_PAGE(level1_vsyscall_pgt)
25041 + .fill 512,8,0
25042 +
25043 #undef PMDS
25044
25045 - .data
25046 + .align PAGE_SIZE
25047 +ENTRY(cpu_gdt_table)
25048 + .rept NR_CPUS
25049 + .quad 0x0000000000000000 /* NULL descriptor */
25050 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25051 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25052 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25053 + .quad 0x00cffb000000ffff /* __USER32_CS */
25054 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25055 + .quad 0x00affb000000ffff /* __USER_CS */
25056 +
25057 +#ifdef CONFIG_PAX_KERNEXEC
25058 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25059 +#else
25060 + .quad 0x0 /* unused */
25061 +#endif
25062 +
25063 + .quad 0,0 /* TSS */
25064 + .quad 0,0 /* LDT */
25065 + .quad 0,0,0 /* three TLS descriptors */
25066 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25067 + /* asm/segment.h:GDT_ENTRIES must match this */
25068 +
25069 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25070 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25071 +#else
25072 + .quad 0x0 /* unused */
25073 +#endif
25074 +
25075 + /* zero the remaining page */
25076 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25077 + .endr
25078 +
25079 .align 16
25080 .globl early_gdt_descr
25081 early_gdt_descr:
25082 .word GDT_ENTRIES*8-1
25083 early_gdt_descr_base:
25084 - .quad INIT_PER_CPU_VAR(gdt_page)
25085 + .quad cpu_gdt_table
25086
25087 ENTRY(phys_base)
25088 /* This must match the first entry in level2_kernel_pgt */
25089 .quad 0x0000000000000000
25090
25091 #include "../../x86/xen/xen-head.S"
25092 -
25093 - __PAGE_ALIGNED_BSS
25094 +
25095 + .section .rodata,"a",@progbits
25096 NEXT_PAGE(empty_zero_page)
25097 .skip PAGE_SIZE
25098 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25099 index 05fd74f..c3548b1 100644
25100 --- a/arch/x86/kernel/i386_ksyms_32.c
25101 +++ b/arch/x86/kernel/i386_ksyms_32.c
25102 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25103 EXPORT_SYMBOL(cmpxchg8b_emu);
25104 #endif
25105
25106 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25107 +
25108 /* Networking helper routines. */
25109 EXPORT_SYMBOL(csum_partial_copy_generic);
25110 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25111 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25112
25113 EXPORT_SYMBOL(__get_user_1);
25114 EXPORT_SYMBOL(__get_user_2);
25115 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25116 EXPORT_SYMBOL(___preempt_schedule_context);
25117 #endif
25118 #endif
25119 +
25120 +#ifdef CONFIG_PAX_KERNEXEC
25121 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25122 +#endif
25123 +
25124 +#ifdef CONFIG_PAX_PER_CPU_PGD
25125 +EXPORT_SYMBOL(cpu_pgd);
25126 +#endif
25127 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25128 index a9a4229..6f4d476 100644
25129 --- a/arch/x86/kernel/i387.c
25130 +++ b/arch/x86/kernel/i387.c
25131 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25132 static inline bool interrupted_user_mode(void)
25133 {
25134 struct pt_regs *regs = get_irq_regs();
25135 - return regs && user_mode_vm(regs);
25136 + return regs && user_mode(regs);
25137 }
25138
25139 /*
25140 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25141 index e7cc537..67d7372 100644
25142 --- a/arch/x86/kernel/i8259.c
25143 +++ b/arch/x86/kernel/i8259.c
25144 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25145 static void make_8259A_irq(unsigned int irq)
25146 {
25147 disable_irq_nosync(irq);
25148 - io_apic_irqs &= ~(1<<irq);
25149 + io_apic_irqs &= ~(1UL<<irq);
25150 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25151 enable_irq(irq);
25152 }
25153 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25154 "spurious 8259A interrupt: IRQ%d.\n", irq);
25155 spurious_irq_mask |= irqmask;
25156 }
25157 - atomic_inc(&irq_err_count);
25158 + atomic_inc_unchecked(&irq_err_count);
25159 /*
25160 * Theoretically we do not have to handle this IRQ,
25161 * but in Linux this does not cause problems and is
25162 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25163 /* (slave's support for AEOI in flat mode is to be investigated) */
25164 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25165
25166 + pax_open_kernel();
25167 if (auto_eoi)
25168 /*
25169 * In AEOI mode we just have to mask the interrupt
25170 * when acking.
25171 */
25172 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25173 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25174 else
25175 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25176 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25177 + pax_close_kernel();
25178
25179 udelay(100); /* wait for 8259A to initialize */
25180
25181 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25182 index a979b5b..1d6db75 100644
25183 --- a/arch/x86/kernel/io_delay.c
25184 +++ b/arch/x86/kernel/io_delay.c
25185 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25186 * Quirk table for systems that misbehave (lock up, etc.) if port
25187 * 0x80 is used:
25188 */
25189 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25190 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25191 {
25192 .callback = dmi_io_delay_0xed_port,
25193 .ident = "Compaq Presario V6000",
25194 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25195 index 4ddaf66..49d5c18 100644
25196 --- a/arch/x86/kernel/ioport.c
25197 +++ b/arch/x86/kernel/ioport.c
25198 @@ -6,6 +6,7 @@
25199 #include <linux/sched.h>
25200 #include <linux/kernel.h>
25201 #include <linux/capability.h>
25202 +#include <linux/security.h>
25203 #include <linux/errno.h>
25204 #include <linux/types.h>
25205 #include <linux/ioport.h>
25206 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25207 return -EINVAL;
25208 if (turn_on && !capable(CAP_SYS_RAWIO))
25209 return -EPERM;
25210 +#ifdef CONFIG_GRKERNSEC_IO
25211 + if (turn_on && grsec_disable_privio) {
25212 + gr_handle_ioperm();
25213 + return -ENODEV;
25214 + }
25215 +#endif
25216
25217 /*
25218 * If it's the first ioperm() call in this thread's lifetime, set the
25219 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25220 * because the ->io_bitmap_max value must match the bitmap
25221 * contents:
25222 */
25223 - tss = &per_cpu(init_tss, get_cpu());
25224 + tss = init_tss + get_cpu();
25225
25226 if (turn_on)
25227 bitmap_clear(t->io_bitmap_ptr, from, num);
25228 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25229 if (level > old) {
25230 if (!capable(CAP_SYS_RAWIO))
25231 return -EPERM;
25232 +#ifdef CONFIG_GRKERNSEC_IO
25233 + if (grsec_disable_privio) {
25234 + gr_handle_iopl();
25235 + return -ENODEV;
25236 + }
25237 +#endif
25238 }
25239 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25240 t->iopl = level << 12;
25241 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25242 index 3790775..53717dc 100644
25243 --- a/arch/x86/kernel/irq.c
25244 +++ b/arch/x86/kernel/irq.c
25245 @@ -22,7 +22,7 @@
25246 #define CREATE_TRACE_POINTS
25247 #include <asm/trace/irq_vectors.h>
25248
25249 -atomic_t irq_err_count;
25250 +atomic_unchecked_t irq_err_count;
25251
25252 /* Function pointer for generic interrupt vector handling */
25253 void (*x86_platform_ipi_callback)(void) = NULL;
25254 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25255 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25256 seq_printf(p, " Hypervisor callback interrupts\n");
25257 #endif
25258 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25259 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25260 #if defined(CONFIG_X86_IO_APIC)
25261 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25262 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25263 #endif
25264 return 0;
25265 }
25266 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25267
25268 u64 arch_irq_stat(void)
25269 {
25270 - u64 sum = atomic_read(&irq_err_count);
25271 + u64 sum = atomic_read_unchecked(&irq_err_count);
25272 return sum;
25273 }
25274
25275 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25276 index 63ce838..2ea3e06 100644
25277 --- a/arch/x86/kernel/irq_32.c
25278 +++ b/arch/x86/kernel/irq_32.c
25279 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25280
25281 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25282
25283 +extern void gr_handle_kernel_exploit(void);
25284 +
25285 int sysctl_panic_on_stackoverflow __read_mostly;
25286
25287 /* Debugging check for stack overflow: is there less than 1KB free? */
25288 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25289 __asm__ __volatile__("andl %%esp,%0" :
25290 "=r" (sp) : "0" (THREAD_SIZE - 1));
25291
25292 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25293 + return sp < STACK_WARN;
25294 }
25295
25296 static void print_stack_overflow(void)
25297 {
25298 printk(KERN_WARNING "low stack detected by irq handler\n");
25299 dump_stack();
25300 + gr_handle_kernel_exploit();
25301 if (sysctl_panic_on_stackoverflow)
25302 panic("low stack detected by irq handler - check messages\n");
25303 }
25304 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25305 static inline int
25306 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25307 {
25308 - struct irq_stack *curstk, *irqstk;
25309 + struct irq_stack *irqstk;
25310 u32 *isp, *prev_esp, arg1, arg2;
25311
25312 - curstk = (struct irq_stack *) current_stack();
25313 irqstk = __this_cpu_read(hardirq_stack);
25314
25315 /*
25316 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25317 * handler) we can't do that and just have to keep using the
25318 * current stack (which is the irq stack already after all)
25319 */
25320 - if (unlikely(curstk == irqstk))
25321 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25322 return 0;
25323
25324 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25325 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25326
25327 /* Save the next esp at the bottom of the stack */
25328 prev_esp = (u32 *)irqstk;
25329 *prev_esp = current_stack_pointer;
25330
25331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25332 + __set_fs(MAKE_MM_SEG(0));
25333 +#endif
25334 +
25335 if (unlikely(overflow))
25336 call_on_stack(print_stack_overflow, isp);
25337
25338 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25339 : "0" (irq), "1" (desc), "2" (isp),
25340 "D" (desc->handle_irq)
25341 : "memory", "cc", "ecx");
25342 +
25343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25344 + __set_fs(current_thread_info()->addr_limit);
25345 +#endif
25346 +
25347 return 1;
25348 }
25349
25350 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25351 */
25352 void irq_ctx_init(int cpu)
25353 {
25354 - struct irq_stack *irqstk;
25355 -
25356 if (per_cpu(hardirq_stack, cpu))
25357 return;
25358
25359 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25360 - THREADINFO_GFP,
25361 - THREAD_SIZE_ORDER));
25362 - per_cpu(hardirq_stack, cpu) = irqstk;
25363 -
25364 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25365 - THREADINFO_GFP,
25366 - THREAD_SIZE_ORDER));
25367 - per_cpu(softirq_stack, cpu) = irqstk;
25368 -
25369 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25370 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25371 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25372 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25373 }
25374
25375 void do_softirq_own_stack(void)
25376 {
25377 - struct thread_info *curstk;
25378 struct irq_stack *irqstk;
25379 u32 *isp, *prev_esp;
25380
25381 - curstk = current_stack();
25382 irqstk = __this_cpu_read(softirq_stack);
25383
25384 /* build the stack frame on the softirq stack */
25385 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25386 prev_esp = (u32 *)irqstk;
25387 *prev_esp = current_stack_pointer;
25388
25389 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25390 + __set_fs(MAKE_MM_SEG(0));
25391 +#endif
25392 +
25393 call_on_stack(__do_softirq, isp);
25394 +
25395 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25396 + __set_fs(current_thread_info()->addr_limit);
25397 +#endif
25398 +
25399 }
25400
25401 bool handle_irq(unsigned irq, struct pt_regs *regs)
25402 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25403 if (unlikely(!desc))
25404 return false;
25405
25406 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25407 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25408 if (unlikely(overflow))
25409 print_stack_overflow();
25410 desc->handle_irq(irq, desc);
25411 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25412 index e4b503d..824fce8 100644
25413 --- a/arch/x86/kernel/irq_64.c
25414 +++ b/arch/x86/kernel/irq_64.c
25415 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25416 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25417 EXPORT_PER_CPU_SYMBOL(irq_regs);
25418
25419 +extern void gr_handle_kernel_exploit(void);
25420 +
25421 int sysctl_panic_on_stackoverflow;
25422
25423 /*
25424 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25425 u64 estack_top, estack_bottom;
25426 u64 curbase = (u64)task_stack_page(current);
25427
25428 - if (user_mode_vm(regs))
25429 + if (user_mode(regs))
25430 return;
25431
25432 if (regs->sp >= curbase + sizeof(struct thread_info) +
25433 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25434 irq_stack_top, irq_stack_bottom,
25435 estack_top, estack_bottom);
25436
25437 + gr_handle_kernel_exploit();
25438 +
25439 if (sysctl_panic_on_stackoverflow)
25440 panic("low stack detected by irq handler - check messages\n");
25441 #endif
25442 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25443 index 26d5a55..a01160a 100644
25444 --- a/arch/x86/kernel/jump_label.c
25445 +++ b/arch/x86/kernel/jump_label.c
25446 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25447 * Jump label is enabled for the first time.
25448 * So we expect a default_nop...
25449 */
25450 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25451 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25452 != 0))
25453 bug_at((void *)entry->code, __LINE__);
25454 } else {
25455 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25456 * ...otherwise expect an ideal_nop. Otherwise
25457 * something went horribly wrong.
25458 */
25459 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25460 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25461 != 0))
25462 bug_at((void *)entry->code, __LINE__);
25463 }
25464 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25465 * are converting the default nop to the ideal nop.
25466 */
25467 if (init) {
25468 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25469 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25470 bug_at((void *)entry->code, __LINE__);
25471 } else {
25472 code.jump = 0xe9;
25473 code.offset = entry->target -
25474 (entry->code + JUMP_LABEL_NOP_SIZE);
25475 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25476 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25477 bug_at((void *)entry->code, __LINE__);
25478 }
25479 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25480 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25481 index 7ec1d5f..5a7d130 100644
25482 --- a/arch/x86/kernel/kgdb.c
25483 +++ b/arch/x86/kernel/kgdb.c
25484 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25485 #ifdef CONFIG_X86_32
25486 switch (regno) {
25487 case GDB_SS:
25488 - if (!user_mode_vm(regs))
25489 + if (!user_mode(regs))
25490 *(unsigned long *)mem = __KERNEL_DS;
25491 break;
25492 case GDB_SP:
25493 - if (!user_mode_vm(regs))
25494 + if (!user_mode(regs))
25495 *(unsigned long *)mem = kernel_stack_pointer(regs);
25496 break;
25497 case GDB_GS:
25498 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25499 bp->attr.bp_addr = breakinfo[breakno].addr;
25500 bp->attr.bp_len = breakinfo[breakno].len;
25501 bp->attr.bp_type = breakinfo[breakno].type;
25502 - info->address = breakinfo[breakno].addr;
25503 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25504 + info->address = ktla_ktva(breakinfo[breakno].addr);
25505 + else
25506 + info->address = breakinfo[breakno].addr;
25507 info->len = breakinfo[breakno].len;
25508 info->type = breakinfo[breakno].type;
25509 val = arch_install_hw_breakpoint(bp);
25510 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25511 case 'k':
25512 /* clear the trace bit */
25513 linux_regs->flags &= ~X86_EFLAGS_TF;
25514 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25515 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25516
25517 /* set the trace bit if we're stepping */
25518 if (remcomInBuffer[0] == 's') {
25519 linux_regs->flags |= X86_EFLAGS_TF;
25520 - atomic_set(&kgdb_cpu_doing_single_step,
25521 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25522 raw_smp_processor_id());
25523 }
25524
25525 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25526
25527 switch (cmd) {
25528 case DIE_DEBUG:
25529 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25530 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25531 if (user_mode(regs))
25532 return single_step_cont(regs, args);
25533 break;
25534 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25535 #endif /* CONFIG_DEBUG_RODATA */
25536
25537 bpt->type = BP_BREAKPOINT;
25538 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25539 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25540 BREAK_INSTR_SIZE);
25541 if (err)
25542 return err;
25543 - err = probe_kernel_write((char *)bpt->bpt_addr,
25544 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25545 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25546 #ifdef CONFIG_DEBUG_RODATA
25547 if (!err)
25548 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25549 return -EBUSY;
25550 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25551 BREAK_INSTR_SIZE);
25552 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25553 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25554 if (err)
25555 return err;
25556 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25557 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25558 if (mutex_is_locked(&text_mutex))
25559 goto knl_write;
25560 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25561 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25562 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25563 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25564 goto knl_write;
25565 return err;
25566 knl_write:
25567 #endif /* CONFIG_DEBUG_RODATA */
25568 - return probe_kernel_write((char *)bpt->bpt_addr,
25569 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25570 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25571 }
25572
25573 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25574 index 93d2c04..36d0e94 100644
25575 --- a/arch/x86/kernel/kprobes/core.c
25576 +++ b/arch/x86/kernel/kprobes/core.c
25577 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25578 s32 raddr;
25579 } __packed *insn;
25580
25581 - insn = (struct __arch_relative_insn *)from;
25582 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25583 +
25584 + pax_open_kernel();
25585 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25586 insn->op = op;
25587 + pax_close_kernel();
25588 }
25589
25590 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25591 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25592 kprobe_opcode_t opcode;
25593 kprobe_opcode_t *orig_opcodes = opcodes;
25594
25595 - if (search_exception_tables((unsigned long)opcodes))
25596 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25597 return 0; /* Page fault may occur on this address. */
25598
25599 retry:
25600 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25601 * for the first byte, we can recover the original instruction
25602 * from it and kp->opcode.
25603 */
25604 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25605 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25606 buf[0] = kp->opcode;
25607 - return (unsigned long)buf;
25608 + return ktva_ktla((unsigned long)buf);
25609 }
25610
25611 /*
25612 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25613 /* Another subsystem puts a breakpoint, failed to recover */
25614 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25615 return 0;
25616 + pax_open_kernel();
25617 memcpy(dest, insn.kaddr, insn.length);
25618 + pax_close_kernel();
25619
25620 #ifdef CONFIG_X86_64
25621 if (insn_rip_relative(&insn)) {
25622 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25623 return 0;
25624 }
25625 disp = (u8 *) dest + insn_offset_displacement(&insn);
25626 + pax_open_kernel();
25627 *(s32 *) disp = (s32) newdisp;
25628 + pax_close_kernel();
25629 }
25630 #endif
25631 return insn.length;
25632 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25633 * nor set current_kprobe, because it doesn't use single
25634 * stepping.
25635 */
25636 - regs->ip = (unsigned long)p->ainsn.insn;
25637 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25638 preempt_enable_no_resched();
25639 return;
25640 }
25641 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25642 regs->flags &= ~X86_EFLAGS_IF;
25643 /* single step inline if the instruction is an int3 */
25644 if (p->opcode == BREAKPOINT_INSTRUCTION)
25645 - regs->ip = (unsigned long)p->addr;
25646 + regs->ip = ktla_ktva((unsigned long)p->addr);
25647 else
25648 - regs->ip = (unsigned long)p->ainsn.insn;
25649 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25650 }
25651 NOKPROBE_SYMBOL(setup_singlestep);
25652
25653 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25654 struct kprobe *p;
25655 struct kprobe_ctlblk *kcb;
25656
25657 - if (user_mode_vm(regs))
25658 + if (user_mode(regs))
25659 return 0;
25660
25661 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25662 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25663 setup_singlestep(p, regs, kcb, 0);
25664 return 1;
25665 }
25666 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25667 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25668 /*
25669 * The breakpoint instruction was removed right
25670 * after we hit it. Another cpu has removed
25671 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25672 " movq %rax, 152(%rsp)\n"
25673 RESTORE_REGS_STRING
25674 " popfq\n"
25675 +#ifdef KERNEXEC_PLUGIN
25676 + " btsq $63,(%rsp)\n"
25677 +#endif
25678 #else
25679 " pushf\n"
25680 SAVE_REGS_STRING
25681 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25682 struct kprobe_ctlblk *kcb)
25683 {
25684 unsigned long *tos = stack_addr(regs);
25685 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25686 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25687 unsigned long orig_ip = (unsigned long)p->addr;
25688 kprobe_opcode_t *insn = p->ainsn.insn;
25689
25690 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25691 struct die_args *args = data;
25692 int ret = NOTIFY_DONE;
25693
25694 - if (args->regs && user_mode_vm(args->regs))
25695 + if (args->regs && user_mode(args->regs))
25696 return ret;
25697
25698 if (val == DIE_GPF) {
25699 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25700 index f1314d0..15f3154 100644
25701 --- a/arch/x86/kernel/kprobes/opt.c
25702 +++ b/arch/x86/kernel/kprobes/opt.c
25703 @@ -79,6 +79,7 @@ found:
25704 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25705 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25706 {
25707 + pax_open_kernel();
25708 #ifdef CONFIG_X86_64
25709 *addr++ = 0x48;
25710 *addr++ = 0xbf;
25711 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25712 *addr++ = 0xb8;
25713 #endif
25714 *(unsigned long *)addr = val;
25715 + pax_close_kernel();
25716 }
25717
25718 asm (
25719 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25720 * Verify if the address gap is in 2GB range, because this uses
25721 * a relative jump.
25722 */
25723 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25724 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25725 if (abs(rel) > 0x7fffffff) {
25726 __arch_remove_optimized_kprobe(op, 0);
25727 return -ERANGE;
25728 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25729 op->optinsn.size = ret;
25730
25731 /* Copy arch-dep-instance from template */
25732 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25733 + pax_open_kernel();
25734 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25735 + pax_close_kernel();
25736
25737 /* Set probe information */
25738 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25739
25740 /* Set probe function call */
25741 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25742 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25743
25744 /* Set returning jmp instruction at the tail of out-of-line buffer */
25745 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25746 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25747 (u8 *)op->kp.addr + op->optinsn.size);
25748
25749 flush_icache_range((unsigned long) buf,
25750 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25751 WARN_ON(kprobe_disabled(&op->kp));
25752
25753 /* Backup instructions which will be replaced by jump address */
25754 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25755 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25756 RELATIVE_ADDR_SIZE);
25757
25758 insn_buf[0] = RELATIVEJUMP_OPCODE;
25759 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25760 /* This kprobe is really able to run optimized path. */
25761 op = container_of(p, struct optimized_kprobe, kp);
25762 /* Detour through copied instructions */
25763 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25764 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25765 if (!reenter)
25766 reset_current_kprobe();
25767 preempt_enable_no_resched();
25768 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25769 index c2bedae..25e7ab60 100644
25770 --- a/arch/x86/kernel/ksysfs.c
25771 +++ b/arch/x86/kernel/ksysfs.c
25772 @@ -184,7 +184,7 @@ out:
25773
25774 static struct kobj_attribute type_attr = __ATTR_RO(type);
25775
25776 -static struct bin_attribute data_attr = {
25777 +static bin_attribute_no_const data_attr __read_only = {
25778 .attr = {
25779 .name = "data",
25780 .mode = S_IRUGO,
25781 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25782 index c37886d..d851d32 100644
25783 --- a/arch/x86/kernel/ldt.c
25784 +++ b/arch/x86/kernel/ldt.c
25785 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25786 if (reload) {
25787 #ifdef CONFIG_SMP
25788 preempt_disable();
25789 - load_LDT(pc);
25790 + load_LDT_nolock(pc);
25791 if (!cpumask_equal(mm_cpumask(current->mm),
25792 cpumask_of(smp_processor_id())))
25793 smp_call_function(flush_ldt, current->mm, 1);
25794 preempt_enable();
25795 #else
25796 - load_LDT(pc);
25797 + load_LDT_nolock(pc);
25798 #endif
25799 }
25800 if (oldsize) {
25801 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25802 return err;
25803
25804 for (i = 0; i < old->size; i++)
25805 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25806 + write_ldt_entry(new->ldt, i, old->ldt + i);
25807 return 0;
25808 }
25809
25810 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25811 retval = copy_ldt(&mm->context, &old_mm->context);
25812 mutex_unlock(&old_mm->context.lock);
25813 }
25814 +
25815 + if (tsk == current) {
25816 + mm->context.vdso = 0;
25817 +
25818 +#ifdef CONFIG_X86_32
25819 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25820 + mm->context.user_cs_base = 0UL;
25821 + mm->context.user_cs_limit = ~0UL;
25822 +
25823 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25824 + cpus_clear(mm->context.cpu_user_cs_mask);
25825 +#endif
25826 +
25827 +#endif
25828 +#endif
25829 +
25830 + }
25831 +
25832 return retval;
25833 }
25834
25835 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25836 }
25837 }
25838
25839 +#ifdef CONFIG_PAX_SEGMEXEC
25840 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25841 + error = -EINVAL;
25842 + goto out_unlock;
25843 + }
25844 +#endif
25845 +
25846 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25847 error = -EINVAL;
25848 goto out_unlock;
25849 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25850 index 72e8e31..f2f1605 100644
25851 --- a/arch/x86/kernel/machine_kexec_32.c
25852 +++ b/arch/x86/kernel/machine_kexec_32.c
25853 @@ -25,7 +25,7 @@
25854 #include <asm/cacheflush.h>
25855 #include <asm/debugreg.h>
25856
25857 -static void set_idt(void *newidt, __u16 limit)
25858 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25859 {
25860 struct desc_ptr curidt;
25861
25862 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25863 }
25864
25865
25866 -static void set_gdt(void *newgdt, __u16 limit)
25867 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25868 {
25869 struct desc_ptr curgdt;
25870
25871 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25872 }
25873
25874 control_page = page_address(image->control_code_page);
25875 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25876 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25877
25878 relocate_kernel_ptr = control_page;
25879 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25880 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25881 index c73aecf..4c63630 100644
25882 --- a/arch/x86/kernel/mcount_64.S
25883 +++ b/arch/x86/kernel/mcount_64.S
25884 @@ -7,7 +7,7 @@
25885 #include <linux/linkage.h>
25886 #include <asm/ptrace.h>
25887 #include <asm/ftrace.h>
25888 -
25889 +#include <asm/alternative-asm.h>
25890
25891 .code64
25892 .section .entry.text, "ax"
25893 @@ -24,8 +24,9 @@
25894 #ifdef CONFIG_DYNAMIC_FTRACE
25895
25896 ENTRY(function_hook)
25897 + pax_force_retaddr
25898 retq
25899 -END(function_hook)
25900 +ENDPROC(function_hook)
25901
25902 /* skip is set if stack has been adjusted */
25903 .macro ftrace_caller_setup skip=0
25904 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25905 #endif
25906
25907 GLOBAL(ftrace_stub)
25908 + pax_force_retaddr
25909 retq
25910 -END(ftrace_caller)
25911 +ENDPROC(ftrace_caller)
25912
25913 ENTRY(ftrace_regs_caller)
25914 /* Save the current flags before compare (in SS location)*/
25915 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25916 popfq
25917 jmp ftrace_stub
25918
25919 -END(ftrace_regs_caller)
25920 +ENDPROC(ftrace_regs_caller)
25921
25922
25923 #else /* ! CONFIG_DYNAMIC_FTRACE */
25924 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25925 #endif
25926
25927 GLOBAL(ftrace_stub)
25928 + pax_force_retaddr
25929 retq
25930
25931 trace:
25932 @@ -158,12 +161,13 @@ trace:
25933 #endif
25934 subq $MCOUNT_INSN_SIZE, %rdi
25935
25936 + pax_force_fptr ftrace_trace_function
25937 call *ftrace_trace_function
25938
25939 MCOUNT_RESTORE_FRAME
25940
25941 jmp ftrace_stub
25942 -END(function_hook)
25943 +ENDPROC(function_hook)
25944 #endif /* CONFIG_DYNAMIC_FTRACE */
25945 #endif /* CONFIG_FUNCTION_TRACER */
25946
25947 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25948
25949 MCOUNT_RESTORE_FRAME
25950
25951 + pax_force_retaddr
25952 retq
25953 -END(ftrace_graph_caller)
25954 +ENDPROC(ftrace_graph_caller)
25955
25956 GLOBAL(return_to_handler)
25957 subq $24, %rsp
25958 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25959 movq 8(%rsp), %rdx
25960 movq (%rsp), %rax
25961 addq $24, %rsp
25962 + pax_force_fptr %rdi
25963 jmp *%rdi
25964 +ENDPROC(return_to_handler)
25965 #endif
25966 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25967 index e69f988..da078ea 100644
25968 --- a/arch/x86/kernel/module.c
25969 +++ b/arch/x86/kernel/module.c
25970 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25971 }
25972 #endif
25973
25974 -void *module_alloc(unsigned long size)
25975 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25976 {
25977 - if (PAGE_ALIGN(size) > MODULES_LEN)
25978 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25979 return NULL;
25980 return __vmalloc_node_range(size, 1,
25981 MODULES_VADDR + get_module_load_offset(),
25982 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25983 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25984 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25985 + prot, NUMA_NO_NODE,
25986 __builtin_return_address(0));
25987 }
25988
25989 +void *module_alloc(unsigned long size)
25990 +{
25991 +
25992 +#ifdef CONFIG_PAX_KERNEXEC
25993 + return __module_alloc(size, PAGE_KERNEL);
25994 +#else
25995 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25996 +#endif
25997 +
25998 +}
25999 +
26000 +#ifdef CONFIG_PAX_KERNEXEC
26001 +#ifdef CONFIG_X86_32
26002 +void *module_alloc_exec(unsigned long size)
26003 +{
26004 + struct vm_struct *area;
26005 +
26006 + if (size == 0)
26007 + return NULL;
26008 +
26009 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26010 +return area ? area->addr : NULL;
26011 +}
26012 +EXPORT_SYMBOL(module_alloc_exec);
26013 +
26014 +void module_free_exec(struct module *mod, void *module_region)
26015 +{
26016 + vunmap(module_region);
26017 +}
26018 +EXPORT_SYMBOL(module_free_exec);
26019 +#else
26020 +void module_free_exec(struct module *mod, void *module_region)
26021 +{
26022 + module_free(mod, module_region);
26023 +}
26024 +EXPORT_SYMBOL(module_free_exec);
26025 +
26026 +void *module_alloc_exec(unsigned long size)
26027 +{
26028 + return __module_alloc(size, PAGE_KERNEL_RX);
26029 +}
26030 +EXPORT_SYMBOL(module_alloc_exec);
26031 +#endif
26032 +#endif
26033 +
26034 #ifdef CONFIG_X86_32
26035 int apply_relocate(Elf32_Shdr *sechdrs,
26036 const char *strtab,
26037 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26038 unsigned int i;
26039 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26040 Elf32_Sym *sym;
26041 - uint32_t *location;
26042 + uint32_t *plocation, location;
26043
26044 DEBUGP("Applying relocate section %u to %u\n",
26045 relsec, sechdrs[relsec].sh_info);
26046 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26047 /* This is where to make the change */
26048 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26049 - + rel[i].r_offset;
26050 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26051 + location = (uint32_t)plocation;
26052 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26053 + plocation = ktla_ktva((void *)plocation);
26054 /* This is the symbol it is referring to. Note that all
26055 undefined symbols have been resolved. */
26056 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26057 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26058 switch (ELF32_R_TYPE(rel[i].r_info)) {
26059 case R_386_32:
26060 /* We add the value into the location given */
26061 - *location += sym->st_value;
26062 + pax_open_kernel();
26063 + *plocation += sym->st_value;
26064 + pax_close_kernel();
26065 break;
26066 case R_386_PC32:
26067 /* Add the value, subtract its position */
26068 - *location += sym->st_value - (uint32_t)location;
26069 + pax_open_kernel();
26070 + *plocation += sym->st_value - location;
26071 + pax_close_kernel();
26072 break;
26073 default:
26074 pr_err("%s: Unknown relocation: %u\n",
26075 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26076 case R_X86_64_NONE:
26077 break;
26078 case R_X86_64_64:
26079 + pax_open_kernel();
26080 *(u64 *)loc = val;
26081 + pax_close_kernel();
26082 break;
26083 case R_X86_64_32:
26084 + pax_open_kernel();
26085 *(u32 *)loc = val;
26086 + pax_close_kernel();
26087 if (val != *(u32 *)loc)
26088 goto overflow;
26089 break;
26090 case R_X86_64_32S:
26091 + pax_open_kernel();
26092 *(s32 *)loc = val;
26093 + pax_close_kernel();
26094 if ((s64)val != *(s32 *)loc)
26095 goto overflow;
26096 break;
26097 case R_X86_64_PC32:
26098 val -= (u64)loc;
26099 + pax_open_kernel();
26100 *(u32 *)loc = val;
26101 + pax_close_kernel();
26102 +
26103 #if 0
26104 if ((s64)val != *(s32 *)loc)
26105 goto overflow;
26106 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26107 index c9603ac..9f88728 100644
26108 --- a/arch/x86/kernel/msr.c
26109 +++ b/arch/x86/kernel/msr.c
26110 @@ -37,6 +37,7 @@
26111 #include <linux/notifier.h>
26112 #include <linux/uaccess.h>
26113 #include <linux/gfp.h>
26114 +#include <linux/grsecurity.h>
26115
26116 #include <asm/processor.h>
26117 #include <asm/msr.h>
26118 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26119 int err = 0;
26120 ssize_t bytes = 0;
26121
26122 +#ifdef CONFIG_GRKERNSEC_KMEM
26123 + gr_handle_msr_write();
26124 + return -EPERM;
26125 +#endif
26126 +
26127 if (count % 8)
26128 return -EINVAL; /* Invalid chunk size */
26129
26130 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26131 err = -EBADF;
26132 break;
26133 }
26134 +#ifdef CONFIG_GRKERNSEC_KMEM
26135 + gr_handle_msr_write();
26136 + return -EPERM;
26137 +#endif
26138 if (copy_from_user(&regs, uregs, sizeof regs)) {
26139 err = -EFAULT;
26140 break;
26141 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26142 return notifier_from_errno(err);
26143 }
26144
26145 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26146 +static struct notifier_block msr_class_cpu_notifier = {
26147 .notifier_call = msr_class_cpu_callback,
26148 };
26149
26150 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26151 index c3e985d..110a36a 100644
26152 --- a/arch/x86/kernel/nmi.c
26153 +++ b/arch/x86/kernel/nmi.c
26154 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26155
26156 static void nmi_max_handler(struct irq_work *w)
26157 {
26158 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26159 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26160 int remainder_ns, decimal_msecs;
26161 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26162 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26163
26164 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26165 decimal_msecs = remainder_ns / 1000;
26166
26167 printk_ratelimited(KERN_INFO
26168 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26169 - a->handler, whole_msecs, decimal_msecs);
26170 + n->action->handler, whole_msecs, decimal_msecs);
26171 }
26172
26173 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26174 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26175 delta = sched_clock() - delta;
26176 trace_nmi_handler(a->handler, (int)delta, thishandled);
26177
26178 - if (delta < nmi_longest_ns || delta < a->max_duration)
26179 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26180 continue;
26181
26182 - a->max_duration = delta;
26183 - irq_work_queue(&a->irq_work);
26184 + a->work->max_duration = delta;
26185 + irq_work_queue(&a->work->irq_work);
26186 }
26187
26188 rcu_read_unlock();
26189 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26190 }
26191 NOKPROBE_SYMBOL(nmi_handle);
26192
26193 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26194 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26195 {
26196 struct nmi_desc *desc = nmi_to_desc(type);
26197 unsigned long flags;
26198 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26199 if (!action->handler)
26200 return -EINVAL;
26201
26202 - init_irq_work(&action->irq_work, nmi_max_handler);
26203 + action->work->action = action;
26204 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26205
26206 spin_lock_irqsave(&desc->lock, flags);
26207
26208 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26209 * event confuses some handlers (kdump uses this flag)
26210 */
26211 if (action->flags & NMI_FLAG_FIRST)
26212 - list_add_rcu(&action->list, &desc->head);
26213 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26214 else
26215 - list_add_tail_rcu(&action->list, &desc->head);
26216 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26217
26218 spin_unlock_irqrestore(&desc->lock, flags);
26219 return 0;
26220 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26221 if (!strcmp(n->name, name)) {
26222 WARN(in_nmi(),
26223 "Trying to free NMI (%s) from NMI context!\n", n->name);
26224 - list_del_rcu(&n->list);
26225 + pax_list_del_rcu((struct list_head *)&n->list);
26226 break;
26227 }
26228 }
26229 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26230 dotraplinkage notrace void
26231 do_nmi(struct pt_regs *regs, long error_code)
26232 {
26233 +
26234 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26235 + if (!user_mode(regs)) {
26236 + unsigned long cs = regs->cs & 0xFFFF;
26237 + unsigned long ip = ktva_ktla(regs->ip);
26238 +
26239 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26240 + regs->ip = ip;
26241 + }
26242 +#endif
26243 +
26244 nmi_nesting_preprocess(regs);
26245
26246 nmi_enter();
26247 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26248 index 6d9582e..f746287 100644
26249 --- a/arch/x86/kernel/nmi_selftest.c
26250 +++ b/arch/x86/kernel/nmi_selftest.c
26251 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26252 {
26253 /* trap all the unknown NMIs we may generate */
26254 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26255 - __initdata);
26256 + __initconst);
26257 }
26258
26259 static void __init cleanup_nmi_testsuite(void)
26260 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26261 unsigned long timeout;
26262
26263 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26264 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26265 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26266 nmi_fail = FAILURE;
26267 return;
26268 }
26269 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26270 index bbb6c73..24a58ef 100644
26271 --- a/arch/x86/kernel/paravirt-spinlocks.c
26272 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26273 @@ -8,7 +8,7 @@
26274
26275 #include <asm/paravirt.h>
26276
26277 -struct pv_lock_ops pv_lock_ops = {
26278 +struct pv_lock_ops pv_lock_ops __read_only = {
26279 #ifdef CONFIG_SMP
26280 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26281 .unlock_kick = paravirt_nop,
26282 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26283 index 548d25f..f8fb99c 100644
26284 --- a/arch/x86/kernel/paravirt.c
26285 +++ b/arch/x86/kernel/paravirt.c
26286 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26287 {
26288 return x;
26289 }
26290 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26291 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26292 +#endif
26293
26294 void __init default_banner(void)
26295 {
26296 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26297
26298 if (opfunc == NULL)
26299 /* If there's no function, patch it with a ud2a (BUG) */
26300 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26301 - else if (opfunc == _paravirt_nop)
26302 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26303 + else if (opfunc == (void *)_paravirt_nop)
26304 /* If the operation is a nop, then nop the callsite */
26305 ret = paravirt_patch_nop();
26306
26307 /* identity functions just return their single argument */
26308 - else if (opfunc == _paravirt_ident_32)
26309 + else if (opfunc == (void *)_paravirt_ident_32)
26310 ret = paravirt_patch_ident_32(insnbuf, len);
26311 - else if (opfunc == _paravirt_ident_64)
26312 + else if (opfunc == (void *)_paravirt_ident_64)
26313 ret = paravirt_patch_ident_64(insnbuf, len);
26314 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26315 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26316 + ret = paravirt_patch_ident_64(insnbuf, len);
26317 +#endif
26318
26319 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26320 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26321 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26322 if (insn_len > len || start == NULL)
26323 insn_len = len;
26324 else
26325 - memcpy(insnbuf, start, insn_len);
26326 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26327
26328 return insn_len;
26329 }
26330 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26331 return this_cpu_read(paravirt_lazy_mode);
26332 }
26333
26334 -struct pv_info pv_info = {
26335 +struct pv_info pv_info __read_only = {
26336 .name = "bare hardware",
26337 .paravirt_enabled = 0,
26338 .kernel_rpl = 0,
26339 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26340 #endif
26341 };
26342
26343 -struct pv_init_ops pv_init_ops = {
26344 +struct pv_init_ops pv_init_ops __read_only = {
26345 .patch = native_patch,
26346 };
26347
26348 -struct pv_time_ops pv_time_ops = {
26349 +struct pv_time_ops pv_time_ops __read_only = {
26350 .sched_clock = native_sched_clock,
26351 .steal_clock = native_steal_clock,
26352 };
26353
26354 -__visible struct pv_irq_ops pv_irq_ops = {
26355 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26356 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26357 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26358 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26359 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26360 #endif
26361 };
26362
26363 -__visible struct pv_cpu_ops pv_cpu_ops = {
26364 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26365 .cpuid = native_cpuid,
26366 .get_debugreg = native_get_debugreg,
26367 .set_debugreg = native_set_debugreg,
26368 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26369 NOKPROBE_SYMBOL(native_set_debugreg);
26370 NOKPROBE_SYMBOL(native_load_idt);
26371
26372 -struct pv_apic_ops pv_apic_ops = {
26373 +struct pv_apic_ops pv_apic_ops __read_only= {
26374 #ifdef CONFIG_X86_LOCAL_APIC
26375 .startup_ipi_hook = paravirt_nop,
26376 #endif
26377 };
26378
26379 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26380 +#ifdef CONFIG_X86_32
26381 +#ifdef CONFIG_X86_PAE
26382 +/* 64-bit pagetable entries */
26383 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26384 +#else
26385 /* 32-bit pagetable entries */
26386 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26387 +#endif
26388 #else
26389 /* 64-bit pagetable entries */
26390 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26391 #endif
26392
26393 -struct pv_mmu_ops pv_mmu_ops = {
26394 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26395
26396 .read_cr2 = native_read_cr2,
26397 .write_cr2 = native_write_cr2,
26398 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26399 .make_pud = PTE_IDENT,
26400
26401 .set_pgd = native_set_pgd,
26402 + .set_pgd_batched = native_set_pgd_batched,
26403 #endif
26404 #endif /* PAGETABLE_LEVELS >= 3 */
26405
26406 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26407 },
26408
26409 .set_fixmap = native_set_fixmap,
26410 +
26411 +#ifdef CONFIG_PAX_KERNEXEC
26412 + .pax_open_kernel = native_pax_open_kernel,
26413 + .pax_close_kernel = native_pax_close_kernel,
26414 +#endif
26415 +
26416 };
26417
26418 EXPORT_SYMBOL_GPL(pv_time_ops);
26419 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26420 index a1da673..b6f5831 100644
26421 --- a/arch/x86/kernel/paravirt_patch_64.c
26422 +++ b/arch/x86/kernel/paravirt_patch_64.c
26423 @@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26424 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26425 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26426 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26427 +
26428 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26429 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26430 +#endif
26431 +
26432 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26433 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26434
26435 @@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26436 PATCH_SITE(pv_mmu_ops, read_cr3);
26437 PATCH_SITE(pv_mmu_ops, write_cr3);
26438 PATCH_SITE(pv_cpu_ops, clts);
26439 +
26440 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26441 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26442 +#endif
26443 +
26444 PATCH_SITE(pv_cpu_ops, wbinvd);
26445
26446 patch_site:
26447 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26448 index 0497f71..7186c0d 100644
26449 --- a/arch/x86/kernel/pci-calgary_64.c
26450 +++ b/arch/x86/kernel/pci-calgary_64.c
26451 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26452 tce_space = be64_to_cpu(readq(target));
26453 tce_space = tce_space & TAR_SW_BITS;
26454
26455 - tce_space = tce_space & (~specified_table_size);
26456 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26457 info->tce_space = (u64 *)__va(tce_space);
26458 }
26459 }
26460 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26461 index 35ccf75..7a15747 100644
26462 --- a/arch/x86/kernel/pci-iommu_table.c
26463 +++ b/arch/x86/kernel/pci-iommu_table.c
26464 @@ -2,7 +2,7 @@
26465 #include <asm/iommu_table.h>
26466 #include <linux/string.h>
26467 #include <linux/kallsyms.h>
26468 -
26469 +#include <linux/sched.h>
26470
26471 #define DEBUG 1
26472
26473 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26474 index 77dd0ad..9ec4723 100644
26475 --- a/arch/x86/kernel/pci-swiotlb.c
26476 +++ b/arch/x86/kernel/pci-swiotlb.c
26477 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26478 struct dma_attrs *attrs)
26479 {
26480 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26481 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26482 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26483 else
26484 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26485 }
26486 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26487 index e127dda..94e384d 100644
26488 --- a/arch/x86/kernel/process.c
26489 +++ b/arch/x86/kernel/process.c
26490 @@ -36,7 +36,8 @@
26491 * section. Since TSS's are completely CPU-local, we want them
26492 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26493 */
26494 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26495 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26496 +EXPORT_SYMBOL(init_tss);
26497
26498 #ifdef CONFIG_X86_64
26499 static DEFINE_PER_CPU(unsigned char, is_idle);
26500 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26501 task_xstate_cachep =
26502 kmem_cache_create("task_xstate", xstate_size,
26503 __alignof__(union thread_xstate),
26504 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26505 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26506 setup_xstate_comp();
26507 }
26508
26509 @@ -108,7 +109,7 @@ void exit_thread(void)
26510 unsigned long *bp = t->io_bitmap_ptr;
26511
26512 if (bp) {
26513 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26514 + struct tss_struct *tss = init_tss + get_cpu();
26515
26516 t->io_bitmap_ptr = NULL;
26517 clear_thread_flag(TIF_IO_BITMAP);
26518 @@ -128,6 +129,9 @@ void flush_thread(void)
26519 {
26520 struct task_struct *tsk = current;
26521
26522 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26523 + loadsegment(gs, 0);
26524 +#endif
26525 flush_ptrace_hw_breakpoint(tsk);
26526 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26527 drop_init_fpu(tsk);
26528 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26529 void exit_idle(void)
26530 {
26531 /* idle loop has pid 0 */
26532 - if (current->pid)
26533 + if (task_pid_nr(current))
26534 return;
26535 __exit_idle();
26536 }
26537 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26538 return ret;
26539 }
26540 #endif
26541 -void stop_this_cpu(void *dummy)
26542 +__noreturn void stop_this_cpu(void *dummy)
26543 {
26544 local_irq_disable();
26545 /*
26546 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26547 }
26548 early_param("idle", idle_setup);
26549
26550 -unsigned long arch_align_stack(unsigned long sp)
26551 +#ifdef CONFIG_PAX_RANDKSTACK
26552 +void pax_randomize_kstack(struct pt_regs *regs)
26553 {
26554 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26555 - sp -= get_random_int() % 8192;
26556 - return sp & ~0xf;
26557 -}
26558 + struct thread_struct *thread = &current->thread;
26559 + unsigned long time;
26560
26561 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26562 -{
26563 - unsigned long range_end = mm->brk + 0x02000000;
26564 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26565 -}
26566 + if (!randomize_va_space)
26567 + return;
26568 +
26569 + if (v8086_mode(regs))
26570 + return;
26571
26572 + rdtscl(time);
26573 +
26574 + /* P4 seems to return a 0 LSB, ignore it */
26575 +#ifdef CONFIG_MPENTIUM4
26576 + time &= 0x3EUL;
26577 + time <<= 2;
26578 +#elif defined(CONFIG_X86_64)
26579 + time &= 0xFUL;
26580 + time <<= 4;
26581 +#else
26582 + time &= 0x1FUL;
26583 + time <<= 3;
26584 +#endif
26585 +
26586 + thread->sp0 ^= time;
26587 + load_sp0(init_tss + smp_processor_id(), thread);
26588 +
26589 +#ifdef CONFIG_X86_64
26590 + this_cpu_write(kernel_stack, thread->sp0);
26591 +#endif
26592 +}
26593 +#endif
26594 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26595 index 8f3ebfe..cbc731b 100644
26596 --- a/arch/x86/kernel/process_32.c
26597 +++ b/arch/x86/kernel/process_32.c
26598 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26599 unsigned long thread_saved_pc(struct task_struct *tsk)
26600 {
26601 return ((unsigned long *)tsk->thread.sp)[3];
26602 +//XXX return tsk->thread.eip;
26603 }
26604
26605 void __show_regs(struct pt_regs *regs, int all)
26606 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26607 unsigned long sp;
26608 unsigned short ss, gs;
26609
26610 - if (user_mode_vm(regs)) {
26611 + if (user_mode(regs)) {
26612 sp = regs->sp;
26613 ss = regs->ss & 0xffff;
26614 - gs = get_user_gs(regs);
26615 } else {
26616 sp = kernel_stack_pointer(regs);
26617 savesegment(ss, ss);
26618 - savesegment(gs, gs);
26619 }
26620 + gs = get_user_gs(regs);
26621
26622 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26623 (u16)regs->cs, regs->ip, regs->flags,
26624 - smp_processor_id());
26625 + raw_smp_processor_id());
26626 print_symbol("EIP is at %s\n", regs->ip);
26627
26628 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26629 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26630 int copy_thread(unsigned long clone_flags, unsigned long sp,
26631 unsigned long arg, struct task_struct *p)
26632 {
26633 - struct pt_regs *childregs = task_pt_regs(p);
26634 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26635 struct task_struct *tsk;
26636 int err;
26637
26638 p->thread.sp = (unsigned long) childregs;
26639 p->thread.sp0 = (unsigned long) (childregs+1);
26640 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26641 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26642
26643 if (unlikely(p->flags & PF_KTHREAD)) {
26644 /* kernel thread */
26645 memset(childregs, 0, sizeof(struct pt_regs));
26646 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26647 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26648 - childregs->ds = __USER_DS;
26649 - childregs->es = __USER_DS;
26650 + savesegment(gs, childregs->gs);
26651 + childregs->ds = __KERNEL_DS;
26652 + childregs->es = __KERNEL_DS;
26653 childregs->fs = __KERNEL_PERCPU;
26654 childregs->bx = sp; /* function */
26655 childregs->bp = arg;
26656 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26657 struct thread_struct *prev = &prev_p->thread,
26658 *next = &next_p->thread;
26659 int cpu = smp_processor_id();
26660 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26661 + struct tss_struct *tss = init_tss + cpu;
26662 fpu_switch_t fpu;
26663
26664 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26665 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26666 */
26667 lazy_save_gs(prev->gs);
26668
26669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26670 + __set_fs(task_thread_info(next_p)->addr_limit);
26671 +#endif
26672 +
26673 /*
26674 * Load the per-thread Thread-Local Storage descriptor.
26675 */
26676 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26677 */
26678 arch_end_context_switch(next_p);
26679
26680 - this_cpu_write(kernel_stack,
26681 - (unsigned long)task_stack_page(next_p) +
26682 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26683 + this_cpu_write(current_task, next_p);
26684 + this_cpu_write(current_tinfo, &next_p->tinfo);
26685 + this_cpu_write(kernel_stack, next->sp0);
26686
26687 /*
26688 * Restore %gs if needed (which is common)
26689 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26690
26691 switch_fpu_finish(next_p, fpu);
26692
26693 - this_cpu_write(current_task, next_p);
26694 -
26695 return prev_p;
26696 }
26697
26698 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26699 } while (count++ < 16);
26700 return 0;
26701 }
26702 -
26703 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26704 index 5a2c029..ec8611d 100644
26705 --- a/arch/x86/kernel/process_64.c
26706 +++ b/arch/x86/kernel/process_64.c
26707 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26708 struct pt_regs *childregs;
26709 struct task_struct *me = current;
26710
26711 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26712 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26713 childregs = task_pt_regs(p);
26714 p->thread.sp = (unsigned long) childregs;
26715 p->thread.usersp = me->thread.usersp;
26716 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26717 set_tsk_thread_flag(p, TIF_FORK);
26718 p->thread.io_bitmap_ptr = NULL;
26719
26720 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26721 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26722 savesegment(es, p->thread.es);
26723 savesegment(ds, p->thread.ds);
26724 + savesegment(ss, p->thread.ss);
26725 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26726 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26727
26728 if (unlikely(p->flags & PF_KTHREAD)) {
26729 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26730 struct thread_struct *prev = &prev_p->thread;
26731 struct thread_struct *next = &next_p->thread;
26732 int cpu = smp_processor_id();
26733 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26734 + struct tss_struct *tss = init_tss + cpu;
26735 unsigned fsindex, gsindex;
26736 fpu_switch_t fpu;
26737
26738 @@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26739 if (unlikely(next->ds | prev->ds))
26740 loadsegment(ds, next->ds);
26741
26742 + savesegment(ss, prev->ss);
26743 + if (unlikely(next->ss != prev->ss))
26744 + loadsegment(ss, next->ss);
26745 +
26746 /*
26747 * Switch FS and GS.
26748 *
26749 @@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26750 prev->usersp = this_cpu_read(old_rsp);
26751 this_cpu_write(old_rsp, next->usersp);
26752 this_cpu_write(current_task, next_p);
26753 + this_cpu_write(current_tinfo, &next_p->tinfo);
26754
26755 /*
26756 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26757 @@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26758 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26759 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26760
26761 - this_cpu_write(kernel_stack,
26762 - (unsigned long)task_stack_page(next_p) +
26763 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26764 + this_cpu_write(kernel_stack, next->sp0);
26765
26766 /*
26767 * Now maybe reload the debug registers and handle I/O bitmaps
26768 @@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26769 if (!p || p == current || p->state == TASK_RUNNING)
26770 return 0;
26771 stack = (unsigned long)task_stack_page(p);
26772 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26773 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26774 return 0;
26775 fp = *(u64 *)(p->thread.sp);
26776 do {
26777 - if (fp < (unsigned long)stack ||
26778 - fp >= (unsigned long)stack+THREAD_SIZE)
26779 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26780 return 0;
26781 ip = *(u64 *)(fp+8);
26782 if (!in_sched_functions(ip))
26783 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26784 index e510618..5165ac0 100644
26785 --- a/arch/x86/kernel/ptrace.c
26786 +++ b/arch/x86/kernel/ptrace.c
26787 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26788 unsigned long sp = (unsigned long)&regs->sp;
26789 u32 *prev_esp;
26790
26791 - if (context == (sp & ~(THREAD_SIZE - 1)))
26792 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26793 return sp;
26794
26795 - prev_esp = (u32 *)(context);
26796 + prev_esp = *(u32 **)(context);
26797 if (prev_esp)
26798 return (unsigned long)prev_esp;
26799
26800 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26801 if (child->thread.gs != value)
26802 return do_arch_prctl(child, ARCH_SET_GS, value);
26803 return 0;
26804 +
26805 + case offsetof(struct user_regs_struct,ip):
26806 + /*
26807 + * Protect against any attempt to set ip to an
26808 + * impossible address. There are dragons lurking if the
26809 + * address is noncanonical. (This explicitly allows
26810 + * setting ip to TASK_SIZE_MAX, because user code can do
26811 + * that all by itself by running off the end of its
26812 + * address space.
26813 + */
26814 + if (value > TASK_SIZE_MAX)
26815 + return -EIO;
26816 + break;
26817 +
26818 #endif
26819 }
26820
26821 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26822 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26823 {
26824 int i;
26825 - int dr7 = 0;
26826 + unsigned long dr7 = 0;
26827 struct arch_hw_breakpoint *info;
26828
26829 for (i = 0; i < HBP_NUM; i++) {
26830 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26831 unsigned long addr, unsigned long data)
26832 {
26833 int ret;
26834 - unsigned long __user *datap = (unsigned long __user *)data;
26835 + unsigned long __user *datap = (__force unsigned long __user *)data;
26836
26837 switch (request) {
26838 /* read the word at location addr in the USER area. */
26839 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26840 if ((int) addr < 0)
26841 return -EIO;
26842 ret = do_get_thread_area(child, addr,
26843 - (struct user_desc __user *)data);
26844 + (__force struct user_desc __user *) data);
26845 break;
26846
26847 case PTRACE_SET_THREAD_AREA:
26848 if ((int) addr < 0)
26849 return -EIO;
26850 ret = do_set_thread_area(child, addr,
26851 - (struct user_desc __user *)data, 0);
26852 + (__force struct user_desc __user *) data, 0);
26853 break;
26854 #endif
26855
26856 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26857
26858 #ifdef CONFIG_X86_64
26859
26860 -static struct user_regset x86_64_regsets[] __read_mostly = {
26861 +static user_regset_no_const x86_64_regsets[] __read_only = {
26862 [REGSET_GENERAL] = {
26863 .core_note_type = NT_PRSTATUS,
26864 .n = sizeof(struct user_regs_struct) / sizeof(long),
26865 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26866 #endif /* CONFIG_X86_64 */
26867
26868 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26869 -static struct user_regset x86_32_regsets[] __read_mostly = {
26870 +static user_regset_no_const x86_32_regsets[] __read_only = {
26871 [REGSET_GENERAL] = {
26872 .core_note_type = NT_PRSTATUS,
26873 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26874 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26875 */
26876 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26877
26878 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26879 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26880 {
26881 #ifdef CONFIG_X86_64
26882 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26883 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26884 memset(info, 0, sizeof(*info));
26885 info->si_signo = SIGTRAP;
26886 info->si_code = si_code;
26887 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26888 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26889 }
26890
26891 void user_single_step_siginfo(struct task_struct *tsk,
26892 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26893 }
26894 }
26895
26896 +#ifdef CONFIG_GRKERNSEC_SETXID
26897 +extern void gr_delayed_cred_worker(void);
26898 +#endif
26899 +
26900 /*
26901 * We can return 0 to resume the syscall or anything else to go to phase
26902 * 2. If we resume the syscall, we need to put something appropriate in
26903 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26904
26905 BUG_ON(regs != task_pt_regs(current));
26906
26907 +#ifdef CONFIG_GRKERNSEC_SETXID
26908 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26909 + gr_delayed_cred_worker();
26910 +#endif
26911 +
26912 /*
26913 * If we stepped into a sysenter/syscall insn, it trapped in
26914 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26915 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26916 */
26917 user_exit();
26918
26919 +#ifdef CONFIG_GRKERNSEC_SETXID
26920 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26921 + gr_delayed_cred_worker();
26922 +#endif
26923 +
26924 audit_syscall_exit(regs);
26925
26926 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26927 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26928 index 2f355d2..e75ed0a 100644
26929 --- a/arch/x86/kernel/pvclock.c
26930 +++ b/arch/x86/kernel/pvclock.c
26931 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26932 reset_hung_task_detector();
26933 }
26934
26935 -static atomic64_t last_value = ATOMIC64_INIT(0);
26936 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26937
26938 void pvclock_resume(void)
26939 {
26940 - atomic64_set(&last_value, 0);
26941 + atomic64_set_unchecked(&last_value, 0);
26942 }
26943
26944 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26945 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26946 * updating at the same time, and one of them could be slightly behind,
26947 * making the assumption that last_value always go forward fail to hold.
26948 */
26949 - last = atomic64_read(&last_value);
26950 + last = atomic64_read_unchecked(&last_value);
26951 do {
26952 if (ret < last)
26953 return last;
26954 - last = atomic64_cmpxchg(&last_value, last, ret);
26955 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26956 } while (unlikely(last != ret));
26957
26958 return ret;
26959 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26960 index 17962e6..47f55db 100644
26961 --- a/arch/x86/kernel/reboot.c
26962 +++ b/arch/x86/kernel/reboot.c
26963 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26964
26965 void __noreturn machine_real_restart(unsigned int type)
26966 {
26967 +
26968 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26969 + struct desc_struct *gdt;
26970 +#endif
26971 +
26972 local_irq_disable();
26973
26974 /*
26975 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26976
26977 /* Jump to the identity-mapped low memory code */
26978 #ifdef CONFIG_X86_32
26979 - asm volatile("jmpl *%0" : :
26980 +
26981 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26982 + gdt = get_cpu_gdt_table(smp_processor_id());
26983 + pax_open_kernel();
26984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26985 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26986 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26987 + loadsegment(ds, __KERNEL_DS);
26988 + loadsegment(es, __KERNEL_DS);
26989 + loadsegment(ss, __KERNEL_DS);
26990 +#endif
26991 +#ifdef CONFIG_PAX_KERNEXEC
26992 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26993 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26994 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26995 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26996 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26997 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26998 +#endif
26999 + pax_close_kernel();
27000 +#endif
27001 +
27002 + asm volatile("ljmpl *%0" : :
27003 "rm" (real_mode_header->machine_real_restart_asm),
27004 "a" (type));
27005 #else
27006 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27007 * This means that this function can never return, it can misbehave
27008 * by not rebooting properly and hanging.
27009 */
27010 -static void native_machine_emergency_restart(void)
27011 +static void __noreturn native_machine_emergency_restart(void)
27012 {
27013 int i;
27014 int attempt = 0;
27015 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27016 #endif
27017 }
27018
27019 -static void __machine_emergency_restart(int emergency)
27020 +static void __noreturn __machine_emergency_restart(int emergency)
27021 {
27022 reboot_emergency = emergency;
27023 machine_ops.emergency_restart();
27024 }
27025
27026 -static void native_machine_restart(char *__unused)
27027 +static void __noreturn native_machine_restart(char *__unused)
27028 {
27029 pr_notice("machine restart\n");
27030
27031 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27032 __machine_emergency_restart(0);
27033 }
27034
27035 -static void native_machine_halt(void)
27036 +static void __noreturn native_machine_halt(void)
27037 {
27038 /* Stop other cpus and apics */
27039 machine_shutdown();
27040 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27041 stop_this_cpu(NULL);
27042 }
27043
27044 -static void native_machine_power_off(void)
27045 +static void __noreturn native_machine_power_off(void)
27046 {
27047 if (pm_power_off) {
27048 if (!reboot_force)
27049 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27050 }
27051 /* A fallback in case there is no PM info available */
27052 tboot_shutdown(TB_SHUTDOWN_HALT);
27053 + unreachable();
27054 }
27055
27056 -struct machine_ops machine_ops = {
27057 +struct machine_ops machine_ops __read_only = {
27058 .power_off = native_machine_power_off,
27059 .shutdown = native_machine_shutdown,
27060 .emergency_restart = native_machine_emergency_restart,
27061 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27062 index c8e41e9..64049ef 100644
27063 --- a/arch/x86/kernel/reboot_fixups_32.c
27064 +++ b/arch/x86/kernel/reboot_fixups_32.c
27065 @@ -57,7 +57,7 @@ struct device_fixup {
27066 unsigned int vendor;
27067 unsigned int device;
27068 void (*reboot_fixup)(struct pci_dev *);
27069 -};
27070 +} __do_const;
27071
27072 /*
27073 * PCI ids solely used for fixups_table go here
27074 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27075 index 3fd2c69..a444264 100644
27076 --- a/arch/x86/kernel/relocate_kernel_64.S
27077 +++ b/arch/x86/kernel/relocate_kernel_64.S
27078 @@ -96,8 +96,7 @@ relocate_kernel:
27079
27080 /* jump to identity mapped page */
27081 addq $(identity_mapped - relocate_kernel), %r8
27082 - pushq %r8
27083 - ret
27084 + jmp *%r8
27085
27086 identity_mapped:
27087 /* set return address to 0 if not preserving context */
27088 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27089 index ab08aa2..6d74a3a 100644
27090 --- a/arch/x86/kernel/setup.c
27091 +++ b/arch/x86/kernel/setup.c
27092 @@ -110,6 +110,7 @@
27093 #include <asm/mce.h>
27094 #include <asm/alternative.h>
27095 #include <asm/prom.h>
27096 +#include <asm/boot.h>
27097
27098 /*
27099 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27100 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27101 #endif
27102
27103
27104 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27105 -__visible unsigned long mmu_cr4_features;
27106 +#ifdef CONFIG_X86_64
27107 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27108 +#elif defined(CONFIG_X86_PAE)
27109 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27110 #else
27111 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27112 +__visible unsigned long mmu_cr4_features __read_only;
27113 #endif
27114
27115 +void set_in_cr4(unsigned long mask)
27116 +{
27117 + unsigned long cr4 = read_cr4();
27118 +
27119 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27120 + return;
27121 +
27122 + pax_open_kernel();
27123 + mmu_cr4_features |= mask;
27124 + pax_close_kernel();
27125 +
27126 + if (trampoline_cr4_features)
27127 + *trampoline_cr4_features = mmu_cr4_features;
27128 + cr4 |= mask;
27129 + write_cr4(cr4);
27130 +}
27131 +EXPORT_SYMBOL(set_in_cr4);
27132 +
27133 +void clear_in_cr4(unsigned long mask)
27134 +{
27135 + unsigned long cr4 = read_cr4();
27136 +
27137 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27138 + return;
27139 +
27140 + pax_open_kernel();
27141 + mmu_cr4_features &= ~mask;
27142 + pax_close_kernel();
27143 +
27144 + if (trampoline_cr4_features)
27145 + *trampoline_cr4_features = mmu_cr4_features;
27146 + cr4 &= ~mask;
27147 + write_cr4(cr4);
27148 +}
27149 +EXPORT_SYMBOL(clear_in_cr4);
27150 +
27151 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27152 int bootloader_type, bootloader_version;
27153
27154 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27155 * area (640->1Mb) as ram even though it is not.
27156 * take them out.
27157 */
27158 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27159 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27160
27161 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27162 }
27163 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27164 /* called before trim_bios_range() to spare extra sanitize */
27165 static void __init e820_add_kernel_range(void)
27166 {
27167 - u64 start = __pa_symbol(_text);
27168 + u64 start = __pa_symbol(ktla_ktva(_text));
27169 u64 size = __pa_symbol(_end) - start;
27170
27171 /*
27172 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27173
27174 void __init setup_arch(char **cmdline_p)
27175 {
27176 +#ifdef CONFIG_X86_32
27177 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27178 +#else
27179 memblock_reserve(__pa_symbol(_text),
27180 (unsigned long)__bss_stop - (unsigned long)_text);
27181 +#endif
27182
27183 early_reserve_initrd();
27184
27185 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27186
27187 if (!boot_params.hdr.root_flags)
27188 root_mountflags &= ~MS_RDONLY;
27189 - init_mm.start_code = (unsigned long) _text;
27190 - init_mm.end_code = (unsigned long) _etext;
27191 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27192 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27193 init_mm.end_data = (unsigned long) _edata;
27194 init_mm.brk = _brk_end;
27195
27196 - code_resource.start = __pa_symbol(_text);
27197 - code_resource.end = __pa_symbol(_etext)-1;
27198 - data_resource.start = __pa_symbol(_etext);
27199 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27200 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27201 + data_resource.start = __pa_symbol(_sdata);
27202 data_resource.end = __pa_symbol(_edata)-1;
27203 bss_resource.start = __pa_symbol(__bss_start);
27204 bss_resource.end = __pa_symbol(__bss_stop)-1;
27205 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27206 index 5cdff03..80fa283 100644
27207 --- a/arch/x86/kernel/setup_percpu.c
27208 +++ b/arch/x86/kernel/setup_percpu.c
27209 @@ -21,19 +21,17 @@
27210 #include <asm/cpu.h>
27211 #include <asm/stackprotector.h>
27212
27213 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27214 +#ifdef CONFIG_SMP
27215 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27216 EXPORT_PER_CPU_SYMBOL(cpu_number);
27217 +#endif
27218
27219 -#ifdef CONFIG_X86_64
27220 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27221 -#else
27222 -#define BOOT_PERCPU_OFFSET 0
27223 -#endif
27224
27225 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27226 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27227
27228 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27229 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27230 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27231 };
27232 EXPORT_SYMBOL(__per_cpu_offset);
27233 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27234 {
27235 #ifdef CONFIG_NEED_MULTIPLE_NODES
27236 pg_data_t *last = NULL;
27237 - unsigned int cpu;
27238 + int cpu;
27239
27240 for_each_possible_cpu(cpu) {
27241 int node = early_cpu_to_node(cpu);
27242 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27243 {
27244 #ifdef CONFIG_X86_32
27245 struct desc_struct gdt;
27246 + unsigned long base = per_cpu_offset(cpu);
27247
27248 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27249 - 0x2 | DESCTYPE_S, 0x8);
27250 - gdt.s = 1;
27251 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27252 + 0x83 | DESCTYPE_S, 0xC);
27253 write_gdt_entry(get_cpu_gdt_table(cpu),
27254 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27255 #endif
27256 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27257 /* alrighty, percpu areas up and running */
27258 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27259 for_each_possible_cpu(cpu) {
27260 +#ifdef CONFIG_CC_STACKPROTECTOR
27261 +#ifdef CONFIG_X86_32
27262 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27263 +#endif
27264 +#endif
27265 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27266 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27267 per_cpu(cpu_number, cpu) = cpu;
27268 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27269 */
27270 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27271 #endif
27272 +#ifdef CONFIG_CC_STACKPROTECTOR
27273 +#ifdef CONFIG_X86_32
27274 + if (!cpu)
27275 + per_cpu(stack_canary.canary, cpu) = canary;
27276 +#endif
27277 +#endif
27278 /*
27279 * Up to this point, the boot CPU has been using .init.data
27280 * area. Reload any changed state for the boot CPU.
27281 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27282 index ed37a76..39f936e 100644
27283 --- a/arch/x86/kernel/signal.c
27284 +++ b/arch/x86/kernel/signal.c
27285 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27286 * Align the stack pointer according to the i386 ABI,
27287 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27288 */
27289 - sp = ((sp + 4) & -16ul) - 4;
27290 + sp = ((sp - 12) & -16ul) - 4;
27291 #else /* !CONFIG_X86_32 */
27292 sp = round_down(sp, 16) - 8;
27293 #endif
27294 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27295 }
27296
27297 if (current->mm->context.vdso)
27298 - restorer = current->mm->context.vdso +
27299 - selected_vdso32->sym___kernel_sigreturn;
27300 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27301 else
27302 - restorer = &frame->retcode;
27303 + restorer = (void __user *)&frame->retcode;
27304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27305 restorer = ksig->ka.sa.sa_restorer;
27306
27307 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27308 * reasons and because gdb uses it as a signature to notice
27309 * signal handler stack frames.
27310 */
27311 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27312 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27313
27314 if (err)
27315 return -EFAULT;
27316 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27317 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27318
27319 /* Set up to return from userspace. */
27320 - restorer = current->mm->context.vdso +
27321 - selected_vdso32->sym___kernel_rt_sigreturn;
27322 + if (current->mm->context.vdso)
27323 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27324 + else
27325 + restorer = (void __user *)&frame->retcode;
27326 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27327 restorer = ksig->ka.sa.sa_restorer;
27328 put_user_ex(restorer, &frame->pretcode);
27329 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27330 * reasons and because gdb uses it as a signature to notice
27331 * signal handler stack frames.
27332 */
27333 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27334 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27335 } put_user_catch(err);
27336
27337 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27338 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27339 {
27340 int usig = signr_convert(ksig->sig);
27341 sigset_t *set = sigmask_to_save();
27342 - compat_sigset_t *cset = (compat_sigset_t *) set;
27343 + sigset_t sigcopy;
27344 + compat_sigset_t *cset;
27345 +
27346 + sigcopy = *set;
27347 +
27348 + cset = (compat_sigset_t *) &sigcopy;
27349
27350 /* Set up the stack frame */
27351 if (is_ia32_frame()) {
27352 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27353 } else if (is_x32_frame()) {
27354 return x32_setup_rt_frame(ksig, cset, regs);
27355 } else {
27356 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27357 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27358 }
27359 }
27360
27361 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27362 index be8e1bd..a3d93fa 100644
27363 --- a/arch/x86/kernel/smp.c
27364 +++ b/arch/x86/kernel/smp.c
27365 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27366
27367 __setup("nonmi_ipi", nonmi_ipi_setup);
27368
27369 -struct smp_ops smp_ops = {
27370 +struct smp_ops smp_ops __read_only = {
27371 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27372 .smp_prepare_cpus = native_smp_prepare_cpus,
27373 .smp_cpus_done = native_smp_cpus_done,
27374 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27375 index 668d8f2..84a9d54 100644
27376 --- a/arch/x86/kernel/smpboot.c
27377 +++ b/arch/x86/kernel/smpboot.c
27378 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27379
27380 enable_start_cpu0 = 0;
27381
27382 -#ifdef CONFIG_X86_32
27383 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27384 + barrier();
27385 +
27386 /* switch away from the initial page table */
27387 +#ifdef CONFIG_PAX_PER_CPU_PGD
27388 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27389 +#else
27390 load_cr3(swapper_pg_dir);
27391 +#endif
27392 __flush_tlb_all();
27393 -#endif
27394
27395 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27396 - barrier();
27397 /*
27398 * Check TSC synchronization with the BP:
27399 */
27400 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27401 alternatives_enable_smp();
27402
27403 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27404 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27405 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27406 per_cpu(current_task, cpu) = idle;
27407 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27408
27409 #ifdef CONFIG_X86_32
27410 /* Stack for startup_32 can be just as for start_secondary onwards */
27411 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27412 clear_tsk_thread_flag(idle, TIF_FORK);
27413 initial_gs = per_cpu_offset(cpu);
27414 #endif
27415 - per_cpu(kernel_stack, cpu) =
27416 - (unsigned long)task_stack_page(idle) -
27417 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27418 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27419 + pax_open_kernel();
27420 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27421 + pax_close_kernel();
27422 initial_code = (unsigned long)start_secondary;
27423 stack_start = idle->thread.sp;
27424
27425 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27426 /* the FPU context is blank, nobody can own it */
27427 __cpu_disable_lazy_restore(cpu);
27428
27429 +#ifdef CONFIG_PAX_PER_CPU_PGD
27430 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27431 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27432 + KERNEL_PGD_PTRS);
27433 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27434 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27435 + KERNEL_PGD_PTRS);
27436 +#endif
27437 +
27438 err = do_boot_cpu(apicid, cpu, tidle);
27439 if (err) {
27440 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27441 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27442 index 9b4d51d..5d28b58 100644
27443 --- a/arch/x86/kernel/step.c
27444 +++ b/arch/x86/kernel/step.c
27445 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27446 struct desc_struct *desc;
27447 unsigned long base;
27448
27449 - seg &= ~7UL;
27450 + seg >>= 3;
27451
27452 mutex_lock(&child->mm->context.lock);
27453 - if (unlikely((seg >> 3) >= child->mm->context.size))
27454 + if (unlikely(seg >= child->mm->context.size))
27455 addr = -1L; /* bogus selector, access would fault */
27456 else {
27457 desc = child->mm->context.ldt + seg;
27458 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27459 addr += base;
27460 }
27461 mutex_unlock(&child->mm->context.lock);
27462 - }
27463 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27464 + addr = ktla_ktva(addr);
27465
27466 return addr;
27467 }
27468 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27469 unsigned char opcode[15];
27470 unsigned long addr = convert_ip_to_linear(child, regs);
27471
27472 + if (addr == -EINVAL)
27473 + return 0;
27474 +
27475 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27476 for (i = 0; i < copied; i++) {
27477 switch (opcode[i]) {
27478 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27479 new file mode 100644
27480 index 0000000..5877189
27481 --- /dev/null
27482 +++ b/arch/x86/kernel/sys_i386_32.c
27483 @@ -0,0 +1,189 @@
27484 +/*
27485 + * This file contains various random system calls that
27486 + * have a non-standard calling sequence on the Linux/i386
27487 + * platform.
27488 + */
27489 +
27490 +#include <linux/errno.h>
27491 +#include <linux/sched.h>
27492 +#include <linux/mm.h>
27493 +#include <linux/fs.h>
27494 +#include <linux/smp.h>
27495 +#include <linux/sem.h>
27496 +#include <linux/msg.h>
27497 +#include <linux/shm.h>
27498 +#include <linux/stat.h>
27499 +#include <linux/syscalls.h>
27500 +#include <linux/mman.h>
27501 +#include <linux/file.h>
27502 +#include <linux/utsname.h>
27503 +#include <linux/ipc.h>
27504 +#include <linux/elf.h>
27505 +
27506 +#include <linux/uaccess.h>
27507 +#include <linux/unistd.h>
27508 +
27509 +#include <asm/syscalls.h>
27510 +
27511 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27512 +{
27513 + unsigned long pax_task_size = TASK_SIZE;
27514 +
27515 +#ifdef CONFIG_PAX_SEGMEXEC
27516 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27517 + pax_task_size = SEGMEXEC_TASK_SIZE;
27518 +#endif
27519 +
27520 + if (flags & MAP_FIXED)
27521 + if (len > pax_task_size || addr > pax_task_size - len)
27522 + return -EINVAL;
27523 +
27524 + return 0;
27525 +}
27526 +
27527 +/*
27528 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27529 + */
27530 +static unsigned long get_align_mask(void)
27531 +{
27532 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27533 + return 0;
27534 +
27535 + if (!(current->flags & PF_RANDOMIZE))
27536 + return 0;
27537 +
27538 + return va_align.mask;
27539 +}
27540 +
27541 +unsigned long
27542 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27543 + unsigned long len, unsigned long pgoff, unsigned long flags)
27544 +{
27545 + struct mm_struct *mm = current->mm;
27546 + struct vm_area_struct *vma;
27547 + unsigned long pax_task_size = TASK_SIZE;
27548 + struct vm_unmapped_area_info info;
27549 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27550 +
27551 +#ifdef CONFIG_PAX_SEGMEXEC
27552 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27553 + pax_task_size = SEGMEXEC_TASK_SIZE;
27554 +#endif
27555 +
27556 + pax_task_size -= PAGE_SIZE;
27557 +
27558 + if (len > pax_task_size)
27559 + return -ENOMEM;
27560 +
27561 + if (flags & MAP_FIXED)
27562 + return addr;
27563 +
27564 +#ifdef CONFIG_PAX_RANDMMAP
27565 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27566 +#endif
27567 +
27568 + if (addr) {
27569 + addr = PAGE_ALIGN(addr);
27570 + if (pax_task_size - len >= addr) {
27571 + vma = find_vma(mm, addr);
27572 + if (check_heap_stack_gap(vma, addr, len, offset))
27573 + return addr;
27574 + }
27575 + }
27576 +
27577 + info.flags = 0;
27578 + info.length = len;
27579 + info.align_mask = filp ? get_align_mask() : 0;
27580 + info.align_offset = pgoff << PAGE_SHIFT;
27581 + info.threadstack_offset = offset;
27582 +
27583 +#ifdef CONFIG_PAX_PAGEEXEC
27584 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27585 + info.low_limit = 0x00110000UL;
27586 + info.high_limit = mm->start_code;
27587 +
27588 +#ifdef CONFIG_PAX_RANDMMAP
27589 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27590 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27591 +#endif
27592 +
27593 + if (info.low_limit < info.high_limit) {
27594 + addr = vm_unmapped_area(&info);
27595 + if (!IS_ERR_VALUE(addr))
27596 + return addr;
27597 + }
27598 + } else
27599 +#endif
27600 +
27601 + info.low_limit = mm->mmap_base;
27602 + info.high_limit = pax_task_size;
27603 +
27604 + return vm_unmapped_area(&info);
27605 +}
27606 +
27607 +unsigned long
27608 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27609 + const unsigned long len, const unsigned long pgoff,
27610 + const unsigned long flags)
27611 +{
27612 + struct vm_area_struct *vma;
27613 + struct mm_struct *mm = current->mm;
27614 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27615 + struct vm_unmapped_area_info info;
27616 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27617 +
27618 +#ifdef CONFIG_PAX_SEGMEXEC
27619 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27620 + pax_task_size = SEGMEXEC_TASK_SIZE;
27621 +#endif
27622 +
27623 + pax_task_size -= PAGE_SIZE;
27624 +
27625 + /* requested length too big for entire address space */
27626 + if (len > pax_task_size)
27627 + return -ENOMEM;
27628 +
27629 + if (flags & MAP_FIXED)
27630 + return addr;
27631 +
27632 +#ifdef CONFIG_PAX_PAGEEXEC
27633 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27634 + goto bottomup;
27635 +#endif
27636 +
27637 +#ifdef CONFIG_PAX_RANDMMAP
27638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27639 +#endif
27640 +
27641 + /* requesting a specific address */
27642 + if (addr) {
27643 + addr = PAGE_ALIGN(addr);
27644 + if (pax_task_size - len >= addr) {
27645 + vma = find_vma(mm, addr);
27646 + if (check_heap_stack_gap(vma, addr, len, offset))
27647 + return addr;
27648 + }
27649 + }
27650 +
27651 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27652 + info.length = len;
27653 + info.low_limit = PAGE_SIZE;
27654 + info.high_limit = mm->mmap_base;
27655 + info.align_mask = filp ? get_align_mask() : 0;
27656 + info.align_offset = pgoff << PAGE_SHIFT;
27657 + info.threadstack_offset = offset;
27658 +
27659 + addr = vm_unmapped_area(&info);
27660 + if (!(addr & ~PAGE_MASK))
27661 + return addr;
27662 + VM_BUG_ON(addr != -ENOMEM);
27663 +
27664 +bottomup:
27665 + /*
27666 + * A failed mmap() very likely causes application failure,
27667 + * so fall back to the bottom-up function here. This scenario
27668 + * can happen with large stack limits and large mmap()
27669 + * allocations.
27670 + */
27671 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27672 +}
27673 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27674 index 30277e2..5664a29 100644
27675 --- a/arch/x86/kernel/sys_x86_64.c
27676 +++ b/arch/x86/kernel/sys_x86_64.c
27677 @@ -81,8 +81,8 @@ out:
27678 return error;
27679 }
27680
27681 -static void find_start_end(unsigned long flags, unsigned long *begin,
27682 - unsigned long *end)
27683 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27684 + unsigned long *begin, unsigned long *end)
27685 {
27686 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27687 unsigned long new_begin;
27688 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27689 *begin = new_begin;
27690 }
27691 } else {
27692 - *begin = current->mm->mmap_legacy_base;
27693 + *begin = mm->mmap_legacy_base;
27694 *end = TASK_SIZE;
27695 }
27696 }
27697 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27698 struct vm_area_struct *vma;
27699 struct vm_unmapped_area_info info;
27700 unsigned long begin, end;
27701 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27702
27703 if (flags & MAP_FIXED)
27704 return addr;
27705
27706 - find_start_end(flags, &begin, &end);
27707 + find_start_end(mm, flags, &begin, &end);
27708
27709 if (len > end)
27710 return -ENOMEM;
27711
27712 +#ifdef CONFIG_PAX_RANDMMAP
27713 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27714 +#endif
27715 +
27716 if (addr) {
27717 addr = PAGE_ALIGN(addr);
27718 vma = find_vma(mm, addr);
27719 - if (end - len >= addr &&
27720 - (!vma || addr + len <= vma->vm_start))
27721 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27722 return addr;
27723 }
27724
27725 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27726 info.high_limit = end;
27727 info.align_mask = filp ? get_align_mask() : 0;
27728 info.align_offset = pgoff << PAGE_SHIFT;
27729 + info.threadstack_offset = offset;
27730 return vm_unmapped_area(&info);
27731 }
27732
27733 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27734 struct mm_struct *mm = current->mm;
27735 unsigned long addr = addr0;
27736 struct vm_unmapped_area_info info;
27737 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27738
27739 /* requested length too big for entire address space */
27740 if (len > TASK_SIZE)
27741 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27742 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27743 goto bottomup;
27744
27745 +#ifdef CONFIG_PAX_RANDMMAP
27746 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27747 +#endif
27748 +
27749 /* requesting a specific address */
27750 if (addr) {
27751 addr = PAGE_ALIGN(addr);
27752 vma = find_vma(mm, addr);
27753 - if (TASK_SIZE - len >= addr &&
27754 - (!vma || addr + len <= vma->vm_start))
27755 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27756 return addr;
27757 }
27758
27759 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27760 info.high_limit = mm->mmap_base;
27761 info.align_mask = filp ? get_align_mask() : 0;
27762 info.align_offset = pgoff << PAGE_SHIFT;
27763 + info.threadstack_offset = offset;
27764 addr = vm_unmapped_area(&info);
27765 if (!(addr & ~PAGE_MASK))
27766 return addr;
27767 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27768 index 91a4496..bb87552 100644
27769 --- a/arch/x86/kernel/tboot.c
27770 +++ b/arch/x86/kernel/tboot.c
27771 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27772
27773 void tboot_shutdown(u32 shutdown_type)
27774 {
27775 - void (*shutdown)(void);
27776 + void (* __noreturn shutdown)(void);
27777
27778 if (!tboot_enabled())
27779 return;
27780 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27781
27782 switch_to_tboot_pt();
27783
27784 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27785 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27786 shutdown();
27787
27788 /* should not reach here */
27789 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27790 return -ENODEV;
27791 }
27792
27793 -static atomic_t ap_wfs_count;
27794 +static atomic_unchecked_t ap_wfs_count;
27795
27796 static int tboot_wait_for_aps(int num_aps)
27797 {
27798 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27799 {
27800 switch (action) {
27801 case CPU_DYING:
27802 - atomic_inc(&ap_wfs_count);
27803 + atomic_inc_unchecked(&ap_wfs_count);
27804 if (num_online_cpus() == 1)
27805 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27806 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27807 return NOTIFY_BAD;
27808 break;
27809 }
27810 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27811
27812 tboot_create_trampoline();
27813
27814 - atomic_set(&ap_wfs_count, 0);
27815 + atomic_set_unchecked(&ap_wfs_count, 0);
27816 register_hotcpu_notifier(&tboot_cpu_notifier);
27817
27818 #ifdef CONFIG_DEBUG_FS
27819 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27820 index 0fa2960..91eabbe 100644
27821 --- a/arch/x86/kernel/time.c
27822 +++ b/arch/x86/kernel/time.c
27823 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27824 {
27825 unsigned long pc = instruction_pointer(regs);
27826
27827 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27828 + if (!user_mode(regs) && in_lock_functions(pc)) {
27829 #ifdef CONFIG_FRAME_POINTER
27830 - return *(unsigned long *)(regs->bp + sizeof(long));
27831 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27832 #else
27833 unsigned long *sp =
27834 (unsigned long *)kernel_stack_pointer(regs);
27835 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27836 * or above a saved flags. Eflags has bits 22-31 zero,
27837 * kernel addresses don't.
27838 */
27839 +
27840 +#ifdef CONFIG_PAX_KERNEXEC
27841 + return ktla_ktva(sp[0]);
27842 +#else
27843 if (sp[0] >> 22)
27844 return sp[0];
27845 if (sp[1] >> 22)
27846 return sp[1];
27847 #endif
27848 +
27849 +#endif
27850 }
27851 return pc;
27852 }
27853 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27854 index 7fc5e84..c6e445a 100644
27855 --- a/arch/x86/kernel/tls.c
27856 +++ b/arch/x86/kernel/tls.c
27857 @@ -139,6 +139,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27858 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27859 return -EINVAL;
27860
27861 +#ifdef CONFIG_PAX_SEGMEXEC
27862 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27863 + return -EINVAL;
27864 +#endif
27865 +
27866 set_tls_desc(p, idx, &info, 1);
27867
27868 return 0;
27869 @@ -256,7 +261,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27870
27871 if (kbuf)
27872 info = kbuf;
27873 - else if (__copy_from_user(infobuf, ubuf, count))
27874 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27875 return -EFAULT;
27876 else
27877 info = infobuf;
27878 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27879 index 1c113db..287b42e 100644
27880 --- a/arch/x86/kernel/tracepoint.c
27881 +++ b/arch/x86/kernel/tracepoint.c
27882 @@ -9,11 +9,11 @@
27883 #include <linux/atomic.h>
27884
27885 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27886 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27887 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27888 (unsigned long) trace_idt_table };
27889
27890 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27891 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27892 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27893
27894 static int trace_irq_vector_refcount;
27895 static DEFINE_MUTEX(irq_vector_mutex);
27896 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27897 index 07ab8e9..99c8456 100644
27898 --- a/arch/x86/kernel/traps.c
27899 +++ b/arch/x86/kernel/traps.c
27900 @@ -67,7 +67,7 @@
27901 #include <asm/proto.h>
27902
27903 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27904 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27905 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27906 #else
27907 #include <asm/processor-flags.h>
27908 #include <asm/setup.h>
27909 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27910 #endif
27911
27912 /* Must be page-aligned because the real IDT is used in a fixmap. */
27913 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27914 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27915
27916 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27917 EXPORT_SYMBOL_GPL(used_vectors);
27918 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27919 }
27920
27921 static nokprobe_inline int
27922 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27923 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27924 struct pt_regs *regs, long error_code)
27925 {
27926 #ifdef CONFIG_X86_32
27927 - if (regs->flags & X86_VM_MASK) {
27928 + if (v8086_mode(regs)) {
27929 /*
27930 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27931 * On nmi (interrupt 2), do_trap should not be called.
27932 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27933 return -1;
27934 }
27935 #endif
27936 - if (!user_mode(regs)) {
27937 + if (!user_mode_novm(regs)) {
27938 if (!fixup_exception(regs)) {
27939 tsk->thread.error_code = error_code;
27940 tsk->thread.trap_nr = trapnr;
27941 +
27942 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27943 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27944 + str = "PAX: suspicious stack segment fault";
27945 +#endif
27946 +
27947 die(str, regs, error_code);
27948 }
27949 +
27950 +#ifdef CONFIG_PAX_REFCOUNT
27951 + if (trapnr == X86_TRAP_OF)
27952 + pax_report_refcount_overflow(regs);
27953 +#endif
27954 +
27955 return 0;
27956 }
27957
27958 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27959 }
27960
27961 static void
27962 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27963 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27964 long error_code, siginfo_t *info)
27965 {
27966 struct task_struct *tsk = current;
27967 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27968 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27969 printk_ratelimit()) {
27970 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27971 - tsk->comm, tsk->pid, str,
27972 + tsk->comm, task_pid_nr(tsk), str,
27973 regs->ip, regs->sp, error_code);
27974 print_vma_addr(" in ", regs->ip);
27975 pr_cont("\n");
27976 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27977 tsk->thread.error_code = error_code;
27978 tsk->thread.trap_nr = X86_TRAP_DF;
27979
27980 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27981 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27982 + die("grsec: kernel stack overflow detected", regs, error_code);
27983 +#endif
27984 +
27985 #ifdef CONFIG_DOUBLEFAULT
27986 df_debug(regs, error_code);
27987 #endif
27988 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27989 conditional_sti(regs);
27990
27991 #ifdef CONFIG_X86_32
27992 - if (regs->flags & X86_VM_MASK) {
27993 + if (v8086_mode(regs)) {
27994 local_irq_enable();
27995 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27996 goto exit;
27997 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27998 #endif
27999
28000 tsk = current;
28001 - if (!user_mode(regs)) {
28002 + if (!user_mode_novm(regs)) {
28003 if (fixup_exception(regs))
28004 goto exit;
28005
28006 tsk->thread.error_code = error_code;
28007 tsk->thread.trap_nr = X86_TRAP_GP;
28008 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28009 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28010 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28011 +
28012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28013 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28014 + die("PAX: suspicious general protection fault", regs, error_code);
28015 + else
28016 +#endif
28017 +
28018 die("general protection fault", regs, error_code);
28019 + }
28020 goto exit;
28021 }
28022
28023 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28024 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28025 + struct mm_struct *mm = tsk->mm;
28026 + unsigned long limit;
28027 +
28028 + down_write(&mm->mmap_sem);
28029 + limit = mm->context.user_cs_limit;
28030 + if (limit < TASK_SIZE) {
28031 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28032 + up_write(&mm->mmap_sem);
28033 + return;
28034 + }
28035 + up_write(&mm->mmap_sem);
28036 + }
28037 +#endif
28038 +
28039 tsk->thread.error_code = error_code;
28040 tsk->thread.trap_nr = X86_TRAP_GP;
28041
28042 @@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28043 container_of(task_pt_regs(current),
28044 struct bad_iret_stack, regs);
28045
28046 + if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28047 + new_stack = s;
28048 +
28049 /* Copy the IRET target to the new stack. */
28050 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28051
28052 /* Copy the remainder of the stack from the current stack. */
28053 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28054
28055 - BUG_ON(!user_mode_vm(&new_stack->regs));
28056 + BUG_ON(!user_mode(&new_stack->regs));
28057 return new_stack;
28058 }
28059 NOKPROBE_SYMBOL(fixup_bad_iret);
28060 @@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28061 /* It's safe to allow irq's after DR6 has been saved */
28062 preempt_conditional_sti(regs);
28063
28064 - if (regs->flags & X86_VM_MASK) {
28065 + if (v8086_mode(regs)) {
28066 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28067 X86_TRAP_DB);
28068 preempt_conditional_cli(regs);
28069 @@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28070 * We already checked v86 mode above, so we can check for kernel mode
28071 * by just checking the CPL of CS.
28072 */
28073 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28074 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28075 tsk->thread.debugreg6 &= ~DR_STEP;
28076 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28077 regs->flags &= ~X86_EFLAGS_TF;
28078 @@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28079 return;
28080 conditional_sti(regs);
28081
28082 - if (!user_mode_vm(regs))
28083 + if (!user_mode(regs))
28084 {
28085 if (!fixup_exception(regs)) {
28086 task->thread.error_code = error_code;
28087 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28088 index 5054497..139f8f8 100644
28089 --- a/arch/x86/kernel/tsc.c
28090 +++ b/arch/x86/kernel/tsc.c
28091 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28092 */
28093 smp_wmb();
28094
28095 - ACCESS_ONCE(c2n->head) = data;
28096 + ACCESS_ONCE_RW(c2n->head) = data;
28097 }
28098
28099 /*
28100 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28101 index 5d1cbfe..2a21feb 100644
28102 --- a/arch/x86/kernel/uprobes.c
28103 +++ b/arch/x86/kernel/uprobes.c
28104 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28105 int ret = NOTIFY_DONE;
28106
28107 /* We are only interested in userspace traps */
28108 - if (regs && !user_mode_vm(regs))
28109 + if (regs && !user_mode(regs))
28110 return NOTIFY_DONE;
28111
28112 switch (val) {
28113 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28114
28115 if (nleft != rasize) {
28116 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28117 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28118 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28119
28120 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28121 }
28122 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28123 index b9242ba..50c5edd 100644
28124 --- a/arch/x86/kernel/verify_cpu.S
28125 +++ b/arch/x86/kernel/verify_cpu.S
28126 @@ -20,6 +20,7 @@
28127 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28128 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28129 * arch/x86/kernel/head_32.S: processor startup
28130 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28131 *
28132 * verify_cpu, returns the status of longmode and SSE in register %eax.
28133 * 0: Success 1: Failure
28134 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28135 index e8edcf5..27f9344 100644
28136 --- a/arch/x86/kernel/vm86_32.c
28137 +++ b/arch/x86/kernel/vm86_32.c
28138 @@ -44,6 +44,7 @@
28139 #include <linux/ptrace.h>
28140 #include <linux/audit.h>
28141 #include <linux/stddef.h>
28142 +#include <linux/grsecurity.h>
28143
28144 #include <asm/uaccess.h>
28145 #include <asm/io.h>
28146 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28147 do_exit(SIGSEGV);
28148 }
28149
28150 - tss = &per_cpu(init_tss, get_cpu());
28151 + tss = init_tss + get_cpu();
28152 current->thread.sp0 = current->thread.saved_sp0;
28153 current->thread.sysenter_cs = __KERNEL_CS;
28154 load_sp0(tss, &current->thread);
28155 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28156
28157 if (tsk->thread.saved_sp0)
28158 return -EPERM;
28159 +
28160 +#ifdef CONFIG_GRKERNSEC_VM86
28161 + if (!capable(CAP_SYS_RAWIO)) {
28162 + gr_handle_vm86();
28163 + return -EPERM;
28164 + }
28165 +#endif
28166 +
28167 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28168 offsetof(struct kernel_vm86_struct, vm86plus) -
28169 sizeof(info.regs));
28170 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28171 int tmp;
28172 struct vm86plus_struct __user *v86;
28173
28174 +#ifdef CONFIG_GRKERNSEC_VM86
28175 + if (!capable(CAP_SYS_RAWIO)) {
28176 + gr_handle_vm86();
28177 + return -EPERM;
28178 + }
28179 +#endif
28180 +
28181 tsk = current;
28182 switch (cmd) {
28183 case VM86_REQUEST_IRQ:
28184 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28185 tsk->thread.saved_fs = info->regs32->fs;
28186 tsk->thread.saved_gs = get_user_gs(info->regs32);
28187
28188 - tss = &per_cpu(init_tss, get_cpu());
28189 + tss = init_tss + get_cpu();
28190 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28191 if (cpu_has_sep)
28192 tsk->thread.sysenter_cs = 0;
28193 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28194 goto cannot_handle;
28195 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28196 goto cannot_handle;
28197 - intr_ptr = (unsigned long __user *) (i << 2);
28198 + intr_ptr = (__force unsigned long __user *) (i << 2);
28199 if (get_user(segoffs, intr_ptr))
28200 goto cannot_handle;
28201 if ((segoffs >> 16) == BIOSSEG)
28202 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28203 index 49edf2d..df596b1 100644
28204 --- a/arch/x86/kernel/vmlinux.lds.S
28205 +++ b/arch/x86/kernel/vmlinux.lds.S
28206 @@ -26,6 +26,13 @@
28207 #include <asm/page_types.h>
28208 #include <asm/cache.h>
28209 #include <asm/boot.h>
28210 +#include <asm/segment.h>
28211 +
28212 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28213 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28214 +#else
28215 +#define __KERNEL_TEXT_OFFSET 0
28216 +#endif
28217
28218 #undef i386 /* in case the preprocessor is a 32bit one */
28219
28220 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28221
28222 PHDRS {
28223 text PT_LOAD FLAGS(5); /* R_E */
28224 +#ifdef CONFIG_X86_32
28225 + module PT_LOAD FLAGS(5); /* R_E */
28226 +#endif
28227 +#ifdef CONFIG_XEN
28228 + rodata PT_LOAD FLAGS(5); /* R_E */
28229 +#else
28230 + rodata PT_LOAD FLAGS(4); /* R__ */
28231 +#endif
28232 data PT_LOAD FLAGS(6); /* RW_ */
28233 -#ifdef CONFIG_X86_64
28234 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28235 #ifdef CONFIG_SMP
28236 percpu PT_LOAD FLAGS(6); /* RW_ */
28237 #endif
28238 + text.init PT_LOAD FLAGS(5); /* R_E */
28239 + text.exit PT_LOAD FLAGS(5); /* R_E */
28240 init PT_LOAD FLAGS(7); /* RWE */
28241 -#endif
28242 note PT_NOTE FLAGS(0); /* ___ */
28243 }
28244
28245 SECTIONS
28246 {
28247 #ifdef CONFIG_X86_32
28248 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28249 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28250 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28251 #else
28252 - . = __START_KERNEL;
28253 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28254 + . = __START_KERNEL;
28255 #endif
28256
28257 /* Text and read-only data */
28258 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28259 - _text = .;
28260 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28261 /* bootstrapping code */
28262 +#ifdef CONFIG_X86_32
28263 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28264 +#else
28265 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28266 +#endif
28267 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28268 + _text = .;
28269 HEAD_TEXT
28270 . = ALIGN(8);
28271 _stext = .;
28272 @@ -104,13 +124,47 @@ SECTIONS
28273 IRQENTRY_TEXT
28274 *(.fixup)
28275 *(.gnu.warning)
28276 - /* End of text section */
28277 - _etext = .;
28278 } :text = 0x9090
28279
28280 - NOTES :text :note
28281 + . += __KERNEL_TEXT_OFFSET;
28282
28283 - EXCEPTION_TABLE(16) :text = 0x9090
28284 +#ifdef CONFIG_X86_32
28285 + . = ALIGN(PAGE_SIZE);
28286 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28287 +
28288 +#ifdef CONFIG_PAX_KERNEXEC
28289 + MODULES_EXEC_VADDR = .;
28290 + BYTE(0)
28291 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28292 + . = ALIGN(HPAGE_SIZE) - 1;
28293 + MODULES_EXEC_END = .;
28294 +#endif
28295 +
28296 + } :module
28297 +#endif
28298 +
28299 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28300 + /* End of text section */
28301 + BYTE(0)
28302 + _etext = . - __KERNEL_TEXT_OFFSET;
28303 + }
28304 +
28305 +#ifdef CONFIG_X86_32
28306 + . = ALIGN(PAGE_SIZE);
28307 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28308 + . = ALIGN(PAGE_SIZE);
28309 + *(.empty_zero_page)
28310 + *(.initial_pg_fixmap)
28311 + *(.initial_pg_pmd)
28312 + *(.initial_page_table)
28313 + *(.swapper_pg_dir)
28314 + } :rodata
28315 +#endif
28316 +
28317 + . = ALIGN(PAGE_SIZE);
28318 + NOTES :rodata :note
28319 +
28320 + EXCEPTION_TABLE(16) :rodata
28321
28322 #if defined(CONFIG_DEBUG_RODATA)
28323 /* .text should occupy whole number of pages */
28324 @@ -122,16 +176,20 @@ SECTIONS
28325
28326 /* Data */
28327 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28328 +
28329 +#ifdef CONFIG_PAX_KERNEXEC
28330 + . = ALIGN(HPAGE_SIZE);
28331 +#else
28332 + . = ALIGN(PAGE_SIZE);
28333 +#endif
28334 +
28335 /* Start of data section */
28336 _sdata = .;
28337
28338 /* init_task */
28339 INIT_TASK_DATA(THREAD_SIZE)
28340
28341 -#ifdef CONFIG_X86_32
28342 - /* 32 bit has nosave before _edata */
28343 NOSAVE_DATA
28344 -#endif
28345
28346 PAGE_ALIGNED_DATA(PAGE_SIZE)
28347
28348 @@ -174,12 +232,19 @@ SECTIONS
28349 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28350
28351 /* Init code and data - will be freed after init */
28352 - . = ALIGN(PAGE_SIZE);
28353 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28354 + BYTE(0)
28355 +
28356 +#ifdef CONFIG_PAX_KERNEXEC
28357 + . = ALIGN(HPAGE_SIZE);
28358 +#else
28359 + . = ALIGN(PAGE_SIZE);
28360 +#endif
28361 +
28362 __init_begin = .; /* paired with __init_end */
28363 - }
28364 + } :init.begin
28365
28366 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28367 +#ifdef CONFIG_SMP
28368 /*
28369 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28370 * output PHDR, so the next output section - .init.text - should
28371 @@ -188,12 +253,27 @@ SECTIONS
28372 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28373 #endif
28374
28375 - INIT_TEXT_SECTION(PAGE_SIZE)
28376 -#ifdef CONFIG_X86_64
28377 - :init
28378 -#endif
28379 + . = ALIGN(PAGE_SIZE);
28380 + init_begin = .;
28381 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28382 + VMLINUX_SYMBOL(_sinittext) = .;
28383 + INIT_TEXT
28384 + . = ALIGN(PAGE_SIZE);
28385 + } :text.init
28386
28387 - INIT_DATA_SECTION(16)
28388 + /*
28389 + * .exit.text is discard at runtime, not link time, to deal with
28390 + * references from .altinstructions and .eh_frame
28391 + */
28392 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28393 + EXIT_TEXT
28394 + VMLINUX_SYMBOL(_einittext) = .;
28395 + . = ALIGN(16);
28396 + } :text.exit
28397 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28398 +
28399 + . = ALIGN(PAGE_SIZE);
28400 + INIT_DATA_SECTION(16) :init
28401
28402 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28403 __x86_cpu_dev_start = .;
28404 @@ -264,19 +344,12 @@ SECTIONS
28405 }
28406
28407 . = ALIGN(8);
28408 - /*
28409 - * .exit.text is discard at runtime, not link time, to deal with
28410 - * references from .altinstructions and .eh_frame
28411 - */
28412 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28413 - EXIT_TEXT
28414 - }
28415
28416 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28417 EXIT_DATA
28418 }
28419
28420 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28421 +#ifndef CONFIG_SMP
28422 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28423 #endif
28424
28425 @@ -295,16 +368,10 @@ SECTIONS
28426 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28427 __smp_locks = .;
28428 *(.smp_locks)
28429 - . = ALIGN(PAGE_SIZE);
28430 __smp_locks_end = .;
28431 + . = ALIGN(PAGE_SIZE);
28432 }
28433
28434 -#ifdef CONFIG_X86_64
28435 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28436 - NOSAVE_DATA
28437 - }
28438 -#endif
28439 -
28440 /* BSS */
28441 . = ALIGN(PAGE_SIZE);
28442 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28443 @@ -320,6 +387,7 @@ SECTIONS
28444 __brk_base = .;
28445 . += 64 * 1024; /* 64k alignment slop space */
28446 *(.brk_reservation) /* areas brk users have reserved */
28447 + . = ALIGN(HPAGE_SIZE);
28448 __brk_limit = .;
28449 }
28450
28451 @@ -346,13 +414,12 @@ SECTIONS
28452 * for the boot processor.
28453 */
28454 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28455 -INIT_PER_CPU(gdt_page);
28456 INIT_PER_CPU(irq_stack_union);
28457
28458 /*
28459 * Build-time check on the image size:
28460 */
28461 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28462 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28463 "kernel image bigger than KERNEL_IMAGE_SIZE");
28464
28465 #ifdef CONFIG_SMP
28466 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28467 index 957779f..74e405c 100644
28468 --- a/arch/x86/kernel/vsyscall_64.c
28469 +++ b/arch/x86/kernel/vsyscall_64.c
28470 @@ -54,15 +54,13 @@
28471
28472 DEFINE_VVAR(int, vgetcpu_mode);
28473
28474 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28475 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28476
28477 static int __init vsyscall_setup(char *str)
28478 {
28479 if (str) {
28480 if (!strcmp("emulate", str))
28481 vsyscall_mode = EMULATE;
28482 - else if (!strcmp("native", str))
28483 - vsyscall_mode = NATIVE;
28484 else if (!strcmp("none", str))
28485 vsyscall_mode = NONE;
28486 else
28487 @@ -279,8 +277,7 @@ do_ret:
28488 return true;
28489
28490 sigsegv:
28491 - force_sig(SIGSEGV, current);
28492 - return true;
28493 + do_group_exit(SIGKILL);
28494 }
28495
28496 /*
28497 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28498 extern char __vsyscall_page;
28499 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28500
28501 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28502 - vsyscall_mode == NATIVE
28503 - ? PAGE_KERNEL_VSYSCALL
28504 - : PAGE_KERNEL_VVAR);
28505 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28506 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28507 (unsigned long)VSYSCALL_ADDR);
28508 }
28509 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28510 index 04068192..4d75aa6 100644
28511 --- a/arch/x86/kernel/x8664_ksyms_64.c
28512 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28513 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28514 EXPORT_SYMBOL(copy_user_generic_unrolled);
28515 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28516 EXPORT_SYMBOL(__copy_user_nocache);
28517 -EXPORT_SYMBOL(_copy_from_user);
28518 -EXPORT_SYMBOL(_copy_to_user);
28519
28520 EXPORT_SYMBOL(copy_page);
28521 EXPORT_SYMBOL(clear_page);
28522 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28523 EXPORT_SYMBOL(___preempt_schedule_context);
28524 #endif
28525 #endif
28526 +
28527 +#ifdef CONFIG_PAX_PER_CPU_PGD
28528 +EXPORT_SYMBOL(cpu_pgd);
28529 +#endif
28530 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28531 index e48b674..a451dd9 100644
28532 --- a/arch/x86/kernel/x86_init.c
28533 +++ b/arch/x86/kernel/x86_init.c
28534 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28535 static void default_nmi_init(void) { };
28536 static int default_i8042_detect(void) { return 1; };
28537
28538 -struct x86_platform_ops x86_platform = {
28539 +struct x86_platform_ops x86_platform __read_only = {
28540 .calibrate_tsc = native_calibrate_tsc,
28541 .get_wallclock = mach_get_cmos_time,
28542 .set_wallclock = mach_set_rtc_mmss,
28543 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28544 EXPORT_SYMBOL_GPL(x86_platform);
28545
28546 #if defined(CONFIG_PCI_MSI)
28547 -struct x86_msi_ops x86_msi = {
28548 +struct x86_msi_ops x86_msi __read_only = {
28549 .setup_msi_irqs = native_setup_msi_irqs,
28550 .compose_msi_msg = native_compose_msi_msg,
28551 .teardown_msi_irq = native_teardown_msi_irq,
28552 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28553 }
28554 #endif
28555
28556 -struct x86_io_apic_ops x86_io_apic_ops = {
28557 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28558 .init = native_io_apic_init_mappings,
28559 .read = native_io_apic_read,
28560 .write = native_io_apic_write,
28561 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28562 index 0de1fae..298d037 100644
28563 --- a/arch/x86/kernel/xsave.c
28564 +++ b/arch/x86/kernel/xsave.c
28565 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28566
28567 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28568 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28569 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28570 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28571
28572 if (!use_xsave())
28573 return err;
28574
28575 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28576 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28577
28578 /*
28579 * Read the xstate_bv which we copied (directly from the cpu or
28580 * from the state in task struct) to the user buffers.
28581 */
28582 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28583 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28584
28585 /*
28586 * For legacy compatible, we always set FP/SSE bits in the bit
28587 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28588 */
28589 xstate_bv |= XSTATE_FPSSE;
28590
28591 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28592 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28593
28594 return err;
28595 }
28596 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28597 {
28598 int err;
28599
28600 + buf = (struct xsave_struct __user *)____m(buf);
28601 if (use_xsave())
28602 err = xsave_user(buf);
28603 else if (use_fxsr())
28604 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28605 */
28606 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28607 {
28608 + buf = (void __user *)____m(buf);
28609 if (use_xsave()) {
28610 if ((unsigned long)buf % 64 || fx_only) {
28611 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28612 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28613 index 88f9201..0e7f1a3 100644
28614 --- a/arch/x86/kvm/cpuid.c
28615 +++ b/arch/x86/kvm/cpuid.c
28616 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28617 struct kvm_cpuid2 *cpuid,
28618 struct kvm_cpuid_entry2 __user *entries)
28619 {
28620 - int r;
28621 + int r, i;
28622
28623 r = -E2BIG;
28624 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28625 goto out;
28626 r = -EFAULT;
28627 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28628 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28629 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28630 goto out;
28631 + for (i = 0; i < cpuid->nent; ++i) {
28632 + struct kvm_cpuid_entry2 cpuid_entry;
28633 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28634 + goto out;
28635 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28636 + }
28637 vcpu->arch.cpuid_nent = cpuid->nent;
28638 kvm_apic_set_version(vcpu);
28639 kvm_x86_ops->cpuid_update(vcpu);
28640 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28641 struct kvm_cpuid2 *cpuid,
28642 struct kvm_cpuid_entry2 __user *entries)
28643 {
28644 - int r;
28645 + int r, i;
28646
28647 r = -E2BIG;
28648 if (cpuid->nent < vcpu->arch.cpuid_nent)
28649 goto out;
28650 r = -EFAULT;
28651 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28652 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28653 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28654 goto out;
28655 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28656 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28657 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28658 + goto out;
28659 + }
28660 return 0;
28661
28662 out:
28663 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28664 index c7327a7..c3e2419 100644
28665 --- a/arch/x86/kvm/emulate.c
28666 +++ b/arch/x86/kvm/emulate.c
28667 @@ -3508,7 +3508,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28668 int cr = ctxt->modrm_reg;
28669 u64 efer = 0;
28670
28671 - static u64 cr_reserved_bits[] = {
28672 + static const u64 cr_reserved_bits[] = {
28673 0xffffffff00000000ULL,
28674 0, 0, 0, /* CR3 checked later */
28675 CR4_RESERVED_BITS,
28676 @@ -3543,7 +3543,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28677
28678 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28679 if (efer & EFER_LMA)
28680 - rsvd = CR3_L_MODE_RESERVED_BITS;
28681 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28682
28683 if (new_val & rsvd)
28684 return emulate_gp(ctxt, 0);
28685 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28686 index b8345dd..f225d71 100644
28687 --- a/arch/x86/kvm/lapic.c
28688 +++ b/arch/x86/kvm/lapic.c
28689 @@ -55,7 +55,7 @@
28690 #define APIC_BUS_CYCLE_NS 1
28691
28692 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28693 -#define apic_debug(fmt, arg...)
28694 +#define apic_debug(fmt, arg...) do {} while (0)
28695
28696 #define APIC_LVT_NUM 6
28697 /* 14 is the version for Xeon and Pentium 8.4.8*/
28698 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28699 index fd49c86..77e1aa0 100644
28700 --- a/arch/x86/kvm/paging_tmpl.h
28701 +++ b/arch/x86/kvm/paging_tmpl.h
28702 @@ -343,7 +343,7 @@ retry_walk:
28703 if (unlikely(kvm_is_error_hva(host_addr)))
28704 goto error;
28705
28706 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28707 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28708 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28709 goto error;
28710 walker->ptep_user[walker->level - 1] = ptep_user;
28711 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28712 index 7527cef..c63a838e 100644
28713 --- a/arch/x86/kvm/svm.c
28714 +++ b/arch/x86/kvm/svm.c
28715 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28716 int cpu = raw_smp_processor_id();
28717
28718 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28719 +
28720 + pax_open_kernel();
28721 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28722 + pax_close_kernel();
28723 +
28724 load_TR_desc();
28725 }
28726
28727 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28728 #endif
28729 #endif
28730
28731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28732 + __set_fs(current_thread_info()->addr_limit);
28733 +#endif
28734 +
28735 reload_tss(vcpu);
28736
28737 local_irq_disable();
28738 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28739 index ed70394..c629a68 100644
28740 --- a/arch/x86/kvm/vmx.c
28741 +++ b/arch/x86/kvm/vmx.c
28742 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28743 #endif
28744 }
28745
28746 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28747 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28748 {
28749 vmcs_writel(field, vmcs_readl(field) & ~mask);
28750 }
28751
28752 -static void vmcs_set_bits(unsigned long field, u32 mask)
28753 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28754 {
28755 vmcs_writel(field, vmcs_readl(field) | mask);
28756 }
28757 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28758 struct desc_struct *descs;
28759
28760 descs = (void *)gdt->address;
28761 +
28762 + pax_open_kernel();
28763 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28764 + pax_close_kernel();
28765 +
28766 load_TR_desc();
28767 }
28768
28769 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28770 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28771 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28772
28773 +#ifdef CONFIG_PAX_PER_CPU_PGD
28774 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28775 +#endif
28776 +
28777 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28778 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28779 vmx->loaded_vmcs->cpu = cpu;
28780 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28781 * reads and returns guest's timestamp counter "register"
28782 * guest_tsc = host_tsc + tsc_offset -- 21.3
28783 */
28784 -static u64 guest_read_tsc(void)
28785 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28786 {
28787 u64 host_tsc, tsc_offset;
28788
28789 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28790 * page upon invalidation. No need to do anything if the
28791 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28792 */
28793 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28794 + pax_open_kernel();
28795 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28796 + pax_close_kernel();
28797 }
28798
28799 - if (!cpu_has_vmx_tpr_shadow())
28800 - kvm_x86_ops->update_cr8_intercept = NULL;
28801 + if (!cpu_has_vmx_tpr_shadow()) {
28802 + pax_open_kernel();
28803 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28804 + pax_close_kernel();
28805 + }
28806
28807 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28808 kvm_disable_largepages();
28809 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28810 if (!cpu_has_vmx_apicv())
28811 enable_apicv = 0;
28812
28813 + pax_open_kernel();
28814 if (enable_apicv)
28815 - kvm_x86_ops->update_cr8_intercept = NULL;
28816 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28817 else {
28818 - kvm_x86_ops->hwapic_irr_update = NULL;
28819 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28820 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28821 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28822 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28823 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28824 }
28825 + pax_close_kernel();
28826
28827 if (nested)
28828 nested_vmx_setup_ctls_msrs();
28829 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28830 unsigned long cr4;
28831
28832 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28833 +
28834 +#ifndef CONFIG_PAX_PER_CPU_PGD
28835 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28836 +#endif
28837
28838 /* Save the most likely value for this task's CR4 in the VMCS. */
28839 cr4 = read_cr4();
28840 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28841 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28842 vmx->host_idt_base = dt.address;
28843
28844 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28845 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28846
28847 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28848 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28849 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28850 "jmp 2f \n\t"
28851 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28852 "2: "
28853 +
28854 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28855 + "ljmp %[cs],$3f\n\t"
28856 + "3: "
28857 +#endif
28858 +
28859 /* Save guest registers, load host registers, keep flags */
28860 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28861 "pop %0 \n\t"
28862 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28863 #endif
28864 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28865 [wordsize]"i"(sizeof(ulong))
28866 +
28867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28868 + ,[cs]"i"(__KERNEL_CS)
28869 +#endif
28870 +
28871 : "cc", "memory"
28872 #ifdef CONFIG_X86_64
28873 , "rax", "rbx", "rdi", "rsi"
28874 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28875 if (debugctlmsr)
28876 update_debugctlmsr(debugctlmsr);
28877
28878 -#ifndef CONFIG_X86_64
28879 +#ifdef CONFIG_X86_32
28880 /*
28881 * The sysexit path does not restore ds/es, so we must set them to
28882 * a reasonable value ourselves.
28883 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28884 * may be executed in interrupt context, which saves and restore segments
28885 * around it, nullifying its effect.
28886 */
28887 - loadsegment(ds, __USER_DS);
28888 - loadsegment(es, __USER_DS);
28889 + loadsegment(ds, __KERNEL_DS);
28890 + loadsegment(es, __KERNEL_DS);
28891 + loadsegment(ss, __KERNEL_DS);
28892 +
28893 +#ifdef CONFIG_PAX_KERNEXEC
28894 + loadsegment(fs, __KERNEL_PERCPU);
28895 +#endif
28896 +
28897 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28898 + __set_fs(current_thread_info()->addr_limit);
28899 +#endif
28900 +
28901 #endif
28902
28903 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28904 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28905 index 506488c..f8df17e 100644
28906 --- a/arch/x86/kvm/x86.c
28907 +++ b/arch/x86/kvm/x86.c
28908 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28909
28910 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28911 {
28912 + cr3 &= ~CR3_PCID_INVD;
28913 +
28914 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28915 kvm_mmu_sync_roots(vcpu);
28916 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28917 @@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28918 {
28919 struct kvm *kvm = vcpu->kvm;
28920 int lm = is_long_mode(vcpu);
28921 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28922 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28923 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28924 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28925 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28926 : kvm->arch.xen_hvm_config.blob_size_32;
28927 u32 page_num = data & ~PAGE_MASK;
28928 @@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28929 if (n < msr_list.nmsrs)
28930 goto out;
28931 r = -EFAULT;
28932 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28933 + goto out;
28934 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28935 num_msrs_to_save * sizeof(u32)))
28936 goto out;
28937 @@ -5743,7 +5747,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28938 };
28939 #endif
28940
28941 -int kvm_arch_init(void *opaque)
28942 +int kvm_arch_init(const void *opaque)
28943 {
28944 int r;
28945 struct kvm_x86_ops *ops = opaque;
28946 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28947 index aae9413..d11e829 100644
28948 --- a/arch/x86/lguest/boot.c
28949 +++ b/arch/x86/lguest/boot.c
28950 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28951 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28952 * Launcher to reboot us.
28953 */
28954 -static void lguest_restart(char *reason)
28955 +static __noreturn void lguest_restart(char *reason)
28956 {
28957 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28958 + BUG();
28959 }
28960
28961 /*G:050
28962 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28963 index 00933d5..3a64af9 100644
28964 --- a/arch/x86/lib/atomic64_386_32.S
28965 +++ b/arch/x86/lib/atomic64_386_32.S
28966 @@ -48,6 +48,10 @@ BEGIN(read)
28967 movl (v), %eax
28968 movl 4(v), %edx
28969 RET_ENDP
28970 +BEGIN(read_unchecked)
28971 + movl (v), %eax
28972 + movl 4(v), %edx
28973 +RET_ENDP
28974 #undef v
28975
28976 #define v %esi
28977 @@ -55,6 +59,10 @@ BEGIN(set)
28978 movl %ebx, (v)
28979 movl %ecx, 4(v)
28980 RET_ENDP
28981 +BEGIN(set_unchecked)
28982 + movl %ebx, (v)
28983 + movl %ecx, 4(v)
28984 +RET_ENDP
28985 #undef v
28986
28987 #define v %esi
28988 @@ -70,6 +78,20 @@ RET_ENDP
28989 BEGIN(add)
28990 addl %eax, (v)
28991 adcl %edx, 4(v)
28992 +
28993 +#ifdef CONFIG_PAX_REFCOUNT
28994 + jno 0f
28995 + subl %eax, (v)
28996 + sbbl %edx, 4(v)
28997 + int $4
28998 +0:
28999 + _ASM_EXTABLE(0b, 0b)
29000 +#endif
29001 +
29002 +RET_ENDP
29003 +BEGIN(add_unchecked)
29004 + addl %eax, (v)
29005 + adcl %edx, 4(v)
29006 RET_ENDP
29007 #undef v
29008
29009 @@ -77,6 +99,24 @@ RET_ENDP
29010 BEGIN(add_return)
29011 addl (v), %eax
29012 adcl 4(v), %edx
29013 +
29014 +#ifdef CONFIG_PAX_REFCOUNT
29015 + into
29016 +1234:
29017 + _ASM_EXTABLE(1234b, 2f)
29018 +#endif
29019 +
29020 + movl %eax, (v)
29021 + movl %edx, 4(v)
29022 +
29023 +#ifdef CONFIG_PAX_REFCOUNT
29024 +2:
29025 +#endif
29026 +
29027 +RET_ENDP
29028 +BEGIN(add_return_unchecked)
29029 + addl (v), %eax
29030 + adcl 4(v), %edx
29031 movl %eax, (v)
29032 movl %edx, 4(v)
29033 RET_ENDP
29034 @@ -86,6 +126,20 @@ RET_ENDP
29035 BEGIN(sub)
29036 subl %eax, (v)
29037 sbbl %edx, 4(v)
29038 +
29039 +#ifdef CONFIG_PAX_REFCOUNT
29040 + jno 0f
29041 + addl %eax, (v)
29042 + adcl %edx, 4(v)
29043 + int $4
29044 +0:
29045 + _ASM_EXTABLE(0b, 0b)
29046 +#endif
29047 +
29048 +RET_ENDP
29049 +BEGIN(sub_unchecked)
29050 + subl %eax, (v)
29051 + sbbl %edx, 4(v)
29052 RET_ENDP
29053 #undef v
29054
29055 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29056 sbbl $0, %edx
29057 addl (v), %eax
29058 adcl 4(v), %edx
29059 +
29060 +#ifdef CONFIG_PAX_REFCOUNT
29061 + into
29062 +1234:
29063 + _ASM_EXTABLE(1234b, 2f)
29064 +#endif
29065 +
29066 + movl %eax, (v)
29067 + movl %edx, 4(v)
29068 +
29069 +#ifdef CONFIG_PAX_REFCOUNT
29070 +2:
29071 +#endif
29072 +
29073 +RET_ENDP
29074 +BEGIN(sub_return_unchecked)
29075 + negl %edx
29076 + negl %eax
29077 + sbbl $0, %edx
29078 + addl (v), %eax
29079 + adcl 4(v), %edx
29080 movl %eax, (v)
29081 movl %edx, 4(v)
29082 RET_ENDP
29083 @@ -105,6 +180,20 @@ RET_ENDP
29084 BEGIN(inc)
29085 addl $1, (v)
29086 adcl $0, 4(v)
29087 +
29088 +#ifdef CONFIG_PAX_REFCOUNT
29089 + jno 0f
29090 + subl $1, (v)
29091 + sbbl $0, 4(v)
29092 + int $4
29093 +0:
29094 + _ASM_EXTABLE(0b, 0b)
29095 +#endif
29096 +
29097 +RET_ENDP
29098 +BEGIN(inc_unchecked)
29099 + addl $1, (v)
29100 + adcl $0, 4(v)
29101 RET_ENDP
29102 #undef v
29103
29104 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29105 movl 4(v), %edx
29106 addl $1, %eax
29107 adcl $0, %edx
29108 +
29109 +#ifdef CONFIG_PAX_REFCOUNT
29110 + into
29111 +1234:
29112 + _ASM_EXTABLE(1234b, 2f)
29113 +#endif
29114 +
29115 + movl %eax, (v)
29116 + movl %edx, 4(v)
29117 +
29118 +#ifdef CONFIG_PAX_REFCOUNT
29119 +2:
29120 +#endif
29121 +
29122 +RET_ENDP
29123 +BEGIN(inc_return_unchecked)
29124 + movl (v), %eax
29125 + movl 4(v), %edx
29126 + addl $1, %eax
29127 + adcl $0, %edx
29128 movl %eax, (v)
29129 movl %edx, 4(v)
29130 RET_ENDP
29131 @@ -123,6 +232,20 @@ RET_ENDP
29132 BEGIN(dec)
29133 subl $1, (v)
29134 sbbl $0, 4(v)
29135 +
29136 +#ifdef CONFIG_PAX_REFCOUNT
29137 + jno 0f
29138 + addl $1, (v)
29139 + adcl $0, 4(v)
29140 + int $4
29141 +0:
29142 + _ASM_EXTABLE(0b, 0b)
29143 +#endif
29144 +
29145 +RET_ENDP
29146 +BEGIN(dec_unchecked)
29147 + subl $1, (v)
29148 + sbbl $0, 4(v)
29149 RET_ENDP
29150 #undef v
29151
29152 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29153 movl 4(v), %edx
29154 subl $1, %eax
29155 sbbl $0, %edx
29156 +
29157 +#ifdef CONFIG_PAX_REFCOUNT
29158 + into
29159 +1234:
29160 + _ASM_EXTABLE(1234b, 2f)
29161 +#endif
29162 +
29163 + movl %eax, (v)
29164 + movl %edx, 4(v)
29165 +
29166 +#ifdef CONFIG_PAX_REFCOUNT
29167 +2:
29168 +#endif
29169 +
29170 +RET_ENDP
29171 +BEGIN(dec_return_unchecked)
29172 + movl (v), %eax
29173 + movl 4(v), %edx
29174 + subl $1, %eax
29175 + sbbl $0, %edx
29176 movl %eax, (v)
29177 movl %edx, 4(v)
29178 RET_ENDP
29179 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29180 adcl %edx, %edi
29181 addl (v), %eax
29182 adcl 4(v), %edx
29183 +
29184 +#ifdef CONFIG_PAX_REFCOUNT
29185 + into
29186 +1234:
29187 + _ASM_EXTABLE(1234b, 2f)
29188 +#endif
29189 +
29190 cmpl %eax, %ecx
29191 je 3f
29192 1:
29193 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29194 1:
29195 addl $1, %eax
29196 adcl $0, %edx
29197 +
29198 +#ifdef CONFIG_PAX_REFCOUNT
29199 + into
29200 +1234:
29201 + _ASM_EXTABLE(1234b, 2f)
29202 +#endif
29203 +
29204 movl %eax, (v)
29205 movl %edx, 4(v)
29206 movl $1, %eax
29207 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29208 movl 4(v), %edx
29209 subl $1, %eax
29210 sbbl $0, %edx
29211 +
29212 +#ifdef CONFIG_PAX_REFCOUNT
29213 + into
29214 +1234:
29215 + _ASM_EXTABLE(1234b, 1f)
29216 +#endif
29217 +
29218 js 1f
29219 movl %eax, (v)
29220 movl %edx, 4(v)
29221 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29222 index f5cc9eb..51fa319 100644
29223 --- a/arch/x86/lib/atomic64_cx8_32.S
29224 +++ b/arch/x86/lib/atomic64_cx8_32.S
29225 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29226 CFI_STARTPROC
29227
29228 read64 %ecx
29229 + pax_force_retaddr
29230 ret
29231 CFI_ENDPROC
29232 ENDPROC(atomic64_read_cx8)
29233
29234 +ENTRY(atomic64_read_unchecked_cx8)
29235 + CFI_STARTPROC
29236 +
29237 + read64 %ecx
29238 + pax_force_retaddr
29239 + ret
29240 + CFI_ENDPROC
29241 +ENDPROC(atomic64_read_unchecked_cx8)
29242 +
29243 ENTRY(atomic64_set_cx8)
29244 CFI_STARTPROC
29245
29246 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29247 cmpxchg8b (%esi)
29248 jne 1b
29249
29250 + pax_force_retaddr
29251 ret
29252 CFI_ENDPROC
29253 ENDPROC(atomic64_set_cx8)
29254
29255 +ENTRY(atomic64_set_unchecked_cx8)
29256 + CFI_STARTPROC
29257 +
29258 +1:
29259 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29260 + * are atomic on 586 and newer */
29261 + cmpxchg8b (%esi)
29262 + jne 1b
29263 +
29264 + pax_force_retaddr
29265 + ret
29266 + CFI_ENDPROC
29267 +ENDPROC(atomic64_set_unchecked_cx8)
29268 +
29269 ENTRY(atomic64_xchg_cx8)
29270 CFI_STARTPROC
29271
29272 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29273 cmpxchg8b (%esi)
29274 jne 1b
29275
29276 + pax_force_retaddr
29277 ret
29278 CFI_ENDPROC
29279 ENDPROC(atomic64_xchg_cx8)
29280
29281 -.macro addsub_return func ins insc
29282 -ENTRY(atomic64_\func\()_return_cx8)
29283 +.macro addsub_return func ins insc unchecked=""
29284 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29285 CFI_STARTPROC
29286 SAVE ebp
29287 SAVE ebx
29288 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29289 movl %edx, %ecx
29290 \ins\()l %esi, %ebx
29291 \insc\()l %edi, %ecx
29292 +
29293 +.ifb \unchecked
29294 +#ifdef CONFIG_PAX_REFCOUNT
29295 + into
29296 +2:
29297 + _ASM_EXTABLE(2b, 3f)
29298 +#endif
29299 +.endif
29300 +
29301 LOCK_PREFIX
29302 cmpxchg8b (%ebp)
29303 jne 1b
29304 -
29305 -10:
29306 movl %ebx, %eax
29307 movl %ecx, %edx
29308 +
29309 +.ifb \unchecked
29310 +#ifdef CONFIG_PAX_REFCOUNT
29311 +3:
29312 +#endif
29313 +.endif
29314 +
29315 RESTORE edi
29316 RESTORE esi
29317 RESTORE ebx
29318 RESTORE ebp
29319 + pax_force_retaddr
29320 ret
29321 CFI_ENDPROC
29322 -ENDPROC(atomic64_\func\()_return_cx8)
29323 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29324 .endm
29325
29326 addsub_return add add adc
29327 addsub_return sub sub sbb
29328 +addsub_return add add adc _unchecked
29329 +addsub_return sub sub sbb _unchecked
29330
29331 -.macro incdec_return func ins insc
29332 -ENTRY(atomic64_\func\()_return_cx8)
29333 +.macro incdec_return func ins insc unchecked=""
29334 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29335 CFI_STARTPROC
29336 SAVE ebx
29337
29338 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29339 movl %edx, %ecx
29340 \ins\()l $1, %ebx
29341 \insc\()l $0, %ecx
29342 +
29343 +.ifb \unchecked
29344 +#ifdef CONFIG_PAX_REFCOUNT
29345 + into
29346 +2:
29347 + _ASM_EXTABLE(2b, 3f)
29348 +#endif
29349 +.endif
29350 +
29351 LOCK_PREFIX
29352 cmpxchg8b (%esi)
29353 jne 1b
29354
29355 -10:
29356 movl %ebx, %eax
29357 movl %ecx, %edx
29358 +
29359 +.ifb \unchecked
29360 +#ifdef CONFIG_PAX_REFCOUNT
29361 +3:
29362 +#endif
29363 +.endif
29364 +
29365 RESTORE ebx
29366 + pax_force_retaddr
29367 ret
29368 CFI_ENDPROC
29369 -ENDPROC(atomic64_\func\()_return_cx8)
29370 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29371 .endm
29372
29373 incdec_return inc add adc
29374 incdec_return dec sub sbb
29375 +incdec_return inc add adc _unchecked
29376 +incdec_return dec sub sbb _unchecked
29377
29378 ENTRY(atomic64_dec_if_positive_cx8)
29379 CFI_STARTPROC
29380 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29381 movl %edx, %ecx
29382 subl $1, %ebx
29383 sbb $0, %ecx
29384 +
29385 +#ifdef CONFIG_PAX_REFCOUNT
29386 + into
29387 +1234:
29388 + _ASM_EXTABLE(1234b, 2f)
29389 +#endif
29390 +
29391 js 2f
29392 LOCK_PREFIX
29393 cmpxchg8b (%esi)
29394 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29395 movl %ebx, %eax
29396 movl %ecx, %edx
29397 RESTORE ebx
29398 + pax_force_retaddr
29399 ret
29400 CFI_ENDPROC
29401 ENDPROC(atomic64_dec_if_positive_cx8)
29402 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29403 movl %edx, %ecx
29404 addl %ebp, %ebx
29405 adcl %edi, %ecx
29406 +
29407 +#ifdef CONFIG_PAX_REFCOUNT
29408 + into
29409 +1234:
29410 + _ASM_EXTABLE(1234b, 3f)
29411 +#endif
29412 +
29413 LOCK_PREFIX
29414 cmpxchg8b (%esi)
29415 jne 1b
29416 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29417 CFI_ADJUST_CFA_OFFSET -8
29418 RESTORE ebx
29419 RESTORE ebp
29420 + pax_force_retaddr
29421 ret
29422 4:
29423 cmpl %edx, 4(%esp)
29424 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29425 xorl %ecx, %ecx
29426 addl $1, %ebx
29427 adcl %edx, %ecx
29428 +
29429 +#ifdef CONFIG_PAX_REFCOUNT
29430 + into
29431 +1234:
29432 + _ASM_EXTABLE(1234b, 3f)
29433 +#endif
29434 +
29435 LOCK_PREFIX
29436 cmpxchg8b (%esi)
29437 jne 1b
29438 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29439 movl $1, %eax
29440 3:
29441 RESTORE ebx
29442 + pax_force_retaddr
29443 ret
29444 CFI_ENDPROC
29445 ENDPROC(atomic64_inc_not_zero_cx8)
29446 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29447 index e78b8eee..7e173a8 100644
29448 --- a/arch/x86/lib/checksum_32.S
29449 +++ b/arch/x86/lib/checksum_32.S
29450 @@ -29,7 +29,8 @@
29451 #include <asm/dwarf2.h>
29452 #include <asm/errno.h>
29453 #include <asm/asm.h>
29454 -
29455 +#include <asm/segment.h>
29456 +
29457 /*
29458 * computes a partial checksum, e.g. for TCP/UDP fragments
29459 */
29460 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29461
29462 #define ARGBASE 16
29463 #define FP 12
29464 -
29465 -ENTRY(csum_partial_copy_generic)
29466 +
29467 +ENTRY(csum_partial_copy_generic_to_user)
29468 CFI_STARTPROC
29469 +
29470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29471 + pushl_cfi %gs
29472 + popl_cfi %es
29473 + jmp csum_partial_copy_generic
29474 +#endif
29475 +
29476 +ENTRY(csum_partial_copy_generic_from_user)
29477 +
29478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29479 + pushl_cfi %gs
29480 + popl_cfi %ds
29481 +#endif
29482 +
29483 +ENTRY(csum_partial_copy_generic)
29484 subl $4,%esp
29485 CFI_ADJUST_CFA_OFFSET 4
29486 pushl_cfi %edi
29487 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29488 jmp 4f
29489 SRC(1: movw (%esi), %bx )
29490 addl $2, %esi
29491 -DST( movw %bx, (%edi) )
29492 +DST( movw %bx, %es:(%edi) )
29493 addl $2, %edi
29494 addw %bx, %ax
29495 adcl $0, %eax
29496 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29497 SRC(1: movl (%esi), %ebx )
29498 SRC( movl 4(%esi), %edx )
29499 adcl %ebx, %eax
29500 -DST( movl %ebx, (%edi) )
29501 +DST( movl %ebx, %es:(%edi) )
29502 adcl %edx, %eax
29503 -DST( movl %edx, 4(%edi) )
29504 +DST( movl %edx, %es:4(%edi) )
29505
29506 SRC( movl 8(%esi), %ebx )
29507 SRC( movl 12(%esi), %edx )
29508 adcl %ebx, %eax
29509 -DST( movl %ebx, 8(%edi) )
29510 +DST( movl %ebx, %es:8(%edi) )
29511 adcl %edx, %eax
29512 -DST( movl %edx, 12(%edi) )
29513 +DST( movl %edx, %es:12(%edi) )
29514
29515 SRC( movl 16(%esi), %ebx )
29516 SRC( movl 20(%esi), %edx )
29517 adcl %ebx, %eax
29518 -DST( movl %ebx, 16(%edi) )
29519 +DST( movl %ebx, %es:16(%edi) )
29520 adcl %edx, %eax
29521 -DST( movl %edx, 20(%edi) )
29522 +DST( movl %edx, %es:20(%edi) )
29523
29524 SRC( movl 24(%esi), %ebx )
29525 SRC( movl 28(%esi), %edx )
29526 adcl %ebx, %eax
29527 -DST( movl %ebx, 24(%edi) )
29528 +DST( movl %ebx, %es:24(%edi) )
29529 adcl %edx, %eax
29530 -DST( movl %edx, 28(%edi) )
29531 +DST( movl %edx, %es:28(%edi) )
29532
29533 lea 32(%esi), %esi
29534 lea 32(%edi), %edi
29535 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29536 shrl $2, %edx # This clears CF
29537 SRC(3: movl (%esi), %ebx )
29538 adcl %ebx, %eax
29539 -DST( movl %ebx, (%edi) )
29540 +DST( movl %ebx, %es:(%edi) )
29541 lea 4(%esi), %esi
29542 lea 4(%edi), %edi
29543 dec %edx
29544 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29545 jb 5f
29546 SRC( movw (%esi), %cx )
29547 leal 2(%esi), %esi
29548 -DST( movw %cx, (%edi) )
29549 +DST( movw %cx, %es:(%edi) )
29550 leal 2(%edi), %edi
29551 je 6f
29552 shll $16,%ecx
29553 SRC(5: movb (%esi), %cl )
29554 -DST( movb %cl, (%edi) )
29555 +DST( movb %cl, %es:(%edi) )
29556 6: addl %ecx, %eax
29557 adcl $0, %eax
29558 7:
29559 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29560
29561 6001:
29562 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29563 - movl $-EFAULT, (%ebx)
29564 + movl $-EFAULT, %ss:(%ebx)
29565
29566 # zero the complete destination - computing the rest
29567 # is too much work
29568 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29569
29570 6002:
29571 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29572 - movl $-EFAULT,(%ebx)
29573 + movl $-EFAULT,%ss:(%ebx)
29574 jmp 5000b
29575
29576 .previous
29577
29578 + pushl_cfi %ss
29579 + popl_cfi %ds
29580 + pushl_cfi %ss
29581 + popl_cfi %es
29582 popl_cfi %ebx
29583 CFI_RESTORE ebx
29584 popl_cfi %esi
29585 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29586 popl_cfi %ecx # equivalent to addl $4,%esp
29587 ret
29588 CFI_ENDPROC
29589 -ENDPROC(csum_partial_copy_generic)
29590 +ENDPROC(csum_partial_copy_generic_to_user)
29591
29592 #else
29593
29594 /* Version for PentiumII/PPro */
29595
29596 #define ROUND1(x) \
29597 + nop; nop; nop; \
29598 SRC(movl x(%esi), %ebx ) ; \
29599 addl %ebx, %eax ; \
29600 - DST(movl %ebx, x(%edi) ) ;
29601 + DST(movl %ebx, %es:x(%edi)) ;
29602
29603 #define ROUND(x) \
29604 + nop; nop; nop; \
29605 SRC(movl x(%esi), %ebx ) ; \
29606 adcl %ebx, %eax ; \
29607 - DST(movl %ebx, x(%edi) ) ;
29608 + DST(movl %ebx, %es:x(%edi)) ;
29609
29610 #define ARGBASE 12
29611 -
29612 -ENTRY(csum_partial_copy_generic)
29613 +
29614 +ENTRY(csum_partial_copy_generic_to_user)
29615 CFI_STARTPROC
29616 +
29617 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29618 + pushl_cfi %gs
29619 + popl_cfi %es
29620 + jmp csum_partial_copy_generic
29621 +#endif
29622 +
29623 +ENTRY(csum_partial_copy_generic_from_user)
29624 +
29625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29626 + pushl_cfi %gs
29627 + popl_cfi %ds
29628 +#endif
29629 +
29630 +ENTRY(csum_partial_copy_generic)
29631 pushl_cfi %ebx
29632 CFI_REL_OFFSET ebx, 0
29633 pushl_cfi %edi
29634 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29635 subl %ebx, %edi
29636 lea -1(%esi),%edx
29637 andl $-32,%edx
29638 - lea 3f(%ebx,%ebx), %ebx
29639 + lea 3f(%ebx,%ebx,2), %ebx
29640 testl %esi, %esi
29641 jmp *%ebx
29642 1: addl $64,%esi
29643 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29644 jb 5f
29645 SRC( movw (%esi), %dx )
29646 leal 2(%esi), %esi
29647 -DST( movw %dx, (%edi) )
29648 +DST( movw %dx, %es:(%edi) )
29649 leal 2(%edi), %edi
29650 je 6f
29651 shll $16,%edx
29652 5:
29653 SRC( movb (%esi), %dl )
29654 -DST( movb %dl, (%edi) )
29655 +DST( movb %dl, %es:(%edi) )
29656 6: addl %edx, %eax
29657 adcl $0, %eax
29658 7:
29659 .section .fixup, "ax"
29660 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29661 - movl $-EFAULT, (%ebx)
29662 + movl $-EFAULT, %ss:(%ebx)
29663 # zero the complete destination (computing the rest is too much work)
29664 movl ARGBASE+8(%esp),%edi # dst
29665 movl ARGBASE+12(%esp),%ecx # len
29666 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29667 rep; stosb
29668 jmp 7b
29669 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29670 - movl $-EFAULT, (%ebx)
29671 + movl $-EFAULT, %ss:(%ebx)
29672 jmp 7b
29673 .previous
29674
29675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29676 + pushl_cfi %ss
29677 + popl_cfi %ds
29678 + pushl_cfi %ss
29679 + popl_cfi %es
29680 +#endif
29681 +
29682 popl_cfi %esi
29683 CFI_RESTORE esi
29684 popl_cfi %edi
29685 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29686 CFI_RESTORE ebx
29687 ret
29688 CFI_ENDPROC
29689 -ENDPROC(csum_partial_copy_generic)
29690 +ENDPROC(csum_partial_copy_generic_to_user)
29691
29692 #undef ROUND
29693 #undef ROUND1
29694 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29695 index f2145cf..cea889d 100644
29696 --- a/arch/x86/lib/clear_page_64.S
29697 +++ b/arch/x86/lib/clear_page_64.S
29698 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29699 movl $4096/8,%ecx
29700 xorl %eax,%eax
29701 rep stosq
29702 + pax_force_retaddr
29703 ret
29704 CFI_ENDPROC
29705 ENDPROC(clear_page_c)
29706 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29707 movl $4096,%ecx
29708 xorl %eax,%eax
29709 rep stosb
29710 + pax_force_retaddr
29711 ret
29712 CFI_ENDPROC
29713 ENDPROC(clear_page_c_e)
29714 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29715 leaq 64(%rdi),%rdi
29716 jnz .Lloop
29717 nop
29718 + pax_force_retaddr
29719 ret
29720 CFI_ENDPROC
29721 .Lclear_page_end:
29722 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29723
29724 #include <asm/cpufeature.h>
29725
29726 - .section .altinstr_replacement,"ax"
29727 + .section .altinstr_replacement,"a"
29728 1: .byte 0xeb /* jmp <disp8> */
29729 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29730 2: .byte 0xeb /* jmp <disp8> */
29731 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29732 index 40a1725..5d12ac4 100644
29733 --- a/arch/x86/lib/cmpxchg16b_emu.S
29734 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29735 @@ -8,6 +8,7 @@
29736 #include <linux/linkage.h>
29737 #include <asm/dwarf2.h>
29738 #include <asm/percpu.h>
29739 +#include <asm/alternative-asm.h>
29740
29741 .text
29742
29743 @@ -46,12 +47,14 @@ CFI_STARTPROC
29744 CFI_REMEMBER_STATE
29745 popfq_cfi
29746 mov $1, %al
29747 + pax_force_retaddr
29748 ret
29749
29750 CFI_RESTORE_STATE
29751 .Lnot_same:
29752 popfq_cfi
29753 xor %al,%al
29754 + pax_force_retaddr
29755 ret
29756
29757 CFI_ENDPROC
29758 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29759 index 176cca6..e0d658e 100644
29760 --- a/arch/x86/lib/copy_page_64.S
29761 +++ b/arch/x86/lib/copy_page_64.S
29762 @@ -9,6 +9,7 @@ copy_page_rep:
29763 CFI_STARTPROC
29764 movl $4096/8, %ecx
29765 rep movsq
29766 + pax_force_retaddr
29767 ret
29768 CFI_ENDPROC
29769 ENDPROC(copy_page_rep)
29770 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29771 CFI_ADJUST_CFA_OFFSET 2*8
29772 movq %rbx, (%rsp)
29773 CFI_REL_OFFSET rbx, 0
29774 - movq %r12, 1*8(%rsp)
29775 - CFI_REL_OFFSET r12, 1*8
29776 + movq %r13, 1*8(%rsp)
29777 + CFI_REL_OFFSET r13, 1*8
29778
29779 movl $(4096/64)-5, %ecx
29780 .p2align 4
29781 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29782 movq 0x8*4(%rsi), %r9
29783 movq 0x8*5(%rsi), %r10
29784 movq 0x8*6(%rsi), %r11
29785 - movq 0x8*7(%rsi), %r12
29786 + movq 0x8*7(%rsi), %r13
29787
29788 prefetcht0 5*64(%rsi)
29789
29790 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29791 movq %r9, 0x8*4(%rdi)
29792 movq %r10, 0x8*5(%rdi)
29793 movq %r11, 0x8*6(%rdi)
29794 - movq %r12, 0x8*7(%rdi)
29795 + movq %r13, 0x8*7(%rdi)
29796
29797 leaq 64 (%rsi), %rsi
29798 leaq 64 (%rdi), %rdi
29799 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29800 movq 0x8*4(%rsi), %r9
29801 movq 0x8*5(%rsi), %r10
29802 movq 0x8*6(%rsi), %r11
29803 - movq 0x8*7(%rsi), %r12
29804 + movq 0x8*7(%rsi), %r13
29805
29806 movq %rax, 0x8*0(%rdi)
29807 movq %rbx, 0x8*1(%rdi)
29808 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29809 movq %r9, 0x8*4(%rdi)
29810 movq %r10, 0x8*5(%rdi)
29811 movq %r11, 0x8*6(%rdi)
29812 - movq %r12, 0x8*7(%rdi)
29813 + movq %r13, 0x8*7(%rdi)
29814
29815 leaq 64(%rdi), %rdi
29816 leaq 64(%rsi), %rsi
29817 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29818
29819 movq (%rsp), %rbx
29820 CFI_RESTORE rbx
29821 - movq 1*8(%rsp), %r12
29822 - CFI_RESTORE r12
29823 + movq 1*8(%rsp), %r13
29824 + CFI_RESTORE r13
29825 addq $2*8, %rsp
29826 CFI_ADJUST_CFA_OFFSET -2*8
29827 + pax_force_retaddr
29828 ret
29829 .Lcopy_page_end:
29830 CFI_ENDPROC
29831 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29832
29833 #include <asm/cpufeature.h>
29834
29835 - .section .altinstr_replacement,"ax"
29836 + .section .altinstr_replacement,"a"
29837 1: .byte 0xeb /* jmp <disp8> */
29838 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29839 2:
29840 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29841 index dee945d..a84067b 100644
29842 --- a/arch/x86/lib/copy_user_64.S
29843 +++ b/arch/x86/lib/copy_user_64.S
29844 @@ -18,31 +18,7 @@
29845 #include <asm/alternative-asm.h>
29846 #include <asm/asm.h>
29847 #include <asm/smap.h>
29848 -
29849 -/*
29850 - * By placing feature2 after feature1 in altinstructions section, we logically
29851 - * implement:
29852 - * If CPU has feature2, jmp to alt2 is used
29853 - * else if CPU has feature1, jmp to alt1 is used
29854 - * else jmp to orig is used.
29855 - */
29856 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29857 -0:
29858 - .byte 0xe9 /* 32bit jump */
29859 - .long \orig-1f /* by default jump to orig */
29860 -1:
29861 - .section .altinstr_replacement,"ax"
29862 -2: .byte 0xe9 /* near jump with 32bit immediate */
29863 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29864 -3: .byte 0xe9 /* near jump with 32bit immediate */
29865 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29866 - .previous
29867 -
29868 - .section .altinstructions,"a"
29869 - altinstruction_entry 0b,2b,\feature1,5,5
29870 - altinstruction_entry 0b,3b,\feature2,5,5
29871 - .previous
29872 - .endm
29873 +#include <asm/pgtable.h>
29874
29875 .macro ALIGN_DESTINATION
29876 #ifdef FIX_ALIGNMENT
29877 @@ -70,52 +46,6 @@
29878 #endif
29879 .endm
29880
29881 -/* Standard copy_to_user with segment limit checking */
29882 -ENTRY(_copy_to_user)
29883 - CFI_STARTPROC
29884 - GET_THREAD_INFO(%rax)
29885 - movq %rdi,%rcx
29886 - addq %rdx,%rcx
29887 - jc bad_to_user
29888 - cmpq TI_addr_limit(%rax),%rcx
29889 - ja bad_to_user
29890 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29891 - copy_user_generic_unrolled,copy_user_generic_string, \
29892 - copy_user_enhanced_fast_string
29893 - CFI_ENDPROC
29894 -ENDPROC(_copy_to_user)
29895 -
29896 -/* Standard copy_from_user with segment limit checking */
29897 -ENTRY(_copy_from_user)
29898 - CFI_STARTPROC
29899 - GET_THREAD_INFO(%rax)
29900 - movq %rsi,%rcx
29901 - addq %rdx,%rcx
29902 - jc bad_from_user
29903 - cmpq TI_addr_limit(%rax),%rcx
29904 - ja bad_from_user
29905 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29906 - copy_user_generic_unrolled,copy_user_generic_string, \
29907 - copy_user_enhanced_fast_string
29908 - CFI_ENDPROC
29909 -ENDPROC(_copy_from_user)
29910 -
29911 - .section .fixup,"ax"
29912 - /* must zero dest */
29913 -ENTRY(bad_from_user)
29914 -bad_from_user:
29915 - CFI_STARTPROC
29916 - movl %edx,%ecx
29917 - xorl %eax,%eax
29918 - rep
29919 - stosb
29920 -bad_to_user:
29921 - movl %edx,%eax
29922 - ret
29923 - CFI_ENDPROC
29924 -ENDPROC(bad_from_user)
29925 - .previous
29926 -
29927 /*
29928 * copy_user_generic_unrolled - memory copy with exception handling.
29929 * This version is for CPUs like P4 that don't have efficient micro
29930 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29931 */
29932 ENTRY(copy_user_generic_unrolled)
29933 CFI_STARTPROC
29934 + ASM_PAX_OPEN_USERLAND
29935 ASM_STAC
29936 cmpl $8,%edx
29937 jb 20f /* less then 8 bytes, go to byte copy loop */
29938 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29939 jnz 21b
29940 23: xor %eax,%eax
29941 ASM_CLAC
29942 + ASM_PAX_CLOSE_USERLAND
29943 + pax_force_retaddr
29944 ret
29945
29946 .section .fixup,"ax"
29947 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29948 */
29949 ENTRY(copy_user_generic_string)
29950 CFI_STARTPROC
29951 + ASM_PAX_OPEN_USERLAND
29952 ASM_STAC
29953 cmpl $8,%edx
29954 jb 2f /* less than 8 bytes, go to byte copy loop */
29955 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29956 movsb
29957 xorl %eax,%eax
29958 ASM_CLAC
29959 + ASM_PAX_CLOSE_USERLAND
29960 + pax_force_retaddr
29961 ret
29962
29963 .section .fixup,"ax"
29964 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29965 */
29966 ENTRY(copy_user_enhanced_fast_string)
29967 CFI_STARTPROC
29968 + ASM_PAX_OPEN_USERLAND
29969 ASM_STAC
29970 movl %edx,%ecx
29971 1: rep
29972 movsb
29973 xorl %eax,%eax
29974 ASM_CLAC
29975 + ASM_PAX_CLOSE_USERLAND
29976 + pax_force_retaddr
29977 ret
29978
29979 .section .fixup,"ax"
29980 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29981 index 6a4f43c..c70fb52 100644
29982 --- a/arch/x86/lib/copy_user_nocache_64.S
29983 +++ b/arch/x86/lib/copy_user_nocache_64.S
29984 @@ -8,6 +8,7 @@
29985
29986 #include <linux/linkage.h>
29987 #include <asm/dwarf2.h>
29988 +#include <asm/alternative-asm.h>
29989
29990 #define FIX_ALIGNMENT 1
29991
29992 @@ -16,6 +17,7 @@
29993 #include <asm/thread_info.h>
29994 #include <asm/asm.h>
29995 #include <asm/smap.h>
29996 +#include <asm/pgtable.h>
29997
29998 .macro ALIGN_DESTINATION
29999 #ifdef FIX_ALIGNMENT
30000 @@ -49,6 +51,16 @@
30001 */
30002 ENTRY(__copy_user_nocache)
30003 CFI_STARTPROC
30004 +
30005 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30006 + mov pax_user_shadow_base,%rcx
30007 + cmp %rcx,%rsi
30008 + jae 1f
30009 + add %rcx,%rsi
30010 +1:
30011 +#endif
30012 +
30013 + ASM_PAX_OPEN_USERLAND
30014 ASM_STAC
30015 cmpl $8,%edx
30016 jb 20f /* less then 8 bytes, go to byte copy loop */
30017 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30018 jnz 21b
30019 23: xorl %eax,%eax
30020 ASM_CLAC
30021 + ASM_PAX_CLOSE_USERLAND
30022 sfence
30023 + pax_force_retaddr
30024 ret
30025
30026 .section .fixup,"ax"
30027 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30028 index 2419d5f..fe52d0e 100644
30029 --- a/arch/x86/lib/csum-copy_64.S
30030 +++ b/arch/x86/lib/csum-copy_64.S
30031 @@ -9,6 +9,7 @@
30032 #include <asm/dwarf2.h>
30033 #include <asm/errno.h>
30034 #include <asm/asm.h>
30035 +#include <asm/alternative-asm.h>
30036
30037 /*
30038 * Checksum copy with exception handling.
30039 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30040 CFI_ADJUST_CFA_OFFSET 7*8
30041 movq %rbx, 2*8(%rsp)
30042 CFI_REL_OFFSET rbx, 2*8
30043 - movq %r12, 3*8(%rsp)
30044 - CFI_REL_OFFSET r12, 3*8
30045 + movq %r15, 3*8(%rsp)
30046 + CFI_REL_OFFSET r15, 3*8
30047 movq %r14, 4*8(%rsp)
30048 CFI_REL_OFFSET r14, 4*8
30049 movq %r13, 5*8(%rsp)
30050 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30051 movl %edx, %ecx
30052
30053 xorl %r9d, %r9d
30054 - movq %rcx, %r12
30055 + movq %rcx, %r15
30056
30057 - shrq $6, %r12
30058 + shrq $6, %r15
30059 jz .Lhandle_tail /* < 64 */
30060
30061 clc
30062
30063 /* main loop. clear in 64 byte blocks */
30064 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30065 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30066 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30067 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30068 .p2align 4
30069 .Lloop:
30070 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30071 adcq %r14, %rax
30072 adcq %r13, %rax
30073
30074 - decl %r12d
30075 + decl %r15d
30076
30077 dest
30078 movq %rbx, (%rsi)
30079 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30080 .Lende:
30081 movq 2*8(%rsp), %rbx
30082 CFI_RESTORE rbx
30083 - movq 3*8(%rsp), %r12
30084 - CFI_RESTORE r12
30085 + movq 3*8(%rsp), %r15
30086 + CFI_RESTORE r15
30087 movq 4*8(%rsp), %r14
30088 CFI_RESTORE r14
30089 movq 5*8(%rsp), %r13
30090 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30091 CFI_RESTORE rbp
30092 addq $7*8, %rsp
30093 CFI_ADJUST_CFA_OFFSET -7*8
30094 + pax_force_retaddr
30095 ret
30096 CFI_RESTORE_STATE
30097
30098 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30099 index 1318f75..44c30fd 100644
30100 --- a/arch/x86/lib/csum-wrappers_64.c
30101 +++ b/arch/x86/lib/csum-wrappers_64.c
30102 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30103 len -= 2;
30104 }
30105 }
30106 + pax_open_userland();
30107 stac();
30108 - isum = csum_partial_copy_generic((__force const void *)src,
30109 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30110 dst, len, isum, errp, NULL);
30111 clac();
30112 + pax_close_userland();
30113 if (unlikely(*errp))
30114 goto out_err;
30115
30116 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30117 }
30118
30119 *errp = 0;
30120 + pax_open_userland();
30121 stac();
30122 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30123 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30124 len, isum, NULL, errp);
30125 clac();
30126 + pax_close_userland();
30127 return ret;
30128 }
30129 EXPORT_SYMBOL(csum_partial_copy_to_user);
30130 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30131 index a451235..1daa956 100644
30132 --- a/arch/x86/lib/getuser.S
30133 +++ b/arch/x86/lib/getuser.S
30134 @@ -33,17 +33,40 @@
30135 #include <asm/thread_info.h>
30136 #include <asm/asm.h>
30137 #include <asm/smap.h>
30138 +#include <asm/segment.h>
30139 +#include <asm/pgtable.h>
30140 +#include <asm/alternative-asm.h>
30141 +
30142 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30143 +#define __copyuser_seg gs;
30144 +#else
30145 +#define __copyuser_seg
30146 +#endif
30147
30148 .text
30149 ENTRY(__get_user_1)
30150 CFI_STARTPROC
30151 +
30152 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30153 GET_THREAD_INFO(%_ASM_DX)
30154 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30155 jae bad_get_user
30156 ASM_STAC
30157 -1: movzbl (%_ASM_AX),%edx
30158 +
30159 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30160 + mov pax_user_shadow_base,%_ASM_DX
30161 + cmp %_ASM_DX,%_ASM_AX
30162 + jae 1234f
30163 + add %_ASM_DX,%_ASM_AX
30164 +1234:
30165 +#endif
30166 +
30167 +#endif
30168 +
30169 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30170 xor %eax,%eax
30171 ASM_CLAC
30172 + pax_force_retaddr
30173 ret
30174 CFI_ENDPROC
30175 ENDPROC(__get_user_1)
30176 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30177 ENTRY(__get_user_2)
30178 CFI_STARTPROC
30179 add $1,%_ASM_AX
30180 +
30181 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30182 jc bad_get_user
30183 GET_THREAD_INFO(%_ASM_DX)
30184 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30185 jae bad_get_user
30186 ASM_STAC
30187 -2: movzwl -1(%_ASM_AX),%edx
30188 +
30189 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30190 + mov pax_user_shadow_base,%_ASM_DX
30191 + cmp %_ASM_DX,%_ASM_AX
30192 + jae 1234f
30193 + add %_ASM_DX,%_ASM_AX
30194 +1234:
30195 +#endif
30196 +
30197 +#endif
30198 +
30199 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30200 xor %eax,%eax
30201 ASM_CLAC
30202 + pax_force_retaddr
30203 ret
30204 CFI_ENDPROC
30205 ENDPROC(__get_user_2)
30206 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30207 ENTRY(__get_user_4)
30208 CFI_STARTPROC
30209 add $3,%_ASM_AX
30210 +
30211 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30212 jc bad_get_user
30213 GET_THREAD_INFO(%_ASM_DX)
30214 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30215 jae bad_get_user
30216 ASM_STAC
30217 -3: movl -3(%_ASM_AX),%edx
30218 +
30219 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30220 + mov pax_user_shadow_base,%_ASM_DX
30221 + cmp %_ASM_DX,%_ASM_AX
30222 + jae 1234f
30223 + add %_ASM_DX,%_ASM_AX
30224 +1234:
30225 +#endif
30226 +
30227 +#endif
30228 +
30229 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30230 xor %eax,%eax
30231 ASM_CLAC
30232 + pax_force_retaddr
30233 ret
30234 CFI_ENDPROC
30235 ENDPROC(__get_user_4)
30236 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30237 GET_THREAD_INFO(%_ASM_DX)
30238 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30239 jae bad_get_user
30240 +
30241 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30242 + mov pax_user_shadow_base,%_ASM_DX
30243 + cmp %_ASM_DX,%_ASM_AX
30244 + jae 1234f
30245 + add %_ASM_DX,%_ASM_AX
30246 +1234:
30247 +#endif
30248 +
30249 ASM_STAC
30250 4: movq -7(%_ASM_AX),%rdx
30251 xor %eax,%eax
30252 ASM_CLAC
30253 + pax_force_retaddr
30254 ret
30255 #else
30256 add $7,%_ASM_AX
30257 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30258 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30259 jae bad_get_user_8
30260 ASM_STAC
30261 -4: movl -7(%_ASM_AX),%edx
30262 -5: movl -3(%_ASM_AX),%ecx
30263 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30264 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30265 xor %eax,%eax
30266 ASM_CLAC
30267 + pax_force_retaddr
30268 ret
30269 #endif
30270 CFI_ENDPROC
30271 @@ -113,6 +175,7 @@ bad_get_user:
30272 xor %edx,%edx
30273 mov $(-EFAULT),%_ASM_AX
30274 ASM_CLAC
30275 + pax_force_retaddr
30276 ret
30277 CFI_ENDPROC
30278 END(bad_get_user)
30279 @@ -124,6 +187,7 @@ bad_get_user_8:
30280 xor %ecx,%ecx
30281 mov $(-EFAULT),%_ASM_AX
30282 ASM_CLAC
30283 + pax_force_retaddr
30284 ret
30285 CFI_ENDPROC
30286 END(bad_get_user_8)
30287 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30288 index 54fcffe..7be149e 100644
30289 --- a/arch/x86/lib/insn.c
30290 +++ b/arch/x86/lib/insn.c
30291 @@ -20,8 +20,10 @@
30292
30293 #ifdef __KERNEL__
30294 #include <linux/string.h>
30295 +#include <asm/pgtable_types.h>
30296 #else
30297 #include <string.h>
30298 +#define ktla_ktva(addr) addr
30299 #endif
30300 #include <asm/inat.h>
30301 #include <asm/insn.h>
30302 @@ -53,8 +55,8 @@
30303 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30304 {
30305 memset(insn, 0, sizeof(*insn));
30306 - insn->kaddr = kaddr;
30307 - insn->next_byte = kaddr;
30308 + insn->kaddr = ktla_ktva(kaddr);
30309 + insn->next_byte = ktla_ktva(kaddr);
30310 insn->x86_64 = x86_64 ? 1 : 0;
30311 insn->opnd_bytes = 4;
30312 if (x86_64)
30313 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30314 index 05a95e7..326f2fa 100644
30315 --- a/arch/x86/lib/iomap_copy_64.S
30316 +++ b/arch/x86/lib/iomap_copy_64.S
30317 @@ -17,6 +17,7 @@
30318
30319 #include <linux/linkage.h>
30320 #include <asm/dwarf2.h>
30321 +#include <asm/alternative-asm.h>
30322
30323 /*
30324 * override generic version in lib/iomap_copy.c
30325 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30326 CFI_STARTPROC
30327 movl %edx,%ecx
30328 rep movsd
30329 + pax_force_retaddr
30330 ret
30331 CFI_ENDPROC
30332 ENDPROC(__iowrite32_copy)
30333 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30334 index 56313a3..0db417e 100644
30335 --- a/arch/x86/lib/memcpy_64.S
30336 +++ b/arch/x86/lib/memcpy_64.S
30337 @@ -24,7 +24,7 @@
30338 * This gets patched over the unrolled variant (below) via the
30339 * alternative instructions framework:
30340 */
30341 - .section .altinstr_replacement, "ax", @progbits
30342 + .section .altinstr_replacement, "a", @progbits
30343 .Lmemcpy_c:
30344 movq %rdi, %rax
30345 movq %rdx, %rcx
30346 @@ -33,6 +33,7 @@
30347 rep movsq
30348 movl %edx, %ecx
30349 rep movsb
30350 + pax_force_retaddr
30351 ret
30352 .Lmemcpy_e:
30353 .previous
30354 @@ -44,11 +45,12 @@
30355 * This gets patched over the unrolled variant (below) via the
30356 * alternative instructions framework:
30357 */
30358 - .section .altinstr_replacement, "ax", @progbits
30359 + .section .altinstr_replacement, "a", @progbits
30360 .Lmemcpy_c_e:
30361 movq %rdi, %rax
30362 movq %rdx, %rcx
30363 rep movsb
30364 + pax_force_retaddr
30365 ret
30366 .Lmemcpy_e_e:
30367 .previous
30368 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30369 movq %r9, 1*8(%rdi)
30370 movq %r10, -2*8(%rdi, %rdx)
30371 movq %r11, -1*8(%rdi, %rdx)
30372 + pax_force_retaddr
30373 retq
30374 .p2align 4
30375 .Lless_16bytes:
30376 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30377 movq -1*8(%rsi, %rdx), %r9
30378 movq %r8, 0*8(%rdi)
30379 movq %r9, -1*8(%rdi, %rdx)
30380 + pax_force_retaddr
30381 retq
30382 .p2align 4
30383 .Lless_8bytes:
30384 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30385 movl -4(%rsi, %rdx), %r8d
30386 movl %ecx, (%rdi)
30387 movl %r8d, -4(%rdi, %rdx)
30388 + pax_force_retaddr
30389 retq
30390 .p2align 4
30391 .Lless_3bytes:
30392 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30393 movb %cl, (%rdi)
30394
30395 .Lend:
30396 + pax_force_retaddr
30397 retq
30398 CFI_ENDPROC
30399 ENDPROC(memcpy)
30400 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30401 index 65268a6..dd1de11 100644
30402 --- a/arch/x86/lib/memmove_64.S
30403 +++ b/arch/x86/lib/memmove_64.S
30404 @@ -202,14 +202,16 @@ ENTRY(memmove)
30405 movb (%rsi), %r11b
30406 movb %r11b, (%rdi)
30407 13:
30408 + pax_force_retaddr
30409 retq
30410 CFI_ENDPROC
30411
30412 - .section .altinstr_replacement,"ax"
30413 + .section .altinstr_replacement,"a"
30414 .Lmemmove_begin_forward_efs:
30415 /* Forward moving data. */
30416 movq %rdx, %rcx
30417 rep movsb
30418 + pax_force_retaddr
30419 retq
30420 .Lmemmove_end_forward_efs:
30421 .previous
30422 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30423 index 2dcb380..2eb79fe 100644
30424 --- a/arch/x86/lib/memset_64.S
30425 +++ b/arch/x86/lib/memset_64.S
30426 @@ -16,7 +16,7 @@
30427 *
30428 * rax original destination
30429 */
30430 - .section .altinstr_replacement, "ax", @progbits
30431 + .section .altinstr_replacement, "a", @progbits
30432 .Lmemset_c:
30433 movq %rdi,%r9
30434 movq %rdx,%rcx
30435 @@ -30,6 +30,7 @@
30436 movl %edx,%ecx
30437 rep stosb
30438 movq %r9,%rax
30439 + pax_force_retaddr
30440 ret
30441 .Lmemset_e:
30442 .previous
30443 @@ -45,13 +46,14 @@
30444 *
30445 * rax original destination
30446 */
30447 - .section .altinstr_replacement, "ax", @progbits
30448 + .section .altinstr_replacement, "a", @progbits
30449 .Lmemset_c_e:
30450 movq %rdi,%r9
30451 movb %sil,%al
30452 movq %rdx,%rcx
30453 rep stosb
30454 movq %r9,%rax
30455 + pax_force_retaddr
30456 ret
30457 .Lmemset_e_e:
30458 .previous
30459 @@ -118,6 +120,7 @@ ENTRY(__memset)
30460
30461 .Lende:
30462 movq %r10,%rax
30463 + pax_force_retaddr
30464 ret
30465
30466 CFI_RESTORE_STATE
30467 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30468 index c9f2d9b..e7fd2c0 100644
30469 --- a/arch/x86/lib/mmx_32.c
30470 +++ b/arch/x86/lib/mmx_32.c
30471 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30472 {
30473 void *p;
30474 int i;
30475 + unsigned long cr0;
30476
30477 if (unlikely(in_interrupt()))
30478 return __memcpy(to, from, len);
30479 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30480 kernel_fpu_begin();
30481
30482 __asm__ __volatile__ (
30483 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30484 - " prefetch 64(%0)\n"
30485 - " prefetch 128(%0)\n"
30486 - " prefetch 192(%0)\n"
30487 - " prefetch 256(%0)\n"
30488 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30489 + " prefetch 64(%1)\n"
30490 + " prefetch 128(%1)\n"
30491 + " prefetch 192(%1)\n"
30492 + " prefetch 256(%1)\n"
30493 "2: \n"
30494 ".section .fixup, \"ax\"\n"
30495 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30496 + "3: \n"
30497 +
30498 +#ifdef CONFIG_PAX_KERNEXEC
30499 + " movl %%cr0, %0\n"
30500 + " movl %0, %%eax\n"
30501 + " andl $0xFFFEFFFF, %%eax\n"
30502 + " movl %%eax, %%cr0\n"
30503 +#endif
30504 +
30505 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30506 +
30507 +#ifdef CONFIG_PAX_KERNEXEC
30508 + " movl %0, %%cr0\n"
30509 +#endif
30510 +
30511 " jmp 2b\n"
30512 ".previous\n"
30513 _ASM_EXTABLE(1b, 3b)
30514 - : : "r" (from));
30515 + : "=&r" (cr0) : "r" (from) : "ax");
30516
30517 for ( ; i > 5; i--) {
30518 __asm__ __volatile__ (
30519 - "1: prefetch 320(%0)\n"
30520 - "2: movq (%0), %%mm0\n"
30521 - " movq 8(%0), %%mm1\n"
30522 - " movq 16(%0), %%mm2\n"
30523 - " movq 24(%0), %%mm3\n"
30524 - " movq %%mm0, (%1)\n"
30525 - " movq %%mm1, 8(%1)\n"
30526 - " movq %%mm2, 16(%1)\n"
30527 - " movq %%mm3, 24(%1)\n"
30528 - " movq 32(%0), %%mm0\n"
30529 - " movq 40(%0), %%mm1\n"
30530 - " movq 48(%0), %%mm2\n"
30531 - " movq 56(%0), %%mm3\n"
30532 - " movq %%mm0, 32(%1)\n"
30533 - " movq %%mm1, 40(%1)\n"
30534 - " movq %%mm2, 48(%1)\n"
30535 - " movq %%mm3, 56(%1)\n"
30536 + "1: prefetch 320(%1)\n"
30537 + "2: movq (%1), %%mm0\n"
30538 + " movq 8(%1), %%mm1\n"
30539 + " movq 16(%1), %%mm2\n"
30540 + " movq 24(%1), %%mm3\n"
30541 + " movq %%mm0, (%2)\n"
30542 + " movq %%mm1, 8(%2)\n"
30543 + " movq %%mm2, 16(%2)\n"
30544 + " movq %%mm3, 24(%2)\n"
30545 + " movq 32(%1), %%mm0\n"
30546 + " movq 40(%1), %%mm1\n"
30547 + " movq 48(%1), %%mm2\n"
30548 + " movq 56(%1), %%mm3\n"
30549 + " movq %%mm0, 32(%2)\n"
30550 + " movq %%mm1, 40(%2)\n"
30551 + " movq %%mm2, 48(%2)\n"
30552 + " movq %%mm3, 56(%2)\n"
30553 ".section .fixup, \"ax\"\n"
30554 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30555 + "3:\n"
30556 +
30557 +#ifdef CONFIG_PAX_KERNEXEC
30558 + " movl %%cr0, %0\n"
30559 + " movl %0, %%eax\n"
30560 + " andl $0xFFFEFFFF, %%eax\n"
30561 + " movl %%eax, %%cr0\n"
30562 +#endif
30563 +
30564 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30565 +
30566 +#ifdef CONFIG_PAX_KERNEXEC
30567 + " movl %0, %%cr0\n"
30568 +#endif
30569 +
30570 " jmp 2b\n"
30571 ".previous\n"
30572 _ASM_EXTABLE(1b, 3b)
30573 - : : "r" (from), "r" (to) : "memory");
30574 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30575
30576 from += 64;
30577 to += 64;
30578 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30579 static void fast_copy_page(void *to, void *from)
30580 {
30581 int i;
30582 + unsigned long cr0;
30583
30584 kernel_fpu_begin();
30585
30586 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30587 * but that is for later. -AV
30588 */
30589 __asm__ __volatile__(
30590 - "1: prefetch (%0)\n"
30591 - " prefetch 64(%0)\n"
30592 - " prefetch 128(%0)\n"
30593 - " prefetch 192(%0)\n"
30594 - " prefetch 256(%0)\n"
30595 + "1: prefetch (%1)\n"
30596 + " prefetch 64(%1)\n"
30597 + " prefetch 128(%1)\n"
30598 + " prefetch 192(%1)\n"
30599 + " prefetch 256(%1)\n"
30600 "2: \n"
30601 ".section .fixup, \"ax\"\n"
30602 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30603 + "3: \n"
30604 +
30605 +#ifdef CONFIG_PAX_KERNEXEC
30606 + " movl %%cr0, %0\n"
30607 + " movl %0, %%eax\n"
30608 + " andl $0xFFFEFFFF, %%eax\n"
30609 + " movl %%eax, %%cr0\n"
30610 +#endif
30611 +
30612 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30613 +
30614 +#ifdef CONFIG_PAX_KERNEXEC
30615 + " movl %0, %%cr0\n"
30616 +#endif
30617 +
30618 " jmp 2b\n"
30619 ".previous\n"
30620 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30621 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30622
30623 for (i = 0; i < (4096-320)/64; i++) {
30624 __asm__ __volatile__ (
30625 - "1: prefetch 320(%0)\n"
30626 - "2: movq (%0), %%mm0\n"
30627 - " movntq %%mm0, (%1)\n"
30628 - " movq 8(%0), %%mm1\n"
30629 - " movntq %%mm1, 8(%1)\n"
30630 - " movq 16(%0), %%mm2\n"
30631 - " movntq %%mm2, 16(%1)\n"
30632 - " movq 24(%0), %%mm3\n"
30633 - " movntq %%mm3, 24(%1)\n"
30634 - " movq 32(%0), %%mm4\n"
30635 - " movntq %%mm4, 32(%1)\n"
30636 - " movq 40(%0), %%mm5\n"
30637 - " movntq %%mm5, 40(%1)\n"
30638 - " movq 48(%0), %%mm6\n"
30639 - " movntq %%mm6, 48(%1)\n"
30640 - " movq 56(%0), %%mm7\n"
30641 - " movntq %%mm7, 56(%1)\n"
30642 + "1: prefetch 320(%1)\n"
30643 + "2: movq (%1), %%mm0\n"
30644 + " movntq %%mm0, (%2)\n"
30645 + " movq 8(%1), %%mm1\n"
30646 + " movntq %%mm1, 8(%2)\n"
30647 + " movq 16(%1), %%mm2\n"
30648 + " movntq %%mm2, 16(%2)\n"
30649 + " movq 24(%1), %%mm3\n"
30650 + " movntq %%mm3, 24(%2)\n"
30651 + " movq 32(%1), %%mm4\n"
30652 + " movntq %%mm4, 32(%2)\n"
30653 + " movq 40(%1), %%mm5\n"
30654 + " movntq %%mm5, 40(%2)\n"
30655 + " movq 48(%1), %%mm6\n"
30656 + " movntq %%mm6, 48(%2)\n"
30657 + " movq 56(%1), %%mm7\n"
30658 + " movntq %%mm7, 56(%2)\n"
30659 ".section .fixup, \"ax\"\n"
30660 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30661 + "3:\n"
30662 +
30663 +#ifdef CONFIG_PAX_KERNEXEC
30664 + " movl %%cr0, %0\n"
30665 + " movl %0, %%eax\n"
30666 + " andl $0xFFFEFFFF, %%eax\n"
30667 + " movl %%eax, %%cr0\n"
30668 +#endif
30669 +
30670 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30671 +
30672 +#ifdef CONFIG_PAX_KERNEXEC
30673 + " movl %0, %%cr0\n"
30674 +#endif
30675 +
30676 " jmp 2b\n"
30677 ".previous\n"
30678 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30679 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30680
30681 from += 64;
30682 to += 64;
30683 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30684 static void fast_copy_page(void *to, void *from)
30685 {
30686 int i;
30687 + unsigned long cr0;
30688
30689 kernel_fpu_begin();
30690
30691 __asm__ __volatile__ (
30692 - "1: prefetch (%0)\n"
30693 - " prefetch 64(%0)\n"
30694 - " prefetch 128(%0)\n"
30695 - " prefetch 192(%0)\n"
30696 - " prefetch 256(%0)\n"
30697 + "1: prefetch (%1)\n"
30698 + " prefetch 64(%1)\n"
30699 + " prefetch 128(%1)\n"
30700 + " prefetch 192(%1)\n"
30701 + " prefetch 256(%1)\n"
30702 "2: \n"
30703 ".section .fixup, \"ax\"\n"
30704 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30705 + "3: \n"
30706 +
30707 +#ifdef CONFIG_PAX_KERNEXEC
30708 + " movl %%cr0, %0\n"
30709 + " movl %0, %%eax\n"
30710 + " andl $0xFFFEFFFF, %%eax\n"
30711 + " movl %%eax, %%cr0\n"
30712 +#endif
30713 +
30714 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30715 +
30716 +#ifdef CONFIG_PAX_KERNEXEC
30717 + " movl %0, %%cr0\n"
30718 +#endif
30719 +
30720 " jmp 2b\n"
30721 ".previous\n"
30722 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30723 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30724
30725 for (i = 0; i < 4096/64; i++) {
30726 __asm__ __volatile__ (
30727 - "1: prefetch 320(%0)\n"
30728 - "2: movq (%0), %%mm0\n"
30729 - " movq 8(%0), %%mm1\n"
30730 - " movq 16(%0), %%mm2\n"
30731 - " movq 24(%0), %%mm3\n"
30732 - " movq %%mm0, (%1)\n"
30733 - " movq %%mm1, 8(%1)\n"
30734 - " movq %%mm2, 16(%1)\n"
30735 - " movq %%mm3, 24(%1)\n"
30736 - " movq 32(%0), %%mm0\n"
30737 - " movq 40(%0), %%mm1\n"
30738 - " movq 48(%0), %%mm2\n"
30739 - " movq 56(%0), %%mm3\n"
30740 - " movq %%mm0, 32(%1)\n"
30741 - " movq %%mm1, 40(%1)\n"
30742 - " movq %%mm2, 48(%1)\n"
30743 - " movq %%mm3, 56(%1)\n"
30744 + "1: prefetch 320(%1)\n"
30745 + "2: movq (%1), %%mm0\n"
30746 + " movq 8(%1), %%mm1\n"
30747 + " movq 16(%1), %%mm2\n"
30748 + " movq 24(%1), %%mm3\n"
30749 + " movq %%mm0, (%2)\n"
30750 + " movq %%mm1, 8(%2)\n"
30751 + " movq %%mm2, 16(%2)\n"
30752 + " movq %%mm3, 24(%2)\n"
30753 + " movq 32(%1), %%mm0\n"
30754 + " movq 40(%1), %%mm1\n"
30755 + " movq 48(%1), %%mm2\n"
30756 + " movq 56(%1), %%mm3\n"
30757 + " movq %%mm0, 32(%2)\n"
30758 + " movq %%mm1, 40(%2)\n"
30759 + " movq %%mm2, 48(%2)\n"
30760 + " movq %%mm3, 56(%2)\n"
30761 ".section .fixup, \"ax\"\n"
30762 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30763 + "3:\n"
30764 +
30765 +#ifdef CONFIG_PAX_KERNEXEC
30766 + " movl %%cr0, %0\n"
30767 + " movl %0, %%eax\n"
30768 + " andl $0xFFFEFFFF, %%eax\n"
30769 + " movl %%eax, %%cr0\n"
30770 +#endif
30771 +
30772 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30773 +
30774 +#ifdef CONFIG_PAX_KERNEXEC
30775 + " movl %0, %%cr0\n"
30776 +#endif
30777 +
30778 " jmp 2b\n"
30779 ".previous\n"
30780 _ASM_EXTABLE(1b, 3b)
30781 - : : "r" (from), "r" (to) : "memory");
30782 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30783
30784 from += 64;
30785 to += 64;
30786 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30787 index f6d13ee..d789440 100644
30788 --- a/arch/x86/lib/msr-reg.S
30789 +++ b/arch/x86/lib/msr-reg.S
30790 @@ -3,6 +3,7 @@
30791 #include <asm/dwarf2.h>
30792 #include <asm/asm.h>
30793 #include <asm/msr.h>
30794 +#include <asm/alternative-asm.h>
30795
30796 #ifdef CONFIG_X86_64
30797 /*
30798 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30799 movl %edi, 28(%r10)
30800 popq_cfi %rbp
30801 popq_cfi %rbx
30802 + pax_force_retaddr
30803 ret
30804 3:
30805 CFI_RESTORE_STATE
30806 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30807 index fc6ba17..d4d989d 100644
30808 --- a/arch/x86/lib/putuser.S
30809 +++ b/arch/x86/lib/putuser.S
30810 @@ -16,7 +16,9 @@
30811 #include <asm/errno.h>
30812 #include <asm/asm.h>
30813 #include <asm/smap.h>
30814 -
30815 +#include <asm/segment.h>
30816 +#include <asm/pgtable.h>
30817 +#include <asm/alternative-asm.h>
30818
30819 /*
30820 * __put_user_X
30821 @@ -30,57 +32,125 @@
30822 * as they get called from within inline assembly.
30823 */
30824
30825 -#define ENTER CFI_STARTPROC ; \
30826 - GET_THREAD_INFO(%_ASM_BX)
30827 -#define EXIT ASM_CLAC ; \
30828 - ret ; \
30829 +#define ENTER CFI_STARTPROC
30830 +#define EXIT ASM_CLAC ; \
30831 + pax_force_retaddr ; \
30832 + ret ; \
30833 CFI_ENDPROC
30834
30835 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30836 +#define _DEST %_ASM_CX,%_ASM_BX
30837 +#else
30838 +#define _DEST %_ASM_CX
30839 +#endif
30840 +
30841 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30842 +#define __copyuser_seg gs;
30843 +#else
30844 +#define __copyuser_seg
30845 +#endif
30846 +
30847 .text
30848 ENTRY(__put_user_1)
30849 ENTER
30850 +
30851 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30852 + GET_THREAD_INFO(%_ASM_BX)
30853 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30854 jae bad_put_user
30855 ASM_STAC
30856 -1: movb %al,(%_ASM_CX)
30857 +
30858 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30859 + mov pax_user_shadow_base,%_ASM_BX
30860 + cmp %_ASM_BX,%_ASM_CX
30861 + jb 1234f
30862 + xor %ebx,%ebx
30863 +1234:
30864 +#endif
30865 +
30866 +#endif
30867 +
30868 +1: __copyuser_seg movb %al,(_DEST)
30869 xor %eax,%eax
30870 EXIT
30871 ENDPROC(__put_user_1)
30872
30873 ENTRY(__put_user_2)
30874 ENTER
30875 +
30876 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30877 + GET_THREAD_INFO(%_ASM_BX)
30878 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30879 sub $1,%_ASM_BX
30880 cmp %_ASM_BX,%_ASM_CX
30881 jae bad_put_user
30882 ASM_STAC
30883 -2: movw %ax,(%_ASM_CX)
30884 +
30885 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30886 + mov pax_user_shadow_base,%_ASM_BX
30887 + cmp %_ASM_BX,%_ASM_CX
30888 + jb 1234f
30889 + xor %ebx,%ebx
30890 +1234:
30891 +#endif
30892 +
30893 +#endif
30894 +
30895 +2: __copyuser_seg movw %ax,(_DEST)
30896 xor %eax,%eax
30897 EXIT
30898 ENDPROC(__put_user_2)
30899
30900 ENTRY(__put_user_4)
30901 ENTER
30902 +
30903 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30904 + GET_THREAD_INFO(%_ASM_BX)
30905 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30906 sub $3,%_ASM_BX
30907 cmp %_ASM_BX,%_ASM_CX
30908 jae bad_put_user
30909 ASM_STAC
30910 -3: movl %eax,(%_ASM_CX)
30911 +
30912 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30913 + mov pax_user_shadow_base,%_ASM_BX
30914 + cmp %_ASM_BX,%_ASM_CX
30915 + jb 1234f
30916 + xor %ebx,%ebx
30917 +1234:
30918 +#endif
30919 +
30920 +#endif
30921 +
30922 +3: __copyuser_seg movl %eax,(_DEST)
30923 xor %eax,%eax
30924 EXIT
30925 ENDPROC(__put_user_4)
30926
30927 ENTRY(__put_user_8)
30928 ENTER
30929 +
30930 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30931 + GET_THREAD_INFO(%_ASM_BX)
30932 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30933 sub $7,%_ASM_BX
30934 cmp %_ASM_BX,%_ASM_CX
30935 jae bad_put_user
30936 ASM_STAC
30937 -4: mov %_ASM_AX,(%_ASM_CX)
30938 +
30939 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30940 + mov pax_user_shadow_base,%_ASM_BX
30941 + cmp %_ASM_BX,%_ASM_CX
30942 + jb 1234f
30943 + xor %ebx,%ebx
30944 +1234:
30945 +#endif
30946 +
30947 +#endif
30948 +
30949 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30950 #ifdef CONFIG_X86_32
30951 -5: movl %edx,4(%_ASM_CX)
30952 +5: __copyuser_seg movl %edx,4(_DEST)
30953 #endif
30954 xor %eax,%eax
30955 EXIT
30956 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30957 index 5dff5f0..cadebf4 100644
30958 --- a/arch/x86/lib/rwsem.S
30959 +++ b/arch/x86/lib/rwsem.S
30960 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30961 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30962 CFI_RESTORE __ASM_REG(dx)
30963 restore_common_regs
30964 + pax_force_retaddr
30965 ret
30966 CFI_ENDPROC
30967 ENDPROC(call_rwsem_down_read_failed)
30968 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30969 movq %rax,%rdi
30970 call rwsem_down_write_failed
30971 restore_common_regs
30972 + pax_force_retaddr
30973 ret
30974 CFI_ENDPROC
30975 ENDPROC(call_rwsem_down_write_failed)
30976 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30977 movq %rax,%rdi
30978 call rwsem_wake
30979 restore_common_regs
30980 -1: ret
30981 +1: pax_force_retaddr
30982 + ret
30983 CFI_ENDPROC
30984 ENDPROC(call_rwsem_wake)
30985
30986 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30987 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30988 CFI_RESTORE __ASM_REG(dx)
30989 restore_common_regs
30990 + pax_force_retaddr
30991 ret
30992 CFI_ENDPROC
30993 ENDPROC(call_rwsem_downgrade_wake)
30994 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30995 index b30b5eb..2b57052 100644
30996 --- a/arch/x86/lib/thunk_64.S
30997 +++ b/arch/x86/lib/thunk_64.S
30998 @@ -9,6 +9,7 @@
30999 #include <asm/dwarf2.h>
31000 #include <asm/calling.h>
31001 #include <asm/asm.h>
31002 +#include <asm/alternative-asm.h>
31003
31004 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31005 .macro THUNK name, func, put_ret_addr_in_rdi=0
31006 @@ -16,11 +17,11 @@
31007 \name:
31008 CFI_STARTPROC
31009
31010 - /* this one pushes 9 elems, the next one would be %rIP */
31011 - SAVE_ARGS
31012 + /* this one pushes 15+1 elems, the next one would be %rIP */
31013 + SAVE_ARGS 8
31014
31015 .if \put_ret_addr_in_rdi
31016 - movq_cfi_restore 9*8, rdi
31017 + movq_cfi_restore RIP, rdi
31018 .endif
31019
31020 call \func
31021 @@ -47,9 +48,10 @@
31022
31023 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31024 CFI_STARTPROC
31025 - SAVE_ARGS
31026 + SAVE_ARGS 8
31027 restore:
31028 - RESTORE_ARGS
31029 + RESTORE_ARGS 1,8
31030 + pax_force_retaddr
31031 ret
31032 CFI_ENDPROC
31033 _ASM_NOKPROBE(restore)
31034 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31035 index e2f5e21..4b22130 100644
31036 --- a/arch/x86/lib/usercopy_32.c
31037 +++ b/arch/x86/lib/usercopy_32.c
31038 @@ -42,11 +42,13 @@ do { \
31039 int __d0; \
31040 might_fault(); \
31041 __asm__ __volatile__( \
31042 + __COPYUSER_SET_ES \
31043 ASM_STAC "\n" \
31044 "0: rep; stosl\n" \
31045 " movl %2,%0\n" \
31046 "1: rep; stosb\n" \
31047 "2: " ASM_CLAC "\n" \
31048 + __COPYUSER_RESTORE_ES \
31049 ".section .fixup,\"ax\"\n" \
31050 "3: lea 0(%2,%0,4),%0\n" \
31051 " jmp 2b\n" \
31052 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31053
31054 #ifdef CONFIG_X86_INTEL_USERCOPY
31055 static unsigned long
31056 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31057 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31058 {
31059 int d0, d1;
31060 __asm__ __volatile__(
31061 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31062 " .align 2,0x90\n"
31063 "3: movl 0(%4), %%eax\n"
31064 "4: movl 4(%4), %%edx\n"
31065 - "5: movl %%eax, 0(%3)\n"
31066 - "6: movl %%edx, 4(%3)\n"
31067 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31068 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31069 "7: movl 8(%4), %%eax\n"
31070 "8: movl 12(%4),%%edx\n"
31071 - "9: movl %%eax, 8(%3)\n"
31072 - "10: movl %%edx, 12(%3)\n"
31073 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31074 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31075 "11: movl 16(%4), %%eax\n"
31076 "12: movl 20(%4), %%edx\n"
31077 - "13: movl %%eax, 16(%3)\n"
31078 - "14: movl %%edx, 20(%3)\n"
31079 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31080 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31081 "15: movl 24(%4), %%eax\n"
31082 "16: movl 28(%4), %%edx\n"
31083 - "17: movl %%eax, 24(%3)\n"
31084 - "18: movl %%edx, 28(%3)\n"
31085 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31086 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31087 "19: movl 32(%4), %%eax\n"
31088 "20: movl 36(%4), %%edx\n"
31089 - "21: movl %%eax, 32(%3)\n"
31090 - "22: movl %%edx, 36(%3)\n"
31091 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31092 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31093 "23: movl 40(%4), %%eax\n"
31094 "24: movl 44(%4), %%edx\n"
31095 - "25: movl %%eax, 40(%3)\n"
31096 - "26: movl %%edx, 44(%3)\n"
31097 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31098 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31099 "27: movl 48(%4), %%eax\n"
31100 "28: movl 52(%4), %%edx\n"
31101 - "29: movl %%eax, 48(%3)\n"
31102 - "30: movl %%edx, 52(%3)\n"
31103 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31104 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31105 "31: movl 56(%4), %%eax\n"
31106 "32: movl 60(%4), %%edx\n"
31107 - "33: movl %%eax, 56(%3)\n"
31108 - "34: movl %%edx, 60(%3)\n"
31109 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31110 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31111 " addl $-64, %0\n"
31112 " addl $64, %4\n"
31113 " addl $64, %3\n"
31114 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31115 " shrl $2, %0\n"
31116 " andl $3, %%eax\n"
31117 " cld\n"
31118 + __COPYUSER_SET_ES
31119 "99: rep; movsl\n"
31120 "36: movl %%eax, %0\n"
31121 "37: rep; movsb\n"
31122 "100:\n"
31123 + __COPYUSER_RESTORE_ES
31124 + ".section .fixup,\"ax\"\n"
31125 + "101: lea 0(%%eax,%0,4),%0\n"
31126 + " jmp 100b\n"
31127 + ".previous\n"
31128 + _ASM_EXTABLE(1b,100b)
31129 + _ASM_EXTABLE(2b,100b)
31130 + _ASM_EXTABLE(3b,100b)
31131 + _ASM_EXTABLE(4b,100b)
31132 + _ASM_EXTABLE(5b,100b)
31133 + _ASM_EXTABLE(6b,100b)
31134 + _ASM_EXTABLE(7b,100b)
31135 + _ASM_EXTABLE(8b,100b)
31136 + _ASM_EXTABLE(9b,100b)
31137 + _ASM_EXTABLE(10b,100b)
31138 + _ASM_EXTABLE(11b,100b)
31139 + _ASM_EXTABLE(12b,100b)
31140 + _ASM_EXTABLE(13b,100b)
31141 + _ASM_EXTABLE(14b,100b)
31142 + _ASM_EXTABLE(15b,100b)
31143 + _ASM_EXTABLE(16b,100b)
31144 + _ASM_EXTABLE(17b,100b)
31145 + _ASM_EXTABLE(18b,100b)
31146 + _ASM_EXTABLE(19b,100b)
31147 + _ASM_EXTABLE(20b,100b)
31148 + _ASM_EXTABLE(21b,100b)
31149 + _ASM_EXTABLE(22b,100b)
31150 + _ASM_EXTABLE(23b,100b)
31151 + _ASM_EXTABLE(24b,100b)
31152 + _ASM_EXTABLE(25b,100b)
31153 + _ASM_EXTABLE(26b,100b)
31154 + _ASM_EXTABLE(27b,100b)
31155 + _ASM_EXTABLE(28b,100b)
31156 + _ASM_EXTABLE(29b,100b)
31157 + _ASM_EXTABLE(30b,100b)
31158 + _ASM_EXTABLE(31b,100b)
31159 + _ASM_EXTABLE(32b,100b)
31160 + _ASM_EXTABLE(33b,100b)
31161 + _ASM_EXTABLE(34b,100b)
31162 + _ASM_EXTABLE(35b,100b)
31163 + _ASM_EXTABLE(36b,100b)
31164 + _ASM_EXTABLE(37b,100b)
31165 + _ASM_EXTABLE(99b,101b)
31166 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31167 + : "1"(to), "2"(from), "0"(size)
31168 + : "eax", "edx", "memory");
31169 + return size;
31170 +}
31171 +
31172 +static unsigned long
31173 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31174 +{
31175 + int d0, d1;
31176 + __asm__ __volatile__(
31177 + " .align 2,0x90\n"
31178 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31179 + " cmpl $67, %0\n"
31180 + " jbe 3f\n"
31181 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31182 + " .align 2,0x90\n"
31183 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31184 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31185 + "5: movl %%eax, 0(%3)\n"
31186 + "6: movl %%edx, 4(%3)\n"
31187 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31188 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31189 + "9: movl %%eax, 8(%3)\n"
31190 + "10: movl %%edx, 12(%3)\n"
31191 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31192 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31193 + "13: movl %%eax, 16(%3)\n"
31194 + "14: movl %%edx, 20(%3)\n"
31195 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31196 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31197 + "17: movl %%eax, 24(%3)\n"
31198 + "18: movl %%edx, 28(%3)\n"
31199 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31200 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31201 + "21: movl %%eax, 32(%3)\n"
31202 + "22: movl %%edx, 36(%3)\n"
31203 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31204 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31205 + "25: movl %%eax, 40(%3)\n"
31206 + "26: movl %%edx, 44(%3)\n"
31207 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31208 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31209 + "29: movl %%eax, 48(%3)\n"
31210 + "30: movl %%edx, 52(%3)\n"
31211 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31212 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31213 + "33: movl %%eax, 56(%3)\n"
31214 + "34: movl %%edx, 60(%3)\n"
31215 + " addl $-64, %0\n"
31216 + " addl $64, %4\n"
31217 + " addl $64, %3\n"
31218 + " cmpl $63, %0\n"
31219 + " ja 1b\n"
31220 + "35: movl %0, %%eax\n"
31221 + " shrl $2, %0\n"
31222 + " andl $3, %%eax\n"
31223 + " cld\n"
31224 + "99: rep; "__copyuser_seg" movsl\n"
31225 + "36: movl %%eax, %0\n"
31226 + "37: rep; "__copyuser_seg" movsb\n"
31227 + "100:\n"
31228 ".section .fixup,\"ax\"\n"
31229 "101: lea 0(%%eax,%0,4),%0\n"
31230 " jmp 100b\n"
31231 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31232 int d0, d1;
31233 __asm__ __volatile__(
31234 " .align 2,0x90\n"
31235 - "0: movl 32(%4), %%eax\n"
31236 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31237 " cmpl $67, %0\n"
31238 " jbe 2f\n"
31239 - "1: movl 64(%4), %%eax\n"
31240 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31241 " .align 2,0x90\n"
31242 - "2: movl 0(%4), %%eax\n"
31243 - "21: movl 4(%4), %%edx\n"
31244 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31245 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31246 " movl %%eax, 0(%3)\n"
31247 " movl %%edx, 4(%3)\n"
31248 - "3: movl 8(%4), %%eax\n"
31249 - "31: movl 12(%4),%%edx\n"
31250 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31251 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31252 " movl %%eax, 8(%3)\n"
31253 " movl %%edx, 12(%3)\n"
31254 - "4: movl 16(%4), %%eax\n"
31255 - "41: movl 20(%4), %%edx\n"
31256 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31257 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31258 " movl %%eax, 16(%3)\n"
31259 " movl %%edx, 20(%3)\n"
31260 - "10: movl 24(%4), %%eax\n"
31261 - "51: movl 28(%4), %%edx\n"
31262 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31263 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31264 " movl %%eax, 24(%3)\n"
31265 " movl %%edx, 28(%3)\n"
31266 - "11: movl 32(%4), %%eax\n"
31267 - "61: movl 36(%4), %%edx\n"
31268 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31269 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31270 " movl %%eax, 32(%3)\n"
31271 " movl %%edx, 36(%3)\n"
31272 - "12: movl 40(%4), %%eax\n"
31273 - "71: movl 44(%4), %%edx\n"
31274 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31275 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31276 " movl %%eax, 40(%3)\n"
31277 " movl %%edx, 44(%3)\n"
31278 - "13: movl 48(%4), %%eax\n"
31279 - "81: movl 52(%4), %%edx\n"
31280 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31281 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31282 " movl %%eax, 48(%3)\n"
31283 " movl %%edx, 52(%3)\n"
31284 - "14: movl 56(%4), %%eax\n"
31285 - "91: movl 60(%4), %%edx\n"
31286 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31287 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31288 " movl %%eax, 56(%3)\n"
31289 " movl %%edx, 60(%3)\n"
31290 " addl $-64, %0\n"
31291 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31292 " shrl $2, %0\n"
31293 " andl $3, %%eax\n"
31294 " cld\n"
31295 - "6: rep; movsl\n"
31296 + "6: rep; "__copyuser_seg" movsl\n"
31297 " movl %%eax,%0\n"
31298 - "7: rep; movsb\n"
31299 + "7: rep; "__copyuser_seg" movsb\n"
31300 "8:\n"
31301 ".section .fixup,\"ax\"\n"
31302 "9: lea 0(%%eax,%0,4),%0\n"
31303 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31304
31305 __asm__ __volatile__(
31306 " .align 2,0x90\n"
31307 - "0: movl 32(%4), %%eax\n"
31308 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31309 " cmpl $67, %0\n"
31310 " jbe 2f\n"
31311 - "1: movl 64(%4), %%eax\n"
31312 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31313 " .align 2,0x90\n"
31314 - "2: movl 0(%4), %%eax\n"
31315 - "21: movl 4(%4), %%edx\n"
31316 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31317 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31318 " movnti %%eax, 0(%3)\n"
31319 " movnti %%edx, 4(%3)\n"
31320 - "3: movl 8(%4), %%eax\n"
31321 - "31: movl 12(%4),%%edx\n"
31322 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31323 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31324 " movnti %%eax, 8(%3)\n"
31325 " movnti %%edx, 12(%3)\n"
31326 - "4: movl 16(%4), %%eax\n"
31327 - "41: movl 20(%4), %%edx\n"
31328 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31329 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31330 " movnti %%eax, 16(%3)\n"
31331 " movnti %%edx, 20(%3)\n"
31332 - "10: movl 24(%4), %%eax\n"
31333 - "51: movl 28(%4), %%edx\n"
31334 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31335 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31336 " movnti %%eax, 24(%3)\n"
31337 " movnti %%edx, 28(%3)\n"
31338 - "11: movl 32(%4), %%eax\n"
31339 - "61: movl 36(%4), %%edx\n"
31340 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31341 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31342 " movnti %%eax, 32(%3)\n"
31343 " movnti %%edx, 36(%3)\n"
31344 - "12: movl 40(%4), %%eax\n"
31345 - "71: movl 44(%4), %%edx\n"
31346 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31347 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31348 " movnti %%eax, 40(%3)\n"
31349 " movnti %%edx, 44(%3)\n"
31350 - "13: movl 48(%4), %%eax\n"
31351 - "81: movl 52(%4), %%edx\n"
31352 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31353 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31354 " movnti %%eax, 48(%3)\n"
31355 " movnti %%edx, 52(%3)\n"
31356 - "14: movl 56(%4), %%eax\n"
31357 - "91: movl 60(%4), %%edx\n"
31358 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31359 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31360 " movnti %%eax, 56(%3)\n"
31361 " movnti %%edx, 60(%3)\n"
31362 " addl $-64, %0\n"
31363 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31364 " shrl $2, %0\n"
31365 " andl $3, %%eax\n"
31366 " cld\n"
31367 - "6: rep; movsl\n"
31368 + "6: rep; "__copyuser_seg" movsl\n"
31369 " movl %%eax,%0\n"
31370 - "7: rep; movsb\n"
31371 + "7: rep; "__copyuser_seg" movsb\n"
31372 "8:\n"
31373 ".section .fixup,\"ax\"\n"
31374 "9: lea 0(%%eax,%0,4),%0\n"
31375 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31376
31377 __asm__ __volatile__(
31378 " .align 2,0x90\n"
31379 - "0: movl 32(%4), %%eax\n"
31380 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31381 " cmpl $67, %0\n"
31382 " jbe 2f\n"
31383 - "1: movl 64(%4), %%eax\n"
31384 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31385 " .align 2,0x90\n"
31386 - "2: movl 0(%4), %%eax\n"
31387 - "21: movl 4(%4), %%edx\n"
31388 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31389 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31390 " movnti %%eax, 0(%3)\n"
31391 " movnti %%edx, 4(%3)\n"
31392 - "3: movl 8(%4), %%eax\n"
31393 - "31: movl 12(%4),%%edx\n"
31394 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31395 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31396 " movnti %%eax, 8(%3)\n"
31397 " movnti %%edx, 12(%3)\n"
31398 - "4: movl 16(%4), %%eax\n"
31399 - "41: movl 20(%4), %%edx\n"
31400 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31401 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31402 " movnti %%eax, 16(%3)\n"
31403 " movnti %%edx, 20(%3)\n"
31404 - "10: movl 24(%4), %%eax\n"
31405 - "51: movl 28(%4), %%edx\n"
31406 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31407 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31408 " movnti %%eax, 24(%3)\n"
31409 " movnti %%edx, 28(%3)\n"
31410 - "11: movl 32(%4), %%eax\n"
31411 - "61: movl 36(%4), %%edx\n"
31412 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31413 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31414 " movnti %%eax, 32(%3)\n"
31415 " movnti %%edx, 36(%3)\n"
31416 - "12: movl 40(%4), %%eax\n"
31417 - "71: movl 44(%4), %%edx\n"
31418 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31419 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31420 " movnti %%eax, 40(%3)\n"
31421 " movnti %%edx, 44(%3)\n"
31422 - "13: movl 48(%4), %%eax\n"
31423 - "81: movl 52(%4), %%edx\n"
31424 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31425 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31426 " movnti %%eax, 48(%3)\n"
31427 " movnti %%edx, 52(%3)\n"
31428 - "14: movl 56(%4), %%eax\n"
31429 - "91: movl 60(%4), %%edx\n"
31430 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31431 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31432 " movnti %%eax, 56(%3)\n"
31433 " movnti %%edx, 60(%3)\n"
31434 " addl $-64, %0\n"
31435 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31436 " shrl $2, %0\n"
31437 " andl $3, %%eax\n"
31438 " cld\n"
31439 - "6: rep; movsl\n"
31440 + "6: rep; "__copyuser_seg" movsl\n"
31441 " movl %%eax,%0\n"
31442 - "7: rep; movsb\n"
31443 + "7: rep; "__copyuser_seg" movsb\n"
31444 "8:\n"
31445 ".section .fixup,\"ax\"\n"
31446 "9: lea 0(%%eax,%0,4),%0\n"
31447 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31448 */
31449 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31450 unsigned long size);
31451 -unsigned long __copy_user_intel(void __user *to, const void *from,
31452 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31453 + unsigned long size);
31454 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31455 unsigned long size);
31456 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31457 const void __user *from, unsigned long size);
31458 #endif /* CONFIG_X86_INTEL_USERCOPY */
31459
31460 /* Generic arbitrary sized copy. */
31461 -#define __copy_user(to, from, size) \
31462 +#define __copy_user(to, from, size, prefix, set, restore) \
31463 do { \
31464 int __d0, __d1, __d2; \
31465 __asm__ __volatile__( \
31466 + set \
31467 " cmp $7,%0\n" \
31468 " jbe 1f\n" \
31469 " movl %1,%0\n" \
31470 " negl %0\n" \
31471 " andl $7,%0\n" \
31472 " subl %0,%3\n" \
31473 - "4: rep; movsb\n" \
31474 + "4: rep; "prefix"movsb\n" \
31475 " movl %3,%0\n" \
31476 " shrl $2,%0\n" \
31477 " andl $3,%3\n" \
31478 " .align 2,0x90\n" \
31479 - "0: rep; movsl\n" \
31480 + "0: rep; "prefix"movsl\n" \
31481 " movl %3,%0\n" \
31482 - "1: rep; movsb\n" \
31483 + "1: rep; "prefix"movsb\n" \
31484 "2:\n" \
31485 + restore \
31486 ".section .fixup,\"ax\"\n" \
31487 "5: addl %3,%0\n" \
31488 " jmp 2b\n" \
31489 @@ -538,14 +650,14 @@ do { \
31490 " negl %0\n" \
31491 " andl $7,%0\n" \
31492 " subl %0,%3\n" \
31493 - "4: rep; movsb\n" \
31494 + "4: rep; "__copyuser_seg"movsb\n" \
31495 " movl %3,%0\n" \
31496 " shrl $2,%0\n" \
31497 " andl $3,%3\n" \
31498 " .align 2,0x90\n" \
31499 - "0: rep; movsl\n" \
31500 + "0: rep; "__copyuser_seg"movsl\n" \
31501 " movl %3,%0\n" \
31502 - "1: rep; movsb\n" \
31503 + "1: rep; "__copyuser_seg"movsb\n" \
31504 "2:\n" \
31505 ".section .fixup,\"ax\"\n" \
31506 "5: addl %3,%0\n" \
31507 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31508 {
31509 stac();
31510 if (movsl_is_ok(to, from, n))
31511 - __copy_user(to, from, n);
31512 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31513 else
31514 - n = __copy_user_intel(to, from, n);
31515 + n = __generic_copy_to_user_intel(to, from, n);
31516 clac();
31517 return n;
31518 }
31519 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31520 {
31521 stac();
31522 if (movsl_is_ok(to, from, n))
31523 - __copy_user(to, from, n);
31524 + __copy_user(to, from, n, __copyuser_seg, "", "");
31525 else
31526 - n = __copy_user_intel((void __user *)to,
31527 - (const void *)from, n);
31528 + n = __generic_copy_from_user_intel(to, from, n);
31529 clac();
31530 return n;
31531 }
31532 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31533 if (n > 64 && cpu_has_xmm2)
31534 n = __copy_user_intel_nocache(to, from, n);
31535 else
31536 - __copy_user(to, from, n);
31537 + __copy_user(to, from, n, __copyuser_seg, "", "");
31538 #else
31539 - __copy_user(to, from, n);
31540 + __copy_user(to, from, n, __copyuser_seg, "", "");
31541 #endif
31542 clac();
31543 return n;
31544 }
31545 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31546
31547 -/**
31548 - * copy_to_user: - Copy a block of data into user space.
31549 - * @to: Destination address, in user space.
31550 - * @from: Source address, in kernel space.
31551 - * @n: Number of bytes to copy.
31552 - *
31553 - * Context: User context only. This function may sleep.
31554 - *
31555 - * Copy data from kernel space to user space.
31556 - *
31557 - * Returns number of bytes that could not be copied.
31558 - * On success, this will be zero.
31559 - */
31560 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31562 +void __set_fs(mm_segment_t x)
31563 {
31564 - if (access_ok(VERIFY_WRITE, to, n))
31565 - n = __copy_to_user(to, from, n);
31566 - return n;
31567 + switch (x.seg) {
31568 + case 0:
31569 + loadsegment(gs, 0);
31570 + break;
31571 + case TASK_SIZE_MAX:
31572 + loadsegment(gs, __USER_DS);
31573 + break;
31574 + case -1UL:
31575 + loadsegment(gs, __KERNEL_DS);
31576 + break;
31577 + default:
31578 + BUG();
31579 + }
31580 }
31581 -EXPORT_SYMBOL(_copy_to_user);
31582 +EXPORT_SYMBOL(__set_fs);
31583
31584 -/**
31585 - * copy_from_user: - Copy a block of data from user space.
31586 - * @to: Destination address, in kernel space.
31587 - * @from: Source address, in user space.
31588 - * @n: Number of bytes to copy.
31589 - *
31590 - * Context: User context only. This function may sleep.
31591 - *
31592 - * Copy data from user space to kernel space.
31593 - *
31594 - * Returns number of bytes that could not be copied.
31595 - * On success, this will be zero.
31596 - *
31597 - * If some data could not be copied, this function will pad the copied
31598 - * data to the requested size using zero bytes.
31599 - */
31600 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31601 +void set_fs(mm_segment_t x)
31602 {
31603 - if (access_ok(VERIFY_READ, from, n))
31604 - n = __copy_from_user(to, from, n);
31605 - else
31606 - memset(to, 0, n);
31607 - return n;
31608 + current_thread_info()->addr_limit = x;
31609 + __set_fs(x);
31610 }
31611 -EXPORT_SYMBOL(_copy_from_user);
31612 +EXPORT_SYMBOL(set_fs);
31613 +#endif
31614 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31615 index c905e89..01ab928 100644
31616 --- a/arch/x86/lib/usercopy_64.c
31617 +++ b/arch/x86/lib/usercopy_64.c
31618 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31619 might_fault();
31620 /* no memory constraint because it doesn't change any memory gcc knows
31621 about */
31622 + pax_open_userland();
31623 stac();
31624 asm volatile(
31625 " testq %[size8],%[size8]\n"
31626 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31627 _ASM_EXTABLE(0b,3b)
31628 _ASM_EXTABLE(1b,2b)
31629 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31630 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31631 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31632 [zero] "r" (0UL), [eight] "r" (8UL));
31633 clac();
31634 + pax_close_userland();
31635 return size;
31636 }
31637 EXPORT_SYMBOL(__clear_user);
31638 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31639 }
31640 EXPORT_SYMBOL(clear_user);
31641
31642 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31643 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31644 {
31645 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31646 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31647 - }
31648 - return len;
31649 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31650 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31651 + return len;
31652 }
31653 EXPORT_SYMBOL(copy_in_user);
31654
31655 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31656 * it is not necessary to optimize tail handling.
31657 */
31658 __visible unsigned long
31659 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31660 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31661 {
31662 char c;
31663 unsigned zero_len;
31664
31665 + clac();
31666 + pax_close_userland();
31667 for (; len; --len, to++) {
31668 if (__get_user_nocheck(c, from++, sizeof(char)))
31669 break;
31670 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31671 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31672 if (__put_user_nocheck(c, to++, sizeof(char)))
31673 break;
31674 - clac();
31675 return len;
31676 }
31677 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31678 index 6a19ad9..1c48f9a 100644
31679 --- a/arch/x86/mm/Makefile
31680 +++ b/arch/x86/mm/Makefile
31681 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31682 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31683
31684 obj-$(CONFIG_MEMTEST) += memtest.o
31685 +
31686 +quote:="
31687 +obj-$(CONFIG_X86_64) += uderef_64.o
31688 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31689 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31690 index 903ec1e..c4166b2 100644
31691 --- a/arch/x86/mm/extable.c
31692 +++ b/arch/x86/mm/extable.c
31693 @@ -6,12 +6,24 @@
31694 static inline unsigned long
31695 ex_insn_addr(const struct exception_table_entry *x)
31696 {
31697 - return (unsigned long)&x->insn + x->insn;
31698 + unsigned long reloc = 0;
31699 +
31700 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31701 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31702 +#endif
31703 +
31704 + return (unsigned long)&x->insn + x->insn + reloc;
31705 }
31706 static inline unsigned long
31707 ex_fixup_addr(const struct exception_table_entry *x)
31708 {
31709 - return (unsigned long)&x->fixup + x->fixup;
31710 + unsigned long reloc = 0;
31711 +
31712 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31713 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31714 +#endif
31715 +
31716 + return (unsigned long)&x->fixup + x->fixup + reloc;
31717 }
31718
31719 int fixup_exception(struct pt_regs *regs)
31720 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31721 unsigned long new_ip;
31722
31723 #ifdef CONFIG_PNPBIOS
31724 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31725 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31726 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31727 extern u32 pnp_bios_is_utter_crap;
31728 pnp_bios_is_utter_crap = 1;
31729 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31730 i += 4;
31731 p->fixup -= i;
31732 i += 4;
31733 +
31734 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31735 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31736 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31737 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31738 +#endif
31739 +
31740 }
31741 }
31742
31743 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31744 index 4d8ee82..ffc1011 100644
31745 --- a/arch/x86/mm/fault.c
31746 +++ b/arch/x86/mm/fault.c
31747 @@ -13,12 +13,19 @@
31748 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31749 #include <linux/prefetch.h> /* prefetchw */
31750 #include <linux/context_tracking.h> /* exception_enter(), ... */
31751 +#include <linux/unistd.h>
31752 +#include <linux/compiler.h>
31753
31754 #include <asm/traps.h> /* dotraplinkage, ... */
31755 #include <asm/pgalloc.h> /* pgd_*(), ... */
31756 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31757 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31758 #include <asm/vsyscall.h> /* emulate_vsyscall */
31759 +#include <asm/tlbflush.h>
31760 +
31761 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31762 +#include <asm/stacktrace.h>
31763 +#endif
31764
31765 #define CREATE_TRACE_POINTS
31766 #include <asm/trace/exceptions.h>
31767 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31768 int ret = 0;
31769
31770 /* kprobe_running() needs smp_processor_id() */
31771 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31772 + if (kprobes_built_in() && !user_mode(regs)) {
31773 preempt_disable();
31774 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31775 ret = 1;
31776 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31777 return !instr_lo || (instr_lo>>1) == 1;
31778 case 0x00:
31779 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31780 - if (probe_kernel_address(instr, opcode))
31781 + if (user_mode(regs)) {
31782 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31783 + return 0;
31784 + } else if (probe_kernel_address(instr, opcode))
31785 return 0;
31786
31787 *prefetch = (instr_lo == 0xF) &&
31788 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31789 while (instr < max_instr) {
31790 unsigned char opcode;
31791
31792 - if (probe_kernel_address(instr, opcode))
31793 + if (user_mode(regs)) {
31794 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31795 + break;
31796 + } else if (probe_kernel_address(instr, opcode))
31797 break;
31798
31799 instr++;
31800 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31801 force_sig_info(si_signo, &info, tsk);
31802 }
31803
31804 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31805 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31806 +#endif
31807 +
31808 +#ifdef CONFIG_PAX_EMUTRAMP
31809 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31810 +#endif
31811 +
31812 +#ifdef CONFIG_PAX_PAGEEXEC
31813 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31814 +{
31815 + pgd_t *pgd;
31816 + pud_t *pud;
31817 + pmd_t *pmd;
31818 +
31819 + pgd = pgd_offset(mm, address);
31820 + if (!pgd_present(*pgd))
31821 + return NULL;
31822 + pud = pud_offset(pgd, address);
31823 + if (!pud_present(*pud))
31824 + return NULL;
31825 + pmd = pmd_offset(pud, address);
31826 + if (!pmd_present(*pmd))
31827 + return NULL;
31828 + return pmd;
31829 +}
31830 +#endif
31831 +
31832 DEFINE_SPINLOCK(pgd_lock);
31833 LIST_HEAD(pgd_list);
31834
31835 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31836 for (address = VMALLOC_START & PMD_MASK;
31837 address >= TASK_SIZE && address < FIXADDR_TOP;
31838 address += PMD_SIZE) {
31839 +
31840 +#ifdef CONFIG_PAX_PER_CPU_PGD
31841 + unsigned long cpu;
31842 +#else
31843 struct page *page;
31844 +#endif
31845
31846 spin_lock(&pgd_lock);
31847 +
31848 +#ifdef CONFIG_PAX_PER_CPU_PGD
31849 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31850 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31851 + pmd_t *ret;
31852 +
31853 + ret = vmalloc_sync_one(pgd, address);
31854 + if (!ret)
31855 + break;
31856 + pgd = get_cpu_pgd(cpu, kernel);
31857 +#else
31858 list_for_each_entry(page, &pgd_list, lru) {
31859 + pgd_t *pgd;
31860 spinlock_t *pgt_lock;
31861 pmd_t *ret;
31862
31863 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31864 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31865
31866 spin_lock(pgt_lock);
31867 - ret = vmalloc_sync_one(page_address(page), address);
31868 + pgd = page_address(page);
31869 +#endif
31870 +
31871 + ret = vmalloc_sync_one(pgd, address);
31872 +
31873 +#ifndef CONFIG_PAX_PER_CPU_PGD
31874 spin_unlock(pgt_lock);
31875 +#endif
31876
31877 if (!ret)
31878 break;
31879 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31880 * an interrupt in the middle of a task switch..
31881 */
31882 pgd_paddr = read_cr3();
31883 +
31884 +#ifdef CONFIG_PAX_PER_CPU_PGD
31885 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31886 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31887 +#endif
31888 +
31889 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31890 if (!pmd_k)
31891 return -1;
31892 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31893 * happen within a race in page table update. In the later
31894 * case just flush:
31895 */
31896 - pgd = pgd_offset(current->active_mm, address);
31897 +
31898 pgd_ref = pgd_offset_k(address);
31899 if (pgd_none(*pgd_ref))
31900 return -1;
31901
31902 +#ifdef CONFIG_PAX_PER_CPU_PGD
31903 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31904 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31905 + if (pgd_none(*pgd)) {
31906 + set_pgd(pgd, *pgd_ref);
31907 + arch_flush_lazy_mmu_mode();
31908 + } else {
31909 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31910 + }
31911 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31912 +#else
31913 + pgd = pgd_offset(current->active_mm, address);
31914 +#endif
31915 +
31916 if (pgd_none(*pgd)) {
31917 set_pgd(pgd, *pgd_ref);
31918 arch_flush_lazy_mmu_mode();
31919 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31920 static int is_errata100(struct pt_regs *regs, unsigned long address)
31921 {
31922 #ifdef CONFIG_X86_64
31923 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31924 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31925 return 1;
31926 #endif
31927 return 0;
31928 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31929 }
31930
31931 static const char nx_warning[] = KERN_CRIT
31932 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31933 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31934 static const char smep_warning[] = KERN_CRIT
31935 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
31936 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31937
31938 static void
31939 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31940 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31941 if (!oops_may_print())
31942 return;
31943
31944 - if (error_code & PF_INSTR) {
31945 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31946 unsigned int level;
31947 pgd_t *pgd;
31948 pte_t *pte;
31949 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31950 pte = lookup_address_in_pgd(pgd, address, &level);
31951
31952 if (pte && pte_present(*pte) && !pte_exec(*pte))
31953 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31954 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31955 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31956 (pgd_flags(*pgd) & _PAGE_USER) &&
31957 (read_cr4() & X86_CR4_SMEP))
31958 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31959 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31960 }
31961
31962 +#ifdef CONFIG_PAX_KERNEXEC
31963 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31964 + if (current->signal->curr_ip)
31965 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31966 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31967 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31968 + else
31969 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31970 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31971 + }
31972 +#endif
31973 +
31974 printk(KERN_ALERT "BUG: unable to handle kernel ");
31975 if (address < PAGE_SIZE)
31976 printk(KERN_CONT "NULL pointer dereference");
31977 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31978 return;
31979 }
31980 #endif
31981 +
31982 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31983 + if (pax_is_fetch_fault(regs, error_code, address)) {
31984 +
31985 +#ifdef CONFIG_PAX_EMUTRAMP
31986 + switch (pax_handle_fetch_fault(regs)) {
31987 + case 2:
31988 + return;
31989 + }
31990 +#endif
31991 +
31992 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31993 + do_group_exit(SIGKILL);
31994 + }
31995 +#endif
31996 +
31997 /* Kernel addresses are always protection faults: */
31998 if (address >= TASK_SIZE)
31999 error_code |= PF_PROT;
32000 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32001 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32002 printk(KERN_ERR
32003 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32004 - tsk->comm, tsk->pid, address);
32005 + tsk->comm, task_pid_nr(tsk), address);
32006 code = BUS_MCEERR_AR;
32007 }
32008 #endif
32009 @@ -916,6 +1028,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32010 return 1;
32011 }
32012
32013 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32014 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32015 +{
32016 + pte_t *pte;
32017 + pmd_t *pmd;
32018 + spinlock_t *ptl;
32019 + unsigned char pte_mask;
32020 +
32021 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32022 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32023 + return 0;
32024 +
32025 + /* PaX: it's our fault, let's handle it if we can */
32026 +
32027 + /* PaX: take a look at read faults before acquiring any locks */
32028 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32029 + /* instruction fetch attempt from a protected page in user mode */
32030 + up_read(&mm->mmap_sem);
32031 +
32032 +#ifdef CONFIG_PAX_EMUTRAMP
32033 + switch (pax_handle_fetch_fault(regs)) {
32034 + case 2:
32035 + return 1;
32036 + }
32037 +#endif
32038 +
32039 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32040 + do_group_exit(SIGKILL);
32041 + }
32042 +
32043 + pmd = pax_get_pmd(mm, address);
32044 + if (unlikely(!pmd))
32045 + return 0;
32046 +
32047 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32048 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32049 + pte_unmap_unlock(pte, ptl);
32050 + return 0;
32051 + }
32052 +
32053 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32054 + /* write attempt to a protected page in user mode */
32055 + pte_unmap_unlock(pte, ptl);
32056 + return 0;
32057 + }
32058 +
32059 +#ifdef CONFIG_SMP
32060 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32061 +#else
32062 + if (likely(address > get_limit(regs->cs)))
32063 +#endif
32064 + {
32065 + set_pte(pte, pte_mkread(*pte));
32066 + __flush_tlb_one(address);
32067 + pte_unmap_unlock(pte, ptl);
32068 + up_read(&mm->mmap_sem);
32069 + return 1;
32070 + }
32071 +
32072 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32073 +
32074 + /*
32075 + * PaX: fill DTLB with user rights and retry
32076 + */
32077 + __asm__ __volatile__ (
32078 + "orb %2,(%1)\n"
32079 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32080 +/*
32081 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32082 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32083 + * page fault when examined during a TLB load attempt. this is true not only
32084 + * for PTEs holding a non-present entry but also present entries that will
32085 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32086 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32087 + * for our target pages since their PTEs are simply not in the TLBs at all.
32088 +
32089 + * the best thing in omitting it is that we gain around 15-20% speed in the
32090 + * fast path of the page fault handler and can get rid of tracing since we
32091 + * can no longer flush unintended entries.
32092 + */
32093 + "invlpg (%0)\n"
32094 +#endif
32095 + __copyuser_seg"testb $0,(%0)\n"
32096 + "xorb %3,(%1)\n"
32097 + :
32098 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32099 + : "memory", "cc");
32100 + pte_unmap_unlock(pte, ptl);
32101 + up_read(&mm->mmap_sem);
32102 + return 1;
32103 +}
32104 +#endif
32105 +
32106 /*
32107 * Handle a spurious fault caused by a stale TLB entry.
32108 *
32109 @@ -1001,6 +1206,9 @@ int show_unhandled_signals = 1;
32110 static inline int
32111 access_error(unsigned long error_code, struct vm_area_struct *vma)
32112 {
32113 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32114 + return 1;
32115 +
32116 if (error_code & PF_WRITE) {
32117 /* write, present and write, not present: */
32118 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32119 @@ -1035,7 +1243,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32120 if (error_code & PF_USER)
32121 return false;
32122
32123 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32124 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32125 return false;
32126
32127 return true;
32128 @@ -1063,6 +1271,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32129 tsk = current;
32130 mm = tsk->mm;
32131
32132 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32133 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32134 + if (!search_exception_tables(regs->ip)) {
32135 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32136 + bad_area_nosemaphore(regs, error_code, address);
32137 + return;
32138 + }
32139 + if (address < pax_user_shadow_base) {
32140 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32141 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32142 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32143 + } else
32144 + address -= pax_user_shadow_base;
32145 + }
32146 +#endif
32147 +
32148 /*
32149 * Detect and handle instructions that would cause a page fault for
32150 * both a tracked kernel page and a userspace page.
32151 @@ -1140,7 +1364,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32152 * User-mode registers count as a user access even for any
32153 * potential system fault or CPU buglet:
32154 */
32155 - if (user_mode_vm(regs)) {
32156 + if (user_mode(regs)) {
32157 local_irq_enable();
32158 error_code |= PF_USER;
32159 flags |= FAULT_FLAG_USER;
32160 @@ -1187,6 +1411,11 @@ retry:
32161 might_sleep();
32162 }
32163
32164 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32165 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32166 + return;
32167 +#endif
32168 +
32169 vma = find_vma(mm, address);
32170 if (unlikely(!vma)) {
32171 bad_area(regs, error_code, address);
32172 @@ -1198,18 +1427,24 @@ retry:
32173 bad_area(regs, error_code, address);
32174 return;
32175 }
32176 - if (error_code & PF_USER) {
32177 - /*
32178 - * Accessing the stack below %sp is always a bug.
32179 - * The large cushion allows instructions like enter
32180 - * and pusha to work. ("enter $65535, $31" pushes
32181 - * 32 pointers and then decrements %sp by 65535.)
32182 - */
32183 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32184 - bad_area(regs, error_code, address);
32185 - return;
32186 - }
32187 + /*
32188 + * Accessing the stack below %sp is always a bug.
32189 + * The large cushion allows instructions like enter
32190 + * and pusha to work. ("enter $65535, $31" pushes
32191 + * 32 pointers and then decrements %sp by 65535.)
32192 + */
32193 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32194 + bad_area(regs, error_code, address);
32195 + return;
32196 }
32197 +
32198 +#ifdef CONFIG_PAX_SEGMEXEC
32199 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32200 + bad_area(regs, error_code, address);
32201 + return;
32202 + }
32203 +#endif
32204 +
32205 if (unlikely(expand_stack(vma, address))) {
32206 bad_area(regs, error_code, address);
32207 return;
32208 @@ -1327,3 +1562,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32209 }
32210 NOKPROBE_SYMBOL(trace_do_page_fault);
32211 #endif /* CONFIG_TRACING */
32212 +
32213 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32214 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32215 +{
32216 + struct mm_struct *mm = current->mm;
32217 + unsigned long ip = regs->ip;
32218 +
32219 + if (v8086_mode(regs))
32220 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32221 +
32222 +#ifdef CONFIG_PAX_PAGEEXEC
32223 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32224 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32225 + return true;
32226 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32227 + return true;
32228 + return false;
32229 + }
32230 +#endif
32231 +
32232 +#ifdef CONFIG_PAX_SEGMEXEC
32233 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32234 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32235 + return true;
32236 + return false;
32237 + }
32238 +#endif
32239 +
32240 + return false;
32241 +}
32242 +#endif
32243 +
32244 +#ifdef CONFIG_PAX_EMUTRAMP
32245 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32246 +{
32247 + int err;
32248 +
32249 + do { /* PaX: libffi trampoline emulation */
32250 + unsigned char mov, jmp;
32251 + unsigned int addr1, addr2;
32252 +
32253 +#ifdef CONFIG_X86_64
32254 + if ((regs->ip + 9) >> 32)
32255 + break;
32256 +#endif
32257 +
32258 + err = get_user(mov, (unsigned char __user *)regs->ip);
32259 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32260 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32261 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32262 +
32263 + if (err)
32264 + break;
32265 +
32266 + if (mov == 0xB8 && jmp == 0xE9) {
32267 + regs->ax = addr1;
32268 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32269 + return 2;
32270 + }
32271 + } while (0);
32272 +
32273 + do { /* PaX: gcc trampoline emulation #1 */
32274 + unsigned char mov1, mov2;
32275 + unsigned short jmp;
32276 + unsigned int addr1, addr2;
32277 +
32278 +#ifdef CONFIG_X86_64
32279 + if ((regs->ip + 11) >> 32)
32280 + break;
32281 +#endif
32282 +
32283 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32284 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32285 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32286 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32287 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32288 +
32289 + if (err)
32290 + break;
32291 +
32292 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32293 + regs->cx = addr1;
32294 + regs->ax = addr2;
32295 + regs->ip = addr2;
32296 + return 2;
32297 + }
32298 + } while (0);
32299 +
32300 + do { /* PaX: gcc trampoline emulation #2 */
32301 + unsigned char mov, jmp;
32302 + unsigned int addr1, addr2;
32303 +
32304 +#ifdef CONFIG_X86_64
32305 + if ((regs->ip + 9) >> 32)
32306 + break;
32307 +#endif
32308 +
32309 + err = get_user(mov, (unsigned char __user *)regs->ip);
32310 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32311 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32312 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32313 +
32314 + if (err)
32315 + break;
32316 +
32317 + if (mov == 0xB9 && jmp == 0xE9) {
32318 + regs->cx = addr1;
32319 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32320 + return 2;
32321 + }
32322 + } while (0);
32323 +
32324 + return 1; /* PaX in action */
32325 +}
32326 +
32327 +#ifdef CONFIG_X86_64
32328 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32329 +{
32330 + int err;
32331 +
32332 + do { /* PaX: libffi trampoline emulation */
32333 + unsigned short mov1, mov2, jmp1;
32334 + unsigned char stcclc, jmp2;
32335 + unsigned long addr1, addr2;
32336 +
32337 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32338 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32339 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32340 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32341 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32342 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32343 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32344 +
32345 + if (err)
32346 + break;
32347 +
32348 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32349 + regs->r11 = addr1;
32350 + regs->r10 = addr2;
32351 + if (stcclc == 0xF8)
32352 + regs->flags &= ~X86_EFLAGS_CF;
32353 + else
32354 + regs->flags |= X86_EFLAGS_CF;
32355 + regs->ip = addr1;
32356 + return 2;
32357 + }
32358 + } while (0);
32359 +
32360 + do { /* PaX: gcc trampoline emulation #1 */
32361 + unsigned short mov1, mov2, jmp1;
32362 + unsigned char jmp2;
32363 + unsigned int addr1;
32364 + unsigned long addr2;
32365 +
32366 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32367 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32368 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32369 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32370 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32371 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32372 +
32373 + if (err)
32374 + break;
32375 +
32376 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32377 + regs->r11 = addr1;
32378 + regs->r10 = addr2;
32379 + regs->ip = addr1;
32380 + return 2;
32381 + }
32382 + } while (0);
32383 +
32384 + do { /* PaX: gcc trampoline emulation #2 */
32385 + unsigned short mov1, mov2, jmp1;
32386 + unsigned char jmp2;
32387 + unsigned long addr1, addr2;
32388 +
32389 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32390 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32391 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32392 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32393 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32394 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32395 +
32396 + if (err)
32397 + break;
32398 +
32399 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32400 + regs->r11 = addr1;
32401 + regs->r10 = addr2;
32402 + regs->ip = addr1;
32403 + return 2;
32404 + }
32405 + } while (0);
32406 +
32407 + return 1; /* PaX in action */
32408 +}
32409 +#endif
32410 +
32411 +/*
32412 + * PaX: decide what to do with offenders (regs->ip = fault address)
32413 + *
32414 + * returns 1 when task should be killed
32415 + * 2 when gcc trampoline was detected
32416 + */
32417 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32418 +{
32419 + if (v8086_mode(regs))
32420 + return 1;
32421 +
32422 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32423 + return 1;
32424 +
32425 +#ifdef CONFIG_X86_32
32426 + return pax_handle_fetch_fault_32(regs);
32427 +#else
32428 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32429 + return pax_handle_fetch_fault_32(regs);
32430 + else
32431 + return pax_handle_fetch_fault_64(regs);
32432 +#endif
32433 +}
32434 +#endif
32435 +
32436 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32437 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32438 +{
32439 + long i;
32440 +
32441 + printk(KERN_ERR "PAX: bytes at PC: ");
32442 + for (i = 0; i < 20; i++) {
32443 + unsigned char c;
32444 + if (get_user(c, (unsigned char __force_user *)pc+i))
32445 + printk(KERN_CONT "?? ");
32446 + else
32447 + printk(KERN_CONT "%02x ", c);
32448 + }
32449 + printk("\n");
32450 +
32451 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32452 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32453 + unsigned long c;
32454 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32455 +#ifdef CONFIG_X86_32
32456 + printk(KERN_CONT "???????? ");
32457 +#else
32458 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32459 + printk(KERN_CONT "???????? ???????? ");
32460 + else
32461 + printk(KERN_CONT "???????????????? ");
32462 +#endif
32463 + } else {
32464 +#ifdef CONFIG_X86_64
32465 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32466 + printk(KERN_CONT "%08x ", (unsigned int)c);
32467 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32468 + } else
32469 +#endif
32470 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32471 + }
32472 + }
32473 + printk("\n");
32474 +}
32475 +#endif
32476 +
32477 +/**
32478 + * probe_kernel_write(): safely attempt to write to a location
32479 + * @dst: address to write to
32480 + * @src: pointer to the data that shall be written
32481 + * @size: size of the data chunk
32482 + *
32483 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32484 + * happens, handle that and return -EFAULT.
32485 + */
32486 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32487 +{
32488 + long ret;
32489 + mm_segment_t old_fs = get_fs();
32490 +
32491 + set_fs(KERNEL_DS);
32492 + pagefault_disable();
32493 + pax_open_kernel();
32494 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32495 + pax_close_kernel();
32496 + pagefault_enable();
32497 + set_fs(old_fs);
32498 +
32499 + return ret ? -EFAULT : 0;
32500 +}
32501 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32502 index 207d9aef..69030980 100644
32503 --- a/arch/x86/mm/gup.c
32504 +++ b/arch/x86/mm/gup.c
32505 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32506 addr = start;
32507 len = (unsigned long) nr_pages << PAGE_SHIFT;
32508 end = start + len;
32509 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32510 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32511 (void __user *)start, len)))
32512 return 0;
32513
32514 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32515 goto slow_irqon;
32516 #endif
32517
32518 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32519 + (void __user *)start, len)))
32520 + return 0;
32521 +
32522 /*
32523 * XXX: batch / limit 'nr', to avoid large irq off latency
32524 * needs some instrumenting to determine the common sizes used by
32525 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32526 index 4500142..53a363c 100644
32527 --- a/arch/x86/mm/highmem_32.c
32528 +++ b/arch/x86/mm/highmem_32.c
32529 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32530 idx = type + KM_TYPE_NR*smp_processor_id();
32531 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32532 BUG_ON(!pte_none(*(kmap_pte-idx)));
32533 +
32534 + pax_open_kernel();
32535 set_pte(kmap_pte-idx, mk_pte(page, prot));
32536 + pax_close_kernel();
32537 +
32538 arch_flush_lazy_mmu_mode();
32539
32540 return (void *)vaddr;
32541 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32542 index 8b977eb..4732c33 100644
32543 --- a/arch/x86/mm/hugetlbpage.c
32544 +++ b/arch/x86/mm/hugetlbpage.c
32545 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32546 #ifdef CONFIG_HUGETLB_PAGE
32547 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32548 unsigned long addr, unsigned long len,
32549 - unsigned long pgoff, unsigned long flags)
32550 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32551 {
32552 struct hstate *h = hstate_file(file);
32553 struct vm_unmapped_area_info info;
32554 -
32555 +
32556 info.flags = 0;
32557 info.length = len;
32558 info.low_limit = current->mm->mmap_legacy_base;
32559 info.high_limit = TASK_SIZE;
32560 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32561 info.align_offset = 0;
32562 + info.threadstack_offset = offset;
32563 return vm_unmapped_area(&info);
32564 }
32565
32566 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32567 unsigned long addr0, unsigned long len,
32568 - unsigned long pgoff, unsigned long flags)
32569 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32570 {
32571 struct hstate *h = hstate_file(file);
32572 struct vm_unmapped_area_info info;
32573 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32574 info.high_limit = current->mm->mmap_base;
32575 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32576 info.align_offset = 0;
32577 + info.threadstack_offset = offset;
32578 addr = vm_unmapped_area(&info);
32579
32580 /*
32581 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32582 VM_BUG_ON(addr != -ENOMEM);
32583 info.flags = 0;
32584 info.low_limit = TASK_UNMAPPED_BASE;
32585 +
32586 +#ifdef CONFIG_PAX_RANDMMAP
32587 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32588 + info.low_limit += current->mm->delta_mmap;
32589 +#endif
32590 +
32591 info.high_limit = TASK_SIZE;
32592 addr = vm_unmapped_area(&info);
32593 }
32594 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32595 struct hstate *h = hstate_file(file);
32596 struct mm_struct *mm = current->mm;
32597 struct vm_area_struct *vma;
32598 + unsigned long pax_task_size = TASK_SIZE;
32599 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32600
32601 if (len & ~huge_page_mask(h))
32602 return -EINVAL;
32603 - if (len > TASK_SIZE)
32604 +
32605 +#ifdef CONFIG_PAX_SEGMEXEC
32606 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32607 + pax_task_size = SEGMEXEC_TASK_SIZE;
32608 +#endif
32609 +
32610 + pax_task_size -= PAGE_SIZE;
32611 +
32612 + if (len > pax_task_size)
32613 return -ENOMEM;
32614
32615 if (flags & MAP_FIXED) {
32616 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32617 return addr;
32618 }
32619
32620 +#ifdef CONFIG_PAX_RANDMMAP
32621 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32622 +#endif
32623 +
32624 if (addr) {
32625 addr = ALIGN(addr, huge_page_size(h));
32626 vma = find_vma(mm, addr);
32627 - if (TASK_SIZE - len >= addr &&
32628 - (!vma || addr + len <= vma->vm_start))
32629 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32630 return addr;
32631 }
32632 if (mm->get_unmapped_area == arch_get_unmapped_area)
32633 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32634 - pgoff, flags);
32635 + pgoff, flags, offset);
32636 else
32637 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32638 - pgoff, flags);
32639 + pgoff, flags, offset);
32640 }
32641 #endif /* CONFIG_HUGETLB_PAGE */
32642
32643 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32644 index 66dba36..f8082ec 100644
32645 --- a/arch/x86/mm/init.c
32646 +++ b/arch/x86/mm/init.c
32647 @@ -4,6 +4,7 @@
32648 #include <linux/swap.h>
32649 #include <linux/memblock.h>
32650 #include <linux/bootmem.h> /* for max_low_pfn */
32651 +#include <linux/tboot.h>
32652
32653 #include <asm/cacheflush.h>
32654 #include <asm/e820.h>
32655 @@ -17,6 +18,8 @@
32656 #include <asm/proto.h>
32657 #include <asm/dma.h> /* for MAX_DMA_PFN */
32658 #include <asm/microcode.h>
32659 +#include <asm/desc.h>
32660 +#include <asm/bios_ebda.h>
32661
32662 /*
32663 * We need to define the tracepoints somewhere, and tlb.c
32664 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32665 early_ioremap_page_table_range_init();
32666 #endif
32667
32668 +#ifdef CONFIG_PAX_PER_CPU_PGD
32669 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32670 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32671 + KERNEL_PGD_PTRS);
32672 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32673 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32674 + KERNEL_PGD_PTRS);
32675 + load_cr3(get_cpu_pgd(0, kernel));
32676 +#else
32677 load_cr3(swapper_pg_dir);
32678 +#endif
32679 +
32680 __flush_tlb_all();
32681
32682 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32683 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32684 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32685 * mmio resources as well as potential bios/acpi data regions.
32686 */
32687 +
32688 +#ifdef CONFIG_GRKERNSEC_KMEM
32689 +static unsigned int ebda_start __read_only;
32690 +static unsigned int ebda_end __read_only;
32691 +#endif
32692 +
32693 int devmem_is_allowed(unsigned long pagenr)
32694 {
32695 - if (pagenr < 256)
32696 +#ifdef CONFIG_GRKERNSEC_KMEM
32697 + /* allow BDA */
32698 + if (!pagenr)
32699 return 1;
32700 + /* allow EBDA */
32701 + if (pagenr >= ebda_start && pagenr < ebda_end)
32702 + return 1;
32703 + /* if tboot is in use, allow access to its hardcoded serial log range */
32704 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32705 + return 1;
32706 +#else
32707 + if (!pagenr)
32708 + return 1;
32709 +#ifdef CONFIG_VM86
32710 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32711 + return 1;
32712 +#endif
32713 +#endif
32714 +
32715 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32716 + return 1;
32717 +#ifdef CONFIG_GRKERNSEC_KMEM
32718 + /* throw out everything else below 1MB */
32719 + if (pagenr <= 256)
32720 + return 0;
32721 +#endif
32722 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32723 return 0;
32724 if (!page_is_ram(pagenr))
32725 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32726 #endif
32727 }
32728
32729 +#ifdef CONFIG_GRKERNSEC_KMEM
32730 +static inline void gr_init_ebda(void)
32731 +{
32732 + unsigned int ebda_addr;
32733 + unsigned int ebda_size = 0;
32734 +
32735 + ebda_addr = get_bios_ebda();
32736 + if (ebda_addr) {
32737 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32738 + ebda_size <<= 10;
32739 + }
32740 + if (ebda_addr && ebda_size) {
32741 + ebda_start = ebda_addr >> PAGE_SHIFT;
32742 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32743 + } else {
32744 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32745 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32746 + }
32747 +}
32748 +#else
32749 +static inline void gr_init_ebda(void) { }
32750 +#endif
32751 +
32752 void free_initmem(void)
32753 {
32754 +#ifdef CONFIG_PAX_KERNEXEC
32755 +#ifdef CONFIG_X86_32
32756 + /* PaX: limit KERNEL_CS to actual size */
32757 + unsigned long addr, limit;
32758 + struct desc_struct d;
32759 + int cpu;
32760 +#else
32761 + pgd_t *pgd;
32762 + pud_t *pud;
32763 + pmd_t *pmd;
32764 + unsigned long addr, end;
32765 +#endif
32766 +#endif
32767 +
32768 + gr_init_ebda();
32769 +
32770 +#ifdef CONFIG_PAX_KERNEXEC
32771 +#ifdef CONFIG_X86_32
32772 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32773 + limit = (limit - 1UL) >> PAGE_SHIFT;
32774 +
32775 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32776 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32777 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32778 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32779 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32780 + }
32781 +
32782 + /* PaX: make KERNEL_CS read-only */
32783 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32784 + if (!paravirt_enabled())
32785 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32786 +/*
32787 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32788 + pgd = pgd_offset_k(addr);
32789 + pud = pud_offset(pgd, addr);
32790 + pmd = pmd_offset(pud, addr);
32791 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32792 + }
32793 +*/
32794 +#ifdef CONFIG_X86_PAE
32795 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32796 +/*
32797 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32798 + pgd = pgd_offset_k(addr);
32799 + pud = pud_offset(pgd, addr);
32800 + pmd = pmd_offset(pud, addr);
32801 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32802 + }
32803 +*/
32804 +#endif
32805 +
32806 +#ifdef CONFIG_MODULES
32807 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32808 +#endif
32809 +
32810 +#else
32811 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32812 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32813 + pgd = pgd_offset_k(addr);
32814 + pud = pud_offset(pgd, addr);
32815 + pmd = pmd_offset(pud, addr);
32816 + if (!pmd_present(*pmd))
32817 + continue;
32818 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32819 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32820 + else
32821 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32822 + }
32823 +
32824 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32825 + end = addr + KERNEL_IMAGE_SIZE;
32826 + for (; addr < end; addr += PMD_SIZE) {
32827 + pgd = pgd_offset_k(addr);
32828 + pud = pud_offset(pgd, addr);
32829 + pmd = pmd_offset(pud, addr);
32830 + if (!pmd_present(*pmd))
32831 + continue;
32832 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32833 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32834 + }
32835 +#endif
32836 +
32837 + flush_tlb_all();
32838 +#endif
32839 +
32840 free_init_pages("unused kernel",
32841 (unsigned long)(&__init_begin),
32842 (unsigned long)(&__init_end));
32843 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32844 index c8140e1..59257fc 100644
32845 --- a/arch/x86/mm/init_32.c
32846 +++ b/arch/x86/mm/init_32.c
32847 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32848 bool __read_mostly __vmalloc_start_set = false;
32849
32850 /*
32851 - * Creates a middle page table and puts a pointer to it in the
32852 - * given global directory entry. This only returns the gd entry
32853 - * in non-PAE compilation mode, since the middle layer is folded.
32854 - */
32855 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32856 -{
32857 - pud_t *pud;
32858 - pmd_t *pmd_table;
32859 -
32860 -#ifdef CONFIG_X86_PAE
32861 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32862 - pmd_table = (pmd_t *)alloc_low_page();
32863 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32864 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32865 - pud = pud_offset(pgd, 0);
32866 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32867 -
32868 - return pmd_table;
32869 - }
32870 -#endif
32871 - pud = pud_offset(pgd, 0);
32872 - pmd_table = pmd_offset(pud, 0);
32873 -
32874 - return pmd_table;
32875 -}
32876 -
32877 -/*
32878 * Create a page table and place a pointer to it in a middle page
32879 * directory entry:
32880 */
32881 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32882 pte_t *page_table = (pte_t *)alloc_low_page();
32883
32884 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32885 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32886 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32887 +#else
32888 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32889 +#endif
32890 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32891 }
32892
32893 return pte_offset_kernel(pmd, 0);
32894 }
32895
32896 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32897 +{
32898 + pud_t *pud;
32899 + pmd_t *pmd_table;
32900 +
32901 + pud = pud_offset(pgd, 0);
32902 + pmd_table = pmd_offset(pud, 0);
32903 +
32904 + return pmd_table;
32905 +}
32906 +
32907 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32908 {
32909 int pgd_idx = pgd_index(vaddr);
32910 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32911 int pgd_idx, pmd_idx;
32912 unsigned long vaddr;
32913 pgd_t *pgd;
32914 + pud_t *pud;
32915 pmd_t *pmd;
32916 pte_t *pte = NULL;
32917 unsigned long count = page_table_range_init_count(start, end);
32918 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32919 pgd = pgd_base + pgd_idx;
32920
32921 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32922 - pmd = one_md_table_init(pgd);
32923 - pmd = pmd + pmd_index(vaddr);
32924 + pud = pud_offset(pgd, vaddr);
32925 + pmd = pmd_offset(pud, vaddr);
32926 +
32927 +#ifdef CONFIG_X86_PAE
32928 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32929 +#endif
32930 +
32931 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32932 pmd++, pmd_idx++) {
32933 pte = page_table_kmap_check(one_page_table_init(pmd),
32934 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32935 }
32936 }
32937
32938 -static inline int is_kernel_text(unsigned long addr)
32939 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32940 {
32941 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32942 - return 1;
32943 - return 0;
32944 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32945 + end <= ktla_ktva((unsigned long)_stext)) &&
32946 + (start >= ktla_ktva((unsigned long)_einittext) ||
32947 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32948 +
32949 +#ifdef CONFIG_ACPI_SLEEP
32950 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32951 +#endif
32952 +
32953 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32954 + return 0;
32955 + return 1;
32956 }
32957
32958 /*
32959 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32960 unsigned long last_map_addr = end;
32961 unsigned long start_pfn, end_pfn;
32962 pgd_t *pgd_base = swapper_pg_dir;
32963 - int pgd_idx, pmd_idx, pte_ofs;
32964 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32965 unsigned long pfn;
32966 pgd_t *pgd;
32967 + pud_t *pud;
32968 pmd_t *pmd;
32969 pte_t *pte;
32970 unsigned pages_2m, pages_4k;
32971 @@ -291,8 +295,13 @@ repeat:
32972 pfn = start_pfn;
32973 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32974 pgd = pgd_base + pgd_idx;
32975 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32976 - pmd = one_md_table_init(pgd);
32977 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32978 + pud = pud_offset(pgd, 0);
32979 + pmd = pmd_offset(pud, 0);
32980 +
32981 +#ifdef CONFIG_X86_PAE
32982 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32983 +#endif
32984
32985 if (pfn >= end_pfn)
32986 continue;
32987 @@ -304,14 +313,13 @@ repeat:
32988 #endif
32989 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32990 pmd++, pmd_idx++) {
32991 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32992 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32993
32994 /*
32995 * Map with big pages if possible, otherwise
32996 * create normal page tables:
32997 */
32998 if (use_pse) {
32999 - unsigned int addr2;
33000 pgprot_t prot = PAGE_KERNEL_LARGE;
33001 /*
33002 * first pass will use the same initial
33003 @@ -322,11 +330,7 @@ repeat:
33004 _PAGE_PSE);
33005
33006 pfn &= PMD_MASK >> PAGE_SHIFT;
33007 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33008 - PAGE_OFFSET + PAGE_SIZE-1;
33009 -
33010 - if (is_kernel_text(addr) ||
33011 - is_kernel_text(addr2))
33012 + if (is_kernel_text(address, address + PMD_SIZE))
33013 prot = PAGE_KERNEL_LARGE_EXEC;
33014
33015 pages_2m++;
33016 @@ -343,7 +347,7 @@ repeat:
33017 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33018 pte += pte_ofs;
33019 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33020 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33021 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33022 pgprot_t prot = PAGE_KERNEL;
33023 /*
33024 * first pass will use the same initial
33025 @@ -351,7 +355,7 @@ repeat:
33026 */
33027 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33028
33029 - if (is_kernel_text(addr))
33030 + if (is_kernel_text(address, address + PAGE_SIZE))
33031 prot = PAGE_KERNEL_EXEC;
33032
33033 pages_4k++;
33034 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33035
33036 pud = pud_offset(pgd, va);
33037 pmd = pmd_offset(pud, va);
33038 - if (!pmd_present(*pmd))
33039 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33040 break;
33041
33042 /* should not be large page here */
33043 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33044
33045 static void __init pagetable_init(void)
33046 {
33047 - pgd_t *pgd_base = swapper_pg_dir;
33048 -
33049 - permanent_kmaps_init(pgd_base);
33050 + permanent_kmaps_init(swapper_pg_dir);
33051 }
33052
33053 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33054 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33055 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33056
33057 /* user-defined highmem size */
33058 @@ -787,10 +789,10 @@ void __init mem_init(void)
33059 ((unsigned long)&__init_end -
33060 (unsigned long)&__init_begin) >> 10,
33061
33062 - (unsigned long)&_etext, (unsigned long)&_edata,
33063 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33064 + (unsigned long)&_sdata, (unsigned long)&_edata,
33065 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33066
33067 - (unsigned long)&_text, (unsigned long)&_etext,
33068 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33069 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33070
33071 /*
33072 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33073 if (!kernel_set_to_readonly)
33074 return;
33075
33076 + start = ktla_ktva(start);
33077 pr_debug("Set kernel text: %lx - %lx for read write\n",
33078 start, start+size);
33079
33080 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33081 if (!kernel_set_to_readonly)
33082 return;
33083
33084 + start = ktla_ktva(start);
33085 pr_debug("Set kernel text: %lx - %lx for read only\n",
33086 start, start+size);
33087
33088 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33089 unsigned long start = PFN_ALIGN(_text);
33090 unsigned long size = PFN_ALIGN(_etext) - start;
33091
33092 + start = ktla_ktva(start);
33093 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33094 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33095 size >> 10);
33096 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33097 index 4e5dfec..6fd6dc5 100644
33098 --- a/arch/x86/mm/init_64.c
33099 +++ b/arch/x86/mm/init_64.c
33100 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33101 * around without checking the pgd every time.
33102 */
33103
33104 -pteval_t __supported_pte_mask __read_mostly = ~0;
33105 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33106 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33107
33108 int force_personality32;
33109 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33110
33111 for (address = start; address <= end; address += PGDIR_SIZE) {
33112 const pgd_t *pgd_ref = pgd_offset_k(address);
33113 +
33114 +#ifdef CONFIG_PAX_PER_CPU_PGD
33115 + unsigned long cpu;
33116 +#else
33117 struct page *page;
33118 +#endif
33119
33120 /*
33121 * When it is called after memory hot remove, pgd_none()
33122 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33123 continue;
33124
33125 spin_lock(&pgd_lock);
33126 +
33127 +#ifdef CONFIG_PAX_PER_CPU_PGD
33128 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33129 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33130 +
33131 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33132 + BUG_ON(pgd_page_vaddr(*pgd)
33133 + != pgd_page_vaddr(*pgd_ref));
33134 +
33135 + if (removed) {
33136 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33137 + pgd_clear(pgd);
33138 + } else {
33139 + if (pgd_none(*pgd))
33140 + set_pgd(pgd, *pgd_ref);
33141 + }
33142 +
33143 + pgd = pgd_offset_cpu(cpu, kernel, address);
33144 +#else
33145 list_for_each_entry(page, &pgd_list, lru) {
33146 pgd_t *pgd;
33147 spinlock_t *pgt_lock;
33148 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33149 /* the pgt_lock only for Xen */
33150 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33151 spin_lock(pgt_lock);
33152 +#endif
33153
33154 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33155 BUG_ON(pgd_page_vaddr(*pgd)
33156 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33157 set_pgd(pgd, *pgd_ref);
33158 }
33159
33160 +#ifndef CONFIG_PAX_PER_CPU_PGD
33161 spin_unlock(pgt_lock);
33162 +#endif
33163 +
33164 }
33165 spin_unlock(&pgd_lock);
33166 }
33167 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33168 {
33169 if (pgd_none(*pgd)) {
33170 pud_t *pud = (pud_t *)spp_getpage();
33171 - pgd_populate(&init_mm, pgd, pud);
33172 + pgd_populate_kernel(&init_mm, pgd, pud);
33173 if (pud != pud_offset(pgd, 0))
33174 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33175 pud, pud_offset(pgd, 0));
33176 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33177 {
33178 if (pud_none(*pud)) {
33179 pmd_t *pmd = (pmd_t *) spp_getpage();
33180 - pud_populate(&init_mm, pud, pmd);
33181 + pud_populate_kernel(&init_mm, pud, pmd);
33182 if (pmd != pmd_offset(pud, 0))
33183 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33184 pmd, pmd_offset(pud, 0));
33185 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33186 pmd = fill_pmd(pud, vaddr);
33187 pte = fill_pte(pmd, vaddr);
33188
33189 + pax_open_kernel();
33190 set_pte(pte, new_pte);
33191 + pax_close_kernel();
33192
33193 /*
33194 * It's enough to flush this one mapping.
33195 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33196 pgd = pgd_offset_k((unsigned long)__va(phys));
33197 if (pgd_none(*pgd)) {
33198 pud = (pud_t *) spp_getpage();
33199 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33200 - _PAGE_USER));
33201 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33202 }
33203 pud = pud_offset(pgd, (unsigned long)__va(phys));
33204 if (pud_none(*pud)) {
33205 pmd = (pmd_t *) spp_getpage();
33206 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33207 - _PAGE_USER));
33208 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33209 }
33210 pmd = pmd_offset(pud, phys);
33211 BUG_ON(!pmd_none(*pmd));
33212 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33213 prot);
33214
33215 spin_lock(&init_mm.page_table_lock);
33216 - pud_populate(&init_mm, pud, pmd);
33217 + pud_populate_kernel(&init_mm, pud, pmd);
33218 spin_unlock(&init_mm.page_table_lock);
33219 }
33220 __flush_tlb_all();
33221 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33222 page_size_mask);
33223
33224 spin_lock(&init_mm.page_table_lock);
33225 - pgd_populate(&init_mm, pgd, pud);
33226 + pgd_populate_kernel(&init_mm, pgd, pud);
33227 spin_unlock(&init_mm.page_table_lock);
33228 pgd_changed = true;
33229 }
33230 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33231 static struct vm_area_struct gate_vma = {
33232 .vm_start = VSYSCALL_ADDR,
33233 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33234 - .vm_page_prot = PAGE_READONLY_EXEC,
33235 - .vm_flags = VM_READ | VM_EXEC,
33236 + .vm_page_prot = PAGE_READONLY,
33237 + .vm_flags = VM_READ,
33238 .vm_ops = &gate_vma_ops,
33239 };
33240
33241 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33242 index 7b179b49..6bd17777 100644
33243 --- a/arch/x86/mm/iomap_32.c
33244 +++ b/arch/x86/mm/iomap_32.c
33245 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33246 type = kmap_atomic_idx_push();
33247 idx = type + KM_TYPE_NR * smp_processor_id();
33248 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33249 +
33250 + pax_open_kernel();
33251 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33252 + pax_close_kernel();
33253 +
33254 arch_flush_lazy_mmu_mode();
33255
33256 return (void *)vaddr;
33257 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33258 index af78e50..4f1fe56 100644
33259 --- a/arch/x86/mm/ioremap.c
33260 +++ b/arch/x86/mm/ioremap.c
33261 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33262 unsigned long i;
33263
33264 for (i = 0; i < nr_pages; ++i)
33265 - if (pfn_valid(start_pfn + i) &&
33266 - !PageReserved(pfn_to_page(start_pfn + i)))
33267 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33268 + !PageReserved(pfn_to_page(start_pfn + i))))
33269 return 1;
33270
33271 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33272 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33273 *
33274 * Caller must ensure there is only one unmapping for the same pointer.
33275 */
33276 -void iounmap(volatile void __iomem *addr)
33277 +void iounmap(const volatile void __iomem *addr)
33278 {
33279 struct vm_struct *p, *o;
33280
33281 @@ -329,30 +329,29 @@ EXPORT_SYMBOL(iounmap);
33282 */
33283 void *xlate_dev_mem_ptr(unsigned long phys)
33284 {
33285 - void *addr;
33286 - unsigned long start = phys & PAGE_MASK;
33287 -
33288 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33289 - if (page_is_ram(start >> PAGE_SHIFT))
33290 + if (page_is_ram(phys >> PAGE_SHIFT))
33291 +#ifdef CONFIG_HIGHMEM
33292 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33293 +#endif
33294 return __va(phys);
33295
33296 - addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33297 - if (addr)
33298 - addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
33299 -
33300 - return addr;
33301 + return (void __force *)ioremap_cache(phys, PAGE_SIZE);
33302 }
33303
33304 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33305 {
33306 if (page_is_ram(phys >> PAGE_SHIFT))
33307 +#ifdef CONFIG_HIGHMEM
33308 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33309 +#endif
33310 return;
33311
33312 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33313 return;
33314 }
33315
33316 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33317 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33318
33319 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33320 {
33321 @@ -388,8 +387,7 @@ void __init early_ioremap_init(void)
33322 early_ioremap_setup();
33323
33324 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33325 - memset(bm_pte, 0, sizeof(bm_pte));
33326 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33327 + pmd_populate_user(&init_mm, pmd, bm_pte);
33328
33329 /*
33330 * The boot-ioremap range spans multiple pmds, for which
33331 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33332 index b4f2e7e..96c9c3e 100644
33333 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33334 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33335 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33336 * memory (e.g. tracked pages)? For now, we need this to avoid
33337 * invoking kmemcheck for PnP BIOS calls.
33338 */
33339 - if (regs->flags & X86_VM_MASK)
33340 + if (v8086_mode(regs))
33341 return false;
33342 - if (regs->cs != __KERNEL_CS)
33343 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33344 return false;
33345
33346 pte = kmemcheck_pte_lookup(address);
33347 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33348 index 919b912..9267313 100644
33349 --- a/arch/x86/mm/mmap.c
33350 +++ b/arch/x86/mm/mmap.c
33351 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33352 * Leave an at least ~128 MB hole with possible stack randomization.
33353 */
33354 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33355 -#define MAX_GAP (TASK_SIZE/6*5)
33356 +#define MAX_GAP (pax_task_size/6*5)
33357
33358 static int mmap_is_legacy(void)
33359 {
33360 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33361 return rnd << PAGE_SHIFT;
33362 }
33363
33364 -static unsigned long mmap_base(void)
33365 +static unsigned long mmap_base(struct mm_struct *mm)
33366 {
33367 unsigned long gap = rlimit(RLIMIT_STACK);
33368 + unsigned long pax_task_size = TASK_SIZE;
33369 +
33370 +#ifdef CONFIG_PAX_SEGMEXEC
33371 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33372 + pax_task_size = SEGMEXEC_TASK_SIZE;
33373 +#endif
33374
33375 if (gap < MIN_GAP)
33376 gap = MIN_GAP;
33377 else if (gap > MAX_GAP)
33378 gap = MAX_GAP;
33379
33380 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33381 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33382 }
33383
33384 /*
33385 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33386 * does, but not when emulating X86_32
33387 */
33388 -static unsigned long mmap_legacy_base(void)
33389 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33390 {
33391 - if (mmap_is_ia32())
33392 + if (mmap_is_ia32()) {
33393 +
33394 +#ifdef CONFIG_PAX_SEGMEXEC
33395 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33396 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33397 + else
33398 +#endif
33399 +
33400 return TASK_UNMAPPED_BASE;
33401 - else
33402 + } else
33403 return TASK_UNMAPPED_BASE + mmap_rnd();
33404 }
33405
33406 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33407 */
33408 void arch_pick_mmap_layout(struct mm_struct *mm)
33409 {
33410 - mm->mmap_legacy_base = mmap_legacy_base();
33411 - mm->mmap_base = mmap_base();
33412 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33413 + mm->mmap_base = mmap_base(mm);
33414 +
33415 +#ifdef CONFIG_PAX_RANDMMAP
33416 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33417 + mm->mmap_legacy_base += mm->delta_mmap;
33418 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33419 + }
33420 +#endif
33421
33422 if (mmap_is_legacy()) {
33423 mm->mmap_base = mm->mmap_legacy_base;
33424 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33425 index 0057a7a..95c7edd 100644
33426 --- a/arch/x86/mm/mmio-mod.c
33427 +++ b/arch/x86/mm/mmio-mod.c
33428 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33429 break;
33430 default:
33431 {
33432 - unsigned char *ip = (unsigned char *)instptr;
33433 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33434 my_trace->opcode = MMIO_UNKNOWN_OP;
33435 my_trace->width = 0;
33436 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33437 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33438 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33439 void __iomem *addr)
33440 {
33441 - static atomic_t next_id;
33442 + static atomic_unchecked_t next_id;
33443 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33444 /* These are page-unaligned. */
33445 struct mmiotrace_map map = {
33446 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33447 .private = trace
33448 },
33449 .phys = offset,
33450 - .id = atomic_inc_return(&next_id)
33451 + .id = atomic_inc_return_unchecked(&next_id)
33452 };
33453 map.map_id = trace->id;
33454
33455 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33456 ioremap_trace_core(offset, size, addr);
33457 }
33458
33459 -static void iounmap_trace_core(volatile void __iomem *addr)
33460 +static void iounmap_trace_core(const volatile void __iomem *addr)
33461 {
33462 struct mmiotrace_map map = {
33463 .phys = 0,
33464 @@ -328,7 +328,7 @@ not_enabled:
33465 }
33466 }
33467
33468 -void mmiotrace_iounmap(volatile void __iomem *addr)
33469 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33470 {
33471 might_sleep();
33472 if (is_enabled()) /* recheck and proper locking in *_core() */
33473 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33474 index 1a88370..3f598b5 100644
33475 --- a/arch/x86/mm/numa.c
33476 +++ b/arch/x86/mm/numa.c
33477 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33478 }
33479 }
33480
33481 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33482 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33483 {
33484 unsigned long uninitialized_var(pfn_align);
33485 int i, nid;
33486 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33487 index 36de293..b820ddc 100644
33488 --- a/arch/x86/mm/pageattr.c
33489 +++ b/arch/x86/mm/pageattr.c
33490 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33491 */
33492 #ifdef CONFIG_PCI_BIOS
33493 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33494 - pgprot_val(forbidden) |= _PAGE_NX;
33495 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33496 #endif
33497
33498 /*
33499 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33500 * Does not cover __inittext since that is gone later on. On
33501 * 64bit we do not enforce !NX on the low mapping
33502 */
33503 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33504 - pgprot_val(forbidden) |= _PAGE_NX;
33505 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33506 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33507
33508 +#ifdef CONFIG_DEBUG_RODATA
33509 /*
33510 * The .rodata section needs to be read-only. Using the pfn
33511 * catches all aliases.
33512 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33513 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33514 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33515 pgprot_val(forbidden) |= _PAGE_RW;
33516 +#endif
33517
33518 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33519 /*
33520 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33521 }
33522 #endif
33523
33524 +#ifdef CONFIG_PAX_KERNEXEC
33525 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33526 + pgprot_val(forbidden) |= _PAGE_RW;
33527 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33528 + }
33529 +#endif
33530 +
33531 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33532
33533 return prot;
33534 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33535 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33536 {
33537 /* change init_mm */
33538 + pax_open_kernel();
33539 set_pte_atomic(kpte, pte);
33540 +
33541 #ifdef CONFIG_X86_32
33542 if (!SHARED_KERNEL_PMD) {
33543 +
33544 +#ifdef CONFIG_PAX_PER_CPU_PGD
33545 + unsigned long cpu;
33546 +#else
33547 struct page *page;
33548 +#endif
33549
33550 +#ifdef CONFIG_PAX_PER_CPU_PGD
33551 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33552 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33553 +#else
33554 list_for_each_entry(page, &pgd_list, lru) {
33555 - pgd_t *pgd;
33556 + pgd_t *pgd = (pgd_t *)page_address(page);
33557 +#endif
33558 +
33559 pud_t *pud;
33560 pmd_t *pmd;
33561
33562 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33563 + pgd += pgd_index(address);
33564 pud = pud_offset(pgd, address);
33565 pmd = pmd_offset(pud, address);
33566 set_pte_atomic((pte_t *)pmd, pte);
33567 }
33568 }
33569 #endif
33570 + pax_close_kernel();
33571 }
33572
33573 static int
33574 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33575 index 6574388..87e9bef 100644
33576 --- a/arch/x86/mm/pat.c
33577 +++ b/arch/x86/mm/pat.c
33578 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33579
33580 if (!entry) {
33581 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33582 - current->comm, current->pid, start, end - 1);
33583 + current->comm, task_pid_nr(current), start, end - 1);
33584 return -EINVAL;
33585 }
33586
33587 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33588
33589 while (cursor < to) {
33590 if (!devmem_is_allowed(pfn)) {
33591 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33592 - current->comm, from, to - 1);
33593 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33594 + current->comm, from, to - 1, cursor);
33595 return 0;
33596 }
33597 cursor += PAGE_SIZE;
33598 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33599 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33600 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33601 "for [mem %#010Lx-%#010Lx]\n",
33602 - current->comm, current->pid,
33603 + current->comm, task_pid_nr(current),
33604 cattr_name(flags),
33605 base, (unsigned long long)(base + size-1));
33606 return -EINVAL;
33607 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33608 flags = lookup_memtype(paddr);
33609 if (want_flags != flags) {
33610 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33611 - current->comm, current->pid,
33612 + current->comm, task_pid_nr(current),
33613 cattr_name(want_flags),
33614 (unsigned long long)paddr,
33615 (unsigned long long)(paddr + size - 1),
33616 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33617 free_memtype(paddr, paddr + size);
33618 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33619 " for [mem %#010Lx-%#010Lx], got %s\n",
33620 - current->comm, current->pid,
33621 + current->comm, task_pid_nr(current),
33622 cattr_name(want_flags),
33623 (unsigned long long)paddr,
33624 (unsigned long long)(paddr + size - 1),
33625 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33626 index 415f6c4..d319983 100644
33627 --- a/arch/x86/mm/pat_rbtree.c
33628 +++ b/arch/x86/mm/pat_rbtree.c
33629 @@ -160,7 +160,7 @@ success:
33630
33631 failure:
33632 printk(KERN_INFO "%s:%d conflicting memory types "
33633 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33634 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33635 end, cattr_name(found_type), cattr_name(match->type));
33636 return -EBUSY;
33637 }
33638 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33639 index 9f0614d..92ae64a 100644
33640 --- a/arch/x86/mm/pf_in.c
33641 +++ b/arch/x86/mm/pf_in.c
33642 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33643 int i;
33644 enum reason_type rv = OTHERS;
33645
33646 - p = (unsigned char *)ins_addr;
33647 + p = (unsigned char *)ktla_ktva(ins_addr);
33648 p += skip_prefix(p, &prf);
33649 p += get_opcode(p, &opcode);
33650
33651 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33652 struct prefix_bits prf;
33653 int i;
33654
33655 - p = (unsigned char *)ins_addr;
33656 + p = (unsigned char *)ktla_ktva(ins_addr);
33657 p += skip_prefix(p, &prf);
33658 p += get_opcode(p, &opcode);
33659
33660 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33661 struct prefix_bits prf;
33662 int i;
33663
33664 - p = (unsigned char *)ins_addr;
33665 + p = (unsigned char *)ktla_ktva(ins_addr);
33666 p += skip_prefix(p, &prf);
33667 p += get_opcode(p, &opcode);
33668
33669 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33670 struct prefix_bits prf;
33671 int i;
33672
33673 - p = (unsigned char *)ins_addr;
33674 + p = (unsigned char *)ktla_ktva(ins_addr);
33675 p += skip_prefix(p, &prf);
33676 p += get_opcode(p, &opcode);
33677 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33678 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33679 struct prefix_bits prf;
33680 int i;
33681
33682 - p = (unsigned char *)ins_addr;
33683 + p = (unsigned char *)ktla_ktva(ins_addr);
33684 p += skip_prefix(p, &prf);
33685 p += get_opcode(p, &opcode);
33686 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33687 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33688 index 6fb6927..4fc13c0 100644
33689 --- a/arch/x86/mm/pgtable.c
33690 +++ b/arch/x86/mm/pgtable.c
33691 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33692 list_del(&page->lru);
33693 }
33694
33695 -#define UNSHARED_PTRS_PER_PGD \
33696 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33697 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33698 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33699
33700 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33701 +{
33702 + unsigned int count = USER_PGD_PTRS;
33703
33704 + if (!pax_user_shadow_base)
33705 + return;
33706 +
33707 + while (count--)
33708 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33709 +}
33710 +#endif
33711 +
33712 +#ifdef CONFIG_PAX_PER_CPU_PGD
33713 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33714 +{
33715 + unsigned int count = USER_PGD_PTRS;
33716 +
33717 + while (count--) {
33718 + pgd_t pgd;
33719 +
33720 +#ifdef CONFIG_X86_64
33721 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33722 +#else
33723 + pgd = *src++;
33724 +#endif
33725 +
33726 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33727 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33728 +#endif
33729 +
33730 + *dst++ = pgd;
33731 + }
33732 +
33733 +}
33734 +#endif
33735 +
33736 +#ifdef CONFIG_X86_64
33737 +#define pxd_t pud_t
33738 +#define pyd_t pgd_t
33739 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33740 +#define pgtable_pxd_page_ctor(page) true
33741 +#define pgtable_pxd_page_dtor(page)
33742 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33743 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33744 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33745 +#define PYD_SIZE PGDIR_SIZE
33746 +#else
33747 +#define pxd_t pmd_t
33748 +#define pyd_t pud_t
33749 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33750 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33751 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33752 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33753 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33754 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33755 +#define PYD_SIZE PUD_SIZE
33756 +#endif
33757 +
33758 +#ifdef CONFIG_PAX_PER_CPU_PGD
33759 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33760 +static inline void pgd_dtor(pgd_t *pgd) {}
33761 +#else
33762 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33763 {
33764 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33765 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33766 pgd_list_del(pgd);
33767 spin_unlock(&pgd_lock);
33768 }
33769 +#endif
33770
33771 /*
33772 * List of all pgd's needed for non-PAE so it can invalidate entries
33773 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33774 * -- nyc
33775 */
33776
33777 -#ifdef CONFIG_X86_PAE
33778 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33779 /*
33780 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33781 * updating the top-level pagetable entries to guarantee the
33782 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33783 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33784 * and initialize the kernel pmds here.
33785 */
33786 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33787 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33788
33789 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33790 {
33791 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33792 */
33793 flush_tlb_mm(mm);
33794 }
33795 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33796 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33797 #else /* !CONFIG_X86_PAE */
33798
33799 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33800 -#define PREALLOCATED_PMDS 0
33801 +#define PREALLOCATED_PXDS 0
33802
33803 #endif /* CONFIG_X86_PAE */
33804
33805 -static void free_pmds(pmd_t *pmds[])
33806 +static void free_pxds(pxd_t *pxds[])
33807 {
33808 int i;
33809
33810 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33811 - if (pmds[i]) {
33812 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33813 - free_page((unsigned long)pmds[i]);
33814 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33815 + if (pxds[i]) {
33816 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33817 + free_page((unsigned long)pxds[i]);
33818 }
33819 }
33820
33821 -static int preallocate_pmds(pmd_t *pmds[])
33822 +static int preallocate_pxds(pxd_t *pxds[])
33823 {
33824 int i;
33825 bool failed = false;
33826
33827 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33828 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33829 - if (!pmd)
33830 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33831 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33832 + if (!pxd)
33833 failed = true;
33834 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33835 - free_page((unsigned long)pmd);
33836 - pmd = NULL;
33837 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33838 + free_page((unsigned long)pxd);
33839 + pxd = NULL;
33840 failed = true;
33841 }
33842 - pmds[i] = pmd;
33843 + pxds[i] = pxd;
33844 }
33845
33846 if (failed) {
33847 - free_pmds(pmds);
33848 + free_pxds(pxds);
33849 return -ENOMEM;
33850 }
33851
33852 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33853 * preallocate which never got a corresponding vma will need to be
33854 * freed manually.
33855 */
33856 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33857 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33858 {
33859 int i;
33860
33861 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33862 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33863 pgd_t pgd = pgdp[i];
33864
33865 if (pgd_val(pgd) != 0) {
33866 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33867 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33868
33869 - pgdp[i] = native_make_pgd(0);
33870 + set_pgd(pgdp + i, native_make_pgd(0));
33871
33872 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33873 - pmd_free(mm, pmd);
33874 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33875 + pxd_free(mm, pxd);
33876 }
33877 }
33878 }
33879
33880 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33881 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33882 {
33883 - pud_t *pud;
33884 + pyd_t *pyd;
33885 int i;
33886
33887 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33888 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33889 return;
33890
33891 - pud = pud_offset(pgd, 0);
33892 -
33893 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33894 - pmd_t *pmd = pmds[i];
33895 +#ifdef CONFIG_X86_64
33896 + pyd = pyd_offset(mm, 0L);
33897 +#else
33898 + pyd = pyd_offset(pgd, 0L);
33899 +#endif
33900
33901 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33902 + pxd_t *pxd = pxds[i];
33903 if (i >= KERNEL_PGD_BOUNDARY)
33904 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33905 - sizeof(pmd_t) * PTRS_PER_PMD);
33906 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33907 + sizeof(pxd_t) * PTRS_PER_PMD);
33908
33909 - pud_populate(mm, pud, pmd);
33910 + pyd_populate(mm, pyd, pxd);
33911 }
33912 }
33913
33914 pgd_t *pgd_alloc(struct mm_struct *mm)
33915 {
33916 pgd_t *pgd;
33917 - pmd_t *pmds[PREALLOCATED_PMDS];
33918 + pxd_t *pxds[PREALLOCATED_PXDS];
33919
33920 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33921
33922 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33923
33924 mm->pgd = pgd;
33925
33926 - if (preallocate_pmds(pmds) != 0)
33927 + if (preallocate_pxds(pxds) != 0)
33928 goto out_free_pgd;
33929
33930 if (paravirt_pgd_alloc(mm) != 0)
33931 - goto out_free_pmds;
33932 + goto out_free_pxds;
33933
33934 /*
33935 * Make sure that pre-populating the pmds is atomic with
33936 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33937 spin_lock(&pgd_lock);
33938
33939 pgd_ctor(mm, pgd);
33940 - pgd_prepopulate_pmd(mm, pgd, pmds);
33941 + pgd_prepopulate_pxd(mm, pgd, pxds);
33942
33943 spin_unlock(&pgd_lock);
33944
33945 return pgd;
33946
33947 -out_free_pmds:
33948 - free_pmds(pmds);
33949 +out_free_pxds:
33950 + free_pxds(pxds);
33951 out_free_pgd:
33952 free_page((unsigned long)pgd);
33953 out:
33954 @@ -313,7 +380,7 @@ out:
33955
33956 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33957 {
33958 - pgd_mop_up_pmds(mm, pgd);
33959 + pgd_mop_up_pxds(mm, pgd);
33960 pgd_dtor(pgd);
33961 paravirt_pgd_free(mm, pgd);
33962 free_page((unsigned long)pgd);
33963 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33964 index 75cc097..79a097f 100644
33965 --- a/arch/x86/mm/pgtable_32.c
33966 +++ b/arch/x86/mm/pgtable_32.c
33967 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33968 return;
33969 }
33970 pte = pte_offset_kernel(pmd, vaddr);
33971 +
33972 + pax_open_kernel();
33973 if (pte_val(pteval))
33974 set_pte_at(&init_mm, vaddr, pte, pteval);
33975 else
33976 pte_clear(&init_mm, vaddr, pte);
33977 + pax_close_kernel();
33978
33979 /*
33980 * It's enough to flush this one mapping.
33981 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33982 index e666cbb..61788c45 100644
33983 --- a/arch/x86/mm/physaddr.c
33984 +++ b/arch/x86/mm/physaddr.c
33985 @@ -10,7 +10,7 @@
33986 #ifdef CONFIG_X86_64
33987
33988 #ifdef CONFIG_DEBUG_VIRTUAL
33989 -unsigned long __phys_addr(unsigned long x)
33990 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33991 {
33992 unsigned long y = x - __START_KERNEL_map;
33993
33994 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33995 #else
33996
33997 #ifdef CONFIG_DEBUG_VIRTUAL
33998 -unsigned long __phys_addr(unsigned long x)
33999 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34000 {
34001 unsigned long phys_addr = x - PAGE_OFFSET;
34002 /* VMALLOC_* aren't constants */
34003 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34004 index 90555bf..f5f1828 100644
34005 --- a/arch/x86/mm/setup_nx.c
34006 +++ b/arch/x86/mm/setup_nx.c
34007 @@ -5,8 +5,10 @@
34008 #include <asm/pgtable.h>
34009 #include <asm/proto.h>
34010
34011 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34012 static int disable_nx;
34013
34014 +#ifndef CONFIG_PAX_PAGEEXEC
34015 /*
34016 * noexec = on|off
34017 *
34018 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34019 return 0;
34020 }
34021 early_param("noexec", noexec_setup);
34022 +#endif
34023 +
34024 +#endif
34025
34026 void x86_configure_nx(void)
34027 {
34028 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34029 if (cpu_has_nx && !disable_nx)
34030 __supported_pte_mask |= _PAGE_NX;
34031 else
34032 +#endif
34033 __supported_pte_mask &= ~_PAGE_NX;
34034 }
34035
34036 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34037 index ee61c36..e6fedeb 100644
34038 --- a/arch/x86/mm/tlb.c
34039 +++ b/arch/x86/mm/tlb.c
34040 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34041 BUG();
34042 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34043 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34044 +
34045 +#ifndef CONFIG_PAX_PER_CPU_PGD
34046 load_cr3(swapper_pg_dir);
34047 +#endif
34048 +
34049 /*
34050 * This gets called in the idle path where RCU
34051 * functions differently. Tracing normally
34052 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34053 new file mode 100644
34054 index 0000000..dace51c
34055 --- /dev/null
34056 +++ b/arch/x86/mm/uderef_64.c
34057 @@ -0,0 +1,37 @@
34058 +#include <linux/mm.h>
34059 +#include <asm/pgtable.h>
34060 +#include <asm/uaccess.h>
34061 +
34062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34063 +/* PaX: due to the special call convention these functions must
34064 + * - remain leaf functions under all configurations,
34065 + * - never be called directly, only dereferenced from the wrappers.
34066 + */
34067 +void __pax_open_userland(void)
34068 +{
34069 + unsigned int cpu;
34070 +
34071 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34072 + return;
34073 +
34074 + cpu = raw_get_cpu();
34075 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34076 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34077 + raw_put_cpu_no_resched();
34078 +}
34079 +EXPORT_SYMBOL(__pax_open_userland);
34080 +
34081 +void __pax_close_userland(void)
34082 +{
34083 + unsigned int cpu;
34084 +
34085 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34086 + return;
34087 +
34088 + cpu = raw_get_cpu();
34089 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34090 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34091 + raw_put_cpu_no_resched();
34092 +}
34093 +EXPORT_SYMBOL(__pax_close_userland);
34094 +#endif
34095 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34096 index 6440221..f84b5c7 100644
34097 --- a/arch/x86/net/bpf_jit.S
34098 +++ b/arch/x86/net/bpf_jit.S
34099 @@ -9,6 +9,7 @@
34100 */
34101 #include <linux/linkage.h>
34102 #include <asm/dwarf2.h>
34103 +#include <asm/alternative-asm.h>
34104
34105 /*
34106 * Calling convention :
34107 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34108 jle bpf_slow_path_word
34109 mov (SKBDATA,%rsi),%eax
34110 bswap %eax /* ntohl() */
34111 + pax_force_retaddr
34112 ret
34113
34114 sk_load_half:
34115 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34116 jle bpf_slow_path_half
34117 movzwl (SKBDATA,%rsi),%eax
34118 rol $8,%ax # ntohs()
34119 + pax_force_retaddr
34120 ret
34121
34122 sk_load_byte:
34123 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34124 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34125 jle bpf_slow_path_byte
34126 movzbl (SKBDATA,%rsi),%eax
34127 + pax_force_retaddr
34128 ret
34129
34130 /* rsi contains offset and can be scratched */
34131 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34132 js bpf_error
34133 mov - MAX_BPF_STACK + 32(%rbp),%eax
34134 bswap %eax
34135 + pax_force_retaddr
34136 ret
34137
34138 bpf_slow_path_half:
34139 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34140 mov - MAX_BPF_STACK + 32(%rbp),%ax
34141 rol $8,%ax
34142 movzwl %ax,%eax
34143 + pax_force_retaddr
34144 ret
34145
34146 bpf_slow_path_byte:
34147 bpf_slow_path_common(1)
34148 js bpf_error
34149 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34150 + pax_force_retaddr
34151 ret
34152
34153 #define sk_negative_common(SIZE) \
34154 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34155 sk_negative_common(4)
34156 mov (%rax), %eax
34157 bswap %eax
34158 + pax_force_retaddr
34159 ret
34160
34161 bpf_slow_path_half_neg:
34162 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34163 mov (%rax),%ax
34164 rol $8,%ax
34165 movzwl %ax,%eax
34166 + pax_force_retaddr
34167 ret
34168
34169 bpf_slow_path_byte_neg:
34170 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34171 .globl sk_load_byte_negative_offset
34172 sk_negative_common(1)
34173 movzbl (%rax), %eax
34174 + pax_force_retaddr
34175 ret
34176
34177 bpf_error:
34178 @@ -156,4 +166,5 @@ bpf_error:
34179 mov - MAX_BPF_STACK + 16(%rbp),%r14
34180 mov - MAX_BPF_STACK + 24(%rbp),%r15
34181 leaveq
34182 + pax_force_retaddr
34183 ret
34184 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34185 index 3f62734..a57894f 100644
34186 --- a/arch/x86/net/bpf_jit_comp.c
34187 +++ b/arch/x86/net/bpf_jit_comp.c
34188 @@ -13,7 +13,11 @@
34189 #include <linux/if_vlan.h>
34190 #include <asm/cacheflush.h>
34191
34192 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34193 +int bpf_jit_enable __read_only;
34194 +#else
34195 int bpf_jit_enable __read_mostly;
34196 +#endif
34197
34198 /*
34199 * assembly code in arch/x86/net/bpf_jit.S
34200 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34201 static void jit_fill_hole(void *area, unsigned int size)
34202 {
34203 /* fill whole space with int3 instructions */
34204 + pax_open_kernel();
34205 memset(area, 0xcc, size);
34206 + pax_close_kernel();
34207 }
34208
34209 struct jit_context {
34210 @@ -894,7 +900,9 @@ common_load:
34211 pr_err("bpf_jit_compile fatal error\n");
34212 return -EFAULT;
34213 }
34214 + pax_open_kernel();
34215 memcpy(image + proglen, temp, ilen);
34216 + pax_close_kernel();
34217 }
34218 proglen += ilen;
34219 addrs[i] = proglen;
34220 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34221
34222 if (image) {
34223 bpf_flush_icache(header, image + proglen);
34224 - set_memory_ro((unsigned long)header, header->pages);
34225 prog->bpf_func = (void *)image;
34226 prog->jited = true;
34227 }
34228 @@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34229 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34230 struct bpf_binary_header *header = (void *)addr;
34231
34232 - if (!fp->jited)
34233 - goto free_filter;
34234 + if (fp->jited)
34235 + bpf_jit_binary_free(header);
34236
34237 - set_memory_rw(addr, header->pages);
34238 - bpf_jit_binary_free(header);
34239 -
34240 -free_filter:
34241 bpf_prog_unlock_free(fp);
34242 }
34243 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34244 index 5d04be5..2beeaa2 100644
34245 --- a/arch/x86/oprofile/backtrace.c
34246 +++ b/arch/x86/oprofile/backtrace.c
34247 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34248 struct stack_frame_ia32 *fp;
34249 unsigned long bytes;
34250
34251 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34252 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34253 if (bytes != 0)
34254 return NULL;
34255
34256 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34257 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34258
34259 oprofile_add_trace(bufhead[0].return_address);
34260
34261 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34262 struct stack_frame bufhead[2];
34263 unsigned long bytes;
34264
34265 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34266 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34267 if (bytes != 0)
34268 return NULL;
34269
34270 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34271 {
34272 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34273
34274 - if (!user_mode_vm(regs)) {
34275 + if (!user_mode(regs)) {
34276 unsigned long stack = kernel_stack_pointer(regs);
34277 if (depth)
34278 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34279 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34280 index 1d2e639..f6ef82a 100644
34281 --- a/arch/x86/oprofile/nmi_int.c
34282 +++ b/arch/x86/oprofile/nmi_int.c
34283 @@ -23,6 +23,7 @@
34284 #include <asm/nmi.h>
34285 #include <asm/msr.h>
34286 #include <asm/apic.h>
34287 +#include <asm/pgtable.h>
34288
34289 #include "op_counter.h"
34290 #include "op_x86_model.h"
34291 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34292 if (ret)
34293 return ret;
34294
34295 - if (!model->num_virt_counters)
34296 - model->num_virt_counters = model->num_counters;
34297 + if (!model->num_virt_counters) {
34298 + pax_open_kernel();
34299 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34300 + pax_close_kernel();
34301 + }
34302
34303 mux_init(ops);
34304
34305 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34306 index 50d86c0..7985318 100644
34307 --- a/arch/x86/oprofile/op_model_amd.c
34308 +++ b/arch/x86/oprofile/op_model_amd.c
34309 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34310 num_counters = AMD64_NUM_COUNTERS;
34311 }
34312
34313 - op_amd_spec.num_counters = num_counters;
34314 - op_amd_spec.num_controls = num_counters;
34315 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34316 + pax_open_kernel();
34317 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34318 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34319 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34320 + pax_close_kernel();
34321
34322 return 0;
34323 }
34324 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34325 index d90528e..0127e2b 100644
34326 --- a/arch/x86/oprofile/op_model_ppro.c
34327 +++ b/arch/x86/oprofile/op_model_ppro.c
34328 @@ -19,6 +19,7 @@
34329 #include <asm/msr.h>
34330 #include <asm/apic.h>
34331 #include <asm/nmi.h>
34332 +#include <asm/pgtable.h>
34333
34334 #include "op_x86_model.h"
34335 #include "op_counter.h"
34336 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34337
34338 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34339
34340 - op_arch_perfmon_spec.num_counters = num_counters;
34341 - op_arch_perfmon_spec.num_controls = num_counters;
34342 + pax_open_kernel();
34343 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34344 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34345 + pax_close_kernel();
34346 }
34347
34348 static int arch_perfmon_init(struct oprofile_operations *ignore)
34349 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34350 index 71e8a67..6a313bb 100644
34351 --- a/arch/x86/oprofile/op_x86_model.h
34352 +++ b/arch/x86/oprofile/op_x86_model.h
34353 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34354 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34355 struct op_msrs const * const msrs);
34356 #endif
34357 -};
34358 +} __do_const;
34359
34360 struct op_counter_config;
34361
34362 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34363 index b9958c3..24229ab 100644
34364 --- a/arch/x86/pci/intel_mid_pci.c
34365 +++ b/arch/x86/pci/intel_mid_pci.c
34366 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34367 pci_mmcfg_late_init();
34368 pcibios_enable_irq = intel_mid_pci_irq_enable;
34369 pcibios_disable_irq = intel_mid_pci_irq_disable;
34370 - pci_root_ops = intel_mid_pci_ops;
34371 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34372 pci_soc_mode = 1;
34373 /* Continue with standard init */
34374 return 1;
34375 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34376 index eb500c2..eab9e70 100644
34377 --- a/arch/x86/pci/irq.c
34378 +++ b/arch/x86/pci/irq.c
34379 @@ -51,7 +51,7 @@ struct irq_router {
34380 struct irq_router_handler {
34381 u16 vendor;
34382 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34383 -};
34384 +} __do_const;
34385
34386 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34387 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34388 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34389 return 0;
34390 }
34391
34392 -static __initdata struct irq_router_handler pirq_routers[] = {
34393 +static __initconst const struct irq_router_handler pirq_routers[] = {
34394 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34395 { PCI_VENDOR_ID_AL, ali_router_probe },
34396 { PCI_VENDOR_ID_ITE, ite_router_probe },
34397 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34398 static void __init pirq_find_router(struct irq_router *r)
34399 {
34400 struct irq_routing_table *rt = pirq_table;
34401 - struct irq_router_handler *h;
34402 + const struct irq_router_handler *h;
34403
34404 #ifdef CONFIG_PCI_BIOS
34405 if (!rt->signature) {
34406 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34407 return 0;
34408 }
34409
34410 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34411 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34412 {
34413 .callback = fix_broken_hp_bios_irq9,
34414 .ident = "HP Pavilion N5400 Series Laptop",
34415 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34416 index 9b83b90..4112152 100644
34417 --- a/arch/x86/pci/pcbios.c
34418 +++ b/arch/x86/pci/pcbios.c
34419 @@ -79,7 +79,7 @@ union bios32 {
34420 static struct {
34421 unsigned long address;
34422 unsigned short segment;
34423 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34424 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34425
34426 /*
34427 * Returns the entry point for the given service, NULL on error
34428 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34429 unsigned long length; /* %ecx */
34430 unsigned long entry; /* %edx */
34431 unsigned long flags;
34432 + struct desc_struct d, *gdt;
34433
34434 local_irq_save(flags);
34435 - __asm__("lcall *(%%edi); cld"
34436 +
34437 + gdt = get_cpu_gdt_table(smp_processor_id());
34438 +
34439 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34440 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34441 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34442 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34443 +
34444 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34445 : "=a" (return_code),
34446 "=b" (address),
34447 "=c" (length),
34448 "=d" (entry)
34449 : "0" (service),
34450 "1" (0),
34451 - "D" (&bios32_indirect));
34452 + "D" (&bios32_indirect),
34453 + "r"(__PCIBIOS_DS)
34454 + : "memory");
34455 +
34456 + pax_open_kernel();
34457 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34458 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34459 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34460 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34461 + pax_close_kernel();
34462 +
34463 local_irq_restore(flags);
34464
34465 switch (return_code) {
34466 - case 0:
34467 - return address + entry;
34468 - case 0x80: /* Not present */
34469 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34470 - return 0;
34471 - default: /* Shouldn't happen */
34472 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34473 - service, return_code);
34474 + case 0: {
34475 + int cpu;
34476 + unsigned char flags;
34477 +
34478 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34479 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34480 + printk(KERN_WARNING "bios32_service: not valid\n");
34481 return 0;
34482 + }
34483 + address = address + PAGE_OFFSET;
34484 + length += 16UL; /* some BIOSs underreport this... */
34485 + flags = 4;
34486 + if (length >= 64*1024*1024) {
34487 + length >>= PAGE_SHIFT;
34488 + flags |= 8;
34489 + }
34490 +
34491 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34492 + gdt = get_cpu_gdt_table(cpu);
34493 + pack_descriptor(&d, address, length, 0x9b, flags);
34494 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34495 + pack_descriptor(&d, address, length, 0x93, flags);
34496 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34497 + }
34498 + return entry;
34499 + }
34500 + case 0x80: /* Not present */
34501 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34502 + return 0;
34503 + default: /* Shouldn't happen */
34504 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34505 + service, return_code);
34506 + return 0;
34507 }
34508 }
34509
34510 static struct {
34511 unsigned long address;
34512 unsigned short segment;
34513 -} pci_indirect = { 0, __KERNEL_CS };
34514 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34515
34516 -static int pci_bios_present;
34517 +static int pci_bios_present __read_only;
34518
34519 static int __init check_pcibios(void)
34520 {
34521 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34522 unsigned long flags, pcibios_entry;
34523
34524 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34525 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34526 + pci_indirect.address = pcibios_entry;
34527
34528 local_irq_save(flags);
34529 - __asm__(
34530 - "lcall *(%%edi); cld\n\t"
34531 + __asm__("movw %w6, %%ds\n\t"
34532 + "lcall *%%ss:(%%edi); cld\n\t"
34533 + "push %%ss\n\t"
34534 + "pop %%ds\n\t"
34535 "jc 1f\n\t"
34536 "xor %%ah, %%ah\n"
34537 "1:"
34538 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34539 "=b" (ebx),
34540 "=c" (ecx)
34541 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34542 - "D" (&pci_indirect)
34543 + "D" (&pci_indirect),
34544 + "r" (__PCIBIOS_DS)
34545 : "memory");
34546 local_irq_restore(flags);
34547
34548 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34549
34550 switch (len) {
34551 case 1:
34552 - __asm__("lcall *(%%esi); cld\n\t"
34553 + __asm__("movw %w6, %%ds\n\t"
34554 + "lcall *%%ss:(%%esi); cld\n\t"
34555 + "push %%ss\n\t"
34556 + "pop %%ds\n\t"
34557 "jc 1f\n\t"
34558 "xor %%ah, %%ah\n"
34559 "1:"
34560 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34561 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34562 "b" (bx),
34563 "D" ((long)reg),
34564 - "S" (&pci_indirect));
34565 + "S" (&pci_indirect),
34566 + "r" (__PCIBIOS_DS));
34567 /*
34568 * Zero-extend the result beyond 8 bits, do not trust the
34569 * BIOS having done it:
34570 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34571 *value &= 0xff;
34572 break;
34573 case 2:
34574 - __asm__("lcall *(%%esi); cld\n\t"
34575 + __asm__("movw %w6, %%ds\n\t"
34576 + "lcall *%%ss:(%%esi); cld\n\t"
34577 + "push %%ss\n\t"
34578 + "pop %%ds\n\t"
34579 "jc 1f\n\t"
34580 "xor %%ah, %%ah\n"
34581 "1:"
34582 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34583 : "1" (PCIBIOS_READ_CONFIG_WORD),
34584 "b" (bx),
34585 "D" ((long)reg),
34586 - "S" (&pci_indirect));
34587 + "S" (&pci_indirect),
34588 + "r" (__PCIBIOS_DS));
34589 /*
34590 * Zero-extend the result beyond 16 bits, do not trust the
34591 * BIOS having done it:
34592 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34593 *value &= 0xffff;
34594 break;
34595 case 4:
34596 - __asm__("lcall *(%%esi); cld\n\t"
34597 + __asm__("movw %w6, %%ds\n\t"
34598 + "lcall *%%ss:(%%esi); cld\n\t"
34599 + "push %%ss\n\t"
34600 + "pop %%ds\n\t"
34601 "jc 1f\n\t"
34602 "xor %%ah, %%ah\n"
34603 "1:"
34604 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34605 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34606 "b" (bx),
34607 "D" ((long)reg),
34608 - "S" (&pci_indirect));
34609 + "S" (&pci_indirect),
34610 + "r" (__PCIBIOS_DS));
34611 break;
34612 }
34613
34614 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34615
34616 switch (len) {
34617 case 1:
34618 - __asm__("lcall *(%%esi); cld\n\t"
34619 + __asm__("movw %w6, %%ds\n\t"
34620 + "lcall *%%ss:(%%esi); cld\n\t"
34621 + "push %%ss\n\t"
34622 + "pop %%ds\n\t"
34623 "jc 1f\n\t"
34624 "xor %%ah, %%ah\n"
34625 "1:"
34626 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34627 "c" (value),
34628 "b" (bx),
34629 "D" ((long)reg),
34630 - "S" (&pci_indirect));
34631 + "S" (&pci_indirect),
34632 + "r" (__PCIBIOS_DS));
34633 break;
34634 case 2:
34635 - __asm__("lcall *(%%esi); cld\n\t"
34636 + __asm__("movw %w6, %%ds\n\t"
34637 + "lcall *%%ss:(%%esi); cld\n\t"
34638 + "push %%ss\n\t"
34639 + "pop %%ds\n\t"
34640 "jc 1f\n\t"
34641 "xor %%ah, %%ah\n"
34642 "1:"
34643 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34644 "c" (value),
34645 "b" (bx),
34646 "D" ((long)reg),
34647 - "S" (&pci_indirect));
34648 + "S" (&pci_indirect),
34649 + "r" (__PCIBIOS_DS));
34650 break;
34651 case 4:
34652 - __asm__("lcall *(%%esi); cld\n\t"
34653 + __asm__("movw %w6, %%ds\n\t"
34654 + "lcall *%%ss:(%%esi); cld\n\t"
34655 + "push %%ss\n\t"
34656 + "pop %%ds\n\t"
34657 "jc 1f\n\t"
34658 "xor %%ah, %%ah\n"
34659 "1:"
34660 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34661 "c" (value),
34662 "b" (bx),
34663 "D" ((long)reg),
34664 - "S" (&pci_indirect));
34665 + "S" (&pci_indirect),
34666 + "r" (__PCIBIOS_DS));
34667 break;
34668 }
34669
34670 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34671
34672 DBG("PCI: Fetching IRQ routing table... ");
34673 __asm__("push %%es\n\t"
34674 + "movw %w8, %%ds\n\t"
34675 "push %%ds\n\t"
34676 "pop %%es\n\t"
34677 - "lcall *(%%esi); cld\n\t"
34678 + "lcall *%%ss:(%%esi); cld\n\t"
34679 "pop %%es\n\t"
34680 + "push %%ss\n\t"
34681 + "pop %%ds\n"
34682 "jc 1f\n\t"
34683 "xor %%ah, %%ah\n"
34684 "1:"
34685 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34686 "1" (0),
34687 "D" ((long) &opt),
34688 "S" (&pci_indirect),
34689 - "m" (opt)
34690 + "m" (opt),
34691 + "r" (__PCIBIOS_DS)
34692 : "memory");
34693 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34694 if (ret & 0xff00)
34695 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34696 {
34697 int ret;
34698
34699 - __asm__("lcall *(%%esi); cld\n\t"
34700 + __asm__("movw %w5, %%ds\n\t"
34701 + "lcall *%%ss:(%%esi); cld\n\t"
34702 + "push %%ss\n\t"
34703 + "pop %%ds\n"
34704 "jc 1f\n\t"
34705 "xor %%ah, %%ah\n"
34706 "1:"
34707 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34708 : "0" (PCIBIOS_SET_PCI_HW_INT),
34709 "b" ((dev->bus->number << 8) | dev->devfn),
34710 "c" ((irq << 8) | (pin + 10)),
34711 - "S" (&pci_indirect));
34712 + "S" (&pci_indirect),
34713 + "r" (__PCIBIOS_DS));
34714 return !(ret & 0xff00);
34715 }
34716 EXPORT_SYMBOL(pcibios_set_irq_routing);
34717 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34718 index 40e7cda..c7e6672 100644
34719 --- a/arch/x86/platform/efi/efi_32.c
34720 +++ b/arch/x86/platform/efi/efi_32.c
34721 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34722 {
34723 struct desc_ptr gdt_descr;
34724
34725 +#ifdef CONFIG_PAX_KERNEXEC
34726 + struct desc_struct d;
34727 +#endif
34728 +
34729 local_irq_save(efi_rt_eflags);
34730
34731 load_cr3(initial_page_table);
34732 __flush_tlb_all();
34733
34734 +#ifdef CONFIG_PAX_KERNEXEC
34735 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34736 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34737 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34738 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34739 +#endif
34740 +
34741 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34742 gdt_descr.size = GDT_SIZE - 1;
34743 load_gdt(&gdt_descr);
34744 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34745 {
34746 struct desc_ptr gdt_descr;
34747
34748 +#ifdef CONFIG_PAX_KERNEXEC
34749 + struct desc_struct d;
34750 +
34751 + memset(&d, 0, sizeof d);
34752 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34753 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34754 +#endif
34755 +
34756 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34757 gdt_descr.size = GDT_SIZE - 1;
34758 load_gdt(&gdt_descr);
34759
34760 +#ifdef CONFIG_PAX_PER_CPU_PGD
34761 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34762 +#else
34763 load_cr3(swapper_pg_dir);
34764 +#endif
34765 +
34766 __flush_tlb_all();
34767
34768 local_irq_restore(efi_rt_eflags);
34769 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34770 index 35aecb6..46177db 100644
34771 --- a/arch/x86/platform/efi/efi_64.c
34772 +++ b/arch/x86/platform/efi/efi_64.c
34773 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34774 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34775 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34776 }
34777 +
34778 +#ifdef CONFIG_PAX_PER_CPU_PGD
34779 + load_cr3(swapper_pg_dir);
34780 +#endif
34781 +
34782 __flush_tlb_all();
34783 }
34784
34785 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34786 for (pgd = 0; pgd < n_pgds; pgd++)
34787 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34788 kfree(save_pgd);
34789 +
34790 +#ifdef CONFIG_PAX_PER_CPU_PGD
34791 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34792 +#endif
34793 +
34794 __flush_tlb_all();
34795 local_irq_restore(efi_flags);
34796 early_code_mapping_set_exec(0);
34797 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34798 unsigned npages;
34799 pgd_t *pgd;
34800
34801 - if (efi_enabled(EFI_OLD_MEMMAP))
34802 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34803 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34804 + * able to execute the EFI services.
34805 + */
34806 + if (__supported_pte_mask & _PAGE_NX) {
34807 + unsigned long addr = (unsigned long) __va(0);
34808 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34809 +
34810 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34811 +#ifdef CONFIG_PAX_PER_CPU_PGD
34812 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34813 +#endif
34814 + set_pgd(pgd_offset_k(addr), pe);
34815 + }
34816 +
34817 return 0;
34818 + }
34819
34820 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34821 pgd = __va(efi_scratch.efi_pgt);
34822 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34823 index 040192b..7d3300f 100644
34824 --- a/arch/x86/platform/efi/efi_stub_32.S
34825 +++ b/arch/x86/platform/efi/efi_stub_32.S
34826 @@ -6,7 +6,9 @@
34827 */
34828
34829 #include <linux/linkage.h>
34830 +#include <linux/init.h>
34831 #include <asm/page_types.h>
34832 +#include <asm/segment.h>
34833
34834 /*
34835 * efi_call_phys(void *, ...) is a function with variable parameters.
34836 @@ -20,7 +22,7 @@
34837 * service functions will comply with gcc calling convention, too.
34838 */
34839
34840 -.text
34841 +__INIT
34842 ENTRY(efi_call_phys)
34843 /*
34844 * 0. The function can only be called in Linux kernel. So CS has been
34845 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34846 * The mapping of lower virtual memory has been created in prolog and
34847 * epilog.
34848 */
34849 - movl $1f, %edx
34850 - subl $__PAGE_OFFSET, %edx
34851 - jmp *%edx
34852 +#ifdef CONFIG_PAX_KERNEXEC
34853 + movl $(__KERNEXEC_EFI_DS), %edx
34854 + mov %edx, %ds
34855 + mov %edx, %es
34856 + mov %edx, %ss
34857 + addl $2f,(1f)
34858 + ljmp *(1f)
34859 +
34860 +__INITDATA
34861 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34862 +.previous
34863 +
34864 +2:
34865 + subl $2b,(1b)
34866 +#else
34867 + jmp 1f-__PAGE_OFFSET
34868 1:
34869 +#endif
34870
34871 /*
34872 * 2. Now on the top of stack is the return
34873 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34874 * parameter 2, ..., param n. To make things easy, we save the return
34875 * address of efi_call_phys in a global variable.
34876 */
34877 - popl %edx
34878 - movl %edx, saved_return_addr
34879 - /* get the function pointer into ECX*/
34880 - popl %ecx
34881 - movl %ecx, efi_rt_function_ptr
34882 - movl $2f, %edx
34883 - subl $__PAGE_OFFSET, %edx
34884 - pushl %edx
34885 + popl (saved_return_addr)
34886 + popl (efi_rt_function_ptr)
34887
34888 /*
34889 * 3. Clear PG bit in %CR0.
34890 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34891 /*
34892 * 5. Call the physical function.
34893 */
34894 - jmp *%ecx
34895 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34896
34897 -2:
34898 /*
34899 * 6. After EFI runtime service returns, control will return to
34900 * following instruction. We'd better readjust stack pointer first.
34901 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34902 movl %cr0, %edx
34903 orl $0x80000000, %edx
34904 movl %edx, %cr0
34905 - jmp 1f
34906 -1:
34907 +
34908 /*
34909 * 8. Now restore the virtual mode from flat mode by
34910 * adding EIP with PAGE_OFFSET.
34911 */
34912 - movl $1f, %edx
34913 - jmp *%edx
34914 +#ifdef CONFIG_PAX_KERNEXEC
34915 + movl $(__KERNEL_DS), %edx
34916 + mov %edx, %ds
34917 + mov %edx, %es
34918 + mov %edx, %ss
34919 + ljmp $(__KERNEL_CS),$1f
34920 +#else
34921 + jmp 1f+__PAGE_OFFSET
34922 +#endif
34923 1:
34924
34925 /*
34926 * 9. Balance the stack. And because EAX contain the return value,
34927 * we'd better not clobber it.
34928 */
34929 - leal efi_rt_function_ptr, %edx
34930 - movl (%edx), %ecx
34931 - pushl %ecx
34932 + pushl (efi_rt_function_ptr)
34933
34934 /*
34935 - * 10. Push the saved return address onto the stack and return.
34936 + * 10. Return to the saved return address.
34937 */
34938 - leal saved_return_addr, %edx
34939 - movl (%edx), %ecx
34940 - pushl %ecx
34941 - ret
34942 + jmpl *(saved_return_addr)
34943 ENDPROC(efi_call_phys)
34944 .previous
34945
34946 -.data
34947 +__INITDATA
34948 saved_return_addr:
34949 .long 0
34950 efi_rt_function_ptr:
34951 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34952 index 5fcda72..cd4dc41 100644
34953 --- a/arch/x86/platform/efi/efi_stub_64.S
34954 +++ b/arch/x86/platform/efi/efi_stub_64.S
34955 @@ -11,6 +11,7 @@
34956 #include <asm/msr.h>
34957 #include <asm/processor-flags.h>
34958 #include <asm/page_types.h>
34959 +#include <asm/alternative-asm.h>
34960
34961 #define SAVE_XMM \
34962 mov %rsp, %rax; \
34963 @@ -88,6 +89,7 @@ ENTRY(efi_call)
34964 RESTORE_PGT
34965 addq $48, %rsp
34966 RESTORE_XMM
34967 + pax_force_retaddr 0, 1
34968 ret
34969 ENDPROC(efi_call)
34970
34971 @@ -245,8 +247,8 @@ efi_gdt64:
34972 .long 0 /* Filled out by user */
34973 .word 0
34974 .quad 0x0000000000000000 /* NULL descriptor */
34975 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
34976 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
34977 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
34978 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
34979 .quad 0x0080890000000000 /* TS descriptor */
34980 .quad 0x0000000000000000 /* TS continued */
34981 efi_gdt64_end:
34982 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34983 index 1bbedc4..eb795b5 100644
34984 --- a/arch/x86/platform/intel-mid/intel-mid.c
34985 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34986 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34987 {
34988 };
34989
34990 -static void intel_mid_reboot(void)
34991 +static void __noreturn intel_mid_reboot(void)
34992 {
34993 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34994 + BUG();
34995 }
34996
34997 static unsigned long __init intel_mid_calibrate_tsc(void)
34998 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34999 index 3c1c386..59a68ed 100644
35000 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35001 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35002 @@ -13,6 +13,6 @@
35003 /* For every CPU addition a new get_<cpuname>_ops interface needs
35004 * to be added.
35005 */
35006 -extern void *get_penwell_ops(void);
35007 -extern void *get_cloverview_ops(void);
35008 -extern void *get_tangier_ops(void);
35009 +extern const void *get_penwell_ops(void);
35010 +extern const void *get_cloverview_ops(void);
35011 +extern const void *get_tangier_ops(void);
35012 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35013 index 23381d2..8ddc10e 100644
35014 --- a/arch/x86/platform/intel-mid/mfld.c
35015 +++ b/arch/x86/platform/intel-mid/mfld.c
35016 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35017 pm_power_off = mfld_power_off;
35018 }
35019
35020 -void *get_penwell_ops(void)
35021 +const void *get_penwell_ops(void)
35022 {
35023 return &penwell_ops;
35024 }
35025
35026 -void *get_cloverview_ops(void)
35027 +const void *get_cloverview_ops(void)
35028 {
35029 return &penwell_ops;
35030 }
35031 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35032 index aaca917..66eadbc 100644
35033 --- a/arch/x86/platform/intel-mid/mrfl.c
35034 +++ b/arch/x86/platform/intel-mid/mrfl.c
35035 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35036 .arch_setup = tangier_arch_setup,
35037 };
35038
35039 -void *get_tangier_ops(void)
35040 +const void *get_tangier_ops(void)
35041 {
35042 return &tangier_ops;
35043 }
35044 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35045 index d6ee929..3637cb5 100644
35046 --- a/arch/x86/platform/olpc/olpc_dt.c
35047 +++ b/arch/x86/platform/olpc/olpc_dt.c
35048 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35049 return res;
35050 }
35051
35052 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35053 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35054 .nextprop = olpc_dt_nextprop,
35055 .getproplen = olpc_dt_getproplen,
35056 .getproperty = olpc_dt_getproperty,
35057 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35058 index 6ec7910..ecdbb11 100644
35059 --- a/arch/x86/power/cpu.c
35060 +++ b/arch/x86/power/cpu.c
35061 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35062 static void fix_processor_context(void)
35063 {
35064 int cpu = smp_processor_id();
35065 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35066 -#ifdef CONFIG_X86_64
35067 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35068 - tss_desc tss;
35069 -#endif
35070 + struct tss_struct *t = init_tss + cpu;
35071 +
35072 set_tss_desc(cpu, t); /*
35073 * This just modifies memory; should not be
35074 * necessary. But... This is necessary, because
35075 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35076 */
35077
35078 #ifdef CONFIG_X86_64
35079 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35080 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35081 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35082 -
35083 syscall_init(); /* This sets MSR_*STAR and related */
35084 #endif
35085 load_TR_desc(); /* This does ltr */
35086 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35087 index bad628a..a102610 100644
35088 --- a/arch/x86/realmode/init.c
35089 +++ b/arch/x86/realmode/init.c
35090 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35091 __va(real_mode_header->trampoline_header);
35092
35093 #ifdef CONFIG_X86_32
35094 - trampoline_header->start = __pa_symbol(startup_32_smp);
35095 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35096 +
35097 +#ifdef CONFIG_PAX_KERNEXEC
35098 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35099 +#endif
35100 +
35101 + trampoline_header->boot_cs = __BOOT_CS;
35102 trampoline_header->gdt_limit = __BOOT_DS + 7;
35103 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35104 #else
35105 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35106 *trampoline_cr4_features = read_cr4();
35107
35108 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35109 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35110 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35111 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35112 #endif
35113 }
35114 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35115 index 7c0d7be..d24dc88 100644
35116 --- a/arch/x86/realmode/rm/Makefile
35117 +++ b/arch/x86/realmode/rm/Makefile
35118 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35119
35120 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35121 -I$(srctree)/arch/x86/boot
35122 +ifdef CONSTIFY_PLUGIN
35123 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35124 +endif
35125 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35126 GCOV_PROFILE := n
35127 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35128 index a28221d..93c40f1 100644
35129 --- a/arch/x86/realmode/rm/header.S
35130 +++ b/arch/x86/realmode/rm/header.S
35131 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35132 #endif
35133 /* APM/BIOS reboot */
35134 .long pa_machine_real_restart_asm
35135 -#ifdef CONFIG_X86_64
35136 +#ifdef CONFIG_X86_32
35137 + .long __KERNEL_CS
35138 +#else
35139 .long __KERNEL32_CS
35140 #endif
35141 END(real_mode_header)
35142 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35143 index 48ddd76..c26749f 100644
35144 --- a/arch/x86/realmode/rm/trampoline_32.S
35145 +++ b/arch/x86/realmode/rm/trampoline_32.S
35146 @@ -24,6 +24,12 @@
35147 #include <asm/page_types.h>
35148 #include "realmode.h"
35149
35150 +#ifdef CONFIG_PAX_KERNEXEC
35151 +#define ta(X) (X)
35152 +#else
35153 +#define ta(X) (pa_ ## X)
35154 +#endif
35155 +
35156 .text
35157 .code16
35158
35159 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35160
35161 cli # We should be safe anyway
35162
35163 - movl tr_start, %eax # where we need to go
35164 -
35165 movl $0xA5A5A5A5, trampoline_status
35166 # write marker for master knows we're running
35167
35168 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35169 movw $1, %dx # protected mode (PE) bit
35170 lmsw %dx # into protected mode
35171
35172 - ljmpl $__BOOT_CS, $pa_startup_32
35173 + ljmpl *(trampoline_header)
35174
35175 .section ".text32","ax"
35176 .code32
35177 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35178 .balign 8
35179 GLOBAL(trampoline_header)
35180 tr_start: .space 4
35181 - tr_gdt_pad: .space 2
35182 + tr_boot_cs: .space 2
35183 tr_gdt: .space 6
35184 END(trampoline_header)
35185
35186 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35187 index dac7b20..72dbaca 100644
35188 --- a/arch/x86/realmode/rm/trampoline_64.S
35189 +++ b/arch/x86/realmode/rm/trampoline_64.S
35190 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35191 movl %edx, %gs
35192
35193 movl pa_tr_cr4, %eax
35194 + andl $~X86_CR4_PCIDE, %eax
35195 movl %eax, %cr4 # Enable PAE mode
35196
35197 # Setup trampoline 4 level pagetables
35198 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35199 wrmsr
35200
35201 # Enable paging and in turn activate Long Mode
35202 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35203 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35204 movl %eax, %cr0
35205
35206 /*
35207 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35208 index 9e7e147..25a4158 100644
35209 --- a/arch/x86/realmode/rm/wakeup_asm.S
35210 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35211 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35212 lgdtl pmode_gdt
35213
35214 /* This really couldn't... */
35215 - movl pmode_entry, %eax
35216 movl pmode_cr0, %ecx
35217 movl %ecx, %cr0
35218 - ljmpl $__KERNEL_CS, $pa_startup_32
35219 - /* -> jmp *%eax in trampoline_32.S */
35220 +
35221 + ljmpl *pmode_entry
35222 #else
35223 jmp trampoline_start
35224 #endif
35225 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35226 index 604a37e..e49702a 100644
35227 --- a/arch/x86/tools/Makefile
35228 +++ b/arch/x86/tools/Makefile
35229 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35230
35231 $(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
35232
35233 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35234 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35235 hostprogs-y += relocs
35236 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35237 PHONY += relocs
35238 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35239 index a5efb21..97490e9 100644
35240 --- a/arch/x86/tools/relocs.c
35241 +++ b/arch/x86/tools/relocs.c
35242 @@ -1,5 +1,7 @@
35243 /* This is included from relocs_32/64.c */
35244
35245 +#include "../../../include/generated/autoconf.h"
35246 +
35247 #define ElfW(type) _ElfW(ELF_BITS, type)
35248 #define _ElfW(bits, type) __ElfW(bits, type)
35249 #define __ElfW(bits, type) Elf##bits##_##type
35250 @@ -11,6 +13,7 @@
35251 #define Elf_Sym ElfW(Sym)
35252
35253 static Elf_Ehdr ehdr;
35254 +static Elf_Phdr *phdr;
35255
35256 struct relocs {
35257 uint32_t *offset;
35258 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35259 }
35260 }
35261
35262 +static void read_phdrs(FILE *fp)
35263 +{
35264 + unsigned int i;
35265 +
35266 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35267 + if (!phdr) {
35268 + die("Unable to allocate %d program headers\n",
35269 + ehdr.e_phnum);
35270 + }
35271 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35272 + die("Seek to %d failed: %s\n",
35273 + ehdr.e_phoff, strerror(errno));
35274 + }
35275 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35276 + die("Cannot read ELF program headers: %s\n",
35277 + strerror(errno));
35278 + }
35279 + for(i = 0; i < ehdr.e_phnum; i++) {
35280 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35281 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35282 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35283 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35284 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35285 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35286 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35287 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35288 + }
35289 +
35290 +}
35291 +
35292 static void read_shdrs(FILE *fp)
35293 {
35294 - int i;
35295 + unsigned int i;
35296 Elf_Shdr shdr;
35297
35298 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35299 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35300
35301 static void read_strtabs(FILE *fp)
35302 {
35303 - int i;
35304 + unsigned int i;
35305 for (i = 0; i < ehdr.e_shnum; i++) {
35306 struct section *sec = &secs[i];
35307 if (sec->shdr.sh_type != SHT_STRTAB) {
35308 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35309
35310 static void read_symtabs(FILE *fp)
35311 {
35312 - int i,j;
35313 + unsigned int i,j;
35314 for (i = 0; i < ehdr.e_shnum; i++) {
35315 struct section *sec = &secs[i];
35316 if (sec->shdr.sh_type != SHT_SYMTAB) {
35317 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35318 }
35319
35320
35321 -static void read_relocs(FILE *fp)
35322 +static void read_relocs(FILE *fp, int use_real_mode)
35323 {
35324 - int i,j;
35325 + unsigned int i,j;
35326 + uint32_t base;
35327 +
35328 for (i = 0; i < ehdr.e_shnum; i++) {
35329 struct section *sec = &secs[i];
35330 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35331 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35332 die("Cannot read symbol table: %s\n",
35333 strerror(errno));
35334 }
35335 + base = 0;
35336 +
35337 +#ifdef CONFIG_X86_32
35338 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35339 + if (phdr[j].p_type != PT_LOAD )
35340 + continue;
35341 + 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)
35342 + continue;
35343 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35344 + break;
35345 + }
35346 +#endif
35347 +
35348 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35349 Elf_Rel *rel = &sec->reltab[j];
35350 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35351 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35352 rel->r_info = elf_xword_to_cpu(rel->r_info);
35353 #if (SHT_REL_TYPE == SHT_RELA)
35354 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35355 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35356
35357 static void print_absolute_symbols(void)
35358 {
35359 - int i;
35360 + unsigned int i;
35361 const char *format;
35362
35363 if (ELF_BITS == 64)
35364 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35365 for (i = 0; i < ehdr.e_shnum; i++) {
35366 struct section *sec = &secs[i];
35367 char *sym_strtab;
35368 - int j;
35369 + unsigned int j;
35370
35371 if (sec->shdr.sh_type != SHT_SYMTAB) {
35372 continue;
35373 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35374
35375 static void print_absolute_relocs(void)
35376 {
35377 - int i, printed = 0;
35378 + unsigned int i, printed = 0;
35379 const char *format;
35380
35381 if (ELF_BITS == 64)
35382 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35383 struct section *sec_applies, *sec_symtab;
35384 char *sym_strtab;
35385 Elf_Sym *sh_symtab;
35386 - int j;
35387 + unsigned int j;
35388 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35389 continue;
35390 }
35391 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35392 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35393 Elf_Sym *sym, const char *symname))
35394 {
35395 - int i;
35396 + unsigned int i;
35397 /* Walk through the relocations */
35398 for (i = 0; i < ehdr.e_shnum; i++) {
35399 char *sym_strtab;
35400 Elf_Sym *sh_symtab;
35401 struct section *sec_applies, *sec_symtab;
35402 - int j;
35403 + unsigned int j;
35404 struct section *sec = &secs[i];
35405
35406 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35407 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35408 {
35409 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35410 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35411 + char *sym_strtab = sec->link->link->strtab;
35412 +
35413 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35414 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35415 + return 0;
35416 +
35417 +#ifdef CONFIG_PAX_KERNEXEC
35418 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35419 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35420 + return 0;
35421 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35422 + return 0;
35423 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35424 + return 0;
35425 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35426 + return 0;
35427 +#endif
35428
35429 switch (r_type) {
35430 case R_386_NONE:
35431 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35432
35433 static void emit_relocs(int as_text, int use_real_mode)
35434 {
35435 - int i;
35436 + unsigned int i;
35437 int (*write_reloc)(uint32_t, FILE *) = write32;
35438 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35439 const char *symname);
35440 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35441 {
35442 regex_init(use_real_mode);
35443 read_ehdr(fp);
35444 + read_phdrs(fp);
35445 read_shdrs(fp);
35446 read_strtabs(fp);
35447 read_symtabs(fp);
35448 - read_relocs(fp);
35449 + read_relocs(fp, use_real_mode);
35450 if (ELF_BITS == 64)
35451 percpu_init();
35452 if (show_absolute_syms) {
35453 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35454 index f40281e..92728c9 100644
35455 --- a/arch/x86/um/mem_32.c
35456 +++ b/arch/x86/um/mem_32.c
35457 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35458 gate_vma.vm_start = FIXADDR_USER_START;
35459 gate_vma.vm_end = FIXADDR_USER_END;
35460 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35461 - gate_vma.vm_page_prot = __P101;
35462 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35463
35464 return 0;
35465 }
35466 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35467 index 80ffa5b..a33bd15 100644
35468 --- a/arch/x86/um/tls_32.c
35469 +++ b/arch/x86/um/tls_32.c
35470 @@ -260,7 +260,7 @@ out:
35471 if (unlikely(task == current &&
35472 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35473 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35474 - "without flushed TLS.", current->pid);
35475 + "without flushed TLS.", task_pid_nr(current));
35476 }
35477
35478 return 0;
35479 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35480 index 5a4affe..9e2d522 100644
35481 --- a/arch/x86/vdso/Makefile
35482 +++ b/arch/x86/vdso/Makefile
35483 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35484 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35485 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35486
35487 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35488 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35489 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35490 GCOV_PROFILE := n
35491
35492 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35493 index 0224987..c7d65a5 100644
35494 --- a/arch/x86/vdso/vdso2c.h
35495 +++ b/arch/x86/vdso/vdso2c.h
35496 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35497 unsigned long load_size = -1; /* Work around bogus warning */
35498 unsigned long mapping_size;
35499 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35500 - int i;
35501 + unsigned int i;
35502 unsigned long j;
35503 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35504 *alt_sec = NULL;
35505 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35506 index e904c27..b9eaa03 100644
35507 --- a/arch/x86/vdso/vdso32-setup.c
35508 +++ b/arch/x86/vdso/vdso32-setup.c
35509 @@ -14,6 +14,7 @@
35510 #include <asm/cpufeature.h>
35511 #include <asm/processor.h>
35512 #include <asm/vdso.h>
35513 +#include <asm/mman.h>
35514
35515 #ifdef CONFIG_COMPAT_VDSO
35516 #define VDSO_DEFAULT 0
35517 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35518 index 208c220..54f1447 100644
35519 --- a/arch/x86/vdso/vma.c
35520 +++ b/arch/x86/vdso/vma.c
35521 @@ -16,10 +16,9 @@
35522 #include <asm/vdso.h>
35523 #include <asm/page.h>
35524 #include <asm/hpet.h>
35525 +#include <asm/mman.h>
35526
35527 #if defined(CONFIG_X86_64)
35528 -unsigned int __read_mostly vdso64_enabled = 1;
35529 -
35530 extern unsigned short vdso_sync_cpuid;
35531 #endif
35532
35533 @@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35534 .pages = no_pages,
35535 };
35536
35537 +#ifdef CONFIG_PAX_RANDMMAP
35538 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35539 + calculate_addr = false;
35540 +#endif
35541 +
35542 if (calculate_addr) {
35543 addr = vdso_addr(current->mm->start_stack,
35544 image->size - image->sym_vvar_start);
35545 @@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35546 down_write(&mm->mmap_sem);
35547
35548 addr = get_unmapped_area(NULL, addr,
35549 - image->size - image->sym_vvar_start, 0, 0);
35550 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35551 if (IS_ERR_VALUE(addr)) {
35552 ret = addr;
35553 goto up_fail;
35554 }
35555
35556 text_start = addr - image->sym_vvar_start;
35557 - current->mm->context.vdso = (void __user *)text_start;
35558 + mm->context.vdso = text_start;
35559
35560 /*
35561 * MAYWRITE to allow gdb to COW and set breakpoints
35562 @@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35563 hpet_address >> PAGE_SHIFT,
35564 PAGE_SIZE,
35565 pgprot_noncached(PAGE_READONLY));
35566 -
35567 - if (ret)
35568 - goto up_fail;
35569 }
35570 #endif
35571
35572 up_fail:
35573 if (ret)
35574 - current->mm->context.vdso = NULL;
35575 + current->mm->context.vdso = 0;
35576
35577 up_write(&mm->mmap_sem);
35578 return ret;
35579 @@ -204,8 +205,8 @@ static int load_vdso32(void)
35580
35581 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35582 current_thread_info()->sysenter_return =
35583 - current->mm->context.vdso +
35584 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35585 + (void __force_user *)(current->mm->context.vdso +
35586 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35587
35588 return 0;
35589 }
35590 @@ -214,9 +215,6 @@ static int load_vdso32(void)
35591 #ifdef CONFIG_X86_64
35592 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35593 {
35594 - if (!vdso64_enabled)
35595 - return 0;
35596 -
35597 return map_vdso(&vdso_image_64, true);
35598 }
35599
35600 @@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35601 int uses_interp)
35602 {
35603 #ifdef CONFIG_X86_X32_ABI
35604 - if (test_thread_flag(TIF_X32)) {
35605 - if (!vdso64_enabled)
35606 - return 0;
35607 -
35608 + if (test_thread_flag(TIF_X32))
35609 return map_vdso(&vdso_image_x32, true);
35610 - }
35611 #endif
35612
35613 return load_vdso32();
35614 @@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35615 return load_vdso32();
35616 }
35617 #endif
35618 -
35619 -#ifdef CONFIG_X86_64
35620 -static __init int vdso_setup(char *s)
35621 -{
35622 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35623 - return 0;
35624 -}
35625 -__setup("vdso=", vdso_setup);
35626 -#endif
35627 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35628 index e88fda8..76ce7ce 100644
35629 --- a/arch/x86/xen/Kconfig
35630 +++ b/arch/x86/xen/Kconfig
35631 @@ -9,6 +9,7 @@ config XEN
35632 select XEN_HAVE_PVMMU
35633 depends on X86_64 || (X86_32 && X86_PAE)
35634 depends on X86_TSC
35635 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35636 help
35637 This is the Linux Xen port. Enabling this will allow the
35638 kernel to boot in a paravirtualized environment under the
35639 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35640 index fac5e4f..89c3525 100644
35641 --- a/arch/x86/xen/enlighten.c
35642 +++ b/arch/x86/xen/enlighten.c
35643 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35644
35645 struct shared_info xen_dummy_shared_info;
35646
35647 -void *xen_initial_gdt;
35648 -
35649 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35650 __read_mostly int xen_have_vector_callback;
35651 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35652 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35653 {
35654 unsigned long va = dtr->address;
35655 unsigned int size = dtr->size + 1;
35656 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35657 - unsigned long frames[pages];
35658 + unsigned long frames[65536 / PAGE_SIZE];
35659 int f;
35660
35661 /*
35662 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35663 {
35664 unsigned long va = dtr->address;
35665 unsigned int size = dtr->size + 1;
35666 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35667 - unsigned long frames[pages];
35668 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35669 int f;
35670
35671 /*
35672 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35673 * 8-byte entries, or 16 4k pages..
35674 */
35675
35676 - BUG_ON(size > 65536);
35677 + BUG_ON(size > GDT_SIZE);
35678 BUG_ON(va & ~PAGE_MASK);
35679
35680 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35681 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35682 return 0;
35683 }
35684
35685 -static void set_xen_basic_apic_ops(void)
35686 +static void __init set_xen_basic_apic_ops(void)
35687 {
35688 apic->read = xen_apic_read;
35689 apic->write = xen_apic_write;
35690 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35691 #endif
35692 };
35693
35694 -static void xen_reboot(int reason)
35695 +static __noreturn void xen_reboot(int reason)
35696 {
35697 struct sched_shutdown r = { .reason = reason };
35698
35699 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35700 - BUG();
35701 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35702 + BUG();
35703 }
35704
35705 -static void xen_restart(char *msg)
35706 +static __noreturn void xen_restart(char *msg)
35707 {
35708 xen_reboot(SHUTDOWN_reboot);
35709 }
35710
35711 -static void xen_emergency_restart(void)
35712 +static __noreturn void xen_emergency_restart(void)
35713 {
35714 xen_reboot(SHUTDOWN_reboot);
35715 }
35716
35717 -static void xen_machine_halt(void)
35718 +static __noreturn void xen_machine_halt(void)
35719 {
35720 xen_reboot(SHUTDOWN_poweroff);
35721 }
35722
35723 -static void xen_machine_power_off(void)
35724 +static __noreturn void xen_machine_power_off(void)
35725 {
35726 if (pm_power_off)
35727 pm_power_off();
35728 @@ -1456,8 +1452,11 @@ static void __ref xen_setup_gdt(int cpu)
35729 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35730 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35731
35732 - setup_stack_canary_segment(0);
35733 - switch_to_new_gdt(0);
35734 + setup_stack_canary_segment(cpu);
35735 +#ifdef CONFIG_X86_64
35736 + load_percpu_segment(cpu);
35737 +#endif
35738 + switch_to_new_gdt(cpu);
35739
35740 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35741 pv_cpu_ops.load_gdt = xen_load_gdt;
35742 @@ -1573,7 +1572,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35743 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35744
35745 /* Work out if we support NX */
35746 - x86_configure_nx();
35747 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35748 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35749 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35750 + unsigned l, h;
35751 +
35752 + __supported_pte_mask |= _PAGE_NX;
35753 + rdmsr(MSR_EFER, l, h);
35754 + l |= EFER_NX;
35755 + wrmsr(MSR_EFER, l, h);
35756 + }
35757 +#endif
35758
35759 /* Get mfn list */
35760 xen_build_dynamic_phys_to_machine();
35761 @@ -1601,13 +1610,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35762
35763 machine_ops = xen_machine_ops;
35764
35765 - /*
35766 - * The only reliable way to retain the initial address of the
35767 - * percpu gdt_page is to remember it here, so we can go and
35768 - * mark it RW later, when the initial percpu area is freed.
35769 - */
35770 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35771 -
35772 xen_smp_init();
35773
35774 #ifdef CONFIG_ACPI_NUMA
35775 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35776 index a8a1a3d..8216142 100644
35777 --- a/arch/x86/xen/mmu.c
35778 +++ b/arch/x86/xen/mmu.c
35779 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35780 return val;
35781 }
35782
35783 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35784 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35785 {
35786 if (val & _PAGE_PRESENT) {
35787 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35788 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35789 * L3_k[511] -> level2_fixmap_pgt */
35790 convert_pfn_mfn(level3_kernel_pgt);
35791
35792 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35793 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35794 + convert_pfn_mfn(level3_vmemmap_pgt);
35795 /* L3_k[511][506] -> level1_fixmap_pgt */
35796 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35797 convert_pfn_mfn(level2_fixmap_pgt);
35798 }
35799 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35800 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35801 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35802 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35803 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35804 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35805 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35806 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35807 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35808 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35809 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35810 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35811 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35812 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35813 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35814
35815 /* Pin down new L4 */
35816 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35817 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35818 pv_mmu_ops.set_pud = xen_set_pud;
35819 #if PAGETABLE_LEVELS == 4
35820 pv_mmu_ops.set_pgd = xen_set_pgd;
35821 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35822 #endif
35823
35824 /* This will work as long as patching hasn't happened yet
35825 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35826 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35827 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35828 .set_pgd = xen_set_pgd_hyper,
35829 + .set_pgd_batched = xen_set_pgd_hyper,
35830
35831 .alloc_pud = xen_alloc_pmd_init,
35832 .release_pud = xen_release_pmd_init,
35833 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35834 index 4c071ae..00e7049 100644
35835 --- a/arch/x86/xen/smp.c
35836 +++ b/arch/x86/xen/smp.c
35837 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35838
35839 if (xen_pv_domain()) {
35840 if (!xen_feature(XENFEAT_writable_page_tables))
35841 - /* We've switched to the "real" per-cpu gdt, so make
35842 - * sure the old memory can be recycled. */
35843 - make_lowmem_page_readwrite(xen_initial_gdt);
35844 -
35845 #ifdef CONFIG_X86_32
35846 /*
35847 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35848 * expects __USER_DS
35849 */
35850 - loadsegment(ds, __USER_DS);
35851 - loadsegment(es, __USER_DS);
35852 + loadsegment(ds, __KERNEL_DS);
35853 + loadsegment(es, __KERNEL_DS);
35854 #endif
35855
35856 xen_filter_cpu_maps();
35857 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35858 #ifdef CONFIG_X86_32
35859 /* Note: PVH is not yet supported on x86_32. */
35860 ctxt->user_regs.fs = __KERNEL_PERCPU;
35861 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35862 + savesegment(gs, ctxt->user_regs.gs);
35863 #endif
35864 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35865
35866 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35867 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35868 ctxt->flags = VGCF_IN_KERNEL;
35869 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35870 - ctxt->user_regs.ds = __USER_DS;
35871 - ctxt->user_regs.es = __USER_DS;
35872 + ctxt->user_regs.ds = __KERNEL_DS;
35873 + ctxt->user_regs.es = __KERNEL_DS;
35874 ctxt->user_regs.ss = __KERNEL_DS;
35875
35876 xen_copy_trap_info(ctxt->trap_ctxt);
35877 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35878 int rc;
35879
35880 per_cpu(current_task, cpu) = idle;
35881 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35882 #ifdef CONFIG_X86_32
35883 irq_ctx_init(cpu);
35884 #else
35885 clear_tsk_thread_flag(idle, TIF_FORK);
35886 #endif
35887 - per_cpu(kernel_stack, cpu) =
35888 - (unsigned long)task_stack_page(idle) -
35889 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35890 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35891
35892 xen_setup_runstate_info(cpu);
35893 xen_setup_timer(cpu);
35894 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35895
35896 void __init xen_smp_init(void)
35897 {
35898 - smp_ops = xen_smp_ops;
35899 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35900 xen_fill_possible_map();
35901 }
35902
35903 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35904 index fd92a64..1f72641 100644
35905 --- a/arch/x86/xen/xen-asm_32.S
35906 +++ b/arch/x86/xen/xen-asm_32.S
35907 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35908 pushw %fs
35909 movl $(__KERNEL_PERCPU), %eax
35910 movl %eax, %fs
35911 - movl %fs:xen_vcpu, %eax
35912 + mov PER_CPU_VAR(xen_vcpu), %eax
35913 POP_FS
35914 #else
35915 movl %ss:xen_vcpu, %eax
35916 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35917 index 674b2225..f1f5dc1 100644
35918 --- a/arch/x86/xen/xen-head.S
35919 +++ b/arch/x86/xen/xen-head.S
35920 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35921 #ifdef CONFIG_X86_32
35922 mov %esi,xen_start_info
35923 mov $init_thread_union+THREAD_SIZE,%esp
35924 +#ifdef CONFIG_SMP
35925 + movl $cpu_gdt_table,%edi
35926 + movl $__per_cpu_load,%eax
35927 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35928 + rorl $16,%eax
35929 + movb %al,__KERNEL_PERCPU + 4(%edi)
35930 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35931 + movl $__per_cpu_end - 1,%eax
35932 + subl $__per_cpu_start,%eax
35933 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35934 +#endif
35935 #else
35936 mov %rsi,xen_start_info
35937 mov $init_thread_union+THREAD_SIZE,%rsp
35938 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35939 index 28c7e0b..2acfec7 100644
35940 --- a/arch/x86/xen/xen-ops.h
35941 +++ b/arch/x86/xen/xen-ops.h
35942 @@ -10,8 +10,6 @@
35943 extern const char xen_hypervisor_callback[];
35944 extern const char xen_failsafe_callback[];
35945
35946 -extern void *xen_initial_gdt;
35947 -
35948 struct trap_info;
35949 void xen_copy_trap_info(struct trap_info *traps);
35950
35951 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35952 index 525bd3d..ef888b1 100644
35953 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35954 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35955 @@ -119,9 +119,9 @@
35956 ----------------------------------------------------------------------*/
35957
35958 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35959 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35960 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35961 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35962 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35963
35964 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35965 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35966 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35967 index 2f33760..835e50a 100644
35968 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35969 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35970 @@ -11,6 +11,7 @@
35971 #ifndef _XTENSA_CORE_H
35972 #define _XTENSA_CORE_H
35973
35974 +#include <linux/const.h>
35975
35976 /****************************************************************************
35977 Parameters Useful for Any Code, USER or PRIVILEGED
35978 @@ -112,9 +113,9 @@
35979 ----------------------------------------------------------------------*/
35980
35981 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35982 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35983 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35984 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35985 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35986
35987 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35988 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35989 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35990 index af00795..2bb8105 100644
35991 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35992 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35993 @@ -11,6 +11,7 @@
35994 #ifndef _XTENSA_CORE_CONFIGURATION_H
35995 #define _XTENSA_CORE_CONFIGURATION_H
35996
35997 +#include <linux/const.h>
35998
35999 /****************************************************************************
36000 Parameters Useful for Any Code, USER or PRIVILEGED
36001 @@ -118,9 +119,9 @@
36002 ----------------------------------------------------------------------*/
36003
36004 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36005 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36006 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36007 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36008 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36009
36010 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36011 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36012 diff --git a/block/bio.c b/block/bio.c
36013 index 3e6e198..5c65199 100644
36014 --- a/block/bio.c
36015 +++ b/block/bio.c
36016 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36017 /*
36018 * Overflow, abort
36019 */
36020 - if (end < start)
36021 + if (end < start || end - start > INT_MAX - nr_pages)
36022 return ERR_PTR(-EINVAL);
36023
36024 nr_pages += end - start;
36025 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36026 /*
36027 * Overflow, abort
36028 */
36029 - if (end < start)
36030 + if (end < start || end - start > INT_MAX - nr_pages)
36031 return ERR_PTR(-EINVAL);
36032
36033 nr_pages += end - start;
36034 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36035 const int read = bio_data_dir(bio) == READ;
36036 struct bio_map_data *bmd = bio->bi_private;
36037 int i;
36038 - char *p = bmd->sgvecs[0].iov_base;
36039 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36040
36041 bio_for_each_segment_all(bvec, bio, i) {
36042 char *addr = page_address(bvec->bv_page);
36043 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36044 index 0736729..2ec3b48 100644
36045 --- a/block/blk-iopoll.c
36046 +++ b/block/blk-iopoll.c
36047 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36048 }
36049 EXPORT_SYMBOL(blk_iopoll_complete);
36050
36051 -static void blk_iopoll_softirq(struct softirq_action *h)
36052 +static __latent_entropy void blk_iopoll_softirq(void)
36053 {
36054 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36055 int rearm = 0, budget = blk_iopoll_budget;
36056 diff --git a/block/blk-map.c b/block/blk-map.c
36057 index f890d43..97b0482 100644
36058 --- a/block/blk-map.c
36059 +++ b/block/blk-map.c
36060 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36061 if (!len || !kbuf)
36062 return -EINVAL;
36063
36064 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36065 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36066 if (do_copy)
36067 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36068 else
36069 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36070 index 53b1737..08177d2e 100644
36071 --- a/block/blk-softirq.c
36072 +++ b/block/blk-softirq.c
36073 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36074 * Softirq action handler - move entries to local list and loop over them
36075 * while passing them to the queue registered handler.
36076 */
36077 -static void blk_done_softirq(struct softirq_action *h)
36078 +static __latent_entropy void blk_done_softirq(void)
36079 {
36080 struct list_head *cpu_list, local_list;
36081
36082 diff --git a/block/bsg.c b/block/bsg.c
36083 index 276e869..6fe4c61 100644
36084 --- a/block/bsg.c
36085 +++ b/block/bsg.c
36086 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36087 struct sg_io_v4 *hdr, struct bsg_device *bd,
36088 fmode_t has_write_perm)
36089 {
36090 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36091 + unsigned char *cmdptr;
36092 +
36093 if (hdr->request_len > BLK_MAX_CDB) {
36094 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36095 if (!rq->cmd)
36096 return -ENOMEM;
36097 - }
36098 + cmdptr = rq->cmd;
36099 + } else
36100 + cmdptr = tmpcmd;
36101
36102 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36103 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36104 hdr->request_len))
36105 return -EFAULT;
36106
36107 + if (cmdptr != rq->cmd)
36108 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36109 +
36110 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36111 if (blk_verify_command(rq->cmd, has_write_perm))
36112 return -EPERM;
36113 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36114 index f678c73..f35aa18 100644
36115 --- a/block/compat_ioctl.c
36116 +++ b/block/compat_ioctl.c
36117 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36118 cgc = compat_alloc_user_space(sizeof(*cgc));
36119 cgc32 = compat_ptr(arg);
36120
36121 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36122 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36123 get_user(data, &cgc32->buffer) ||
36124 put_user(compat_ptr(data), &cgc->buffer) ||
36125 copy_in_user(&cgc->buflen, &cgc32->buflen,
36126 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36127 err |= __get_user(f->spec1, &uf->spec1);
36128 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36129 err |= __get_user(name, &uf->name);
36130 - f->name = compat_ptr(name);
36131 + f->name = (void __force_kernel *)compat_ptr(name);
36132 if (err) {
36133 err = -EFAULT;
36134 goto out;
36135 diff --git a/block/genhd.c b/block/genhd.c
36136 index 0a536dc..b8f7aca 100644
36137 --- a/block/genhd.c
36138 +++ b/block/genhd.c
36139 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36140
36141 /*
36142 * Register device numbers dev..(dev+range-1)
36143 - * range must be nonzero
36144 + * Noop if @range is zero.
36145 * The hash chain is sorted on range, so that subranges can override.
36146 */
36147 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36148 struct kobject *(*probe)(dev_t, int *, void *),
36149 int (*lock)(dev_t, void *), void *data)
36150 {
36151 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36152 + if (range)
36153 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36154 }
36155
36156 EXPORT_SYMBOL(blk_register_region);
36157
36158 +/* undo blk_register_region(), noop if @range is zero */
36159 void blk_unregister_region(dev_t devt, unsigned long range)
36160 {
36161 - kobj_unmap(bdev_map, devt, range);
36162 + if (range)
36163 + kobj_unmap(bdev_map, devt, range);
36164 }
36165
36166 EXPORT_SYMBOL(blk_unregister_region);
36167 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36168 index 56d08fd..2e07090 100644
36169 --- a/block/partitions/efi.c
36170 +++ b/block/partitions/efi.c
36171 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36172 if (!gpt)
36173 return NULL;
36174
36175 + if (!le32_to_cpu(gpt->num_partition_entries))
36176 + return NULL;
36177 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36178 + if (!pte)
36179 + return NULL;
36180 +
36181 count = le32_to_cpu(gpt->num_partition_entries) *
36182 le32_to_cpu(gpt->sizeof_partition_entry);
36183 - if (!count)
36184 - return NULL;
36185 - pte = kmalloc(count, GFP_KERNEL);
36186 - if (!pte)
36187 - return NULL;
36188 -
36189 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36190 (u8 *) pte, count) < count) {
36191 kfree(pte);
36192 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36193 index b0c2a61..10bb6ec 100644
36194 --- a/block/scsi_ioctl.c
36195 +++ b/block/scsi_ioctl.c
36196 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36197 return put_user(0, p);
36198 }
36199
36200 -static int sg_get_timeout(struct request_queue *q)
36201 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36202 {
36203 return jiffies_to_clock_t(q->sg_timeout);
36204 }
36205 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36206 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36207 struct sg_io_hdr *hdr, fmode_t mode)
36208 {
36209 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36210 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36211 + unsigned char *cmdptr;
36212 +
36213 + if (rq->cmd != rq->__cmd)
36214 + cmdptr = rq->cmd;
36215 + else
36216 + cmdptr = tmpcmd;
36217 +
36218 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36219 return -EFAULT;
36220 +
36221 + if (cmdptr != rq->cmd)
36222 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36223 +
36224 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36225 return -EPERM;
36226
36227 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36228 int err;
36229 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36230 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36231 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36232 + unsigned char *cmdptr;
36233
36234 if (!sic)
36235 return -EINVAL;
36236 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36237 */
36238 err = -EFAULT;
36239 rq->cmd_len = cmdlen;
36240 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36241 +
36242 + if (rq->cmd != rq->__cmd)
36243 + cmdptr = rq->cmd;
36244 + else
36245 + cmdptr = tmpcmd;
36246 +
36247 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36248 goto error;
36249
36250 + if (rq->cmd != cmdptr)
36251 + memcpy(rq->cmd, cmdptr, cmdlen);
36252 +
36253 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36254 goto error;
36255
36256 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36257 index 650afac1..f3307de 100644
36258 --- a/crypto/cryptd.c
36259 +++ b/crypto/cryptd.c
36260 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36261
36262 struct cryptd_blkcipher_request_ctx {
36263 crypto_completion_t complete;
36264 -};
36265 +} __no_const;
36266
36267 struct cryptd_hash_ctx {
36268 struct crypto_shash *child;
36269 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36270
36271 struct cryptd_aead_request_ctx {
36272 crypto_completion_t complete;
36273 -};
36274 +} __no_const;
36275
36276 static void cryptd_queue_worker(struct work_struct *work);
36277
36278 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36279 index c305d41..a96de79 100644
36280 --- a/crypto/pcrypt.c
36281 +++ b/crypto/pcrypt.c
36282 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36283 int ret;
36284
36285 pinst->kobj.kset = pcrypt_kset;
36286 - ret = kobject_add(&pinst->kobj, NULL, name);
36287 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36288 if (!ret)
36289 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36290
36291 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36292 index 6921c7f..78e1af7 100644
36293 --- a/drivers/acpi/acpica/hwxfsleep.c
36294 +++ b/drivers/acpi/acpica/hwxfsleep.c
36295 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36296 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36297
36298 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36299 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36300 - acpi_hw_extended_sleep},
36301 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36302 - acpi_hw_extended_wake_prep},
36303 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36304 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36305 + .extended_function = acpi_hw_extended_sleep},
36306 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36307 + .extended_function = acpi_hw_extended_wake_prep},
36308 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36309 + .extended_function = acpi_hw_extended_wake}
36310 };
36311
36312 /*
36313 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36314 index 16129c7..8b675cd 100644
36315 --- a/drivers/acpi/apei/apei-internal.h
36316 +++ b/drivers/acpi/apei/apei-internal.h
36317 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36318 struct apei_exec_ins_type {
36319 u32 flags;
36320 apei_exec_ins_func_t run;
36321 -};
36322 +} __do_const;
36323
36324 struct apei_exec_context {
36325 u32 ip;
36326 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36327 index fc5f780..e5ac91a 100644
36328 --- a/drivers/acpi/apei/ghes.c
36329 +++ b/drivers/acpi/apei/ghes.c
36330 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36331 const struct acpi_hest_generic *generic,
36332 const struct acpi_hest_generic_status *estatus)
36333 {
36334 - static atomic_t seqno;
36335 + static atomic_unchecked_t seqno;
36336 unsigned int curr_seqno;
36337 char pfx_seq[64];
36338
36339 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36340 else
36341 pfx = KERN_ERR;
36342 }
36343 - curr_seqno = atomic_inc_return(&seqno);
36344 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36345 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36346 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36347 pfx_seq, generic->header.source_id);
36348 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36349 index a83e3c6..c3d617f 100644
36350 --- a/drivers/acpi/bgrt.c
36351 +++ b/drivers/acpi/bgrt.c
36352 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36353 if (!bgrt_image)
36354 return -ENODEV;
36355
36356 - bin_attr_image.private = bgrt_image;
36357 - bin_attr_image.size = bgrt_image_size;
36358 + pax_open_kernel();
36359 + *(void **)&bin_attr_image.private = bgrt_image;
36360 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36361 + pax_close_kernel();
36362
36363 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36364 if (!bgrt_kobj)
36365 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36366 index 7556e7c..89a96bd 100644
36367 --- a/drivers/acpi/blacklist.c
36368 +++ b/drivers/acpi/blacklist.c
36369 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36370 u32 is_critical_error;
36371 };
36372
36373 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36374 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36375
36376 /*
36377 * POLICY: If *anything* doesn't work, put it on the blacklist.
36378 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36379 return 0;
36380 }
36381
36382 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36383 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36384 {
36385 .callback = dmi_disable_osi_vista,
36386 .ident = "Fujitsu Siemens",
36387 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36388 index c68e724..e863008 100644
36389 --- a/drivers/acpi/custom_method.c
36390 +++ b/drivers/acpi/custom_method.c
36391 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36392 struct acpi_table_header table;
36393 acpi_status status;
36394
36395 +#ifdef CONFIG_GRKERNSEC_KMEM
36396 + return -EPERM;
36397 +#endif
36398 +
36399 if (!(*ppos)) {
36400 /* parse the table header to get the table length */
36401 if (count <= sizeof(struct acpi_table_header))
36402 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36403 index 6341e66..ebcf59c 100644
36404 --- a/drivers/acpi/device_pm.c
36405 +++ b/drivers/acpi/device_pm.c
36406 @@ -1029,6 +1029,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36407
36408 #endif /* CONFIG_PM_SLEEP */
36409
36410 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36411 +
36412 static struct dev_pm_domain acpi_general_pm_domain = {
36413 .ops = {
36414 #ifdef CONFIG_PM_RUNTIME
36415 @@ -1047,6 +1049,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36416 .restore_early = acpi_subsys_resume_early,
36417 #endif
36418 },
36419 + .detach = acpi_dev_pm_detach
36420 };
36421
36422 /**
36423 @@ -1116,7 +1119,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36424 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36425 }
36426
36427 - dev->pm_domain->detach = acpi_dev_pm_detach;
36428 return 0;
36429 }
36430 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36431 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36432 index 17f9ec5..d9a455e 100644
36433 --- a/drivers/acpi/processor_idle.c
36434 +++ b/drivers/acpi/processor_idle.c
36435 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36436 {
36437 int i, count = CPUIDLE_DRIVER_STATE_START;
36438 struct acpi_processor_cx *cx;
36439 - struct cpuidle_state *state;
36440 + cpuidle_state_no_const *state;
36441 struct cpuidle_driver *drv = &acpi_idle_driver;
36442
36443 if (!pr->flags.power_setup_done)
36444 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36445 index 13e577c..cef11ee 100644
36446 --- a/drivers/acpi/sysfs.c
36447 +++ b/drivers/acpi/sysfs.c
36448 @@ -423,11 +423,11 @@ static u32 num_counters;
36449 static struct attribute **all_attrs;
36450 static u32 acpi_gpe_count;
36451
36452 -static struct attribute_group interrupt_stats_attr_group = {
36453 +static attribute_group_no_const interrupt_stats_attr_group = {
36454 .name = "interrupts",
36455 };
36456
36457 -static struct kobj_attribute *counter_attrs;
36458 +static kobj_attribute_no_const *counter_attrs;
36459
36460 static void delete_gpe_attr_array(void)
36461 {
36462 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36463 index 97683e4..655f6ba 100644
36464 --- a/drivers/ata/libahci.c
36465 +++ b/drivers/ata/libahci.c
36466 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36467 }
36468 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36469
36470 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36471 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36472 struct ata_taskfile *tf, int is_cmd, u16 flags,
36473 unsigned long timeout_msec)
36474 {
36475 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36476 index 485f7ea..9a8df4a 100644
36477 --- a/drivers/ata/libata-core.c
36478 +++ b/drivers/ata/libata-core.c
36479 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36480 static void ata_dev_xfermask(struct ata_device *dev);
36481 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36482
36483 -atomic_t ata_print_id = ATOMIC_INIT(0);
36484 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36485
36486 struct ata_force_param {
36487 const char *name;
36488 @@ -4800,7 +4800,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36489 struct ata_port *ap;
36490 unsigned int tag;
36491
36492 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36493 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36494 ap = qc->ap;
36495
36496 qc->flags = 0;
36497 @@ -4816,7 +4816,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36498 struct ata_port *ap;
36499 struct ata_link *link;
36500
36501 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36502 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36503 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36504 ap = qc->ap;
36505 link = qc->dev->link;
36506 @@ -5920,6 +5920,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36507 return;
36508
36509 spin_lock(&lock);
36510 + pax_open_kernel();
36511
36512 for (cur = ops->inherits; cur; cur = cur->inherits) {
36513 void **inherit = (void **)cur;
36514 @@ -5933,8 +5934,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36515 if (IS_ERR(*pp))
36516 *pp = NULL;
36517
36518 - ops->inherits = NULL;
36519 + *(struct ata_port_operations **)&ops->inherits = NULL;
36520
36521 + pax_close_kernel();
36522 spin_unlock(&lock);
36523 }
36524
36525 @@ -6130,7 +6132,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36526
36527 /* give ports names and add SCSI hosts */
36528 for (i = 0; i < host->n_ports; i++) {
36529 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36530 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36531 host->ports[i]->local_port_no = i + 1;
36532 }
36533
36534 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36535 index 0586f66..1a8f74a 100644
36536 --- a/drivers/ata/libata-scsi.c
36537 +++ b/drivers/ata/libata-scsi.c
36538 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36539
36540 if (rc)
36541 return rc;
36542 - ap->print_id = atomic_inc_return(&ata_print_id);
36543 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36544 return 0;
36545 }
36546 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36547 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36548 index 5f4e0cc..ff2c347 100644
36549 --- a/drivers/ata/libata.h
36550 +++ b/drivers/ata/libata.h
36551 @@ -53,7 +53,7 @@ enum {
36552 ATA_DNXFER_QUIET = (1 << 31),
36553 };
36554
36555 -extern atomic_t ata_print_id;
36556 +extern atomic_unchecked_t ata_print_id;
36557 extern int atapi_passthru16;
36558 extern int libata_fua;
36559 extern int libata_noacpi;
36560 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36561 index 38216b9..4ec6aeb 100644
36562 --- a/drivers/ata/pata_arasan_cf.c
36563 +++ b/drivers/ata/pata_arasan_cf.c
36564 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36565 /* Handle platform specific quirks */
36566 if (quirk) {
36567 if (quirk & CF_BROKEN_PIO) {
36568 - ap->ops->set_piomode = NULL;
36569 + pax_open_kernel();
36570 + *(void **)&ap->ops->set_piomode = NULL;
36571 + pax_close_kernel();
36572 ap->pio_mask = 0;
36573 }
36574 if (quirk & CF_BROKEN_MWDMA)
36575 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36576 index f9b983a..887b9d8 100644
36577 --- a/drivers/atm/adummy.c
36578 +++ b/drivers/atm/adummy.c
36579 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36580 vcc->pop(vcc, skb);
36581 else
36582 dev_kfree_skb_any(skb);
36583 - atomic_inc(&vcc->stats->tx);
36584 + atomic_inc_unchecked(&vcc->stats->tx);
36585
36586 return 0;
36587 }
36588 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36589 index f1a9198..f466a4a 100644
36590 --- a/drivers/atm/ambassador.c
36591 +++ b/drivers/atm/ambassador.c
36592 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36593 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36594
36595 // VC layer stats
36596 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36597 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36598
36599 // free the descriptor
36600 kfree (tx_descr);
36601 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36602 dump_skb ("<<<", vc, skb);
36603
36604 // VC layer stats
36605 - atomic_inc(&atm_vcc->stats->rx);
36606 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36607 __net_timestamp(skb);
36608 // end of our responsibility
36609 atm_vcc->push (atm_vcc, skb);
36610 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36611 } else {
36612 PRINTK (KERN_INFO, "dropped over-size frame");
36613 // should we count this?
36614 - atomic_inc(&atm_vcc->stats->rx_drop);
36615 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36616 }
36617
36618 } else {
36619 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36620 }
36621
36622 if (check_area (skb->data, skb->len)) {
36623 - atomic_inc(&atm_vcc->stats->tx_err);
36624 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36625 return -ENOMEM; // ?
36626 }
36627
36628 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36629 index 480fa6f..947067c 100644
36630 --- a/drivers/atm/atmtcp.c
36631 +++ b/drivers/atm/atmtcp.c
36632 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36633 if (vcc->pop) vcc->pop(vcc,skb);
36634 else dev_kfree_skb(skb);
36635 if (dev_data) return 0;
36636 - atomic_inc(&vcc->stats->tx_err);
36637 + atomic_inc_unchecked(&vcc->stats->tx_err);
36638 return -ENOLINK;
36639 }
36640 size = skb->len+sizeof(struct atmtcp_hdr);
36641 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36642 if (!new_skb) {
36643 if (vcc->pop) vcc->pop(vcc,skb);
36644 else dev_kfree_skb(skb);
36645 - atomic_inc(&vcc->stats->tx_err);
36646 + atomic_inc_unchecked(&vcc->stats->tx_err);
36647 return -ENOBUFS;
36648 }
36649 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36650 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36651 if (vcc->pop) vcc->pop(vcc,skb);
36652 else dev_kfree_skb(skb);
36653 out_vcc->push(out_vcc,new_skb);
36654 - atomic_inc(&vcc->stats->tx);
36655 - atomic_inc(&out_vcc->stats->rx);
36656 + atomic_inc_unchecked(&vcc->stats->tx);
36657 + atomic_inc_unchecked(&out_vcc->stats->rx);
36658 return 0;
36659 }
36660
36661 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36662 read_unlock(&vcc_sklist_lock);
36663 if (!out_vcc) {
36664 result = -EUNATCH;
36665 - atomic_inc(&vcc->stats->tx_err);
36666 + atomic_inc_unchecked(&vcc->stats->tx_err);
36667 goto done;
36668 }
36669 skb_pull(skb,sizeof(struct atmtcp_hdr));
36670 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36671 __net_timestamp(new_skb);
36672 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36673 out_vcc->push(out_vcc,new_skb);
36674 - atomic_inc(&vcc->stats->tx);
36675 - atomic_inc(&out_vcc->stats->rx);
36676 + atomic_inc_unchecked(&vcc->stats->tx);
36677 + atomic_inc_unchecked(&out_vcc->stats->rx);
36678 done:
36679 if (vcc->pop) vcc->pop(vcc,skb);
36680 else dev_kfree_skb(skb);
36681 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36682 index d65975a..0b87e20 100644
36683 --- a/drivers/atm/eni.c
36684 +++ b/drivers/atm/eni.c
36685 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36686 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36687 vcc->dev->number);
36688 length = 0;
36689 - atomic_inc(&vcc->stats->rx_err);
36690 + atomic_inc_unchecked(&vcc->stats->rx_err);
36691 }
36692 else {
36693 length = ATM_CELL_SIZE-1; /* no HEC */
36694 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36695 size);
36696 }
36697 eff = length = 0;
36698 - atomic_inc(&vcc->stats->rx_err);
36699 + atomic_inc_unchecked(&vcc->stats->rx_err);
36700 }
36701 else {
36702 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36703 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36704 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36705 vcc->dev->number,vcc->vci,length,size << 2,descr);
36706 length = eff = 0;
36707 - atomic_inc(&vcc->stats->rx_err);
36708 + atomic_inc_unchecked(&vcc->stats->rx_err);
36709 }
36710 }
36711 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36712 @@ -767,7 +767,7 @@ rx_dequeued++;
36713 vcc->push(vcc,skb);
36714 pushed++;
36715 }
36716 - atomic_inc(&vcc->stats->rx);
36717 + atomic_inc_unchecked(&vcc->stats->rx);
36718 }
36719 wake_up(&eni_dev->rx_wait);
36720 }
36721 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36722 PCI_DMA_TODEVICE);
36723 if (vcc->pop) vcc->pop(vcc,skb);
36724 else dev_kfree_skb_irq(skb);
36725 - atomic_inc(&vcc->stats->tx);
36726 + atomic_inc_unchecked(&vcc->stats->tx);
36727 wake_up(&eni_dev->tx_wait);
36728 dma_complete++;
36729 }
36730 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36731 index 82f2ae0..f205c02 100644
36732 --- a/drivers/atm/firestream.c
36733 +++ b/drivers/atm/firestream.c
36734 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36735 }
36736 }
36737
36738 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36739 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36740
36741 fs_dprintk (FS_DEBUG_TXMEM, "i");
36742 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36743 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36744 #endif
36745 skb_put (skb, qe->p1 & 0xffff);
36746 ATM_SKB(skb)->vcc = atm_vcc;
36747 - atomic_inc(&atm_vcc->stats->rx);
36748 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36749 __net_timestamp(skb);
36750 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36751 atm_vcc->push (atm_vcc, skb);
36752 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36753 kfree (pe);
36754 }
36755 if (atm_vcc)
36756 - atomic_inc(&atm_vcc->stats->rx_drop);
36757 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36758 break;
36759 case 0x1f: /* Reassembly abort: no buffers. */
36760 /* Silently increment error counter. */
36761 if (atm_vcc)
36762 - atomic_inc(&atm_vcc->stats->rx_drop);
36763 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36764 break;
36765 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36766 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36767 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36768 index d4725fc..2d4ea65 100644
36769 --- a/drivers/atm/fore200e.c
36770 +++ b/drivers/atm/fore200e.c
36771 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36772 #endif
36773 /* check error condition */
36774 if (*entry->status & STATUS_ERROR)
36775 - atomic_inc(&vcc->stats->tx_err);
36776 + atomic_inc_unchecked(&vcc->stats->tx_err);
36777 else
36778 - atomic_inc(&vcc->stats->tx);
36779 + atomic_inc_unchecked(&vcc->stats->tx);
36780 }
36781 }
36782
36783 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36784 if (skb == NULL) {
36785 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36786
36787 - atomic_inc(&vcc->stats->rx_drop);
36788 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36789 return -ENOMEM;
36790 }
36791
36792 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36793
36794 dev_kfree_skb_any(skb);
36795
36796 - atomic_inc(&vcc->stats->rx_drop);
36797 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36798 return -ENOMEM;
36799 }
36800
36801 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36802
36803 vcc->push(vcc, skb);
36804 - atomic_inc(&vcc->stats->rx);
36805 + atomic_inc_unchecked(&vcc->stats->rx);
36806
36807 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36808
36809 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36810 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36811 fore200e->atm_dev->number,
36812 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36813 - atomic_inc(&vcc->stats->rx_err);
36814 + atomic_inc_unchecked(&vcc->stats->rx_err);
36815 }
36816 }
36817
36818 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36819 goto retry_here;
36820 }
36821
36822 - atomic_inc(&vcc->stats->tx_err);
36823 + atomic_inc_unchecked(&vcc->stats->tx_err);
36824
36825 fore200e->tx_sat++;
36826 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36827 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36828 index c39702b..785b73b 100644
36829 --- a/drivers/atm/he.c
36830 +++ b/drivers/atm/he.c
36831 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36832
36833 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36834 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36835 - atomic_inc(&vcc->stats->rx_drop);
36836 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36837 goto return_host_buffers;
36838 }
36839
36840 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36841 RBRQ_LEN_ERR(he_dev->rbrq_head)
36842 ? "LEN_ERR" : "",
36843 vcc->vpi, vcc->vci);
36844 - atomic_inc(&vcc->stats->rx_err);
36845 + atomic_inc_unchecked(&vcc->stats->rx_err);
36846 goto return_host_buffers;
36847 }
36848
36849 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36850 vcc->push(vcc, skb);
36851 spin_lock(&he_dev->global_lock);
36852
36853 - atomic_inc(&vcc->stats->rx);
36854 + atomic_inc_unchecked(&vcc->stats->rx);
36855
36856 return_host_buffers:
36857 ++pdus_assembled;
36858 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36859 tpd->vcc->pop(tpd->vcc, tpd->skb);
36860 else
36861 dev_kfree_skb_any(tpd->skb);
36862 - atomic_inc(&tpd->vcc->stats->tx_err);
36863 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36864 }
36865 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36866 return;
36867 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36868 vcc->pop(vcc, skb);
36869 else
36870 dev_kfree_skb_any(skb);
36871 - atomic_inc(&vcc->stats->tx_err);
36872 + atomic_inc_unchecked(&vcc->stats->tx_err);
36873 return -EINVAL;
36874 }
36875
36876 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36877 vcc->pop(vcc, skb);
36878 else
36879 dev_kfree_skb_any(skb);
36880 - atomic_inc(&vcc->stats->tx_err);
36881 + atomic_inc_unchecked(&vcc->stats->tx_err);
36882 return -EINVAL;
36883 }
36884 #endif
36885 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36886 vcc->pop(vcc, skb);
36887 else
36888 dev_kfree_skb_any(skb);
36889 - atomic_inc(&vcc->stats->tx_err);
36890 + atomic_inc_unchecked(&vcc->stats->tx_err);
36891 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36892 return -ENOMEM;
36893 }
36894 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36895 vcc->pop(vcc, skb);
36896 else
36897 dev_kfree_skb_any(skb);
36898 - atomic_inc(&vcc->stats->tx_err);
36899 + atomic_inc_unchecked(&vcc->stats->tx_err);
36900 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36901 return -ENOMEM;
36902 }
36903 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36904 __enqueue_tpd(he_dev, tpd, cid);
36905 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36906
36907 - atomic_inc(&vcc->stats->tx);
36908 + atomic_inc_unchecked(&vcc->stats->tx);
36909
36910 return 0;
36911 }
36912 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36913 index 1dc0519..1aadaf7 100644
36914 --- a/drivers/atm/horizon.c
36915 +++ b/drivers/atm/horizon.c
36916 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36917 {
36918 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36919 // VC layer stats
36920 - atomic_inc(&vcc->stats->rx);
36921 + atomic_inc_unchecked(&vcc->stats->rx);
36922 __net_timestamp(skb);
36923 // end of our responsibility
36924 vcc->push (vcc, skb);
36925 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36926 dev->tx_iovec = NULL;
36927
36928 // VC layer stats
36929 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36930 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36931
36932 // free the skb
36933 hrz_kfree_skb (skb);
36934 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36935 index 2b24ed0..b3d6acc 100644
36936 --- a/drivers/atm/idt77252.c
36937 +++ b/drivers/atm/idt77252.c
36938 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36939 else
36940 dev_kfree_skb(skb);
36941
36942 - atomic_inc(&vcc->stats->tx);
36943 + atomic_inc_unchecked(&vcc->stats->tx);
36944 }
36945
36946 atomic_dec(&scq->used);
36947 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36948 if ((sb = dev_alloc_skb(64)) == NULL) {
36949 printk("%s: Can't allocate buffers for aal0.\n",
36950 card->name);
36951 - atomic_add(i, &vcc->stats->rx_drop);
36952 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36953 break;
36954 }
36955 if (!atm_charge(vcc, sb->truesize)) {
36956 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36957 card->name);
36958 - atomic_add(i - 1, &vcc->stats->rx_drop);
36959 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36960 dev_kfree_skb(sb);
36961 break;
36962 }
36963 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36964 ATM_SKB(sb)->vcc = vcc;
36965 __net_timestamp(sb);
36966 vcc->push(vcc, sb);
36967 - atomic_inc(&vcc->stats->rx);
36968 + atomic_inc_unchecked(&vcc->stats->rx);
36969
36970 cell += ATM_CELL_PAYLOAD;
36971 }
36972 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36973 "(CDC: %08x)\n",
36974 card->name, len, rpp->len, readl(SAR_REG_CDC));
36975 recycle_rx_pool_skb(card, rpp);
36976 - atomic_inc(&vcc->stats->rx_err);
36977 + atomic_inc_unchecked(&vcc->stats->rx_err);
36978 return;
36979 }
36980 if (stat & SAR_RSQE_CRC) {
36981 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36982 recycle_rx_pool_skb(card, rpp);
36983 - atomic_inc(&vcc->stats->rx_err);
36984 + atomic_inc_unchecked(&vcc->stats->rx_err);
36985 return;
36986 }
36987 if (skb_queue_len(&rpp->queue) > 1) {
36988 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36989 RXPRINTK("%s: Can't alloc RX skb.\n",
36990 card->name);
36991 recycle_rx_pool_skb(card, rpp);
36992 - atomic_inc(&vcc->stats->rx_err);
36993 + atomic_inc_unchecked(&vcc->stats->rx_err);
36994 return;
36995 }
36996 if (!atm_charge(vcc, skb->truesize)) {
36997 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36998 __net_timestamp(skb);
36999
37000 vcc->push(vcc, skb);
37001 - atomic_inc(&vcc->stats->rx);
37002 + atomic_inc_unchecked(&vcc->stats->rx);
37003
37004 return;
37005 }
37006 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37007 __net_timestamp(skb);
37008
37009 vcc->push(vcc, skb);
37010 - atomic_inc(&vcc->stats->rx);
37011 + atomic_inc_unchecked(&vcc->stats->rx);
37012
37013 if (skb->truesize > SAR_FB_SIZE_3)
37014 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37015 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37016 if (vcc->qos.aal != ATM_AAL0) {
37017 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37018 card->name, vpi, vci);
37019 - atomic_inc(&vcc->stats->rx_drop);
37020 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37021 goto drop;
37022 }
37023
37024 if ((sb = dev_alloc_skb(64)) == NULL) {
37025 printk("%s: Can't allocate buffers for AAL0.\n",
37026 card->name);
37027 - atomic_inc(&vcc->stats->rx_err);
37028 + atomic_inc_unchecked(&vcc->stats->rx_err);
37029 goto drop;
37030 }
37031
37032 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37033 ATM_SKB(sb)->vcc = vcc;
37034 __net_timestamp(sb);
37035 vcc->push(vcc, sb);
37036 - atomic_inc(&vcc->stats->rx);
37037 + atomic_inc_unchecked(&vcc->stats->rx);
37038
37039 drop:
37040 skb_pull(queue, 64);
37041 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37042
37043 if (vc == NULL) {
37044 printk("%s: NULL connection in send().\n", card->name);
37045 - atomic_inc(&vcc->stats->tx_err);
37046 + atomic_inc_unchecked(&vcc->stats->tx_err);
37047 dev_kfree_skb(skb);
37048 return -EINVAL;
37049 }
37050 if (!test_bit(VCF_TX, &vc->flags)) {
37051 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37052 - atomic_inc(&vcc->stats->tx_err);
37053 + atomic_inc_unchecked(&vcc->stats->tx_err);
37054 dev_kfree_skb(skb);
37055 return -EINVAL;
37056 }
37057 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37058 break;
37059 default:
37060 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37061 - atomic_inc(&vcc->stats->tx_err);
37062 + atomic_inc_unchecked(&vcc->stats->tx_err);
37063 dev_kfree_skb(skb);
37064 return -EINVAL;
37065 }
37066
37067 if (skb_shinfo(skb)->nr_frags != 0) {
37068 printk("%s: No scatter-gather yet.\n", card->name);
37069 - atomic_inc(&vcc->stats->tx_err);
37070 + atomic_inc_unchecked(&vcc->stats->tx_err);
37071 dev_kfree_skb(skb);
37072 return -EINVAL;
37073 }
37074 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37075
37076 err = queue_skb(card, vc, skb, oam);
37077 if (err) {
37078 - atomic_inc(&vcc->stats->tx_err);
37079 + atomic_inc_unchecked(&vcc->stats->tx_err);
37080 dev_kfree_skb(skb);
37081 return err;
37082 }
37083 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37084 skb = dev_alloc_skb(64);
37085 if (!skb) {
37086 printk("%s: Out of memory in send_oam().\n", card->name);
37087 - atomic_inc(&vcc->stats->tx_err);
37088 + atomic_inc_unchecked(&vcc->stats->tx_err);
37089 return -ENOMEM;
37090 }
37091 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37092 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37093 index 4217f29..88f547a 100644
37094 --- a/drivers/atm/iphase.c
37095 +++ b/drivers/atm/iphase.c
37096 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37097 status = (u_short) (buf_desc_ptr->desc_mode);
37098 if (status & (RX_CER | RX_PTE | RX_OFL))
37099 {
37100 - atomic_inc(&vcc->stats->rx_err);
37101 + atomic_inc_unchecked(&vcc->stats->rx_err);
37102 IF_ERR(printk("IA: bad packet, dropping it");)
37103 if (status & RX_CER) {
37104 IF_ERR(printk(" cause: packet CRC error\n");)
37105 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37106 len = dma_addr - buf_addr;
37107 if (len > iadev->rx_buf_sz) {
37108 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37109 - atomic_inc(&vcc->stats->rx_err);
37110 + atomic_inc_unchecked(&vcc->stats->rx_err);
37111 goto out_free_desc;
37112 }
37113
37114 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37115 ia_vcc = INPH_IA_VCC(vcc);
37116 if (ia_vcc == NULL)
37117 {
37118 - atomic_inc(&vcc->stats->rx_err);
37119 + atomic_inc_unchecked(&vcc->stats->rx_err);
37120 atm_return(vcc, skb->truesize);
37121 dev_kfree_skb_any(skb);
37122 goto INCR_DLE;
37123 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37124 if ((length > iadev->rx_buf_sz) || (length >
37125 (skb->len - sizeof(struct cpcs_trailer))))
37126 {
37127 - atomic_inc(&vcc->stats->rx_err);
37128 + atomic_inc_unchecked(&vcc->stats->rx_err);
37129 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37130 length, skb->len);)
37131 atm_return(vcc, skb->truesize);
37132 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37133
37134 IF_RX(printk("rx_dle_intr: skb push");)
37135 vcc->push(vcc,skb);
37136 - atomic_inc(&vcc->stats->rx);
37137 + atomic_inc_unchecked(&vcc->stats->rx);
37138 iadev->rx_pkt_cnt++;
37139 }
37140 INCR_DLE:
37141 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37142 {
37143 struct k_sonet_stats *stats;
37144 stats = &PRIV(_ia_dev[board])->sonet_stats;
37145 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37146 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37147 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37148 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37149 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37150 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37151 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37152 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37153 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37154 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37155 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37156 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37157 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37158 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37159 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37160 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37161 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37162 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37163 }
37164 ia_cmds.status = 0;
37165 break;
37166 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37167 if ((desc == 0) || (desc > iadev->num_tx_desc))
37168 {
37169 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37170 - atomic_inc(&vcc->stats->tx);
37171 + atomic_inc_unchecked(&vcc->stats->tx);
37172 if (vcc->pop)
37173 vcc->pop(vcc, skb);
37174 else
37175 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37176 ATM_DESC(skb) = vcc->vci;
37177 skb_queue_tail(&iadev->tx_dma_q, skb);
37178
37179 - atomic_inc(&vcc->stats->tx);
37180 + atomic_inc_unchecked(&vcc->stats->tx);
37181 iadev->tx_pkt_cnt++;
37182 /* Increment transaction counter */
37183 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37184
37185 #if 0
37186 /* add flow control logic */
37187 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37188 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37189 if (iavcc->vc_desc_cnt > 10) {
37190 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37191 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37192 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37193 index 93eaf8d..b4ca7da 100644
37194 --- a/drivers/atm/lanai.c
37195 +++ b/drivers/atm/lanai.c
37196 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37197 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37198 lanai_endtx(lanai, lvcc);
37199 lanai_free_skb(lvcc->tx.atmvcc, skb);
37200 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37201 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37202 }
37203
37204 /* Try to fill the buffer - don't call unless there is backlog */
37205 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37206 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37207 __net_timestamp(skb);
37208 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37209 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37210 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37211 out:
37212 lvcc->rx.buf.ptr = end;
37213 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37214 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37215 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37216 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37217 lanai->stats.service_rxnotaal5++;
37218 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37219 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37220 return 0;
37221 }
37222 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37223 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37224 int bytes;
37225 read_unlock(&vcc_sklist_lock);
37226 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37227 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37228 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37229 lvcc->stats.x.aal5.service_trash++;
37230 bytes = (SERVICE_GET_END(s) * 16) -
37231 (((unsigned long) lvcc->rx.buf.ptr) -
37232 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37233 }
37234 if (s & SERVICE_STREAM) {
37235 read_unlock(&vcc_sklist_lock);
37236 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37237 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37238 lvcc->stats.x.aal5.service_stream++;
37239 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37240 "PDU on VCI %d!\n", lanai->number, vci);
37241 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37242 return 0;
37243 }
37244 DPRINTK("got rx crc error on vci %d\n", vci);
37245 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37246 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37247 lvcc->stats.x.aal5.service_rxcrc++;
37248 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37249 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37250 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37251 index 9988ac9..7c52585 100644
37252 --- a/drivers/atm/nicstar.c
37253 +++ b/drivers/atm/nicstar.c
37254 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37255 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37256 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37257 card->index);
37258 - atomic_inc(&vcc->stats->tx_err);
37259 + atomic_inc_unchecked(&vcc->stats->tx_err);
37260 dev_kfree_skb_any(skb);
37261 return -EINVAL;
37262 }
37263 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37264 if (!vc->tx) {
37265 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37266 card->index);
37267 - atomic_inc(&vcc->stats->tx_err);
37268 + atomic_inc_unchecked(&vcc->stats->tx_err);
37269 dev_kfree_skb_any(skb);
37270 return -EINVAL;
37271 }
37272 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37273 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37274 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37275 card->index);
37276 - atomic_inc(&vcc->stats->tx_err);
37277 + atomic_inc_unchecked(&vcc->stats->tx_err);
37278 dev_kfree_skb_any(skb);
37279 return -EINVAL;
37280 }
37281
37282 if (skb_shinfo(skb)->nr_frags != 0) {
37283 printk("nicstar%d: No scatter-gather yet.\n", 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 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37290 }
37291
37292 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37293 - atomic_inc(&vcc->stats->tx_err);
37294 + atomic_inc_unchecked(&vcc->stats->tx_err);
37295 dev_kfree_skb_any(skb);
37296 return -EIO;
37297 }
37298 - atomic_inc(&vcc->stats->tx);
37299 + atomic_inc_unchecked(&vcc->stats->tx);
37300
37301 return 0;
37302 }
37303 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37304 printk
37305 ("nicstar%d: Can't allocate buffers for aal0.\n",
37306 card->index);
37307 - atomic_add(i, &vcc->stats->rx_drop);
37308 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37309 break;
37310 }
37311 if (!atm_charge(vcc, sb->truesize)) {
37312 RXPRINTK
37313 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37314 card->index);
37315 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37316 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37317 dev_kfree_skb_any(sb);
37318 break;
37319 }
37320 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37321 ATM_SKB(sb)->vcc = vcc;
37322 __net_timestamp(sb);
37323 vcc->push(vcc, sb);
37324 - atomic_inc(&vcc->stats->rx);
37325 + atomic_inc_unchecked(&vcc->stats->rx);
37326 cell += ATM_CELL_PAYLOAD;
37327 }
37328
37329 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37330 if (iovb == NULL) {
37331 printk("nicstar%d: Out of iovec buffers.\n",
37332 card->index);
37333 - atomic_inc(&vcc->stats->rx_drop);
37334 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37335 recycle_rx_buf(card, skb);
37336 return;
37337 }
37338 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37339 small or large buffer itself. */
37340 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37341 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37342 - atomic_inc(&vcc->stats->rx_err);
37343 + atomic_inc_unchecked(&vcc->stats->rx_err);
37344 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37345 NS_MAX_IOVECS);
37346 NS_PRV_IOVCNT(iovb) = 0;
37347 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37348 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37349 card->index);
37350 which_list(card, skb);
37351 - atomic_inc(&vcc->stats->rx_err);
37352 + atomic_inc_unchecked(&vcc->stats->rx_err);
37353 recycle_rx_buf(card, skb);
37354 vc->rx_iov = NULL;
37355 recycle_iov_buf(card, iovb);
37356 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37357 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37358 card->index);
37359 which_list(card, skb);
37360 - atomic_inc(&vcc->stats->rx_err);
37361 + atomic_inc_unchecked(&vcc->stats->rx_err);
37362 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37363 NS_PRV_IOVCNT(iovb));
37364 vc->rx_iov = NULL;
37365 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37366 printk(" - PDU size mismatch.\n");
37367 else
37368 printk(".\n");
37369 - atomic_inc(&vcc->stats->rx_err);
37370 + atomic_inc_unchecked(&vcc->stats->rx_err);
37371 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37372 NS_PRV_IOVCNT(iovb));
37373 vc->rx_iov = NULL;
37374 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37375 /* skb points to a small buffer */
37376 if (!atm_charge(vcc, skb->truesize)) {
37377 push_rxbufs(card, skb);
37378 - atomic_inc(&vcc->stats->rx_drop);
37379 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37380 } else {
37381 skb_put(skb, len);
37382 dequeue_sm_buf(card, skb);
37383 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37384 ATM_SKB(skb)->vcc = vcc;
37385 __net_timestamp(skb);
37386 vcc->push(vcc, skb);
37387 - atomic_inc(&vcc->stats->rx);
37388 + atomic_inc_unchecked(&vcc->stats->rx);
37389 }
37390 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37391 struct sk_buff *sb;
37392 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37393 if (len <= NS_SMBUFSIZE) {
37394 if (!atm_charge(vcc, sb->truesize)) {
37395 push_rxbufs(card, sb);
37396 - atomic_inc(&vcc->stats->rx_drop);
37397 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37398 } else {
37399 skb_put(sb, len);
37400 dequeue_sm_buf(card, sb);
37401 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37402 ATM_SKB(sb)->vcc = vcc;
37403 __net_timestamp(sb);
37404 vcc->push(vcc, sb);
37405 - atomic_inc(&vcc->stats->rx);
37406 + atomic_inc_unchecked(&vcc->stats->rx);
37407 }
37408
37409 push_rxbufs(card, skb);
37410 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37411
37412 if (!atm_charge(vcc, skb->truesize)) {
37413 push_rxbufs(card, skb);
37414 - atomic_inc(&vcc->stats->rx_drop);
37415 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37416 } else {
37417 dequeue_lg_buf(card, skb);
37418 #ifdef NS_USE_DESTRUCTORS
37419 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37420 ATM_SKB(skb)->vcc = vcc;
37421 __net_timestamp(skb);
37422 vcc->push(vcc, skb);
37423 - atomic_inc(&vcc->stats->rx);
37424 + atomic_inc_unchecked(&vcc->stats->rx);
37425 }
37426
37427 push_rxbufs(card, sb);
37428 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37429 printk
37430 ("nicstar%d: Out of huge buffers.\n",
37431 card->index);
37432 - atomic_inc(&vcc->stats->rx_drop);
37433 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37434 recycle_iovec_rx_bufs(card,
37435 (struct iovec *)
37436 iovb->data,
37437 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37438 card->hbpool.count++;
37439 } else
37440 dev_kfree_skb_any(hb);
37441 - atomic_inc(&vcc->stats->rx_drop);
37442 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37443 } else {
37444 /* Copy the small buffer to the huge buffer */
37445 sb = (struct sk_buff *)iov->iov_base;
37446 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37447 #endif /* NS_USE_DESTRUCTORS */
37448 __net_timestamp(hb);
37449 vcc->push(vcc, hb);
37450 - atomic_inc(&vcc->stats->rx);
37451 + atomic_inc_unchecked(&vcc->stats->rx);
37452 }
37453 }
37454
37455 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37456 index 21b0bc6..b5f40ba 100644
37457 --- a/drivers/atm/solos-pci.c
37458 +++ b/drivers/atm/solos-pci.c
37459 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37460 }
37461 atm_charge(vcc, skb->truesize);
37462 vcc->push(vcc, skb);
37463 - atomic_inc(&vcc->stats->rx);
37464 + atomic_inc_unchecked(&vcc->stats->rx);
37465 break;
37466
37467 case PKT_STATUS:
37468 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37469 vcc = SKB_CB(oldskb)->vcc;
37470
37471 if (vcc) {
37472 - atomic_inc(&vcc->stats->tx);
37473 + atomic_inc_unchecked(&vcc->stats->tx);
37474 solos_pop(vcc, oldskb);
37475 } else {
37476 dev_kfree_skb_irq(oldskb);
37477 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37478 index 0215934..ce9f5b1 100644
37479 --- a/drivers/atm/suni.c
37480 +++ b/drivers/atm/suni.c
37481 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37482
37483
37484 #define ADD_LIMITED(s,v) \
37485 - atomic_add((v),&stats->s); \
37486 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37487 + atomic_add_unchecked((v),&stats->s); \
37488 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37489
37490
37491 static void suni_hz(unsigned long from_timer)
37492 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37493 index 5120a96..e2572bd 100644
37494 --- a/drivers/atm/uPD98402.c
37495 +++ b/drivers/atm/uPD98402.c
37496 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37497 struct sonet_stats tmp;
37498 int error = 0;
37499
37500 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37501 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37502 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37503 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37504 if (zero && !error) {
37505 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37506
37507
37508 #define ADD_LIMITED(s,v) \
37509 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37510 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37511 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37512 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37513 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37514 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37515
37516
37517 static void stat_event(struct atm_dev *dev)
37518 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37519 if (reason & uPD98402_INT_PFM) stat_event(dev);
37520 if (reason & uPD98402_INT_PCO) {
37521 (void) GET(PCOCR); /* clear interrupt cause */
37522 - atomic_add(GET(HECCT),
37523 + atomic_add_unchecked(GET(HECCT),
37524 &PRIV(dev)->sonet_stats.uncorr_hcs);
37525 }
37526 if ((reason & uPD98402_INT_RFO) &&
37527 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37528 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37529 uPD98402_INT_LOS),PIMR); /* enable them */
37530 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37531 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37532 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37533 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37534 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37535 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37536 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37537 return 0;
37538 }
37539
37540 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37541 index 969c3c2..9b72956 100644
37542 --- a/drivers/atm/zatm.c
37543 +++ b/drivers/atm/zatm.c
37544 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37545 }
37546 if (!size) {
37547 dev_kfree_skb_irq(skb);
37548 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37549 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37550 continue;
37551 }
37552 if (!atm_charge(vcc,skb->truesize)) {
37553 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37554 skb->len = size;
37555 ATM_SKB(skb)->vcc = vcc;
37556 vcc->push(vcc,skb);
37557 - atomic_inc(&vcc->stats->rx);
37558 + atomic_inc_unchecked(&vcc->stats->rx);
37559 }
37560 zout(pos & 0xffff,MTA(mbx));
37561 #if 0 /* probably a stupid idea */
37562 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37563 skb_queue_head(&zatm_vcc->backlog,skb);
37564 break;
37565 }
37566 - atomic_inc(&vcc->stats->tx);
37567 + atomic_inc_unchecked(&vcc->stats->tx);
37568 wake_up(&zatm_vcc->tx_wait);
37569 }
37570
37571 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37572 index 876bae5..8978785 100644
37573 --- a/drivers/base/bus.c
37574 +++ b/drivers/base/bus.c
37575 @@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37576 return -EINVAL;
37577
37578 mutex_lock(&subsys->p->mutex);
37579 - list_add_tail(&sif->node, &subsys->p->interfaces);
37580 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37581 if (sif->add_dev) {
37582 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37583 while ((dev = subsys_dev_iter_next(&iter)))
37584 @@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37585 subsys = sif->subsys;
37586
37587 mutex_lock(&subsys->p->mutex);
37588 - list_del_init(&sif->node);
37589 + pax_list_del_init((struct list_head *)&sif->node);
37590 if (sif->remove_dev) {
37591 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37592 while ((dev = subsys_dev_iter_next(&iter)))
37593 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37594 index 25798db..15f130e 100644
37595 --- a/drivers/base/devtmpfs.c
37596 +++ b/drivers/base/devtmpfs.c
37597 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37598 if (!thread)
37599 return 0;
37600
37601 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37602 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37603 if (err)
37604 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37605 else
37606 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37607 *err = sys_unshare(CLONE_NEWNS);
37608 if (*err)
37609 goto out;
37610 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37611 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37612 if (*err)
37613 goto out;
37614 - sys_chdir("/.."); /* will traverse into overmounted root */
37615 - sys_chroot(".");
37616 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37617 + sys_chroot((char __force_user *)".");
37618 complete(&setup_done);
37619 while (1) {
37620 spin_lock(&req_lock);
37621 diff --git a/drivers/base/node.c b/drivers/base/node.c
37622 index 472168c..4af587e 100644
37623 --- a/drivers/base/node.c
37624 +++ b/drivers/base/node.c
37625 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37626 struct node_attr {
37627 struct device_attribute attr;
37628 enum node_states state;
37629 -};
37630 +} __do_const;
37631
37632 static ssize_t show_node_state(struct device *dev,
37633 struct device_attribute *attr, char *buf)
37634 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37635 index fb83d4a..e1797b3 100644
37636 --- a/drivers/base/power/domain.c
37637 +++ b/drivers/base/power/domain.c
37638 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37639 {
37640 struct cpuidle_driver *cpuidle_drv;
37641 struct gpd_cpuidle_data *cpuidle_data;
37642 - struct cpuidle_state *idle_state;
37643 + cpuidle_state_no_const *idle_state;
37644 int ret = 0;
37645
37646 if (IS_ERR_OR_NULL(genpd) || state < 0)
37647 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37648 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37649 {
37650 struct gpd_cpuidle_data *cpuidle_data;
37651 - struct cpuidle_state *idle_state;
37652 + cpuidle_state_no_const *idle_state;
37653 int ret = 0;
37654
37655 if (IS_ERR_OR_NULL(genpd))
37656 @@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37657 return ret;
37658 }
37659
37660 - dev->pm_domain->detach = genpd_dev_pm_detach;
37661 + pax_open_kernel();
37662 + *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37663 + pax_close_kernel();
37664
37665 return 0;
37666 }
37667 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37668 index a9d26ed..74b8405 100644
37669 --- a/drivers/base/power/sysfs.c
37670 +++ b/drivers/base/power/sysfs.c
37671 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37672 return -EIO;
37673 }
37674 }
37675 - return sprintf(buf, p);
37676 + return sprintf(buf, "%s", p);
37677 }
37678
37679 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37680 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37681 index c2744b3..08fac19 100644
37682 --- a/drivers/base/power/wakeup.c
37683 +++ b/drivers/base/power/wakeup.c
37684 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37685 * They need to be modified together atomically, so it's better to use one
37686 * atomic variable to hold them both.
37687 */
37688 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37689 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37690
37691 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37692 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37693
37694 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37695 {
37696 - unsigned int comb = atomic_read(&combined_event_count);
37697 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37698
37699 *cnt = (comb >> IN_PROGRESS_BITS);
37700 *inpr = comb & MAX_IN_PROGRESS;
37701 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37702 ws->start_prevent_time = ws->last_time;
37703
37704 /* Increment the counter of events in progress. */
37705 - cec = atomic_inc_return(&combined_event_count);
37706 + cec = atomic_inc_return_unchecked(&combined_event_count);
37707
37708 trace_wakeup_source_activate(ws->name, cec);
37709 }
37710 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37711 * Increment the counter of registered wakeup events and decrement the
37712 * couter of wakeup events in progress simultaneously.
37713 */
37714 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37715 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37716 trace_wakeup_source_deactivate(ws->name, cec);
37717
37718 split_counters(&cnt, &inpr);
37719 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37720 index 8d98a32..61d3165 100644
37721 --- a/drivers/base/syscore.c
37722 +++ b/drivers/base/syscore.c
37723 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37724 void register_syscore_ops(struct syscore_ops *ops)
37725 {
37726 mutex_lock(&syscore_ops_lock);
37727 - list_add_tail(&ops->node, &syscore_ops_list);
37728 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37729 mutex_unlock(&syscore_ops_lock);
37730 }
37731 EXPORT_SYMBOL_GPL(register_syscore_ops);
37732 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37733 void unregister_syscore_ops(struct syscore_ops *ops)
37734 {
37735 mutex_lock(&syscore_ops_lock);
37736 - list_del(&ops->node);
37737 + pax_list_del((struct list_head *)&ops->node);
37738 mutex_unlock(&syscore_ops_lock);
37739 }
37740 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37741 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37742 index ff20f19..018f1da 100644
37743 --- a/drivers/block/cciss.c
37744 +++ b/drivers/block/cciss.c
37745 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37746 while (!list_empty(&h->reqQ)) {
37747 c = list_entry(h->reqQ.next, CommandList_struct, list);
37748 /* can't do anything if fifo is full */
37749 - if ((h->access.fifo_full(h))) {
37750 + if ((h->access->fifo_full(h))) {
37751 dev_warn(&h->pdev->dev, "fifo full\n");
37752 break;
37753 }
37754 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37755 h->Qdepth--;
37756
37757 /* Tell the controller execute command */
37758 - h->access.submit_command(h, c);
37759 + h->access->submit_command(h, c);
37760
37761 /* Put job onto the completed Q */
37762 addQ(&h->cmpQ, c);
37763 @@ -3444,17 +3444,17 @@ startio:
37764
37765 static inline unsigned long get_next_completion(ctlr_info_t *h)
37766 {
37767 - return h->access.command_completed(h);
37768 + return h->access->command_completed(h);
37769 }
37770
37771 static inline int interrupt_pending(ctlr_info_t *h)
37772 {
37773 - return h->access.intr_pending(h);
37774 + return h->access->intr_pending(h);
37775 }
37776
37777 static inline long interrupt_not_for_us(ctlr_info_t *h)
37778 {
37779 - return ((h->access.intr_pending(h) == 0) ||
37780 + return ((h->access->intr_pending(h) == 0) ||
37781 (h->interrupts_enabled == 0));
37782 }
37783
37784 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37785 u32 a;
37786
37787 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37788 - return h->access.command_completed(h);
37789 + return h->access->command_completed(h);
37790
37791 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37792 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37793 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37794 trans_support & CFGTBL_Trans_use_short_tags);
37795
37796 /* Change the access methods to the performant access methods */
37797 - h->access = SA5_performant_access;
37798 + h->access = &SA5_performant_access;
37799 h->transMethod = CFGTBL_Trans_Performant;
37800
37801 return;
37802 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37803 if (prod_index < 0)
37804 return -ENODEV;
37805 h->product_name = products[prod_index].product_name;
37806 - h->access = *(products[prod_index].access);
37807 + h->access = products[prod_index].access;
37808
37809 if (cciss_board_disabled(h)) {
37810 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37811 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37812 }
37813
37814 /* make sure the board interrupts are off */
37815 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37816 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37817 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37818 if (rc)
37819 goto clean2;
37820 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37821 * fake ones to scoop up any residual completions.
37822 */
37823 spin_lock_irqsave(&h->lock, flags);
37824 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37825 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37826 spin_unlock_irqrestore(&h->lock, flags);
37827 free_irq(h->intr[h->intr_mode], h);
37828 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37829 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37830 dev_info(&h->pdev->dev, "Board READY.\n");
37831 dev_info(&h->pdev->dev,
37832 "Waiting for stale completions to drain.\n");
37833 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37834 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37835 msleep(10000);
37836 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37837 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37838
37839 rc = controller_reset_failed(h->cfgtable);
37840 if (rc)
37841 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37842 cciss_scsi_setup(h);
37843
37844 /* Turn the interrupts on so we can service requests */
37845 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37846 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37847
37848 /* Get the firmware version */
37849 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37850 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37851 kfree(flush_buf);
37852 if (return_code != IO_OK)
37853 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37854 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37855 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37856 free_irq(h->intr[h->intr_mode], h);
37857 }
37858
37859 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37860 index 7fda30e..2f27946 100644
37861 --- a/drivers/block/cciss.h
37862 +++ b/drivers/block/cciss.h
37863 @@ -101,7 +101,7 @@ struct ctlr_info
37864 /* information about each logical volume */
37865 drive_info_struct *drv[CISS_MAX_LUN];
37866
37867 - struct access_method access;
37868 + struct access_method *access;
37869
37870 /* queue and queue Info */
37871 struct list_head reqQ;
37872 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37873 }
37874
37875 static struct access_method SA5_access = {
37876 - SA5_submit_command,
37877 - SA5_intr_mask,
37878 - SA5_fifo_full,
37879 - SA5_intr_pending,
37880 - SA5_completed,
37881 + .submit_command = SA5_submit_command,
37882 + .set_intr_mask = SA5_intr_mask,
37883 + .fifo_full = SA5_fifo_full,
37884 + .intr_pending = SA5_intr_pending,
37885 + .command_completed = SA5_completed,
37886 };
37887
37888 static struct access_method SA5B_access = {
37889 - SA5_submit_command,
37890 - SA5B_intr_mask,
37891 - SA5_fifo_full,
37892 - SA5B_intr_pending,
37893 - SA5_completed,
37894 + .submit_command = SA5_submit_command,
37895 + .set_intr_mask = SA5B_intr_mask,
37896 + .fifo_full = SA5_fifo_full,
37897 + .intr_pending = SA5B_intr_pending,
37898 + .command_completed = SA5_completed,
37899 };
37900
37901 static struct access_method SA5_performant_access = {
37902 - SA5_submit_command,
37903 - SA5_performant_intr_mask,
37904 - SA5_fifo_full,
37905 - SA5_performant_intr_pending,
37906 - SA5_performant_completed,
37907 + .submit_command = SA5_submit_command,
37908 + .set_intr_mask = SA5_performant_intr_mask,
37909 + .fifo_full = SA5_fifo_full,
37910 + .intr_pending = SA5_performant_intr_pending,
37911 + .command_completed = SA5_performant_completed,
37912 };
37913
37914 struct board_type {
37915 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37916 index 2b94403..fd6ad1f 100644
37917 --- a/drivers/block/cpqarray.c
37918 +++ b/drivers/block/cpqarray.c
37919 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37920 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37921 goto Enomem4;
37922 }
37923 - hba[i]->access.set_intr_mask(hba[i], 0);
37924 + hba[i]->access->set_intr_mask(hba[i], 0);
37925 if (request_irq(hba[i]->intr, do_ida_intr,
37926 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37927 {
37928 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37929 add_timer(&hba[i]->timer);
37930
37931 /* Enable IRQ now that spinlock and rate limit timer are set up */
37932 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37933 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37934
37935 for(j=0; j<NWD; j++) {
37936 struct gendisk *disk = ida_gendisk[i][j];
37937 @@ -694,7 +694,7 @@ DBGINFO(
37938 for(i=0; i<NR_PRODUCTS; i++) {
37939 if (board_id == products[i].board_id) {
37940 c->product_name = products[i].product_name;
37941 - c->access = *(products[i].access);
37942 + c->access = products[i].access;
37943 break;
37944 }
37945 }
37946 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37947 hba[ctlr]->intr = intr;
37948 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37949 hba[ctlr]->product_name = products[j].product_name;
37950 - hba[ctlr]->access = *(products[j].access);
37951 + hba[ctlr]->access = products[j].access;
37952 hba[ctlr]->ctlr = ctlr;
37953 hba[ctlr]->board_id = board_id;
37954 hba[ctlr]->pci_dev = NULL; /* not PCI */
37955 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37956
37957 while((c = h->reqQ) != NULL) {
37958 /* Can't do anything if we're busy */
37959 - if (h->access.fifo_full(h) == 0)
37960 + if (h->access->fifo_full(h) == 0)
37961 return;
37962
37963 /* Get the first entry from the request Q */
37964 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37965 h->Qdepth--;
37966
37967 /* Tell the controller to do our bidding */
37968 - h->access.submit_command(h, c);
37969 + h->access->submit_command(h, c);
37970
37971 /* Get onto the completion Q */
37972 addQ(&h->cmpQ, c);
37973 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37974 unsigned long flags;
37975 __u32 a,a1;
37976
37977 - istat = h->access.intr_pending(h);
37978 + istat = h->access->intr_pending(h);
37979 /* Is this interrupt for us? */
37980 if (istat == 0)
37981 return IRQ_NONE;
37982 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37983 */
37984 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37985 if (istat & FIFO_NOT_EMPTY) {
37986 - while((a = h->access.command_completed(h))) {
37987 + while((a = h->access->command_completed(h))) {
37988 a1 = a; a &= ~3;
37989 if ((c = h->cmpQ) == NULL)
37990 {
37991 @@ -1448,11 +1448,11 @@ static int sendcmd(
37992 /*
37993 * Disable interrupt
37994 */
37995 - info_p->access.set_intr_mask(info_p, 0);
37996 + info_p->access->set_intr_mask(info_p, 0);
37997 /* Make sure there is room in the command FIFO */
37998 /* Actually it should be completely empty at this time. */
37999 for (i = 200000; i > 0; i--) {
38000 - temp = info_p->access.fifo_full(info_p);
38001 + temp = info_p->access->fifo_full(info_p);
38002 if (temp != 0) {
38003 break;
38004 }
38005 @@ -1465,7 +1465,7 @@ DBG(
38006 /*
38007 * Send the cmd
38008 */
38009 - info_p->access.submit_command(info_p, c);
38010 + info_p->access->submit_command(info_p, c);
38011 complete = pollcomplete(ctlr);
38012
38013 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38014 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38015 * we check the new geometry. Then turn interrupts back on when
38016 * we're done.
38017 */
38018 - host->access.set_intr_mask(host, 0);
38019 + host->access->set_intr_mask(host, 0);
38020 getgeometry(ctlr);
38021 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38022 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38023
38024 for(i=0; i<NWD; i++) {
38025 struct gendisk *disk = ida_gendisk[ctlr][i];
38026 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38027 /* Wait (up to 2 seconds) for a command to complete */
38028
38029 for (i = 200000; i > 0; i--) {
38030 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38031 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38032 if (done == 0) {
38033 udelay(10); /* a short fixed delay */
38034 } else
38035 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38036 index be73e9d..7fbf140 100644
38037 --- a/drivers/block/cpqarray.h
38038 +++ b/drivers/block/cpqarray.h
38039 @@ -99,7 +99,7 @@ struct ctlr_info {
38040 drv_info_t drv[NWD];
38041 struct proc_dir_entry *proc;
38042
38043 - struct access_method access;
38044 + struct access_method *access;
38045
38046 cmdlist_t *reqQ;
38047 cmdlist_t *cmpQ;
38048 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38049 index 434c77d..6d3219a 100644
38050 --- a/drivers/block/drbd/drbd_bitmap.c
38051 +++ b/drivers/block/drbd/drbd_bitmap.c
38052 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38053 submit_bio(rw, bio);
38054 /* this should not count as user activity and cause the
38055 * resync to throttle -- see drbd_rs_should_slow_down(). */
38056 - atomic_add(len >> 9, &device->rs_sect_ev);
38057 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38058 }
38059 }
38060
38061 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38062 index 9b22f8f..f2932af 100644
38063 --- a/drivers/block/drbd/drbd_int.h
38064 +++ b/drivers/block/drbd/drbd_int.h
38065 @@ -385,7 +385,7 @@ struct drbd_epoch {
38066 struct drbd_connection *connection;
38067 struct list_head list;
38068 unsigned int barrier_nr;
38069 - atomic_t epoch_size; /* increased on every request added. */
38070 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38071 atomic_t active; /* increased on every req. added, and dec on every finished. */
38072 unsigned long flags;
38073 };
38074 @@ -946,7 +946,7 @@ struct drbd_device {
38075 unsigned int al_tr_number;
38076 int al_tr_cycle;
38077 wait_queue_head_t seq_wait;
38078 - atomic_t packet_seq;
38079 + atomic_unchecked_t packet_seq;
38080 unsigned int peer_seq;
38081 spinlock_t peer_seq_lock;
38082 unsigned long comm_bm_set; /* communicated number of set bits. */
38083 @@ -955,8 +955,8 @@ struct drbd_device {
38084 struct mutex own_state_mutex;
38085 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38086 char congestion_reason; /* Why we where congested... */
38087 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38088 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38089 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38090 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38091 int rs_last_sect_ev; /* counter to compare with */
38092 int rs_last_events; /* counter of read or write "events" (unit sectors)
38093 * on the lower level device when we last looked. */
38094 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38095 char __user *uoptval;
38096 int err;
38097
38098 - uoptval = (char __user __force *)optval;
38099 + uoptval = (char __force_user *)optval;
38100
38101 set_fs(KERNEL_DS);
38102 if (level == SOL_SOCKET)
38103 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38104 index 973c185..05d8b1a 100644
38105 --- a/drivers/block/drbd/drbd_main.c
38106 +++ b/drivers/block/drbd/drbd_main.c
38107 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38108 p->sector = sector;
38109 p->block_id = block_id;
38110 p->blksize = blksize;
38111 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38112 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38113 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38114 }
38115
38116 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38117 return -EIO;
38118 p->sector = cpu_to_be64(req->i.sector);
38119 p->block_id = (unsigned long)req;
38120 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38121 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38122 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38123 if (device->state.conn >= C_SYNC_SOURCE &&
38124 device->state.conn <= C_PAUSED_SYNC_T)
38125 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38126 atomic_set(&device->unacked_cnt, 0);
38127 atomic_set(&device->local_cnt, 0);
38128 atomic_set(&device->pp_in_use_by_net, 0);
38129 - atomic_set(&device->rs_sect_in, 0);
38130 - atomic_set(&device->rs_sect_ev, 0);
38131 + atomic_set_unchecked(&device->rs_sect_in, 0);
38132 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38133 atomic_set(&device->ap_in_flight, 0);
38134 atomic_set(&device->md_io.in_use, 0);
38135
38136 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38137 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38138 struct drbd_resource *resource = connection->resource;
38139
38140 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38141 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38142 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38143 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38144 kfree(connection->current_epoch);
38145
38146 idr_destroy(&connection->peer_devices);
38147 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38148 index 1cd47df..57c53c0 100644
38149 --- a/drivers/block/drbd/drbd_nl.c
38150 +++ b/drivers/block/drbd/drbd_nl.c
38151 @@ -3645,13 +3645,13 @@ finish:
38152
38153 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38154 {
38155 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38156 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38157 struct sk_buff *msg;
38158 struct drbd_genlmsghdr *d_out;
38159 unsigned seq;
38160 int err = -ENOMEM;
38161
38162 - seq = atomic_inc_return(&drbd_genl_seq);
38163 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38164 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38165 if (!msg)
38166 goto failed;
38167 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38168 index 6960fb0..215d76b 100644
38169 --- a/drivers/block/drbd/drbd_receiver.c
38170 +++ b/drivers/block/drbd/drbd_receiver.c
38171 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38172 struct drbd_device *device = peer_device->device;
38173 int err;
38174
38175 - atomic_set(&device->packet_seq, 0);
38176 + atomic_set_unchecked(&device->packet_seq, 0);
38177 device->peer_seq = 0;
38178
38179 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38180 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38181 do {
38182 next_epoch = NULL;
38183
38184 - epoch_size = atomic_read(&epoch->epoch_size);
38185 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38186
38187 switch (ev & ~EV_CLEANUP) {
38188 case EV_PUT:
38189 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38190 rv = FE_DESTROYED;
38191 } else {
38192 epoch->flags = 0;
38193 - atomic_set(&epoch->epoch_size, 0);
38194 + atomic_set_unchecked(&epoch->epoch_size, 0);
38195 /* atomic_set(&epoch->active, 0); is already zero */
38196 if (rv == FE_STILL_LIVE)
38197 rv = FE_RECYCLED;
38198 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38199 conn_wait_active_ee_empty(connection);
38200 drbd_flush(connection);
38201
38202 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38203 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38204 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38205 if (epoch)
38206 break;
38207 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38208 }
38209
38210 epoch->flags = 0;
38211 - atomic_set(&epoch->epoch_size, 0);
38212 + atomic_set_unchecked(&epoch->epoch_size, 0);
38213 atomic_set(&epoch->active, 0);
38214
38215 spin_lock(&connection->epoch_lock);
38216 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38217 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38218 list_add(&epoch->list, &connection->current_epoch->list);
38219 connection->current_epoch = epoch;
38220 connection->epochs++;
38221 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38222 list_add_tail(&peer_req->w.list, &device->sync_ee);
38223 spin_unlock_irq(&device->resource->req_lock);
38224
38225 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38226 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38227 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38228 return 0;
38229
38230 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38231 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38232 }
38233
38234 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38235 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38236
38237 return err;
38238 }
38239 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38240
38241 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38242 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38243 - atomic_inc(&connection->current_epoch->epoch_size);
38244 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38245 err2 = drbd_drain_block(peer_device, pi->size);
38246 if (!err)
38247 err = err2;
38248 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38249
38250 spin_lock(&connection->epoch_lock);
38251 peer_req->epoch = connection->current_epoch;
38252 - atomic_inc(&peer_req->epoch->epoch_size);
38253 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38254 atomic_inc(&peer_req->epoch->active);
38255 spin_unlock(&connection->epoch_lock);
38256
38257 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38258
38259 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38260 (int)part_stat_read(&disk->part0, sectors[1]) -
38261 - atomic_read(&device->rs_sect_ev);
38262 + atomic_read_unchecked(&device->rs_sect_ev);
38263
38264 if (atomic_read(&device->ap_actlog_cnt)
38265 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38266 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38267 device->use_csums = true;
38268 } else if (pi->cmd == P_OV_REPLY) {
38269 /* track progress, we may need to throttle */
38270 - atomic_add(size >> 9, &device->rs_sect_in);
38271 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38272 peer_req->w.cb = w_e_end_ov_reply;
38273 dec_rs_pending(device);
38274 /* drbd_rs_begin_io done when we sent this request,
38275 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38276 goto out_free_e;
38277
38278 submit_for_resync:
38279 - atomic_add(size >> 9, &device->rs_sect_ev);
38280 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38281
38282 submit:
38283 update_receiver_timing_details(connection, drbd_submit_peer_request);
38284 @@ -4564,7 +4564,7 @@ struct data_cmd {
38285 int expect_payload;
38286 size_t pkt_size;
38287 int (*fn)(struct drbd_connection *, struct packet_info *);
38288 -};
38289 +} __do_const;
38290
38291 static struct data_cmd drbd_cmd_handler[] = {
38292 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38293 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38294 if (!list_empty(&connection->current_epoch->list))
38295 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38296 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38297 - atomic_set(&connection->current_epoch->epoch_size, 0);
38298 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38299 connection->send.seen_any_write_yet = false;
38300
38301 drbd_info(connection, "Connection closed\n");
38302 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38303 put_ldev(device);
38304 }
38305 dec_rs_pending(device);
38306 - atomic_add(blksize >> 9, &device->rs_sect_in);
38307 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38308
38309 return 0;
38310 }
38311 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38312 struct asender_cmd {
38313 size_t pkt_size;
38314 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38315 -};
38316 +} __do_const;
38317
38318 static struct asender_cmd asender_tbl[] = {
38319 [P_PING] = { 0, got_Ping },
38320 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38321 index d2d1f97..6a1188f 100644
38322 --- a/drivers/block/drbd/drbd_worker.c
38323 +++ b/drivers/block/drbd/drbd_worker.c
38324 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38325 list_add_tail(&peer_req->w.list, &device->read_ee);
38326 spin_unlock_irq(&device->resource->req_lock);
38327
38328 - atomic_add(size >> 9, &device->rs_sect_ev);
38329 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38330 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38331 return 0;
38332
38333 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38334 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38335 int number, mxb;
38336
38337 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38338 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38339 device->rs_in_flight -= sect_in;
38340
38341 rcu_read_lock();
38342 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38343 {
38344 struct fifo_buffer *plan;
38345
38346 - atomic_set(&device->rs_sect_in, 0);
38347 - atomic_set(&device->rs_sect_ev, 0);
38348 + atomic_set_unchecked(&device->rs_sect_in, 0);
38349 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38350 device->rs_in_flight = 0;
38351
38352 /* Updating the RCU protected object in place is necessary since
38353 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38354 index 6cb1beb..bf490f7 100644
38355 --- a/drivers/block/loop.c
38356 +++ b/drivers/block/loop.c
38357 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38358
38359 file_start_write(file);
38360 set_fs(get_ds());
38361 - bw = file->f_op->write(file, buf, len, &pos);
38362 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38363 set_fs(old_fs);
38364 file_end_write(file);
38365 if (likely(bw == len))
38366 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38367 index e2bb8af..44b8aef 100644
38368 --- a/drivers/block/nvme-core.c
38369 +++ b/drivers/block/nvme-core.c
38370 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38371 static struct task_struct *nvme_thread;
38372 static struct workqueue_struct *nvme_workq;
38373 static wait_queue_head_t nvme_kthread_wait;
38374 -static struct notifier_block nvme_nb;
38375
38376 static void nvme_reset_failed_dev(struct work_struct *ws);
38377
38378 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38379 .err_handler = &nvme_err_handler,
38380 };
38381
38382 +static struct notifier_block nvme_nb = {
38383 + .notifier_call = &nvme_cpu_notify,
38384 +};
38385 +
38386 static int __init nvme_init(void)
38387 {
38388 int result;
38389 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38390 else if (result > 0)
38391 nvme_major = result;
38392
38393 - nvme_nb.notifier_call = &nvme_cpu_notify;
38394 result = register_hotcpu_notifier(&nvme_nb);
38395 if (result)
38396 goto unregister_blkdev;
38397 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38398 index 09e628da..7607aaa 100644
38399 --- a/drivers/block/pktcdvd.c
38400 +++ b/drivers/block/pktcdvd.c
38401 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38402
38403 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38404 {
38405 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38406 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38407 }
38408
38409 /*
38410 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38411 return -EROFS;
38412 }
38413 pd->settings.fp = ti.fp;
38414 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38415 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38416
38417 if (ti.nwa_v) {
38418 pd->nwa = be32_to_cpu(ti.next_writable);
38419 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38420 index e5565fb..71be10b4 100644
38421 --- a/drivers/block/smart1,2.h
38422 +++ b/drivers/block/smart1,2.h
38423 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38424 }
38425
38426 static struct access_method smart4_access = {
38427 - smart4_submit_command,
38428 - smart4_intr_mask,
38429 - smart4_fifo_full,
38430 - smart4_intr_pending,
38431 - smart4_completed,
38432 + .submit_command = smart4_submit_command,
38433 + .set_intr_mask = smart4_intr_mask,
38434 + .fifo_full = smart4_fifo_full,
38435 + .intr_pending = smart4_intr_pending,
38436 + .command_completed = smart4_completed,
38437 };
38438
38439 /*
38440 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38441 }
38442
38443 static struct access_method smart2_access = {
38444 - smart2_submit_command,
38445 - smart2_intr_mask,
38446 - smart2_fifo_full,
38447 - smart2_intr_pending,
38448 - smart2_completed,
38449 + .submit_command = smart2_submit_command,
38450 + .set_intr_mask = smart2_intr_mask,
38451 + .fifo_full = smart2_fifo_full,
38452 + .intr_pending = smart2_intr_pending,
38453 + .command_completed = smart2_completed,
38454 };
38455
38456 /*
38457 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38458 }
38459
38460 static struct access_method smart2e_access = {
38461 - smart2e_submit_command,
38462 - smart2e_intr_mask,
38463 - smart2e_fifo_full,
38464 - smart2e_intr_pending,
38465 - smart2e_completed,
38466 + .submit_command = smart2e_submit_command,
38467 + .set_intr_mask = smart2e_intr_mask,
38468 + .fifo_full = smart2e_fifo_full,
38469 + .intr_pending = smart2e_intr_pending,
38470 + .command_completed = smart2e_completed,
38471 };
38472
38473 /*
38474 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38475 }
38476
38477 static struct access_method smart1_access = {
38478 - smart1_submit_command,
38479 - smart1_intr_mask,
38480 - smart1_fifo_full,
38481 - smart1_intr_pending,
38482 - smart1_completed,
38483 + .submit_command = smart1_submit_command,
38484 + .set_intr_mask = smart1_intr_mask,
38485 + .fifo_full = smart1_fifo_full,
38486 + .intr_pending = smart1_intr_pending,
38487 + .command_completed = smart1_completed,
38488 };
38489 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38490 index f038dba..bb74c08 100644
38491 --- a/drivers/bluetooth/btwilink.c
38492 +++ b/drivers/bluetooth/btwilink.c
38493 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38494
38495 static int bt_ti_probe(struct platform_device *pdev)
38496 {
38497 - static struct ti_st *hst;
38498 + struct ti_st *hst;
38499 struct hci_dev *hdev;
38500 int err;
38501
38502 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38503 index 5d28a45..a538f90 100644
38504 --- a/drivers/cdrom/cdrom.c
38505 +++ b/drivers/cdrom/cdrom.c
38506 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38507 ENSURE(reset, CDC_RESET);
38508 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38509 cdi->mc_flags = 0;
38510 - cdo->n_minors = 0;
38511 cdi->options = CDO_USE_FFLAGS;
38512
38513 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38514 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38515 else
38516 cdi->cdda_method = CDDA_OLD;
38517
38518 - if (!cdo->generic_packet)
38519 - cdo->generic_packet = cdrom_dummy_generic_packet;
38520 + if (!cdo->generic_packet) {
38521 + pax_open_kernel();
38522 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38523 + pax_close_kernel();
38524 + }
38525
38526 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38527 mutex_lock(&cdrom_mutex);
38528 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38529 if (cdi->exit)
38530 cdi->exit(cdi);
38531
38532 - cdi->ops->n_minors--;
38533 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38534 }
38535
38536 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38537 */
38538 nr = nframes;
38539 do {
38540 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38541 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38542 if (cgc.buffer)
38543 break;
38544
38545 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38546 struct cdrom_device_info *cdi;
38547 int ret;
38548
38549 - ret = scnprintf(info + *pos, max_size - *pos, header);
38550 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38551 if (!ret)
38552 return 1;
38553
38554 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38555 index 584bc31..e64a12c 100644
38556 --- a/drivers/cdrom/gdrom.c
38557 +++ b/drivers/cdrom/gdrom.c
38558 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38559 .audio_ioctl = gdrom_audio_ioctl,
38560 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38561 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38562 - .n_minors = 1,
38563 };
38564
38565 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38566 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38567 index efefd12..4f1d494 100644
38568 --- a/drivers/char/Kconfig
38569 +++ b/drivers/char/Kconfig
38570 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38571
38572 config DEVKMEM
38573 bool "/dev/kmem virtual device support"
38574 - default y
38575 + default n
38576 + depends on !GRKERNSEC_KMEM
38577 help
38578 Say Y here if you want to support the /dev/kmem device. The
38579 /dev/kmem device is rarely used, but can be used for certain
38580 @@ -577,6 +578,7 @@ config DEVPORT
38581 bool
38582 depends on !M68K
38583 depends on ISA || PCI
38584 + depends on !GRKERNSEC_KMEM
38585 default y
38586
38587 source "drivers/s390/char/Kconfig"
38588 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38589 index a48e05b..6bac831 100644
38590 --- a/drivers/char/agp/compat_ioctl.c
38591 +++ b/drivers/char/agp/compat_ioctl.c
38592 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38593 return -ENOMEM;
38594 }
38595
38596 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38597 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38598 sizeof(*usegment) * ureserve.seg_count)) {
38599 kfree(usegment);
38600 kfree(ksegment);
38601 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38602 index 09f17eb..8531d2f 100644
38603 --- a/drivers/char/agp/frontend.c
38604 +++ b/drivers/char/agp/frontend.c
38605 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38606 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38607 return -EFAULT;
38608
38609 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38610 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38611 return -EFAULT;
38612
38613 client = agp_find_client_by_pid(reserve.pid);
38614 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38615 if (segment == NULL)
38616 return -ENOMEM;
38617
38618 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38619 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38620 sizeof(struct agp_segment) * reserve.seg_count)) {
38621 kfree(segment);
38622 return -EFAULT;
38623 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38624 index 4f94375..413694e 100644
38625 --- a/drivers/char/genrtc.c
38626 +++ b/drivers/char/genrtc.c
38627 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38628 switch (cmd) {
38629
38630 case RTC_PLL_GET:
38631 + memset(&pll, 0, sizeof(pll));
38632 if (get_rtc_pll(&pll))
38633 return -EINVAL;
38634 else
38635 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38636 index d5d4cd8..22d561d 100644
38637 --- a/drivers/char/hpet.c
38638 +++ b/drivers/char/hpet.c
38639 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38640 }
38641
38642 static int
38643 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38644 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38645 struct hpet_info *info)
38646 {
38647 struct hpet_timer __iomem *timer;
38648 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38649 index f816211..89eadea 100644
38650 --- a/drivers/char/ipmi/ipmi_msghandler.c
38651 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38652 @@ -438,7 +438,7 @@ struct ipmi_smi {
38653 struct proc_dir_entry *proc_dir;
38654 char proc_dir_name[10];
38655
38656 - atomic_t stats[IPMI_NUM_STATS];
38657 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38658
38659 /*
38660 * run_to_completion duplicate of smb_info, smi_info
38661 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38662 static DEFINE_MUTEX(smi_watchers_mutex);
38663
38664 #define ipmi_inc_stat(intf, stat) \
38665 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38666 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38667 #define ipmi_get_stat(intf, stat) \
38668 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38669 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38670
38671 static int is_lan_addr(struct ipmi_addr *addr)
38672 {
38673 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38674 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38675 init_waitqueue_head(&intf->waitq);
38676 for (i = 0; i < IPMI_NUM_STATS; i++)
38677 - atomic_set(&intf->stats[i], 0);
38678 + atomic_set_unchecked(&intf->stats[i], 0);
38679
38680 intf->proc_dir = NULL;
38681
38682 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38683 index 5c4e1f6..0ea58f9 100644
38684 --- a/drivers/char/ipmi/ipmi_si_intf.c
38685 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38686 @@ -285,7 +285,7 @@ struct smi_info {
38687 unsigned char slave_addr;
38688
38689 /* Counters and things for the proc filesystem. */
38690 - atomic_t stats[SI_NUM_STATS];
38691 + atomic_unchecked_t stats[SI_NUM_STATS];
38692
38693 struct task_struct *thread;
38694
38695 @@ -294,9 +294,9 @@ struct smi_info {
38696 };
38697
38698 #define smi_inc_stat(smi, stat) \
38699 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38700 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38701 #define smi_get_stat(smi, stat) \
38702 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38703 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38704
38705 #define SI_MAX_PARMS 4
38706
38707 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38708 atomic_set(&new_smi->req_events, 0);
38709 new_smi->run_to_completion = false;
38710 for (i = 0; i < SI_NUM_STATS; i++)
38711 - atomic_set(&new_smi->stats[i], 0);
38712 + atomic_set_unchecked(&new_smi->stats[i], 0);
38713
38714 new_smi->interrupt_disabled = true;
38715 atomic_set(&new_smi->stop_operation, 0);
38716 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38717 index 524b707..62a3d70 100644
38718 --- a/drivers/char/mem.c
38719 +++ b/drivers/char/mem.c
38720 @@ -18,6 +18,7 @@
38721 #include <linux/raw.h>
38722 #include <linux/tty.h>
38723 #include <linux/capability.h>
38724 +#include <linux/security.h>
38725 #include <linux/ptrace.h>
38726 #include <linux/device.h>
38727 #include <linux/highmem.h>
38728 @@ -36,6 +37,10 @@
38729
38730 #define DEVPORT_MINOR 4
38731
38732 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38733 +extern const struct file_operations grsec_fops;
38734 +#endif
38735 +
38736 static inline unsigned long size_inside_page(unsigned long start,
38737 unsigned long size)
38738 {
38739 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38740
38741 while (cursor < to) {
38742 if (!devmem_is_allowed(pfn)) {
38743 +#ifdef CONFIG_GRKERNSEC_KMEM
38744 + gr_handle_mem_readwrite(from, to);
38745 +#else
38746 printk(KERN_INFO
38747 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38748 current->comm, from, to);
38749 +#endif
38750 return 0;
38751 }
38752 cursor += PAGE_SIZE;
38753 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38754 }
38755 return 1;
38756 }
38757 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38758 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38759 +{
38760 + return 0;
38761 +}
38762 #else
38763 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38764 {
38765 @@ -121,7 +135,8 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38766 #endif
38767
38768 while (count > 0) {
38769 - unsigned long remaining;
38770 + unsigned long remaining = 0;
38771 + char *temp;
38772
38773 sz = size_inside_page(p, count);
38774
38775 @@ -137,7 +152,24 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38776 if (!ptr)
38777 return -EFAULT;
38778
38779 - remaining = copy_to_user(buf, ptr, sz);
38780 +#ifdef CONFIG_PAX_USERCOPY
38781 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38782 + if (!temp) {
38783 + unxlate_dev_mem_ptr(p, ptr);
38784 + return -ENOMEM;
38785 + }
38786 + remaining = probe_kernel_read(temp, ptr, sz);
38787 +#else
38788 + temp = ptr;
38789 +#endif
38790 +
38791 + if (!remaining)
38792 + remaining = copy_to_user(buf, temp, sz);
38793 +
38794 +#ifdef CONFIG_PAX_USERCOPY
38795 + kfree(temp);
38796 +#endif
38797 +
38798 unxlate_dev_mem_ptr(p, ptr);
38799 if (remaining)
38800 return -EFAULT;
38801 @@ -369,9 +401,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38802 size_t count, loff_t *ppos)
38803 {
38804 unsigned long p = *ppos;
38805 - ssize_t low_count, read, sz;
38806 + ssize_t low_count, read, sz, err = 0;
38807 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38808 - int err = 0;
38809
38810 read = 0;
38811 if (p < (unsigned long) high_memory) {
38812 @@ -393,6 +424,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38813 }
38814 #endif
38815 while (low_count > 0) {
38816 + char *temp;
38817 +
38818 sz = size_inside_page(p, low_count);
38819
38820 /*
38821 @@ -402,7 +435,23 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38822 */
38823 kbuf = xlate_dev_kmem_ptr((char *)p);
38824
38825 - if (copy_to_user(buf, kbuf, sz))
38826 +#ifdef CONFIG_PAX_USERCOPY
38827 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38828 + if (!temp)
38829 + return -ENOMEM;
38830 + err = probe_kernel_read(temp, kbuf, sz);
38831 +#else
38832 + temp = kbuf;
38833 +#endif
38834 +
38835 + if (!err)
38836 + err = copy_to_user(buf, temp, sz);
38837 +
38838 +#ifdef CONFIG_PAX_USERCOPY
38839 + kfree(temp);
38840 +#endif
38841 +
38842 + if (err)
38843 return -EFAULT;
38844 buf += sz;
38845 p += sz;
38846 @@ -797,6 +846,9 @@ static const struct memdev {
38847 #ifdef CONFIG_PRINTK
38848 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38849 #endif
38850 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38851 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38852 +#endif
38853 };
38854
38855 static int memory_open(struct inode *inode, struct file *filp)
38856 @@ -868,7 +920,7 @@ static int __init chr_dev_init(void)
38857 continue;
38858
38859 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38860 - NULL, devlist[minor].name);
38861 + NULL, "%s", devlist[minor].name);
38862 }
38863
38864 return tty_init();
38865 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38866 index 9df78e2..01ba9ae 100644
38867 --- a/drivers/char/nvram.c
38868 +++ b/drivers/char/nvram.c
38869 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38870
38871 spin_unlock_irq(&rtc_lock);
38872
38873 - if (copy_to_user(buf, contents, tmp - contents))
38874 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38875 return -EFAULT;
38876
38877 *ppos = i;
38878 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38879 index 0ea9986..e7b07e4 100644
38880 --- a/drivers/char/pcmcia/synclink_cs.c
38881 +++ b/drivers/char/pcmcia/synclink_cs.c
38882 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38883
38884 if (debug_level >= DEBUG_LEVEL_INFO)
38885 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38886 - __FILE__, __LINE__, info->device_name, port->count);
38887 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38888
38889 if (tty_port_close_start(port, tty, filp) == 0)
38890 goto cleanup;
38891 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38892 cleanup:
38893 if (debug_level >= DEBUG_LEVEL_INFO)
38894 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38895 - tty->driver->name, port->count);
38896 + tty->driver->name, atomic_read(&port->count));
38897 }
38898
38899 /* Wait until the transmitter is empty.
38900 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38901
38902 if (debug_level >= DEBUG_LEVEL_INFO)
38903 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38904 - __FILE__, __LINE__, tty->driver->name, port->count);
38905 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38906
38907 /* If port is closing, signal caller to try again */
38908 if (port->flags & ASYNC_CLOSING){
38909 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38910 goto cleanup;
38911 }
38912 spin_lock(&port->lock);
38913 - port->count++;
38914 + atomic_inc(&port->count);
38915 spin_unlock(&port->lock);
38916 spin_unlock_irqrestore(&info->netlock, flags);
38917
38918 - if (port->count == 1) {
38919 + if (atomic_read(&port->count) == 1) {
38920 /* 1st open on this device, init hardware */
38921 retval = startup(info, tty);
38922 if (retval < 0)
38923 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38924 unsigned short new_crctype;
38925
38926 /* return error if TTY interface open */
38927 - if (info->port.count)
38928 + if (atomic_read(&info->port.count))
38929 return -EBUSY;
38930
38931 switch (encoding)
38932 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38933
38934 /* arbitrate between network and tty opens */
38935 spin_lock_irqsave(&info->netlock, flags);
38936 - if (info->port.count != 0 || info->netcount != 0) {
38937 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38938 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38939 spin_unlock_irqrestore(&info->netlock, flags);
38940 return -EBUSY;
38941 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38942 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38943
38944 /* return error if TTY interface open */
38945 - if (info->port.count)
38946 + if (atomic_read(&info->port.count))
38947 return -EBUSY;
38948
38949 if (cmd != SIOCWANDEV)
38950 diff --git a/drivers/char/random.c b/drivers/char/random.c
38951 index 04645c0..6416f00 100644
38952 --- a/drivers/char/random.c
38953 +++ b/drivers/char/random.c
38954 @@ -289,9 +289,6 @@
38955 /*
38956 * To allow fractional bits to be tracked, the entropy_count field is
38957 * denominated in units of 1/8th bits.
38958 - *
38959 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38960 - * credit_entropy_bits() needs to be 64 bits wide.
38961 */
38962 #define ENTROPY_SHIFT 3
38963 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38964 @@ -439,9 +436,9 @@ struct entropy_store {
38965 };
38966
38967 static void push_to_pool(struct work_struct *work);
38968 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38969 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38970 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38971 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38972 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38973 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38974
38975 static struct entropy_store input_pool = {
38976 .poolinfo = &poolinfo_table[0],
38977 @@ -569,19 +566,19 @@ static void fast_mix(struct fast_pool *f)
38978 __u32 c = f->pool[2], d = f->pool[3];
38979
38980 a += b; c += d;
38981 - b = rol32(a, 6); d = rol32(c, 27);
38982 + b = rol32(b, 6); d = rol32(d, 27);
38983 d ^= a; b ^= c;
38984
38985 a += b; c += d;
38986 - b = rol32(a, 16); d = rol32(c, 14);
38987 + b = rol32(b, 16); d = rol32(d, 14);
38988 d ^= a; b ^= c;
38989
38990 a += b; c += d;
38991 - b = rol32(a, 6); d = rol32(c, 27);
38992 + b = rol32(b, 6); d = rol32(d, 27);
38993 d ^= a; b ^= c;
38994
38995 a += b; c += d;
38996 - b = rol32(a, 16); d = rol32(c, 14);
38997 + b = rol32(b, 16); d = rol32(d, 14);
38998 d ^= a; b ^= c;
38999
39000 f->pool[0] = a; f->pool[1] = b;
39001 @@ -635,7 +632,7 @@ retry:
39002 /* The +2 corresponds to the /4 in the denominator */
39003
39004 do {
39005 - unsigned int anfrac = min(pnfrac, pool_size/2);
39006 + u64 anfrac = min(pnfrac, pool_size/2);
39007 unsigned int add =
39008 ((pool_size - entropy_count)*anfrac*3) >> s;
39009
39010 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39011
39012 extract_buf(r, tmp);
39013 i = min_t(int, nbytes, EXTRACT_SIZE);
39014 - if (copy_to_user(buf, tmp, i)) {
39015 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39016 ret = -EFAULT;
39017 break;
39018 }
39019 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39020 static int proc_do_uuid(struct ctl_table *table, int write,
39021 void __user *buffer, size_t *lenp, loff_t *ppos)
39022 {
39023 - struct ctl_table fake_table;
39024 + ctl_table_no_const fake_table;
39025 unsigned char buf[64], tmp_uuid[16], *uuid;
39026
39027 uuid = table->data;
39028 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39029 static int proc_do_entropy(struct ctl_table *table, int write,
39030 void __user *buffer, size_t *lenp, loff_t *ppos)
39031 {
39032 - struct ctl_table fake_table;
39033 + ctl_table_no_const fake_table;
39034 int entropy_count;
39035
39036 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39037 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39038 index 7cc1fe22..b602d6b 100644
39039 --- a/drivers/char/sonypi.c
39040 +++ b/drivers/char/sonypi.c
39041 @@ -54,6 +54,7 @@
39042
39043 #include <asm/uaccess.h>
39044 #include <asm/io.h>
39045 +#include <asm/local.h>
39046
39047 #include <linux/sonypi.h>
39048
39049 @@ -490,7 +491,7 @@ static struct sonypi_device {
39050 spinlock_t fifo_lock;
39051 wait_queue_head_t fifo_proc_list;
39052 struct fasync_struct *fifo_async;
39053 - int open_count;
39054 + local_t open_count;
39055 int model;
39056 struct input_dev *input_jog_dev;
39057 struct input_dev *input_key_dev;
39058 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39059 static int sonypi_misc_release(struct inode *inode, struct file *file)
39060 {
39061 mutex_lock(&sonypi_device.lock);
39062 - sonypi_device.open_count--;
39063 + local_dec(&sonypi_device.open_count);
39064 mutex_unlock(&sonypi_device.lock);
39065 return 0;
39066 }
39067 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39068 {
39069 mutex_lock(&sonypi_device.lock);
39070 /* Flush input queue on first open */
39071 - if (!sonypi_device.open_count)
39072 + if (!local_read(&sonypi_device.open_count))
39073 kfifo_reset(&sonypi_device.fifo);
39074 - sonypi_device.open_count++;
39075 + local_inc(&sonypi_device.open_count);
39076 mutex_unlock(&sonypi_device.lock);
39077
39078 return 0;
39079 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39080 index 565a947..dcdc06e 100644
39081 --- a/drivers/char/tpm/tpm_acpi.c
39082 +++ b/drivers/char/tpm/tpm_acpi.c
39083 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39084 virt = acpi_os_map_iomem(start, len);
39085 if (!virt) {
39086 kfree(log->bios_event_log);
39087 + log->bios_event_log = NULL;
39088 printk("%s: ERROR - Unable to map memory\n", __func__);
39089 return -EIO;
39090 }
39091
39092 - memcpy_fromio(log->bios_event_log, virt, len);
39093 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39094
39095 acpi_os_unmap_iomem(virt, len);
39096 return 0;
39097 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39098 index 3a56a13..f8cbd25 100644
39099 --- a/drivers/char/tpm/tpm_eventlog.c
39100 +++ b/drivers/char/tpm/tpm_eventlog.c
39101 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39102 event = addr;
39103
39104 if ((event->event_type == 0 && event->event_size == 0) ||
39105 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39106 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39107 return NULL;
39108
39109 return addr;
39110 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39111 return NULL;
39112
39113 if ((event->event_type == 0 && event->event_size == 0) ||
39114 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39115 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39116 return NULL;
39117
39118 (*pos)++;
39119 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39120 int i;
39121
39122 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39123 - seq_putc(m, data[i]);
39124 + if (!seq_putc(m, data[i]))
39125 + return -EFAULT;
39126
39127 return 0;
39128 }
39129 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39130 index cf7a561..c319ce0 100644
39131 --- a/drivers/char/virtio_console.c
39132 +++ b/drivers/char/virtio_console.c
39133 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39134 if (to_user) {
39135 ssize_t ret;
39136
39137 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39138 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39139 if (ret)
39140 return -EFAULT;
39141 } else {
39142 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39143 if (!port_has_data(port) && !port->host_connected)
39144 return 0;
39145
39146 - return fill_readbuf(port, ubuf, count, true);
39147 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39148 }
39149
39150 static int wait_port_writable(struct port *port, bool nonblock)
39151 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39152 index b9355da..9611f4e 100644
39153 --- a/drivers/clk/clk-composite.c
39154 +++ b/drivers/clk/clk-composite.c
39155 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39156 struct clk *clk;
39157 struct clk_init_data init;
39158 struct clk_composite *composite;
39159 - struct clk_ops *clk_composite_ops;
39160 + clk_ops_no_const *clk_composite_ops;
39161
39162 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39163 if (!composite) {
39164 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39165 index dd3a78c..386d49c 100644
39166 --- a/drivers/clk/socfpga/clk-gate.c
39167 +++ b/drivers/clk/socfpga/clk-gate.c
39168 @@ -22,6 +22,7 @@
39169 #include <linux/mfd/syscon.h>
39170 #include <linux/of.h>
39171 #include <linux/regmap.h>
39172 +#include <asm/pgtable.h>
39173
39174 #include "clk.h"
39175
39176 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39177 return 0;
39178 }
39179
39180 -static struct clk_ops gateclk_ops = {
39181 +static clk_ops_no_const gateclk_ops __read_only = {
39182 .prepare = socfpga_clk_prepare,
39183 .recalc_rate = socfpga_clk_recalc_rate,
39184 .get_parent = socfpga_clk_get_parent,
39185 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39186 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39187 socfpga_clk->hw.bit_idx = clk_gate[1];
39188
39189 - gateclk_ops.enable = clk_gate_ops.enable;
39190 - gateclk_ops.disable = clk_gate_ops.disable;
39191 + pax_open_kernel();
39192 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39193 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39194 + pax_close_kernel();
39195 }
39196
39197 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39198 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39199 index de6da95..c98278b 100644
39200 --- a/drivers/clk/socfpga/clk-pll.c
39201 +++ b/drivers/clk/socfpga/clk-pll.c
39202 @@ -21,6 +21,7 @@
39203 #include <linux/io.h>
39204 #include <linux/of.h>
39205 #include <linux/of_address.h>
39206 +#include <asm/pgtable.h>
39207
39208 #include "clk.h"
39209
39210 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39211 CLK_MGR_PLL_CLK_SRC_MASK;
39212 }
39213
39214 -static struct clk_ops clk_pll_ops = {
39215 +static clk_ops_no_const clk_pll_ops __read_only = {
39216 .recalc_rate = clk_pll_recalc_rate,
39217 .get_parent = clk_pll_get_parent,
39218 };
39219 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39220 pll_clk->hw.hw.init = &init;
39221
39222 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39223 - clk_pll_ops.enable = clk_gate_ops.enable;
39224 - clk_pll_ops.disable = clk_gate_ops.disable;
39225 + pax_open_kernel();
39226 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39227 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39228 + pax_close_kernel();
39229
39230 clk = clk_register(NULL, &pll_clk->hw.hw);
39231 if (WARN_ON(IS_ERR(clk))) {
39232 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39233 index b0c18ed..1713a80 100644
39234 --- a/drivers/cpufreq/acpi-cpufreq.c
39235 +++ b/drivers/cpufreq/acpi-cpufreq.c
39236 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39237 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39238 per_cpu(acfreq_data, cpu) = data;
39239
39240 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39241 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39242 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39243 + pax_open_kernel();
39244 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39245 + pax_close_kernel();
39246 + }
39247
39248 result = acpi_processor_register_performance(data->acpi_data, cpu);
39249 if (result)
39250 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39251 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39252 break;
39253 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39254 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39255 + pax_open_kernel();
39256 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39257 + pax_close_kernel();
39258 break;
39259 default:
39260 break;
39261 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39262 if (!msrs)
39263 return;
39264
39265 - acpi_cpufreq_driver.boost_supported = true;
39266 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39267 + pax_open_kernel();
39268 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39269 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39270 + pax_close_kernel();
39271
39272 cpu_notifier_register_begin();
39273
39274 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39275 index f657c57..31d97ae 100644
39276 --- a/drivers/cpufreq/cpufreq-dt.c
39277 +++ b/drivers/cpufreq/cpufreq-dt.c
39278 @@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39279 if (!IS_ERR(cpu_reg))
39280 regulator_put(cpu_reg);
39281
39282 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39283 + pax_open_kernel();
39284 + *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39285 + pax_close_kernel();
39286
39287 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39288 if (ret)
39289 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39290 index 4473eba..a4c9dc2 100644
39291 --- a/drivers/cpufreq/cpufreq.c
39292 +++ b/drivers/cpufreq/cpufreq.c
39293 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39294 }
39295
39296 mutex_lock(&cpufreq_governor_mutex);
39297 - list_del(&governor->governor_list);
39298 + pax_list_del(&governor->governor_list);
39299 mutex_unlock(&cpufreq_governor_mutex);
39300 return;
39301 }
39302 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39303 return NOTIFY_OK;
39304 }
39305
39306 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39307 +static struct notifier_block cpufreq_cpu_notifier = {
39308 .notifier_call = cpufreq_cpu_callback,
39309 };
39310
39311 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39312 return 0;
39313
39314 write_lock_irqsave(&cpufreq_driver_lock, flags);
39315 - cpufreq_driver->boost_enabled = state;
39316 + pax_open_kernel();
39317 + *(bool *)&cpufreq_driver->boost_enabled = state;
39318 + pax_close_kernel();
39319 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39320
39321 ret = cpufreq_driver->set_boost(state);
39322 if (ret) {
39323 write_lock_irqsave(&cpufreq_driver_lock, flags);
39324 - cpufreq_driver->boost_enabled = !state;
39325 + pax_open_kernel();
39326 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39327 + pax_close_kernel();
39328 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39329
39330 pr_err("%s: Cannot %s BOOST\n",
39331 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39332
39333 pr_debug("trying to register driver %s\n", driver_data->name);
39334
39335 - if (driver_data->setpolicy)
39336 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39337 + if (driver_data->setpolicy) {
39338 + pax_open_kernel();
39339 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39340 + pax_close_kernel();
39341 + }
39342
39343 write_lock_irqsave(&cpufreq_driver_lock, flags);
39344 if (cpufreq_driver) {
39345 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39346 * Check if driver provides function to enable boost -
39347 * if not, use cpufreq_boost_set_sw as default
39348 */
39349 - if (!cpufreq_driver->set_boost)
39350 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39351 + if (!cpufreq_driver->set_boost) {
39352 + pax_open_kernel();
39353 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39354 + pax_close_kernel();
39355 + }
39356
39357 ret = cpufreq_sysfs_create_file(&boost.attr);
39358 if (ret) {
39359 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39360 index 1b44496..b80ff5e 100644
39361 --- a/drivers/cpufreq/cpufreq_governor.c
39362 +++ b/drivers/cpufreq/cpufreq_governor.c
39363 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39364 struct dbs_data *dbs_data;
39365 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39366 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39367 - struct od_ops *od_ops = NULL;
39368 + const struct od_ops *od_ops = NULL;
39369 struct od_dbs_tuners *od_tuners = NULL;
39370 struct cs_dbs_tuners *cs_tuners = NULL;
39371 struct cpu_dbs_common_info *cpu_cdbs;
39372 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39373
39374 if ((cdata->governor == GOV_CONSERVATIVE) &&
39375 (!policy->governor->initialized)) {
39376 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39377 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39378
39379 cpufreq_register_notifier(cs_ops->notifier_block,
39380 CPUFREQ_TRANSITION_NOTIFIER);
39381 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39382
39383 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39384 (policy->governor->initialized == 1)) {
39385 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39386 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39387
39388 cpufreq_unregister_notifier(cs_ops->notifier_block,
39389 CPUFREQ_TRANSITION_NOTIFIER);
39390 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39391 index cc401d1..8197340 100644
39392 --- a/drivers/cpufreq/cpufreq_governor.h
39393 +++ b/drivers/cpufreq/cpufreq_governor.h
39394 @@ -212,7 +212,7 @@ struct common_dbs_data {
39395 void (*exit)(struct dbs_data *dbs_data);
39396
39397 /* Governor specific ops, see below */
39398 - void *gov_ops;
39399 + const void *gov_ops;
39400 };
39401
39402 /* Governor Per policy data */
39403 @@ -232,7 +232,7 @@ struct od_ops {
39404 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39405 unsigned int freq_next, unsigned int relation);
39406 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39407 -};
39408 +} __no_const;
39409
39410 struct cs_ops {
39411 struct notifier_block *notifier_block;
39412 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39413 index ad3f38f..8f086cd 100644
39414 --- a/drivers/cpufreq/cpufreq_ondemand.c
39415 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39416 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39417
39418 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39419
39420 -static struct od_ops od_ops = {
39421 +static struct od_ops od_ops __read_only = {
39422 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39423 .powersave_bias_target = generic_powersave_bias_target,
39424 .freq_increase = dbs_freq_increase,
39425 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39426 (struct cpufreq_policy *, unsigned int, unsigned int),
39427 unsigned int powersave_bias)
39428 {
39429 - od_ops.powersave_bias_target = f;
39430 + pax_open_kernel();
39431 + *(void **)&od_ops.powersave_bias_target = f;
39432 + pax_close_kernel();
39433 od_set_powersave_bias(powersave_bias);
39434 }
39435 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39436
39437 void od_unregister_powersave_bias_handler(void)
39438 {
39439 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39440 + pax_open_kernel();
39441 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39442 + pax_close_kernel();
39443 od_set_powersave_bias(0);
39444 }
39445 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39446 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39447 index 27bb6d3..4cf595c 100644
39448 --- a/drivers/cpufreq/intel_pstate.c
39449 +++ b/drivers/cpufreq/intel_pstate.c
39450 @@ -133,10 +133,10 @@ struct pstate_funcs {
39451 struct cpu_defaults {
39452 struct pstate_adjust_policy pid_policy;
39453 struct pstate_funcs funcs;
39454 -};
39455 +} __do_const;
39456
39457 static struct pstate_adjust_policy pid_params;
39458 -static struct pstate_funcs pstate_funcs;
39459 +static struct pstate_funcs *pstate_funcs;
39460
39461 struct perf_limits {
39462 int no_turbo;
39463 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39464
39465 cpu->pstate.current_pstate = pstate;
39466
39467 - pstate_funcs.set(cpu, pstate);
39468 + pstate_funcs->set(cpu, pstate);
39469 }
39470
39471 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39472 {
39473 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39474 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39475 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39476 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39477 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39478 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39479 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39480 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39481
39482 - if (pstate_funcs.get_vid)
39483 - pstate_funcs.get_vid(cpu);
39484 + if (pstate_funcs->get_vid)
39485 + pstate_funcs->get_vid(cpu);
39486 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39487 }
39488
39489 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39490 rdmsrl(MSR_IA32_APERF, aperf);
39491 rdmsrl(MSR_IA32_MPERF, mperf);
39492
39493 - if (!pstate_funcs.get_max() ||
39494 - !pstate_funcs.get_min() ||
39495 - !pstate_funcs.get_turbo())
39496 + if (!pstate_funcs->get_max() ||
39497 + !pstate_funcs->get_min() ||
39498 + !pstate_funcs->get_turbo())
39499 return -ENODEV;
39500
39501 rdmsrl(MSR_IA32_APERF, tmp);
39502 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39503 return 0;
39504 }
39505
39506 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39507 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39508 {
39509 pid_params.sample_rate_ms = policy->sample_rate_ms;
39510 pid_params.p_gain_pct = policy->p_gain_pct;
39511 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39512
39513 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39514 {
39515 - pstate_funcs.get_max = funcs->get_max;
39516 - pstate_funcs.get_min = funcs->get_min;
39517 - pstate_funcs.get_turbo = funcs->get_turbo;
39518 - pstate_funcs.get_scaling = funcs->get_scaling;
39519 - pstate_funcs.set = funcs->set;
39520 - pstate_funcs.get_vid = funcs->get_vid;
39521 + pstate_funcs = funcs;
39522 }
39523
39524 #if IS_ENABLED(CONFIG_ACPI)
39525 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39526 index 529cfd9..0e28fff 100644
39527 --- a/drivers/cpufreq/p4-clockmod.c
39528 +++ b/drivers/cpufreq/p4-clockmod.c
39529 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39530 case 0x0F: /* Core Duo */
39531 case 0x16: /* Celeron Core */
39532 case 0x1C: /* Atom */
39533 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39534 + pax_open_kernel();
39535 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39536 + pax_close_kernel();
39537 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39538 case 0x0D: /* Pentium M (Dothan) */
39539 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39540 + pax_open_kernel();
39541 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39542 + pax_close_kernel();
39543 /* fall through */
39544 case 0x09: /* Pentium M (Banias) */
39545 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39546 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39547
39548 /* on P-4s, the TSC runs with constant frequency independent whether
39549 * throttling is active or not. */
39550 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39551 + pax_open_kernel();
39552 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39553 + pax_close_kernel();
39554
39555 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39556 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39557 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39558 index 9bb42ba..b01b4a2 100644
39559 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39560 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39561 @@ -18,14 +18,12 @@
39562 #include <asm/head.h>
39563 #include <asm/timer.h>
39564
39565 -static struct cpufreq_driver *cpufreq_us3_driver;
39566 -
39567 struct us3_freq_percpu_info {
39568 struct cpufreq_frequency_table table[4];
39569 };
39570
39571 /* Indexed by cpu number. */
39572 -static struct us3_freq_percpu_info *us3_freq_table;
39573 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39574
39575 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39576 * in the Safari config register.
39577 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39578
39579 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39580 {
39581 - if (cpufreq_us3_driver)
39582 - us3_freq_target(policy, 0);
39583 + us3_freq_target(policy, 0);
39584
39585 return 0;
39586 }
39587
39588 +static int __init us3_freq_init(void);
39589 +static void __exit us3_freq_exit(void);
39590 +
39591 +static struct cpufreq_driver cpufreq_us3_driver = {
39592 + .init = us3_freq_cpu_init,
39593 + .verify = cpufreq_generic_frequency_table_verify,
39594 + .target_index = us3_freq_target,
39595 + .get = us3_freq_get,
39596 + .exit = us3_freq_cpu_exit,
39597 + .name = "UltraSPARC-III",
39598 +
39599 +};
39600 +
39601 static int __init us3_freq_init(void)
39602 {
39603 unsigned long manuf, impl, ver;
39604 - int ret;
39605
39606 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39607 return -ENODEV;
39608 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39609 (impl == CHEETAH_IMPL ||
39610 impl == CHEETAH_PLUS_IMPL ||
39611 impl == JAGUAR_IMPL ||
39612 - impl == PANTHER_IMPL)) {
39613 - struct cpufreq_driver *driver;
39614 -
39615 - ret = -ENOMEM;
39616 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39617 - if (!driver)
39618 - goto err_out;
39619 -
39620 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39621 - GFP_KERNEL);
39622 - if (!us3_freq_table)
39623 - goto err_out;
39624 -
39625 - driver->init = us3_freq_cpu_init;
39626 - driver->verify = cpufreq_generic_frequency_table_verify;
39627 - driver->target_index = us3_freq_target;
39628 - driver->get = us3_freq_get;
39629 - driver->exit = us3_freq_cpu_exit;
39630 - strcpy(driver->name, "UltraSPARC-III");
39631 -
39632 - cpufreq_us3_driver = driver;
39633 - ret = cpufreq_register_driver(driver);
39634 - if (ret)
39635 - goto err_out;
39636 -
39637 - return 0;
39638 -
39639 -err_out:
39640 - if (driver) {
39641 - kfree(driver);
39642 - cpufreq_us3_driver = NULL;
39643 - }
39644 - kfree(us3_freq_table);
39645 - us3_freq_table = NULL;
39646 - return ret;
39647 - }
39648 + impl == PANTHER_IMPL))
39649 + return cpufreq_register_driver(&cpufreq_us3_driver);
39650
39651 return -ENODEV;
39652 }
39653
39654 static void __exit us3_freq_exit(void)
39655 {
39656 - if (cpufreq_us3_driver) {
39657 - cpufreq_unregister_driver(cpufreq_us3_driver);
39658 - kfree(cpufreq_us3_driver);
39659 - cpufreq_us3_driver = NULL;
39660 - kfree(us3_freq_table);
39661 - us3_freq_table = NULL;
39662 - }
39663 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39664 }
39665
39666 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39667 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39668 index 7d4a315..21bb886 100644
39669 --- a/drivers/cpufreq/speedstep-centrino.c
39670 +++ b/drivers/cpufreq/speedstep-centrino.c
39671 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39672 !cpu_has(cpu, X86_FEATURE_EST))
39673 return -ENODEV;
39674
39675 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39676 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39677 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39678 + pax_open_kernel();
39679 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39680 + pax_close_kernel();
39681 + }
39682
39683 if (policy->cpu != 0)
39684 return -ENODEV;
39685 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39686 index e431d11..d0b997e 100644
39687 --- a/drivers/cpuidle/driver.c
39688 +++ b/drivers/cpuidle/driver.c
39689 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39690
39691 static void poll_idle_init(struct cpuidle_driver *drv)
39692 {
39693 - struct cpuidle_state *state = &drv->states[0];
39694 + cpuidle_state_no_const *state = &drv->states[0];
39695
39696 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39697 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39698 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39699 index fb9f511..213e6cc 100644
39700 --- a/drivers/cpuidle/governor.c
39701 +++ b/drivers/cpuidle/governor.c
39702 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39703 mutex_lock(&cpuidle_lock);
39704 if (__cpuidle_find_governor(gov->name) == NULL) {
39705 ret = 0;
39706 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39707 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39708 if (!cpuidle_curr_governor ||
39709 cpuidle_curr_governor->rating < gov->rating)
39710 cpuidle_switch_governor(gov);
39711 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39712 index 97c5903..023ad23 100644
39713 --- a/drivers/cpuidle/sysfs.c
39714 +++ b/drivers/cpuidle/sysfs.c
39715 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39716 NULL
39717 };
39718
39719 -static struct attribute_group cpuidle_attr_group = {
39720 +static attribute_group_no_const cpuidle_attr_group = {
39721 .attrs = cpuidle_default_attrs,
39722 .name = "cpuidle",
39723 };
39724 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39725 index 8d2a772..33826c9 100644
39726 --- a/drivers/crypto/hifn_795x.c
39727 +++ b/drivers/crypto/hifn_795x.c
39728 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39729 MODULE_PARM_DESC(hifn_pll_ref,
39730 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39731
39732 -static atomic_t hifn_dev_number;
39733 +static atomic_unchecked_t hifn_dev_number;
39734
39735 #define ACRYPTO_OP_DECRYPT 0
39736 #define ACRYPTO_OP_ENCRYPT 1
39737 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39738 goto err_out_disable_pci_device;
39739
39740 snprintf(name, sizeof(name), "hifn%d",
39741 - atomic_inc_return(&hifn_dev_number)-1);
39742 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39743
39744 err = pci_request_regions(pdev, name);
39745 if (err)
39746 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39747 index 30b538d8..1610d75 100644
39748 --- a/drivers/devfreq/devfreq.c
39749 +++ b/drivers/devfreq/devfreq.c
39750 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39751 goto err_out;
39752 }
39753
39754 - list_add(&governor->node, &devfreq_governor_list);
39755 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39756
39757 list_for_each_entry(devfreq, &devfreq_list, node) {
39758 int ret = 0;
39759 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39760 }
39761 }
39762
39763 - list_del(&governor->node);
39764 + pax_list_del((struct list_head *)&governor->node);
39765 err_out:
39766 mutex_unlock(&devfreq_list_lock);
39767
39768 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39769 index 42d4974..2714f36 100644
39770 --- a/drivers/dma/sh/shdma-base.c
39771 +++ b/drivers/dma/sh/shdma-base.c
39772 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39773 schan->slave_id = -EINVAL;
39774 }
39775
39776 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39777 - sdev->desc_size, GFP_KERNEL);
39778 + schan->desc = kcalloc(sdev->desc_size,
39779 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39780 if (!schan->desc) {
39781 ret = -ENOMEM;
39782 goto edescalloc;
39783 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39784 index 58eb857..d7e42c8 100644
39785 --- a/drivers/dma/sh/shdmac.c
39786 +++ b/drivers/dma/sh/shdmac.c
39787 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39788 return ret;
39789 }
39790
39791 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39792 +static struct notifier_block sh_dmae_nmi_notifier = {
39793 .notifier_call = sh_dmae_nmi_handler,
39794
39795 /* Run before NMI debug handler and KGDB */
39796 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39797 index 592af5f..bb1d583 100644
39798 --- a/drivers/edac/edac_device.c
39799 +++ b/drivers/edac/edac_device.c
39800 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39801 */
39802 int edac_device_alloc_index(void)
39803 {
39804 - static atomic_t device_indexes = ATOMIC_INIT(0);
39805 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39806
39807 - return atomic_inc_return(&device_indexes) - 1;
39808 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39809 }
39810 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39811
39812 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39813 index a6cd361..7bdbf53 100644
39814 --- a/drivers/edac/edac_mc_sysfs.c
39815 +++ b/drivers/edac/edac_mc_sysfs.c
39816 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39817 struct dev_ch_attribute {
39818 struct device_attribute attr;
39819 int channel;
39820 -};
39821 +} __do_const;
39822
39823 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39824 struct dev_ch_attribute dev_attr_legacy_##_name = \
39825 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39826 }
39827
39828 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39829 + pax_open_kernel();
39830 if (mci->get_sdram_scrub_rate) {
39831 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39832 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39833 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39834 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39835 }
39836 if (mci->set_sdram_scrub_rate) {
39837 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39838 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39839 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39840 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39841 }
39842 + pax_close_kernel();
39843 err = device_create_file(&mci->dev,
39844 &dev_attr_sdram_scrub_rate);
39845 if (err) {
39846 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39847 index 2cf44b4d..6dd2dc7 100644
39848 --- a/drivers/edac/edac_pci.c
39849 +++ b/drivers/edac/edac_pci.c
39850 @@ -29,7 +29,7 @@
39851
39852 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39853 static LIST_HEAD(edac_pci_list);
39854 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39855 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39856
39857 /*
39858 * edac_pci_alloc_ctl_info
39859 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39860 */
39861 int edac_pci_alloc_index(void)
39862 {
39863 - return atomic_inc_return(&pci_indexes) - 1;
39864 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39865 }
39866 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39867
39868 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39869 index e8658e4..22746d6 100644
39870 --- a/drivers/edac/edac_pci_sysfs.c
39871 +++ b/drivers/edac/edac_pci_sysfs.c
39872 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39873 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39874 static int edac_pci_poll_msec = 1000; /* one second workq period */
39875
39876 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39877 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39878 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39879 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39880
39881 static struct kobject *edac_pci_top_main_kobj;
39882 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39883 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39884 void *value;
39885 ssize_t(*show) (void *, char *);
39886 ssize_t(*store) (void *, const char *, size_t);
39887 -};
39888 +} __do_const;
39889
39890 /* Set of show/store abstract level functions for PCI Parity object */
39891 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39892 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39893 edac_printk(KERN_CRIT, EDAC_PCI,
39894 "Signaled System Error on %s\n",
39895 pci_name(dev));
39896 - atomic_inc(&pci_nonparity_count);
39897 + atomic_inc_unchecked(&pci_nonparity_count);
39898 }
39899
39900 if (status & (PCI_STATUS_PARITY)) {
39901 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39902 "Master Data Parity Error on %s\n",
39903 pci_name(dev));
39904
39905 - atomic_inc(&pci_parity_count);
39906 + atomic_inc_unchecked(&pci_parity_count);
39907 }
39908
39909 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39910 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39911 "Detected Parity Error on %s\n",
39912 pci_name(dev));
39913
39914 - atomic_inc(&pci_parity_count);
39915 + atomic_inc_unchecked(&pci_parity_count);
39916 }
39917 }
39918
39919 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39920 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39921 "Signaled System Error on %s\n",
39922 pci_name(dev));
39923 - atomic_inc(&pci_nonparity_count);
39924 + atomic_inc_unchecked(&pci_nonparity_count);
39925 }
39926
39927 if (status & (PCI_STATUS_PARITY)) {
39928 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39929 "Master Data Parity Error on "
39930 "%s\n", pci_name(dev));
39931
39932 - atomic_inc(&pci_parity_count);
39933 + atomic_inc_unchecked(&pci_parity_count);
39934 }
39935
39936 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39937 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39938 "Detected Parity Error on %s\n",
39939 pci_name(dev));
39940
39941 - atomic_inc(&pci_parity_count);
39942 + atomic_inc_unchecked(&pci_parity_count);
39943 }
39944 }
39945 }
39946 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39947 if (!check_pci_errors)
39948 return;
39949
39950 - before_count = atomic_read(&pci_parity_count);
39951 + before_count = atomic_read_unchecked(&pci_parity_count);
39952
39953 /* scan all PCI devices looking for a Parity Error on devices and
39954 * bridges.
39955 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39956 /* Only if operator has selected panic on PCI Error */
39957 if (edac_pci_get_panic_on_pe()) {
39958 /* If the count is different 'after' from 'before' */
39959 - if (before_count != atomic_read(&pci_parity_count))
39960 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39961 panic("EDAC: PCI Parity Error");
39962 }
39963 }
39964 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39965 index 51b7e3a..aa8a3e8 100644
39966 --- a/drivers/edac/mce_amd.h
39967 +++ b/drivers/edac/mce_amd.h
39968 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39969 bool (*mc0_mce)(u16, u8);
39970 bool (*mc1_mce)(u16, u8);
39971 bool (*mc2_mce)(u16, u8);
39972 -};
39973 +} __no_const;
39974
39975 void amd_report_gart_errors(bool);
39976 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39977 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39978 index 57ea7f4..af06b76 100644
39979 --- a/drivers/firewire/core-card.c
39980 +++ b/drivers/firewire/core-card.c
39981 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39982 const struct fw_card_driver *driver,
39983 struct device *device)
39984 {
39985 - static atomic_t index = ATOMIC_INIT(-1);
39986 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39987
39988 - card->index = atomic_inc_return(&index);
39989 + card->index = atomic_inc_return_unchecked(&index);
39990 card->driver = driver;
39991 card->device = device;
39992 card->current_tlabel = 0;
39993 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39994
39995 void fw_core_remove_card(struct fw_card *card)
39996 {
39997 - struct fw_card_driver dummy_driver = dummy_driver_template;
39998 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39999
40000 card->driver->update_phy_reg(card, 4,
40001 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40002 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40003 index 2c6d5e1..a2cca6b 100644
40004 --- a/drivers/firewire/core-device.c
40005 +++ b/drivers/firewire/core-device.c
40006 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40007 struct config_rom_attribute {
40008 struct device_attribute attr;
40009 u32 key;
40010 -};
40011 +} __do_const;
40012
40013 static ssize_t show_immediate(struct device *dev,
40014 struct device_attribute *dattr, char *buf)
40015 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40016 index eb6935c..3cc2bfa 100644
40017 --- a/drivers/firewire/core-transaction.c
40018 +++ b/drivers/firewire/core-transaction.c
40019 @@ -38,6 +38,7 @@
40020 #include <linux/timer.h>
40021 #include <linux/types.h>
40022 #include <linux/workqueue.h>
40023 +#include <linux/sched.h>
40024
40025 #include <asm/byteorder.h>
40026
40027 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40028 index e1480ff6..1a429bd 100644
40029 --- a/drivers/firewire/core.h
40030 +++ b/drivers/firewire/core.h
40031 @@ -111,6 +111,7 @@ struct fw_card_driver {
40032
40033 int (*stop_iso)(struct fw_iso_context *ctx);
40034 };
40035 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40036
40037 void fw_card_initialize(struct fw_card *card,
40038 const struct fw_card_driver *driver, struct device *device);
40039 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40040 index a66a321..f6caf20 100644
40041 --- a/drivers/firewire/ohci.c
40042 +++ b/drivers/firewire/ohci.c
40043 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40044 be32_to_cpu(ohci->next_header));
40045 }
40046
40047 +#ifndef CONFIG_GRKERNSEC
40048 if (param_remote_dma) {
40049 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40050 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40051 }
40052 +#endif
40053
40054 spin_unlock_irq(&ohci->lock);
40055
40056 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40057 unsigned long flags;
40058 int n, ret = 0;
40059
40060 +#ifndef CONFIG_GRKERNSEC
40061 if (param_remote_dma)
40062 return 0;
40063 +#endif
40064
40065 /*
40066 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40067 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40068 index 94a58a0..f5eba42 100644
40069 --- a/drivers/firmware/dmi-id.c
40070 +++ b/drivers/firmware/dmi-id.c
40071 @@ -16,7 +16,7 @@
40072 struct dmi_device_attribute{
40073 struct device_attribute dev_attr;
40074 int field;
40075 -};
40076 +} __do_const;
40077 #define to_dmi_dev_attr(_dev_attr) \
40078 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40079
40080 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40081 index 17afc51..0ef90cd 100644
40082 --- a/drivers/firmware/dmi_scan.c
40083 +++ b/drivers/firmware/dmi_scan.c
40084 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40085 if (buf == NULL)
40086 return -1;
40087
40088 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40089 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40090
40091 dmi_unmap(buf);
40092 return 0;
40093 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40094 index 5b53d61..72cee96 100644
40095 --- a/drivers/firmware/efi/cper.c
40096 +++ b/drivers/firmware/efi/cper.c
40097 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40098 */
40099 u64 cper_next_record_id(void)
40100 {
40101 - static atomic64_t seq;
40102 + static atomic64_unchecked_t seq;
40103
40104 - if (!atomic64_read(&seq))
40105 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40106 + if (!atomic64_read_unchecked(&seq))
40107 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40108
40109 - return atomic64_inc_return(&seq);
40110 + return atomic64_inc_return_unchecked(&seq);
40111 }
40112 EXPORT_SYMBOL_GPL(cper_next_record_id);
40113
40114 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40115 index 8590099..d83627a 100644
40116 --- a/drivers/firmware/efi/efi.c
40117 +++ b/drivers/firmware/efi/efi.c
40118 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40119 };
40120
40121 static struct efivars generic_efivars;
40122 -static struct efivar_operations generic_ops;
40123 +static efivar_operations_no_const generic_ops __read_only;
40124
40125 static int generic_ops_register(void)
40126 {
40127 - generic_ops.get_variable = efi.get_variable;
40128 - generic_ops.set_variable = efi.set_variable;
40129 - generic_ops.get_next_variable = efi.get_next_variable;
40130 - generic_ops.query_variable_store = efi_query_variable_store;
40131 + pax_open_kernel();
40132 + *(void **)&generic_ops.get_variable = efi.get_variable;
40133 + *(void **)&generic_ops.set_variable = efi.set_variable;
40134 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40135 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40136 + pax_close_kernel();
40137
40138 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40139 }
40140 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40141 index f256ecd..387dcb1 100644
40142 --- a/drivers/firmware/efi/efivars.c
40143 +++ b/drivers/firmware/efi/efivars.c
40144 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40145 static int
40146 create_efivars_bin_attributes(void)
40147 {
40148 - struct bin_attribute *attr;
40149 + bin_attribute_no_const *attr;
40150 int error;
40151
40152 /* new_var */
40153 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40154 index 2f569aa..c95f4fb 100644
40155 --- a/drivers/firmware/google/memconsole.c
40156 +++ b/drivers/firmware/google/memconsole.c
40157 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40158 if (!found_memconsole())
40159 return -ENODEV;
40160
40161 - memconsole_bin_attr.size = memconsole_length;
40162 + pax_open_kernel();
40163 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40164 + pax_close_kernel();
40165 +
40166 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40167 }
40168
40169 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40170 index fe49ec3..1ade794 100644
40171 --- a/drivers/gpio/gpio-em.c
40172 +++ b/drivers/gpio/gpio-em.c
40173 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40174 struct em_gio_priv *p;
40175 struct resource *io[2], *irq[2];
40176 struct gpio_chip *gpio_chip;
40177 - struct irq_chip *irq_chip;
40178 + irq_chip_no_const *irq_chip;
40179 const char *name = dev_name(&pdev->dev);
40180 int ret;
40181
40182 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40183 index 3784e81..73637b5 100644
40184 --- a/drivers/gpio/gpio-ich.c
40185 +++ b/drivers/gpio/gpio-ich.c
40186 @@ -94,7 +94,7 @@ struct ichx_desc {
40187 * this option allows driver caching written output values
40188 */
40189 bool use_outlvl_cache;
40190 -};
40191 +} __do_const;
40192
40193 static struct {
40194 spinlock_t lock;
40195 diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40196 index 415682f..08438b8 100644
40197 --- a/drivers/gpio/gpio-omap.c
40198 +++ b/drivers/gpio/gpio-omap.c
40199 @@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40200 const struct omap_gpio_platform_data *pdata;
40201 struct resource *res;
40202 struct gpio_bank *bank;
40203 - struct irq_chip *irqc;
40204 + irq_chip_no_const *irqc;
40205 int ret;
40206
40207 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40208 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40209 index bf6c094..6573caf 100644
40210 --- a/drivers/gpio/gpio-rcar.c
40211 +++ b/drivers/gpio/gpio-rcar.c
40212 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40213 struct gpio_rcar_priv *p;
40214 struct resource *io, *irq;
40215 struct gpio_chip *gpio_chip;
40216 - struct irq_chip *irq_chip;
40217 + irq_chip_no_const *irq_chip;
40218 struct device *dev = &pdev->dev;
40219 const char *name = dev_name(dev);
40220 int ret;
40221 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40222 index dbf28fa..04dad4e 100644
40223 --- a/drivers/gpio/gpio-vr41xx.c
40224 +++ b/drivers/gpio/gpio-vr41xx.c
40225 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40226 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40227 maskl, pendl, maskh, pendh);
40228
40229 - atomic_inc(&irq_err_count);
40230 + atomic_inc_unchecked(&irq_err_count);
40231
40232 return -EINVAL;
40233 }
40234 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40235 index c81bda0..a8ccd9f 100644
40236 --- a/drivers/gpio/gpiolib.c
40237 +++ b/drivers/gpio/gpiolib.c
40238 @@ -539,8 +539,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40239 }
40240
40241 if (gpiochip->irqchip) {
40242 - gpiochip->irqchip->irq_request_resources = NULL;
40243 - gpiochip->irqchip->irq_release_resources = NULL;
40244 + pax_open_kernel();
40245 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40246 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40247 + pax_close_kernel();
40248 gpiochip->irqchip = NULL;
40249 }
40250 }
40251 @@ -606,8 +608,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40252 gpiochip->irqchip = NULL;
40253 return -EINVAL;
40254 }
40255 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40256 - irqchip->irq_release_resources = gpiochip_irq_relres;
40257 +
40258 + pax_open_kernel();
40259 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40260 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40261 + pax_close_kernel();
40262
40263 /*
40264 * Prepare the mapping since the irqchip shall be orthogonal to
40265 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40266 index e79c8d3..a9370bc 100644
40267 --- a/drivers/gpu/drm/drm_crtc.c
40268 +++ b/drivers/gpu/drm/drm_crtc.c
40269 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40270 goto done;
40271 }
40272
40273 - if (copy_to_user(&enum_ptr[copied].name,
40274 + if (copy_to_user(enum_ptr[copied].name,
40275 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40276 ret = -EFAULT;
40277 goto done;
40278 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40279 index bc3da32..7289357 100644
40280 --- a/drivers/gpu/drm/drm_drv.c
40281 +++ b/drivers/gpu/drm/drm_drv.c
40282 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40283
40284 drm_device_set_unplugged(dev);
40285
40286 - if (dev->open_count == 0) {
40287 + if (local_read(&dev->open_count) == 0) {
40288 drm_put_dev(dev);
40289 }
40290 mutex_unlock(&drm_global_mutex);
40291 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
40292 index e9a2827..5df4716 100644
40293 --- a/drivers/gpu/drm/drm_fb_helper.c
40294 +++ b/drivers/gpu/drm/drm_fb_helper.c
40295 @@ -771,7 +771,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
40296 int i, j, rc = 0;
40297 int start;
40298
40299 - drm_modeset_lock_all(dev);
40300 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40301 + return -EBUSY;
40302 + }
40303 if (!drm_fb_helper_is_bound(fb_helper)) {
40304 drm_modeset_unlock_all(dev);
40305 return -EBUSY;
40306 @@ -945,7 +947,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
40307 int ret = 0;
40308 int i;
40309
40310 - drm_modeset_lock_all(dev);
40311 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40312 + return -EBUSY;
40313 + }
40314 if (!drm_fb_helper_is_bound(fb_helper)) {
40315 drm_modeset_unlock_all(dev);
40316 return -EBUSY;
40317 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40318 index ed7bc68..0d536af 100644
40319 --- a/drivers/gpu/drm/drm_fops.c
40320 +++ b/drivers/gpu/drm/drm_fops.c
40321 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40322 return PTR_ERR(minor);
40323
40324 dev = minor->dev;
40325 - if (!dev->open_count++)
40326 + if (local_inc_return(&dev->open_count) == 1)
40327 need_setup = 1;
40328
40329 /* share address_space across all char-devs of a single device */
40330 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40331 return 0;
40332
40333 err_undo:
40334 - dev->open_count--;
40335 + local_dec(&dev->open_count);
40336 drm_minor_release(minor);
40337 return retcode;
40338 }
40339 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40340
40341 mutex_lock(&drm_global_mutex);
40342
40343 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40344 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40345
40346 mutex_lock(&dev->struct_mutex);
40347 list_del(&file_priv->lhead);
40348 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40349 * Begin inline drm_release
40350 */
40351
40352 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40353 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40354 task_pid_nr(current),
40355 (long)old_encode_dev(file_priv->minor->kdev->devt),
40356 - dev->open_count);
40357 + local_read(&dev->open_count));
40358
40359 /* Release any auth tokens that might point to this file_priv,
40360 (do that under the drm_global_mutex) */
40361 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40362 * End inline drm_release
40363 */
40364
40365 - if (!--dev->open_count) {
40366 + if (local_dec_and_test(&dev->open_count)) {
40367 retcode = drm_lastclose(dev);
40368 if (drm_device_is_unplugged(dev))
40369 drm_put_dev(dev);
40370 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40371 index 3d2e91c..d31c4c9 100644
40372 --- a/drivers/gpu/drm/drm_global.c
40373 +++ b/drivers/gpu/drm/drm_global.c
40374 @@ -36,7 +36,7 @@
40375 struct drm_global_item {
40376 struct mutex mutex;
40377 void *object;
40378 - int refcount;
40379 + atomic_t refcount;
40380 };
40381
40382 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40383 @@ -49,7 +49,7 @@ void drm_global_init(void)
40384 struct drm_global_item *item = &glob[i];
40385 mutex_init(&item->mutex);
40386 item->object = NULL;
40387 - item->refcount = 0;
40388 + atomic_set(&item->refcount, 0);
40389 }
40390 }
40391
40392 @@ -59,7 +59,7 @@ void drm_global_release(void)
40393 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40394 struct drm_global_item *item = &glob[i];
40395 BUG_ON(item->object != NULL);
40396 - BUG_ON(item->refcount != 0);
40397 + BUG_ON(atomic_read(&item->refcount) != 0);
40398 }
40399 }
40400
40401 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40402 struct drm_global_item *item = &glob[ref->global_type];
40403
40404 mutex_lock(&item->mutex);
40405 - if (item->refcount == 0) {
40406 + if (atomic_read(&item->refcount) == 0) {
40407 item->object = kzalloc(ref->size, GFP_KERNEL);
40408 if (unlikely(item->object == NULL)) {
40409 ret = -ENOMEM;
40410 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40411 goto out_err;
40412
40413 }
40414 - ++item->refcount;
40415 + atomic_inc(&item->refcount);
40416 ref->object = item->object;
40417 mutex_unlock(&item->mutex);
40418 return 0;
40419 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40420 struct drm_global_item *item = &glob[ref->global_type];
40421
40422 mutex_lock(&item->mutex);
40423 - BUG_ON(item->refcount == 0);
40424 + BUG_ON(atomic_read(&item->refcount) == 0);
40425 BUG_ON(ref->object != item->object);
40426 - if (--item->refcount == 0) {
40427 + if (atomic_dec_and_test(&item->refcount)) {
40428 ref->release(ref);
40429 item->object = NULL;
40430 }
40431 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40432 index 51efebd..2b70935 100644
40433 --- a/drivers/gpu/drm/drm_info.c
40434 +++ b/drivers/gpu/drm/drm_info.c
40435 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40436 struct drm_local_map *map;
40437 struct drm_map_list *r_list;
40438
40439 - /* Hardcoded from _DRM_FRAME_BUFFER,
40440 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40441 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40442 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40443 + static const char * const types[] = {
40444 + [_DRM_FRAME_BUFFER] = "FB",
40445 + [_DRM_REGISTERS] = "REG",
40446 + [_DRM_SHM] = "SHM",
40447 + [_DRM_AGP] = "AGP",
40448 + [_DRM_SCATTER_GATHER] = "SG",
40449 + [_DRM_CONSISTENT] = "PCI"};
40450 const char *type;
40451 int i;
40452
40453 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40454 map = r_list->map;
40455 if (!map)
40456 continue;
40457 - if (map->type < 0 || map->type > 5)
40458 + if (map->type >= ARRAY_SIZE(types))
40459 type = "??";
40460 else
40461 type = types[map->type];
40462 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40463 index 2f4c4343..dd12cd2 100644
40464 --- a/drivers/gpu/drm/drm_ioc32.c
40465 +++ b/drivers/gpu/drm/drm_ioc32.c
40466 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40467 request = compat_alloc_user_space(nbytes);
40468 if (!access_ok(VERIFY_WRITE, request, nbytes))
40469 return -EFAULT;
40470 - list = (struct drm_buf_desc *) (request + 1);
40471 + list = (struct drm_buf_desc __user *) (request + 1);
40472
40473 if (__put_user(count, &request->count)
40474 || __put_user(list, &request->list))
40475 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40476 request = compat_alloc_user_space(nbytes);
40477 if (!access_ok(VERIFY_WRITE, request, nbytes))
40478 return -EFAULT;
40479 - list = (struct drm_buf_pub *) (request + 1);
40480 + list = (struct drm_buf_pub __user *) (request + 1);
40481
40482 if (__put_user(count, &request->count)
40483 || __put_user(list, &request->list))
40484 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40485 return 0;
40486 }
40487
40488 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40489 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40490 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40491 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40492 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40493 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40494 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40495 {
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497 - drm_ioctl_compat_t *fn;
40498 int ret;
40499
40500 /* Assume that ioctls without an explicit compat routine will just
40501 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40502 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40503 return drm_ioctl(filp, cmd, arg);
40504
40505 - fn = drm_compat_ioctls[nr];
40506 -
40507 - if (fn != NULL)
40508 - ret = (*fn) (filp, cmd, arg);
40509 + if (drm_compat_ioctls[nr] != NULL)
40510 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40511 else
40512 ret = drm_ioctl(filp, cmd, arg);
40513
40514 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40515 index 00587a1..57a65ca 100644
40516 --- a/drivers/gpu/drm/drm_ioctl.c
40517 +++ b/drivers/gpu/drm/drm_ioctl.c
40518 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40519 struct drm_file *file_priv = filp->private_data;
40520 struct drm_device *dev;
40521 const struct drm_ioctl_desc *ioctl = NULL;
40522 - drm_ioctl_t *func;
40523 + drm_ioctl_no_const_t func;
40524 unsigned int nr = DRM_IOCTL_NR(cmd);
40525 int retcode = -EINVAL;
40526 char stack_kdata[128];
40527 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40528 index 93ec5dc..82acbaf 100644
40529 --- a/drivers/gpu/drm/i810/i810_drv.h
40530 +++ b/drivers/gpu/drm/i810/i810_drv.h
40531 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40532 int page_flipping;
40533
40534 wait_queue_head_t irq_queue;
40535 - atomic_t irq_received;
40536 - atomic_t irq_emitted;
40537 + atomic_unchecked_t irq_received;
40538 + atomic_unchecked_t irq_emitted;
40539
40540 int front_offset;
40541 } drm_i810_private_t;
40542 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40543 index 318ade9..1f5de55 100644
40544 --- a/drivers/gpu/drm/i915/i915_dma.c
40545 +++ b/drivers/gpu/drm/i915/i915_dma.c
40546 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40547 * locking inversion with the driver load path. And the access here is
40548 * completely racy anyway. So don't bother with locking for now.
40549 */
40550 - return dev->open_count == 0;
40551 + return local_read(&dev->open_count) == 0;
40552 }
40553
40554 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40555 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40556 index 1a0611b..dd1fbfc 100644
40557 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40558 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40559 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40560 static int
40561 validate_exec_list(struct drm_device *dev,
40562 struct drm_i915_gem_exec_object2 *exec,
40563 - int count)
40564 + unsigned int count)
40565 {
40566 unsigned relocs_total = 0;
40567 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40568 unsigned invalid_flags;
40569 - int i;
40570 + unsigned int i;
40571
40572 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40573 if (USES_FULL_PPGTT(dev))
40574 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40575 index 2e0613e..a8b94d9 100644
40576 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40577 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40578 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40579 (unsigned long)request);
40580 }
40581
40582 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40583 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40584 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40585 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40586 [DRM_I915_GETPARAM] = compat_i915_getparam,
40587 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40588 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40589 {
40590 unsigned int nr = DRM_IOCTL_NR(cmd);
40591 - drm_ioctl_compat_t *fn = NULL;
40592 int ret;
40593
40594 if (nr < DRM_COMMAND_BASE)
40595 return drm_compat_ioctl(filp, cmd, arg);
40596
40597 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40598 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40599 -
40600 - if (fn != NULL)
40601 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40602 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40603 ret = (*fn) (filp, cmd, arg);
40604 - else
40605 + } else
40606 ret = drm_ioctl(filp, cmd, arg);
40607
40608 return ret;
40609 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40610 index 31b9664..5d478d3 100644
40611 --- a/drivers/gpu/drm/i915/intel_display.c
40612 +++ b/drivers/gpu/drm/i915/intel_display.c
40613 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40614 int subsystem_vendor;
40615 int subsystem_device;
40616 void (*hook)(struct drm_device *dev);
40617 -};
40618 +} __do_const;
40619
40620 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40621 struct intel_dmi_quirk {
40622 void (*hook)(struct drm_device *dev);
40623 const struct dmi_system_id (*dmi_id_list)[];
40624 -};
40625 +} __do_const;
40626
40627 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40628 {
40629 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40630 return 1;
40631 }
40632
40633 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40634 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40635 {
40636 - .dmi_id_list = &(const struct dmi_system_id[]) {
40637 - {
40638 - .callback = intel_dmi_reverse_brightness,
40639 - .ident = "NCR Corporation",
40640 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40641 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40642 - },
40643 - },
40644 - { } /* terminating entry */
40645 + .callback = intel_dmi_reverse_brightness,
40646 + .ident = "NCR Corporation",
40647 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40648 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40649 },
40650 + },
40651 + { } /* terminating entry */
40652 +};
40653 +
40654 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40655 + {
40656 + .dmi_id_list = &intel_dmi_quirks_table,
40657 .hook = quirk_invert_brightness,
40658 },
40659 };
40660 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40661 index b4a2014..219ab78 100644
40662 --- a/drivers/gpu/drm/mga/mga_drv.h
40663 +++ b/drivers/gpu/drm/mga/mga_drv.h
40664 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40665 u32 clear_cmd;
40666 u32 maccess;
40667
40668 - atomic_t vbl_received; /**< Number of vblanks received. */
40669 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40670 wait_queue_head_t fence_queue;
40671 - atomic_t last_fence_retired;
40672 + atomic_unchecked_t last_fence_retired;
40673 u32 next_fence_to_post;
40674
40675 unsigned int fb_cpp;
40676 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40677 index 729bfd5..ead8823 100644
40678 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40679 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40680 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40681 return 0;
40682 }
40683
40684 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40685 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40686 [DRM_MGA_INIT] = compat_mga_init,
40687 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40688 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40689 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40690 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40691 {
40692 unsigned int nr = DRM_IOCTL_NR(cmd);
40693 - drm_ioctl_compat_t *fn = NULL;
40694 int ret;
40695
40696 if (nr < DRM_COMMAND_BASE)
40697 return drm_compat_ioctl(filp, cmd, arg);
40698
40699 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40700 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40701 -
40702 - if (fn != NULL)
40703 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40704 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40705 ret = (*fn) (filp, cmd, arg);
40706 - else
40707 + } else
40708 ret = drm_ioctl(filp, cmd, arg);
40709
40710 return ret;
40711 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40712 index 1b071b8..de8601a 100644
40713 --- a/drivers/gpu/drm/mga/mga_irq.c
40714 +++ b/drivers/gpu/drm/mga/mga_irq.c
40715 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40716 if (crtc != 0)
40717 return 0;
40718
40719 - return atomic_read(&dev_priv->vbl_received);
40720 + return atomic_read_unchecked(&dev_priv->vbl_received);
40721 }
40722
40723
40724 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40725 /* VBLANK interrupt */
40726 if (status & MGA_VLINEPEN) {
40727 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40728 - atomic_inc(&dev_priv->vbl_received);
40729 + atomic_inc_unchecked(&dev_priv->vbl_received);
40730 drm_handle_vblank(dev, 0);
40731 handled = 1;
40732 }
40733 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40734 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40735 MGA_WRITE(MGA_PRIMEND, prim_end);
40736
40737 - atomic_inc(&dev_priv->last_fence_retired);
40738 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40739 wake_up(&dev_priv->fence_queue);
40740 handled = 1;
40741 }
40742 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40743 * using fences.
40744 */
40745 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40746 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40747 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40748 - *sequence) <= (1 << 23)));
40749
40750 *sequence = cur_fence;
40751 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40752 index dae2c96..324dbe4 100644
40753 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40754 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40755 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40756 struct bit_table {
40757 const char id;
40758 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40759 -};
40760 +} __no_const;
40761
40762 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40763
40764 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40765 index 8ae36f2..1147a30 100644
40766 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40767 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40768 @@ -121,7 +121,6 @@ struct nouveau_drm {
40769 struct drm_global_reference mem_global_ref;
40770 struct ttm_bo_global_ref bo_global_ref;
40771 struct ttm_bo_device bdev;
40772 - atomic_t validate_sequence;
40773 int (*move)(struct nouveau_channel *,
40774 struct ttm_buffer_object *,
40775 struct ttm_mem_reg *, struct ttm_mem_reg *);
40776 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40777 index 462679a..88e32a7 100644
40778 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40779 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40780 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40781 unsigned long arg)
40782 {
40783 unsigned int nr = DRM_IOCTL_NR(cmd);
40784 - drm_ioctl_compat_t *fn = NULL;
40785 + drm_ioctl_compat_t fn = NULL;
40786 int ret;
40787
40788 if (nr < DRM_COMMAND_BASE)
40789 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40790 index 3d1cfcb..0542700 100644
40791 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40792 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40793 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40794 }
40795
40796 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40797 - nouveau_vram_manager_init,
40798 - nouveau_vram_manager_fini,
40799 - nouveau_vram_manager_new,
40800 - nouveau_vram_manager_del,
40801 - nouveau_vram_manager_debug
40802 + .init = nouveau_vram_manager_init,
40803 + .takedown = nouveau_vram_manager_fini,
40804 + .get_node = nouveau_vram_manager_new,
40805 + .put_node = nouveau_vram_manager_del,
40806 + .debug = nouveau_vram_manager_debug
40807 };
40808
40809 static int
40810 @@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40811 }
40812
40813 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40814 - nouveau_gart_manager_init,
40815 - nouveau_gart_manager_fini,
40816 - nouveau_gart_manager_new,
40817 - nouveau_gart_manager_del,
40818 - nouveau_gart_manager_debug
40819 + .init = nouveau_gart_manager_init,
40820 + .takedown = nouveau_gart_manager_fini,
40821 + .get_node = nouveau_gart_manager_new,
40822 + .put_node = nouveau_gart_manager_del,
40823 + .debug = nouveau_gart_manager_debug
40824 };
40825
40826 /*XXX*/
40827 @@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40828 }
40829
40830 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40831 - nv04_gart_manager_init,
40832 - nv04_gart_manager_fini,
40833 - nv04_gart_manager_new,
40834 - nv04_gart_manager_del,
40835 - nv04_gart_manager_debug
40836 + .init = nv04_gart_manager_init,
40837 + .takedown = nv04_gart_manager_fini,
40838 + .get_node = nv04_gart_manager_new,
40839 + .put_node = nv04_gart_manager_del,
40840 + .debug = nv04_gart_manager_debug
40841 };
40842
40843 int
40844 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40845 index c7592ec..dd45ebc 100644
40846 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40847 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40848 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40849 * locking inversion with the driver load path. And the access here is
40850 * completely racy anyway. So don't bother with locking for now.
40851 */
40852 - return dev->open_count == 0;
40853 + return local_read(&dev->open_count) == 0;
40854 }
40855
40856 static const struct vga_switcheroo_client_ops
40857 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40858 index 9782364..89bd954 100644
40859 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40860 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40861 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40862 int ret;
40863
40864 mutex_lock(&qdev->async_io_mutex);
40865 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40866 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40867 if (qdev->last_sent_io_cmd > irq_num) {
40868 if (intr)
40869 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40870 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40871 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40872 else
40873 ret = wait_event_timeout(qdev->io_cmd_event,
40874 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40875 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40876 /* 0 is timeout, just bail the "hw" has gone away */
40877 if (ret <= 0)
40878 goto out;
40879 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40880 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40881 }
40882 outb(val, addr);
40883 qdev->last_sent_io_cmd = irq_num + 1;
40884 if (intr)
40885 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40886 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40887 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40888 else
40889 ret = wait_event_timeout(qdev->io_cmd_event,
40890 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40891 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40892 out:
40893 if (ret > 0)
40894 ret = 0;
40895 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40896 index 6911b8c..89d6867 100644
40897 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40898 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40899 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40900 struct drm_info_node *node = (struct drm_info_node *) m->private;
40901 struct qxl_device *qdev = node->minor->dev->dev_private;
40902
40903 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40904 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40905 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40906 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40907 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40908 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40909 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40910 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40911 seq_printf(m, "%d\n", qdev->irq_received_error);
40912 return 0;
40913 }
40914 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40915 index 7c6cafe..460f542 100644
40916 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40917 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40918 @@ -290,10 +290,10 @@ struct qxl_device {
40919 unsigned int last_sent_io_cmd;
40920
40921 /* interrupt handling */
40922 - atomic_t irq_received;
40923 - atomic_t irq_received_display;
40924 - atomic_t irq_received_cursor;
40925 - atomic_t irq_received_io_cmd;
40926 + atomic_unchecked_t irq_received;
40927 + atomic_unchecked_t irq_received_display;
40928 + atomic_unchecked_t irq_received_cursor;
40929 + atomic_unchecked_t irq_received_io_cmd;
40930 unsigned irq_received_error;
40931 wait_queue_head_t display_event;
40932 wait_queue_head_t cursor_event;
40933 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40934 index b110883..dd06418 100644
40935 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40936 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40937 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40938
40939 /* TODO copy slow path code from i915 */
40940 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40941 - 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);
40942 + 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);
40943
40944 {
40945 struct qxl_drawable *draw = fb_cmd;
40946 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40947 struct drm_qxl_reloc reloc;
40948
40949 if (copy_from_user(&reloc,
40950 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40951 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40952 sizeof(reloc))) {
40953 ret = -EFAULT;
40954 goto out_free_bos;
40955 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40956
40957 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40958
40959 - struct drm_qxl_command *commands =
40960 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40961 + struct drm_qxl_command __user *commands =
40962 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40963
40964 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40965 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40966 sizeof(user_cmd)))
40967 return -EFAULT;
40968
40969 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40970 index 0bf1e20..42a7310 100644
40971 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40972 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40973 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40974 if (!pending)
40975 return IRQ_NONE;
40976
40977 - atomic_inc(&qdev->irq_received);
40978 + atomic_inc_unchecked(&qdev->irq_received);
40979
40980 if (pending & QXL_INTERRUPT_DISPLAY) {
40981 - atomic_inc(&qdev->irq_received_display);
40982 + atomic_inc_unchecked(&qdev->irq_received_display);
40983 wake_up_all(&qdev->display_event);
40984 qxl_queue_garbage_collect(qdev, false);
40985 }
40986 if (pending & QXL_INTERRUPT_CURSOR) {
40987 - atomic_inc(&qdev->irq_received_cursor);
40988 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40989 wake_up_all(&qdev->cursor_event);
40990 }
40991 if (pending & QXL_INTERRUPT_IO_CMD) {
40992 - atomic_inc(&qdev->irq_received_io_cmd);
40993 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40994 wake_up_all(&qdev->io_cmd_event);
40995 }
40996 if (pending & QXL_INTERRUPT_ERROR) {
40997 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40998 init_waitqueue_head(&qdev->io_cmd_event);
40999 INIT_WORK(&qdev->client_monitors_config_work,
41000 qxl_client_monitors_config_work_func);
41001 - atomic_set(&qdev->irq_received, 0);
41002 - atomic_set(&qdev->irq_received_display, 0);
41003 - atomic_set(&qdev->irq_received_cursor, 0);
41004 - atomic_set(&qdev->irq_received_io_cmd, 0);
41005 + atomic_set_unchecked(&qdev->irq_received, 0);
41006 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41007 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41008 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41009 qdev->irq_received_error = 0;
41010 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41011 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41012 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41013 index 0cbc4c9..0e46686 100644
41014 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41015 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41016 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41017 }
41018 }
41019
41020 -static struct vm_operations_struct qxl_ttm_vm_ops;
41021 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41022 static const struct vm_operations_struct *ttm_vm_ops;
41023
41024 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41025 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41026 return r;
41027 if (unlikely(ttm_vm_ops == NULL)) {
41028 ttm_vm_ops = vma->vm_ops;
41029 + pax_open_kernel();
41030 qxl_ttm_vm_ops = *ttm_vm_ops;
41031 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41032 + pax_close_kernel();
41033 }
41034 vma->vm_ops = &qxl_ttm_vm_ops;
41035 return 0;
41036 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41037 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41038 {
41039 #if defined(CONFIG_DEBUG_FS)
41040 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41041 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41042 - unsigned i;
41043 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41044 + {
41045 + .name = "qxl_mem_mm",
41046 + .show = &qxl_mm_dump_table,
41047 + },
41048 + {
41049 + .name = "qxl_surf_mm",
41050 + .show = &qxl_mm_dump_table,
41051 + }
41052 + };
41053
41054 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41055 - if (i == 0)
41056 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41057 - else
41058 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41059 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41060 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41061 - qxl_mem_types_list[i].driver_features = 0;
41062 - if (i == 0)
41063 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41064 - else
41065 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41066 + pax_open_kernel();
41067 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41068 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41069 + pax_close_kernel();
41070
41071 - }
41072 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41073 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41074 #else
41075 return 0;
41076 #endif
41077 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41078 index 2c45ac9..5d740f8 100644
41079 --- a/drivers/gpu/drm/r128/r128_cce.c
41080 +++ b/drivers/gpu/drm/r128/r128_cce.c
41081 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41082
41083 /* GH: Simple idle check.
41084 */
41085 - atomic_set(&dev_priv->idle_count, 0);
41086 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41087
41088 /* We don't support anything other than bus-mastering ring mode,
41089 * but the ring can be in either AGP or PCI space for the ring
41090 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41091 index 723e5d6..102dbaf 100644
41092 --- a/drivers/gpu/drm/r128/r128_drv.h
41093 +++ b/drivers/gpu/drm/r128/r128_drv.h
41094 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41095 int is_pci;
41096 unsigned long cce_buffers_offset;
41097
41098 - atomic_t idle_count;
41099 + atomic_unchecked_t idle_count;
41100
41101 int page_flipping;
41102 int current_page;
41103 u32 crtc_offset;
41104 u32 crtc_offset_cntl;
41105
41106 - atomic_t vbl_received;
41107 + atomic_unchecked_t vbl_received;
41108
41109 u32 color_fmt;
41110 unsigned int front_offset;
41111 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41112 index 663f38c..c689495 100644
41113 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41114 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41115 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41116 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41117 }
41118
41119 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41120 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41121 [DRM_R128_INIT] = compat_r128_init,
41122 [DRM_R128_DEPTH] = compat_r128_depth,
41123 [DRM_R128_STIPPLE] = compat_r128_stipple,
41124 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41125 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41126 {
41127 unsigned int nr = DRM_IOCTL_NR(cmd);
41128 - drm_ioctl_compat_t *fn = NULL;
41129 int ret;
41130
41131 if (nr < DRM_COMMAND_BASE)
41132 return drm_compat_ioctl(filp, cmd, arg);
41133
41134 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41135 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41136 -
41137 - if (fn != NULL)
41138 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41139 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41140 ret = (*fn) (filp, cmd, arg);
41141 - else
41142 + } else
41143 ret = drm_ioctl(filp, cmd, arg);
41144
41145 return ret;
41146 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41147 index c2ae496..30b5993 100644
41148 --- a/drivers/gpu/drm/r128/r128_irq.c
41149 +++ b/drivers/gpu/drm/r128/r128_irq.c
41150 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41151 if (crtc != 0)
41152 return 0;
41153
41154 - return atomic_read(&dev_priv->vbl_received);
41155 + return atomic_read_unchecked(&dev_priv->vbl_received);
41156 }
41157
41158 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41159 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41160 /* VBLANK interrupt */
41161 if (status & R128_CRTC_VBLANK_INT) {
41162 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41163 - atomic_inc(&dev_priv->vbl_received);
41164 + atomic_inc_unchecked(&dev_priv->vbl_received);
41165 drm_handle_vblank(dev, 0);
41166 return IRQ_HANDLED;
41167 }
41168 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41169 index 575e986..66e62ca 100644
41170 --- a/drivers/gpu/drm/r128/r128_state.c
41171 +++ b/drivers/gpu/drm/r128/r128_state.c
41172 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41173
41174 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41175 {
41176 - if (atomic_read(&dev_priv->idle_count) == 0)
41177 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41178 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41179 else
41180 - atomic_set(&dev_priv->idle_count, 0);
41181 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41182 }
41183
41184 #endif
41185 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41186 index 4a85bb6..aaea819 100644
41187 --- a/drivers/gpu/drm/radeon/mkregtable.c
41188 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41189 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41190 regex_t mask_rex;
41191 regmatch_t match[4];
41192 char buf[1024];
41193 - size_t end;
41194 + long end;
41195 int len;
41196 int done = 0;
41197 int r;
41198 unsigned o;
41199 struct offset *offset;
41200 char last_reg_s[10];
41201 - int last_reg;
41202 + unsigned long last_reg;
41203
41204 if (regcomp
41205 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41206 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41207 index bdf263a..0305446 100644
41208 --- a/drivers/gpu/drm/radeon/radeon_device.c
41209 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41210 @@ -1216,7 +1216,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41211 * locking inversion with the driver load path. And the access here is
41212 * completely racy anyway. So don't bother with locking for now.
41213 */
41214 - return dev->open_count == 0;
41215 + return local_read(&dev->open_count) == 0;
41216 }
41217
41218 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41219 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41220 index 46bd393..6ae4719 100644
41221 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41222 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41223 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41224
41225 /* SW interrupt */
41226 wait_queue_head_t swi_queue;
41227 - atomic_t swi_emitted;
41228 + atomic_unchecked_t swi_emitted;
41229 int vblank_crtc;
41230 uint32_t irq_enable_reg;
41231 uint32_t r500_disp_irq_reg;
41232 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41233 index 0b98ea1..0881827 100644
41234 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41235 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41236 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41237 request = compat_alloc_user_space(sizeof(*request));
41238 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41239 || __put_user(req32.param, &request->param)
41240 - || __put_user((void __user *)(unsigned long)req32.value,
41241 + || __put_user((unsigned long)req32.value,
41242 &request->value))
41243 return -EFAULT;
41244
41245 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41246 #define compat_radeon_cp_setparam NULL
41247 #endif /* X86_64 || IA64 */
41248
41249 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41250 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41251 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41252 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41253 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41254 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41255 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41256 {
41257 unsigned int nr = DRM_IOCTL_NR(cmd);
41258 - drm_ioctl_compat_t *fn = NULL;
41259 int ret;
41260
41261 if (nr < DRM_COMMAND_BASE)
41262 return drm_compat_ioctl(filp, cmd, arg);
41263
41264 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41265 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41266 -
41267 - if (fn != NULL)
41268 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41269 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41270 ret = (*fn) (filp, cmd, arg);
41271 - else
41272 + } else
41273 ret = drm_ioctl(filp, cmd, arg);
41274
41275 return ret;
41276 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41277 index 244b19b..c19226d 100644
41278 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41279 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41280 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41281 unsigned int ret;
41282 RING_LOCALS;
41283
41284 - atomic_inc(&dev_priv->swi_emitted);
41285 - ret = atomic_read(&dev_priv->swi_emitted);
41286 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41287 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41288
41289 BEGIN_RING(4);
41290 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41291 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41292 drm_radeon_private_t *dev_priv =
41293 (drm_radeon_private_t *) dev->dev_private;
41294
41295 - atomic_set(&dev_priv->swi_emitted, 0);
41296 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41297 init_waitqueue_head(&dev_priv->swi_queue);
41298
41299 dev->max_vblank_count = 0x001fffff;
41300 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41301 index 535403e..5dd655b 100644
41302 --- a/drivers/gpu/drm/radeon/radeon_state.c
41303 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41304 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41305 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41306 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41307
41308 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41309 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41310 sarea_priv->nbox * sizeof(depth_boxes[0])))
41311 return -EFAULT;
41312
41313 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41314 {
41315 drm_radeon_private_t *dev_priv = dev->dev_private;
41316 drm_radeon_getparam_t *param = data;
41317 - int value;
41318 + int value = 0;
41319
41320 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41321
41322 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41323 index d2510cf..63bd4ed 100644
41324 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41325 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41326 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41327 man->size = size >> PAGE_SHIFT;
41328 }
41329
41330 -static struct vm_operations_struct radeon_ttm_vm_ops;
41331 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41332 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41333
41334 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41335 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41336 }
41337 if (unlikely(ttm_vm_ops == NULL)) {
41338 ttm_vm_ops = vma->vm_ops;
41339 + pax_open_kernel();
41340 radeon_ttm_vm_ops = *ttm_vm_ops;
41341 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41342 + pax_close_kernel();
41343 }
41344 vma->vm_ops = &radeon_ttm_vm_ops;
41345 return 0;
41346 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41347 index 054a79f..30d9ac4 100644
41348 --- a/drivers/gpu/drm/tegra/dc.c
41349 +++ b/drivers/gpu/drm/tegra/dc.c
41350 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41351 }
41352
41353 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41354 - dc->debugfs_files[i].data = dc;
41355 + *(void **)&dc->debugfs_files[i].data = dc;
41356
41357 err = drm_debugfs_create_files(dc->debugfs_files,
41358 ARRAY_SIZE(debugfs_files),
41359 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41360 index f787445..2df2c65 100644
41361 --- a/drivers/gpu/drm/tegra/dsi.c
41362 +++ b/drivers/gpu/drm/tegra/dsi.c
41363 @@ -41,7 +41,7 @@ struct tegra_dsi {
41364 struct clk *clk_lp;
41365 struct clk *clk;
41366
41367 - struct drm_info_list *debugfs_files;
41368 + drm_info_list_no_const *debugfs_files;
41369 struct drm_minor *minor;
41370 struct dentry *debugfs;
41371
41372 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41373 index ffe2654..03c7b1c 100644
41374 --- a/drivers/gpu/drm/tegra/hdmi.c
41375 +++ b/drivers/gpu/drm/tegra/hdmi.c
41376 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41377 bool stereo;
41378 bool dvi;
41379
41380 - struct drm_info_list *debugfs_files;
41381 + drm_info_list_no_const *debugfs_files;
41382 struct drm_minor *minor;
41383 struct dentry *debugfs;
41384 };
41385 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41386 index 964387f..4eafc00 100644
41387 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41388 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41389 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41390 }
41391
41392 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41393 - ttm_bo_man_init,
41394 - ttm_bo_man_takedown,
41395 - ttm_bo_man_get_node,
41396 - ttm_bo_man_put_node,
41397 - ttm_bo_man_debug
41398 + .init = ttm_bo_man_init,
41399 + .takedown = ttm_bo_man_takedown,
41400 + .get_node = ttm_bo_man_get_node,
41401 + .put_node = ttm_bo_man_put_node,
41402 + .debug = ttm_bo_man_debug
41403 };
41404 EXPORT_SYMBOL(ttm_bo_manager_func);
41405 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41406 index a1803fb..c53f6b0 100644
41407 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41408 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41409 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41410 zone->glob = glob;
41411 glob->zone_kernel = zone;
41412 ret = kobject_init_and_add(
41413 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41414 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41415 if (unlikely(ret != 0)) {
41416 kobject_put(&zone->kobj);
41417 return ret;
41418 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41419 zone->glob = glob;
41420 glob->zone_dma32 = zone;
41421 ret = kobject_init_and_add(
41422 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41423 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41424 if (unlikely(ret != 0)) {
41425 kobject_put(&zone->kobj);
41426 return ret;
41427 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41428 index 025c429..314062f 100644
41429 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41430 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41431 @@ -54,7 +54,7 @@
41432
41433 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41434 #define SMALL_ALLOCATION 16
41435 -#define FREE_ALL_PAGES (~0U)
41436 +#define FREE_ALL_PAGES (~0UL)
41437 /* times are in msecs */
41438 #define PAGE_FREE_INTERVAL 1000
41439
41440 @@ -299,15 +299,14 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41441 * @free_all: If set to true will free all pages in pool
41442 * @use_static: Safe to use static buffer
41443 **/
41444 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41445 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41446 bool use_static)
41447 {
41448 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41449 unsigned long irq_flags;
41450 struct page *p;
41451 struct page **pages_to_free;
41452 - unsigned freed_pages = 0,
41453 - npages_to_free = nr_free;
41454 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41455
41456 if (NUM_PAGES_TO_ALLOC < nr_free)
41457 npages_to_free = NUM_PAGES_TO_ALLOC;
41458 @@ -371,7 +370,8 @@ restart:
41459 __list_del(&p->lru, &pool->list);
41460
41461 ttm_pool_update_free_locked(pool, freed_pages);
41462 - nr_free -= freed_pages;
41463 + if (likely(nr_free != FREE_ALL_PAGES))
41464 + nr_free -= freed_pages;
41465 }
41466
41467 spin_unlock_irqrestore(&pool->lock, irq_flags);
41468 @@ -399,7 +399,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41469 unsigned i;
41470 unsigned pool_offset;
41471 struct ttm_page_pool *pool;
41472 - int shrink_pages = sc->nr_to_scan;
41473 + unsigned long shrink_pages = sc->nr_to_scan;
41474 unsigned long freed = 0;
41475
41476 if (!mutex_trylock(&lock))
41477 @@ -407,7 +407,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41478 pool_offset = ++start_pool % NUM_POOLS;
41479 /* select start pool in round robin fashion */
41480 for (i = 0; i < NUM_POOLS; ++i) {
41481 - unsigned nr_free = shrink_pages;
41482 + unsigned long nr_free = shrink_pages;
41483 if (shrink_pages == 0)
41484 break;
41485 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41486 @@ -673,7 +673,7 @@ out:
41487 }
41488
41489 /* Put all pages in pages list to correct pool to wait for reuse */
41490 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41491 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41492 enum ttm_caching_state cstate)
41493 {
41494 unsigned long irq_flags;
41495 @@ -728,7 +728,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41496 struct list_head plist;
41497 struct page *p = NULL;
41498 gfp_t gfp_flags = GFP_USER;
41499 - unsigned count;
41500 + unsigned long count;
41501 int r;
41502
41503 /* set zero flag for page allocation if required */
41504 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41505 index 01e1d27..aaa018a 100644
41506 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41507 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41508 @@ -56,7 +56,7 @@
41509
41510 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41511 #define SMALL_ALLOCATION 4
41512 -#define FREE_ALL_PAGES (~0U)
41513 +#define FREE_ALL_PAGES (~0UL)
41514 /* times are in msecs */
41515 #define IS_UNDEFINED (0)
41516 #define IS_WC (1<<1)
41517 @@ -413,7 +413,7 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41518 * @nr_free: If set to true will free all pages in pool
41519 * @use_static: Safe to use static buffer
41520 **/
41521 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41522 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41523 bool use_static)
41524 {
41525 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41526 @@ -421,8 +421,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41527 struct dma_page *dma_p, *tmp;
41528 struct page **pages_to_free;
41529 struct list_head d_pages;
41530 - unsigned freed_pages = 0,
41531 - npages_to_free = nr_free;
41532 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41533
41534 if (NUM_PAGES_TO_ALLOC < nr_free)
41535 npages_to_free = NUM_PAGES_TO_ALLOC;
41536 @@ -499,7 +498,8 @@ restart:
41537 /* remove range of pages from the pool */
41538 if (freed_pages) {
41539 ttm_pool_update_free_locked(pool, freed_pages);
41540 - nr_free -= freed_pages;
41541 + if (likely(nr_free != FREE_ALL_PAGES))
41542 + nr_free -= freed_pages;
41543 }
41544
41545 spin_unlock_irqrestore(&pool->lock, irq_flags);
41546 @@ -936,7 +936,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41547 struct dma_page *d_page, *next;
41548 enum pool_type type;
41549 bool is_cached = false;
41550 - unsigned count = 0, i, npages = 0;
41551 + unsigned long count = 0, i, npages = 0;
41552 unsigned long irq_flags;
41553
41554 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41555 @@ -1012,7 +1012,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41556 static unsigned start_pool;
41557 unsigned idx = 0;
41558 unsigned pool_offset;
41559 - unsigned shrink_pages = sc->nr_to_scan;
41560 + unsigned long shrink_pages = sc->nr_to_scan;
41561 struct device_pools *p;
41562 unsigned long freed = 0;
41563
41564 @@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41565 goto out;
41566 pool_offset = ++start_pool % _manager->npools;
41567 list_for_each_entry(p, &_manager->pools, pools) {
41568 - unsigned nr_free;
41569 + unsigned long nr_free;
41570
41571 if (!p->dev)
41572 continue;
41573 @@ -1039,7 +1039,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41574 shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
41575 freed += nr_free - shrink_pages;
41576
41577 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41578 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41579 p->pool->dev_name, p->pool->name, current->pid,
41580 nr_free, shrink_pages);
41581 }
41582 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41583 index 8cbcb45..a4d9cf7 100644
41584 --- a/drivers/gpu/drm/udl/udl_fb.c
41585 +++ b/drivers/gpu/drm/udl/udl_fb.c
41586 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41587 fb_deferred_io_cleanup(info);
41588 kfree(info->fbdefio);
41589 info->fbdefio = NULL;
41590 - info->fbops->fb_mmap = udl_fb_mmap;
41591 }
41592
41593 pr_warn("released /dev/fb%d user=%d count=%d\n",
41594 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41595 index ef8c500..01030c8 100644
41596 --- a/drivers/gpu/drm/via/via_drv.h
41597 +++ b/drivers/gpu/drm/via/via_drv.h
41598 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41599 typedef uint32_t maskarray_t[5];
41600
41601 typedef struct drm_via_irq {
41602 - atomic_t irq_received;
41603 + atomic_unchecked_t irq_received;
41604 uint32_t pending_mask;
41605 uint32_t enable_mask;
41606 wait_queue_head_t irq_queue;
41607 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41608 struct timeval last_vblank;
41609 int last_vblank_valid;
41610 unsigned usec_per_vblank;
41611 - atomic_t vbl_received;
41612 + atomic_unchecked_t vbl_received;
41613 drm_via_state_t hc_state;
41614 char pci_buf[VIA_PCI_BUF_SIZE];
41615 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41616 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41617 index 1319433..a993b0c 100644
41618 --- a/drivers/gpu/drm/via/via_irq.c
41619 +++ b/drivers/gpu/drm/via/via_irq.c
41620 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41621 if (crtc != 0)
41622 return 0;
41623
41624 - return atomic_read(&dev_priv->vbl_received);
41625 + return atomic_read_unchecked(&dev_priv->vbl_received);
41626 }
41627
41628 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41629 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41630
41631 status = VIA_READ(VIA_REG_INTERRUPT);
41632 if (status & VIA_IRQ_VBLANK_PENDING) {
41633 - atomic_inc(&dev_priv->vbl_received);
41634 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41635 + atomic_inc_unchecked(&dev_priv->vbl_received);
41636 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41637 do_gettimeofday(&cur_vblank);
41638 if (dev_priv->last_vblank_valid) {
41639 dev_priv->usec_per_vblank =
41640 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41641 dev_priv->last_vblank = cur_vblank;
41642 dev_priv->last_vblank_valid = 1;
41643 }
41644 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41645 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41646 DRM_DEBUG("US per vblank is: %u\n",
41647 dev_priv->usec_per_vblank);
41648 }
41649 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41650
41651 for (i = 0; i < dev_priv->num_irqs; ++i) {
41652 if (status & cur_irq->pending_mask) {
41653 - atomic_inc(&cur_irq->irq_received);
41654 + atomic_inc_unchecked(&cur_irq->irq_received);
41655 wake_up(&cur_irq->irq_queue);
41656 handled = 1;
41657 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41658 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41659 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41660 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41661 masks[irq][4]));
41662 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41663 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41664 } else {
41665 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41666 (((cur_irq_sequence =
41667 - atomic_read(&cur_irq->irq_received)) -
41668 + atomic_read_unchecked(&cur_irq->irq_received)) -
41669 *sequence) <= (1 << 23)));
41670 }
41671 *sequence = cur_irq_sequence;
41672 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41673 }
41674
41675 for (i = 0; i < dev_priv->num_irqs; ++i) {
41676 - atomic_set(&cur_irq->irq_received, 0);
41677 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41678 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41679 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41680 init_waitqueue_head(&cur_irq->irq_queue);
41681 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41682 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41683 case VIA_IRQ_RELATIVE:
41684 irqwait->request.sequence +=
41685 - atomic_read(&cur_irq->irq_received);
41686 + atomic_read_unchecked(&cur_irq->irq_received);
41687 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41688 case VIA_IRQ_ABSOLUTE:
41689 break;
41690 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41691 index d26a6da..5fa41ed 100644
41692 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41693 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41694 @@ -447,7 +447,7 @@ struct vmw_private {
41695 * Fencing and IRQs.
41696 */
41697
41698 - atomic_t marker_seq;
41699 + atomic_unchecked_t marker_seq;
41700 wait_queue_head_t fence_queue;
41701 wait_queue_head_t fifo_queue;
41702 spinlock_t waiter_lock;
41703 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41704 index 39f2b03..d1b0a64 100644
41705 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41706 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41707 @@ -152,7 +152,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41708 (unsigned int) min,
41709 (unsigned int) fifo->capabilities);
41710
41711 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41712 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41713 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41714 vmw_marker_queue_init(&fifo->marker_queue);
41715 return vmw_fifo_send_fence(dev_priv, &dummy);
41716 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41717 if (reserveable)
41718 iowrite32(bytes, fifo_mem +
41719 SVGA_FIFO_RESERVED);
41720 - return fifo_mem + (next_cmd >> 2);
41721 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41722 } else {
41723 need_bounce = true;
41724 }
41725 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41726
41727 fm = vmw_fifo_reserve(dev_priv, bytes);
41728 if (unlikely(fm == NULL)) {
41729 - *seqno = atomic_read(&dev_priv->marker_seq);
41730 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41731 ret = -ENOMEM;
41732 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41733 false, 3*HZ);
41734 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41735 }
41736
41737 do {
41738 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41739 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41740 } while (*seqno == 0);
41741
41742 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41743 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41744 index 170b61b..fec7348 100644
41745 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41746 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41747 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41748 }
41749
41750 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41751 - vmw_gmrid_man_init,
41752 - vmw_gmrid_man_takedown,
41753 - vmw_gmrid_man_get_node,
41754 - vmw_gmrid_man_put_node,
41755 - vmw_gmrid_man_debug
41756 + .init = vmw_gmrid_man_init,
41757 + .takedown = vmw_gmrid_man_takedown,
41758 + .get_node = vmw_gmrid_man_get_node,
41759 + .put_node = vmw_gmrid_man_put_node,
41760 + .debug = vmw_gmrid_man_debug
41761 };
41762 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41763 index 69c8ce2..cacb0ab 100644
41764 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41765 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41766 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41767 int ret;
41768
41769 num_clips = arg->num_clips;
41770 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41771 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41772
41773 if (unlikely(num_clips == 0))
41774 return 0;
41775 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41776 int ret;
41777
41778 num_clips = arg->num_clips;
41779 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41780 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41781
41782 if (unlikely(num_clips == 0))
41783 return 0;
41784 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41785 index 9fe9827..0aa2fc0 100644
41786 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41787 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41788 @@ -102,7 +102,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41789 * emitted. Then the fence is stale and signaled.
41790 */
41791
41792 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41793 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41794 > VMW_FENCE_WRAP);
41795
41796 return ret;
41797 @@ -133,7 +133,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41798
41799 if (fifo_idle)
41800 down_read(&fifo_state->rwsem);
41801 - signal_seq = atomic_read(&dev_priv->marker_seq);
41802 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41803 ret = 0;
41804
41805 for (;;) {
41806 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41807 index efd1ffd..0ae13ca 100644
41808 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41809 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41810 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41811 while (!vmw_lag_lt(queue, us)) {
41812 spin_lock(&queue->lock);
41813 if (list_empty(&queue->head))
41814 - seqno = atomic_read(&dev_priv->marker_seq);
41815 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41816 else {
41817 marker = list_first_entry(&queue->head,
41818 struct vmw_marker, head);
41819 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41820 index 37ac7b5..d52a5c9 100644
41821 --- a/drivers/gpu/vga/vga_switcheroo.c
41822 +++ b/drivers/gpu/vga/vga_switcheroo.c
41823 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41824
41825 /* this version is for the case where the power switch is separate
41826 to the device being powered down. */
41827 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41828 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41829 {
41830 /* copy over all the bus versions */
41831 if (dev->bus && dev->bus->pm) {
41832 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41833 return ret;
41834 }
41835
41836 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41837 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41838 {
41839 /* copy over all the bus versions */
41840 if (dev->bus && dev->bus->pm) {
41841 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41842 index dfaccfc..bfea740 100644
41843 --- a/drivers/hid/hid-core.c
41844 +++ b/drivers/hid/hid-core.c
41845 @@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41846
41847 int hid_add_device(struct hid_device *hdev)
41848 {
41849 - static atomic_t id = ATOMIC_INIT(0);
41850 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41851 int ret;
41852
41853 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41854 @@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41855 /* XXX hack, any other cleaner solution after the driver core
41856 * is converted to allow more than 20 bytes as the device name? */
41857 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41858 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41859 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41860
41861 hid_debug_register(hdev, dev_name(&hdev->dev));
41862 ret = device_add(&hdev->dev);
41863 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41864 index 71f5692..147d3da 100644
41865 --- a/drivers/hid/hid-logitech-dj.c
41866 +++ b/drivers/hid/hid-logitech-dj.c
41867 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41868 * device (via hid_input_report() ) and return 1 so hid-core does not do
41869 * anything else with it.
41870 */
41871 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41872 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41873 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41874 + __func__, dj_report->device_index);
41875 + return false;
41876 + }
41877
41878 /* case 1) */
41879 if (data[0] != REPORT_ID_DJ_SHORT)
41880 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41881 index bc4269e..b6e6102 100644
41882 --- a/drivers/hid/hid-sony.c
41883 +++ b/drivers/hid/hid-sony.c
41884 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41885 __u8 buf[36];
41886 };
41887
41888 +#define DS4_REPORT_0x02_SIZE 37
41889 +#define DS4_REPORT_0x05_SIZE 32
41890 +#define DS4_REPORT_0x11_SIZE 78
41891 +#define DS4_REPORT_0x81_SIZE 7
41892 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41893 +
41894 static spinlock_t sony_dev_list_lock;
41895 static LIST_HEAD(sony_device_list);
41896 static DEFINE_IDA(sony_device_id_allocator);
41897 @@ -811,6 +817,7 @@ struct sony_sc {
41898 struct work_struct state_worker;
41899 struct power_supply battery;
41900 int device_id;
41901 + __u8 *output_report_dmabuf;
41902
41903 #ifdef CONFIG_SONY_FF
41904 __u8 left;
41905 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41906
41907 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41908 {
41909 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41910 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41911 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41912 + __u8 *buf;
41913 + int ret;
41914 +
41915 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41916 + if (!buf)
41917 + return -ENOMEM;
41918 +
41919 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41920 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41921 +
41922 + kfree(buf);
41923 +
41924 + return ret;
41925 }
41926
41927 /*
41928 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41929 */
41930 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41931 {
41932 - __u8 buf[37] = { 0 };
41933 + __u8 *buf;
41934 + int ret;
41935
41936 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41937 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41938 + if (!buf)
41939 + return -ENOMEM;
41940 +
41941 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41942 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41943 +
41944 + kfree(buf);
41945 +
41946 + return ret;
41947 }
41948
41949 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41950 @@ -1471,9 +1498,7 @@ error_leds:
41951
41952 static void sixaxis_state_worker(struct work_struct *work)
41953 {
41954 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41955 - int n;
41956 - union sixaxis_output_report_01 report = {
41957 + static const union sixaxis_output_report_01 default_report = {
41958 .buf = {
41959 0x01,
41960 0x00, 0xff, 0x00, 0xff, 0x00,
41961 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41962 0x00, 0x00, 0x00, 0x00, 0x00
41963 }
41964 };
41965 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41966 + struct sixaxis_output_report *report =
41967 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
41968 + int n;
41969 +
41970 + /* Initialize the report with default values */
41971 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41972
41973 #ifdef CONFIG_SONY_FF
41974 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41975 - report.data.rumble.left_motor_force = sc->left;
41976 + report->rumble.right_motor_on = sc->right ? 1 : 0;
41977 + report->rumble.left_motor_force = sc->left;
41978 #endif
41979
41980 - report.data.leds_bitmap |= sc->led_state[0] << 1;
41981 - report.data.leds_bitmap |= sc->led_state[1] << 2;
41982 - report.data.leds_bitmap |= sc->led_state[2] << 3;
41983 - report.data.leds_bitmap |= sc->led_state[3] << 4;
41984 + report->leds_bitmap |= sc->led_state[0] << 1;
41985 + report->leds_bitmap |= sc->led_state[1] << 2;
41986 + report->leds_bitmap |= sc->led_state[2] << 3;
41987 + report->leds_bitmap |= sc->led_state[3] << 4;
41988
41989 /* Set flag for all leds off, required for 3rd party INTEC controller */
41990 - if ((report.data.leds_bitmap & 0x1E) == 0)
41991 - report.data.leds_bitmap |= 0x20;
41992 + if ((report->leds_bitmap & 0x1E) == 0)
41993 + report->leds_bitmap |= 0x20;
41994
41995 /*
41996 * The LEDs in the report are indexed in reverse order to their
41997 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41998 */
41999 for (n = 0; n < 4; n++) {
42000 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
42001 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
42002 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
42003 + report->led[3 - n].duty_off = sc->led_delay_off[n];
42004 + report->led[3 - n].duty_on = sc->led_delay_on[n];
42005 }
42006 }
42007
42008 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
42009 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42010 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
42011 + sizeof(struct sixaxis_output_report),
42012 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42013 }
42014
42015 static void dualshock4_state_worker(struct work_struct *work)
42016 {
42017 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
42018 struct hid_device *hdev = sc->hdev;
42019 + __u8 *buf = sc->output_report_dmabuf;
42020 int offset;
42021
42022 - __u8 buf[78] = { 0 };
42023 -
42024 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42025 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
42026 buf[0] = 0x05;
42027 buf[1] = 0xFF;
42028 offset = 4;
42029 } else {
42030 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
42031 buf[0] = 0x11;
42032 buf[1] = 0xB0;
42033 buf[3] = 0x0F;
42034 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
42035 buf[offset++] = sc->led_delay_off[3];
42036
42037 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42038 - hid_hw_output_report(hdev, buf, 32);
42039 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42040 else
42041 - hid_hw_raw_request(hdev, 0x11, buf, 78,
42042 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42043 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42044 }
42045
42046 +static int sony_allocate_output_report(struct sony_sc *sc)
42047 +{
42048 + if (sc->quirks & SIXAXIS_CONTROLLER)
42049 + sc->output_report_dmabuf =
42050 + kmalloc(sizeof(union sixaxis_output_report_01),
42051 + GFP_KERNEL);
42052 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42053 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42054 + GFP_KERNEL);
42055 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42056 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42057 + GFP_KERNEL);
42058 + else
42059 + return 0;
42060 +
42061 + if (!sc->output_report_dmabuf)
42062 + return -ENOMEM;
42063 +
42064 + return 0;
42065 +}
42066 +
42067 #ifdef CONFIG_SONY_FF
42068 static int sony_play_effect(struct input_dev *dev, void *data,
42069 struct ff_effect *effect)
42070 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42071
42072 static int sony_check_add(struct sony_sc *sc)
42073 {
42074 + __u8 *buf = NULL;
42075 int n, ret;
42076
42077 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42078 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42079 return 0;
42080 }
42081 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42082 - __u8 buf[7];
42083 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42084 + if (!buf)
42085 + return -ENOMEM;
42086
42087 /*
42088 * The MAC address of a DS4 controller connected via USB can be
42089 * retrieved with feature report 0x81. The address begins at
42090 * offset 1.
42091 */
42092 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42093 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42094 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42095 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42096 + HID_REQ_GET_REPORT);
42097
42098 - if (ret != 7) {
42099 + if (ret != DS4_REPORT_0x81_SIZE) {
42100 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42101 - return ret < 0 ? ret : -EINVAL;
42102 + ret = ret < 0 ? ret : -EINVAL;
42103 + goto out_free;
42104 }
42105
42106 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42107 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42108 - __u8 buf[18];
42109 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42110 + if (!buf)
42111 + return -ENOMEM;
42112
42113 /*
42114 * The MAC address of a Sixaxis controller connected via USB can
42115 * be retrieved with feature report 0xf2. The address begins at
42116 * offset 4.
42117 */
42118 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42119 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42120 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42121 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42122 + HID_REQ_GET_REPORT);
42123
42124 - if (ret != 18) {
42125 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42126 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42127 - return ret < 0 ? ret : -EINVAL;
42128 + ret = ret < 0 ? ret : -EINVAL;
42129 + goto out_free;
42130 }
42131
42132 /*
42133 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42134 return 0;
42135 }
42136
42137 - return sony_check_add_dev_list(sc);
42138 + ret = sony_check_add_dev_list(sc);
42139 +
42140 +out_free:
42141 +
42142 + kfree(buf);
42143 +
42144 + return ret;
42145 }
42146
42147 static int sony_set_device_id(struct sony_sc *sc)
42148 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42149 return ret;
42150 }
42151
42152 + ret = sony_allocate_output_report(sc);
42153 + if (ret < 0) {
42154 + hid_err(hdev, "failed to allocate the output report buffer\n");
42155 + goto err_stop;
42156 + }
42157 +
42158 ret = sony_set_device_id(sc);
42159 if (ret < 0) {
42160 hid_err(hdev, "failed to allocate the device id\n");
42161 @@ -1984,6 +2060,7 @@ err_stop:
42162 if (sc->quirks & SONY_BATTERY_SUPPORT)
42163 sony_battery_remove(sc);
42164 sony_cancel_work_sync(sc);
42165 + kfree(sc->output_report_dmabuf);
42166 sony_remove_dev_list(sc);
42167 sony_release_device_id(sc);
42168 hid_hw_stop(hdev);
42169 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42170
42171 sony_cancel_work_sync(sc);
42172
42173 + kfree(sc->output_report_dmabuf);
42174 +
42175 sony_remove_dev_list(sc);
42176
42177 sony_release_device_id(sc);
42178 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42179 index c13fb5b..55a3802 100644
42180 --- a/drivers/hid/hid-wiimote-debug.c
42181 +++ b/drivers/hid/hid-wiimote-debug.c
42182 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42183 else if (size == 0)
42184 return -EIO;
42185
42186 - if (copy_to_user(u, buf, size))
42187 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42188 return -EFAULT;
42189
42190 *off += size;
42191 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42192 index 433f72a..2926005 100644
42193 --- a/drivers/hv/channel.c
42194 +++ b/drivers/hv/channel.c
42195 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42196 unsigned long flags;
42197 int ret = 0;
42198
42199 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42200 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42201 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42202 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42203
42204 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42205 if (ret)
42206 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42207 index 3e4235c..877d0e5 100644
42208 --- a/drivers/hv/hv.c
42209 +++ b/drivers/hv/hv.c
42210 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42211 u64 output_address = (output) ? virt_to_phys(output) : 0;
42212 u32 output_address_hi = output_address >> 32;
42213 u32 output_address_lo = output_address & 0xFFFFFFFF;
42214 - void *hypercall_page = hv_context.hypercall_page;
42215 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42216
42217 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42218 "=a"(hv_status_lo) : "d" (control_hi),
42219 @@ -156,7 +156,7 @@ int hv_init(void)
42220 /* See if the hypercall page is already set */
42221 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42222
42223 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42224 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42225
42226 if (!virtaddr)
42227 goto cleanup;
42228 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42229 index 5e90c5d..d8fcefb 100644
42230 --- a/drivers/hv/hv_balloon.c
42231 +++ b/drivers/hv/hv_balloon.c
42232 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42233
42234 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42235 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42236 -static atomic_t trans_id = ATOMIC_INIT(0);
42237 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42238
42239 static int dm_ring_size = (5 * PAGE_SIZE);
42240
42241 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42242 pr_info("Memory hot add failed\n");
42243
42244 dm->state = DM_INITIALIZED;
42245 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42246 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42247 vmbus_sendpacket(dm->dev->channel, &resp,
42248 sizeof(struct dm_hot_add_response),
42249 (unsigned long)NULL,
42250 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42251 memset(&status, 0, sizeof(struct dm_status));
42252 status.hdr.type = DM_STATUS_REPORT;
42253 status.hdr.size = sizeof(struct dm_status);
42254 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42255 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42256
42257 /*
42258 * The host expects the guest to report free memory.
42259 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42260 * send the status. This can happen if we were interrupted
42261 * after we picked our transaction ID.
42262 */
42263 - if (status.hdr.trans_id != atomic_read(&trans_id))
42264 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42265 return;
42266
42267 /*
42268 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42269 */
42270
42271 do {
42272 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42273 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42274 ret = vmbus_sendpacket(dm_device.dev->channel,
42275 bl_resp,
42276 bl_resp->hdr.size,
42277 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42278
42279 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42280 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42281 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42282 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42283 resp.hdr.size = sizeof(struct dm_unballoon_response);
42284
42285 vmbus_sendpacket(dm_device.dev->channel, &resp,
42286 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42287 memset(&version_req, 0, sizeof(struct dm_version_request));
42288 version_req.hdr.type = DM_VERSION_REQUEST;
42289 version_req.hdr.size = sizeof(struct dm_version_request);
42290 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42291 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42292 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42293 version_req.is_last_attempt = 1;
42294
42295 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42296 memset(&version_req, 0, sizeof(struct dm_version_request));
42297 version_req.hdr.type = DM_VERSION_REQUEST;
42298 version_req.hdr.size = sizeof(struct dm_version_request);
42299 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42300 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42301 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42302 version_req.is_last_attempt = 0;
42303
42304 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42305 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42306 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42307 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42308 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42309 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42310
42311 cap_msg.caps.cap_bits.balloon = 1;
42312 cap_msg.caps.cap_bits.hot_add = 1;
42313 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42314 index c386d8d..d6004c4 100644
42315 --- a/drivers/hv/hyperv_vmbus.h
42316 +++ b/drivers/hv/hyperv_vmbus.h
42317 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42318 struct vmbus_connection {
42319 enum vmbus_connect_state conn_state;
42320
42321 - atomic_t next_gpadl_handle;
42322 + atomic_unchecked_t next_gpadl_handle;
42323
42324 /*
42325 * Represents channel interrupts. Each bit position represents a
42326 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42327 index 4d6b269..2e23b86 100644
42328 --- a/drivers/hv/vmbus_drv.c
42329 +++ b/drivers/hv/vmbus_drv.c
42330 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42331 {
42332 int ret = 0;
42333
42334 - static atomic_t device_num = ATOMIC_INIT(0);
42335 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42336
42337 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42338 - atomic_inc_return(&device_num));
42339 + atomic_inc_return_unchecked(&device_num));
42340
42341 child_device_obj->device.bus = &hv_bus;
42342 child_device_obj->device.parent = &hv_acpi_dev->dev;
42343 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42344 index 579bdf9..75118b5 100644
42345 --- a/drivers/hwmon/acpi_power_meter.c
42346 +++ b/drivers/hwmon/acpi_power_meter.c
42347 @@ -116,7 +116,7 @@ struct sensor_template {
42348 struct device_attribute *devattr,
42349 const char *buf, size_t count);
42350 int index;
42351 -};
42352 +} __do_const;
42353
42354 /* Averaging interval */
42355 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42356 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42357 struct sensor_template *attrs)
42358 {
42359 struct device *dev = &resource->acpi_dev->dev;
42360 - struct sensor_device_attribute *sensors =
42361 + sensor_device_attribute_no_const *sensors =
42362 &resource->sensors[resource->num_sensors];
42363 int res = 0;
42364
42365 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42366 index 3288f13..71cfb4e 100644
42367 --- a/drivers/hwmon/applesmc.c
42368 +++ b/drivers/hwmon/applesmc.c
42369 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42370 {
42371 struct applesmc_node_group *grp;
42372 struct applesmc_dev_attr *node;
42373 - struct attribute *attr;
42374 + attribute_no_const *attr;
42375 int ret, i;
42376
42377 for (grp = groups; grp->format; grp++) {
42378 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42379 index cccef87..06ce8ec 100644
42380 --- a/drivers/hwmon/asus_atk0110.c
42381 +++ b/drivers/hwmon/asus_atk0110.c
42382 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42383 struct atk_sensor_data {
42384 struct list_head list;
42385 struct atk_data *data;
42386 - struct device_attribute label_attr;
42387 - struct device_attribute input_attr;
42388 - struct device_attribute limit1_attr;
42389 - struct device_attribute limit2_attr;
42390 + device_attribute_no_const label_attr;
42391 + device_attribute_no_const input_attr;
42392 + device_attribute_no_const limit1_attr;
42393 + device_attribute_no_const limit2_attr;
42394 char label_attr_name[ATTR_NAME_SIZE];
42395 char input_attr_name[ATTR_NAME_SIZE];
42396 char limit1_attr_name[ATTR_NAME_SIZE];
42397 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42398 static struct device_attribute atk_name_attr =
42399 __ATTR(name, 0444, atk_name_show, NULL);
42400
42401 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42402 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42403 sysfs_show_func show)
42404 {
42405 sysfs_attr_init(&attr->attr);
42406 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42407 index d76f0b7..55ae976 100644
42408 --- a/drivers/hwmon/coretemp.c
42409 +++ b/drivers/hwmon/coretemp.c
42410 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42411 return NOTIFY_OK;
42412 }
42413
42414 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42415 +static struct notifier_block coretemp_cpu_notifier = {
42416 .notifier_call = coretemp_cpu_callback,
42417 };
42418
42419 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42420 index 7a8a6fb..015c1fd 100644
42421 --- a/drivers/hwmon/ibmaem.c
42422 +++ b/drivers/hwmon/ibmaem.c
42423 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42424 struct aem_rw_sensor_template *rw)
42425 {
42426 struct device *dev = &data->pdev->dev;
42427 - struct sensor_device_attribute *sensors = data->sensors;
42428 + sensor_device_attribute_no_const *sensors = data->sensors;
42429 int err;
42430
42431 /* Set up read-only sensors */
42432 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42433 index 14c82da..09b25d7 100644
42434 --- a/drivers/hwmon/iio_hwmon.c
42435 +++ b/drivers/hwmon/iio_hwmon.c
42436 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42437 {
42438 struct device *dev = &pdev->dev;
42439 struct iio_hwmon_state *st;
42440 - struct sensor_device_attribute *a;
42441 + sensor_device_attribute_no_const *a;
42442 int ret, i;
42443 int in_i = 1, temp_i = 1, curr_i = 1;
42444 enum iio_chan_type type;
42445 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42446 index 7710f46..427a28d 100644
42447 --- a/drivers/hwmon/nct6683.c
42448 +++ b/drivers/hwmon/nct6683.c
42449 @@ -397,11 +397,11 @@ static struct attribute_group *
42450 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42451 int repeat)
42452 {
42453 - struct sensor_device_attribute_2 *a2;
42454 - struct sensor_device_attribute *a;
42455 + sensor_device_attribute_2_no_const *a2;
42456 + sensor_device_attribute_no_const *a;
42457 struct sensor_device_template **t;
42458 struct sensor_device_attr_u *su;
42459 - struct attribute_group *group;
42460 + attribute_group_no_const *group;
42461 struct attribute **attrs;
42462 int i, j, count;
42463
42464 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42465 index 504cbdd..35d6f25 100644
42466 --- a/drivers/hwmon/nct6775.c
42467 +++ b/drivers/hwmon/nct6775.c
42468 @@ -943,10 +943,10 @@ static struct attribute_group *
42469 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42470 int repeat)
42471 {
42472 - struct attribute_group *group;
42473 + attribute_group_no_const *group;
42474 struct sensor_device_attr_u *su;
42475 - struct sensor_device_attribute *a;
42476 - struct sensor_device_attribute_2 *a2;
42477 + sensor_device_attribute_no_const *a;
42478 + sensor_device_attribute_2_no_const *a2;
42479 struct attribute **attrs;
42480 struct sensor_device_template **t;
42481 int i, count;
42482 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42483 index 291d11f..3f0dbbd 100644
42484 --- a/drivers/hwmon/pmbus/pmbus_core.c
42485 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42486 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42487 return 0;
42488 }
42489
42490 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42491 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42492 const char *name,
42493 umode_t mode,
42494 ssize_t (*show)(struct device *dev,
42495 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42496 dev_attr->store = store;
42497 }
42498
42499 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42500 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42501 const char *name,
42502 umode_t mode,
42503 ssize_t (*show)(struct device *dev,
42504 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42505 u16 reg, u8 mask)
42506 {
42507 struct pmbus_boolean *boolean;
42508 - struct sensor_device_attribute *a;
42509 + sensor_device_attribute_no_const *a;
42510
42511 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42512 if (!boolean)
42513 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42514 bool update, bool readonly)
42515 {
42516 struct pmbus_sensor *sensor;
42517 - struct device_attribute *a;
42518 + device_attribute_no_const *a;
42519
42520 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42521 if (!sensor)
42522 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42523 const char *lstring, int index)
42524 {
42525 struct pmbus_label *label;
42526 - struct device_attribute *a;
42527 + device_attribute_no_const *a;
42528
42529 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42530 if (!label)
42531 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42532 index 97cd45a..ac54d8b 100644
42533 --- a/drivers/hwmon/sht15.c
42534 +++ b/drivers/hwmon/sht15.c
42535 @@ -169,7 +169,7 @@ struct sht15_data {
42536 int supply_uv;
42537 bool supply_uv_valid;
42538 struct work_struct update_supply_work;
42539 - atomic_t interrupt_handled;
42540 + atomic_unchecked_t interrupt_handled;
42541 };
42542
42543 /**
42544 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42545 ret = gpio_direction_input(data->pdata->gpio_data);
42546 if (ret)
42547 return ret;
42548 - atomic_set(&data->interrupt_handled, 0);
42549 + atomic_set_unchecked(&data->interrupt_handled, 0);
42550
42551 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42552 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42553 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42554 /* Only relevant if the interrupt hasn't occurred. */
42555 - if (!atomic_read(&data->interrupt_handled))
42556 + if (!atomic_read_unchecked(&data->interrupt_handled))
42557 schedule_work(&data->read_work);
42558 }
42559 ret = wait_event_timeout(data->wait_queue,
42560 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42561
42562 /* First disable the interrupt */
42563 disable_irq_nosync(irq);
42564 - atomic_inc(&data->interrupt_handled);
42565 + atomic_inc_unchecked(&data->interrupt_handled);
42566 /* Then schedule a reading work struct */
42567 if (data->state != SHT15_READING_NOTHING)
42568 schedule_work(&data->read_work);
42569 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42570 * If not, then start the interrupt again - care here as could
42571 * have gone low in meantime so verify it hasn't!
42572 */
42573 - atomic_set(&data->interrupt_handled, 0);
42574 + atomic_set_unchecked(&data->interrupt_handled, 0);
42575 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42576 /* If still not occurred or another handler was scheduled */
42577 if (gpio_get_value(data->pdata->gpio_data)
42578 - || atomic_read(&data->interrupt_handled))
42579 + || atomic_read_unchecked(&data->interrupt_handled))
42580 return;
42581 }
42582
42583 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42584 index 8df43c5..b07b91d 100644
42585 --- a/drivers/hwmon/via-cputemp.c
42586 +++ b/drivers/hwmon/via-cputemp.c
42587 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42588 return NOTIFY_OK;
42589 }
42590
42591 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42592 +static struct notifier_block via_cputemp_cpu_notifier = {
42593 .notifier_call = via_cputemp_cpu_callback,
42594 };
42595
42596 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42597 index 65e3240..e6c511d 100644
42598 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42599 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42600 @@ -39,7 +39,7 @@
42601 extern struct i2c_adapter amd756_smbus;
42602
42603 static struct i2c_adapter *s4882_adapter;
42604 -static struct i2c_algorithm *s4882_algo;
42605 +static i2c_algorithm_no_const *s4882_algo;
42606
42607 /* Wrapper access functions for multiplexed SMBus */
42608 static DEFINE_MUTEX(amd756_lock);
42609 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42610 index b19a310..d6eece0 100644
42611 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42612 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42613 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42614 /* usb layer */
42615
42616 /* Send command to device, and get response. */
42617 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42618 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42619 {
42620 int ret = 0;
42621 int actual;
42622 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42623 index 88eda09..cf40434 100644
42624 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42625 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42626 @@ -37,7 +37,7 @@
42627 extern struct i2c_adapter *nforce2_smbus;
42628
42629 static struct i2c_adapter *s4985_adapter;
42630 -static struct i2c_algorithm *s4985_algo;
42631 +static i2c_algorithm_no_const *s4985_algo;
42632
42633 /* Wrapper access functions for multiplexed SMBus */
42634 static DEFINE_MUTEX(nforce2_lock);
42635 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42636 index 71c7a39..71dd3e0 100644
42637 --- a/drivers/i2c/i2c-dev.c
42638 +++ b/drivers/i2c/i2c-dev.c
42639 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42640 break;
42641 }
42642
42643 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42644 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42645 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42646 if (IS_ERR(rdwr_pa[i].buf)) {
42647 res = PTR_ERR(rdwr_pa[i].buf);
42648 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42649 index 0b510ba..4fbb5085 100644
42650 --- a/drivers/ide/ide-cd.c
42651 +++ b/drivers/ide/ide-cd.c
42652 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42653 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42654 if ((unsigned long)buf & alignment
42655 || blk_rq_bytes(rq) & q->dma_pad_mask
42656 - || object_is_on_stack(buf))
42657 + || object_starts_on_stack(buf))
42658 drive->dma = 0;
42659 }
42660 }
42661 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42662 index af3e76d..96dfe5e 100644
42663 --- a/drivers/iio/industrialio-core.c
42664 +++ b/drivers/iio/industrialio-core.c
42665 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42666 }
42667
42668 static
42669 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42670 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42671 const char *postfix,
42672 struct iio_chan_spec const *chan,
42673 ssize_t (*readfunc)(struct device *dev,
42674 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42675 index e28a494..f7c2671 100644
42676 --- a/drivers/infiniband/core/cm.c
42677 +++ b/drivers/infiniband/core/cm.c
42678 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42679
42680 struct cm_counter_group {
42681 struct kobject obj;
42682 - atomic_long_t counter[CM_ATTR_COUNT];
42683 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42684 };
42685
42686 struct cm_counter_attribute {
42687 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42688 struct ib_mad_send_buf *msg = NULL;
42689 int ret;
42690
42691 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42692 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42693 counter[CM_REQ_COUNTER]);
42694
42695 /* Quick state check to discard duplicate REQs. */
42696 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42697 if (!cm_id_priv)
42698 return;
42699
42700 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42701 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42702 counter[CM_REP_COUNTER]);
42703 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42704 if (ret)
42705 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42706 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42707 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42708 spin_unlock_irq(&cm_id_priv->lock);
42709 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42710 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42711 counter[CM_RTU_COUNTER]);
42712 goto out;
42713 }
42714 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42715 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42716 dreq_msg->local_comm_id);
42717 if (!cm_id_priv) {
42718 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42719 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42720 counter[CM_DREQ_COUNTER]);
42721 cm_issue_drep(work->port, work->mad_recv_wc);
42722 return -EINVAL;
42723 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42724 case IB_CM_MRA_REP_RCVD:
42725 break;
42726 case IB_CM_TIMEWAIT:
42727 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42728 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42729 counter[CM_DREQ_COUNTER]);
42730 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42731 goto unlock;
42732 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42733 cm_free_msg(msg);
42734 goto deref;
42735 case IB_CM_DREQ_RCVD:
42736 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42737 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42738 counter[CM_DREQ_COUNTER]);
42739 goto unlock;
42740 default:
42741 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42742 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42743 cm_id_priv->msg, timeout)) {
42744 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42745 - atomic_long_inc(&work->port->
42746 + atomic_long_inc_unchecked(&work->port->
42747 counter_group[CM_RECV_DUPLICATES].
42748 counter[CM_MRA_COUNTER]);
42749 goto out;
42750 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42751 break;
42752 case IB_CM_MRA_REQ_RCVD:
42753 case IB_CM_MRA_REP_RCVD:
42754 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42755 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42756 counter[CM_MRA_COUNTER]);
42757 /* fall through */
42758 default:
42759 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42760 case IB_CM_LAP_IDLE:
42761 break;
42762 case IB_CM_MRA_LAP_SENT:
42763 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42764 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42765 counter[CM_LAP_COUNTER]);
42766 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42767 goto unlock;
42768 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42769 cm_free_msg(msg);
42770 goto deref;
42771 case IB_CM_LAP_RCVD:
42772 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42773 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42774 counter[CM_LAP_COUNTER]);
42775 goto unlock;
42776 default:
42777 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42778 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42779 if (cur_cm_id_priv) {
42780 spin_unlock_irq(&cm.lock);
42781 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42782 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42783 counter[CM_SIDR_REQ_COUNTER]);
42784 goto out; /* Duplicate message. */
42785 }
42786 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42787 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42788 msg->retries = 1;
42789
42790 - atomic_long_add(1 + msg->retries,
42791 + atomic_long_add_unchecked(1 + msg->retries,
42792 &port->counter_group[CM_XMIT].counter[attr_index]);
42793 if (msg->retries)
42794 - atomic_long_add(msg->retries,
42795 + atomic_long_add_unchecked(msg->retries,
42796 &port->counter_group[CM_XMIT_RETRIES].
42797 counter[attr_index]);
42798
42799 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42800 }
42801
42802 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42803 - atomic_long_inc(&port->counter_group[CM_RECV].
42804 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42805 counter[attr_id - CM_ATTR_ID_OFFSET]);
42806
42807 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42808 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42809 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42810
42811 return sprintf(buf, "%ld\n",
42812 - atomic_long_read(&group->counter[cm_attr->index]));
42813 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42814 }
42815
42816 static const struct sysfs_ops cm_counter_ops = {
42817 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42818 index 9f5ad7c..588cd84 100644
42819 --- a/drivers/infiniband/core/fmr_pool.c
42820 +++ b/drivers/infiniband/core/fmr_pool.c
42821 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42822
42823 struct task_struct *thread;
42824
42825 - atomic_t req_ser;
42826 - atomic_t flush_ser;
42827 + atomic_unchecked_t req_ser;
42828 + atomic_unchecked_t flush_ser;
42829
42830 wait_queue_head_t force_wait;
42831 };
42832 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42833 struct ib_fmr_pool *pool = pool_ptr;
42834
42835 do {
42836 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42837 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42838 ib_fmr_batch_release(pool);
42839
42840 - atomic_inc(&pool->flush_ser);
42841 + atomic_inc_unchecked(&pool->flush_ser);
42842 wake_up_interruptible(&pool->force_wait);
42843
42844 if (pool->flush_function)
42845 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42846 }
42847
42848 set_current_state(TASK_INTERRUPTIBLE);
42849 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42850 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42851 !kthread_should_stop())
42852 schedule();
42853 __set_current_state(TASK_RUNNING);
42854 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42855 pool->dirty_watermark = params->dirty_watermark;
42856 pool->dirty_len = 0;
42857 spin_lock_init(&pool->pool_lock);
42858 - atomic_set(&pool->req_ser, 0);
42859 - atomic_set(&pool->flush_ser, 0);
42860 + atomic_set_unchecked(&pool->req_ser, 0);
42861 + atomic_set_unchecked(&pool->flush_ser, 0);
42862 init_waitqueue_head(&pool->force_wait);
42863
42864 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42865 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42866 }
42867 spin_unlock_irq(&pool->pool_lock);
42868
42869 - serial = atomic_inc_return(&pool->req_ser);
42870 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42871 wake_up_process(pool->thread);
42872
42873 if (wait_event_interruptible(pool->force_wait,
42874 - atomic_read(&pool->flush_ser) - serial >= 0))
42875 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42876 return -EINTR;
42877
42878 return 0;
42879 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42880 } else {
42881 list_add_tail(&fmr->list, &pool->dirty_list);
42882 if (++pool->dirty_len >= pool->dirty_watermark) {
42883 - atomic_inc(&pool->req_ser);
42884 + atomic_inc_unchecked(&pool->req_ser);
42885 wake_up_process(pool->thread);
42886 }
42887 }
42888 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42889 index ec7a298..8742e59 100644
42890 --- a/drivers/infiniband/hw/cxgb4/mem.c
42891 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42892 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42893 int err;
42894 struct fw_ri_tpte tpt;
42895 u32 stag_idx;
42896 - static atomic_t key;
42897 + static atomic_unchecked_t key;
42898
42899 if (c4iw_fatal_error(rdev))
42900 return -EIO;
42901 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42902 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42903 rdev->stats.stag.max = rdev->stats.stag.cur;
42904 mutex_unlock(&rdev->stats.lock);
42905 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42906 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42907 }
42908 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42909 __func__, stag_state, type, pdid, stag_idx);
42910 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42911 index 79b3dbc..96e5fcc 100644
42912 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42913 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42914 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42915 struct ib_atomic_eth *ateth;
42916 struct ipath_ack_entry *e;
42917 u64 vaddr;
42918 - atomic64_t *maddr;
42919 + atomic64_unchecked_t *maddr;
42920 u64 sdata;
42921 u32 rkey;
42922 u8 next;
42923 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42924 IB_ACCESS_REMOTE_ATOMIC)))
42925 goto nack_acc_unlck;
42926 /* Perform atomic OP and save result. */
42927 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42928 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42929 sdata = be64_to_cpu(ateth->swap_data);
42930 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42931 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42932 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42933 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42934 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42935 be64_to_cpu(ateth->compare_data),
42936 sdata);
42937 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42938 index 1f95bba..9530f87 100644
42939 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42940 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42941 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42942 unsigned long flags;
42943 struct ib_wc wc;
42944 u64 sdata;
42945 - atomic64_t *maddr;
42946 + atomic64_unchecked_t *maddr;
42947 enum ib_wc_status send_status;
42948
42949 /*
42950 @@ -382,11 +382,11 @@ again:
42951 IB_ACCESS_REMOTE_ATOMIC)))
42952 goto acc_err;
42953 /* Perform atomic OP and save result. */
42954 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42955 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42956 sdata = wqe->wr.wr.atomic.compare_add;
42957 *(u64 *) sqp->s_sge.sge.vaddr =
42958 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42959 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42960 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42961 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42962 sdata, wqe->wr.wr.atomic.swap);
42963 goto send_comp;
42964 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42965 index 82a7dd8..8fb6ba6 100644
42966 --- a/drivers/infiniband/hw/mlx4/mad.c
42967 +++ b/drivers/infiniband/hw/mlx4/mad.c
42968 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42969
42970 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42971 {
42972 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42973 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42974 cpu_to_be64(0xff00000000000000LL);
42975 }
42976
42977 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42978 index ed327e6..ca1739e0 100644
42979 --- a/drivers/infiniband/hw/mlx4/mcg.c
42980 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42981 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42982 {
42983 char name[20];
42984
42985 - atomic_set(&ctx->tid, 0);
42986 + atomic_set_unchecked(&ctx->tid, 0);
42987 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42988 ctx->mcg_wq = create_singlethread_workqueue(name);
42989 if (!ctx->mcg_wq)
42990 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42991 index 6eb743f..a7b0f6d 100644
42992 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42993 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42994 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42995 struct list_head mcg_mgid0_list;
42996 struct workqueue_struct *mcg_wq;
42997 struct mlx4_ib_demux_pv_ctx **tun;
42998 - atomic_t tid;
42999 + atomic_unchecked_t tid;
43000 int flushing; /* flushing the work queue */
43001 };
43002
43003 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43004 index 9d3e5c1..6f166df 100644
43005 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43006 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43007 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43008 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43009 }
43010
43011 -int mthca_QUERY_FW(struct mthca_dev *dev)
43012 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43013 {
43014 struct mthca_mailbox *mailbox;
43015 u32 *outbox;
43016 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43017 CMD_TIME_CLASS_B);
43018 }
43019
43020 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43021 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43022 int num_mtt)
43023 {
43024 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43025 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43026 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43027 }
43028
43029 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43030 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43031 int eq_num)
43032 {
43033 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43034 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43035 CMD_TIME_CLASS_B);
43036 }
43037
43038 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43039 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43040 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43041 void *in_mad, void *response_mad)
43042 {
43043 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43044 index ded76c1..0cf0a08 100644
43045 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43046 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43047 @@ -692,7 +692,7 @@ err_close:
43048 return err;
43049 }
43050
43051 -static int mthca_setup_hca(struct mthca_dev *dev)
43052 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43053 {
43054 int err;
43055
43056 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43057 index ed9a989..6aa5dc2 100644
43058 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43059 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43060 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43061 * through the bitmaps)
43062 */
43063
43064 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43065 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43066 {
43067 int o;
43068 int m;
43069 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43070 return key;
43071 }
43072
43073 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43074 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43075 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43076 {
43077 struct mthca_mailbox *mailbox;
43078 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43079 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43080 }
43081
43082 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43083 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43084 u64 *buffer_list, int buffer_size_shift,
43085 int list_len, u64 iova, u64 total_size,
43086 u32 access, struct mthca_mr *mr)
43087 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43088 index 415f8e1..e34214e 100644
43089 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43090 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43091 @@ -764,7 +764,7 @@ unlock:
43092 return 0;
43093 }
43094
43095 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43096 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43097 {
43098 struct mthca_dev *dev = to_mdev(ibcq->device);
43099 struct mthca_cq *cq = to_mcq(ibcq);
43100 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43101 index 3b2a6dc..bce26ff 100644
43102 --- a/drivers/infiniband/hw/nes/nes.c
43103 +++ b/drivers/infiniband/hw/nes/nes.c
43104 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43105 LIST_HEAD(nes_adapter_list);
43106 static LIST_HEAD(nes_dev_list);
43107
43108 -atomic_t qps_destroyed;
43109 +atomic_unchecked_t qps_destroyed;
43110
43111 static unsigned int ee_flsh_adapter;
43112 static unsigned int sysfs_nonidx_addr;
43113 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43114 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43115 struct nes_adapter *nesadapter = nesdev->nesadapter;
43116
43117 - atomic_inc(&qps_destroyed);
43118 + atomic_inc_unchecked(&qps_destroyed);
43119
43120 /* Free the control structures */
43121
43122 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43123 index bd9d132..70d84f4 100644
43124 --- a/drivers/infiniband/hw/nes/nes.h
43125 +++ b/drivers/infiniband/hw/nes/nes.h
43126 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43127 extern unsigned int wqm_quanta;
43128 extern struct list_head nes_adapter_list;
43129
43130 -extern atomic_t cm_connects;
43131 -extern atomic_t cm_accepts;
43132 -extern atomic_t cm_disconnects;
43133 -extern atomic_t cm_closes;
43134 -extern atomic_t cm_connecteds;
43135 -extern atomic_t cm_connect_reqs;
43136 -extern atomic_t cm_rejects;
43137 -extern atomic_t mod_qp_timouts;
43138 -extern atomic_t qps_created;
43139 -extern atomic_t qps_destroyed;
43140 -extern atomic_t sw_qps_destroyed;
43141 +extern atomic_unchecked_t cm_connects;
43142 +extern atomic_unchecked_t cm_accepts;
43143 +extern atomic_unchecked_t cm_disconnects;
43144 +extern atomic_unchecked_t cm_closes;
43145 +extern atomic_unchecked_t cm_connecteds;
43146 +extern atomic_unchecked_t cm_connect_reqs;
43147 +extern atomic_unchecked_t cm_rejects;
43148 +extern atomic_unchecked_t mod_qp_timouts;
43149 +extern atomic_unchecked_t qps_created;
43150 +extern atomic_unchecked_t qps_destroyed;
43151 +extern atomic_unchecked_t sw_qps_destroyed;
43152 extern u32 mh_detected;
43153 extern u32 mh_pauses_sent;
43154 extern u32 cm_packets_sent;
43155 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43156 extern u32 cm_packets_received;
43157 extern u32 cm_packets_dropped;
43158 extern u32 cm_packets_retrans;
43159 -extern atomic_t cm_listens_created;
43160 -extern atomic_t cm_listens_destroyed;
43161 +extern atomic_unchecked_t cm_listens_created;
43162 +extern atomic_unchecked_t cm_listens_destroyed;
43163 extern u32 cm_backlog_drops;
43164 -extern atomic_t cm_loopbacks;
43165 -extern atomic_t cm_nodes_created;
43166 -extern atomic_t cm_nodes_destroyed;
43167 -extern atomic_t cm_accel_dropped_pkts;
43168 -extern atomic_t cm_resets_recvd;
43169 -extern atomic_t pau_qps_created;
43170 -extern atomic_t pau_qps_destroyed;
43171 +extern atomic_unchecked_t cm_loopbacks;
43172 +extern atomic_unchecked_t cm_nodes_created;
43173 +extern atomic_unchecked_t cm_nodes_destroyed;
43174 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43175 +extern atomic_unchecked_t cm_resets_recvd;
43176 +extern atomic_unchecked_t pau_qps_created;
43177 +extern atomic_unchecked_t pau_qps_destroyed;
43178
43179 extern u32 int_mod_timer_init;
43180 extern u32 int_mod_cq_depth_256;
43181 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43182 index 6f09a72..cf4399d 100644
43183 --- a/drivers/infiniband/hw/nes/nes_cm.c
43184 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43185 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43186 u32 cm_packets_retrans;
43187 u32 cm_packets_created;
43188 u32 cm_packets_received;
43189 -atomic_t cm_listens_created;
43190 -atomic_t cm_listens_destroyed;
43191 +atomic_unchecked_t cm_listens_created;
43192 +atomic_unchecked_t cm_listens_destroyed;
43193 u32 cm_backlog_drops;
43194 -atomic_t cm_loopbacks;
43195 -atomic_t cm_nodes_created;
43196 -atomic_t cm_nodes_destroyed;
43197 -atomic_t cm_accel_dropped_pkts;
43198 -atomic_t cm_resets_recvd;
43199 +atomic_unchecked_t cm_loopbacks;
43200 +atomic_unchecked_t cm_nodes_created;
43201 +atomic_unchecked_t cm_nodes_destroyed;
43202 +atomic_unchecked_t cm_accel_dropped_pkts;
43203 +atomic_unchecked_t cm_resets_recvd;
43204
43205 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43206 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43207 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43208 /* instance of function pointers for client API */
43209 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43210 static struct nes_cm_ops nes_cm_api = {
43211 - mini_cm_accelerated,
43212 - mini_cm_listen,
43213 - mini_cm_del_listen,
43214 - mini_cm_connect,
43215 - mini_cm_close,
43216 - mini_cm_accept,
43217 - mini_cm_reject,
43218 - mini_cm_recv_pkt,
43219 - mini_cm_dealloc_core,
43220 - mini_cm_get,
43221 - mini_cm_set
43222 + .accelerated = mini_cm_accelerated,
43223 + .listen = mini_cm_listen,
43224 + .stop_listener = mini_cm_del_listen,
43225 + .connect = mini_cm_connect,
43226 + .close = mini_cm_close,
43227 + .accept = mini_cm_accept,
43228 + .reject = mini_cm_reject,
43229 + .recv_pkt = mini_cm_recv_pkt,
43230 + .destroy_cm_core = mini_cm_dealloc_core,
43231 + .get = mini_cm_get,
43232 + .set = mini_cm_set
43233 };
43234
43235 static struct nes_cm_core *g_cm_core;
43236
43237 -atomic_t cm_connects;
43238 -atomic_t cm_accepts;
43239 -atomic_t cm_disconnects;
43240 -atomic_t cm_closes;
43241 -atomic_t cm_connecteds;
43242 -atomic_t cm_connect_reqs;
43243 -atomic_t cm_rejects;
43244 +atomic_unchecked_t cm_connects;
43245 +atomic_unchecked_t cm_accepts;
43246 +atomic_unchecked_t cm_disconnects;
43247 +atomic_unchecked_t cm_closes;
43248 +atomic_unchecked_t cm_connecteds;
43249 +atomic_unchecked_t cm_connect_reqs;
43250 +atomic_unchecked_t cm_rejects;
43251
43252 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43253 {
43254 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43255 kfree(listener);
43256 listener = NULL;
43257 ret = 0;
43258 - atomic_inc(&cm_listens_destroyed);
43259 + atomic_inc_unchecked(&cm_listens_destroyed);
43260 } else {
43261 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43262 }
43263 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43264 cm_node->rem_mac);
43265
43266 add_hte_node(cm_core, cm_node);
43267 - atomic_inc(&cm_nodes_created);
43268 + atomic_inc_unchecked(&cm_nodes_created);
43269
43270 return cm_node;
43271 }
43272 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43273 }
43274
43275 atomic_dec(&cm_core->node_cnt);
43276 - atomic_inc(&cm_nodes_destroyed);
43277 + atomic_inc_unchecked(&cm_nodes_destroyed);
43278 nesqp = cm_node->nesqp;
43279 if (nesqp) {
43280 nesqp->cm_node = NULL;
43281 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43282
43283 static void drop_packet(struct sk_buff *skb)
43284 {
43285 - atomic_inc(&cm_accel_dropped_pkts);
43286 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43287 dev_kfree_skb_any(skb);
43288 }
43289
43290 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43291 {
43292
43293 int reset = 0; /* whether to send reset in case of err.. */
43294 - atomic_inc(&cm_resets_recvd);
43295 + atomic_inc_unchecked(&cm_resets_recvd);
43296 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43297 " refcnt=%d\n", cm_node, cm_node->state,
43298 atomic_read(&cm_node->ref_count));
43299 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43300 rem_ref_cm_node(cm_node->cm_core, cm_node);
43301 return NULL;
43302 }
43303 - atomic_inc(&cm_loopbacks);
43304 + atomic_inc_unchecked(&cm_loopbacks);
43305 loopbackremotenode->loopbackpartner = cm_node;
43306 loopbackremotenode->tcp_cntxt.rcv_wscale =
43307 NES_CM_DEFAULT_RCV_WND_SCALE;
43308 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43309 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43310 else {
43311 rem_ref_cm_node(cm_core, cm_node);
43312 - atomic_inc(&cm_accel_dropped_pkts);
43313 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43314 dev_kfree_skb_any(skb);
43315 }
43316 break;
43317 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43318
43319 if ((cm_id) && (cm_id->event_handler)) {
43320 if (issue_disconn) {
43321 - atomic_inc(&cm_disconnects);
43322 + atomic_inc_unchecked(&cm_disconnects);
43323 cm_event.event = IW_CM_EVENT_DISCONNECT;
43324 cm_event.status = disconn_status;
43325 cm_event.local_addr = cm_id->local_addr;
43326 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43327 }
43328
43329 if (issue_close) {
43330 - atomic_inc(&cm_closes);
43331 + atomic_inc_unchecked(&cm_closes);
43332 nes_disconnect(nesqp, 1);
43333
43334 cm_id->provider_data = nesqp;
43335 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43336
43337 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43338 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43339 - atomic_inc(&cm_accepts);
43340 + atomic_inc_unchecked(&cm_accepts);
43341
43342 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43343 netdev_refcnt_read(nesvnic->netdev));
43344 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43345 struct nes_cm_core *cm_core;
43346 u8 *start_buff;
43347
43348 - atomic_inc(&cm_rejects);
43349 + atomic_inc_unchecked(&cm_rejects);
43350 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43351 loopback = cm_node->loopbackpartner;
43352 cm_core = cm_node->cm_core;
43353 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43354 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43355 ntohs(laddr->sin_port));
43356
43357 - atomic_inc(&cm_connects);
43358 + atomic_inc_unchecked(&cm_connects);
43359 nesqp->active_conn = 1;
43360
43361 /* cache the cm_id in the qp */
43362 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43363 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43364 return err;
43365 }
43366 - atomic_inc(&cm_listens_created);
43367 + atomic_inc_unchecked(&cm_listens_created);
43368 }
43369
43370 cm_id->add_ref(cm_id);
43371 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43372
43373 if (nesqp->destroyed)
43374 return;
43375 - atomic_inc(&cm_connecteds);
43376 + atomic_inc_unchecked(&cm_connecteds);
43377 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43378 " local port 0x%04X. jiffies = %lu.\n",
43379 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43380 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43381
43382 cm_id->add_ref(cm_id);
43383 ret = cm_id->event_handler(cm_id, &cm_event);
43384 - atomic_inc(&cm_closes);
43385 + atomic_inc_unchecked(&cm_closes);
43386 cm_event.event = IW_CM_EVENT_CLOSE;
43387 cm_event.status = 0;
43388 cm_event.provider_data = cm_id->provider_data;
43389 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43390 return;
43391 cm_id = cm_node->cm_id;
43392
43393 - atomic_inc(&cm_connect_reqs);
43394 + atomic_inc_unchecked(&cm_connect_reqs);
43395 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43396 cm_node, cm_id, jiffies);
43397
43398 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43399 return;
43400 cm_id = cm_node->cm_id;
43401
43402 - atomic_inc(&cm_connect_reqs);
43403 + atomic_inc_unchecked(&cm_connect_reqs);
43404 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43405 cm_node, cm_id, jiffies);
43406
43407 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43408 index 4166452..fc952c3 100644
43409 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43410 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43411 @@ -40,8 +40,8 @@
43412 #include "nes.h"
43413 #include "nes_mgt.h"
43414
43415 -atomic_t pau_qps_created;
43416 -atomic_t pau_qps_destroyed;
43417 +atomic_unchecked_t pau_qps_created;
43418 +atomic_unchecked_t pau_qps_destroyed;
43419
43420 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43421 {
43422 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43423 {
43424 struct sk_buff *skb;
43425 unsigned long flags;
43426 - atomic_inc(&pau_qps_destroyed);
43427 + atomic_inc_unchecked(&pau_qps_destroyed);
43428
43429 /* Free packets that have not yet been forwarded */
43430 /* Lock is acquired by skb_dequeue when removing the skb */
43431 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43432 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43433 skb_queue_head_init(&nesqp->pau_list);
43434 spin_lock_init(&nesqp->pau_lock);
43435 - atomic_inc(&pau_qps_created);
43436 + atomic_inc_unchecked(&pau_qps_created);
43437 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43438 }
43439
43440 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43441 index 49eb511..a774366 100644
43442 --- a/drivers/infiniband/hw/nes/nes_nic.c
43443 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43444 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43445 target_stat_values[++index] = mh_detected;
43446 target_stat_values[++index] = mh_pauses_sent;
43447 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43448 - target_stat_values[++index] = atomic_read(&cm_connects);
43449 - target_stat_values[++index] = atomic_read(&cm_accepts);
43450 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43451 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43452 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43453 - target_stat_values[++index] = atomic_read(&cm_rejects);
43454 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43455 - target_stat_values[++index] = atomic_read(&qps_created);
43456 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43457 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43458 - target_stat_values[++index] = atomic_read(&cm_closes);
43459 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43460 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43461 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43462 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43463 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43464 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43465 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43466 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43467 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43468 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43469 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43470 target_stat_values[++index] = cm_packets_sent;
43471 target_stat_values[++index] = cm_packets_bounced;
43472 target_stat_values[++index] = cm_packets_created;
43473 target_stat_values[++index] = cm_packets_received;
43474 target_stat_values[++index] = cm_packets_dropped;
43475 target_stat_values[++index] = cm_packets_retrans;
43476 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43477 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43478 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43479 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43480 target_stat_values[++index] = cm_backlog_drops;
43481 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43482 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43483 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43484 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43485 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43486 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43487 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43488 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43489 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43490 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43491 target_stat_values[++index] = nesadapter->free_4kpbl;
43492 target_stat_values[++index] = nesadapter->free_256pbl;
43493 target_stat_values[++index] = int_mod_timer_init;
43494 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43495 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43496 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43497 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43498 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43499 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43500 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43501 }
43502
43503 /**
43504 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43505 index fef067c..6a25ccd 100644
43506 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43507 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43508 @@ -46,9 +46,9 @@
43509
43510 #include <rdma/ib_umem.h>
43511
43512 -atomic_t mod_qp_timouts;
43513 -atomic_t qps_created;
43514 -atomic_t sw_qps_destroyed;
43515 +atomic_unchecked_t mod_qp_timouts;
43516 +atomic_unchecked_t qps_created;
43517 +atomic_unchecked_t sw_qps_destroyed;
43518
43519 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43520
43521 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43522 if (init_attr->create_flags)
43523 return ERR_PTR(-EINVAL);
43524
43525 - atomic_inc(&qps_created);
43526 + atomic_inc_unchecked(&qps_created);
43527 switch (init_attr->qp_type) {
43528 case IB_QPT_RC:
43529 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43530 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43531 struct iw_cm_event cm_event;
43532 int ret = 0;
43533
43534 - atomic_inc(&sw_qps_destroyed);
43535 + atomic_inc_unchecked(&sw_qps_destroyed);
43536 nesqp->destroyed = 1;
43537
43538 /* Blow away the connection if it exists. */
43539 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43540 index c00ae09..04e91be 100644
43541 --- a/drivers/infiniband/hw/qib/qib.h
43542 +++ b/drivers/infiniband/hw/qib/qib.h
43543 @@ -52,6 +52,7 @@
43544 #include <linux/kref.h>
43545 #include <linux/sched.h>
43546 #include <linux/kthread.h>
43547 +#include <linux/slab.h>
43548
43549 #include "qib_common.h"
43550 #include "qib_verbs.h"
43551 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43552 index cdc7df4..a2fdfdb 100644
43553 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43554 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43555 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43556 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43557 }
43558
43559 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43560 +static struct rtnl_link_ops ipoib_link_ops = {
43561 .kind = "ipoib",
43562 .maxtype = IFLA_IPOIB_MAX,
43563 .policy = ipoib_policy,
43564 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43565 index e29c04e..adbf68c 100644
43566 --- a/drivers/input/gameport/gameport.c
43567 +++ b/drivers/input/gameport/gameport.c
43568 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43569 */
43570 static void gameport_init_port(struct gameport *gameport)
43571 {
43572 - static atomic_t gameport_no = ATOMIC_INIT(0);
43573 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43574
43575 __module_get(THIS_MODULE);
43576
43577 mutex_init(&gameport->drv_mutex);
43578 device_initialize(&gameport->dev);
43579 dev_set_name(&gameport->dev, "gameport%lu",
43580 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43581 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43582 gameport->dev.bus = &gameport_bus;
43583 gameport->dev.release = gameport_release_port;
43584 if (gameport->parent)
43585 diff --git a/drivers/input/input.c b/drivers/input/input.c
43586 index 0f175f5..4c481c0 100644
43587 --- a/drivers/input/input.c
43588 +++ b/drivers/input/input.c
43589 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43590 */
43591 struct input_dev *input_allocate_device(void)
43592 {
43593 - static atomic_t input_no = ATOMIC_INIT(0);
43594 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43595 struct input_dev *dev;
43596
43597 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43598 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43599 INIT_LIST_HEAD(&dev->node);
43600
43601 dev_set_name(&dev->dev, "input%lu",
43602 - (unsigned long) atomic_inc_return(&input_no) - 1);
43603 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43604
43605 __module_get(THIS_MODULE);
43606 }
43607 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43608 index 4a95b22..874c182 100644
43609 --- a/drivers/input/joystick/sidewinder.c
43610 +++ b/drivers/input/joystick/sidewinder.c
43611 @@ -30,6 +30,7 @@
43612 #include <linux/kernel.h>
43613 #include <linux/module.h>
43614 #include <linux/slab.h>
43615 +#include <linux/sched.h>
43616 #include <linux/input.h>
43617 #include <linux/gameport.h>
43618 #include <linux/jiffies.h>
43619 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43620 index fc55f0d..11e2aa6 100644
43621 --- a/drivers/input/joystick/xpad.c
43622 +++ b/drivers/input/joystick/xpad.c
43623 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43624
43625 static int xpad_led_probe(struct usb_xpad *xpad)
43626 {
43627 - static atomic_t led_seq = ATOMIC_INIT(0);
43628 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43629 long led_no;
43630 struct xpad_led *led;
43631 struct led_classdev *led_cdev;
43632 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43633 if (!led)
43634 return -ENOMEM;
43635
43636 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43637 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43638
43639 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43640 led->xpad = xpad;
43641 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43642 index afed8e2..3aa8a18 100644
43643 --- a/drivers/input/misc/ims-pcu.c
43644 +++ b/drivers/input/misc/ims-pcu.c
43645 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43646
43647 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43648 {
43649 - static atomic_t device_no = ATOMIC_INIT(0);
43650 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43651
43652 const struct ims_pcu_device_info *info;
43653 int error;
43654 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43655 }
43656
43657 /* Device appears to be operable, complete initialization */
43658 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43659 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43660
43661 /*
43662 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43663 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43664 index f4cf664..3204fda 100644
43665 --- a/drivers/input/mouse/psmouse.h
43666 +++ b/drivers/input/mouse/psmouse.h
43667 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43668 ssize_t (*set)(struct psmouse *psmouse, void *data,
43669 const char *buf, size_t count);
43670 bool protect;
43671 -};
43672 +} __do_const;
43673 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43674
43675 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43676 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43677 index b604564..3f14ae4 100644
43678 --- a/drivers/input/mousedev.c
43679 +++ b/drivers/input/mousedev.c
43680 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43681
43682 spin_unlock_irq(&client->packet_lock);
43683
43684 - if (copy_to_user(buffer, data, count))
43685 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43686 return -EFAULT;
43687
43688 return count;
43689 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43690 index d399b8b..4913ede 100644
43691 --- a/drivers/input/serio/serio.c
43692 +++ b/drivers/input/serio/serio.c
43693 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43694 */
43695 static void serio_init_port(struct serio *serio)
43696 {
43697 - static atomic_t serio_no = ATOMIC_INIT(0);
43698 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43699
43700 __module_get(THIS_MODULE);
43701
43702 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43703 mutex_init(&serio->drv_mutex);
43704 device_initialize(&serio->dev);
43705 dev_set_name(&serio->dev, "serio%lu",
43706 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43707 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43708 serio->dev.bus = &serio_bus;
43709 serio->dev.release = serio_release_port;
43710 serio->dev.groups = serio_device_attr_groups;
43711 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43712 index c9a02fe..0debc75 100644
43713 --- a/drivers/input/serio/serio_raw.c
43714 +++ b/drivers/input/serio/serio_raw.c
43715 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43716
43717 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43718 {
43719 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43720 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43721 struct serio_raw *serio_raw;
43722 int err;
43723
43724 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43725 }
43726
43727 snprintf(serio_raw->name, sizeof(serio_raw->name),
43728 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43729 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43730 kref_init(&serio_raw->kref);
43731 INIT_LIST_HEAD(&serio_raw->client_list);
43732 init_waitqueue_head(&serio_raw->wait);
43733 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43734 index 505a9ad..356734c 100644
43735 --- a/drivers/iommu/amd_iommu.c
43736 +++ b/drivers/iommu/amd_iommu.c
43737 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43738
43739 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43740 {
43741 + phys_addr_t physaddr;
43742 WARN_ON(address & 0x7ULL);
43743
43744 memset(cmd, 0, sizeof(*cmd));
43745 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43746 - cmd->data[1] = upper_32_bits(__pa(address));
43747 +
43748 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43749 + if (object_starts_on_stack((void *)address)) {
43750 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43751 + physaddr = __pa((u64)adjbuf);
43752 + } else
43753 +#endif
43754 + physaddr = __pa(address);
43755 +
43756 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43757 + cmd->data[1] = upper_32_bits(physaddr);
43758 cmd->data[2] = 1;
43759 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43760 }
43761 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43762 index 60558f7..5a02369 100644
43763 --- a/drivers/iommu/arm-smmu.c
43764 +++ b/drivers/iommu/arm-smmu.c
43765 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43766 cfg->irptndx = cfg->cbndx;
43767 }
43768
43769 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43770 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43771 arm_smmu_init_context_bank(smmu_domain);
43772 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43773
43774 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43775 index ed8b048..7fbcc01 100644
43776 --- a/drivers/iommu/iommu.c
43777 +++ b/drivers/iommu/iommu.c
43778 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43779 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43780 {
43781 int err;
43782 - struct notifier_block *nb;
43783 + notifier_block_no_const *nb;
43784 struct iommu_callback_data cb = {
43785 .ops = ops,
43786 };
43787 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43788 index 74a1767..5a359e8 100644
43789 --- a/drivers/iommu/irq_remapping.c
43790 +++ b/drivers/iommu/irq_remapping.c
43791 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43792 void panic_if_irq_remap(const char *msg)
43793 {
43794 if (irq_remapping_enabled)
43795 - panic(msg);
43796 + panic("%s", msg);
43797 }
43798
43799 static void ir_ack_apic_edge(struct irq_data *data)
43800 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43801
43802 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43803 {
43804 - chip->irq_print_chip = ir_print_prefix;
43805 - chip->irq_ack = ir_ack_apic_edge;
43806 - chip->irq_eoi = ir_ack_apic_level;
43807 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43808 + pax_open_kernel();
43809 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43810 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43811 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43812 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43813 + pax_close_kernel();
43814 }
43815
43816 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43817 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43818 index 38493ff..001538b 100644
43819 --- a/drivers/irqchip/irq-gic.c
43820 +++ b/drivers/irqchip/irq-gic.c
43821 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43822 * Supported arch specific GIC irq extension.
43823 * Default make them NULL.
43824 */
43825 -struct irq_chip gic_arch_extn = {
43826 +irq_chip_no_const gic_arch_extn = {
43827 .irq_eoi = NULL,
43828 .irq_mask = NULL,
43829 .irq_unmask = NULL,
43830 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43831 chained_irq_exit(chip, desc);
43832 }
43833
43834 -static struct irq_chip gic_chip = {
43835 +static irq_chip_no_const gic_chip __read_only = {
43836 .name = "GIC",
43837 .irq_mask = gic_mask_irq,
43838 .irq_unmask = gic_unmask_irq,
43839 diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43840 index 542e850..1bb094c 100644
43841 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43842 +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43843 @@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43844 struct intc_irqpin_iomem *i;
43845 struct resource *io[INTC_IRQPIN_REG_NR];
43846 struct resource *irq;
43847 - struct irq_chip *irq_chip;
43848 + irq_chip_no_const *irq_chip;
43849 void (*enable_fn)(struct irq_data *d);
43850 void (*disable_fn)(struct irq_data *d);
43851 const char *name = dev_name(dev);
43852 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43853 index 8777065..a4a9967 100644
43854 --- a/drivers/irqchip/irq-renesas-irqc.c
43855 +++ b/drivers/irqchip/irq-renesas-irqc.c
43856 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43857 struct irqc_priv *p;
43858 struct resource *io;
43859 struct resource *irq;
43860 - struct irq_chip *irq_chip;
43861 + irq_chip_no_const *irq_chip;
43862 const char *name = dev_name(&pdev->dev);
43863 int ret;
43864 int k;
43865 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43866 index 6a2df32..dc962f1 100644
43867 --- a/drivers/isdn/capi/capi.c
43868 +++ b/drivers/isdn/capi/capi.c
43869 @@ -81,8 +81,8 @@ struct capiminor {
43870
43871 struct capi20_appl *ap;
43872 u32 ncci;
43873 - atomic_t datahandle;
43874 - atomic_t msgid;
43875 + atomic_unchecked_t datahandle;
43876 + atomic_unchecked_t msgid;
43877
43878 struct tty_port port;
43879 int ttyinstop;
43880 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43881 capimsg_setu16(s, 2, mp->ap->applid);
43882 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43883 capimsg_setu8 (s, 5, CAPI_RESP);
43884 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43885 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43886 capimsg_setu32(s, 8, mp->ncci);
43887 capimsg_setu16(s, 12, datahandle);
43888 }
43889 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43890 mp->outbytes -= len;
43891 spin_unlock_bh(&mp->outlock);
43892
43893 - datahandle = atomic_inc_return(&mp->datahandle);
43894 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43895 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43896 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43897 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43898 capimsg_setu16(skb->data, 2, mp->ap->applid);
43899 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43900 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43901 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43902 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43903 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43904 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43905 capimsg_setu16(skb->data, 16, len); /* Data length */
43906 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43907 index aecec6d..11e13c5 100644
43908 --- a/drivers/isdn/gigaset/bas-gigaset.c
43909 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43910 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43911
43912
43913 static const struct gigaset_ops gigops = {
43914 - gigaset_write_cmd,
43915 - gigaset_write_room,
43916 - gigaset_chars_in_buffer,
43917 - gigaset_brkchars,
43918 - gigaset_init_bchannel,
43919 - gigaset_close_bchannel,
43920 - gigaset_initbcshw,
43921 - gigaset_freebcshw,
43922 - gigaset_reinitbcshw,
43923 - gigaset_initcshw,
43924 - gigaset_freecshw,
43925 - gigaset_set_modem_ctrl,
43926 - gigaset_baud_rate,
43927 - gigaset_set_line_ctrl,
43928 - gigaset_isoc_send_skb,
43929 - gigaset_isoc_input,
43930 + .write_cmd = gigaset_write_cmd,
43931 + .write_room = gigaset_write_room,
43932 + .chars_in_buffer = gigaset_chars_in_buffer,
43933 + .brkchars = gigaset_brkchars,
43934 + .init_bchannel = gigaset_init_bchannel,
43935 + .close_bchannel = gigaset_close_bchannel,
43936 + .initbcshw = gigaset_initbcshw,
43937 + .freebcshw = gigaset_freebcshw,
43938 + .reinitbcshw = gigaset_reinitbcshw,
43939 + .initcshw = gigaset_initcshw,
43940 + .freecshw = gigaset_freecshw,
43941 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43942 + .baud_rate = gigaset_baud_rate,
43943 + .set_line_ctrl = gigaset_set_line_ctrl,
43944 + .send_skb = gigaset_isoc_send_skb,
43945 + .handle_input = gigaset_isoc_input,
43946 };
43947
43948 /* bas_gigaset_init
43949 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43950 index 600c79b..3752bab 100644
43951 --- a/drivers/isdn/gigaset/interface.c
43952 +++ b/drivers/isdn/gigaset/interface.c
43953 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43954 }
43955 tty->driver_data = cs;
43956
43957 - ++cs->port.count;
43958 + atomic_inc(&cs->port.count);
43959
43960 - if (cs->port.count == 1) {
43961 + if (atomic_read(&cs->port.count) == 1) {
43962 tty_port_tty_set(&cs->port, tty);
43963 cs->port.low_latency = 1;
43964 }
43965 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43966
43967 if (!cs->connected)
43968 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43969 - else if (!cs->port.count)
43970 + else if (!atomic_read(&cs->port.count))
43971 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43972 - else if (!--cs->port.count)
43973 + else if (!atomic_dec_return(&cs->port.count))
43974 tty_port_tty_set(&cs->port, NULL);
43975
43976 mutex_unlock(&cs->mutex);
43977 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43978 index 8c91fd5..14f13ce 100644
43979 --- a/drivers/isdn/gigaset/ser-gigaset.c
43980 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43981 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43982 }
43983
43984 static const struct gigaset_ops ops = {
43985 - gigaset_write_cmd,
43986 - gigaset_write_room,
43987 - gigaset_chars_in_buffer,
43988 - gigaset_brkchars,
43989 - gigaset_init_bchannel,
43990 - gigaset_close_bchannel,
43991 - gigaset_initbcshw,
43992 - gigaset_freebcshw,
43993 - gigaset_reinitbcshw,
43994 - gigaset_initcshw,
43995 - gigaset_freecshw,
43996 - gigaset_set_modem_ctrl,
43997 - gigaset_baud_rate,
43998 - gigaset_set_line_ctrl,
43999 - gigaset_m10x_send_skb, /* asyncdata.c */
44000 - gigaset_m10x_input, /* asyncdata.c */
44001 + .write_cmd = gigaset_write_cmd,
44002 + .write_room = gigaset_write_room,
44003 + .chars_in_buffer = gigaset_chars_in_buffer,
44004 + .brkchars = gigaset_brkchars,
44005 + .init_bchannel = gigaset_init_bchannel,
44006 + .close_bchannel = gigaset_close_bchannel,
44007 + .initbcshw = gigaset_initbcshw,
44008 + .freebcshw = gigaset_freebcshw,
44009 + .reinitbcshw = gigaset_reinitbcshw,
44010 + .initcshw = gigaset_initcshw,
44011 + .freecshw = gigaset_freecshw,
44012 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44013 + .baud_rate = gigaset_baud_rate,
44014 + .set_line_ctrl = gigaset_set_line_ctrl,
44015 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44016 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44017 };
44018
44019
44020 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44021 index a8e652d..edadaa4 100644
44022 --- a/drivers/isdn/gigaset/usb-gigaset.c
44023 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44024 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44025 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44026 memcpy(cs->hw.usb->bchars, buf, 6);
44027 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44028 - 0, 0, &buf, 6, 2000);
44029 + 0, 0, buf, 6, 2000);
44030 }
44031
44032 static void gigaset_freebcshw(struct bc_state *bcs)
44033 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44034 }
44035
44036 static const struct gigaset_ops ops = {
44037 - gigaset_write_cmd,
44038 - gigaset_write_room,
44039 - gigaset_chars_in_buffer,
44040 - gigaset_brkchars,
44041 - gigaset_init_bchannel,
44042 - gigaset_close_bchannel,
44043 - gigaset_initbcshw,
44044 - gigaset_freebcshw,
44045 - gigaset_reinitbcshw,
44046 - gigaset_initcshw,
44047 - gigaset_freecshw,
44048 - gigaset_set_modem_ctrl,
44049 - gigaset_baud_rate,
44050 - gigaset_set_line_ctrl,
44051 - gigaset_m10x_send_skb,
44052 - gigaset_m10x_input,
44053 + .write_cmd = gigaset_write_cmd,
44054 + .write_room = gigaset_write_room,
44055 + .chars_in_buffer = gigaset_chars_in_buffer,
44056 + .brkchars = gigaset_brkchars,
44057 + .init_bchannel = gigaset_init_bchannel,
44058 + .close_bchannel = gigaset_close_bchannel,
44059 + .initbcshw = gigaset_initbcshw,
44060 + .freebcshw = gigaset_freebcshw,
44061 + .reinitbcshw = gigaset_reinitbcshw,
44062 + .initcshw = gigaset_initcshw,
44063 + .freecshw = gigaset_freecshw,
44064 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44065 + .baud_rate = gigaset_baud_rate,
44066 + .set_line_ctrl = gigaset_set_line_ctrl,
44067 + .send_skb = gigaset_m10x_send_skb,
44068 + .handle_input = gigaset_m10x_input,
44069 };
44070
44071 /*
44072 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44073 index 4d9b195..455075c 100644
44074 --- a/drivers/isdn/hardware/avm/b1.c
44075 +++ b/drivers/isdn/hardware/avm/b1.c
44076 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44077 }
44078 if (left) {
44079 if (t4file->user) {
44080 - if (copy_from_user(buf, dp, left))
44081 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44082 return -EFAULT;
44083 } else {
44084 memcpy(buf, dp, left);
44085 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44086 }
44087 if (left) {
44088 if (config->user) {
44089 - if (copy_from_user(buf, dp, left))
44090 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44091 return -EFAULT;
44092 } else {
44093 memcpy(buf, dp, left);
44094 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
44095 index a82e542..f766a79 100644
44096 --- a/drivers/isdn/hardware/eicon/message.c
44097 +++ b/drivers/isdn/hardware/eicon/message.c
44098 @@ -1474,7 +1474,7 @@ static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
44099 add_ai(plci, &parms[5]);
44100 sig_req(plci, REJECT, 0);
44101 }
44102 - else if (Reject == 1 || Reject > 9)
44103 + else if (Reject == 1 || Reject >= 9)
44104 {
44105 add_ai(plci, &parms[5]);
44106 sig_req(plci, HANGUP, 0);
44107 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44108 index 9b856e1..fa03c92 100644
44109 --- a/drivers/isdn/i4l/isdn_common.c
44110 +++ b/drivers/isdn/i4l/isdn_common.c
44111 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44112 } else
44113 return -EINVAL;
44114 case IIOCDBGVAR:
44115 + if (!capable(CAP_SYS_RAWIO))
44116 + return -EPERM;
44117 if (arg) {
44118 if (copy_to_user(argp, &dev, sizeof(ulong)))
44119 return -EFAULT;
44120 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44121 index 91d5730..336523e 100644
44122 --- a/drivers/isdn/i4l/isdn_concap.c
44123 +++ b/drivers/isdn/i4l/isdn_concap.c
44124 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44125 }
44126
44127 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44128 - &isdn_concap_dl_data_req,
44129 - &isdn_concap_dl_connect_req,
44130 - &isdn_concap_dl_disconn_req
44131 + .data_req = &isdn_concap_dl_data_req,
44132 + .connect_req = &isdn_concap_dl_connect_req,
44133 + .disconn_req = &isdn_concap_dl_disconn_req
44134 };
44135
44136 /* The following should better go into a dedicated source file such that
44137 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44138 index bc91261..2ef7e36 100644
44139 --- a/drivers/isdn/i4l/isdn_tty.c
44140 +++ b/drivers/isdn/i4l/isdn_tty.c
44141 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44142
44143 #ifdef ISDN_DEBUG_MODEM_OPEN
44144 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44145 - port->count);
44146 + atomic_read(&port->count));
44147 #endif
44148 - port->count++;
44149 + atomic_inc(&port->count);
44150 port->tty = tty;
44151 /*
44152 * Start up serial port
44153 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44154 #endif
44155 return;
44156 }
44157 - if ((tty->count == 1) && (port->count != 1)) {
44158 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44159 /*
44160 * Uh, oh. tty->count is 1, which means that the tty
44161 * structure will be freed. Info->count should always
44162 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44163 * serial port won't be shutdown.
44164 */
44165 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44166 - "info->count is %d\n", port->count);
44167 - port->count = 1;
44168 + "info->count is %d\n", atomic_read(&port->count));
44169 + atomic_set(&port->count, 1);
44170 }
44171 - if (--port->count < 0) {
44172 + if (atomic_dec_return(&port->count) < 0) {
44173 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44174 - info->line, port->count);
44175 - port->count = 0;
44176 + info->line, atomic_read(&port->count));
44177 + atomic_set(&port->count, 0);
44178 }
44179 - if (port->count) {
44180 + if (atomic_read(&port->count)) {
44181 #ifdef ISDN_DEBUG_MODEM_OPEN
44182 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44183 #endif
44184 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44185 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44186 return;
44187 isdn_tty_shutdown(info);
44188 - port->count = 0;
44189 + atomic_set(&port->count, 0);
44190 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44191 port->tty = NULL;
44192 wake_up_interruptible(&port->open_wait);
44193 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44194 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44195 modem_info *info = &dev->mdm.info[i];
44196
44197 - if (info->port.count == 0)
44198 + if (atomic_read(&info->port.count) == 0)
44199 continue;
44200 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44201 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44202 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44203 index e2d4e58..40cd045 100644
44204 --- a/drivers/isdn/i4l/isdn_x25iface.c
44205 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44206 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44207
44208
44209 static struct concap_proto_ops ix25_pops = {
44210 - &isdn_x25iface_proto_new,
44211 - &isdn_x25iface_proto_del,
44212 - &isdn_x25iface_proto_restart,
44213 - &isdn_x25iface_proto_close,
44214 - &isdn_x25iface_xmit,
44215 - &isdn_x25iface_receive,
44216 - &isdn_x25iface_connect_ind,
44217 - &isdn_x25iface_disconn_ind
44218 + .proto_new = &isdn_x25iface_proto_new,
44219 + .proto_del = &isdn_x25iface_proto_del,
44220 + .restart = &isdn_x25iface_proto_restart,
44221 + .close = &isdn_x25iface_proto_close,
44222 + .encap_and_xmit = &isdn_x25iface_xmit,
44223 + .data_ind = &isdn_x25iface_receive,
44224 + .connect_ind = &isdn_x25iface_connect_ind,
44225 + .disconn_ind = &isdn_x25iface_disconn_ind
44226 };
44227
44228 /* error message helper function */
44229 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44230 index 6a7447c..cae33fe 100644
44231 --- a/drivers/isdn/icn/icn.c
44232 +++ b/drivers/isdn/icn/icn.c
44233 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44234 if (count > len)
44235 count = len;
44236 if (user) {
44237 - if (copy_from_user(msg, buf, count))
44238 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44239 return -EFAULT;
44240 } else
44241 memcpy(msg, buf, count);
44242 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44243 index 87f7dff..7300125 100644
44244 --- a/drivers/isdn/mISDN/dsp_cmx.c
44245 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44246 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44247 static u16 dsp_count; /* last sample count */
44248 static int dsp_count_valid; /* if we have last sample count */
44249
44250 -void
44251 +void __intentional_overflow(-1)
44252 dsp_cmx_send(void *arg)
44253 {
44254 struct dsp_conf *conf;
44255 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44256 index f58a354..fbae176 100644
44257 --- a/drivers/leds/leds-clevo-mail.c
44258 +++ b/drivers/leds/leds-clevo-mail.c
44259 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44260 * detected as working, but in reality it is not) as low as
44261 * possible.
44262 */
44263 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44264 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44265 {
44266 .callback = clevo_mail_led_dmi_callback,
44267 .ident = "Clevo D410J",
44268 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44269 index 046cb70..6b20d39 100644
44270 --- a/drivers/leds/leds-ss4200.c
44271 +++ b/drivers/leds/leds-ss4200.c
44272 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44273 * detected as working, but in reality it is not) as low as
44274 * possible.
44275 */
44276 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44277 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44278 {
44279 .callback = ss4200_led_dmi_callback,
44280 .ident = "Intel SS4200-E",
44281 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44282 index 6590558..a74c5dd 100644
44283 --- a/drivers/lguest/core.c
44284 +++ b/drivers/lguest/core.c
44285 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44286 * The end address needs +1 because __get_vm_area allocates an
44287 * extra guard page, so we need space for that.
44288 */
44289 +
44290 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44291 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44292 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44293 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44294 +#else
44295 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44296 VM_ALLOC, switcher_addr, switcher_addr
44297 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44298 +#endif
44299 +
44300 if (!switcher_vma) {
44301 err = -ENOMEM;
44302 printk("lguest: could not map switcher pages high\n");
44303 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44304 * Now the Switcher is mapped at the right address, we can't fail!
44305 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44306 */
44307 - memcpy(switcher_vma->addr, start_switcher_text,
44308 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44309 end_switcher_text - start_switcher_text);
44310
44311 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44312 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44313 index e8b55c3..3514c37 100644
44314 --- a/drivers/lguest/page_tables.c
44315 +++ b/drivers/lguest/page_tables.c
44316 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44317 /*:*/
44318
44319 #ifdef CONFIG_X86_PAE
44320 -static void release_pmd(pmd_t *spmd)
44321 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44322 {
44323 /* If the entry's not present, there's nothing to release. */
44324 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44325 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44326 index 922a1ac..9dd0c2a 100644
44327 --- a/drivers/lguest/x86/core.c
44328 +++ b/drivers/lguest/x86/core.c
44329 @@ -59,7 +59,7 @@ static struct {
44330 /* Offset from where switcher.S was compiled to where we've copied it */
44331 static unsigned long switcher_offset(void)
44332 {
44333 - return switcher_addr - (unsigned long)start_switcher_text;
44334 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44335 }
44336
44337 /* This cpu's struct lguest_pages (after the Switcher text page) */
44338 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44339 * These copies are pretty cheap, so we do them unconditionally: */
44340 /* Save the current Host top-level page directory.
44341 */
44342 +
44343 +#ifdef CONFIG_PAX_PER_CPU_PGD
44344 + pages->state.host_cr3 = read_cr3();
44345 +#else
44346 pages->state.host_cr3 = __pa(current->mm->pgd);
44347 +#endif
44348 +
44349 /*
44350 * Set up the Guest's page tables to see this CPU's pages (and no
44351 * other CPU's pages).
44352 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44353 * compiled-in switcher code and the high-mapped copy we just made.
44354 */
44355 for (i = 0; i < IDT_ENTRIES; i++)
44356 - default_idt_entries[i] += switcher_offset();
44357 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44358
44359 /*
44360 * Set up the Switcher's per-cpu areas.
44361 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44362 * it will be undisturbed when we switch. To change %cs and jump we
44363 * need this structure to feed to Intel's "lcall" instruction.
44364 */
44365 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44366 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44367 lguest_entry.segment = LGUEST_CS;
44368
44369 /*
44370 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44371 index 40634b0..4f5855e 100644
44372 --- a/drivers/lguest/x86/switcher_32.S
44373 +++ b/drivers/lguest/x86/switcher_32.S
44374 @@ -87,6 +87,7 @@
44375 #include <asm/page.h>
44376 #include <asm/segment.h>
44377 #include <asm/lguest.h>
44378 +#include <asm/processor-flags.h>
44379
44380 // We mark the start of the code to copy
44381 // It's placed in .text tho it's never run here
44382 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44383 // Changes type when we load it: damn Intel!
44384 // For after we switch over our page tables
44385 // That entry will be read-only: we'd crash.
44386 +
44387 +#ifdef CONFIG_PAX_KERNEXEC
44388 + mov %cr0, %edx
44389 + xor $X86_CR0_WP, %edx
44390 + mov %edx, %cr0
44391 +#endif
44392 +
44393 movl $(GDT_ENTRY_TSS*8), %edx
44394 ltr %dx
44395
44396 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44397 // Let's clear it again for our return.
44398 // The GDT descriptor of the Host
44399 // Points to the table after two "size" bytes
44400 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44401 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44402 // Clear "used" from type field (byte 5, bit 2)
44403 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44404 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44405 +
44406 +#ifdef CONFIG_PAX_KERNEXEC
44407 + mov %cr0, %eax
44408 + xor $X86_CR0_WP, %eax
44409 + mov %eax, %cr0
44410 +#endif
44411
44412 // Once our page table's switched, the Guest is live!
44413 // The Host fades as we run this final step.
44414 @@ -295,13 +309,12 @@ deliver_to_host:
44415 // I consulted gcc, and it gave
44416 // These instructions, which I gladly credit:
44417 leal (%edx,%ebx,8), %eax
44418 - movzwl (%eax),%edx
44419 - movl 4(%eax), %eax
44420 - xorw %ax, %ax
44421 - orl %eax, %edx
44422 + movl 4(%eax), %edx
44423 + movw (%eax), %dx
44424 // Now the address of the handler's in %edx
44425 // We call it now: its "iret" drops us home.
44426 - jmp *%edx
44427 + ljmp $__KERNEL_CS, $1f
44428 +1: jmp *%edx
44429
44430 // Every interrupt can come to us here
44431 // But we must truly tell each apart.
44432 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44433 index a08e3ee..df8ade2 100644
44434 --- a/drivers/md/bcache/closure.h
44435 +++ b/drivers/md/bcache/closure.h
44436 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44437 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44438 struct workqueue_struct *wq)
44439 {
44440 - BUG_ON(object_is_on_stack(cl));
44441 + BUG_ON(object_starts_on_stack(cl));
44442 closure_set_ip(cl);
44443 cl->fn = fn;
44444 cl->wq = wq;
44445 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44446 index da3604e..7789cb4c 100644
44447 --- a/drivers/md/bitmap.c
44448 +++ b/drivers/md/bitmap.c
44449 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44450 chunk_kb ? "KB" : "B");
44451 if (bitmap->storage.file) {
44452 seq_printf(seq, ", file: ");
44453 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44454 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44455 }
44456
44457 seq_printf(seq, "\n");
44458 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44459 index 0be9381..114262b 100644
44460 --- a/drivers/md/dm-ioctl.c
44461 +++ b/drivers/md/dm-ioctl.c
44462 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44463 cmd == DM_LIST_VERSIONS_CMD)
44464 return 0;
44465
44466 - if ((cmd == DM_DEV_CREATE_CMD)) {
44467 + if (cmd == DM_DEV_CREATE_CMD) {
44468 if (!*param->name) {
44469 DMWARN("name not supplied when creating device");
44470 return -EINVAL;
44471 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44472 index 7dfdb5c..4caada6 100644
44473 --- a/drivers/md/dm-raid1.c
44474 +++ b/drivers/md/dm-raid1.c
44475 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44476
44477 struct mirror {
44478 struct mirror_set *ms;
44479 - atomic_t error_count;
44480 + atomic_unchecked_t error_count;
44481 unsigned long error_type;
44482 struct dm_dev *dev;
44483 sector_t offset;
44484 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44485 struct mirror *m;
44486
44487 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44488 - if (!atomic_read(&m->error_count))
44489 + if (!atomic_read_unchecked(&m->error_count))
44490 return m;
44491
44492 return NULL;
44493 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44494 * simple way to tell if a device has encountered
44495 * errors.
44496 */
44497 - atomic_inc(&m->error_count);
44498 + atomic_inc_unchecked(&m->error_count);
44499
44500 if (test_and_set_bit(error_type, &m->error_type))
44501 return;
44502 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44503 struct mirror *m = get_default_mirror(ms);
44504
44505 do {
44506 - if (likely(!atomic_read(&m->error_count)))
44507 + if (likely(!atomic_read_unchecked(&m->error_count)))
44508 return m;
44509
44510 if (m-- == ms->mirror)
44511 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44512 {
44513 struct mirror *default_mirror = get_default_mirror(m->ms);
44514
44515 - return !atomic_read(&default_mirror->error_count);
44516 + return !atomic_read_unchecked(&default_mirror->error_count);
44517 }
44518
44519 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44520 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44521 */
44522 if (likely(region_in_sync(ms, region, 1)))
44523 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44524 - else if (m && atomic_read(&m->error_count))
44525 + else if (m && atomic_read_unchecked(&m->error_count))
44526 m = NULL;
44527
44528 if (likely(m))
44529 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44530 }
44531
44532 ms->mirror[mirror].ms = ms;
44533 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44534 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44535 ms->mirror[mirror].error_type = 0;
44536 ms->mirror[mirror].offset = offset;
44537
44538 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44539 */
44540 static char device_status_char(struct mirror *m)
44541 {
44542 - if (!atomic_read(&(m->error_count)))
44543 + if (!atomic_read_unchecked(&(m->error_count)))
44544 return 'A';
44545
44546 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44547 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44548 index 87f86c7..a1a4100 100644
44549 --- a/drivers/md/dm-stats.c
44550 +++ b/drivers/md/dm-stats.c
44551 @@ -382,7 +382,7 @@ do_sync_free:
44552 synchronize_rcu_expedited();
44553 dm_stat_free(&s->rcu_head);
44554 } else {
44555 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44556 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44557 call_rcu(&s->rcu_head, dm_stat_free);
44558 }
44559 return 0;
44560 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44561 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44562 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44563 ));
44564 - ACCESS_ONCE(last->last_sector) = end_sector;
44565 - ACCESS_ONCE(last->last_rw) = bi_rw;
44566 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44567 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44568 }
44569
44570 rcu_read_lock();
44571 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44572 index f8b37d4..5c5cafd 100644
44573 --- a/drivers/md/dm-stripe.c
44574 +++ b/drivers/md/dm-stripe.c
44575 @@ -21,7 +21,7 @@ struct stripe {
44576 struct dm_dev *dev;
44577 sector_t physical_start;
44578
44579 - atomic_t error_count;
44580 + atomic_unchecked_t error_count;
44581 };
44582
44583 struct stripe_c {
44584 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44585 kfree(sc);
44586 return r;
44587 }
44588 - atomic_set(&(sc->stripe[i].error_count), 0);
44589 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44590 }
44591
44592 ti->private = sc;
44593 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44594 DMEMIT("%d ", sc->stripes);
44595 for (i = 0; i < sc->stripes; i++) {
44596 DMEMIT("%s ", sc->stripe[i].dev->name);
44597 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44598 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44599 'D' : 'A';
44600 }
44601 buffer[i] = '\0';
44602 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44603 */
44604 for (i = 0; i < sc->stripes; i++)
44605 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44606 - atomic_inc(&(sc->stripe[i].error_count));
44607 - if (atomic_read(&(sc->stripe[i].error_count)) <
44608 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44609 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44610 DM_IO_ERROR_THRESHOLD)
44611 schedule_work(&sc->trigger_event);
44612 }
44613 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44614 index b2bd1eb..38f7a44 100644
44615 --- a/drivers/md/dm-table.c
44616 +++ b/drivers/md/dm-table.c
44617 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44618 if (!dev_size)
44619 return 0;
44620
44621 - if ((start >= dev_size) || (start + len > dev_size)) {
44622 + if ((start >= dev_size) || (len > dev_size - start)) {
44623 DMWARN("%s: %s too small for target: "
44624 "start=%llu, len=%llu, dev_size=%llu",
44625 dm_device_name(ti->table->md), bdevname(bdev, b),
44626 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44627 index e9d33ad..dae9880d 100644
44628 --- a/drivers/md/dm-thin-metadata.c
44629 +++ b/drivers/md/dm-thin-metadata.c
44630 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44631 {
44632 pmd->info.tm = pmd->tm;
44633 pmd->info.levels = 2;
44634 - pmd->info.value_type.context = pmd->data_sm;
44635 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44636 pmd->info.value_type.size = sizeof(__le64);
44637 pmd->info.value_type.inc = data_block_inc;
44638 pmd->info.value_type.dec = data_block_dec;
44639 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44640
44641 pmd->bl_info.tm = pmd->tm;
44642 pmd->bl_info.levels = 1;
44643 - pmd->bl_info.value_type.context = pmd->data_sm;
44644 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44645 pmd->bl_info.value_type.size = sizeof(__le64);
44646 pmd->bl_info.value_type.inc = data_block_inc;
44647 pmd->bl_info.value_type.dec = data_block_dec;
44648 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44649 index 62c5136..aede7f1 100644
44650 --- a/drivers/md/dm.c
44651 +++ b/drivers/md/dm.c
44652 @@ -183,9 +183,9 @@ struct mapped_device {
44653 /*
44654 * Event handling.
44655 */
44656 - atomic_t event_nr;
44657 + atomic_unchecked_t event_nr;
44658 wait_queue_head_t eventq;
44659 - atomic_t uevent_seq;
44660 + atomic_unchecked_t uevent_seq;
44661 struct list_head uevent_list;
44662 spinlock_t uevent_lock; /* Protect access to uevent_list */
44663
44664 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44665 spin_lock_init(&md->deferred_lock);
44666 atomic_set(&md->holders, 1);
44667 atomic_set(&md->open_count, 0);
44668 - atomic_set(&md->event_nr, 0);
44669 - atomic_set(&md->uevent_seq, 0);
44670 + atomic_set_unchecked(&md->event_nr, 0);
44671 + atomic_set_unchecked(&md->uevent_seq, 0);
44672 INIT_LIST_HEAD(&md->uevent_list);
44673 INIT_LIST_HEAD(&md->table_devices);
44674 spin_lock_init(&md->uevent_lock);
44675 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44676
44677 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44678
44679 - atomic_inc(&md->event_nr);
44680 + atomic_inc_unchecked(&md->event_nr);
44681 wake_up(&md->eventq);
44682 }
44683
44684 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44685
44686 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44687 {
44688 - return atomic_add_return(1, &md->uevent_seq);
44689 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44690 }
44691
44692 uint32_t dm_get_event_nr(struct mapped_device *md)
44693 {
44694 - return atomic_read(&md->event_nr);
44695 + return atomic_read_unchecked(&md->event_nr);
44696 }
44697
44698 int dm_wait_event(struct mapped_device *md, int event_nr)
44699 {
44700 return wait_event_interruptible(md->eventq,
44701 - (event_nr != atomic_read(&md->event_nr)));
44702 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44703 }
44704
44705 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44706 diff --git a/drivers/md/md.c b/drivers/md/md.c
44707 index 9233c71..ed5243a 100644
44708 --- a/drivers/md/md.c
44709 +++ b/drivers/md/md.c
44710 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44711 * start build, activate spare
44712 */
44713 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44714 -static atomic_t md_event_count;
44715 +static atomic_unchecked_t md_event_count;
44716 void md_new_event(struct mddev *mddev)
44717 {
44718 - atomic_inc(&md_event_count);
44719 + atomic_inc_unchecked(&md_event_count);
44720 wake_up(&md_event_waiters);
44721 }
44722 EXPORT_SYMBOL_GPL(md_new_event);
44723 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44724 */
44725 static void md_new_event_inintr(struct mddev *mddev)
44726 {
44727 - atomic_inc(&md_event_count);
44728 + atomic_inc_unchecked(&md_event_count);
44729 wake_up(&md_event_waiters);
44730 }
44731
44732 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44733 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44734 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44735 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44736 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44737 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44738
44739 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44740 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44741 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44742 else
44743 sb->resync_offset = cpu_to_le64(0);
44744
44745 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44746 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44747
44748 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44749 sb->size = cpu_to_le64(mddev->dev_sectors);
44750 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44751 static ssize_t
44752 errors_show(struct md_rdev *rdev, char *page)
44753 {
44754 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44755 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44756 }
44757
44758 static ssize_t
44759 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44760 char *e;
44761 unsigned long n = simple_strtoul(buf, &e, 10);
44762 if (*buf && (*e == 0 || *e == '\n')) {
44763 - atomic_set(&rdev->corrected_errors, n);
44764 + atomic_set_unchecked(&rdev->corrected_errors, n);
44765 return len;
44766 }
44767 return -EINVAL;
44768 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44769 rdev->sb_loaded = 0;
44770 rdev->bb_page = NULL;
44771 atomic_set(&rdev->nr_pending, 0);
44772 - atomic_set(&rdev->read_errors, 0);
44773 - atomic_set(&rdev->corrected_errors, 0);
44774 + atomic_set_unchecked(&rdev->read_errors, 0);
44775 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44776
44777 INIT_LIST_HEAD(&rdev->same_set);
44778 init_waitqueue_head(&rdev->blocked_wait);
44779 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44780
44781 spin_unlock(&pers_lock);
44782 seq_printf(seq, "\n");
44783 - seq->poll_event = atomic_read(&md_event_count);
44784 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44785 return 0;
44786 }
44787 if (v == (void*)2) {
44788 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44789 return error;
44790
44791 seq = file->private_data;
44792 - seq->poll_event = atomic_read(&md_event_count);
44793 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44794 return error;
44795 }
44796
44797 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44798 /* always allow read */
44799 mask = POLLIN | POLLRDNORM;
44800
44801 - if (seq->poll_event != atomic_read(&md_event_count))
44802 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44803 mask |= POLLERR | POLLPRI;
44804 return mask;
44805 }
44806 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44807 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44808 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44809 (int)part_stat_read(&disk->part0, sectors[1]) -
44810 - atomic_read(&disk->sync_io);
44811 + atomic_read_unchecked(&disk->sync_io);
44812 /* sync IO will cause sync_io to increase before the disk_stats
44813 * as sync_io is counted when a request starts, and
44814 * disk_stats is counted when it completes.
44815 diff --git a/drivers/md/md.h b/drivers/md/md.h
44816 index 03cec5b..0a658c1 100644
44817 --- a/drivers/md/md.h
44818 +++ b/drivers/md/md.h
44819 @@ -94,13 +94,13 @@ struct md_rdev {
44820 * only maintained for arrays that
44821 * support hot removal
44822 */
44823 - atomic_t read_errors; /* number of consecutive read errors that
44824 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44825 * we have tried to ignore.
44826 */
44827 struct timespec last_read_error; /* monotonic time since our
44828 * last read error
44829 */
44830 - atomic_t corrected_errors; /* number of corrected read errors,
44831 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44832 * for reporting to userspace and storing
44833 * in superblock.
44834 */
44835 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44836
44837 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44838 {
44839 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44840 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44841 }
44842
44843 struct md_personality
44844 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44845 index f4e22bc..8f83114 100644
44846 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44847 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44848 @@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44849 * Flick into a mode where all blocks get allocated in the new area.
44850 */
44851 smm->begin = old_len;
44852 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44853 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44854
44855 /*
44856 * Extend.
44857 @@ -712,7 +712,7 @@ out:
44858 /*
44859 * Switch back to normal behaviour.
44860 */
44861 - memcpy(sm, &ops, sizeof(*sm));
44862 + memcpy((void *)sm, &ops, sizeof(*sm));
44863 return r;
44864 }
44865
44866 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44867 index 3e6d115..ffecdeb 100644
44868 --- a/drivers/md/persistent-data/dm-space-map.h
44869 +++ b/drivers/md/persistent-data/dm-space-map.h
44870 @@ -71,6 +71,7 @@ struct dm_space_map {
44871 dm_sm_threshold_fn fn,
44872 void *context);
44873 };
44874 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44875
44876 /*----------------------------------------------------------------*/
44877
44878 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44879 index 40b35be..a327e11 100644
44880 --- a/drivers/md/raid1.c
44881 +++ b/drivers/md/raid1.c
44882 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44883 if (r1_sync_page_io(rdev, sect, s,
44884 bio->bi_io_vec[idx].bv_page,
44885 READ) != 0)
44886 - atomic_add(s, &rdev->corrected_errors);
44887 + atomic_add_unchecked(s, &rdev->corrected_errors);
44888 }
44889 sectors -= s;
44890 sect += s;
44891 @@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44892 !test_bit(Faulty, &rdev->flags)) {
44893 if (r1_sync_page_io(rdev, sect, s,
44894 conf->tmppage, READ)) {
44895 - atomic_add(s, &rdev->corrected_errors);
44896 + atomic_add_unchecked(s, &rdev->corrected_errors);
44897 printk(KERN_INFO
44898 "md/raid1:%s: read error corrected "
44899 "(%d sectors at %llu on %s)\n",
44900 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44901 index 32e282f..5cec803 100644
44902 --- a/drivers/md/raid10.c
44903 +++ b/drivers/md/raid10.c
44904 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44905 /* The write handler will notice the lack of
44906 * R10BIO_Uptodate and record any errors etc
44907 */
44908 - atomic_add(r10_bio->sectors,
44909 + atomic_add_unchecked(r10_bio->sectors,
44910 &conf->mirrors[d].rdev->corrected_errors);
44911
44912 /* for reconstruct, we always reschedule after a read.
44913 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44914 {
44915 struct timespec cur_time_mon;
44916 unsigned long hours_since_last;
44917 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44918 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44919
44920 ktime_get_ts(&cur_time_mon);
44921
44922 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44923 * overflowing the shift of read_errors by hours_since_last.
44924 */
44925 if (hours_since_last >= 8 * sizeof(read_errors))
44926 - atomic_set(&rdev->read_errors, 0);
44927 + atomic_set_unchecked(&rdev->read_errors, 0);
44928 else
44929 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44930 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44931 }
44932
44933 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44934 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44935 return;
44936
44937 check_decay_read_errors(mddev, rdev);
44938 - atomic_inc(&rdev->read_errors);
44939 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44940 + atomic_inc_unchecked(&rdev->read_errors);
44941 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44942 char b[BDEVNAME_SIZE];
44943 bdevname(rdev->bdev, b);
44944
44945 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44946 "md/raid10:%s: %s: Raid device exceeded "
44947 "read_error threshold [cur %d:max %d]\n",
44948 mdname(mddev), b,
44949 - atomic_read(&rdev->read_errors), max_read_errors);
44950 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44951 printk(KERN_NOTICE
44952 "md/raid10:%s: %s: Failing raid device\n",
44953 mdname(mddev), b);
44954 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44955 sect +
44956 choose_data_offset(r10_bio, rdev)),
44957 bdevname(rdev->bdev, b));
44958 - atomic_add(s, &rdev->corrected_errors);
44959 + atomic_add_unchecked(s, &rdev->corrected_errors);
44960 }
44961
44962 rdev_dec_pending(rdev, mddev);
44963 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44964 index b98765f..09e86d5 100644
44965 --- a/drivers/md/raid5.c
44966 +++ b/drivers/md/raid5.c
44967 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44968 return 1;
44969 }
44970
44971 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44972 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44973 +#endif
44974 +
44975 static int grow_stripes(struct r5conf *conf, int num)
44976 {
44977 struct kmem_cache *sc;
44978 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44979 "raid%d-%s", conf->level, mdname(conf->mddev));
44980 else
44981 sprintf(conf->cache_name[0],
44982 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44983 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44984 +#else
44985 "raid%d-%p", conf->level, conf->mddev);
44986 +#endif
44987 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44988
44989 conf->active_name = 0;
44990 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44991 mdname(conf->mddev), STRIPE_SECTORS,
44992 (unsigned long long)s,
44993 bdevname(rdev->bdev, b));
44994 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44995 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44996 clear_bit(R5_ReadError, &sh->dev[i].flags);
44997 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44998 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44999 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45000
45001 - if (atomic_read(&rdev->read_errors))
45002 - atomic_set(&rdev->read_errors, 0);
45003 + if (atomic_read_unchecked(&rdev->read_errors))
45004 + atomic_set_unchecked(&rdev->read_errors, 0);
45005 } else {
45006 const char *bdn = bdevname(rdev->bdev, b);
45007 int retry = 0;
45008 int set_bad = 0;
45009
45010 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45011 - atomic_inc(&rdev->read_errors);
45012 + atomic_inc_unchecked(&rdev->read_errors);
45013 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45014 printk_ratelimited(
45015 KERN_WARNING
45016 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45017 mdname(conf->mddev),
45018 (unsigned long long)s,
45019 bdn);
45020 - } else if (atomic_read(&rdev->read_errors)
45021 + } else if (atomic_read_unchecked(&rdev->read_errors)
45022 > conf->max_nr_stripes)
45023 printk(KERN_WARNING
45024 "md/raid:%s: Too many read errors, failing device %s.\n",
45025 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45026 index 983db75..ef9248c 100644
45027 --- a/drivers/media/dvb-core/dvbdev.c
45028 +++ b/drivers/media/dvb-core/dvbdev.c
45029 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45030 const struct dvb_device *template, void *priv, int type)
45031 {
45032 struct dvb_device *dvbdev;
45033 - struct file_operations *dvbdevfops;
45034 + file_operations_no_const *dvbdevfops;
45035 struct device *clsdev;
45036 int minor;
45037 int id;
45038 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45039 index 6ad22b6..6e90e2a 100644
45040 --- a/drivers/media/dvb-frontends/af9033.h
45041 +++ b/drivers/media/dvb-frontends/af9033.h
45042 @@ -96,6 +96,6 @@ struct af9033_ops {
45043 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45044 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45045 int onoff);
45046 -};
45047 +} __no_const;
45048
45049 #endif /* AF9033_H */
45050 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45051 index 9b6c3bb..baeb5c7 100644
45052 --- a/drivers/media/dvb-frontends/dib3000.h
45053 +++ b/drivers/media/dvb-frontends/dib3000.h
45054 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45055 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45056 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45057 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45058 -};
45059 +} __no_const;
45060
45061 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45062 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45063 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45064 index 1fea0e9..321ce8f 100644
45065 --- a/drivers/media/dvb-frontends/dib7000p.h
45066 +++ b/drivers/media/dvb-frontends/dib7000p.h
45067 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45068 int (*get_adc_power)(struct dvb_frontend *fe);
45069 int (*slave_reset)(struct dvb_frontend *fe);
45070 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45071 -};
45072 +} __no_const;
45073
45074 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45075 void *dib7000p_attach(struct dib7000p_ops *ops);
45076 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45077 index 84cc103..5780c54 100644
45078 --- a/drivers/media/dvb-frontends/dib8000.h
45079 +++ b/drivers/media/dvb-frontends/dib8000.h
45080 @@ -61,7 +61,7 @@ struct dib8000_ops {
45081 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45082 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45083 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45084 -};
45085 +} __no_const;
45086
45087 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45088 void *dib8000_attach(struct dib8000_ops *ops);
45089 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45090 index ce27e6d..b70435a 100644
45091 --- a/drivers/media/pci/cx88/cx88-video.c
45092 +++ b/drivers/media/pci/cx88/cx88-video.c
45093 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45094
45095 /* ------------------------------------------------------------------ */
45096
45097 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45098 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45099 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45100 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45101 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45102 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45103
45104 module_param_array(video_nr, int, NULL, 0444);
45105 module_param_array(vbi_nr, int, NULL, 0444);
45106 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45107 index 802642d..5534900 100644
45108 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45109 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45110 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45111 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45112
45113 /* ivtv instance counter */
45114 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45115 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45116
45117 /* Parameter declarations */
45118 static int cardtype[IVTV_MAX_CARDS];
45119 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45120 index 8cbe6b4..ea3601c 100644
45121 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45122 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45123 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45124
45125 static int solo_sysfs_init(struct solo_dev *solo_dev)
45126 {
45127 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45128 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45129 struct device *dev = &solo_dev->dev;
45130 const char *driver;
45131 int i;
45132 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45133 index c7141f2..5301fec 100644
45134 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45135 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45136 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45137
45138 int solo_g723_init(struct solo_dev *solo_dev)
45139 {
45140 - static struct snd_device_ops ops = { NULL };
45141 + static struct snd_device_ops ops = { };
45142 struct snd_card *card;
45143 struct snd_kcontrol_new kctl;
45144 char name[32];
45145 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45146 index 8c84846..27b4f83 100644
45147 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45148 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45149 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45150
45151 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45152 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45153 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45154 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45155 if (p2m_id < 0)
45156 p2m_id = -p2m_id;
45157 }
45158 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45159 index 72017b7..dd37ae6 100644
45160 --- a/drivers/media/pci/solo6x10/solo6x10.h
45161 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45162 @@ -219,7 +219,7 @@ struct solo_dev {
45163
45164 /* P2M DMA Engine */
45165 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45166 - atomic_t p2m_count;
45167 + atomic_unchecked_t p2m_count;
45168 int p2m_jiffies;
45169 unsigned int p2m_timeouts;
45170
45171 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45172 index 63f0b64..a017c1c 100644
45173 --- a/drivers/media/pci/tw68/tw68-core.c
45174 +++ b/drivers/media/pci/tw68/tw68-core.c
45175 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45176 module_param_array(card, int, NULL, 0444);
45177 MODULE_PARM_DESC(card, "card type");
45178
45179 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45180 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45181
45182 /* ------------------------------------------------------------------ */
45183
45184 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45185 index 64ab6fb..ef4a8b9 100644
45186 --- a/drivers/media/platform/omap/omap_vout.c
45187 +++ b/drivers/media/platform/omap/omap_vout.c
45188 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45189 OMAP_VIDEO2,
45190 };
45191
45192 -static struct videobuf_queue_ops video_vbq_ops;
45193 /* Variables configurable through module params*/
45194 static u32 video1_numbuffers = 3;
45195 static u32 video2_numbuffers = 3;
45196 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45197 {
45198 struct videobuf_queue *q;
45199 struct omap_vout_device *vout = NULL;
45200 + static struct videobuf_queue_ops video_vbq_ops = {
45201 + .buf_setup = omap_vout_buffer_setup,
45202 + .buf_prepare = omap_vout_buffer_prepare,
45203 + .buf_release = omap_vout_buffer_release,
45204 + .buf_queue = omap_vout_buffer_queue,
45205 + };
45206
45207 vout = video_drvdata(file);
45208 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45209 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45210 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45211
45212 q = &vout->vbq;
45213 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45214 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45215 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45216 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45217 spin_lock_init(&vout->vbq_lock);
45218
45219 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45220 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45221 index fb2acc5..a2fcbdc4 100644
45222 --- a/drivers/media/platform/s5p-tv/mixer.h
45223 +++ b/drivers/media/platform/s5p-tv/mixer.h
45224 @@ -156,7 +156,7 @@ struct mxr_layer {
45225 /** layer index (unique identifier) */
45226 int idx;
45227 /** callbacks for layer methods */
45228 - struct mxr_layer_ops ops;
45229 + struct mxr_layer_ops *ops;
45230 /** format array */
45231 const struct mxr_format **fmt_array;
45232 /** size of format array */
45233 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45234 index 74344c7..a39e70e 100644
45235 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45236 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45237 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45238 {
45239 struct mxr_layer *layer;
45240 int ret;
45241 - struct mxr_layer_ops ops = {
45242 + static struct mxr_layer_ops ops = {
45243 .release = mxr_graph_layer_release,
45244 .buffer_set = mxr_graph_buffer_set,
45245 .stream_set = mxr_graph_stream_set,
45246 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45247 index b713403..53cb5ad 100644
45248 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45249 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45250 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45251 layer->update_buf = next;
45252 }
45253
45254 - layer->ops.buffer_set(layer, layer->update_buf);
45255 + layer->ops->buffer_set(layer, layer->update_buf);
45256
45257 if (done && done != layer->shadow_buf)
45258 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45259 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45260 index b4d2696..91df48e 100644
45261 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45262 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45263 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45264 layer->geo.src.height = layer->geo.src.full_height;
45265
45266 mxr_geometry_dump(mdev, &layer->geo);
45267 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45268 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45269 mxr_geometry_dump(mdev, &layer->geo);
45270 }
45271
45272 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45273 layer->geo.dst.full_width = mbus_fmt.width;
45274 layer->geo.dst.full_height = mbus_fmt.height;
45275 layer->geo.dst.field = mbus_fmt.field;
45276 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45277 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45278
45279 mxr_geometry_dump(mdev, &layer->geo);
45280 }
45281 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45282 /* set source size to highest accepted value */
45283 geo->src.full_width = max(geo->dst.full_width, pix->width);
45284 geo->src.full_height = max(geo->dst.full_height, pix->height);
45285 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45286 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45287 mxr_geometry_dump(mdev, &layer->geo);
45288 /* set cropping to total visible screen */
45289 geo->src.width = pix->width;
45290 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45291 geo->src.x_offset = 0;
45292 geo->src.y_offset = 0;
45293 /* assure consistency of geometry */
45294 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45295 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45296 mxr_geometry_dump(mdev, &layer->geo);
45297 /* set full size to lowest possible value */
45298 geo->src.full_width = 0;
45299 geo->src.full_height = 0;
45300 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45301 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45302 mxr_geometry_dump(mdev, &layer->geo);
45303
45304 /* returning results */
45305 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45306 target->width = s->r.width;
45307 target->height = s->r.height;
45308
45309 - layer->ops.fix_geometry(layer, stage, s->flags);
45310 + layer->ops->fix_geometry(layer, stage, s->flags);
45311
45312 /* retrieve update selection rectangle */
45313 res.left = target->x_offset;
45314 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45315 mxr_output_get(mdev);
45316
45317 mxr_layer_update_output(layer);
45318 - layer->ops.format_set(layer);
45319 + layer->ops->format_set(layer);
45320 /* enabling layer in hardware */
45321 spin_lock_irqsave(&layer->enq_slock, flags);
45322 layer->state = MXR_LAYER_STREAMING;
45323 spin_unlock_irqrestore(&layer->enq_slock, flags);
45324
45325 - layer->ops.stream_set(layer, MXR_ENABLE);
45326 + layer->ops->stream_set(layer, MXR_ENABLE);
45327 mxr_streamer_get(mdev);
45328
45329 return 0;
45330 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45331 spin_unlock_irqrestore(&layer->enq_slock, flags);
45332
45333 /* disabling layer in hardware */
45334 - layer->ops.stream_set(layer, MXR_DISABLE);
45335 + layer->ops->stream_set(layer, MXR_DISABLE);
45336 /* remove one streamer */
45337 mxr_streamer_put(mdev);
45338 /* allow changes in output configuration */
45339 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45340
45341 void mxr_layer_release(struct mxr_layer *layer)
45342 {
45343 - if (layer->ops.release)
45344 - layer->ops.release(layer);
45345 + if (layer->ops->release)
45346 + layer->ops->release(layer);
45347 }
45348
45349 void mxr_base_layer_release(struct mxr_layer *layer)
45350 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45351
45352 layer->mdev = mdev;
45353 layer->idx = idx;
45354 - layer->ops = *ops;
45355 + layer->ops = ops;
45356
45357 spin_lock_init(&layer->enq_slock);
45358 INIT_LIST_HEAD(&layer->enq_list);
45359 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45360 index c9388c4..ce71ece 100644
45361 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45362 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45363 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45364 {
45365 struct mxr_layer *layer;
45366 int ret;
45367 - struct mxr_layer_ops ops = {
45368 + static struct mxr_layer_ops ops = {
45369 .release = mxr_vp_layer_release,
45370 .buffer_set = mxr_vp_buffer_set,
45371 .stream_set = mxr_vp_stream_set,
45372 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45373 index 82affae..42833ec 100644
45374 --- a/drivers/media/radio/radio-cadet.c
45375 +++ b/drivers/media/radio/radio-cadet.c
45376 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45377 unsigned char readbuf[RDS_BUFFER];
45378 int i = 0;
45379
45380 + if (count > RDS_BUFFER)
45381 + return -EFAULT;
45382 mutex_lock(&dev->lock);
45383 if (dev->rdsstat == 0)
45384 cadet_start_rds(dev);
45385 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45386 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45387 mutex_unlock(&dev->lock);
45388
45389 - if (i && copy_to_user(data, readbuf, i))
45390 - return -EFAULT;
45391 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45392 + i = -EFAULT;
45393 +
45394 return i;
45395 }
45396
45397 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45398 index 5236035..c622c74 100644
45399 --- a/drivers/media/radio/radio-maxiradio.c
45400 +++ b/drivers/media/radio/radio-maxiradio.c
45401 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45402 /* TEA5757 pin mappings */
45403 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45404
45405 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45406 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45407
45408 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45409 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45410 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45411 index 050b3bb..79f62b9 100644
45412 --- a/drivers/media/radio/radio-shark.c
45413 +++ b/drivers/media/radio/radio-shark.c
45414 @@ -79,7 +79,7 @@ struct shark_device {
45415 u32 last_val;
45416 };
45417
45418 -static atomic_t shark_instance = ATOMIC_INIT(0);
45419 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45420
45421 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45422 {
45423 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45424 index 8654e0d..0608a64 100644
45425 --- a/drivers/media/radio/radio-shark2.c
45426 +++ b/drivers/media/radio/radio-shark2.c
45427 @@ -74,7 +74,7 @@ struct shark_device {
45428 u8 *transfer_buffer;
45429 };
45430
45431 -static atomic_t shark_instance = ATOMIC_INIT(0);
45432 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45433
45434 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45435 {
45436 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45437 index 633022b..7f10754 100644
45438 --- a/drivers/media/radio/radio-si476x.c
45439 +++ b/drivers/media/radio/radio-si476x.c
45440 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45441 struct si476x_radio *radio;
45442 struct v4l2_ctrl *ctrl;
45443
45444 - static atomic_t instance = ATOMIC_INIT(0);
45445 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45446
45447 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45448 if (!radio)
45449 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45450 index 9fd1527..8927230 100644
45451 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45452 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45453 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45454
45455 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45456 {
45457 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45458 - char result[64];
45459 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45460 - sizeof(result), 0);
45461 + char *buf;
45462 + char *result;
45463 + int retval;
45464 +
45465 + buf = kmalloc(2, GFP_KERNEL);
45466 + if (buf == NULL)
45467 + return -ENOMEM;
45468 + result = kmalloc(64, GFP_KERNEL);
45469 + if (result == NULL) {
45470 + kfree(buf);
45471 + return -ENOMEM;
45472 + }
45473 +
45474 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45475 + buf[1] = enable ? 1 : 0;
45476 +
45477 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45478 +
45479 + kfree(buf);
45480 + kfree(result);
45481 + return retval;
45482 }
45483
45484 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45485 {
45486 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45487 - char state[3];
45488 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45489 + char *buf;
45490 + char *state;
45491 + int retval;
45492 +
45493 + buf = kmalloc(2, GFP_KERNEL);
45494 + if (buf == NULL)
45495 + return -ENOMEM;
45496 + state = kmalloc(3, GFP_KERNEL);
45497 + if (state == NULL) {
45498 + kfree(buf);
45499 + return -ENOMEM;
45500 + }
45501 +
45502 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45503 + buf[1] = enable ? 1 : 0;
45504 +
45505 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45506 +
45507 + kfree(buf);
45508 + kfree(state);
45509 + return retval;
45510 }
45511
45512 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45513 {
45514 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45515 - char state[3];
45516 + char *query;
45517 + char *state;
45518 int ret;
45519 + query = kmalloc(1, GFP_KERNEL);
45520 + if (query == NULL)
45521 + return -ENOMEM;
45522 + state = kmalloc(3, GFP_KERNEL);
45523 + if (state == NULL) {
45524 + kfree(query);
45525 + return -ENOMEM;
45526 + }
45527 +
45528 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45529
45530 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45531
45532 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45533 - sizeof(state), 0);
45534 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45535 if (ret < 0) {
45536 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45537 "state info\n");
45538 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45539
45540 /* Copy this pointer as we are gonna need it in the release phase */
45541 cinergyt2_usb_device = adap->dev;
45542 -
45543 + kfree(query);
45544 + kfree(state);
45545 return 0;
45546 }
45547
45548 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45549 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45550 {
45551 struct cinergyt2_state *st = d->priv;
45552 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45553 + u8 *key, *cmd;
45554 int i;
45555
45556 + cmd = kmalloc(1, GFP_KERNEL);
45557 + if (cmd == NULL)
45558 + return -EINVAL;
45559 + key = kzalloc(5, GFP_KERNEL);
45560 + if (key == NULL) {
45561 + kfree(cmd);
45562 + return -EINVAL;
45563 + }
45564 +
45565 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45566 +
45567 *state = REMOTE_NO_KEY_PRESSED;
45568
45569 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45570 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45571 if (key[4] == 0xff) {
45572 /* key repeat */
45573 st->rc_counter++;
45574 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45575 *event = d->last_event;
45576 deb_rc("repeat key, event %x\n",
45577 *event);
45578 - return 0;
45579 + goto out;
45580 }
45581 }
45582 deb_rc("repeated key (non repeatable)\n");
45583 }
45584 - return 0;
45585 + goto out;
45586 }
45587
45588 /* hack to pass checksum on the custom field */
45589 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45590
45591 deb_rc("key: %*ph\n", 5, key);
45592 }
45593 +out:
45594 + kfree(cmd);
45595 + kfree(key);
45596 return 0;
45597 }
45598
45599 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45600 index c890fe4..f9b2ae6 100644
45601 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45602 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45603 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45604 fe_status_t *status)
45605 {
45606 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45607 - struct dvbt_get_status_msg result;
45608 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45609 + struct dvbt_get_status_msg *result;
45610 + u8 *cmd;
45611 int ret;
45612
45613 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45614 - sizeof(result), 0);
45615 + cmd = kmalloc(1, GFP_KERNEL);
45616 + if (cmd == NULL)
45617 + return -ENOMEM;
45618 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45619 + if (result == NULL) {
45620 + kfree(cmd);
45621 + return -ENOMEM;
45622 + }
45623 +
45624 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45625 +
45626 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45627 + sizeof(*result), 0);
45628 if (ret < 0)
45629 - return ret;
45630 + goto out;
45631
45632 *status = 0;
45633
45634 - if (0xffff - le16_to_cpu(result.gain) > 30)
45635 + if (0xffff - le16_to_cpu(result->gain) > 30)
45636 *status |= FE_HAS_SIGNAL;
45637 - if (result.lock_bits & (1 << 6))
45638 + if (result->lock_bits & (1 << 6))
45639 *status |= FE_HAS_LOCK;
45640 - if (result.lock_bits & (1 << 5))
45641 + if (result->lock_bits & (1 << 5))
45642 *status |= FE_HAS_SYNC;
45643 - if (result.lock_bits & (1 << 4))
45644 + if (result->lock_bits & (1 << 4))
45645 *status |= FE_HAS_CARRIER;
45646 - if (result.lock_bits & (1 << 1))
45647 + if (result->lock_bits & (1 << 1))
45648 *status |= FE_HAS_VITERBI;
45649
45650 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45651 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45652 *status &= ~FE_HAS_LOCK;
45653
45654 - return 0;
45655 +out:
45656 + kfree(cmd);
45657 + kfree(result);
45658 + return ret;
45659 }
45660
45661 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45662 {
45663 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45664 - struct dvbt_get_status_msg status;
45665 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45666 + struct dvbt_get_status_msg *status;
45667 + char *cmd;
45668 int ret;
45669
45670 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45671 - sizeof(status), 0);
45672 + cmd = kmalloc(1, GFP_KERNEL);
45673 + if (cmd == NULL)
45674 + return -ENOMEM;
45675 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45676 + if (status == NULL) {
45677 + kfree(cmd);
45678 + return -ENOMEM;
45679 + }
45680 +
45681 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45682 +
45683 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45684 + sizeof(*status), 0);
45685 if (ret < 0)
45686 - return ret;
45687 + goto out;
45688
45689 - *ber = le32_to_cpu(status.viterbi_error_rate);
45690 + *ber = le32_to_cpu(status->viterbi_error_rate);
45691 +out:
45692 + kfree(cmd);
45693 + kfree(status);
45694 return 0;
45695 }
45696
45697 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45698 {
45699 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45700 - struct dvbt_get_status_msg status;
45701 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45702 + struct dvbt_get_status_msg *status;
45703 + u8 *cmd;
45704 int ret;
45705
45706 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45707 - sizeof(status), 0);
45708 + cmd = kmalloc(1, GFP_KERNEL);
45709 + if (cmd == NULL)
45710 + return -ENOMEM;
45711 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45712 + if (status == NULL) {
45713 + kfree(cmd);
45714 + return -ENOMEM;
45715 + }
45716 +
45717 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45718 +
45719 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45720 + sizeof(*status), 0);
45721 if (ret < 0) {
45722 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45723 ret);
45724 - return ret;
45725 + goto out;
45726 }
45727 - *unc = le32_to_cpu(status.uncorrected_block_count);
45728 - return 0;
45729 + *unc = le32_to_cpu(status->uncorrected_block_count);
45730 +
45731 +out:
45732 + kfree(cmd);
45733 + kfree(status);
45734 + return ret;
45735 }
45736
45737 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45738 u16 *strength)
45739 {
45740 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45741 - struct dvbt_get_status_msg status;
45742 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45743 + struct dvbt_get_status_msg *status;
45744 + char *cmd;
45745 int ret;
45746
45747 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45748 - sizeof(status), 0);
45749 + cmd = kmalloc(1, GFP_KERNEL);
45750 + if (cmd == NULL)
45751 + return -ENOMEM;
45752 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45753 + if (status == NULL) {
45754 + kfree(cmd);
45755 + return -ENOMEM;
45756 + }
45757 +
45758 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45759 +
45760 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45761 + sizeof(*status), 0);
45762 if (ret < 0) {
45763 err("cinergyt2_fe_read_signal_strength() Failed!"
45764 " (Error=%d)\n", ret);
45765 - return ret;
45766 + goto out;
45767 }
45768 - *strength = (0xffff - le16_to_cpu(status.gain));
45769 + *strength = (0xffff - le16_to_cpu(status->gain));
45770 +
45771 +out:
45772 + kfree(cmd);
45773 + kfree(status);
45774 return 0;
45775 }
45776
45777 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45778 {
45779 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45780 - struct dvbt_get_status_msg status;
45781 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45782 + struct dvbt_get_status_msg *status;
45783 + char *cmd;
45784 int ret;
45785
45786 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45787 - sizeof(status), 0);
45788 + cmd = kmalloc(1, GFP_KERNEL);
45789 + if (cmd == NULL)
45790 + return -ENOMEM;
45791 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45792 + if (status == NULL) {
45793 + kfree(cmd);
45794 + return -ENOMEM;
45795 + }
45796 +
45797 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45798 +
45799 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45800 + sizeof(*status), 0);
45801 if (ret < 0) {
45802 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45803 - return ret;
45804 + goto out;
45805 }
45806 - *snr = (status.snr << 8) | status.snr;
45807 - return 0;
45808 + *snr = (status->snr << 8) | status->snr;
45809 +
45810 +out:
45811 + kfree(cmd);
45812 + kfree(status);
45813 + return ret;
45814 }
45815
45816 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45817 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45818 {
45819 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45820 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45821 - struct dvbt_set_parameters_msg param;
45822 - char result[2];
45823 + struct dvbt_set_parameters_msg *param;
45824 + char *result;
45825 int err;
45826
45827 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45828 - param.tps = cpu_to_le16(compute_tps(fep));
45829 - param.freq = cpu_to_le32(fep->frequency / 1000);
45830 - param.flags = 0;
45831 + result = kmalloc(2, GFP_KERNEL);
45832 + if (result == NULL)
45833 + return -ENOMEM;
45834 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45835 + if (param == NULL) {
45836 + kfree(result);
45837 + return -ENOMEM;
45838 + }
45839 +
45840 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45841 + param->tps = cpu_to_le16(compute_tps(fep));
45842 + param->freq = cpu_to_le32(fep->frequency / 1000);
45843 + param->flags = 0;
45844
45845 switch (fep->bandwidth_hz) {
45846 default:
45847 case 8000000:
45848 - param.bandwidth = 8;
45849 + param->bandwidth = 8;
45850 break;
45851 case 7000000:
45852 - param.bandwidth = 7;
45853 + param->bandwidth = 7;
45854 break;
45855 case 6000000:
45856 - param.bandwidth = 6;
45857 + param->bandwidth = 6;
45858 break;
45859 }
45860
45861 err = dvb_usb_generic_rw(state->d,
45862 - (char *)&param, sizeof(param),
45863 - result, sizeof(result), 0);
45864 + (char *)param, sizeof(*param),
45865 + result, 2, 0);
45866 if (err < 0)
45867 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45868
45869 - return (err < 0) ? err : 0;
45870 + kfree(result);
45871 + kfree(param);
45872 + return err;
45873 }
45874
45875 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45876 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45877 index 733a7ff..f8b52e3 100644
45878 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45879 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45880 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45881
45882 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45883 {
45884 - struct hexline hx;
45885 - u8 reset;
45886 + struct hexline *hx;
45887 + u8 *reset;
45888 int ret,pos=0;
45889
45890 + reset = kmalloc(1, GFP_KERNEL);
45891 + if (reset == NULL)
45892 + return -ENOMEM;
45893 +
45894 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45895 + if (hx == NULL) {
45896 + kfree(reset);
45897 + return -ENOMEM;
45898 + }
45899 +
45900 /* stop the CPU */
45901 - reset = 1;
45902 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45903 + reset[0] = 1;
45904 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45905 err("could not stop the USB controller CPU.");
45906
45907 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45908 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45909 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45910 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45911 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45912 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45913
45914 - if (ret != hx.len) {
45915 + if (ret != hx->len) {
45916 err("error while transferring firmware "
45917 "(transferred size: %d, block size: %d)",
45918 - ret,hx.len);
45919 + ret,hx->len);
45920 ret = -EINVAL;
45921 break;
45922 }
45923 }
45924 if (ret < 0) {
45925 err("firmware download failed at %d with %d",pos,ret);
45926 + kfree(reset);
45927 + kfree(hx);
45928 return ret;
45929 }
45930
45931 if (ret == 0) {
45932 /* restart the CPU */
45933 - reset = 0;
45934 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45935 + reset[0] = 0;
45936 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45937 err("could not restart the USB controller CPU.");
45938 ret = -EINVAL;
45939 }
45940 } else
45941 ret = -EIO;
45942
45943 + kfree(reset);
45944 + kfree(hx);
45945 +
45946 return ret;
45947 }
45948 EXPORT_SYMBOL(usb_cypress_load_firmware);
45949 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45950 index 1a3df10..57997a5 100644
45951 --- a/drivers/media/usb/dvb-usb/dw2102.c
45952 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45953 @@ -118,7 +118,7 @@ struct su3000_state {
45954
45955 struct s6x0_state {
45956 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45957 -};
45958 +} __no_const;
45959
45960 /* debug */
45961 static int dvb_usb_dw2102_debug;
45962 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45963 index 6b0b8b6b..4038398 100644
45964 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45965 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45966 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
45967 static int technisat_usb2_i2c_access(struct usb_device *udev,
45968 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45969 {
45970 - u8 b[64];
45971 - int ret, actual_length;
45972 + u8 *b = kmalloc(64, GFP_KERNEL);
45973 + int ret, actual_length, error = 0;
45974 +
45975 + if (b == NULL)
45976 + return -ENOMEM;
45977
45978 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45979 debug_dump(tx, txlen, deb_i2c);
45980 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45981
45982 if (ret < 0) {
45983 err("i2c-error: out failed %02x = %d", device_addr, ret);
45984 - return -ENODEV;
45985 + error = -ENODEV;
45986 + goto out;
45987 }
45988
45989 ret = usb_bulk_msg(udev,
45990 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45991 b, 64, &actual_length, 1000);
45992 if (ret < 0) {
45993 err("i2c-error: in failed %02x = %d", device_addr, ret);
45994 - return -ENODEV;
45995 + error = -ENODEV;
45996 + goto out;
45997 }
45998
45999 if (b[0] != I2C_STATUS_OK) {
46000 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46001 /* handle tuner-i2c-nak */
46002 if (!(b[0] == I2C_STATUS_NAK &&
46003 device_addr == 0x60
46004 - /* && device_is_technisat_usb2 */))
46005 - return -ENODEV;
46006 + /* && device_is_technisat_usb2 */)) {
46007 + error = -ENODEV;
46008 + goto out;
46009 + }
46010 }
46011
46012 deb_i2c("status: %d, ", b[0]);
46013 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46014
46015 deb_i2c("\n");
46016
46017 - return 0;
46018 +out:
46019 + kfree(b);
46020 + return error;
46021 }
46022
46023 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46024 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46025 {
46026 int ret;
46027
46028 - u8 led[8] = {
46029 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46030 - 0
46031 - };
46032 + u8 *led = kzalloc(8, GFP_KERNEL);
46033 +
46034 + if (led == NULL)
46035 + return -ENOMEM;
46036
46037 if (disable_led_control && state != TECH_LED_OFF)
46038 return 0;
46039
46040 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46041 +
46042 switch (state) {
46043 case TECH_LED_ON:
46044 led[1] = 0x82;
46045 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46046 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46047 USB_TYPE_VENDOR | USB_DIR_OUT,
46048 0, 0,
46049 - led, sizeof(led), 500);
46050 + led, 8, 500);
46051
46052 mutex_unlock(&d->i2c_mutex);
46053 +
46054 + kfree(led);
46055 +
46056 return ret;
46057 }
46058
46059 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46060 {
46061 int ret;
46062 - u8 b = 0;
46063 + u8 *b = kzalloc(1, GFP_KERNEL);
46064 +
46065 + if (b == NULL)
46066 + return -ENOMEM;
46067
46068 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46069 return -EAGAIN;
46070 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46071 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46072 USB_TYPE_VENDOR | USB_DIR_OUT,
46073 (red << 8) | green, 0,
46074 - &b, 1, 500);
46075 + b, 1, 500);
46076
46077 mutex_unlock(&d->i2c_mutex);
46078
46079 + kfree(b);
46080 +
46081 return ret;
46082 }
46083
46084 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46085 struct dvb_usb_device_description **desc, int *cold)
46086 {
46087 int ret;
46088 - u8 version[3];
46089 + u8 *version = kmalloc(3, GFP_KERNEL);
46090
46091 /* first select the interface */
46092 if (usb_set_interface(udev, 0, 1) != 0)
46093 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46094
46095 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46096
46097 + if (version == NULL)
46098 + return 0;
46099 +
46100 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46101 GET_VERSION_INFO_VENDOR_REQUEST,
46102 USB_TYPE_VENDOR | USB_DIR_IN,
46103 0, 0,
46104 - version, sizeof(version), 500);
46105 + version, 3, 500);
46106
46107 if (ret < 0)
46108 *cold = 1;
46109 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46110 *cold = 0;
46111 }
46112
46113 + kfree(version);
46114 +
46115 return 0;
46116 }
46117
46118 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46119
46120 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46121 {
46122 - u8 buf[62], *b;
46123 + u8 *buf, *b;
46124 int ret;
46125 struct ir_raw_event ev;
46126
46127 + buf = kmalloc(62, GFP_KERNEL);
46128 +
46129 + if (buf == NULL)
46130 + return -ENOMEM;
46131 +
46132 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46133 buf[1] = 0x08;
46134 buf[2] = 0x8f;
46135 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46136 GET_IR_DATA_VENDOR_REQUEST,
46137 USB_TYPE_VENDOR | USB_DIR_IN,
46138 0x8080, 0,
46139 - buf, sizeof(buf), 500);
46140 + buf, 62, 500);
46141
46142 unlock:
46143 mutex_unlock(&d->i2c_mutex);
46144
46145 - if (ret < 0)
46146 + if (ret < 0) {
46147 + kfree(buf);
46148 return ret;
46149 + }
46150
46151 - if (ret == 1)
46152 + if (ret == 1) {
46153 + kfree(buf);
46154 return 0; /* no key pressed */
46155 + }
46156
46157 /* decoding */
46158 b = buf+1;
46159 @@ -653,6 +686,8 @@ unlock:
46160
46161 ir_raw_event_handle(d->rc_dev);
46162
46163 + kfree(buf);
46164 +
46165 return 1;
46166 }
46167
46168 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46169 index e502a5f..2a27f40 100644
46170 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46171 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46172 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46173 * by passing a very big num_planes value */
46174 uplane = compat_alloc_user_space(num_planes *
46175 sizeof(struct v4l2_plane));
46176 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46177 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46178
46179 while (--num_planes >= 0) {
46180 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46181 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46182 if (num_planes == 0)
46183 return 0;
46184
46185 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46186 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46187 if (get_user(p, &up->m.planes))
46188 return -EFAULT;
46189 uplane32 = compat_ptr(p);
46190 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46191 get_user(kp->flags, &up->flags) ||
46192 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46193 return -EFAULT;
46194 - kp->base = (__force void *)compat_ptr(tmp);
46195 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46196 return 0;
46197 }
46198
46199 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46200 n * sizeof(struct v4l2_ext_control32)))
46201 return -EFAULT;
46202 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46203 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46204 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46205 while (--n >= 0) {
46206 u32 id;
46207
46208 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46209 {
46210 struct v4l2_ext_control32 __user *ucontrols;
46211 struct v4l2_ext_control __user *kcontrols =
46212 - (__force struct v4l2_ext_control __user *)kp->controls;
46213 + (struct v4l2_ext_control __force_user *)kp->controls;
46214 int n = kp->count;
46215 compat_caddr_t p;
46216
46217 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46218 get_user(tmp, &up->edid) ||
46219 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46220 return -EFAULT;
46221 - kp->edid = (__force u8 *)compat_ptr(tmp);
46222 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46223 return 0;
46224 }
46225
46226 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46227 index 015f92a..59e311e 100644
46228 --- a/drivers/media/v4l2-core/v4l2-device.c
46229 +++ b/drivers/media/v4l2-core/v4l2-device.c
46230 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46231 EXPORT_SYMBOL_GPL(v4l2_device_put);
46232
46233 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46234 - atomic_t *instance)
46235 + atomic_unchecked_t *instance)
46236 {
46237 - int num = atomic_inc_return(instance) - 1;
46238 + int num = atomic_inc_return_unchecked(instance) - 1;
46239 int len = strlen(basename);
46240
46241 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46242 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46243 index 9ccb19a..d131468 100644
46244 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46245 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46246 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46247 struct file *file, void *fh, void *p);
46248 } u;
46249 void (*debug)(const void *arg, bool write_only);
46250 -};
46251 +} __do_const;
46252 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46253
46254 /* This control needs a priority check */
46255 #define INFO_FL_PRIO (1 << 0)
46256 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46257 struct video_device *vfd = video_devdata(file);
46258 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46259 bool write_only = false;
46260 - struct v4l2_ioctl_info default_info;
46261 + v4l2_ioctl_info_no_const default_info;
46262 const struct v4l2_ioctl_info *info;
46263 void *fh = file->private_data;
46264 struct v4l2_fh *vfh = NULL;
46265 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46266 ret = -EINVAL;
46267 break;
46268 }
46269 - *user_ptr = (void __user *)buf->m.planes;
46270 + *user_ptr = (void __force_user *)buf->m.planes;
46271 *kernel_ptr = (void **)&buf->m.planes;
46272 *array_size = sizeof(struct v4l2_plane) * buf->length;
46273 ret = 1;
46274 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46275 ret = -EINVAL;
46276 break;
46277 }
46278 - *user_ptr = (void __user *)edid->edid;
46279 + *user_ptr = (void __force_user *)edid->edid;
46280 *kernel_ptr = (void **)&edid->edid;
46281 *array_size = edid->blocks * 128;
46282 ret = 1;
46283 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46284 ret = -EINVAL;
46285 break;
46286 }
46287 - *user_ptr = (void __user *)ctrls->controls;
46288 + *user_ptr = (void __force_user *)ctrls->controls;
46289 *kernel_ptr = (void **)&ctrls->controls;
46290 *array_size = sizeof(struct v4l2_ext_control)
46291 * ctrls->count;
46292 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46293 }
46294
46295 if (has_array_args) {
46296 - *kernel_ptr = (void __force *)user_ptr;
46297 + *kernel_ptr = (void __force_kernel *)user_ptr;
46298 if (copy_to_user(user_ptr, mbuf, array_size))
46299 err = -EFAULT;
46300 goto out_array_args;
46301 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46302 index 187f836..679544b 100644
46303 --- a/drivers/message/fusion/mptbase.c
46304 +++ b/drivers/message/fusion/mptbase.c
46305 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46306 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46307 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46308
46309 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46310 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46311 +#else
46312 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46313 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46314 +#endif
46315 +
46316 /*
46317 * Rounding UP to nearest 4-kB boundary here...
46318 */
46319 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46320 ioc->facts.GlobalCredits);
46321
46322 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46323 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46324 + NULL, NULL);
46325 +#else
46326 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46327 +#endif
46328 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46329 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46330 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46331 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46332 index 0707fa2..70ca794 100644
46333 --- a/drivers/message/fusion/mptsas.c
46334 +++ b/drivers/message/fusion/mptsas.c
46335 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46336 return 0;
46337 }
46338
46339 +static inline void
46340 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46341 +{
46342 + if (phy_info->port_details) {
46343 + phy_info->port_details->rphy = rphy;
46344 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46345 + ioc->name, rphy));
46346 + }
46347 +
46348 + if (rphy) {
46349 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46350 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46351 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46352 + ioc->name, rphy, rphy->dev.release));
46353 + }
46354 +}
46355 +
46356 /* no mutex */
46357 static void
46358 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46359 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46360 return NULL;
46361 }
46362
46363 -static inline void
46364 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46365 -{
46366 - if (phy_info->port_details) {
46367 - phy_info->port_details->rphy = rphy;
46368 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46369 - ioc->name, rphy));
46370 - }
46371 -
46372 - if (rphy) {
46373 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46374 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46375 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46376 - ioc->name, rphy, rphy->dev.release));
46377 - }
46378 -}
46379 -
46380 static inline struct sas_port *
46381 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46382 {
46383 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46384 index b7d87cd..3fb36da 100644
46385 --- a/drivers/message/i2o/i2o_proc.c
46386 +++ b/drivers/message/i2o/i2o_proc.c
46387 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46388 "Array Controller Device"
46389 };
46390
46391 -static char *chtostr(char *tmp, u8 *chars, int n)
46392 -{
46393 - tmp[0] = 0;
46394 - return strncat(tmp, (char *)chars, n);
46395 -}
46396 -
46397 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46398 char *group)
46399 {
46400 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46401 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46402 {
46403 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46404 - static u32 work32[5];
46405 - static u8 *work8 = (u8 *) work32;
46406 - static u16 *work16 = (u16 *) work32;
46407 + u32 work32[5];
46408 + u8 *work8 = (u8 *) work32;
46409 + u16 *work16 = (u16 *) work32;
46410 int token;
46411 u32 hwcap;
46412
46413 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46414 } *result;
46415
46416 i2o_exec_execute_ddm_table ddm_table;
46417 - char tmp[28 + 1];
46418
46419 result = kmalloc(sizeof(*result), GFP_KERNEL);
46420 if (!result)
46421 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46422
46423 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46424 seq_printf(seq, "%-#8x", ddm_table.module_id);
46425 - seq_printf(seq, "%-29s",
46426 - chtostr(tmp, ddm_table.module_name_version, 28));
46427 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46428 seq_printf(seq, "%9d ", ddm_table.data_size);
46429 seq_printf(seq, "%8d", ddm_table.code_size);
46430
46431 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46432
46433 i2o_driver_result_table *result;
46434 i2o_driver_store_table *dst;
46435 - char tmp[28 + 1];
46436
46437 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46438 if (result == NULL)
46439 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46440
46441 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46442 seq_printf(seq, "%-#8x", dst->module_id);
46443 - seq_printf(seq, "%-29s",
46444 - chtostr(tmp, dst->module_name_version, 28));
46445 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46446 + seq_printf(seq, "%-.28s", dst->module_name_version);
46447 + seq_printf(seq, "%-.8s", dst->date);
46448 seq_printf(seq, "%8d ", dst->module_size);
46449 seq_printf(seq, "%8d ", dst->mpb_size);
46450 seq_printf(seq, "0x%04x", dst->module_flags);
46451 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46452 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46453 {
46454 struct i2o_device *d = (struct i2o_device *)seq->private;
46455 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46456 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46457 // == (allow) 512d bytes (max)
46458 - static u16 *work16 = (u16 *) work32;
46459 + u16 *work16 = (u16 *) work32;
46460 int token;
46461 - char tmp[16 + 1];
46462
46463 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46464
46465 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46466 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46467 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46468 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46469 - seq_printf(seq, "Vendor info : %s\n",
46470 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46471 - seq_printf(seq, "Product info : %s\n",
46472 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46473 - seq_printf(seq, "Description : %s\n",
46474 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46475 - seq_printf(seq, "Product rev. : %s\n",
46476 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46477 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46478 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46479 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46480 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46481
46482 seq_printf(seq, "Serial number : ");
46483 print_serial_number(seq, (u8 *) (work32 + 16),
46484 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46485 u8 pad[256]; // allow up to 256 byte (max) serial number
46486 } result;
46487
46488 - char tmp[24 + 1];
46489 -
46490 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46491
46492 if (token < 0) {
46493 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46494 }
46495
46496 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46497 - seq_printf(seq, "Module name : %s\n",
46498 - chtostr(tmp, result.module_name, 24));
46499 - seq_printf(seq, "Module revision : %s\n",
46500 - chtostr(tmp, result.module_rev, 8));
46501 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46502 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46503
46504 seq_printf(seq, "Serial number : ");
46505 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46506 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46507 u8 instance_number[4];
46508 } result;
46509
46510 - char tmp[64 + 1];
46511 -
46512 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46513
46514 if (token < 0) {
46515 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46516 return 0;
46517 }
46518
46519 - seq_printf(seq, "Device name : %s\n",
46520 - chtostr(tmp, result.device_name, 64));
46521 - seq_printf(seq, "Service name : %s\n",
46522 - chtostr(tmp, result.service_name, 64));
46523 - seq_printf(seq, "Physical name : %s\n",
46524 - chtostr(tmp, result.physical_location, 64));
46525 - seq_printf(seq, "Instance number : %s\n",
46526 - chtostr(tmp, result.instance_number, 4));
46527 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46528 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46529 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46530 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46531
46532 return 0;
46533 }
46534 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46535 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46536 {
46537 struct i2o_device *d = (struct i2o_device *)seq->private;
46538 - static u32 work32[12];
46539 - static u16 *work16 = (u16 *) work32;
46540 - static u8 *work8 = (u8 *) work32;
46541 + u32 work32[12];
46542 + u16 *work16 = (u16 *) work32;
46543 + u8 *work8 = (u8 *) work32;
46544 int token;
46545
46546 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46547 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46548 index 92752fb..a7494f6 100644
46549 --- a/drivers/message/i2o/iop.c
46550 +++ b/drivers/message/i2o/iop.c
46551 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46552
46553 spin_lock_irqsave(&c->context_list_lock, flags);
46554
46555 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46556 - atomic_inc(&c->context_list_counter);
46557 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46558 + atomic_inc_unchecked(&c->context_list_counter);
46559
46560 - entry->context = atomic_read(&c->context_list_counter);
46561 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46562
46563 list_add(&entry->list, &c->context_list);
46564
46565 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46566
46567 #if BITS_PER_LONG == 64
46568 spin_lock_init(&c->context_list_lock);
46569 - atomic_set(&c->context_list_counter, 0);
46570 + atomic_set_unchecked(&c->context_list_counter, 0);
46571 INIT_LIST_HEAD(&c->context_list);
46572 #endif
46573
46574 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46575 index b2c7e3b..85aa4764 100644
46576 --- a/drivers/mfd/ab8500-debugfs.c
46577 +++ b/drivers/mfd/ab8500-debugfs.c
46578 @@ -100,7 +100,7 @@ static int irq_last;
46579 static u32 *irq_count;
46580 static int num_irqs;
46581
46582 -static struct device_attribute **dev_attr;
46583 +static device_attribute_no_const **dev_attr;
46584 static char **event_name;
46585
46586 static u8 avg_sample = SAMPLE_16;
46587 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46588 index c880c89..45a7c68 100644
46589 --- a/drivers/mfd/max8925-i2c.c
46590 +++ b/drivers/mfd/max8925-i2c.c
46591 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46592 const struct i2c_device_id *id)
46593 {
46594 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46595 - static struct max8925_chip *chip;
46596 + struct max8925_chip *chip;
46597 struct device_node *node = client->dev.of_node;
46598
46599 if (node && !pdata) {
46600 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46601 index 7612d89..70549c2 100644
46602 --- a/drivers/mfd/tps65910.c
46603 +++ b/drivers/mfd/tps65910.c
46604 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46605 struct tps65910_platform_data *pdata)
46606 {
46607 int ret = 0;
46608 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46609 + struct regmap_irq_chip *tps6591x_irqs_chip;
46610
46611 if (!irq) {
46612 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46613 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46614 index 1b772ef..01e77d33 100644
46615 --- a/drivers/mfd/twl4030-irq.c
46616 +++ b/drivers/mfd/twl4030-irq.c
46617 @@ -34,6 +34,7 @@
46618 #include <linux/of.h>
46619 #include <linux/irqdomain.h>
46620 #include <linux/i2c/twl.h>
46621 +#include <asm/pgtable.h>
46622
46623 #include "twl-core.h"
46624
46625 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46626 * Install an irq handler for each of the SIH modules;
46627 * clone dummy irq_chip since PIH can't *do* anything
46628 */
46629 - twl4030_irq_chip = dummy_irq_chip;
46630 - twl4030_irq_chip.name = "twl4030";
46631 + pax_open_kernel();
46632 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46633 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46634
46635 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46636 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46637 + pax_close_kernel();
46638
46639 for (i = irq_base; i < irq_end; i++) {
46640 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46641 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46642 index 464419b..64bae8d 100644
46643 --- a/drivers/misc/c2port/core.c
46644 +++ b/drivers/misc/c2port/core.c
46645 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46646 goto error_idr_alloc;
46647 c2dev->id = ret;
46648
46649 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46650 + pax_open_kernel();
46651 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46652 + pax_close_kernel();
46653
46654 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46655 "c2port%d", c2dev->id);
46656 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46657 index 3f2b625..945e179 100644
46658 --- a/drivers/misc/eeprom/sunxi_sid.c
46659 +++ b/drivers/misc/eeprom/sunxi_sid.c
46660 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46661
46662 platform_set_drvdata(pdev, sid_data);
46663
46664 - sid_bin_attr.size = sid_data->keysize;
46665 + pax_open_kernel();
46666 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46667 + pax_close_kernel();
46668 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46669 return -ENODEV;
46670
46671 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46672 index 36f5d52..32311c3 100644
46673 --- a/drivers/misc/kgdbts.c
46674 +++ b/drivers/misc/kgdbts.c
46675 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46676 char before[BREAK_INSTR_SIZE];
46677 char after[BREAK_INSTR_SIZE];
46678
46679 - probe_kernel_read(before, (char *)kgdbts_break_test,
46680 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46681 BREAK_INSTR_SIZE);
46682 init_simple_test();
46683 ts.tst = plant_and_detach_test;
46684 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46685 /* Activate test with initial breakpoint */
46686 if (!is_early)
46687 kgdb_breakpoint();
46688 - probe_kernel_read(after, (char *)kgdbts_break_test,
46689 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46690 BREAK_INSTR_SIZE);
46691 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46692 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46693 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46694 index 3ef4627..8d00486 100644
46695 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46696 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46697 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46698 * the lid is closed. This leads to interrupts as soon as a little move
46699 * is done.
46700 */
46701 - atomic_inc(&lis3->count);
46702 + atomic_inc_unchecked(&lis3->count);
46703
46704 wake_up_interruptible(&lis3->misc_wait);
46705 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46706 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46707 if (lis3->pm_dev)
46708 pm_runtime_get_sync(lis3->pm_dev);
46709
46710 - atomic_set(&lis3->count, 0);
46711 + atomic_set_unchecked(&lis3->count, 0);
46712 return 0;
46713 }
46714
46715 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46716 add_wait_queue(&lis3->misc_wait, &wait);
46717 while (true) {
46718 set_current_state(TASK_INTERRUPTIBLE);
46719 - data = atomic_xchg(&lis3->count, 0);
46720 + data = atomic_xchg_unchecked(&lis3->count, 0);
46721 if (data)
46722 break;
46723
46724 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46725 struct lis3lv02d, miscdev);
46726
46727 poll_wait(file, &lis3->misc_wait, wait);
46728 - if (atomic_read(&lis3->count))
46729 + if (atomic_read_unchecked(&lis3->count))
46730 return POLLIN | POLLRDNORM;
46731 return 0;
46732 }
46733 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46734 index c439c82..1f20f57 100644
46735 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46736 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46737 @@ -297,7 +297,7 @@ struct lis3lv02d {
46738 struct input_polled_dev *idev; /* input device */
46739 struct platform_device *pdev; /* platform device */
46740 struct regulator_bulk_data regulators[2];
46741 - atomic_t count; /* interrupt count after last read */
46742 + atomic_unchecked_t count; /* interrupt count after last read */
46743 union axis_conversion ac; /* hw -> logical axis */
46744 int mapped_btns[3];
46745
46746 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46747 index 2f30bad..c4c13d0 100644
46748 --- a/drivers/misc/sgi-gru/gruhandles.c
46749 +++ b/drivers/misc/sgi-gru/gruhandles.c
46750 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46751 unsigned long nsec;
46752
46753 nsec = CLKS2NSEC(clks);
46754 - atomic_long_inc(&mcs_op_statistics[op].count);
46755 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46756 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46757 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46758 if (mcs_op_statistics[op].max < nsec)
46759 mcs_op_statistics[op].max = nsec;
46760 }
46761 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46762 index 4f76359..cdfcb2e 100644
46763 --- a/drivers/misc/sgi-gru/gruprocfs.c
46764 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46765 @@ -32,9 +32,9 @@
46766
46767 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46768
46769 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46770 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46771 {
46772 - unsigned long val = atomic_long_read(v);
46773 + unsigned long val = atomic_long_read_unchecked(v);
46774
46775 seq_printf(s, "%16lu %s\n", val, id);
46776 }
46777 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46778
46779 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46780 for (op = 0; op < mcsop_last; op++) {
46781 - count = atomic_long_read(&mcs_op_statistics[op].count);
46782 - total = atomic_long_read(&mcs_op_statistics[op].total);
46783 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46784 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46785 max = mcs_op_statistics[op].max;
46786 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46787 count ? total / count : 0, max);
46788 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46789 index 5c3ce24..4915ccb 100644
46790 --- a/drivers/misc/sgi-gru/grutables.h
46791 +++ b/drivers/misc/sgi-gru/grutables.h
46792 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46793 * GRU statistics.
46794 */
46795 struct gru_stats_s {
46796 - atomic_long_t vdata_alloc;
46797 - atomic_long_t vdata_free;
46798 - atomic_long_t gts_alloc;
46799 - atomic_long_t gts_free;
46800 - atomic_long_t gms_alloc;
46801 - atomic_long_t gms_free;
46802 - atomic_long_t gts_double_allocate;
46803 - atomic_long_t assign_context;
46804 - atomic_long_t assign_context_failed;
46805 - atomic_long_t free_context;
46806 - atomic_long_t load_user_context;
46807 - atomic_long_t load_kernel_context;
46808 - atomic_long_t lock_kernel_context;
46809 - atomic_long_t unlock_kernel_context;
46810 - atomic_long_t steal_user_context;
46811 - atomic_long_t steal_kernel_context;
46812 - atomic_long_t steal_context_failed;
46813 - atomic_long_t nopfn;
46814 - atomic_long_t asid_new;
46815 - atomic_long_t asid_next;
46816 - atomic_long_t asid_wrap;
46817 - atomic_long_t asid_reuse;
46818 - atomic_long_t intr;
46819 - atomic_long_t intr_cbr;
46820 - atomic_long_t intr_tfh;
46821 - atomic_long_t intr_spurious;
46822 - atomic_long_t intr_mm_lock_failed;
46823 - atomic_long_t call_os;
46824 - atomic_long_t call_os_wait_queue;
46825 - atomic_long_t user_flush_tlb;
46826 - atomic_long_t user_unload_context;
46827 - atomic_long_t user_exception;
46828 - atomic_long_t set_context_option;
46829 - atomic_long_t check_context_retarget_intr;
46830 - atomic_long_t check_context_unload;
46831 - atomic_long_t tlb_dropin;
46832 - atomic_long_t tlb_preload_page;
46833 - atomic_long_t tlb_dropin_fail_no_asid;
46834 - atomic_long_t tlb_dropin_fail_upm;
46835 - atomic_long_t tlb_dropin_fail_invalid;
46836 - atomic_long_t tlb_dropin_fail_range_active;
46837 - atomic_long_t tlb_dropin_fail_idle;
46838 - atomic_long_t tlb_dropin_fail_fmm;
46839 - atomic_long_t tlb_dropin_fail_no_exception;
46840 - atomic_long_t tfh_stale_on_fault;
46841 - atomic_long_t mmu_invalidate_range;
46842 - atomic_long_t mmu_invalidate_page;
46843 - atomic_long_t flush_tlb;
46844 - atomic_long_t flush_tlb_gru;
46845 - atomic_long_t flush_tlb_gru_tgh;
46846 - atomic_long_t flush_tlb_gru_zero_asid;
46847 + atomic_long_unchecked_t vdata_alloc;
46848 + atomic_long_unchecked_t vdata_free;
46849 + atomic_long_unchecked_t gts_alloc;
46850 + atomic_long_unchecked_t gts_free;
46851 + atomic_long_unchecked_t gms_alloc;
46852 + atomic_long_unchecked_t gms_free;
46853 + atomic_long_unchecked_t gts_double_allocate;
46854 + atomic_long_unchecked_t assign_context;
46855 + atomic_long_unchecked_t assign_context_failed;
46856 + atomic_long_unchecked_t free_context;
46857 + atomic_long_unchecked_t load_user_context;
46858 + atomic_long_unchecked_t load_kernel_context;
46859 + atomic_long_unchecked_t lock_kernel_context;
46860 + atomic_long_unchecked_t unlock_kernel_context;
46861 + atomic_long_unchecked_t steal_user_context;
46862 + atomic_long_unchecked_t steal_kernel_context;
46863 + atomic_long_unchecked_t steal_context_failed;
46864 + atomic_long_unchecked_t nopfn;
46865 + atomic_long_unchecked_t asid_new;
46866 + atomic_long_unchecked_t asid_next;
46867 + atomic_long_unchecked_t asid_wrap;
46868 + atomic_long_unchecked_t asid_reuse;
46869 + atomic_long_unchecked_t intr;
46870 + atomic_long_unchecked_t intr_cbr;
46871 + atomic_long_unchecked_t intr_tfh;
46872 + atomic_long_unchecked_t intr_spurious;
46873 + atomic_long_unchecked_t intr_mm_lock_failed;
46874 + atomic_long_unchecked_t call_os;
46875 + atomic_long_unchecked_t call_os_wait_queue;
46876 + atomic_long_unchecked_t user_flush_tlb;
46877 + atomic_long_unchecked_t user_unload_context;
46878 + atomic_long_unchecked_t user_exception;
46879 + atomic_long_unchecked_t set_context_option;
46880 + atomic_long_unchecked_t check_context_retarget_intr;
46881 + atomic_long_unchecked_t check_context_unload;
46882 + atomic_long_unchecked_t tlb_dropin;
46883 + atomic_long_unchecked_t tlb_preload_page;
46884 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46885 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46886 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46887 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46888 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46889 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46890 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46891 + atomic_long_unchecked_t tfh_stale_on_fault;
46892 + atomic_long_unchecked_t mmu_invalidate_range;
46893 + atomic_long_unchecked_t mmu_invalidate_page;
46894 + atomic_long_unchecked_t flush_tlb;
46895 + atomic_long_unchecked_t flush_tlb_gru;
46896 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46897 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46898
46899 - atomic_long_t copy_gpa;
46900 - atomic_long_t read_gpa;
46901 + atomic_long_unchecked_t copy_gpa;
46902 + atomic_long_unchecked_t read_gpa;
46903
46904 - atomic_long_t mesq_receive;
46905 - atomic_long_t mesq_receive_none;
46906 - atomic_long_t mesq_send;
46907 - atomic_long_t mesq_send_failed;
46908 - atomic_long_t mesq_noop;
46909 - atomic_long_t mesq_send_unexpected_error;
46910 - atomic_long_t mesq_send_lb_overflow;
46911 - atomic_long_t mesq_send_qlimit_reached;
46912 - atomic_long_t mesq_send_amo_nacked;
46913 - atomic_long_t mesq_send_put_nacked;
46914 - atomic_long_t mesq_page_overflow;
46915 - atomic_long_t mesq_qf_locked;
46916 - atomic_long_t mesq_qf_noop_not_full;
46917 - atomic_long_t mesq_qf_switch_head_failed;
46918 - atomic_long_t mesq_qf_unexpected_error;
46919 - atomic_long_t mesq_noop_unexpected_error;
46920 - atomic_long_t mesq_noop_lb_overflow;
46921 - atomic_long_t mesq_noop_qlimit_reached;
46922 - atomic_long_t mesq_noop_amo_nacked;
46923 - atomic_long_t mesq_noop_put_nacked;
46924 - atomic_long_t mesq_noop_page_overflow;
46925 + atomic_long_unchecked_t mesq_receive;
46926 + atomic_long_unchecked_t mesq_receive_none;
46927 + atomic_long_unchecked_t mesq_send;
46928 + atomic_long_unchecked_t mesq_send_failed;
46929 + atomic_long_unchecked_t mesq_noop;
46930 + atomic_long_unchecked_t mesq_send_unexpected_error;
46931 + atomic_long_unchecked_t mesq_send_lb_overflow;
46932 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46933 + atomic_long_unchecked_t mesq_send_amo_nacked;
46934 + atomic_long_unchecked_t mesq_send_put_nacked;
46935 + atomic_long_unchecked_t mesq_page_overflow;
46936 + atomic_long_unchecked_t mesq_qf_locked;
46937 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46938 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46939 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46940 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46941 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46942 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46943 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46944 + atomic_long_unchecked_t mesq_noop_put_nacked;
46945 + atomic_long_unchecked_t mesq_noop_page_overflow;
46946
46947 };
46948
46949 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46950 tghop_invalidate, mcsop_last};
46951
46952 struct mcs_op_statistic {
46953 - atomic_long_t count;
46954 - atomic_long_t total;
46955 + atomic_long_unchecked_t count;
46956 + atomic_long_unchecked_t total;
46957 unsigned long max;
46958 };
46959
46960 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46961
46962 #define STAT(id) do { \
46963 if (gru_options & OPT_STATS) \
46964 - atomic_long_inc(&gru_stats.id); \
46965 + atomic_long_inc_unchecked(&gru_stats.id); \
46966 } while (0)
46967
46968 #ifdef CONFIG_SGI_GRU_DEBUG
46969 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46970 index c862cd4..0d176fe 100644
46971 --- a/drivers/misc/sgi-xp/xp.h
46972 +++ b/drivers/misc/sgi-xp/xp.h
46973 @@ -288,7 +288,7 @@ struct xpc_interface {
46974 xpc_notify_func, void *);
46975 void (*received) (short, int, void *);
46976 enum xp_retval (*partid_to_nasids) (short, void *);
46977 -};
46978 +} __no_const;
46979
46980 extern struct xpc_interface xpc_interface;
46981
46982 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46983 index 01be66d..e3a0c7e 100644
46984 --- a/drivers/misc/sgi-xp/xp_main.c
46985 +++ b/drivers/misc/sgi-xp/xp_main.c
46986 @@ -78,13 +78,13 @@ xpc_notloaded(void)
46987 }
46988
46989 struct xpc_interface xpc_interface = {
46990 - (void (*)(int))xpc_notloaded,
46991 - (void (*)(int))xpc_notloaded,
46992 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46993 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46994 + .connect = (void (*)(int))xpc_notloaded,
46995 + .disconnect = (void (*)(int))xpc_notloaded,
46996 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46997 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46998 void *))xpc_notloaded,
46999 - (void (*)(short, int, void *))xpc_notloaded,
47000 - (enum xp_retval(*)(short, void *))xpc_notloaded
47001 + .received = (void (*)(short, int, void *))xpc_notloaded,
47002 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47003 };
47004 EXPORT_SYMBOL_GPL(xpc_interface);
47005
47006 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47007 index b94d5f7..7f494c5 100644
47008 --- a/drivers/misc/sgi-xp/xpc.h
47009 +++ b/drivers/misc/sgi-xp/xpc.h
47010 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47011 void (*received_payload) (struct xpc_channel *, void *);
47012 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47013 };
47014 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47015
47016 /* struct xpc_partition act_state values (for XPC HB) */
47017
47018 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47019 /* found in xpc_main.c */
47020 extern struct device *xpc_part;
47021 extern struct device *xpc_chan;
47022 -extern struct xpc_arch_operations xpc_arch_ops;
47023 +extern xpc_arch_operations_no_const xpc_arch_ops;
47024 extern int xpc_disengage_timelimit;
47025 extern int xpc_disengage_timedout;
47026 extern int xpc_activate_IRQ_rcvd;
47027 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47028 index 82dc574..8539ab2 100644
47029 --- a/drivers/misc/sgi-xp/xpc_main.c
47030 +++ b/drivers/misc/sgi-xp/xpc_main.c
47031 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47032 .notifier_call = xpc_system_die,
47033 };
47034
47035 -struct xpc_arch_operations xpc_arch_ops;
47036 +xpc_arch_operations_no_const xpc_arch_ops;
47037
47038 /*
47039 * Timer function to enforce the timelimit on the partition disengage.
47040 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47041
47042 if (((die_args->trapnr == X86_TRAP_MF) ||
47043 (die_args->trapnr == X86_TRAP_XF)) &&
47044 - !user_mode_vm(die_args->regs))
47045 + !user_mode(die_args->regs))
47046 xpc_die_deactivate();
47047
47048 break;
47049 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47050 index a11451f..9e1bbad 100644
47051 --- a/drivers/mmc/card/block.c
47052 +++ b/drivers/mmc/card/block.c
47053 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47054 if (idata->ic.postsleep_min_us)
47055 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47056
47057 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47058 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47059 err = -EFAULT;
47060 goto cmd_rel_host;
47061 }
47062 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47063 index 7911e05..d0f9dda 100644
47064 --- a/drivers/mmc/core/mmc_ops.c
47065 +++ b/drivers/mmc/core/mmc_ops.c
47066 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47067 void *data_buf;
47068 int is_on_stack;
47069
47070 - is_on_stack = object_is_on_stack(buf);
47071 + is_on_stack = object_starts_on_stack(buf);
47072 if (is_on_stack) {
47073 /*
47074 * dma onto stack is unsafe/nonportable, but callers to this
47075 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47076 index 01b99e8..5c325e3 100644
47077 --- a/drivers/mmc/host/dw_mmc.h
47078 +++ b/drivers/mmc/host/dw_mmc.h
47079 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47080 int (*parse_dt)(struct dw_mci *host);
47081 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47082 struct dw_mci_tuning_data *tuning_data);
47083 -};
47084 +} __do_const;
47085 #endif /* _DW_MMC_H_ */
47086 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47087 index 43af791..86f4c48 100644
47088 --- a/drivers/mmc/host/mmci.c
47089 +++ b/drivers/mmc/host/mmci.c
47090 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47091 mmc->caps |= MMC_CAP_CMD23;
47092
47093 if (variant->busy_detect) {
47094 - mmci_ops.card_busy = mmci_card_busy;
47095 + pax_open_kernel();
47096 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47097 + pax_close_kernel();
47098 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47099 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47100 mmc->max_busy_timeout = 0;
47101 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47102 index 9c2b9cb..cebb09a 100644
47103 --- a/drivers/mmc/host/omap_hsmmc.c
47104 +++ b/drivers/mmc/host/omap_hsmmc.c
47105 @@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47106
47107 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47108 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47109 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47110 + pax_open_kernel();
47111 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47112 + pax_close_kernel();
47113 }
47114
47115 pm_runtime_enable(host->dev);
47116 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47117 index 587ee0e..b3bbcab 100644
47118 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47119 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47120 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47121 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47122 }
47123
47124 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47125 - sdhci_esdhc_ops.platform_execute_tuning =
47126 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47127 + pax_open_kernel();
47128 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47129 esdhc_executing_tuning;
47130 + pax_close_kernel();
47131 + }
47132
47133 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47134 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47135 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47136 index 0ce6eb1..8dcce1b 100644
47137 --- a/drivers/mmc/host/sdhci-s3c.c
47138 +++ b/drivers/mmc/host/sdhci-s3c.c
47139 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47140 * we can use overriding functions instead of default.
47141 */
47142 if (sc->no_divider) {
47143 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47144 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47145 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47146 + pax_open_kernel();
47147 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47148 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47149 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47150 + pax_close_kernel();
47151 }
47152
47153 /* It supports additional host capabilities if needed */
47154 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47155 index 423666b..81ff5eb 100644
47156 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47157 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47158 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47159 size_t totlen = 0, thislen;
47160 int ret = 0;
47161 size_t buflen = 0;
47162 - static char *buffer;
47163 + char *buffer;
47164
47165 if (!ECCBUF_SIZE) {
47166 /* We should fall back to a general writev implementation.
47167 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47168 index b3b7ca1..5dd4634 100644
47169 --- a/drivers/mtd/nand/denali.c
47170 +++ b/drivers/mtd/nand/denali.c
47171 @@ -24,6 +24,7 @@
47172 #include <linux/slab.h>
47173 #include <linux/mtd/mtd.h>
47174 #include <linux/module.h>
47175 +#include <linux/slab.h>
47176
47177 #include "denali.h"
47178
47179 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47180 index 959cb9b..8520fe5 100644
47181 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47182 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47183 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47184
47185 /* first try to map the upper buffer directly */
47186 if (virt_addr_valid(this->upper_buf) &&
47187 - !object_is_on_stack(this->upper_buf)) {
47188 + !object_starts_on_stack(this->upper_buf)) {
47189 sg_init_one(sgl, this->upper_buf, this->upper_len);
47190 ret = dma_map_sg(this->dev, sgl, 1, dr);
47191 if (ret == 0)
47192 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47193 index 51b9d6a..52af9a7 100644
47194 --- a/drivers/mtd/nftlmount.c
47195 +++ b/drivers/mtd/nftlmount.c
47196 @@ -24,6 +24,7 @@
47197 #include <asm/errno.h>
47198 #include <linux/delay.h>
47199 #include <linux/slab.h>
47200 +#include <linux/sched.h>
47201 #include <linux/mtd/mtd.h>
47202 #include <linux/mtd/nand.h>
47203 #include <linux/mtd/nftl.h>
47204 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47205 index c23184a..4115c41 100644
47206 --- a/drivers/mtd/sm_ftl.c
47207 +++ b/drivers/mtd/sm_ftl.c
47208 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47209 #define SM_CIS_VENDOR_OFFSET 0x59
47210 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47211 {
47212 - struct attribute_group *attr_group;
47213 + attribute_group_no_const *attr_group;
47214 struct attribute **attributes;
47215 struct sm_sysfs_attribute *vendor_attribute;
47216 char *vendor;
47217 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47218 index a5115fb..81b03f6 100644
47219 --- a/drivers/net/bonding/bond_main.c
47220 +++ b/drivers/net/bonding/bond_main.c
47221 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47222 bond_dev_queue_xmit(bond, skb, slave->dev);
47223 } else {
47224 dev_kfree_skb_any(skb);
47225 - atomic_long_inc(&dev->tx_dropped);
47226 + atomic_long_inc_unchecked(&dev->tx_dropped);
47227 }
47228
47229 return NETDEV_TX_OK;
47230 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47231 index 45f09a6..f154f8d 100644
47232 --- a/drivers/net/bonding/bond_netlink.c
47233 +++ b/drivers/net/bonding/bond_netlink.c
47234 @@ -585,7 +585,7 @@ nla_put_failure:
47235 return -EMSGSIZE;
47236 }
47237
47238 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47239 +struct rtnl_link_ops bond_link_ops = {
47240 .kind = "bond",
47241 .priv_size = sizeof(struct bonding),
47242 .setup = bond_setup,
47243 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47244 index 5e40a8b..126bfda 100644
47245 --- a/drivers/net/caif/caif_hsi.c
47246 +++ b/drivers/net/caif/caif_hsi.c
47247 @@ -1445,7 +1445,7 @@ err:
47248 return -ENODEV;
47249 }
47250
47251 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47252 +static struct rtnl_link_ops caif_hsi_link_ops = {
47253 .kind = "cfhsi",
47254 .priv_size = sizeof(struct cfhsi),
47255 .setup = cfhsi_setup,
47256 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47257 index 98d73aa..63ef9da 100644
47258 --- a/drivers/net/can/Kconfig
47259 +++ b/drivers/net/can/Kconfig
47260 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47261
47262 config CAN_FLEXCAN
47263 tristate "Support for Freescale FLEXCAN based chips"
47264 - depends on ARM || PPC
47265 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47266 ---help---
47267 Say Y here if you want to support for Freescale FlexCAN.
47268
47269 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47270 index 4b008c9..2b1151f 100644
47271 --- a/drivers/net/can/dev.c
47272 +++ b/drivers/net/can/dev.c
47273 @@ -872,7 +872,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47274 return -EOPNOTSUPP;
47275 }
47276
47277 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47278 +static struct rtnl_link_ops can_link_ops = {
47279 .kind = "can",
47280 .maxtype = IFLA_CAN_MAX,
47281 .policy = can_policy,
47282 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47283 index 4e94057..32032ff 100644
47284 --- a/drivers/net/can/vcan.c
47285 +++ b/drivers/net/can/vcan.c
47286 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47287 dev->destructor = free_netdev;
47288 }
47289
47290 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47291 +static struct rtnl_link_ops vcan_link_ops = {
47292 .kind = "vcan",
47293 .setup = vcan_setup,
47294 };
47295 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47296 index ff435fb..d408b1f 100644
47297 --- a/drivers/net/dummy.c
47298 +++ b/drivers/net/dummy.c
47299 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47300 return 0;
47301 }
47302
47303 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47304 +static struct rtnl_link_ops dummy_link_ops = {
47305 .kind = "dummy",
47306 .setup = dummy_setup,
47307 .validate = dummy_validate,
47308 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47309 index 1d162cc..b546a75 100644
47310 --- a/drivers/net/ethernet/8390/ax88796.c
47311 +++ b/drivers/net/ethernet/8390/ax88796.c
47312 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47313 if (ax->plat->reg_offsets)
47314 ei_local->reg_offset = ax->plat->reg_offsets;
47315 else {
47316 + resource_size_t _mem_size = mem_size;
47317 + do_div(_mem_size, 0x18);
47318 ei_local->reg_offset = ax->reg_offsets;
47319 for (ret = 0; ret < 0x18; ret++)
47320 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47321 + ax->reg_offsets[ret] = _mem_size * ret;
47322 }
47323
47324 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47325 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47326 index 4efc435..4ab9e14 100644
47327 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47328 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47329 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47330 return 0;
47331 }
47332
47333 -static struct net_device_ops altera_tse_netdev_ops = {
47334 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47335 .ndo_open = tse_open,
47336 .ndo_stop = tse_shutdown,
47337 .ndo_start_xmit = tse_start_xmit,
47338 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47339 ndev->netdev_ops = &altera_tse_netdev_ops;
47340 altera_tse_set_ethtool_ops(ndev);
47341
47342 + pax_open_kernel();
47343 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47344
47345 if (priv->hash_filter)
47346 altera_tse_netdev_ops.ndo_set_rx_mode =
47347 tse_set_rx_mode_hashfilter;
47348 + pax_close_kernel();
47349
47350 /* Scatter/gather IO is not supported,
47351 * so it is turned off
47352 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47353 index caade30..3e257d9 100644
47354 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47355 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47356 @@ -1072,14 +1072,14 @@ do { \
47357 * operations, everything works on mask values.
47358 */
47359 #define XMDIO_READ(_pdata, _mmd, _reg) \
47360 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47361 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47362 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47363
47364 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47365 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47366
47367 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47368 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47369 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47370 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47371
47372 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47373 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47374 index 8a50b01..39c1ad0 100644
47375 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47376 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47377 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47378
47379 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47380
47381 - pdata->hw_if.config_dcb_tc(pdata);
47382 + pdata->hw_if->config_dcb_tc(pdata);
47383
47384 return 0;
47385 }
47386 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47387
47388 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47389
47390 - pdata->hw_if.config_dcb_pfc(pdata);
47391 + pdata->hw_if->config_dcb_pfc(pdata);
47392
47393 return 0;
47394 }
47395 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47396 index 6fc5da0..61ac2cb 100644
47397 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47398 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47399 @@ -235,7 +235,7 @@ err_ring:
47400
47401 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47402 {
47403 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47404 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47405 struct xgbe_channel *channel;
47406 struct xgbe_ring *ring;
47407 struct xgbe_ring_data *rdata;
47408 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47409
47410 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47411 {
47412 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47413 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47414 struct xgbe_channel *channel;
47415 struct xgbe_ring *ring;
47416 struct xgbe_ring_desc *rdesc;
47417 @@ -505,7 +505,7 @@ err_out:
47418 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47419 {
47420 struct xgbe_prv_data *pdata = channel->pdata;
47421 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47422 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47423 struct xgbe_ring *ring = channel->rx_ring;
47424 struct xgbe_ring_data *rdata;
47425 struct sk_buff *skb = NULL;
47426 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47427 DBGPR("<--xgbe_realloc_skb\n");
47428 }
47429
47430 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47431 -{
47432 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47433 -
47434 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47435 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47436 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47437 - desc_if->realloc_skb = xgbe_realloc_skb;
47438 - desc_if->unmap_skb = xgbe_unmap_skb;
47439 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47440 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47441 -
47442 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47443 -}
47444 +const struct xgbe_desc_if default_xgbe_desc_if = {
47445 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47446 + .free_ring_resources = xgbe_free_ring_resources,
47447 + .map_tx_skb = xgbe_map_tx_skb,
47448 + .realloc_skb = xgbe_realloc_skb,
47449 + .unmap_skb = xgbe_unmap_skb,
47450 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47451 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47452 +};
47453 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47454 index 9da3a03..022f15c 100644
47455 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47456 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47457 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47458
47459 static int xgbe_init(struct xgbe_prv_data *pdata)
47460 {
47461 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47462 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47463 int ret;
47464
47465 DBGPR("-->xgbe_init\n");
47466 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47467 return 0;
47468 }
47469
47470 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47471 -{
47472 - DBGPR("-->xgbe_init_function_ptrs\n");
47473 -
47474 - hw_if->tx_complete = xgbe_tx_complete;
47475 -
47476 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47477 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47478 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47479 - hw_if->set_mac_address = xgbe_set_mac_address;
47480 -
47481 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47482 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47483 -
47484 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47485 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47486 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47487 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47488 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47489 -
47490 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47491 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47492 -
47493 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47494 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47495 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47496 -
47497 - hw_if->enable_tx = xgbe_enable_tx;
47498 - hw_if->disable_tx = xgbe_disable_tx;
47499 - hw_if->enable_rx = xgbe_enable_rx;
47500 - hw_if->disable_rx = xgbe_disable_rx;
47501 -
47502 - hw_if->powerup_tx = xgbe_powerup_tx;
47503 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47504 - hw_if->powerup_rx = xgbe_powerup_rx;
47505 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47506 -
47507 - hw_if->pre_xmit = xgbe_pre_xmit;
47508 - hw_if->dev_read = xgbe_dev_read;
47509 - hw_if->enable_int = xgbe_enable_int;
47510 - hw_if->disable_int = xgbe_disable_int;
47511 - hw_if->init = xgbe_init;
47512 - hw_if->exit = xgbe_exit;
47513 +const struct xgbe_hw_if default_xgbe_hw_if = {
47514 + .tx_complete = xgbe_tx_complete,
47515 +
47516 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47517 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47518 + .add_mac_addresses = xgbe_add_mac_addresses,
47519 + .set_mac_address = xgbe_set_mac_address,
47520 +
47521 + .enable_rx_csum = xgbe_enable_rx_csum,
47522 + .disable_rx_csum = xgbe_disable_rx_csum,
47523 +
47524 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47525 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47526 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47527 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47528 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47529 +
47530 + .read_mmd_regs = xgbe_read_mmd_regs,
47531 + .write_mmd_regs = xgbe_write_mmd_regs,
47532 +
47533 + .set_gmii_speed = xgbe_set_gmii_speed,
47534 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47535 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47536 +
47537 + .enable_tx = xgbe_enable_tx,
47538 + .disable_tx = xgbe_disable_tx,
47539 + .enable_rx = xgbe_enable_rx,
47540 + .disable_rx = xgbe_disable_rx,
47541 +
47542 + .powerup_tx = xgbe_powerup_tx,
47543 + .powerdown_tx = xgbe_powerdown_tx,
47544 + .powerup_rx = xgbe_powerup_rx,
47545 + .powerdown_rx = xgbe_powerdown_rx,
47546 +
47547 + .pre_xmit = xgbe_pre_xmit,
47548 + .dev_read = xgbe_dev_read,
47549 + .enable_int = xgbe_enable_int,
47550 + .disable_int = xgbe_disable_int,
47551 + .init = xgbe_init,
47552 + .exit = xgbe_exit,
47553
47554 /* Descriptor related Sequences have to be initialized here */
47555 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47556 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47557 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47558 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47559 - hw_if->is_last_desc = xgbe_is_last_desc;
47560 - hw_if->is_context_desc = xgbe_is_context_desc;
47561 + .tx_desc_init = xgbe_tx_desc_init,
47562 + .rx_desc_init = xgbe_rx_desc_init,
47563 + .tx_desc_reset = xgbe_tx_desc_reset,
47564 + .rx_desc_reset = xgbe_rx_desc_reset,
47565 + .is_last_desc = xgbe_is_last_desc,
47566 + .is_context_desc = xgbe_is_context_desc,
47567
47568 /* For FLOW ctrl */
47569 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47570 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47571 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47572 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47573
47574 /* For RX coalescing */
47575 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47576 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47577 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47578 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47579 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47580 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47581 + .usec_to_riwt = xgbe_usec_to_riwt,
47582 + .riwt_to_usec = xgbe_riwt_to_usec,
47583
47584 /* For RX and TX threshold config */
47585 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47586 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47587 + .config_rx_threshold = xgbe_config_rx_threshold,
47588 + .config_tx_threshold = xgbe_config_tx_threshold,
47589
47590 /* For RX and TX Store and Forward Mode config */
47591 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47592 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47593 + .config_rsf_mode = xgbe_config_rsf_mode,
47594 + .config_tsf_mode = xgbe_config_tsf_mode,
47595
47596 /* For TX DMA Operating on Second Frame config */
47597 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47598 + .config_osp_mode = xgbe_config_osp_mode,
47599
47600 /* For RX and TX PBL config */
47601 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47602 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47603 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47604 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47605 - hw_if->config_pblx8 = xgbe_config_pblx8;
47606 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47607 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47608 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47609 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47610 + .config_pblx8 = xgbe_config_pblx8,
47611
47612 /* For MMC statistics support */
47613 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47614 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47615 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47616 + .tx_mmc_int = xgbe_tx_mmc_int,
47617 + .rx_mmc_int = xgbe_rx_mmc_int,
47618 + .read_mmc_stats = xgbe_read_mmc_stats,
47619
47620 /* For PTP config */
47621 - hw_if->config_tstamp = xgbe_config_tstamp;
47622 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47623 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47624 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47625 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47626 + .config_tstamp = xgbe_config_tstamp,
47627 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47628 + .set_tstamp_time = xgbe_set_tstamp_time,
47629 + .get_tstamp_time = xgbe_get_tstamp_time,
47630 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47631
47632 /* For Data Center Bridging config */
47633 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47634 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47635 -
47636 - DBGPR("<--xgbe_init_function_ptrs\n");
47637 -}
47638 + .config_dcb_tc = xgbe_config_dcb_tc,
47639 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47640 +};
47641 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47642 index 2349ea9..a83a677 100644
47643 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47644 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47645 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47646
47647 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47648 {
47649 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47650 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47651 struct xgbe_channel *channel;
47652 enum xgbe_int int_id;
47653 unsigned int i;
47654 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47655
47656 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47657 {
47658 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47659 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47660 struct xgbe_channel *channel;
47661 enum xgbe_int int_id;
47662 unsigned int i;
47663 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47664 static irqreturn_t xgbe_isr(int irq, void *data)
47665 {
47666 struct xgbe_prv_data *pdata = data;
47667 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47668 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47669 struct xgbe_channel *channel;
47670 unsigned int dma_isr, dma_ch_isr;
47671 unsigned int mac_isr, mac_tssr;
47672 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47673
47674 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47675 {
47676 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47677 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47678
47679 DBGPR("-->xgbe_init_tx_coalesce\n");
47680
47681 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47682
47683 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47684 {
47685 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47686 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47687
47688 DBGPR("-->xgbe_init_rx_coalesce\n");
47689
47690 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47691
47692 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47693 {
47694 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47695 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47696 struct xgbe_channel *channel;
47697 struct xgbe_ring *ring;
47698 struct xgbe_ring_data *rdata;
47699 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47700
47701 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47702 {
47703 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47704 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47705 struct xgbe_channel *channel;
47706 struct xgbe_ring *ring;
47707 struct xgbe_ring_data *rdata;
47708 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47709 static void xgbe_adjust_link(struct net_device *netdev)
47710 {
47711 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47712 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47713 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47714 struct phy_device *phydev = pdata->phydev;
47715 int new_state = 0;
47716
47717 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47718 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47719 {
47720 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47721 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47722 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47723 unsigned long flags;
47724
47725 DBGPR("-->xgbe_powerdown\n");
47726 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47727 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47728 {
47729 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47730 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47731 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47732 unsigned long flags;
47733
47734 DBGPR("-->xgbe_powerup\n");
47735 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47736
47737 static int xgbe_start(struct xgbe_prv_data *pdata)
47738 {
47739 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47740 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47741 struct net_device *netdev = pdata->netdev;
47742
47743 DBGPR("-->xgbe_start\n");
47744 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47745
47746 static void xgbe_stop(struct xgbe_prv_data *pdata)
47747 {
47748 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47749 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47750 struct net_device *netdev = pdata->netdev;
47751
47752 DBGPR("-->xgbe_stop\n");
47753 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47754
47755 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47756 {
47757 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47758 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47759
47760 DBGPR("-->xgbe_restart_dev\n");
47761
47762 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47763 return -ERANGE;
47764 }
47765
47766 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47767 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47768
47769 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47770
47771 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47772 static int xgbe_open(struct net_device *netdev)
47773 {
47774 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47775 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47776 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47777 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47778 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47779 int ret;
47780
47781 DBGPR("-->xgbe_open\n");
47782 @@ -1170,8 +1170,8 @@ err_phy_init:
47783 static int xgbe_close(struct net_device *netdev)
47784 {
47785 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47786 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47787 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47788 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47789 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47790
47791 DBGPR("-->xgbe_close\n");
47792
47793 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47794 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47795 {
47796 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47797 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47798 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47799 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47800 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47801 struct xgbe_channel *channel;
47802 struct xgbe_ring *ring;
47803 struct xgbe_packet_data *packet;
47804 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47805 static void xgbe_set_rx_mode(struct net_device *netdev)
47806 {
47807 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47808 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47809 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47810 unsigned int pr_mode, am_mode;
47811
47812 DBGPR("-->xgbe_set_rx_mode\n");
47813 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47814 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47815 {
47816 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47817 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47818 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47819 struct sockaddr *saddr = addr;
47820
47821 DBGPR("-->xgbe_set_mac_address\n");
47822 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47823
47824 DBGPR("-->%s\n", __func__);
47825
47826 - pdata->hw_if.read_mmc_stats(pdata);
47827 + pdata->hw_if->read_mmc_stats(pdata);
47828
47829 s->rx_packets = pstats->rxframecount_gb;
47830 s->rx_bytes = pstats->rxoctetcount_gb;
47831 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47832 u16 vid)
47833 {
47834 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47835 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47836 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47837
47838 DBGPR("-->%s\n", __func__);
47839
47840 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47841 u16 vid)
47842 {
47843 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47844 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47845 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47846
47847 DBGPR("-->%s\n", __func__);
47848
47849 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47850 netdev_features_t features)
47851 {
47852 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47853 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47854 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47855 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47856
47857 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47858 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47859 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47860 {
47861 struct xgbe_prv_data *pdata = channel->pdata;
47862 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47863 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47864 struct xgbe_ring *ring = channel->rx_ring;
47865 struct xgbe_ring_data *rdata;
47866
47867 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47868 static int xgbe_tx_poll(struct xgbe_channel *channel)
47869 {
47870 struct xgbe_prv_data *pdata = channel->pdata;
47871 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47872 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47873 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47874 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47875 struct xgbe_ring *ring = channel->tx_ring;
47876 struct xgbe_ring_data *rdata;
47877 struct xgbe_ring_desc *rdesc;
47878 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47879 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47880 {
47881 struct xgbe_prv_data *pdata = channel->pdata;
47882 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47883 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47884 struct xgbe_ring *ring = channel->rx_ring;
47885 struct xgbe_ring_data *rdata;
47886 struct xgbe_packet_data *packet;
47887 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47888 index 49508ec..2617cca 100644
47889 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47890 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47891 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47892
47893 DBGPR("-->%s\n", __func__);
47894
47895 - pdata->hw_if.read_mmc_stats(pdata);
47896 + pdata->hw_if->read_mmc_stats(pdata);
47897 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47898 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47899 *data++ = *(u64 *)stat;
47900 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47901 struct ethtool_coalesce *ec)
47902 {
47903 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47904 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47905 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47906 unsigned int riwt;
47907
47908 DBGPR("-->xgbe_get_coalesce\n");
47909 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47910 struct ethtool_coalesce *ec)
47911 {
47912 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47913 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47914 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47915 unsigned int rx_frames, rx_riwt, rx_usecs;
47916 unsigned int tx_frames, tx_usecs;
47917
47918 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47919 index f5a8fa0..0bb58ff 100644
47920 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47921 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47922 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47923 DBGPR("<--xgbe_default_config\n");
47924 }
47925
47926 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47927 -{
47928 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47929 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47930 -}
47931 -
47932 static int xgbe_probe(struct platform_device *pdev)
47933 {
47934 struct xgbe_prv_data *pdata;
47935 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47936 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47937
47938 /* Set all the function pointers */
47939 - xgbe_init_all_fptrs(pdata);
47940 - hw_if = &pdata->hw_if;
47941 - desc_if = &pdata->desc_if;
47942 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47943 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47944
47945 /* Issue software reset to device */
47946 hw_if->exit(pdata);
47947 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47948 index 363b210..b241389 100644
47949 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47950 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47951 @@ -126,7 +126,7 @@
47952 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47953 {
47954 struct xgbe_prv_data *pdata = mii->priv;
47955 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47956 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47957 int mmd_data;
47958
47959 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47960 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47961 u16 mmd_val)
47962 {
47963 struct xgbe_prv_data *pdata = mii->priv;
47964 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47965 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47966 int mmd_data = mmd_val;
47967
47968 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47969 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47970 index a1bf9d1c..84adcab 100644
47971 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47972 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47973 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47974 tstamp_cc);
47975 u64 nsec;
47976
47977 - nsec = pdata->hw_if.get_tstamp_time(pdata);
47978 + nsec = pdata->hw_if->get_tstamp_time(pdata);
47979
47980 return nsec;
47981 }
47982 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47983
47984 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47985
47986 - pdata->hw_if.update_tstamp_addend(pdata, addend);
47987 + pdata->hw_if->update_tstamp_addend(pdata, addend);
47988
47989 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47990
47991 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47992 index 789957d..d7d0245 100644
47993 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47994 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47995 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
47996
47997 int irq_number;
47998
47999 - struct xgbe_hw_if hw_if;
48000 - struct xgbe_desc_if desc_if;
48001 + const struct xgbe_hw_if *hw_if;
48002 + const struct xgbe_desc_if *desc_if;
48003
48004 /* AXI DMA settings */
48005 unsigned int axdomain;
48006 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
48007 #endif
48008 };
48009
48010 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48011 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48012 +
48013 /* Function prototypes*/
48014
48015 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48016 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48017 index adcacda..fa6e0ae 100644
48018 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48019 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48020 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48021 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48022 {
48023 /* RX_MODE controlling object */
48024 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48025 + bnx2x_init_rx_mode_obj(bp);
48026
48027 /* multicast configuration controlling object */
48028 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48029 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48030 index 7bc2924..2112002 100644
48031 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48032 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48033 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48034 return rc;
48035 }
48036
48037 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48038 - struct bnx2x_rx_mode_obj *o)
48039 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48040 {
48041 if (CHIP_IS_E1x(bp)) {
48042 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48043 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48044 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48045 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48046 } else {
48047 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48048 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48049 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48050 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48051 }
48052 }
48053
48054 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48055 index e97275f..52e28bc 100644
48056 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48057 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48058 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48059
48060 /********************* RX MODE ****************/
48061
48062 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48063 - struct bnx2x_rx_mode_obj *o);
48064 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48065
48066 /**
48067 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48068 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48069 index 31c9f82..e65e986 100644
48070 --- a/drivers/net/ethernet/broadcom/tg3.h
48071 +++ b/drivers/net/ethernet/broadcom/tg3.h
48072 @@ -150,6 +150,7 @@
48073 #define CHIPREV_ID_5750_A0 0x4000
48074 #define CHIPREV_ID_5750_A1 0x4001
48075 #define CHIPREV_ID_5750_A3 0x4003
48076 +#define CHIPREV_ID_5750_C1 0x4201
48077 #define CHIPREV_ID_5750_C2 0x4202
48078 #define CHIPREV_ID_5752_A0_HW 0x5000
48079 #define CHIPREV_ID_5752_A0 0x6000
48080 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48081 index 903466e..b285864 100644
48082 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48083 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48084 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48085 }
48086
48087 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48088 - bna_cb_ioceth_enable,
48089 - bna_cb_ioceth_disable,
48090 - bna_cb_ioceth_hbfail,
48091 - bna_cb_ioceth_reset
48092 + .enable_cbfn = bna_cb_ioceth_enable,
48093 + .disable_cbfn = bna_cb_ioceth_disable,
48094 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48095 + .reset_cbfn = bna_cb_ioceth_reset
48096 };
48097
48098 static void bna_attr_init(struct bna_ioceth *ioceth)
48099 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48100 index 8cffcdf..aadf043 100644
48101 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48102 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48103 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48104 */
48105 struct l2t_skb_cb {
48106 arp_failure_handler_func arp_failure_handler;
48107 -};
48108 +} __no_const;
48109
48110 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48111
48112 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48113 index 279873c..11e1921 100644
48114 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48115 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48116 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48117
48118 int i;
48119 struct adapter *ap = netdev2adap(dev);
48120 - static const unsigned int *reg_ranges;
48121 + const unsigned int *reg_ranges;
48122 int arr_size = 0, buf_size = 0;
48123
48124 if (is_t4(ap->params.chip)) {
48125 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48126 index cf8b6ff..274271e 100644
48127 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48128 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48129 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48130 for (i=0; i<ETH_ALEN; i++) {
48131 tmp.addr[i] = dev->dev_addr[i];
48132 }
48133 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48134 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48135 break;
48136
48137 case DE4X5_SET_HWADDR: /* Set the hardware address */
48138 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48139 spin_lock_irqsave(&lp->lock, flags);
48140 memcpy(&statbuf, &lp->pktStats, ioc->len);
48141 spin_unlock_irqrestore(&lp->lock, flags);
48142 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48143 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48144 return -EFAULT;
48145 break;
48146 }
48147 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48148 index d2975fa..8aaec07 100644
48149 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48150 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48151 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48152
48153 if (wrapped)
48154 newacc += 65536;
48155 - ACCESS_ONCE(*acc) = newacc;
48156 + ACCESS_ONCE_RW(*acc) = newacc;
48157 }
48158
48159 static void populate_erx_stats(struct be_adapter *adapter,
48160 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48161 index c77fa4a..7fd42fc 100644
48162 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48163 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48164 @@ -30,6 +30,8 @@
48165 #include <linux/netdevice.h>
48166 #include <linux/phy.h>
48167 #include <linux/platform_device.h>
48168 +#include <linux/interrupt.h>
48169 +#include <linux/irqreturn.h>
48170 #include <net/ip.h>
48171
48172 #include "ftgmac100.h"
48173 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48174 index 4ff1adc..0ea6bf4 100644
48175 --- a/drivers/net/ethernet/faraday/ftmac100.c
48176 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48177 @@ -31,6 +31,8 @@
48178 #include <linux/module.h>
48179 #include <linux/netdevice.h>
48180 #include <linux/platform_device.h>
48181 +#include <linux/interrupt.h>
48182 +#include <linux/irqreturn.h>
48183
48184 #include "ftmac100.h"
48185
48186 diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48187 index 76d7070..f6971182 100644
48188 --- a/drivers/net/ethernet/freescale/gianfar_ethtool.c
48189 +++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48190 @@ -1581,7 +1581,7 @@ static int gfar_write_filer_table(struct gfar_private *priv,
48191 return -EBUSY;
48192
48193 /* Fill regular entries */
48194 - for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
48195 + for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].prop);
48196 i++)
48197 gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
48198 /* Fill the rest with fall-troughs */
48199 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48200 index 537b621..07f87ce 100644
48201 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48202 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48203 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48204 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48205
48206 /* Update the base adjustement value. */
48207 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48208 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48209 smp_mb(); /* Force the above update. */
48210 }
48211
48212 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48213 index 5fd4b52..87aa34b 100644
48214 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48215 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48216 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48217 }
48218
48219 /* update the base incval used to calculate frequency adjustment */
48220 - ACCESS_ONCE(adapter->base_incval) = incval;
48221 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48222 smp_mb();
48223
48224 /* need lock to prevent incorrect read while modifying cyclecounter */
48225 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48226 index 11ff28b..375d659 100644
48227 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48228 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48229 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48230 wmb();
48231
48232 /* we want to dirty this cache line once */
48233 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48234 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48235 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48236 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48237
48238 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48239
48240 diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48241 index de10dbb..8b54f29 100644
48242 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48243 +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48244 @@ -233,7 +233,8 @@ do { \
48245 extern int mlx4_log_num_mgm_entry_size;
48246 extern int log_mtts_per_seg;
48247
48248 -#define MLX4_MAX_NUM_SLAVES (MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF)
48249 +#define MLX4_MAX_NUM_SLAVES (min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
48250 + MLX4_MFUNC_MAX))
48251 #define ALL_SLAVES 0xff
48252
48253 struct mlx4_bitmap {
48254 diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
48255 index f5e4b82..db0c7a9 100644
48256 --- a/drivers/net/ethernet/neterion/s2io.c
48257 +++ b/drivers/net/ethernet/neterion/s2io.c
48258 @@ -6987,7 +6987,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48259 if (sp->s2io_entries[i].in_use == MSIX_FLG) {
48260 if (sp->s2io_entries[i].type ==
48261 MSIX_RING_TYPE) {
48262 - sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
48263 + snprintf(sp->desc[i],
48264 + sizeof(sp->desc[i]),
48265 + "%s:MSI-X-%d-RX",
48266 dev->name, i);
48267 err = request_irq(sp->entries[i].vector,
48268 s2io_msix_ring_handle,
48269 @@ -6996,7 +6998,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48270 sp->s2io_entries[i].arg);
48271 } else if (sp->s2io_entries[i].type ==
48272 MSIX_ALARM_TYPE) {
48273 - sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
48274 + snprintf(sp->desc[i],
48275 + sizeof(sp->desc[i]),
48276 + "%s:MSI-X-%d-TX",
48277 dev->name, i);
48278 err = request_irq(sp->entries[i].vector,
48279 s2io_msix_fifo_handle,
48280 @@ -8154,7 +8158,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
48281 "%s: UDP Fragmentation Offload(UFO) enabled\n",
48282 dev->name);
48283 /* Initialize device name */
48284 - sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
48285 + snprintf(sp->name, sizeof(sp->name), "%s Neterion %s", dev->name,
48286 + sp->product_name);
48287
48288 if (vlan_tag_strip)
48289 sp->vlan_strip_flag = 1;
48290 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48291 index 2bbd01f..e8baa64 100644
48292 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48293 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48294 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48295 struct __vxge_hw_fifo *fifo;
48296 struct vxge_hw_fifo_config *config;
48297 u32 txdl_size, txdl_per_memblock;
48298 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48299 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48300 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48301 + };
48302 +
48303 struct __vxge_hw_virtualpath *vpath;
48304
48305 if ((vp == NULL) || (attr == NULL)) {
48306 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48307 goto exit;
48308 }
48309
48310 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48311 -
48312 fifo->mempool =
48313 __vxge_hw_mempool_create(vpath->hldev,
48314 fifo->config->memblock_size,
48315 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48316 index 2bb48d5..d1a865d 100644
48317 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48318 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48319 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48320 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48321 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48322 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48323 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48324 + pax_open_kernel();
48325 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48326 + pax_close_kernel();
48327 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48328 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48329 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48330 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48331 index be7d7a6..a8983f8 100644
48332 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48333 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48334 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48335 case QLCNIC_NON_PRIV_FUNC:
48336 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48337 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48338 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48339 + pax_open_kernel();
48340 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48341 + pax_close_kernel();
48342 break;
48343 case QLCNIC_PRIV_FUNC:
48344 ahw->op_mode = QLCNIC_PRIV_FUNC;
48345 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48346 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48347 + pax_open_kernel();
48348 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48349 + pax_close_kernel();
48350 break;
48351 case QLCNIC_MGMT_FUNC:
48352 ahw->op_mode = QLCNIC_MGMT_FUNC;
48353 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48354 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48355 + pax_open_kernel();
48356 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48357 + pax_close_kernel();
48358 break;
48359 default:
48360 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48361 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48362 index c9f57fb..208bdc1 100644
48363 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48364 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48365 @@ -1285,7 +1285,7 @@ flash_temp:
48366 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48367 {
48368 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48369 - static const struct qlcnic_dump_operations *fw_dump_ops;
48370 + const struct qlcnic_dump_operations *fw_dump_ops;
48371 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48372 u32 entry_offset, dump, no_entries, buf_offset = 0;
48373 int i, k, ops_cnt, ops_index, dump_size = 0;
48374 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48375 index cf154f7..c948d1b 100644
48376 --- a/drivers/net/ethernet/realtek/r8169.c
48377 +++ b/drivers/net/ethernet/realtek/r8169.c
48378 @@ -788,22 +788,22 @@ struct rtl8169_private {
48379 struct mdio_ops {
48380 void (*write)(struct rtl8169_private *, int, int);
48381 int (*read)(struct rtl8169_private *, int);
48382 - } mdio_ops;
48383 + } __no_const mdio_ops;
48384
48385 struct pll_power_ops {
48386 void (*down)(struct rtl8169_private *);
48387 void (*up)(struct rtl8169_private *);
48388 - } pll_power_ops;
48389 + } __no_const pll_power_ops;
48390
48391 struct jumbo_ops {
48392 void (*enable)(struct rtl8169_private *);
48393 void (*disable)(struct rtl8169_private *);
48394 - } jumbo_ops;
48395 + } __no_const jumbo_ops;
48396
48397 struct csi_ops {
48398 void (*write)(struct rtl8169_private *, int, int);
48399 u32 (*read)(struct rtl8169_private *, int);
48400 - } csi_ops;
48401 + } __no_const csi_ops;
48402
48403 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48404 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48405 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48406 index 6b861e3..204ac86 100644
48407 --- a/drivers/net/ethernet/sfc/ptp.c
48408 +++ b/drivers/net/ethernet/sfc/ptp.c
48409 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48410 ptp->start.dma_addr);
48411
48412 /* Clear flag that signals MC ready */
48413 - ACCESS_ONCE(*start) = 0;
48414 + ACCESS_ONCE_RW(*start) = 0;
48415 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48416 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48417 EFX_BUG_ON_PARANOID(rc);
48418 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48419 index 08c483b..2c4a553 100644
48420 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48421 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48422 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48423
48424 writel(value, ioaddr + MMC_CNTRL);
48425
48426 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48427 - MMC_CNTRL, value);
48428 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48429 +// MMC_CNTRL, value);
48430 }
48431
48432 /* To mask all all interrupts.*/
48433 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48434 index 2f48f79..8ae1a1a 100644
48435 --- a/drivers/net/hyperv/hyperv_net.h
48436 +++ b/drivers/net/hyperv/hyperv_net.h
48437 @@ -171,7 +171,7 @@ struct rndis_device {
48438 enum rndis_device_state state;
48439 bool link_state;
48440 bool link_change;
48441 - atomic_t new_req_id;
48442 + atomic_unchecked_t new_req_id;
48443
48444 spinlock_t request_lock;
48445 struct list_head req_list;
48446 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48447 index 2b86f0b..ecc996f 100644
48448 --- a/drivers/net/hyperv/rndis_filter.c
48449 +++ b/drivers/net/hyperv/rndis_filter.c
48450 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48451 * template
48452 */
48453 set = &rndis_msg->msg.set_req;
48454 - set->req_id = atomic_inc_return(&dev->new_req_id);
48455 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48456
48457 /* Add to the request list */
48458 spin_lock_irqsave(&dev->request_lock, flags);
48459 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48460
48461 /* Setup the rndis set */
48462 halt = &request->request_msg.msg.halt_req;
48463 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48464 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48465
48466 /* Ignore return since this msg is optional. */
48467 rndis_filter_send_request(dev, request);
48468 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48469 index 6cbc56a..5f7e6c8 100644
48470 --- a/drivers/net/ieee802154/fakehard.c
48471 +++ b/drivers/net/ieee802154/fakehard.c
48472 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48473 phy->transmit_power = 0xbf;
48474
48475 dev->netdev_ops = &fake_ops;
48476 - dev->ml_priv = &fake_mlme;
48477 + dev->ml_priv = (void *)&fake_mlme;
48478
48479 priv = netdev_priv(dev);
48480 priv->phy = phy;
48481 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48482 index 34f846b..4a0d5b1 100644
48483 --- a/drivers/net/ifb.c
48484 +++ b/drivers/net/ifb.c
48485 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48486 return 0;
48487 }
48488
48489 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48490 +static struct rtnl_link_ops ifb_link_ops = {
48491 .kind = "ifb",
48492 .priv_size = sizeof(struct ifb_private),
48493 .setup = ifb_setup,
48494 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48495 index bfb0b6e..5c396ce 100644
48496 --- a/drivers/net/macvlan.c
48497 +++ b/drivers/net/macvlan.c
48498 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48499 free_nskb:
48500 kfree_skb(nskb);
48501 err:
48502 - atomic_long_inc(&skb->dev->rx_dropped);
48503 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48504 }
48505
48506 static void macvlan_flush_sources(struct macvlan_port *port,
48507 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48508 int macvlan_link_register(struct rtnl_link_ops *ops)
48509 {
48510 /* common fields */
48511 - ops->priv_size = sizeof(struct macvlan_dev);
48512 - ops->validate = macvlan_validate;
48513 - ops->maxtype = IFLA_MACVLAN_MAX;
48514 - ops->policy = macvlan_policy;
48515 - ops->changelink = macvlan_changelink;
48516 - ops->get_size = macvlan_get_size;
48517 - ops->fill_info = macvlan_fill_info;
48518 + pax_open_kernel();
48519 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48520 + *(void **)&ops->validate = macvlan_validate;
48521 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48522 + *(const void **)&ops->policy = macvlan_policy;
48523 + *(void **)&ops->changelink = macvlan_changelink;
48524 + *(void **)&ops->get_size = macvlan_get_size;
48525 + *(void **)&ops->fill_info = macvlan_fill_info;
48526 + pax_close_kernel();
48527
48528 return rtnl_link_register(ops);
48529 };
48530 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48531 return NOTIFY_DONE;
48532 }
48533
48534 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48535 +static struct notifier_block macvlan_notifier_block = {
48536 .notifier_call = macvlan_device_event,
48537 };
48538
48539 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48540 index 880cc09..6a68ba6 100644
48541 --- a/drivers/net/macvtap.c
48542 +++ b/drivers/net/macvtap.c
48543 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48544 dev->tx_queue_len = TUN_READQ_SIZE;
48545 }
48546
48547 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48548 +static struct rtnl_link_ops macvtap_link_ops = {
48549 .kind = "macvtap",
48550 .setup = macvtap_setup,
48551 .newlink = macvtap_newlink,
48552 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48553 }
48554
48555 ret = 0;
48556 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48557 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48558 put_user(q->flags, &ifr->ifr_flags))
48559 ret = -EFAULT;
48560 macvtap_put_vlan(vlan);
48561 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48562 return NOTIFY_DONE;
48563 }
48564
48565 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48566 +static struct notifier_block macvtap_notifier_block = {
48567 .notifier_call = macvtap_device_event,
48568 };
48569
48570 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48571 index 34924df..a747360 100644
48572 --- a/drivers/net/nlmon.c
48573 +++ b/drivers/net/nlmon.c
48574 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48575 return 0;
48576 }
48577
48578 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48579 +static struct rtnl_link_ops nlmon_link_ops = {
48580 .kind = "nlmon",
48581 .priv_size = sizeof(struct nlmon),
48582 .setup = nlmon_setup,
48583 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48584 index 794a473..9fd437b 100644
48585 --- a/drivers/net/ppp/ppp_generic.c
48586 +++ b/drivers/net/ppp/ppp_generic.c
48587 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48588 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48589 struct ppp_stats stats;
48590 struct ppp_comp_stats cstats;
48591 - char *vers;
48592
48593 switch (cmd) {
48594 case SIOCGPPPSTATS:
48595 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48596 break;
48597
48598 case SIOCGPPPVER:
48599 - vers = PPP_VERSION;
48600 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48601 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48602 break;
48603 err = 0;
48604 break;
48605 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48606 index 079f7ad..b2a2bfa7 100644
48607 --- a/drivers/net/slip/slhc.c
48608 +++ b/drivers/net/slip/slhc.c
48609 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48610 register struct tcphdr *thp;
48611 register struct iphdr *ip;
48612 register struct cstate *cs;
48613 - int len, hdrlen;
48614 + long len, hdrlen;
48615 unsigned char *cp = icp;
48616
48617 /* We've got a compressed packet; read the change byte */
48618 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48619 index 9c505c4..5d0c879 100644
48620 --- a/drivers/net/team/team.c
48621 +++ b/drivers/net/team/team.c
48622 @@ -2102,7 +2102,7 @@ static unsigned int team_get_num_rx_queues(void)
48623 return TEAM_DEFAULT_NUM_RX_QUEUES;
48624 }
48625
48626 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48627 +static struct rtnl_link_ops team_link_ops = {
48628 .kind = DRV_NAME,
48629 .priv_size = sizeof(struct team),
48630 .setup = team_setup,
48631 @@ -2892,7 +2892,7 @@ static int team_device_event(struct notifier_block *unused,
48632 return NOTIFY_DONE;
48633 }
48634
48635 -static struct notifier_block team_notifier_block __read_mostly = {
48636 +static struct notifier_block team_notifier_block = {
48637 .notifier_call = team_device_event,
48638 };
48639
48640 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48641 index 9dd3746..74f191e 100644
48642 --- a/drivers/net/tun.c
48643 +++ b/drivers/net/tun.c
48644 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48645 return -EINVAL;
48646 }
48647
48648 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48649 +static struct rtnl_link_ops tun_link_ops = {
48650 .kind = DRV_NAME,
48651 .priv_size = sizeof(struct tun_struct),
48652 .setup = tun_setup,
48653 @@ -1868,7 +1868,7 @@ unlock:
48654 }
48655
48656 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48657 - unsigned long arg, int ifreq_len)
48658 + unsigned long arg, size_t ifreq_len)
48659 {
48660 struct tun_file *tfile = file->private_data;
48661 struct tun_struct *tun;
48662 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48663 unsigned int ifindex;
48664 int ret;
48665
48666 + if (ifreq_len > sizeof ifr)
48667 + return -EFAULT;
48668 +
48669 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48670 if (copy_from_user(&ifr, argp, ifreq_len))
48671 return -EFAULT;
48672 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48673 index babda7d..e40c90a 100644
48674 --- a/drivers/net/usb/hso.c
48675 +++ b/drivers/net/usb/hso.c
48676 @@ -71,7 +71,7 @@
48677 #include <asm/byteorder.h>
48678 #include <linux/serial_core.h>
48679 #include <linux/serial.h>
48680 -
48681 +#include <asm/local.h>
48682
48683 #define MOD_AUTHOR "Option Wireless"
48684 #define MOD_DESCRIPTION "USB High Speed Option driver"
48685 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48686 struct urb *urb;
48687
48688 urb = serial->rx_urb[0];
48689 - if (serial->port.count > 0) {
48690 + if (atomic_read(&serial->port.count) > 0) {
48691 count = put_rxbuf_data(urb, serial);
48692 if (count == -1)
48693 return;
48694 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48695 DUMP1(urb->transfer_buffer, urb->actual_length);
48696
48697 /* Anyone listening? */
48698 - if (serial->port.count == 0)
48699 + if (atomic_read(&serial->port.count) == 0)
48700 return;
48701
48702 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48703 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48704 tty_port_tty_set(&serial->port, tty);
48705
48706 /* check for port already opened, if not set the termios */
48707 - serial->port.count++;
48708 - if (serial->port.count == 1) {
48709 + if (atomic_inc_return(&serial->port.count) == 1) {
48710 serial->rx_state = RX_IDLE;
48711 /* Force default termio settings */
48712 _hso_serial_set_termios(tty, NULL);
48713 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48714 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48715 if (result) {
48716 hso_stop_serial_device(serial->parent);
48717 - serial->port.count--;
48718 + atomic_dec(&serial->port.count);
48719 kref_put(&serial->parent->ref, hso_serial_ref_free);
48720 }
48721 } else {
48722 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48723
48724 /* reset the rts and dtr */
48725 /* do the actual close */
48726 - serial->port.count--;
48727 + atomic_dec(&serial->port.count);
48728
48729 - if (serial->port.count <= 0) {
48730 - serial->port.count = 0;
48731 + if (atomic_read(&serial->port.count) <= 0) {
48732 + atomic_set(&serial->port.count, 0);
48733 tty_port_tty_set(&serial->port, NULL);
48734 if (!usb_gone)
48735 hso_stop_serial_device(serial->parent);
48736 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48737
48738 /* the actual setup */
48739 spin_lock_irqsave(&serial->serial_lock, flags);
48740 - if (serial->port.count)
48741 + if (atomic_read(&serial->port.count))
48742 _hso_serial_set_termios(tty, old);
48743 else
48744 tty->termios = *old;
48745 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48746 D1("Pending read interrupt on port %d\n", i);
48747 spin_lock(&serial->serial_lock);
48748 if (serial->rx_state == RX_IDLE &&
48749 - serial->port.count > 0) {
48750 + atomic_read(&serial->port.count) > 0) {
48751 /* Setup and send a ctrl req read on
48752 * port i */
48753 if (!serial->rx_urb_filled[0]) {
48754 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48755 /* Start all serial ports */
48756 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48757 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48758 - if (dev2ser(serial_table[i])->port.count) {
48759 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48760 result =
48761 hso_start_serial_device(serial_table[i], GFP_NOIO);
48762 hso_kick_transmit(dev2ser(serial_table[i]));
48763 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48764 index c6554c7..7e2ebd7 100644
48765 --- a/drivers/net/usb/r8152.c
48766 +++ b/drivers/net/usb/r8152.c
48767 @@ -577,7 +577,7 @@ struct r8152 {
48768 void (*unload)(struct r8152 *);
48769 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48770 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48771 - } rtl_ops;
48772 + } __no_const rtl_ops;
48773
48774 int intr_interval;
48775 u32 saved_wolopts;
48776 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48777 index a2515887..6d13233 100644
48778 --- a/drivers/net/usb/sierra_net.c
48779 +++ b/drivers/net/usb/sierra_net.c
48780 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48781 /* atomic counter partially included in MAC address to make sure 2 devices
48782 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48783 */
48784 -static atomic_t iface_counter = ATOMIC_INIT(0);
48785 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48786
48787 /*
48788 * SYNC Timer Delay definition used to set the expiry time
48789 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48790 dev->net->netdev_ops = &sierra_net_device_ops;
48791
48792 /* change MAC addr to include, ifacenum, and to be unique */
48793 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48794 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48795 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48796
48797 /* we will have to manufacture ethernet headers, prepare template */
48798 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48799 index b0bc8ea..3af931b5 100644
48800 --- a/drivers/net/virtio_net.c
48801 +++ b/drivers/net/virtio_net.c
48802 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48803 #define RECEIVE_AVG_WEIGHT 64
48804
48805 /* Minimum alignment for mergeable packet buffers. */
48806 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48807 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48808
48809 #define VIRTNET_DRIVER_VERSION "1.0.0"
48810
48811 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48812 index 42b2d6a5..2a2cb41 100644
48813 --- a/drivers/net/vxlan.c
48814 +++ b/drivers/net/vxlan.c
48815 @@ -2695,7 +2695,7 @@ nla_put_failure:
48816 return -EMSGSIZE;
48817 }
48818
48819 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48820 +static struct rtnl_link_ops vxlan_link_ops = {
48821 .kind = "vxlan",
48822 .maxtype = IFLA_VXLAN_MAX,
48823 .policy = vxlan_policy,
48824 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48825 return NOTIFY_DONE;
48826 }
48827
48828 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48829 +static struct notifier_block vxlan_notifier_block = {
48830 .notifier_call = vxlan_lowerdev_event,
48831 };
48832
48833 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48834 index 5920c99..ff2e4a5 100644
48835 --- a/drivers/net/wan/lmc/lmc_media.c
48836 +++ b/drivers/net/wan/lmc/lmc_media.c
48837 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48838 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48839
48840 lmc_media_t lmc_ds3_media = {
48841 - lmc_ds3_init, /* special media init stuff */
48842 - lmc_ds3_default, /* reset to default state */
48843 - lmc_ds3_set_status, /* reset status to state provided */
48844 - lmc_dummy_set_1, /* set clock source */
48845 - lmc_dummy_set2_1, /* set line speed */
48846 - lmc_ds3_set_100ft, /* set cable length */
48847 - lmc_ds3_set_scram, /* set scrambler */
48848 - lmc_ds3_get_link_status, /* get link status */
48849 - lmc_dummy_set_1, /* set link status */
48850 - lmc_ds3_set_crc_length, /* set CRC length */
48851 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48852 - lmc_ds3_watchdog
48853 + .init = lmc_ds3_init, /* special media init stuff */
48854 + .defaults = lmc_ds3_default, /* reset to default state */
48855 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48856 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48857 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48858 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48859 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48860 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48861 + .set_link_status = lmc_dummy_set_1, /* set link status */
48862 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48863 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48864 + .watchdog = lmc_ds3_watchdog
48865 };
48866
48867 lmc_media_t lmc_hssi_media = {
48868 - lmc_hssi_init, /* special media init stuff */
48869 - lmc_hssi_default, /* reset to default state */
48870 - lmc_hssi_set_status, /* reset status to state provided */
48871 - lmc_hssi_set_clock, /* set clock source */
48872 - lmc_dummy_set2_1, /* set line speed */
48873 - lmc_dummy_set_1, /* set cable length */
48874 - lmc_dummy_set_1, /* set scrambler */
48875 - lmc_hssi_get_link_status, /* get link status */
48876 - lmc_hssi_set_link_status, /* set link status */
48877 - lmc_hssi_set_crc_length, /* set CRC length */
48878 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48879 - lmc_hssi_watchdog
48880 + .init = lmc_hssi_init, /* special media init stuff */
48881 + .defaults = lmc_hssi_default, /* reset to default state */
48882 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48883 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48884 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48885 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48886 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48887 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48888 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48889 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48890 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48891 + .watchdog = lmc_hssi_watchdog
48892 };
48893
48894 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48895 - lmc_ssi_default, /* reset to default state */
48896 - lmc_ssi_set_status, /* reset status to state provided */
48897 - lmc_ssi_set_clock, /* set clock source */
48898 - lmc_ssi_set_speed, /* set line speed */
48899 - lmc_dummy_set_1, /* set cable length */
48900 - lmc_dummy_set_1, /* set scrambler */
48901 - lmc_ssi_get_link_status, /* get link status */
48902 - lmc_ssi_set_link_status, /* set link status */
48903 - lmc_ssi_set_crc_length, /* set CRC length */
48904 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48905 - lmc_ssi_watchdog
48906 +lmc_media_t lmc_ssi_media = {
48907 + .init = lmc_ssi_init, /* special media init stuff */
48908 + .defaults = lmc_ssi_default, /* reset to default state */
48909 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48910 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48911 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48912 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48913 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48914 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48915 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48916 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48917 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48918 + .watchdog = lmc_ssi_watchdog
48919 };
48920
48921 lmc_media_t lmc_t1_media = {
48922 - lmc_t1_init, /* special media init stuff */
48923 - lmc_t1_default, /* reset to default state */
48924 - lmc_t1_set_status, /* reset status to state provided */
48925 - lmc_t1_set_clock, /* set clock source */
48926 - lmc_dummy_set2_1, /* set line speed */
48927 - lmc_dummy_set_1, /* set cable length */
48928 - lmc_dummy_set_1, /* set scrambler */
48929 - lmc_t1_get_link_status, /* get link status */
48930 - lmc_dummy_set_1, /* set link status */
48931 - lmc_t1_set_crc_length, /* set CRC length */
48932 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48933 - lmc_t1_watchdog
48934 + .init = lmc_t1_init, /* special media init stuff */
48935 + .defaults = lmc_t1_default, /* reset to default state */
48936 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48937 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48938 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48939 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48940 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48941 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48942 + .set_link_status = lmc_dummy_set_1, /* set link status */
48943 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48944 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48945 + .watchdog = lmc_t1_watchdog
48946 };
48947
48948 static void
48949 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48950 index feacc3b..5bac0de 100644
48951 --- a/drivers/net/wan/z85230.c
48952 +++ b/drivers/net/wan/z85230.c
48953 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48954
48955 struct z8530_irqhandler z8530_sync =
48956 {
48957 - z8530_rx,
48958 - z8530_tx,
48959 - z8530_status
48960 + .rx = z8530_rx,
48961 + .tx = z8530_tx,
48962 + .status = z8530_status
48963 };
48964
48965 EXPORT_SYMBOL(z8530_sync);
48966 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48967 }
48968
48969 static struct z8530_irqhandler z8530_dma_sync = {
48970 - z8530_dma_rx,
48971 - z8530_dma_tx,
48972 - z8530_dma_status
48973 + .rx = z8530_dma_rx,
48974 + .tx = z8530_dma_tx,
48975 + .status = z8530_dma_status
48976 };
48977
48978 static struct z8530_irqhandler z8530_txdma_sync = {
48979 - z8530_rx,
48980 - z8530_dma_tx,
48981 - z8530_dma_status
48982 + .rx = z8530_rx,
48983 + .tx = z8530_dma_tx,
48984 + .status = z8530_dma_status
48985 };
48986
48987 /**
48988 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
48989
48990 struct z8530_irqhandler z8530_nop=
48991 {
48992 - z8530_rx_clear,
48993 - z8530_tx_clear,
48994 - z8530_status_clear
48995 + .rx = z8530_rx_clear,
48996 + .tx = z8530_tx_clear,
48997 + .status = z8530_status_clear
48998 };
48999
49000
49001 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49002 index 0b60295..b8bfa5b 100644
49003 --- a/drivers/net/wimax/i2400m/rx.c
49004 +++ b/drivers/net/wimax/i2400m/rx.c
49005 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49006 if (i2400m->rx_roq == NULL)
49007 goto error_roq_alloc;
49008
49009 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49010 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49011 GFP_KERNEL);
49012 if (rd == NULL) {
49013 result = -ENOMEM;
49014 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49015 index e71a2ce..2268d61 100644
49016 --- a/drivers/net/wireless/airo.c
49017 +++ b/drivers/net/wireless/airo.c
49018 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49019 struct airo_info *ai = dev->ml_priv;
49020 int ridcode;
49021 int enabled;
49022 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49023 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49024 unsigned char *iobuf;
49025
49026 /* Only super-user can write RIDs */
49027 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49028 index da92bfa..5a9001a 100644
49029 --- a/drivers/net/wireless/at76c50x-usb.c
49030 +++ b/drivers/net/wireless/at76c50x-usb.c
49031 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49032 }
49033
49034 /* Convert timeout from the DFU status to jiffies */
49035 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49036 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49037 {
49038 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49039 | (s->poll_timeout[1] << 8)
49040 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49041 index 676bd4e..0b807a3 100644
49042 --- a/drivers/net/wireless/ath/ath10k/htc.c
49043 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49044 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
49045 /* registered target arrival callback from the HIF layer */
49046 int ath10k_htc_init(struct ath10k *ar)
49047 {
49048 - struct ath10k_hif_cb htc_callbacks;
49049 + static struct ath10k_hif_cb htc_callbacks = {
49050 + .rx_completion = ath10k_htc_rx_completion_handler,
49051 + .tx_completion = ath10k_htc_tx_completion_handler,
49052 + };
49053 struct ath10k_htc_ep *ep = NULL;
49054 struct ath10k_htc *htc = &ar->htc;
49055
49056 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
49057 ath10k_htc_reset_endpoint_states(htc);
49058
49059 /* setup HIF layer callbacks */
49060 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49061 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49062 htc->ar = ar;
49063
49064 /* Get HIF default pipe for HTC message exchange */
49065 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49066 index 527179c..a890150 100644
49067 --- a/drivers/net/wireless/ath/ath10k/htc.h
49068 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49069 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
49070
49071 struct ath10k_htc_ops {
49072 void (*target_send_suspend_complete)(struct ath10k *ar);
49073 -};
49074 +} __no_const;
49075
49076 struct ath10k_htc_ep_ops {
49077 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49078 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49079 void (*ep_tx_credits)(struct ath10k *);
49080 -};
49081 +} __no_const;
49082
49083 /* service connection information */
49084 struct ath10k_htc_svc_conn_req {
49085 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49086 index 2a93519..7052786 100644
49087 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49088 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49089 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49090 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49091 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49092
49093 - ACCESS_ONCE(ads->ds_link) = i->link;
49094 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49095 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49096 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49097
49098 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49099 ctl6 = SM(i->keytype, AR_EncrType);
49100 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49101
49102 if ((i->is_first || i->is_last) &&
49103 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49104 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49105 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49106 | set11nTries(i->rates, 1)
49107 | set11nTries(i->rates, 2)
49108 | set11nTries(i->rates, 3)
49109 | (i->dur_update ? AR_DurUpdateEna : 0)
49110 | SM(0, AR_BurstDur);
49111
49112 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49113 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49114 | set11nRate(i->rates, 1)
49115 | set11nRate(i->rates, 2)
49116 | set11nRate(i->rates, 3);
49117 } else {
49118 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49119 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49120 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49121 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49122 }
49123
49124 if (!i->is_first) {
49125 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49126 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49127 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49128 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49129 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49130 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49131 return;
49132 }
49133
49134 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49135 break;
49136 }
49137
49138 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49139 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49140 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49141 | SM(i->txpower, AR_XmitPower0)
49142 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49143 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49144 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49145 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49146
49147 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49148 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49149 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49150 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49151
49152 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49153 return;
49154
49155 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49156 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49157 | set11nPktDurRTSCTS(i->rates, 1);
49158
49159 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49160 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49161 | set11nPktDurRTSCTS(i->rates, 3);
49162
49163 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49164 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49165 | set11nRateFlags(i->rates, 1)
49166 | set11nRateFlags(i->rates, 2)
49167 | set11nRateFlags(i->rates, 3)
49168 | SM(i->rtscts_rate, AR_RTSCTSRate);
49169
49170 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49171 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49172 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49173 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49174 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49175 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49176 }
49177
49178 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49179 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49180 index 057b165..98ae88f 100644
49181 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49182 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49183 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49184 (i->qcu << AR_TxQcuNum_S) | desc_len;
49185
49186 checksum += val;
49187 - ACCESS_ONCE(ads->info) = val;
49188 + ACCESS_ONCE_RW(ads->info) = val;
49189
49190 checksum += i->link;
49191 - ACCESS_ONCE(ads->link) = i->link;
49192 + ACCESS_ONCE_RW(ads->link) = i->link;
49193
49194 checksum += i->buf_addr[0];
49195 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49196 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49197 checksum += i->buf_addr[1];
49198 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49199 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49200 checksum += i->buf_addr[2];
49201 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49202 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49203 checksum += i->buf_addr[3];
49204 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49205 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49206
49207 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49208 - ACCESS_ONCE(ads->ctl3) = val;
49209 + ACCESS_ONCE_RW(ads->ctl3) = val;
49210 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49211 - ACCESS_ONCE(ads->ctl5) = val;
49212 + ACCESS_ONCE_RW(ads->ctl5) = val;
49213 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49214 - ACCESS_ONCE(ads->ctl7) = val;
49215 + ACCESS_ONCE_RW(ads->ctl7) = val;
49216 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49217 - ACCESS_ONCE(ads->ctl9) = val;
49218 + ACCESS_ONCE_RW(ads->ctl9) = val;
49219
49220 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49221 - ACCESS_ONCE(ads->ctl10) = checksum;
49222 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49223
49224 if (i->is_first || i->is_last) {
49225 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49226 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49227 | set11nTries(i->rates, 1)
49228 | set11nTries(i->rates, 2)
49229 | set11nTries(i->rates, 3)
49230 | (i->dur_update ? AR_DurUpdateEna : 0)
49231 | SM(0, AR_BurstDur);
49232
49233 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49234 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49235 | set11nRate(i->rates, 1)
49236 | set11nRate(i->rates, 2)
49237 | set11nRate(i->rates, 3);
49238 } else {
49239 - ACCESS_ONCE(ads->ctl13) = 0;
49240 - ACCESS_ONCE(ads->ctl14) = 0;
49241 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49242 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49243 }
49244
49245 ads->ctl20 = 0;
49246 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49247
49248 ctl17 = SM(i->keytype, AR_EncrType);
49249 if (!i->is_first) {
49250 - ACCESS_ONCE(ads->ctl11) = 0;
49251 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49252 - ACCESS_ONCE(ads->ctl15) = 0;
49253 - ACCESS_ONCE(ads->ctl16) = 0;
49254 - ACCESS_ONCE(ads->ctl17) = ctl17;
49255 - ACCESS_ONCE(ads->ctl18) = 0;
49256 - ACCESS_ONCE(ads->ctl19) = 0;
49257 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49258 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49259 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49260 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49261 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49262 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49263 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49264 return;
49265 }
49266
49267 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49268 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49269 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49270 | SM(i->txpower, AR_XmitPower0)
49271 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49272 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49273 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49274 ctl12 |= SM(val, AR_PAPRDChainMask);
49275
49276 - ACCESS_ONCE(ads->ctl12) = ctl12;
49277 - ACCESS_ONCE(ads->ctl17) = ctl17;
49278 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49279 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49280
49281 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49282 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49283 | set11nPktDurRTSCTS(i->rates, 1);
49284
49285 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49286 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49287 | set11nPktDurRTSCTS(i->rates, 3);
49288
49289 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49290 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49291 | set11nRateFlags(i->rates, 1)
49292 | set11nRateFlags(i->rates, 2)
49293 | set11nRateFlags(i->rates, 3)
49294 | SM(i->rtscts_rate, AR_RTSCTSRate);
49295
49296 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49297 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49298
49299 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49300 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49301 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49302 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49303 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49304 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49305 }
49306
49307 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49308 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49309 index e8e8dd2..030f80e 100644
49310 --- a/drivers/net/wireless/ath/ath9k/hw.h
49311 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49312 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49313
49314 /* ANI */
49315 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49316 -};
49317 +} __no_const;
49318
49319 /**
49320 * struct ath_spec_scan - parameters for Atheros spectral scan
49321 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49322 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49323 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49324 #endif
49325 -};
49326 +} __no_const;
49327
49328 struct ath_nf_limits {
49329 s16 max;
49330 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49331 index 4f18a6b..b07d92f 100644
49332 --- a/drivers/net/wireless/ath/ath9k/main.c
49333 +++ b/drivers/net/wireless/ath/ath9k/main.c
49334 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49335 if (!ath9k_is_chanctx_enabled())
49336 return;
49337
49338 - ath9k_ops.hw_scan = ath9k_hw_scan;
49339 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49340 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49341 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49342 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49343 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49344 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49345 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49346 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49347 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49348 + pax_open_kernel();
49349 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49350 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49351 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49352 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49353 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49354 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49355 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49356 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49357 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49358 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49359 + pax_close_kernel();
49360 }
49361
49362 #endif
49363 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49364 index 058a9f2..d5cb1ba 100644
49365 --- a/drivers/net/wireless/b43/phy_lp.c
49366 +++ b/drivers/net/wireless/b43/phy_lp.c
49367 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49368 {
49369 struct ssb_bus *bus = dev->dev->sdev->bus;
49370
49371 - static const struct b206x_channel *chandata = NULL;
49372 + const struct b206x_channel *chandata = NULL;
49373 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49374 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49375 u16 old_comm15, scale;
49376 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49377 index dc1d20c..f7a4f06 100644
49378 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49379 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49380 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49381 */
49382 if (il3945_mod_params.disable_hw_scan) {
49383 D_INFO("Disabling hw_scan\n");
49384 - il3945_mac_ops.hw_scan = NULL;
49385 + pax_open_kernel();
49386 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49387 + pax_close_kernel();
49388 }
49389
49390 D_INFO("*** LOAD DRIVER ***\n");
49391 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49392 index 0ffb6ff..c0b7f0e 100644
49393 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49394 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49395 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49396 {
49397 struct iwl_priv *priv = file->private_data;
49398 char buf[64];
49399 - int buf_size;
49400 + size_t buf_size;
49401 u32 offset, len;
49402
49403 memset(buf, 0, sizeof(buf));
49404 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49405 struct iwl_priv *priv = file->private_data;
49406
49407 char buf[8];
49408 - int buf_size;
49409 + size_t buf_size;
49410 u32 reset_flag;
49411
49412 memset(buf, 0, sizeof(buf));
49413 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49414 {
49415 struct iwl_priv *priv = file->private_data;
49416 char buf[8];
49417 - int buf_size;
49418 + size_t buf_size;
49419 int ht40;
49420
49421 memset(buf, 0, sizeof(buf));
49422 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49423 {
49424 struct iwl_priv *priv = file->private_data;
49425 char buf[8];
49426 - int buf_size;
49427 + size_t buf_size;
49428 int value;
49429
49430 memset(buf, 0, sizeof(buf));
49431 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49432 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49433 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49434
49435 -static const char *fmt_value = " %-30s %10u\n";
49436 -static const char *fmt_hex = " %-30s 0x%02X\n";
49437 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49438 -static const char *fmt_header =
49439 +static const char fmt_value[] = " %-30s %10u\n";
49440 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49441 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49442 +static const char fmt_header[] =
49443 "%-32s current cumulative delta max\n";
49444
49445 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49446 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49447 {
49448 struct iwl_priv *priv = file->private_data;
49449 char buf[8];
49450 - int buf_size;
49451 + size_t buf_size;
49452 int clear;
49453
49454 memset(buf, 0, sizeof(buf));
49455 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49456 {
49457 struct iwl_priv *priv = file->private_data;
49458 char buf[8];
49459 - int buf_size;
49460 + size_t buf_size;
49461 int trace;
49462
49463 memset(buf, 0, sizeof(buf));
49464 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49465 {
49466 struct iwl_priv *priv = file->private_data;
49467 char buf[8];
49468 - int buf_size;
49469 + size_t buf_size;
49470 int missed;
49471
49472 memset(buf, 0, sizeof(buf));
49473 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49474
49475 struct iwl_priv *priv = file->private_data;
49476 char buf[8];
49477 - int buf_size;
49478 + size_t buf_size;
49479 int plcp;
49480
49481 memset(buf, 0, sizeof(buf));
49482 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49483
49484 struct iwl_priv *priv = file->private_data;
49485 char buf[8];
49486 - int buf_size;
49487 + size_t buf_size;
49488 int flush;
49489
49490 memset(buf, 0, sizeof(buf));
49491 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49492
49493 struct iwl_priv *priv = file->private_data;
49494 char buf[8];
49495 - int buf_size;
49496 + size_t buf_size;
49497 int rts;
49498
49499 if (!priv->cfg->ht_params)
49500 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49501 {
49502 struct iwl_priv *priv = file->private_data;
49503 char buf[8];
49504 - int buf_size;
49505 + size_t buf_size;
49506
49507 memset(buf, 0, sizeof(buf));
49508 buf_size = min(count, sizeof(buf) - 1);
49509 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49510 struct iwl_priv *priv = file->private_data;
49511 u32 event_log_flag;
49512 char buf[8];
49513 - int buf_size;
49514 + size_t buf_size;
49515
49516 /* check that the interface is up */
49517 if (!iwl_is_ready(priv))
49518 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49519 struct iwl_priv *priv = file->private_data;
49520 char buf[8];
49521 u32 calib_disabled;
49522 - int buf_size;
49523 + size_t buf_size;
49524
49525 memset(buf, 0, sizeof(buf));
49526 buf_size = min(count, sizeof(buf) - 1);
49527 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49528 index dd2f3f8..fb1ae88 100644
49529 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49530 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49531 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49532 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49533
49534 char buf[8];
49535 - int buf_size;
49536 + size_t buf_size;
49537 u32 reset_flag;
49538
49539 memset(buf, 0, sizeof(buf));
49540 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49541 {
49542 struct iwl_trans *trans = file->private_data;
49543 char buf[8];
49544 - int buf_size;
49545 + size_t buf_size;
49546 int csr;
49547
49548 memset(buf, 0, sizeof(buf));
49549 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49550 index c9ad4cf..49a2fa0 100644
49551 --- a/drivers/net/wireless/mac80211_hwsim.c
49552 +++ b/drivers/net/wireless/mac80211_hwsim.c
49553 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49554 if (channels < 1)
49555 return -EINVAL;
49556
49557 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49558 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49559 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49560 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49561 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49562 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49563 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49564 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49565 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49566 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49567 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49568 - mac80211_hwsim_assign_vif_chanctx;
49569 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49570 - mac80211_hwsim_unassign_vif_chanctx;
49571 + pax_open_kernel();
49572 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49573 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49574 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49575 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49576 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49577 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49578 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49579 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49580 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49581 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49582 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49583 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49584 + pax_close_kernel();
49585
49586 spin_lock_init(&hwsim_radio_lock);
49587 INIT_LIST_HEAD(&hwsim_radios);
49588 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49589 index 1a4facd..a2ecbbd 100644
49590 --- a/drivers/net/wireless/rndis_wlan.c
49591 +++ b/drivers/net/wireless/rndis_wlan.c
49592 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49593
49594 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49595
49596 - if (rts_threshold < 0 || rts_threshold > 2347)
49597 + if (rts_threshold > 2347)
49598 rts_threshold = 2347;
49599
49600 tmp = cpu_to_le32(rts_threshold);
49601 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49602 index d13f25c..2573994 100644
49603 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49604 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49605 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49606 * for hardware which doesn't support hardware
49607 * sequence counting.
49608 */
49609 - atomic_t seqno;
49610 + atomic_unchecked_t seqno;
49611 };
49612
49613 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49614 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49615 index 66ff364..3ce34f7 100644
49616 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49617 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49618 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49619 * sequence counter given by mac80211.
49620 */
49621 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49622 - seqno = atomic_add_return(0x10, &intf->seqno);
49623 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49624 else
49625 - seqno = atomic_read(&intf->seqno);
49626 + seqno = atomic_read_unchecked(&intf->seqno);
49627
49628 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49629 hdr->seq_ctrl |= cpu_to_le16(seqno);
49630 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49631 index b661f896..ddf7d2b 100644
49632 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49633 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49634 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49635
49636 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49637
49638 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49639 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49640 + pax_open_kernel();
49641 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49642 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49643 + pax_close_kernel();
49644
49645 wl1251_info("using dedicated interrupt line");
49646 } else {
49647 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49648 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49649 + pax_open_kernel();
49650 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49651 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49652 + pax_close_kernel();
49653
49654 wl1251_info("using SDIO interrupt");
49655 }
49656 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49657 index 0bccf12..3d95068 100644
49658 --- a/drivers/net/wireless/ti/wl12xx/main.c
49659 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49660 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49661 sizeof(wl->conf.mem));
49662
49663 /* read data preparation is only needed by wl127x */
49664 - wl->ops->prepare_read = wl127x_prepare_read;
49665 + pax_open_kernel();
49666 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49667 + pax_close_kernel();
49668
49669 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49670 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49671 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49672 sizeof(wl->conf.mem));
49673
49674 /* read data preparation is only needed by wl127x */
49675 - wl->ops->prepare_read = wl127x_prepare_read;
49676 + pax_open_kernel();
49677 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49678 + pax_close_kernel();
49679
49680 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49681 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49682 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49683 index 7af1936..128bb35 100644
49684 --- a/drivers/net/wireless/ti/wl18xx/main.c
49685 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49686 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49687 }
49688
49689 if (!checksum_param) {
49690 - wl18xx_ops.set_rx_csum = NULL;
49691 - wl18xx_ops.init_vif = NULL;
49692 + pax_open_kernel();
49693 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49694 + *(void **)&wl18xx_ops.init_vif = NULL;
49695 + pax_close_kernel();
49696 }
49697
49698 /* Enable 11a Band only if we have 5G antennas */
49699 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49700 index a912dc0..a8225ba 100644
49701 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49702 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49703 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49704 {
49705 struct zd_usb *usb = urb->context;
49706 struct zd_usb_interrupt *intr = &usb->intr;
49707 - int len;
49708 + unsigned int len;
49709 u16 int_num;
49710
49711 ZD_ASSERT(in_interrupt());
49712 diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
49713 index d752d1c..23e3203 100644
49714 --- a/drivers/net/xen-netback/interface.c
49715 +++ b/drivers/net/xen-netback/interface.c
49716 @@ -578,6 +578,7 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
49717 goto err_rx_unbind;
49718 }
49719 queue->task = task;
49720 + get_task_struct(task);
49721
49722 task = kthread_create(xenvif_dealloc_kthread,
49723 (void *)queue, "%s-dealloc", queue->name);
49724 @@ -634,6 +635,7 @@ void xenvif_disconnect(struct xenvif *vif)
49725
49726 if (queue->task) {
49727 kthread_stop(queue->task);
49728 + put_task_struct(queue->task);
49729 queue->task = NULL;
49730 }
49731
49732 diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
49733 index c39aace..e18728d 100644
49734 --- a/drivers/net/xen-netback/netback.c
49735 +++ b/drivers/net/xen-netback/netback.c
49736 @@ -2111,8 +2111,7 @@ int xenvif_kthread_guest_rx(void *data)
49737 */
49738 if (unlikely(vif->disabled && queue->id == 0)) {
49739 xenvif_carrier_off(vif);
49740 - xenvif_rx_queue_purge(queue);
49741 - continue;
49742 + break;
49743 }
49744
49745 if (!skb_queue_empty(&queue->rx_queue))
49746 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49747 index 683671a..4519fc2 100644
49748 --- a/drivers/nfc/nfcwilink.c
49749 +++ b/drivers/nfc/nfcwilink.c
49750 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49751
49752 static int nfcwilink_probe(struct platform_device *pdev)
49753 {
49754 - static struct nfcwilink *drv;
49755 + struct nfcwilink *drv;
49756 int rc;
49757 __u32 protocols;
49758
49759 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49760 index d93b2b6..ae50401 100644
49761 --- a/drivers/oprofile/buffer_sync.c
49762 +++ b/drivers/oprofile/buffer_sync.c
49763 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49764 if (cookie == NO_COOKIE)
49765 offset = pc;
49766 if (cookie == INVALID_COOKIE) {
49767 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49768 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49769 offset = pc;
49770 }
49771 if (cookie != last_cookie) {
49772 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49773 /* add userspace sample */
49774
49775 if (!mm) {
49776 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49777 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49778 return 0;
49779 }
49780
49781 cookie = lookup_dcookie(mm, s->eip, &offset);
49782
49783 if (cookie == INVALID_COOKIE) {
49784 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49785 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49786 return 0;
49787 }
49788
49789 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49790 /* ignore backtraces if failed to add a sample */
49791 if (state == sb_bt_start) {
49792 state = sb_bt_ignore;
49793 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49794 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49795 }
49796 }
49797 release_mm(mm);
49798 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49799 index c0cc4e7..44d4e54 100644
49800 --- a/drivers/oprofile/event_buffer.c
49801 +++ b/drivers/oprofile/event_buffer.c
49802 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49803 }
49804
49805 if (buffer_pos == buffer_size) {
49806 - atomic_inc(&oprofile_stats.event_lost_overflow);
49807 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49808 return;
49809 }
49810
49811 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49812 index ed2c3ec..deda85a 100644
49813 --- a/drivers/oprofile/oprof.c
49814 +++ b/drivers/oprofile/oprof.c
49815 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49816 if (oprofile_ops.switch_events())
49817 return;
49818
49819 - atomic_inc(&oprofile_stats.multiplex_counter);
49820 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49821 start_switch_worker();
49822 }
49823
49824 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49825 index ee2cfce..7f8f699 100644
49826 --- a/drivers/oprofile/oprofile_files.c
49827 +++ b/drivers/oprofile/oprofile_files.c
49828 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49829
49830 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49831
49832 -static ssize_t timeout_read(struct file *file, char __user *buf,
49833 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49834 size_t count, loff_t *offset)
49835 {
49836 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49837 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49838 index 59659ce..6c860a0 100644
49839 --- a/drivers/oprofile/oprofile_stats.c
49840 +++ b/drivers/oprofile/oprofile_stats.c
49841 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49842 cpu_buf->sample_invalid_eip = 0;
49843 }
49844
49845 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49846 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49847 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49848 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49849 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49850 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49851 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49852 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49853 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49854 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49855 }
49856
49857
49858 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49859 index 1fc622b..8c48fc3 100644
49860 --- a/drivers/oprofile/oprofile_stats.h
49861 +++ b/drivers/oprofile/oprofile_stats.h
49862 @@ -13,11 +13,11 @@
49863 #include <linux/atomic.h>
49864
49865 struct oprofile_stat_struct {
49866 - atomic_t sample_lost_no_mm;
49867 - atomic_t sample_lost_no_mapping;
49868 - atomic_t bt_lost_no_mapping;
49869 - atomic_t event_lost_overflow;
49870 - atomic_t multiplex_counter;
49871 + atomic_unchecked_t sample_lost_no_mm;
49872 + atomic_unchecked_t sample_lost_no_mapping;
49873 + atomic_unchecked_t bt_lost_no_mapping;
49874 + atomic_unchecked_t event_lost_overflow;
49875 + atomic_unchecked_t multiplex_counter;
49876 };
49877
49878 extern struct oprofile_stat_struct oprofile_stats;
49879 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49880 index 3f49345..c750d0b 100644
49881 --- a/drivers/oprofile/oprofilefs.c
49882 +++ b/drivers/oprofile/oprofilefs.c
49883 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49884
49885 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49886 {
49887 - atomic_t *val = file->private_data;
49888 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49889 + atomic_unchecked_t *val = file->private_data;
49890 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49891 }
49892
49893
49894 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49895
49896
49897 int oprofilefs_create_ro_atomic(struct dentry *root,
49898 - char const *name, atomic_t *val)
49899 + char const *name, atomic_unchecked_t *val)
49900 {
49901 return __oprofilefs_create_file(root, name,
49902 &atomic_ro_fops, 0444, val);
49903 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49904 index bdef916..88c7dee 100644
49905 --- a/drivers/oprofile/timer_int.c
49906 +++ b/drivers/oprofile/timer_int.c
49907 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49908 return NOTIFY_OK;
49909 }
49910
49911 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49912 +static struct notifier_block oprofile_cpu_notifier = {
49913 .notifier_call = oprofile_cpu_notify,
49914 };
49915
49916 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49917 index 3b47080..6cd05dd 100644
49918 --- a/drivers/parport/procfs.c
49919 +++ b/drivers/parport/procfs.c
49920 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49921
49922 *ppos += len;
49923
49924 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49925 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49926 }
49927
49928 #ifdef CONFIG_PARPORT_1284
49929 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49930
49931 *ppos += len;
49932
49933 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49934 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49935 }
49936 #endif /* IEEE1284.3 support. */
49937
49938 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49939 index 6ca2399..68d866b 100644
49940 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49941 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49942 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49943 goto init_cleanup;
49944 }
49945
49946 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49947 + pax_open_kernel();
49948 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49949 + pax_close_kernel();
49950 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49951
49952 return retval;
49953 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49954 index 66b7bbe..26bee78 100644
49955 --- a/drivers/pci/hotplug/cpcihp_generic.c
49956 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49957 @@ -73,7 +73,6 @@ static u16 port;
49958 static unsigned int enum_bit;
49959 static u8 enum_mask;
49960
49961 -static struct cpci_hp_controller_ops generic_hpc_ops;
49962 static struct cpci_hp_controller generic_hpc;
49963
49964 static int __init validate_parameters(void)
49965 @@ -139,6 +138,10 @@ static int query_enum(void)
49966 return ((value & enum_mask) == enum_mask);
49967 }
49968
49969 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49970 + .query_enum = query_enum,
49971 +};
49972 +
49973 static int __init cpcihp_generic_init(void)
49974 {
49975 int status;
49976 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49977 pci_dev_put(dev);
49978
49979 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49980 - generic_hpc_ops.query_enum = query_enum;
49981 generic_hpc.ops = &generic_hpc_ops;
49982
49983 status = cpci_hp_register_controller(&generic_hpc);
49984 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49985 index 7ecf34e..effed62 100644
49986 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
49987 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49988 @@ -59,7 +59,6 @@
49989 /* local variables */
49990 static bool debug;
49991 static bool poll;
49992 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
49993 static struct cpci_hp_controller zt5550_hpc;
49994
49995 /* Primary cPCI bus bridge device */
49996 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49997 return 0;
49998 }
49999
50000 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50001 + .query_enum = zt5550_hc_query_enum,
50002 +};
50003 +
50004 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50005 {
50006 int status;
50007 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50008 dbg("returned from zt5550_hc_config");
50009
50010 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50011 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50012 zt5550_hpc.ops = &zt5550_hpc_ops;
50013 if (!poll) {
50014 zt5550_hpc.irq = hc_dev->irq;
50015 zt5550_hpc.irq_flags = IRQF_SHARED;
50016 zt5550_hpc.dev_id = hc_dev;
50017
50018 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50019 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50020 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50021 + pax_open_kernel();
50022 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50023 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50024 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50025 + pax_open_kernel();
50026 } else {
50027 info("using ENUM# polling mode");
50028 }
50029 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50030 index 1e08ff8c..3cd145f 100644
50031 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50032 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50033 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
50034
50035 void compaq_nvram_init (void __iomem *rom_start)
50036 {
50037 +#ifndef CONFIG_PAX_KERNEXEC
50038 if (rom_start)
50039 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50040 +#endif
50041
50042 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50043
50044 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50045 index 56d8486..f26113f 100644
50046 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50047 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50048 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50049 return -EINVAL;
50050 }
50051
50052 - slot->ops->owner = owner;
50053 - slot->ops->mod_name = mod_name;
50054 + pax_open_kernel();
50055 + *(struct module **)&slot->ops->owner = owner;
50056 + *(const char **)&slot->ops->mod_name = mod_name;
50057 + pax_close_kernel();
50058
50059 mutex_lock(&pci_hp_mutex);
50060 /*
50061 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50062 index 07aa722..84514b4 100644
50063 --- a/drivers/pci/hotplug/pciehp_core.c
50064 +++ b/drivers/pci/hotplug/pciehp_core.c
50065 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50066 struct slot *slot = ctrl->slot;
50067 struct hotplug_slot *hotplug = NULL;
50068 struct hotplug_slot_info *info = NULL;
50069 - struct hotplug_slot_ops *ops = NULL;
50070 + hotplug_slot_ops_no_const *ops = NULL;
50071 char name[SLOT_NAME_SIZE];
50072 int retval = -ENOMEM;
50073
50074 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50075 index 084587d..4a8f9df 100644
50076 --- a/drivers/pci/msi.c
50077 +++ b/drivers/pci/msi.c
50078 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50079 {
50080 struct attribute **msi_attrs;
50081 struct attribute *msi_attr;
50082 - struct device_attribute *msi_dev_attr;
50083 - struct attribute_group *msi_irq_group;
50084 + device_attribute_no_const *msi_dev_attr;
50085 + attribute_group_no_const *msi_irq_group;
50086 const struct attribute_group **msi_irq_groups;
50087 struct msi_desc *entry;
50088 int ret = -ENOMEM;
50089 @@ -549,7 +549,7 @@ error_attrs:
50090 count = 0;
50091 msi_attr = msi_attrs[count];
50092 while (msi_attr) {
50093 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50094 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50095 kfree(msi_attr->name);
50096 kfree(msi_dev_attr);
50097 ++count;
50098 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50099 index 2c6643f..3a6d8e0 100644
50100 --- a/drivers/pci/pci-sysfs.c
50101 +++ b/drivers/pci/pci-sysfs.c
50102 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50103 {
50104 /* allocate attribute structure, piggyback attribute name */
50105 int name_len = write_combine ? 13 : 10;
50106 - struct bin_attribute *res_attr;
50107 + bin_attribute_no_const *res_attr;
50108 int retval;
50109
50110 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50111 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50112 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50113 {
50114 int retval;
50115 - struct bin_attribute *attr;
50116 + bin_attribute_no_const *attr;
50117
50118 /* If the device has VPD, try to expose it in sysfs. */
50119 if (dev->vpd) {
50120 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50121 {
50122 int retval;
50123 int rom_size = 0;
50124 - struct bin_attribute *attr;
50125 + bin_attribute_no_const *attr;
50126
50127 if (!sysfs_initialized)
50128 return -EACCES;
50129 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50130 index b5defca..e3664cc 100644
50131 --- a/drivers/pci/pci.h
50132 +++ b/drivers/pci/pci.h
50133 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
50134 struct pci_vpd {
50135 unsigned int len;
50136 const struct pci_vpd_ops *ops;
50137 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50138 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50139 };
50140
50141 int pci_vpd_pci22_init(struct pci_dev *dev);
50142 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50143 index e1e7026..d28dd33 100644
50144 --- a/drivers/pci/pcie/aspm.c
50145 +++ b/drivers/pci/pcie/aspm.c
50146 @@ -27,9 +27,9 @@
50147 #define MODULE_PARAM_PREFIX "pcie_aspm."
50148
50149 /* Note: those are not register definitions */
50150 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50151 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50152 -#define ASPM_STATE_L1 (4) /* L1 state */
50153 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50154 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50155 +#define ASPM_STATE_L1 (4U) /* L1 state */
50156 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50157 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50158
50159 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50160 index 3010ffc..5e2e133 100644
50161 --- a/drivers/pci/probe.c
50162 +++ b/drivers/pci/probe.c
50163 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50164 struct pci_bus_region region, inverted_region;
50165 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50166
50167 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50168 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50169
50170 /* No printks while decoding is disabled! */
50171 if (!dev->mmio_always_on) {
50172 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50173 index 3f155e7..0f4b1f0 100644
50174 --- a/drivers/pci/proc.c
50175 +++ b/drivers/pci/proc.c
50176 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50177 static int __init pci_proc_init(void)
50178 {
50179 struct pci_dev *dev = NULL;
50180 +
50181 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50182 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50183 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50184 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50185 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50186 +#endif
50187 +#else
50188 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50189 +#endif
50190 proc_create("devices", 0, proc_bus_pci_dir,
50191 &proc_bus_pci_dev_operations);
50192 proc_initialized = 1;
50193 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50194 index d866db8..c827d1f 100644
50195 --- a/drivers/platform/chrome/chromeos_laptop.c
50196 +++ b/drivers/platform/chrome/chromeos_laptop.c
50197 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50198 .callback = chromeos_laptop_dmi_matched, \
50199 .driver_data = (void *)&board_
50200
50201 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50202 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50203 {
50204 .ident = "Samsung Series 5 550",
50205 .matches = {
50206 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50207 index c5af23b..3d62d5e 100644
50208 --- a/drivers/platform/x86/alienware-wmi.c
50209 +++ b/drivers/platform/x86/alienware-wmi.c
50210 @@ -150,7 +150,7 @@ struct wmax_led_args {
50211 } __packed;
50212
50213 static struct platform_device *platform_device;
50214 -static struct device_attribute *zone_dev_attrs;
50215 +static device_attribute_no_const *zone_dev_attrs;
50216 static struct attribute **zone_attrs;
50217 static struct platform_zone *zone_data;
50218
50219 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50220 }
50221 };
50222
50223 -static struct attribute_group zone_attribute_group = {
50224 +static attribute_group_no_const zone_attribute_group = {
50225 .name = "rgb_zones",
50226 };
50227
50228 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50229 index 21fc932..ee9394a 100644
50230 --- a/drivers/platform/x86/asus-wmi.c
50231 +++ b/drivers/platform/x86/asus-wmi.c
50232 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50233 int err;
50234 u32 retval = -1;
50235
50236 +#ifdef CONFIG_GRKERNSEC_KMEM
50237 + return -EPERM;
50238 +#endif
50239 +
50240 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50241
50242 if (err < 0)
50243 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50244 int err;
50245 u32 retval = -1;
50246
50247 +#ifdef CONFIG_GRKERNSEC_KMEM
50248 + return -EPERM;
50249 +#endif
50250 +
50251 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50252 &retval);
50253
50254 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50255 union acpi_object *obj;
50256 acpi_status status;
50257
50258 +#ifdef CONFIG_GRKERNSEC_KMEM
50259 + return -EPERM;
50260 +#endif
50261 +
50262 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50263 1, asus->debug.method_id,
50264 &input, &output);
50265 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50266 index 62f8030..c7f2a45 100644
50267 --- a/drivers/platform/x86/msi-laptop.c
50268 +++ b/drivers/platform/x86/msi-laptop.c
50269 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50270
50271 if (!quirks->ec_read_only) {
50272 /* allow userland write sysfs file */
50273 - dev_attr_bluetooth.store = store_bluetooth;
50274 - dev_attr_wlan.store = store_wlan;
50275 - dev_attr_threeg.store = store_threeg;
50276 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50277 - dev_attr_wlan.attr.mode |= S_IWUSR;
50278 - dev_attr_threeg.attr.mode |= S_IWUSR;
50279 + pax_open_kernel();
50280 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50281 + *(void **)&dev_attr_wlan.store = store_wlan;
50282 + *(void **)&dev_attr_threeg.store = store_threeg;
50283 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50284 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50285 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50286 + pax_close_kernel();
50287 }
50288
50289 /* disable hardware control by fn key */
50290 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50291 index 70222f2..8c8ce66 100644
50292 --- a/drivers/platform/x86/msi-wmi.c
50293 +++ b/drivers/platform/x86/msi-wmi.c
50294 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50295 static void msi_wmi_notify(u32 value, void *context)
50296 {
50297 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50298 - static struct key_entry *key;
50299 + struct key_entry *key;
50300 union acpi_object *obj;
50301 acpi_status status;
50302
50303 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50304 index 26ad9ff..7c52909 100644
50305 --- a/drivers/platform/x86/sony-laptop.c
50306 +++ b/drivers/platform/x86/sony-laptop.c
50307 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50308 }
50309
50310 /* High speed charging function */
50311 -static struct device_attribute *hsc_handle;
50312 +static device_attribute_no_const *hsc_handle;
50313
50314 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50315 struct device_attribute *attr,
50316 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50317 }
50318
50319 /* low battery function */
50320 -static struct device_attribute *lowbatt_handle;
50321 +static device_attribute_no_const *lowbatt_handle;
50322
50323 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50324 struct device_attribute *attr,
50325 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50326 }
50327
50328 /* fan speed function */
50329 -static struct device_attribute *fan_handle, *hsf_handle;
50330 +static device_attribute_no_const *fan_handle, *hsf_handle;
50331
50332 static ssize_t sony_nc_hsfan_store(struct device *dev,
50333 struct device_attribute *attr,
50334 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50335 }
50336
50337 /* USB charge function */
50338 -static struct device_attribute *uc_handle;
50339 +static device_attribute_no_const *uc_handle;
50340
50341 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50342 struct device_attribute *attr,
50343 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50344 }
50345
50346 /* Panel ID function */
50347 -static struct device_attribute *panel_handle;
50348 +static device_attribute_no_const *panel_handle;
50349
50350 static ssize_t sony_nc_panelid_show(struct device *dev,
50351 struct device_attribute *attr, char *buffer)
50352 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50353 }
50354
50355 /* smart connect function */
50356 -static struct device_attribute *sc_handle;
50357 +static device_attribute_no_const *sc_handle;
50358
50359 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50360 struct device_attribute *attr,
50361 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50362 index cf0f893..5955997 100644
50363 --- a/drivers/platform/x86/thinkpad_acpi.c
50364 +++ b/drivers/platform/x86/thinkpad_acpi.c
50365 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50366 return 0;
50367 }
50368
50369 -void static hotkey_mask_warn_incomplete_mask(void)
50370 +static void hotkey_mask_warn_incomplete_mask(void)
50371 {
50372 /* log only what the user can fix... */
50373 const u32 wantedmask = hotkey_driver_mask &
50374 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50375 && !tp_features.bright_unkfw)
50376 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50377 }
50378 +}
50379
50380 #undef TPACPI_COMPARE_KEY
50381 #undef TPACPI_MAY_SEND_KEY
50382 -}
50383
50384 /*
50385 * Polling driver
50386 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50387 index 438d4c7..ca8a2fb 100644
50388 --- a/drivers/pnp/pnpbios/bioscalls.c
50389 +++ b/drivers/pnp/pnpbios/bioscalls.c
50390 @@ -59,7 +59,7 @@ do { \
50391 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50392 } while(0)
50393
50394 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50395 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50396 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50397
50398 /*
50399 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50400
50401 cpu = get_cpu();
50402 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50403 +
50404 + pax_open_kernel();
50405 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50406 + pax_close_kernel();
50407
50408 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50409 spin_lock_irqsave(&pnp_bios_lock, flags);
50410 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50411 :"memory");
50412 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50413
50414 + pax_open_kernel();
50415 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50416 + pax_close_kernel();
50417 +
50418 put_cpu();
50419
50420 /* If we get here and this is set then the PnP BIOS faulted on us. */
50421 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50422 return status;
50423 }
50424
50425 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50426 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50427 {
50428 int i;
50429
50430 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50431 pnp_bios_callpoint.offset = header->fields.pm16offset;
50432 pnp_bios_callpoint.segment = PNP_CS16;
50433
50434 + pax_open_kernel();
50435 +
50436 for_each_possible_cpu(i) {
50437 struct desc_struct *gdt = get_cpu_gdt_table(i);
50438 if (!gdt)
50439 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50440 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50441 (unsigned long)__va(header->fields.pm16dseg));
50442 }
50443 +
50444 + pax_close_kernel();
50445 }
50446 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50447 index 0c52e2a..3421ab7 100644
50448 --- a/drivers/power/pda_power.c
50449 +++ b/drivers/power/pda_power.c
50450 @@ -37,7 +37,11 @@ static int polling;
50451
50452 #if IS_ENABLED(CONFIG_USB_PHY)
50453 static struct usb_phy *transceiver;
50454 -static struct notifier_block otg_nb;
50455 +static int otg_handle_notification(struct notifier_block *nb,
50456 + unsigned long event, void *unused);
50457 +static struct notifier_block otg_nb = {
50458 + .notifier_call = otg_handle_notification
50459 +};
50460 #endif
50461
50462 static struct regulator *ac_draw;
50463 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50464
50465 #if IS_ENABLED(CONFIG_USB_PHY)
50466 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50467 - otg_nb.notifier_call = otg_handle_notification;
50468 ret = usb_register_notifier(transceiver, &otg_nb);
50469 if (ret) {
50470 dev_err(dev, "failure to register otg notifier\n");
50471 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50472 index cc439fd..8fa30df 100644
50473 --- a/drivers/power/power_supply.h
50474 +++ b/drivers/power/power_supply.h
50475 @@ -16,12 +16,12 @@ struct power_supply;
50476
50477 #ifdef CONFIG_SYSFS
50478
50479 -extern void power_supply_init_attrs(struct device_type *dev_type);
50480 +extern void power_supply_init_attrs(void);
50481 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50482
50483 #else
50484
50485 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50486 +static inline void power_supply_init_attrs(void) {}
50487 #define power_supply_uevent NULL
50488
50489 #endif /* CONFIG_SYSFS */
50490 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50491 index 694e8cd..9f03483 100644
50492 --- a/drivers/power/power_supply_core.c
50493 +++ b/drivers/power/power_supply_core.c
50494 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50495 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50496 EXPORT_SYMBOL_GPL(power_supply_notifier);
50497
50498 -static struct device_type power_supply_dev_type;
50499 +extern const struct attribute_group *power_supply_attr_groups[];
50500 +static struct device_type power_supply_dev_type = {
50501 + .groups = power_supply_attr_groups,
50502 +};
50503
50504 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50505 struct power_supply *supply)
50506 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50507 return PTR_ERR(power_supply_class);
50508
50509 power_supply_class->dev_uevent = power_supply_uevent;
50510 - power_supply_init_attrs(&power_supply_dev_type);
50511 + power_supply_init_attrs();
50512
50513 return 0;
50514 }
50515 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50516 index 62653f5..d0bb485 100644
50517 --- a/drivers/power/power_supply_sysfs.c
50518 +++ b/drivers/power/power_supply_sysfs.c
50519 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50520 .is_visible = power_supply_attr_is_visible,
50521 };
50522
50523 -static const struct attribute_group *power_supply_attr_groups[] = {
50524 +const struct attribute_group *power_supply_attr_groups[] = {
50525 &power_supply_attr_group,
50526 NULL,
50527 };
50528
50529 -void power_supply_init_attrs(struct device_type *dev_type)
50530 +void power_supply_init_attrs(void)
50531 {
50532 int i;
50533
50534 - dev_type->groups = power_supply_attr_groups;
50535 -
50536 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50537 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50538 }
50539 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50540 index 84419af..268ede8 100644
50541 --- a/drivers/powercap/powercap_sys.c
50542 +++ b/drivers/powercap/powercap_sys.c
50543 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50544 struct device_attribute name_attr;
50545 };
50546
50547 +static ssize_t show_constraint_name(struct device *dev,
50548 + struct device_attribute *dev_attr,
50549 + char *buf);
50550 +
50551 static struct powercap_constraint_attr
50552 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50553 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50554 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50555 + .power_limit_attr = {
50556 + .attr = {
50557 + .name = NULL,
50558 + .mode = S_IWUSR | S_IRUGO
50559 + },
50560 + .show = show_constraint_power_limit_uw,
50561 + .store = store_constraint_power_limit_uw
50562 + },
50563 +
50564 + .time_window_attr = {
50565 + .attr = {
50566 + .name = NULL,
50567 + .mode = S_IWUSR | S_IRUGO
50568 + },
50569 + .show = show_constraint_time_window_us,
50570 + .store = store_constraint_time_window_us
50571 + },
50572 +
50573 + .max_power_attr = {
50574 + .attr = {
50575 + .name = NULL,
50576 + .mode = S_IRUGO
50577 + },
50578 + .show = show_constraint_max_power_uw,
50579 + .store = NULL
50580 + },
50581 +
50582 + .min_power_attr = {
50583 + .attr = {
50584 + .name = NULL,
50585 + .mode = S_IRUGO
50586 + },
50587 + .show = show_constraint_min_power_uw,
50588 + .store = NULL
50589 + },
50590 +
50591 + .max_time_window_attr = {
50592 + .attr = {
50593 + .name = NULL,
50594 + .mode = S_IRUGO
50595 + },
50596 + .show = show_constraint_max_time_window_us,
50597 + .store = NULL
50598 + },
50599 +
50600 + .min_time_window_attr = {
50601 + .attr = {
50602 + .name = NULL,
50603 + .mode = S_IRUGO
50604 + },
50605 + .show = show_constraint_min_time_window_us,
50606 + .store = NULL
50607 + },
50608 +
50609 + .name_attr = {
50610 + .attr = {
50611 + .name = NULL,
50612 + .mode = S_IRUGO
50613 + },
50614 + .show = show_constraint_name,
50615 + .store = NULL
50616 + }
50617 + }
50618 +};
50619
50620 /* A list of powercap control_types */
50621 static LIST_HEAD(powercap_cntrl_list);
50622 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50623 }
50624
50625 static int create_constraint_attribute(int id, const char *name,
50626 - int mode,
50627 - struct device_attribute *dev_attr,
50628 - ssize_t (*show)(struct device *,
50629 - struct device_attribute *, char *),
50630 - ssize_t (*store)(struct device *,
50631 - struct device_attribute *,
50632 - const char *, size_t)
50633 - )
50634 + struct device_attribute *dev_attr)
50635 {
50636 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50637
50638 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50639 - id, name);
50640 - if (!dev_attr->attr.name)
50641 + if (!name)
50642 return -ENOMEM;
50643 - dev_attr->attr.mode = mode;
50644 - dev_attr->show = show;
50645 - dev_attr->store = store;
50646 +
50647 + pax_open_kernel();
50648 + *(const char **)&dev_attr->attr.name = name;
50649 + pax_close_kernel();
50650
50651 return 0;
50652 }
50653 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50654
50655 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50656 ret = create_constraint_attribute(i, "power_limit_uw",
50657 - S_IWUSR | S_IRUGO,
50658 - &constraint_attrs[i].power_limit_attr,
50659 - show_constraint_power_limit_uw,
50660 - store_constraint_power_limit_uw);
50661 + &constraint_attrs[i].power_limit_attr);
50662 if (ret)
50663 goto err_alloc;
50664 ret = create_constraint_attribute(i, "time_window_us",
50665 - S_IWUSR | S_IRUGO,
50666 - &constraint_attrs[i].time_window_attr,
50667 - show_constraint_time_window_us,
50668 - store_constraint_time_window_us);
50669 + &constraint_attrs[i].time_window_attr);
50670 if (ret)
50671 goto err_alloc;
50672 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50673 - &constraint_attrs[i].name_attr,
50674 - show_constraint_name,
50675 - NULL);
50676 + ret = create_constraint_attribute(i, "name",
50677 + &constraint_attrs[i].name_attr);
50678 if (ret)
50679 goto err_alloc;
50680 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50681 - &constraint_attrs[i].max_power_attr,
50682 - show_constraint_max_power_uw,
50683 - NULL);
50684 + ret = create_constraint_attribute(i, "max_power_uw",
50685 + &constraint_attrs[i].max_power_attr);
50686 if (ret)
50687 goto err_alloc;
50688 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50689 - &constraint_attrs[i].min_power_attr,
50690 - show_constraint_min_power_uw,
50691 - NULL);
50692 + ret = create_constraint_attribute(i, "min_power_uw",
50693 + &constraint_attrs[i].min_power_attr);
50694 if (ret)
50695 goto err_alloc;
50696 ret = create_constraint_attribute(i, "max_time_window_us",
50697 - S_IRUGO,
50698 - &constraint_attrs[i].max_time_window_attr,
50699 - show_constraint_max_time_window_us,
50700 - NULL);
50701 + &constraint_attrs[i].max_time_window_attr);
50702 if (ret)
50703 goto err_alloc;
50704 ret = create_constraint_attribute(i, "min_time_window_us",
50705 - S_IRUGO,
50706 - &constraint_attrs[i].min_time_window_attr,
50707 - show_constraint_min_time_window_us,
50708 - NULL);
50709 + &constraint_attrs[i].min_time_window_attr);
50710 if (ret)
50711 goto err_alloc;
50712
50713 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50714 power_zone->zone_dev_attrs[count++] =
50715 &dev_attr_max_energy_range_uj.attr;
50716 if (power_zone->ops->get_energy_uj) {
50717 + pax_open_kernel();
50718 if (power_zone->ops->reset_energy_uj)
50719 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50720 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50721 else
50722 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50723 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50724 + pax_close_kernel();
50725 power_zone->zone_dev_attrs[count++] =
50726 &dev_attr_energy_uj.attr;
50727 }
50728 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50729 index 9c5d414..c7900ce 100644
50730 --- a/drivers/ptp/ptp_private.h
50731 +++ b/drivers/ptp/ptp_private.h
50732 @@ -51,7 +51,7 @@ struct ptp_clock {
50733 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50734 wait_queue_head_t tsev_wq;
50735 int defunct; /* tells readers to go away when clock is being removed */
50736 - struct device_attribute *pin_dev_attr;
50737 + device_attribute_no_const *pin_dev_attr;
50738 struct attribute **pin_attr;
50739 struct attribute_group pin_attr_group;
50740 };
50741 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50742 index 302e626..12579af 100644
50743 --- a/drivers/ptp/ptp_sysfs.c
50744 +++ b/drivers/ptp/ptp_sysfs.c
50745 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50746 goto no_pin_attr;
50747
50748 for (i = 0; i < n_pins; i++) {
50749 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50750 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50751 sysfs_attr_init(&da->attr);
50752 da->attr.name = info->pin_config[i].name;
50753 da->attr.mode = 0644;
50754 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50755 index fc6fb54..b8c794ba 100644
50756 --- a/drivers/regulator/core.c
50757 +++ b/drivers/regulator/core.c
50758 @@ -3569,7 +3569,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50759 {
50760 const struct regulation_constraints *constraints = NULL;
50761 const struct regulator_init_data *init_data;
50762 - static atomic_t regulator_no = ATOMIC_INIT(0);
50763 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50764 struct regulator_dev *rdev;
50765 struct device *dev;
50766 int ret, i;
50767 @@ -3643,7 +3643,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50768 rdev->dev.class = &regulator_class;
50769 rdev->dev.parent = dev;
50770 dev_set_name(&rdev->dev, "regulator.%d",
50771 - atomic_inc_return(&regulator_no) - 1);
50772 + atomic_inc_return_unchecked(&regulator_no) - 1);
50773 ret = device_register(&rdev->dev);
50774 if (ret != 0) {
50775 put_device(&rdev->dev);
50776 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50777 index 7eee2ca..4024513 100644
50778 --- a/drivers/regulator/max8660.c
50779 +++ b/drivers/regulator/max8660.c
50780 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50781 max8660->shadow_regs[MAX8660_OVER1] = 5;
50782 } else {
50783 /* Otherwise devices can be toggled via software */
50784 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50785 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50786 + pax_open_kernel();
50787 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50788 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50789 + pax_close_kernel();
50790 }
50791
50792 /*
50793 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50794 index dbedf17..18ff6b7 100644
50795 --- a/drivers/regulator/max8973-regulator.c
50796 +++ b/drivers/regulator/max8973-regulator.c
50797 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50798 if (!pdata || !pdata->enable_ext_control) {
50799 max->desc.enable_reg = MAX8973_VOUT;
50800 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50801 - max->ops.enable = regulator_enable_regmap;
50802 - max->ops.disable = regulator_disable_regmap;
50803 - max->ops.is_enabled = regulator_is_enabled_regmap;
50804 + pax_open_kernel();
50805 + *(void **)&max->ops.enable = regulator_enable_regmap;
50806 + *(void **)&max->ops.disable = regulator_disable_regmap;
50807 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50808 + pax_close_kernel();
50809 }
50810
50811 if (pdata) {
50812 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50813 index 793b662..01c20fc 100644
50814 --- a/drivers/regulator/mc13892-regulator.c
50815 +++ b/drivers/regulator/mc13892-regulator.c
50816 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50817 mc13xxx_unlock(mc13892);
50818
50819 /* update mc13892_vcam ops */
50820 - memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50821 + pax_open_kernel();
50822 + memcpy((void *)&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50823 sizeof(struct regulator_ops));
50824 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50825 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50826 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50827 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50828 + pax_close_kernel();
50829 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50830
50831 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50832 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50833 index 5b2e761..c8c8a4a 100644
50834 --- a/drivers/rtc/rtc-cmos.c
50835 +++ b/drivers/rtc/rtc-cmos.c
50836 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50837 hpet_rtc_timer_init();
50838
50839 /* export at least the first block of NVRAM */
50840 - nvram.size = address_space - NVRAM_OFFSET;
50841 + pax_open_kernel();
50842 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50843 + pax_close_kernel();
50844 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50845 if (retval < 0) {
50846 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50847 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50848 index d049393..bb20be0 100644
50849 --- a/drivers/rtc/rtc-dev.c
50850 +++ b/drivers/rtc/rtc-dev.c
50851 @@ -16,6 +16,7 @@
50852 #include <linux/module.h>
50853 #include <linux/rtc.h>
50854 #include <linux/sched.h>
50855 +#include <linux/grsecurity.h>
50856 #include "rtc-core.h"
50857
50858 static dev_t rtc_devt;
50859 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50860 if (copy_from_user(&tm, uarg, sizeof(tm)))
50861 return -EFAULT;
50862
50863 + gr_log_timechange();
50864 +
50865 return rtc_set_time(rtc, &tm);
50866
50867 case RTC_PIE_ON:
50868 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50869 index bb43cf7..ee4d274 100644
50870 --- a/drivers/rtc/rtc-ds1307.c
50871 +++ b/drivers/rtc/rtc-ds1307.c
50872 @@ -107,7 +107,7 @@ struct ds1307 {
50873 u8 offset; /* register's offset */
50874 u8 regs[11];
50875 u16 nvram_offset;
50876 - struct bin_attribute *nvram;
50877 + bin_attribute_no_const *nvram;
50878 enum ds_type type;
50879 unsigned long flags;
50880 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50881 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50882 index 11880c1..b823aa4 100644
50883 --- a/drivers/rtc/rtc-m48t59.c
50884 +++ b/drivers/rtc/rtc-m48t59.c
50885 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50886 if (IS_ERR(m48t59->rtc))
50887 return PTR_ERR(m48t59->rtc);
50888
50889 - m48t59_nvram_attr.size = pdata->offset;
50890 + pax_open_kernel();
50891 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50892 + pax_close_kernel();
50893
50894 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50895 if (ret)
50896 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50897 index e693af6..2e525b6 100644
50898 --- a/drivers/scsi/bfa/bfa_fcpim.h
50899 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50900 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50901
50902 struct bfa_itn_s {
50903 bfa_isr_func_t isr;
50904 -};
50905 +} __no_const;
50906
50907 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50908 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50909 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50910 index 0f19455..ef7adb5 100644
50911 --- a/drivers/scsi/bfa/bfa_fcs.c
50912 +++ b/drivers/scsi/bfa/bfa_fcs.c
50913 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50914 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50915
50916 static struct bfa_fcs_mod_s fcs_modules[] = {
50917 - { bfa_fcs_port_attach, NULL, NULL },
50918 - { bfa_fcs_uf_attach, NULL, NULL },
50919 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50920 - bfa_fcs_fabric_modexit },
50921 + {
50922 + .attach = bfa_fcs_port_attach,
50923 + .modinit = NULL,
50924 + .modexit = NULL
50925 + },
50926 + {
50927 + .attach = bfa_fcs_uf_attach,
50928 + .modinit = NULL,
50929 + .modexit = NULL
50930 + },
50931 + {
50932 + .attach = bfa_fcs_fabric_attach,
50933 + .modinit = bfa_fcs_fabric_modinit,
50934 + .modexit = bfa_fcs_fabric_modexit
50935 + },
50936 };
50937
50938 /*
50939 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50940 index ff75ef8..2dfe00a 100644
50941 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50942 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50943 @@ -89,15 +89,26 @@ static struct {
50944 void (*offline) (struct bfa_fcs_lport_s *port);
50945 } __port_action[] = {
50946 {
50947 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50948 - bfa_fcs_lport_unknown_offline}, {
50949 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50950 - bfa_fcs_lport_fab_offline}, {
50951 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50952 - bfa_fcs_lport_n2n_offline}, {
50953 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50954 - bfa_fcs_lport_loop_offline},
50955 - };
50956 + .init = bfa_fcs_lport_unknown_init,
50957 + .online = bfa_fcs_lport_unknown_online,
50958 + .offline = bfa_fcs_lport_unknown_offline
50959 + },
50960 + {
50961 + .init = bfa_fcs_lport_fab_init,
50962 + .online = bfa_fcs_lport_fab_online,
50963 + .offline = bfa_fcs_lport_fab_offline
50964 + },
50965 + {
50966 + .init = bfa_fcs_lport_n2n_init,
50967 + .online = bfa_fcs_lport_n2n_online,
50968 + .offline = bfa_fcs_lport_n2n_offline
50969 + },
50970 + {
50971 + .init = bfa_fcs_lport_loop_init,
50972 + .online = bfa_fcs_lport_loop_online,
50973 + .offline = bfa_fcs_lport_loop_offline
50974 + },
50975 +};
50976
50977 /*
50978 * fcs_port_sm FCS logical port state machine
50979 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50980 index a38aafa0..fe8f03b 100644
50981 --- a/drivers/scsi/bfa/bfa_ioc.h
50982 +++ b/drivers/scsi/bfa/bfa_ioc.h
50983 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50984 bfa_ioc_disable_cbfn_t disable_cbfn;
50985 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50986 bfa_ioc_reset_cbfn_t reset_cbfn;
50987 -};
50988 +} __no_const;
50989
50990 /*
50991 * IOC event notification mechanism.
50992 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50993 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50994 enum bfi_ioc_state fwstate);
50995 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50996 -};
50997 +} __no_const;
50998
50999 /*
51000 * Queue element to wait for room in request queue. FIFO order is
51001 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51002 index a14c784..6de6790 100644
51003 --- a/drivers/scsi/bfa/bfa_modules.h
51004 +++ b/drivers/scsi/bfa/bfa_modules.h
51005 @@ -78,12 +78,12 @@ enum {
51006 \
51007 extern struct bfa_module_s hal_mod_ ## __mod; \
51008 struct bfa_module_s hal_mod_ ## __mod = { \
51009 - bfa_ ## __mod ## _meminfo, \
51010 - bfa_ ## __mod ## _attach, \
51011 - bfa_ ## __mod ## _detach, \
51012 - bfa_ ## __mod ## _start, \
51013 - bfa_ ## __mod ## _stop, \
51014 - bfa_ ## __mod ## _iocdisable, \
51015 + .meminfo = bfa_ ## __mod ## _meminfo, \
51016 + .attach = bfa_ ## __mod ## _attach, \
51017 + .detach = bfa_ ## __mod ## _detach, \
51018 + .start = bfa_ ## __mod ## _start, \
51019 + .stop = bfa_ ## __mod ## _stop, \
51020 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51021 }
51022
51023 #define BFA_CACHELINE_SZ (256)
51024 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51025 index 045c4e1..13de803 100644
51026 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51027 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51028 @@ -33,8 +33,8 @@
51029 */
51030 #include "libfcoe.h"
51031
51032 -static atomic_t ctlr_num;
51033 -static atomic_t fcf_num;
51034 +static atomic_unchecked_t ctlr_num;
51035 +static atomic_unchecked_t fcf_num;
51036
51037 /*
51038 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51039 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51040 if (!ctlr)
51041 goto out;
51042
51043 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51044 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51045 ctlr->f = f;
51046 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51047 INIT_LIST_HEAD(&ctlr->fcfs);
51048 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51049 fcf->dev.parent = &ctlr->dev;
51050 fcf->dev.bus = &fcoe_bus_type;
51051 fcf->dev.type = &fcoe_fcf_device_type;
51052 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51053 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51054 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51055
51056 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51057 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51058 {
51059 int error;
51060
51061 - atomic_set(&ctlr_num, 0);
51062 - atomic_set(&fcf_num, 0);
51063 + atomic_set_unchecked(&ctlr_num, 0);
51064 + atomic_set_unchecked(&fcf_num, 0);
51065
51066 error = bus_register(&fcoe_bus_type);
51067 if (error)
51068 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51069 index 6de80e3..a11e0ac 100644
51070 --- a/drivers/scsi/hosts.c
51071 +++ b/drivers/scsi/hosts.c
51072 @@ -42,7 +42,7 @@
51073 #include "scsi_logging.h"
51074
51075
51076 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51077 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51078
51079
51080 static void scsi_host_cls_release(struct device *dev)
51081 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51082 * subtract one because we increment first then return, but we need to
51083 * know what the next host number was before increment
51084 */
51085 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51086 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51087 shost->dma_channel = 0xff;
51088
51089 /* These three are default values which can be overridden */
51090 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51091 index cef5d49..01e280e 100644
51092 --- a/drivers/scsi/hpsa.c
51093 +++ b/drivers/scsi/hpsa.c
51094 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51095 unsigned long flags;
51096
51097 if (h->transMethod & CFGTBL_Trans_io_accel1)
51098 - return h->access.command_completed(h, q);
51099 + return h->access->command_completed(h, q);
51100
51101 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51102 - return h->access.command_completed(h, q);
51103 + return h->access->command_completed(h, q);
51104
51105 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51106 a = rq->head[rq->current_entry];
51107 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51108 while (!list_empty(&h->reqQ)) {
51109 c = list_entry(h->reqQ.next, struct CommandList, list);
51110 /* can't do anything if fifo is full */
51111 - if ((h->access.fifo_full(h))) {
51112 + if ((h->access->fifo_full(h))) {
51113 h->fifo_recently_full = 1;
51114 dev_warn(&h->pdev->dev, "fifo full\n");
51115 break;
51116 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51117
51118 /* Tell the controller execute command */
51119 spin_unlock_irqrestore(&h->lock, *flags);
51120 - h->access.submit_command(h, c);
51121 + h->access->submit_command(h, c);
51122 spin_lock_irqsave(&h->lock, *flags);
51123 }
51124 }
51125 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51126
51127 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51128 {
51129 - return h->access.command_completed(h, q);
51130 + return h->access->command_completed(h, q);
51131 }
51132
51133 static inline bool interrupt_pending(struct ctlr_info *h)
51134 {
51135 - return h->access.intr_pending(h);
51136 + return h->access->intr_pending(h);
51137 }
51138
51139 static inline long interrupt_not_for_us(struct ctlr_info *h)
51140 {
51141 - return (h->access.intr_pending(h) == 0) ||
51142 + return (h->access->intr_pending(h) == 0) ||
51143 (h->interrupts_enabled == 0);
51144 }
51145
51146 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51147 if (prod_index < 0)
51148 return -ENODEV;
51149 h->product_name = products[prod_index].product_name;
51150 - h->access = *(products[prod_index].access);
51151 + h->access = products[prod_index].access;
51152
51153 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51154 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51155 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51156 unsigned long flags;
51157 u32 lockup_detected;
51158
51159 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51160 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51161 spin_lock_irqsave(&h->lock, flags);
51162 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51163 if (!lockup_detected) {
51164 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51165 }
51166
51167 /* make sure the board interrupts are off */
51168 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51169 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51170
51171 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51172 goto clean2;
51173 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51174 * fake ones to scoop up any residual completions.
51175 */
51176 spin_lock_irqsave(&h->lock, flags);
51177 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51178 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51179 spin_unlock_irqrestore(&h->lock, flags);
51180 free_irqs(h);
51181 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51182 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51183 dev_info(&h->pdev->dev, "Board READY.\n");
51184 dev_info(&h->pdev->dev,
51185 "Waiting for stale completions to drain.\n");
51186 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51187 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51188 msleep(10000);
51189 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51190 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51191
51192 rc = controller_reset_failed(h->cfgtable);
51193 if (rc)
51194 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51195 h->drv_req_rescan = 0;
51196
51197 /* Turn the interrupts on so we can service requests */
51198 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51199 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51200
51201 hpsa_hba_inquiry(h);
51202 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51203 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51204 * To write all data in the battery backed cache to disks
51205 */
51206 hpsa_flush_cache(h);
51207 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51208 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51209 hpsa_free_irqs_and_disable_msix(h);
51210 }
51211
51212 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51213 CFGTBL_Trans_enable_directed_msix |
51214 (trans_support & (CFGTBL_Trans_io_accel1 |
51215 CFGTBL_Trans_io_accel2));
51216 - struct access_method access = SA5_performant_access;
51217 + struct access_method *access = &SA5_performant_access;
51218
51219 /* This is a bit complicated. There are 8 registers on
51220 * the controller which we write to to tell it 8 different
51221 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51222 * perform the superfluous readl() after each command submission.
51223 */
51224 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51225 - access = SA5_performant_access_no_read;
51226 + access = &SA5_performant_access_no_read;
51227
51228 /* Controller spec: zero out this buffer. */
51229 for (i = 0; i < h->nreply_queues; i++)
51230 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51231 * enable outbound interrupt coalescing in accelerator mode;
51232 */
51233 if (trans_support & CFGTBL_Trans_io_accel1) {
51234 - access = SA5_ioaccel_mode1_access;
51235 + access = &SA5_ioaccel_mode1_access;
51236 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51237 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51238 } else {
51239 if (trans_support & CFGTBL_Trans_io_accel2) {
51240 - access = SA5_ioaccel_mode2_access;
51241 + access = &SA5_ioaccel_mode2_access;
51242 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51243 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51244 }
51245 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51246 index 24472ce..8782caf 100644
51247 --- a/drivers/scsi/hpsa.h
51248 +++ b/drivers/scsi/hpsa.h
51249 @@ -127,7 +127,7 @@ struct ctlr_info {
51250 unsigned int msix_vector;
51251 unsigned int msi_vector;
51252 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51253 - struct access_method access;
51254 + struct access_method *access;
51255 char hba_mode_enabled;
51256
51257 /* queue and queue Info */
51258 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51259 }
51260
51261 static struct access_method SA5_access = {
51262 - SA5_submit_command,
51263 - SA5_intr_mask,
51264 - SA5_fifo_full,
51265 - SA5_intr_pending,
51266 - SA5_completed,
51267 + .submit_command = SA5_submit_command,
51268 + .set_intr_mask = SA5_intr_mask,
51269 + .fifo_full = SA5_fifo_full,
51270 + .intr_pending = SA5_intr_pending,
51271 + .command_completed = SA5_completed,
51272 };
51273
51274 static struct access_method SA5_ioaccel_mode1_access = {
51275 - SA5_submit_command,
51276 - SA5_performant_intr_mask,
51277 - SA5_fifo_full,
51278 - SA5_ioaccel_mode1_intr_pending,
51279 - SA5_ioaccel_mode1_completed,
51280 + .submit_command = SA5_submit_command,
51281 + .set_intr_mask = SA5_performant_intr_mask,
51282 + .fifo_full = SA5_fifo_full,
51283 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51284 + .command_completed = SA5_ioaccel_mode1_completed,
51285 };
51286
51287 static struct access_method SA5_ioaccel_mode2_access = {
51288 - SA5_submit_command_ioaccel2,
51289 - SA5_performant_intr_mask,
51290 - SA5_fifo_full,
51291 - SA5_performant_intr_pending,
51292 - SA5_performant_completed,
51293 + .submit_command = SA5_submit_command_ioaccel2,
51294 + .set_intr_mask = SA5_performant_intr_mask,
51295 + .fifo_full = SA5_fifo_full,
51296 + .intr_pending = SA5_performant_intr_pending,
51297 + .command_completed = SA5_performant_completed,
51298 };
51299
51300 static struct access_method SA5_performant_access = {
51301 - SA5_submit_command,
51302 - SA5_performant_intr_mask,
51303 - SA5_fifo_full,
51304 - SA5_performant_intr_pending,
51305 - SA5_performant_completed,
51306 + .submit_command = SA5_submit_command,
51307 + .set_intr_mask = SA5_performant_intr_mask,
51308 + .fifo_full = SA5_fifo_full,
51309 + .intr_pending = SA5_performant_intr_pending,
51310 + .command_completed = SA5_performant_completed,
51311 };
51312
51313 static struct access_method SA5_performant_access_no_read = {
51314 - SA5_submit_command_no_read,
51315 - SA5_performant_intr_mask,
51316 - SA5_fifo_full,
51317 - SA5_performant_intr_pending,
51318 - SA5_performant_completed,
51319 + .submit_command = SA5_submit_command_no_read,
51320 + .set_intr_mask = SA5_performant_intr_mask,
51321 + .fifo_full = SA5_fifo_full,
51322 + .intr_pending = SA5_performant_intr_pending,
51323 + .command_completed = SA5_performant_completed,
51324 };
51325
51326 struct board_type {
51327 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51328 index 1b3a094..068e683 100644
51329 --- a/drivers/scsi/libfc/fc_exch.c
51330 +++ b/drivers/scsi/libfc/fc_exch.c
51331 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51332 u16 pool_max_index;
51333
51334 struct {
51335 - atomic_t no_free_exch;
51336 - atomic_t no_free_exch_xid;
51337 - atomic_t xid_not_found;
51338 - atomic_t xid_busy;
51339 - atomic_t seq_not_found;
51340 - atomic_t non_bls_resp;
51341 + atomic_unchecked_t no_free_exch;
51342 + atomic_unchecked_t no_free_exch_xid;
51343 + atomic_unchecked_t xid_not_found;
51344 + atomic_unchecked_t xid_busy;
51345 + atomic_unchecked_t seq_not_found;
51346 + atomic_unchecked_t non_bls_resp;
51347 } stats;
51348 };
51349
51350 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51351 /* allocate memory for exchange */
51352 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51353 if (!ep) {
51354 - atomic_inc(&mp->stats.no_free_exch);
51355 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51356 goto out;
51357 }
51358 memset(ep, 0, sizeof(*ep));
51359 @@ -874,7 +874,7 @@ out:
51360 return ep;
51361 err:
51362 spin_unlock_bh(&pool->lock);
51363 - atomic_inc(&mp->stats.no_free_exch_xid);
51364 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51365 mempool_free(ep, mp->ep_pool);
51366 return NULL;
51367 }
51368 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51369 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51370 ep = fc_exch_find(mp, xid);
51371 if (!ep) {
51372 - atomic_inc(&mp->stats.xid_not_found);
51373 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51374 reject = FC_RJT_OX_ID;
51375 goto out;
51376 }
51377 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51378 ep = fc_exch_find(mp, xid);
51379 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51380 if (ep) {
51381 - atomic_inc(&mp->stats.xid_busy);
51382 + atomic_inc_unchecked(&mp->stats.xid_busy);
51383 reject = FC_RJT_RX_ID;
51384 goto rel;
51385 }
51386 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51387 }
51388 xid = ep->xid; /* get our XID */
51389 } else if (!ep) {
51390 - atomic_inc(&mp->stats.xid_not_found);
51391 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51392 reject = FC_RJT_RX_ID; /* XID not found */
51393 goto out;
51394 }
51395 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51396 } else {
51397 sp = &ep->seq;
51398 if (sp->id != fh->fh_seq_id) {
51399 - atomic_inc(&mp->stats.seq_not_found);
51400 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51401 if (f_ctl & FC_FC_END_SEQ) {
51402 /*
51403 * Update sequence_id based on incoming last
51404 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51405
51406 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51407 if (!ep) {
51408 - atomic_inc(&mp->stats.xid_not_found);
51409 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51410 goto out;
51411 }
51412 if (ep->esb_stat & ESB_ST_COMPLETE) {
51413 - atomic_inc(&mp->stats.xid_not_found);
51414 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51415 goto rel;
51416 }
51417 if (ep->rxid == FC_XID_UNKNOWN)
51418 ep->rxid = ntohs(fh->fh_rx_id);
51419 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51420 - atomic_inc(&mp->stats.xid_not_found);
51421 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51422 goto rel;
51423 }
51424 if (ep->did != ntoh24(fh->fh_s_id) &&
51425 ep->did != FC_FID_FLOGI) {
51426 - atomic_inc(&mp->stats.xid_not_found);
51427 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51428 goto rel;
51429 }
51430 sof = fr_sof(fp);
51431 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51432 sp->ssb_stat |= SSB_ST_RESP;
51433 sp->id = fh->fh_seq_id;
51434 } else if (sp->id != fh->fh_seq_id) {
51435 - atomic_inc(&mp->stats.seq_not_found);
51436 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51437 goto rel;
51438 }
51439
51440 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51441 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51442
51443 if (!sp)
51444 - atomic_inc(&mp->stats.xid_not_found);
51445 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51446 else
51447 - atomic_inc(&mp->stats.non_bls_resp);
51448 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51449
51450 fc_frame_free(fp);
51451 }
51452 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51453
51454 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51455 mp = ema->mp;
51456 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51457 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51458 st->fc_no_free_exch_xid +=
51459 - atomic_read(&mp->stats.no_free_exch_xid);
51460 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51461 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51462 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51463 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51464 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51465 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51466 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51467 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51468 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51469 }
51470 }
51471 EXPORT_SYMBOL(fc_exch_update_stats);
51472 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51473 index 766098a..1c6c971 100644
51474 --- a/drivers/scsi/libsas/sas_ata.c
51475 +++ b/drivers/scsi/libsas/sas_ata.c
51476 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51477 .postreset = ata_std_postreset,
51478 .error_handler = ata_std_error_handler,
51479 .post_internal_cmd = sas_ata_post_internal,
51480 - .qc_defer = ata_std_qc_defer,
51481 + .qc_defer = ata_std_qc_defer,
51482 .qc_prep = ata_noop_qc_prep,
51483 .qc_issue = sas_ata_qc_issue,
51484 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51485 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51486 index 434e903..5a4a79b 100644
51487 --- a/drivers/scsi/lpfc/lpfc.h
51488 +++ b/drivers/scsi/lpfc/lpfc.h
51489 @@ -430,7 +430,7 @@ struct lpfc_vport {
51490 struct dentry *debug_nodelist;
51491 struct dentry *vport_debugfs_root;
51492 struct lpfc_debugfs_trc *disc_trc;
51493 - atomic_t disc_trc_cnt;
51494 + atomic_unchecked_t disc_trc_cnt;
51495 #endif
51496 uint8_t stat_data_enabled;
51497 uint8_t stat_data_blocked;
51498 @@ -880,8 +880,8 @@ struct lpfc_hba {
51499 struct timer_list fabric_block_timer;
51500 unsigned long bit_flags;
51501 #define FABRIC_COMANDS_BLOCKED 0
51502 - atomic_t num_rsrc_err;
51503 - atomic_t num_cmd_success;
51504 + atomic_unchecked_t num_rsrc_err;
51505 + atomic_unchecked_t num_cmd_success;
51506 unsigned long last_rsrc_error_time;
51507 unsigned long last_ramp_down_time;
51508 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51509 @@ -916,7 +916,7 @@ struct lpfc_hba {
51510
51511 struct dentry *debug_slow_ring_trc;
51512 struct lpfc_debugfs_trc *slow_ring_trc;
51513 - atomic_t slow_ring_trc_cnt;
51514 + atomic_unchecked_t slow_ring_trc_cnt;
51515 /* iDiag debugfs sub-directory */
51516 struct dentry *idiag_root;
51517 struct dentry *idiag_pci_cfg;
51518 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51519 index 786a2af..562c6a2 100644
51520 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51521 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51522 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51523
51524 #include <linux/debugfs.h>
51525
51526 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51527 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51528 static unsigned long lpfc_debugfs_start_time = 0L;
51529
51530 /* iDiag */
51531 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51532 lpfc_debugfs_enable = 0;
51533
51534 len = 0;
51535 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51536 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51537 (lpfc_debugfs_max_disc_trc - 1);
51538 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51539 dtp = vport->disc_trc + i;
51540 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51541 lpfc_debugfs_enable = 0;
51542
51543 len = 0;
51544 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51545 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51546 (lpfc_debugfs_max_slow_ring_trc - 1);
51547 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51548 dtp = phba->slow_ring_trc + i;
51549 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51550 !vport || !vport->disc_trc)
51551 return;
51552
51553 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51554 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51555 (lpfc_debugfs_max_disc_trc - 1);
51556 dtp = vport->disc_trc + index;
51557 dtp->fmt = fmt;
51558 dtp->data1 = data1;
51559 dtp->data2 = data2;
51560 dtp->data3 = data3;
51561 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51562 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51563 dtp->jif = jiffies;
51564 #endif
51565 return;
51566 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51567 !phba || !phba->slow_ring_trc)
51568 return;
51569
51570 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51571 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51572 (lpfc_debugfs_max_slow_ring_trc - 1);
51573 dtp = phba->slow_ring_trc + index;
51574 dtp->fmt = fmt;
51575 dtp->data1 = data1;
51576 dtp->data2 = data2;
51577 dtp->data3 = data3;
51578 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51579 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51580 dtp->jif = jiffies;
51581 #endif
51582 return;
51583 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51584 "slow_ring buffer\n");
51585 goto debug_failed;
51586 }
51587 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51588 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51589 memset(phba->slow_ring_trc, 0,
51590 (sizeof(struct lpfc_debugfs_trc) *
51591 lpfc_debugfs_max_slow_ring_trc));
51592 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51593 "buffer\n");
51594 goto debug_failed;
51595 }
51596 - atomic_set(&vport->disc_trc_cnt, 0);
51597 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51598
51599 snprintf(name, sizeof(name), "discovery_trace");
51600 vport->debug_disc_trc =
51601 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51602 index 0b2c53a..aec2b45 100644
51603 --- a/drivers/scsi/lpfc/lpfc_init.c
51604 +++ b/drivers/scsi/lpfc/lpfc_init.c
51605 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51606 "misc_register returned with status %d", error);
51607
51608 if (lpfc_enable_npiv) {
51609 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51610 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51611 + pax_open_kernel();
51612 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51613 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51614 + pax_close_kernel();
51615 }
51616 lpfc_transport_template =
51617 fc_attach_transport(&lpfc_transport_functions);
51618 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51619 index b99399f..d29dc75 100644
51620 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51621 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51622 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51623 unsigned long expires;
51624
51625 spin_lock_irqsave(&phba->hbalock, flags);
51626 - atomic_inc(&phba->num_rsrc_err);
51627 + atomic_inc_unchecked(&phba->num_rsrc_err);
51628 phba->last_rsrc_error_time = jiffies;
51629
51630 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51631 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51632 unsigned long num_rsrc_err, num_cmd_success;
51633 int i;
51634
51635 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51636 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51637 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51638 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51639
51640 /*
51641 * The error and success command counters are global per
51642 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51643 }
51644 }
51645 lpfc_destroy_vport_work_array(phba, vports);
51646 - atomic_set(&phba->num_rsrc_err, 0);
51647 - atomic_set(&phba->num_cmd_success, 0);
51648 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51649 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51650 }
51651
51652 /**
51653 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51654 index c80ed04..e674f01 100644
51655 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51656 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51657 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51658 {
51659 struct scsi_device *sdev = to_scsi_device(dev);
51660 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51661 - static struct _raid_device *raid_device;
51662 + struct _raid_device *raid_device;
51663 unsigned long flags;
51664 Mpi2RaidVolPage0_t vol_pg0;
51665 Mpi2ConfigReply_t mpi_reply;
51666 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51667 {
51668 struct scsi_device *sdev = to_scsi_device(dev);
51669 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51670 - static struct _raid_device *raid_device;
51671 + struct _raid_device *raid_device;
51672 unsigned long flags;
51673 Mpi2RaidVolPage0_t vol_pg0;
51674 Mpi2ConfigReply_t mpi_reply;
51675 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51676 Mpi2EventDataIrOperationStatus_t *event_data =
51677 (Mpi2EventDataIrOperationStatus_t *)
51678 fw_event->event_data;
51679 - static struct _raid_device *raid_device;
51680 + struct _raid_device *raid_device;
51681 unsigned long flags;
51682 u16 handle;
51683
51684 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51685 u64 sas_address;
51686 struct _sas_device *sas_device;
51687 struct _sas_node *expander_device;
51688 - static struct _raid_device *raid_device;
51689 + struct _raid_device *raid_device;
51690 u8 retry_count;
51691 unsigned long flags;
51692
51693 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51694 index bcb64eb..f08cf71 100644
51695 --- a/drivers/scsi/pmcraid.c
51696 +++ b/drivers/scsi/pmcraid.c
51697 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51698 res->scsi_dev = scsi_dev;
51699 scsi_dev->hostdata = res;
51700 res->change_detected = 0;
51701 - atomic_set(&res->read_failures, 0);
51702 - atomic_set(&res->write_failures, 0);
51703 + atomic_set_unchecked(&res->read_failures, 0);
51704 + atomic_set_unchecked(&res->write_failures, 0);
51705 rc = 0;
51706 }
51707 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51708 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51709
51710 /* If this was a SCSI read/write command keep count of errors */
51711 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51712 - atomic_inc(&res->read_failures);
51713 + atomic_inc_unchecked(&res->read_failures);
51714 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51715 - atomic_inc(&res->write_failures);
51716 + atomic_inc_unchecked(&res->write_failures);
51717
51718 if (!RES_IS_GSCSI(res->cfg_entry) &&
51719 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51720 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51721 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51722 * hrrq_id assigned here in queuecommand
51723 */
51724 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51725 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51726 pinstance->num_hrrq;
51727 cmd->cmd_done = pmcraid_io_done;
51728
51729 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51730 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51731 * hrrq_id assigned here in queuecommand
51732 */
51733 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51734 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51735 pinstance->num_hrrq;
51736
51737 if (request_size) {
51738 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51739
51740 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51741 /* add resources only after host is added into system */
51742 - if (!atomic_read(&pinstance->expose_resources))
51743 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51744 return;
51745
51746 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51747 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51748 init_waitqueue_head(&pinstance->reset_wait_q);
51749
51750 atomic_set(&pinstance->outstanding_cmds, 0);
51751 - atomic_set(&pinstance->last_message_id, 0);
51752 - atomic_set(&pinstance->expose_resources, 0);
51753 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51754 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51755
51756 INIT_LIST_HEAD(&pinstance->free_res_q);
51757 INIT_LIST_HEAD(&pinstance->used_res_q);
51758 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51759 /* Schedule worker thread to handle CCN and take care of adding and
51760 * removing devices to OS
51761 */
51762 - atomic_set(&pinstance->expose_resources, 1);
51763 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51764 schedule_work(&pinstance->worker_q);
51765 return rc;
51766
51767 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51768 index e1d150f..6c6df44 100644
51769 --- a/drivers/scsi/pmcraid.h
51770 +++ b/drivers/scsi/pmcraid.h
51771 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51772 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51773
51774 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51775 - atomic_t last_message_id;
51776 + atomic_unchecked_t last_message_id;
51777
51778 /* configuration table */
51779 struct pmcraid_config_table *cfg_table;
51780 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51781 atomic_t outstanding_cmds;
51782
51783 /* should add/delete resources to mid-layer now ?*/
51784 - atomic_t expose_resources;
51785 + atomic_unchecked_t expose_resources;
51786
51787
51788
51789 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51790 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51791 };
51792 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51793 - atomic_t read_failures; /* count of failed READ commands */
51794 - atomic_t write_failures; /* count of failed WRITE commands */
51795 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51796 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51797
51798 /* To indicate add/delete/modify during CCN */
51799 u8 change_detected;
51800 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51801 index 82b92c4..3178171 100644
51802 --- a/drivers/scsi/qla2xxx/qla_attr.c
51803 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51804 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51805 return 0;
51806 }
51807
51808 -struct fc_function_template qla2xxx_transport_functions = {
51809 +fc_function_template_no_const qla2xxx_transport_functions = {
51810
51811 .show_host_node_name = 1,
51812 .show_host_port_name = 1,
51813 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51814 .bsg_timeout = qla24xx_bsg_timeout,
51815 };
51816
51817 -struct fc_function_template qla2xxx_transport_vport_functions = {
51818 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51819
51820 .show_host_node_name = 1,
51821 .show_host_port_name = 1,
51822 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51823 index b1865a7..a7723d3 100644
51824 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51825 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51826 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51827 struct device_attribute;
51828 extern struct device_attribute *qla2x00_host_attrs[];
51829 struct fc_function_template;
51830 -extern struct fc_function_template qla2xxx_transport_functions;
51831 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51832 +extern fc_function_template_no_const qla2xxx_transport_functions;
51833 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51834 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51835 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51836 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51837 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51838 index db3dbd9..2492392 100644
51839 --- a/drivers/scsi/qla2xxx/qla_os.c
51840 +++ b/drivers/scsi/qla2xxx/qla_os.c
51841 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51842 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51843 /* Ok, a 64bit DMA mask is applicable. */
51844 ha->flags.enable_64bit_addressing = 1;
51845 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51846 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51847 + pax_open_kernel();
51848 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51849 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51850 + pax_close_kernel();
51851 return;
51852 }
51853 }
51854 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51855 index 8f6d0fb..1b21097 100644
51856 --- a/drivers/scsi/qla4xxx/ql4_def.h
51857 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51858 @@ -305,7 +305,7 @@ struct ddb_entry {
51859 * (4000 only) */
51860 atomic_t relogin_timer; /* Max Time to wait for
51861 * relogin to complete */
51862 - atomic_t relogin_retry_count; /* Num of times relogin has been
51863 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51864 * retried */
51865 uint32_t default_time2wait; /* Default Min time between
51866 * relogins (+aens) */
51867 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51868 index 199fcf7..3c3a918 100644
51869 --- a/drivers/scsi/qla4xxx/ql4_os.c
51870 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51871 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51872 */
51873 if (!iscsi_is_session_online(cls_sess)) {
51874 /* Reset retry relogin timer */
51875 - atomic_inc(&ddb_entry->relogin_retry_count);
51876 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51877 DEBUG2(ql4_printk(KERN_INFO, ha,
51878 "%s: index[%d] relogin timed out-retrying"
51879 " relogin (%d), retry (%d)\n", __func__,
51880 ddb_entry->fw_ddb_index,
51881 - atomic_read(&ddb_entry->relogin_retry_count),
51882 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51883 ddb_entry->default_time2wait + 4));
51884 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51885 atomic_set(&ddb_entry->retry_relogin_timer,
51886 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51887
51888 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51889 atomic_set(&ddb_entry->relogin_timer, 0);
51890 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51891 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51892 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51893 ddb_entry->default_relogin_timeout =
51894 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51895 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51896 index 79c77b4..ef6ec0b 100644
51897 --- a/drivers/scsi/scsi.c
51898 +++ b/drivers/scsi/scsi.c
51899 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51900 struct Scsi_Host *host = cmd->device->host;
51901 int rtn = 0;
51902
51903 - atomic_inc(&cmd->device->iorequest_cnt);
51904 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51905
51906 /* check if the device is still usable */
51907 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51908 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51909 index 17fb051..937fbbd 100644
51910 --- a/drivers/scsi/scsi_lib.c
51911 +++ b/drivers/scsi/scsi_lib.c
51912 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51913 shost = sdev->host;
51914 scsi_init_cmd_errh(cmd);
51915 cmd->result = DID_NO_CONNECT << 16;
51916 - atomic_inc(&cmd->device->iorequest_cnt);
51917 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51918
51919 /*
51920 * SCSI request completion path will do scsi_device_unbusy(),
51921 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51922
51923 INIT_LIST_HEAD(&cmd->eh_entry);
51924
51925 - atomic_inc(&cmd->device->iodone_cnt);
51926 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51927 if (cmd->result)
51928 - atomic_inc(&cmd->device->ioerr_cnt);
51929 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51930
51931 disposition = scsi_decide_disposition(cmd);
51932 if (disposition != SUCCESS &&
51933 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51934 index f4cb7b3..dfa79c4 100644
51935 --- a/drivers/scsi/scsi_sysfs.c
51936 +++ b/drivers/scsi/scsi_sysfs.c
51937 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51938 char *buf) \
51939 { \
51940 struct scsi_device *sdev = to_scsi_device(dev); \
51941 - unsigned long long count = atomic_read(&sdev->field); \
51942 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51943 return snprintf(buf, 20, "0x%llx\n", count); \
51944 } \
51945 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51946 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51947 index 5d6f348..18778a6b 100644
51948 --- a/drivers/scsi/scsi_transport_fc.c
51949 +++ b/drivers/scsi/scsi_transport_fc.c
51950 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51951 * Netlink Infrastructure
51952 */
51953
51954 -static atomic_t fc_event_seq;
51955 +static atomic_unchecked_t fc_event_seq;
51956
51957 /**
51958 * fc_get_event_number - Obtain the next sequential FC event number
51959 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51960 u32
51961 fc_get_event_number(void)
51962 {
51963 - return atomic_add_return(1, &fc_event_seq);
51964 + return atomic_add_return_unchecked(1, &fc_event_seq);
51965 }
51966 EXPORT_SYMBOL(fc_get_event_number);
51967
51968 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51969 {
51970 int error;
51971
51972 - atomic_set(&fc_event_seq, 0);
51973 + atomic_set_unchecked(&fc_event_seq, 0);
51974
51975 error = transport_class_register(&fc_host_class);
51976 if (error)
51977 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51978 char *cp;
51979
51980 *val = simple_strtoul(buf, &cp, 0);
51981 - if ((*cp && (*cp != '\n')) || (*val < 0))
51982 + if (*cp && (*cp != '\n'))
51983 return -EINVAL;
51984 /*
51985 * Check for overflow; dev_loss_tmo is u32
51986 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51987 index 67d43e3..8cee73c 100644
51988 --- a/drivers/scsi/scsi_transport_iscsi.c
51989 +++ b/drivers/scsi/scsi_transport_iscsi.c
51990 @@ -79,7 +79,7 @@ struct iscsi_internal {
51991 struct transport_container session_cont;
51992 };
51993
51994 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51995 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51996 static struct workqueue_struct *iscsi_eh_timer_workq;
51997
51998 static DEFINE_IDA(iscsi_sess_ida);
51999 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52000 int err;
52001
52002 ihost = shost->shost_data;
52003 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52004 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52005
52006 if (target_id == ISCSI_MAX_TARGET) {
52007 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52008 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52009 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52010 ISCSI_TRANSPORT_VERSION);
52011
52012 - atomic_set(&iscsi_session_nr, 0);
52013 + atomic_set_unchecked(&iscsi_session_nr, 0);
52014
52015 err = class_register(&iscsi_transport_class);
52016 if (err)
52017 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52018 index ae45bd9..c32a586 100644
52019 --- a/drivers/scsi/scsi_transport_srp.c
52020 +++ b/drivers/scsi/scsi_transport_srp.c
52021 @@ -35,7 +35,7 @@
52022 #include "scsi_priv.h"
52023
52024 struct srp_host_attrs {
52025 - atomic_t next_port_id;
52026 + atomic_unchecked_t next_port_id;
52027 };
52028 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52029
52030 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52031 struct Scsi_Host *shost = dev_to_shost(dev);
52032 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52033
52034 - atomic_set(&srp_host->next_port_id, 0);
52035 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52036 return 0;
52037 }
52038
52039 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52040 rport_fast_io_fail_timedout);
52041 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52042
52043 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52044 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52045 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52046
52047 transport_setup_device(&rport->dev);
52048 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52049 index dd8c8d6..4cdf6a1 100644
52050 --- a/drivers/scsi/sd.c
52051 +++ b/drivers/scsi/sd.c
52052 @@ -3024,7 +3024,7 @@ static int sd_probe(struct device *dev)
52053 sdkp->disk = gd;
52054 sdkp->index = index;
52055 atomic_set(&sdkp->openers, 0);
52056 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52057 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52058
52059 if (!sdp->request_queue->rq_timeout) {
52060 if (sdp->type != TYPE_MOD)
52061 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52062 index 6035444..c82edd4 100644
52063 --- a/drivers/scsi/sg.c
52064 +++ b/drivers/scsi/sg.c
52065 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52066 sdp->disk->disk_name,
52067 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52068 NULL,
52069 - (char *)arg);
52070 + (char __user *)arg);
52071 case BLKTRACESTART:
52072 return blk_trace_startstop(sdp->device->request_queue, 1);
52073 case BLKTRACESTOP:
52074 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52075 index 11a5043..e36f04c 100644
52076 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52077 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52078 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52079 return i;
52080 }
52081
52082 -static struct bin_attribute fuse_bin_attr = {
52083 +static bin_attribute_no_const fuse_bin_attr = {
52084 .attr = { .name = "fuse", .mode = S_IRUGO, },
52085 .read = fuse_read,
52086 };
52087 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52088 index 50f20f2..6bd81e0 100644
52089 --- a/drivers/spi/spi.c
52090 +++ b/drivers/spi/spi.c
52091 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
52092 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52093
52094 /* portable code must never pass more than 32 bytes */
52095 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52096 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52097
52098 static u8 *buf;
52099
52100 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52101 index b41429f..2de5373 100644
52102 --- a/drivers/staging/android/timed_output.c
52103 +++ b/drivers/staging/android/timed_output.c
52104 @@ -25,7 +25,7 @@
52105 #include "timed_output.h"
52106
52107 static struct class *timed_output_class;
52108 -static atomic_t device_count;
52109 +static atomic_unchecked_t device_count;
52110
52111 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52112 char *buf)
52113 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52114 timed_output_class = class_create(THIS_MODULE, "timed_output");
52115 if (IS_ERR(timed_output_class))
52116 return PTR_ERR(timed_output_class);
52117 - atomic_set(&device_count, 0);
52118 + atomic_set_unchecked(&device_count, 0);
52119 timed_output_class->dev_groups = timed_output_groups;
52120 }
52121
52122 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52123 if (ret < 0)
52124 return ret;
52125
52126 - tdev->index = atomic_inc_return(&device_count);
52127 + tdev->index = atomic_inc_return_unchecked(&device_count);
52128 tdev->dev = device_create(timed_output_class, NULL,
52129 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52130 if (IS_ERR(tdev->dev))
52131 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52132 index 001348c..cfaac8a 100644
52133 --- a/drivers/staging/gdm724x/gdm_tty.c
52134 +++ b/drivers/staging/gdm724x/gdm_tty.c
52135 @@ -44,7 +44,7 @@
52136 #define gdm_tty_send_control(n, r, v, d, l) (\
52137 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52138
52139 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52140 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52141
52142 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52143 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52144 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52145 index 9cb222e..8766f26 100644
52146 --- a/drivers/staging/imx-drm/imx-drm-core.c
52147 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52148 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52149 if (imxdrm->pipes >= MAX_CRTC)
52150 return -EINVAL;
52151
52152 - if (imxdrm->drm->open_count)
52153 + if (local_read(&imxdrm->drm->open_count))
52154 return -EBUSY;
52155
52156 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52157 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52158 index 503b2d7..c904931 100644
52159 --- a/drivers/staging/line6/driver.c
52160 +++ b/drivers/staging/line6/driver.c
52161 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52162 {
52163 struct usb_device *usbdev = line6->usbdev;
52164 int ret;
52165 - unsigned char len;
52166 + unsigned char *plen;
52167
52168 /* query the serial number: */
52169 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52170 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52171 return ret;
52172 }
52173
52174 + plen = kmalloc(1, GFP_KERNEL);
52175 + if (plen == NULL)
52176 + return -ENOMEM;
52177 +
52178 /* Wait for data length. We'll get 0xff until length arrives. */
52179 do {
52180 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52181 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52182 USB_DIR_IN,
52183 - 0x0012, 0x0000, &len, 1,
52184 + 0x0012, 0x0000, plen, 1,
52185 LINE6_TIMEOUT * HZ);
52186 if (ret < 0) {
52187 dev_err(line6->ifcdev,
52188 "receive length failed (error %d)\n", ret);
52189 + kfree(plen);
52190 return ret;
52191 }
52192 - } while (len == 0xff);
52193 + } while (*plen == 0xff);
52194
52195 - if (len != datalen) {
52196 + if (*plen != datalen) {
52197 /* should be equal or something went wrong */
52198 dev_err(line6->ifcdev,
52199 "length mismatch (expected %d, got %d)\n",
52200 - (int)datalen, (int)len);
52201 + (int)datalen, (int)*plen);
52202 + kfree(plen);
52203 return -EINVAL;
52204 }
52205 + kfree(plen);
52206
52207 /* receive the result: */
52208 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52209 @@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52210 {
52211 struct usb_device *usbdev = line6->usbdev;
52212 int ret;
52213 - unsigned char status;
52214 + unsigned char *status;
52215
52216 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52217 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52218 @@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52219 return ret;
52220 }
52221
52222 + status = kmalloc(1, GFP_KERNEL);
52223 + if (status == NULL)
52224 + return -ENOMEM;
52225 +
52226 do {
52227 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52228 0x67,
52229 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52230 USB_DIR_IN,
52231 0x0012, 0x0000,
52232 - &status, 1, LINE6_TIMEOUT * HZ);
52233 + status, 1, LINE6_TIMEOUT * HZ);
52234
52235 if (ret < 0) {
52236 dev_err(line6->ifcdev,
52237 "receiving status failed (error %d)\n", ret);
52238 + kfree(status);
52239 return ret;
52240 }
52241 - } while (status == 0xff);
52242 + } while (*status == 0xff);
52243
52244 - if (status != 0) {
52245 + if (*status != 0) {
52246 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52247 + kfree(status);
52248 return -EINVAL;
52249 }
52250
52251 + kfree(status);
52252 +
52253 return 0;
52254 }
52255
52256 diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52257 index 6943715..0a93632 100644
52258 --- a/drivers/staging/line6/toneport.c
52259 +++ b/drivers/staging/line6/toneport.c
52260 @@ -11,6 +11,7 @@
52261 */
52262
52263 #include <linux/wait.h>
52264 +#include <linux/slab.h>
52265 #include <sound/control.h>
52266
52267 #include "audio.h"
52268 @@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52269 */
52270 static void toneport_setup(struct usb_line6_toneport *toneport)
52271 {
52272 - int ticks;
52273 + int *ticks;
52274 struct usb_line6 *line6 = &toneport->line6;
52275 struct usb_device *usbdev = line6->usbdev;
52276 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52277
52278 + ticks = kmalloc(sizeof(int), GFP_KERNEL);
52279 + if (ticks == NULL)
52280 + return;
52281 +
52282 /* sync time on device with host: */
52283 - ticks = (int)get_seconds();
52284 - line6_write_data(line6, 0x80c6, &ticks, 4);
52285 + *ticks = (int)get_seconds();
52286 + line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52287 +
52288 + kfree(ticks);
52289
52290 /* enable device: */
52291 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52292 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52293 index a94f336..6a1924d 100644
52294 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52295 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52296 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52297 return 0;
52298 }
52299
52300 -sfw_test_client_ops_t brw_test_client;
52301 -void brw_init_test_client(void)
52302 -{
52303 - brw_test_client.tso_init = brw_client_init;
52304 - brw_test_client.tso_fini = brw_client_fini;
52305 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52306 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52307 +sfw_test_client_ops_t brw_test_client = {
52308 + .tso_init = brw_client_init,
52309 + .tso_fini = brw_client_fini,
52310 + .tso_prep_rpc = brw_client_prep_rpc,
52311 + .tso_done_rpc = brw_client_done_rpc,
52312 };
52313
52314 srpc_service_t brw_test_service;
52315 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52316 index df04ab7..1deb1ac 100644
52317 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52318 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52319 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52320
52321 extern sfw_test_client_ops_t ping_test_client;
52322 extern srpc_service_t ping_test_service;
52323 -extern void ping_init_test_client(void);
52324 extern void ping_init_test_service(void);
52325
52326 extern sfw_test_client_ops_t brw_test_client;
52327 extern srpc_service_t brw_test_service;
52328 -extern void brw_init_test_client(void);
52329 extern void brw_init_test_service(void);
52330
52331
52332 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52333 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52334 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52335
52336 - brw_init_test_client();
52337 brw_init_test_service();
52338 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52339 LASSERT (rc == 0);
52340
52341 - ping_init_test_client();
52342 ping_init_test_service();
52343 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52344 LASSERT (rc == 0);
52345 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52346 index 750cac4..e4d751f 100644
52347 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52348 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52349 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52350 return 0;
52351 }
52352
52353 -sfw_test_client_ops_t ping_test_client;
52354 -void ping_init_test_client(void)
52355 -{
52356 - ping_test_client.tso_init = ping_client_init;
52357 - ping_test_client.tso_fini = ping_client_fini;
52358 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52359 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52360 -}
52361 +sfw_test_client_ops_t ping_test_client = {
52362 + .tso_init = ping_client_init,
52363 + .tso_fini = ping_client_fini,
52364 + .tso_prep_rpc = ping_client_prep_rpc,
52365 + .tso_done_rpc = ping_client_done_rpc,
52366 +};
52367
52368 srpc_service_t ping_test_service;
52369 void ping_init_test_service(void)
52370 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52371 index 14ac46f..eca2c16 100644
52372 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52373 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52374 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52375 ldlm_completion_callback lcs_completion;
52376 ldlm_blocking_callback lcs_blocking;
52377 ldlm_glimpse_callback lcs_glimpse;
52378 -};
52379 +} __no_const;
52380
52381 /* ldlm_lockd.c */
52382 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52383 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52384 index 2a88b80..62e7e5f 100644
52385 --- a/drivers/staging/lustre/lustre/include/obd.h
52386 +++ b/drivers/staging/lustre/lustre/include/obd.h
52387 @@ -1362,7 +1362,7 @@ struct md_ops {
52388 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52389 * wrapper function in include/linux/obd_class.h.
52390 */
52391 -};
52392 +} __no_const;
52393
52394 struct lsm_operations {
52395 void (*lsm_free)(struct lov_stripe_md *);
52396 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52397 index b798daa..b28ca8f 100644
52398 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52399 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52400 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52401 int added = (mode == LCK_NL);
52402 int overlaps = 0;
52403 int splitted = 0;
52404 - const struct ldlm_callback_suite null_cbs = { NULL };
52405 + const struct ldlm_callback_suite null_cbs = { };
52406
52407 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52408 *flags, new->l_policy_data.l_flock.owner,
52409 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52410 index bbe2c68..c6b4275 100644
52411 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52412 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52413 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52414 void __user *buffer, size_t *lenp, loff_t *ppos)
52415 {
52416 int rc, max_delay_cs;
52417 - struct ctl_table dummy = *table;
52418 + ctl_table_no_const dummy = *table;
52419 long d;
52420
52421 dummy.data = &max_delay_cs;
52422 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52423 void __user *buffer, size_t *lenp, loff_t *ppos)
52424 {
52425 int rc, min_delay_cs;
52426 - struct ctl_table dummy = *table;
52427 + ctl_table_no_const dummy = *table;
52428 long d;
52429
52430 dummy.data = &min_delay_cs;
52431 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52432 void __user *buffer, size_t *lenp, loff_t *ppos)
52433 {
52434 int rc, backoff;
52435 - struct ctl_table dummy = *table;
52436 + ctl_table_no_const dummy = *table;
52437
52438 dummy.data = &backoff;
52439 dummy.proc_handler = &proc_dointvec;
52440 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52441 index 2c4fc74..b04ca79 100644
52442 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52443 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52444 @@ -315,11 +315,11 @@ out:
52445
52446
52447 struct cfs_psdev_ops libcfs_psdev_ops = {
52448 - libcfs_psdev_open,
52449 - libcfs_psdev_release,
52450 - NULL,
52451 - NULL,
52452 - libcfs_ioctl
52453 + .p_open = libcfs_psdev_open,
52454 + .p_close = libcfs_psdev_release,
52455 + .p_read = NULL,
52456 + .p_write = NULL,
52457 + .p_ioctl = libcfs_ioctl
52458 };
52459
52460 extern int insert_proc(void);
52461 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52462 index b0bb709..0117c96 100644
52463 --- a/drivers/staging/lustre/lustre/llite/dir.c
52464 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52465 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52466 int mode;
52467 int err;
52468
52469 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52470 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52471 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52472 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52473 lump);
52474 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52475 index b2b6c3c..302e4e4 100644
52476 --- a/drivers/staging/octeon/ethernet-rx.c
52477 +++ b/drivers/staging/octeon/ethernet-rx.c
52478 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52479 /* Increment RX stats for virtual ports */
52480 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52481 #ifdef CONFIG_64BIT
52482 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52483 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52484 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52485 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52486 #else
52487 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52488 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52489 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52490 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52491 #endif
52492 }
52493 netif_receive_skb(skb);
52494 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52495 dev->name);
52496 */
52497 #ifdef CONFIG_64BIT
52498 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52499 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52500 #else
52501 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52502 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52503 #endif
52504 dev_kfree_skb_irq(skb);
52505 }
52506 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52507 index 8f9e3fb..d283fb9 100644
52508 --- a/drivers/staging/octeon/ethernet.c
52509 +++ b/drivers/staging/octeon/ethernet.c
52510 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52511 * since the RX tasklet also increments it.
52512 */
52513 #ifdef CONFIG_64BIT
52514 - atomic64_add(rx_status.dropped_packets,
52515 - (atomic64_t *)&priv->stats.rx_dropped);
52516 + atomic64_add_unchecked(rx_status.dropped_packets,
52517 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52518 #else
52519 - atomic_add(rx_status.dropped_packets,
52520 - (atomic_t *)&priv->stats.rx_dropped);
52521 + atomic_add_unchecked(rx_status.dropped_packets,
52522 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52523 #endif
52524 }
52525
52526 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52527 index 9191993..30e9817 100644
52528 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52529 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52530 @@ -225,7 +225,7 @@ struct hal_ops {
52531
52532 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52533 void (*hal_reset_security_engine)(struct adapter *adapter);
52534 -};
52535 +} __no_const;
52536
52537 enum rt_eeprom_type {
52538 EEPROM_93C46,
52539 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52540 index 070cc03..6806e37 100644
52541 --- a/drivers/staging/rtl8712/rtl871x_io.h
52542 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52543 @@ -108,7 +108,7 @@ struct _io_ops {
52544 u8 *pmem);
52545 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52546 u8 *pmem);
52547 -};
52548 +} __no_const;
52549
52550 struct io_req {
52551 struct list_head list;
52552 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52553 index 2bf2e2f..84421c9 100644
52554 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52555 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52556 @@ -228,7 +228,7 @@ typedef struct {
52557 void (*device_resume)(ulong busNo, ulong devNo);
52558 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52559 ulong *maxSize);
52560 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52561 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52562
52563 /* These functions live inside visorchipset, and will be called to indicate
52564 * responses to specific events (by code outside of visorchipset).
52565 @@ -243,7 +243,7 @@ typedef struct {
52566 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52567 void (*device_pause)(ulong busNo, ulong devNo, int response);
52568 void (*device_resume)(ulong busNo, ulong devNo, int response);
52569 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52570 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52571
52572 /** Register functions (in the bus driver) to get called by visorchipset
52573 * whenever a bus or device appears for which this service partition is
52574 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52575 index ae0dade..803d53a 100644
52576 --- a/drivers/staging/vt6655/hostap.c
52577 +++ b/drivers/staging/vt6655/hostap.c
52578 @@ -65,14 +65,13 @@
52579 *
52580 */
52581
52582 +static net_device_ops_no_const apdev_netdev_ops;
52583 +
52584 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52585 {
52586 struct vnt_private *apdev_priv;
52587 struct net_device *dev = pDevice->dev;
52588 int ret;
52589 - const struct net_device_ops apdev_netdev_ops = {
52590 - .ndo_start_xmit = pDevice->tx_80211,
52591 - };
52592
52593 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52594
52595 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52596 *apdev_priv = *pDevice;
52597 eth_hw_addr_inherit(pDevice->apdev, dev);
52598
52599 + /* only half broken now */
52600 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52601 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52602
52603 pDevice->apdev->type = ARPHRD_IEEE80211;
52604 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52605 index e7e9372..161f530 100644
52606 --- a/drivers/target/sbp/sbp_target.c
52607 +++ b/drivers/target/sbp/sbp_target.c
52608 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52609
52610 #define SESSION_MAINTENANCE_INTERVAL HZ
52611
52612 -static atomic_t login_id = ATOMIC_INIT(0);
52613 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52614
52615 static void session_maintenance_work(struct work_struct *);
52616 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52617 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52618 login->lun = se_lun;
52619 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52620 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52621 - login->login_id = atomic_inc_return(&login_id);
52622 + login->login_id = atomic_inc_return_unchecked(&login_id);
52623
52624 login->tgt_agt = sbp_target_agent_register(login);
52625 if (IS_ERR(login->tgt_agt)) {
52626 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52627 index 24fa5d1..fae56f1 100644
52628 --- a/drivers/target/target_core_device.c
52629 +++ b/drivers/target/target_core_device.c
52630 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52631 spin_lock_init(&dev->se_tmr_lock);
52632 spin_lock_init(&dev->qf_cmd_lock);
52633 sema_init(&dev->caw_sem, 1);
52634 - atomic_set(&dev->dev_ordered_id, 0);
52635 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52636 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52637 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52638 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52639 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52640 index be877bf..7be9cd4 100644
52641 --- a/drivers/target/target_core_transport.c
52642 +++ b/drivers/target/target_core_transport.c
52643 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52644 * Used to determine when ORDERED commands should go from
52645 * Dormant to Active status.
52646 */
52647 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52648 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52649 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52650 cmd->se_ordered_id, cmd->sam_task_attr,
52651 dev->transport->name);
52652 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52653 index edc1cce..769e4cb 100644
52654 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52655 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52656 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52657 platform_set_drvdata(pdev, priv);
52658
52659 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52660 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52661 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52662 + pax_open_kernel();
52663 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52664 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52665 + pax_close_kernel();
52666 }
52667 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52668 priv, &int3400_thermal_ops,
52669 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52670 index 62143ba..ae21165 100644
52671 --- a/drivers/thermal/of-thermal.c
52672 +++ b/drivers/thermal/of-thermal.c
52673 @@ -30,6 +30,7 @@
52674 #include <linux/err.h>
52675 #include <linux/export.h>
52676 #include <linux/string.h>
52677 +#include <linux/mm.h>
52678
52679 #include "thermal_core.h"
52680
52681 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52682 tz->get_trend = get_trend;
52683 tz->sensor_data = data;
52684
52685 - tzd->ops->get_temp = of_thermal_get_temp;
52686 - tzd->ops->get_trend = of_thermal_get_trend;
52687 + pax_open_kernel();
52688 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52689 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52690 + pax_close_kernel();
52691 mutex_unlock(&tzd->lock);
52692
52693 return tzd;
52694 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52695 return;
52696
52697 mutex_lock(&tzd->lock);
52698 - tzd->ops->get_temp = NULL;
52699 - tzd->ops->get_trend = NULL;
52700 + pax_open_kernel();
52701 + *(void **)&tzd->ops->get_temp = NULL;
52702 + *(void **)&tzd->ops->get_trend = NULL;
52703 + pax_close_kernel();
52704
52705 tz->get_temp = NULL;
52706 tz->get_trend = NULL;
52707 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52708 index fd66f57..48e6376 100644
52709 --- a/drivers/tty/cyclades.c
52710 +++ b/drivers/tty/cyclades.c
52711 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52712 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52713 info->port.count);
52714 #endif
52715 - info->port.count++;
52716 + atomic_inc(&info->port.count);
52717 #ifdef CY_DEBUG_COUNT
52718 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52719 - current->pid, info->port.count);
52720 + current->pid, atomic_read(&info->port.count));
52721 #endif
52722
52723 /*
52724 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52725 for (j = 0; j < cy_card[i].nports; j++) {
52726 info = &cy_card[i].ports[j];
52727
52728 - if (info->port.count) {
52729 + if (atomic_read(&info->port.count)) {
52730 /* XXX is the ldisc num worth this? */
52731 struct tty_struct *tty;
52732 struct tty_ldisc *ld;
52733 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52734 index 4fcec1d..5a036f7 100644
52735 --- a/drivers/tty/hvc/hvc_console.c
52736 +++ b/drivers/tty/hvc/hvc_console.c
52737 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52738
52739 spin_lock_irqsave(&hp->port.lock, flags);
52740 /* Check and then increment for fast path open. */
52741 - if (hp->port.count++ > 0) {
52742 + if (atomic_inc_return(&hp->port.count) > 1) {
52743 spin_unlock_irqrestore(&hp->port.lock, flags);
52744 hvc_kick();
52745 return 0;
52746 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52747
52748 spin_lock_irqsave(&hp->port.lock, flags);
52749
52750 - if (--hp->port.count == 0) {
52751 + if (atomic_dec_return(&hp->port.count) == 0) {
52752 spin_unlock_irqrestore(&hp->port.lock, flags);
52753 /* We are done with the tty pointer now. */
52754 tty_port_tty_set(&hp->port, NULL);
52755 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52756 */
52757 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52758 } else {
52759 - if (hp->port.count < 0)
52760 + if (atomic_read(&hp->port.count) < 0)
52761 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52762 - hp->vtermno, hp->port.count);
52763 + hp->vtermno, atomic_read(&hp->port.count));
52764 spin_unlock_irqrestore(&hp->port.lock, flags);
52765 }
52766 }
52767 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52768 * open->hangup case this can be called after the final close so prevent
52769 * that from happening for now.
52770 */
52771 - if (hp->port.count <= 0) {
52772 + if (atomic_read(&hp->port.count) <= 0) {
52773 spin_unlock_irqrestore(&hp->port.lock, flags);
52774 return;
52775 }
52776
52777 - hp->port.count = 0;
52778 + atomic_set(&hp->port.count, 0);
52779 spin_unlock_irqrestore(&hp->port.lock, flags);
52780 tty_port_tty_set(&hp->port, NULL);
52781
52782 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52783 return -EPIPE;
52784
52785 /* FIXME what's this (unprotected) check for? */
52786 - if (hp->port.count <= 0)
52787 + if (atomic_read(&hp->port.count) <= 0)
52788 return -EIO;
52789
52790 spin_lock_irqsave(&hp->lock, flags);
52791 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52792 index 81e939e..95ead10 100644
52793 --- a/drivers/tty/hvc/hvcs.c
52794 +++ b/drivers/tty/hvc/hvcs.c
52795 @@ -83,6 +83,7 @@
52796 #include <asm/hvcserver.h>
52797 #include <asm/uaccess.h>
52798 #include <asm/vio.h>
52799 +#include <asm/local.h>
52800
52801 /*
52802 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52803 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52804
52805 spin_lock_irqsave(&hvcsd->lock, flags);
52806
52807 - if (hvcsd->port.count > 0) {
52808 + if (atomic_read(&hvcsd->port.count) > 0) {
52809 spin_unlock_irqrestore(&hvcsd->lock, flags);
52810 printk(KERN_INFO "HVCS: vterm state unchanged. "
52811 "The hvcs device node is still in use.\n");
52812 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52813 }
52814 }
52815
52816 - hvcsd->port.count = 0;
52817 + atomic_set(&hvcsd->port.count, 0);
52818 hvcsd->port.tty = tty;
52819 tty->driver_data = hvcsd;
52820
52821 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52822 unsigned long flags;
52823
52824 spin_lock_irqsave(&hvcsd->lock, flags);
52825 - hvcsd->port.count++;
52826 + atomic_inc(&hvcsd->port.count);
52827 hvcsd->todo_mask |= HVCS_SCHED_READ;
52828 spin_unlock_irqrestore(&hvcsd->lock, flags);
52829
52830 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52831 hvcsd = tty->driver_data;
52832
52833 spin_lock_irqsave(&hvcsd->lock, flags);
52834 - if (--hvcsd->port.count == 0) {
52835 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52836
52837 vio_disable_interrupts(hvcsd->vdev);
52838
52839 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52840
52841 free_irq(irq, hvcsd);
52842 return;
52843 - } else if (hvcsd->port.count < 0) {
52844 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52845 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52846 " is missmanaged.\n",
52847 - hvcsd->vdev->unit_address, hvcsd->port.count);
52848 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52849 }
52850
52851 spin_unlock_irqrestore(&hvcsd->lock, flags);
52852 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52853
52854 spin_lock_irqsave(&hvcsd->lock, flags);
52855 /* Preserve this so that we know how many kref refs to put */
52856 - temp_open_count = hvcsd->port.count;
52857 + temp_open_count = atomic_read(&hvcsd->port.count);
52858
52859 /*
52860 * Don't kref put inside the spinlock because the destruction
52861 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52862 tty->driver_data = NULL;
52863 hvcsd->port.tty = NULL;
52864
52865 - hvcsd->port.count = 0;
52866 + atomic_set(&hvcsd->port.count, 0);
52867
52868 /* This will drop any buffered data on the floor which is OK in a hangup
52869 * scenario. */
52870 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52871 * the middle of a write operation? This is a crummy place to do this
52872 * but we want to keep it all in the spinlock.
52873 */
52874 - if (hvcsd->port.count <= 0) {
52875 + if (atomic_read(&hvcsd->port.count) <= 0) {
52876 spin_unlock_irqrestore(&hvcsd->lock, flags);
52877 return -ENODEV;
52878 }
52879 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52880 {
52881 struct hvcs_struct *hvcsd = tty->driver_data;
52882
52883 - if (!hvcsd || hvcsd->port.count <= 0)
52884 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52885 return 0;
52886
52887 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52888 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52889 index 4190199..06d5bfa 100644
52890 --- a/drivers/tty/hvc/hvsi.c
52891 +++ b/drivers/tty/hvc/hvsi.c
52892 @@ -85,7 +85,7 @@ struct hvsi_struct {
52893 int n_outbuf;
52894 uint32_t vtermno;
52895 uint32_t virq;
52896 - atomic_t seqno; /* HVSI packet sequence number */
52897 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52898 uint16_t mctrl;
52899 uint8_t state; /* HVSI protocol state */
52900 uint8_t flags;
52901 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52902
52903 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52904 packet.hdr.len = sizeof(struct hvsi_query_response);
52905 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52906 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52907 packet.verb = VSV_SEND_VERSION_NUMBER;
52908 packet.u.version = HVSI_VERSION;
52909 packet.query_seqno = query_seqno+1;
52910 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52911
52912 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52913 packet.hdr.len = sizeof(struct hvsi_query);
52914 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52915 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52916 packet.verb = verb;
52917
52918 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52919 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52920 int wrote;
52921
52922 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52923 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52924 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52925 packet.hdr.len = sizeof(struct hvsi_control);
52926 packet.verb = VSV_SET_MODEM_CTL;
52927 packet.mask = HVSI_TSDTR;
52928 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52929 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52930
52931 packet.hdr.type = VS_DATA_PACKET_HEADER;
52932 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52933 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52934 packet.hdr.len = count + sizeof(struct hvsi_header);
52935 memcpy(&packet.data, buf, count);
52936
52937 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52938 struct hvsi_control packet __ALIGNED__;
52939
52940 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52941 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52942 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52943 packet.hdr.len = 6;
52944 packet.verb = VSV_CLOSE_PROTOCOL;
52945
52946 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52947
52948 tty_port_tty_set(&hp->port, tty);
52949 spin_lock_irqsave(&hp->lock, flags);
52950 - hp->port.count++;
52951 + atomic_inc(&hp->port.count);
52952 atomic_set(&hp->seqno, 0);
52953 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52954 spin_unlock_irqrestore(&hp->lock, flags);
52955 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52956
52957 spin_lock_irqsave(&hp->lock, flags);
52958
52959 - if (--hp->port.count == 0) {
52960 + if (atomic_dec_return(&hp->port.count) == 0) {
52961 tty_port_tty_set(&hp->port, NULL);
52962 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52963
52964 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52965
52966 spin_lock_irqsave(&hp->lock, flags);
52967 }
52968 - } else if (hp->port.count < 0)
52969 + } else if (atomic_read(&hp->port.count) < 0)
52970 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52971 - hp - hvsi_ports, hp->port.count);
52972 + hp - hvsi_ports, atomic_read(&hp->port.count));
52973
52974 spin_unlock_irqrestore(&hp->lock, flags);
52975 }
52976 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52977 tty_port_tty_set(&hp->port, NULL);
52978
52979 spin_lock_irqsave(&hp->lock, flags);
52980 - hp->port.count = 0;
52981 + atomic_set(&hp->port.count, 0);
52982 hp->n_outbuf = 0;
52983 spin_unlock_irqrestore(&hp->lock, flags);
52984 }
52985 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52986 index 7ae6c29..05c6dba 100644
52987 --- a/drivers/tty/hvc/hvsi_lib.c
52988 +++ b/drivers/tty/hvc/hvsi_lib.c
52989 @@ -8,7 +8,7 @@
52990
52991 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52992 {
52993 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52994 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52995
52996 /* Assumes that always succeeds, works in practice */
52997 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52998 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52999
53000 /* Reset state */
53001 pv->established = 0;
53002 - atomic_set(&pv->seqno, 0);
53003 + atomic_set_unchecked(&pv->seqno, 0);
53004
53005 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53006
53007 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53008 index 345cebb..d5a1e9e 100644
53009 --- a/drivers/tty/ipwireless/tty.c
53010 +++ b/drivers/tty/ipwireless/tty.c
53011 @@ -28,6 +28,7 @@
53012 #include <linux/tty_driver.h>
53013 #include <linux/tty_flip.h>
53014 #include <linux/uaccess.h>
53015 +#include <asm/local.h>
53016
53017 #include "tty.h"
53018 #include "network.h"
53019 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53020 return -ENODEV;
53021
53022 mutex_lock(&tty->ipw_tty_mutex);
53023 - if (tty->port.count == 0)
53024 + if (atomic_read(&tty->port.count) == 0)
53025 tty->tx_bytes_queued = 0;
53026
53027 - tty->port.count++;
53028 + atomic_inc(&tty->port.count);
53029
53030 tty->port.tty = linux_tty;
53031 linux_tty->driver_data = tty;
53032 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53033
53034 static void do_ipw_close(struct ipw_tty *tty)
53035 {
53036 - tty->port.count--;
53037 -
53038 - if (tty->port.count == 0) {
53039 + if (atomic_dec_return(&tty->port.count) == 0) {
53040 struct tty_struct *linux_tty = tty->port.tty;
53041
53042 if (linux_tty != NULL) {
53043 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53044 return;
53045
53046 mutex_lock(&tty->ipw_tty_mutex);
53047 - if (tty->port.count == 0) {
53048 + if (atomic_read(&tty->port.count) == 0) {
53049 mutex_unlock(&tty->ipw_tty_mutex);
53050 return;
53051 }
53052 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53053
53054 mutex_lock(&tty->ipw_tty_mutex);
53055
53056 - if (!tty->port.count) {
53057 + if (!atomic_read(&tty->port.count)) {
53058 mutex_unlock(&tty->ipw_tty_mutex);
53059 return;
53060 }
53061 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53062 return -ENODEV;
53063
53064 mutex_lock(&tty->ipw_tty_mutex);
53065 - if (!tty->port.count) {
53066 + if (!atomic_read(&tty->port.count)) {
53067 mutex_unlock(&tty->ipw_tty_mutex);
53068 return -EINVAL;
53069 }
53070 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53071 if (!tty)
53072 return -ENODEV;
53073
53074 - if (!tty->port.count)
53075 + if (!atomic_read(&tty->port.count))
53076 return -EINVAL;
53077
53078 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53079 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53080 if (!tty)
53081 return 0;
53082
53083 - if (!tty->port.count)
53084 + if (!atomic_read(&tty->port.count))
53085 return 0;
53086
53087 return tty->tx_bytes_queued;
53088 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53089 if (!tty)
53090 return -ENODEV;
53091
53092 - if (!tty->port.count)
53093 + if (!atomic_read(&tty->port.count))
53094 return -EINVAL;
53095
53096 return get_control_lines(tty);
53097 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53098 if (!tty)
53099 return -ENODEV;
53100
53101 - if (!tty->port.count)
53102 + if (!atomic_read(&tty->port.count))
53103 return -EINVAL;
53104
53105 return set_control_lines(tty, set, clear);
53106 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53107 if (!tty)
53108 return -ENODEV;
53109
53110 - if (!tty->port.count)
53111 + if (!atomic_read(&tty->port.count))
53112 return -EINVAL;
53113
53114 /* FIXME: Exactly how is the tty object locked here .. */
53115 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53116 * are gone */
53117 mutex_lock(&ttyj->ipw_tty_mutex);
53118 }
53119 - while (ttyj->port.count)
53120 + while (atomic_read(&ttyj->port.count))
53121 do_ipw_close(ttyj);
53122 ipwireless_disassociate_network_ttys(network,
53123 ttyj->channel_idx);
53124 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53125 index 14c54e0..1efd4f2 100644
53126 --- a/drivers/tty/moxa.c
53127 +++ b/drivers/tty/moxa.c
53128 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53129 }
53130
53131 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53132 - ch->port.count++;
53133 + atomic_inc(&ch->port.count);
53134 tty->driver_data = ch;
53135 tty_port_tty_set(&ch->port, tty);
53136 mutex_lock(&ch->port.mutex);
53137 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53138 index c434376..114ce13 100644
53139 --- a/drivers/tty/n_gsm.c
53140 +++ b/drivers/tty/n_gsm.c
53141 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53142 spin_lock_init(&dlci->lock);
53143 mutex_init(&dlci->mutex);
53144 dlci->fifo = &dlci->_fifo;
53145 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53146 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53147 kfree(dlci);
53148 return NULL;
53149 }
53150 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53151 struct gsm_dlci *dlci = tty->driver_data;
53152 struct tty_port *port = &dlci->port;
53153
53154 - port->count++;
53155 + atomic_inc(&port->count);
53156 tty_port_tty_set(port, tty);
53157
53158 dlci->modem_rx = 0;
53159 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53160 index 47ca0f3..3c0b803 100644
53161 --- a/drivers/tty/n_tty.c
53162 +++ b/drivers/tty/n_tty.c
53163 @@ -115,7 +115,7 @@ struct n_tty_data {
53164 int minimum_to_wake;
53165
53166 /* consumer-published */
53167 - size_t read_tail;
53168 + size_t read_tail __intentional_overflow(-1);
53169 size_t line_start;
53170
53171 /* protected by output lock */
53172 @@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53173 {
53174 *ops = tty_ldisc_N_TTY;
53175 ops->owner = NULL;
53176 - ops->refcount = ops->flags = 0;
53177 + atomic_set(&ops->refcount, 0);
53178 + ops->flags = 0;
53179 }
53180 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53181 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53182 index 7c4447a..70fbc1e 100644
53183 --- a/drivers/tty/pty.c
53184 +++ b/drivers/tty/pty.c
53185 @@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
53186 panic("Couldn't register Unix98 pts driver");
53187
53188 /* Now create the /dev/ptmx special device */
53189 + pax_open_kernel();
53190 tty_default_fops(&ptmx_fops);
53191 - ptmx_fops.open = ptmx_open;
53192 + *(void **)&ptmx_fops.open = ptmx_open;
53193 + pax_close_kernel();
53194
53195 cdev_init(&ptmx_cdev, &ptmx_fops);
53196 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53197 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53198 index 383c4c7..d408e21 100644
53199 --- a/drivers/tty/rocket.c
53200 +++ b/drivers/tty/rocket.c
53201 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53202 tty->driver_data = info;
53203 tty_port_tty_set(port, tty);
53204
53205 - if (port->count++ == 0) {
53206 + if (atomic_inc_return(&port->count) == 1) {
53207 atomic_inc(&rp_num_ports_open);
53208
53209 #ifdef ROCKET_DEBUG_OPEN
53210 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53211 #endif
53212 }
53213 #ifdef ROCKET_DEBUG_OPEN
53214 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53215 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53216 #endif
53217
53218 /*
53219 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53220 spin_unlock_irqrestore(&info->port.lock, flags);
53221 return;
53222 }
53223 - if (info->port.count)
53224 + if (atomic_read(&info->port.count))
53225 atomic_dec(&rp_num_ports_open);
53226 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53227 spin_unlock_irqrestore(&info->port.lock, flags);
53228 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53229 index aa28209..e08fb85 100644
53230 --- a/drivers/tty/serial/ioc4_serial.c
53231 +++ b/drivers/tty/serial/ioc4_serial.c
53232 @@ -437,7 +437,7 @@ struct ioc4_soft {
53233 } is_intr_info[MAX_IOC4_INTR_ENTS];
53234
53235 /* Number of entries active in the above array */
53236 - atomic_t is_num_intrs;
53237 + atomic_unchecked_t is_num_intrs;
53238 } is_intr_type[IOC4_NUM_INTR_TYPES];
53239
53240 /* is_ir_lock must be held while
53241 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53242 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53243 || (type == IOC4_OTHER_INTR_TYPE)));
53244
53245 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53246 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53247 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53248
53249 /* Save off the lower level interrupt handler */
53250 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53251
53252 soft = arg;
53253 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53254 - num_intrs = (int)atomic_read(
53255 + num_intrs = (int)atomic_read_unchecked(
53256 &soft->is_intr_type[intr_type].is_num_intrs);
53257
53258 this_mir = this_ir = pending_intrs(soft, intr_type);
53259 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53260 index 129dc5b..1da5bb8 100644
53261 --- a/drivers/tty/serial/kgdb_nmi.c
53262 +++ b/drivers/tty/serial/kgdb_nmi.c
53263 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53264 * I/O utilities that messages sent to the console will automatically
53265 * be displayed on the dbg_io.
53266 */
53267 - dbg_io_ops->is_console = true;
53268 + pax_open_kernel();
53269 + *(int *)&dbg_io_ops->is_console = true;
53270 + pax_close_kernel();
53271
53272 return 0;
53273 }
53274 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53275 index a260cde..6b2b5ce 100644
53276 --- a/drivers/tty/serial/kgdboc.c
53277 +++ b/drivers/tty/serial/kgdboc.c
53278 @@ -24,8 +24,9 @@
53279 #define MAX_CONFIG_LEN 40
53280
53281 static struct kgdb_io kgdboc_io_ops;
53282 +static struct kgdb_io kgdboc_io_ops_console;
53283
53284 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53285 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53286 static int configured = -1;
53287
53288 static char config[MAX_CONFIG_LEN];
53289 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53290 kgdboc_unregister_kbd();
53291 if (configured == 1)
53292 kgdb_unregister_io_module(&kgdboc_io_ops);
53293 + else if (configured == 2)
53294 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53295 }
53296
53297 static int configure_kgdboc(void)
53298 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53299 int err;
53300 char *cptr = config;
53301 struct console *cons;
53302 + int is_console = 0;
53303
53304 err = kgdboc_option_setup(config);
53305 if (err || !strlen(config) || isspace(config[0]))
53306 goto noconfig;
53307
53308 err = -ENODEV;
53309 - kgdboc_io_ops.is_console = 0;
53310 kgdb_tty_driver = NULL;
53311
53312 kgdboc_use_kms = 0;
53313 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53314 int idx;
53315 if (cons->device && cons->device(cons, &idx) == p &&
53316 idx == tty_line) {
53317 - kgdboc_io_ops.is_console = 1;
53318 + is_console = 1;
53319 break;
53320 }
53321 cons = cons->next;
53322 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53323 kgdb_tty_line = tty_line;
53324
53325 do_register:
53326 - err = kgdb_register_io_module(&kgdboc_io_ops);
53327 + if (is_console) {
53328 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53329 + configured = 2;
53330 + } else {
53331 + err = kgdb_register_io_module(&kgdboc_io_ops);
53332 + configured = 1;
53333 + }
53334 if (err)
53335 goto noconfig;
53336
53337 @@ -205,8 +214,6 @@ do_register:
53338 if (err)
53339 goto nmi_con_failed;
53340
53341 - configured = 1;
53342 -
53343 return 0;
53344
53345 nmi_con_failed:
53346 @@ -223,7 +230,7 @@ noconfig:
53347 static int __init init_kgdboc(void)
53348 {
53349 /* Already configured? */
53350 - if (configured == 1)
53351 + if (configured >= 1)
53352 return 0;
53353
53354 return configure_kgdboc();
53355 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53356 if (config[len - 1] == '\n')
53357 config[len - 1] = '\0';
53358
53359 - if (configured == 1)
53360 + if (configured >= 1)
53361 cleanup_kgdboc();
53362
53363 /* Go and configure with the new params. */
53364 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53365 .post_exception = kgdboc_post_exp_handler,
53366 };
53367
53368 +static struct kgdb_io kgdboc_io_ops_console = {
53369 + .name = "kgdboc",
53370 + .read_char = kgdboc_get_char,
53371 + .write_char = kgdboc_put_char,
53372 + .pre_exception = kgdboc_pre_exp_handler,
53373 + .post_exception = kgdboc_post_exp_handler,
53374 + .is_console = 1
53375 +};
53376 +
53377 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53378 /* This is only available if kgdboc is a built in for early debugging */
53379 static int __init kgdboc_early_init(char *opt)
53380 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53381 index 4b6c783..9a19db3 100644
53382 --- a/drivers/tty/serial/msm_serial.c
53383 +++ b/drivers/tty/serial/msm_serial.c
53384 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53385 .cons = MSM_CONSOLE,
53386 };
53387
53388 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53389 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53390
53391 static const struct of_device_id msm_uartdm_table[] = {
53392 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53393 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53394 int irq;
53395
53396 if (pdev->id == -1)
53397 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53398 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53399
53400 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53401 return -ENXIO;
53402 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53403 index 587d63b..48423a6 100644
53404 --- a/drivers/tty/serial/samsung.c
53405 +++ b/drivers/tty/serial/samsung.c
53406 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53407 }
53408 }
53409
53410 +static int s3c64xx_serial_startup(struct uart_port *port);
53411 static int s3c24xx_serial_startup(struct uart_port *port)
53412 {
53413 struct s3c24xx_uart_port *ourport = to_ourport(port);
53414 int ret;
53415
53416 + /* Startup sequence is different for s3c64xx and higher SoC's */
53417 + if (s3c24xx_serial_has_interrupt_mask(port))
53418 + return s3c64xx_serial_startup(port);
53419 +
53420 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53421 port, (unsigned long long)port->mapbase, port->membase);
53422
53423 @@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53424 /* setup info for port */
53425 port->dev = &platdev->dev;
53426
53427 - /* Startup sequence is different for s3c64xx and higher SoC's */
53428 - if (s3c24xx_serial_has_interrupt_mask(port))
53429 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53430 -
53431 port->uartclk = 1;
53432
53433 if (cfg->uart_flags & UPF_CONS_FLOW) {
53434 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53435 index a28dee9..168ba47 100644
53436 --- a/drivers/tty/serial/serial_core.c
53437 +++ b/drivers/tty/serial/serial_core.c
53438 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53439
53440 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53441
53442 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53443 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53444 return;
53445
53446 /*
53447 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53448 uart_flush_buffer(tty);
53449 uart_shutdown(tty, state);
53450 spin_lock_irqsave(&port->lock, flags);
53451 - port->count = 0;
53452 + atomic_set(&port->count, 0);
53453 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53454 spin_unlock_irqrestore(&port->lock, flags);
53455 tty_port_tty_set(port, NULL);
53456 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53457 goto end;
53458 }
53459
53460 - port->count++;
53461 + atomic_inc(&port->count);
53462 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53463 retval = -ENXIO;
53464 goto err_dec_count;
53465 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53466 end:
53467 return retval;
53468 err_dec_count:
53469 - port->count--;
53470 + atomic_dec(&port->count);
53471 mutex_unlock(&port->mutex);
53472 goto end;
53473 }
53474 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53475 index b799170..87dafd5 100644
53476 --- a/drivers/tty/synclink.c
53477 +++ b/drivers/tty/synclink.c
53478 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53479
53480 if (debug_level >= DEBUG_LEVEL_INFO)
53481 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53482 - __FILE__,__LINE__, info->device_name, info->port.count);
53483 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53484
53485 if (tty_port_close_start(&info->port, tty, filp) == 0)
53486 goto cleanup;
53487 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53488 cleanup:
53489 if (debug_level >= DEBUG_LEVEL_INFO)
53490 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53491 - tty->driver->name, info->port.count);
53492 + tty->driver->name, atomic_read(&info->port.count));
53493
53494 } /* end of mgsl_close() */
53495
53496 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53497
53498 mgsl_flush_buffer(tty);
53499 shutdown(info);
53500 -
53501 - info->port.count = 0;
53502 +
53503 + atomic_set(&info->port.count, 0);
53504 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53505 info->port.tty = NULL;
53506
53507 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53508
53509 if (debug_level >= DEBUG_LEVEL_INFO)
53510 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53511 - __FILE__,__LINE__, tty->driver->name, port->count );
53512 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53513
53514 spin_lock_irqsave(&info->irq_spinlock, flags);
53515 - port->count--;
53516 + atomic_dec(&port->count);
53517 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53518 port->blocked_open++;
53519
53520 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53521
53522 if (debug_level >= DEBUG_LEVEL_INFO)
53523 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53524 - __FILE__,__LINE__, tty->driver->name, port->count );
53525 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53526
53527 tty_unlock(tty);
53528 schedule();
53529 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53530
53531 /* FIXME: Racy on hangup during close wait */
53532 if (!tty_hung_up_p(filp))
53533 - port->count++;
53534 + atomic_inc(&port->count);
53535 port->blocked_open--;
53536
53537 if (debug_level >= DEBUG_LEVEL_INFO)
53538 printk("%s(%d):block_til_ready after blocking 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 if (!retval)
53543 port->flags |= ASYNC_NORMAL_ACTIVE;
53544 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53545
53546 if (debug_level >= DEBUG_LEVEL_INFO)
53547 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53548 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53549 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53550
53551 /* If port is closing, signal caller to try again */
53552 if (info->port.flags & ASYNC_CLOSING){
53553 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53554 spin_unlock_irqrestore(&info->netlock, flags);
53555 goto cleanup;
53556 }
53557 - info->port.count++;
53558 + atomic_inc(&info->port.count);
53559 spin_unlock_irqrestore(&info->netlock, flags);
53560
53561 - if (info->port.count == 1) {
53562 + if (atomic_read(&info->port.count) == 1) {
53563 /* 1st open on this device, init hardware */
53564 retval = startup(info);
53565 if (retval < 0)
53566 @@ -3442,8 +3442,8 @@ cleanup:
53567 if (retval) {
53568 if (tty->count == 1)
53569 info->port.tty = NULL; /* tty layer will release tty struct */
53570 - if(info->port.count)
53571 - info->port.count--;
53572 + if (atomic_read(&info->port.count))
53573 + atomic_dec(&info->port.count);
53574 }
53575
53576 return retval;
53577 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53578 unsigned short new_crctype;
53579
53580 /* return error if TTY interface open */
53581 - if (info->port.count)
53582 + if (atomic_read(&info->port.count))
53583 return -EBUSY;
53584
53585 switch (encoding)
53586 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53587
53588 /* arbitrate between network and tty opens */
53589 spin_lock_irqsave(&info->netlock, flags);
53590 - if (info->port.count != 0 || info->netcount != 0) {
53591 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53592 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53593 spin_unlock_irqrestore(&info->netlock, flags);
53594 return -EBUSY;
53595 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53596 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53597
53598 /* return error if TTY interface open */
53599 - if (info->port.count)
53600 + if (atomic_read(&info->port.count))
53601 return -EBUSY;
53602
53603 if (cmd != SIOCWANDEV)
53604 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53605 index 0e8c39b..e0cb171 100644
53606 --- a/drivers/tty/synclink_gt.c
53607 +++ b/drivers/tty/synclink_gt.c
53608 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53609 tty->driver_data = info;
53610 info->port.tty = tty;
53611
53612 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53613 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53614
53615 /* If port is closing, signal caller to try again */
53616 if (info->port.flags & ASYNC_CLOSING){
53617 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53618 mutex_unlock(&info->port.mutex);
53619 goto cleanup;
53620 }
53621 - info->port.count++;
53622 + atomic_inc(&info->port.count);
53623 spin_unlock_irqrestore(&info->netlock, flags);
53624
53625 - if (info->port.count == 1) {
53626 + if (atomic_read(&info->port.count) == 1) {
53627 /* 1st open on this device, init hardware */
53628 retval = startup(info);
53629 if (retval < 0) {
53630 @@ -715,8 +715,8 @@ cleanup:
53631 if (retval) {
53632 if (tty->count == 1)
53633 info->port.tty = NULL; /* tty layer will release tty struct */
53634 - if(info->port.count)
53635 - info->port.count--;
53636 + if(atomic_read(&info->port.count))
53637 + atomic_dec(&info->port.count);
53638 }
53639
53640 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53641 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53642
53643 if (sanity_check(info, tty->name, "close"))
53644 return;
53645 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53646 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53647
53648 if (tty_port_close_start(&info->port, tty, filp) == 0)
53649 goto cleanup;
53650 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53651 tty_port_close_end(&info->port, tty);
53652 info->port.tty = NULL;
53653 cleanup:
53654 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53655 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53656 }
53657
53658 static void hangup(struct tty_struct *tty)
53659 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53660 shutdown(info);
53661
53662 spin_lock_irqsave(&info->port.lock, flags);
53663 - info->port.count = 0;
53664 + atomic_set(&info->port.count, 0);
53665 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53666 info->port.tty = NULL;
53667 spin_unlock_irqrestore(&info->port.lock, flags);
53668 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53669 unsigned short new_crctype;
53670
53671 /* return error if TTY interface open */
53672 - if (info->port.count)
53673 + if (atomic_read(&info->port.count))
53674 return -EBUSY;
53675
53676 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53677 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53678
53679 /* arbitrate between network and tty opens */
53680 spin_lock_irqsave(&info->netlock, flags);
53681 - if (info->port.count != 0 || info->netcount != 0) {
53682 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53683 DBGINFO(("%s hdlc_open busy\n", dev->name));
53684 spin_unlock_irqrestore(&info->netlock, flags);
53685 return -EBUSY;
53686 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53687 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53688
53689 /* return error if TTY interface open */
53690 - if (info->port.count)
53691 + if (atomic_read(&info->port.count))
53692 return -EBUSY;
53693
53694 if (cmd != SIOCWANDEV)
53695 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53696 if (port == NULL)
53697 continue;
53698 spin_lock(&port->lock);
53699 - if ((port->port.count || port->netcount) &&
53700 + if ((atomic_read(&port->port.count) || port->netcount) &&
53701 port->pending_bh && !port->bh_running &&
53702 !port->bh_requested) {
53703 DBGISR(("%s bh queued\n", port->device_name));
53704 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53705 add_wait_queue(&port->open_wait, &wait);
53706
53707 spin_lock_irqsave(&info->lock, flags);
53708 - port->count--;
53709 + atomic_dec(&port->count);
53710 spin_unlock_irqrestore(&info->lock, flags);
53711 port->blocked_open++;
53712
53713 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53714 remove_wait_queue(&port->open_wait, &wait);
53715
53716 if (!tty_hung_up_p(filp))
53717 - port->count++;
53718 + atomic_inc(&port->count);
53719 port->blocked_open--;
53720
53721 if (!retval)
53722 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53723 index c3f9091..abe4601 100644
53724 --- a/drivers/tty/synclinkmp.c
53725 +++ b/drivers/tty/synclinkmp.c
53726 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53727
53728 if (debug_level >= DEBUG_LEVEL_INFO)
53729 printk("%s(%d):%s open(), old ref count = %d\n",
53730 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53731 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53732
53733 /* If port is closing, signal caller to try again */
53734 if (info->port.flags & ASYNC_CLOSING){
53735 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53736 spin_unlock_irqrestore(&info->netlock, flags);
53737 goto cleanup;
53738 }
53739 - info->port.count++;
53740 + atomic_inc(&info->port.count);
53741 spin_unlock_irqrestore(&info->netlock, flags);
53742
53743 - if (info->port.count == 1) {
53744 + if (atomic_read(&info->port.count) == 1) {
53745 /* 1st open on this device, init hardware */
53746 retval = startup(info);
53747 if (retval < 0)
53748 @@ -796,8 +796,8 @@ cleanup:
53749 if (retval) {
53750 if (tty->count == 1)
53751 info->port.tty = NULL; /* tty layer will release tty struct */
53752 - if(info->port.count)
53753 - info->port.count--;
53754 + if(atomic_read(&info->port.count))
53755 + atomic_dec(&info->port.count);
53756 }
53757
53758 return retval;
53759 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53760
53761 if (debug_level >= DEBUG_LEVEL_INFO)
53762 printk("%s(%d):%s close() entry, count=%d\n",
53763 - __FILE__,__LINE__, info->device_name, info->port.count);
53764 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53765
53766 if (tty_port_close_start(&info->port, tty, filp) == 0)
53767 goto cleanup;
53768 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53769 cleanup:
53770 if (debug_level >= DEBUG_LEVEL_INFO)
53771 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53772 - tty->driver->name, info->port.count);
53773 + tty->driver->name, atomic_read(&info->port.count));
53774 }
53775
53776 /* Called by tty_hangup() when a hangup is signaled.
53777 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53778 shutdown(info);
53779
53780 spin_lock_irqsave(&info->port.lock, flags);
53781 - info->port.count = 0;
53782 + atomic_set(&info->port.count, 0);
53783 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53784 info->port.tty = NULL;
53785 spin_unlock_irqrestore(&info->port.lock, flags);
53786 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53787 unsigned short new_crctype;
53788
53789 /* return error if TTY interface open */
53790 - if (info->port.count)
53791 + if (atomic_read(&info->port.count))
53792 return -EBUSY;
53793
53794 switch (encoding)
53795 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53796
53797 /* arbitrate between network and tty opens */
53798 spin_lock_irqsave(&info->netlock, flags);
53799 - if (info->port.count != 0 || info->netcount != 0) {
53800 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53801 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53802 spin_unlock_irqrestore(&info->netlock, flags);
53803 return -EBUSY;
53804 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53805 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53806
53807 /* return error if TTY interface open */
53808 - if (info->port.count)
53809 + if (atomic_read(&info->port.count))
53810 return -EBUSY;
53811
53812 if (cmd != SIOCWANDEV)
53813 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53814 * do not request bottom half processing if the
53815 * device is not open in a normal mode.
53816 */
53817 - if ( port && (port->port.count || port->netcount) &&
53818 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53819 port->pending_bh && !port->bh_running &&
53820 !port->bh_requested ) {
53821 if ( debug_level >= DEBUG_LEVEL_ISR )
53822 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53823
53824 if (debug_level >= DEBUG_LEVEL_INFO)
53825 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53826 - __FILE__,__LINE__, tty->driver->name, port->count );
53827 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53828
53829 spin_lock_irqsave(&info->lock, flags);
53830 - port->count--;
53831 + atomic_dec(&port->count);
53832 spin_unlock_irqrestore(&info->lock, flags);
53833 port->blocked_open++;
53834
53835 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53836
53837 if (debug_level >= DEBUG_LEVEL_INFO)
53838 printk("%s(%d):%s block_til_ready() count=%d\n",
53839 - __FILE__,__LINE__, tty->driver->name, port->count );
53840 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53841
53842 tty_unlock(tty);
53843 schedule();
53844 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53845 set_current_state(TASK_RUNNING);
53846 remove_wait_queue(&port->open_wait, &wait);
53847 if (!tty_hung_up_p(filp))
53848 - port->count++;
53849 + atomic_inc(&port->count);
53850 port->blocked_open--;
53851
53852 if (debug_level >= DEBUG_LEVEL_INFO)
53853 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53854 - __FILE__,__LINE__, tty->driver->name, port->count );
53855 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53856
53857 if (!retval)
53858 port->flags |= ASYNC_NORMAL_ACTIVE;
53859 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53860 index 42bad18..447d7a2 100644
53861 --- a/drivers/tty/sysrq.c
53862 +++ b/drivers/tty/sysrq.c
53863 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53864 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53865 size_t count, loff_t *ppos)
53866 {
53867 - if (count) {
53868 + if (count && capable(CAP_SYS_ADMIN)) {
53869 char c;
53870
53871 if (get_user(c, buf))
53872 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53873 index 0508a1d..b610592 100644
53874 --- a/drivers/tty/tty_io.c
53875 +++ b/drivers/tty/tty_io.c
53876 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53877
53878 void tty_default_fops(struct file_operations *fops)
53879 {
53880 - *fops = tty_fops;
53881 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53882 }
53883
53884 /*
53885 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53886 index 2d822aa..a566234 100644
53887 --- a/drivers/tty/tty_ldisc.c
53888 +++ b/drivers/tty/tty_ldisc.c
53889 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53890 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53891 tty_ldiscs[disc] = new_ldisc;
53892 new_ldisc->num = disc;
53893 - new_ldisc->refcount = 0;
53894 + atomic_set(&new_ldisc->refcount, 0);
53895 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53896
53897 return ret;
53898 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53899 return -EINVAL;
53900
53901 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53902 - if (tty_ldiscs[disc]->refcount)
53903 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53904 ret = -EBUSY;
53905 else
53906 tty_ldiscs[disc] = NULL;
53907 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53908 if (ldops) {
53909 ret = ERR_PTR(-EAGAIN);
53910 if (try_module_get(ldops->owner)) {
53911 - ldops->refcount++;
53912 + atomic_inc(&ldops->refcount);
53913 ret = ldops;
53914 }
53915 }
53916 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53917 unsigned long flags;
53918
53919 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53920 - ldops->refcount--;
53921 + atomic_dec(&ldops->refcount);
53922 module_put(ldops->owner);
53923 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53924 }
53925 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53926 index 1b93357..ea9f82c 100644
53927 --- a/drivers/tty/tty_port.c
53928 +++ b/drivers/tty/tty_port.c
53929 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53930 unsigned long flags;
53931
53932 spin_lock_irqsave(&port->lock, flags);
53933 - port->count = 0;
53934 + atomic_set(&port->count, 0);
53935 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53936 tty = port->tty;
53937 if (tty)
53938 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53939
53940 /* The port lock protects the port counts */
53941 spin_lock_irqsave(&port->lock, flags);
53942 - port->count--;
53943 + atomic_dec(&port->count);
53944 port->blocked_open++;
53945 spin_unlock_irqrestore(&port->lock, flags);
53946
53947 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53948 we must not mess that up further */
53949 spin_lock_irqsave(&port->lock, flags);
53950 if (!tty_hung_up_p(filp))
53951 - port->count++;
53952 + atomic_inc(&port->count);
53953 port->blocked_open--;
53954 if (retval == 0)
53955 port->flags |= ASYNC_NORMAL_ACTIVE;
53956 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53957 return 0;
53958 }
53959
53960 - if (tty->count == 1 && port->count != 1) {
53961 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53962 printk(KERN_WARNING
53963 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53964 - port->count);
53965 - port->count = 1;
53966 + atomic_read(&port->count));
53967 + atomic_set(&port->count, 1);
53968 }
53969 - if (--port->count < 0) {
53970 + if (atomic_dec_return(&port->count) < 0) {
53971 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53972 - port->count);
53973 - port->count = 0;
53974 + atomic_read(&port->count));
53975 + atomic_set(&port->count, 0);
53976 }
53977
53978 - if (port->count) {
53979 + if (atomic_read(&port->count)) {
53980 spin_unlock_irqrestore(&port->lock, flags);
53981 return 0;
53982 }
53983 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53984 struct file *filp)
53985 {
53986 spin_lock_irq(&port->lock);
53987 - ++port->count;
53988 + atomic_inc(&port->count);
53989 spin_unlock_irq(&port->lock);
53990 tty_port_tty_set(port, tty);
53991
53992 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53993 index c039cfe..0b463b0 100644
53994 --- a/drivers/tty/vt/keyboard.c
53995 +++ b/drivers/tty/vt/keyboard.c
53996 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53997 kbd->kbdmode == VC_OFF) &&
53998 value != KVAL(K_SAK))
53999 return; /* SAK is allowed even in raw mode */
54000 +
54001 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54002 + {
54003 + void *func = fn_handler[value];
54004 + if (func == fn_show_state || func == fn_show_ptregs ||
54005 + func == fn_show_mem)
54006 + return;
54007 + }
54008 +#endif
54009 +
54010 fn_handler[value](vc);
54011 }
54012
54013 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54014 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54015 return -EFAULT;
54016
54017 - if (!capable(CAP_SYS_TTY_CONFIG))
54018 - perm = 0;
54019 -
54020 switch (cmd) {
54021 case KDGKBENT:
54022 /* Ensure another thread doesn't free it under us */
54023 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54024 spin_unlock_irqrestore(&kbd_event_lock, flags);
54025 return put_user(val, &user_kbe->kb_value);
54026 case KDSKBENT:
54027 + if (!capable(CAP_SYS_TTY_CONFIG))
54028 + perm = 0;
54029 +
54030 if (!perm)
54031 return -EPERM;
54032 if (!i && v == K_NOSUCHMAP) {
54033 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54034 int i, j, k;
54035 int ret;
54036
54037 - if (!capable(CAP_SYS_TTY_CONFIG))
54038 - perm = 0;
54039 -
54040 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54041 if (!kbs) {
54042 ret = -ENOMEM;
54043 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54044 kfree(kbs);
54045 return ((p && *p) ? -EOVERFLOW : 0);
54046 case KDSKBSENT:
54047 + if (!capable(CAP_SYS_TTY_CONFIG))
54048 + perm = 0;
54049 +
54050 if (!perm) {
54051 ret = -EPERM;
54052 goto reterr;
54053 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54054 index 60fa627..7214965 100644
54055 --- a/drivers/uio/uio.c
54056 +++ b/drivers/uio/uio.c
54057 @@ -25,6 +25,7 @@
54058 #include <linux/kobject.h>
54059 #include <linux/cdev.h>
54060 #include <linux/uio_driver.h>
54061 +#include <asm/local.h>
54062
54063 #define UIO_MAX_DEVICES (1U << MINORBITS)
54064
54065 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
54066 struct device_attribute *attr, char *buf)
54067 {
54068 struct uio_device *idev = dev_get_drvdata(dev);
54069 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54070 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54071 }
54072 static DEVICE_ATTR_RO(event);
54073
54074 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
54075 {
54076 struct uio_device *idev = info->uio_dev;
54077
54078 - atomic_inc(&idev->event);
54079 + atomic_inc_unchecked(&idev->event);
54080 wake_up_interruptible(&idev->wait);
54081 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54082 }
54083 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54084 }
54085
54086 listener->dev = idev;
54087 - listener->event_count = atomic_read(&idev->event);
54088 + listener->event_count = atomic_read_unchecked(&idev->event);
54089 filep->private_data = listener;
54090
54091 if (idev->info->open) {
54092 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54093 return -EIO;
54094
54095 poll_wait(filep, &idev->wait, wait);
54096 - if (listener->event_count != atomic_read(&idev->event))
54097 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54098 return POLLIN | POLLRDNORM;
54099 return 0;
54100 }
54101 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54102 do {
54103 set_current_state(TASK_INTERRUPTIBLE);
54104
54105 - event_count = atomic_read(&idev->event);
54106 + event_count = atomic_read_unchecked(&idev->event);
54107 if (event_count != listener->event_count) {
54108 if (copy_to_user(buf, &event_count, count))
54109 retval = -EFAULT;
54110 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54111 static int uio_find_mem_index(struct vm_area_struct *vma)
54112 {
54113 struct uio_device *idev = vma->vm_private_data;
54114 + unsigned long size;
54115
54116 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54117 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54118 + size = idev->info->mem[vma->vm_pgoff].size;
54119 + if (size == 0)
54120 + return -1;
54121 + if (vma->vm_end - vma->vm_start > size)
54122 return -1;
54123 return (int)vma->vm_pgoff;
54124 }
54125 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
54126 idev->owner = owner;
54127 idev->info = info;
54128 init_waitqueue_head(&idev->wait);
54129 - atomic_set(&idev->event, 0);
54130 + atomic_set_unchecked(&idev->event, 0);
54131
54132 ret = uio_get_minor(idev);
54133 if (ret)
54134 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54135 index 813d4d3..a71934f 100644
54136 --- a/drivers/usb/atm/cxacru.c
54137 +++ b/drivers/usb/atm/cxacru.c
54138 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54139 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54140 if (ret < 2)
54141 return -EINVAL;
54142 - if (index < 0 || index > 0x7f)
54143 + if (index > 0x7f)
54144 return -EINVAL;
54145 pos += tmp;
54146
54147 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54148 index dada014..1d0d517 100644
54149 --- a/drivers/usb/atm/usbatm.c
54150 +++ b/drivers/usb/atm/usbatm.c
54151 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54152 if (printk_ratelimit())
54153 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54154 __func__, vpi, vci);
54155 - atomic_inc(&vcc->stats->rx_err);
54156 + atomic_inc_unchecked(&vcc->stats->rx_err);
54157 return;
54158 }
54159
54160 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54161 if (length > ATM_MAX_AAL5_PDU) {
54162 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54163 __func__, length, vcc);
54164 - atomic_inc(&vcc->stats->rx_err);
54165 + atomic_inc_unchecked(&vcc->stats->rx_err);
54166 goto out;
54167 }
54168
54169 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54170 if (sarb->len < pdu_length) {
54171 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54172 __func__, pdu_length, sarb->len, vcc);
54173 - atomic_inc(&vcc->stats->rx_err);
54174 + atomic_inc_unchecked(&vcc->stats->rx_err);
54175 goto out;
54176 }
54177
54178 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54179 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54180 __func__, vcc);
54181 - atomic_inc(&vcc->stats->rx_err);
54182 + atomic_inc_unchecked(&vcc->stats->rx_err);
54183 goto out;
54184 }
54185
54186 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54187 if (printk_ratelimit())
54188 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54189 __func__, length);
54190 - atomic_inc(&vcc->stats->rx_drop);
54191 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54192 goto out;
54193 }
54194
54195 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54196
54197 vcc->push(vcc, skb);
54198
54199 - atomic_inc(&vcc->stats->rx);
54200 + atomic_inc_unchecked(&vcc->stats->rx);
54201 out:
54202 skb_trim(sarb, 0);
54203 }
54204 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54205 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54206
54207 usbatm_pop(vcc, skb);
54208 - atomic_inc(&vcc->stats->tx);
54209 + atomic_inc_unchecked(&vcc->stats->tx);
54210
54211 skb = skb_dequeue(&instance->sndqueue);
54212 }
54213 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54214 if (!left--)
54215 return sprintf(page,
54216 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54217 - atomic_read(&atm_dev->stats.aal5.tx),
54218 - atomic_read(&atm_dev->stats.aal5.tx_err),
54219 - atomic_read(&atm_dev->stats.aal5.rx),
54220 - atomic_read(&atm_dev->stats.aal5.rx_err),
54221 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54222 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54223 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54224 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54225 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54226 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54227
54228 if (!left--) {
54229 if (instance->disconnected)
54230 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54231 index 2a3bbdf..91d72cf 100644
54232 --- a/drivers/usb/core/devices.c
54233 +++ b/drivers/usb/core/devices.c
54234 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54235 * time it gets called.
54236 */
54237 static struct device_connect_event {
54238 - atomic_t count;
54239 + atomic_unchecked_t count;
54240 wait_queue_head_t wait;
54241 } device_event = {
54242 .count = ATOMIC_INIT(1),
54243 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54244
54245 void usbfs_conn_disc_event(void)
54246 {
54247 - atomic_add(2, &device_event.count);
54248 + atomic_add_unchecked(2, &device_event.count);
54249 wake_up(&device_event.wait);
54250 }
54251
54252 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54253
54254 poll_wait(file, &device_event.wait, wait);
54255
54256 - event_count = atomic_read(&device_event.count);
54257 + event_count = atomic_read_unchecked(&device_event.count);
54258 if (file->f_version != event_count) {
54259 file->f_version = event_count;
54260 return POLLIN | POLLRDNORM;
54261 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54262 index 0b59731..46ee7d1 100644
54263 --- a/drivers/usb/core/devio.c
54264 +++ b/drivers/usb/core/devio.c
54265 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54266 struct usb_dev_state *ps = file->private_data;
54267 struct usb_device *dev = ps->dev;
54268 ssize_t ret = 0;
54269 - unsigned len;
54270 + size_t len;
54271 loff_t pos;
54272 int i;
54273
54274 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54275 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54276 struct usb_config_descriptor *config =
54277 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54278 - unsigned int length = le16_to_cpu(config->wTotalLength);
54279 + size_t length = le16_to_cpu(config->wTotalLength);
54280
54281 if (*ppos < pos + length) {
54282
54283 /* The descriptor may claim to be longer than it
54284 * really is. Here is the actual allocated length. */
54285 - unsigned alloclen =
54286 + size_t alloclen =
54287 le16_to_cpu(dev->config[i].desc.wTotalLength);
54288
54289 - len = length - (*ppos - pos);
54290 + len = length + pos - *ppos;
54291 if (len > nbytes)
54292 len = nbytes;
54293
54294 /* Simply don't write (skip over) unallocated parts */
54295 if (alloclen > (*ppos - pos)) {
54296 - alloclen -= (*ppos - pos);
54297 + alloclen = alloclen + pos - *ppos;
54298 if (copy_to_user(buf,
54299 dev->rawdescriptors[i] + (*ppos - pos),
54300 min(len, alloclen))) {
54301 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54302 index a6efb41..6f72549b 100644
54303 --- a/drivers/usb/core/hcd.c
54304 +++ b/drivers/usb/core/hcd.c
54305 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54306 */
54307 usb_get_urb(urb);
54308 atomic_inc(&urb->use_count);
54309 - atomic_inc(&urb->dev->urbnum);
54310 + atomic_inc_unchecked(&urb->dev->urbnum);
54311 usbmon_urb_submit(&hcd->self, urb);
54312
54313 /* NOTE requirements on root-hub callers (usbfs and the hub
54314 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54315 urb->hcpriv = NULL;
54316 INIT_LIST_HEAD(&urb->urb_list);
54317 atomic_dec(&urb->use_count);
54318 - atomic_dec(&urb->dev->urbnum);
54319 + atomic_dec_unchecked(&urb->dev->urbnum);
54320 if (atomic_read(&urb->reject))
54321 wake_up(&usb_kill_urb_queue);
54322 usb_put_urb(urb);
54323 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54324 index b649fef..c7107a0 100644
54325 --- a/drivers/usb/core/hub.c
54326 +++ b/drivers/usb/core/hub.c
54327 @@ -26,6 +26,7 @@
54328 #include <linux/mutex.h>
54329 #include <linux/random.h>
54330 #include <linux/pm_qos.h>
54331 +#include <linux/grsecurity.h>
54332
54333 #include <asm/uaccess.h>
54334 #include <asm/byteorder.h>
54335 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54336 goto done;
54337 return;
54338 }
54339 +
54340 + if (gr_handle_new_usb())
54341 + goto done;
54342 +
54343 if (hub_is_superspeed(hub->hdev))
54344 unit_load = 150;
54345 else
54346 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54347 index f7b7713..23d07ec 100644
54348 --- a/drivers/usb/core/message.c
54349 +++ b/drivers/usb/core/message.c
54350 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54351 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54352 * error number.
54353 */
54354 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54355 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54356 __u8 requesttype, __u16 value, __u16 index, void *data,
54357 __u16 size, int timeout)
54358 {
54359 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54360 * If successful, 0. Otherwise a negative error number. The number of actual
54361 * bytes transferred will be stored in the @actual_length parameter.
54362 */
54363 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54364 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54365 void *data, int len, int *actual_length, int timeout)
54366 {
54367 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54368 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54369 * bytes transferred will be stored in the @actual_length parameter.
54370 *
54371 */
54372 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54373 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54374 void *data, int len, int *actual_length, int timeout)
54375 {
54376 struct urb *urb;
54377 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54378 index 1236c60..d47a51c 100644
54379 --- a/drivers/usb/core/sysfs.c
54380 +++ b/drivers/usb/core/sysfs.c
54381 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54382 struct usb_device *udev;
54383
54384 udev = to_usb_device(dev);
54385 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54386 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54387 }
54388 static DEVICE_ATTR_RO(urbnum);
54389
54390 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54391 index 2dd2362..1135437 100644
54392 --- a/drivers/usb/core/usb.c
54393 +++ b/drivers/usb/core/usb.c
54394 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54395 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54396 dev->state = USB_STATE_ATTACHED;
54397 dev->lpm_disable_count = 1;
54398 - atomic_set(&dev->urbnum, 0);
54399 + atomic_set_unchecked(&dev->urbnum, 0);
54400
54401 INIT_LIST_HEAD(&dev->ep0.urb_list);
54402 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54403 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54404 index 8cfc319..4868255 100644
54405 --- a/drivers/usb/early/ehci-dbgp.c
54406 +++ b/drivers/usb/early/ehci-dbgp.c
54407 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54408
54409 #ifdef CONFIG_KGDB
54410 static struct kgdb_io kgdbdbgp_io_ops;
54411 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54412 +static struct kgdb_io kgdbdbgp_io_ops_console;
54413 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54414 #else
54415 #define dbgp_kgdb_mode (0)
54416 #endif
54417 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54418 .write_char = kgdbdbgp_write_char,
54419 };
54420
54421 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54422 + .name = "kgdbdbgp",
54423 + .read_char = kgdbdbgp_read_char,
54424 + .write_char = kgdbdbgp_write_char,
54425 + .is_console = 1
54426 +};
54427 +
54428 static int kgdbdbgp_wait_time;
54429
54430 static int __init kgdbdbgp_parse_config(char *str)
54431 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54432 ptr++;
54433 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54434 }
54435 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54436 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54437 + if (early_dbgp_console.index != -1)
54438 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54439 + else
54440 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54441
54442 return 0;
54443 }
54444 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54445 index f7b2032..fbb340c 100644
54446 --- a/drivers/usb/gadget/function/f_uac1.c
54447 +++ b/drivers/usb/gadget/function/f_uac1.c
54448 @@ -14,6 +14,7 @@
54449 #include <linux/module.h>
54450 #include <linux/device.h>
54451 #include <linux/atomic.h>
54452 +#include <linux/module.h>
54453
54454 #include "u_uac1.h"
54455
54456 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54457 index 491082a..dfd7d17 100644
54458 --- a/drivers/usb/gadget/function/u_serial.c
54459 +++ b/drivers/usb/gadget/function/u_serial.c
54460 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54461 spin_lock_irq(&port->port_lock);
54462
54463 /* already open? Great. */
54464 - if (port->port.count) {
54465 + if (atomic_read(&port->port.count)) {
54466 status = 0;
54467 - port->port.count++;
54468 + atomic_inc(&port->port.count);
54469
54470 /* currently opening/closing? wait ... */
54471 } else if (port->openclose) {
54472 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54473 tty->driver_data = port;
54474 port->port.tty = tty;
54475
54476 - port->port.count = 1;
54477 + atomic_set(&port->port.count, 1);
54478 port->openclose = false;
54479
54480 /* if connected, start the I/O stream */
54481 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54482
54483 spin_lock_irq(&port->port_lock);
54484
54485 - if (port->port.count != 1) {
54486 - if (port->port.count == 0)
54487 + if (atomic_read(&port->port.count) != 1) {
54488 + if (atomic_read(&port->port.count) == 0)
54489 WARN_ON(1);
54490 else
54491 - --port->port.count;
54492 + atomic_dec(&port->port.count);
54493 goto exit;
54494 }
54495
54496 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54497 * and sleep if necessary
54498 */
54499 port->openclose = true;
54500 - port->port.count = 0;
54501 + atomic_set(&port->port.count, 0);
54502
54503 gser = port->port_usb;
54504 if (gser && gser->disconnect)
54505 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54506 int cond;
54507
54508 spin_lock_irq(&port->port_lock);
54509 - cond = (port->port.count == 0) && !port->openclose;
54510 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54511 spin_unlock_irq(&port->port_lock);
54512 return cond;
54513 }
54514 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54515 /* if it's already open, start I/O ... and notify the serial
54516 * protocol about open/close status (connect/disconnect).
54517 */
54518 - if (port->port.count) {
54519 + if (atomic_read(&port->port.count)) {
54520 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54521 gs_start_io(port);
54522 if (gser->connect)
54523 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54524
54525 port->port_usb = NULL;
54526 gser->ioport = NULL;
54527 - if (port->port.count > 0 || port->openclose) {
54528 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54529 wake_up_interruptible(&port->drain_wait);
54530 if (port->port.tty)
54531 tty_hangup(port->port.tty);
54532 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54533
54534 /* finally, free any unused/unusable I/O buffers */
54535 spin_lock_irqsave(&port->port_lock, flags);
54536 - if (port->port.count == 0 && !port->openclose)
54537 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54538 gs_buf_free(&port->port_write_buf);
54539 gs_free_requests(gser->out, &port->read_pool, NULL);
54540 gs_free_requests(gser->out, &port->read_queue, NULL);
54541 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54542 index a44a07f..ecea924 100644
54543 --- a/drivers/usb/gadget/function/u_uac1.c
54544 +++ b/drivers/usb/gadget/function/u_uac1.c
54545 @@ -17,6 +17,7 @@
54546 #include <linux/ctype.h>
54547 #include <linux/random.h>
54548 #include <linux/syscalls.h>
54549 +#include <linux/module.h>
54550
54551 #include "u_uac1.h"
54552
54553 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54554 index 5728829..fefc6bf 100644
54555 --- a/drivers/usb/host/ehci-hub.c
54556 +++ b/drivers/usb/host/ehci-hub.c
54557 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54558 urb->transfer_flags = URB_DIR_IN;
54559 usb_get_urb(urb);
54560 atomic_inc(&urb->use_count);
54561 - atomic_inc(&urb->dev->urbnum);
54562 + atomic_inc_unchecked(&urb->dev->urbnum);
54563 urb->setup_dma = dma_map_single(
54564 hcd->self.controller,
54565 urb->setup_packet,
54566 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54567 urb->status = -EINPROGRESS;
54568 usb_get_urb(urb);
54569 atomic_inc(&urb->use_count);
54570 - atomic_inc(&urb->dev->urbnum);
54571 + atomic_inc_unchecked(&urb->dev->urbnum);
54572 retval = submit_single_step_set_feature(hcd, urb, 0);
54573 if (!retval && !wait_for_completion_timeout(&done,
54574 msecs_to_jiffies(2000))) {
54575 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54576 index 1db0626..4948782 100644
54577 --- a/drivers/usb/host/hwa-hc.c
54578 +++ b/drivers/usb/host/hwa-hc.c
54579 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54580 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54581 struct wahc *wa = &hwahc->wa;
54582 struct device *dev = &wa->usb_iface->dev;
54583 - u8 mas_le[UWB_NUM_MAS/8];
54584 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54585 +
54586 + if (mas_le == NULL)
54587 + return -ENOMEM;
54588
54589 /* Set the stream index */
54590 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54591 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54592 WUSB_REQ_SET_WUSB_MAS,
54593 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54594 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54595 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54596 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54597 if (result < 0)
54598 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54599 out:
54600 + kfree(mas_le);
54601 +
54602 return result;
54603 }
54604
54605 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54606 index b3d245e..99549ed 100644
54607 --- a/drivers/usb/misc/appledisplay.c
54608 +++ b/drivers/usb/misc/appledisplay.c
54609 @@ -84,7 +84,7 @@ struct appledisplay {
54610 struct mutex sysfslock; /* concurrent read and write */
54611 };
54612
54613 -static atomic_t count_displays = ATOMIC_INIT(0);
54614 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54615 static struct workqueue_struct *wq;
54616
54617 static void appledisplay_complete(struct urb *urb)
54618 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54619
54620 /* Register backlight device */
54621 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54622 - atomic_inc_return(&count_displays) - 1);
54623 + atomic_inc_return_unchecked(&count_displays) - 1);
54624 memset(&props, 0, sizeof(struct backlight_properties));
54625 props.type = BACKLIGHT_RAW;
54626 props.max_brightness = 0xff;
54627 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54628 index 29fa1c3..a57b08e 100644
54629 --- a/drivers/usb/serial/console.c
54630 +++ b/drivers/usb/serial/console.c
54631 @@ -125,7 +125,7 @@ static int usb_console_setup(struct console *co, char *options)
54632
54633 info->port = port;
54634
54635 - ++port->port.count;
54636 + atomic_inc(&port->port.count);
54637 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54638 if (serial->type->set_termios) {
54639 /*
54640 @@ -173,7 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
54641 }
54642 /* Now that any required fake tty operations are completed restore
54643 * the tty port count */
54644 - --port->port.count;
54645 + atomic_dec(&port->port.count);
54646 /* The console is special in terms of closing the device so
54647 * indicate this port is now acting as a system console. */
54648 port->port.console = 1;
54649 @@ -186,7 +186,7 @@ static int usb_console_setup(struct console *co, char *options)
54650 put_tty:
54651 tty_kref_put(tty);
54652 reset_open_count:
54653 - port->port.count = 0;
54654 + atomic_set(&port->port.count, 0);
54655 usb_autopm_put_interface(serial->interface);
54656 error_get_interface:
54657 usb_serial_put(serial);
54658 @@ -197,7 +197,7 @@ static int usb_console_setup(struct console *co, char *options)
54659 static void usb_console_write(struct console *co,
54660 const char *buf, unsigned count)
54661 {
54662 - static struct usbcons_info *info = &usbcons_info;
54663 + struct usbcons_info *info = &usbcons_info;
54664 struct usb_serial_port *port = info->port;
54665 struct usb_serial *serial;
54666 int retval = -ENODEV;
54667 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54668 index 307e339..6aa97cb 100644
54669 --- a/drivers/usb/storage/usb.h
54670 +++ b/drivers/usb/storage/usb.h
54671 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54672 __u8 useProtocol;
54673 __u8 useTransport;
54674 int (*initFunction)(struct us_data *);
54675 -};
54676 +} __do_const;
54677
54678
54679 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54680 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54681 index a863a98..d272795 100644
54682 --- a/drivers/usb/usbip/vhci.h
54683 +++ b/drivers/usb/usbip/vhci.h
54684 @@ -83,7 +83,7 @@ struct vhci_hcd {
54685 unsigned resuming:1;
54686 unsigned long re_timeout;
54687
54688 - atomic_t seqnum;
54689 + atomic_unchecked_t seqnum;
54690
54691 /*
54692 * NOTE:
54693 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54694 index c02374b..32d47a9 100644
54695 --- a/drivers/usb/usbip/vhci_hcd.c
54696 +++ b/drivers/usb/usbip/vhci_hcd.c
54697 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54698
54699 spin_lock(&vdev->priv_lock);
54700
54701 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54702 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54703 if (priv->seqnum == 0xffff)
54704 dev_info(&urb->dev->dev, "seqnum max\n");
54705
54706 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54707 return -ENOMEM;
54708 }
54709
54710 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54711 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54712 if (unlink->seqnum == 0xffff)
54713 pr_info("seqnum max\n");
54714
54715 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54716 vdev->rhport = rhport;
54717 }
54718
54719 - atomic_set(&vhci->seqnum, 0);
54720 + atomic_set_unchecked(&vhci->seqnum, 0);
54721 spin_lock_init(&vhci->lock);
54722
54723 hcd->power_budget = 0; /* no limit */
54724 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54725 index 00e4a54..d676f85 100644
54726 --- a/drivers/usb/usbip/vhci_rx.c
54727 +++ b/drivers/usb/usbip/vhci_rx.c
54728 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54729 if (!urb) {
54730 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54731 pr_info("max seqnum %d\n",
54732 - atomic_read(&the_controller->seqnum));
54733 + atomic_read_unchecked(&the_controller->seqnum));
54734 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54735 return;
54736 }
54737 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54738 index edc7267..9f65ce2 100644
54739 --- a/drivers/usb/wusbcore/wa-hc.h
54740 +++ b/drivers/usb/wusbcore/wa-hc.h
54741 @@ -240,7 +240,7 @@ struct wahc {
54742 spinlock_t xfer_list_lock;
54743 struct work_struct xfer_enqueue_work;
54744 struct work_struct xfer_error_work;
54745 - atomic_t xfer_id_count;
54746 + atomic_unchecked_t xfer_id_count;
54747
54748 kernel_ulong_t quirks;
54749 };
54750 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54751 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54752 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54753 wa->dto_in_use = 0;
54754 - atomic_set(&wa->xfer_id_count, 1);
54755 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54756 /* init the buf in URBs */
54757 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54758 usb_init_urb(&(wa->buf_in_urbs[index]));
54759 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54760 index 69af4fd..da390d7 100644
54761 --- a/drivers/usb/wusbcore/wa-xfer.c
54762 +++ b/drivers/usb/wusbcore/wa-xfer.c
54763 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54764 */
54765 static void wa_xfer_id_init(struct wa_xfer *xfer)
54766 {
54767 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54768 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54769 }
54770
54771 /* Return the xfer's ID. */
54772 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54773 index f018d8d..ccab63f 100644
54774 --- a/drivers/vfio/vfio.c
54775 +++ b/drivers/vfio/vfio.c
54776 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54777 return 0;
54778
54779 /* TODO Prevent device auto probing */
54780 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54781 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54782 iommu_group_id(group->iommu_group));
54783
54784 return 0;
54785 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54786 index 5174eba..451e6bc 100644
54787 --- a/drivers/vhost/vringh.c
54788 +++ b/drivers/vhost/vringh.c
54789 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54790 /* Userspace access helpers: in this case, addresses are really userspace. */
54791 static inline int getu16_user(u16 *val, const u16 *p)
54792 {
54793 - return get_user(*val, (__force u16 __user *)p);
54794 + return get_user(*val, (u16 __force_user *)p);
54795 }
54796
54797 static inline int putu16_user(u16 *p, u16 val)
54798 {
54799 - return put_user(val, (__force u16 __user *)p);
54800 + return put_user(val, (u16 __force_user *)p);
54801 }
54802
54803 static inline int copydesc_user(void *dst, const void *src, size_t len)
54804 {
54805 - return copy_from_user(dst, (__force void __user *)src, len) ?
54806 + return copy_from_user(dst, (void __force_user *)src, len) ?
54807 -EFAULT : 0;
54808 }
54809
54810 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54811 const struct vring_used_elem *src,
54812 unsigned int num)
54813 {
54814 - return copy_to_user((__force void __user *)dst, src,
54815 + return copy_to_user((void __force_user *)dst, src,
54816 sizeof(*dst) * num) ? -EFAULT : 0;
54817 }
54818
54819 static inline int xfer_from_user(void *src, void *dst, size_t len)
54820 {
54821 - return copy_from_user(dst, (__force void __user *)src, len) ?
54822 + return copy_from_user(dst, (void __force_user *)src, len) ?
54823 -EFAULT : 0;
54824 }
54825
54826 static inline int xfer_to_user(void *dst, void *src, size_t len)
54827 {
54828 - return copy_to_user((__force void __user *)dst, src, len) ?
54829 + return copy_to_user((void __force_user *)dst, src, len) ?
54830 -EFAULT : 0;
54831 }
54832
54833 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54834 vrh->last_used_idx = 0;
54835 vrh->vring.num = num;
54836 /* vring expects kernel addresses, but only used via accessors. */
54837 - vrh->vring.desc = (__force struct vring_desc *)desc;
54838 - vrh->vring.avail = (__force struct vring_avail *)avail;
54839 - vrh->vring.used = (__force struct vring_used *)used;
54840 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54841 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54842 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54843 return 0;
54844 }
54845 EXPORT_SYMBOL(vringh_init_user);
54846 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54847
54848 static inline int putu16_kern(u16 *p, u16 val)
54849 {
54850 - ACCESS_ONCE(*p) = val;
54851 + ACCESS_ONCE_RW(*p) = val;
54852 return 0;
54853 }
54854
54855 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54856 index 84a110a..96312c3 100644
54857 --- a/drivers/video/backlight/kb3886_bl.c
54858 +++ b/drivers/video/backlight/kb3886_bl.c
54859 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54860 static unsigned long kb3886bl_flags;
54861 #define KB3886BL_SUSPENDED 0x01
54862
54863 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54864 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54865 {
54866 .ident = "Sahara Touch-iT",
54867 .matches = {
54868 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54869 index 1b0b233..6f34c2c 100644
54870 --- a/drivers/video/fbdev/arcfb.c
54871 +++ b/drivers/video/fbdev/arcfb.c
54872 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54873 return -ENOSPC;
54874
54875 err = 0;
54876 - if ((count + p) > fbmemlength) {
54877 + if (count > (fbmemlength - p)) {
54878 count = fbmemlength - p;
54879 err = -ENOSPC;
54880 }
54881 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54882 index aedf2fb..47c9aca 100644
54883 --- a/drivers/video/fbdev/aty/aty128fb.c
54884 +++ b/drivers/video/fbdev/aty/aty128fb.c
54885 @@ -149,7 +149,7 @@ enum {
54886 };
54887
54888 /* Must match above enum */
54889 -static char * const r128_family[] = {
54890 +static const char * const r128_family[] = {
54891 "AGP",
54892 "PCI",
54893 "PRO AGP",
54894 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54895 index 37ec09b..98f8862 100644
54896 --- a/drivers/video/fbdev/aty/atyfb_base.c
54897 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54898 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54899 par->accel_flags = var->accel_flags; /* hack */
54900
54901 if (var->accel_flags) {
54902 - info->fbops->fb_sync = atyfb_sync;
54903 + pax_open_kernel();
54904 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54905 + pax_close_kernel();
54906 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54907 } else {
54908 - info->fbops->fb_sync = NULL;
54909 + pax_open_kernel();
54910 + *(void **)&info->fbops->fb_sync = NULL;
54911 + pax_close_kernel();
54912 info->flags |= FBINFO_HWACCEL_DISABLED;
54913 }
54914
54915 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54916 index 2fa0317..4983f2a 100644
54917 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54918 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54919 @@ -8,6 +8,7 @@
54920 #include "../core/fb_draw.h"
54921
54922 #include <asm/io.h>
54923 +#include <asm/pgtable.h>
54924
54925 #ifdef __sparc__
54926 #include <asm/fbio.h>
54927 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54928 info->sprite.buf_align = 16; /* and 64 lines tall. */
54929 info->sprite.flags = FB_PIXMAP_IO;
54930
54931 - info->fbops->fb_cursor = atyfb_cursor;
54932 + pax_open_kernel();
54933 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54934 + pax_close_kernel();
54935
54936 return 0;
54937 }
54938 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54939 index d6cab1f..112f680 100644
54940 --- a/drivers/video/fbdev/core/fb_defio.c
54941 +++ b/drivers/video/fbdev/core/fb_defio.c
54942 @@ -207,7 +207,9 @@ void fb_deferred_io_init(struct fb_info *info)
54943
54944 BUG_ON(!fbdefio);
54945 mutex_init(&fbdefio->lock);
54946 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54947 + pax_open_kernel();
54948 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54949 + pax_close_kernel();
54950 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54951 INIT_LIST_HEAD(&fbdefio->pagelist);
54952 if (fbdefio->delay == 0) /* set a default of 1 s */
54953 @@ -238,7 +240,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54954 page->mapping = NULL;
54955 }
54956
54957 - info->fbops->fb_mmap = NULL;
54958 + *(void **)&info->fbops->fb_mmap = NULL;
54959 mutex_destroy(&fbdefio->lock);
54960 }
54961 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54962 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54963 index 0705d88..d9429bf 100644
54964 --- a/drivers/video/fbdev/core/fbmem.c
54965 +++ b/drivers/video/fbdev/core/fbmem.c
54966 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54967 __u32 data;
54968 int err;
54969
54970 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54971 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54972
54973 data = (__u32) (unsigned long) fix->smem_start;
54974 err |= put_user(data, &fix32->smem_start);
54975 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54976 index 4254336..282567e 100644
54977 --- a/drivers/video/fbdev/hyperv_fb.c
54978 +++ b/drivers/video/fbdev/hyperv_fb.c
54979 @@ -240,7 +240,7 @@ static uint screen_fb_size;
54980 static inline int synthvid_send(struct hv_device *hdev,
54981 struct synthvid_msg *msg)
54982 {
54983 - static atomic64_t request_id = ATOMIC64_INIT(0);
54984 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54985 int ret;
54986
54987 msg->pipe_hdr.type = PIPE_MSG_DATA;
54988 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54989
54990 ret = vmbus_sendpacket(hdev->channel, msg,
54991 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54992 - atomic64_inc_return(&request_id),
54993 + atomic64_inc_return_unchecked(&request_id),
54994 VM_PKT_DATA_INBAND, 0);
54995
54996 if (ret)
54997 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54998 index 7672d2e..b56437f 100644
54999 --- a/drivers/video/fbdev/i810/i810_accel.c
55000 +++ b/drivers/video/fbdev/i810/i810_accel.c
55001 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55002 }
55003 }
55004 printk("ringbuffer lockup!!!\n");
55005 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55006 i810_report_error(mmio);
55007 par->dev_flags |= LOCKUP;
55008 info->pixmap.scan_align = 1;
55009 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55010 index a01147f..5d896f8 100644
55011 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55012 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55013 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55014
55015 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55016 struct matrox_switch matrox_mystique = {
55017 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55018 + .preinit = MGA1064_preinit,
55019 + .reset = MGA1064_reset,
55020 + .init = MGA1064_init,
55021 + .restore = MGA1064_restore,
55022 };
55023 EXPORT_SYMBOL(matrox_mystique);
55024 #endif
55025
55026 #ifdef CONFIG_FB_MATROX_G
55027 struct matrox_switch matrox_G100 = {
55028 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55029 + .preinit = MGAG100_preinit,
55030 + .reset = MGAG100_reset,
55031 + .init = MGAG100_init,
55032 + .restore = MGAG100_restore,
55033 };
55034 EXPORT_SYMBOL(matrox_G100);
55035 #endif
55036 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55037 index 195ad7c..09743fc 100644
55038 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55039 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55040 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55041 }
55042
55043 struct matrox_switch matrox_millennium = {
55044 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55045 + .preinit = Ti3026_preinit,
55046 + .reset = Ti3026_reset,
55047 + .init = Ti3026_init,
55048 + .restore = Ti3026_restore
55049 };
55050 EXPORT_SYMBOL(matrox_millennium);
55051 #endif
55052 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55053 index fe92eed..106e085 100644
55054 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55055 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55056 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55057 struct mb862xxfb_par *par = info->par;
55058
55059 if (info->var.bits_per_pixel == 32) {
55060 - info->fbops->fb_fillrect = cfb_fillrect;
55061 - info->fbops->fb_copyarea = cfb_copyarea;
55062 - info->fbops->fb_imageblit = cfb_imageblit;
55063 + pax_open_kernel();
55064 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55065 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55066 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55067 + pax_close_kernel();
55068 } else {
55069 outreg(disp, GC_L0EM, 3);
55070 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55071 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55072 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55073 + pax_open_kernel();
55074 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55075 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55076 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55077 + pax_close_kernel();
55078 }
55079 outreg(draw, GDC_REG_DRAW_BASE, 0);
55080 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55081 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55082 index def0412..fed6529 100644
55083 --- a/drivers/video/fbdev/nvidia/nvidia.c
55084 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55085 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55086 info->fix.line_length = (info->var.xres_virtual *
55087 info->var.bits_per_pixel) >> 3;
55088 if (info->var.accel_flags) {
55089 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55090 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55091 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55092 - info->fbops->fb_sync = nvidiafb_sync;
55093 + pax_open_kernel();
55094 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55095 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55096 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55097 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55098 + pax_close_kernel();
55099 info->pixmap.scan_align = 4;
55100 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55101 info->flags |= FBINFO_READS_FAST;
55102 NVResetGraphics(info);
55103 } else {
55104 - info->fbops->fb_imageblit = cfb_imageblit;
55105 - info->fbops->fb_fillrect = cfb_fillrect;
55106 - info->fbops->fb_copyarea = cfb_copyarea;
55107 - info->fbops->fb_sync = NULL;
55108 + pax_open_kernel();
55109 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55110 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55111 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55112 + *(void **)&info->fbops->fb_sync = NULL;
55113 + pax_close_kernel();
55114 info->pixmap.scan_align = 1;
55115 info->flags |= FBINFO_HWACCEL_DISABLED;
55116 info->flags &= ~FBINFO_READS_FAST;
55117 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55118 info->pixmap.size = 8 * 1024;
55119 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55120
55121 - if (!hwcur)
55122 - info->fbops->fb_cursor = NULL;
55123 + if (!hwcur) {
55124 + pax_open_kernel();
55125 + *(void **)&info->fbops->fb_cursor = NULL;
55126 + pax_close_kernel();
55127 + }
55128
55129 info->var.accel_flags = (!noaccel);
55130
55131 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55132 index 2412a0d..294215b 100644
55133 --- a/drivers/video/fbdev/omap2/dss/display.c
55134 +++ b/drivers/video/fbdev/omap2/dss/display.c
55135 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55136 if (dssdev->name == NULL)
55137 dssdev->name = dssdev->alias;
55138
55139 + pax_open_kernel();
55140 if (drv && drv->get_resolution == NULL)
55141 - drv->get_resolution = omapdss_default_get_resolution;
55142 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55143 if (drv && drv->get_recommended_bpp == NULL)
55144 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55145 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55146 if (drv && drv->get_timings == NULL)
55147 - drv->get_timings = omapdss_default_get_timings;
55148 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55149 + pax_close_kernel();
55150
55151 mutex_lock(&panel_list_mutex);
55152 list_add_tail(&dssdev->panel_list, &panel_list);
55153 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55154 index 83433cb..71e9b98 100644
55155 --- a/drivers/video/fbdev/s1d13xxxfb.c
55156 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55157 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55158
55159 switch(prod_id) {
55160 case S1D13506_PROD_ID: /* activate acceleration */
55161 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55162 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55163 + pax_open_kernel();
55164 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55165 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55166 + pax_close_kernel();
55167 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55168 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55169 break;
55170 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55171 index 2bcc84a..29dd1ea 100644
55172 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55173 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55174 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55175 }
55176
55177 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55178 - lcdc_sys_write_index,
55179 - lcdc_sys_write_data,
55180 - lcdc_sys_read_data,
55181 + .write_index = lcdc_sys_write_index,
55182 + .write_data = lcdc_sys_write_data,
55183 + .read_data = lcdc_sys_read_data,
55184 };
55185
55186 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55187 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55188 index d513ed6..90b0de9 100644
55189 --- a/drivers/video/fbdev/smscufx.c
55190 +++ b/drivers/video/fbdev/smscufx.c
55191 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55192 fb_deferred_io_cleanup(info);
55193 kfree(info->fbdefio);
55194 info->fbdefio = NULL;
55195 - info->fbops->fb_mmap = ufx_ops_mmap;
55196 + pax_open_kernel();
55197 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55198 + pax_close_kernel();
55199 }
55200
55201 pr_debug("released /dev/fb%d user=%d count=%d",
55202 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55203 index 046d51d..be564da 100644
55204 --- a/drivers/video/fbdev/udlfb.c
55205 +++ b/drivers/video/fbdev/udlfb.c
55206 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55207 dlfb_urb_completion(urb);
55208
55209 error:
55210 - atomic_add(bytes_sent, &dev->bytes_sent);
55211 - atomic_add(bytes_identical, &dev->bytes_identical);
55212 - atomic_add(width*height*2, &dev->bytes_rendered);
55213 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55214 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55215 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55216 end_cycles = get_cycles();
55217 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55218 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55219 >> 10)), /* Kcycles */
55220 &dev->cpu_kcycles_used);
55221
55222 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55223 dlfb_urb_completion(urb);
55224
55225 error:
55226 - atomic_add(bytes_sent, &dev->bytes_sent);
55227 - atomic_add(bytes_identical, &dev->bytes_identical);
55228 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55229 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55230 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55231 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55232 end_cycles = get_cycles();
55233 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55234 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55235 >> 10)), /* Kcycles */
55236 &dev->cpu_kcycles_used);
55237 }
55238 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55239 fb_deferred_io_cleanup(info);
55240 kfree(info->fbdefio);
55241 info->fbdefio = NULL;
55242 - info->fbops->fb_mmap = dlfb_ops_mmap;
55243 + pax_open_kernel();
55244 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55245 + pax_close_kernel();
55246 }
55247
55248 pr_warn("released /dev/fb%d user=%d count=%d\n",
55249 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55250 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55251 struct dlfb_data *dev = fb_info->par;
55252 return snprintf(buf, PAGE_SIZE, "%u\n",
55253 - atomic_read(&dev->bytes_rendered));
55254 + atomic_read_unchecked(&dev->bytes_rendered));
55255 }
55256
55257 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55258 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55259 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55260 struct dlfb_data *dev = fb_info->par;
55261 return snprintf(buf, PAGE_SIZE, "%u\n",
55262 - atomic_read(&dev->bytes_identical));
55263 + atomic_read_unchecked(&dev->bytes_identical));
55264 }
55265
55266 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55267 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55268 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55269 struct dlfb_data *dev = fb_info->par;
55270 return snprintf(buf, PAGE_SIZE, "%u\n",
55271 - atomic_read(&dev->bytes_sent));
55272 + atomic_read_unchecked(&dev->bytes_sent));
55273 }
55274
55275 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55276 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55277 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55278 struct dlfb_data *dev = fb_info->par;
55279 return snprintf(buf, PAGE_SIZE, "%u\n",
55280 - atomic_read(&dev->cpu_kcycles_used));
55281 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55282 }
55283
55284 static ssize_t edid_show(
55285 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55286 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55287 struct dlfb_data *dev = fb_info->par;
55288
55289 - atomic_set(&dev->bytes_rendered, 0);
55290 - atomic_set(&dev->bytes_identical, 0);
55291 - atomic_set(&dev->bytes_sent, 0);
55292 - atomic_set(&dev->cpu_kcycles_used, 0);
55293 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55294 + atomic_set_unchecked(&dev->bytes_identical, 0);
55295 + atomic_set_unchecked(&dev->bytes_sent, 0);
55296 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55297
55298 return count;
55299 }
55300 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55301 index 509d452..7c9d2de 100644
55302 --- a/drivers/video/fbdev/uvesafb.c
55303 +++ b/drivers/video/fbdev/uvesafb.c
55304 @@ -19,6 +19,7 @@
55305 #include <linux/io.h>
55306 #include <linux/mutex.h>
55307 #include <linux/slab.h>
55308 +#include <linux/moduleloader.h>
55309 #include <video/edid.h>
55310 #include <video/uvesafb.h>
55311 #ifdef CONFIG_X86
55312 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55313 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55314 par->pmi_setpal = par->ypan = 0;
55315 } else {
55316 +
55317 +#ifdef CONFIG_PAX_KERNEXEC
55318 +#ifdef CONFIG_MODULES
55319 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55320 +#endif
55321 + if (!par->pmi_code) {
55322 + par->pmi_setpal = par->ypan = 0;
55323 + return 0;
55324 + }
55325 +#endif
55326 +
55327 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55328 + task->t.regs.edi);
55329 +
55330 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55331 + pax_open_kernel();
55332 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55333 + pax_close_kernel();
55334 +
55335 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55336 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55337 +#else
55338 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55339 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55340 +#endif
55341 +
55342 printk(KERN_INFO "uvesafb: protected mode interface info at "
55343 "%04x:%04x\n",
55344 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55345 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55346 par->ypan = ypan;
55347
55348 if (par->pmi_setpal || par->ypan) {
55349 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55350 if (__supported_pte_mask & _PAGE_NX) {
55351 par->pmi_setpal = par->ypan = 0;
55352 printk(KERN_WARNING "uvesafb: NX protection is active, "
55353 "better not use the PMI.\n");
55354 - } else {
55355 + } else
55356 +#endif
55357 uvesafb_vbe_getpmi(task, par);
55358 - }
55359 }
55360 #else
55361 /* The protected mode interface is not available on non-x86. */
55362 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55363 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55364
55365 /* Disable blanking if the user requested so. */
55366 - if (!blank)
55367 - info->fbops->fb_blank = NULL;
55368 + if (!blank) {
55369 + pax_open_kernel();
55370 + *(void **)&info->fbops->fb_blank = NULL;
55371 + pax_close_kernel();
55372 + }
55373
55374 /*
55375 * Find out how much IO memory is required for the mode with
55376 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55377 info->flags = FBINFO_FLAG_DEFAULT |
55378 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55379
55380 - if (!par->ypan)
55381 - info->fbops->fb_pan_display = NULL;
55382 + if (!par->ypan) {
55383 + pax_open_kernel();
55384 + *(void **)&info->fbops->fb_pan_display = NULL;
55385 + pax_close_kernel();
55386 + }
55387 }
55388
55389 static void uvesafb_init_mtrr(struct fb_info *info)
55390 @@ -1787,6 +1817,11 @@ out_mode:
55391 out:
55392 kfree(par->vbe_modes);
55393
55394 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55395 + if (par->pmi_code)
55396 + module_free_exec(NULL, par->pmi_code);
55397 +#endif
55398 +
55399 framebuffer_release(info);
55400 return err;
55401 }
55402 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55403 kfree(par->vbe_state_orig);
55404 kfree(par->vbe_state_saved);
55405
55406 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55407 + if (par->pmi_code)
55408 + module_free_exec(NULL, par->pmi_code);
55409 +#endif
55410 +
55411 framebuffer_release(info);
55412 }
55413 return 0;
55414 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55415 index 6170e7f..dd63031 100644
55416 --- a/drivers/video/fbdev/vesafb.c
55417 +++ b/drivers/video/fbdev/vesafb.c
55418 @@ -9,6 +9,7 @@
55419 */
55420
55421 #include <linux/module.h>
55422 +#include <linux/moduleloader.h>
55423 #include <linux/kernel.h>
55424 #include <linux/errno.h>
55425 #include <linux/string.h>
55426 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55427 static int vram_total; /* Set total amount of memory */
55428 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55429 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55430 -static void (*pmi_start)(void) __read_mostly;
55431 -static void (*pmi_pal) (void) __read_mostly;
55432 +static void (*pmi_start)(void) __read_only;
55433 +static void (*pmi_pal) (void) __read_only;
55434 static int depth __read_mostly;
55435 static int vga_compat __read_mostly;
55436 /* --------------------------------------------------------------------- */
55437 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55438 unsigned int size_remap;
55439 unsigned int size_total;
55440 char *option = NULL;
55441 + void *pmi_code = NULL;
55442
55443 /* ignore error return of fb_get_options */
55444 fb_get_options("vesafb", &option);
55445 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55446 size_remap = size_total;
55447 vesafb_fix.smem_len = size_remap;
55448
55449 -#ifndef __i386__
55450 - screen_info.vesapm_seg = 0;
55451 -#endif
55452 -
55453 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55454 printk(KERN_WARNING
55455 "vesafb: cannot reserve video memory at 0x%lx\n",
55456 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55457 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55458 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55459
55460 +#ifdef __i386__
55461 +
55462 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55463 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55464 + if (!pmi_code)
55465 +#elif !defined(CONFIG_PAX_KERNEXEC)
55466 + if (0)
55467 +#endif
55468 +
55469 +#endif
55470 + screen_info.vesapm_seg = 0;
55471 +
55472 if (screen_info.vesapm_seg) {
55473 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55474 - screen_info.vesapm_seg,screen_info.vesapm_off);
55475 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55476 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55477 }
55478
55479 if (screen_info.vesapm_seg < 0xc000)
55480 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55481
55482 if (ypan || pmi_setpal) {
55483 unsigned short *pmi_base;
55484 +
55485 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55486 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55487 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55488 +
55489 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55490 + pax_open_kernel();
55491 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55492 +#else
55493 + pmi_code = pmi_base;
55494 +#endif
55495 +
55496 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55497 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55498 +
55499 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55500 + pmi_start = ktva_ktla(pmi_start);
55501 + pmi_pal = ktva_ktla(pmi_pal);
55502 + pax_close_kernel();
55503 +#endif
55504 +
55505 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55506 if (pmi_base[3]) {
55507 printk(KERN_INFO "vesafb: pmi: ports = ");
55508 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55509 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55510 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55511
55512 - if (!ypan)
55513 - info->fbops->fb_pan_display = NULL;
55514 + if (!ypan) {
55515 + pax_open_kernel();
55516 + *(void **)&info->fbops->fb_pan_display = NULL;
55517 + pax_close_kernel();
55518 + }
55519
55520 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55521 err = -ENOMEM;
55522 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55523 fb_info(info, "%s frame buffer device\n", info->fix.id);
55524 return 0;
55525 err:
55526 +
55527 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55528 + module_free_exec(NULL, pmi_code);
55529 +#endif
55530 +
55531 if (info->screen_base)
55532 iounmap(info->screen_base);
55533 framebuffer_release(info);
55534 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55535 index 88714ae..16c2e11 100644
55536 --- a/drivers/video/fbdev/via/via_clock.h
55537 +++ b/drivers/video/fbdev/via/via_clock.h
55538 @@ -56,7 +56,7 @@ struct via_clock {
55539
55540 void (*set_engine_pll_state)(u8 state);
55541 void (*set_engine_pll)(struct via_pll_config config);
55542 -};
55543 +} __no_const;
55544
55545
55546 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55547 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55548 index 3c14e43..2630570 100644
55549 --- a/drivers/video/logo/logo_linux_clut224.ppm
55550 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55551 @@ -2,1603 +2,1123 @@ P3
55552 # Standard 224-color Linux logo
55553 80 80
55554 255
55555 - 0 0 0 0 0 0 0 0 0 0 0 0
55556 - 0 0 0 0 0 0 0 0 0 0 0 0
55557 - 0 0 0 0 0 0 0 0 0 0 0 0
55558 - 0 0 0 0 0 0 0 0 0 0 0 0
55559 - 0 0 0 0 0 0 0 0 0 0 0 0
55560 - 0 0 0 0 0 0 0 0 0 0 0 0
55561 - 0 0 0 0 0 0 0 0 0 0 0 0
55562 - 0 0 0 0 0 0 0 0 0 0 0 0
55563 - 0 0 0 0 0 0 0 0 0 0 0 0
55564 - 6 6 6 6 6 6 10 10 10 10 10 10
55565 - 10 10 10 6 6 6 6 6 6 6 6 6
55566 - 0 0 0 0 0 0 0 0 0 0 0 0
55567 - 0 0 0 0 0 0 0 0 0 0 0 0
55568 - 0 0 0 0 0 0 0 0 0 0 0 0
55569 - 0 0 0 0 0 0 0 0 0 0 0 0
55570 - 0 0 0 0 0 0 0 0 0 0 0 0
55571 - 0 0 0 0 0 0 0 0 0 0 0 0
55572 - 0 0 0 0 0 0 0 0 0 0 0 0
55573 - 0 0 0 0 0 0 0 0 0 0 0 0
55574 - 0 0 0 0 0 0 0 0 0 0 0 0
55575 - 0 0 0 0 0 0 0 0 0 0 0 0
55576 - 0 0 0 0 0 0 0 0 0 0 0 0
55577 - 0 0 0 0 0 0 0 0 0 0 0 0
55578 - 0 0 0 0 0 0 0 0 0 0 0 0
55579 - 0 0 0 0 0 0 0 0 0 0 0 0
55580 - 0 0 0 0 0 0 0 0 0 0 0 0
55581 - 0 0 0 0 0 0 0 0 0 0 0 0
55582 - 0 0 0 0 0 0 0 0 0 0 0 0
55583 - 0 0 0 6 6 6 10 10 10 14 14 14
55584 - 22 22 22 26 26 26 30 30 30 34 34 34
55585 - 30 30 30 30 30 30 26 26 26 18 18 18
55586 - 14 14 14 10 10 10 6 6 6 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 0 0 0 0 0 0 0 0 0 0 0 0
55591 - 0 0 0 0 0 0 0 0 0 0 0 0
55592 - 0 0 0 0 0 0 0 0 0 0 0 0
55593 - 0 0 0 0 0 0 0 0 0 0 0 0
55594 - 0 0 0 0 0 0 0 0 0 0 0 0
55595 - 0 0 0 0 0 0 0 0 0 0 0 0
55596 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
55604 - 54 54 54 66 66 66 78 78 78 78 78 78
55605 - 78 78 78 74 74 74 66 66 66 54 54 54
55606 - 42 42 42 26 26 26 18 18 18 10 10 10
55607 - 6 6 6 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 0 0 0 0 0 0 0 0 0
55610 - 0 0 0 0 0 0 0 0 0 0 0 0
55611 - 0 0 0 0 0 0 0 0 0 0 0 0
55612 - 0 0 0 0 0 0 0 0 0 0 0 0
55613 - 0 0 0 0 0 0 0 0 0 0 0 0
55614 - 0 0 0 0 0 0 0 0 0 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 1 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 10 10 10
55623 - 22 22 22 42 42 42 66 66 66 86 86 86
55624 - 66 66 66 38 38 38 38 38 38 22 22 22
55625 - 26 26 26 34 34 34 54 54 54 66 66 66
55626 - 86 86 86 70 70 70 46 46 46 26 26 26
55627 - 14 14 14 6 6 6 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 0 0 0 0 0 0 0 0 0 0 0 0
55630 - 0 0 0 0 0 0 0 0 0 0 0 0
55631 - 0 0 0 0 0 0 0 0 0 0 0 0
55632 - 0 0 0 0 0 0 0 0 0 0 0 0
55633 - 0 0 0 0 0 0 0 0 0 0 0 0
55634 - 0 0 0 0 0 0 0 0 0 0 0 0
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
55643 - 50 50 50 82 82 82 58 58 58 6 6 6
55644 - 2 2 6 2 2 6 2 2 6 2 2 6
55645 - 2 2 6 2 2 6 2 2 6 2 2 6
55646 - 6 6 6 54 54 54 86 86 86 66 66 66
55647 - 38 38 38 18 18 18 6 6 6 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 0 0 0
55649 - 0 0 0 0 0 0 0 0 0 0 0 0
55650 - 0 0 0 0 0 0 0 0 0 0 0 0
55651 - 0 0 0 0 0 0 0 0 0 0 0 0
55652 - 0 0 0 0 0 0 0 0 0 0 0 0
55653 - 0 0 0 0 0 0 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 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 6 6 6 22 22 22 50 50 50
55663 - 78 78 78 34 34 34 2 2 6 2 2 6
55664 - 2 2 6 2 2 6 2 2 6 2 2 6
55665 - 2 2 6 2 2 6 2 2 6 2 2 6
55666 - 2 2 6 2 2 6 6 6 6 70 70 70
55667 - 78 78 78 46 46 46 22 22 22 6 6 6
55668 - 0 0 0 0 0 0 0 0 0 0 0 0
55669 - 0 0 0 0 0 0 0 0 0 0 0 0
55670 - 0 0 0 0 0 0 0 0 0 0 0 0
55671 - 0 0 0 0 0 0 0 0 0 0 0 0
55672 - 0 0 0 0 0 0 0 0 0 0 0 0
55673 - 0 0 0 0 0 0 0 0 0 0 0 0
55674 - 0 0 0 0 0 0 0 0 0 0 0 0
55675 - 0 0 0 0 0 0 0 0 0 0 0 0
55676 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
55683 - 26 26 26 2 2 6 2 2 6 2 2 6
55684 - 2 2 6 2 2 6 2 2 6 2 2 6
55685 - 2 2 6 2 2 6 2 2 6 14 14 14
55686 - 46 46 46 34 34 34 6 6 6 2 2 6
55687 - 42 42 42 78 78 78 42 42 42 18 18 18
55688 - 6 6 6 0 0 0 0 0 0 0 0 0
55689 - 0 0 0 0 0 0 0 0 0 0 0 0
55690 - 0 0 0 0 0 0 0 0 0 0 0 0
55691 - 0 0 0 0 0 0 0 0 0 0 0 0
55692 - 0 0 0 0 0 0 0 0 0 0 0 0
55693 - 0 0 0 0 0 0 0 0 0 0 0 0
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 1 0 0 0 0 0 1 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 10 10 10 30 30 30 66 66 66 58 58 58
55703 - 2 2 6 2 2 6 2 2 6 2 2 6
55704 - 2 2 6 2 2 6 2 2 6 2 2 6
55705 - 2 2 6 2 2 6 2 2 6 26 26 26
55706 - 86 86 86 101 101 101 46 46 46 10 10 10
55707 - 2 2 6 58 58 58 70 70 70 34 34 34
55708 - 10 10 10 0 0 0 0 0 0 0 0 0
55709 - 0 0 0 0 0 0 0 0 0 0 0 0
55710 - 0 0 0 0 0 0 0 0 0 0 0 0
55711 - 0 0 0 0 0 0 0 0 0 0 0 0
55712 - 0 0 0 0 0 0 0 0 0 0 0 0
55713 - 0 0 0 0 0 0 0 0 0 0 0 0
55714 - 0 0 0 0 0 0 0 0 0 0 0 0
55715 - 0 0 0 0 0 0 0 0 0 0 0 0
55716 - 0 0 1 0 0 1 0 0 1 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 14 14 14 42 42 42 86 86 86 10 10 10
55723 - 2 2 6 2 2 6 2 2 6 2 2 6
55724 - 2 2 6 2 2 6 2 2 6 2 2 6
55725 - 2 2 6 2 2 6 2 2 6 30 30 30
55726 - 94 94 94 94 94 94 58 58 58 26 26 26
55727 - 2 2 6 6 6 6 78 78 78 54 54 54
55728 - 22 22 22 6 6 6 0 0 0 0 0 0
55729 - 0 0 0 0 0 0 0 0 0 0 0 0
55730 - 0 0 0 0 0 0 0 0 0 0 0 0
55731 - 0 0 0 0 0 0 0 0 0 0 0 0
55732 - 0 0 0 0 0 0 0 0 0 0 0 0
55733 - 0 0 0 0 0 0 0 0 0 0 0 0
55734 - 0 0 0 0 0 0 0 0 0 0 0 0
55735 - 0 0 0 0 0 0 0 0 0 0 0 0
55736 - 0 0 0 0 0 0 0 0 0 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 6 6 6
55742 - 22 22 22 62 62 62 62 62 62 2 2 6
55743 - 2 2 6 2 2 6 2 2 6 2 2 6
55744 - 2 2 6 2 2 6 2 2 6 2 2 6
55745 - 2 2 6 2 2 6 2 2 6 26 26 26
55746 - 54 54 54 38 38 38 18 18 18 10 10 10
55747 - 2 2 6 2 2 6 34 34 34 82 82 82
55748 - 38 38 38 14 14 14 0 0 0 0 0 0
55749 - 0 0 0 0 0 0 0 0 0 0 0 0
55750 - 0 0 0 0 0 0 0 0 0 0 0 0
55751 - 0 0 0 0 0 0 0 0 0 0 0 0
55752 - 0 0 0 0 0 0 0 0 0 0 0 0
55753 - 0 0 0 0 0 0 0 0 0 0 0 0
55754 - 0 0 0 0 0 0 0 0 0 0 0 0
55755 - 0 0 0 0 0 0 0 0 0 0 0 0
55756 - 0 0 0 0 0 1 0 0 1 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 6 6 6
55762 - 30 30 30 78 78 78 30 30 30 2 2 6
55763 - 2 2 6 2 2 6 2 2 6 2 2 6
55764 - 2 2 6 2 2 6 2 2 6 2 2 6
55765 - 2 2 6 2 2 6 2 2 6 10 10 10
55766 - 10 10 10 2 2 6 2 2 6 2 2 6
55767 - 2 2 6 2 2 6 2 2 6 78 78 78
55768 - 50 50 50 18 18 18 6 6 6 0 0 0
55769 - 0 0 0 0 0 0 0 0 0 0 0 0
55770 - 0 0 0 0 0 0 0 0 0 0 0 0
55771 - 0 0 0 0 0 0 0 0 0 0 0 0
55772 - 0 0 0 0 0 0 0 0 0 0 0 0
55773 - 0 0 0 0 0 0 0 0 0 0 0 0
55774 - 0 0 0 0 0 0 0 0 0 0 0 0
55775 - 0 0 0 0 0 0 0 0 0 0 0 0
55776 - 0 0 1 0 0 0 0 0 0 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 10 10 10
55782 - 38 38 38 86 86 86 14 14 14 2 2 6
55783 - 2 2 6 2 2 6 2 2 6 2 2 6
55784 - 2 2 6 2 2 6 2 2 6 2 2 6
55785 - 2 2 6 2 2 6 2 2 6 2 2 6
55786 - 2 2 6 2 2 6 2 2 6 2 2 6
55787 - 2 2 6 2 2 6 2 2 6 54 54 54
55788 - 66 66 66 26 26 26 6 6 6 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 0 0 0
55790 - 0 0 0 0 0 0 0 0 0 0 0 0
55791 - 0 0 0 0 0 0 0 0 0 0 0 0
55792 - 0 0 0 0 0 0 0 0 0 0 0 0
55793 - 0 0 0 0 0 0 0 0 0 0 0 0
55794 - 0 0 0 0 0 0 0 0 0 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 0 0 0 1 0 0 1 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 14 14 14
55802 - 42 42 42 82 82 82 2 2 6 2 2 6
55803 - 2 2 6 6 6 6 10 10 10 2 2 6
55804 - 2 2 6 2 2 6 2 2 6 2 2 6
55805 - 2 2 6 2 2 6 2 2 6 6 6 6
55806 - 14 14 14 10 10 10 2 2 6 2 2 6
55807 - 2 2 6 2 2 6 2 2 6 18 18 18
55808 - 82 82 82 34 34 34 10 10 10 0 0 0
55809 - 0 0 0 0 0 0 0 0 0 0 0 0
55810 - 0 0 0 0 0 0 0 0 0 0 0 0
55811 - 0 0 0 0 0 0 0 0 0 0 0 0
55812 - 0 0 0 0 0 0 0 0 0 0 0 0
55813 - 0 0 0 0 0 0 0 0 0 0 0 0
55814 - 0 0 0 0 0 0 0 0 0 0 0 0
55815 - 0 0 0 0 0 0 0 0 0 0 0 0
55816 - 0 0 1 0 0 0 0 0 0 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 14 14 14
55822 - 46 46 46 86 86 86 2 2 6 2 2 6
55823 - 6 6 6 6 6 6 22 22 22 34 34 34
55824 - 6 6 6 2 2 6 2 2 6 2 2 6
55825 - 2 2 6 2 2 6 18 18 18 34 34 34
55826 - 10 10 10 50 50 50 22 22 22 2 2 6
55827 - 2 2 6 2 2 6 2 2 6 10 10 10
55828 - 86 86 86 42 42 42 14 14 14 0 0 0
55829 - 0 0 0 0 0 0 0 0 0 0 0 0
55830 - 0 0 0 0 0 0 0 0 0 0 0 0
55831 - 0 0 0 0 0 0 0 0 0 0 0 0
55832 - 0 0 0 0 0 0 0 0 0 0 0 0
55833 - 0 0 0 0 0 0 0 0 0 0 0 0
55834 - 0 0 0 0 0 0 0 0 0 0 0 0
55835 - 0 0 0 0 0 0 0 0 0 0 0 0
55836 - 0 0 1 0 0 1 0 0 1 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 14 14 14
55842 - 46 46 46 86 86 86 2 2 6 2 2 6
55843 - 38 38 38 116 116 116 94 94 94 22 22 22
55844 - 22 22 22 2 2 6 2 2 6 2 2 6
55845 - 14 14 14 86 86 86 138 138 138 162 162 162
55846 -154 154 154 38 38 38 26 26 26 6 6 6
55847 - 2 2 6 2 2 6 2 2 6 2 2 6
55848 - 86 86 86 46 46 46 14 14 14 0 0 0
55849 - 0 0 0 0 0 0 0 0 0 0 0 0
55850 - 0 0 0 0 0 0 0 0 0 0 0 0
55851 - 0 0 0 0 0 0 0 0 0 0 0 0
55852 - 0 0 0 0 0 0 0 0 0 0 0 0
55853 - 0 0 0 0 0 0 0 0 0 0 0 0
55854 - 0 0 0 0 0 0 0 0 0 0 0 0
55855 - 0 0 0 0 0 0 0 0 0 0 0 0
55856 - 0 0 0 0 0 0 0 0 0 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 14 14 14
55862 - 46 46 46 86 86 86 2 2 6 14 14 14
55863 -134 134 134 198 198 198 195 195 195 116 116 116
55864 - 10 10 10 2 2 6 2 2 6 6 6 6
55865 -101 98 89 187 187 187 210 210 210 218 218 218
55866 -214 214 214 134 134 134 14 14 14 6 6 6
55867 - 2 2 6 2 2 6 2 2 6 2 2 6
55868 - 86 86 86 50 50 50 18 18 18 6 6 6
55869 - 0 0 0 0 0 0 0 0 0 0 0 0
55870 - 0 0 0 0 0 0 0 0 0 0 0 0
55871 - 0 0 0 0 0 0 0 0 0 0 0 0
55872 - 0 0 0 0 0 0 0 0 0 0 0 0
55873 - 0 0 0 0 0 0 0 0 0 0 0 0
55874 - 0 0 0 0 0 0 0 0 0 0 0 0
55875 - 0 0 0 0 0 0 0 0 1 0 0 0
55876 - 0 0 1 0 0 1 0 0 1 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 14 14 14
55882 - 46 46 46 86 86 86 2 2 6 54 54 54
55883 -218 218 218 195 195 195 226 226 226 246 246 246
55884 - 58 58 58 2 2 6 2 2 6 30 30 30
55885 -210 210 210 253 253 253 174 174 174 123 123 123
55886 -221 221 221 234 234 234 74 74 74 2 2 6
55887 - 2 2 6 2 2 6 2 2 6 2 2 6
55888 - 70 70 70 58 58 58 22 22 22 6 6 6
55889 - 0 0 0 0 0 0 0 0 0 0 0 0
55890 - 0 0 0 0 0 0 0 0 0 0 0 0
55891 - 0 0 0 0 0 0 0 0 0 0 0 0
55892 - 0 0 0 0 0 0 0 0 0 0 0 0
55893 - 0 0 0 0 0 0 0 0 0 0 0 0
55894 - 0 0 0 0 0 0 0 0 0 0 0 0
55895 - 0 0 0 0 0 0 0 0 0 0 0 0
55896 - 0 0 0 0 0 0 0 0 0 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 0 14 14 14
55902 - 46 46 46 82 82 82 2 2 6 106 106 106
55903 -170 170 170 26 26 26 86 86 86 226 226 226
55904 -123 123 123 10 10 10 14 14 14 46 46 46
55905 -231 231 231 190 190 190 6 6 6 70 70 70
55906 - 90 90 90 238 238 238 158 158 158 2 2 6
55907 - 2 2 6 2 2 6 2 2 6 2 2 6
55908 - 70 70 70 58 58 58 22 22 22 6 6 6
55909 - 0 0 0 0 0 0 0 0 0 0 0 0
55910 - 0 0 0 0 0 0 0 0 0 0 0 0
55911 - 0 0 0 0 0 0 0 0 0 0 0 0
55912 - 0 0 0 0 0 0 0 0 0 0 0 0
55913 - 0 0 0 0 0 0 0 0 0 0 0 0
55914 - 0 0 0 0 0 0 0 0 0 0 0 0
55915 - 0 0 0 0 0 0 0 0 1 0 0 0
55916 - 0 0 1 0 0 1 0 0 1 0 0 0
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 0 0 0 0 0 0 0 0 0
55921 - 0 0 0 0 0 0 0 0 0 14 14 14
55922 - 42 42 42 86 86 86 6 6 6 116 116 116
55923 -106 106 106 6 6 6 70 70 70 149 149 149
55924 -128 128 128 18 18 18 38 38 38 54 54 54
55925 -221 221 221 106 106 106 2 2 6 14 14 14
55926 - 46 46 46 190 190 190 198 198 198 2 2 6
55927 - 2 2 6 2 2 6 2 2 6 2 2 6
55928 - 74 74 74 62 62 62 22 22 22 6 6 6
55929 - 0 0 0 0 0 0 0 0 0 0 0 0
55930 - 0 0 0 0 0 0 0 0 0 0 0 0
55931 - 0 0 0 0 0 0 0 0 0 0 0 0
55932 - 0 0 0 0 0 0 0 0 0 0 0 0
55933 - 0 0 0 0 0 0 0 0 0 0 0 0
55934 - 0 0 0 0 0 0 0 0 0 0 0 0
55935 - 0 0 0 0 0 0 0 0 1 0 0 0
55936 - 0 0 1 0 0 0 0 0 1 0 0 0
55937 - 0 0 0 0 0 0 0 0 0 0 0 0
55938 - 0 0 0 0 0 0 0 0 0 0 0 0
55939 - 0 0 0 0 0 0 0 0 0 0 0 0
55940 - 0 0 0 0 0 0 0 0 0 0 0 0
55941 - 0 0 0 0 0 0 0 0 0 14 14 14
55942 - 42 42 42 94 94 94 14 14 14 101 101 101
55943 -128 128 128 2 2 6 18 18 18 116 116 116
55944 -118 98 46 121 92 8 121 92 8 98 78 10
55945 -162 162 162 106 106 106 2 2 6 2 2 6
55946 - 2 2 6 195 195 195 195 195 195 6 6 6
55947 - 2 2 6 2 2 6 2 2 6 2 2 6
55948 - 74 74 74 62 62 62 22 22 22 6 6 6
55949 - 0 0 0 0 0 0 0 0 0 0 0 0
55950 - 0 0 0 0 0 0 0 0 0 0 0 0
55951 - 0 0 0 0 0 0 0 0 0 0 0 0
55952 - 0 0 0 0 0 0 0 0 0 0 0 0
55953 - 0 0 0 0 0 0 0 0 0 0 0 0
55954 - 0 0 0 0 0 0 0 0 0 0 0 0
55955 - 0 0 0 0 0 0 0 0 1 0 0 1
55956 - 0 0 1 0 0 0 0 0 1 0 0 0
55957 - 0 0 0 0 0 0 0 0 0 0 0 0
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 10 10 10
55962 - 38 38 38 90 90 90 14 14 14 58 58 58
55963 -210 210 210 26 26 26 54 38 6 154 114 10
55964 -226 170 11 236 186 11 225 175 15 184 144 12
55965 -215 174 15 175 146 61 37 26 9 2 2 6
55966 - 70 70 70 246 246 246 138 138 138 2 2 6
55967 - 2 2 6 2 2 6 2 2 6 2 2 6
55968 - 70 70 70 66 66 66 26 26 26 6 6 6
55969 - 0 0 0 0 0 0 0 0 0 0 0 0
55970 - 0 0 0 0 0 0 0 0 0 0 0 0
55971 - 0 0 0 0 0 0 0 0 0 0 0 0
55972 - 0 0 0 0 0 0 0 0 0 0 0 0
55973 - 0 0 0 0 0 0 0 0 0 0 0 0
55974 - 0 0 0 0 0 0 0 0 0 0 0 0
55975 - 0 0 0 0 0 0 0 0 0 0 0 0
55976 - 0 0 0 0 0 0 0 0 0 0 0 0
55977 - 0 0 0 0 0 0 0 0 0 0 0 0
55978 - 0 0 0 0 0 0 0 0 0 0 0 0
55979 - 0 0 0 0 0 0 0 0 0 0 0 0
55980 - 0 0 0 0 0 0 0 0 0 0 0 0
55981 - 0 0 0 0 0 0 0 0 0 10 10 10
55982 - 38 38 38 86 86 86 14 14 14 10 10 10
55983 -195 195 195 188 164 115 192 133 9 225 175 15
55984 -239 182 13 234 190 10 232 195 16 232 200 30
55985 -245 207 45 241 208 19 232 195 16 184 144 12
55986 -218 194 134 211 206 186 42 42 42 2 2 6
55987 - 2 2 6 2 2 6 2 2 6 2 2 6
55988 - 50 50 50 74 74 74 30 30 30 6 6 6
55989 - 0 0 0 0 0 0 0 0 0 0 0 0
55990 - 0 0 0 0 0 0 0 0 0 0 0 0
55991 - 0 0 0 0 0 0 0 0 0 0 0 0
55992 - 0 0 0 0 0 0 0 0 0 0 0 0
55993 - 0 0 0 0 0 0 0 0 0 0 0 0
55994 - 0 0 0 0 0 0 0 0 0 0 0 0
55995 - 0 0 0 0 0 0 0 0 0 0 0 0
55996 - 0 0 0 0 0 0 0 0 0 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 10 10 10
56002 - 34 34 34 86 86 86 14 14 14 2 2 6
56003 -121 87 25 192 133 9 219 162 10 239 182 13
56004 -236 186 11 232 195 16 241 208 19 244 214 54
56005 -246 218 60 246 218 38 246 215 20 241 208 19
56006 -241 208 19 226 184 13 121 87 25 2 2 6
56007 - 2 2 6 2 2 6 2 2 6 2 2 6
56008 - 50 50 50 82 82 82 34 34 34 10 10 10
56009 - 0 0 0 0 0 0 0 0 0 0 0 0
56010 - 0 0 0 0 0 0 0 0 0 0 0 0
56011 - 0 0 0 0 0 0 0 0 0 0 0 0
56012 - 0 0 0 0 0 0 0 0 0 0 0 0
56013 - 0 0 0 0 0 0 0 0 0 0 0 0
56014 - 0 0 0 0 0 0 0 0 0 0 0 0
56015 - 0 0 0 0 0 0 0 0 0 0 0 0
56016 - 0 0 0 0 0 0 0 0 0 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 10 10 10
56022 - 34 34 34 82 82 82 30 30 30 61 42 6
56023 -180 123 7 206 145 10 230 174 11 239 182 13
56024 -234 190 10 238 202 15 241 208 19 246 218 74
56025 -246 218 38 246 215 20 246 215 20 246 215 20
56026 -226 184 13 215 174 15 184 144 12 6 6 6
56027 - 2 2 6 2 2 6 2 2 6 2 2 6
56028 - 26 26 26 94 94 94 42 42 42 14 14 14
56029 - 0 0 0 0 0 0 0 0 0 0 0 0
56030 - 0 0 0 0 0 0 0 0 0 0 0 0
56031 - 0 0 0 0 0 0 0 0 0 0 0 0
56032 - 0 0 0 0 0 0 0 0 0 0 0 0
56033 - 0 0 0 0 0 0 0 0 0 0 0 0
56034 - 0 0 0 0 0 0 0 0 0 0 0 0
56035 - 0 0 0 0 0 0 0 0 0 0 0 0
56036 - 0 0 0 0 0 0 0 0 0 0 0 0
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 0 0 0 0 0 0 0 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 10 10 10
56042 - 30 30 30 78 78 78 50 50 50 104 69 6
56043 -192 133 9 216 158 10 236 178 12 236 186 11
56044 -232 195 16 241 208 19 244 214 54 245 215 43
56045 -246 215 20 246 215 20 241 208 19 198 155 10
56046 -200 144 11 216 158 10 156 118 10 2 2 6
56047 - 2 2 6 2 2 6 2 2 6 2 2 6
56048 - 6 6 6 90 90 90 54 54 54 18 18 18
56049 - 6 6 6 0 0 0 0 0 0 0 0 0
56050 - 0 0 0 0 0 0 0 0 0 0 0 0
56051 - 0 0 0 0 0 0 0 0 0 0 0 0
56052 - 0 0 0 0 0 0 0 0 0 0 0 0
56053 - 0 0 0 0 0 0 0 0 0 0 0 0
56054 - 0 0 0 0 0 0 0 0 0 0 0 0
56055 - 0 0 0 0 0 0 0 0 0 0 0 0
56056 - 0 0 0 0 0 0 0 0 0 0 0 0
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 10 10 10
56062 - 30 30 30 78 78 78 46 46 46 22 22 22
56063 -137 92 6 210 162 10 239 182 13 238 190 10
56064 -238 202 15 241 208 19 246 215 20 246 215 20
56065 -241 208 19 203 166 17 185 133 11 210 150 10
56066 -216 158 10 210 150 10 102 78 10 2 2 6
56067 - 6 6 6 54 54 54 14 14 14 2 2 6
56068 - 2 2 6 62 62 62 74 74 74 30 30 30
56069 - 10 10 10 0 0 0 0 0 0 0 0 0
56070 - 0 0 0 0 0 0 0 0 0 0 0 0
56071 - 0 0 0 0 0 0 0 0 0 0 0 0
56072 - 0 0 0 0 0 0 0 0 0 0 0 0
56073 - 0 0 0 0 0 0 0 0 0 0 0 0
56074 - 0 0 0 0 0 0 0 0 0 0 0 0
56075 - 0 0 0 0 0 0 0 0 0 0 0 0
56076 - 0 0 0 0 0 0 0 0 0 0 0 0
56077 - 0 0 0 0 0 0 0 0 0 0 0 0
56078 - 0 0 0 0 0 0 0 0 0 0 0 0
56079 - 0 0 0 0 0 0 0 0 0 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 10 10 10
56082 - 34 34 34 78 78 78 50 50 50 6 6 6
56083 - 94 70 30 139 102 15 190 146 13 226 184 13
56084 -232 200 30 232 195 16 215 174 15 190 146 13
56085 -168 122 10 192 133 9 210 150 10 213 154 11
56086 -202 150 34 182 157 106 101 98 89 2 2 6
56087 - 2 2 6 78 78 78 116 116 116 58 58 58
56088 - 2 2 6 22 22 22 90 90 90 46 46 46
56089 - 18 18 18 6 6 6 0 0 0 0 0 0
56090 - 0 0 0 0 0 0 0 0 0 0 0 0
56091 - 0 0 0 0 0 0 0 0 0 0 0 0
56092 - 0 0 0 0 0 0 0 0 0 0 0 0
56093 - 0 0 0 0 0 0 0 0 0 0 0 0
56094 - 0 0 0 0 0 0 0 0 0 0 0 0
56095 - 0 0 0 0 0 0 0 0 0 0 0 0
56096 - 0 0 0 0 0 0 0 0 0 0 0 0
56097 - 0 0 0 0 0 0 0 0 0 0 0 0
56098 - 0 0 0 0 0 0 0 0 0 0 0 0
56099 - 0 0 0 0 0 0 0 0 0 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 10 10 10
56102 - 38 38 38 86 86 86 50 50 50 6 6 6
56103 -128 128 128 174 154 114 156 107 11 168 122 10
56104 -198 155 10 184 144 12 197 138 11 200 144 11
56105 -206 145 10 206 145 10 197 138 11 188 164 115
56106 -195 195 195 198 198 198 174 174 174 14 14 14
56107 - 2 2 6 22 22 22 116 116 116 116 116 116
56108 - 22 22 22 2 2 6 74 74 74 70 70 70
56109 - 30 30 30 10 10 10 0 0 0 0 0 0
56110 - 0 0 0 0 0 0 0 0 0 0 0 0
56111 - 0 0 0 0 0 0 0 0 0 0 0 0
56112 - 0 0 0 0 0 0 0 0 0 0 0 0
56113 - 0 0 0 0 0 0 0 0 0 0 0 0
56114 - 0 0 0 0 0 0 0 0 0 0 0 0
56115 - 0 0 0 0 0 0 0 0 0 0 0 0
56116 - 0 0 0 0 0 0 0 0 0 0 0 0
56117 - 0 0 0 0 0 0 0 0 0 0 0 0
56118 - 0 0 0 0 0 0 0 0 0 0 0 0
56119 - 0 0 0 0 0 0 0 0 0 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 6 6 6 18 18 18
56122 - 50 50 50 101 101 101 26 26 26 10 10 10
56123 -138 138 138 190 190 190 174 154 114 156 107 11
56124 -197 138 11 200 144 11 197 138 11 192 133 9
56125 -180 123 7 190 142 34 190 178 144 187 187 187
56126 -202 202 202 221 221 221 214 214 214 66 66 66
56127 - 2 2 6 2 2 6 50 50 50 62 62 62
56128 - 6 6 6 2 2 6 10 10 10 90 90 90
56129 - 50 50 50 18 18 18 6 6 6 0 0 0
56130 - 0 0 0 0 0 0 0 0 0 0 0 0
56131 - 0 0 0 0 0 0 0 0 0 0 0 0
56132 - 0 0 0 0 0 0 0 0 0 0 0 0
56133 - 0 0 0 0 0 0 0 0 0 0 0 0
56134 - 0 0 0 0 0 0 0 0 0 0 0 0
56135 - 0 0 0 0 0 0 0 0 0 0 0 0
56136 - 0 0 0 0 0 0 0 0 0 0 0 0
56137 - 0 0 0 0 0 0 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 10 10 10 34 34 34
56142 - 74 74 74 74 74 74 2 2 6 6 6 6
56143 -144 144 144 198 198 198 190 190 190 178 166 146
56144 -154 121 60 156 107 11 156 107 11 168 124 44
56145 -174 154 114 187 187 187 190 190 190 210 210 210
56146 -246 246 246 253 253 253 253 253 253 182 182 182
56147 - 6 6 6 2 2 6 2 2 6 2 2 6
56148 - 2 2 6 2 2 6 2 2 6 62 62 62
56149 - 74 74 74 34 34 34 14 14 14 0 0 0
56150 - 0 0 0 0 0 0 0 0 0 0 0 0
56151 - 0 0 0 0 0 0 0 0 0 0 0 0
56152 - 0 0 0 0 0 0 0 0 0 0 0 0
56153 - 0 0 0 0 0 0 0 0 0 0 0 0
56154 - 0 0 0 0 0 0 0 0 0 0 0 0
56155 - 0 0 0 0 0 0 0 0 0 0 0 0
56156 - 0 0 0 0 0 0 0 0 0 0 0 0
56157 - 0 0 0 0 0 0 0 0 0 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 10 10 10 22 22 22 54 54 54
56162 - 94 94 94 18 18 18 2 2 6 46 46 46
56163 -234 234 234 221 221 221 190 190 190 190 190 190
56164 -190 190 190 187 187 187 187 187 187 190 190 190
56165 -190 190 190 195 195 195 214 214 214 242 242 242
56166 -253 253 253 253 253 253 253 253 253 253 253 253
56167 - 82 82 82 2 2 6 2 2 6 2 2 6
56168 - 2 2 6 2 2 6 2 2 6 14 14 14
56169 - 86 86 86 54 54 54 22 22 22 6 6 6
56170 - 0 0 0 0 0 0 0 0 0 0 0 0
56171 - 0 0 0 0 0 0 0 0 0 0 0 0
56172 - 0 0 0 0 0 0 0 0 0 0 0 0
56173 - 0 0 0 0 0 0 0 0 0 0 0 0
56174 - 0 0 0 0 0 0 0 0 0 0 0 0
56175 - 0 0 0 0 0 0 0 0 0 0 0 0
56176 - 0 0 0 0 0 0 0 0 0 0 0 0
56177 - 0 0 0 0 0 0 0 0 0 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 6 6 6 18 18 18 46 46 46 90 90 90
56182 - 46 46 46 18 18 18 6 6 6 182 182 182
56183 -253 253 253 246 246 246 206 206 206 190 190 190
56184 -190 190 190 190 190 190 190 190 190 190 190 190
56185 -206 206 206 231 231 231 250 250 250 253 253 253
56186 -253 253 253 253 253 253 253 253 253 253 253 253
56187 -202 202 202 14 14 14 2 2 6 2 2 6
56188 - 2 2 6 2 2 6 2 2 6 2 2 6
56189 - 42 42 42 86 86 86 42 42 42 18 18 18
56190 - 6 6 6 0 0 0 0 0 0 0 0 0
56191 - 0 0 0 0 0 0 0 0 0 0 0 0
56192 - 0 0 0 0 0 0 0 0 0 0 0 0
56193 - 0 0 0 0 0 0 0 0 0 0 0 0
56194 - 0 0 0 0 0 0 0 0 0 0 0 0
56195 - 0 0 0 0 0 0 0 0 0 0 0 0
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 6 6 6
56201 - 14 14 14 38 38 38 74 74 74 66 66 66
56202 - 2 2 6 6 6 6 90 90 90 250 250 250
56203 -253 253 253 253 253 253 238 238 238 198 198 198
56204 -190 190 190 190 190 190 195 195 195 221 221 221
56205 -246 246 246 253 253 253 253 253 253 253 253 253
56206 -253 253 253 253 253 253 253 253 253 253 253 253
56207 -253 253 253 82 82 82 2 2 6 2 2 6
56208 - 2 2 6 2 2 6 2 2 6 2 2 6
56209 - 2 2 6 78 78 78 70 70 70 34 34 34
56210 - 14 14 14 6 6 6 0 0 0 0 0 0
56211 - 0 0 0 0 0 0 0 0 0 0 0 0
56212 - 0 0 0 0 0 0 0 0 0 0 0 0
56213 - 0 0 0 0 0 0 0 0 0 0 0 0
56214 - 0 0 0 0 0 0 0 0 0 0 0 0
56215 - 0 0 0 0 0 0 0 0 0 0 0 0
56216 - 0 0 0 0 0 0 0 0 0 0 0 0
56217 - 0 0 0 0 0 0 0 0 0 0 0 0
56218 - 0 0 0 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 14 14 14
56221 - 34 34 34 66 66 66 78 78 78 6 6 6
56222 - 2 2 6 18 18 18 218 218 218 253 253 253
56223 -253 253 253 253 253 253 253 253 253 246 246 246
56224 -226 226 226 231 231 231 246 246 246 253 253 253
56225 -253 253 253 253 253 253 253 253 253 253 253 253
56226 -253 253 253 253 253 253 253 253 253 253 253 253
56227 -253 253 253 178 178 178 2 2 6 2 2 6
56228 - 2 2 6 2 2 6 2 2 6 2 2 6
56229 - 2 2 6 18 18 18 90 90 90 62 62 62
56230 - 30 30 30 10 10 10 0 0 0 0 0 0
56231 - 0 0 0 0 0 0 0 0 0 0 0 0
56232 - 0 0 0 0 0 0 0 0 0 0 0 0
56233 - 0 0 0 0 0 0 0 0 0 0 0 0
56234 - 0 0 0 0 0 0 0 0 0 0 0 0
56235 - 0 0 0 0 0 0 0 0 0 0 0 0
56236 - 0 0 0 0 0 0 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 10 10 10 26 26 26
56241 - 58 58 58 90 90 90 18 18 18 2 2 6
56242 - 2 2 6 110 110 110 253 253 253 253 253 253
56243 -253 253 253 253 253 253 253 253 253 253 253 253
56244 -250 250 250 253 253 253 253 253 253 253 253 253
56245 -253 253 253 253 253 253 253 253 253 253 253 253
56246 -253 253 253 253 253 253 253 253 253 253 253 253
56247 -253 253 253 231 231 231 18 18 18 2 2 6
56248 - 2 2 6 2 2 6 2 2 6 2 2 6
56249 - 2 2 6 2 2 6 18 18 18 94 94 94
56250 - 54 54 54 26 26 26 10 10 10 0 0 0
56251 - 0 0 0 0 0 0 0 0 0 0 0 0
56252 - 0 0 0 0 0 0 0 0 0 0 0 0
56253 - 0 0 0 0 0 0 0 0 0 0 0 0
56254 - 0 0 0 0 0 0 0 0 0 0 0 0
56255 - 0 0 0 0 0 0 0 0 0 0 0 0
56256 - 0 0 0 0 0 0 0 0 0 0 0 0
56257 - 0 0 0 0 0 0 0 0 0 0 0 0
56258 - 0 0 0 0 0 0 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 6 6 6 22 22 22 50 50 50
56261 - 90 90 90 26 26 26 2 2 6 2 2 6
56262 - 14 14 14 195 195 195 250 250 250 253 253 253
56263 -253 253 253 253 253 253 253 253 253 253 253 253
56264 -253 253 253 253 253 253 253 253 253 253 253 253
56265 -253 253 253 253 253 253 253 253 253 253 253 253
56266 -253 253 253 253 253 253 253 253 253 253 253 253
56267 -250 250 250 242 242 242 54 54 54 2 2 6
56268 - 2 2 6 2 2 6 2 2 6 2 2 6
56269 - 2 2 6 2 2 6 2 2 6 38 38 38
56270 - 86 86 86 50 50 50 22 22 22 6 6 6
56271 - 0 0 0 0 0 0 0 0 0 0 0 0
56272 - 0 0 0 0 0 0 0 0 0 0 0 0
56273 - 0 0 0 0 0 0 0 0 0 0 0 0
56274 - 0 0 0 0 0 0 0 0 0 0 0 0
56275 - 0 0 0 0 0 0 0 0 0 0 0 0
56276 - 0 0 0 0 0 0 0 0 0 0 0 0
56277 - 0 0 0 0 0 0 0 0 0 0 0 0
56278 - 0 0 0 0 0 0 0 0 0 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 6 6 6 14 14 14 38 38 38 82 82 82
56281 - 34 34 34 2 2 6 2 2 6 2 2 6
56282 - 42 42 42 195 195 195 246 246 246 253 253 253
56283 -253 253 253 253 253 253 253 253 253 250 250 250
56284 -242 242 242 242 242 242 250 250 250 253 253 253
56285 -253 253 253 253 253 253 253 253 253 253 253 253
56286 -253 253 253 250 250 250 246 246 246 238 238 238
56287 -226 226 226 231 231 231 101 101 101 6 6 6
56288 - 2 2 6 2 2 6 2 2 6 2 2 6
56289 - 2 2 6 2 2 6 2 2 6 2 2 6
56290 - 38 38 38 82 82 82 42 42 42 14 14 14
56291 - 6 6 6 0 0 0 0 0 0 0 0 0
56292 - 0 0 0 0 0 0 0 0 0 0 0 0
56293 - 0 0 0 0 0 0 0 0 0 0 0 0
56294 - 0 0 0 0 0 0 0 0 0 0 0 0
56295 - 0 0 0 0 0 0 0 0 0 0 0 0
56296 - 0 0 0 0 0 0 0 0 0 0 0 0
56297 - 0 0 0 0 0 0 0 0 0 0 0 0
56298 - 0 0 0 0 0 0 0 0 0 0 0 0
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 10 10 10 26 26 26 62 62 62 66 66 66
56301 - 2 2 6 2 2 6 2 2 6 6 6 6
56302 - 70 70 70 170 170 170 206 206 206 234 234 234
56303 -246 246 246 250 250 250 250 250 250 238 238 238
56304 -226 226 226 231 231 231 238 238 238 250 250 250
56305 -250 250 250 250 250 250 246 246 246 231 231 231
56306 -214 214 214 206 206 206 202 202 202 202 202 202
56307 -198 198 198 202 202 202 182 182 182 18 18 18
56308 - 2 2 6 2 2 6 2 2 6 2 2 6
56309 - 2 2 6 2 2 6 2 2 6 2 2 6
56310 - 2 2 6 62 62 62 66 66 66 30 30 30
56311 - 10 10 10 0 0 0 0 0 0 0 0 0
56312 - 0 0 0 0 0 0 0 0 0 0 0 0
56313 - 0 0 0 0 0 0 0 0 0 0 0 0
56314 - 0 0 0 0 0 0 0 0 0 0 0 0
56315 - 0 0 0 0 0 0 0 0 0 0 0 0
56316 - 0 0 0 0 0 0 0 0 0 0 0 0
56317 - 0 0 0 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 0 0 0
56319 - 0 0 0 0 0 0 0 0 0 0 0 0
56320 - 14 14 14 42 42 42 82 82 82 18 18 18
56321 - 2 2 6 2 2 6 2 2 6 10 10 10
56322 - 94 94 94 182 182 182 218 218 218 242 242 242
56323 -250 250 250 253 253 253 253 253 253 250 250 250
56324 -234 234 234 253 253 253 253 253 253 253 253 253
56325 -253 253 253 253 253 253 253 253 253 246 246 246
56326 -238 238 238 226 226 226 210 210 210 202 202 202
56327 -195 195 195 195 195 195 210 210 210 158 158 158
56328 - 6 6 6 14 14 14 50 50 50 14 14 14
56329 - 2 2 6 2 2 6 2 2 6 2 2 6
56330 - 2 2 6 6 6 6 86 86 86 46 46 46
56331 - 18 18 18 6 6 6 0 0 0 0 0 0
56332 - 0 0 0 0 0 0 0 0 0 0 0 0
56333 - 0 0 0 0 0 0 0 0 0 0 0 0
56334 - 0 0 0 0 0 0 0 0 0 0 0 0
56335 - 0 0 0 0 0 0 0 0 0 0 0 0
56336 - 0 0 0 0 0 0 0 0 0 0 0 0
56337 - 0 0 0 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 0 0 0
56339 - 0 0 0 0 0 0 0 0 0 6 6 6
56340 - 22 22 22 54 54 54 70 70 70 2 2 6
56341 - 2 2 6 10 10 10 2 2 6 22 22 22
56342 -166 166 166 231 231 231 250 250 250 253 253 253
56343 -253 253 253 253 253 253 253 253 253 250 250 250
56344 -242 242 242 253 253 253 253 253 253 253 253 253
56345 -253 253 253 253 253 253 253 253 253 253 253 253
56346 -253 253 253 253 253 253 253 253 253 246 246 246
56347 -231 231 231 206 206 206 198 198 198 226 226 226
56348 - 94 94 94 2 2 6 6 6 6 38 38 38
56349 - 30 30 30 2 2 6 2 2 6 2 2 6
56350 - 2 2 6 2 2 6 62 62 62 66 66 66
56351 - 26 26 26 10 10 10 0 0 0 0 0 0
56352 - 0 0 0 0 0 0 0 0 0 0 0 0
56353 - 0 0 0 0 0 0 0 0 0 0 0 0
56354 - 0 0 0 0 0 0 0 0 0 0 0 0
56355 - 0 0 0 0 0 0 0 0 0 0 0 0
56356 - 0 0 0 0 0 0 0 0 0 0 0 0
56357 - 0 0 0 0 0 0 0 0 0 0 0 0
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 10 10 10
56360 - 30 30 30 74 74 74 50 50 50 2 2 6
56361 - 26 26 26 26 26 26 2 2 6 106 106 106
56362 -238 238 238 253 253 253 253 253 253 253 253 253
56363 -253 253 253 253 253 253 253 253 253 253 253 253
56364 -253 253 253 253 253 253 253 253 253 253 253 253
56365 -253 253 253 253 253 253 253 253 253 253 253 253
56366 -253 253 253 253 253 253 253 253 253 253 253 253
56367 -253 253 253 246 246 246 218 218 218 202 202 202
56368 -210 210 210 14 14 14 2 2 6 2 2 6
56369 - 30 30 30 22 22 22 2 2 6 2 2 6
56370 - 2 2 6 2 2 6 18 18 18 86 86 86
56371 - 42 42 42 14 14 14 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 0 0 0 0 0 0 0 0 0
56376 - 0 0 0 0 0 0 0 0 0 0 0 0
56377 - 0 0 0 0 0 0 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 14 14 14
56380 - 42 42 42 90 90 90 22 22 22 2 2 6
56381 - 42 42 42 2 2 6 18 18 18 218 218 218
56382 -253 253 253 253 253 253 253 253 253 253 253 253
56383 -253 253 253 253 253 253 253 253 253 253 253 253
56384 -253 253 253 253 253 253 253 253 253 253 253 253
56385 -253 253 253 253 253 253 253 253 253 253 253 253
56386 -253 253 253 253 253 253 253 253 253 253 253 253
56387 -253 253 253 253 253 253 250 250 250 221 221 221
56388 -218 218 218 101 101 101 2 2 6 14 14 14
56389 - 18 18 18 38 38 38 10 10 10 2 2 6
56390 - 2 2 6 2 2 6 2 2 6 78 78 78
56391 - 58 58 58 22 22 22 6 6 6 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 0 0 0 0 0 0 0 0 0 0 0 0
56396 - 0 0 0 0 0 0 0 0 0 0 0 0
56397 - 0 0 0 0 0 0 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 0 0 0
56399 - 0 0 0 0 0 0 6 6 6 18 18 18
56400 - 54 54 54 82 82 82 2 2 6 26 26 26
56401 - 22 22 22 2 2 6 123 123 123 253 253 253
56402 -253 253 253 253 253 253 253 253 253 253 253 253
56403 -253 253 253 253 253 253 253 253 253 253 253 253
56404 -253 253 253 253 253 253 253 253 253 253 253 253
56405 -253 253 253 253 253 253 253 253 253 253 253 253
56406 -253 253 253 253 253 253 253 253 253 253 253 253
56407 -253 253 253 253 253 253 253 253 253 250 250 250
56408 -238 238 238 198 198 198 6 6 6 38 38 38
56409 - 58 58 58 26 26 26 38 38 38 2 2 6
56410 - 2 2 6 2 2 6 2 2 6 46 46 46
56411 - 78 78 78 30 30 30 10 10 10 0 0 0
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 0 0 0
56415 - 0 0 0 0 0 0 0 0 0 0 0 0
56416 - 0 0 0 0 0 0 0 0 0 0 0 0
56417 - 0 0 0 0 0 0 0 0 0 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 10 10 10 30 30 30
56420 - 74 74 74 58 58 58 2 2 6 42 42 42
56421 - 2 2 6 22 22 22 231 231 231 253 253 253
56422 -253 253 253 253 253 253 253 253 253 253 253 253
56423 -253 253 253 253 253 253 253 253 253 250 250 250
56424 -253 253 253 253 253 253 253 253 253 253 253 253
56425 -253 253 253 253 253 253 253 253 253 253 253 253
56426 -253 253 253 253 253 253 253 253 253 253 253 253
56427 -253 253 253 253 253 253 253 253 253 253 253 253
56428 -253 253 253 246 246 246 46 46 46 38 38 38
56429 - 42 42 42 14 14 14 38 38 38 14 14 14
56430 - 2 2 6 2 2 6 2 2 6 6 6 6
56431 - 86 86 86 46 46 46 14 14 14 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 6 6 6 14 14 14 42 42 42
56440 - 90 90 90 18 18 18 18 18 18 26 26 26
56441 - 2 2 6 116 116 116 253 253 253 253 253 253
56442 -253 253 253 253 253 253 253 253 253 253 253 253
56443 -253 253 253 253 253 253 250 250 250 238 238 238
56444 -253 253 253 253 253 253 253 253 253 253 253 253
56445 -253 253 253 253 253 253 253 253 253 253 253 253
56446 -253 253 253 253 253 253 253 253 253 253 253 253
56447 -253 253 253 253 253 253 253 253 253 253 253 253
56448 -253 253 253 253 253 253 94 94 94 6 6 6
56449 - 2 2 6 2 2 6 10 10 10 34 34 34
56450 - 2 2 6 2 2 6 2 2 6 2 2 6
56451 - 74 74 74 58 58 58 22 22 22 6 6 6
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 10 10 10 26 26 26 66 66 66
56460 - 82 82 82 2 2 6 38 38 38 6 6 6
56461 - 14 14 14 210 210 210 253 253 253 253 253 253
56462 -253 253 253 253 253 253 253 253 253 253 253 253
56463 -253 253 253 253 253 253 246 246 246 242 242 242
56464 -253 253 253 253 253 253 253 253 253 253 253 253
56465 -253 253 253 253 253 253 253 253 253 253 253 253
56466 -253 253 253 253 253 253 253 253 253 253 253 253
56467 -253 253 253 253 253 253 253 253 253 253 253 253
56468 -253 253 253 253 253 253 144 144 144 2 2 6
56469 - 2 2 6 2 2 6 2 2 6 46 46 46
56470 - 2 2 6 2 2 6 2 2 6 2 2 6
56471 - 42 42 42 74 74 74 30 30 30 10 10 10
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 6 6 6 14 14 14 42 42 42 90 90 90
56480 - 26 26 26 6 6 6 42 42 42 2 2 6
56481 - 74 74 74 250 250 250 253 253 253 253 253 253
56482 -253 253 253 253 253 253 253 253 253 253 253 253
56483 -253 253 253 253 253 253 242 242 242 242 242 242
56484 -253 253 253 253 253 253 253 253 253 253 253 253
56485 -253 253 253 253 253 253 253 253 253 253 253 253
56486 -253 253 253 253 253 253 253 253 253 253 253 253
56487 -253 253 253 253 253 253 253 253 253 253 253 253
56488 -253 253 253 253 253 253 182 182 182 2 2 6
56489 - 2 2 6 2 2 6 2 2 6 46 46 46
56490 - 2 2 6 2 2 6 2 2 6 2 2 6
56491 - 10 10 10 86 86 86 38 38 38 10 10 10
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 0 0 0 0 0 0 0 0 0
56497 - 0 0 0 0 0 0 0 0 0 0 0 0
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 10 10 10 26 26 26 66 66 66 82 82 82
56500 - 2 2 6 22 22 22 18 18 18 2 2 6
56501 -149 149 149 253 253 253 253 253 253 253 253 253
56502 -253 253 253 253 253 253 253 253 253 253 253 253
56503 -253 253 253 253 253 253 234 234 234 242 242 242
56504 -253 253 253 253 253 253 253 253 253 253 253 253
56505 -253 253 253 253 253 253 253 253 253 253 253 253
56506 -253 253 253 253 253 253 253 253 253 253 253 253
56507 -253 253 253 253 253 253 253 253 253 253 253 253
56508 -253 253 253 253 253 253 206 206 206 2 2 6
56509 - 2 2 6 2 2 6 2 2 6 38 38 38
56510 - 2 2 6 2 2 6 2 2 6 2 2 6
56511 - 6 6 6 86 86 86 46 46 46 14 14 14
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 0 0 0 0 0 0 0 0 0 0 0 0
56517 - 0 0 0 0 0 0 0 0 0 0 0 0
56518 - 0 0 0 0 0 0 0 0 0 6 6 6
56519 - 18 18 18 46 46 46 86 86 86 18 18 18
56520 - 2 2 6 34 34 34 10 10 10 6 6 6
56521 -210 210 210 253 253 253 253 253 253 253 253 253
56522 -253 253 253 253 253 253 253 253 253 253 253 253
56523 -253 253 253 253 253 253 234 234 234 242 242 242
56524 -253 253 253 253 253 253 253 253 253 253 253 253
56525 -253 253 253 253 253 253 253 253 253 253 253 253
56526 -253 253 253 253 253 253 253 253 253 253 253 253
56527 -253 253 253 253 253 253 253 253 253 253 253 253
56528 -253 253 253 253 253 253 221 221 221 6 6 6
56529 - 2 2 6 2 2 6 6 6 6 30 30 30
56530 - 2 2 6 2 2 6 2 2 6 2 2 6
56531 - 2 2 6 82 82 82 54 54 54 18 18 18
56532 - 6 6 6 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 0 0 0
56536 - 0 0 0 0 0 0 0 0 0 0 0 0
56537 - 0 0 0 0 0 0 0 0 0 0 0 0
56538 - 0 0 0 0 0 0 0 0 0 10 10 10
56539 - 26 26 26 66 66 66 62 62 62 2 2 6
56540 - 2 2 6 38 38 38 10 10 10 26 26 26
56541 -238 238 238 253 253 253 253 253 253 253 253 253
56542 -253 253 253 253 253 253 253 253 253 253 253 253
56543 -253 253 253 253 253 253 231 231 231 238 238 238
56544 -253 253 253 253 253 253 253 253 253 253 253 253
56545 -253 253 253 253 253 253 253 253 253 253 253 253
56546 -253 253 253 253 253 253 253 253 253 253 253 253
56547 -253 253 253 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 231 231 231 6 6 6
56549 - 2 2 6 2 2 6 10 10 10 30 30 30
56550 - 2 2 6 2 2 6 2 2 6 2 2 6
56551 - 2 2 6 66 66 66 58 58 58 22 22 22
56552 - 6 6 6 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 0 0 0 0 0 0
56556 - 0 0 0 0 0 0 0 0 0 0 0 0
56557 - 0 0 0 0 0 0 0 0 0 0 0 0
56558 - 0 0 0 0 0 0 0 0 0 10 10 10
56559 - 38 38 38 78 78 78 6 6 6 2 2 6
56560 - 2 2 6 46 46 46 14 14 14 42 42 42
56561 -246 246 246 253 253 253 253 253 253 253 253 253
56562 -253 253 253 253 253 253 253 253 253 253 253 253
56563 -253 253 253 253 253 253 231 231 231 242 242 242
56564 -253 253 253 253 253 253 253 253 253 253 253 253
56565 -253 253 253 253 253 253 253 253 253 253 253 253
56566 -253 253 253 253 253 253 253 253 253 253 253 253
56567 -253 253 253 253 253 253 253 253 253 253 253 253
56568 -253 253 253 253 253 253 234 234 234 10 10 10
56569 - 2 2 6 2 2 6 22 22 22 14 14 14
56570 - 2 2 6 2 2 6 2 2 6 2 2 6
56571 - 2 2 6 66 66 66 62 62 62 22 22 22
56572 - 6 6 6 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 0 0 0 0 0 0 0 0 0
56576 - 0 0 0 0 0 0 0 0 0 0 0 0
56577 - 0 0 0 0 0 0 0 0 0 0 0 0
56578 - 0 0 0 0 0 0 6 6 6 18 18 18
56579 - 50 50 50 74 74 74 2 2 6 2 2 6
56580 - 14 14 14 70 70 70 34 34 34 62 62 62
56581 -250 250 250 253 253 253 253 253 253 253 253 253
56582 -253 253 253 253 253 253 253 253 253 253 253 253
56583 -253 253 253 253 253 253 231 231 231 246 246 246
56584 -253 253 253 253 253 253 253 253 253 253 253 253
56585 -253 253 253 253 253 253 253 253 253 253 253 253
56586 -253 253 253 253 253 253 253 253 253 253 253 253
56587 -253 253 253 253 253 253 253 253 253 253 253 253
56588 -253 253 253 253 253 253 234 234 234 14 14 14
56589 - 2 2 6 2 2 6 30 30 30 2 2 6
56590 - 2 2 6 2 2 6 2 2 6 2 2 6
56591 - 2 2 6 66 66 66 62 62 62 22 22 22
56592 - 6 6 6 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 0 0 0 0 0 0 0 0 0 0 0 0
56596 - 0 0 0 0 0 0 0 0 0 0 0 0
56597 - 0 0 0 0 0 0 0 0 0 0 0 0
56598 - 0 0 0 0 0 0 6 6 6 18 18 18
56599 - 54 54 54 62 62 62 2 2 6 2 2 6
56600 - 2 2 6 30 30 30 46 46 46 70 70 70
56601 -250 250 250 253 253 253 253 253 253 253 253 253
56602 -253 253 253 253 253 253 253 253 253 253 253 253
56603 -253 253 253 253 253 253 231 231 231 246 246 246
56604 -253 253 253 253 253 253 253 253 253 253 253 253
56605 -253 253 253 253 253 253 253 253 253 253 253 253
56606 -253 253 253 253 253 253 253 253 253 253 253 253
56607 -253 253 253 253 253 253 253 253 253 253 253 253
56608 -253 253 253 253 253 253 226 226 226 10 10 10
56609 - 2 2 6 6 6 6 30 30 30 2 2 6
56610 - 2 2 6 2 2 6 2 2 6 2 2 6
56611 - 2 2 6 66 66 66 58 58 58 22 22 22
56612 - 6 6 6 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 0 0 0 0 0 0 0 0 0 0 0 0
56616 - 0 0 0 0 0 0 0 0 0 0 0 0
56617 - 0 0 0 0 0 0 0 0 0 0 0 0
56618 - 0 0 0 0 0 0 6 6 6 22 22 22
56619 - 58 58 58 62 62 62 2 2 6 2 2 6
56620 - 2 2 6 2 2 6 30 30 30 78 78 78
56621 -250 250 250 253 253 253 253 253 253 253 253 253
56622 -253 253 253 253 253 253 253 253 253 253 253 253
56623 -253 253 253 253 253 253 231 231 231 246 246 246
56624 -253 253 253 253 253 253 253 253 253 253 253 253
56625 -253 253 253 253 253 253 253 253 253 253 253 253
56626 -253 253 253 253 253 253 253 253 253 253 253 253
56627 -253 253 253 253 253 253 253 253 253 253 253 253
56628 -253 253 253 253 253 253 206 206 206 2 2 6
56629 - 22 22 22 34 34 34 18 14 6 22 22 22
56630 - 26 26 26 18 18 18 6 6 6 2 2 6
56631 - 2 2 6 82 82 82 54 54 54 18 18 18
56632 - 6 6 6 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 0 0 0 0 0 0 0 0 0 0 0 0
56636 - 0 0 0 0 0 0 0 0 0 0 0 0
56637 - 0 0 0 0 0 0 0 0 0 0 0 0
56638 - 0 0 0 0 0 0 6 6 6 26 26 26
56639 - 62 62 62 106 106 106 74 54 14 185 133 11
56640 -210 162 10 121 92 8 6 6 6 62 62 62
56641 -238 238 238 253 253 253 253 253 253 253 253 253
56642 -253 253 253 253 253 253 253 253 253 253 253 253
56643 -253 253 253 253 253 253 231 231 231 246 246 246
56644 -253 253 253 253 253 253 253 253 253 253 253 253
56645 -253 253 253 253 253 253 253 253 253 253 253 253
56646 -253 253 253 253 253 253 253 253 253 253 253 253
56647 -253 253 253 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 158 158 158 18 18 18
56649 - 14 14 14 2 2 6 2 2 6 2 2 6
56650 - 6 6 6 18 18 18 66 66 66 38 38 38
56651 - 6 6 6 94 94 94 50 50 50 18 18 18
56652 - 6 6 6 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 0 0 0 0 0 0 6 6 6
56658 - 10 10 10 10 10 10 18 18 18 38 38 38
56659 - 78 78 78 142 134 106 216 158 10 242 186 14
56660 -246 190 14 246 190 14 156 118 10 10 10 10
56661 - 90 90 90 238 238 238 253 253 253 253 253 253
56662 -253 253 253 253 253 253 253 253 253 253 253 253
56663 -253 253 253 253 253 253 231 231 231 250 250 250
56664 -253 253 253 253 253 253 253 253 253 253 253 253
56665 -253 253 253 253 253 253 253 253 253 253 253 253
56666 -253 253 253 253 253 253 253 253 253 253 253 253
56667 -253 253 253 253 253 253 253 253 253 246 230 190
56668 -238 204 91 238 204 91 181 142 44 37 26 9
56669 - 2 2 6 2 2 6 2 2 6 2 2 6
56670 - 2 2 6 2 2 6 38 38 38 46 46 46
56671 - 26 26 26 106 106 106 54 54 54 18 18 18
56672 - 6 6 6 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 0 0 0
56675 - 0 0 0 0 0 0 0 0 0 0 0 0
56676 - 0 0 0 0 0 0 0 0 0 0 0 0
56677 - 0 0 0 6 6 6 14 14 14 22 22 22
56678 - 30 30 30 38 38 38 50 50 50 70 70 70
56679 -106 106 106 190 142 34 226 170 11 242 186 14
56680 -246 190 14 246 190 14 246 190 14 154 114 10
56681 - 6 6 6 74 74 74 226 226 226 253 253 253
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 231 231 231 250 250 250
56684 -253 253 253 253 253 253 253 253 253 253 253 253
56685 -253 253 253 253 253 253 253 253 253 253 253 253
56686 -253 253 253 253 253 253 253 253 253 253 253 253
56687 -253 253 253 253 253 253 253 253 253 228 184 62
56688 -241 196 14 241 208 19 232 195 16 38 30 10
56689 - 2 2 6 2 2 6 2 2 6 2 2 6
56690 - 2 2 6 6 6 6 30 30 30 26 26 26
56691 -203 166 17 154 142 90 66 66 66 26 26 26
56692 - 6 6 6 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 0 0 0
56695 - 0 0 0 0 0 0 0 0 0 0 0 0
56696 - 0 0 0 0 0 0 0 0 0 0 0 0
56697 - 6 6 6 18 18 18 38 38 38 58 58 58
56698 - 78 78 78 86 86 86 101 101 101 123 123 123
56699 -175 146 61 210 150 10 234 174 13 246 186 14
56700 -246 190 14 246 190 14 246 190 14 238 190 10
56701 -102 78 10 2 2 6 46 46 46 198 198 198
56702 -253 253 253 253 253 253 253 253 253 253 253 253
56703 -253 253 253 253 253 253 234 234 234 242 242 242
56704 -253 253 253 253 253 253 253 253 253 253 253 253
56705 -253 253 253 253 253 253 253 253 253 253 253 253
56706 -253 253 253 253 253 253 253 253 253 253 253 253
56707 -253 253 253 253 253 253 253 253 253 224 178 62
56708 -242 186 14 241 196 14 210 166 10 22 18 6
56709 - 2 2 6 2 2 6 2 2 6 2 2 6
56710 - 2 2 6 2 2 6 6 6 6 121 92 8
56711 -238 202 15 232 195 16 82 82 82 34 34 34
56712 - 10 10 10 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 0 0 0
56715 - 0 0 0 0 0 0 0 0 0 0 0 0
56716 - 0 0 0 0 0 0 0 0 0 0 0 0
56717 - 14 14 14 38 38 38 70 70 70 154 122 46
56718 -190 142 34 200 144 11 197 138 11 197 138 11
56719 -213 154 11 226 170 11 242 186 14 246 190 14
56720 -246 190 14 246 190 14 246 190 14 246 190 14
56721 -225 175 15 46 32 6 2 2 6 22 22 22
56722 -158 158 158 250 250 250 253 253 253 253 253 253
56723 -253 253 253 253 253 253 253 253 253 253 253 253
56724 -253 253 253 253 253 253 253 253 253 253 253 253
56725 -253 253 253 253 253 253 253 253 253 253 253 253
56726 -253 253 253 253 253 253 253 253 253 253 253 253
56727 -253 253 253 250 250 250 242 242 242 224 178 62
56728 -239 182 13 236 186 11 213 154 11 46 32 6
56729 - 2 2 6 2 2 6 2 2 6 2 2 6
56730 - 2 2 6 2 2 6 61 42 6 225 175 15
56731 -238 190 10 236 186 11 112 100 78 42 42 42
56732 - 14 14 14 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 0 0 0 6 6 6
56737 - 22 22 22 54 54 54 154 122 46 213 154 11
56738 -226 170 11 230 174 11 226 170 11 226 170 11
56739 -236 178 12 242 186 14 246 190 14 246 190 14
56740 -246 190 14 246 190 14 246 190 14 246 190 14
56741 -241 196 14 184 144 12 10 10 10 2 2 6
56742 - 6 6 6 116 116 116 242 242 242 253 253 253
56743 -253 253 253 253 253 253 253 253 253 253 253 253
56744 -253 253 253 253 253 253 253 253 253 253 253 253
56745 -253 253 253 253 253 253 253 253 253 253 253 253
56746 -253 253 253 253 253 253 253 253 253 253 253 253
56747 -253 253 253 231 231 231 198 198 198 214 170 54
56748 -236 178 12 236 178 12 210 150 10 137 92 6
56749 - 18 14 6 2 2 6 2 2 6 2 2 6
56750 - 6 6 6 70 47 6 200 144 11 236 178 12
56751 -239 182 13 239 182 13 124 112 88 58 58 58
56752 - 22 22 22 6 6 6 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 10 10 10
56757 - 30 30 30 70 70 70 180 133 36 226 170 11
56758 -239 182 13 242 186 14 242 186 14 246 186 14
56759 -246 190 14 246 190 14 246 190 14 246 190 14
56760 -246 190 14 246 190 14 246 190 14 246 190 14
56761 -246 190 14 232 195 16 98 70 6 2 2 6
56762 - 2 2 6 2 2 6 66 66 66 221 221 221
56763 -253 253 253 253 253 253 253 253 253 253 253 253
56764 -253 253 253 253 253 253 253 253 253 253 253 253
56765 -253 253 253 253 253 253 253 253 253 253 253 253
56766 -253 253 253 253 253 253 253 253 253 253 253 253
56767 -253 253 253 206 206 206 198 198 198 214 166 58
56768 -230 174 11 230 174 11 216 158 10 192 133 9
56769 -163 110 8 116 81 8 102 78 10 116 81 8
56770 -167 114 7 197 138 11 226 170 11 239 182 13
56771 -242 186 14 242 186 14 162 146 94 78 78 78
56772 - 34 34 34 14 14 14 6 6 6 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 6 6 6
56777 - 30 30 30 78 78 78 190 142 34 226 170 11
56778 -239 182 13 246 190 14 246 190 14 246 190 14
56779 -246 190 14 246 190 14 246 190 14 246 190 14
56780 -246 190 14 246 190 14 246 190 14 246 190 14
56781 -246 190 14 241 196 14 203 166 17 22 18 6
56782 - 2 2 6 2 2 6 2 2 6 38 38 38
56783 -218 218 218 253 253 253 253 253 253 253 253 253
56784 -253 253 253 253 253 253 253 253 253 253 253 253
56785 -253 253 253 253 253 253 253 253 253 253 253 253
56786 -253 253 253 253 253 253 253 253 253 253 253 253
56787 -250 250 250 206 206 206 198 198 198 202 162 69
56788 -226 170 11 236 178 12 224 166 10 210 150 10
56789 -200 144 11 197 138 11 192 133 9 197 138 11
56790 -210 150 10 226 170 11 242 186 14 246 190 14
56791 -246 190 14 246 186 14 225 175 15 124 112 88
56792 - 62 62 62 30 30 30 14 14 14 6 6 6
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 0 0 0 0 0 0 10 10 10
56797 - 30 30 30 78 78 78 174 135 50 224 166 10
56798 -239 182 13 246 190 14 246 190 14 246 190 14
56799 -246 190 14 246 190 14 246 190 14 246 190 14
56800 -246 190 14 246 190 14 246 190 14 246 190 14
56801 -246 190 14 246 190 14 241 196 14 139 102 15
56802 - 2 2 6 2 2 6 2 2 6 2 2 6
56803 - 78 78 78 250 250 250 253 253 253 253 253 253
56804 -253 253 253 253 253 253 253 253 253 253 253 253
56805 -253 253 253 253 253 253 253 253 253 253 253 253
56806 -253 253 253 253 253 253 253 253 253 253 253 253
56807 -250 250 250 214 214 214 198 198 198 190 150 46
56808 -219 162 10 236 178 12 234 174 13 224 166 10
56809 -216 158 10 213 154 11 213 154 11 216 158 10
56810 -226 170 11 239 182 13 246 190 14 246 190 14
56811 -246 190 14 246 190 14 242 186 14 206 162 42
56812 -101 101 101 58 58 58 30 30 30 14 14 14
56813 - 6 6 6 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 0 0 0 0 0 0 0 0 0 10 10 10
56817 - 30 30 30 74 74 74 174 135 50 216 158 10
56818 -236 178 12 246 190 14 246 190 14 246 190 14
56819 -246 190 14 246 190 14 246 190 14 246 190 14
56820 -246 190 14 246 190 14 246 190 14 246 190 14
56821 -246 190 14 246 190 14 241 196 14 226 184 13
56822 - 61 42 6 2 2 6 2 2 6 2 2 6
56823 - 22 22 22 238 238 238 253 253 253 253 253 253
56824 -253 253 253 253 253 253 253 253 253 253 253 253
56825 -253 253 253 253 253 253 253 253 253 253 253 253
56826 -253 253 253 253 253 253 253 253 253 253 253 253
56827 -253 253 253 226 226 226 187 187 187 180 133 36
56828 -216 158 10 236 178 12 239 182 13 236 178 12
56829 -230 174 11 226 170 11 226 170 11 230 174 11
56830 -236 178 12 242 186 14 246 190 14 246 190 14
56831 -246 190 14 246 190 14 246 186 14 239 182 13
56832 -206 162 42 106 106 106 66 66 66 34 34 34
56833 - 14 14 14 6 6 6 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 6 6 6
56837 - 26 26 26 70 70 70 163 133 67 213 154 11
56838 -236 178 12 246 190 14 246 190 14 246 190 14
56839 -246 190 14 246 190 14 246 190 14 246 190 14
56840 -246 190 14 246 190 14 246 190 14 246 190 14
56841 -246 190 14 246 190 14 246 190 14 241 196 14
56842 -190 146 13 18 14 6 2 2 6 2 2 6
56843 - 46 46 46 246 246 246 253 253 253 253 253 253
56844 -253 253 253 253 253 253 253 253 253 253 253 253
56845 -253 253 253 253 253 253 253 253 253 253 253 253
56846 -253 253 253 253 253 253 253 253 253 253 253 253
56847 -253 253 253 221 221 221 86 86 86 156 107 11
56848 -216 158 10 236 178 12 242 186 14 246 186 14
56849 -242 186 14 239 182 13 239 182 13 242 186 14
56850 -242 186 14 246 186 14 246 190 14 246 190 14
56851 -246 190 14 246 190 14 246 190 14 246 190 14
56852 -242 186 14 225 175 15 142 122 72 66 66 66
56853 - 30 30 30 10 10 10 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 6 6 6
56857 - 26 26 26 70 70 70 163 133 67 210 150 10
56858 -236 178 12 246 190 14 246 190 14 246 190 14
56859 -246 190 14 246 190 14 246 190 14 246 190 14
56860 -246 190 14 246 190 14 246 190 14 246 190 14
56861 -246 190 14 246 190 14 246 190 14 246 190 14
56862 -232 195 16 121 92 8 34 34 34 106 106 106
56863 -221 221 221 253 253 253 253 253 253 253 253 253
56864 -253 253 253 253 253 253 253 253 253 253 253 253
56865 -253 253 253 253 253 253 253 253 253 253 253 253
56866 -253 253 253 253 253 253 253 253 253 253 253 253
56867 -242 242 242 82 82 82 18 14 6 163 110 8
56868 -216 158 10 236 178 12 242 186 14 246 190 14
56869 -246 190 14 246 190 14 246 190 14 246 190 14
56870 -246 190 14 246 190 14 246 190 14 246 190 14
56871 -246 190 14 246 190 14 246 190 14 246 190 14
56872 -246 190 14 246 190 14 242 186 14 163 133 67
56873 - 46 46 46 18 18 18 6 6 6 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 0 0 0 0 10 10 10
56877 - 30 30 30 78 78 78 163 133 67 210 150 10
56878 -236 178 12 246 186 14 246 190 14 246 190 14
56879 -246 190 14 246 190 14 246 190 14 246 190 14
56880 -246 190 14 246 190 14 246 190 14 246 190 14
56881 -246 190 14 246 190 14 246 190 14 246 190 14
56882 -241 196 14 215 174 15 190 178 144 253 253 253
56883 -253 253 253 253 253 253 253 253 253 253 253 253
56884 -253 253 253 253 253 253 253 253 253 253 253 253
56885 -253 253 253 253 253 253 253 253 253 253 253 253
56886 -253 253 253 253 253 253 253 253 253 218 218 218
56887 - 58 58 58 2 2 6 22 18 6 167 114 7
56888 -216 158 10 236 178 12 246 186 14 246 190 14
56889 -246 190 14 246 190 14 246 190 14 246 190 14
56890 -246 190 14 246 190 14 246 190 14 246 190 14
56891 -246 190 14 246 190 14 246 190 14 246 190 14
56892 -246 190 14 246 186 14 242 186 14 190 150 46
56893 - 54 54 54 22 22 22 6 6 6 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 0 0 0 14 14 14
56897 - 38 38 38 86 86 86 180 133 36 213 154 11
56898 -236 178 12 246 186 14 246 190 14 246 190 14
56899 -246 190 14 246 190 14 246 190 14 246 190 14
56900 -246 190 14 246 190 14 246 190 14 246 190 14
56901 -246 190 14 246 190 14 246 190 14 246 190 14
56902 -246 190 14 232 195 16 190 146 13 214 214 214
56903 -253 253 253 253 253 253 253 253 253 253 253 253
56904 -253 253 253 253 253 253 253 253 253 253 253 253
56905 -253 253 253 253 253 253 253 253 253 253 253 253
56906 -253 253 253 250 250 250 170 170 170 26 26 26
56907 - 2 2 6 2 2 6 37 26 9 163 110 8
56908 -219 162 10 239 182 13 246 186 14 246 190 14
56909 -246 190 14 246 190 14 246 190 14 246 190 14
56910 -246 190 14 246 190 14 246 190 14 246 190 14
56911 -246 190 14 246 190 14 246 190 14 246 190 14
56912 -246 186 14 236 178 12 224 166 10 142 122 72
56913 - 46 46 46 18 18 18 6 6 6 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 0 0 0 0 6 6 6 18 18 18
56917 - 50 50 50 109 106 95 192 133 9 224 166 10
56918 -242 186 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 190 14 246 190 14 246 190 14
56921 -246 190 14 246 190 14 246 190 14 246 190 14
56922 -242 186 14 226 184 13 210 162 10 142 110 46
56923 -226 226 226 253 253 253 253 253 253 253 253 253
56924 -253 253 253 253 253 253 253 253 253 253 253 253
56925 -253 253 253 253 253 253 253 253 253 253 253 253
56926 -198 198 198 66 66 66 2 2 6 2 2 6
56927 - 2 2 6 2 2 6 50 34 6 156 107 11
56928 -219 162 10 239 182 13 246 186 14 246 190 14
56929 -246 190 14 246 190 14 246 190 14 246 190 14
56930 -246 190 14 246 190 14 246 190 14 246 190 14
56931 -246 190 14 246 190 14 246 190 14 242 186 14
56932 -234 174 13 213 154 11 154 122 46 66 66 66
56933 - 30 30 30 10 10 10 0 0 0 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 6 6 6 22 22 22
56937 - 58 58 58 154 121 60 206 145 10 234 174 13
56938 -242 186 14 246 186 14 246 190 14 246 190 14
56939 -246 190 14 246 190 14 246 190 14 246 190 14
56940 -246 190 14 246 190 14 246 190 14 246 190 14
56941 -246 190 14 246 190 14 246 190 14 246 190 14
56942 -246 186 14 236 178 12 210 162 10 163 110 8
56943 - 61 42 6 138 138 138 218 218 218 250 250 250
56944 -253 253 253 253 253 253 253 253 253 250 250 250
56945 -242 242 242 210 210 210 144 144 144 66 66 66
56946 - 6 6 6 2 2 6 2 2 6 2 2 6
56947 - 2 2 6 2 2 6 61 42 6 163 110 8
56948 -216 158 10 236 178 12 246 190 14 246 190 14
56949 -246 190 14 246 190 14 246 190 14 246 190 14
56950 -246 190 14 246 190 14 246 190 14 246 190 14
56951 -246 190 14 239 182 13 230 174 11 216 158 10
56952 -190 142 34 124 112 88 70 70 70 38 38 38
56953 - 18 18 18 6 6 6 0 0 0 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 0 0 0 0 0 0
56956 - 0 0 0 0 0 0 6 6 6 22 22 22
56957 - 62 62 62 168 124 44 206 145 10 224 166 10
56958 -236 178 12 239 182 13 242 186 14 242 186 14
56959 -246 186 14 246 190 14 246 190 14 246 190 14
56960 -246 190 14 246 190 14 246 190 14 246 190 14
56961 -246 190 14 246 190 14 246 190 14 246 190 14
56962 -246 190 14 236 178 12 216 158 10 175 118 6
56963 - 80 54 7 2 2 6 6 6 6 30 30 30
56964 - 54 54 54 62 62 62 50 50 50 38 38 38
56965 - 14 14 14 2 2 6 2 2 6 2 2 6
56966 - 2 2 6 2 2 6 2 2 6 2 2 6
56967 - 2 2 6 6 6 6 80 54 7 167 114 7
56968 -213 154 11 236 178 12 246 190 14 246 190 14
56969 -246 190 14 246 190 14 246 190 14 246 190 14
56970 -246 190 14 242 186 14 239 182 13 239 182 13
56971 -230 174 11 210 150 10 174 135 50 124 112 88
56972 - 82 82 82 54 54 54 34 34 34 18 18 18
56973 - 6 6 6 0 0 0 0 0 0 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 0 0 0 0 0 0
56976 - 0 0 0 0 0 0 6 6 6 18 18 18
56977 - 50 50 50 158 118 36 192 133 9 200 144 11
56978 -216 158 10 219 162 10 224 166 10 226 170 11
56979 -230 174 11 236 178 12 239 182 13 239 182 13
56980 -242 186 14 246 186 14 246 190 14 246 190 14
56981 -246 190 14 246 190 14 246 190 14 246 190 14
56982 -246 186 14 230 174 11 210 150 10 163 110 8
56983 -104 69 6 10 10 10 2 2 6 2 2 6
56984 - 2 2 6 2 2 6 2 2 6 2 2 6
56985 - 2 2 6 2 2 6 2 2 6 2 2 6
56986 - 2 2 6 2 2 6 2 2 6 2 2 6
56987 - 2 2 6 6 6 6 91 60 6 167 114 7
56988 -206 145 10 230 174 11 242 186 14 246 190 14
56989 -246 190 14 246 190 14 246 186 14 242 186 14
56990 -239 182 13 230 174 11 224 166 10 213 154 11
56991 -180 133 36 124 112 88 86 86 86 58 58 58
56992 - 38 38 38 22 22 22 10 10 10 6 6 6
56993 - 0 0 0 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 0 0 0
56995 - 0 0 0 0 0 0 0 0 0 0 0 0
56996 - 0 0 0 0 0 0 0 0 0 14 14 14
56997 - 34 34 34 70 70 70 138 110 50 158 118 36
56998 -167 114 7 180 123 7 192 133 9 197 138 11
56999 -200 144 11 206 145 10 213 154 11 219 162 10
57000 -224 166 10 230 174 11 239 182 13 242 186 14
57001 -246 186 14 246 186 14 246 186 14 246 186 14
57002 -239 182 13 216 158 10 185 133 11 152 99 6
57003 -104 69 6 18 14 6 2 2 6 2 2 6
57004 - 2 2 6 2 2 6 2 2 6 2 2 6
57005 - 2 2 6 2 2 6 2 2 6 2 2 6
57006 - 2 2 6 2 2 6 2 2 6 2 2 6
57007 - 2 2 6 6 6 6 80 54 7 152 99 6
57008 -192 133 9 219 162 10 236 178 12 239 182 13
57009 -246 186 14 242 186 14 239 182 13 236 178 12
57010 -224 166 10 206 145 10 192 133 9 154 121 60
57011 - 94 94 94 62 62 62 42 42 42 22 22 22
57012 - 14 14 14 6 6 6 0 0 0 0 0 0
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 0 0 0
57015 - 0 0 0 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 0 0 0 6 6 6
57017 - 18 18 18 34 34 34 58 58 58 78 78 78
57018 -101 98 89 124 112 88 142 110 46 156 107 11
57019 -163 110 8 167 114 7 175 118 6 180 123 7
57020 -185 133 11 197 138 11 210 150 10 219 162 10
57021 -226 170 11 236 178 12 236 178 12 234 174 13
57022 -219 162 10 197 138 11 163 110 8 130 83 6
57023 - 91 60 6 10 10 10 2 2 6 2 2 6
57024 - 18 18 18 38 38 38 38 38 38 38 38 38
57025 - 38 38 38 38 38 38 38 38 38 38 38 38
57026 - 38 38 38 38 38 38 26 26 26 2 2 6
57027 - 2 2 6 6 6 6 70 47 6 137 92 6
57028 -175 118 6 200 144 11 219 162 10 230 174 11
57029 -234 174 13 230 174 11 219 162 10 210 150 10
57030 -192 133 9 163 110 8 124 112 88 82 82 82
57031 - 50 50 50 30 30 30 14 14 14 6 6 6
57032 - 0 0 0 0 0 0 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 0 0 0 0 0 0
57035 - 0 0 0 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 0 0 0 0 0 0 0
57037 - 6 6 6 14 14 14 22 22 22 34 34 34
57038 - 42 42 42 58 58 58 74 74 74 86 86 86
57039 -101 98 89 122 102 70 130 98 46 121 87 25
57040 -137 92 6 152 99 6 163 110 8 180 123 7
57041 -185 133 11 197 138 11 206 145 10 200 144 11
57042 -180 123 7 156 107 11 130 83 6 104 69 6
57043 - 50 34 6 54 54 54 110 110 110 101 98 89
57044 - 86 86 86 82 82 82 78 78 78 78 78 78
57045 - 78 78 78 78 78 78 78 78 78 78 78 78
57046 - 78 78 78 82 82 82 86 86 86 94 94 94
57047 -106 106 106 101 101 101 86 66 34 124 80 6
57048 -156 107 11 180 123 7 192 133 9 200 144 11
57049 -206 145 10 200 144 11 192 133 9 175 118 6
57050 -139 102 15 109 106 95 70 70 70 42 42 42
57051 - 22 22 22 10 10 10 0 0 0 0 0 0
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 0 0 0 0 0 0
57055 - 0 0 0 0 0 0 0 0 0 0 0 0
57056 - 0 0 0 0 0 0 0 0 0 0 0 0
57057 - 0 0 0 0 0 0 6 6 6 10 10 10
57058 - 14 14 14 22 22 22 30 30 30 38 38 38
57059 - 50 50 50 62 62 62 74 74 74 90 90 90
57060 -101 98 89 112 100 78 121 87 25 124 80 6
57061 -137 92 6 152 99 6 152 99 6 152 99 6
57062 -138 86 6 124 80 6 98 70 6 86 66 30
57063 -101 98 89 82 82 82 58 58 58 46 46 46
57064 - 38 38 38 34 34 34 34 34 34 34 34 34
57065 - 34 34 34 34 34 34 34 34 34 34 34 34
57066 - 34 34 34 34 34 34 38 38 38 42 42 42
57067 - 54 54 54 82 82 82 94 86 76 91 60 6
57068 -134 86 6 156 107 11 167 114 7 175 118 6
57069 -175 118 6 167 114 7 152 99 6 121 87 25
57070 -101 98 89 62 62 62 34 34 34 18 18 18
57071 - 6 6 6 0 0 0 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 0 0 0 0 0 0 0 0 0
57075 - 0 0 0 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 0 0 0 0 0 0 0
57077 - 0 0 0 0 0 0 0 0 0 0 0 0
57078 - 0 0 0 6 6 6 6 6 6 10 10 10
57079 - 18 18 18 22 22 22 30 30 30 42 42 42
57080 - 50 50 50 66 66 66 86 86 86 101 98 89
57081 -106 86 58 98 70 6 104 69 6 104 69 6
57082 -104 69 6 91 60 6 82 62 34 90 90 90
57083 - 62 62 62 38 38 38 22 22 22 14 14 14
57084 - 10 10 10 10 10 10 10 10 10 10 10 10
57085 - 10 10 10 10 10 10 6 6 6 10 10 10
57086 - 10 10 10 10 10 10 10 10 10 14 14 14
57087 - 22 22 22 42 42 42 70 70 70 89 81 66
57088 - 80 54 7 104 69 6 124 80 6 137 92 6
57089 -134 86 6 116 81 8 100 82 52 86 86 86
57090 - 58 58 58 30 30 30 14 14 14 6 6 6
57091 - 0 0 0 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 0 0 0 0 0 0 0 0 0 0 0 0
57095 - 0 0 0 0 0 0 0 0 0 0 0 0
57096 - 0 0 0 0 0 0 0 0 0 0 0 0
57097 - 0 0 0 0 0 0 0 0 0 0 0 0
57098 - 0 0 0 0 0 0 0 0 0 0 0 0
57099 - 0 0 0 6 6 6 10 10 10 14 14 14
57100 - 18 18 18 26 26 26 38 38 38 54 54 54
57101 - 70 70 70 86 86 86 94 86 76 89 81 66
57102 - 89 81 66 86 86 86 74 74 74 50 50 50
57103 - 30 30 30 14 14 14 6 6 6 0 0 0
57104 - 0 0 0 0 0 0 0 0 0 0 0 0
57105 - 0 0 0 0 0 0 0 0 0 0 0 0
57106 - 0 0 0 0 0 0 0 0 0 0 0 0
57107 - 6 6 6 18 18 18 34 34 34 58 58 58
57108 - 82 82 82 89 81 66 89 81 66 89 81 66
57109 - 94 86 66 94 86 76 74 74 74 50 50 50
57110 - 26 26 26 14 14 14 6 6 6 0 0 0
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 0 0 0
57114 - 0 0 0 0 0 0 0 0 0 0 0 0
57115 - 0 0 0 0 0 0 0 0 0 0 0 0
57116 - 0 0 0 0 0 0 0 0 0 0 0 0
57117 - 0 0 0 0 0 0 0 0 0 0 0 0
57118 - 0 0 0 0 0 0 0 0 0 0 0 0
57119 - 0 0 0 0 0 0 0 0 0 0 0 0
57120 - 6 6 6 6 6 6 14 14 14 18 18 18
57121 - 30 30 30 38 38 38 46 46 46 54 54 54
57122 - 50 50 50 42 42 42 30 30 30 18 18 18
57123 - 10 10 10 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 14 14 14 26 26 26
57128 - 38 38 38 50 50 50 58 58 58 58 58 58
57129 - 54 54 54 42 42 42 30 30 30 18 18 18
57130 - 10 10 10 0 0 0 0 0 0 0 0 0
57131 - 0 0 0 0 0 0 0 0 0 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 - 0 0 0 0 0 0 0 0 0 0 0 0
57136 - 0 0 0 0 0 0 0 0 0 0 0 0
57137 - 0 0 0 0 0 0 0 0 0 0 0 0
57138 - 0 0 0 0 0 0 0 0 0 0 0 0
57139 - 0 0 0 0 0 0 0 0 0 0 0 0
57140 - 0 0 0 0 0 0 0 0 0 6 6 6
57141 - 6 6 6 10 10 10 14 14 14 18 18 18
57142 - 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
57148 - 14 14 14 18 18 18 22 22 22 22 22 22
57149 - 18 18 18 14 14 14 10 10 10 6 6 6
57150 - 0 0 0 0 0 0 0 0 0 0 0 0
57151 - 0 0 0 0 0 0 0 0 0 0 0 0
57152 - 0 0 0 0 0 0 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 0 0 0
57154 - 0 0 0 0 0 0 0 0 0 0 0 0
57155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57168 +4 4 4 4 4 4
57169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57182 +4 4 4 4 4 4
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 3 3 3 0 0 0 0 0 0
57244 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
57249 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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 2 2 2 0 0 0 3 4 3 26 28 28
57258 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57259 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
57263 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57264 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57265 +1 1 1 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57272 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57273 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
57277 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57278 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57279 +2 2 2 2 1 0 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 5 5 5 5 5 5 2 2 2 0 0 0
57285 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57286 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57287 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
57290 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57291 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57292 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57293 +37 51 59 2 0 0 1 1 1 4 5 5 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57299 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57300 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57301 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57302 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57304 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57305 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57306 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57307 +64 123 161 14 17 19 0 0 0 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 5 5 5
57312 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57313 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57314 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57315 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57316 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57317 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57318 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57319 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57320 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57321 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 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 5 5 5 3 3 3
57326 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57327 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57328 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57329 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57330 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57331 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57332 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57333 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57334 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57335 +31 91 132 3 6 7 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 2 2 2 0 0 0 4 0 0
57340 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57341 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57342 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57343 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57344 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57345 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57346 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57347 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57348 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57349 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57354 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57355 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57356 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57357 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57358 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57359 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57360 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57361 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57362 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57363 +1 1 2 4 3 3 4 4 4 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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57368 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57369 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57370 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57371 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57372 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57373 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57374 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57375 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57376 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57377 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 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 3 3 3 0 0 0
57381 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57382 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57383 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57384 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57385 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57386 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57387 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57388 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57389 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57390 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57391 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57395 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57396 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57397 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57398 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57399 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57400 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57401 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57402 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57403 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57404 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57405 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57406 +0 0 0 4 4 4
57407 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57408 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57409 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57410 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57411 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57412 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57413 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57414 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57415 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57416 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57417 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57418 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57419 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57420 +2 0 0 0 0 0
57421 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57422 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57423 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57424 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57425 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57426 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57427 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57428 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57429 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57430 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57431 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57432 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57433 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57434 +37 38 37 0 0 0
57435 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57436 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57437 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57438 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57439 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57440 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57441 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57442 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57443 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57444 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57445 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57446 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57447 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57448 +85 115 134 4 0 0
57449 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57450 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57451 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57452 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57453 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57454 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57455 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57456 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57457 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57458 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57459 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57460 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57461 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57462 +60 73 81 4 0 0
57463 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57464 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57465 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57466 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57467 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57468 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57469 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57470 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57471 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57472 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57473 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57474 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57475 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57476 +16 19 21 4 0 0
57477 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57478 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57479 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57480 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57481 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57482 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57483 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57484 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57485 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57486 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57487 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57488 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57489 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57490 +4 0 0 4 3 3
57491 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57492 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57493 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57495 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57496 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57497 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57498 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57499 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57500 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57501 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57502 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57503 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57504 +3 2 2 4 4 4
57505 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57506 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57507 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57508 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57509 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57510 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57511 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57512 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57513 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57514 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57515 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57516 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57517 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57518 +4 4 4 4 4 4
57519 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57520 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57521 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57522 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57523 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57524 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57525 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57526 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57527 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57528 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57529 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57530 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57531 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57532 +4 4 4 4 4 4
57533 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57534 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57535 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57536 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57537 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57538 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57539 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57540 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57541 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57542 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57543 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57544 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57545 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57546 +5 5 5 5 5 5
57547 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57548 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57549 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57550 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57551 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57552 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57553 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57554 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57555 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57556 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57557 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57558 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57559 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57560 +5 5 5 4 4 4
57561 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57562 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57563 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57564 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57565 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57566 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57567 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57568 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57569 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57570 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57571 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57572 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57574 +4 4 4 4 4 4
57575 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57576 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57577 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57578 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57579 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57580 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57581 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57582 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57583 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57584 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57585 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57586 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57588 +4 4 4 4 4 4
57589 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57590 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57591 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57592 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57593 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57594 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57595 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57596 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57597 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57598 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57599 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57600 +4 4 4 4 4 4 4 4 4 4 4 4 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 157 156 157 155 154 155 137 136 137
57604 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57605 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57606 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57607 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 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 136 185 209 90 154 193 26 108 161 22 40 52
57611 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57612 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57613 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57614 +4 4 4 4 4 4 4 4 4 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 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57618 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57619 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57620 +90 154 193 64 123 161 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 90 154 193
57622 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57623 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57624 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57625 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57626 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57627 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 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 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57632 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57633 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57634 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57635 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57636 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57637 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57638 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57639 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57640 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57641 +6 6 6 4 0 0 6 6 6 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 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57646 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57647 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57648 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57649 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57650 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57651 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57652 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57653 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57654 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57655 +4 0 0 3 2 2 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 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57660 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57661 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57662 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57663 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57664 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57665 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57666 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57667 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57668 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57669 +4 0 0 4 3 3 5 5 5 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 60 73 81 167 166 167 174 174 174 163 162 163
57674 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57675 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57676 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57677 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57678 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57679 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57680 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57681 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57682 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57683 +4 0 0 4 3 3 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 167 166 167 174 174 174 166 165 166
57688 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57689 +5 5 5 4 3 3 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 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57692 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57693 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57694 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57695 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57696 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57697 +4 0 0 3 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 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57702 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57703 +5 5 5 4 4 4 1 1 2 6 10 14 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 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57707 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57708 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57709 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57710 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57711 +0 0 0 3 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 174 174 174 177 184 187 174 174 174
57716 +174 174 174 190 197 201 157 156 157 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 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57719 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57720 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57721 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57722 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57723 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57724 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57725 +0 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 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57730 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57731 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57732 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57733 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57734 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57735 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57736 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57737 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 177 184 187 193 200 203 174 174 174
57744 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57745 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57746 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57747 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57748 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57749 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57750 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57751 +4 4 4 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 190 197 201 174 174 174
57758 +177 184 187 193 200 203 163 162 163 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 10 87 144
57760 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57761 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57762 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57763 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57764 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57765 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
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 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57772 +190 197 201 193 200 203 165 164 165 37 38 37 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 16 89 141 18 97 151 18 97 151 10 87 144
57775 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57776 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57777 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57778 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 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 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57786 +190 197 201 193 200 203 165 164 165 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 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57789 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57790 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57791 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57792 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57793 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
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 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57800 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57801 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57802 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57803 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57804 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57805 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57806 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 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 220 221 221 174 174 174
57814 +190 197 201 205 212 215 167 166 167 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 10 87 144 22 40 52 1 1 2
57817 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57818 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57819 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57820 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57821 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 220 221 221 190 197 201 174 174 174
57828 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57829 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57830 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57831 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57832 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57833 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57834 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
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 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57843 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57844 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57845 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57846 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57847 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57848 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
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 26 28 28 4 0 0 4 3 3
57857 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57858 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57859 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57860 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57861 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57862 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57863 +4 4 4 5 5 5 4 4 4 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 190 197 201 41 54 63 4 0 0 2 2 2
57871 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57872 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57873 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57874 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57875 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57876 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57877 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
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 193 200 203 174 174 174
57884 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57885 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57886 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57887 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57888 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57889 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57890 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57891 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57892 +131 129 131 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 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57899 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57900 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57901 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57902 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57903 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57904 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57905 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57906 +125 124 125 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 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57912 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57913 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57914 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57915 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57916 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57917 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57918 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57919 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57920 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
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 26 28 28 156 155 156 220 221 221 220 221 221
57926 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57927 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57928 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57929 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57930 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57931 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57932 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57933 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57934 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57935 +0 0 0 4 4 4 4 4 4 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 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57940 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57941 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57942 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57943 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57944 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57945 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57946 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57947 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57948 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57949 +4 3 3 5 5 5 4 4 4 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57954 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57955 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57956 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57957 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57958 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57959 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57960 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57961 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57962 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57963 +5 5 5 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 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57968 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57969 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57970 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57971 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57972 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57973 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57974 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57975 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57976 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57978 +4 4 4 4 4 4 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 6 6 6 6 6 6 6 6 6
57982 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57983 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57984 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57985 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57986 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57987 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57988 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57989 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57990 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57992 +4 4 4 4 4 4 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 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57996 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57997 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57998 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57999 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58000 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58001 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58002 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58003 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58004 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006 +4 4 4 4 4 4 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 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58010 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58011 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58012 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58013 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58014 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58015 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58016 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58017 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58018 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020 +4 4 4 4 4 4 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 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58024 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58025 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58026 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58027 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58028 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58029 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58030 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58031 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034 +4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6 4 0 0
58038 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58039 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58040 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58041 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58042 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58043 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58044 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58045 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58048 +4 4 4 4 4 4 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 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58052 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58053 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58054 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58055 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58056 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58057 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58058 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58059 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58062 +4 4 4 4 4 4 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 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58066 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58067 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58068 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58069 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58070 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58071 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58072 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078 +4 4 4 4 4 4
58079 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58080 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58081 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58082 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58083 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58084 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58085 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58086 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092 +4 4 4 4 4 4
58093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58094 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58095 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58096 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58097 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58098 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58099 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58100 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106 +4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58108 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58109 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58110 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58111 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58112 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58113 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58114 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4
58122 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58123 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58124 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58125 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58126 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58127 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58128 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134 +4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58137 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58138 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58139 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58140 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58141 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58142 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148 +4 4 4 4 4 4
58149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58152 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58153 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58154 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58155 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58167 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58168 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58169 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174 +4 4 4 4 4 4 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 4 4 4
58180 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58181 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58182 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58183 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188 +4 4 4 4 4 4 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 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58195 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58196 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58197 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5
58209 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58210 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58211 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58216 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
58223 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58224 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58225 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58230 +4 4 4 4 4 4 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 4 4 4
58237 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58238 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58239 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58244 +4 4 4 4 4 4 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 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58252 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58258 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58266 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58272 +4 4 4 4 4 4 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 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58276 index fef20db..d28b1ab 100644
58277 --- a/drivers/xen/xenfs/xenstored.c
58278 +++ b/drivers/xen/xenfs/xenstored.c
58279 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58280 static int xsd_kva_open(struct inode *inode, struct file *file)
58281 {
58282 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58283 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58284 + NULL);
58285 +#else
58286 xen_store_interface);
58287 +#endif
58288 +
58289 if (!file->private_data)
58290 return -ENOMEM;
58291 return 0;
58292 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58293 index eb14e05..5156de7 100644
58294 --- a/fs/9p/vfs_addr.c
58295 +++ b/fs/9p/vfs_addr.c
58296 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58297
58298 retval = v9fs_file_write_internal(inode,
58299 v9inode->writeback_fid,
58300 - (__force const char __user *)buffer,
58301 + (const char __force_user *)buffer,
58302 len, &offset, 0);
58303 if (retval > 0)
58304 retval = 0;
58305 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58306 index 296482f..183ddc3 100644
58307 --- a/fs/9p/vfs_inode.c
58308 +++ b/fs/9p/vfs_inode.c
58309 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58310 void
58311 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58312 {
58313 - char *s = nd_get_link(nd);
58314 + const char *s = nd_get_link(nd);
58315
58316 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58317 dentry, IS_ERR(s) ? "<error>" : s);
58318 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58319 index 370b24c..ff0be7b 100644
58320 --- a/fs/Kconfig.binfmt
58321 +++ b/fs/Kconfig.binfmt
58322 @@ -103,7 +103,7 @@ config HAVE_AOUT
58323
58324 config BINFMT_AOUT
58325 tristate "Kernel support for a.out and ECOFF binaries"
58326 - depends on HAVE_AOUT
58327 + depends on HAVE_AOUT && BROKEN
58328 ---help---
58329 A.out (Assembler.OUTput) is a set of formats for libraries and
58330 executables used in the earliest versions of UNIX. Linux used
58331 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58332 index 2946712..f737435 100644
58333 --- a/fs/afs/inode.c
58334 +++ b/fs/afs/inode.c
58335 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58336 struct afs_vnode *vnode;
58337 struct super_block *sb;
58338 struct inode *inode;
58339 - static atomic_t afs_autocell_ino;
58340 + static atomic_unchecked_t afs_autocell_ino;
58341
58342 _enter("{%x:%u},%*.*s,",
58343 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58344 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58345 data.fid.unique = 0;
58346 data.fid.vnode = 0;
58347
58348 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58349 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58350 afs_iget5_autocell_test, afs_iget5_set,
58351 &data);
58352 if (!inode) {
58353 diff --git a/fs/aio.c b/fs/aio.c
58354 index 14b9315..365980f 100644
58355 --- a/fs/aio.c
58356 +++ b/fs/aio.c
58357 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58358 size += sizeof(struct io_event) * nr_events;
58359
58360 nr_pages = PFN_UP(size);
58361 - if (nr_pages < 0)
58362 + if (nr_pages <= 0)
58363 return -EINVAL;
58364
58365 file = aio_private_file(ctx, nr_pages);
58366 diff --git a/fs/attr.c b/fs/attr.c
58367 index 6530ced..4a827e2 100644
58368 --- a/fs/attr.c
58369 +++ b/fs/attr.c
58370 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58371 unsigned long limit;
58372
58373 limit = rlimit(RLIMIT_FSIZE);
58374 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58375 if (limit != RLIM_INFINITY && offset > limit)
58376 goto out_sig;
58377 if (offset > inode->i_sb->s_maxbytes)
58378 diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
58379 index aaf96cb..ac7d921 100644
58380 --- a/fs/autofs4/dev-ioctl.c
58381 +++ b/fs/autofs4/dev-ioctl.c
58382 @@ -95,7 +95,7 @@ static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
58383 */
58384 static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in)
58385 {
58386 - struct autofs_dev_ioctl tmp;
58387 + struct autofs_dev_ioctl tmp, *res;
58388
58389 if (copy_from_user(&tmp, in, sizeof(tmp)))
58390 return ERR_PTR(-EFAULT);
58391 @@ -106,7 +106,11 @@ static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *i
58392 if (tmp.size > (PATH_MAX + sizeof(tmp)))
58393 return ERR_PTR(-ENAMETOOLONG);
58394
58395 - return memdup_user(in, tmp.size);
58396 + res = memdup_user(in, tmp.size);
58397 + if (!IS_ERR(res))
58398 + res->size = tmp.size;
58399 +
58400 + return res;
58401 }
58402
58403 static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)
58404 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58405 index 116fd38..c04182da 100644
58406 --- a/fs/autofs4/waitq.c
58407 +++ b/fs/autofs4/waitq.c
58408 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58409 {
58410 unsigned long sigpipe, flags;
58411 mm_segment_t fs;
58412 - const char *data = (const char *)addr;
58413 + const char __user *data = (const char __force_user *)addr;
58414 ssize_t wr = 0;
58415
58416 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58417 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58418 return 1;
58419 }
58420
58421 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58422 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58423 +#endif
58424 +
58425 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58426 enum autofs_notify notify)
58427 {
58428 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58429
58430 /* If this is a direct mount request create a dummy name */
58431 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58432 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58433 + /* this name does get written to userland via autofs4_write() */
58434 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58435 +#else
58436 qstr.len = sprintf(name, "%p", dentry);
58437 +#endif
58438 else {
58439 qstr.len = autofs4_getpath(sbi, dentry, &name);
58440 if (!qstr.len) {
58441 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58442 index 2722387..56059b5 100644
58443 --- a/fs/befs/endian.h
58444 +++ b/fs/befs/endian.h
58445 @@ -11,7 +11,7 @@
58446
58447 #include <asm/byteorder.h>
58448
58449 -static inline u64
58450 +static inline u64 __intentional_overflow(-1)
58451 fs64_to_cpu(const struct super_block *sb, fs64 n)
58452 {
58453 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58454 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58455 return (__force fs64)cpu_to_be64(n);
58456 }
58457
58458 -static inline u32
58459 +static inline u32 __intentional_overflow(-1)
58460 fs32_to_cpu(const struct super_block *sb, fs32 n)
58461 {
58462 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58463 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58464 return (__force fs32)cpu_to_be32(n);
58465 }
58466
58467 -static inline u16
58468 +static inline u16 __intentional_overflow(-1)
58469 fs16_to_cpu(const struct super_block *sb, fs16 n)
58470 {
58471 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58472 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58473 index 929dec0..84bd914 100644
58474 --- a/fs/binfmt_aout.c
58475 +++ b/fs/binfmt_aout.c
58476 @@ -16,6 +16,7 @@
58477 #include <linux/string.h>
58478 #include <linux/fs.h>
58479 #include <linux/file.h>
58480 +#include <linux/security.h>
58481 #include <linux/stat.h>
58482 #include <linux/fcntl.h>
58483 #include <linux/ptrace.h>
58484 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58485 #endif
58486 # define START_STACK(u) ((void __user *)u.start_stack)
58487
58488 + memset(&dump, 0, sizeof(dump));
58489 +
58490 fs = get_fs();
58491 set_fs(KERNEL_DS);
58492 has_dumped = 1;
58493 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58494
58495 /* If the size of the dump file exceeds the rlimit, then see what would happen
58496 if we wrote the stack, but not the data area. */
58497 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58498 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58499 dump.u_dsize = 0;
58500
58501 /* Make sure we have enough room to write the stack and data areas. */
58502 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58503 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58504 dump.u_ssize = 0;
58505
58506 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58507 rlim = rlimit(RLIMIT_DATA);
58508 if (rlim >= RLIM_INFINITY)
58509 rlim = ~0;
58510 +
58511 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58512 if (ex.a_data + ex.a_bss > rlim)
58513 return -ENOMEM;
58514
58515 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58516
58517 install_exec_creds(bprm);
58518
58519 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58520 + current->mm->pax_flags = 0UL;
58521 +#endif
58522 +
58523 +#ifdef CONFIG_PAX_PAGEEXEC
58524 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58525 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58526 +
58527 +#ifdef CONFIG_PAX_EMUTRAMP
58528 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58529 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58530 +#endif
58531 +
58532 +#ifdef CONFIG_PAX_MPROTECT
58533 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58534 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58535 +#endif
58536 +
58537 + }
58538 +#endif
58539 +
58540 if (N_MAGIC(ex) == OMAGIC) {
58541 unsigned long text_addr, map_size;
58542 loff_t pos;
58543 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58544 return error;
58545
58546 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58547 - PROT_READ | PROT_WRITE | PROT_EXEC,
58548 + PROT_READ | PROT_WRITE,
58549 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58550 fd_offset + ex.a_text);
58551 if (error != N_DATADDR(ex))
58552 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58553 index d8fc060..cbd44d5 100644
58554 --- a/fs/binfmt_elf.c
58555 +++ b/fs/binfmt_elf.c
58556 @@ -34,6 +34,7 @@
58557 #include <linux/utsname.h>
58558 #include <linux/coredump.h>
58559 #include <linux/sched.h>
58560 +#include <linux/xattr.h>
58561 #include <asm/uaccess.h>
58562 #include <asm/param.h>
58563 #include <asm/page.h>
58564 @@ -47,7 +48,7 @@
58565
58566 static int load_elf_binary(struct linux_binprm *bprm);
58567 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58568 - int, int, unsigned long);
58569 + int, int, unsigned long) __intentional_overflow(-1);
58570
58571 #ifdef CONFIG_USELIB
58572 static int load_elf_library(struct file *);
58573 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58574 #define elf_core_dump NULL
58575 #endif
58576
58577 +#ifdef CONFIG_PAX_MPROTECT
58578 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58579 +#endif
58580 +
58581 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58582 +static void elf_handle_mmap(struct file *file);
58583 +#endif
58584 +
58585 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58586 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58587 #else
58588 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58589 .load_binary = load_elf_binary,
58590 .load_shlib = load_elf_library,
58591 .core_dump = elf_core_dump,
58592 +
58593 +#ifdef CONFIG_PAX_MPROTECT
58594 + .handle_mprotect= elf_handle_mprotect,
58595 +#endif
58596 +
58597 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58598 + .handle_mmap = elf_handle_mmap,
58599 +#endif
58600 +
58601 .min_coredump = ELF_EXEC_PAGESIZE,
58602 };
58603
58604 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58605
58606 static int set_brk(unsigned long start, unsigned long end)
58607 {
58608 + unsigned long e = end;
58609 +
58610 start = ELF_PAGEALIGN(start);
58611 end = ELF_PAGEALIGN(end);
58612 if (end > start) {
58613 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58614 if (BAD_ADDR(addr))
58615 return addr;
58616 }
58617 - current->mm->start_brk = current->mm->brk = end;
58618 + current->mm->start_brk = current->mm->brk = e;
58619 return 0;
58620 }
58621
58622 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58623 elf_addr_t __user *u_rand_bytes;
58624 const char *k_platform = ELF_PLATFORM;
58625 const char *k_base_platform = ELF_BASE_PLATFORM;
58626 - unsigned char k_rand_bytes[16];
58627 + u32 k_rand_bytes[4];
58628 int items;
58629 elf_addr_t *elf_info;
58630 int ei_index = 0;
58631 const struct cred *cred = current_cred();
58632 struct vm_area_struct *vma;
58633 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58634
58635 /*
58636 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58637 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58638 * Generate 16 random bytes for userspace PRNG seeding.
58639 */
58640 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58641 - u_rand_bytes = (elf_addr_t __user *)
58642 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58643 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58644 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58645 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58646 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58647 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58648 + u_rand_bytes = (elf_addr_t __user *) p;
58649 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58650 return -EFAULT;
58651
58652 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58653 return -EFAULT;
58654 current->mm->env_end = p;
58655
58656 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58657 +
58658 /* Put the elf_info on the stack in the right place. */
58659 sp = (elf_addr_t __user *)envp + 1;
58660 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58661 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58662 return -EFAULT;
58663 return 0;
58664 }
58665 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58666 an ELF header */
58667
58668 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58669 - struct file *interpreter, unsigned long *interp_map_addr,
58670 - unsigned long no_base)
58671 + struct file *interpreter, unsigned long no_base)
58672 {
58673 struct elf_phdr *elf_phdata;
58674 struct elf_phdr *eppnt;
58675 - unsigned long load_addr = 0;
58676 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58677 int load_addr_set = 0;
58678 unsigned long last_bss = 0, elf_bss = 0;
58679 - unsigned long error = ~0UL;
58680 + unsigned long error = -EINVAL;
58681 unsigned long total_size;
58682 int retval, i, size;
58683
58684 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58685 goto out_close;
58686 }
58687
58688 +#ifdef CONFIG_PAX_SEGMEXEC
58689 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58690 + pax_task_size = SEGMEXEC_TASK_SIZE;
58691 +#endif
58692 +
58693 eppnt = elf_phdata;
58694 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58695 if (eppnt->p_type == PT_LOAD) {
58696 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58697 map_addr = elf_map(interpreter, load_addr + vaddr,
58698 eppnt, elf_prot, elf_type, total_size);
58699 total_size = 0;
58700 - if (!*interp_map_addr)
58701 - *interp_map_addr = map_addr;
58702 error = map_addr;
58703 if (BAD_ADDR(map_addr))
58704 goto out_close;
58705 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58706 k = load_addr + eppnt->p_vaddr;
58707 if (BAD_ADDR(k) ||
58708 eppnt->p_filesz > eppnt->p_memsz ||
58709 - eppnt->p_memsz > TASK_SIZE ||
58710 - TASK_SIZE - eppnt->p_memsz < k) {
58711 + eppnt->p_memsz > pax_task_size ||
58712 + pax_task_size - eppnt->p_memsz < k) {
58713 error = -ENOMEM;
58714 goto out_close;
58715 }
58716 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58717 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58718
58719 /* Map the last of the bss segment */
58720 - error = vm_brk(elf_bss, last_bss - elf_bss);
58721 - if (BAD_ADDR(error))
58722 - goto out_close;
58723 + if (last_bss > elf_bss) {
58724 + error = vm_brk(elf_bss, last_bss - elf_bss);
58725 + if (BAD_ADDR(error))
58726 + goto out_close;
58727 + }
58728 }
58729
58730 error = load_addr;
58731 @@ -543,6 +574,336 @@ out:
58732 return error;
58733 }
58734
58735 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58736 +#ifdef CONFIG_PAX_SOFTMODE
58737 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58738 +{
58739 + unsigned long pax_flags = 0UL;
58740 +
58741 +#ifdef CONFIG_PAX_PAGEEXEC
58742 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58743 + pax_flags |= MF_PAX_PAGEEXEC;
58744 +#endif
58745 +
58746 +#ifdef CONFIG_PAX_SEGMEXEC
58747 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58748 + pax_flags |= MF_PAX_SEGMEXEC;
58749 +#endif
58750 +
58751 +#ifdef CONFIG_PAX_EMUTRAMP
58752 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58753 + pax_flags |= MF_PAX_EMUTRAMP;
58754 +#endif
58755 +
58756 +#ifdef CONFIG_PAX_MPROTECT
58757 + if (elf_phdata->p_flags & PF_MPROTECT)
58758 + pax_flags |= MF_PAX_MPROTECT;
58759 +#endif
58760 +
58761 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58762 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58763 + pax_flags |= MF_PAX_RANDMMAP;
58764 +#endif
58765 +
58766 + return pax_flags;
58767 +}
58768 +#endif
58769 +
58770 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58771 +{
58772 + unsigned long pax_flags = 0UL;
58773 +
58774 +#ifdef CONFIG_PAX_PAGEEXEC
58775 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58776 + pax_flags |= MF_PAX_PAGEEXEC;
58777 +#endif
58778 +
58779 +#ifdef CONFIG_PAX_SEGMEXEC
58780 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58781 + pax_flags |= MF_PAX_SEGMEXEC;
58782 +#endif
58783 +
58784 +#ifdef CONFIG_PAX_EMUTRAMP
58785 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58786 + pax_flags |= MF_PAX_EMUTRAMP;
58787 +#endif
58788 +
58789 +#ifdef CONFIG_PAX_MPROTECT
58790 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58791 + pax_flags |= MF_PAX_MPROTECT;
58792 +#endif
58793 +
58794 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58795 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58796 + pax_flags |= MF_PAX_RANDMMAP;
58797 +#endif
58798 +
58799 + return pax_flags;
58800 +}
58801 +#endif
58802 +
58803 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58804 +#ifdef CONFIG_PAX_SOFTMODE
58805 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58806 +{
58807 + unsigned long pax_flags = 0UL;
58808 +
58809 +#ifdef CONFIG_PAX_PAGEEXEC
58810 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58811 + pax_flags |= MF_PAX_PAGEEXEC;
58812 +#endif
58813 +
58814 +#ifdef CONFIG_PAX_SEGMEXEC
58815 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58816 + pax_flags |= MF_PAX_SEGMEXEC;
58817 +#endif
58818 +
58819 +#ifdef CONFIG_PAX_EMUTRAMP
58820 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58821 + pax_flags |= MF_PAX_EMUTRAMP;
58822 +#endif
58823 +
58824 +#ifdef CONFIG_PAX_MPROTECT
58825 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58826 + pax_flags |= MF_PAX_MPROTECT;
58827 +#endif
58828 +
58829 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58830 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58831 + pax_flags |= MF_PAX_RANDMMAP;
58832 +#endif
58833 +
58834 + return pax_flags;
58835 +}
58836 +#endif
58837 +
58838 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58839 +{
58840 + unsigned long pax_flags = 0UL;
58841 +
58842 +#ifdef CONFIG_PAX_PAGEEXEC
58843 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58844 + pax_flags |= MF_PAX_PAGEEXEC;
58845 +#endif
58846 +
58847 +#ifdef CONFIG_PAX_SEGMEXEC
58848 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58849 + pax_flags |= MF_PAX_SEGMEXEC;
58850 +#endif
58851 +
58852 +#ifdef CONFIG_PAX_EMUTRAMP
58853 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58854 + pax_flags |= MF_PAX_EMUTRAMP;
58855 +#endif
58856 +
58857 +#ifdef CONFIG_PAX_MPROTECT
58858 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58859 + pax_flags |= MF_PAX_MPROTECT;
58860 +#endif
58861 +
58862 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58863 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58864 + pax_flags |= MF_PAX_RANDMMAP;
58865 +#endif
58866 +
58867 + return pax_flags;
58868 +}
58869 +#endif
58870 +
58871 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58872 +static unsigned long pax_parse_defaults(void)
58873 +{
58874 + unsigned long pax_flags = 0UL;
58875 +
58876 +#ifdef CONFIG_PAX_SOFTMODE
58877 + if (pax_softmode)
58878 + return pax_flags;
58879 +#endif
58880 +
58881 +#ifdef CONFIG_PAX_PAGEEXEC
58882 + pax_flags |= MF_PAX_PAGEEXEC;
58883 +#endif
58884 +
58885 +#ifdef CONFIG_PAX_SEGMEXEC
58886 + pax_flags |= MF_PAX_SEGMEXEC;
58887 +#endif
58888 +
58889 +#ifdef CONFIG_PAX_MPROTECT
58890 + pax_flags |= MF_PAX_MPROTECT;
58891 +#endif
58892 +
58893 +#ifdef CONFIG_PAX_RANDMMAP
58894 + if (randomize_va_space)
58895 + pax_flags |= MF_PAX_RANDMMAP;
58896 +#endif
58897 +
58898 + return pax_flags;
58899 +}
58900 +
58901 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58902 +{
58903 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58904 +
58905 +#ifdef CONFIG_PAX_EI_PAX
58906 +
58907 +#ifdef CONFIG_PAX_SOFTMODE
58908 + if (pax_softmode)
58909 + return pax_flags;
58910 +#endif
58911 +
58912 + pax_flags = 0UL;
58913 +
58914 +#ifdef CONFIG_PAX_PAGEEXEC
58915 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58916 + pax_flags |= MF_PAX_PAGEEXEC;
58917 +#endif
58918 +
58919 +#ifdef CONFIG_PAX_SEGMEXEC
58920 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58921 + pax_flags |= MF_PAX_SEGMEXEC;
58922 +#endif
58923 +
58924 +#ifdef CONFIG_PAX_EMUTRAMP
58925 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58926 + pax_flags |= MF_PAX_EMUTRAMP;
58927 +#endif
58928 +
58929 +#ifdef CONFIG_PAX_MPROTECT
58930 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58931 + pax_flags |= MF_PAX_MPROTECT;
58932 +#endif
58933 +
58934 +#ifdef CONFIG_PAX_ASLR
58935 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58936 + pax_flags |= MF_PAX_RANDMMAP;
58937 +#endif
58938 +
58939 +#endif
58940 +
58941 + return pax_flags;
58942 +
58943 +}
58944 +
58945 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58946 +{
58947 +
58948 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58949 + unsigned long i;
58950 +
58951 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58952 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58953 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58954 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58955 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58956 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58957 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58958 + return PAX_PARSE_FLAGS_FALLBACK;
58959 +
58960 +#ifdef CONFIG_PAX_SOFTMODE
58961 + if (pax_softmode)
58962 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58963 + else
58964 +#endif
58965 +
58966 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58967 + break;
58968 + }
58969 +#endif
58970 +
58971 + return PAX_PARSE_FLAGS_FALLBACK;
58972 +}
58973 +
58974 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58975 +{
58976 +
58977 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58978 + ssize_t xattr_size, i;
58979 + unsigned char xattr_value[sizeof("pemrs") - 1];
58980 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58981 +
58982 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58983 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58984 + return PAX_PARSE_FLAGS_FALLBACK;
58985 +
58986 + for (i = 0; i < xattr_size; i++)
58987 + switch (xattr_value[i]) {
58988 + default:
58989 + return PAX_PARSE_FLAGS_FALLBACK;
58990 +
58991 +#define parse_flag(option1, option2, flag) \
58992 + case option1: \
58993 + if (pax_flags_hardmode & MF_PAX_##flag) \
58994 + return PAX_PARSE_FLAGS_FALLBACK;\
58995 + pax_flags_hardmode |= MF_PAX_##flag; \
58996 + break; \
58997 + case option2: \
58998 + if (pax_flags_softmode & MF_PAX_##flag) \
58999 + return PAX_PARSE_FLAGS_FALLBACK;\
59000 + pax_flags_softmode |= MF_PAX_##flag; \
59001 + break;
59002 +
59003 + parse_flag('p', 'P', PAGEEXEC);
59004 + parse_flag('e', 'E', EMUTRAMP);
59005 + parse_flag('m', 'M', MPROTECT);
59006 + parse_flag('r', 'R', RANDMMAP);
59007 + parse_flag('s', 'S', SEGMEXEC);
59008 +
59009 +#undef parse_flag
59010 + }
59011 +
59012 + if (pax_flags_hardmode & pax_flags_softmode)
59013 + return PAX_PARSE_FLAGS_FALLBACK;
59014 +
59015 +#ifdef CONFIG_PAX_SOFTMODE
59016 + if (pax_softmode)
59017 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59018 + else
59019 +#endif
59020 +
59021 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59022 +#else
59023 + return PAX_PARSE_FLAGS_FALLBACK;
59024 +#endif
59025 +
59026 +}
59027 +
59028 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59029 +{
59030 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59031 +
59032 + pax_flags = pax_parse_defaults();
59033 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59034 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59035 + xattr_pax_flags = pax_parse_xattr_pax(file);
59036 +
59037 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59038 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59039 + pt_pax_flags != xattr_pax_flags)
59040 + return -EINVAL;
59041 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59042 + pax_flags = xattr_pax_flags;
59043 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59044 + pax_flags = pt_pax_flags;
59045 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59046 + pax_flags = ei_pax_flags;
59047 +
59048 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59049 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59050 + if ((__supported_pte_mask & _PAGE_NX))
59051 + pax_flags &= ~MF_PAX_SEGMEXEC;
59052 + else
59053 + pax_flags &= ~MF_PAX_PAGEEXEC;
59054 + }
59055 +#endif
59056 +
59057 + if (0 > pax_check_flags(&pax_flags))
59058 + return -EINVAL;
59059 +
59060 + current->mm->pax_flags = pax_flags;
59061 + return 0;
59062 +}
59063 +#endif
59064 +
59065 /*
59066 * These are the functions used to load ELF style executables and shared
59067 * libraries. There is no binary dependent code anywhere else.
59068 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59069 {
59070 unsigned int random_variable = 0;
59071
59072 +#ifdef CONFIG_PAX_RANDUSTACK
59073 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59074 + return stack_top - current->mm->delta_stack;
59075 +#endif
59076 +
59077 if ((current->flags & PF_RANDOMIZE) &&
59078 !(current->personality & ADDR_NO_RANDOMIZE)) {
59079 random_variable = get_random_int() & STACK_RND_MASK;
59080 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59081 unsigned long load_addr = 0, load_bias = 0;
59082 int load_addr_set = 0;
59083 char * elf_interpreter = NULL;
59084 - unsigned long error;
59085 + unsigned long error = 0;
59086 struct elf_phdr *elf_ppnt, *elf_phdata;
59087 unsigned long elf_bss, elf_brk;
59088 int retval, i;
59089 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59090 struct elfhdr elf_ex;
59091 struct elfhdr interp_elf_ex;
59092 } *loc;
59093 + unsigned long pax_task_size;
59094
59095 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59096 if (!loc) {
59097 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59098 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59099 may depend on the personality. */
59100 SET_PERSONALITY(loc->elf_ex);
59101 +
59102 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59103 + current->mm->pax_flags = 0UL;
59104 +#endif
59105 +
59106 +#ifdef CONFIG_PAX_DLRESOLVE
59107 + current->mm->call_dl_resolve = 0UL;
59108 +#endif
59109 +
59110 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59111 + current->mm->call_syscall = 0UL;
59112 +#endif
59113 +
59114 +#ifdef CONFIG_PAX_ASLR
59115 + current->mm->delta_mmap = 0UL;
59116 + current->mm->delta_stack = 0UL;
59117 +#endif
59118 +
59119 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59120 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59121 + send_sig(SIGKILL, current, 0);
59122 + goto out_free_dentry;
59123 + }
59124 +#endif
59125 +
59126 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59127 + pax_set_initial_flags(bprm);
59128 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59129 + if (pax_set_initial_flags_func)
59130 + (pax_set_initial_flags_func)(bprm);
59131 +#endif
59132 +
59133 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59134 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59135 + current->mm->context.user_cs_limit = PAGE_SIZE;
59136 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59137 + }
59138 +#endif
59139 +
59140 +#ifdef CONFIG_PAX_SEGMEXEC
59141 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59142 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59143 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59144 + pax_task_size = SEGMEXEC_TASK_SIZE;
59145 + current->mm->def_flags |= VM_NOHUGEPAGE;
59146 + } else
59147 +#endif
59148 +
59149 + pax_task_size = TASK_SIZE;
59150 +
59151 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59152 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59153 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59154 + put_cpu();
59155 + }
59156 +#endif
59157 +
59158 +#ifdef CONFIG_PAX_ASLR
59159 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59160 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59161 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59162 + }
59163 +#endif
59164 +
59165 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59166 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59167 + executable_stack = EXSTACK_DISABLE_X;
59168 + current->personality &= ~READ_IMPLIES_EXEC;
59169 + } else
59170 +#endif
59171 +
59172 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59173 current->personality |= READ_IMPLIES_EXEC;
59174
59175 @@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59176 #else
59177 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59178 #endif
59179 +
59180 +#ifdef CONFIG_PAX_RANDMMAP
59181 + /* PaX: randomize base address at the default exe base if requested */
59182 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59183 +#ifdef CONFIG_SPARC64
59184 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59185 +#else
59186 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59187 +#endif
59188 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59189 + elf_flags |= MAP_FIXED;
59190 + }
59191 +#endif
59192 +
59193 }
59194
59195 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59196 @@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59197 * allowed task size. Note that p_filesz must always be
59198 * <= p_memsz so it is only necessary to check p_memsz.
59199 */
59200 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59201 - elf_ppnt->p_memsz > TASK_SIZE ||
59202 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59203 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59204 + elf_ppnt->p_memsz > pax_task_size ||
59205 + pax_task_size - elf_ppnt->p_memsz < k) {
59206 /* set_brk can never work. Avoid overflows. */
59207 retval = -EINVAL;
59208 goto out_free_dentry;
59209 @@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
59210 if (retval)
59211 goto out_free_dentry;
59212 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59213 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59214 - goto out_free_dentry;
59215 + /*
59216 + * This bss-zeroing can fail if the ELF
59217 + * file specifies odd protections. So
59218 + * we don't check the return value
59219 + */
59220 }
59221
59222 +#ifdef CONFIG_PAX_RANDMMAP
59223 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59224 + unsigned long start, size, flags;
59225 + vm_flags_t vm_flags;
59226 +
59227 + start = ELF_PAGEALIGN(elf_brk);
59228 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59229 + flags = MAP_FIXED | MAP_PRIVATE;
59230 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59231 +
59232 + down_write(&current->mm->mmap_sem);
59233 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59234 + retval = -ENOMEM;
59235 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59236 +// if (current->personality & ADDR_NO_RANDOMIZE)
59237 +// vm_flags |= VM_READ | VM_MAYREAD;
59238 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59239 + retval = IS_ERR_VALUE(start) ? start : 0;
59240 + }
59241 + up_write(&current->mm->mmap_sem);
59242 + if (retval == 0)
59243 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59244 + if (retval < 0)
59245 + goto out_free_dentry;
59246 + }
59247 +#endif
59248 +
59249 if (elf_interpreter) {
59250 - unsigned long interp_map_addr = 0;
59251 -
59252 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59253 interpreter,
59254 - &interp_map_addr,
59255 load_bias);
59256 if (!IS_ERR((void *)elf_entry)) {
59257 /*
59258 @@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59259 * Decide what to dump of a segment, part, all or none.
59260 */
59261 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59262 - unsigned long mm_flags)
59263 + unsigned long mm_flags, long signr)
59264 {
59265 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59266
59267 @@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59268 if (vma->vm_file == NULL)
59269 return 0;
59270
59271 - if (FILTER(MAPPED_PRIVATE))
59272 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59273 goto whole;
59274
59275 /*
59276 @@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59277 {
59278 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59279 int i = 0;
59280 - do
59281 + do {
59282 i += 2;
59283 - while (auxv[i - 2] != AT_NULL);
59284 + } while (auxv[i - 2] != AT_NULL);
59285 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59286 }
59287
59288 @@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59289 {
59290 mm_segment_t old_fs = get_fs();
59291 set_fs(KERNEL_DS);
59292 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59293 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59294 set_fs(old_fs);
59295 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59296 }
59297 @@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59298 }
59299
59300 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59301 - unsigned long mm_flags)
59302 + struct coredump_params *cprm)
59303 {
59304 struct vm_area_struct *vma;
59305 size_t size = 0;
59306
59307 for (vma = first_vma(current, gate_vma); vma != NULL;
59308 vma = next_vma(vma, gate_vma))
59309 - size += vma_dump_size(vma, mm_flags);
59310 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59311 return size;
59312 }
59313
59314 @@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59315
59316 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59317
59318 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59319 + offset += elf_core_vma_data_size(gate_vma, cprm);
59320 offset += elf_core_extra_data_size();
59321 e_shoff = offset;
59322
59323 @@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59324 phdr.p_offset = offset;
59325 phdr.p_vaddr = vma->vm_start;
59326 phdr.p_paddr = 0;
59327 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59328 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59329 phdr.p_memsz = vma->vm_end - vma->vm_start;
59330 offset += phdr.p_filesz;
59331 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59332 @@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59333 unsigned long addr;
59334 unsigned long end;
59335
59336 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59337 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59338
59339 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59340 struct page *page;
59341 @@ -2195,6 +2674,167 @@ out:
59342
59343 #endif /* CONFIG_ELF_CORE */
59344
59345 +#ifdef CONFIG_PAX_MPROTECT
59346 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59347 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59348 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59349 + *
59350 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59351 + * basis because we want to allow the common case and not the special ones.
59352 + */
59353 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59354 +{
59355 + struct elfhdr elf_h;
59356 + struct elf_phdr elf_p;
59357 + unsigned long i;
59358 + unsigned long oldflags;
59359 + bool is_textrel_rw, is_textrel_rx, is_relro;
59360 +
59361 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59362 + return;
59363 +
59364 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59365 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59366 +
59367 +#ifdef CONFIG_PAX_ELFRELOCS
59368 + /* possible TEXTREL */
59369 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59370 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59371 +#else
59372 + is_textrel_rw = false;
59373 + is_textrel_rx = false;
59374 +#endif
59375 +
59376 + /* possible RELRO */
59377 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59378 +
59379 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59380 + return;
59381 +
59382 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59383 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59384 +
59385 +#ifdef CONFIG_PAX_ETEXECRELOCS
59386 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59387 +#else
59388 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59389 +#endif
59390 +
59391 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59392 + !elf_check_arch(&elf_h) ||
59393 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59394 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59395 + return;
59396 +
59397 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59398 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59399 + return;
59400 + switch (elf_p.p_type) {
59401 + case PT_DYNAMIC:
59402 + if (!is_textrel_rw && !is_textrel_rx)
59403 + continue;
59404 + i = 0UL;
59405 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59406 + elf_dyn dyn;
59407 +
59408 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59409 + break;
59410 + if (dyn.d_tag == DT_NULL)
59411 + break;
59412 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59413 + gr_log_textrel(vma);
59414 + if (is_textrel_rw)
59415 + vma->vm_flags |= VM_MAYWRITE;
59416 + else
59417 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59418 + vma->vm_flags &= ~VM_MAYWRITE;
59419 + break;
59420 + }
59421 + i++;
59422 + }
59423 + is_textrel_rw = false;
59424 + is_textrel_rx = false;
59425 + continue;
59426 +
59427 + case PT_GNU_RELRO:
59428 + if (!is_relro)
59429 + continue;
59430 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59431 + vma->vm_flags &= ~VM_MAYWRITE;
59432 + is_relro = false;
59433 + continue;
59434 +
59435 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59436 + case PT_PAX_FLAGS: {
59437 + const char *msg_mprotect = "", *msg_emutramp = "";
59438 + char *buffer_lib, *buffer_exe;
59439 +
59440 + if (elf_p.p_flags & PF_NOMPROTECT)
59441 + msg_mprotect = "MPROTECT disabled";
59442 +
59443 +#ifdef CONFIG_PAX_EMUTRAMP
59444 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59445 + msg_emutramp = "EMUTRAMP enabled";
59446 +#endif
59447 +
59448 + if (!msg_mprotect[0] && !msg_emutramp[0])
59449 + continue;
59450 +
59451 + if (!printk_ratelimit())
59452 + continue;
59453 +
59454 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59455 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59456 + if (buffer_lib && buffer_exe) {
59457 + char *path_lib, *path_exe;
59458 +
59459 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59460 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59461 +
59462 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59463 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59464 +
59465 + }
59466 + free_page((unsigned long)buffer_exe);
59467 + free_page((unsigned long)buffer_lib);
59468 + continue;
59469 + }
59470 +#endif
59471 +
59472 + }
59473 + }
59474 +}
59475 +#endif
59476 +
59477 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59478 +
59479 +extern int grsec_enable_log_rwxmaps;
59480 +
59481 +static void elf_handle_mmap(struct file *file)
59482 +{
59483 + struct elfhdr elf_h;
59484 + struct elf_phdr elf_p;
59485 + unsigned long i;
59486 +
59487 + if (!grsec_enable_log_rwxmaps)
59488 + return;
59489 +
59490 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59491 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59492 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59493 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59494 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59495 + return;
59496 +
59497 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59498 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59499 + return;
59500 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59501 + gr_log_ptgnustack(file);
59502 + }
59503 +}
59504 +#endif
59505 +
59506 static int __init init_elf_binfmt(void)
59507 {
59508 register_binfmt(&elf_format);
59509 diff --git a/fs/block_dev.c b/fs/block_dev.c
59510 index 1d9c9f3..2905786 100644
59511 --- a/fs/block_dev.c
59512 +++ b/fs/block_dev.c
59513 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59514 else if (bdev->bd_contains == bdev)
59515 return true; /* is a whole device which isn't held */
59516
59517 - else if (whole->bd_holder == bd_may_claim)
59518 + else if (whole->bd_holder == (void *)bd_may_claim)
59519 return true; /* is a partition of a device that is being partitioned */
59520 else if (whole->bd_holder != NULL)
59521 return false; /* is a partition of a held device */
59522 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59523 index 150822e..75bb326 100644
59524 --- a/fs/btrfs/ctree.c
59525 +++ b/fs/btrfs/ctree.c
59526 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59527 free_extent_buffer(buf);
59528 add_root_to_dirty_list(root);
59529 } else {
59530 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59531 - parent_start = parent->start;
59532 - else
59533 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59534 + if (parent)
59535 + parent_start = parent->start;
59536 + else
59537 + parent_start = 0;
59538 + } else
59539 parent_start = 0;
59540
59541 WARN_ON(trans->transid != btrfs_header_generation(parent));
59542 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59543 index de4e70f..b41dc45 100644
59544 --- a/fs/btrfs/delayed-inode.c
59545 +++ b/fs/btrfs/delayed-inode.c
59546 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59547
59548 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59549 {
59550 - int seq = atomic_inc_return(&delayed_root->items_seq);
59551 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59552 if ((atomic_dec_return(&delayed_root->items) <
59553 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59554 waitqueue_active(&delayed_root->wait))
59555 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59556
59557 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59558 {
59559 - int val = atomic_read(&delayed_root->items_seq);
59560 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59561
59562 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59563 return 1;
59564 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59565 int seq;
59566 int ret;
59567
59568 - seq = atomic_read(&delayed_root->items_seq);
59569 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59570
59571 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59572 if (ret)
59573 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59574 index f70119f..ab5894d 100644
59575 --- a/fs/btrfs/delayed-inode.h
59576 +++ b/fs/btrfs/delayed-inode.h
59577 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59578 */
59579 struct list_head prepare_list;
59580 atomic_t items; /* for delayed items */
59581 - atomic_t items_seq; /* for delayed items */
59582 + atomic_unchecked_t items_seq; /* for delayed items */
59583 int nodes; /* for delayed nodes */
59584 wait_queue_head_t wait;
59585 };
59586 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59587 struct btrfs_delayed_root *delayed_root)
59588 {
59589 atomic_set(&delayed_root->items, 0);
59590 - atomic_set(&delayed_root->items_seq, 0);
59591 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59592 delayed_root->nodes = 0;
59593 spin_lock_init(&delayed_root->lock);
59594 init_waitqueue_head(&delayed_root->wait);
59595 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59596 index 4399f0c..a34d8b4 100644
59597 --- a/fs/btrfs/ioctl.c
59598 +++ b/fs/btrfs/ioctl.c
59599 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59600 for (i = 0; i < num_types; i++) {
59601 struct btrfs_space_info *tmp;
59602
59603 + /* Don't copy in more than we allocated */
59604 if (!slot_count)
59605 break;
59606
59607 + slot_count--;
59608 +
59609 info = NULL;
59610 rcu_read_lock();
59611 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59612 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59613 memcpy(dest, &space, sizeof(space));
59614 dest++;
59615 space_args.total_spaces++;
59616 - slot_count--;
59617 }
59618 - if (!slot_count)
59619 - break;
59620 }
59621 up_read(&info->groups_sem);
59622 }
59623 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59624 index cde9c03..ad4d4db 100644
59625 --- a/fs/btrfs/super.c
59626 +++ b/fs/btrfs/super.c
59627 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59628 function, line, errstr);
59629 return;
59630 }
59631 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59632 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59633 /* Wake up anybody who may be waiting on this transaction */
59634 wake_up(&root->fs_info->transaction_wait);
59635 wake_up(&root->fs_info->transaction_blocked_wait);
59636 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59637 index b2e7bb4..3719201 100644
59638 --- a/fs/btrfs/sysfs.c
59639 +++ b/fs/btrfs/sysfs.c
59640 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59641 for (set = 0; set < FEAT_MAX; set++) {
59642 int i;
59643 struct attribute *attrs[2];
59644 - struct attribute_group agroup = {
59645 + attribute_group_no_const agroup = {
59646 .name = "features",
59647 .attrs = attrs,
59648 };
59649 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59650 index 2299bfd..4098e72 100644
59651 --- a/fs/btrfs/tests/free-space-tests.c
59652 +++ b/fs/btrfs/tests/free-space-tests.c
59653 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59654 * extent entry.
59655 */
59656 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59657 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59658 + pax_open_kernel();
59659 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59660 + pax_close_kernel();
59661
59662 /*
59663 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59664 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59665 if (ret)
59666 return ret;
59667
59668 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59669 + pax_open_kernel();
59670 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59671 + pax_close_kernel();
59672 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59673
59674 return 0;
59675 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59676 index 154990c..d0cf699 100644
59677 --- a/fs/btrfs/tree-log.h
59678 +++ b/fs/btrfs/tree-log.h
59679 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59680 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59681 struct btrfs_trans_handle *trans)
59682 {
59683 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59684 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59685 }
59686
59687 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59688 diff --git a/fs/buffer.c b/fs/buffer.c
59689 index 20805db..2e8fc69 100644
59690 --- a/fs/buffer.c
59691 +++ b/fs/buffer.c
59692 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59693 bh_cachep = kmem_cache_create("buffer_head",
59694 sizeof(struct buffer_head), 0,
59695 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59696 - SLAB_MEM_SPREAD),
59697 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59698 NULL);
59699
59700 /*
59701 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59702 index fbb08e9..0fda764 100644
59703 --- a/fs/cachefiles/bind.c
59704 +++ b/fs/cachefiles/bind.c
59705 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59706 args);
59707
59708 /* start by checking things over */
59709 - ASSERT(cache->fstop_percent >= 0 &&
59710 - cache->fstop_percent < cache->fcull_percent &&
59711 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59712 cache->fcull_percent < cache->frun_percent &&
59713 cache->frun_percent < 100);
59714
59715 - ASSERT(cache->bstop_percent >= 0 &&
59716 - cache->bstop_percent < cache->bcull_percent &&
59717 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59718 cache->bcull_percent < cache->brun_percent &&
59719 cache->brun_percent < 100);
59720
59721 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59722 index ce1b115..4a6852c 100644
59723 --- a/fs/cachefiles/daemon.c
59724 +++ b/fs/cachefiles/daemon.c
59725 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59726 if (n > buflen)
59727 return -EMSGSIZE;
59728
59729 - if (copy_to_user(_buffer, buffer, n) != 0)
59730 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59731 return -EFAULT;
59732
59733 return n;
59734 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59735 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59736 return -EIO;
59737
59738 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59739 + if (datalen > PAGE_SIZE - 1)
59740 return -EOPNOTSUPP;
59741
59742 /* drag the command string into the kernel so we can parse it */
59743 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59744 if (args[0] != '%' || args[1] != '\0')
59745 return -EINVAL;
59746
59747 - if (fstop < 0 || fstop >= cache->fcull_percent)
59748 + if (fstop >= cache->fcull_percent)
59749 return cachefiles_daemon_range_error(cache, args);
59750
59751 cache->fstop_percent = fstop;
59752 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59753 if (args[0] != '%' || args[1] != '\0')
59754 return -EINVAL;
59755
59756 - if (bstop < 0 || bstop >= cache->bcull_percent)
59757 + if (bstop >= cache->bcull_percent)
59758 return cachefiles_daemon_range_error(cache, args);
59759
59760 cache->bstop_percent = bstop;
59761 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59762 index 8c52472..c4e3a69 100644
59763 --- a/fs/cachefiles/internal.h
59764 +++ b/fs/cachefiles/internal.h
59765 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59766 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59767 struct rb_root active_nodes; /* active nodes (can't be culled) */
59768 rwlock_t active_lock; /* lock for active_nodes */
59769 - atomic_t gravecounter; /* graveyard uniquifier */
59770 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59771 unsigned frun_percent; /* when to stop culling (% files) */
59772 unsigned fcull_percent; /* when to start culling (% files) */
59773 unsigned fstop_percent; /* when to stop allocating (% files) */
59774 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59775 * proc.c
59776 */
59777 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59778 -extern atomic_t cachefiles_lookup_histogram[HZ];
59779 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59780 -extern atomic_t cachefiles_create_histogram[HZ];
59781 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59782 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59783 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59784
59785 extern int __init cachefiles_proc_init(void);
59786 extern void cachefiles_proc_cleanup(void);
59787 static inline
59788 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59789 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59790 {
59791 unsigned long jif = jiffies - start_jif;
59792 if (jif >= HZ)
59793 jif = HZ - 1;
59794 - atomic_inc(&histogram[jif]);
59795 + atomic_inc_unchecked(&histogram[jif]);
59796 }
59797
59798 #else
59799 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59800 index e12f189..ed17244 100644
59801 --- a/fs/cachefiles/namei.c
59802 +++ b/fs/cachefiles/namei.c
59803 @@ -312,7 +312,7 @@ try_again:
59804 /* first step is to make up a grave dentry in the graveyard */
59805 sprintf(nbuffer, "%08x%08x",
59806 (uint32_t) get_seconds(),
59807 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59808 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59809
59810 /* do the multiway lock magic */
59811 trap = lock_rename(cache->graveyard, dir);
59812 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59813 index eccd339..4c1d995 100644
59814 --- a/fs/cachefiles/proc.c
59815 +++ b/fs/cachefiles/proc.c
59816 @@ -14,9 +14,9 @@
59817 #include <linux/seq_file.h>
59818 #include "internal.h"
59819
59820 -atomic_t cachefiles_lookup_histogram[HZ];
59821 -atomic_t cachefiles_mkdir_histogram[HZ];
59822 -atomic_t cachefiles_create_histogram[HZ];
59823 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59824 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59825 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59826
59827 /*
59828 * display the latency histogram
59829 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59830 return 0;
59831 default:
59832 index = (unsigned long) v - 3;
59833 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59834 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59835 - z = atomic_read(&cachefiles_create_histogram[index]);
59836 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59837 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59838 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59839 if (x == 0 && y == 0 && z == 0)
59840 return 0;
59841
59842 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59843 index 695e788..f4a9d4d 100644
59844 --- a/fs/ceph/dir.c
59845 +++ b/fs/ceph/dir.c
59846 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59847 struct dentry *dentry, *last;
59848 struct ceph_dentry_info *di;
59849 int err = 0;
59850 + char d_name[DNAME_INLINE_LEN];
59851 + const unsigned char *name;
59852
59853 /* claim ref on last dentry we returned */
59854 last = fi->dentry;
59855 @@ -192,7 +194,12 @@ more:
59856
59857 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59858 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59859 - if (!dir_emit(ctx, dentry->d_name.name,
59860 + name = dentry->d_name.name;
59861 + if (name == dentry->d_iname) {
59862 + memcpy(d_name, name, dentry->d_name.len);
59863 + name = d_name;
59864 + }
59865 + if (!dir_emit(ctx, name,
59866 dentry->d_name.len,
59867 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59868 dentry->d_inode->i_mode >> 12)) {
59869 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59870 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59871 struct ceph_mds_client *mdsc = fsc->mdsc;
59872 unsigned frag = fpos_frag(ctx->pos);
59873 - int off = fpos_off(ctx->pos);
59874 + unsigned int off = fpos_off(ctx->pos);
59875 int err;
59876 u32 ftype;
59877 struct ceph_mds_reply_info_parsed *rinfo;
59878 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59879 index f6e1237..796ffd1 100644
59880 --- a/fs/ceph/super.c
59881 +++ b/fs/ceph/super.c
59882 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59883 /*
59884 * construct our own bdi so we can control readahead, etc.
59885 */
59886 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59887 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59888
59889 static int ceph_register_bdi(struct super_block *sb,
59890 struct ceph_fs_client *fsc)
59891 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59892 default_backing_dev_info.ra_pages;
59893
59894 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59895 - atomic_long_inc_return(&bdi_seq));
59896 + atomic_long_inc_return_unchecked(&bdi_seq));
59897 if (!err)
59898 sb->s_bdi = &fsc->backing_dev_info;
59899 return err;
59900 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59901 index 44ec726..11a056f 100644
59902 --- a/fs/cifs/cifs_debug.c
59903 +++ b/fs/cifs/cifs_debug.c
59904 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59905
59906 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59907 #ifdef CONFIG_CIFS_STATS2
59908 - atomic_set(&totBufAllocCount, 0);
59909 - atomic_set(&totSmBufAllocCount, 0);
59910 + atomic_set_unchecked(&totBufAllocCount, 0);
59911 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59912 #endif /* CONFIG_CIFS_STATS2 */
59913 spin_lock(&cifs_tcp_ses_lock);
59914 list_for_each(tmp1, &cifs_tcp_ses_list) {
59915 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59916 tcon = list_entry(tmp3,
59917 struct cifs_tcon,
59918 tcon_list);
59919 - atomic_set(&tcon->num_smbs_sent, 0);
59920 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59921 if (server->ops->clear_stats)
59922 server->ops->clear_stats(tcon);
59923 }
59924 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59925 smBufAllocCount.counter, cifs_min_small);
59926 #ifdef CONFIG_CIFS_STATS2
59927 seq_printf(m, "Total Large %d Small %d Allocations\n",
59928 - atomic_read(&totBufAllocCount),
59929 - atomic_read(&totSmBufAllocCount));
59930 + atomic_read_unchecked(&totBufAllocCount),
59931 + atomic_read_unchecked(&totSmBufAllocCount));
59932 #endif /* CONFIG_CIFS_STATS2 */
59933
59934 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59935 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59936 if (tcon->need_reconnect)
59937 seq_puts(m, "\tDISCONNECTED ");
59938 seq_printf(m, "\nSMBs: %d",
59939 - atomic_read(&tcon->num_smbs_sent));
59940 + atomic_read_unchecked(&tcon->num_smbs_sent));
59941 if (server->ops->print_stats)
59942 server->ops->print_stats(m, tcon);
59943 }
59944 @@ -615,9 +615,11 @@ cifs_security_flags_handle_must_flags(unsigned int *flags)
59945 *flags = CIFSSEC_MUST_NTLMV2;
59946 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
59947 *flags = CIFSSEC_MUST_NTLM;
59948 - else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59949 + else if (CIFSSEC_MUST_LANMAN &&
59950 + (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59951 *flags = CIFSSEC_MUST_LANMAN;
59952 - else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59953 + else if (CIFSSEC_MUST_PLNTXT &&
59954 + (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59955 *flags = CIFSSEC_MUST_PLNTXT;
59956
59957 *flags |= signflags;
59958 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59959 index 9d7996e..35ad5cf4 100644
59960 --- a/fs/cifs/cifsfs.c
59961 +++ b/fs/cifs/cifsfs.c
59962 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59963 */
59964 cifs_req_cachep = kmem_cache_create("cifs_request",
59965 CIFSMaxBufSize + max_hdr_size, 0,
59966 - SLAB_HWCACHE_ALIGN, NULL);
59967 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59968 if (cifs_req_cachep == NULL)
59969 return -ENOMEM;
59970
59971 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59972 efficient to alloc 1 per page off the slab compared to 17K (5page)
59973 alloc of large cifs buffers even when page debugging is on */
59974 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59975 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59976 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59977 NULL);
59978 if (cifs_sm_req_cachep == NULL) {
59979 mempool_destroy(cifs_req_poolp);
59980 @@ -1205,8 +1205,8 @@ init_cifs(void)
59981 atomic_set(&bufAllocCount, 0);
59982 atomic_set(&smBufAllocCount, 0);
59983 #ifdef CONFIG_CIFS_STATS2
59984 - atomic_set(&totBufAllocCount, 0);
59985 - atomic_set(&totSmBufAllocCount, 0);
59986 + atomic_set_unchecked(&totBufAllocCount, 0);
59987 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59988 #endif /* CONFIG_CIFS_STATS2 */
59989
59990 atomic_set(&midCount, 0);
59991 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59992 index 02a33e5..3a28b5a 100644
59993 --- a/fs/cifs/cifsglob.h
59994 +++ b/fs/cifs/cifsglob.h
59995 @@ -823,35 +823,35 @@ struct cifs_tcon {
59996 __u16 Flags; /* optional support bits */
59997 enum statusEnum tidStatus;
59998 #ifdef CONFIG_CIFS_STATS
59999 - atomic_t num_smbs_sent;
60000 + atomic_unchecked_t num_smbs_sent;
60001 union {
60002 struct {
60003 - atomic_t num_writes;
60004 - atomic_t num_reads;
60005 - atomic_t num_flushes;
60006 - atomic_t num_oplock_brks;
60007 - atomic_t num_opens;
60008 - atomic_t num_closes;
60009 - atomic_t num_deletes;
60010 - atomic_t num_mkdirs;
60011 - atomic_t num_posixopens;
60012 - atomic_t num_posixmkdirs;
60013 - atomic_t num_rmdirs;
60014 - atomic_t num_renames;
60015 - atomic_t num_t2renames;
60016 - atomic_t num_ffirst;
60017 - atomic_t num_fnext;
60018 - atomic_t num_fclose;
60019 - atomic_t num_hardlinks;
60020 - atomic_t num_symlinks;
60021 - atomic_t num_locks;
60022 - atomic_t num_acl_get;
60023 - atomic_t num_acl_set;
60024 + atomic_unchecked_t num_writes;
60025 + atomic_unchecked_t num_reads;
60026 + atomic_unchecked_t num_flushes;
60027 + atomic_unchecked_t num_oplock_brks;
60028 + atomic_unchecked_t num_opens;
60029 + atomic_unchecked_t num_closes;
60030 + atomic_unchecked_t num_deletes;
60031 + atomic_unchecked_t num_mkdirs;
60032 + atomic_unchecked_t num_posixopens;
60033 + atomic_unchecked_t num_posixmkdirs;
60034 + atomic_unchecked_t num_rmdirs;
60035 + atomic_unchecked_t num_renames;
60036 + atomic_unchecked_t num_t2renames;
60037 + atomic_unchecked_t num_ffirst;
60038 + atomic_unchecked_t num_fnext;
60039 + atomic_unchecked_t num_fclose;
60040 + atomic_unchecked_t num_hardlinks;
60041 + atomic_unchecked_t num_symlinks;
60042 + atomic_unchecked_t num_locks;
60043 + atomic_unchecked_t num_acl_get;
60044 + atomic_unchecked_t num_acl_set;
60045 } cifs_stats;
60046 #ifdef CONFIG_CIFS_SMB2
60047 struct {
60048 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60049 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60050 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60051 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60052 } smb2_stats;
60053 #endif /* CONFIG_CIFS_SMB2 */
60054 } stats;
60055 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
60056 }
60057
60058 #ifdef CONFIG_CIFS_STATS
60059 -#define cifs_stats_inc atomic_inc
60060 +#define cifs_stats_inc atomic_inc_unchecked
60061
60062 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60063 unsigned int bytes)
60064 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60065 /* Various Debug counters */
60066 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60067 #ifdef CONFIG_CIFS_STATS2
60068 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60069 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60070 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60071 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60072 #endif
60073 GLOBAL_EXTERN atomic_t smBufAllocCount;
60074 GLOBAL_EXTERN atomic_t midCount;
60075 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60076 index 9a7b6947..4132187 100644
60077 --- a/fs/cifs/file.c
60078 +++ b/fs/cifs/file.c
60079 @@ -2060,10 +2060,14 @@ static int cifs_writepages(struct address_space *mapping,
60080 index = mapping->writeback_index; /* Start from prev offset */
60081 end = -1;
60082 } else {
60083 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60084 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60085 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60086 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60087 range_whole = true;
60088 + index = 0;
60089 + end = ULONG_MAX;
60090 + } else {
60091 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60092 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60093 + }
60094 scanned = true;
60095 }
60096 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60097 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60098 index b7415d5..3984ec0 100644
60099 --- a/fs/cifs/misc.c
60100 +++ b/fs/cifs/misc.c
60101 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60102 memset(ret_buf, 0, buf_size + 3);
60103 atomic_inc(&bufAllocCount);
60104 #ifdef CONFIG_CIFS_STATS2
60105 - atomic_inc(&totBufAllocCount);
60106 + atomic_inc_unchecked(&totBufAllocCount);
60107 #endif /* CONFIG_CIFS_STATS2 */
60108 }
60109
60110 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60111 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60112 atomic_inc(&smBufAllocCount);
60113 #ifdef CONFIG_CIFS_STATS2
60114 - atomic_inc(&totSmBufAllocCount);
60115 + atomic_inc_unchecked(&totSmBufAllocCount);
60116 #endif /* CONFIG_CIFS_STATS2 */
60117
60118 }
60119 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60120 index d297903..1cb7516 100644
60121 --- a/fs/cifs/smb1ops.c
60122 +++ b/fs/cifs/smb1ops.c
60123 @@ -622,27 +622,27 @@ static void
60124 cifs_clear_stats(struct cifs_tcon *tcon)
60125 {
60126 #ifdef CONFIG_CIFS_STATS
60127 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60128 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60129 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60130 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60131 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60132 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60133 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60134 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60135 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60136 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60137 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60138 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60139 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60140 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60141 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60142 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60143 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60144 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60145 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60146 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60147 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60148 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60149 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60150 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60151 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60152 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60153 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60154 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60155 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60156 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60157 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60158 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60159 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60160 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60161 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60162 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60163 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60164 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60165 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60166 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60167 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60168 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60169 #endif
60170 }
60171
60172 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60173 {
60174 #ifdef CONFIG_CIFS_STATS
60175 seq_printf(m, " Oplocks breaks: %d",
60176 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60177 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60178 seq_printf(m, "\nReads: %d Bytes: %llu",
60179 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60180 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60181 (long long)(tcon->bytes_read));
60182 seq_printf(m, "\nWrites: %d Bytes: %llu",
60183 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60184 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60185 (long long)(tcon->bytes_written));
60186 seq_printf(m, "\nFlushes: %d",
60187 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60188 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60189 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60190 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60191 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60192 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60193 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60194 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60195 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60196 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60197 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60198 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60199 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60200 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60201 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60202 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60203 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60204 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60205 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60206 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60207 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60208 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60209 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60210 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60211 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60212 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60213 seq_printf(m, "\nRenames: %d T2 Renames %d",
60214 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60215 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60216 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60217 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60218 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60219 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60220 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60221 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60222 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60223 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60224 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60225 #endif
60226 }
60227
60228 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60229 index c5f521b..1a40865 100644
60230 --- a/fs/cifs/smb2ops.c
60231 +++ b/fs/cifs/smb2ops.c
60232 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60233 #ifdef CONFIG_CIFS_STATS
60234 int i;
60235 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60236 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60237 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60238 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60239 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60240 }
60241 #endif
60242 }
60243 @@ -458,65 +458,65 @@ static void
60244 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60245 {
60246 #ifdef CONFIG_CIFS_STATS
60247 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60248 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60249 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60250 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60251 seq_printf(m, "\nNegotiates: %d sent %d failed",
60252 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60253 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60254 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60255 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60256 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60257 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60258 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60259 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60260 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60261 seq_printf(m, "\nLogoffs: %d sent %d failed",
60262 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60263 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60264 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60265 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60266 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60267 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60268 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60269 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60270 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60271 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60272 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60273 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60274 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60275 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60276 seq_printf(m, "\nCreates: %d sent %d failed",
60277 - atomic_read(&sent[SMB2_CREATE_HE]),
60278 - atomic_read(&failed[SMB2_CREATE_HE]));
60279 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60280 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60281 seq_printf(m, "\nCloses: %d sent %d failed",
60282 - atomic_read(&sent[SMB2_CLOSE_HE]),
60283 - atomic_read(&failed[SMB2_CLOSE_HE]));
60284 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60285 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60286 seq_printf(m, "\nFlushes: %d sent %d failed",
60287 - atomic_read(&sent[SMB2_FLUSH_HE]),
60288 - atomic_read(&failed[SMB2_FLUSH_HE]));
60289 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60290 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60291 seq_printf(m, "\nReads: %d sent %d failed",
60292 - atomic_read(&sent[SMB2_READ_HE]),
60293 - atomic_read(&failed[SMB2_READ_HE]));
60294 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60295 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60296 seq_printf(m, "\nWrites: %d sent %d failed",
60297 - atomic_read(&sent[SMB2_WRITE_HE]),
60298 - atomic_read(&failed[SMB2_WRITE_HE]));
60299 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60300 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60301 seq_printf(m, "\nLocks: %d sent %d failed",
60302 - atomic_read(&sent[SMB2_LOCK_HE]),
60303 - atomic_read(&failed[SMB2_LOCK_HE]));
60304 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60305 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60306 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60307 - atomic_read(&sent[SMB2_IOCTL_HE]),
60308 - atomic_read(&failed[SMB2_IOCTL_HE]));
60309 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60310 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60311 seq_printf(m, "\nCancels: %d sent %d failed",
60312 - atomic_read(&sent[SMB2_CANCEL_HE]),
60313 - atomic_read(&failed[SMB2_CANCEL_HE]));
60314 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60315 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60316 seq_printf(m, "\nEchos: %d sent %d failed",
60317 - atomic_read(&sent[SMB2_ECHO_HE]),
60318 - atomic_read(&failed[SMB2_ECHO_HE]));
60319 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60320 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60321 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60322 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60323 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60324 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60325 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60326 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60327 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60328 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60329 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60330 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60331 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60332 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60333 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60334 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60335 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60336 seq_printf(m, "\nSetInfos: %d sent %d failed",
60337 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60338 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60339 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60340 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60341 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60342 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60343 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60344 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60345 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60346 #endif
60347 }
60348
60349 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60350 index 8f1672b..af339c07 100644
60351 --- a/fs/cifs/smb2pdu.c
60352 +++ b/fs/cifs/smb2pdu.c
60353 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60354 default:
60355 cifs_dbg(VFS, "info level %u isn't supported\n",
60356 srch_inf->info_level);
60357 - rc = -EINVAL;
60358 - goto qdir_exit;
60359 + return -EINVAL;
60360 }
60361
60362 req->FileIndex = cpu_to_le32(index);
60363 diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
60364 index 6c15663..a4232ec 100644
60365 --- a/fs/cifs/smbencrypt.c
60366 +++ b/fs/cifs/smbencrypt.c
60367 @@ -221,7 +221,7 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16,
60368 }
60369
60370 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16));
60371 - memset(wpwd, 0, 129 * sizeof(__le16));
60372 + memzero_explicit(wpwd, sizeof(wpwd));
60373
60374 return rc;
60375 }
60376 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60377 index 46ee6f2..89a9e7f 100644
60378 --- a/fs/coda/cache.c
60379 +++ b/fs/coda/cache.c
60380 @@ -24,7 +24,7 @@
60381 #include "coda_linux.h"
60382 #include "coda_cache.h"
60383
60384 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60385 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60386
60387 /* replace or extend an acl cache hit */
60388 void coda_cache_enter(struct inode *inode, int mask)
60389 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60390 struct coda_inode_info *cii = ITOC(inode);
60391
60392 spin_lock(&cii->c_lock);
60393 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60394 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60395 if (!uid_eq(cii->c_uid, current_fsuid())) {
60396 cii->c_uid = current_fsuid();
60397 cii->c_cached_perm = mask;
60398 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60399 {
60400 struct coda_inode_info *cii = ITOC(inode);
60401 spin_lock(&cii->c_lock);
60402 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60403 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60404 spin_unlock(&cii->c_lock);
60405 }
60406
60407 /* remove all acl caches */
60408 void coda_cache_clear_all(struct super_block *sb)
60409 {
60410 - atomic_inc(&permission_epoch);
60411 + atomic_inc_unchecked(&permission_epoch);
60412 }
60413
60414
60415 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60416 spin_lock(&cii->c_lock);
60417 hit = (mask & cii->c_cached_perm) == mask &&
60418 uid_eq(cii->c_uid, current_fsuid()) &&
60419 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60420 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60421 spin_unlock(&cii->c_lock);
60422
60423 return hit;
60424 diff --git a/fs/compat.c b/fs/compat.c
60425 index b13df99..6f6f4a3 100644
60426 --- a/fs/compat.c
60427 +++ b/fs/compat.c
60428 @@ -54,7 +54,7 @@
60429 #include <asm/ioctls.h>
60430 #include "internal.h"
60431
60432 -int compat_log = 1;
60433 +int compat_log = 0;
60434
60435 int compat_printk(const char *fmt, ...)
60436 {
60437 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60438
60439 set_fs(KERNEL_DS);
60440 /* The __user pointer cast is valid because of the set_fs() */
60441 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60442 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60443 set_fs(oldfs);
60444 /* truncating is ok because it's a user address */
60445 if (!ret)
60446 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60447 goto out;
60448
60449 ret = -EINVAL;
60450 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60451 + if (nr_segs > UIO_MAXIOV)
60452 goto out;
60453 if (nr_segs > fast_segs) {
60454 ret = -ENOMEM;
60455 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60456 struct compat_readdir_callback {
60457 struct dir_context ctx;
60458 struct compat_old_linux_dirent __user *dirent;
60459 + struct file * file;
60460 int result;
60461 };
60462
60463 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60464 buf->result = -EOVERFLOW;
60465 return -EOVERFLOW;
60466 }
60467 +
60468 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60469 + return 0;
60470 +
60471 buf->result++;
60472 dirent = buf->dirent;
60473 if (!access_ok(VERIFY_WRITE, dirent,
60474 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60475 if (!f.file)
60476 return -EBADF;
60477
60478 + buf.file = f.file;
60479 error = iterate_dir(f.file, &buf.ctx);
60480 if (buf.result)
60481 error = buf.result;
60482 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60483 struct dir_context ctx;
60484 struct compat_linux_dirent __user *current_dir;
60485 struct compat_linux_dirent __user *previous;
60486 + struct file * file;
60487 int count;
60488 int error;
60489 };
60490 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60491 buf->error = -EOVERFLOW;
60492 return -EOVERFLOW;
60493 }
60494 +
60495 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60496 + return 0;
60497 +
60498 dirent = buf->previous;
60499 if (dirent) {
60500 if (__put_user(offset, &dirent->d_off))
60501 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60502 if (!f.file)
60503 return -EBADF;
60504
60505 + buf.file = f.file;
60506 error = iterate_dir(f.file, &buf.ctx);
60507 if (error >= 0)
60508 error = buf.error;
60509 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60510 struct dir_context ctx;
60511 struct linux_dirent64 __user *current_dir;
60512 struct linux_dirent64 __user *previous;
60513 + struct file * file;
60514 int count;
60515 int error;
60516 };
60517 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60518 buf->error = -EINVAL; /* only used if we fail.. */
60519 if (reclen > buf->count)
60520 return -EINVAL;
60521 +
60522 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60523 + return 0;
60524 +
60525 dirent = buf->previous;
60526
60527 if (dirent) {
60528 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60529 if (!f.file)
60530 return -EBADF;
60531
60532 + buf.file = f.file;
60533 error = iterate_dir(f.file, &buf.ctx);
60534 if (error >= 0)
60535 error = buf.error;
60536 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60537 index 4d24d17..4f8c09e 100644
60538 --- a/fs/compat_binfmt_elf.c
60539 +++ b/fs/compat_binfmt_elf.c
60540 @@ -30,11 +30,13 @@
60541 #undef elf_phdr
60542 #undef elf_shdr
60543 #undef elf_note
60544 +#undef elf_dyn
60545 #undef elf_addr_t
60546 #define elfhdr elf32_hdr
60547 #define elf_phdr elf32_phdr
60548 #define elf_shdr elf32_shdr
60549 #define elf_note elf32_note
60550 +#define elf_dyn Elf32_Dyn
60551 #define elf_addr_t Elf32_Addr
60552
60553 /*
60554 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60555 index afec645..9c65620 100644
60556 --- a/fs/compat_ioctl.c
60557 +++ b/fs/compat_ioctl.c
60558 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60559 return -EFAULT;
60560 if (__get_user(udata, &ss32->iomem_base))
60561 return -EFAULT;
60562 - ss.iomem_base = compat_ptr(udata);
60563 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60564 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60565 __get_user(ss.port_high, &ss32->port_high))
60566 return -EFAULT;
60567 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60568 for (i = 0; i < nmsgs; i++) {
60569 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60570 return -EFAULT;
60571 - if (get_user(datap, &umsgs[i].buf) ||
60572 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60573 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60574 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60575 return -EFAULT;
60576 }
60577 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60578 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60579 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60580 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60581 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60582 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60583 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60584 return -EFAULT;
60585
60586 return ioctl_preallocate(file, p);
60587 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60588 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60589 {
60590 unsigned int a, b;
60591 - a = *(unsigned int *)p;
60592 - b = *(unsigned int *)q;
60593 + a = *(const unsigned int *)p;
60594 + b = *(const unsigned int *)q;
60595 if (a > b)
60596 return 1;
60597 if (a < b)
60598 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60599 index 668dcab..daebcd6 100644
60600 --- a/fs/configfs/dir.c
60601 +++ b/fs/configfs/dir.c
60602 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60603 }
60604 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60605 struct configfs_dirent *next;
60606 - const char *name;
60607 + const unsigned char * name;
60608 + char d_name[sizeof(next->s_dentry->d_iname)];
60609 int len;
60610 struct inode *inode = NULL;
60611
60612 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60613 continue;
60614
60615 name = configfs_get_name(next);
60616 - len = strlen(name);
60617 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60618 + len = next->s_dentry->d_name.len;
60619 + memcpy(d_name, name, len);
60620 + name = d_name;
60621 + } else
60622 + len = strlen(name);
60623
60624 /*
60625 * We'll have a dentry and an inode for
60626 diff --git a/fs/coredump.c b/fs/coredump.c
60627 index b5c86ff..0dac262 100644
60628 --- a/fs/coredump.c
60629 +++ b/fs/coredump.c
60630 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60631 struct pipe_inode_info *pipe = file->private_data;
60632
60633 pipe_lock(pipe);
60634 - pipe->readers++;
60635 - pipe->writers--;
60636 + atomic_inc(&pipe->readers);
60637 + atomic_dec(&pipe->writers);
60638 wake_up_interruptible_sync(&pipe->wait);
60639 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60640 pipe_unlock(pipe);
60641 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60642 * We actually want wait_event_freezable() but then we need
60643 * to clear TIF_SIGPENDING and improve dump_interrupted().
60644 */
60645 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60646 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60647
60648 pipe_lock(pipe);
60649 - pipe->readers--;
60650 - pipe->writers++;
60651 + atomic_dec(&pipe->readers);
60652 + atomic_inc(&pipe->writers);
60653 pipe_unlock(pipe);
60654 }
60655
60656 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60657 struct files_struct *displaced;
60658 bool need_nonrelative = false;
60659 bool core_dumped = false;
60660 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60661 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60662 + long signr = siginfo->si_signo;
60663 + int dumpable;
60664 struct coredump_params cprm = {
60665 .siginfo = siginfo,
60666 .regs = signal_pt_regs(),
60667 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60668 .mm_flags = mm->flags,
60669 };
60670
60671 - audit_core_dumps(siginfo->si_signo);
60672 + audit_core_dumps(signr);
60673 +
60674 + dumpable = __get_dumpable(cprm.mm_flags);
60675 +
60676 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60677 + gr_handle_brute_attach(dumpable);
60678
60679 binfmt = mm->binfmt;
60680 if (!binfmt || !binfmt->core_dump)
60681 goto fail;
60682 - if (!__get_dumpable(cprm.mm_flags))
60683 + if (!dumpable)
60684 goto fail;
60685
60686 cred = prepare_creds();
60687 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60688 need_nonrelative = true;
60689 }
60690
60691 - retval = coredump_wait(siginfo->si_signo, &core_state);
60692 + retval = coredump_wait(signr, &core_state);
60693 if (retval < 0)
60694 goto fail_creds;
60695
60696 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60697 }
60698 cprm.limit = RLIM_INFINITY;
60699
60700 - dump_count = atomic_inc_return(&core_dump_count);
60701 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60702 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60703 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60704 task_tgid_vnr(current), current->comm);
60705 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60706 } else {
60707 struct inode *inode;
60708
60709 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60710 +
60711 if (cprm.limit < binfmt->min_coredump)
60712 goto fail_unlock;
60713
60714 @@ -681,7 +690,7 @@ close_fail:
60715 filp_close(cprm.file, NULL);
60716 fail_dropcount:
60717 if (ispipe)
60718 - atomic_dec(&core_dump_count);
60719 + atomic_dec_unchecked(&core_dump_count);
60720 fail_unlock:
60721 kfree(cn.corename);
60722 coredump_finish(mm, core_dumped);
60723 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60724 struct file *file = cprm->file;
60725 loff_t pos = file->f_pos;
60726 ssize_t n;
60727 +
60728 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60729 if (cprm->written + nr > cprm->limit)
60730 return 0;
60731 while (nr) {
60732 diff --git a/fs/dcache.c b/fs/dcache.c
60733 index 03dca3c..15f326d 100644
60734 --- a/fs/dcache.c
60735 +++ b/fs/dcache.c
60736 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60737 * dentry_iput drops the locks, at which point nobody (except
60738 * transient RCU lookups) can reach this dentry.
60739 */
60740 - BUG_ON((int)dentry->d_lockref.count > 0);
60741 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60742 this_cpu_dec(nr_dentry);
60743 if (dentry->d_op && dentry->d_op->d_release)
60744 dentry->d_op->d_release(dentry);
60745 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60746 struct dentry *parent = dentry->d_parent;
60747 if (IS_ROOT(dentry))
60748 return NULL;
60749 - if (unlikely((int)dentry->d_lockref.count < 0))
60750 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60751 return NULL;
60752 if (likely(spin_trylock(&parent->d_lock)))
60753 return parent;
60754 @@ -638,7 +638,7 @@ repeat:
60755 dentry->d_flags |= DCACHE_REFERENCED;
60756 dentry_lru_add(dentry);
60757
60758 - dentry->d_lockref.count--;
60759 + __lockref_dec(&dentry->d_lockref);
60760 spin_unlock(&dentry->d_lock);
60761 return;
60762
60763 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60764 /* This must be called with d_lock held */
60765 static inline void __dget_dlock(struct dentry *dentry)
60766 {
60767 - dentry->d_lockref.count++;
60768 + __lockref_inc(&dentry->d_lockref);
60769 }
60770
60771 static inline void __dget(struct dentry *dentry)
60772 @@ -694,8 +694,8 @@ repeat:
60773 goto repeat;
60774 }
60775 rcu_read_unlock();
60776 - BUG_ON(!ret->d_lockref.count);
60777 - ret->d_lockref.count++;
60778 + BUG_ON(!__lockref_read(&ret->d_lockref));
60779 + __lockref_inc(&ret->d_lockref);
60780 spin_unlock(&ret->d_lock);
60781 return ret;
60782 }
60783 @@ -773,9 +773,9 @@ restart:
60784 spin_lock(&inode->i_lock);
60785 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60786 spin_lock(&dentry->d_lock);
60787 - if (!dentry->d_lockref.count) {
60788 + if (!__lockref_read(&dentry->d_lockref)) {
60789 struct dentry *parent = lock_parent(dentry);
60790 - if (likely(!dentry->d_lockref.count)) {
60791 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60792 __dentry_kill(dentry);
60793 dput(parent);
60794 goto restart;
60795 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60796 * We found an inuse dentry which was not removed from
60797 * the LRU because of laziness during lookup. Do not free it.
60798 */
60799 - if ((int)dentry->d_lockref.count > 0) {
60800 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60801 spin_unlock(&dentry->d_lock);
60802 if (parent)
60803 spin_unlock(&parent->d_lock);
60804 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60805 dentry = parent;
60806 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60807 parent = lock_parent(dentry);
60808 - if (dentry->d_lockref.count != 1) {
60809 - dentry->d_lockref.count--;
60810 + if (__lockref_read(&dentry->d_lockref) != 1) {
60811 + __lockref_inc(&dentry->d_lockref);
60812 spin_unlock(&dentry->d_lock);
60813 if (parent)
60814 spin_unlock(&parent->d_lock);
60815 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60816 * counts, just remove them from the LRU. Otherwise give them
60817 * another pass through the LRU.
60818 */
60819 - if (dentry->d_lockref.count) {
60820 + if (__lockref_read(&dentry->d_lockref) > 0) {
60821 d_lru_isolate(dentry);
60822 spin_unlock(&dentry->d_lock);
60823 return LRU_REMOVED;
60824 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60825 } else {
60826 if (dentry->d_flags & DCACHE_LRU_LIST)
60827 d_lru_del(dentry);
60828 - if (!dentry->d_lockref.count) {
60829 + if (!__lockref_read(&dentry->d_lockref)) {
60830 d_shrink_add(dentry, &data->dispose);
60831 data->found++;
60832 }
60833 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60834 return D_WALK_CONTINUE;
60835
60836 /* root with refcount 1 is fine */
60837 - if (dentry == _data && dentry->d_lockref.count == 1)
60838 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60839 return D_WALK_CONTINUE;
60840
60841 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60842 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60843 dentry->d_inode ?
60844 dentry->d_inode->i_ino : 0UL,
60845 dentry,
60846 - dentry->d_lockref.count,
60847 + __lockref_read(&dentry->d_lockref),
60848 dentry->d_sb->s_type->name,
60849 dentry->d_sb->s_id);
60850 WARN_ON(1);
60851 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60852 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60853 if (name->len > DNAME_INLINE_LEN-1) {
60854 size_t size = offsetof(struct external_name, name[1]);
60855 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60856 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60857 if (!p) {
60858 kmem_cache_free(dentry_cache, dentry);
60859 return NULL;
60860 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60861 smp_wmb();
60862 dentry->d_name.name = dname;
60863
60864 - dentry->d_lockref.count = 1;
60865 + __lockref_set(&dentry->d_lockref, 1);
60866 dentry->d_flags = 0;
60867 spin_lock_init(&dentry->d_lock);
60868 seqcount_init(&dentry->d_seq);
60869 @@ -1452,6 +1452,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60870 dentry->d_sb = sb;
60871 dentry->d_op = NULL;
60872 dentry->d_fsdata = NULL;
60873 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
60874 + atomic_set(&dentry->chroot_refcnt, 0);
60875 +#endif
60876 INIT_HLIST_BL_NODE(&dentry->d_hash);
60877 INIT_LIST_HEAD(&dentry->d_lru);
60878 INIT_LIST_HEAD(&dentry->d_subdirs);
60879 @@ -2183,7 +2186,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60880 goto next;
60881 }
60882
60883 - dentry->d_lockref.count++;
60884 + __lockref_inc(&dentry->d_lockref);
60885 found = dentry;
60886 spin_unlock(&dentry->d_lock);
60887 break;
60888 @@ -2282,7 +2285,7 @@ again:
60889 spin_lock(&dentry->d_lock);
60890 inode = dentry->d_inode;
60891 isdir = S_ISDIR(inode->i_mode);
60892 - if (dentry->d_lockref.count == 1) {
60893 + if (__lockref_read(&dentry->d_lockref) == 1) {
60894 if (!spin_trylock(&inode->i_lock)) {
60895 spin_unlock(&dentry->d_lock);
60896 cpu_relax();
60897 @@ -3308,7 +3311,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60898
60899 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60900 dentry->d_flags |= DCACHE_GENOCIDE;
60901 - dentry->d_lockref.count--;
60902 + __lockref_dec(&dentry->d_lockref);
60903 }
60904 }
60905 return D_WALK_CONTINUE;
60906 @@ -3424,7 +3427,8 @@ void __init vfs_caches_init(unsigned long mempages)
60907 mempages -= reserve;
60908
60909 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60910 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60911 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60912 + SLAB_NO_SANITIZE, NULL);
60913
60914 dcache_init();
60915 inode_init();
60916 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60917 index 05f2960..780f4f8 100644
60918 --- a/fs/debugfs/inode.c
60919 +++ b/fs/debugfs/inode.c
60920 @@ -246,10 +246,19 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root)
60921 return 0;
60922 }
60923
60924 +static void debugfs_evict_inode(struct inode *inode)
60925 +{
60926 + truncate_inode_pages_final(&inode->i_data);
60927 + clear_inode(inode);
60928 + if (S_ISLNK(inode->i_mode))
60929 + kfree(inode->i_private);
60930 +}
60931 +
60932 static const struct super_operations debugfs_super_operations = {
60933 .statfs = simple_statfs,
60934 .remount_fs = debugfs_remount,
60935 .show_options = debugfs_show_options,
60936 + .evict_inode = debugfs_evict_inode,
60937 };
60938
60939 static int debug_fill_super(struct super_block *sb, void *data, int silent)
60940 @@ -416,7 +425,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60941 */
60942 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60943 {
60944 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60945 + return __create_file(name, S_IFDIR | S_IRWXU,
60946 +#else
60947 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60948 +#endif
60949 parent, NULL, NULL);
60950 }
60951 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60952 @@ -466,23 +479,14 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
60953 int ret = 0;
60954
60955 if (debugfs_positive(dentry)) {
60956 - if (dentry->d_inode) {
60957 - dget(dentry);
60958 - switch (dentry->d_inode->i_mode & S_IFMT) {
60959 - case S_IFDIR:
60960 - ret = simple_rmdir(parent->d_inode, dentry);
60961 - break;
60962 - case S_IFLNK:
60963 - kfree(dentry->d_inode->i_private);
60964 - /* fall through */
60965 - default:
60966 - simple_unlink(parent->d_inode, dentry);
60967 - break;
60968 - }
60969 - if (!ret)
60970 - d_delete(dentry);
60971 - dput(dentry);
60972 - }
60973 + dget(dentry);
60974 + if (S_ISDIR(dentry->d_inode->i_mode))
60975 + ret = simple_rmdir(parent->d_inode, dentry);
60976 + else
60977 + simple_unlink(parent->d_inode, dentry);
60978 + if (!ret)
60979 + d_delete(dentry);
60980 + dput(dentry);
60981 }
60982 return ret;
60983 }
60984 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60985 index 1686dc2..9611c50 100644
60986 --- a/fs/ecryptfs/inode.c
60987 +++ b/fs/ecryptfs/inode.c
60988 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60989 old_fs = get_fs();
60990 set_fs(get_ds());
60991 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60992 - (char __user *)lower_buf,
60993 + (char __force_user *)lower_buf,
60994 PATH_MAX);
60995 set_fs(old_fs);
60996 if (rc < 0)
60997 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60998 index e4141f2..d8263e8 100644
60999 --- a/fs/ecryptfs/miscdev.c
61000 +++ b/fs/ecryptfs/miscdev.c
61001 @@ -304,7 +304,7 @@ check_list:
61002 goto out_unlock_msg_ctx;
61003 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61004 if (msg_ctx->msg) {
61005 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61006 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61007 goto out_unlock_msg_ctx;
61008 i += packet_length_size;
61009 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61010 diff --git a/fs/exec.c b/fs/exec.c
61011 index 7302b75..44eb2f8 100644
61012 --- a/fs/exec.c
61013 +++ b/fs/exec.c
61014 @@ -56,8 +56,20 @@
61015 #include <linux/pipe_fs_i.h>
61016 #include <linux/oom.h>
61017 #include <linux/compat.h>
61018 +#include <linux/random.h>
61019 +#include <linux/seq_file.h>
61020 +#include <linux/coredump.h>
61021 +#include <linux/mman.h>
61022 +
61023 +#ifdef CONFIG_PAX_REFCOUNT
61024 +#include <linux/kallsyms.h>
61025 +#include <linux/kdebug.h>
61026 +#endif
61027 +
61028 +#include <trace/events/fs.h>
61029
61030 #include <asm/uaccess.h>
61031 +#include <asm/sections.h>
61032 #include <asm/mmu_context.h>
61033 #include <asm/tlb.h>
61034
61035 @@ -66,19 +78,34 @@
61036
61037 #include <trace/events/sched.h>
61038
61039 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61040 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61041 +{
61042 + 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");
61043 +}
61044 +#endif
61045 +
61046 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61047 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61048 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61049 +#endif
61050 +
61051 int suid_dumpable = 0;
61052
61053 static LIST_HEAD(formats);
61054 static DEFINE_RWLOCK(binfmt_lock);
61055
61056 +extern int gr_process_kernel_exec_ban(void);
61057 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61058 +
61059 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61060 {
61061 BUG_ON(!fmt);
61062 if (WARN_ON(!fmt->load_binary))
61063 return;
61064 write_lock(&binfmt_lock);
61065 - insert ? list_add(&fmt->lh, &formats) :
61066 - list_add_tail(&fmt->lh, &formats);
61067 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61068 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61069 write_unlock(&binfmt_lock);
61070 }
61071
61072 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61073 void unregister_binfmt(struct linux_binfmt * fmt)
61074 {
61075 write_lock(&binfmt_lock);
61076 - list_del(&fmt->lh);
61077 + pax_list_del((struct list_head *)&fmt->lh);
61078 write_unlock(&binfmt_lock);
61079 }
61080
61081 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61082 int write)
61083 {
61084 struct page *page;
61085 - int ret;
61086
61087 -#ifdef CONFIG_STACK_GROWSUP
61088 - if (write) {
61089 - ret = expand_downwards(bprm->vma, pos);
61090 - if (ret < 0)
61091 - return NULL;
61092 - }
61093 -#endif
61094 - ret = get_user_pages(current, bprm->mm, pos,
61095 - 1, write, 1, &page, NULL);
61096 - if (ret <= 0)
61097 + if (0 > expand_downwards(bprm->vma, pos))
61098 + return NULL;
61099 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61100 return NULL;
61101
61102 if (write) {
61103 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61104 if (size <= ARG_MAX)
61105 return page;
61106
61107 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61108 + // only allow 512KB for argv+env on suid/sgid binaries
61109 + // to prevent easy ASLR exhaustion
61110 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61111 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61112 + (size > (512 * 1024))) {
61113 + put_page(page);
61114 + return NULL;
61115 + }
61116 +#endif
61117 +
61118 /*
61119 * Limit to 1/4-th the stack size for the argv+env strings.
61120 * This ensures that:
61121 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61122 vma->vm_end = STACK_TOP_MAX;
61123 vma->vm_start = vma->vm_end - PAGE_SIZE;
61124 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61125 +
61126 +#ifdef CONFIG_PAX_SEGMEXEC
61127 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61128 +#endif
61129 +
61130 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61131 INIT_LIST_HEAD(&vma->anon_vma_chain);
61132
61133 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61134 mm->stack_vm = mm->total_vm = 1;
61135 up_write(&mm->mmap_sem);
61136 bprm->p = vma->vm_end - sizeof(void *);
61137 +
61138 +#ifdef CONFIG_PAX_RANDUSTACK
61139 + if (randomize_va_space)
61140 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61141 +#endif
61142 +
61143 return 0;
61144 err:
61145 up_write(&mm->mmap_sem);
61146 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61147 } ptr;
61148 };
61149
61150 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61151 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61152 {
61153 const char __user *native;
61154
61155 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61156 compat_uptr_t compat;
61157
61158 if (get_user(compat, argv.ptr.compat + nr))
61159 - return ERR_PTR(-EFAULT);
61160 + return (const char __force_user *)ERR_PTR(-EFAULT);
61161
61162 return compat_ptr(compat);
61163 }
61164 #endif
61165
61166 if (get_user(native, argv.ptr.native + nr))
61167 - return ERR_PTR(-EFAULT);
61168 + return (const char __force_user *)ERR_PTR(-EFAULT);
61169
61170 return native;
61171 }
61172 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61173 if (!p)
61174 break;
61175
61176 - if (IS_ERR(p))
61177 + if (IS_ERR((const char __force_kernel *)p))
61178 return -EFAULT;
61179
61180 if (i >= max)
61181 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61182
61183 ret = -EFAULT;
61184 str = get_user_arg_ptr(argv, argc);
61185 - if (IS_ERR(str))
61186 + if (IS_ERR((const char __force_kernel *)str))
61187 goto out;
61188
61189 len = strnlen_user(str, MAX_ARG_STRLEN);
61190 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61191 int r;
61192 mm_segment_t oldfs = get_fs();
61193 struct user_arg_ptr argv = {
61194 - .ptr.native = (const char __user *const __user *)__argv,
61195 + .ptr.native = (const char __user * const __force_user *)__argv,
61196 };
61197
61198 set_fs(KERNEL_DS);
61199 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61200 unsigned long new_end = old_end - shift;
61201 struct mmu_gather tlb;
61202
61203 - BUG_ON(new_start > new_end);
61204 + if (new_start >= new_end || new_start < mmap_min_addr)
61205 + return -ENOMEM;
61206
61207 /*
61208 * ensure there are no vmas between where we want to go
61209 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61210 if (vma != find_vma(mm, new_start))
61211 return -EFAULT;
61212
61213 +#ifdef CONFIG_PAX_SEGMEXEC
61214 + BUG_ON(pax_find_mirror_vma(vma));
61215 +#endif
61216 +
61217 /*
61218 * cover the whole range: [new_start, old_end)
61219 */
61220 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61221 stack_top = arch_align_stack(stack_top);
61222 stack_top = PAGE_ALIGN(stack_top);
61223
61224 - if (unlikely(stack_top < mmap_min_addr) ||
61225 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61226 - return -ENOMEM;
61227 -
61228 stack_shift = vma->vm_end - stack_top;
61229
61230 bprm->p -= stack_shift;
61231 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61232 bprm->exec -= stack_shift;
61233
61234 down_write(&mm->mmap_sem);
61235 +
61236 + /* Move stack pages down in memory. */
61237 + if (stack_shift) {
61238 + ret = shift_arg_pages(vma, stack_shift);
61239 + if (ret)
61240 + goto out_unlock;
61241 + }
61242 +
61243 vm_flags = VM_STACK_FLAGS;
61244
61245 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61246 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61247 + vm_flags &= ~VM_EXEC;
61248 +
61249 +#ifdef CONFIG_PAX_MPROTECT
61250 + if (mm->pax_flags & MF_PAX_MPROTECT)
61251 + vm_flags &= ~VM_MAYEXEC;
61252 +#endif
61253 +
61254 + }
61255 +#endif
61256 +
61257 /*
61258 * Adjust stack execute permissions; explicitly enable for
61259 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61260 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61261 goto out_unlock;
61262 BUG_ON(prev != vma);
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 /* mprotect_fixup is overkill to remove the temporary stack flags */
61272 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61273
61274 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61275 #endif
61276 current->mm->start_stack = bprm->p;
61277 ret = expand_stack(vma, stack_base);
61278 +
61279 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61280 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61281 + unsigned long size;
61282 + vm_flags_t vm_flags;
61283 +
61284 + size = STACK_TOP - vma->vm_end;
61285 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61286 +
61287 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61288 +
61289 +#ifdef CONFIG_X86
61290 + if (!ret) {
61291 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61292 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61293 + }
61294 +#endif
61295 +
61296 + }
61297 +#endif
61298 +
61299 if (ret)
61300 ret = -EFAULT;
61301
61302 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61303
61304 fsnotify_open(file);
61305
61306 + trace_open_exec(name->name);
61307 +
61308 err = deny_write_access(file);
61309 if (err)
61310 goto exit;
61311 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61312 old_fs = get_fs();
61313 set_fs(get_ds());
61314 /* The cast to a user pointer is valid due to the set_fs() */
61315 - result = vfs_read(file, (void __user *)addr, count, &pos);
61316 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61317 set_fs(old_fs);
61318 return result;
61319 }
61320 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61321 tsk->mm = mm;
61322 tsk->active_mm = mm;
61323 activate_mm(active_mm, mm);
61324 + populate_stack();
61325 tsk->mm->vmacache_seqnum = 0;
61326 vmacache_flush(tsk);
61327 task_unlock(tsk);
61328 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61329 }
61330 rcu_read_unlock();
61331
61332 - if (p->fs->users > n_fs)
61333 + if (atomic_read(&p->fs->users) > n_fs)
61334 bprm->unsafe |= LSM_UNSAFE_SHARE;
61335 else
61336 p->fs->in_exec = 1;
61337 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61338 return ret;
61339 }
61340
61341 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61342 +static DEFINE_PER_CPU(u64, exec_counter);
61343 +static int __init init_exec_counters(void)
61344 +{
61345 + unsigned int cpu;
61346 +
61347 + for_each_possible_cpu(cpu) {
61348 + per_cpu(exec_counter, cpu) = (u64)cpu;
61349 + }
61350 +
61351 + return 0;
61352 +}
61353 +early_initcall(init_exec_counters);
61354 +static inline void increment_exec_counter(void)
61355 +{
61356 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61357 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61358 +}
61359 +#else
61360 +static inline void increment_exec_counter(void) {}
61361 +#endif
61362 +
61363 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61364 + struct user_arg_ptr argv);
61365 +
61366 /*
61367 * sys_execve() executes a new program.
61368 */
61369 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61370 struct user_arg_ptr argv,
61371 struct user_arg_ptr envp)
61372 {
61373 +#ifdef CONFIG_GRKERNSEC
61374 + struct file *old_exec_file;
61375 + struct acl_subject_label *old_acl;
61376 + struct rlimit old_rlim[RLIM_NLIMITS];
61377 +#endif
61378 struct linux_binprm *bprm;
61379 struct file *file;
61380 struct files_struct *displaced;
61381 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61382 if (IS_ERR(filename))
61383 return PTR_ERR(filename);
61384
61385 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61386 +
61387 /*
61388 * We move the actual failure in case of RLIMIT_NPROC excess from
61389 * set*uid() to execve() because too many poorly written programs
61390 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61391 if (IS_ERR(file))
61392 goto out_unmark;
61393
61394 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61395 + retval = -EPERM;
61396 + goto out_unmark;
61397 + }
61398 +
61399 sched_exec();
61400
61401 bprm->file = file;
61402 bprm->filename = bprm->interp = filename->name;
61403
61404 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61405 + retval = -EACCES;
61406 + goto out_unmark;
61407 + }
61408 +
61409 retval = bprm_mm_init(bprm);
61410 if (retval)
61411 goto out_unmark;
61412 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61413 if (retval < 0)
61414 goto out;
61415
61416 +#ifdef CONFIG_GRKERNSEC
61417 + old_acl = current->acl;
61418 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61419 + old_exec_file = current->exec_file;
61420 + get_file(file);
61421 + current->exec_file = file;
61422 +#endif
61423 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61424 + /* limit suid stack to 8MB
61425 + * we saved the old limits above and will restore them if this exec fails
61426 + */
61427 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61428 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61429 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61430 +#endif
61431 +
61432 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61433 + retval = -EPERM;
61434 + goto out_fail;
61435 + }
61436 +
61437 + if (!gr_tpe_allow(file)) {
61438 + retval = -EACCES;
61439 + goto out_fail;
61440 + }
61441 +
61442 + if (gr_check_crash_exec(file)) {
61443 + retval = -EACCES;
61444 + goto out_fail;
61445 + }
61446 +
61447 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61448 + bprm->unsafe);
61449 + if (retval < 0)
61450 + goto out_fail;
61451 +
61452 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61453 if (retval < 0)
61454 - goto out;
61455 + goto out_fail;
61456
61457 bprm->exec = bprm->p;
61458 retval = copy_strings(bprm->envc, envp, bprm);
61459 if (retval < 0)
61460 - goto out;
61461 + goto out_fail;
61462
61463 retval = copy_strings(bprm->argc, argv, bprm);
61464 if (retval < 0)
61465 - goto out;
61466 + goto out_fail;
61467 +
61468 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61469 +
61470 + gr_handle_exec_args(bprm, argv);
61471
61472 retval = exec_binprm(bprm);
61473 if (retval < 0)
61474 - goto out;
61475 + goto out_fail;
61476 +#ifdef CONFIG_GRKERNSEC
61477 + if (old_exec_file)
61478 + fput(old_exec_file);
61479 +#endif
61480
61481 /* execve succeeded */
61482 +
61483 + increment_exec_counter();
61484 current->fs->in_exec = 0;
61485 current->in_execve = 0;
61486 acct_update_integrals(current);
61487 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61488 put_files_struct(displaced);
61489 return retval;
61490
61491 +out_fail:
61492 +#ifdef CONFIG_GRKERNSEC
61493 + current->acl = old_acl;
61494 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61495 + fput(current->exec_file);
61496 + current->exec_file = old_exec_file;
61497 +#endif
61498 +
61499 out:
61500 if (bprm->mm) {
61501 acct_arg_size(bprm, 0);
61502 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61503 return compat_do_execve(getname(filename), argv, envp);
61504 }
61505 #endif
61506 +
61507 +int pax_check_flags(unsigned long *flags)
61508 +{
61509 + int retval = 0;
61510 +
61511 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61512 + if (*flags & MF_PAX_SEGMEXEC)
61513 + {
61514 + *flags &= ~MF_PAX_SEGMEXEC;
61515 + retval = -EINVAL;
61516 + }
61517 +#endif
61518 +
61519 + if ((*flags & MF_PAX_PAGEEXEC)
61520 +
61521 +#ifdef CONFIG_PAX_PAGEEXEC
61522 + && (*flags & MF_PAX_SEGMEXEC)
61523 +#endif
61524 +
61525 + )
61526 + {
61527 + *flags &= ~MF_PAX_PAGEEXEC;
61528 + retval = -EINVAL;
61529 + }
61530 +
61531 + if ((*flags & MF_PAX_MPROTECT)
61532 +
61533 +#ifdef CONFIG_PAX_MPROTECT
61534 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61535 +#endif
61536 +
61537 + )
61538 + {
61539 + *flags &= ~MF_PAX_MPROTECT;
61540 + retval = -EINVAL;
61541 + }
61542 +
61543 + if ((*flags & MF_PAX_EMUTRAMP)
61544 +
61545 +#ifdef CONFIG_PAX_EMUTRAMP
61546 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61547 +#endif
61548 +
61549 + )
61550 + {
61551 + *flags &= ~MF_PAX_EMUTRAMP;
61552 + retval = -EINVAL;
61553 + }
61554 +
61555 + return retval;
61556 +}
61557 +
61558 +EXPORT_SYMBOL(pax_check_flags);
61559 +
61560 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61561 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61562 +{
61563 + char *pathname = d_path(path, buf, buflen);
61564 +
61565 + if (IS_ERR(pathname))
61566 + goto toolong;
61567 +
61568 + pathname = mangle_path(buf, pathname, "\t\n\\");
61569 + if (!pathname)
61570 + goto toolong;
61571 +
61572 + *pathname = 0;
61573 + return buf;
61574 +
61575 +toolong:
61576 + return "<path too long>";
61577 +}
61578 +EXPORT_SYMBOL(pax_get_path);
61579 +
61580 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61581 +{
61582 + struct task_struct *tsk = current;
61583 + struct mm_struct *mm = current->mm;
61584 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61585 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61586 + char *path_exec = NULL;
61587 + char *path_fault = NULL;
61588 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61589 + siginfo_t info = { };
61590 +
61591 + if (buffer_exec && buffer_fault) {
61592 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61593 +
61594 + down_read(&mm->mmap_sem);
61595 + vma = mm->mmap;
61596 + while (vma && (!vma_exec || !vma_fault)) {
61597 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61598 + vma_exec = vma;
61599 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61600 + vma_fault = vma;
61601 + vma = vma->vm_next;
61602 + }
61603 + if (vma_exec)
61604 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61605 + if (vma_fault) {
61606 + start = vma_fault->vm_start;
61607 + end = vma_fault->vm_end;
61608 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61609 + if (vma_fault->vm_file)
61610 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61611 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61612 + path_fault = "<heap>";
61613 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61614 + path_fault = "<stack>";
61615 + else
61616 + path_fault = "<anonymous mapping>";
61617 + }
61618 + up_read(&mm->mmap_sem);
61619 + }
61620 + if (tsk->signal->curr_ip)
61621 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61622 + else
61623 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61624 + 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),
61625 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61626 + free_page((unsigned long)buffer_exec);
61627 + free_page((unsigned long)buffer_fault);
61628 + pax_report_insns(regs, pc, sp);
61629 + info.si_signo = SIGKILL;
61630 + info.si_errno = 0;
61631 + info.si_code = SI_KERNEL;
61632 + info.si_pid = 0;
61633 + info.si_uid = 0;
61634 + do_coredump(&info);
61635 +}
61636 +#endif
61637 +
61638 +#ifdef CONFIG_PAX_REFCOUNT
61639 +void pax_report_refcount_overflow(struct pt_regs *regs)
61640 +{
61641 + if (current->signal->curr_ip)
61642 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61643 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61644 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61645 + else
61646 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61647 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61648 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61649 + preempt_disable();
61650 + show_regs(regs);
61651 + preempt_enable();
61652 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61653 +}
61654 +#endif
61655 +
61656 +#ifdef CONFIG_PAX_USERCOPY
61657 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61658 +static noinline int check_stack_object(const void *obj, unsigned long len)
61659 +{
61660 + const void * const stack = task_stack_page(current);
61661 + const void * const stackend = stack + THREAD_SIZE;
61662 +
61663 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61664 + const void *frame = NULL;
61665 + const void *oldframe;
61666 +#endif
61667 +
61668 + if (obj + len < obj)
61669 + return -1;
61670 +
61671 + if (obj + len <= stack || stackend <= obj)
61672 + return 0;
61673 +
61674 + if (obj < stack || stackend < obj + len)
61675 + return -1;
61676 +
61677 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61678 + oldframe = __builtin_frame_address(1);
61679 + if (oldframe)
61680 + frame = __builtin_frame_address(2);
61681 + /*
61682 + low ----------------------------------------------> high
61683 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61684 + ^----------------^
61685 + allow copies only within here
61686 + */
61687 + while (stack <= frame && frame < stackend) {
61688 + /* if obj + len extends past the last frame, this
61689 + check won't pass and the next frame will be 0,
61690 + causing us to bail out and correctly report
61691 + the copy as invalid
61692 + */
61693 + if (obj + len <= frame)
61694 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61695 + oldframe = frame;
61696 + frame = *(const void * const *)frame;
61697 + }
61698 + return -1;
61699 +#else
61700 + return 1;
61701 +#endif
61702 +}
61703 +
61704 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61705 +{
61706 + if (current->signal->curr_ip)
61707 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61708 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61709 + else
61710 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61711 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61712 + dump_stack();
61713 + gr_handle_kernel_exploit();
61714 + do_group_exit(SIGKILL);
61715 +}
61716 +#endif
61717 +
61718 +#ifdef CONFIG_PAX_USERCOPY
61719 +
61720 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61721 +{
61722 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61723 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61724 +#ifdef CONFIG_MODULES
61725 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61726 +#else
61727 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61728 +#endif
61729 +
61730 +#else
61731 + unsigned long textlow = (unsigned long)_stext;
61732 + unsigned long texthigh = (unsigned long)_etext;
61733 +
61734 +#ifdef CONFIG_X86_64
61735 + /* check against linear mapping as well */
61736 + if (high > (unsigned long)__va(__pa(textlow)) &&
61737 + low < (unsigned long)__va(__pa(texthigh)))
61738 + return true;
61739 +#endif
61740 +
61741 +#endif
61742 +
61743 + if (high <= textlow || low >= texthigh)
61744 + return false;
61745 + else
61746 + return true;
61747 +}
61748 +#endif
61749 +
61750 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61751 +{
61752 +#ifdef CONFIG_PAX_USERCOPY
61753 + const char *type;
61754 +#endif
61755 +
61756 +#if !defined(CONFIG_STACK_GROWSUP) && !defined(CONFIG_X86_64)
61757 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61758 + unsigned long currentsp = (unsigned long)&stackstart;
61759 + if (unlikely((currentsp < stackstart + 512 ||
61760 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61761 + BUG();
61762 +#endif
61763 +
61764 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61765 + if (const_size)
61766 + return;
61767 +#endif
61768 +
61769 +#ifdef CONFIG_PAX_USERCOPY
61770 + if (!n)
61771 + return;
61772 +
61773 + type = check_heap_object(ptr, n);
61774 + if (!type) {
61775 + int ret = check_stack_object(ptr, n);
61776 + if (ret == 1 || ret == 2)
61777 + return;
61778 + if (ret == 0) {
61779 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61780 + type = "<kernel text>";
61781 + else
61782 + return;
61783 + } else
61784 + type = "<process stack>";
61785 + }
61786 +
61787 + pax_report_usercopy(ptr, n, to_user, type);
61788 +#endif
61789 +
61790 +}
61791 +EXPORT_SYMBOL(__check_object_size);
61792 +
61793 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61794 +void pax_track_stack(void)
61795 +{
61796 + unsigned long sp = (unsigned long)&sp;
61797 + if (sp < current_thread_info()->lowest_stack &&
61798 + sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61799 + current_thread_info()->lowest_stack = sp;
61800 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61801 + BUG();
61802 +}
61803 +EXPORT_SYMBOL(pax_track_stack);
61804 +#endif
61805 +
61806 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61807 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61808 +{
61809 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61810 + dump_stack();
61811 + do_group_exit(SIGKILL);
61812 +}
61813 +EXPORT_SYMBOL(report_size_overflow);
61814 +#endif
61815 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61816 index 9f9992b..8b59411 100644
61817 --- a/fs/ext2/balloc.c
61818 +++ b/fs/ext2/balloc.c
61819 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61820
61821 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61822 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61823 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61824 + if (free_blocks < root_blocks + 1 &&
61825 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61826 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61827 - !in_group_p (sbi->s_resgid))) {
61828 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61829 return 0;
61830 }
61831 return 1;
61832 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61833 index 170dc41..62f6b18 100644
61834 --- a/fs/ext2/super.c
61835 +++ b/fs/ext2/super.c
61836 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61837 #ifdef CONFIG_EXT2_FS_XATTR
61838 if (test_opt(sb, XATTR_USER))
61839 seq_puts(seq, ",user_xattr");
61840 - if (!test_opt(sb, XATTR_USER) &&
61841 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61842 + if (!test_opt(sb, XATTR_USER))
61843 seq_puts(seq, ",nouser_xattr");
61844 - }
61845 #endif
61846
61847 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61848 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61849 if (def_mount_opts & EXT2_DEFM_UID16)
61850 set_opt(sbi->s_mount_opt, NO_UID32);
61851 #ifdef CONFIG_EXT2_FS_XATTR
61852 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61853 - set_opt(sbi->s_mount_opt, XATTR_USER);
61854 + /* always enable user xattrs */
61855 + set_opt(sbi->s_mount_opt, XATTR_USER);
61856 #endif
61857 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61858 if (def_mount_opts & EXT2_DEFM_ACL)
61859 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61860 index 9142614..97484fa 100644
61861 --- a/fs/ext2/xattr.c
61862 +++ b/fs/ext2/xattr.c
61863 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61864 struct buffer_head *bh = NULL;
61865 struct ext2_xattr_entry *entry;
61866 char *end;
61867 - size_t rest = buffer_size;
61868 + size_t rest = buffer_size, total_size = 0;
61869 int error;
61870
61871 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61872 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61873 buffer += size;
61874 }
61875 rest -= size;
61876 + total_size += size;
61877 }
61878 }
61879 - error = buffer_size - rest; /* total size */
61880 + error = total_size;
61881
61882 cleanup:
61883 brelse(bh);
61884 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61885 index 158b5d4..2432610 100644
61886 --- a/fs/ext3/balloc.c
61887 +++ b/fs/ext3/balloc.c
61888 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61889
61890 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61891 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61892 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61893 + if (free_blocks < root_blocks + 1 &&
61894 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61895 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61896 - !in_group_p (sbi->s_resgid))) {
61897 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61898 return 0;
61899 }
61900 return 1;
61901 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61902 index eb742d0..c19f705 100644
61903 --- a/fs/ext3/super.c
61904 +++ b/fs/ext3/super.c
61905 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61906 #ifdef CONFIG_EXT3_FS_XATTR
61907 if (test_opt(sb, XATTR_USER))
61908 seq_puts(seq, ",user_xattr");
61909 - if (!test_opt(sb, XATTR_USER) &&
61910 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61911 + if (!test_opt(sb, XATTR_USER))
61912 seq_puts(seq, ",nouser_xattr");
61913 - }
61914 #endif
61915 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61916 if (test_opt(sb, POSIX_ACL))
61917 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61918 if (def_mount_opts & EXT3_DEFM_UID16)
61919 set_opt(sbi->s_mount_opt, NO_UID32);
61920 #ifdef CONFIG_EXT3_FS_XATTR
61921 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61922 - set_opt(sbi->s_mount_opt, XATTR_USER);
61923 + /* always enable user xattrs */
61924 + set_opt(sbi->s_mount_opt, XATTR_USER);
61925 #endif
61926 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61927 if (def_mount_opts & EXT3_DEFM_ACL)
61928 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61929 index c6874be..f8a6ae8 100644
61930 --- a/fs/ext3/xattr.c
61931 +++ b/fs/ext3/xattr.c
61932 @@ -330,7 +330,7 @@ static int
61933 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61934 char *buffer, size_t buffer_size)
61935 {
61936 - size_t rest = buffer_size;
61937 + size_t rest = buffer_size, total_size = 0;
61938
61939 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61940 const struct xattr_handler *handler =
61941 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61942 buffer += size;
61943 }
61944 rest -= size;
61945 + total_size += size;
61946 }
61947 }
61948 - return buffer_size - rest;
61949 + return total_size;
61950 }
61951
61952 static int
61953 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61954 index 83a6f49..d4e4d03 100644
61955 --- a/fs/ext4/balloc.c
61956 +++ b/fs/ext4/balloc.c
61957 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61958 /* Hm, nope. Are (enough) root reserved clusters available? */
61959 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61960 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61961 - capable(CAP_SYS_RESOURCE) ||
61962 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61963 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61964 + capable_nolog(CAP_SYS_RESOURCE)) {
61965
61966 if (free_clusters >= (nclusters + dirty_clusters +
61967 resv_clusters))
61968 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61969 index c55a1fa..9904ebb 100644
61970 --- a/fs/ext4/ext4.h
61971 +++ b/fs/ext4/ext4.h
61972 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61973 unsigned long s_mb_last_start;
61974
61975 /* stats for buddy allocator */
61976 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61977 - atomic_t s_bal_success; /* we found long enough chunks */
61978 - atomic_t s_bal_allocated; /* in blocks */
61979 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61980 - atomic_t s_bal_goals; /* goal hits */
61981 - atomic_t s_bal_breaks; /* too long searches */
61982 - atomic_t s_bal_2orders; /* 2^order hits */
61983 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61984 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61985 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61986 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61987 + atomic_unchecked_t s_bal_goals; /* goal hits */
61988 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61989 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61990 spinlock_t s_bal_lock;
61991 unsigned long s_mb_buddies_generated;
61992 unsigned long long s_mb_generation_time;
61993 - atomic_t s_mb_lost_chunks;
61994 - atomic_t s_mb_preallocated;
61995 - atomic_t s_mb_discarded;
61996 + atomic_unchecked_t s_mb_lost_chunks;
61997 + atomic_unchecked_t s_mb_preallocated;
61998 + atomic_unchecked_t s_mb_discarded;
61999 atomic_t s_lock_busy;
62000
62001 /* locality groups */
62002 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62003 index dbfe15c..9a6ee8d 100644
62004 --- a/fs/ext4/mballoc.c
62005 +++ b/fs/ext4/mballoc.c
62006 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62007 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62008
62009 if (EXT4_SB(sb)->s_mb_stats)
62010 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62011 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62012
62013 break;
62014 }
62015 @@ -2211,7 +2211,7 @@ repeat:
62016 ac->ac_status = AC_STATUS_CONTINUE;
62017 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62018 cr = 3;
62019 - atomic_inc(&sbi->s_mb_lost_chunks);
62020 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62021 goto repeat;
62022 }
62023 }
62024 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62025 if (sbi->s_mb_stats) {
62026 ext4_msg(sb, KERN_INFO,
62027 "mballoc: %u blocks %u reqs (%u success)",
62028 - atomic_read(&sbi->s_bal_allocated),
62029 - atomic_read(&sbi->s_bal_reqs),
62030 - atomic_read(&sbi->s_bal_success));
62031 + atomic_read_unchecked(&sbi->s_bal_allocated),
62032 + atomic_read_unchecked(&sbi->s_bal_reqs),
62033 + atomic_read_unchecked(&sbi->s_bal_success));
62034 ext4_msg(sb, KERN_INFO,
62035 "mballoc: %u extents scanned, %u goal hits, "
62036 "%u 2^N hits, %u breaks, %u lost",
62037 - atomic_read(&sbi->s_bal_ex_scanned),
62038 - atomic_read(&sbi->s_bal_goals),
62039 - atomic_read(&sbi->s_bal_2orders),
62040 - atomic_read(&sbi->s_bal_breaks),
62041 - atomic_read(&sbi->s_mb_lost_chunks));
62042 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62043 + atomic_read_unchecked(&sbi->s_bal_goals),
62044 + atomic_read_unchecked(&sbi->s_bal_2orders),
62045 + atomic_read_unchecked(&sbi->s_bal_breaks),
62046 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62047 ext4_msg(sb, KERN_INFO,
62048 "mballoc: %lu generated and it took %Lu",
62049 sbi->s_mb_buddies_generated,
62050 sbi->s_mb_generation_time);
62051 ext4_msg(sb, KERN_INFO,
62052 "mballoc: %u preallocated, %u discarded",
62053 - atomic_read(&sbi->s_mb_preallocated),
62054 - atomic_read(&sbi->s_mb_discarded));
62055 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62056 + atomic_read_unchecked(&sbi->s_mb_discarded));
62057 }
62058
62059 free_percpu(sbi->s_locality_groups);
62060 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62061 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62062
62063 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62064 - atomic_inc(&sbi->s_bal_reqs);
62065 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62066 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62067 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62068 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62069 - atomic_inc(&sbi->s_bal_success);
62070 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62071 + atomic_inc_unchecked(&sbi->s_bal_success);
62072 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62073 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62074 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62075 - atomic_inc(&sbi->s_bal_goals);
62076 + atomic_inc_unchecked(&sbi->s_bal_goals);
62077 if (ac->ac_found > sbi->s_mb_max_to_scan)
62078 - atomic_inc(&sbi->s_bal_breaks);
62079 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62080 }
62081
62082 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62083 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62084 trace_ext4_mb_new_inode_pa(ac, pa);
62085
62086 ext4_mb_use_inode_pa(ac, pa);
62087 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62088 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62089
62090 ei = EXT4_I(ac->ac_inode);
62091 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62092 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62093 trace_ext4_mb_new_group_pa(ac, pa);
62094
62095 ext4_mb_use_group_pa(ac, pa);
62096 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62097 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62098
62099 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62100 lg = ac->ac_lg;
62101 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62102 * from the bitmap and continue.
62103 */
62104 }
62105 - atomic_add(free, &sbi->s_mb_discarded);
62106 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62107
62108 return err;
62109 }
62110 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62111 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62112 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62113 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62114 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62115 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62116 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62117
62118 return 0;
62119 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62120 index 8313ca3..8a37d08 100644
62121 --- a/fs/ext4/mmp.c
62122 +++ b/fs/ext4/mmp.c
62123 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62124 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62125 const char *function, unsigned int line, const char *msg)
62126 {
62127 - __ext4_warning(sb, function, line, msg);
62128 + __ext4_warning(sb, function, line, "%s", msg);
62129 __ext4_warning(sb, function, line,
62130 "MMP failure info: last update time: %llu, last update "
62131 "node: %s, last update device: %s\n",
62132 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62133 index fc7391e..1927b04 100644
62134 --- a/fs/ext4/super.c
62135 +++ b/fs/ext4/super.c
62136 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62137 }
62138
62139 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62140 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62141 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62142 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62143
62144 #ifdef CONFIG_QUOTA
62145 @@ -2434,7 +2434,7 @@ struct ext4_attr {
62146 int offset;
62147 int deprecated_val;
62148 } u;
62149 -};
62150 +} __do_const;
62151
62152 static int parse_strtoull(const char *buf,
62153 unsigned long long max, unsigned long long *value)
62154 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62155 index 1e09fc7..0400dd4 100644
62156 --- a/fs/ext4/xattr.c
62157 +++ b/fs/ext4/xattr.c
62158 @@ -399,7 +399,7 @@ static int
62159 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62160 char *buffer, size_t buffer_size)
62161 {
62162 - size_t rest = buffer_size;
62163 + size_t rest = buffer_size, total_size = 0;
62164
62165 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62166 const struct xattr_handler *handler =
62167 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62168 buffer += size;
62169 }
62170 rest -= size;
62171 + total_size += size;
62172 }
62173 }
62174 - return buffer_size - rest;
62175 + return total_size;
62176 }
62177
62178 static int
62179 diff --git a/fs/fcntl.c b/fs/fcntl.c
62180 index 99d440a..eb979d1 100644
62181 --- a/fs/fcntl.c
62182 +++ b/fs/fcntl.c
62183 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62184 int force)
62185 {
62186 security_file_set_fowner(filp);
62187 + if (gr_handle_chroot_fowner(pid, type))
62188 + return;
62189 + if (gr_check_protected_task_fowner(pid, type))
62190 + return;
62191 f_modown(filp, pid, type, force);
62192 }
62193 EXPORT_SYMBOL(__f_setown);
62194 diff --git a/fs/fhandle.c b/fs/fhandle.c
62195 index 999ff5c..2281df9 100644
62196 --- a/fs/fhandle.c
62197 +++ b/fs/fhandle.c
62198 @@ -8,6 +8,7 @@
62199 #include <linux/fs_struct.h>
62200 #include <linux/fsnotify.h>
62201 #include <linux/personality.h>
62202 +#include <linux/grsecurity.h>
62203 #include <asm/uaccess.h>
62204 #include "internal.h"
62205 #include "mount.h"
62206 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62207 } else
62208 retval = 0;
62209 /* copy the mount id */
62210 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62211 - sizeof(*mnt_id)) ||
62212 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62213 copy_to_user(ufh, handle,
62214 sizeof(struct file_handle) + handle_bytes))
62215 retval = -EFAULT;
62216 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62217 * the directory. Ideally we would like CAP_DAC_SEARCH.
62218 * But we don't have that
62219 */
62220 - if (!capable(CAP_DAC_READ_SEARCH)) {
62221 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62222 retval = -EPERM;
62223 goto out_err;
62224 }
62225 @@ -195,8 +195,9 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62226 goto out_err;
62227 }
62228 /* copy the full handle */
62229 - if (copy_from_user(handle, ufh,
62230 - sizeof(struct file_handle) +
62231 + *handle = f_handle;
62232 + if (copy_from_user(&handle->f_handle,
62233 + &ufh->f_handle,
62234 f_handle.handle_bytes)) {
62235 retval = -EFAULT;
62236 goto out_handle;
62237 diff --git a/fs/file.c b/fs/file.c
62238 index ab3eb6a..8de2392 100644
62239 --- a/fs/file.c
62240 +++ b/fs/file.c
62241 @@ -16,6 +16,7 @@
62242 #include <linux/slab.h>
62243 #include <linux/vmalloc.h>
62244 #include <linux/file.h>
62245 +#include <linux/security.h>
62246 #include <linux/fdtable.h>
62247 #include <linux/bitops.h>
62248 #include <linux/interrupt.h>
62249 @@ -139,7 +140,7 @@ out:
62250 * Return <0 error code on error; 1 on successful completion.
62251 * The files->file_lock should be held on entry, and will be held on exit.
62252 */
62253 -static int expand_fdtable(struct files_struct *files, int nr)
62254 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62255 __releases(files->file_lock)
62256 __acquires(files->file_lock)
62257 {
62258 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62259 * expanded and execution may have blocked.
62260 * The files->file_lock should be held on entry, and will be held on exit.
62261 */
62262 -static int expand_files(struct files_struct *files, int nr)
62263 +static int expand_files(struct files_struct *files, unsigned int nr)
62264 {
62265 struct fdtable *fdt;
62266
62267 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62268 if (!file)
62269 return __close_fd(files, fd);
62270
62271 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62272 if (fd >= rlimit(RLIMIT_NOFILE))
62273 return -EBADF;
62274
62275 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62276 if (unlikely(oldfd == newfd))
62277 return -EINVAL;
62278
62279 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62280 if (newfd >= rlimit(RLIMIT_NOFILE))
62281 return -EBADF;
62282
62283 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62284 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62285 {
62286 int err;
62287 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62288 if (from >= rlimit(RLIMIT_NOFILE))
62289 return -EINVAL;
62290 err = alloc_fd(from, flags);
62291 diff --git a/fs/filesystems.c b/fs/filesystems.c
62292 index 5797d45..7d7d79a 100644
62293 --- a/fs/filesystems.c
62294 +++ b/fs/filesystems.c
62295 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62296 int len = dot ? dot - name : strlen(name);
62297
62298 fs = __get_fs_type(name, len);
62299 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62300 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62301 +#else
62302 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62303 +#endif
62304 fs = __get_fs_type(name, len);
62305
62306 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62307 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62308 index 7dca743..2f2786d 100644
62309 --- a/fs/fs_struct.c
62310 +++ b/fs/fs_struct.c
62311 @@ -4,6 +4,7 @@
62312 #include <linux/path.h>
62313 #include <linux/slab.h>
62314 #include <linux/fs_struct.h>
62315 +#include <linux/grsecurity.h>
62316 #include "internal.h"
62317
62318 /*
62319 @@ -15,14 +16,18 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62320 struct path old_root;
62321
62322 path_get(path);
62323 + gr_inc_chroot_refcnts(path->dentry, path->mnt);
62324 spin_lock(&fs->lock);
62325 write_seqcount_begin(&fs->seq);
62326 old_root = fs->root;
62327 fs->root = *path;
62328 + gr_set_chroot_entries(current, path);
62329 write_seqcount_end(&fs->seq);
62330 spin_unlock(&fs->lock);
62331 - if (old_root.dentry)
62332 + if (old_root.dentry) {
62333 + gr_dec_chroot_refcnts(old_root.dentry, old_root.mnt);
62334 path_put(&old_root);
62335 + }
62336 }
62337
62338 /*
62339 @@ -67,6 +72,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62340 int hits = 0;
62341 spin_lock(&fs->lock);
62342 write_seqcount_begin(&fs->seq);
62343 + /* this root replacement is only done by pivot_root,
62344 + leave grsec's chroot tagging alone for this task
62345 + so that a pivoted root isn't treated as a chroot
62346 + */
62347 hits += replace_path(&fs->root, old_root, new_root);
62348 hits += replace_path(&fs->pwd, old_root, new_root);
62349 write_seqcount_end(&fs->seq);
62350 @@ -85,6 +94,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62351
62352 void free_fs_struct(struct fs_struct *fs)
62353 {
62354 + gr_dec_chroot_refcnts(fs->root.dentry, fs->root.mnt);
62355 path_put(&fs->root);
62356 path_put(&fs->pwd);
62357 kmem_cache_free(fs_cachep, fs);
62358 @@ -99,7 +109,8 @@ void exit_fs(struct task_struct *tsk)
62359 task_lock(tsk);
62360 spin_lock(&fs->lock);
62361 tsk->fs = NULL;
62362 - kill = !--fs->users;
62363 + gr_clear_chroot_entries(tsk);
62364 + kill = !atomic_dec_return(&fs->users);
62365 spin_unlock(&fs->lock);
62366 task_unlock(tsk);
62367 if (kill)
62368 @@ -112,7 +123,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62369 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62370 /* We don't need to lock fs - think why ;-) */
62371 if (fs) {
62372 - fs->users = 1;
62373 + atomic_set(&fs->users, 1);
62374 fs->in_exec = 0;
62375 spin_lock_init(&fs->lock);
62376 seqcount_init(&fs->seq);
62377 @@ -121,6 +132,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62378 spin_lock(&old->lock);
62379 fs->root = old->root;
62380 path_get(&fs->root);
62381 + /* instead of calling gr_set_chroot_entries here,
62382 + we call it from every caller of this function
62383 + */
62384 fs->pwd = old->pwd;
62385 path_get(&fs->pwd);
62386 spin_unlock(&old->lock);
62387 @@ -139,8 +153,9 @@ int unshare_fs_struct(void)
62388
62389 task_lock(current);
62390 spin_lock(&fs->lock);
62391 - kill = !--fs->users;
62392 + kill = !atomic_dec_return(&fs->users);
62393 current->fs = new_fs;
62394 + gr_set_chroot_entries(current, &new_fs->root);
62395 spin_unlock(&fs->lock);
62396 task_unlock(current);
62397
62398 @@ -153,13 +168,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62399
62400 int current_umask(void)
62401 {
62402 - return current->fs->umask;
62403 + return current->fs->umask | gr_acl_umask();
62404 }
62405 EXPORT_SYMBOL(current_umask);
62406
62407 /* to be mentioned only in INIT_TASK */
62408 struct fs_struct init_fs = {
62409 - .users = 1,
62410 + .users = ATOMIC_INIT(1),
62411 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62412 .seq = SEQCNT_ZERO(init_fs.seq),
62413 .umask = 0022,
62414 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62415 index 89acec7..a575262 100644
62416 --- a/fs/fscache/cookie.c
62417 +++ b/fs/fscache/cookie.c
62418 @@ -19,7 +19,7 @@
62419
62420 struct kmem_cache *fscache_cookie_jar;
62421
62422 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62423 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62424
62425 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62426 static int fscache_alloc_object(struct fscache_cache *cache,
62427 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62428 parent ? (char *) parent->def->name : "<no-parent>",
62429 def->name, netfs_data, enable);
62430
62431 - fscache_stat(&fscache_n_acquires);
62432 + fscache_stat_unchecked(&fscache_n_acquires);
62433
62434 /* if there's no parent cookie, then we don't create one here either */
62435 if (!parent) {
62436 - fscache_stat(&fscache_n_acquires_null);
62437 + fscache_stat_unchecked(&fscache_n_acquires_null);
62438 _leave(" [no parent]");
62439 return NULL;
62440 }
62441 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62442 /* allocate and initialise a cookie */
62443 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62444 if (!cookie) {
62445 - fscache_stat(&fscache_n_acquires_oom);
62446 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62447 _leave(" [ENOMEM]");
62448 return NULL;
62449 }
62450 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62451
62452 switch (cookie->def->type) {
62453 case FSCACHE_COOKIE_TYPE_INDEX:
62454 - fscache_stat(&fscache_n_cookie_index);
62455 + fscache_stat_unchecked(&fscache_n_cookie_index);
62456 break;
62457 case FSCACHE_COOKIE_TYPE_DATAFILE:
62458 - fscache_stat(&fscache_n_cookie_data);
62459 + fscache_stat_unchecked(&fscache_n_cookie_data);
62460 break;
62461 default:
62462 - fscache_stat(&fscache_n_cookie_special);
62463 + fscache_stat_unchecked(&fscache_n_cookie_special);
62464 break;
62465 }
62466
62467 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62468 } else {
62469 atomic_dec(&parent->n_children);
62470 __fscache_cookie_put(cookie);
62471 - fscache_stat(&fscache_n_acquires_nobufs);
62472 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62473 _leave(" = NULL");
62474 return NULL;
62475 }
62476 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62477 }
62478 }
62479
62480 - fscache_stat(&fscache_n_acquires_ok);
62481 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62482 _leave(" = %p", cookie);
62483 return cookie;
62484 }
62485 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62486 cache = fscache_select_cache_for_object(cookie->parent);
62487 if (!cache) {
62488 up_read(&fscache_addremove_sem);
62489 - fscache_stat(&fscache_n_acquires_no_cache);
62490 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62491 _leave(" = -ENOMEDIUM [no cache]");
62492 return -ENOMEDIUM;
62493 }
62494 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62495 object = cache->ops->alloc_object(cache, cookie);
62496 fscache_stat_d(&fscache_n_cop_alloc_object);
62497 if (IS_ERR(object)) {
62498 - fscache_stat(&fscache_n_object_no_alloc);
62499 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62500 ret = PTR_ERR(object);
62501 goto error;
62502 }
62503
62504 - fscache_stat(&fscache_n_object_alloc);
62505 + fscache_stat_unchecked(&fscache_n_object_alloc);
62506
62507 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62508 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62509
62510 _debug("ALLOC OBJ%x: %s {%lx}",
62511 object->debug_id, cookie->def->name, object->events);
62512 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62513
62514 _enter("{%s}", cookie->def->name);
62515
62516 - fscache_stat(&fscache_n_invalidates);
62517 + fscache_stat_unchecked(&fscache_n_invalidates);
62518
62519 /* Only permit invalidation of data files. Invalidating an index will
62520 * require the caller to release all its attachments to the tree rooted
62521 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62522 {
62523 struct fscache_object *object;
62524
62525 - fscache_stat(&fscache_n_updates);
62526 + fscache_stat_unchecked(&fscache_n_updates);
62527
62528 if (!cookie) {
62529 - fscache_stat(&fscache_n_updates_null);
62530 + fscache_stat_unchecked(&fscache_n_updates_null);
62531 _leave(" [no cookie]");
62532 return;
62533 }
62534 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62535 */
62536 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62537 {
62538 - fscache_stat(&fscache_n_relinquishes);
62539 + fscache_stat_unchecked(&fscache_n_relinquishes);
62540 if (retire)
62541 - fscache_stat(&fscache_n_relinquishes_retire);
62542 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62543
62544 if (!cookie) {
62545 - fscache_stat(&fscache_n_relinquishes_null);
62546 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62547 _leave(" [no cookie]");
62548 return;
62549 }
62550 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62551 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62552 goto inconsistent;
62553
62554 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62555 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62556
62557 __fscache_use_cookie(cookie);
62558 if (fscache_submit_op(object, op) < 0)
62559 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62560 index 7872a62..d91b19f 100644
62561 --- a/fs/fscache/internal.h
62562 +++ b/fs/fscache/internal.h
62563 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62564 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62565 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62566 struct fscache_operation *,
62567 - atomic_t *,
62568 - atomic_t *,
62569 + atomic_unchecked_t *,
62570 + atomic_unchecked_t *,
62571 void (*)(struct fscache_operation *));
62572 extern void fscache_invalidate_writes(struct fscache_cookie *);
62573
62574 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62575 * stats.c
62576 */
62577 #ifdef CONFIG_FSCACHE_STATS
62578 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62579 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62580 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62581 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62582
62583 -extern atomic_t fscache_n_op_pend;
62584 -extern atomic_t fscache_n_op_run;
62585 -extern atomic_t fscache_n_op_enqueue;
62586 -extern atomic_t fscache_n_op_deferred_release;
62587 -extern atomic_t fscache_n_op_release;
62588 -extern atomic_t fscache_n_op_gc;
62589 -extern atomic_t fscache_n_op_cancelled;
62590 -extern atomic_t fscache_n_op_rejected;
62591 +extern atomic_unchecked_t fscache_n_op_pend;
62592 +extern atomic_unchecked_t fscache_n_op_run;
62593 +extern atomic_unchecked_t fscache_n_op_enqueue;
62594 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62595 +extern atomic_unchecked_t fscache_n_op_release;
62596 +extern atomic_unchecked_t fscache_n_op_gc;
62597 +extern atomic_unchecked_t fscache_n_op_cancelled;
62598 +extern atomic_unchecked_t fscache_n_op_rejected;
62599
62600 -extern atomic_t fscache_n_attr_changed;
62601 -extern atomic_t fscache_n_attr_changed_ok;
62602 -extern atomic_t fscache_n_attr_changed_nobufs;
62603 -extern atomic_t fscache_n_attr_changed_nomem;
62604 -extern atomic_t fscache_n_attr_changed_calls;
62605 +extern atomic_unchecked_t fscache_n_attr_changed;
62606 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62607 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62608 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62609 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62610
62611 -extern atomic_t fscache_n_allocs;
62612 -extern atomic_t fscache_n_allocs_ok;
62613 -extern atomic_t fscache_n_allocs_wait;
62614 -extern atomic_t fscache_n_allocs_nobufs;
62615 -extern atomic_t fscache_n_allocs_intr;
62616 -extern atomic_t fscache_n_allocs_object_dead;
62617 -extern atomic_t fscache_n_alloc_ops;
62618 -extern atomic_t fscache_n_alloc_op_waits;
62619 +extern atomic_unchecked_t fscache_n_allocs;
62620 +extern atomic_unchecked_t fscache_n_allocs_ok;
62621 +extern atomic_unchecked_t fscache_n_allocs_wait;
62622 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62623 +extern atomic_unchecked_t fscache_n_allocs_intr;
62624 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62625 +extern atomic_unchecked_t fscache_n_alloc_ops;
62626 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62627
62628 -extern atomic_t fscache_n_retrievals;
62629 -extern atomic_t fscache_n_retrievals_ok;
62630 -extern atomic_t fscache_n_retrievals_wait;
62631 -extern atomic_t fscache_n_retrievals_nodata;
62632 -extern atomic_t fscache_n_retrievals_nobufs;
62633 -extern atomic_t fscache_n_retrievals_intr;
62634 -extern atomic_t fscache_n_retrievals_nomem;
62635 -extern atomic_t fscache_n_retrievals_object_dead;
62636 -extern atomic_t fscache_n_retrieval_ops;
62637 -extern atomic_t fscache_n_retrieval_op_waits;
62638 +extern atomic_unchecked_t fscache_n_retrievals;
62639 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62640 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62641 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62642 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62643 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62644 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62645 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62646 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62647 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62648
62649 -extern atomic_t fscache_n_stores;
62650 -extern atomic_t fscache_n_stores_ok;
62651 -extern atomic_t fscache_n_stores_again;
62652 -extern atomic_t fscache_n_stores_nobufs;
62653 -extern atomic_t fscache_n_stores_oom;
62654 -extern atomic_t fscache_n_store_ops;
62655 -extern atomic_t fscache_n_store_calls;
62656 -extern atomic_t fscache_n_store_pages;
62657 -extern atomic_t fscache_n_store_radix_deletes;
62658 -extern atomic_t fscache_n_store_pages_over_limit;
62659 +extern atomic_unchecked_t fscache_n_stores;
62660 +extern atomic_unchecked_t fscache_n_stores_ok;
62661 +extern atomic_unchecked_t fscache_n_stores_again;
62662 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62663 +extern atomic_unchecked_t fscache_n_stores_oom;
62664 +extern atomic_unchecked_t fscache_n_store_ops;
62665 +extern atomic_unchecked_t fscache_n_store_calls;
62666 +extern atomic_unchecked_t fscache_n_store_pages;
62667 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62668 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62669
62670 -extern atomic_t fscache_n_store_vmscan_not_storing;
62671 -extern atomic_t fscache_n_store_vmscan_gone;
62672 -extern atomic_t fscache_n_store_vmscan_busy;
62673 -extern atomic_t fscache_n_store_vmscan_cancelled;
62674 -extern atomic_t fscache_n_store_vmscan_wait;
62675 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62676 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62677 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62678 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62679 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62680
62681 -extern atomic_t fscache_n_marks;
62682 -extern atomic_t fscache_n_uncaches;
62683 +extern atomic_unchecked_t fscache_n_marks;
62684 +extern atomic_unchecked_t fscache_n_uncaches;
62685
62686 -extern atomic_t fscache_n_acquires;
62687 -extern atomic_t fscache_n_acquires_null;
62688 -extern atomic_t fscache_n_acquires_no_cache;
62689 -extern atomic_t fscache_n_acquires_ok;
62690 -extern atomic_t fscache_n_acquires_nobufs;
62691 -extern atomic_t fscache_n_acquires_oom;
62692 +extern atomic_unchecked_t fscache_n_acquires;
62693 +extern atomic_unchecked_t fscache_n_acquires_null;
62694 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62695 +extern atomic_unchecked_t fscache_n_acquires_ok;
62696 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62697 +extern atomic_unchecked_t fscache_n_acquires_oom;
62698
62699 -extern atomic_t fscache_n_invalidates;
62700 -extern atomic_t fscache_n_invalidates_run;
62701 +extern atomic_unchecked_t fscache_n_invalidates;
62702 +extern atomic_unchecked_t fscache_n_invalidates_run;
62703
62704 -extern atomic_t fscache_n_updates;
62705 -extern atomic_t fscache_n_updates_null;
62706 -extern atomic_t fscache_n_updates_run;
62707 +extern atomic_unchecked_t fscache_n_updates;
62708 +extern atomic_unchecked_t fscache_n_updates_null;
62709 +extern atomic_unchecked_t fscache_n_updates_run;
62710
62711 -extern atomic_t fscache_n_relinquishes;
62712 -extern atomic_t fscache_n_relinquishes_null;
62713 -extern atomic_t fscache_n_relinquishes_waitcrt;
62714 -extern atomic_t fscache_n_relinquishes_retire;
62715 +extern atomic_unchecked_t fscache_n_relinquishes;
62716 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62717 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62718 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62719
62720 -extern atomic_t fscache_n_cookie_index;
62721 -extern atomic_t fscache_n_cookie_data;
62722 -extern atomic_t fscache_n_cookie_special;
62723 +extern atomic_unchecked_t fscache_n_cookie_index;
62724 +extern atomic_unchecked_t fscache_n_cookie_data;
62725 +extern atomic_unchecked_t fscache_n_cookie_special;
62726
62727 -extern atomic_t fscache_n_object_alloc;
62728 -extern atomic_t fscache_n_object_no_alloc;
62729 -extern atomic_t fscache_n_object_lookups;
62730 -extern atomic_t fscache_n_object_lookups_negative;
62731 -extern atomic_t fscache_n_object_lookups_positive;
62732 -extern atomic_t fscache_n_object_lookups_timed_out;
62733 -extern atomic_t fscache_n_object_created;
62734 -extern atomic_t fscache_n_object_avail;
62735 -extern atomic_t fscache_n_object_dead;
62736 +extern atomic_unchecked_t fscache_n_object_alloc;
62737 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62738 +extern atomic_unchecked_t fscache_n_object_lookups;
62739 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62740 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62741 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62742 +extern atomic_unchecked_t fscache_n_object_created;
62743 +extern atomic_unchecked_t fscache_n_object_avail;
62744 +extern atomic_unchecked_t fscache_n_object_dead;
62745
62746 -extern atomic_t fscache_n_checkaux_none;
62747 -extern atomic_t fscache_n_checkaux_okay;
62748 -extern atomic_t fscache_n_checkaux_update;
62749 -extern atomic_t fscache_n_checkaux_obsolete;
62750 +extern atomic_unchecked_t fscache_n_checkaux_none;
62751 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62752 +extern atomic_unchecked_t fscache_n_checkaux_update;
62753 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62754
62755 extern atomic_t fscache_n_cop_alloc_object;
62756 extern atomic_t fscache_n_cop_lookup_object;
62757 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62758 atomic_inc(stat);
62759 }
62760
62761 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62762 +{
62763 + atomic_inc_unchecked(stat);
62764 +}
62765 +
62766 static inline void fscache_stat_d(atomic_t *stat)
62767 {
62768 atomic_dec(stat);
62769 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62770
62771 #define __fscache_stat(stat) (NULL)
62772 #define fscache_stat(stat) do {} while (0)
62773 +#define fscache_stat_unchecked(stat) do {} while (0)
62774 #define fscache_stat_d(stat) do {} while (0)
62775 #endif
62776
62777 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62778 index da032da..0076ce7 100644
62779 --- a/fs/fscache/object.c
62780 +++ b/fs/fscache/object.c
62781 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62782 _debug("LOOKUP \"%s\" in \"%s\"",
62783 cookie->def->name, object->cache->tag->name);
62784
62785 - fscache_stat(&fscache_n_object_lookups);
62786 + fscache_stat_unchecked(&fscache_n_object_lookups);
62787 fscache_stat(&fscache_n_cop_lookup_object);
62788 ret = object->cache->ops->lookup_object(object);
62789 fscache_stat_d(&fscache_n_cop_lookup_object);
62790 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62791 if (ret == -ETIMEDOUT) {
62792 /* probably stuck behind another object, so move this one to
62793 * the back of the queue */
62794 - fscache_stat(&fscache_n_object_lookups_timed_out);
62795 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62796 _leave(" [timeout]");
62797 return NO_TRANSIT;
62798 }
62799 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62800 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62801
62802 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62803 - fscache_stat(&fscache_n_object_lookups_negative);
62804 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62805
62806 /* Allow write requests to begin stacking up and read requests to begin
62807 * returning ENODATA.
62808 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62809 /* if we were still looking up, then we must have a positive lookup
62810 * result, in which case there may be data available */
62811 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62812 - fscache_stat(&fscache_n_object_lookups_positive);
62813 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62814
62815 /* We do (presumably) have data */
62816 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62817 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62818 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62819 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62820 } else {
62821 - fscache_stat(&fscache_n_object_created);
62822 + fscache_stat_unchecked(&fscache_n_object_created);
62823 }
62824
62825 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62826 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62827 fscache_stat_d(&fscache_n_cop_lookup_complete);
62828
62829 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62830 - fscache_stat(&fscache_n_object_avail);
62831 + fscache_stat_unchecked(&fscache_n_object_avail);
62832
62833 _leave("");
62834 return transit_to(JUMPSTART_DEPS);
62835 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62836
62837 /* this just shifts the object release to the work processor */
62838 fscache_put_object(object);
62839 - fscache_stat(&fscache_n_object_dead);
62840 + fscache_stat_unchecked(&fscache_n_object_dead);
62841
62842 _leave("");
62843 return transit_to(OBJECT_DEAD);
62844 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62845 enum fscache_checkaux result;
62846
62847 if (!object->cookie->def->check_aux) {
62848 - fscache_stat(&fscache_n_checkaux_none);
62849 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62850 return FSCACHE_CHECKAUX_OKAY;
62851 }
62852
62853 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62854 switch (result) {
62855 /* entry okay as is */
62856 case FSCACHE_CHECKAUX_OKAY:
62857 - fscache_stat(&fscache_n_checkaux_okay);
62858 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62859 break;
62860
62861 /* entry requires update */
62862 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62863 - fscache_stat(&fscache_n_checkaux_update);
62864 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62865 break;
62866
62867 /* entry requires deletion */
62868 case FSCACHE_CHECKAUX_OBSOLETE:
62869 - fscache_stat(&fscache_n_checkaux_obsolete);
62870 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62871 break;
62872
62873 default:
62874 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62875 {
62876 const struct fscache_state *s;
62877
62878 - fscache_stat(&fscache_n_invalidates_run);
62879 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62880 fscache_stat(&fscache_n_cop_invalidate_object);
62881 s = _fscache_invalidate_object(object, event);
62882 fscache_stat_d(&fscache_n_cop_invalidate_object);
62883 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62884 {
62885 _enter("{OBJ%x},%d", object->debug_id, event);
62886
62887 - fscache_stat(&fscache_n_updates_run);
62888 + fscache_stat_unchecked(&fscache_n_updates_run);
62889 fscache_stat(&fscache_n_cop_update_object);
62890 object->cache->ops->update_object(object);
62891 fscache_stat_d(&fscache_n_cop_update_object);
62892 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62893 index e7b87a0..a85d47a 100644
62894 --- a/fs/fscache/operation.c
62895 +++ b/fs/fscache/operation.c
62896 @@ -17,7 +17,7 @@
62897 #include <linux/slab.h>
62898 #include "internal.h"
62899
62900 -atomic_t fscache_op_debug_id;
62901 +atomic_unchecked_t fscache_op_debug_id;
62902 EXPORT_SYMBOL(fscache_op_debug_id);
62903
62904 /**
62905 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62906 ASSERTCMP(atomic_read(&op->usage), >, 0);
62907 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62908
62909 - fscache_stat(&fscache_n_op_enqueue);
62910 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62911 switch (op->flags & FSCACHE_OP_TYPE) {
62912 case FSCACHE_OP_ASYNC:
62913 _debug("queue async");
62914 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62915 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62916 if (op->processor)
62917 fscache_enqueue_operation(op);
62918 - fscache_stat(&fscache_n_op_run);
62919 + fscache_stat_unchecked(&fscache_n_op_run);
62920 }
62921
62922 /*
62923 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62924 if (object->n_in_progress > 0) {
62925 atomic_inc(&op->usage);
62926 list_add_tail(&op->pend_link, &object->pending_ops);
62927 - fscache_stat(&fscache_n_op_pend);
62928 + fscache_stat_unchecked(&fscache_n_op_pend);
62929 } else if (!list_empty(&object->pending_ops)) {
62930 atomic_inc(&op->usage);
62931 list_add_tail(&op->pend_link, &object->pending_ops);
62932 - fscache_stat(&fscache_n_op_pend);
62933 + fscache_stat_unchecked(&fscache_n_op_pend);
62934 fscache_start_operations(object);
62935 } else {
62936 ASSERTCMP(object->n_in_progress, ==, 0);
62937 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62938 object->n_exclusive++; /* reads and writes must wait */
62939 atomic_inc(&op->usage);
62940 list_add_tail(&op->pend_link, &object->pending_ops);
62941 - fscache_stat(&fscache_n_op_pend);
62942 + fscache_stat_unchecked(&fscache_n_op_pend);
62943 ret = 0;
62944 } else {
62945 /* If we're in any other state, there must have been an I/O
62946 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62947 if (object->n_exclusive > 0) {
62948 atomic_inc(&op->usage);
62949 list_add_tail(&op->pend_link, &object->pending_ops);
62950 - fscache_stat(&fscache_n_op_pend);
62951 + fscache_stat_unchecked(&fscache_n_op_pend);
62952 } else if (!list_empty(&object->pending_ops)) {
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 fscache_start_operations(object);
62958 } else {
62959 ASSERTCMP(object->n_exclusive, ==, 0);
62960 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62961 object->n_ops++;
62962 atomic_inc(&op->usage);
62963 list_add_tail(&op->pend_link, &object->pending_ops);
62964 - fscache_stat(&fscache_n_op_pend);
62965 + fscache_stat_unchecked(&fscache_n_op_pend);
62966 ret = 0;
62967 } else if (fscache_object_is_dying(object)) {
62968 - fscache_stat(&fscache_n_op_rejected);
62969 + fscache_stat_unchecked(&fscache_n_op_rejected);
62970 op->state = FSCACHE_OP_ST_CANCELLED;
62971 ret = -ENOBUFS;
62972 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62973 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62974 ret = -EBUSY;
62975 if (op->state == FSCACHE_OP_ST_PENDING) {
62976 ASSERT(!list_empty(&op->pend_link));
62977 - fscache_stat(&fscache_n_op_cancelled);
62978 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62979 list_del_init(&op->pend_link);
62980 if (do_cancel)
62981 do_cancel(op);
62982 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62983 while (!list_empty(&object->pending_ops)) {
62984 op = list_entry(object->pending_ops.next,
62985 struct fscache_operation, pend_link);
62986 - fscache_stat(&fscache_n_op_cancelled);
62987 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62988 list_del_init(&op->pend_link);
62989
62990 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62991 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62992 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62993 op->state = FSCACHE_OP_ST_DEAD;
62994
62995 - fscache_stat(&fscache_n_op_release);
62996 + fscache_stat_unchecked(&fscache_n_op_release);
62997
62998 if (op->release) {
62999 op->release(op);
63000 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63001 * lock, and defer it otherwise */
63002 if (!spin_trylock(&object->lock)) {
63003 _debug("defer put");
63004 - fscache_stat(&fscache_n_op_deferred_release);
63005 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63006
63007 cache = object->cache;
63008 spin_lock(&cache->op_gc_list_lock);
63009 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63010
63011 _debug("GC DEFERRED REL OBJ%x OP%x",
63012 object->debug_id, op->debug_id);
63013 - fscache_stat(&fscache_n_op_gc);
63014 + fscache_stat_unchecked(&fscache_n_op_gc);
63015
63016 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63017 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63018 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63019 index de33b3f..8be4d29 100644
63020 --- a/fs/fscache/page.c
63021 +++ b/fs/fscache/page.c
63022 @@ -74,7 +74,7 @@ try_again:
63023 val = radix_tree_lookup(&cookie->stores, page->index);
63024 if (!val) {
63025 rcu_read_unlock();
63026 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63027 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63028 __fscache_uncache_page(cookie, page);
63029 return true;
63030 }
63031 @@ -104,11 +104,11 @@ try_again:
63032 spin_unlock(&cookie->stores_lock);
63033
63034 if (xpage) {
63035 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63036 - fscache_stat(&fscache_n_store_radix_deletes);
63037 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63038 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63039 ASSERTCMP(xpage, ==, page);
63040 } else {
63041 - fscache_stat(&fscache_n_store_vmscan_gone);
63042 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63043 }
63044
63045 wake_up_bit(&cookie->flags, 0);
63046 @@ -123,11 +123,11 @@ page_busy:
63047 * sleeping on memory allocation, so we may need to impose a timeout
63048 * too. */
63049 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63050 - fscache_stat(&fscache_n_store_vmscan_busy);
63051 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63052 return false;
63053 }
63054
63055 - fscache_stat(&fscache_n_store_vmscan_wait);
63056 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63057 if (!release_page_wait_timeout(cookie, page))
63058 _debug("fscache writeout timeout page: %p{%lx}",
63059 page, page->index);
63060 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63061 FSCACHE_COOKIE_STORING_TAG);
63062 if (!radix_tree_tag_get(&cookie->stores, page->index,
63063 FSCACHE_COOKIE_PENDING_TAG)) {
63064 - fscache_stat(&fscache_n_store_radix_deletes);
63065 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63066 xpage = radix_tree_delete(&cookie->stores, page->index);
63067 }
63068 spin_unlock(&cookie->stores_lock);
63069 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63070
63071 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63072
63073 - fscache_stat(&fscache_n_attr_changed_calls);
63074 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63075
63076 if (fscache_object_is_active(object)) {
63077 fscache_stat(&fscache_n_cop_attr_changed);
63078 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63079
63080 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63081
63082 - fscache_stat(&fscache_n_attr_changed);
63083 + fscache_stat_unchecked(&fscache_n_attr_changed);
63084
63085 op = kzalloc(sizeof(*op), GFP_KERNEL);
63086 if (!op) {
63087 - fscache_stat(&fscache_n_attr_changed_nomem);
63088 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63089 _leave(" = -ENOMEM");
63090 return -ENOMEM;
63091 }
63092 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63093 if (fscache_submit_exclusive_op(object, op) < 0)
63094 goto nobufs_dec;
63095 spin_unlock(&cookie->lock);
63096 - fscache_stat(&fscache_n_attr_changed_ok);
63097 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63098 fscache_put_operation(op);
63099 _leave(" = 0");
63100 return 0;
63101 @@ -242,7 +242,7 @@ nobufs:
63102 kfree(op);
63103 if (wake_cookie)
63104 __fscache_wake_unused_cookie(cookie);
63105 - fscache_stat(&fscache_n_attr_changed_nobufs);
63106 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63107 _leave(" = %d", -ENOBUFS);
63108 return -ENOBUFS;
63109 }
63110 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63111 /* allocate a retrieval operation and attempt to submit it */
63112 op = kzalloc(sizeof(*op), GFP_NOIO);
63113 if (!op) {
63114 - fscache_stat(&fscache_n_retrievals_nomem);
63115 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63116 return NULL;
63117 }
63118
63119 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63120 return 0;
63121 }
63122
63123 - fscache_stat(&fscache_n_retrievals_wait);
63124 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63125
63126 jif = jiffies;
63127 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63128 TASK_INTERRUPTIBLE) != 0) {
63129 - fscache_stat(&fscache_n_retrievals_intr);
63130 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63131 _leave(" = -ERESTARTSYS");
63132 return -ERESTARTSYS;
63133 }
63134 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63135 */
63136 int fscache_wait_for_operation_activation(struct fscache_object *object,
63137 struct fscache_operation *op,
63138 - atomic_t *stat_op_waits,
63139 - atomic_t *stat_object_dead,
63140 + atomic_unchecked_t *stat_op_waits,
63141 + atomic_unchecked_t *stat_object_dead,
63142 void (*do_cancel)(struct fscache_operation *))
63143 {
63144 int ret;
63145 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63146
63147 _debug(">>> WT");
63148 if (stat_op_waits)
63149 - fscache_stat(stat_op_waits);
63150 + fscache_stat_unchecked(stat_op_waits);
63151 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63152 TASK_INTERRUPTIBLE) != 0) {
63153 ret = fscache_cancel_op(op, do_cancel);
63154 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63155 check_if_dead:
63156 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63157 if (stat_object_dead)
63158 - fscache_stat(stat_object_dead);
63159 + fscache_stat_unchecked(stat_object_dead);
63160 _leave(" = -ENOBUFS [cancelled]");
63161 return -ENOBUFS;
63162 }
63163 @@ -381,7 +381,7 @@ check_if_dead:
63164 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63165 fscache_cancel_op(op, do_cancel);
63166 if (stat_object_dead)
63167 - fscache_stat(stat_object_dead);
63168 + fscache_stat_unchecked(stat_object_dead);
63169 return -ENOBUFS;
63170 }
63171 return 0;
63172 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63173
63174 _enter("%p,%p,,,", cookie, page);
63175
63176 - fscache_stat(&fscache_n_retrievals);
63177 + fscache_stat_unchecked(&fscache_n_retrievals);
63178
63179 if (hlist_empty(&cookie->backing_objects))
63180 goto nobufs;
63181 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63182 goto nobufs_unlock_dec;
63183 spin_unlock(&cookie->lock);
63184
63185 - fscache_stat(&fscache_n_retrieval_ops);
63186 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63187
63188 /* pin the netfs read context in case we need to do the actual netfs
63189 * read because we've encountered a cache read failure */
63190 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63191
63192 error:
63193 if (ret == -ENOMEM)
63194 - fscache_stat(&fscache_n_retrievals_nomem);
63195 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63196 else if (ret == -ERESTARTSYS)
63197 - fscache_stat(&fscache_n_retrievals_intr);
63198 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63199 else if (ret == -ENODATA)
63200 - fscache_stat(&fscache_n_retrievals_nodata);
63201 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63202 else if (ret < 0)
63203 - fscache_stat(&fscache_n_retrievals_nobufs);
63204 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63205 else
63206 - fscache_stat(&fscache_n_retrievals_ok);
63207 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63208
63209 fscache_put_retrieval(op);
63210 _leave(" = %d", ret);
63211 @@ -505,7 +505,7 @@ nobufs_unlock:
63212 __fscache_wake_unused_cookie(cookie);
63213 kfree(op);
63214 nobufs:
63215 - fscache_stat(&fscache_n_retrievals_nobufs);
63216 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63217 _leave(" = -ENOBUFS");
63218 return -ENOBUFS;
63219 }
63220 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63221
63222 _enter("%p,,%d,,,", cookie, *nr_pages);
63223
63224 - fscache_stat(&fscache_n_retrievals);
63225 + fscache_stat_unchecked(&fscache_n_retrievals);
63226
63227 if (hlist_empty(&cookie->backing_objects))
63228 goto nobufs;
63229 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63230 goto nobufs_unlock_dec;
63231 spin_unlock(&cookie->lock);
63232
63233 - fscache_stat(&fscache_n_retrieval_ops);
63234 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63235
63236 /* pin the netfs read context in case we need to do the actual netfs
63237 * read because we've encountered a cache read failure */
63238 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63239
63240 error:
63241 if (ret == -ENOMEM)
63242 - fscache_stat(&fscache_n_retrievals_nomem);
63243 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63244 else if (ret == -ERESTARTSYS)
63245 - fscache_stat(&fscache_n_retrievals_intr);
63246 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63247 else if (ret == -ENODATA)
63248 - fscache_stat(&fscache_n_retrievals_nodata);
63249 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63250 else if (ret < 0)
63251 - fscache_stat(&fscache_n_retrievals_nobufs);
63252 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63253 else
63254 - fscache_stat(&fscache_n_retrievals_ok);
63255 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63256
63257 fscache_put_retrieval(op);
63258 _leave(" = %d", ret);
63259 @@ -636,7 +636,7 @@ nobufs_unlock:
63260 if (wake_cookie)
63261 __fscache_wake_unused_cookie(cookie);
63262 nobufs:
63263 - fscache_stat(&fscache_n_retrievals_nobufs);
63264 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63265 _leave(" = -ENOBUFS");
63266 return -ENOBUFS;
63267 }
63268 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63269
63270 _enter("%p,%p,,,", cookie, page);
63271
63272 - fscache_stat(&fscache_n_allocs);
63273 + fscache_stat_unchecked(&fscache_n_allocs);
63274
63275 if (hlist_empty(&cookie->backing_objects))
63276 goto nobufs;
63277 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63278 goto nobufs_unlock_dec;
63279 spin_unlock(&cookie->lock);
63280
63281 - fscache_stat(&fscache_n_alloc_ops);
63282 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63283
63284 ret = fscache_wait_for_operation_activation(
63285 object, &op->op,
63286 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63287
63288 error:
63289 if (ret == -ERESTARTSYS)
63290 - fscache_stat(&fscache_n_allocs_intr);
63291 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63292 else if (ret < 0)
63293 - fscache_stat(&fscache_n_allocs_nobufs);
63294 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63295 else
63296 - fscache_stat(&fscache_n_allocs_ok);
63297 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63298
63299 fscache_put_retrieval(op);
63300 _leave(" = %d", ret);
63301 @@ -730,7 +730,7 @@ nobufs_unlock:
63302 if (wake_cookie)
63303 __fscache_wake_unused_cookie(cookie);
63304 nobufs:
63305 - fscache_stat(&fscache_n_allocs_nobufs);
63306 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63307 _leave(" = -ENOBUFS");
63308 return -ENOBUFS;
63309 }
63310 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63311
63312 spin_lock(&cookie->stores_lock);
63313
63314 - fscache_stat(&fscache_n_store_calls);
63315 + fscache_stat_unchecked(&fscache_n_store_calls);
63316
63317 /* find a page to store */
63318 page = NULL;
63319 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63320 page = results[0];
63321 _debug("gang %d [%lx]", n, page->index);
63322 if (page->index > op->store_limit) {
63323 - fscache_stat(&fscache_n_store_pages_over_limit);
63324 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63325 goto superseded;
63326 }
63327
63328 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63329 spin_unlock(&cookie->stores_lock);
63330 spin_unlock(&object->lock);
63331
63332 - fscache_stat(&fscache_n_store_pages);
63333 + fscache_stat_unchecked(&fscache_n_store_pages);
63334 fscache_stat(&fscache_n_cop_write_page);
63335 ret = object->cache->ops->write_page(op, page);
63336 fscache_stat_d(&fscache_n_cop_write_page);
63337 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63338 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63339 ASSERT(PageFsCache(page));
63340
63341 - fscache_stat(&fscache_n_stores);
63342 + fscache_stat_unchecked(&fscache_n_stores);
63343
63344 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63345 _leave(" = -ENOBUFS [invalidating]");
63346 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63347 spin_unlock(&cookie->stores_lock);
63348 spin_unlock(&object->lock);
63349
63350 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63351 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63352 op->store_limit = object->store_limit;
63353
63354 __fscache_use_cookie(cookie);
63355 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63356
63357 spin_unlock(&cookie->lock);
63358 radix_tree_preload_end();
63359 - fscache_stat(&fscache_n_store_ops);
63360 - fscache_stat(&fscache_n_stores_ok);
63361 + fscache_stat_unchecked(&fscache_n_store_ops);
63362 + fscache_stat_unchecked(&fscache_n_stores_ok);
63363
63364 /* the work queue now carries its own ref on the object */
63365 fscache_put_operation(&op->op);
63366 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63367 return 0;
63368
63369 already_queued:
63370 - fscache_stat(&fscache_n_stores_again);
63371 + fscache_stat_unchecked(&fscache_n_stores_again);
63372 already_pending:
63373 spin_unlock(&cookie->stores_lock);
63374 spin_unlock(&object->lock);
63375 spin_unlock(&cookie->lock);
63376 radix_tree_preload_end();
63377 kfree(op);
63378 - fscache_stat(&fscache_n_stores_ok);
63379 + fscache_stat_unchecked(&fscache_n_stores_ok);
63380 _leave(" = 0");
63381 return 0;
63382
63383 @@ -1039,14 +1039,14 @@ nobufs:
63384 kfree(op);
63385 if (wake_cookie)
63386 __fscache_wake_unused_cookie(cookie);
63387 - fscache_stat(&fscache_n_stores_nobufs);
63388 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63389 _leave(" = -ENOBUFS");
63390 return -ENOBUFS;
63391
63392 nomem_free:
63393 kfree(op);
63394 nomem:
63395 - fscache_stat(&fscache_n_stores_oom);
63396 + fscache_stat_unchecked(&fscache_n_stores_oom);
63397 _leave(" = -ENOMEM");
63398 return -ENOMEM;
63399 }
63400 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63401 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63402 ASSERTCMP(page, !=, NULL);
63403
63404 - fscache_stat(&fscache_n_uncaches);
63405 + fscache_stat_unchecked(&fscache_n_uncaches);
63406
63407 /* cache withdrawal may beat us to it */
63408 if (!PageFsCache(page))
63409 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63410 struct fscache_cookie *cookie = op->op.object->cookie;
63411
63412 #ifdef CONFIG_FSCACHE_STATS
63413 - atomic_inc(&fscache_n_marks);
63414 + atomic_inc_unchecked(&fscache_n_marks);
63415 #endif
63416
63417 _debug("- mark %p{%lx}", page, page->index);
63418 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63419 index 40d13c7..ddf52b9 100644
63420 --- a/fs/fscache/stats.c
63421 +++ b/fs/fscache/stats.c
63422 @@ -18,99 +18,99 @@
63423 /*
63424 * operation counters
63425 */
63426 -atomic_t fscache_n_op_pend;
63427 -atomic_t fscache_n_op_run;
63428 -atomic_t fscache_n_op_enqueue;
63429 -atomic_t fscache_n_op_requeue;
63430 -atomic_t fscache_n_op_deferred_release;
63431 -atomic_t fscache_n_op_release;
63432 -atomic_t fscache_n_op_gc;
63433 -atomic_t fscache_n_op_cancelled;
63434 -atomic_t fscache_n_op_rejected;
63435 +atomic_unchecked_t fscache_n_op_pend;
63436 +atomic_unchecked_t fscache_n_op_run;
63437 +atomic_unchecked_t fscache_n_op_enqueue;
63438 +atomic_unchecked_t fscache_n_op_requeue;
63439 +atomic_unchecked_t fscache_n_op_deferred_release;
63440 +atomic_unchecked_t fscache_n_op_release;
63441 +atomic_unchecked_t fscache_n_op_gc;
63442 +atomic_unchecked_t fscache_n_op_cancelled;
63443 +atomic_unchecked_t fscache_n_op_rejected;
63444
63445 -atomic_t fscache_n_attr_changed;
63446 -atomic_t fscache_n_attr_changed_ok;
63447 -atomic_t fscache_n_attr_changed_nobufs;
63448 -atomic_t fscache_n_attr_changed_nomem;
63449 -atomic_t fscache_n_attr_changed_calls;
63450 +atomic_unchecked_t fscache_n_attr_changed;
63451 +atomic_unchecked_t fscache_n_attr_changed_ok;
63452 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63453 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63454 +atomic_unchecked_t fscache_n_attr_changed_calls;
63455
63456 -atomic_t fscache_n_allocs;
63457 -atomic_t fscache_n_allocs_ok;
63458 -atomic_t fscache_n_allocs_wait;
63459 -atomic_t fscache_n_allocs_nobufs;
63460 -atomic_t fscache_n_allocs_intr;
63461 -atomic_t fscache_n_allocs_object_dead;
63462 -atomic_t fscache_n_alloc_ops;
63463 -atomic_t fscache_n_alloc_op_waits;
63464 +atomic_unchecked_t fscache_n_allocs;
63465 +atomic_unchecked_t fscache_n_allocs_ok;
63466 +atomic_unchecked_t fscache_n_allocs_wait;
63467 +atomic_unchecked_t fscache_n_allocs_nobufs;
63468 +atomic_unchecked_t fscache_n_allocs_intr;
63469 +atomic_unchecked_t fscache_n_allocs_object_dead;
63470 +atomic_unchecked_t fscache_n_alloc_ops;
63471 +atomic_unchecked_t fscache_n_alloc_op_waits;
63472
63473 -atomic_t fscache_n_retrievals;
63474 -atomic_t fscache_n_retrievals_ok;
63475 -atomic_t fscache_n_retrievals_wait;
63476 -atomic_t fscache_n_retrievals_nodata;
63477 -atomic_t fscache_n_retrievals_nobufs;
63478 -atomic_t fscache_n_retrievals_intr;
63479 -atomic_t fscache_n_retrievals_nomem;
63480 -atomic_t fscache_n_retrievals_object_dead;
63481 -atomic_t fscache_n_retrieval_ops;
63482 -atomic_t fscache_n_retrieval_op_waits;
63483 +atomic_unchecked_t fscache_n_retrievals;
63484 +atomic_unchecked_t fscache_n_retrievals_ok;
63485 +atomic_unchecked_t fscache_n_retrievals_wait;
63486 +atomic_unchecked_t fscache_n_retrievals_nodata;
63487 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63488 +atomic_unchecked_t fscache_n_retrievals_intr;
63489 +atomic_unchecked_t fscache_n_retrievals_nomem;
63490 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63491 +atomic_unchecked_t fscache_n_retrieval_ops;
63492 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63493
63494 -atomic_t fscache_n_stores;
63495 -atomic_t fscache_n_stores_ok;
63496 -atomic_t fscache_n_stores_again;
63497 -atomic_t fscache_n_stores_nobufs;
63498 -atomic_t fscache_n_stores_oom;
63499 -atomic_t fscache_n_store_ops;
63500 -atomic_t fscache_n_store_calls;
63501 -atomic_t fscache_n_store_pages;
63502 -atomic_t fscache_n_store_radix_deletes;
63503 -atomic_t fscache_n_store_pages_over_limit;
63504 +atomic_unchecked_t fscache_n_stores;
63505 +atomic_unchecked_t fscache_n_stores_ok;
63506 +atomic_unchecked_t fscache_n_stores_again;
63507 +atomic_unchecked_t fscache_n_stores_nobufs;
63508 +atomic_unchecked_t fscache_n_stores_oom;
63509 +atomic_unchecked_t fscache_n_store_ops;
63510 +atomic_unchecked_t fscache_n_store_calls;
63511 +atomic_unchecked_t fscache_n_store_pages;
63512 +atomic_unchecked_t fscache_n_store_radix_deletes;
63513 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63514
63515 -atomic_t fscache_n_store_vmscan_not_storing;
63516 -atomic_t fscache_n_store_vmscan_gone;
63517 -atomic_t fscache_n_store_vmscan_busy;
63518 -atomic_t fscache_n_store_vmscan_cancelled;
63519 -atomic_t fscache_n_store_vmscan_wait;
63520 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63521 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63522 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63523 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63524 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63525
63526 -atomic_t fscache_n_marks;
63527 -atomic_t fscache_n_uncaches;
63528 +atomic_unchecked_t fscache_n_marks;
63529 +atomic_unchecked_t fscache_n_uncaches;
63530
63531 -atomic_t fscache_n_acquires;
63532 -atomic_t fscache_n_acquires_null;
63533 -atomic_t fscache_n_acquires_no_cache;
63534 -atomic_t fscache_n_acquires_ok;
63535 -atomic_t fscache_n_acquires_nobufs;
63536 -atomic_t fscache_n_acquires_oom;
63537 +atomic_unchecked_t fscache_n_acquires;
63538 +atomic_unchecked_t fscache_n_acquires_null;
63539 +atomic_unchecked_t fscache_n_acquires_no_cache;
63540 +atomic_unchecked_t fscache_n_acquires_ok;
63541 +atomic_unchecked_t fscache_n_acquires_nobufs;
63542 +atomic_unchecked_t fscache_n_acquires_oom;
63543
63544 -atomic_t fscache_n_invalidates;
63545 -atomic_t fscache_n_invalidates_run;
63546 +atomic_unchecked_t fscache_n_invalidates;
63547 +atomic_unchecked_t fscache_n_invalidates_run;
63548
63549 -atomic_t fscache_n_updates;
63550 -atomic_t fscache_n_updates_null;
63551 -atomic_t fscache_n_updates_run;
63552 +atomic_unchecked_t fscache_n_updates;
63553 +atomic_unchecked_t fscache_n_updates_null;
63554 +atomic_unchecked_t fscache_n_updates_run;
63555
63556 -atomic_t fscache_n_relinquishes;
63557 -atomic_t fscache_n_relinquishes_null;
63558 -atomic_t fscache_n_relinquishes_waitcrt;
63559 -atomic_t fscache_n_relinquishes_retire;
63560 +atomic_unchecked_t fscache_n_relinquishes;
63561 +atomic_unchecked_t fscache_n_relinquishes_null;
63562 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63563 +atomic_unchecked_t fscache_n_relinquishes_retire;
63564
63565 -atomic_t fscache_n_cookie_index;
63566 -atomic_t fscache_n_cookie_data;
63567 -atomic_t fscache_n_cookie_special;
63568 +atomic_unchecked_t fscache_n_cookie_index;
63569 +atomic_unchecked_t fscache_n_cookie_data;
63570 +atomic_unchecked_t fscache_n_cookie_special;
63571
63572 -atomic_t fscache_n_object_alloc;
63573 -atomic_t fscache_n_object_no_alloc;
63574 -atomic_t fscache_n_object_lookups;
63575 -atomic_t fscache_n_object_lookups_negative;
63576 -atomic_t fscache_n_object_lookups_positive;
63577 -atomic_t fscache_n_object_lookups_timed_out;
63578 -atomic_t fscache_n_object_created;
63579 -atomic_t fscache_n_object_avail;
63580 -atomic_t fscache_n_object_dead;
63581 +atomic_unchecked_t fscache_n_object_alloc;
63582 +atomic_unchecked_t fscache_n_object_no_alloc;
63583 +atomic_unchecked_t fscache_n_object_lookups;
63584 +atomic_unchecked_t fscache_n_object_lookups_negative;
63585 +atomic_unchecked_t fscache_n_object_lookups_positive;
63586 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63587 +atomic_unchecked_t fscache_n_object_created;
63588 +atomic_unchecked_t fscache_n_object_avail;
63589 +atomic_unchecked_t fscache_n_object_dead;
63590
63591 -atomic_t fscache_n_checkaux_none;
63592 -atomic_t fscache_n_checkaux_okay;
63593 -atomic_t fscache_n_checkaux_update;
63594 -atomic_t fscache_n_checkaux_obsolete;
63595 +atomic_unchecked_t fscache_n_checkaux_none;
63596 +atomic_unchecked_t fscache_n_checkaux_okay;
63597 +atomic_unchecked_t fscache_n_checkaux_update;
63598 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63599
63600 atomic_t fscache_n_cop_alloc_object;
63601 atomic_t fscache_n_cop_lookup_object;
63602 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63603 seq_puts(m, "FS-Cache statistics\n");
63604
63605 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63606 - atomic_read(&fscache_n_cookie_index),
63607 - atomic_read(&fscache_n_cookie_data),
63608 - atomic_read(&fscache_n_cookie_special));
63609 + atomic_read_unchecked(&fscache_n_cookie_index),
63610 + atomic_read_unchecked(&fscache_n_cookie_data),
63611 + atomic_read_unchecked(&fscache_n_cookie_special));
63612
63613 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63614 - atomic_read(&fscache_n_object_alloc),
63615 - atomic_read(&fscache_n_object_no_alloc),
63616 - atomic_read(&fscache_n_object_avail),
63617 - atomic_read(&fscache_n_object_dead));
63618 + atomic_read_unchecked(&fscache_n_object_alloc),
63619 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63620 + atomic_read_unchecked(&fscache_n_object_avail),
63621 + atomic_read_unchecked(&fscache_n_object_dead));
63622 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63623 - atomic_read(&fscache_n_checkaux_none),
63624 - atomic_read(&fscache_n_checkaux_okay),
63625 - atomic_read(&fscache_n_checkaux_update),
63626 - atomic_read(&fscache_n_checkaux_obsolete));
63627 + atomic_read_unchecked(&fscache_n_checkaux_none),
63628 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63629 + atomic_read_unchecked(&fscache_n_checkaux_update),
63630 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63631
63632 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63633 - atomic_read(&fscache_n_marks),
63634 - atomic_read(&fscache_n_uncaches));
63635 + atomic_read_unchecked(&fscache_n_marks),
63636 + atomic_read_unchecked(&fscache_n_uncaches));
63637
63638 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63639 " oom=%u\n",
63640 - atomic_read(&fscache_n_acquires),
63641 - atomic_read(&fscache_n_acquires_null),
63642 - atomic_read(&fscache_n_acquires_no_cache),
63643 - atomic_read(&fscache_n_acquires_ok),
63644 - atomic_read(&fscache_n_acquires_nobufs),
63645 - atomic_read(&fscache_n_acquires_oom));
63646 + atomic_read_unchecked(&fscache_n_acquires),
63647 + atomic_read_unchecked(&fscache_n_acquires_null),
63648 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63649 + atomic_read_unchecked(&fscache_n_acquires_ok),
63650 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63651 + atomic_read_unchecked(&fscache_n_acquires_oom));
63652
63653 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63654 - atomic_read(&fscache_n_object_lookups),
63655 - atomic_read(&fscache_n_object_lookups_negative),
63656 - atomic_read(&fscache_n_object_lookups_positive),
63657 - atomic_read(&fscache_n_object_created),
63658 - atomic_read(&fscache_n_object_lookups_timed_out));
63659 + atomic_read_unchecked(&fscache_n_object_lookups),
63660 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63661 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63662 + atomic_read_unchecked(&fscache_n_object_created),
63663 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63664
63665 seq_printf(m, "Invals : n=%u run=%u\n",
63666 - atomic_read(&fscache_n_invalidates),
63667 - atomic_read(&fscache_n_invalidates_run));
63668 + atomic_read_unchecked(&fscache_n_invalidates),
63669 + atomic_read_unchecked(&fscache_n_invalidates_run));
63670
63671 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63672 - atomic_read(&fscache_n_updates),
63673 - atomic_read(&fscache_n_updates_null),
63674 - atomic_read(&fscache_n_updates_run));
63675 + atomic_read_unchecked(&fscache_n_updates),
63676 + atomic_read_unchecked(&fscache_n_updates_null),
63677 + atomic_read_unchecked(&fscache_n_updates_run));
63678
63679 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63680 - atomic_read(&fscache_n_relinquishes),
63681 - atomic_read(&fscache_n_relinquishes_null),
63682 - atomic_read(&fscache_n_relinquishes_waitcrt),
63683 - atomic_read(&fscache_n_relinquishes_retire));
63684 + atomic_read_unchecked(&fscache_n_relinquishes),
63685 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63686 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63687 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63688
63689 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63690 - atomic_read(&fscache_n_attr_changed),
63691 - atomic_read(&fscache_n_attr_changed_ok),
63692 - atomic_read(&fscache_n_attr_changed_nobufs),
63693 - atomic_read(&fscache_n_attr_changed_nomem),
63694 - atomic_read(&fscache_n_attr_changed_calls));
63695 + atomic_read_unchecked(&fscache_n_attr_changed),
63696 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63697 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63698 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63699 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63700
63701 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63702 - atomic_read(&fscache_n_allocs),
63703 - atomic_read(&fscache_n_allocs_ok),
63704 - atomic_read(&fscache_n_allocs_wait),
63705 - atomic_read(&fscache_n_allocs_nobufs),
63706 - atomic_read(&fscache_n_allocs_intr));
63707 + atomic_read_unchecked(&fscache_n_allocs),
63708 + atomic_read_unchecked(&fscache_n_allocs_ok),
63709 + atomic_read_unchecked(&fscache_n_allocs_wait),
63710 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63711 + atomic_read_unchecked(&fscache_n_allocs_intr));
63712 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63713 - atomic_read(&fscache_n_alloc_ops),
63714 - atomic_read(&fscache_n_alloc_op_waits),
63715 - atomic_read(&fscache_n_allocs_object_dead));
63716 + atomic_read_unchecked(&fscache_n_alloc_ops),
63717 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63718 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63719
63720 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63721 " int=%u oom=%u\n",
63722 - atomic_read(&fscache_n_retrievals),
63723 - atomic_read(&fscache_n_retrievals_ok),
63724 - atomic_read(&fscache_n_retrievals_wait),
63725 - atomic_read(&fscache_n_retrievals_nodata),
63726 - atomic_read(&fscache_n_retrievals_nobufs),
63727 - atomic_read(&fscache_n_retrievals_intr),
63728 - atomic_read(&fscache_n_retrievals_nomem));
63729 + atomic_read_unchecked(&fscache_n_retrievals),
63730 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63731 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63732 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63733 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63734 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63735 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63736 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63737 - atomic_read(&fscache_n_retrieval_ops),
63738 - atomic_read(&fscache_n_retrieval_op_waits),
63739 - atomic_read(&fscache_n_retrievals_object_dead));
63740 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63741 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63742 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63743
63744 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63745 - atomic_read(&fscache_n_stores),
63746 - atomic_read(&fscache_n_stores_ok),
63747 - atomic_read(&fscache_n_stores_again),
63748 - atomic_read(&fscache_n_stores_nobufs),
63749 - atomic_read(&fscache_n_stores_oom));
63750 + atomic_read_unchecked(&fscache_n_stores),
63751 + atomic_read_unchecked(&fscache_n_stores_ok),
63752 + atomic_read_unchecked(&fscache_n_stores_again),
63753 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63754 + atomic_read_unchecked(&fscache_n_stores_oom));
63755 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63756 - atomic_read(&fscache_n_store_ops),
63757 - atomic_read(&fscache_n_store_calls),
63758 - atomic_read(&fscache_n_store_pages),
63759 - atomic_read(&fscache_n_store_radix_deletes),
63760 - atomic_read(&fscache_n_store_pages_over_limit));
63761 + atomic_read_unchecked(&fscache_n_store_ops),
63762 + atomic_read_unchecked(&fscache_n_store_calls),
63763 + atomic_read_unchecked(&fscache_n_store_pages),
63764 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63765 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63766
63767 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63768 - atomic_read(&fscache_n_store_vmscan_not_storing),
63769 - atomic_read(&fscache_n_store_vmscan_gone),
63770 - atomic_read(&fscache_n_store_vmscan_busy),
63771 - atomic_read(&fscache_n_store_vmscan_cancelled),
63772 - atomic_read(&fscache_n_store_vmscan_wait));
63773 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63774 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63775 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63776 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63777 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63778
63779 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63780 - atomic_read(&fscache_n_op_pend),
63781 - atomic_read(&fscache_n_op_run),
63782 - atomic_read(&fscache_n_op_enqueue),
63783 - atomic_read(&fscache_n_op_cancelled),
63784 - atomic_read(&fscache_n_op_rejected));
63785 + atomic_read_unchecked(&fscache_n_op_pend),
63786 + atomic_read_unchecked(&fscache_n_op_run),
63787 + atomic_read_unchecked(&fscache_n_op_enqueue),
63788 + atomic_read_unchecked(&fscache_n_op_cancelled),
63789 + atomic_read_unchecked(&fscache_n_op_rejected));
63790 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63791 - atomic_read(&fscache_n_op_deferred_release),
63792 - atomic_read(&fscache_n_op_release),
63793 - atomic_read(&fscache_n_op_gc));
63794 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63795 + atomic_read_unchecked(&fscache_n_op_release),
63796 + atomic_read_unchecked(&fscache_n_op_gc));
63797
63798 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63799 atomic_read(&fscache_n_cop_alloc_object),
63800 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63801 index 966ace8..030a03a 100644
63802 --- a/fs/fuse/cuse.c
63803 +++ b/fs/fuse/cuse.c
63804 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63805 INIT_LIST_HEAD(&cuse_conntbl[i]);
63806
63807 /* inherit and extend fuse_dev_operations */
63808 - cuse_channel_fops = fuse_dev_operations;
63809 - cuse_channel_fops.owner = THIS_MODULE;
63810 - cuse_channel_fops.open = cuse_channel_open;
63811 - cuse_channel_fops.release = cuse_channel_release;
63812 + pax_open_kernel();
63813 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63814 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63815 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63816 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63817 + pax_close_kernel();
63818
63819 cuse_class = class_create(THIS_MODULE, "cuse");
63820 if (IS_ERR(cuse_class))
63821 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63822 index ca88731..8e9c55d 100644
63823 --- a/fs/fuse/dev.c
63824 +++ b/fs/fuse/dev.c
63825 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63826 ret = 0;
63827 pipe_lock(pipe);
63828
63829 - if (!pipe->readers) {
63830 + if (!atomic_read(&pipe->readers)) {
63831 send_sig(SIGPIPE, current, 0);
63832 if (!ret)
63833 ret = -EPIPE;
63834 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63835 page_nr++;
63836 ret += buf->len;
63837
63838 - if (pipe->files)
63839 + if (atomic_read(&pipe->files))
63840 do_wakeup = 1;
63841 }
63842
63843 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63844 index dbab798..fefa22b 100644
63845 --- a/fs/fuse/dir.c
63846 +++ b/fs/fuse/dir.c
63847 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63848 return link;
63849 }
63850
63851 -static void free_link(char *link)
63852 +static void free_link(const char *link)
63853 {
63854 if (!IS_ERR(link))
63855 free_page((unsigned long) link);
63856 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63857 index fd62cae..3494dfa 100644
63858 --- a/fs/hostfs/hostfs_kern.c
63859 +++ b/fs/hostfs/hostfs_kern.c
63860 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63861
63862 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63863 {
63864 - char *s = nd_get_link(nd);
63865 + const char *s = nd_get_link(nd);
63866 if (!IS_ERR(s))
63867 __putname(s);
63868 }
63869 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63870 index 1e2872b..7aea000 100644
63871 --- a/fs/hugetlbfs/inode.c
63872 +++ b/fs/hugetlbfs/inode.c
63873 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63874 struct mm_struct *mm = current->mm;
63875 struct vm_area_struct *vma;
63876 struct hstate *h = hstate_file(file);
63877 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63878 struct vm_unmapped_area_info info;
63879
63880 if (len & ~huge_page_mask(h))
63881 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63882 return addr;
63883 }
63884
63885 +#ifdef CONFIG_PAX_RANDMMAP
63886 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63887 +#endif
63888 +
63889 if (addr) {
63890 addr = ALIGN(addr, huge_page_size(h));
63891 vma = find_vma(mm, addr);
63892 - if (TASK_SIZE - len >= addr &&
63893 - (!vma || addr + len <= vma->vm_start))
63894 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63895 return addr;
63896 }
63897
63898 info.flags = 0;
63899 info.length = len;
63900 info.low_limit = TASK_UNMAPPED_BASE;
63901 +
63902 +#ifdef CONFIG_PAX_RANDMMAP
63903 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63904 + info.low_limit += mm->delta_mmap;
63905 +#endif
63906 +
63907 info.high_limit = TASK_SIZE;
63908 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63909 info.align_offset = 0;
63910 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63911 };
63912 MODULE_ALIAS_FS("hugetlbfs");
63913
63914 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63915 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63916
63917 static int can_do_hugetlb_shm(void)
63918 {
63919 diff --git a/fs/inode.c b/fs/inode.c
63920 index 26753ba..d19eb34 100644
63921 --- a/fs/inode.c
63922 +++ b/fs/inode.c
63923 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63924 unsigned int *p = &get_cpu_var(last_ino);
63925 unsigned int res = *p;
63926
63927 +start:
63928 +
63929 #ifdef CONFIG_SMP
63930 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63931 - static atomic_t shared_last_ino;
63932 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63933 + static atomic_unchecked_t shared_last_ino;
63934 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63935
63936 res = next - LAST_INO_BATCH;
63937 }
63938 #endif
63939
63940 - *p = ++res;
63941 + if (unlikely(!++res))
63942 + goto start; /* never zero */
63943 + *p = res;
63944 put_cpu_var(last_ino);
63945 return res;
63946 }
63947 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63948 index 4a6cf28..d3a29d3 100644
63949 --- a/fs/jffs2/erase.c
63950 +++ b/fs/jffs2/erase.c
63951 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63952 struct jffs2_unknown_node marker = {
63953 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63954 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63955 - .totlen = cpu_to_je32(c->cleanmarker_size)
63956 + .totlen = cpu_to_je32(c->cleanmarker_size),
63957 + .hdr_crc = cpu_to_je32(0)
63958 };
63959
63960 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63961 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63962 index 09ed551..45684f8 100644
63963 --- a/fs/jffs2/wbuf.c
63964 +++ b/fs/jffs2/wbuf.c
63965 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63966 {
63967 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63968 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63969 - .totlen = constant_cpu_to_je32(8)
63970 + .totlen = constant_cpu_to_je32(8),
63971 + .hdr_crc = constant_cpu_to_je32(0)
63972 };
63973
63974 /*
63975 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63976 index 93e897e..a863de4 100644
63977 --- a/fs/jfs/super.c
63978 +++ b/fs/jfs/super.c
63979 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63980
63981 jfs_inode_cachep =
63982 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63983 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63984 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63985 init_once);
63986 if (jfs_inode_cachep == NULL)
63987 return -ENOMEM;
63988 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63989 index 1c77193..ba73e66 100644
63990 --- a/fs/kernfs/dir.c
63991 +++ b/fs/kernfs/dir.c
63992 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63993 *
63994 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63995 */
63996 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63997 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63998 {
63999 unsigned long hash = init_name_hash();
64000 unsigned int len = strlen(name);
64001 @@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
64002 ret = scops->mkdir(parent, dentry->d_name.name, mode);
64003
64004 kernfs_put_active(parent);
64005 +
64006 + if (!ret) {
64007 + struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
64008 + ret = PTR_ERR_OR_ZERO(dentry_ret);
64009 + }
64010 +
64011 return ret;
64012 }
64013
64014 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64015 index 4429d6d..9831f52 100644
64016 --- a/fs/kernfs/file.c
64017 +++ b/fs/kernfs/file.c
64018 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64019
64020 struct kernfs_open_node {
64021 atomic_t refcnt;
64022 - atomic_t event;
64023 + atomic_unchecked_t event;
64024 wait_queue_head_t poll;
64025 struct list_head files; /* goes through kernfs_open_file.list */
64026 };
64027 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64028 {
64029 struct kernfs_open_file *of = sf->private;
64030
64031 - of->event = atomic_read(&of->kn->attr.open->event);
64032 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64033
64034 return of->kn->attr.ops->seq_show(sf, v);
64035 }
64036 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64037 return ret;
64038 }
64039
64040 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64041 - void *buf, int len, int write)
64042 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64043 + void *buf, size_t len, int write)
64044 {
64045 struct file *file = vma->vm_file;
64046 struct kernfs_open_file *of = kernfs_of(file);
64047 - int ret;
64048 + ssize_t ret;
64049
64050 if (!of->vm_ops)
64051 return -EINVAL;
64052 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64053 return -ENOMEM;
64054
64055 atomic_set(&new_on->refcnt, 0);
64056 - atomic_set(&new_on->event, 1);
64057 + atomic_set_unchecked(&new_on->event, 1);
64058 init_waitqueue_head(&new_on->poll);
64059 INIT_LIST_HEAD(&new_on->files);
64060 goto retry;
64061 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64062
64063 kernfs_put_active(kn);
64064
64065 - if (of->event != atomic_read(&on->event))
64066 + if (of->event != atomic_read_unchecked(&on->event))
64067 goto trigger;
64068
64069 return DEFAULT_POLLMASK;
64070 @@ -818,7 +818,7 @@ repeat:
64071
64072 on = kn->attr.open;
64073 if (on) {
64074 - atomic_inc(&on->event);
64075 + atomic_inc_unchecked(&on->event);
64076 wake_up_interruptible(&on->poll);
64077 }
64078
64079 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64080 index 8a19889..4c3069a 100644
64081 --- a/fs/kernfs/symlink.c
64082 +++ b/fs/kernfs/symlink.c
64083 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64084 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64085 void *cookie)
64086 {
64087 - char *page = nd_get_link(nd);
64088 + const char *page = nd_get_link(nd);
64089 if (!IS_ERR(page))
64090 free_page((unsigned long)page);
64091 }
64092 diff --git a/fs/libfs.c b/fs/libfs.c
64093 index 005843c..06c4191 100644
64094 --- a/fs/libfs.c
64095 +++ b/fs/libfs.c
64096 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64097
64098 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64099 struct dentry *next = list_entry(p, struct dentry, d_child);
64100 + char d_name[sizeof(next->d_iname)];
64101 + const unsigned char *name;
64102 +
64103 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64104 if (!simple_positive(next)) {
64105 spin_unlock(&next->d_lock);
64106 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64107
64108 spin_unlock(&next->d_lock);
64109 spin_unlock(&dentry->d_lock);
64110 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64111 + name = next->d_name.name;
64112 + if (name == next->d_iname) {
64113 + memcpy(d_name, name, next->d_name.len);
64114 + name = d_name;
64115 + }
64116 + if (!dir_emit(ctx, name, next->d_name.len,
64117 next->d_inode->i_ino, dt_type(next->d_inode)))
64118 return 0;
64119 spin_lock(&dentry->d_lock);
64120 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64121 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64122 void *cookie)
64123 {
64124 - char *s = nd_get_link(nd);
64125 + const char *s = nd_get_link(nd);
64126 if (!IS_ERR(s))
64127 kfree(s);
64128 }
64129 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64130 index acd3947..1f896e2 100644
64131 --- a/fs/lockd/clntproc.c
64132 +++ b/fs/lockd/clntproc.c
64133 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64134 /*
64135 * Cookie counter for NLM requests
64136 */
64137 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64138 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64139
64140 void nlmclnt_next_cookie(struct nlm_cookie *c)
64141 {
64142 - u32 cookie = atomic_inc_return(&nlm_cookie);
64143 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64144
64145 memcpy(c->data, &cookie, 4);
64146 c->len=4;
64147 diff --git a/fs/locks.c b/fs/locks.c
64148 index 59e2f90..bd69071 100644
64149 --- a/fs/locks.c
64150 +++ b/fs/locks.c
64151 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
64152 locks_remove_posix(filp, filp);
64153
64154 if (filp->f_op->flock) {
64155 - struct file_lock fl = {
64156 + struct file_lock flock = {
64157 .fl_owner = filp,
64158 .fl_pid = current->tgid,
64159 .fl_file = filp,
64160 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
64161 .fl_type = F_UNLCK,
64162 .fl_end = OFFSET_MAX,
64163 };
64164 - filp->f_op->flock(filp, F_SETLKW, &fl);
64165 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64166 - fl.fl_ops->fl_release_private(&fl);
64167 + filp->f_op->flock(filp, F_SETLKW, &flock);
64168 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64169 + flock.fl_ops->fl_release_private(&flock);
64170 }
64171
64172 spin_lock(&inode->i_lock);
64173 diff --git a/fs/mount.h b/fs/mount.h
64174 index f82c628..9492b99 100644
64175 --- a/fs/mount.h
64176 +++ b/fs/mount.h
64177 @@ -11,7 +11,7 @@ struct mnt_namespace {
64178 u64 seq; /* Sequence number to prevent loops */
64179 wait_queue_head_t poll;
64180 u64 event;
64181 -};
64182 +} __randomize_layout;
64183
64184 struct mnt_pcp {
64185 int mnt_count;
64186 @@ -62,7 +62,7 @@ struct mount {
64187 int mnt_expiry_mark; /* true if marked for expiry */
64188 struct hlist_head mnt_pins;
64189 struct path mnt_ex_mountpoint;
64190 -};
64191 +} __randomize_layout;
64192
64193 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64194
64195 diff --git a/fs/namei.c b/fs/namei.c
64196 index db5fe86..8bce5f0 100644
64197 --- a/fs/namei.c
64198 +++ b/fs/namei.c
64199 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64200 if (ret != -EACCES)
64201 return ret;
64202
64203 +#ifdef CONFIG_GRKERNSEC
64204 + /* we'll block if we have to log due to a denied capability use */
64205 + if (mask & MAY_NOT_BLOCK)
64206 + return -ECHILD;
64207 +#endif
64208 +
64209 if (S_ISDIR(inode->i_mode)) {
64210 /* DACs are overridable for directories */
64211 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64212 - return 0;
64213 if (!(mask & MAY_WRITE))
64214 - if (capable_wrt_inode_uidgid(inode,
64215 - CAP_DAC_READ_SEARCH))
64216 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64217 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64218 return 0;
64219 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64220 + return 0;
64221 return -EACCES;
64222 }
64223 /*
64224 + * Searching includes executable on directories, else just read.
64225 + */
64226 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64227 + if (mask == MAY_READ)
64228 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64229 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64230 + return 0;
64231 +
64232 + /*
64233 * Read/write DACs are always overridable.
64234 * Executable DACs are overridable when there is
64235 * at least one exec bit set.
64236 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64237 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64238 return 0;
64239
64240 - /*
64241 - * Searching includes executable on directories, else just read.
64242 - */
64243 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64244 - if (mask == MAY_READ)
64245 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64246 - return 0;
64247 -
64248 return -EACCES;
64249 }
64250 EXPORT_SYMBOL(generic_permission);
64251 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64252 {
64253 struct dentry *dentry = link->dentry;
64254 int error;
64255 - char *s;
64256 + const char *s;
64257
64258 BUG_ON(nd->flags & LOOKUP_RCU);
64259
64260 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64261 if (error)
64262 goto out_put_nd_path;
64263
64264 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64265 + dentry->d_inode, dentry, nd->path.mnt)) {
64266 + error = -EACCES;
64267 + goto out_put_nd_path;
64268 + }
64269 +
64270 nd->last_type = LAST_BIND;
64271 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64272 error = PTR_ERR(*p);
64273 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64274 if (res)
64275 break;
64276 res = walk_component(nd, path, LOOKUP_FOLLOW);
64277 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64278 + res = -EACCES;
64279 put_link(nd, &link, cookie);
64280 } while (res > 0);
64281
64282 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
64283 static inline u64 hash_name(const char *name)
64284 {
64285 unsigned long a, b, adata, bdata, mask, hash, len;
64286 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64287 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64288
64289 hash = a = 0;
64290 len = -sizeof(unsigned long);
64291 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
64292 if (err)
64293 break;
64294 err = lookup_last(nd, &path);
64295 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64296 + err = -EACCES;
64297 put_link(nd, &link, cookie);
64298 }
64299 }
64300 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
64301 if (!err)
64302 err = complete_walk(nd);
64303
64304 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64305 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64306 + path_put(&nd->path);
64307 + err = -ENOENT;
64308 + }
64309 + }
64310 +
64311 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64312 if (!d_can_lookup(nd->path.dentry)) {
64313 path_put(&nd->path);
64314 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
64315 retval = path_lookupat(dfd, name->name,
64316 flags | LOOKUP_REVAL, nd);
64317
64318 - if (likely(!retval))
64319 + if (likely(!retval)) {
64320 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64321 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64322 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64323 + path_put(&nd->path);
64324 + return -ENOENT;
64325 + }
64326 + }
64327 + }
64328 return retval;
64329 }
64330
64331 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64332 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64333 return -EPERM;
64334
64335 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64336 + return -EPERM;
64337 + if (gr_handle_rawio(inode))
64338 + return -EPERM;
64339 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64340 + return -EACCES;
64341 +
64342 return 0;
64343 }
64344
64345 @@ -2813,7 +2851,7 @@ looked_up:
64346 * cleared otherwise prior to returning.
64347 */
64348 static int lookup_open(struct nameidata *nd, struct path *path,
64349 - struct file *file,
64350 + struct path *link, struct file *file,
64351 const struct open_flags *op,
64352 bool got_write, int *opened)
64353 {
64354 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64355 /* Negative dentry, just create the file */
64356 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64357 umode_t mode = op->mode;
64358 +
64359 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64360 + error = -EACCES;
64361 + goto out_dput;
64362 + }
64363 +
64364 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64365 + error = -EACCES;
64366 + goto out_dput;
64367 + }
64368 +
64369 if (!IS_POSIXACL(dir->d_inode))
64370 mode &= ~current_umask();
64371 /*
64372 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64373 nd->flags & LOOKUP_EXCL);
64374 if (error)
64375 goto out_dput;
64376 + else
64377 + gr_handle_create(dentry, nd->path.mnt);
64378 }
64379 out_no_open:
64380 path->dentry = dentry;
64381 @@ -2883,7 +2934,7 @@ out_dput:
64382 /*
64383 * Handle the last step of open()
64384 */
64385 -static int do_last(struct nameidata *nd, struct path *path,
64386 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64387 struct file *file, const struct open_flags *op,
64388 int *opened, struct filename *name)
64389 {
64390 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64391 if (error)
64392 return error;
64393
64394 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64395 + error = -ENOENT;
64396 + goto out;
64397 + }
64398 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64399 + error = -EACCES;
64400 + goto out;
64401 + }
64402 +
64403 audit_inode(name, dir, LOOKUP_PARENT);
64404 error = -EISDIR;
64405 /* trailing slashes? */
64406 @@ -2952,7 +3012,7 @@ retry_lookup:
64407 */
64408 }
64409 mutex_lock(&dir->d_inode->i_mutex);
64410 - error = lookup_open(nd, path, file, op, got_write, opened);
64411 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64412 mutex_unlock(&dir->d_inode->i_mutex);
64413
64414 if (error <= 0) {
64415 @@ -2976,11 +3036,28 @@ retry_lookup:
64416 goto finish_open_created;
64417 }
64418
64419 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64420 + error = -ENOENT;
64421 + goto exit_dput;
64422 + }
64423 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64424 + error = -EACCES;
64425 + goto exit_dput;
64426 + }
64427 +
64428 /*
64429 * create/update audit record if it already exists.
64430 */
64431 - if (d_is_positive(path->dentry))
64432 + if (d_is_positive(path->dentry)) {
64433 + /* only check if O_CREAT is specified, all other checks need to go
64434 + into may_open */
64435 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64436 + error = -EACCES;
64437 + goto exit_dput;
64438 + }
64439 +
64440 audit_inode(name, path->dentry, 0);
64441 + }
64442
64443 /*
64444 * If atomic_open() acquired write access it is dropped now due to
64445 @@ -3021,6 +3098,11 @@ finish_lookup:
64446 }
64447 }
64448 BUG_ON(inode != path->dentry->d_inode);
64449 + /* if we're resolving a symlink to another symlink */
64450 + if (link && gr_handle_symlink_owner(link, inode)) {
64451 + error = -EACCES;
64452 + goto out;
64453 + }
64454 return 1;
64455 }
64456
64457 @@ -3040,7 +3122,18 @@ finish_open:
64458 path_put(&save_parent);
64459 return error;
64460 }
64461 +
64462 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64463 + error = -ENOENT;
64464 + goto out;
64465 + }
64466 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64467 + error = -EACCES;
64468 + goto out;
64469 + }
64470 +
64471 audit_inode(name, nd->path.dentry, 0);
64472 +
64473 error = -EISDIR;
64474 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64475 goto out;
64476 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64477 if (unlikely(error))
64478 goto out;
64479
64480 - error = do_last(nd, &path, file, op, &opened, pathname);
64481 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64482 while (unlikely(error > 0)) { /* trailing symlink */
64483 struct path link = path;
64484 void *cookie;
64485 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64486 error = follow_link(&link, nd, &cookie);
64487 if (unlikely(error))
64488 break;
64489 - error = do_last(nd, &path, file, op, &opened, pathname);
64490 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64491 put_link(nd, &link, cookie);
64492 }
64493 out:
64494 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64495 goto unlock;
64496
64497 error = -EEXIST;
64498 - if (d_is_positive(dentry))
64499 + if (d_is_positive(dentry)) {
64500 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64501 + error = -ENOENT;
64502 goto fail;
64503 -
64504 + }
64505 /*
64506 * Special case - lookup gave negative, but... we had foo/bar/
64507 * From the vfs_mknod() POV we just have a negative dentry -
64508 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64509 }
64510 EXPORT_SYMBOL(user_path_create);
64511
64512 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64513 +{
64514 + struct filename *tmp = getname(pathname);
64515 + struct dentry *res;
64516 + if (IS_ERR(tmp))
64517 + return ERR_CAST(tmp);
64518 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64519 + if (IS_ERR(res))
64520 + putname(tmp);
64521 + else
64522 + *to = tmp;
64523 + return res;
64524 +}
64525 +
64526 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64527 {
64528 int error = may_create(dir, dentry);
64529 @@ -3442,6 +3551,17 @@ retry:
64530
64531 if (!IS_POSIXACL(path.dentry->d_inode))
64532 mode &= ~current_umask();
64533 +
64534 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64535 + error = -EPERM;
64536 + goto out;
64537 + }
64538 +
64539 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64540 + error = -EACCES;
64541 + goto out;
64542 + }
64543 +
64544 error = security_path_mknod(&path, dentry, mode, dev);
64545 if (error)
64546 goto out;
64547 @@ -3457,6 +3577,8 @@ retry:
64548 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64549 break;
64550 }
64551 + if (!error)
64552 + gr_handle_create(dentry, path.mnt);
64553 out:
64554 done_path_create(&path, dentry);
64555 if (retry_estale(error, lookup_flags)) {
64556 @@ -3511,9 +3633,16 @@ retry:
64557
64558 if (!IS_POSIXACL(path.dentry->d_inode))
64559 mode &= ~current_umask();
64560 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64561 + error = -EACCES;
64562 + goto out;
64563 + }
64564 error = security_path_mkdir(&path, dentry, mode);
64565 if (!error)
64566 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64567 + if (!error)
64568 + gr_handle_create(dentry, path.mnt);
64569 +out:
64570 done_path_create(&path, dentry);
64571 if (retry_estale(error, lookup_flags)) {
64572 lookup_flags |= LOOKUP_REVAL;
64573 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64574 struct filename *name;
64575 struct dentry *dentry;
64576 struct nameidata nd;
64577 + u64 saved_ino = 0;
64578 + dev_t saved_dev = 0;
64579 unsigned int lookup_flags = 0;
64580 retry:
64581 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64582 @@ -3629,10 +3760,21 @@ retry:
64583 error = -ENOENT;
64584 goto exit3;
64585 }
64586 +
64587 + saved_ino = gr_get_ino_from_dentry(dentry);
64588 + saved_dev = gr_get_dev_from_dentry(dentry);
64589 +
64590 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64591 + error = -EACCES;
64592 + goto exit3;
64593 + }
64594 +
64595 error = security_path_rmdir(&nd.path, dentry);
64596 if (error)
64597 goto exit3;
64598 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64599 + if (!error && (saved_dev || saved_ino))
64600 + gr_handle_delete(saved_ino, saved_dev);
64601 exit3:
64602 dput(dentry);
64603 exit2:
64604 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64605 struct nameidata nd;
64606 struct inode *inode = NULL;
64607 struct inode *delegated_inode = NULL;
64608 + u64 saved_ino = 0;
64609 + dev_t saved_dev = 0;
64610 unsigned int lookup_flags = 0;
64611 retry:
64612 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64613 @@ -3751,10 +3895,22 @@ retry_deleg:
64614 if (d_is_negative(dentry))
64615 goto slashes;
64616 ihold(inode);
64617 +
64618 + if (inode->i_nlink <= 1) {
64619 + saved_ino = gr_get_ino_from_dentry(dentry);
64620 + saved_dev = gr_get_dev_from_dentry(dentry);
64621 + }
64622 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64623 + error = -EACCES;
64624 + goto exit2;
64625 + }
64626 +
64627 error = security_path_unlink(&nd.path, dentry);
64628 if (error)
64629 goto exit2;
64630 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64631 + if (!error && (saved_ino || saved_dev))
64632 + gr_handle_delete(saved_ino, saved_dev);
64633 exit2:
64634 dput(dentry);
64635 }
64636 @@ -3843,9 +3999,17 @@ retry:
64637 if (IS_ERR(dentry))
64638 goto out_putname;
64639
64640 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64641 + error = -EACCES;
64642 + goto out;
64643 + }
64644 +
64645 error = security_path_symlink(&path, dentry, from->name);
64646 if (!error)
64647 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64648 + if (!error)
64649 + gr_handle_create(dentry, path.mnt);
64650 +out:
64651 done_path_create(&path, dentry);
64652 if (retry_estale(error, lookup_flags)) {
64653 lookup_flags |= LOOKUP_REVAL;
64654 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64655 struct dentry *new_dentry;
64656 struct path old_path, new_path;
64657 struct inode *delegated_inode = NULL;
64658 + struct filename *to = NULL;
64659 int how = 0;
64660 int error;
64661
64662 @@ -3972,7 +4137,7 @@ retry:
64663 if (error)
64664 return error;
64665
64666 - new_dentry = user_path_create(newdfd, newname, &new_path,
64667 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64668 (how & LOOKUP_REVAL));
64669 error = PTR_ERR(new_dentry);
64670 if (IS_ERR(new_dentry))
64671 @@ -3984,11 +4149,28 @@ retry:
64672 error = may_linkat(&old_path);
64673 if (unlikely(error))
64674 goto out_dput;
64675 +
64676 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64677 + old_path.dentry->d_inode,
64678 + old_path.dentry->d_inode->i_mode, to)) {
64679 + error = -EACCES;
64680 + goto out_dput;
64681 + }
64682 +
64683 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64684 + old_path.dentry, old_path.mnt, to)) {
64685 + error = -EACCES;
64686 + goto out_dput;
64687 + }
64688 +
64689 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64690 if (error)
64691 goto out_dput;
64692 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64693 + if (!error)
64694 + gr_handle_create(new_dentry, new_path.mnt);
64695 out_dput:
64696 + putname(to);
64697 done_path_create(&new_path, new_dentry);
64698 if (delegated_inode) {
64699 error = break_deleg_wait(&delegated_inode);
64700 @@ -4304,6 +4486,20 @@ retry_deleg:
64701 if (new_dentry == trap)
64702 goto exit5;
64703
64704 + if (gr_bad_chroot_rename(old_dentry, oldnd.path.mnt, new_dentry, newnd.path.mnt)) {
64705 + /* use EXDEV error to cause 'mv' to switch to an alternative
64706 + * method for usability
64707 + */
64708 + error = -EXDEV;
64709 + goto exit5;
64710 + }
64711 +
64712 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64713 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64714 + to, flags);
64715 + if (error)
64716 + goto exit5;
64717 +
64718 error = security_path_rename(&oldnd.path, old_dentry,
64719 &newnd.path, new_dentry, flags);
64720 if (error)
64721 @@ -4311,6 +4507,9 @@ retry_deleg:
64722 error = vfs_rename(old_dir->d_inode, old_dentry,
64723 new_dir->d_inode, new_dentry,
64724 &delegated_inode, flags);
64725 + if (!error)
64726 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64727 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64728 exit5:
64729 dput(new_dentry);
64730 exit4:
64731 @@ -4367,14 +4566,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64732
64733 int readlink_copy(char __user *buffer, int buflen, const char *link)
64734 {
64735 + char tmpbuf[64];
64736 + const char *newlink;
64737 int len = PTR_ERR(link);
64738 +
64739 if (IS_ERR(link))
64740 goto out;
64741
64742 len = strlen(link);
64743 if (len > (unsigned) buflen)
64744 len = buflen;
64745 - if (copy_to_user(buffer, link, len))
64746 +
64747 + if (len < sizeof(tmpbuf)) {
64748 + memcpy(tmpbuf, link, len);
64749 + newlink = tmpbuf;
64750 + } else
64751 + newlink = link;
64752 +
64753 + if (copy_to_user(buffer, newlink, len))
64754 len = -EFAULT;
64755 out:
64756 return len;
64757 diff --git a/fs/namespace.c b/fs/namespace.c
64758 index bbde147..f4deeba 100644
64759 --- a/fs/namespace.c
64760 +++ b/fs/namespace.c
64761 @@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64762 if (!(sb->s_flags & MS_RDONLY))
64763 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64764 up_write(&sb->s_umount);
64765 +
64766 + gr_log_remount(mnt->mnt_devname, retval);
64767 +
64768 return retval;
64769 }
64770
64771 @@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64772 }
64773 unlock_mount_hash();
64774 namespace_unlock();
64775 +
64776 + gr_log_unmount(mnt->mnt_devname, retval);
64777 +
64778 return retval;
64779 }
64780
64781 @@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64782 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64783 */
64784
64785 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64786 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64787 {
64788 struct path path;
64789 struct mount *mnt;
64790 @@ -1564,7 +1570,7 @@ out:
64791 /*
64792 * The 2.0 compatible umount. No flags.
64793 */
64794 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64795 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64796 {
64797 return sys_umount(name, 0);
64798 }
64799 @@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64800 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64801 MS_STRICTATIME);
64802
64803 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64804 + retval = -EPERM;
64805 + goto dput_out;
64806 + }
64807 +
64808 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64809 + retval = -EPERM;
64810 + goto dput_out;
64811 + }
64812 +
64813 if (flags & MS_REMOUNT)
64814 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64815 data_page);
64816 @@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64817 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64818 dev_name, data_page);
64819 dput_out:
64820 + gr_log_mount(dev_name, &path, retval);
64821 +
64822 path_put(&path);
64823 +
64824 return retval;
64825 }
64826
64827 @@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64828 * number incrementing at 10Ghz will take 12,427 years to wrap which
64829 * is effectively never, so we can ignore the possibility.
64830 */
64831 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64832 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64833
64834 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64835 {
64836 @@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64837 kfree(new_ns);
64838 return ERR_PTR(ret);
64839 }
64840 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64841 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64842 atomic_set(&new_ns->count, 1);
64843 new_ns->root = NULL;
64844 INIT_LIST_HEAD(&new_ns->list);
64845 @@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64846 return new_ns;
64847 }
64848
64849 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64850 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64851 struct user_namespace *user_ns, struct fs_struct *new_fs)
64852 {
64853 struct mnt_namespace *new_ns;
64854 @@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64855 }
64856 EXPORT_SYMBOL(mount_subtree);
64857
64858 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64859 - char __user *, type, unsigned long, flags, void __user *, data)
64860 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64861 + const char __user *, type, unsigned long, flags, void __user *, data)
64862 {
64863 int ret;
64864 char *kernel_type;
64865 @@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64866 if (error)
64867 goto out2;
64868
64869 + if (gr_handle_chroot_pivot()) {
64870 + error = -EPERM;
64871 + goto out2;
64872 + }
64873 +
64874 get_fs_root(current->fs, &root);
64875 old_mp = lock_mount(&old);
64876 error = PTR_ERR(old_mp);
64877 @@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64878 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64879 return -EPERM;
64880
64881 - if (fs->users != 1)
64882 + if (atomic_read(&fs->users) != 1)
64883 return -EINVAL;
64884
64885 get_mnt_ns(mnt_ns);
64886 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64887 index f4ccfe6..a5cf064 100644
64888 --- a/fs/nfs/callback_xdr.c
64889 +++ b/fs/nfs/callback_xdr.c
64890 @@ -51,7 +51,7 @@ struct callback_op {
64891 callback_decode_arg_t decode_args;
64892 callback_encode_res_t encode_res;
64893 long res_maxsize;
64894 -};
64895 +} __do_const;
64896
64897 static struct callback_op callback_ops[];
64898
64899 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64900 index 00689a8..b162632 100644
64901 --- a/fs/nfs/inode.c
64902 +++ b/fs/nfs/inode.c
64903 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64904 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64905 }
64906
64907 -static atomic_long_t nfs_attr_generation_counter;
64908 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64909
64910 static unsigned long nfs_read_attr_generation_counter(void)
64911 {
64912 - return atomic_long_read(&nfs_attr_generation_counter);
64913 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64914 }
64915
64916 unsigned long nfs_inc_attr_generation_counter(void)
64917 {
64918 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64919 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64920 }
64921
64922 void nfs_fattr_init(struct nfs_fattr *fattr)
64923 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64924 index 0beb023..3f685ec 100644
64925 --- a/fs/nfsd/nfs4proc.c
64926 +++ b/fs/nfsd/nfs4proc.c
64927 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64928 nfsd4op_rsize op_rsize_bop;
64929 stateid_getter op_get_currentstateid;
64930 stateid_setter op_set_currentstateid;
64931 -};
64932 +} __do_const;
64933
64934 static struct nfsd4_operation nfsd4_ops[];
64935
64936 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64937 index 2a77603..68e0e37 100644
64938 --- a/fs/nfsd/nfs4xdr.c
64939 +++ b/fs/nfsd/nfs4xdr.c
64940 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64941
64942 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64943
64944 -static nfsd4_dec nfsd4_dec_ops[] = {
64945 +static const nfsd4_dec nfsd4_dec_ops[] = {
64946 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64947 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64948 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64949 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64950 index 122f691..a00e2e0 100644
64951 --- a/fs/nfsd/nfscache.c
64952 +++ b/fs/nfsd/nfscache.c
64953 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64954 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64955 u32 hash;
64956 struct nfsd_drc_bucket *b;
64957 - int len;
64958 + long len;
64959 size_t bufsize = 0;
64960
64961 if (!rp)
64962 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64963 hash = nfsd_cache_hash(rp->c_xid);
64964 b = &drc_hashtbl[hash];
64965
64966 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64967 - len >>= 2;
64968 + if (statp) {
64969 + len = (char*)statp - (char*)resv->iov_base;
64970 + len = resv->iov_len - len;
64971 + len >>= 2;
64972 + }
64973
64974 /* Don't cache excessive amounts of data and XDR failures */
64975 - if (!statp || len > (256 >> 2)) {
64976 + if (!statp || len > (256 >> 2) || len < 0) {
64977 nfsd_reply_cache_free(b, rp);
64978 return;
64979 }
64980 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64981 switch (cachetype) {
64982 case RC_REPLSTAT:
64983 if (len != 1)
64984 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64985 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64986 rp->c_replstat = *statp;
64987 break;
64988 case RC_REPLBUFF:
64989 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64990 index 989129e..42e019e 100644
64991 --- a/fs/nfsd/vfs.c
64992 +++ b/fs/nfsd/vfs.c
64993 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64994
64995 oldfs = get_fs();
64996 set_fs(KERNEL_DS);
64997 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64998 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64999 set_fs(oldfs);
65000 return nfsd_finish_read(file, count, host_err);
65001 }
65002 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65003
65004 /* Write the data. */
65005 oldfs = get_fs(); set_fs(KERNEL_DS);
65006 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65007 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65008 set_fs(oldfs);
65009 if (host_err < 0)
65010 goto out_nfserr;
65011 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65012 */
65013
65014 oldfs = get_fs(); set_fs(KERNEL_DS);
65015 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65016 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65017 set_fs(oldfs);
65018
65019 if (host_err < 0)
65020 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65021 index 52ccd34..7a6b202 100644
65022 --- a/fs/nls/nls_base.c
65023 +++ b/fs/nls/nls_base.c
65024 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65025
65026 int __register_nls(struct nls_table *nls, struct module *owner)
65027 {
65028 - struct nls_table ** tmp = &tables;
65029 + struct nls_table *tmp = tables;
65030
65031 if (nls->next)
65032 return -EBUSY;
65033
65034 - nls->owner = owner;
65035 + pax_open_kernel();
65036 + *(void **)&nls->owner = owner;
65037 + pax_close_kernel();
65038 spin_lock(&nls_lock);
65039 - while (*tmp) {
65040 - if (nls == *tmp) {
65041 + while (tmp) {
65042 + if (nls == tmp) {
65043 spin_unlock(&nls_lock);
65044 return -EBUSY;
65045 }
65046 - tmp = &(*tmp)->next;
65047 + tmp = tmp->next;
65048 }
65049 - nls->next = tables;
65050 + pax_open_kernel();
65051 + *(struct nls_table **)&nls->next = tables;
65052 + pax_close_kernel();
65053 tables = nls;
65054 spin_unlock(&nls_lock);
65055 return 0;
65056 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65057
65058 int unregister_nls(struct nls_table * nls)
65059 {
65060 - struct nls_table ** tmp = &tables;
65061 + struct nls_table * const * tmp = &tables;
65062
65063 spin_lock(&nls_lock);
65064 while (*tmp) {
65065 if (nls == *tmp) {
65066 - *tmp = nls->next;
65067 + pax_open_kernel();
65068 + *(struct nls_table **)tmp = nls->next;
65069 + pax_close_kernel();
65070 spin_unlock(&nls_lock);
65071 return 0;
65072 }
65073 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65074 return -EINVAL;
65075 }
65076
65077 -static struct nls_table *find_nls(char *charset)
65078 +static struct nls_table *find_nls(const char *charset)
65079 {
65080 struct nls_table *nls;
65081 spin_lock(&nls_lock);
65082 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65083 return nls;
65084 }
65085
65086 -struct nls_table *load_nls(char *charset)
65087 +struct nls_table *load_nls(const char *charset)
65088 {
65089 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65090 }
65091 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65092 index 162b3f1..6076a7c 100644
65093 --- a/fs/nls/nls_euc-jp.c
65094 +++ b/fs/nls/nls_euc-jp.c
65095 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65096 p_nls = load_nls("cp932");
65097
65098 if (p_nls) {
65099 - table.charset2upper = p_nls->charset2upper;
65100 - table.charset2lower = p_nls->charset2lower;
65101 + pax_open_kernel();
65102 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65103 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65104 + pax_close_kernel();
65105 return register_nls(&table);
65106 }
65107
65108 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65109 index a80a741..7b96e1b 100644
65110 --- a/fs/nls/nls_koi8-ru.c
65111 +++ b/fs/nls/nls_koi8-ru.c
65112 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65113 p_nls = load_nls("koi8-u");
65114
65115 if (p_nls) {
65116 - table.charset2upper = p_nls->charset2upper;
65117 - table.charset2lower = p_nls->charset2lower;
65118 + pax_open_kernel();
65119 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65120 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65121 + pax_close_kernel();
65122 return register_nls(&table);
65123 }
65124
65125 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65126 index c991616..5ae51af 100644
65127 --- a/fs/notify/fanotify/fanotify_user.c
65128 +++ b/fs/notify/fanotify/fanotify_user.c
65129 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65130
65131 fd = fanotify_event_metadata.fd;
65132 ret = -EFAULT;
65133 - if (copy_to_user(buf, &fanotify_event_metadata,
65134 - fanotify_event_metadata.event_len))
65135 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65136 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65137 goto out_close_fd;
65138
65139 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65140 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65141 index a95d8e0..a91a5fd 100644
65142 --- a/fs/notify/notification.c
65143 +++ b/fs/notify/notification.c
65144 @@ -48,7 +48,7 @@
65145 #include <linux/fsnotify_backend.h>
65146 #include "fsnotify.h"
65147
65148 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65149 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65150
65151 /**
65152 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65153 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65154 */
65155 u32 fsnotify_get_cookie(void)
65156 {
65157 - return atomic_inc_return(&fsnotify_sync_cookie);
65158 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65159 }
65160 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65161
65162 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65163 index 9e38daf..5727cae 100644
65164 --- a/fs/ntfs/dir.c
65165 +++ b/fs/ntfs/dir.c
65166 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65167 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65168 ~(s64)(ndir->itype.index.block_size - 1)));
65169 /* Bounds checks. */
65170 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65171 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65172 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65173 "inode 0x%lx or driver bug.", vdir->i_ino);
65174 goto err_out;
65175 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65176 index 643faa4..ef9027e 100644
65177 --- a/fs/ntfs/file.c
65178 +++ b/fs/ntfs/file.c
65179 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65180 char *addr;
65181 size_t total = 0;
65182 unsigned len;
65183 - int left;
65184 + unsigned left;
65185
65186 do {
65187 len = PAGE_CACHE_SIZE - ofs;
65188 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65189 index 9e1e112..241a52a 100644
65190 --- a/fs/ntfs/super.c
65191 +++ b/fs/ntfs/super.c
65192 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65193 if (!silent)
65194 ntfs_error(sb, "Primary boot sector is invalid.");
65195 } else if (!silent)
65196 - ntfs_error(sb, read_err_str, "primary");
65197 + ntfs_error(sb, read_err_str, "%s", "primary");
65198 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65199 if (bh_primary)
65200 brelse(bh_primary);
65201 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65202 goto hotfix_primary_boot_sector;
65203 brelse(bh_backup);
65204 } else if (!silent)
65205 - ntfs_error(sb, read_err_str, "backup");
65206 + ntfs_error(sb, read_err_str, "%s", "backup");
65207 /* Try to read NT3.51- backup boot sector. */
65208 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65209 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65210 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65211 "sector.");
65212 brelse(bh_backup);
65213 } else if (!silent)
65214 - ntfs_error(sb, read_err_str, "backup");
65215 + ntfs_error(sb, read_err_str, "%s", "backup");
65216 /* We failed. Cleanup and return. */
65217 if (bh_primary)
65218 brelse(bh_primary);
65219 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65220 index 0440134..d52c93a 100644
65221 --- a/fs/ocfs2/localalloc.c
65222 +++ b/fs/ocfs2/localalloc.c
65223 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65224 goto bail;
65225 }
65226
65227 - atomic_inc(&osb->alloc_stats.moves);
65228 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65229
65230 bail:
65231 if (handle)
65232 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65233 index bbec539..7b266d5 100644
65234 --- a/fs/ocfs2/ocfs2.h
65235 +++ b/fs/ocfs2/ocfs2.h
65236 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65237
65238 struct ocfs2_alloc_stats
65239 {
65240 - atomic_t moves;
65241 - atomic_t local_data;
65242 - atomic_t bitmap_data;
65243 - atomic_t bg_allocs;
65244 - atomic_t bg_extends;
65245 + atomic_unchecked_t moves;
65246 + atomic_unchecked_t local_data;
65247 + atomic_unchecked_t bitmap_data;
65248 + atomic_unchecked_t bg_allocs;
65249 + atomic_unchecked_t bg_extends;
65250 };
65251
65252 enum ocfs2_local_alloc_state
65253 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65254 index 0cb889a..6a26b24 100644
65255 --- a/fs/ocfs2/suballoc.c
65256 +++ b/fs/ocfs2/suballoc.c
65257 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65258 mlog_errno(status);
65259 goto bail;
65260 }
65261 - atomic_inc(&osb->alloc_stats.bg_extends);
65262 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65263
65264 /* You should never ask for this much metadata */
65265 BUG_ON(bits_wanted >
65266 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65267 mlog_errno(status);
65268 goto bail;
65269 }
65270 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65271 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65272
65273 *suballoc_loc = res.sr_bg_blkno;
65274 *suballoc_bit_start = res.sr_bit_offset;
65275 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65276 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65277 res->sr_bits);
65278
65279 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65280 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65281
65282 BUG_ON(res->sr_bits != 1);
65283
65284 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65285 mlog_errno(status);
65286 goto bail;
65287 }
65288 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65289 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65290
65291 BUG_ON(res.sr_bits != 1);
65292
65293 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65294 cluster_start,
65295 num_clusters);
65296 if (!status)
65297 - atomic_inc(&osb->alloc_stats.local_data);
65298 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65299 } else {
65300 if (min_clusters > (osb->bitmap_cpg - 1)) {
65301 /* The only paths asking for contiguousness
65302 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65303 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65304 res.sr_bg_blkno,
65305 res.sr_bit_offset);
65306 - atomic_inc(&osb->alloc_stats.bitmap_data);
65307 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65308 *num_clusters = res.sr_bits;
65309 }
65310 }
65311 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65312 index 93c85bc..02f68a4 100644
65313 --- a/fs/ocfs2/super.c
65314 +++ b/fs/ocfs2/super.c
65315 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65316 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65317 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65318 "Stats",
65319 - atomic_read(&osb->alloc_stats.bitmap_data),
65320 - atomic_read(&osb->alloc_stats.local_data),
65321 - atomic_read(&osb->alloc_stats.bg_allocs),
65322 - atomic_read(&osb->alloc_stats.moves),
65323 - atomic_read(&osb->alloc_stats.bg_extends));
65324 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65325 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65326 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65327 + atomic_read_unchecked(&osb->alloc_stats.moves),
65328 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65329
65330 out += snprintf(buf + out, len - out,
65331 "%10s => State: %u Descriptor: %llu Size: %u bits "
65332 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65333
65334 mutex_init(&osb->system_file_mutex);
65335
65336 - atomic_set(&osb->alloc_stats.moves, 0);
65337 - atomic_set(&osb->alloc_stats.local_data, 0);
65338 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65339 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65340 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65341 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65342 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65343 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65344 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65345 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65346
65347 /* Copy the blockcheck stats from the superblock probe */
65348 osb->osb_ecc_stats = *stats;
65349 diff --git a/fs/open.c b/fs/open.c
65350 index de92c13..52d2a6c 100644
65351 --- a/fs/open.c
65352 +++ b/fs/open.c
65353 @@ -32,6 +32,8 @@
65354 #include <linux/dnotify.h>
65355 #include <linux/compat.h>
65356
65357 +#define CREATE_TRACE_POINTS
65358 +#include <trace/events/fs.h>
65359 #include "internal.h"
65360
65361 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65362 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65363 error = locks_verify_truncate(inode, NULL, length);
65364 if (!error)
65365 error = security_path_truncate(path);
65366 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65367 + error = -EACCES;
65368 if (!error)
65369 error = do_truncate(path->dentry, length, 0, NULL);
65370
65371 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65372 error = locks_verify_truncate(inode, f.file, length);
65373 if (!error)
65374 error = security_path_truncate(&f.file->f_path);
65375 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65376 + error = -EACCES;
65377 if (!error)
65378 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65379 sb_end_write(inode->i_sb);
65380 @@ -380,6 +386,9 @@ retry:
65381 if (__mnt_is_readonly(path.mnt))
65382 res = -EROFS;
65383
65384 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65385 + res = -EACCES;
65386 +
65387 out_path_release:
65388 path_put(&path);
65389 if (retry_estale(res, lookup_flags)) {
65390 @@ -411,6 +420,8 @@ retry:
65391 if (error)
65392 goto dput_and_out;
65393
65394 + gr_log_chdir(path.dentry, path.mnt);
65395 +
65396 set_fs_pwd(current->fs, &path);
65397
65398 dput_and_out:
65399 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65400 goto out_putf;
65401
65402 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65403 +
65404 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65405 + error = -EPERM;
65406 +
65407 + if (!error)
65408 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65409 +
65410 if (!error)
65411 set_fs_pwd(current->fs, &f.file->f_path);
65412 out_putf:
65413 @@ -469,7 +487,13 @@ retry:
65414 if (error)
65415 goto dput_and_out;
65416
65417 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65418 + goto dput_and_out;
65419 +
65420 set_fs_root(current->fs, &path);
65421 +
65422 + gr_handle_chroot_chdir(&path);
65423 +
65424 error = 0;
65425 dput_and_out:
65426 path_put(&path);
65427 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65428 return error;
65429 retry_deleg:
65430 mutex_lock(&inode->i_mutex);
65431 +
65432 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65433 + error = -EACCES;
65434 + goto out_unlock;
65435 + }
65436 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65437 + error = -EACCES;
65438 + goto out_unlock;
65439 + }
65440 +
65441 error = security_path_chmod(path, mode);
65442 if (error)
65443 goto out_unlock;
65444 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65445 uid = make_kuid(current_user_ns(), user);
65446 gid = make_kgid(current_user_ns(), group);
65447
65448 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65449 + return -EACCES;
65450 +
65451 newattrs.ia_valid = ATTR_CTIME;
65452 if (user != (uid_t) -1) {
65453 if (!uid_valid(uid))
65454 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65455 } else {
65456 fsnotify_open(f);
65457 fd_install(fd, f);
65458 + trace_do_sys_open(tmp->name, flags, mode);
65459 }
65460 }
65461 putname(tmp);
65462 diff --git a/fs/pipe.c b/fs/pipe.c
65463 index 21981e5..3d5f55c 100644
65464 --- a/fs/pipe.c
65465 +++ b/fs/pipe.c
65466 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65467
65468 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65469 {
65470 - if (pipe->files)
65471 + if (atomic_read(&pipe->files))
65472 mutex_lock_nested(&pipe->mutex, subclass);
65473 }
65474
65475 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65476
65477 void pipe_unlock(struct pipe_inode_info *pipe)
65478 {
65479 - if (pipe->files)
65480 + if (atomic_read(&pipe->files))
65481 mutex_unlock(&pipe->mutex);
65482 }
65483 EXPORT_SYMBOL(pipe_unlock);
65484 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65485 }
65486 if (bufs) /* More to do? */
65487 continue;
65488 - if (!pipe->writers)
65489 + if (!atomic_read(&pipe->writers))
65490 break;
65491 - if (!pipe->waiting_writers) {
65492 + if (!atomic_read(&pipe->waiting_writers)) {
65493 /* syscall merging: Usually we must not sleep
65494 * if O_NONBLOCK is set, or if we got some data.
65495 * But if a writer sleeps in kernel space, then
65496 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65497
65498 __pipe_lock(pipe);
65499
65500 - if (!pipe->readers) {
65501 + if (!atomic_read(&pipe->readers)) {
65502 send_sig(SIGPIPE, current, 0);
65503 ret = -EPIPE;
65504 goto out;
65505 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65506 for (;;) {
65507 int bufs;
65508
65509 - if (!pipe->readers) {
65510 + if (!atomic_read(&pipe->readers)) {
65511 send_sig(SIGPIPE, current, 0);
65512 if (!ret)
65513 ret = -EPIPE;
65514 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65515 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65516 do_wakeup = 0;
65517 }
65518 - pipe->waiting_writers++;
65519 + atomic_inc(&pipe->waiting_writers);
65520 pipe_wait(pipe);
65521 - pipe->waiting_writers--;
65522 + atomic_dec(&pipe->waiting_writers);
65523 }
65524 out:
65525 __pipe_unlock(pipe);
65526 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65527 mask = 0;
65528 if (filp->f_mode & FMODE_READ) {
65529 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65530 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65531 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65532 mask |= POLLHUP;
65533 }
65534
65535 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65536 * Most Unices do not set POLLERR for FIFOs but on Linux they
65537 * behave exactly like pipes for poll().
65538 */
65539 - if (!pipe->readers)
65540 + if (!atomic_read(&pipe->readers))
65541 mask |= POLLERR;
65542 }
65543
65544 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65545 int kill = 0;
65546
65547 spin_lock(&inode->i_lock);
65548 - if (!--pipe->files) {
65549 + if (atomic_dec_and_test(&pipe->files)) {
65550 inode->i_pipe = NULL;
65551 kill = 1;
65552 }
65553 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65554
65555 __pipe_lock(pipe);
65556 if (file->f_mode & FMODE_READ)
65557 - pipe->readers--;
65558 + atomic_dec(&pipe->readers);
65559 if (file->f_mode & FMODE_WRITE)
65560 - pipe->writers--;
65561 + atomic_dec(&pipe->writers);
65562
65563 - if (pipe->readers || pipe->writers) {
65564 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65565 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65566 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65567 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65568 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65569 kfree(pipe);
65570 }
65571
65572 -static struct vfsmount *pipe_mnt __read_mostly;
65573 +struct vfsmount *pipe_mnt __read_mostly;
65574
65575 /*
65576 * pipefs_dname() is called from d_path().
65577 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65578 goto fail_iput;
65579
65580 inode->i_pipe = pipe;
65581 - pipe->files = 2;
65582 - pipe->readers = pipe->writers = 1;
65583 + atomic_set(&pipe->files, 2);
65584 + atomic_set(&pipe->readers, 1);
65585 + atomic_set(&pipe->writers, 1);
65586 inode->i_fop = &pipefifo_fops;
65587
65588 /*
65589 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65590 spin_lock(&inode->i_lock);
65591 if (inode->i_pipe) {
65592 pipe = inode->i_pipe;
65593 - pipe->files++;
65594 + atomic_inc(&pipe->files);
65595 spin_unlock(&inode->i_lock);
65596 } else {
65597 spin_unlock(&inode->i_lock);
65598 pipe = alloc_pipe_info();
65599 if (!pipe)
65600 return -ENOMEM;
65601 - pipe->files = 1;
65602 + atomic_set(&pipe->files, 1);
65603 spin_lock(&inode->i_lock);
65604 if (unlikely(inode->i_pipe)) {
65605 - inode->i_pipe->files++;
65606 + atomic_inc(&inode->i_pipe->files);
65607 spin_unlock(&inode->i_lock);
65608 free_pipe_info(pipe);
65609 pipe = inode->i_pipe;
65610 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65611 * opened, even when there is no process writing the FIFO.
65612 */
65613 pipe->r_counter++;
65614 - if (pipe->readers++ == 0)
65615 + if (atomic_inc_return(&pipe->readers) == 1)
65616 wake_up_partner(pipe);
65617
65618 - if (!is_pipe && !pipe->writers) {
65619 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65620 if ((filp->f_flags & O_NONBLOCK)) {
65621 /* suppress POLLHUP until we have
65622 * seen a writer */
65623 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65624 * errno=ENXIO when there is no process reading the FIFO.
65625 */
65626 ret = -ENXIO;
65627 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65628 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65629 goto err;
65630
65631 pipe->w_counter++;
65632 - if (!pipe->writers++)
65633 + if (atomic_inc_return(&pipe->writers) == 1)
65634 wake_up_partner(pipe);
65635
65636 - if (!is_pipe && !pipe->readers) {
65637 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65638 if (wait_for_partner(pipe, &pipe->r_counter))
65639 goto err_wr;
65640 }
65641 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65642 * the process can at least talk to itself.
65643 */
65644
65645 - pipe->readers++;
65646 - pipe->writers++;
65647 + atomic_inc(&pipe->readers);
65648 + atomic_inc(&pipe->writers);
65649 pipe->r_counter++;
65650 pipe->w_counter++;
65651 - if (pipe->readers == 1 || pipe->writers == 1)
65652 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65653 wake_up_partner(pipe);
65654 break;
65655
65656 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65657 return 0;
65658
65659 err_rd:
65660 - if (!--pipe->readers)
65661 + if (atomic_dec_and_test(&pipe->readers))
65662 wake_up_interruptible(&pipe->wait);
65663 ret = -ERESTARTSYS;
65664 goto err;
65665
65666 err_wr:
65667 - if (!--pipe->writers)
65668 + if (atomic_dec_and_test(&pipe->writers))
65669 wake_up_interruptible(&pipe->wait);
65670 ret = -ERESTARTSYS;
65671 goto err;
65672 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65673 index 0855f77..6787d50 100644
65674 --- a/fs/posix_acl.c
65675 +++ b/fs/posix_acl.c
65676 @@ -20,6 +20,7 @@
65677 #include <linux/xattr.h>
65678 #include <linux/export.h>
65679 #include <linux/user_namespace.h>
65680 +#include <linux/grsecurity.h>
65681
65682 struct posix_acl **acl_by_type(struct inode *inode, int type)
65683 {
65684 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65685 }
65686 }
65687 if (mode_p)
65688 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65689 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65690 return not_equiv;
65691 }
65692 EXPORT_SYMBOL(posix_acl_equiv_mode);
65693 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65694 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65695 }
65696
65697 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65698 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65699 return not_equiv;
65700 }
65701
65702 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65703 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65704 int err = -ENOMEM;
65705 if (clone) {
65706 + *mode_p &= ~gr_acl_umask();
65707 +
65708 err = posix_acl_create_masq(clone, mode_p);
65709 if (err < 0) {
65710 posix_acl_release(clone);
65711 @@ -659,11 +662,12 @@ struct posix_acl *
65712 posix_acl_from_xattr(struct user_namespace *user_ns,
65713 const void *value, size_t size)
65714 {
65715 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65716 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65717 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65718 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65719 int count;
65720 struct posix_acl *acl;
65721 struct posix_acl_entry *acl_e;
65722 + umode_t umask = gr_acl_umask();
65723
65724 if (!value)
65725 return NULL;
65726 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65727
65728 switch(acl_e->e_tag) {
65729 case ACL_USER_OBJ:
65730 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65731 + break;
65732 case ACL_GROUP_OBJ:
65733 case ACL_MASK:
65734 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65735 + break;
65736 case ACL_OTHER:
65737 + acl_e->e_perm &= ~(umask & S_IRWXO);
65738 break;
65739
65740 case ACL_USER:
65741 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65742 acl_e->e_uid =
65743 make_kuid(user_ns,
65744 le32_to_cpu(entry->e_id));
65745 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65746 goto fail;
65747 break;
65748 case ACL_GROUP:
65749 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65750 acl_e->e_gid =
65751 make_kgid(user_ns,
65752 le32_to_cpu(entry->e_id));
65753 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65754 index 2183fcf..3c32a98 100644
65755 --- a/fs/proc/Kconfig
65756 +++ b/fs/proc/Kconfig
65757 @@ -30,7 +30,7 @@ config PROC_FS
65758
65759 config PROC_KCORE
65760 bool "/proc/kcore support" if !ARM
65761 - depends on PROC_FS && MMU
65762 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65763 help
65764 Provides a virtual ELF core file of the live kernel. This can
65765 be read with gdb and other ELF tools. No modifications can be
65766 @@ -38,8 +38,8 @@ config PROC_KCORE
65767
65768 config PROC_VMCORE
65769 bool "/proc/vmcore support"
65770 - depends on PROC_FS && CRASH_DUMP
65771 - default y
65772 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65773 + default n
65774 help
65775 Exports the dump image of crashed kernel in ELF format.
65776
65777 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65778 limited in memory.
65779
65780 config PROC_PAGE_MONITOR
65781 - default y
65782 - depends on PROC_FS && MMU
65783 + default n
65784 + depends on PROC_FS && MMU && !GRKERNSEC
65785 bool "Enable /proc page monitoring" if EXPERT
65786 help
65787 Various /proc files exist to monitor process memory utilization:
65788 diff --git a/fs/proc/array.c b/fs/proc/array.c
65789 index cd3653e..9b9b79a 100644
65790 --- a/fs/proc/array.c
65791 +++ b/fs/proc/array.c
65792 @@ -60,6 +60,7 @@
65793 #include <linux/tty.h>
65794 #include <linux/string.h>
65795 #include <linux/mman.h>
65796 +#include <linux/grsecurity.h>
65797 #include <linux/proc_fs.h>
65798 #include <linux/ioport.h>
65799 #include <linux/uaccess.h>
65800 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65801 seq_putc(m, '\n');
65802 }
65803
65804 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65805 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65806 +{
65807 + if (p->mm)
65808 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65809 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65810 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65811 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65812 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65813 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65814 + else
65815 + seq_printf(m, "PaX:\t-----\n");
65816 +}
65817 +#endif
65818 +
65819 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65820 struct pid *pid, struct task_struct *task)
65821 {
65822 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65823 task_cpus_allowed(m, task);
65824 cpuset_task_status_allowed(m, task);
65825 task_context_switch_counts(m, task);
65826 +
65827 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65828 + task_pax(m, task);
65829 +#endif
65830 +
65831 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65832 + task_grsec_rbac(m, task);
65833 +#endif
65834 +
65835 return 0;
65836 }
65837
65838 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65839 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65840 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65841 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65842 +#endif
65843 +
65844 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65845 struct pid *pid, struct task_struct *task, int whole)
65846 {
65847 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65848 char tcomm[sizeof(task->comm)];
65849 unsigned long flags;
65850
65851 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65852 + if (current->exec_id != m->exec_id) {
65853 + gr_log_badprocpid("stat");
65854 + return 0;
65855 + }
65856 +#endif
65857 +
65858 state = *get_task_state(task);
65859 vsize = eip = esp = 0;
65860 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65861 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65862 gtime = task_gtime(task);
65863 }
65864
65865 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65866 + if (PAX_RAND_FLAGS(mm)) {
65867 + eip = 0;
65868 + esp = 0;
65869 + wchan = 0;
65870 + }
65871 +#endif
65872 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65873 + wchan = 0;
65874 + eip =0;
65875 + esp =0;
65876 +#endif
65877 +
65878 /* scale priority and nice values from timeslices to -20..20 */
65879 /* to make it look like a "normal" Unix priority/nice value */
65880 priority = task_prio(task);
65881 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65882 seq_put_decimal_ull(m, ' ', vsize);
65883 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65884 seq_put_decimal_ull(m, ' ', rsslim);
65885 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65886 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65887 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65888 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65889 +#else
65890 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65891 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65892 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65893 +#endif
65894 seq_put_decimal_ull(m, ' ', esp);
65895 seq_put_decimal_ull(m, ' ', eip);
65896 /* The signal information here is obsolete.
65897 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65898 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65899 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65900
65901 - if (mm && permitted) {
65902 + if (mm && permitted
65903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65904 + && !PAX_RAND_FLAGS(mm)
65905 +#endif
65906 + ) {
65907 seq_put_decimal_ull(m, ' ', mm->start_data);
65908 seq_put_decimal_ull(m, ' ', mm->end_data);
65909 seq_put_decimal_ull(m, ' ', mm->start_brk);
65910 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65911 struct pid *pid, struct task_struct *task)
65912 {
65913 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65914 - struct mm_struct *mm = get_task_mm(task);
65915 + struct mm_struct *mm;
65916
65917 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65918 + if (current->exec_id != m->exec_id) {
65919 + gr_log_badprocpid("statm");
65920 + return 0;
65921 + }
65922 +#endif
65923 + mm = get_task_mm(task);
65924 if (mm) {
65925 size = task_statm(mm, &shared, &text, &data, &resident);
65926 mmput(mm);
65927 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65928 return 0;
65929 }
65930
65931 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65932 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65933 +{
65934 + unsigned long flags;
65935 + u32 curr_ip = 0;
65936 +
65937 + if (lock_task_sighand(task, &flags)) {
65938 + curr_ip = task->signal->curr_ip;
65939 + unlock_task_sighand(task, &flags);
65940 + }
65941 + return seq_printf(m, "%pI4\n", &curr_ip);
65942 +}
65943 +#endif
65944 +
65945 #ifdef CONFIG_CHECKPOINT_RESTORE
65946 static struct pid *
65947 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65948 diff --git a/fs/proc/base.c b/fs/proc/base.c
65949 index 7dc3ea8..a08077e 100644
65950 --- a/fs/proc/base.c
65951 +++ b/fs/proc/base.c
65952 @@ -113,6 +113,14 @@ struct pid_entry {
65953 union proc_op op;
65954 };
65955
65956 +struct getdents_callback {
65957 + struct linux_dirent __user * current_dir;
65958 + struct linux_dirent __user * previous;
65959 + struct file * file;
65960 + int count;
65961 + int error;
65962 +};
65963 +
65964 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65965 .name = (NAME), \
65966 .len = sizeof(NAME) - 1, \
65967 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65968 return 0;
65969 }
65970
65971 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65972 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65973 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65974 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65975 +#endif
65976 +
65977 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65978 struct pid *pid, struct task_struct *task)
65979 {
65980 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65981 if (mm && !IS_ERR(mm)) {
65982 unsigned int nwords = 0;
65983 +
65984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65985 + /* allow if we're currently ptracing this task */
65986 + if (PAX_RAND_FLAGS(mm) &&
65987 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65988 + mmput(mm);
65989 + return 0;
65990 + }
65991 +#endif
65992 +
65993 do {
65994 nwords += 2;
65995 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65996 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65997 }
65998
65999
66000 -#ifdef CONFIG_KALLSYMS
66001 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66002 /*
66003 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66004 * Returns the resolved symbol. If that fails, simply return the address.
66005 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66006 mutex_unlock(&task->signal->cred_guard_mutex);
66007 }
66008
66009 -#ifdef CONFIG_STACKTRACE
66010 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66011
66012 #define MAX_STACK_TRACE_DEPTH 64
66013
66014 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66015 return 0;
66016 }
66017
66018 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66019 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66020 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66021 struct pid *pid, struct task_struct *task)
66022 {
66023 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66024 /************************************************************************/
66025
66026 /* permission checks */
66027 -static int proc_fd_access_allowed(struct inode *inode)
66028 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66029 {
66030 struct task_struct *task;
66031 int allowed = 0;
66032 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66033 */
66034 task = get_proc_task(inode);
66035 if (task) {
66036 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66037 + if (log)
66038 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66039 + else
66040 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66041 put_task_struct(task);
66042 }
66043 return allowed;
66044 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66045 struct task_struct *task,
66046 int hide_pid_min)
66047 {
66048 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66049 + return false;
66050 +
66051 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66052 + rcu_read_lock();
66053 + {
66054 + const struct cred *tmpcred = current_cred();
66055 + const struct cred *cred = __task_cred(task);
66056 +
66057 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66058 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66059 + || in_group_p(grsec_proc_gid)
66060 +#endif
66061 + ) {
66062 + rcu_read_unlock();
66063 + return true;
66064 + }
66065 + }
66066 + rcu_read_unlock();
66067 +
66068 + if (!pid->hide_pid)
66069 + return false;
66070 +#endif
66071 +
66072 if (pid->hide_pid < hide_pid_min)
66073 return true;
66074 if (in_group_p(pid->pid_gid))
66075 return true;
66076 +
66077 return ptrace_may_access(task, PTRACE_MODE_READ);
66078 }
66079
66080 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66081 put_task_struct(task);
66082
66083 if (!has_perms) {
66084 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66085 + {
66086 +#else
66087 if (pid->hide_pid == 2) {
66088 +#endif
66089 /*
66090 * Let's make getdents(), stat(), and open()
66091 * consistent with each other. If a process
66092 @@ -609,6 +665,10 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
66093
66094 if (task) {
66095 mm = mm_access(task, mode);
66096 + if (!IS_ERR_OR_NULL(mm) && gr_acl_handle_procpidmem(task)) {
66097 + mmput(mm);
66098 + mm = ERR_PTR(-EPERM);
66099 + }
66100 put_task_struct(task);
66101
66102 if (!IS_ERR_OR_NULL(mm)) {
66103 @@ -630,6 +690,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66104 return PTR_ERR(mm);
66105
66106 file->private_data = mm;
66107 +
66108 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66109 + file->f_version = current->exec_id;
66110 +#endif
66111 +
66112 return 0;
66113 }
66114
66115 @@ -651,6 +716,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66116 ssize_t copied;
66117 char *page;
66118
66119 +#ifdef CONFIG_GRKERNSEC
66120 + if (write)
66121 + return -EPERM;
66122 +#endif
66123 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66124 + if (file->f_version != current->exec_id) {
66125 + gr_log_badprocpid("mem");
66126 + return 0;
66127 + }
66128 +#endif
66129 +
66130 if (!mm)
66131 return 0;
66132
66133 @@ -663,7 +739,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66134 goto free;
66135
66136 while (count > 0) {
66137 - int this_len = min_t(int, count, PAGE_SIZE);
66138 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66139
66140 if (write && copy_from_user(page, buf, this_len)) {
66141 copied = -EFAULT;
66142 @@ -755,6 +831,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66143 if (!mm)
66144 return 0;
66145
66146 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66147 + if (file->f_version != current->exec_id) {
66148 + gr_log_badprocpid("environ");
66149 + return 0;
66150 + }
66151 +#endif
66152 +
66153 page = (char *)__get_free_page(GFP_TEMPORARY);
66154 if (!page)
66155 return -ENOMEM;
66156 @@ -764,7 +847,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66157 goto free;
66158 while (count > 0) {
66159 size_t this_len, max_len;
66160 - int retval;
66161 + ssize_t retval;
66162
66163 if (src >= (mm->env_end - mm->env_start))
66164 break;
66165 @@ -1378,7 +1461,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66166 int error = -EACCES;
66167
66168 /* Are we allowed to snoop on the tasks file descriptors? */
66169 - if (!proc_fd_access_allowed(inode))
66170 + if (!proc_fd_access_allowed(inode, 0))
66171 goto out;
66172
66173 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66174 @@ -1422,8 +1505,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66175 struct path path;
66176
66177 /* Are we allowed to snoop on the tasks file descriptors? */
66178 - if (!proc_fd_access_allowed(inode))
66179 - goto out;
66180 + /* logging this is needed for learning on chromium to work properly,
66181 + but we don't want to flood the logs from 'ps' which does a readlink
66182 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66183 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66184 + */
66185 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66186 + if (!proc_fd_access_allowed(inode,0))
66187 + goto out;
66188 + } else {
66189 + if (!proc_fd_access_allowed(inode,1))
66190 + goto out;
66191 + }
66192
66193 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66194 if (error)
66195 @@ -1473,7 +1566,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66196 rcu_read_lock();
66197 cred = __task_cred(task);
66198 inode->i_uid = cred->euid;
66199 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66200 + inode->i_gid = grsec_proc_gid;
66201 +#else
66202 inode->i_gid = cred->egid;
66203 +#endif
66204 rcu_read_unlock();
66205 }
66206 security_task_to_inode(task, inode);
66207 @@ -1509,10 +1606,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66208 return -ENOENT;
66209 }
66210 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66211 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66212 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66213 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66214 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66215 +#endif
66216 task_dumpable(task)) {
66217 cred = __task_cred(task);
66218 stat->uid = cred->euid;
66219 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66220 + stat->gid = grsec_proc_gid;
66221 +#else
66222 stat->gid = cred->egid;
66223 +#endif
66224 }
66225 }
66226 rcu_read_unlock();
66227 @@ -1550,11 +1656,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66228
66229 if (task) {
66230 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66231 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66232 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66233 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66234 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66235 +#endif
66236 task_dumpable(task)) {
66237 rcu_read_lock();
66238 cred = __task_cred(task);
66239 inode->i_uid = cred->euid;
66240 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66241 + inode->i_gid = grsec_proc_gid;
66242 +#else
66243 inode->i_gid = cred->egid;
66244 +#endif
66245 rcu_read_unlock();
66246 } else {
66247 inode->i_uid = GLOBAL_ROOT_UID;
66248 @@ -2085,6 +2200,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66249 if (!task)
66250 goto out_no_task;
66251
66252 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66253 + goto out;
66254 +
66255 /*
66256 * Yes, it does not scale. And it should not. Don't add
66257 * new entries into /proc/<tgid>/ without very good reasons.
66258 @@ -2115,6 +2233,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66259 if (!task)
66260 return -ENOENT;
66261
66262 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66263 + goto out;
66264 +
66265 if (!dir_emit_dots(file, ctx))
66266 goto out;
66267
66268 @@ -2557,7 +2678,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66269 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66270 #endif
66271 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66272 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66273 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66274 ONE("syscall", S_IRUSR, proc_pid_syscall),
66275 #endif
66276 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66277 @@ -2582,10 +2703,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66278 #ifdef CONFIG_SECURITY
66279 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66280 #endif
66281 -#ifdef CONFIG_KALLSYMS
66282 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66283 ONE("wchan", S_IRUGO, proc_pid_wchan),
66284 #endif
66285 -#ifdef CONFIG_STACKTRACE
66286 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66287 ONE("stack", S_IRUSR, proc_pid_stack),
66288 #endif
66289 #ifdef CONFIG_SCHEDSTATS
66290 @@ -2619,6 +2740,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66291 #ifdef CONFIG_HARDWALL
66292 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66293 #endif
66294 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66295 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66296 +#endif
66297 #ifdef CONFIG_USER_NS
66298 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66299 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66300 @@ -2748,7 +2872,14 @@ static int proc_pid_instantiate(struct inode *dir,
66301 if (!inode)
66302 goto out;
66303
66304 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66305 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66306 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66307 + inode->i_gid = grsec_proc_gid;
66308 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66309 +#else
66310 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66311 +#endif
66312 inode->i_op = &proc_tgid_base_inode_operations;
66313 inode->i_fop = &proc_tgid_base_operations;
66314 inode->i_flags|=S_IMMUTABLE;
66315 @@ -2786,7 +2917,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66316 if (!task)
66317 goto out;
66318
66319 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66320 + goto out_put_task;
66321 +
66322 result = proc_pid_instantiate(dir, dentry, task, NULL);
66323 +out_put_task:
66324 put_task_struct(task);
66325 out:
66326 return ERR_PTR(result);
66327 @@ -2900,7 +3035,7 @@ static const struct pid_entry tid_base_stuff[] = {
66328 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66329 #endif
66330 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66331 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66332 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66333 ONE("syscall", S_IRUSR, proc_pid_syscall),
66334 #endif
66335 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66336 @@ -2927,10 +3062,10 @@ static const struct pid_entry tid_base_stuff[] = {
66337 #ifdef CONFIG_SECURITY
66338 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66339 #endif
66340 -#ifdef CONFIG_KALLSYMS
66341 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66342 ONE("wchan", S_IRUGO, proc_pid_wchan),
66343 #endif
66344 -#ifdef CONFIG_STACKTRACE
66345 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66346 ONE("stack", S_IRUSR, proc_pid_stack),
66347 #endif
66348 #ifdef CONFIG_SCHEDSTATS
66349 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66350 index cbd82df..c0407d2 100644
66351 --- a/fs/proc/cmdline.c
66352 +++ b/fs/proc/cmdline.c
66353 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66354
66355 static int __init proc_cmdline_init(void)
66356 {
66357 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66358 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66359 +#else
66360 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66361 +#endif
66362 return 0;
66363 }
66364 fs_initcall(proc_cmdline_init);
66365 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66366 index 50493ed..248166b 100644
66367 --- a/fs/proc/devices.c
66368 +++ b/fs/proc/devices.c
66369 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66370
66371 static int __init proc_devices_init(void)
66372 {
66373 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66374 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66375 +#else
66376 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66377 +#endif
66378 return 0;
66379 }
66380 fs_initcall(proc_devices_init);
66381 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66382 index e11d7c5..9128ce06 100644
66383 --- a/fs/proc/fd.c
66384 +++ b/fs/proc/fd.c
66385 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66386 if (!task)
66387 return -ENOENT;
66388
66389 - files = get_files_struct(task);
66390 + if (!gr_acl_handle_procpidmem(task))
66391 + files = get_files_struct(task);
66392 put_task_struct(task);
66393
66394 if (files) {
66395 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66396 */
66397 int proc_fd_permission(struct inode *inode, int mask)
66398 {
66399 + struct task_struct *task;
66400 int rv = generic_permission(inode, mask);
66401 - if (rv == 0)
66402 - return 0;
66403 +
66404 if (task_tgid(current) == proc_pid(inode))
66405 rv = 0;
66406 +
66407 + task = get_proc_task(inode);
66408 + if (task == NULL)
66409 + return rv;
66410 +
66411 + if (gr_acl_handle_procpidmem(task))
66412 + rv = -EACCES;
66413 +
66414 + put_task_struct(task);
66415 +
66416 return rv;
66417 }
66418
66419 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66420 index 317b726..e329aed 100644
66421 --- a/fs/proc/generic.c
66422 +++ b/fs/proc/generic.c
66423 @@ -23,6 +23,7 @@
66424 #include <linux/bitops.h>
66425 #include <linux/spinlock.h>
66426 #include <linux/completion.h>
66427 +#include <linux/grsecurity.h>
66428 #include <asm/uaccess.h>
66429
66430 #include "internal.h"
66431 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66432 return proc_lookup_de(PDE(dir), dir, dentry);
66433 }
66434
66435 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66436 + unsigned int flags)
66437 +{
66438 + if (gr_proc_is_restricted())
66439 + return ERR_PTR(-EACCES);
66440 +
66441 + return proc_lookup_de(PDE(dir), dir, dentry);
66442 +}
66443 +
66444 /*
66445 * This returns non-zero if at EOF, so that the /proc
66446 * root directory can use this and check if it should
66447 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66448 return proc_readdir_de(PDE(inode), file, ctx);
66449 }
66450
66451 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66452 +{
66453 + struct inode *inode = file_inode(file);
66454 +
66455 + if (gr_proc_is_restricted())
66456 + return -EACCES;
66457 +
66458 + return proc_readdir_de(PDE(inode), file, ctx);
66459 +}
66460 +
66461 /*
66462 * These are the generic /proc directory operations. They
66463 * use the in-memory "struct proc_dir_entry" tree to parse
66464 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66465 .iterate = proc_readdir,
66466 };
66467
66468 +static const struct file_operations proc_dir_restricted_operations = {
66469 + .llseek = generic_file_llseek,
66470 + .read = generic_read_dir,
66471 + .iterate = proc_readdir_restrict,
66472 +};
66473 +
66474 /*
66475 * proc directories can do almost nothing..
66476 */
66477 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66478 .setattr = proc_notify_change,
66479 };
66480
66481 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66482 + .lookup = proc_lookup_restrict,
66483 + .getattr = proc_getattr,
66484 + .setattr = proc_notify_change,
66485 +};
66486 +
66487 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66488 {
66489 struct proc_dir_entry *tmp;
66490 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66491 return ret;
66492
66493 if (S_ISDIR(dp->mode)) {
66494 - dp->proc_fops = &proc_dir_operations;
66495 - dp->proc_iops = &proc_dir_inode_operations;
66496 + if (dp->restricted) {
66497 + dp->proc_fops = &proc_dir_restricted_operations;
66498 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66499 + } else {
66500 + dp->proc_fops = &proc_dir_operations;
66501 + dp->proc_iops = &proc_dir_inode_operations;
66502 + }
66503 dir->nlink++;
66504 } else if (S_ISLNK(dp->mode)) {
66505 dp->proc_iops = &proc_link_inode_operations;
66506 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66507 }
66508 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66509
66510 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66511 + struct proc_dir_entry *parent, void *data)
66512 +{
66513 + struct proc_dir_entry *ent;
66514 +
66515 + if (mode == 0)
66516 + mode = S_IRUGO | S_IXUGO;
66517 +
66518 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66519 + if (ent) {
66520 + ent->data = data;
66521 + ent->restricted = 1;
66522 + if (proc_register(parent, ent) < 0) {
66523 + kfree(ent);
66524 + ent = NULL;
66525 + }
66526 + }
66527 + return ent;
66528 +}
66529 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66530 +
66531 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66532 struct proc_dir_entry *parent)
66533 {
66534 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66535 }
66536 EXPORT_SYMBOL(proc_mkdir);
66537
66538 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66539 + struct proc_dir_entry *parent)
66540 +{
66541 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66542 +}
66543 +EXPORT_SYMBOL(proc_mkdir_restrict);
66544 +
66545 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66546 struct proc_dir_entry *parent,
66547 const struct file_operations *proc_fops,
66548 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66549 index 333080d..0a35ec4 100644
66550 --- a/fs/proc/inode.c
66551 +++ b/fs/proc/inode.c
66552 @@ -23,11 +23,17 @@
66553 #include <linux/slab.h>
66554 #include <linux/mount.h>
66555 #include <linux/magic.h>
66556 +#include <linux/grsecurity.h>
66557
66558 #include <asm/uaccess.h>
66559
66560 #include "internal.h"
66561
66562 +#ifdef CONFIG_PROC_SYSCTL
66563 +extern const struct inode_operations proc_sys_inode_operations;
66564 +extern const struct inode_operations proc_sys_dir_operations;
66565 +#endif
66566 +
66567 static void proc_evict_inode(struct inode *inode)
66568 {
66569 struct proc_dir_entry *de;
66570 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66571 ns = PROC_I(inode)->ns.ns;
66572 if (ns_ops && ns)
66573 ns_ops->put(ns);
66574 +
66575 +#ifdef CONFIG_PROC_SYSCTL
66576 + if (inode->i_op == &proc_sys_inode_operations ||
66577 + inode->i_op == &proc_sys_dir_operations)
66578 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66579 +#endif
66580 +
66581 }
66582
66583 static struct kmem_cache * proc_inode_cachep;
66584 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66585 if (de->mode) {
66586 inode->i_mode = de->mode;
66587 inode->i_uid = de->uid;
66588 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66589 + inode->i_gid = grsec_proc_gid;
66590 +#else
66591 inode->i_gid = de->gid;
66592 +#endif
66593 }
66594 if (de->size)
66595 inode->i_size = de->size;
66596 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66597 index aa7a0ee..f2318df 100644
66598 --- a/fs/proc/internal.h
66599 +++ b/fs/proc/internal.h
66600 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66601 struct completion *pde_unload_completion;
66602 struct list_head pde_openers; /* who did ->open, but not ->release */
66603 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66604 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66605 u8 namelen;
66606 char name[];
66607 -};
66608 +} __randomize_layout;
66609
66610 union proc_op {
66611 int (*proc_get_link)(struct dentry *, struct path *);
66612 @@ -66,7 +67,7 @@ struct proc_inode {
66613 struct ctl_table *sysctl_entry;
66614 struct proc_ns ns;
66615 struct inode vfs_inode;
66616 -};
66617 +} __randomize_layout;
66618
66619 /*
66620 * General functions
66621 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66622 struct pid *, struct task_struct *);
66623 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66624 struct pid *, struct task_struct *);
66625 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66626 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66627 + struct pid *, struct task_struct *);
66628 +#endif
66629
66630 /*
66631 * base.c
66632 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66633 * generic.c
66634 */
66635 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66636 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66637 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66638 struct dentry *);
66639 extern int proc_readdir(struct file *, struct dir_context *);
66640 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66641 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66642
66643 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66644 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66645 index a352d57..cb94a5c 100644
66646 --- a/fs/proc/interrupts.c
66647 +++ b/fs/proc/interrupts.c
66648 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66649
66650 static int __init proc_interrupts_init(void)
66651 {
66652 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66653 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66654 +#else
66655 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66656 +#endif
66657 return 0;
66658 }
66659 fs_initcall(proc_interrupts_init);
66660 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66661 index 91a4e64..cb007c0 100644
66662 --- a/fs/proc/kcore.c
66663 +++ b/fs/proc/kcore.c
66664 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66665 * the addresses in the elf_phdr on our list.
66666 */
66667 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66668 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66669 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66670 + if (tsz > buflen)
66671 tsz = buflen;
66672 -
66673 +
66674 while (buflen) {
66675 struct kcore_list *m;
66676
66677 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66678 kfree(elf_buf);
66679 } else {
66680 if (kern_addr_valid(start)) {
66681 - unsigned long n;
66682 + char *elf_buf;
66683 + mm_segment_t oldfs;
66684
66685 - n = copy_to_user(buffer, (char *)start, tsz);
66686 - /*
66687 - * We cannot distinguish between fault on source
66688 - * and fault on destination. When this happens
66689 - * we clear too and hope it will trigger the
66690 - * EFAULT again.
66691 - */
66692 - if (n) {
66693 - if (clear_user(buffer + tsz - n,
66694 - n))
66695 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66696 + if (!elf_buf)
66697 + return -ENOMEM;
66698 + oldfs = get_fs();
66699 + set_fs(KERNEL_DS);
66700 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66701 + set_fs(oldfs);
66702 + if (copy_to_user(buffer, elf_buf, tsz)) {
66703 + kfree(elf_buf);
66704 return -EFAULT;
66705 + }
66706 }
66707 + set_fs(oldfs);
66708 + kfree(elf_buf);
66709 } else {
66710 if (clear_user(buffer, tsz))
66711 return -EFAULT;
66712 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66713
66714 static int open_kcore(struct inode *inode, struct file *filp)
66715 {
66716 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66717 + return -EPERM;
66718 +#endif
66719 if (!capable(CAP_SYS_RAWIO))
66720 return -EPERM;
66721 if (kcore_need_update)
66722 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66723 index aa1eee0..03dda72 100644
66724 --- a/fs/proc/meminfo.c
66725 +++ b/fs/proc/meminfo.c
66726 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66727 vmi.used >> 10,
66728 vmi.largest_chunk >> 10
66729 #ifdef CONFIG_MEMORY_FAILURE
66730 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66731 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66732 #endif
66733 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66734 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66735 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66736 index d4a3574..b421ce9 100644
66737 --- a/fs/proc/nommu.c
66738 +++ b/fs/proc/nommu.c
66739 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66740
66741 if (file) {
66742 seq_pad(m, ' ');
66743 - seq_path(m, &file->f_path, "");
66744 + seq_path(m, &file->f_path, "\n\\");
66745 }
66746
66747 seq_putc(m, '\n');
66748 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66749 index a63af3e..b4f262a 100644
66750 --- a/fs/proc/proc_net.c
66751 +++ b/fs/proc/proc_net.c
66752 @@ -23,9 +23,27 @@
66753 #include <linux/nsproxy.h>
66754 #include <net/net_namespace.h>
66755 #include <linux/seq_file.h>
66756 +#include <linux/grsecurity.h>
66757
66758 #include "internal.h"
66759
66760 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66761 +static struct seq_operations *ipv6_seq_ops_addr;
66762 +
66763 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66764 +{
66765 + ipv6_seq_ops_addr = addr;
66766 +}
66767 +
66768 +void unregister_ipv6_seq_ops_addr(void)
66769 +{
66770 + ipv6_seq_ops_addr = NULL;
66771 +}
66772 +
66773 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66774 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66775 +#endif
66776 +
66777 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66778 {
66779 return pde->parent->data;
66780 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66781 return maybe_get_net(PDE_NET(PDE(inode)));
66782 }
66783
66784 +extern const struct seq_operations dev_seq_ops;
66785 +
66786 int seq_open_net(struct inode *ino, struct file *f,
66787 const struct seq_operations *ops, int size)
66788 {
66789 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66790
66791 BUG_ON(size < sizeof(*p));
66792
66793 + /* only permit access to /proc/net/dev */
66794 + if (
66795 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66796 + ops != ipv6_seq_ops_addr &&
66797 +#endif
66798 + ops != &dev_seq_ops && gr_proc_is_restricted())
66799 + return -EACCES;
66800 +
66801 net = get_proc_net(ino);
66802 if (net == NULL)
66803 return -ENXIO;
66804 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66805 int err;
66806 struct net *net;
66807
66808 + if (gr_proc_is_restricted())
66809 + return -EACCES;
66810 +
66811 err = -ENXIO;
66812 net = get_proc_net(inode);
66813 if (net == NULL)
66814 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66815 index f92d5dd..26398ac 100644
66816 --- a/fs/proc/proc_sysctl.c
66817 +++ b/fs/proc/proc_sysctl.c
66818 @@ -11,13 +11,21 @@
66819 #include <linux/namei.h>
66820 #include <linux/mm.h>
66821 #include <linux/module.h>
66822 +#include <linux/nsproxy.h>
66823 +#ifdef CONFIG_GRKERNSEC
66824 +#include <net/net_namespace.h>
66825 +#endif
66826 #include "internal.h"
66827
66828 +extern int gr_handle_chroot_sysctl(const int op);
66829 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66830 + const int op);
66831 +
66832 static const struct dentry_operations proc_sys_dentry_operations;
66833 static const struct file_operations proc_sys_file_operations;
66834 -static const struct inode_operations proc_sys_inode_operations;
66835 +const struct inode_operations proc_sys_inode_operations;
66836 static const struct file_operations proc_sys_dir_file_operations;
66837 -static const struct inode_operations proc_sys_dir_operations;
66838 +const struct inode_operations proc_sys_dir_operations;
66839
66840 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66841 {
66842 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66843
66844 err = NULL;
66845 d_set_d_op(dentry, &proc_sys_dentry_operations);
66846 +
66847 + gr_handle_proc_create(dentry, inode);
66848 +
66849 d_add(dentry, inode);
66850
66851 out:
66852 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66853 struct inode *inode = file_inode(filp);
66854 struct ctl_table_header *head = grab_header(inode);
66855 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66856 + int op = write ? MAY_WRITE : MAY_READ;
66857 ssize_t error;
66858 size_t res;
66859
66860 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66861 * and won't be until we finish.
66862 */
66863 error = -EPERM;
66864 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66865 + if (sysctl_perm(head, table, op))
66866 goto out;
66867
66868 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66869 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66870 if (!table->proc_handler)
66871 goto out;
66872
66873 +#ifdef CONFIG_GRKERNSEC
66874 + error = -EPERM;
66875 + if (gr_handle_chroot_sysctl(op))
66876 + goto out;
66877 + dget(filp->f_path.dentry);
66878 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66879 + dput(filp->f_path.dentry);
66880 + goto out;
66881 + }
66882 + dput(filp->f_path.dentry);
66883 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66884 + goto out;
66885 + if (write) {
66886 + if (current->nsproxy->net_ns != table->extra2) {
66887 + if (!capable(CAP_SYS_ADMIN))
66888 + goto out;
66889 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66890 + goto out;
66891 + }
66892 +#endif
66893 +
66894 /* careful: calling conventions are nasty here */
66895 res = count;
66896 error = table->proc_handler(table, write, buf, &res, ppos);
66897 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66898 return false;
66899 } else {
66900 d_set_d_op(child, &proc_sys_dentry_operations);
66901 +
66902 + gr_handle_proc_create(child, inode);
66903 +
66904 d_add(child, inode);
66905 }
66906 } else {
66907 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66908 if ((*pos)++ < ctx->pos)
66909 return true;
66910
66911 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66912 + return 0;
66913 +
66914 if (unlikely(S_ISLNK(table->mode)))
66915 res = proc_sys_link_fill_cache(file, ctx, head, table);
66916 else
66917 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66918 if (IS_ERR(head))
66919 return PTR_ERR(head);
66920
66921 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66922 + return -ENOENT;
66923 +
66924 generic_fillattr(inode, stat);
66925 if (table)
66926 stat->mode = (stat->mode & S_IFMT) | table->mode;
66927 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66928 .llseek = generic_file_llseek,
66929 };
66930
66931 -static const struct inode_operations proc_sys_inode_operations = {
66932 +const struct inode_operations proc_sys_inode_operations = {
66933 .permission = proc_sys_permission,
66934 .setattr = proc_sys_setattr,
66935 .getattr = proc_sys_getattr,
66936 };
66937
66938 -static const struct inode_operations proc_sys_dir_operations = {
66939 +const struct inode_operations proc_sys_dir_operations = {
66940 .lookup = proc_sys_lookup,
66941 .permission = proc_sys_permission,
66942 .setattr = proc_sys_setattr,
66943 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66944 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66945 const char *name, int namelen)
66946 {
66947 - struct ctl_table *table;
66948 + ctl_table_no_const *table;
66949 struct ctl_dir *new;
66950 struct ctl_node *node;
66951 char *new_name;
66952 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66953 return NULL;
66954
66955 node = (struct ctl_node *)(new + 1);
66956 - table = (struct ctl_table *)(node + 1);
66957 + table = (ctl_table_no_const *)(node + 1);
66958 new_name = (char *)(table + 2);
66959 memcpy(new_name, name, namelen);
66960 new_name[namelen] = '\0';
66961 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66962 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66963 struct ctl_table_root *link_root)
66964 {
66965 - struct ctl_table *link_table, *entry, *link;
66966 + ctl_table_no_const *link_table, *link;
66967 + struct ctl_table *entry;
66968 struct ctl_table_header *links;
66969 struct ctl_node *node;
66970 char *link_name;
66971 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66972 return NULL;
66973
66974 node = (struct ctl_node *)(links + 1);
66975 - link_table = (struct ctl_table *)(node + nr_entries);
66976 + link_table = (ctl_table_no_const *)(node + nr_entries);
66977 link_name = (char *)&link_table[nr_entries + 1];
66978
66979 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66980 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66981 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66982 struct ctl_table *table)
66983 {
66984 - struct ctl_table *ctl_table_arg = NULL;
66985 - struct ctl_table *entry, *files;
66986 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66987 + struct ctl_table *entry;
66988 int nr_files = 0;
66989 int nr_dirs = 0;
66990 int err = -ENOMEM;
66991 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66992 nr_files++;
66993 }
66994
66995 - files = table;
66996 /* If there are mixed files and directories we need a new table */
66997 if (nr_dirs && nr_files) {
66998 - struct ctl_table *new;
66999 + ctl_table_no_const *new;
67000 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67001 GFP_KERNEL);
67002 if (!files)
67003 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67004 /* Register everything except a directory full of subdirectories */
67005 if (nr_files || !nr_dirs) {
67006 struct ctl_table_header *header;
67007 - header = __register_sysctl_table(set, path, files);
67008 + header = __register_sysctl_table(set, path, files ? files : table);
67009 if (!header) {
67010 kfree(ctl_table_arg);
67011 goto out;
67012 diff --git a/fs/proc/root.c b/fs/proc/root.c
67013 index 094e44d..085a877 100644
67014 --- a/fs/proc/root.c
67015 +++ b/fs/proc/root.c
67016 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
67017 proc_mkdir("openprom", NULL);
67018 #endif
67019 proc_tty_init();
67020 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67021 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67022 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67023 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67024 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67025 +#endif
67026 +#else
67027 proc_mkdir("bus", NULL);
67028 +#endif
67029 proc_sys_init();
67030 }
67031
67032 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67033 index 510413eb..34d9a8c 100644
67034 --- a/fs/proc/stat.c
67035 +++ b/fs/proc/stat.c
67036 @@ -11,6 +11,7 @@
67037 #include <linux/irqnr.h>
67038 #include <linux/cputime.h>
67039 #include <linux/tick.h>
67040 +#include <linux/grsecurity.h>
67041
67042 #ifndef arch_irq_stat_cpu
67043 #define arch_irq_stat_cpu(cpu) 0
67044 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67045 u64 sum_softirq = 0;
67046 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67047 struct timespec boottime;
67048 + int unrestricted = 1;
67049 +
67050 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67051 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67052 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67053 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67054 + && !in_group_p(grsec_proc_gid)
67055 +#endif
67056 + )
67057 + unrestricted = 0;
67058 +#endif
67059 +#endif
67060
67061 user = nice = system = idle = iowait =
67062 irq = softirq = steal = 0;
67063 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67064 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67065 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67066 idle += get_idle_time(i);
67067 - iowait += get_iowait_time(i);
67068 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67069 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67070 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67071 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67072 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67073 - sum += kstat_cpu_irqs_sum(i);
67074 - sum += arch_irq_stat_cpu(i);
67075 + if (unrestricted) {
67076 + iowait += get_iowait_time(i);
67077 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67078 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67079 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67080 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67081 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67082 + sum += kstat_cpu_irqs_sum(i);
67083 + sum += arch_irq_stat_cpu(i);
67084 + for (j = 0; j < NR_SOFTIRQS; j++) {
67085 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67086
67087 - for (j = 0; j < NR_SOFTIRQS; j++) {
67088 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67089 -
67090 - per_softirq_sums[j] += softirq_stat;
67091 - sum_softirq += softirq_stat;
67092 + per_softirq_sums[j] += softirq_stat;
67093 + sum_softirq += softirq_stat;
67094 + }
67095 }
67096 }
67097 - sum += arch_irq_stat();
67098 + if (unrestricted)
67099 + sum += arch_irq_stat();
67100
67101 seq_puts(p, "cpu ");
67102 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67103 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67104 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67105 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67106 idle = get_idle_time(i);
67107 - iowait = get_iowait_time(i);
67108 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67109 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67110 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67111 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67112 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67113 + if (unrestricted) {
67114 + iowait = get_iowait_time(i);
67115 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67116 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67117 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67118 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67119 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67120 + }
67121 seq_printf(p, "cpu%d", i);
67122 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67123 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67124 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67125
67126 /* sum again ? it could be updated? */
67127 for_each_irq_nr(j)
67128 - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
67129 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs_usr(j) : 0ULL);
67130
67131 seq_printf(p,
67132 "\nctxt %llu\n"
67133 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67134 "processes %lu\n"
67135 "procs_running %lu\n"
67136 "procs_blocked %lu\n",
67137 - nr_context_switches(),
67138 + unrestricted ? nr_context_switches() : 0ULL,
67139 (unsigned long)jif,
67140 - total_forks,
67141 - nr_running(),
67142 - nr_iowait());
67143 + unrestricted ? total_forks : 0UL,
67144 + unrestricted ? nr_running() : 0UL,
67145 + unrestricted ? nr_iowait() : 0UL);
67146
67147 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67148
67149 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67150 index 4e0388c..fc6a0e1 100644
67151 --- a/fs/proc/task_mmu.c
67152 +++ b/fs/proc/task_mmu.c
67153 @@ -13,12 +13,19 @@
67154 #include <linux/swap.h>
67155 #include <linux/swapops.h>
67156 #include <linux/mmu_notifier.h>
67157 +#include <linux/grsecurity.h>
67158
67159 #include <asm/elf.h>
67160 #include <asm/uaccess.h>
67161 #include <asm/tlbflush.h>
67162 #include "internal.h"
67163
67164 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67165 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67166 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67167 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67168 +#endif
67169 +
67170 void task_mem(struct seq_file *m, struct mm_struct *mm)
67171 {
67172 unsigned long data, text, lib, swap;
67173 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67174 "VmExe:\t%8lu kB\n"
67175 "VmLib:\t%8lu kB\n"
67176 "VmPTE:\t%8lu kB\n"
67177 - "VmSwap:\t%8lu kB\n",
67178 - hiwater_vm << (PAGE_SHIFT-10),
67179 + "VmSwap:\t%8lu kB\n"
67180 +
67181 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67182 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67183 +#endif
67184 +
67185 + ,hiwater_vm << (PAGE_SHIFT-10),
67186 total_vm << (PAGE_SHIFT-10),
67187 mm->locked_vm << (PAGE_SHIFT-10),
67188 mm->pinned_vm << (PAGE_SHIFT-10),
67189 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67190 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67191 (PTRS_PER_PTE * sizeof(pte_t) *
67192 atomic_long_read(&mm->nr_ptes)) >> 10,
67193 - swap << (PAGE_SHIFT-10));
67194 + swap << (PAGE_SHIFT-10)
67195 +
67196 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67197 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67198 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67199 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67200 +#else
67201 + , mm->context.user_cs_base
67202 + , mm->context.user_cs_limit
67203 +#endif
67204 +#endif
67205 +
67206 + );
67207 }
67208
67209 unsigned long task_vsize(struct mm_struct *mm)
67210 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67211 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67212 }
67213
67214 - /* We don't show the stack guard page in /proc/maps */
67215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67216 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67217 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67218 +#else
67219 start = vma->vm_start;
67220 - if (stack_guard_page_start(vma, start))
67221 - start += PAGE_SIZE;
67222 end = vma->vm_end;
67223 - if (stack_guard_page_end(vma, end))
67224 - end -= PAGE_SIZE;
67225 +#endif
67226
67227 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67228 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67229 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67230 flags & VM_WRITE ? 'w' : '-',
67231 flags & VM_EXEC ? 'x' : '-',
67232 flags & VM_MAYSHARE ? 's' : 'p',
67233 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67234 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67235 +#else
67236 pgoff,
67237 +#endif
67238 MAJOR(dev), MINOR(dev), ino);
67239
67240 /*
67241 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67242 */
67243 if (file) {
67244 seq_pad(m, ' ');
67245 - seq_path(m, &file->f_path, "\n");
67246 + seq_path(m, &file->f_path, "\n\\");
67247 goto done;
67248 }
67249
67250 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67251 * Thread stack in /proc/PID/task/TID/maps or
67252 * the main process stack.
67253 */
67254 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67255 - vma->vm_end >= mm->start_stack)) {
67256 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67257 + (vma->vm_start <= mm->start_stack &&
67258 + vma->vm_end >= mm->start_stack)) {
67259 name = "[stack]";
67260 } else {
67261 /* Thread stack in /proc/PID/maps */
67262 @@ -359,6 +388,12 @@ done:
67263
67264 static int show_map(struct seq_file *m, void *v, int is_pid)
67265 {
67266 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67267 + if (current->exec_id != m->exec_id) {
67268 + gr_log_badprocpid("maps");
67269 + return 0;
67270 + }
67271 +#endif
67272 show_map_vma(m, v, is_pid);
67273 m_cache_vma(m, v);
67274 return 0;
67275 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67276 .private = &mss,
67277 };
67278
67279 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67280 + if (current->exec_id != m->exec_id) {
67281 + gr_log_badprocpid("smaps");
67282 + return 0;
67283 + }
67284 +#endif
67285 memset(&mss, 0, sizeof mss);
67286 - mss.vma = vma;
67287 - /* mmap_sem is held in m_start */
67288 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67289 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67290 -
67291 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67292 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67293 +#endif
67294 + mss.vma = vma;
67295 + /* mmap_sem is held in m_start */
67296 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67297 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67298 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67299 + }
67300 +#endif
67301 show_map_vma(m, vma, is_pid);
67302
67303 seq_printf(m,
67304 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67305 "KernelPageSize: %8lu kB\n"
67306 "MMUPageSize: %8lu kB\n"
67307 "Locked: %8lu kB\n",
67308 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67309 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67310 +#else
67311 (vma->vm_end - vma->vm_start) >> 10,
67312 +#endif
67313 mss.resident >> 10,
67314 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67315 mss.shared_clean >> 10,
67316 @@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67317 char buffer[64];
67318 int nid;
67319
67320 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67321 + if (current->exec_id != m->exec_id) {
67322 + gr_log_badprocpid("numa_maps");
67323 + return 0;
67324 + }
67325 +#endif
67326 +
67327 if (!mm)
67328 return 0;
67329
67330 @@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67331 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
67332 }
67333
67334 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67335 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67336 +#else
67337 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67338 +#endif
67339
67340 if (file) {
67341 seq_puts(m, " file=");
67342 - seq_path(m, &file->f_path, "\n\t= ");
67343 + seq_path(m, &file->f_path, "\n\t\\= ");
67344 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67345 seq_puts(m, " heap");
67346 } else {
67347 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67348 index 599ec2e..f1413ae 100644
67349 --- a/fs/proc/task_nommu.c
67350 +++ b/fs/proc/task_nommu.c
67351 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67352 else
67353 bytes += kobjsize(mm);
67354
67355 - if (current->fs && current->fs->users > 1)
67356 + if (current->fs && atomic_read(&current->fs->users) > 1)
67357 sbytes += kobjsize(current->fs);
67358 else
67359 bytes += kobjsize(current->fs);
67360 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67361
67362 if (file) {
67363 seq_pad(m, ' ');
67364 - seq_path(m, &file->f_path, "");
67365 + seq_path(m, &file->f_path, "\n\\");
67366 } else if (mm) {
67367 pid_t tid = pid_of_stack(priv, vma, is_pid);
67368
67369 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67370 index a90d6d35..d08047c 100644
67371 --- a/fs/proc/vmcore.c
67372 +++ b/fs/proc/vmcore.c
67373 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67374 nr_bytes = count;
67375
67376 /* If pfn is not ram, return zeros for sparse dump files */
67377 - if (pfn_is_ram(pfn) == 0)
67378 - memset(buf, 0, nr_bytes);
67379 - else {
67380 + if (pfn_is_ram(pfn) == 0) {
67381 + if (userbuf) {
67382 + if (clear_user((char __force_user *)buf, nr_bytes))
67383 + return -EFAULT;
67384 + } else
67385 + memset(buf, 0, nr_bytes);
67386 + } else {
67387 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67388 offset, userbuf);
67389 if (tmp < 0)
67390 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67391 static int copy_to(void *target, void *src, size_t size, int userbuf)
67392 {
67393 if (userbuf) {
67394 - if (copy_to_user((char __user *) target, src, size))
67395 + if (copy_to_user((char __force_user *) target, src, size))
67396 return -EFAULT;
67397 } else {
67398 memcpy(target, src, size);
67399 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67400 if (*fpos < m->offset + m->size) {
67401 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67402 start = m->paddr + *fpos - m->offset;
67403 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67404 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67405 if (tmp < 0)
67406 return tmp;
67407 buflen -= tsz;
67408 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67409 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67410 size_t buflen, loff_t *fpos)
67411 {
67412 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67413 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67414 }
67415
67416 /*
67417 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67418 index d3fb2b6..43a8140 100644
67419 --- a/fs/qnx6/qnx6.h
67420 +++ b/fs/qnx6/qnx6.h
67421 @@ -74,7 +74,7 @@ enum {
67422 BYTESEX_BE,
67423 };
67424
67425 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67426 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67427 {
67428 if (sbi->s_bytesex == BYTESEX_LE)
67429 return le64_to_cpu((__force __le64)n);
67430 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67431 return (__force __fs64)cpu_to_be64(n);
67432 }
67433
67434 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67435 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67436 {
67437 if (sbi->s_bytesex == BYTESEX_LE)
67438 return le32_to_cpu((__force __le32)n);
67439 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67440 index bb2869f..d34ada8 100644
67441 --- a/fs/quota/netlink.c
67442 +++ b/fs/quota/netlink.c
67443 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67444 void quota_send_warning(struct kqid qid, dev_t dev,
67445 const char warntype)
67446 {
67447 - static atomic_t seq;
67448 + static atomic_unchecked_t seq;
67449 struct sk_buff *skb;
67450 void *msg_head;
67451 int ret;
67452 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67453 "VFS: Not enough memory to send quota warning.\n");
67454 return;
67455 }
67456 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67457 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67458 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67459 if (!msg_head) {
67460 printk(KERN_ERR
67461 diff --git a/fs/read_write.c b/fs/read_write.c
67462 index 7d9318c..51b336f 100644
67463 --- a/fs/read_write.c
67464 +++ b/fs/read_write.c
67465 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67466
67467 old_fs = get_fs();
67468 set_fs(get_ds());
67469 - p = (__force const char __user *)buf;
67470 + p = (const char __force_user *)buf;
67471 if (count > MAX_RW_COUNT)
67472 count = MAX_RW_COUNT;
67473 if (file->f_op->write)
67474 diff --git a/fs/readdir.c b/fs/readdir.c
67475 index 33fd922..e0d6094 100644
67476 --- a/fs/readdir.c
67477 +++ b/fs/readdir.c
67478 @@ -18,6 +18,7 @@
67479 #include <linux/security.h>
67480 #include <linux/syscalls.h>
67481 #include <linux/unistd.h>
67482 +#include <linux/namei.h>
67483
67484 #include <asm/uaccess.h>
67485
67486 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67487 struct readdir_callback {
67488 struct dir_context ctx;
67489 struct old_linux_dirent __user * dirent;
67490 + struct file * file;
67491 int result;
67492 };
67493
67494 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67495 buf->result = -EOVERFLOW;
67496 return -EOVERFLOW;
67497 }
67498 +
67499 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67500 + return 0;
67501 +
67502 buf->result++;
67503 dirent = buf->dirent;
67504 if (!access_ok(VERIFY_WRITE, dirent,
67505 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67506 if (!f.file)
67507 return -EBADF;
67508
67509 + buf.file = f.file;
67510 error = iterate_dir(f.file, &buf.ctx);
67511 if (buf.result)
67512 error = buf.result;
67513 @@ -144,6 +151,7 @@ struct getdents_callback {
67514 struct dir_context ctx;
67515 struct linux_dirent __user * current_dir;
67516 struct linux_dirent __user * previous;
67517 + struct file * file;
67518 int count;
67519 int error;
67520 };
67521 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67522 buf->error = -EOVERFLOW;
67523 return -EOVERFLOW;
67524 }
67525 +
67526 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67527 + return 0;
67528 +
67529 dirent = buf->previous;
67530 if (dirent) {
67531 if (__put_user(offset, &dirent->d_off))
67532 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67533 if (!f.file)
67534 return -EBADF;
67535
67536 + buf.file = f.file;
67537 error = iterate_dir(f.file, &buf.ctx);
67538 if (error >= 0)
67539 error = buf.error;
67540 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67541 struct dir_context ctx;
67542 struct linux_dirent64 __user * current_dir;
67543 struct linux_dirent64 __user * previous;
67544 + struct file *file;
67545 int count;
67546 int error;
67547 };
67548 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67549 buf->error = -EINVAL; /* only used if we fail.. */
67550 if (reclen > buf->count)
67551 return -EINVAL;
67552 +
67553 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67554 + return 0;
67555 +
67556 dirent = buf->previous;
67557 if (dirent) {
67558 if (__put_user(offset, &dirent->d_off))
67559 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67560 if (!f.file)
67561 return -EBADF;
67562
67563 + buf.file = f.file;
67564 error = iterate_dir(f.file, &buf.ctx);
67565 if (error >= 0)
67566 error = buf.error;
67567 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67568 index 9c02d96..6562c10 100644
67569 --- a/fs/reiserfs/do_balan.c
67570 +++ b/fs/reiserfs/do_balan.c
67571 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67572 return;
67573 }
67574
67575 - atomic_inc(&fs_generation(tb->tb_sb));
67576 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67577 do_balance_starts(tb);
67578
67579 /*
67580 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67581 index aca73dd..e3c558d 100644
67582 --- a/fs/reiserfs/item_ops.c
67583 +++ b/fs/reiserfs/item_ops.c
67584 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67585 }
67586
67587 static struct item_operations errcatch_ops = {
67588 - errcatch_bytes_number,
67589 - errcatch_decrement_key,
67590 - errcatch_is_left_mergeable,
67591 - errcatch_print_item,
67592 - errcatch_check_item,
67593 + .bytes_number = errcatch_bytes_number,
67594 + .decrement_key = errcatch_decrement_key,
67595 + .is_left_mergeable = errcatch_is_left_mergeable,
67596 + .print_item = errcatch_print_item,
67597 + .check_item = errcatch_check_item,
67598
67599 - errcatch_create_vi,
67600 - errcatch_check_left,
67601 - errcatch_check_right,
67602 - errcatch_part_size,
67603 - errcatch_unit_num,
67604 - errcatch_print_vi
67605 + .create_vi = errcatch_create_vi,
67606 + .check_left = errcatch_check_left,
67607 + .check_right = errcatch_check_right,
67608 + .part_size = errcatch_part_size,
67609 + .unit_num = errcatch_unit_num,
67610 + .print_vi = errcatch_print_vi
67611 };
67612
67613 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67614 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67615 index 621b9f3..af527fd 100644
67616 --- a/fs/reiserfs/procfs.c
67617 +++ b/fs/reiserfs/procfs.c
67618 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67619 "SMALL_TAILS " : "NO_TAILS ",
67620 replay_only(sb) ? "REPLAY_ONLY " : "",
67621 convert_reiserfs(sb) ? "CONV " : "",
67622 - atomic_read(&r->s_generation_counter),
67623 + atomic_read_unchecked(&r->s_generation_counter),
67624 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67625 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67626 SF(s_good_search_by_key_reada), SF(s_bmaps),
67627 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67628 index 1894d96..1dfd1c2 100644
67629 --- a/fs/reiserfs/reiserfs.h
67630 +++ b/fs/reiserfs/reiserfs.h
67631 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67632 /* Comment? -Hans */
67633 wait_queue_head_t s_wait;
67634 /* increased by one every time the tree gets re-balanced */
67635 - atomic_t s_generation_counter;
67636 + atomic_unchecked_t s_generation_counter;
67637
67638 /* File system properties. Currently holds on-disk FS format */
67639 unsigned long s_properties;
67640 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67641 #define REISERFS_USER_MEM 1 /* user memory mode */
67642
67643 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67644 -#define get_generation(s) atomic_read (&fs_generation(s))
67645 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67646 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67647 #define __fs_changed(gen,s) (gen != get_generation (s))
67648 #define fs_changed(gen,s) \
67649 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67650 index b27ef35..d9c6c18 100644
67651 --- a/fs/reiserfs/super.c
67652 +++ b/fs/reiserfs/super.c
67653 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67654 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67655 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67656 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67657 +#ifdef CONFIG_REISERFS_FS_XATTR
67658 + /* turn on user xattrs by default */
67659 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67660 +#endif
67661 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67662 sbi->s_alloc_options.preallocmin = 0;
67663 /* Preallocate by 16 blocks (17-1) at once */
67664 diff --git a/fs/select.c b/fs/select.c
67665 index 467bb1c..cf9d65a 100644
67666 --- a/fs/select.c
67667 +++ b/fs/select.c
67668 @@ -20,6 +20,7 @@
67669 #include <linux/export.h>
67670 #include <linux/slab.h>
67671 #include <linux/poll.h>
67672 +#include <linux/security.h>
67673 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67674 #include <linux/file.h>
67675 #include <linux/fdtable.h>
67676 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67677 struct poll_list *walk = head;
67678 unsigned long todo = nfds;
67679
67680 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67681 if (nfds > rlimit(RLIMIT_NOFILE))
67682 return -EINVAL;
67683
67684 diff --git a/fs/seq_file.c b/fs/seq_file.c
67685 index 3857b72..0b7281e 100644
67686 --- a/fs/seq_file.c
67687 +++ b/fs/seq_file.c
67688 @@ -12,6 +12,8 @@
67689 #include <linux/slab.h>
67690 #include <linux/cred.h>
67691 #include <linux/mm.h>
67692 +#include <linux/sched.h>
67693 +#include <linux/grsecurity.h>
67694
67695 #include <asm/uaccess.h>
67696 #include <asm/page.h>
67697 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67698
67699 static void *seq_buf_alloc(unsigned long size)
67700 {
67701 - void *buf;
67702 -
67703 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67704 - if (!buf && size > PAGE_SIZE)
67705 - buf = vmalloc(size);
67706 - return buf;
67707 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67708 }
67709
67710 /**
67711 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67712 #ifdef CONFIG_USER_NS
67713 p->user_ns = file->f_cred->user_ns;
67714 #endif
67715 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67716 + p->exec_id = current->exec_id;
67717 +#endif
67718
67719 /*
67720 * Wrappers around seq_open(e.g. swaps_open) need to be
67721 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67722 }
67723 EXPORT_SYMBOL(seq_open);
67724
67725 +
67726 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67727 +{
67728 + if (gr_proc_is_restricted())
67729 + return -EACCES;
67730 +
67731 + return seq_open(file, op);
67732 +}
67733 +EXPORT_SYMBOL(seq_open_restrict);
67734 +
67735 static int traverse(struct seq_file *m, loff_t offset)
67736 {
67737 loff_t pos = 0, index;
67738 @@ -165,7 +175,7 @@ Eoverflow:
67739 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67740 {
67741 struct seq_file *m = file->private_data;
67742 - size_t copied = 0;
67743 + ssize_t copied = 0;
67744 loff_t pos;
67745 size_t n;
67746 void *p;
67747 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67748 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67749 void *data)
67750 {
67751 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67752 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67753 int res = -ENOMEM;
67754
67755 if (op) {
67756 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67757 }
67758 EXPORT_SYMBOL(single_open_size);
67759
67760 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67761 + void *data)
67762 +{
67763 + if (gr_proc_is_restricted())
67764 + return -EACCES;
67765 +
67766 + return single_open(file, show, data);
67767 +}
67768 +EXPORT_SYMBOL(single_open_restrict);
67769 +
67770 +
67771 int single_release(struct inode *inode, struct file *file)
67772 {
67773 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67774 diff --git a/fs/splice.c b/fs/splice.c
67775 index 75c6058..770d40c 100644
67776 --- a/fs/splice.c
67777 +++ b/fs/splice.c
67778 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67779 pipe_lock(pipe);
67780
67781 for (;;) {
67782 - if (!pipe->readers) {
67783 + if (!atomic_read(&pipe->readers)) {
67784 send_sig(SIGPIPE, current, 0);
67785 if (!ret)
67786 ret = -EPIPE;
67787 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67788 page_nr++;
67789 ret += buf->len;
67790
67791 - if (pipe->files)
67792 + if (atomic_read(&pipe->files))
67793 do_wakeup = 1;
67794
67795 if (!--spd->nr_pages)
67796 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67797 do_wakeup = 0;
67798 }
67799
67800 - pipe->waiting_writers++;
67801 + atomic_inc(&pipe->waiting_writers);
67802 pipe_wait(pipe);
67803 - pipe->waiting_writers--;
67804 + atomic_dec(&pipe->waiting_writers);
67805 }
67806
67807 pipe_unlock(pipe);
67808 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67809 old_fs = get_fs();
67810 set_fs(get_ds());
67811 /* The cast to a user pointer is valid due to the set_fs() */
67812 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67813 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67814 set_fs(old_fs);
67815
67816 return res;
67817 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67818 old_fs = get_fs();
67819 set_fs(get_ds());
67820 /* The cast to a user pointer is valid due to the set_fs() */
67821 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67822 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67823 set_fs(old_fs);
67824
67825 return res;
67826 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67827 goto err;
67828
67829 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67830 - vec[i].iov_base = (void __user *) page_address(page);
67831 + vec[i].iov_base = (void __force_user *) page_address(page);
67832 vec[i].iov_len = this_len;
67833 spd.pages[i] = page;
67834 spd.nr_pages++;
67835 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67836 ops->release(pipe, buf);
67837 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67838 pipe->nrbufs--;
67839 - if (pipe->files)
67840 + if (atomic_read(&pipe->files))
67841 sd->need_wakeup = true;
67842 }
67843
67844 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67845 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67846 {
67847 while (!pipe->nrbufs) {
67848 - if (!pipe->writers)
67849 + if (!atomic_read(&pipe->writers))
67850 return 0;
67851
67852 - if (!pipe->waiting_writers && sd->num_spliced)
67853 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67854 return 0;
67855
67856 if (sd->flags & SPLICE_F_NONBLOCK)
67857 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67858 ops->release(pipe, buf);
67859 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67860 pipe->nrbufs--;
67861 - if (pipe->files)
67862 + if (atomic_read(&pipe->files))
67863 sd.need_wakeup = true;
67864 } else {
67865 buf->offset += ret;
67866 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67867 * out of the pipe right after the splice_to_pipe(). So set
67868 * PIPE_READERS appropriately.
67869 */
67870 - pipe->readers = 1;
67871 + atomic_set(&pipe->readers, 1);
67872
67873 current->splice_pipe = pipe;
67874 }
67875 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67876
67877 partial[buffers].offset = off;
67878 partial[buffers].len = plen;
67879 + partial[buffers].private = 0;
67880
67881 off = 0;
67882 len -= plen;
67883 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67884 ret = -ERESTARTSYS;
67885 break;
67886 }
67887 - if (!pipe->writers)
67888 + if (!atomic_read(&pipe->writers))
67889 break;
67890 - if (!pipe->waiting_writers) {
67891 + if (!atomic_read(&pipe->waiting_writers)) {
67892 if (flags & SPLICE_F_NONBLOCK) {
67893 ret = -EAGAIN;
67894 break;
67895 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67896 pipe_lock(pipe);
67897
67898 while (pipe->nrbufs >= pipe->buffers) {
67899 - if (!pipe->readers) {
67900 + if (!atomic_read(&pipe->readers)) {
67901 send_sig(SIGPIPE, current, 0);
67902 ret = -EPIPE;
67903 break;
67904 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67905 ret = -ERESTARTSYS;
67906 break;
67907 }
67908 - pipe->waiting_writers++;
67909 + atomic_inc(&pipe->waiting_writers);
67910 pipe_wait(pipe);
67911 - pipe->waiting_writers--;
67912 + atomic_dec(&pipe->waiting_writers);
67913 }
67914
67915 pipe_unlock(pipe);
67916 @@ -1818,14 +1819,14 @@ retry:
67917 pipe_double_lock(ipipe, opipe);
67918
67919 do {
67920 - if (!opipe->readers) {
67921 + if (!atomic_read(&opipe->readers)) {
67922 send_sig(SIGPIPE, current, 0);
67923 if (!ret)
67924 ret = -EPIPE;
67925 break;
67926 }
67927
67928 - if (!ipipe->nrbufs && !ipipe->writers)
67929 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67930 break;
67931
67932 /*
67933 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67934 pipe_double_lock(ipipe, opipe);
67935
67936 do {
67937 - if (!opipe->readers) {
67938 + if (!atomic_read(&opipe->readers)) {
67939 send_sig(SIGPIPE, current, 0);
67940 if (!ret)
67941 ret = -EPIPE;
67942 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67943 * return EAGAIN if we have the potential of some data in the
67944 * future, otherwise just return 0
67945 */
67946 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67947 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67948 ret = -EAGAIN;
67949
67950 pipe_unlock(ipipe);
67951 diff --git a/fs/stat.c b/fs/stat.c
67952 index ae0c3ce..9ee641c 100644
67953 --- a/fs/stat.c
67954 +++ b/fs/stat.c
67955 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67956 stat->gid = inode->i_gid;
67957 stat->rdev = inode->i_rdev;
67958 stat->size = i_size_read(inode);
67959 - stat->atime = inode->i_atime;
67960 - stat->mtime = inode->i_mtime;
67961 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67962 + stat->atime = inode->i_ctime;
67963 + stat->mtime = inode->i_ctime;
67964 + } else {
67965 + stat->atime = inode->i_atime;
67966 + stat->mtime = inode->i_mtime;
67967 + }
67968 stat->ctime = inode->i_ctime;
67969 stat->blksize = (1 << inode->i_blkbits);
67970 stat->blocks = inode->i_blocks;
67971 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67972 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67973 {
67974 struct inode *inode = path->dentry->d_inode;
67975 + int retval;
67976
67977 - if (inode->i_op->getattr)
67978 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67979 + if (inode->i_op->getattr) {
67980 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67981 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67982 + stat->atime = stat->ctime;
67983 + stat->mtime = stat->ctime;
67984 + }
67985 + return retval;
67986 + }
67987
67988 generic_fillattr(inode, stat);
67989 return 0;
67990 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67991 index 0b45ff4..847de5b 100644
67992 --- a/fs/sysfs/dir.c
67993 +++ b/fs/sysfs/dir.c
67994 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67995 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67996 {
67997 struct kernfs_node *parent, *kn;
67998 + const char *name;
67999 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68000 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68001 + const char *parent_name;
68002 +#endif
68003
68004 BUG_ON(!kobj);
68005
68006 + name = kobject_name(kobj);
68007 +
68008 if (kobj->parent)
68009 parent = kobj->parent->sd;
68010 else
68011 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68012 if (!parent)
68013 return -ENOENT;
68014
68015 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68016 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68017 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68018 + parent_name = parent->name;
68019 + mode = S_IRWXU;
68020 +
68021 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68022 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68023 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68024 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68025 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68026 +#endif
68027 +
68028 + kn = kernfs_create_dir_ns(parent, name,
68029 + mode, kobj, ns);
68030 if (IS_ERR(kn)) {
68031 if (PTR_ERR(kn) == -EEXIST)
68032 - sysfs_warn_dup(parent, kobject_name(kobj));
68033 + sysfs_warn_dup(parent, name);
68034 return PTR_ERR(kn);
68035 }
68036
68037 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68038 index 69d4889..a810bd4 100644
68039 --- a/fs/sysv/sysv.h
68040 +++ b/fs/sysv/sysv.h
68041 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68042 #endif
68043 }
68044
68045 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68046 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68047 {
68048 if (sbi->s_bytesex == BYTESEX_PDP)
68049 return PDP_swab((__force __u32)n);
68050 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68051 index fb08b0c..65fcc7e 100644
68052 --- a/fs/ubifs/io.c
68053 +++ b/fs/ubifs/io.c
68054 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68055 return err;
68056 }
68057
68058 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68059 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68060 {
68061 int err;
68062
68063 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68064 index c175b4d..8f36a16 100644
68065 --- a/fs/udf/misc.c
68066 +++ b/fs/udf/misc.c
68067 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68068
68069 u8 udf_tag_checksum(const struct tag *t)
68070 {
68071 - u8 *data = (u8 *)t;
68072 + const u8 *data = (const u8 *)t;
68073 u8 checksum = 0;
68074 int i;
68075 for (i = 0; i < sizeof(struct tag); ++i)
68076 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68077 index 8d974c4..b82f6ec 100644
68078 --- a/fs/ufs/swab.h
68079 +++ b/fs/ufs/swab.h
68080 @@ -22,7 +22,7 @@ enum {
68081 BYTESEX_BE
68082 };
68083
68084 -static inline u64
68085 +static inline u64 __intentional_overflow(-1)
68086 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68087 {
68088 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68089 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68090 return (__force __fs64)cpu_to_be64(n);
68091 }
68092
68093 -static inline u32
68094 +static inline u32 __intentional_overflow(-1)
68095 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68096 {
68097 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68098 diff --git a/fs/utimes.c b/fs/utimes.c
68099 index aa138d6..5f3a811 100644
68100 --- a/fs/utimes.c
68101 +++ b/fs/utimes.c
68102 @@ -1,6 +1,7 @@
68103 #include <linux/compiler.h>
68104 #include <linux/file.h>
68105 #include <linux/fs.h>
68106 +#include <linux/security.h>
68107 #include <linux/linkage.h>
68108 #include <linux/mount.h>
68109 #include <linux/namei.h>
68110 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68111 }
68112 }
68113 retry_deleg:
68114 +
68115 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68116 + error = -EACCES;
68117 + goto mnt_drop_write_and_out;
68118 + }
68119 +
68120 mutex_lock(&inode->i_mutex);
68121 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68122 mutex_unlock(&inode->i_mutex);
68123 diff --git a/fs/xattr.c b/fs/xattr.c
68124 index 64e83ef..b6be154 100644
68125 --- a/fs/xattr.c
68126 +++ b/fs/xattr.c
68127 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68128 return rc;
68129 }
68130
68131 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68132 +ssize_t
68133 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68134 +{
68135 + struct inode *inode = dentry->d_inode;
68136 + ssize_t error;
68137 +
68138 + error = inode_permission(inode, MAY_EXEC);
68139 + if (error)
68140 + return error;
68141 +
68142 + if (inode->i_op->getxattr)
68143 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68144 + else
68145 + error = -EOPNOTSUPP;
68146 +
68147 + return error;
68148 +}
68149 +EXPORT_SYMBOL(pax_getxattr);
68150 +#endif
68151 +
68152 ssize_t
68153 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68154 {
68155 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68156 * Extended attribute SET operations
68157 */
68158 static long
68159 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68160 +setxattr(struct path *path, const char __user *name, const void __user *value,
68161 size_t size, int flags)
68162 {
68163 int error;
68164 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68165 posix_acl_fix_xattr_from_user(kvalue, size);
68166 }
68167
68168 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68169 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68170 + error = -EACCES;
68171 + goto out;
68172 + }
68173 +
68174 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68175 out:
68176 if (vvalue)
68177 vfree(vvalue);
68178 @@ -376,7 +402,7 @@ retry:
68179 return error;
68180 error = mnt_want_write(path.mnt);
68181 if (!error) {
68182 - error = setxattr(path.dentry, name, value, size, flags);
68183 + error = setxattr(&path, name, value, size, flags);
68184 mnt_drop_write(path.mnt);
68185 }
68186 path_put(&path);
68187 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68188 const void __user *,value, size_t, size, int, flags)
68189 {
68190 struct fd f = fdget(fd);
68191 - struct dentry *dentry;
68192 int error = -EBADF;
68193
68194 if (!f.file)
68195 return error;
68196 - dentry = f.file->f_path.dentry;
68197 - audit_inode(NULL, dentry, 0);
68198 + audit_inode(NULL, f.file->f_path.dentry, 0);
68199 error = mnt_want_write_file(f.file);
68200 if (!error) {
68201 - error = setxattr(dentry, name, value, size, flags);
68202 + error = setxattr(&f.file->f_path, name, value, size, flags);
68203 mnt_drop_write_file(f.file);
68204 }
68205 fdput(f);
68206 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68207 * Extended attribute REMOVE operations
68208 */
68209 static long
68210 -removexattr(struct dentry *d, const char __user *name)
68211 +removexattr(struct path *path, const char __user *name)
68212 {
68213 int error;
68214 char kname[XATTR_NAME_MAX + 1];
68215 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68216 if (error < 0)
68217 return error;
68218
68219 - return vfs_removexattr(d, kname);
68220 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68221 + return -EACCES;
68222 +
68223 + return vfs_removexattr(path->dentry, kname);
68224 }
68225
68226 static int path_removexattr(const char __user *pathname,
68227 @@ -625,7 +652,7 @@ retry:
68228 return error;
68229 error = mnt_want_write(path.mnt);
68230 if (!error) {
68231 - error = removexattr(path.dentry, name);
68232 + error = removexattr(&path, name);
68233 mnt_drop_write(path.mnt);
68234 }
68235 path_put(&path);
68236 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68237 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68238 {
68239 struct fd f = fdget(fd);
68240 - struct dentry *dentry;
68241 + struct path *path;
68242 int error = -EBADF;
68243
68244 if (!f.file)
68245 return error;
68246 - dentry = f.file->f_path.dentry;
68247 - audit_inode(NULL, dentry, 0);
68248 + path = &f.file->f_path;
68249 + audit_inode(NULL, path->dentry, 0);
68250 error = mnt_want_write_file(f.file);
68251 if (!error) {
68252 - error = removexattr(dentry, name);
68253 + error = removexattr(path, name);
68254 mnt_drop_write_file(f.file);
68255 }
68256 fdput(f);
68257 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68258 index 79c9819..22226b4 100644
68259 --- a/fs/xfs/libxfs/xfs_bmap.c
68260 +++ b/fs/xfs/libxfs/xfs_bmap.c
68261 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68262
68263 #else
68264 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68265 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68266 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68267 #endif /* DEBUG */
68268
68269 /*
68270 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68271 index f1b69ed..3d0222f 100644
68272 --- a/fs/xfs/xfs_dir2_readdir.c
68273 +++ b/fs/xfs/xfs_dir2_readdir.c
68274 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68275 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68276 filetype = dp->d_ops->sf_get_ftype(sfep);
68277 ctx->pos = off & 0x7fffffff;
68278 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68279 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68280 + char name[sfep->namelen];
68281 + memcpy(name, sfep->name, sfep->namelen);
68282 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68283 + return 0;
68284 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68285 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68286 return 0;
68287 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68288 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68289 index 24c926b6..8726af88 100644
68290 --- a/fs/xfs/xfs_ioctl.c
68291 +++ b/fs/xfs/xfs_ioctl.c
68292 @@ -122,7 +122,7 @@ xfs_find_handle(
68293 }
68294
68295 error = -EFAULT;
68296 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68297 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68298 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68299 goto out_put;
68300
68301 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68302 index 6a51619..9592e1b 100644
68303 --- a/fs/xfs/xfs_linux.h
68304 +++ b/fs/xfs/xfs_linux.h
68305 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68306 * of the compiler which do not like us using do_div in the middle
68307 * of large functions.
68308 */
68309 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68310 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68311 {
68312 __u32 mod;
68313
68314 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68315 return 0;
68316 }
68317 #else
68318 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68319 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68320 {
68321 __u32 mod;
68322
68323 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68324 new file mode 100644
68325 index 0000000..31f8fe4
68326 --- /dev/null
68327 +++ b/grsecurity/Kconfig
68328 @@ -0,0 +1,1182 @@
68329 +#
68330 +# grecurity configuration
68331 +#
68332 +menu "Memory Protections"
68333 +depends on GRKERNSEC
68334 +
68335 +config GRKERNSEC_KMEM
68336 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68337 + default y if GRKERNSEC_CONFIG_AUTO
68338 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68339 + help
68340 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68341 + be written to or read from to modify or leak the contents of the running
68342 + kernel. /dev/port will also not be allowed to be opened, writing to
68343 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68344 + If you have module support disabled, enabling this will close up several
68345 + ways that are currently used to insert malicious code into the running
68346 + kernel.
68347 +
68348 + Even with this feature enabled, we still highly recommend that
68349 + you use the RBAC system, as it is still possible for an attacker to
68350 + modify the running kernel through other more obscure methods.
68351 +
68352 + It is highly recommended that you say Y here if you meet all the
68353 + conditions above.
68354 +
68355 +config GRKERNSEC_VM86
68356 + bool "Restrict VM86 mode"
68357 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68358 + depends on X86_32
68359 +
68360 + help
68361 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68362 + make use of a special execution mode on 32bit x86 processors called
68363 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68364 + video cards and will still work with this option enabled. The purpose
68365 + of the option is to prevent exploitation of emulation errors in
68366 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68367 + Nearly all users should be able to enable this option.
68368 +
68369 +config GRKERNSEC_IO
68370 + bool "Disable privileged I/O"
68371 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68372 + depends on X86
68373 + select RTC_CLASS
68374 + select RTC_INTF_DEV
68375 + select RTC_DRV_CMOS
68376 +
68377 + help
68378 + If you say Y here, all ioperm and iopl calls will return an error.
68379 + Ioperm and iopl can be used to modify the running kernel.
68380 + Unfortunately, some programs need this access to operate properly,
68381 + the most notable of which are XFree86 and hwclock. hwclock can be
68382 + remedied by having RTC support in the kernel, so real-time
68383 + clock support is enabled if this option is enabled, to ensure
68384 + that hwclock operates correctly. If hwclock still does not work,
68385 + either update udev or symlink /dev/rtc to /dev/rtc0.
68386 +
68387 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68388 + you may not be able to boot into a graphical environment with this
68389 + option enabled. In this case, you should use the RBAC system instead.
68390 +
68391 +config GRKERNSEC_BPF_HARDEN
68392 + bool "Harden BPF interpreter"
68393 + default y if GRKERNSEC_CONFIG_AUTO
68394 + help
68395 + Unlike previous versions of grsecurity that hardened both the BPF
68396 + interpreted code against corruption at rest as well as the JIT code
68397 + against JIT-spray attacks and attacker-controlled immediate values
68398 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68399 + and will ensure the interpreted code is read-only at rest. This feature
68400 + may be removed at a later time when eBPF stabilizes to entirely revert
68401 + back to the more secure pre-3.16 BPF interpreter/JIT.
68402 +
68403 + If you're using KERNEXEC, it's recommended that you enable this option
68404 + to supplement the hardening of the kernel.
68405 +
68406 +config GRKERNSEC_PERF_HARDEN
68407 + bool "Disable unprivileged PERF_EVENTS usage by default"
68408 + default y if GRKERNSEC_CONFIG_AUTO
68409 + depends on PERF_EVENTS
68410 + help
68411 + If you say Y here, the range of acceptable values for the
68412 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68413 + default to a new value: 3. When the sysctl is set to this value, no
68414 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68415 +
68416 + Though PERF_EVENTS can be used legitimately for performance monitoring
68417 + and low-level application profiling, it is forced on regardless of
68418 + configuration, has been at fault for several vulnerabilities, and
68419 + creates new opportunities for side channels and other information leaks.
68420 +
68421 + This feature puts PERF_EVENTS into a secure default state and permits
68422 + the administrator to change out of it temporarily if unprivileged
68423 + application profiling is needed.
68424 +
68425 +config GRKERNSEC_RAND_THREADSTACK
68426 + bool "Insert random gaps between thread stacks"
68427 + default y if GRKERNSEC_CONFIG_AUTO
68428 + depends on PAX_RANDMMAP && !PPC
68429 + help
68430 + If you say Y here, a random-sized gap will be enforced between allocated
68431 + thread stacks. Glibc's NPTL and other threading libraries that
68432 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68433 + The implementation currently provides 8 bits of entropy for the gap.
68434 +
68435 + Many distributions do not compile threaded remote services with the
68436 + -fstack-check argument to GCC, causing the variable-sized stack-based
68437 + allocator, alloca(), to not probe the stack on allocation. This
68438 + permits an unbounded alloca() to skip over any guard page and potentially
68439 + modify another thread's stack reliably. An enforced random gap
68440 + reduces the reliability of such an attack and increases the chance
68441 + that such a read/write to another thread's stack instead lands in
68442 + an unmapped area, causing a crash and triggering grsecurity's
68443 + anti-bruteforcing logic.
68444 +
68445 +config GRKERNSEC_PROC_MEMMAP
68446 + bool "Harden ASLR against information leaks and entropy reduction"
68447 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68448 + depends on PAX_NOEXEC || PAX_ASLR
68449 + help
68450 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68451 + give no information about the addresses of its mappings if
68452 + PaX features that rely on random addresses are enabled on the task.
68453 + In addition to sanitizing this information and disabling other
68454 + dangerous sources of information, this option causes reads of sensitive
68455 + /proc/<pid> entries where the file descriptor was opened in a different
68456 + task than the one performing the read. Such attempts are logged.
68457 + This option also limits argv/env strings for suid/sgid binaries
68458 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68459 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68460 + binaries to prevent alternative mmap layouts from being abused.
68461 +
68462 + If you use PaX it is essential that you say Y here as it closes up
68463 + several holes that make full ASLR useless locally.
68464 +
68465 +
68466 +config GRKERNSEC_KSTACKOVERFLOW
68467 + bool "Prevent kernel stack overflows"
68468 + default y if GRKERNSEC_CONFIG_AUTO
68469 + depends on !IA64 && 64BIT
68470 + help
68471 + If you say Y here, the kernel's process stacks will be allocated
68472 + with vmalloc instead of the kernel's default allocator. This
68473 + introduces guard pages that in combination with the alloca checking
68474 + of the STACKLEAK feature prevents all forms of kernel process stack
68475 + overflow abuse. Note that this is different from kernel stack
68476 + buffer overflows.
68477 +
68478 +config GRKERNSEC_BRUTE
68479 + bool "Deter exploit bruteforcing"
68480 + default y if GRKERNSEC_CONFIG_AUTO
68481 + help
68482 + If you say Y here, attempts to bruteforce exploits against forking
68483 + daemons such as apache or sshd, as well as against suid/sgid binaries
68484 + will be deterred. When a child of a forking daemon is killed by PaX
68485 + or crashes due to an illegal instruction or other suspicious signal,
68486 + the parent process will be delayed 30 seconds upon every subsequent
68487 + fork until the administrator is able to assess the situation and
68488 + restart the daemon.
68489 + In the suid/sgid case, the attempt is logged, the user has all their
68490 + existing instances of the suid/sgid binary terminated and will
68491 + be unable to execute any suid/sgid binaries for 15 minutes.
68492 +
68493 + It is recommended that you also enable signal logging in the auditing
68494 + section so that logs are generated when a process triggers a suspicious
68495 + signal.
68496 + If the sysctl option is enabled, a sysctl option with name
68497 + "deter_bruteforce" is created.
68498 +
68499 +config GRKERNSEC_MODHARDEN
68500 + bool "Harden module auto-loading"
68501 + default y if GRKERNSEC_CONFIG_AUTO
68502 + depends on MODULES
68503 + help
68504 + If you say Y here, module auto-loading in response to use of some
68505 + feature implemented by an unloaded module will be restricted to
68506 + root users. Enabling this option helps defend against attacks
68507 + by unprivileged users who abuse the auto-loading behavior to
68508 + cause a vulnerable module to load that is then exploited.
68509 +
68510 + If this option prevents a legitimate use of auto-loading for a
68511 + non-root user, the administrator can execute modprobe manually
68512 + with the exact name of the module mentioned in the alert log.
68513 + Alternatively, the administrator can add the module to the list
68514 + of modules loaded at boot by modifying init scripts.
68515 +
68516 + Modification of init scripts will most likely be needed on
68517 + Ubuntu servers with encrypted home directory support enabled,
68518 + as the first non-root user logging in will cause the ecb(aes),
68519 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68520 +
68521 +config GRKERNSEC_HIDESYM
68522 + bool "Hide kernel symbols"
68523 + default y if GRKERNSEC_CONFIG_AUTO
68524 + select PAX_USERCOPY_SLABS
68525 + help
68526 + If you say Y here, getting information on loaded modules, and
68527 + displaying all kernel symbols through a syscall will be restricted
68528 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68529 + /proc/kallsyms will be restricted to the root user. The RBAC
68530 + system can hide that entry even from root.
68531 +
68532 + This option also prevents leaking of kernel addresses through
68533 + several /proc entries.
68534 +
68535 + Note that this option is only effective provided the following
68536 + conditions are met:
68537 + 1) The kernel using grsecurity is not precompiled by some distribution
68538 + 2) You have also enabled GRKERNSEC_DMESG
68539 + 3) You are using the RBAC system and hiding other files such as your
68540 + kernel image and System.map. Alternatively, enabling this option
68541 + causes the permissions on /boot, /lib/modules, and the kernel
68542 + source directory to change at compile time to prevent
68543 + reading by non-root users.
68544 + If the above conditions are met, this option will aid in providing a
68545 + useful protection against local kernel exploitation of overflows
68546 + and arbitrary read/write vulnerabilities.
68547 +
68548 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68549 + in addition to this feature.
68550 +
68551 +config GRKERNSEC_RANDSTRUCT
68552 + bool "Randomize layout of sensitive kernel structures"
68553 + default y if GRKERNSEC_CONFIG_AUTO
68554 + select GRKERNSEC_HIDESYM
68555 + select MODVERSIONS if MODULES
68556 + help
68557 + If you say Y here, the layouts of a number of sensitive kernel
68558 + structures (task, fs, cred, etc) and all structures composed entirely
68559 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68560 + This can introduce the requirement of an additional infoleak
68561 + vulnerability for exploits targeting these structure types.
68562 +
68563 + Enabling this feature will introduce some performance impact, slightly
68564 + increase memory usage, and prevent the use of forensic tools like
68565 + Volatility against the system (unless the kernel source tree isn't
68566 + cleaned after kernel installation).
68567 +
68568 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68569 + It remains after a make clean to allow for external modules to be compiled
68570 + with the existing seed and will be removed by a make mrproper or
68571 + make distclean.
68572 +
68573 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68574 + to install the supporting headers explicitly in addition to the normal
68575 + gcc package.
68576 +
68577 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68578 + bool "Use cacheline-aware structure randomization"
68579 + depends on GRKERNSEC_RANDSTRUCT
68580 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68581 + help
68582 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68583 + at restricting randomization to cacheline-sized groups of elements. It
68584 + will further not randomize bitfields in structures. This reduces the
68585 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68586 +
68587 +config GRKERNSEC_KERN_LOCKOUT
68588 + bool "Active kernel exploit response"
68589 + default y if GRKERNSEC_CONFIG_AUTO
68590 + depends on X86 || ARM || PPC || SPARC
68591 + help
68592 + If you say Y here, when a PaX alert is triggered due to suspicious
68593 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68594 + or an OOPS occurs due to bad memory accesses, instead of just
68595 + terminating the offending process (and potentially allowing
68596 + a subsequent exploit from the same user), we will take one of two
68597 + actions:
68598 + If the user was root, we will panic the system
68599 + If the user was non-root, we will log the attempt, terminate
68600 + all processes owned by the user, then prevent them from creating
68601 + any new processes until the system is restarted
68602 + This deters repeated kernel exploitation/bruteforcing attempts
68603 + and is useful for later forensics.
68604 +
68605 +config GRKERNSEC_OLD_ARM_USERLAND
68606 + bool "Old ARM userland compatibility"
68607 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68608 + help
68609 + If you say Y here, stubs of executable code to perform such operations
68610 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68611 + table. This is unfortunately needed for old ARM userland meant to run
68612 + across a wide range of processors. Without this option enabled,
68613 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68614 + which is enough for Linaro userlands or other userlands designed for v6
68615 + and newer ARM CPUs. It's recommended that you try without this option enabled
68616 + first, and only enable it if your userland does not boot (it will likely fail
68617 + at init time).
68618 +
68619 +endmenu
68620 +menu "Role Based Access Control Options"
68621 +depends on GRKERNSEC
68622 +
68623 +config GRKERNSEC_RBAC_DEBUG
68624 + bool
68625 +
68626 +config GRKERNSEC_NO_RBAC
68627 + bool "Disable RBAC system"
68628 + help
68629 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68630 + preventing the RBAC system from being enabled. You should only say Y
68631 + here if you have no intention of using the RBAC system, so as to prevent
68632 + an attacker with root access from misusing the RBAC system to hide files
68633 + and processes when loadable module support and /dev/[k]mem have been
68634 + locked down.
68635 +
68636 +config GRKERNSEC_ACL_HIDEKERN
68637 + bool "Hide kernel processes"
68638 + help
68639 + If you say Y here, all kernel threads will be hidden to all
68640 + processes but those whose subject has the "view hidden processes"
68641 + flag.
68642 +
68643 +config GRKERNSEC_ACL_MAXTRIES
68644 + int "Maximum tries before password lockout"
68645 + default 3
68646 + help
68647 + This option enforces the maximum number of times a user can attempt
68648 + to authorize themselves with the grsecurity RBAC system before being
68649 + denied the ability to attempt authorization again for a specified time.
68650 + The lower the number, the harder it will be to brute-force a password.
68651 +
68652 +config GRKERNSEC_ACL_TIMEOUT
68653 + int "Time to wait after max password tries, in seconds"
68654 + default 30
68655 + help
68656 + This option specifies the time the user must wait after attempting to
68657 + authorize to the RBAC system with the maximum number of invalid
68658 + passwords. The higher the number, the harder it will be to brute-force
68659 + a password.
68660 +
68661 +endmenu
68662 +menu "Filesystem Protections"
68663 +depends on GRKERNSEC
68664 +
68665 +config GRKERNSEC_PROC
68666 + bool "Proc restrictions"
68667 + default y if GRKERNSEC_CONFIG_AUTO
68668 + help
68669 + If you say Y here, the permissions of the /proc filesystem
68670 + will be altered to enhance system security and privacy. You MUST
68671 + choose either a user only restriction or a user and group restriction.
68672 + Depending upon the option you choose, you can either restrict users to
68673 + see only the processes they themselves run, or choose a group that can
68674 + view all processes and files normally restricted to root if you choose
68675 + the "restrict to user only" option. NOTE: If you're running identd or
68676 + ntpd as a non-root user, you will have to run it as the group you
68677 + specify here.
68678 +
68679 +config GRKERNSEC_PROC_USER
68680 + bool "Restrict /proc to user only"
68681 + depends on GRKERNSEC_PROC
68682 + help
68683 + If you say Y here, non-root users will only be able to view their own
68684 + processes, and restricts them from viewing network-related information,
68685 + and viewing kernel symbol and module information.
68686 +
68687 +config GRKERNSEC_PROC_USERGROUP
68688 + bool "Allow special group"
68689 + default y if GRKERNSEC_CONFIG_AUTO
68690 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68691 + help
68692 + If you say Y here, you will be able to select a group that will be
68693 + able to view all processes and network-related information. If you've
68694 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68695 + remain hidden. This option is useful if you want to run identd as
68696 + a non-root user. The group you select may also be chosen at boot time
68697 + via "grsec_proc_gid=" on the kernel commandline.
68698 +
68699 +config GRKERNSEC_PROC_GID
68700 + int "GID for special group"
68701 + depends on GRKERNSEC_PROC_USERGROUP
68702 + default 1001
68703 +
68704 +config GRKERNSEC_PROC_ADD
68705 + bool "Additional restrictions"
68706 + default y if GRKERNSEC_CONFIG_AUTO
68707 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68708 + help
68709 + If you say Y here, additional restrictions will be placed on
68710 + /proc that keep normal users from viewing device information and
68711 + slabinfo information that could be useful for exploits.
68712 +
68713 +config GRKERNSEC_LINK
68714 + bool "Linking restrictions"
68715 + default y if GRKERNSEC_CONFIG_AUTO
68716 + help
68717 + If you say Y here, /tmp race exploits will be prevented, since users
68718 + will no longer be able to follow symlinks owned by other users in
68719 + world-writable +t directories (e.g. /tmp), unless the owner of the
68720 + symlink is the owner of the directory. users will also not be
68721 + able to hardlink to files they do not own. If the sysctl option is
68722 + enabled, a sysctl option with name "linking_restrictions" is created.
68723 +
68724 +config GRKERNSEC_SYMLINKOWN
68725 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68726 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68727 + help
68728 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68729 + that prevents it from being used as a security feature. As Apache
68730 + verifies the symlink by performing a stat() against the target of
68731 + the symlink before it is followed, an attacker can setup a symlink
68732 + to point to a same-owned file, then replace the symlink with one
68733 + that targets another user's file just after Apache "validates" the
68734 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68735 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68736 + will be in place for the group you specify. If the sysctl option
68737 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68738 + created.
68739 +
68740 +config GRKERNSEC_SYMLINKOWN_GID
68741 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68742 + depends on GRKERNSEC_SYMLINKOWN
68743 + default 1006
68744 + help
68745 + Setting this GID determines what group kernel-enforced
68746 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68747 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68748 +
68749 +config GRKERNSEC_FIFO
68750 + bool "FIFO restrictions"
68751 + default y if GRKERNSEC_CONFIG_AUTO
68752 + help
68753 + If you say Y here, users will not be able to write to FIFOs they don't
68754 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68755 + the FIFO is the same owner of the directory it's held in. If the sysctl
68756 + option is enabled, a sysctl option with name "fifo_restrictions" is
68757 + created.
68758 +
68759 +config GRKERNSEC_SYSFS_RESTRICT
68760 + bool "Sysfs/debugfs restriction"
68761 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68762 + depends on SYSFS
68763 + help
68764 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68765 + any filesystem normally mounted under it (e.g. debugfs) will be
68766 + mostly accessible only by root. These filesystems generally provide access
68767 + to hardware and debug information that isn't appropriate for unprivileged
68768 + users of the system. Sysfs and debugfs have also become a large source
68769 + of new vulnerabilities, ranging from infoleaks to local compromise.
68770 + There has been very little oversight with an eye toward security involved
68771 + in adding new exporters of information to these filesystems, so their
68772 + use is discouraged.
68773 + For reasons of compatibility, a few directories have been whitelisted
68774 + for access by non-root users:
68775 + /sys/fs/selinux
68776 + /sys/fs/fuse
68777 + /sys/devices/system/cpu
68778 +
68779 +config GRKERNSEC_ROFS
68780 + bool "Runtime read-only mount protection"
68781 + depends on SYSCTL
68782 + help
68783 + If you say Y here, a sysctl option with name "romount_protect" will
68784 + be created. By setting this option to 1 at runtime, filesystems
68785 + will be protected in the following ways:
68786 + * No new writable mounts will be allowed
68787 + * Existing read-only mounts won't be able to be remounted read/write
68788 + * Write operations will be denied on all block devices
68789 + This option acts independently of grsec_lock: once it is set to 1,
68790 + it cannot be turned off. Therefore, please be mindful of the resulting
68791 + behavior if this option is enabled in an init script on a read-only
68792 + filesystem.
68793 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68794 + and GRKERNSEC_IO should be enabled and module loading disabled via
68795 + config or at runtime.
68796 + This feature is mainly intended for secure embedded systems.
68797 +
68798 +
68799 +config GRKERNSEC_DEVICE_SIDECHANNEL
68800 + bool "Eliminate stat/notify-based device sidechannels"
68801 + default y if GRKERNSEC_CONFIG_AUTO
68802 + help
68803 + If you say Y here, timing analyses on block or character
68804 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68805 + will be thwarted for unprivileged users. If a process without
68806 + CAP_MKNOD stats such a device, the last access and last modify times
68807 + will match the device's create time. No access or modify events
68808 + will be triggered through inotify/dnotify/fanotify for such devices.
68809 + This feature will prevent attacks that may at a minimum
68810 + allow an attacker to determine the administrator's password length.
68811 +
68812 +config GRKERNSEC_CHROOT
68813 + bool "Chroot jail restrictions"
68814 + default y if GRKERNSEC_CONFIG_AUTO
68815 + help
68816 + If you say Y here, you will be able to choose several options that will
68817 + make breaking out of a chrooted jail much more difficult. If you
68818 + encounter no software incompatibilities with the following options, it
68819 + is recommended that you enable each one.
68820 +
68821 + Note that the chroot restrictions are not intended to apply to "chroots"
68822 + to directories that are simple bind mounts of the global root filesystem.
68823 + For several other reasons, a user shouldn't expect any significant
68824 + security by performing such a chroot.
68825 +
68826 +config GRKERNSEC_CHROOT_MOUNT
68827 + bool "Deny mounts"
68828 + default y if GRKERNSEC_CONFIG_AUTO
68829 + depends on GRKERNSEC_CHROOT
68830 + help
68831 + If you say Y here, processes inside a chroot will not be able to
68832 + mount or remount filesystems. If the sysctl option is enabled, a
68833 + sysctl option with name "chroot_deny_mount" is created.
68834 +
68835 +config GRKERNSEC_CHROOT_DOUBLE
68836 + bool "Deny double-chroots"
68837 + default y if GRKERNSEC_CONFIG_AUTO
68838 + depends on GRKERNSEC_CHROOT
68839 + help
68840 + If you say Y here, processes inside a chroot will not be able to chroot
68841 + again outside the chroot. This is a widely used method of breaking
68842 + out of a chroot jail and should not be allowed. If the sysctl
68843 + option is enabled, a sysctl option with name
68844 + "chroot_deny_chroot" is created.
68845 +
68846 +config GRKERNSEC_CHROOT_PIVOT
68847 + bool "Deny pivot_root in chroot"
68848 + default y if GRKERNSEC_CONFIG_AUTO
68849 + depends on GRKERNSEC_CHROOT
68850 + help
68851 + If you say Y here, processes inside a chroot will not be able to use
68852 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68853 + works similar to chroot in that it changes the root filesystem. This
68854 + function could be misused in a chrooted process to attempt to break out
68855 + of the chroot, and therefore should not be allowed. If the sysctl
68856 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68857 + created.
68858 +
68859 +config GRKERNSEC_CHROOT_CHDIR
68860 + bool "Enforce chdir(\"/\") on all chroots"
68861 + default y if GRKERNSEC_CONFIG_AUTO
68862 + depends on GRKERNSEC_CHROOT
68863 + help
68864 + If you say Y here, the current working directory of all newly-chrooted
68865 + applications will be set to the the root directory of the chroot.
68866 + The man page on chroot(2) states:
68867 + Note that this call does not change the current working
68868 + directory, so that `.' can be outside the tree rooted at
68869 + `/'. In particular, the super-user can escape from a
68870 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68871 +
68872 + It is recommended that you say Y here, since it's not known to break
68873 + any software. If the sysctl option is enabled, a sysctl option with
68874 + name "chroot_enforce_chdir" is created.
68875 +
68876 +config GRKERNSEC_CHROOT_CHMOD
68877 + bool "Deny (f)chmod +s"
68878 + default y if GRKERNSEC_CONFIG_AUTO
68879 + depends on GRKERNSEC_CHROOT
68880 + help
68881 + If you say Y here, processes inside a chroot will not be able to chmod
68882 + or fchmod files to make them have suid or sgid bits. This protects
68883 + against another published method of breaking a chroot. If the sysctl
68884 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68885 + created.
68886 +
68887 +config GRKERNSEC_CHROOT_FCHDIR
68888 + bool "Deny fchdir and fhandle out of chroot"
68889 + default y if GRKERNSEC_CONFIG_AUTO
68890 + depends on GRKERNSEC_CHROOT
68891 + help
68892 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68893 + to a file descriptor of the chrooting process that points to a directory
68894 + outside the filesystem will be stopped. Additionally, this option prevents
68895 + use of the recently-created syscall for opening files by a guessable "file
68896 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68897 + with name "chroot_deny_fchdir" is created.
68898 +
68899 +config GRKERNSEC_CHROOT_MKNOD
68900 + bool "Deny mknod"
68901 + default y if GRKERNSEC_CONFIG_AUTO
68902 + depends on GRKERNSEC_CHROOT
68903 + help
68904 + If you say Y here, processes inside a chroot will not be allowed to
68905 + mknod. The problem with using mknod inside a chroot is that it
68906 + would allow an attacker to create a device entry that is the same
68907 + as one on the physical root of your system, which could range from
68908 + anything from the console device to a device for your harddrive (which
68909 + they could then use to wipe the drive or steal data). It is recommended
68910 + that you say Y here, unless you run into software incompatibilities.
68911 + If the sysctl option is enabled, a sysctl option with name
68912 + "chroot_deny_mknod" is created.
68913 +
68914 +config GRKERNSEC_CHROOT_SHMAT
68915 + bool "Deny shmat() out of chroot"
68916 + default y if GRKERNSEC_CONFIG_AUTO
68917 + depends on GRKERNSEC_CHROOT
68918 + help
68919 + If you say Y here, processes inside a chroot will not be able to attach
68920 + to shared memory segments that were created outside of the chroot jail.
68921 + It is recommended that you say Y here. If the sysctl option is enabled,
68922 + a sysctl option with name "chroot_deny_shmat" is created.
68923 +
68924 +config GRKERNSEC_CHROOT_UNIX
68925 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68926 + default y if GRKERNSEC_CONFIG_AUTO
68927 + depends on GRKERNSEC_CHROOT
68928 + help
68929 + If you say Y here, processes inside a chroot will not be able to
68930 + connect to abstract (meaning not belonging to a filesystem) Unix
68931 + domain sockets that were bound outside of a chroot. It is recommended
68932 + that you say Y here. If the sysctl option is enabled, a sysctl option
68933 + with name "chroot_deny_unix" is created.
68934 +
68935 +config GRKERNSEC_CHROOT_FINDTASK
68936 + bool "Protect outside processes"
68937 + default y if GRKERNSEC_CONFIG_AUTO
68938 + depends on GRKERNSEC_CHROOT
68939 + help
68940 + If you say Y here, processes inside a chroot will not be able to
68941 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68942 + getsid, or view any process outside of the chroot. If the sysctl
68943 + option is enabled, a sysctl option with name "chroot_findtask" is
68944 + created.
68945 +
68946 +config GRKERNSEC_CHROOT_NICE
68947 + bool "Restrict priority changes"
68948 + default y if GRKERNSEC_CONFIG_AUTO
68949 + depends on GRKERNSEC_CHROOT
68950 + help
68951 + If you say Y here, processes inside a chroot will not be able to raise
68952 + the priority of processes in the chroot, or alter the priority of
68953 + processes outside the chroot. This provides more security than simply
68954 + removing CAP_SYS_NICE from the process' capability set. If the
68955 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68956 + is created.
68957 +
68958 +config GRKERNSEC_CHROOT_SYSCTL
68959 + bool "Deny sysctl writes"
68960 + default y if GRKERNSEC_CONFIG_AUTO
68961 + depends on GRKERNSEC_CHROOT
68962 + help
68963 + If you say Y here, an attacker in a chroot will not be able to
68964 + write to sysctl entries, either by sysctl(2) or through a /proc
68965 + interface. It is strongly recommended that you say Y here. If the
68966 + sysctl option is enabled, a sysctl option with name
68967 + "chroot_deny_sysctl" is created.
68968 +
68969 +config GRKERNSEC_CHROOT_RENAME
68970 + bool "Deny bad renames"
68971 + default y if GRKERNSEC_CONFIG_AUTO
68972 + depends on GRKERNSEC_CHROOT
68973 + help
68974 + If you say Y here, an attacker in a chroot will not be able to
68975 + abuse the ability to create double chroots to break out of the
68976 + chroot by exploiting a race condition between a rename of a directory
68977 + within a chroot against an open of a symlink with relative path
68978 + components. This feature will likewise prevent an accomplice outside
68979 + a chroot from enabling a user inside the chroot to break out and make
68980 + use of their credentials on the global filesystem. Enabling this
68981 + feature is essential to prevent root users from breaking out of a
68982 + chroot. If the sysctl option is enabled, a sysctl option with name
68983 + "chroot_deny_bad_rename" is created.
68984 +
68985 +config GRKERNSEC_CHROOT_CAPS
68986 + bool "Capability restrictions"
68987 + default y if GRKERNSEC_CONFIG_AUTO
68988 + depends on GRKERNSEC_CHROOT
68989 + help
68990 + If you say Y here, the capabilities on all processes within a
68991 + chroot jail will be lowered to stop module insertion, raw i/o,
68992 + system and net admin tasks, rebooting the system, modifying immutable
68993 + files, modifying IPC owned by another, and changing the system time.
68994 + This is left an option because it can break some apps. Disable this
68995 + if your chrooted apps are having problems performing those kinds of
68996 + tasks. If the sysctl option is enabled, a sysctl option with
68997 + name "chroot_caps" is created.
68998 +
68999 +config GRKERNSEC_CHROOT_INITRD
69000 + bool "Exempt initrd tasks from restrictions"
69001 + default y if GRKERNSEC_CONFIG_AUTO
69002 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69003 + help
69004 + If you say Y here, tasks started prior to init will be exempted from
69005 + grsecurity's chroot restrictions. This option is mainly meant to
69006 + resolve Plymouth's performing privileged operations unnecessarily
69007 + in a chroot.
69008 +
69009 +endmenu
69010 +menu "Kernel Auditing"
69011 +depends on GRKERNSEC
69012 +
69013 +config GRKERNSEC_AUDIT_GROUP
69014 + bool "Single group for auditing"
69015 + help
69016 + If you say Y here, the exec and chdir logging features will only operate
69017 + on a group you specify. This option is recommended if you only want to
69018 + watch certain users instead of having a large amount of logs from the
69019 + entire system. If the sysctl option is enabled, a sysctl option with
69020 + name "audit_group" is created.
69021 +
69022 +config GRKERNSEC_AUDIT_GID
69023 + int "GID for auditing"
69024 + depends on GRKERNSEC_AUDIT_GROUP
69025 + default 1007
69026 +
69027 +config GRKERNSEC_EXECLOG
69028 + bool "Exec logging"
69029 + help
69030 + If you say Y here, all execve() calls will be logged (since the
69031 + other exec*() calls are frontends to execve(), all execution
69032 + will be logged). Useful for shell-servers that like to keep track
69033 + of their users. If the sysctl option is enabled, a sysctl option with
69034 + name "exec_logging" is created.
69035 + WARNING: This option when enabled will produce a LOT of logs, especially
69036 + on an active system.
69037 +
69038 +config GRKERNSEC_RESLOG
69039 + bool "Resource logging"
69040 + default y if GRKERNSEC_CONFIG_AUTO
69041 + help
69042 + If you say Y here, all attempts to overstep resource limits will
69043 + be logged with the resource name, the requested size, and the current
69044 + limit. It is highly recommended that you say Y here. If the sysctl
69045 + option is enabled, a sysctl option with name "resource_logging" is
69046 + created. If the RBAC system is enabled, the sysctl value is ignored.
69047 +
69048 +config GRKERNSEC_CHROOT_EXECLOG
69049 + bool "Log execs within chroot"
69050 + help
69051 + If you say Y here, all executions inside a chroot jail will be logged
69052 + to syslog. This can cause a large amount of logs if certain
69053 + applications (eg. djb's daemontools) are installed on the system, and
69054 + is therefore left as an option. If the sysctl option is enabled, a
69055 + sysctl option with name "chroot_execlog" is created.
69056 +
69057 +config GRKERNSEC_AUDIT_PTRACE
69058 + bool "Ptrace logging"
69059 + help
69060 + If you say Y here, all attempts to attach to a process via ptrace
69061 + will be logged. If the sysctl option is enabled, a sysctl option
69062 + with name "audit_ptrace" is created.
69063 +
69064 +config GRKERNSEC_AUDIT_CHDIR
69065 + bool "Chdir logging"
69066 + help
69067 + If you say Y here, all chdir() calls will be logged. If the sysctl
69068 + option is enabled, a sysctl option with name "audit_chdir" is created.
69069 +
69070 +config GRKERNSEC_AUDIT_MOUNT
69071 + bool "(Un)Mount logging"
69072 + help
69073 + If you say Y here, all mounts and unmounts will be logged. If the
69074 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69075 + created.
69076 +
69077 +config GRKERNSEC_SIGNAL
69078 + bool "Signal logging"
69079 + default y if GRKERNSEC_CONFIG_AUTO
69080 + help
69081 + If you say Y here, certain important signals will be logged, such as
69082 + SIGSEGV, which will as a result inform you of when a error in a program
69083 + occurred, which in some cases could mean a possible exploit attempt.
69084 + If the sysctl option is enabled, a sysctl option with name
69085 + "signal_logging" is created.
69086 +
69087 +config GRKERNSEC_FORKFAIL
69088 + bool "Fork failure logging"
69089 + help
69090 + If you say Y here, all failed fork() attempts will be logged.
69091 + This could suggest a fork bomb, or someone attempting to overstep
69092 + their process limit. If the sysctl option is enabled, a sysctl option
69093 + with name "forkfail_logging" is created.
69094 +
69095 +config GRKERNSEC_TIME
69096 + bool "Time change logging"
69097 + default y if GRKERNSEC_CONFIG_AUTO
69098 + help
69099 + If you say Y here, any changes of the system clock will be logged.
69100 + If the sysctl option is enabled, a sysctl option with name
69101 + "timechange_logging" is created.
69102 +
69103 +config GRKERNSEC_PROC_IPADDR
69104 + bool "/proc/<pid>/ipaddr support"
69105 + default y if GRKERNSEC_CONFIG_AUTO
69106 + help
69107 + If you say Y here, a new entry will be added to each /proc/<pid>
69108 + directory that contains the IP address of the person using the task.
69109 + The IP is carried across local TCP and AF_UNIX stream sockets.
69110 + This information can be useful for IDS/IPSes to perform remote response
69111 + to a local attack. The entry is readable by only the owner of the
69112 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69113 + the RBAC system), and thus does not create privacy concerns.
69114 +
69115 +config GRKERNSEC_RWXMAP_LOG
69116 + bool 'Denied RWX mmap/mprotect logging'
69117 + default y if GRKERNSEC_CONFIG_AUTO
69118 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69119 + help
69120 + If you say Y here, calls to mmap() and mprotect() with explicit
69121 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69122 + denied by the PAX_MPROTECT feature. This feature will also
69123 + log other problematic scenarios that can occur when PAX_MPROTECT
69124 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69125 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69126 + is created.
69127 +
69128 +endmenu
69129 +
69130 +menu "Executable Protections"
69131 +depends on GRKERNSEC
69132 +
69133 +config GRKERNSEC_DMESG
69134 + bool "Dmesg(8) restriction"
69135 + default y if GRKERNSEC_CONFIG_AUTO
69136 + help
69137 + If you say Y here, non-root users will not be able to use dmesg(8)
69138 + to view the contents of the kernel's circular log buffer.
69139 + The kernel's log buffer often contains kernel addresses and other
69140 + identifying information useful to an attacker in fingerprinting a
69141 + system for a targeted exploit.
69142 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69143 + created.
69144 +
69145 +config GRKERNSEC_HARDEN_PTRACE
69146 + bool "Deter ptrace-based process snooping"
69147 + default y if GRKERNSEC_CONFIG_AUTO
69148 + help
69149 + If you say Y here, TTY sniffers and other malicious monitoring
69150 + programs implemented through ptrace will be defeated. If you
69151 + have been using the RBAC system, this option has already been
69152 + enabled for several years for all users, with the ability to make
69153 + fine-grained exceptions.
69154 +
69155 + This option only affects the ability of non-root users to ptrace
69156 + processes that are not a descendent of the ptracing process.
69157 + This means that strace ./binary and gdb ./binary will still work,
69158 + but attaching to arbitrary processes will not. If the sysctl
69159 + option is enabled, a sysctl option with name "harden_ptrace" is
69160 + created.
69161 +
69162 +config GRKERNSEC_PTRACE_READEXEC
69163 + bool "Require read access to ptrace sensitive binaries"
69164 + default y if GRKERNSEC_CONFIG_AUTO
69165 + help
69166 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69167 + binaries. This option is useful in environments that
69168 + remove the read bits (e.g. file mode 4711) from suid binaries to
69169 + prevent infoleaking of their contents. This option adds
69170 + consistency to the use of that file mode, as the binary could normally
69171 + be read out when run without privileges while ptracing.
69172 +
69173 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69174 + is created.
69175 +
69176 +config GRKERNSEC_SETXID
69177 + bool "Enforce consistent multithreaded privileges"
69178 + default y if GRKERNSEC_CONFIG_AUTO
69179 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69180 + help
69181 + If you say Y here, a change from a root uid to a non-root uid
69182 + in a multithreaded application will cause the resulting uids,
69183 + gids, supplementary groups, and capabilities in that thread
69184 + to be propagated to the other threads of the process. In most
69185 + cases this is unnecessary, as glibc will emulate this behavior
69186 + on behalf of the application. Other libcs do not act in the
69187 + same way, allowing the other threads of the process to continue
69188 + running with root privileges. If the sysctl option is enabled,
69189 + a sysctl option with name "consistent_setxid" is created.
69190 +
69191 +config GRKERNSEC_HARDEN_IPC
69192 + bool "Disallow access to overly-permissive IPC objects"
69193 + default y if GRKERNSEC_CONFIG_AUTO
69194 + depends on SYSVIPC
69195 + help
69196 + If you say Y here, access to overly-permissive IPC objects (shared
69197 + memory, message queues, and semaphores) will be denied for processes
69198 + given the following criteria beyond normal permission checks:
69199 + 1) If the IPC object is world-accessible and the euid doesn't match
69200 + that of the creator or current uid for the IPC object
69201 + 2) If the IPC object is group-accessible and the egid doesn't
69202 + match that of the creator or current gid for the IPC object
69203 + It's a common error to grant too much permission to these objects,
69204 + with impact ranging from denial of service and information leaking to
69205 + privilege escalation. This feature was developed in response to
69206 + research by Tim Brown:
69207 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69208 + who found hundreds of such insecure usages. Processes with
69209 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69210 + If the sysctl option is enabled, a sysctl option with name
69211 + "harden_ipc" is created.
69212 +
69213 +config GRKERNSEC_TPE
69214 + bool "Trusted Path Execution (TPE)"
69215 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69216 + help
69217 + If you say Y here, you will be able to choose a gid to add to the
69218 + supplementary groups of users you want to mark as "untrusted."
69219 + These users will not be able to execute any files that are not in
69220 + root-owned directories writable only by root. If the sysctl option
69221 + is enabled, a sysctl option with name "tpe" is created.
69222 +
69223 +config GRKERNSEC_TPE_ALL
69224 + bool "Partially restrict all non-root users"
69225 + depends on GRKERNSEC_TPE
69226 + help
69227 + If you say Y here, all non-root users will be covered under
69228 + a weaker TPE restriction. This is separate from, and in addition to,
69229 + the main TPE options that you have selected elsewhere. Thus, if a
69230 + "trusted" GID is chosen, this restriction applies to even that GID.
69231 + Under this restriction, all non-root users will only be allowed to
69232 + execute files in directories they own that are not group or
69233 + world-writable, or in directories owned by root and writable only by
69234 + root. If the sysctl option is enabled, a sysctl option with name
69235 + "tpe_restrict_all" is created.
69236 +
69237 +config GRKERNSEC_TPE_INVERT
69238 + bool "Invert GID option"
69239 + depends on GRKERNSEC_TPE
69240 + help
69241 + If you say Y here, the group you specify in the TPE configuration will
69242 + decide what group TPE restrictions will be *disabled* for. This
69243 + option is useful if you want TPE restrictions to be applied to most
69244 + users on the system. If the sysctl option is enabled, a sysctl option
69245 + with name "tpe_invert" is created. Unlike other sysctl options, this
69246 + entry will default to on for backward-compatibility.
69247 +
69248 +config GRKERNSEC_TPE_GID
69249 + int
69250 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69251 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69252 +
69253 +config GRKERNSEC_TPE_UNTRUSTED_GID
69254 + int "GID for TPE-untrusted users"
69255 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69256 + default 1005
69257 + help
69258 + Setting this GID determines what group TPE restrictions will be
69259 + *enabled* for. If the sysctl option is enabled, a sysctl option
69260 + with name "tpe_gid" is created.
69261 +
69262 +config GRKERNSEC_TPE_TRUSTED_GID
69263 + int "GID for TPE-trusted users"
69264 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69265 + default 1005
69266 + help
69267 + Setting this GID determines what group TPE restrictions will be
69268 + *disabled* for. If the sysctl option is enabled, a sysctl option
69269 + with name "tpe_gid" is created.
69270 +
69271 +endmenu
69272 +menu "Network Protections"
69273 +depends on GRKERNSEC
69274 +
69275 +config GRKERNSEC_BLACKHOLE
69276 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69277 + default y if GRKERNSEC_CONFIG_AUTO
69278 + depends on NET
69279 + help
69280 + If you say Y here, neither TCP resets nor ICMP
69281 + destination-unreachable packets will be sent in response to packets
69282 + sent to ports for which no associated listening process exists.
69283 + It will also prevent the sending of ICMP protocol unreachable packets
69284 + in response to packets with unknown protocols.
69285 + This feature supports both IPV4 and IPV6 and exempts the
69286 + loopback interface from blackholing. Enabling this feature
69287 + makes a host more resilient to DoS attacks and reduces network
69288 + visibility against scanners.
69289 +
69290 + The blackhole feature as-implemented is equivalent to the FreeBSD
69291 + blackhole feature, as it prevents RST responses to all packets, not
69292 + just SYNs. Under most application behavior this causes no
69293 + problems, but applications (like haproxy) may not close certain
69294 + connections in a way that cleanly terminates them on the remote
69295 + end, leaving the remote host in LAST_ACK state. Because of this
69296 + side-effect and to prevent intentional LAST_ACK DoSes, this
69297 + feature also adds automatic mitigation against such attacks.
69298 + The mitigation drastically reduces the amount of time a socket
69299 + can spend in LAST_ACK state. If you're using haproxy and not
69300 + all servers it connects to have this option enabled, consider
69301 + disabling this feature on the haproxy host.
69302 +
69303 + If the sysctl option is enabled, two sysctl options with names
69304 + "ip_blackhole" and "lastack_retries" will be created.
69305 + While "ip_blackhole" takes the standard zero/non-zero on/off
69306 + toggle, "lastack_retries" uses the same kinds of values as
69307 + "tcp_retries1" and "tcp_retries2". The default value of 4
69308 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69309 + state.
69310 +
69311 +config GRKERNSEC_NO_SIMULT_CONNECT
69312 + bool "Disable TCP Simultaneous Connect"
69313 + default y if GRKERNSEC_CONFIG_AUTO
69314 + depends on NET
69315 + help
69316 + If you say Y here, a feature by Willy Tarreau will be enabled that
69317 + removes a weakness in Linux's strict implementation of TCP that
69318 + allows two clients to connect to each other without either entering
69319 + a listening state. The weakness allows an attacker to easily prevent
69320 + a client from connecting to a known server provided the source port
69321 + for the connection is guessed correctly.
69322 +
69323 + As the weakness could be used to prevent an antivirus or IPS from
69324 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69325 + it should be eliminated by enabling this option. Though Linux is
69326 + one of few operating systems supporting simultaneous connect, it
69327 + has no legitimate use in practice and is rarely supported by firewalls.
69328 +
69329 +config GRKERNSEC_SOCKET
69330 + bool "Socket restrictions"
69331 + depends on NET
69332 + help
69333 + If you say Y here, you will be able to choose from several options.
69334 + If you assign a GID on your system and add it to the supplementary
69335 + groups of users you want to restrict socket access to, this patch
69336 + will perform up to three things, based on the option(s) you choose.
69337 +
69338 +config GRKERNSEC_SOCKET_ALL
69339 + bool "Deny any sockets to group"
69340 + depends on GRKERNSEC_SOCKET
69341 + help
69342 + If you say Y here, you will be able to choose a GID of whose users will
69343 + be unable to connect to other hosts from your machine or run server
69344 + applications from your machine. If the sysctl option is enabled, a
69345 + sysctl option with name "socket_all" is created.
69346 +
69347 +config GRKERNSEC_SOCKET_ALL_GID
69348 + int "GID to deny all sockets for"
69349 + depends on GRKERNSEC_SOCKET_ALL
69350 + default 1004
69351 + help
69352 + Here you can choose the GID to disable socket access for. Remember to
69353 + add the users you want socket access disabled for to the GID
69354 + specified here. If the sysctl option is enabled, a sysctl option
69355 + with name "socket_all_gid" is created.
69356 +
69357 +config GRKERNSEC_SOCKET_CLIENT
69358 + bool "Deny client sockets to group"
69359 + depends on GRKERNSEC_SOCKET
69360 + help
69361 + If you say Y here, you will be able to choose a GID of whose users will
69362 + be unable to connect to other hosts from your machine, but will be
69363 + able to run servers. If this option is enabled, all users in the group
69364 + you specify will have to use passive mode when initiating ftp transfers
69365 + from the shell on your machine. If the sysctl option is enabled, a
69366 + sysctl option with name "socket_client" is created.
69367 +
69368 +config GRKERNSEC_SOCKET_CLIENT_GID
69369 + int "GID to deny client sockets for"
69370 + depends on GRKERNSEC_SOCKET_CLIENT
69371 + default 1003
69372 + help
69373 + Here you can choose the GID to disable client socket access for.
69374 + Remember to add the users you want client socket access disabled for to
69375 + the GID specified here. If the sysctl option is enabled, a sysctl
69376 + option with name "socket_client_gid" is created.
69377 +
69378 +config GRKERNSEC_SOCKET_SERVER
69379 + bool "Deny server sockets to group"
69380 + depends on GRKERNSEC_SOCKET
69381 + help
69382 + If you say Y here, you will be able to choose a GID of whose users will
69383 + be unable to run server applications from your machine. If the sysctl
69384 + option is enabled, a sysctl option with name "socket_server" is created.
69385 +
69386 +config GRKERNSEC_SOCKET_SERVER_GID
69387 + int "GID to deny server sockets for"
69388 + depends on GRKERNSEC_SOCKET_SERVER
69389 + default 1002
69390 + help
69391 + Here you can choose the GID to disable server socket access for.
69392 + Remember to add the users you want server socket access disabled for to
69393 + the GID specified here. If the sysctl option is enabled, a sysctl
69394 + option with name "socket_server_gid" is created.
69395 +
69396 +endmenu
69397 +
69398 +menu "Physical Protections"
69399 +depends on GRKERNSEC
69400 +
69401 +config GRKERNSEC_DENYUSB
69402 + bool "Deny new USB connections after toggle"
69403 + default y if GRKERNSEC_CONFIG_AUTO
69404 + depends on SYSCTL && USB_SUPPORT
69405 + help
69406 + If you say Y here, a new sysctl option with name "deny_new_usb"
69407 + will be created. Setting its value to 1 will prevent any new
69408 + USB devices from being recognized by the OS. Any attempted USB
69409 + device insertion will be logged. This option is intended to be
69410 + used against custom USB devices designed to exploit vulnerabilities
69411 + in various USB device drivers.
69412 +
69413 + For greatest effectiveness, this sysctl should be set after any
69414 + relevant init scripts. This option is safe to enable in distros
69415 + as each user can choose whether or not to toggle the sysctl.
69416 +
69417 +config GRKERNSEC_DENYUSB_FORCE
69418 + bool "Reject all USB devices not connected at boot"
69419 + select USB
69420 + depends on GRKERNSEC_DENYUSB
69421 + help
69422 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69423 + that doesn't involve a sysctl entry. This option should only be
69424 + enabled if you're sure you want to deny all new USB connections
69425 + at runtime and don't want to modify init scripts. This should not
69426 + be enabled by distros. It forces the core USB code to be built
69427 + into the kernel image so that all devices connected at boot time
69428 + can be recognized and new USB device connections can be prevented
69429 + prior to init running.
69430 +
69431 +endmenu
69432 +
69433 +menu "Sysctl Support"
69434 +depends on GRKERNSEC && SYSCTL
69435 +
69436 +config GRKERNSEC_SYSCTL
69437 + bool "Sysctl support"
69438 + default y if GRKERNSEC_CONFIG_AUTO
69439 + help
69440 + If you say Y here, you will be able to change the options that
69441 + grsecurity runs with at bootup, without having to recompile your
69442 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69443 + to enable (1) or disable (0) various features. All the sysctl entries
69444 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69445 + All features enabled in the kernel configuration are disabled at boot
69446 + if you do not say Y to the "Turn on features by default" option.
69447 + All options should be set at startup, and the grsec_lock entry should
69448 + be set to a non-zero value after all the options are set.
69449 + *THIS IS EXTREMELY IMPORTANT*
69450 +
69451 +config GRKERNSEC_SYSCTL_DISTRO
69452 + bool "Extra sysctl support for distro makers (READ HELP)"
69453 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69454 + help
69455 + If you say Y here, additional sysctl options will be created
69456 + for features that affect processes running as root. Therefore,
69457 + it is critical when using this option that the grsec_lock entry be
69458 + enabled after boot. Only distros with prebuilt kernel packages
69459 + with this option enabled that can ensure grsec_lock is enabled
69460 + after boot should use this option.
69461 + *Failure to set grsec_lock after boot makes all grsec features
69462 + this option covers useless*
69463 +
69464 + Currently this option creates the following sysctl entries:
69465 + "Disable Privileged I/O": "disable_priv_io"
69466 +
69467 +config GRKERNSEC_SYSCTL_ON
69468 + bool "Turn on features by default"
69469 + default y if GRKERNSEC_CONFIG_AUTO
69470 + depends on GRKERNSEC_SYSCTL
69471 + help
69472 + If you say Y here, instead of having all features enabled in the
69473 + kernel configuration disabled at boot time, the features will be
69474 + enabled at boot time. It is recommended you say Y here unless
69475 + there is some reason you would want all sysctl-tunable features to
69476 + be disabled by default. As mentioned elsewhere, it is important
69477 + to enable the grsec_lock entry once you have finished modifying
69478 + the sysctl entries.
69479 +
69480 +endmenu
69481 +menu "Logging Options"
69482 +depends on GRKERNSEC
69483 +
69484 +config GRKERNSEC_FLOODTIME
69485 + int "Seconds in between log messages (minimum)"
69486 + default 10
69487 + help
69488 + This option allows you to enforce the number of seconds between
69489 + grsecurity log messages. The default should be suitable for most
69490 + people, however, if you choose to change it, choose a value small enough
69491 + to allow informative logs to be produced, but large enough to
69492 + prevent flooding.
69493 +
69494 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69495 + any rate limiting on grsecurity log messages.
69496 +
69497 +config GRKERNSEC_FLOODBURST
69498 + int "Number of messages in a burst (maximum)"
69499 + default 6
69500 + help
69501 + This option allows you to choose the maximum number of messages allowed
69502 + within the flood time interval you chose in a separate option. The
69503 + default should be suitable for most people, however if you find that
69504 + many of your logs are being interpreted as flooding, you may want to
69505 + raise this value.
69506 +
69507 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69508 + any rate limiting on grsecurity log messages.
69509 +
69510 +endmenu
69511 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69512 new file mode 100644
69513 index 0000000..30ababb
69514 --- /dev/null
69515 +++ b/grsecurity/Makefile
69516 @@ -0,0 +1,54 @@
69517 +# grsecurity – access control and security hardening for Linux
69518 +# All code in this directory and various hooks located throughout the Linux kernel are
69519 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69520 +# http://www.grsecurity.net spender@grsecurity.net
69521 +#
69522 +# This program is free software; you can redistribute it and/or
69523 +# modify it under the terms of the GNU General Public License version 2
69524 +# as published by the Free Software Foundation.
69525 +#
69526 +# This program is distributed in the hope that it will be useful,
69527 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69528 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69529 +# GNU General Public License for more details.
69530 +#
69531 +# You should have received a copy of the GNU General Public License
69532 +# along with this program; if not, write to the Free Software
69533 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69534 +
69535 +KBUILD_CFLAGS += -Werror
69536 +
69537 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69538 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69539 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69540 + grsec_usb.o grsec_ipc.o grsec_proc.o
69541 +
69542 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69543 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69544 + gracl_learn.o grsec_log.o gracl_policy.o
69545 +ifdef CONFIG_COMPAT
69546 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69547 +endif
69548 +
69549 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69550 +
69551 +ifdef CONFIG_NET
69552 +obj-y += grsec_sock.o
69553 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69554 +endif
69555 +
69556 +ifndef CONFIG_GRKERNSEC
69557 +obj-y += grsec_disabled.o
69558 +endif
69559 +
69560 +ifdef CONFIG_GRKERNSEC_HIDESYM
69561 +extra-y := grsec_hidesym.o
69562 +$(obj)/grsec_hidesym.o:
69563 + @-chmod -f 500 /boot
69564 + @-chmod -f 500 /lib/modules
69565 + @-chmod -f 500 /lib64/modules
69566 + @-chmod -f 500 /lib32/modules
69567 + @-chmod -f 700 .
69568 + @-chmod -f 700 $(objtree)
69569 + @echo ' grsec: protected kernel image paths'
69570 +endif
69571 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69572 new file mode 100644
69573 index 0000000..6c1e154
69574 --- /dev/null
69575 +++ b/grsecurity/gracl.c
69576 @@ -0,0 +1,2749 @@
69577 +#include <linux/kernel.h>
69578 +#include <linux/module.h>
69579 +#include <linux/sched.h>
69580 +#include <linux/mm.h>
69581 +#include <linux/file.h>
69582 +#include <linux/fs.h>
69583 +#include <linux/namei.h>
69584 +#include <linux/mount.h>
69585 +#include <linux/tty.h>
69586 +#include <linux/proc_fs.h>
69587 +#include <linux/lglock.h>
69588 +#include <linux/slab.h>
69589 +#include <linux/vmalloc.h>
69590 +#include <linux/types.h>
69591 +#include <linux/sysctl.h>
69592 +#include <linux/netdevice.h>
69593 +#include <linux/ptrace.h>
69594 +#include <linux/gracl.h>
69595 +#include <linux/gralloc.h>
69596 +#include <linux/security.h>
69597 +#include <linux/grinternal.h>
69598 +#include <linux/pid_namespace.h>
69599 +#include <linux/stop_machine.h>
69600 +#include <linux/fdtable.h>
69601 +#include <linux/percpu.h>
69602 +#include <linux/lglock.h>
69603 +#include <linux/hugetlb.h>
69604 +#include <linux/posix-timers.h>
69605 +#include <linux/prefetch.h>
69606 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69607 +#include <linux/magic.h>
69608 +#include <linux/pagemap.h>
69609 +#include "../fs/btrfs/async-thread.h"
69610 +#include "../fs/btrfs/ctree.h"
69611 +#include "../fs/btrfs/btrfs_inode.h"
69612 +#endif
69613 +#include "../fs/mount.h"
69614 +
69615 +#include <asm/uaccess.h>
69616 +#include <asm/errno.h>
69617 +#include <asm/mman.h>
69618 +
69619 +#define FOR_EACH_ROLE_START(role) \
69620 + role = running_polstate.role_list; \
69621 + while (role) {
69622 +
69623 +#define FOR_EACH_ROLE_END(role) \
69624 + role = role->prev; \
69625 + }
69626 +
69627 +extern struct path gr_real_root;
69628 +
69629 +static struct gr_policy_state running_polstate;
69630 +struct gr_policy_state *polstate = &running_polstate;
69631 +extern struct gr_alloc_state *current_alloc_state;
69632 +
69633 +extern char *gr_shared_page[4];
69634 +DEFINE_RWLOCK(gr_inode_lock);
69635 +
69636 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69637 +
69638 +#ifdef CONFIG_NET
69639 +extern struct vfsmount *sock_mnt;
69640 +#endif
69641 +
69642 +extern struct vfsmount *pipe_mnt;
69643 +extern struct vfsmount *shm_mnt;
69644 +
69645 +#ifdef CONFIG_HUGETLBFS
69646 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69647 +#endif
69648 +
69649 +extern u16 acl_sp_role_value;
69650 +extern struct acl_object_label *fakefs_obj_rw;
69651 +extern struct acl_object_label *fakefs_obj_rwx;
69652 +
69653 +int gr_acl_is_enabled(void)
69654 +{
69655 + return (gr_status & GR_READY);
69656 +}
69657 +
69658 +void gr_enable_rbac_system(void)
69659 +{
69660 + pax_open_kernel();
69661 + gr_status |= GR_READY;
69662 + pax_close_kernel();
69663 +}
69664 +
69665 +int gr_rbac_disable(void *unused)
69666 +{
69667 + pax_open_kernel();
69668 + gr_status &= ~GR_READY;
69669 + pax_close_kernel();
69670 +
69671 + return 0;
69672 +}
69673 +
69674 +static inline dev_t __get_dev(const struct dentry *dentry)
69675 +{
69676 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69677 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69678 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69679 + else
69680 +#endif
69681 + return dentry->d_sb->s_dev;
69682 +}
69683 +
69684 +static inline u64 __get_ino(const struct dentry *dentry)
69685 +{
69686 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69687 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69688 + return btrfs_ino(dentry->d_inode);
69689 + else
69690 +#endif
69691 + return dentry->d_inode->i_ino;
69692 +}
69693 +
69694 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69695 +{
69696 + return __get_dev(dentry);
69697 +}
69698 +
69699 +u64 gr_get_ino_from_dentry(struct dentry *dentry)
69700 +{
69701 + return __get_ino(dentry);
69702 +}
69703 +
69704 +static char gr_task_roletype_to_char(struct task_struct *task)
69705 +{
69706 + switch (task->role->roletype &
69707 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69708 + GR_ROLE_SPECIAL)) {
69709 + case GR_ROLE_DEFAULT:
69710 + return 'D';
69711 + case GR_ROLE_USER:
69712 + return 'U';
69713 + case GR_ROLE_GROUP:
69714 + return 'G';
69715 + case GR_ROLE_SPECIAL:
69716 + return 'S';
69717 + }
69718 +
69719 + return 'X';
69720 +}
69721 +
69722 +char gr_roletype_to_char(void)
69723 +{
69724 + return gr_task_roletype_to_char(current);
69725 +}
69726 +
69727 +__inline__ int
69728 +gr_acl_tpe_check(void)
69729 +{
69730 + if (unlikely(!(gr_status & GR_READY)))
69731 + return 0;
69732 + if (current->role->roletype & GR_ROLE_TPE)
69733 + return 1;
69734 + else
69735 + return 0;
69736 +}
69737 +
69738 +int
69739 +gr_handle_rawio(const struct inode *inode)
69740 +{
69741 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69742 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69743 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69744 + !capable(CAP_SYS_RAWIO))
69745 + return 1;
69746 +#endif
69747 + return 0;
69748 +}
69749 +
69750 +int
69751 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69752 +{
69753 + if (likely(lena != lenb))
69754 + return 0;
69755 +
69756 + return !memcmp(a, b, lena);
69757 +}
69758 +
69759 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69760 +{
69761 + *buflen -= namelen;
69762 + if (*buflen < 0)
69763 + return -ENAMETOOLONG;
69764 + *buffer -= namelen;
69765 + memcpy(*buffer, str, namelen);
69766 + return 0;
69767 +}
69768 +
69769 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69770 +{
69771 + return prepend(buffer, buflen, name->name, name->len);
69772 +}
69773 +
69774 +static int prepend_path(const struct path *path, struct path *root,
69775 + char **buffer, int *buflen)
69776 +{
69777 + struct dentry *dentry = path->dentry;
69778 + struct vfsmount *vfsmnt = path->mnt;
69779 + struct mount *mnt = real_mount(vfsmnt);
69780 + bool slash = false;
69781 + int error = 0;
69782 +
69783 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69784 + struct dentry * parent;
69785 +
69786 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69787 + /* Global root? */
69788 + if (!mnt_has_parent(mnt)) {
69789 + goto out;
69790 + }
69791 + dentry = mnt->mnt_mountpoint;
69792 + mnt = mnt->mnt_parent;
69793 + vfsmnt = &mnt->mnt;
69794 + continue;
69795 + }
69796 + parent = dentry->d_parent;
69797 + prefetch(parent);
69798 + spin_lock(&dentry->d_lock);
69799 + error = prepend_name(buffer, buflen, &dentry->d_name);
69800 + spin_unlock(&dentry->d_lock);
69801 + if (!error)
69802 + error = prepend(buffer, buflen, "/", 1);
69803 + if (error)
69804 + break;
69805 +
69806 + slash = true;
69807 + dentry = parent;
69808 + }
69809 +
69810 +out:
69811 + if (!error && !slash)
69812 + error = prepend(buffer, buflen, "/", 1);
69813 +
69814 + return error;
69815 +}
69816 +
69817 +/* this must be called with mount_lock and rename_lock held */
69818 +
69819 +static char *__our_d_path(const struct path *path, struct path *root,
69820 + char *buf, int buflen)
69821 +{
69822 + char *res = buf + buflen;
69823 + int error;
69824 +
69825 + prepend(&res, &buflen, "\0", 1);
69826 + error = prepend_path(path, root, &res, &buflen);
69827 + if (error)
69828 + return ERR_PTR(error);
69829 +
69830 + return res;
69831 +}
69832 +
69833 +static char *
69834 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69835 +{
69836 + char *retval;
69837 +
69838 + retval = __our_d_path(path, root, buf, buflen);
69839 + if (unlikely(IS_ERR(retval)))
69840 + retval = strcpy(buf, "<path too long>");
69841 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69842 + retval[1] = '\0';
69843 +
69844 + return retval;
69845 +}
69846 +
69847 +static char *
69848 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69849 + char *buf, int buflen)
69850 +{
69851 + struct path path;
69852 + char *res;
69853 +
69854 + path.dentry = (struct dentry *)dentry;
69855 + path.mnt = (struct vfsmount *)vfsmnt;
69856 +
69857 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69858 + by the RBAC system */
69859 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69860 +
69861 + return res;
69862 +}
69863 +
69864 +static char *
69865 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69866 + char *buf, int buflen)
69867 +{
69868 + char *res;
69869 + struct path path;
69870 + struct path root;
69871 + struct task_struct *reaper = init_pid_ns.child_reaper;
69872 +
69873 + path.dentry = (struct dentry *)dentry;
69874 + path.mnt = (struct vfsmount *)vfsmnt;
69875 +
69876 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69877 + get_fs_root(reaper->fs, &root);
69878 +
69879 + read_seqlock_excl(&mount_lock);
69880 + write_seqlock(&rename_lock);
69881 + res = gen_full_path(&path, &root, buf, buflen);
69882 + write_sequnlock(&rename_lock);
69883 + read_sequnlock_excl(&mount_lock);
69884 +
69885 + path_put(&root);
69886 + return res;
69887 +}
69888 +
69889 +char *
69890 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69891 +{
69892 + char *ret;
69893 + read_seqlock_excl(&mount_lock);
69894 + write_seqlock(&rename_lock);
69895 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69896 + PAGE_SIZE);
69897 + write_sequnlock(&rename_lock);
69898 + read_sequnlock_excl(&mount_lock);
69899 + return ret;
69900 +}
69901 +
69902 +static char *
69903 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69904 +{
69905 + char *ret;
69906 + char *buf;
69907 + int buflen;
69908 +
69909 + read_seqlock_excl(&mount_lock);
69910 + write_seqlock(&rename_lock);
69911 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69912 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69913 + buflen = (int)(ret - buf);
69914 + if (buflen >= 5)
69915 + prepend(&ret, &buflen, "/proc", 5);
69916 + else
69917 + ret = strcpy(buf, "<path too long>");
69918 + write_sequnlock(&rename_lock);
69919 + read_sequnlock_excl(&mount_lock);
69920 + return ret;
69921 +}
69922 +
69923 +char *
69924 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69925 +{
69926 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69927 + PAGE_SIZE);
69928 +}
69929 +
69930 +char *
69931 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69932 +{
69933 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69934 + PAGE_SIZE);
69935 +}
69936 +
69937 +char *
69938 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69939 +{
69940 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69941 + PAGE_SIZE);
69942 +}
69943 +
69944 +char *
69945 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69946 +{
69947 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69948 + PAGE_SIZE);
69949 +}
69950 +
69951 +char *
69952 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69953 +{
69954 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69955 + PAGE_SIZE);
69956 +}
69957 +
69958 +__inline__ __u32
69959 +to_gr_audit(const __u32 reqmode)
69960 +{
69961 + /* masks off auditable permission flags, then shifts them to create
69962 + auditing flags, and adds the special case of append auditing if
69963 + we're requesting write */
69964 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69965 +}
69966 +
69967 +struct acl_role_label *
69968 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69969 + const gid_t gid)
69970 +{
69971 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69972 + struct acl_role_label *match;
69973 + struct role_allowed_ip *ipp;
69974 + unsigned int x;
69975 + u32 curr_ip = task->signal->saved_ip;
69976 +
69977 + match = state->acl_role_set.r_hash[index];
69978 +
69979 + while (match) {
69980 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69981 + for (x = 0; x < match->domain_child_num; x++) {
69982 + if (match->domain_children[x] == uid)
69983 + goto found;
69984 + }
69985 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69986 + break;
69987 + match = match->next;
69988 + }
69989 +found:
69990 + if (match == NULL) {
69991 + try_group:
69992 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69993 + match = state->acl_role_set.r_hash[index];
69994 +
69995 + while (match) {
69996 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69997 + for (x = 0; x < match->domain_child_num; x++) {
69998 + if (match->domain_children[x] == gid)
69999 + goto found2;
70000 + }
70001 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70002 + break;
70003 + match = match->next;
70004 + }
70005 +found2:
70006 + if (match == NULL)
70007 + match = state->default_role;
70008 + if (match->allowed_ips == NULL)
70009 + return match;
70010 + else {
70011 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70012 + if (likely
70013 + ((ntohl(curr_ip) & ipp->netmask) ==
70014 + (ntohl(ipp->addr) & ipp->netmask)))
70015 + return match;
70016 + }
70017 + match = state->default_role;
70018 + }
70019 + } else if (match->allowed_ips == NULL) {
70020 + return match;
70021 + } else {
70022 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70023 + if (likely
70024 + ((ntohl(curr_ip) & ipp->netmask) ==
70025 + (ntohl(ipp->addr) & ipp->netmask)))
70026 + return match;
70027 + }
70028 + goto try_group;
70029 + }
70030 +
70031 + return match;
70032 +}
70033 +
70034 +static struct acl_role_label *
70035 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70036 + const gid_t gid)
70037 +{
70038 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70039 +}
70040 +
70041 +struct acl_subject_label *
70042 +lookup_acl_subj_label(const u64 ino, const dev_t dev,
70043 + const struct acl_role_label *role)
70044 +{
70045 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70046 + struct acl_subject_label *match;
70047 +
70048 + match = role->subj_hash[index];
70049 +
70050 + while (match && (match->inode != ino || match->device != dev ||
70051 + (match->mode & GR_DELETED))) {
70052 + match = match->next;
70053 + }
70054 +
70055 + if (match && !(match->mode & GR_DELETED))
70056 + return match;
70057 + else
70058 + return NULL;
70059 +}
70060 +
70061 +struct acl_subject_label *
70062 +lookup_acl_subj_label_deleted(const u64 ino, const dev_t dev,
70063 + const struct acl_role_label *role)
70064 +{
70065 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70066 + struct acl_subject_label *match;
70067 +
70068 + match = role->subj_hash[index];
70069 +
70070 + while (match && (match->inode != ino || match->device != dev ||
70071 + !(match->mode & GR_DELETED))) {
70072 + match = match->next;
70073 + }
70074 +
70075 + if (match && (match->mode & GR_DELETED))
70076 + return match;
70077 + else
70078 + return NULL;
70079 +}
70080 +
70081 +static struct acl_object_label *
70082 +lookup_acl_obj_label(const u64 ino, const dev_t dev,
70083 + const struct acl_subject_label *subj)
70084 +{
70085 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70086 + struct acl_object_label *match;
70087 +
70088 + match = subj->obj_hash[index];
70089 +
70090 + while (match && (match->inode != ino || match->device != dev ||
70091 + (match->mode & GR_DELETED))) {
70092 + match = match->next;
70093 + }
70094 +
70095 + if (match && !(match->mode & GR_DELETED))
70096 + return match;
70097 + else
70098 + return NULL;
70099 +}
70100 +
70101 +static struct acl_object_label *
70102 +lookup_acl_obj_label_create(const u64 ino, const dev_t dev,
70103 + const struct acl_subject_label *subj)
70104 +{
70105 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70106 + struct acl_object_label *match;
70107 +
70108 + match = subj->obj_hash[index];
70109 +
70110 + while (match && (match->inode != ino || match->device != dev ||
70111 + !(match->mode & GR_DELETED))) {
70112 + match = match->next;
70113 + }
70114 +
70115 + if (match && (match->mode & GR_DELETED))
70116 + return match;
70117 +
70118 + match = subj->obj_hash[index];
70119 +
70120 + while (match && (match->inode != ino || match->device != dev ||
70121 + (match->mode & GR_DELETED))) {
70122 + match = match->next;
70123 + }
70124 +
70125 + if (match && !(match->mode & GR_DELETED))
70126 + return match;
70127 + else
70128 + return NULL;
70129 +}
70130 +
70131 +struct name_entry *
70132 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70133 +{
70134 + unsigned int len = strlen(name);
70135 + unsigned int key = full_name_hash(name, len);
70136 + unsigned int index = key % state->name_set.n_size;
70137 + struct name_entry *match;
70138 +
70139 + match = state->name_set.n_hash[index];
70140 +
70141 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70142 + match = match->next;
70143 +
70144 + return match;
70145 +}
70146 +
70147 +static struct name_entry *
70148 +lookup_name_entry(const char *name)
70149 +{
70150 + return __lookup_name_entry(&running_polstate, name);
70151 +}
70152 +
70153 +static struct name_entry *
70154 +lookup_name_entry_create(const char *name)
70155 +{
70156 + unsigned int len = strlen(name);
70157 + unsigned int key = full_name_hash(name, len);
70158 + unsigned int index = key % running_polstate.name_set.n_size;
70159 + struct name_entry *match;
70160 +
70161 + match = running_polstate.name_set.n_hash[index];
70162 +
70163 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70164 + !match->deleted))
70165 + match = match->next;
70166 +
70167 + if (match && match->deleted)
70168 + return match;
70169 +
70170 + match = running_polstate.name_set.n_hash[index];
70171 +
70172 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70173 + match->deleted))
70174 + match = match->next;
70175 +
70176 + if (match && !match->deleted)
70177 + return match;
70178 + else
70179 + return NULL;
70180 +}
70181 +
70182 +static struct inodev_entry *
70183 +lookup_inodev_entry(const u64 ino, const dev_t dev)
70184 +{
70185 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70186 + struct inodev_entry *match;
70187 +
70188 + match = running_polstate.inodev_set.i_hash[index];
70189 +
70190 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70191 + match = match->next;
70192 +
70193 + return match;
70194 +}
70195 +
70196 +void
70197 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70198 +{
70199 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70200 + state->inodev_set.i_size);
70201 + struct inodev_entry **curr;
70202 +
70203 + entry->prev = NULL;
70204 +
70205 + curr = &state->inodev_set.i_hash[index];
70206 + if (*curr != NULL)
70207 + (*curr)->prev = entry;
70208 +
70209 + entry->next = *curr;
70210 + *curr = entry;
70211 +
70212 + return;
70213 +}
70214 +
70215 +static void
70216 +insert_inodev_entry(struct inodev_entry *entry)
70217 +{
70218 + __insert_inodev_entry(&running_polstate, entry);
70219 +}
70220 +
70221 +void
70222 +insert_acl_obj_label(struct acl_object_label *obj,
70223 + struct acl_subject_label *subj)
70224 +{
70225 + unsigned int index =
70226 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70227 + struct acl_object_label **curr;
70228 +
70229 + obj->prev = NULL;
70230 +
70231 + curr = &subj->obj_hash[index];
70232 + if (*curr != NULL)
70233 + (*curr)->prev = obj;
70234 +
70235 + obj->next = *curr;
70236 + *curr = obj;
70237 +
70238 + return;
70239 +}
70240 +
70241 +void
70242 +insert_acl_subj_label(struct acl_subject_label *obj,
70243 + struct acl_role_label *role)
70244 +{
70245 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70246 + struct acl_subject_label **curr;
70247 +
70248 + obj->prev = NULL;
70249 +
70250 + curr = &role->subj_hash[index];
70251 + if (*curr != NULL)
70252 + (*curr)->prev = obj;
70253 +
70254 + obj->next = *curr;
70255 + *curr = obj;
70256 +
70257 + return;
70258 +}
70259 +
70260 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70261 +
70262 +static int
70263 +glob_match(const char *p, const char *n)
70264 +{
70265 + char c;
70266 +
70267 + while ((c = *p++) != '\0') {
70268 + switch (c) {
70269 + case '?':
70270 + if (*n == '\0')
70271 + return 1;
70272 + else if (*n == '/')
70273 + return 1;
70274 + break;
70275 + case '\\':
70276 + if (*n != c)
70277 + return 1;
70278 + break;
70279 + case '*':
70280 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70281 + if (*n == '/')
70282 + return 1;
70283 + else if (c == '?') {
70284 + if (*n == '\0')
70285 + return 1;
70286 + else
70287 + ++n;
70288 + }
70289 + }
70290 + if (c == '\0') {
70291 + return 0;
70292 + } else {
70293 + const char *endp;
70294 +
70295 + if ((endp = strchr(n, '/')) == NULL)
70296 + endp = n + strlen(n);
70297 +
70298 + if (c == '[') {
70299 + for (--p; n < endp; ++n)
70300 + if (!glob_match(p, n))
70301 + return 0;
70302 + } else if (c == '/') {
70303 + while (*n != '\0' && *n != '/')
70304 + ++n;
70305 + if (*n == '/' && !glob_match(p, n + 1))
70306 + return 0;
70307 + } else {
70308 + for (--p; n < endp; ++n)
70309 + if (*n == c && !glob_match(p, n))
70310 + return 0;
70311 + }
70312 +
70313 + return 1;
70314 + }
70315 + case '[':
70316 + {
70317 + int not;
70318 + char cold;
70319 +
70320 + if (*n == '\0' || *n == '/')
70321 + return 1;
70322 +
70323 + not = (*p == '!' || *p == '^');
70324 + if (not)
70325 + ++p;
70326 +
70327 + c = *p++;
70328 + for (;;) {
70329 + unsigned char fn = (unsigned char)*n;
70330 +
70331 + if (c == '\0')
70332 + return 1;
70333 + else {
70334 + if (c == fn)
70335 + goto matched;
70336 + cold = c;
70337 + c = *p++;
70338 +
70339 + if (c == '-' && *p != ']') {
70340 + unsigned char cend = *p++;
70341 +
70342 + if (cend == '\0')
70343 + return 1;
70344 +
70345 + if (cold <= fn && fn <= cend)
70346 + goto matched;
70347 +
70348 + c = *p++;
70349 + }
70350 + }
70351 +
70352 + if (c == ']')
70353 + break;
70354 + }
70355 + if (!not)
70356 + return 1;
70357 + break;
70358 + matched:
70359 + while (c != ']') {
70360 + if (c == '\0')
70361 + return 1;
70362 +
70363 + c = *p++;
70364 + }
70365 + if (not)
70366 + return 1;
70367 + }
70368 + break;
70369 + default:
70370 + if (c != *n)
70371 + return 1;
70372 + }
70373 +
70374 + ++n;
70375 + }
70376 +
70377 + if (*n == '\0')
70378 + return 0;
70379 +
70380 + if (*n == '/')
70381 + return 0;
70382 +
70383 + return 1;
70384 +}
70385 +
70386 +static struct acl_object_label *
70387 +chk_glob_label(struct acl_object_label *globbed,
70388 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70389 +{
70390 + struct acl_object_label *tmp;
70391 +
70392 + if (*path == NULL)
70393 + *path = gr_to_filename_nolock(dentry, mnt);
70394 +
70395 + tmp = globbed;
70396 +
70397 + while (tmp) {
70398 + if (!glob_match(tmp->filename, *path))
70399 + return tmp;
70400 + tmp = tmp->next;
70401 + }
70402 +
70403 + return NULL;
70404 +}
70405 +
70406 +static struct acl_object_label *
70407 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70408 + const u64 curr_ino, const dev_t curr_dev,
70409 + const struct acl_subject_label *subj, char **path, const int checkglob)
70410 +{
70411 + struct acl_subject_label *tmpsubj;
70412 + struct acl_object_label *retval;
70413 + struct acl_object_label *retval2;
70414 +
70415 + tmpsubj = (struct acl_subject_label *) subj;
70416 + read_lock(&gr_inode_lock);
70417 + do {
70418 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70419 + if (retval) {
70420 + if (checkglob && retval->globbed) {
70421 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70422 + if (retval2)
70423 + retval = retval2;
70424 + }
70425 + break;
70426 + }
70427 + } while ((tmpsubj = tmpsubj->parent_subject));
70428 + read_unlock(&gr_inode_lock);
70429 +
70430 + return retval;
70431 +}
70432 +
70433 +static __inline__ struct acl_object_label *
70434 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70435 + struct dentry *curr_dentry,
70436 + const struct acl_subject_label *subj, char **path, const int checkglob)
70437 +{
70438 + int newglob = checkglob;
70439 + u64 inode;
70440 + dev_t device;
70441 +
70442 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70443 + as we don't want a / * rule to match instead of the / object
70444 + don't do this for create lookups that call this function though, since they're looking up
70445 + on the parent and thus need globbing checks on all paths
70446 + */
70447 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70448 + newglob = GR_NO_GLOB;
70449 +
70450 + spin_lock(&curr_dentry->d_lock);
70451 + inode = __get_ino(curr_dentry);
70452 + device = __get_dev(curr_dentry);
70453 + spin_unlock(&curr_dentry->d_lock);
70454 +
70455 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70456 +}
70457 +
70458 +#ifdef CONFIG_HUGETLBFS
70459 +static inline bool
70460 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70461 +{
70462 + int i;
70463 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70464 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70465 + return true;
70466 + }
70467 +
70468 + return false;
70469 +}
70470 +#endif
70471 +
70472 +static struct acl_object_label *
70473 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70474 + const struct acl_subject_label *subj, char *path, const int checkglob)
70475 +{
70476 + struct dentry *dentry = (struct dentry *) l_dentry;
70477 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70478 + struct mount *real_mnt = real_mount(mnt);
70479 + struct acl_object_label *retval;
70480 + struct dentry *parent;
70481 +
70482 + read_seqlock_excl(&mount_lock);
70483 + write_seqlock(&rename_lock);
70484 +
70485 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70486 +#ifdef CONFIG_NET
70487 + mnt == sock_mnt ||
70488 +#endif
70489 +#ifdef CONFIG_HUGETLBFS
70490 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70491 +#endif
70492 + /* ignore Eric Biederman */
70493 + IS_PRIVATE(l_dentry->d_inode))) {
70494 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70495 + goto out;
70496 + }
70497 +
70498 + for (;;) {
70499 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70500 + break;
70501 +
70502 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70503 + if (!mnt_has_parent(real_mnt))
70504 + break;
70505 +
70506 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70507 + if (retval != NULL)
70508 + goto out;
70509 +
70510 + dentry = real_mnt->mnt_mountpoint;
70511 + real_mnt = real_mnt->mnt_parent;
70512 + mnt = &real_mnt->mnt;
70513 + continue;
70514 + }
70515 +
70516 + parent = dentry->d_parent;
70517 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70518 + if (retval != NULL)
70519 + goto out;
70520 +
70521 + dentry = parent;
70522 + }
70523 +
70524 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70525 +
70526 + /* gr_real_root is pinned so we don't have to hold a reference */
70527 + if (retval == NULL)
70528 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70529 +out:
70530 + write_sequnlock(&rename_lock);
70531 + read_sequnlock_excl(&mount_lock);
70532 +
70533 + BUG_ON(retval == NULL);
70534 +
70535 + return retval;
70536 +}
70537 +
70538 +static __inline__ struct acl_object_label *
70539 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70540 + const struct acl_subject_label *subj)
70541 +{
70542 + char *path = NULL;
70543 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70544 +}
70545 +
70546 +static __inline__ struct acl_object_label *
70547 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70548 + const struct acl_subject_label *subj)
70549 +{
70550 + char *path = NULL;
70551 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70552 +}
70553 +
70554 +static __inline__ struct acl_object_label *
70555 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70556 + const struct acl_subject_label *subj, char *path)
70557 +{
70558 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70559 +}
70560 +
70561 +struct acl_subject_label *
70562 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70563 + const struct acl_role_label *role)
70564 +{
70565 + struct dentry *dentry = (struct dentry *) l_dentry;
70566 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70567 + struct mount *real_mnt = real_mount(mnt);
70568 + struct acl_subject_label *retval;
70569 + struct dentry *parent;
70570 +
70571 + read_seqlock_excl(&mount_lock);
70572 + write_seqlock(&rename_lock);
70573 +
70574 + for (;;) {
70575 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70576 + break;
70577 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70578 + if (!mnt_has_parent(real_mnt))
70579 + break;
70580 +
70581 + spin_lock(&dentry->d_lock);
70582 + read_lock(&gr_inode_lock);
70583 + retval =
70584 + lookup_acl_subj_label(__get_ino(dentry),
70585 + __get_dev(dentry), role);
70586 + read_unlock(&gr_inode_lock);
70587 + spin_unlock(&dentry->d_lock);
70588 + if (retval != NULL)
70589 + goto out;
70590 +
70591 + dentry = real_mnt->mnt_mountpoint;
70592 + real_mnt = real_mnt->mnt_parent;
70593 + mnt = &real_mnt->mnt;
70594 + continue;
70595 + }
70596 +
70597 + spin_lock(&dentry->d_lock);
70598 + read_lock(&gr_inode_lock);
70599 + retval = lookup_acl_subj_label(__get_ino(dentry),
70600 + __get_dev(dentry), role);
70601 + read_unlock(&gr_inode_lock);
70602 + parent = dentry->d_parent;
70603 + spin_unlock(&dentry->d_lock);
70604 +
70605 + if (retval != NULL)
70606 + goto out;
70607 +
70608 + dentry = parent;
70609 + }
70610 +
70611 + spin_lock(&dentry->d_lock);
70612 + read_lock(&gr_inode_lock);
70613 + retval = lookup_acl_subj_label(__get_ino(dentry),
70614 + __get_dev(dentry), role);
70615 + read_unlock(&gr_inode_lock);
70616 + spin_unlock(&dentry->d_lock);
70617 +
70618 + if (unlikely(retval == NULL)) {
70619 + /* gr_real_root is pinned, we don't need to hold a reference */
70620 + read_lock(&gr_inode_lock);
70621 + retval = lookup_acl_subj_label(__get_ino(gr_real_root.dentry),
70622 + __get_dev(gr_real_root.dentry), role);
70623 + read_unlock(&gr_inode_lock);
70624 + }
70625 +out:
70626 + write_sequnlock(&rename_lock);
70627 + read_sequnlock_excl(&mount_lock);
70628 +
70629 + BUG_ON(retval == NULL);
70630 +
70631 + return retval;
70632 +}
70633 +
70634 +void
70635 +assign_special_role(const char *rolename)
70636 +{
70637 + struct acl_object_label *obj;
70638 + struct acl_role_label *r;
70639 + struct acl_role_label *assigned = NULL;
70640 + struct task_struct *tsk;
70641 + struct file *filp;
70642 +
70643 + FOR_EACH_ROLE_START(r)
70644 + if (!strcmp(rolename, r->rolename) &&
70645 + (r->roletype & GR_ROLE_SPECIAL)) {
70646 + assigned = r;
70647 + break;
70648 + }
70649 + FOR_EACH_ROLE_END(r)
70650 +
70651 + if (!assigned)
70652 + return;
70653 +
70654 + read_lock(&tasklist_lock);
70655 + read_lock(&grsec_exec_file_lock);
70656 +
70657 + tsk = current->real_parent;
70658 + if (tsk == NULL)
70659 + goto out_unlock;
70660 +
70661 + filp = tsk->exec_file;
70662 + if (filp == NULL)
70663 + goto out_unlock;
70664 +
70665 + tsk->is_writable = 0;
70666 + tsk->inherited = 0;
70667 +
70668 + tsk->acl_sp_role = 1;
70669 + tsk->acl_role_id = ++acl_sp_role_value;
70670 + tsk->role = assigned;
70671 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70672 +
70673 + /* ignore additional mmap checks for processes that are writable
70674 + by the default ACL */
70675 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70676 + if (unlikely(obj->mode & GR_WRITE))
70677 + tsk->is_writable = 1;
70678 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70679 + if (unlikely(obj->mode & GR_WRITE))
70680 + tsk->is_writable = 1;
70681 +
70682 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70683 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70684 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70685 +#endif
70686 +
70687 +out_unlock:
70688 + read_unlock(&grsec_exec_file_lock);
70689 + read_unlock(&tasklist_lock);
70690 + return;
70691 +}
70692 +
70693 +
70694 +static void
70695 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70696 +{
70697 + struct task_struct *task = current;
70698 + const struct cred *cred = current_cred();
70699 +
70700 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70701 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70702 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70703 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70704 +
70705 + return;
70706 +}
70707 +
70708 +static void
70709 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70710 +{
70711 + struct task_struct *task = current;
70712 + const struct cred *cred = current_cred();
70713 +
70714 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70715 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70716 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70717 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70718 +
70719 + return;
70720 +}
70721 +
70722 +static void
70723 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70724 +{
70725 + struct task_struct *task = current;
70726 + const struct cred *cred = current_cred();
70727 +
70728 + security_learn(GR_ID_LEARN_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 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70732 +
70733 + return;
70734 +}
70735 +
70736 +static void
70737 +gr_set_proc_res(struct task_struct *task)
70738 +{
70739 + struct acl_subject_label *proc;
70740 + unsigned short i;
70741 +
70742 + proc = task->acl;
70743 +
70744 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70745 + return;
70746 +
70747 + for (i = 0; i < RLIM_NLIMITS; i++) {
70748 + unsigned long rlim_cur, rlim_max;
70749 +
70750 + if (!(proc->resmask & (1U << i)))
70751 + continue;
70752 +
70753 + rlim_cur = proc->res[i].rlim_cur;
70754 + rlim_max = proc->res[i].rlim_max;
70755 +
70756 + if (i == RLIMIT_NOFILE) {
70757 + unsigned long saved_sysctl_nr_open = sysctl_nr_open;
70758 + if (rlim_cur > saved_sysctl_nr_open)
70759 + rlim_cur = saved_sysctl_nr_open;
70760 + if (rlim_max > saved_sysctl_nr_open)
70761 + rlim_max = saved_sysctl_nr_open;
70762 + }
70763 +
70764 + task->signal->rlim[i].rlim_cur = rlim_cur;
70765 + task->signal->rlim[i].rlim_max = rlim_max;
70766 +
70767 + if (i == RLIMIT_CPU)
70768 + update_rlimit_cpu(task, rlim_cur);
70769 + }
70770 +
70771 + return;
70772 +}
70773 +
70774 +/* both of the below must be called with
70775 + rcu_read_lock();
70776 + read_lock(&tasklist_lock);
70777 + read_lock(&grsec_exec_file_lock);
70778 + except in the case of gr_set_role_label() (for __gr_get_subject_for_task)
70779 +*/
70780 +
70781 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback)
70782 +{
70783 + char *tmpname;
70784 + struct acl_subject_label *tmpsubj;
70785 + struct file *filp;
70786 + struct name_entry *nmatch;
70787 +
70788 + filp = task->exec_file;
70789 + if (filp == NULL)
70790 + return NULL;
70791 +
70792 + /* the following is to apply the correct subject
70793 + on binaries running when the RBAC system
70794 + is enabled, when the binaries have been
70795 + replaced or deleted since their execution
70796 + -----
70797 + when the RBAC system starts, the inode/dev
70798 + from exec_file will be one the RBAC system
70799 + is unaware of. It only knows the inode/dev
70800 + of the present file on disk, or the absence
70801 + of it.
70802 + */
70803 +
70804 + if (filename)
70805 + nmatch = __lookup_name_entry(state, filename);
70806 + else {
70807 + preempt_disable();
70808 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70809 +
70810 + nmatch = __lookup_name_entry(state, tmpname);
70811 + preempt_enable();
70812 + }
70813 + tmpsubj = NULL;
70814 + if (nmatch) {
70815 + if (nmatch->deleted)
70816 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70817 + else
70818 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70819 + }
70820 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70821 + then we fall back to a normal lookup based on the binary's ino/dev
70822 + */
70823 + if (tmpsubj == NULL && fallback)
70824 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70825 +
70826 + return tmpsubj;
70827 +}
70828 +
70829 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename, int fallback)
70830 +{
70831 + return __gr_get_subject_for_task(&running_polstate, task, filename, fallback);
70832 +}
70833 +
70834 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70835 +{
70836 + struct acl_object_label *obj;
70837 + struct file *filp;
70838 +
70839 + filp = task->exec_file;
70840 +
70841 + task->acl = subj;
70842 + task->is_writable = 0;
70843 + /* ignore additional mmap checks for processes that are writable
70844 + by the default ACL */
70845 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70846 + if (unlikely(obj->mode & GR_WRITE))
70847 + task->is_writable = 1;
70848 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70849 + if (unlikely(obj->mode & GR_WRITE))
70850 + task->is_writable = 1;
70851 +
70852 + gr_set_proc_res(task);
70853 +
70854 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70855 + 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);
70856 +#endif
70857 +}
70858 +
70859 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70860 +{
70861 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70862 +}
70863 +
70864 +__u32
70865 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70866 + const struct vfsmount * mnt)
70867 +{
70868 + __u32 retval = mode;
70869 + struct acl_subject_label *curracl;
70870 + struct acl_object_label *currobj;
70871 +
70872 + if (unlikely(!(gr_status & GR_READY)))
70873 + return (mode & ~GR_AUDITS);
70874 +
70875 + curracl = current->acl;
70876 +
70877 + currobj = chk_obj_label(dentry, mnt, curracl);
70878 + retval = currobj->mode & mode;
70879 +
70880 + /* if we're opening a specified transfer file for writing
70881 + (e.g. /dev/initctl), then transfer our role to init
70882 + */
70883 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70884 + current->role->roletype & GR_ROLE_PERSIST)) {
70885 + struct task_struct *task = init_pid_ns.child_reaper;
70886 +
70887 + if (task->role != current->role) {
70888 + struct acl_subject_label *subj;
70889 +
70890 + task->acl_sp_role = 0;
70891 + task->acl_role_id = current->acl_role_id;
70892 + task->role = current->role;
70893 + rcu_read_lock();
70894 + read_lock(&grsec_exec_file_lock);
70895 + subj = gr_get_subject_for_task(task, NULL, 1);
70896 + gr_apply_subject_to_task(task, subj);
70897 + read_unlock(&grsec_exec_file_lock);
70898 + rcu_read_unlock();
70899 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70900 + }
70901 + }
70902 +
70903 + if (unlikely
70904 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70905 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70906 + __u32 new_mode = mode;
70907 +
70908 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70909 +
70910 + retval = new_mode;
70911 +
70912 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70913 + new_mode |= GR_INHERIT;
70914 +
70915 + if (!(mode & GR_NOLEARN))
70916 + gr_log_learn(dentry, mnt, new_mode);
70917 + }
70918 +
70919 + return retval;
70920 +}
70921 +
70922 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70923 + const struct dentry *parent,
70924 + const struct vfsmount *mnt)
70925 +{
70926 + struct name_entry *match;
70927 + struct acl_object_label *matchpo;
70928 + struct acl_subject_label *curracl;
70929 + char *path;
70930 +
70931 + if (unlikely(!(gr_status & GR_READY)))
70932 + return NULL;
70933 +
70934 + preempt_disable();
70935 + path = gr_to_filename_rbac(new_dentry, mnt);
70936 + match = lookup_name_entry_create(path);
70937 +
70938 + curracl = current->acl;
70939 +
70940 + if (match) {
70941 + read_lock(&gr_inode_lock);
70942 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70943 + read_unlock(&gr_inode_lock);
70944 +
70945 + if (matchpo) {
70946 + preempt_enable();
70947 + return matchpo;
70948 + }
70949 + }
70950 +
70951 + // lookup parent
70952 +
70953 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70954 +
70955 + preempt_enable();
70956 + return matchpo;
70957 +}
70958 +
70959 +__u32
70960 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70961 + const struct vfsmount * mnt, const __u32 mode)
70962 +{
70963 + struct acl_object_label *matchpo;
70964 + __u32 retval;
70965 +
70966 + if (unlikely(!(gr_status & GR_READY)))
70967 + return (mode & ~GR_AUDITS);
70968 +
70969 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70970 +
70971 + retval = matchpo->mode & mode;
70972 +
70973 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70974 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70975 + __u32 new_mode = mode;
70976 +
70977 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70978 +
70979 + gr_log_learn(new_dentry, mnt, new_mode);
70980 + return new_mode;
70981 + }
70982 +
70983 + return retval;
70984 +}
70985 +
70986 +__u32
70987 +gr_check_link(const struct dentry * new_dentry,
70988 + const struct dentry * parent_dentry,
70989 + const struct vfsmount * parent_mnt,
70990 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70991 +{
70992 + struct acl_object_label *obj;
70993 + __u32 oldmode, newmode;
70994 + __u32 needmode;
70995 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70996 + GR_DELETE | GR_INHERIT;
70997 +
70998 + if (unlikely(!(gr_status & GR_READY)))
70999 + return (GR_CREATE | GR_LINK);
71000 +
71001 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71002 + oldmode = obj->mode;
71003 +
71004 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71005 + newmode = obj->mode;
71006 +
71007 + needmode = newmode & checkmodes;
71008 +
71009 + // old name for hardlink must have at least the permissions of the new name
71010 + if ((oldmode & needmode) != needmode)
71011 + goto bad;
71012 +
71013 + // if old name had restrictions/auditing, make sure the new name does as well
71014 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71015 +
71016 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71017 + if (is_privileged_binary(old_dentry))
71018 + needmode |= GR_SETID;
71019 +
71020 + if ((newmode & needmode) != needmode)
71021 + goto bad;
71022 +
71023 + // enforce minimum permissions
71024 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71025 + return newmode;
71026 +bad:
71027 + needmode = oldmode;
71028 + if (is_privileged_binary(old_dentry))
71029 + needmode |= GR_SETID;
71030 +
71031 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71032 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71033 + return (GR_CREATE | GR_LINK);
71034 + } else if (newmode & GR_SUPPRESS)
71035 + return GR_SUPPRESS;
71036 + else
71037 + return 0;
71038 +}
71039 +
71040 +int
71041 +gr_check_hidden_task(const struct task_struct *task)
71042 +{
71043 + if (unlikely(!(gr_status & GR_READY)))
71044 + return 0;
71045 +
71046 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71047 + return 1;
71048 +
71049 + return 0;
71050 +}
71051 +
71052 +int
71053 +gr_check_protected_task(const struct task_struct *task)
71054 +{
71055 + if (unlikely(!(gr_status & GR_READY) || !task))
71056 + return 0;
71057 +
71058 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71059 + task->acl != current->acl)
71060 + return 1;
71061 +
71062 + return 0;
71063 +}
71064 +
71065 +int
71066 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71067 +{
71068 + struct task_struct *p;
71069 + int ret = 0;
71070 +
71071 + if (unlikely(!(gr_status & GR_READY) || !pid))
71072 + return ret;
71073 +
71074 + read_lock(&tasklist_lock);
71075 + do_each_pid_task(pid, type, p) {
71076 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71077 + p->acl != current->acl) {
71078 + ret = 1;
71079 + goto out;
71080 + }
71081 + } while_each_pid_task(pid, type, p);
71082 +out:
71083 + read_unlock(&tasklist_lock);
71084 +
71085 + return ret;
71086 +}
71087 +
71088 +void
71089 +gr_copy_label(struct task_struct *tsk)
71090 +{
71091 + struct task_struct *p = current;
71092 +
71093 + tsk->inherited = p->inherited;
71094 + tsk->acl_sp_role = 0;
71095 + tsk->acl_role_id = p->acl_role_id;
71096 + tsk->acl = p->acl;
71097 + tsk->role = p->role;
71098 + tsk->signal->used_accept = 0;
71099 + tsk->signal->curr_ip = p->signal->curr_ip;
71100 + tsk->signal->saved_ip = p->signal->saved_ip;
71101 + if (p->exec_file)
71102 + get_file(p->exec_file);
71103 + tsk->exec_file = p->exec_file;
71104 + tsk->is_writable = p->is_writable;
71105 + if (unlikely(p->signal->used_accept)) {
71106 + p->signal->curr_ip = 0;
71107 + p->signal->saved_ip = 0;
71108 + }
71109 +
71110 + return;
71111 +}
71112 +
71113 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71114 +
71115 +int
71116 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71117 +{
71118 + unsigned int i;
71119 + __u16 num;
71120 + uid_t *uidlist;
71121 + uid_t curuid;
71122 + int realok = 0;
71123 + int effectiveok = 0;
71124 + int fsok = 0;
71125 + uid_t globalreal, globaleffective, globalfs;
71126 +
71127 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71128 + struct user_struct *user;
71129 +
71130 + if (!uid_valid(real))
71131 + goto skipit;
71132 +
71133 + /* find user based on global namespace */
71134 +
71135 + globalreal = GR_GLOBAL_UID(real);
71136 +
71137 + user = find_user(make_kuid(&init_user_ns, globalreal));
71138 + if (user == NULL)
71139 + goto skipit;
71140 +
71141 + if (gr_process_kernel_setuid_ban(user)) {
71142 + /* for find_user */
71143 + free_uid(user);
71144 + return 1;
71145 + }
71146 +
71147 + /* for find_user */
71148 + free_uid(user);
71149 +
71150 +skipit:
71151 +#endif
71152 +
71153 + if (unlikely(!(gr_status & GR_READY)))
71154 + return 0;
71155 +
71156 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71157 + gr_log_learn_uid_change(real, effective, fs);
71158 +
71159 + num = current->acl->user_trans_num;
71160 + uidlist = current->acl->user_transitions;
71161 +
71162 + if (uidlist == NULL)
71163 + return 0;
71164 +
71165 + if (!uid_valid(real)) {
71166 + realok = 1;
71167 + globalreal = (uid_t)-1;
71168 + } else {
71169 + globalreal = GR_GLOBAL_UID(real);
71170 + }
71171 + if (!uid_valid(effective)) {
71172 + effectiveok = 1;
71173 + globaleffective = (uid_t)-1;
71174 + } else {
71175 + globaleffective = GR_GLOBAL_UID(effective);
71176 + }
71177 + if (!uid_valid(fs)) {
71178 + fsok = 1;
71179 + globalfs = (uid_t)-1;
71180 + } else {
71181 + globalfs = GR_GLOBAL_UID(fs);
71182 + }
71183 +
71184 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71185 + for (i = 0; i < num; i++) {
71186 + curuid = uidlist[i];
71187 + if (globalreal == curuid)
71188 + realok = 1;
71189 + if (globaleffective == curuid)
71190 + effectiveok = 1;
71191 + if (globalfs == curuid)
71192 + fsok = 1;
71193 + }
71194 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71195 + for (i = 0; i < num; i++) {
71196 + curuid = uidlist[i];
71197 + if (globalreal == curuid)
71198 + break;
71199 + if (globaleffective == curuid)
71200 + break;
71201 + if (globalfs == curuid)
71202 + break;
71203 + }
71204 + /* not in deny list */
71205 + if (i == num) {
71206 + realok = 1;
71207 + effectiveok = 1;
71208 + fsok = 1;
71209 + }
71210 + }
71211 +
71212 + if (realok && effectiveok && fsok)
71213 + return 0;
71214 + else {
71215 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71216 + return 1;
71217 + }
71218 +}
71219 +
71220 +int
71221 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71222 +{
71223 + unsigned int i;
71224 + __u16 num;
71225 + gid_t *gidlist;
71226 + gid_t curgid;
71227 + int realok = 0;
71228 + int effectiveok = 0;
71229 + int fsok = 0;
71230 + gid_t globalreal, globaleffective, globalfs;
71231 +
71232 + if (unlikely(!(gr_status & GR_READY)))
71233 + return 0;
71234 +
71235 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71236 + gr_log_learn_gid_change(real, effective, fs);
71237 +
71238 + num = current->acl->group_trans_num;
71239 + gidlist = current->acl->group_transitions;
71240 +
71241 + if (gidlist == NULL)
71242 + return 0;
71243 +
71244 + if (!gid_valid(real)) {
71245 + realok = 1;
71246 + globalreal = (gid_t)-1;
71247 + } else {
71248 + globalreal = GR_GLOBAL_GID(real);
71249 + }
71250 + if (!gid_valid(effective)) {
71251 + effectiveok = 1;
71252 + globaleffective = (gid_t)-1;
71253 + } else {
71254 + globaleffective = GR_GLOBAL_GID(effective);
71255 + }
71256 + if (!gid_valid(fs)) {
71257 + fsok = 1;
71258 + globalfs = (gid_t)-1;
71259 + } else {
71260 + globalfs = GR_GLOBAL_GID(fs);
71261 + }
71262 +
71263 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71264 + for (i = 0; i < num; i++) {
71265 + curgid = gidlist[i];
71266 + if (globalreal == curgid)
71267 + realok = 1;
71268 + if (globaleffective == curgid)
71269 + effectiveok = 1;
71270 + if (globalfs == curgid)
71271 + fsok = 1;
71272 + }
71273 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71274 + for (i = 0; i < num; i++) {
71275 + curgid = gidlist[i];
71276 + if (globalreal == curgid)
71277 + break;
71278 + if (globaleffective == curgid)
71279 + break;
71280 + if (globalfs == curgid)
71281 + break;
71282 + }
71283 + /* not in deny list */
71284 + if (i == num) {
71285 + realok = 1;
71286 + effectiveok = 1;
71287 + fsok = 1;
71288 + }
71289 + }
71290 +
71291 + if (realok && effectiveok && fsok)
71292 + return 0;
71293 + else {
71294 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71295 + return 1;
71296 + }
71297 +}
71298 +
71299 +extern int gr_acl_is_capable(const int cap);
71300 +
71301 +void
71302 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71303 +{
71304 + struct acl_role_label *role = task->role;
71305 + struct acl_role_label *origrole = role;
71306 + struct acl_subject_label *subj = NULL;
71307 + struct acl_object_label *obj;
71308 + struct file *filp;
71309 + uid_t uid;
71310 + gid_t gid;
71311 +
71312 + if (unlikely(!(gr_status & GR_READY)))
71313 + return;
71314 +
71315 + uid = GR_GLOBAL_UID(kuid);
71316 + gid = GR_GLOBAL_GID(kgid);
71317 +
71318 + filp = task->exec_file;
71319 +
71320 + /* kernel process, we'll give them the kernel role */
71321 + if (unlikely(!filp)) {
71322 + task->role = running_polstate.kernel_role;
71323 + task->acl = running_polstate.kernel_role->root_label;
71324 + return;
71325 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71326 + /* save the current ip at time of role lookup so that the proper
71327 + IP will be learned for role_allowed_ip */
71328 + task->signal->saved_ip = task->signal->curr_ip;
71329 + role = lookup_acl_role_label(task, uid, gid);
71330 + }
71331 +
71332 + /* don't change the role if we're not a privileged process */
71333 + if (role && task->role != role &&
71334 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71335 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71336 + return;
71337 +
71338 + task->role = role;
71339 +
71340 + if (task->inherited) {
71341 + /* if we reached our subject through inheritance, then first see
71342 + if there's a subject of the same name in the new role that has
71343 + an object that would result in the same inherited subject
71344 + */
71345 + subj = gr_get_subject_for_task(task, task->acl->filename, 0);
71346 + if (subj) {
71347 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, subj);
71348 + if (!(obj->mode & GR_INHERIT))
71349 + subj = NULL;
71350 + }
71351 +
71352 + }
71353 + if (subj == NULL) {
71354 + /* otherwise:
71355 + perform subject lookup in possibly new role
71356 + we can use this result below in the case where role == task->role
71357 + */
71358 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71359 + }
71360 +
71361 + /* if we changed uid/gid, but result in the same role
71362 + and are using inheritance, don't lose the inherited subject
71363 + if current subject is other than what normal lookup
71364 + would result in, we arrived via inheritance, don't
71365 + lose subject
71366 + */
71367 + if (role != origrole || (!(task->acl->mode & GR_INHERITLEARN) &&
71368 + (subj == task->acl)))
71369 + task->acl = subj;
71370 +
71371 + /* leave task->inherited unaffected */
71372 +
71373 + task->is_writable = 0;
71374 +
71375 + /* ignore additional mmap checks for processes that are writable
71376 + by the default ACL */
71377 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71378 + if (unlikely(obj->mode & GR_WRITE))
71379 + task->is_writable = 1;
71380 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71381 + if (unlikely(obj->mode & GR_WRITE))
71382 + task->is_writable = 1;
71383 +
71384 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71385 + 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);
71386 +#endif
71387 +
71388 + gr_set_proc_res(task);
71389 +
71390 + return;
71391 +}
71392 +
71393 +int
71394 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71395 + const int unsafe_flags)
71396 +{
71397 + struct task_struct *task = current;
71398 + struct acl_subject_label *newacl;
71399 + struct acl_object_label *obj;
71400 + __u32 retmode;
71401 +
71402 + if (unlikely(!(gr_status & GR_READY)))
71403 + return 0;
71404 +
71405 + newacl = chk_subj_label(dentry, mnt, task->role);
71406 +
71407 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71408 + did an exec
71409 + */
71410 + rcu_read_lock();
71411 + read_lock(&tasklist_lock);
71412 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71413 + (task->parent->acl->mode & GR_POVERRIDE))) {
71414 + read_unlock(&tasklist_lock);
71415 + rcu_read_unlock();
71416 + goto skip_check;
71417 + }
71418 + read_unlock(&tasklist_lock);
71419 + rcu_read_unlock();
71420 +
71421 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71422 + !(task->role->roletype & GR_ROLE_GOD) &&
71423 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71424 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71425 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71426 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71427 + else
71428 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71429 + return -EACCES;
71430 + }
71431 +
71432 +skip_check:
71433 +
71434 + obj = chk_obj_label(dentry, mnt, task->acl);
71435 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71436 +
71437 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71438 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71439 + if (obj->nested)
71440 + task->acl = obj->nested;
71441 + else
71442 + task->acl = newacl;
71443 + task->inherited = 0;
71444 + } else {
71445 + task->inherited = 1;
71446 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71447 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71448 + }
71449 +
71450 + task->is_writable = 0;
71451 +
71452 + /* ignore additional mmap checks for processes that are writable
71453 + by the default ACL */
71454 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71455 + if (unlikely(obj->mode & GR_WRITE))
71456 + task->is_writable = 1;
71457 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71458 + if (unlikely(obj->mode & GR_WRITE))
71459 + task->is_writable = 1;
71460 +
71461 + gr_set_proc_res(task);
71462 +
71463 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71464 + 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);
71465 +#endif
71466 + return 0;
71467 +}
71468 +
71469 +/* always called with valid inodev ptr */
71470 +static void
71471 +do_handle_delete(struct inodev_entry *inodev, const u64 ino, const dev_t dev)
71472 +{
71473 + struct acl_object_label *matchpo;
71474 + struct acl_subject_label *matchps;
71475 + struct acl_subject_label *subj;
71476 + struct acl_role_label *role;
71477 + unsigned int x;
71478 +
71479 + FOR_EACH_ROLE_START(role)
71480 + FOR_EACH_SUBJECT_START(role, subj, x)
71481 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71482 + matchpo->mode |= GR_DELETED;
71483 + FOR_EACH_SUBJECT_END(subj,x)
71484 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71485 + /* nested subjects aren't in the role's subj_hash table */
71486 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71487 + matchpo->mode |= GR_DELETED;
71488 + FOR_EACH_NESTED_SUBJECT_END(subj)
71489 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71490 + matchps->mode |= GR_DELETED;
71491 + FOR_EACH_ROLE_END(role)
71492 +
71493 + inodev->nentry->deleted = 1;
71494 +
71495 + return;
71496 +}
71497 +
71498 +void
71499 +gr_handle_delete(const u64 ino, const dev_t dev)
71500 +{
71501 + struct inodev_entry *inodev;
71502 +
71503 + if (unlikely(!(gr_status & GR_READY)))
71504 + return;
71505 +
71506 + write_lock(&gr_inode_lock);
71507 + inodev = lookup_inodev_entry(ino, dev);
71508 + if (inodev != NULL)
71509 + do_handle_delete(inodev, ino, dev);
71510 + write_unlock(&gr_inode_lock);
71511 +
71512 + return;
71513 +}
71514 +
71515 +static void
71516 +update_acl_obj_label(const u64 oldinode, const dev_t olddevice,
71517 + const u64 newinode, const dev_t newdevice,
71518 + struct acl_subject_label *subj)
71519 +{
71520 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71521 + struct acl_object_label *match;
71522 +
71523 + match = subj->obj_hash[index];
71524 +
71525 + while (match && (match->inode != oldinode ||
71526 + match->device != olddevice ||
71527 + !(match->mode & GR_DELETED)))
71528 + match = match->next;
71529 +
71530 + if (match && (match->inode == oldinode)
71531 + && (match->device == olddevice)
71532 + && (match->mode & GR_DELETED)) {
71533 + if (match->prev == NULL) {
71534 + subj->obj_hash[index] = match->next;
71535 + if (match->next != NULL)
71536 + match->next->prev = NULL;
71537 + } else {
71538 + match->prev->next = match->next;
71539 + if (match->next != NULL)
71540 + match->next->prev = match->prev;
71541 + }
71542 + match->prev = NULL;
71543 + match->next = NULL;
71544 + match->inode = newinode;
71545 + match->device = newdevice;
71546 + match->mode &= ~GR_DELETED;
71547 +
71548 + insert_acl_obj_label(match, subj);
71549 + }
71550 +
71551 + return;
71552 +}
71553 +
71554 +static void
71555 +update_acl_subj_label(const u64 oldinode, const dev_t olddevice,
71556 + const u64 newinode, const dev_t newdevice,
71557 + struct acl_role_label *role)
71558 +{
71559 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71560 + struct acl_subject_label *match;
71561 +
71562 + match = role->subj_hash[index];
71563 +
71564 + while (match && (match->inode != oldinode ||
71565 + match->device != olddevice ||
71566 + !(match->mode & GR_DELETED)))
71567 + match = match->next;
71568 +
71569 + if (match && (match->inode == oldinode)
71570 + && (match->device == olddevice)
71571 + && (match->mode & GR_DELETED)) {
71572 + if (match->prev == NULL) {
71573 + role->subj_hash[index] = match->next;
71574 + if (match->next != NULL)
71575 + match->next->prev = NULL;
71576 + } else {
71577 + match->prev->next = match->next;
71578 + if (match->next != NULL)
71579 + match->next->prev = match->prev;
71580 + }
71581 + match->prev = NULL;
71582 + match->next = NULL;
71583 + match->inode = newinode;
71584 + match->device = newdevice;
71585 + match->mode &= ~GR_DELETED;
71586 +
71587 + insert_acl_subj_label(match, role);
71588 + }
71589 +
71590 + return;
71591 +}
71592 +
71593 +static void
71594 +update_inodev_entry(const u64 oldinode, const dev_t olddevice,
71595 + const u64 newinode, const dev_t newdevice)
71596 +{
71597 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71598 + struct inodev_entry *match;
71599 +
71600 + match = running_polstate.inodev_set.i_hash[index];
71601 +
71602 + while (match && (match->nentry->inode != oldinode ||
71603 + match->nentry->device != olddevice || !match->nentry->deleted))
71604 + match = match->next;
71605 +
71606 + if (match && (match->nentry->inode == oldinode)
71607 + && (match->nentry->device == olddevice) &&
71608 + match->nentry->deleted) {
71609 + if (match->prev == NULL) {
71610 + running_polstate.inodev_set.i_hash[index] = match->next;
71611 + if (match->next != NULL)
71612 + match->next->prev = NULL;
71613 + } else {
71614 + match->prev->next = match->next;
71615 + if (match->next != NULL)
71616 + match->next->prev = match->prev;
71617 + }
71618 + match->prev = NULL;
71619 + match->next = NULL;
71620 + match->nentry->inode = newinode;
71621 + match->nentry->device = newdevice;
71622 + match->nentry->deleted = 0;
71623 +
71624 + insert_inodev_entry(match);
71625 + }
71626 +
71627 + return;
71628 +}
71629 +
71630 +static void
71631 +__do_handle_create(const struct name_entry *matchn, u64 ino, dev_t dev)
71632 +{
71633 + struct acl_subject_label *subj;
71634 + struct acl_role_label *role;
71635 + unsigned int x;
71636 +
71637 + FOR_EACH_ROLE_START(role)
71638 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71639 +
71640 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71641 + if ((subj->inode == ino) && (subj->device == dev)) {
71642 + subj->inode = ino;
71643 + subj->device = dev;
71644 + }
71645 + /* nested subjects aren't in the role's subj_hash table */
71646 + update_acl_obj_label(matchn->inode, matchn->device,
71647 + ino, dev, subj);
71648 + FOR_EACH_NESTED_SUBJECT_END(subj)
71649 + FOR_EACH_SUBJECT_START(role, subj, x)
71650 + update_acl_obj_label(matchn->inode, matchn->device,
71651 + ino, dev, subj);
71652 + FOR_EACH_SUBJECT_END(subj,x)
71653 + FOR_EACH_ROLE_END(role)
71654 +
71655 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71656 +
71657 + return;
71658 +}
71659 +
71660 +static void
71661 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71662 + const struct vfsmount *mnt)
71663 +{
71664 + u64 ino = __get_ino(dentry);
71665 + dev_t dev = __get_dev(dentry);
71666 +
71667 + __do_handle_create(matchn, ino, dev);
71668 +
71669 + return;
71670 +}
71671 +
71672 +void
71673 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71674 +{
71675 + struct name_entry *matchn;
71676 +
71677 + if (unlikely(!(gr_status & GR_READY)))
71678 + return;
71679 +
71680 + preempt_disable();
71681 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71682 +
71683 + if (unlikely((unsigned long)matchn)) {
71684 + write_lock(&gr_inode_lock);
71685 + do_handle_create(matchn, dentry, mnt);
71686 + write_unlock(&gr_inode_lock);
71687 + }
71688 + preempt_enable();
71689 +
71690 + return;
71691 +}
71692 +
71693 +void
71694 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71695 +{
71696 + struct name_entry *matchn;
71697 +
71698 + if (unlikely(!(gr_status & GR_READY)))
71699 + return;
71700 +
71701 + preempt_disable();
71702 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71703 +
71704 + if (unlikely((unsigned long)matchn)) {
71705 + write_lock(&gr_inode_lock);
71706 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71707 + write_unlock(&gr_inode_lock);
71708 + }
71709 + preempt_enable();
71710 +
71711 + return;
71712 +}
71713 +
71714 +void
71715 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71716 + struct dentry *old_dentry,
71717 + struct dentry *new_dentry,
71718 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71719 +{
71720 + struct name_entry *matchn;
71721 + struct name_entry *matchn2 = NULL;
71722 + struct inodev_entry *inodev;
71723 + struct inode *inode = new_dentry->d_inode;
71724 + u64 old_ino = __get_ino(old_dentry);
71725 + dev_t old_dev = __get_dev(old_dentry);
71726 + unsigned int exchange = flags & RENAME_EXCHANGE;
71727 +
71728 + /* vfs_rename swaps the name and parent link for old_dentry and
71729 + new_dentry
71730 + at this point, old_dentry has the new name, parent link, and inode
71731 + for the renamed file
71732 + if a file is being replaced by a rename, new_dentry has the inode
71733 + and name for the replaced file
71734 + */
71735 +
71736 + if (unlikely(!(gr_status & GR_READY)))
71737 + return;
71738 +
71739 + preempt_disable();
71740 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71741 +
71742 + /* exchange cases:
71743 + a filename exists for the source, but not dest
71744 + do a recreate on source
71745 + a filename exists for the dest, but not source
71746 + do a recreate on dest
71747 + a filename exists for both source and dest
71748 + delete source and dest, then create source and dest
71749 + a filename exists for neither source nor dest
71750 + no updates needed
71751 +
71752 + the name entry lookups get us the old inode/dev associated with
71753 + each name, so do the deletes first (if possible) so that when
71754 + we do the create, we pick up on the right entries
71755 + */
71756 +
71757 + if (exchange)
71758 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71759 +
71760 + /* we wouldn't have to check d_inode if it weren't for
71761 + NFS silly-renaming
71762 + */
71763 +
71764 + write_lock(&gr_inode_lock);
71765 + if (unlikely((replace || exchange) && inode)) {
71766 + u64 new_ino = __get_ino(new_dentry);
71767 + dev_t new_dev = __get_dev(new_dentry);
71768 +
71769 + inodev = lookup_inodev_entry(new_ino, new_dev);
71770 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71771 + do_handle_delete(inodev, new_ino, new_dev);
71772 + }
71773 +
71774 + inodev = lookup_inodev_entry(old_ino, old_dev);
71775 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71776 + do_handle_delete(inodev, old_ino, old_dev);
71777 +
71778 + if (unlikely(matchn != NULL))
71779 + do_handle_create(matchn, old_dentry, mnt);
71780 +
71781 + if (unlikely(matchn2 != NULL))
71782 + do_handle_create(matchn2, new_dentry, mnt);
71783 +
71784 + write_unlock(&gr_inode_lock);
71785 + preempt_enable();
71786 +
71787 + return;
71788 +}
71789 +
71790 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71791 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71792 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71793 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71794 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71795 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71796 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71797 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71798 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71799 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71800 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71801 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71802 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71803 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71804 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71805 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71806 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71807 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71808 +};
71809 +
71810 +void
71811 +gr_learn_resource(const struct task_struct *task,
71812 + const int res, const unsigned long wanted, const int gt)
71813 +{
71814 + struct acl_subject_label *acl;
71815 + const struct cred *cred;
71816 +
71817 + if (unlikely((gr_status & GR_READY) &&
71818 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71819 + goto skip_reslog;
71820 +
71821 + gr_log_resource(task, res, wanted, gt);
71822 +skip_reslog:
71823 +
71824 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71825 + return;
71826 +
71827 + acl = task->acl;
71828 +
71829 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71830 + !(acl->resmask & (1U << (unsigned short) res))))
71831 + return;
71832 +
71833 + if (wanted >= acl->res[res].rlim_cur) {
71834 + unsigned long res_add;
71835 +
71836 + res_add = wanted + res_learn_bumps[res];
71837 +
71838 + acl->res[res].rlim_cur = res_add;
71839 +
71840 + if (wanted > acl->res[res].rlim_max)
71841 + acl->res[res].rlim_max = res_add;
71842 +
71843 + /* only log the subject filename, since resource logging is supported for
71844 + single-subject learning only */
71845 + rcu_read_lock();
71846 + cred = __task_cred(task);
71847 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71848 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71849 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71850 + "", (unsigned long) res, &task->signal->saved_ip);
71851 + rcu_read_unlock();
71852 + }
71853 +
71854 + return;
71855 +}
71856 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71857 +#endif
71858 +
71859 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71860 +void
71861 +pax_set_initial_flags(struct linux_binprm *bprm)
71862 +{
71863 + struct task_struct *task = current;
71864 + struct acl_subject_label *proc;
71865 + unsigned long flags;
71866 +
71867 + if (unlikely(!(gr_status & GR_READY)))
71868 + return;
71869 +
71870 + flags = pax_get_flags(task);
71871 +
71872 + proc = task->acl;
71873 +
71874 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71875 + flags &= ~MF_PAX_PAGEEXEC;
71876 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71877 + flags &= ~MF_PAX_SEGMEXEC;
71878 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71879 + flags &= ~MF_PAX_RANDMMAP;
71880 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71881 + flags &= ~MF_PAX_EMUTRAMP;
71882 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71883 + flags &= ~MF_PAX_MPROTECT;
71884 +
71885 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71886 + flags |= MF_PAX_PAGEEXEC;
71887 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71888 + flags |= MF_PAX_SEGMEXEC;
71889 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71890 + flags |= MF_PAX_RANDMMAP;
71891 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71892 + flags |= MF_PAX_EMUTRAMP;
71893 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71894 + flags |= MF_PAX_MPROTECT;
71895 +
71896 + pax_set_flags(task, flags);
71897 +
71898 + return;
71899 +}
71900 +#endif
71901 +
71902 +int
71903 +gr_handle_proc_ptrace(struct task_struct *task)
71904 +{
71905 + struct file *filp;
71906 + struct task_struct *tmp = task;
71907 + struct task_struct *curtemp = current;
71908 + __u32 retmode;
71909 +
71910 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71911 + if (unlikely(!(gr_status & GR_READY)))
71912 + return 0;
71913 +#endif
71914 +
71915 + read_lock(&tasklist_lock);
71916 + read_lock(&grsec_exec_file_lock);
71917 + filp = task->exec_file;
71918 +
71919 + while (task_pid_nr(tmp) > 0) {
71920 + if (tmp == curtemp)
71921 + break;
71922 + tmp = tmp->real_parent;
71923 + }
71924 +
71925 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71926 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71927 + read_unlock(&grsec_exec_file_lock);
71928 + read_unlock(&tasklist_lock);
71929 + return 1;
71930 + }
71931 +
71932 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71933 + if (!(gr_status & GR_READY)) {
71934 + read_unlock(&grsec_exec_file_lock);
71935 + read_unlock(&tasklist_lock);
71936 + return 0;
71937 + }
71938 +#endif
71939 +
71940 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71941 + read_unlock(&grsec_exec_file_lock);
71942 + read_unlock(&tasklist_lock);
71943 +
71944 + if (retmode & GR_NOPTRACE)
71945 + return 1;
71946 +
71947 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71948 + && (current->acl != task->acl || (current->acl != current->role->root_label
71949 + && task_pid_nr(current) != task_pid_nr(task))))
71950 + return 1;
71951 +
71952 + return 0;
71953 +}
71954 +
71955 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71956 +{
71957 + if (unlikely(!(gr_status & GR_READY)))
71958 + return;
71959 +
71960 + if (!(current->role->roletype & GR_ROLE_GOD))
71961 + return;
71962 +
71963 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71964 + p->role->rolename, gr_task_roletype_to_char(p),
71965 + p->acl->filename);
71966 +}
71967 +
71968 +int
71969 +gr_handle_ptrace(struct task_struct *task, const long request)
71970 +{
71971 + struct task_struct *tmp = task;
71972 + struct task_struct *curtemp = current;
71973 + __u32 retmode;
71974 +
71975 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71976 + if (unlikely(!(gr_status & GR_READY)))
71977 + return 0;
71978 +#endif
71979 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71980 + read_lock(&tasklist_lock);
71981 + while (task_pid_nr(tmp) > 0) {
71982 + if (tmp == curtemp)
71983 + break;
71984 + tmp = tmp->real_parent;
71985 + }
71986 +
71987 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71988 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71989 + read_unlock(&tasklist_lock);
71990 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71991 + return 1;
71992 + }
71993 + read_unlock(&tasklist_lock);
71994 + }
71995 +
71996 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71997 + if (!(gr_status & GR_READY))
71998 + return 0;
71999 +#endif
72000 +
72001 + read_lock(&grsec_exec_file_lock);
72002 + if (unlikely(!task->exec_file)) {
72003 + read_unlock(&grsec_exec_file_lock);
72004 + return 0;
72005 + }
72006 +
72007 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72008 + read_unlock(&grsec_exec_file_lock);
72009 +
72010 + if (retmode & GR_NOPTRACE) {
72011 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72012 + return 1;
72013 + }
72014 +
72015 + if (retmode & GR_PTRACERD) {
72016 + switch (request) {
72017 + case PTRACE_SEIZE:
72018 + case PTRACE_POKETEXT:
72019 + case PTRACE_POKEDATA:
72020 + case PTRACE_POKEUSR:
72021 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72022 + case PTRACE_SETREGS:
72023 + case PTRACE_SETFPREGS:
72024 +#endif
72025 +#ifdef CONFIG_X86
72026 + case PTRACE_SETFPXREGS:
72027 +#endif
72028 +#ifdef CONFIG_ALTIVEC
72029 + case PTRACE_SETVRREGS:
72030 +#endif
72031 + return 1;
72032 + default:
72033 + return 0;
72034 + }
72035 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72036 + !(current->role->roletype & GR_ROLE_GOD) &&
72037 + (current->acl != task->acl)) {
72038 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72039 + return 1;
72040 + }
72041 +
72042 + return 0;
72043 +}
72044 +
72045 +static int is_writable_mmap(const struct file *filp)
72046 +{
72047 + struct task_struct *task = current;
72048 + struct acl_object_label *obj, *obj2;
72049 +
72050 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72051 + !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))) {
72052 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72053 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72054 + task->role->root_label);
72055 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72056 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72057 + return 1;
72058 + }
72059 + }
72060 + return 0;
72061 +}
72062 +
72063 +int
72064 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72065 +{
72066 + __u32 mode;
72067 +
72068 + if (unlikely(!file || !(prot & PROT_EXEC)))
72069 + return 1;
72070 +
72071 + if (is_writable_mmap(file))
72072 + return 0;
72073 +
72074 + mode =
72075 + gr_search_file(file->f_path.dentry,
72076 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72077 + file->f_path.mnt);
72078 +
72079 + if (!gr_tpe_allow(file))
72080 + return 0;
72081 +
72082 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72083 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72084 + return 0;
72085 + } else if (unlikely(!(mode & GR_EXEC))) {
72086 + return 0;
72087 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72088 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72089 + return 1;
72090 + }
72091 +
72092 + return 1;
72093 +}
72094 +
72095 +int
72096 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72097 +{
72098 + __u32 mode;
72099 +
72100 + if (unlikely(!file || !(prot & PROT_EXEC)))
72101 + return 1;
72102 +
72103 + if (is_writable_mmap(file))
72104 + return 0;
72105 +
72106 + mode =
72107 + gr_search_file(file->f_path.dentry,
72108 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72109 + file->f_path.mnt);
72110 +
72111 + if (!gr_tpe_allow(file))
72112 + return 0;
72113 +
72114 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72115 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72116 + return 0;
72117 + } else if (unlikely(!(mode & GR_EXEC))) {
72118 + return 0;
72119 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72120 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72121 + return 1;
72122 + }
72123 +
72124 + return 1;
72125 +}
72126 +
72127 +void
72128 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72129 +{
72130 + unsigned long runtime, cputime;
72131 + cputime_t utime, stime;
72132 + unsigned int wday, cday;
72133 + __u8 whr, chr;
72134 + __u8 wmin, cmin;
72135 + __u8 wsec, csec;
72136 + struct timespec curtime, starttime;
72137 +
72138 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72139 + !(task->acl->mode & GR_PROCACCT)))
72140 + return;
72141 +
72142 + curtime = ns_to_timespec(ktime_get_ns());
72143 + starttime = ns_to_timespec(task->start_time);
72144 + runtime = curtime.tv_sec - starttime.tv_sec;
72145 + wday = runtime / (60 * 60 * 24);
72146 + runtime -= wday * (60 * 60 * 24);
72147 + whr = runtime / (60 * 60);
72148 + runtime -= whr * (60 * 60);
72149 + wmin = runtime / 60;
72150 + runtime -= wmin * 60;
72151 + wsec = runtime;
72152 +
72153 + task_cputime(task, &utime, &stime);
72154 + cputime = cputime_to_secs(utime + stime);
72155 + cday = cputime / (60 * 60 * 24);
72156 + cputime -= cday * (60 * 60 * 24);
72157 + chr = cputime / (60 * 60);
72158 + cputime -= chr * (60 * 60);
72159 + cmin = cputime / 60;
72160 + cputime -= cmin * 60;
72161 + csec = cputime;
72162 +
72163 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72164 +
72165 + return;
72166 +}
72167 +
72168 +#ifdef CONFIG_TASKSTATS
72169 +int gr_is_taskstats_denied(int pid)
72170 +{
72171 + struct task_struct *task;
72172 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72173 + const struct cred *cred;
72174 +#endif
72175 + int ret = 0;
72176 +
72177 + /* restrict taskstats viewing to un-chrooted root users
72178 + who have the 'view' subject flag if the RBAC system is enabled
72179 + */
72180 +
72181 + rcu_read_lock();
72182 + read_lock(&tasklist_lock);
72183 + task = find_task_by_vpid(pid);
72184 + if (task) {
72185 +#ifdef CONFIG_GRKERNSEC_CHROOT
72186 + if (proc_is_chrooted(task))
72187 + ret = -EACCES;
72188 +#endif
72189 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72190 + cred = __task_cred(task);
72191 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72192 + if (gr_is_global_nonroot(cred->uid))
72193 + ret = -EACCES;
72194 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72195 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72196 + ret = -EACCES;
72197 +#endif
72198 +#endif
72199 + if (gr_status & GR_READY) {
72200 + if (!(task->acl->mode & GR_VIEW))
72201 + ret = -EACCES;
72202 + }
72203 + } else
72204 + ret = -ENOENT;
72205 +
72206 + read_unlock(&tasklist_lock);
72207 + rcu_read_unlock();
72208 +
72209 + return ret;
72210 +}
72211 +#endif
72212 +
72213 +/* AUXV entries are filled via a descendant of search_binary_handler
72214 + after we've already applied the subject for the target
72215 +*/
72216 +int gr_acl_enable_at_secure(void)
72217 +{
72218 + if (unlikely(!(gr_status & GR_READY)))
72219 + return 0;
72220 +
72221 + if (current->acl->mode & GR_ATSECURE)
72222 + return 1;
72223 +
72224 + return 0;
72225 +}
72226 +
72227 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const u64 ino)
72228 +{
72229 + struct task_struct *task = current;
72230 + struct dentry *dentry = file->f_path.dentry;
72231 + struct vfsmount *mnt = file->f_path.mnt;
72232 + struct acl_object_label *obj, *tmp;
72233 + struct acl_subject_label *subj;
72234 + unsigned int bufsize;
72235 + int is_not_root;
72236 + char *path;
72237 + dev_t dev = __get_dev(dentry);
72238 +
72239 + if (unlikely(!(gr_status & GR_READY)))
72240 + return 1;
72241 +
72242 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72243 + return 1;
72244 +
72245 + /* ignore Eric Biederman */
72246 + if (IS_PRIVATE(dentry->d_inode))
72247 + return 1;
72248 +
72249 + subj = task->acl;
72250 + read_lock(&gr_inode_lock);
72251 + do {
72252 + obj = lookup_acl_obj_label(ino, dev, subj);
72253 + if (obj != NULL) {
72254 + read_unlock(&gr_inode_lock);
72255 + return (obj->mode & GR_FIND) ? 1 : 0;
72256 + }
72257 + } while ((subj = subj->parent_subject));
72258 + read_unlock(&gr_inode_lock);
72259 +
72260 + /* this is purely an optimization since we're looking for an object
72261 + for the directory we're doing a readdir on
72262 + if it's possible for any globbed object to match the entry we're
72263 + filling into the directory, then the object we find here will be
72264 + an anchor point with attached globbed objects
72265 + */
72266 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72267 + if (obj->globbed == NULL)
72268 + return (obj->mode & GR_FIND) ? 1 : 0;
72269 +
72270 + is_not_root = ((obj->filename[0] == '/') &&
72271 + (obj->filename[1] == '\0')) ? 0 : 1;
72272 + bufsize = PAGE_SIZE - namelen - is_not_root;
72273 +
72274 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72275 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72276 + return 1;
72277 +
72278 + preempt_disable();
72279 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72280 + bufsize);
72281 +
72282 + bufsize = strlen(path);
72283 +
72284 + /* if base is "/", don't append an additional slash */
72285 + if (is_not_root)
72286 + *(path + bufsize) = '/';
72287 + memcpy(path + bufsize + is_not_root, name, namelen);
72288 + *(path + bufsize + namelen + is_not_root) = '\0';
72289 +
72290 + tmp = obj->globbed;
72291 + while (tmp) {
72292 + if (!glob_match(tmp->filename, path)) {
72293 + preempt_enable();
72294 + return (tmp->mode & GR_FIND) ? 1 : 0;
72295 + }
72296 + tmp = tmp->next;
72297 + }
72298 + preempt_enable();
72299 + return (obj->mode & GR_FIND) ? 1 : 0;
72300 +}
72301 +
72302 +void gr_put_exec_file(struct task_struct *task)
72303 +{
72304 + struct file *filp;
72305 +
72306 + write_lock(&grsec_exec_file_lock);
72307 + filp = task->exec_file;
72308 + task->exec_file = NULL;
72309 + write_unlock(&grsec_exec_file_lock);
72310 +
72311 + if (filp)
72312 + fput(filp);
72313 +
72314 + return;
72315 +}
72316 +
72317 +
72318 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72319 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72320 +#endif
72321 +#ifdef CONFIG_SECURITY
72322 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72323 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72324 +#endif
72325 +
72326 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72327 new file mode 100644
72328 index 0000000..18ffbbd
72329 --- /dev/null
72330 +++ b/grsecurity/gracl_alloc.c
72331 @@ -0,0 +1,105 @@
72332 +#include <linux/kernel.h>
72333 +#include <linux/mm.h>
72334 +#include <linux/slab.h>
72335 +#include <linux/vmalloc.h>
72336 +#include <linux/gracl.h>
72337 +#include <linux/grsecurity.h>
72338 +
72339 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72340 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72341 +
72342 +static __inline__ int
72343 +alloc_pop(void)
72344 +{
72345 + if (current_alloc_state->alloc_stack_next == 1)
72346 + return 0;
72347 +
72348 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72349 +
72350 + current_alloc_state->alloc_stack_next--;
72351 +
72352 + return 1;
72353 +}
72354 +
72355 +static __inline__ int
72356 +alloc_push(void *buf)
72357 +{
72358 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72359 + return 1;
72360 +
72361 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72362 +
72363 + current_alloc_state->alloc_stack_next++;
72364 +
72365 + return 0;
72366 +}
72367 +
72368 +void *
72369 +acl_alloc(unsigned long len)
72370 +{
72371 + void *ret = NULL;
72372 +
72373 + if (!len || len > PAGE_SIZE)
72374 + goto out;
72375 +
72376 + ret = kmalloc(len, GFP_KERNEL);
72377 +
72378 + if (ret) {
72379 + if (alloc_push(ret)) {
72380 + kfree(ret);
72381 + ret = NULL;
72382 + }
72383 + }
72384 +
72385 +out:
72386 + return ret;
72387 +}
72388 +
72389 +void *
72390 +acl_alloc_num(unsigned long num, unsigned long len)
72391 +{
72392 + if (!len || (num > (PAGE_SIZE / len)))
72393 + return NULL;
72394 +
72395 + return acl_alloc(num * len);
72396 +}
72397 +
72398 +void
72399 +acl_free_all(void)
72400 +{
72401 + if (!current_alloc_state->alloc_stack)
72402 + return;
72403 +
72404 + while (alloc_pop()) ;
72405 +
72406 + if (current_alloc_state->alloc_stack) {
72407 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72408 + kfree(current_alloc_state->alloc_stack);
72409 + else
72410 + vfree(current_alloc_state->alloc_stack);
72411 + }
72412 +
72413 + current_alloc_state->alloc_stack = NULL;
72414 + current_alloc_state->alloc_stack_size = 1;
72415 + current_alloc_state->alloc_stack_next = 1;
72416 +
72417 + return;
72418 +}
72419 +
72420 +int
72421 +acl_alloc_stack_init(unsigned long size)
72422 +{
72423 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72424 + current_alloc_state->alloc_stack =
72425 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72426 + else
72427 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72428 +
72429 + current_alloc_state->alloc_stack_size = size;
72430 + current_alloc_state->alloc_stack_next = 1;
72431 +
72432 + if (!current_alloc_state->alloc_stack)
72433 + return 0;
72434 + else
72435 + return 1;
72436 +}
72437 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72438 new file mode 100644
72439 index 0000000..1a94c11
72440 --- /dev/null
72441 +++ b/grsecurity/gracl_cap.c
72442 @@ -0,0 +1,127 @@
72443 +#include <linux/kernel.h>
72444 +#include <linux/module.h>
72445 +#include <linux/sched.h>
72446 +#include <linux/gracl.h>
72447 +#include <linux/grsecurity.h>
72448 +#include <linux/grinternal.h>
72449 +
72450 +extern const char *captab_log[];
72451 +extern int captab_log_entries;
72452 +
72453 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72454 +{
72455 + struct acl_subject_label *curracl;
72456 +
72457 + if (!gr_acl_is_enabled())
72458 + return 1;
72459 +
72460 + curracl = task->acl;
72461 +
72462 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72463 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72464 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72465 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72466 + gr_to_filename(task->exec_file->f_path.dentry,
72467 + task->exec_file->f_path.mnt) : curracl->filename,
72468 + curracl->filename, 0UL,
72469 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72470 + return 1;
72471 + }
72472 +
72473 + return 0;
72474 +}
72475 +
72476 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72477 +{
72478 + struct acl_subject_label *curracl;
72479 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72480 + kernel_cap_t cap_audit = __cap_empty_set;
72481 +
72482 + if (!gr_acl_is_enabled())
72483 + return 1;
72484 +
72485 + curracl = task->acl;
72486 +
72487 + cap_drop = curracl->cap_lower;
72488 + cap_mask = curracl->cap_mask;
72489 + cap_audit = curracl->cap_invert_audit;
72490 +
72491 + while ((curracl = curracl->parent_subject)) {
72492 + /* if the cap isn't specified in the current computed mask but is specified in the
72493 + current level subject, and is lowered in the current level subject, then add
72494 + it to the set of dropped capabilities
72495 + otherwise, add the current level subject's mask to the current computed mask
72496 + */
72497 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72498 + cap_raise(cap_mask, cap);
72499 + if (cap_raised(curracl->cap_lower, cap))
72500 + cap_raise(cap_drop, cap);
72501 + if (cap_raised(curracl->cap_invert_audit, cap))
72502 + cap_raise(cap_audit, cap);
72503 + }
72504 + }
72505 +
72506 + if (!cap_raised(cap_drop, cap)) {
72507 + if (cap_raised(cap_audit, cap))
72508 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72509 + return 1;
72510 + }
72511 +
72512 + /* only learn the capability use if the process has the capability in the
72513 + general case, the two uses in sys.c of gr_learn_cap are an exception
72514 + to this rule to ensure any role transition involves what the full-learned
72515 + policy believes in a privileged process
72516 + */
72517 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72518 + return 1;
72519 +
72520 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72521 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72522 +
72523 + return 0;
72524 +}
72525 +
72526 +int
72527 +gr_acl_is_capable(const int cap)
72528 +{
72529 + return gr_task_acl_is_capable(current, current_cred(), cap);
72530 +}
72531 +
72532 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72533 +{
72534 + struct acl_subject_label *curracl;
72535 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72536 +
72537 + if (!gr_acl_is_enabled())
72538 + return 1;
72539 +
72540 + curracl = task->acl;
72541 +
72542 + cap_drop = curracl->cap_lower;
72543 + cap_mask = curracl->cap_mask;
72544 +
72545 + while ((curracl = curracl->parent_subject)) {
72546 + /* if the cap isn't specified in the current computed mask but is specified in the
72547 + current level subject, and is lowered in the current level subject, then add
72548 + it to the set of dropped capabilities
72549 + otherwise, add the current level subject's mask to the current computed mask
72550 + */
72551 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72552 + cap_raise(cap_mask, cap);
72553 + if (cap_raised(curracl->cap_lower, cap))
72554 + cap_raise(cap_drop, cap);
72555 + }
72556 + }
72557 +
72558 + if (!cap_raised(cap_drop, cap))
72559 + return 1;
72560 +
72561 + return 0;
72562 +}
72563 +
72564 +int
72565 +gr_acl_is_capable_nolog(const int cap)
72566 +{
72567 + return gr_task_acl_is_capable_nolog(current, cap);
72568 +}
72569 +
72570 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72571 new file mode 100644
72572 index 0000000..a43dd06
72573 --- /dev/null
72574 +++ b/grsecurity/gracl_compat.c
72575 @@ -0,0 +1,269 @@
72576 +#include <linux/kernel.h>
72577 +#include <linux/gracl.h>
72578 +#include <linux/compat.h>
72579 +#include <linux/gracl_compat.h>
72580 +
72581 +#include <asm/uaccess.h>
72582 +
72583 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72584 +{
72585 + struct gr_arg_wrapper_compat uwrapcompat;
72586 +
72587 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72588 + return -EFAULT;
72589 +
72590 + if ((uwrapcompat.version != GRSECURITY_VERSION) ||
72591 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72592 + return -EINVAL;
72593 +
72594 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72595 + uwrap->version = uwrapcompat.version;
72596 + uwrap->size = sizeof(struct gr_arg);
72597 +
72598 + return 0;
72599 +}
72600 +
72601 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72602 +{
72603 + struct gr_arg_compat argcompat;
72604 +
72605 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72606 + return -EFAULT;
72607 +
72608 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72609 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72610 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72611 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72612 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72613 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72614 +
72615 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72616 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72617 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72618 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72619 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72620 + arg->segv_device = argcompat.segv_device;
72621 + arg->segv_inode = argcompat.segv_inode;
72622 + arg->segv_uid = argcompat.segv_uid;
72623 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72624 + arg->mode = argcompat.mode;
72625 +
72626 + return 0;
72627 +}
72628 +
72629 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72630 +{
72631 + struct acl_object_label_compat objcompat;
72632 +
72633 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72634 + return -EFAULT;
72635 +
72636 + obj->filename = compat_ptr(objcompat.filename);
72637 + obj->inode = objcompat.inode;
72638 + obj->device = objcompat.device;
72639 + obj->mode = objcompat.mode;
72640 +
72641 + obj->nested = compat_ptr(objcompat.nested);
72642 + obj->globbed = compat_ptr(objcompat.globbed);
72643 +
72644 + obj->prev = compat_ptr(objcompat.prev);
72645 + obj->next = compat_ptr(objcompat.next);
72646 +
72647 + return 0;
72648 +}
72649 +
72650 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72651 +{
72652 + unsigned int i;
72653 + struct acl_subject_label_compat subjcompat;
72654 +
72655 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72656 + return -EFAULT;
72657 +
72658 + subj->filename = compat_ptr(subjcompat.filename);
72659 + subj->inode = subjcompat.inode;
72660 + subj->device = subjcompat.device;
72661 + subj->mode = subjcompat.mode;
72662 + subj->cap_mask = subjcompat.cap_mask;
72663 + subj->cap_lower = subjcompat.cap_lower;
72664 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72665 +
72666 + for (i = 0; i < GR_NLIMITS; i++) {
72667 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72668 + subj->res[i].rlim_cur = RLIM_INFINITY;
72669 + else
72670 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72671 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72672 + subj->res[i].rlim_max = RLIM_INFINITY;
72673 + else
72674 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72675 + }
72676 + subj->resmask = subjcompat.resmask;
72677 +
72678 + subj->user_trans_type = subjcompat.user_trans_type;
72679 + subj->group_trans_type = subjcompat.group_trans_type;
72680 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72681 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72682 + subj->user_trans_num = subjcompat.user_trans_num;
72683 + subj->group_trans_num = subjcompat.group_trans_num;
72684 +
72685 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72686 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72687 + subj->ip_type = subjcompat.ip_type;
72688 + subj->ips = compat_ptr(subjcompat.ips);
72689 + subj->ip_num = subjcompat.ip_num;
72690 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72691 +
72692 + subj->crashes = subjcompat.crashes;
72693 + subj->expires = subjcompat.expires;
72694 +
72695 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72696 + subj->hash = compat_ptr(subjcompat.hash);
72697 + subj->prev = compat_ptr(subjcompat.prev);
72698 + subj->next = compat_ptr(subjcompat.next);
72699 +
72700 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72701 + subj->obj_hash_size = subjcompat.obj_hash_size;
72702 + subj->pax_flags = subjcompat.pax_flags;
72703 +
72704 + return 0;
72705 +}
72706 +
72707 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72708 +{
72709 + struct acl_role_label_compat rolecompat;
72710 +
72711 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72712 + return -EFAULT;
72713 +
72714 + role->rolename = compat_ptr(rolecompat.rolename);
72715 + role->uidgid = rolecompat.uidgid;
72716 + role->roletype = rolecompat.roletype;
72717 +
72718 + role->auth_attempts = rolecompat.auth_attempts;
72719 + role->expires = rolecompat.expires;
72720 +
72721 + role->root_label = compat_ptr(rolecompat.root_label);
72722 + role->hash = compat_ptr(rolecompat.hash);
72723 +
72724 + role->prev = compat_ptr(rolecompat.prev);
72725 + role->next = compat_ptr(rolecompat.next);
72726 +
72727 + role->transitions = compat_ptr(rolecompat.transitions);
72728 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72729 + role->domain_children = compat_ptr(rolecompat.domain_children);
72730 + role->domain_child_num = rolecompat.domain_child_num;
72731 +
72732 + role->umask = rolecompat.umask;
72733 +
72734 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72735 + role->subj_hash_size = rolecompat.subj_hash_size;
72736 +
72737 + return 0;
72738 +}
72739 +
72740 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72741 +{
72742 + struct role_allowed_ip_compat roleip_compat;
72743 +
72744 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72745 + return -EFAULT;
72746 +
72747 + roleip->addr = roleip_compat.addr;
72748 + roleip->netmask = roleip_compat.netmask;
72749 +
72750 + roleip->prev = compat_ptr(roleip_compat.prev);
72751 + roleip->next = compat_ptr(roleip_compat.next);
72752 +
72753 + return 0;
72754 +}
72755 +
72756 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72757 +{
72758 + struct role_transition_compat trans_compat;
72759 +
72760 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72761 + return -EFAULT;
72762 +
72763 + trans->rolename = compat_ptr(trans_compat.rolename);
72764 +
72765 + trans->prev = compat_ptr(trans_compat.prev);
72766 + trans->next = compat_ptr(trans_compat.next);
72767 +
72768 + return 0;
72769 +
72770 +}
72771 +
72772 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72773 +{
72774 + struct gr_hash_struct_compat hash_compat;
72775 +
72776 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72777 + return -EFAULT;
72778 +
72779 + hash->table = compat_ptr(hash_compat.table);
72780 + hash->nametable = compat_ptr(hash_compat.nametable);
72781 + hash->first = compat_ptr(hash_compat.first);
72782 +
72783 + hash->table_size = hash_compat.table_size;
72784 + hash->used_size = hash_compat.used_size;
72785 +
72786 + hash->type = hash_compat.type;
72787 +
72788 + return 0;
72789 +}
72790 +
72791 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72792 +{
72793 + compat_uptr_t ptrcompat;
72794 +
72795 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72796 + return -EFAULT;
72797 +
72798 + *(void **)ptr = compat_ptr(ptrcompat);
72799 +
72800 + return 0;
72801 +}
72802 +
72803 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72804 +{
72805 + struct acl_ip_label_compat ip_compat;
72806 +
72807 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72808 + return -EFAULT;
72809 +
72810 + ip->iface = compat_ptr(ip_compat.iface);
72811 + ip->addr = ip_compat.addr;
72812 + ip->netmask = ip_compat.netmask;
72813 + ip->low = ip_compat.low;
72814 + ip->high = ip_compat.high;
72815 + ip->mode = ip_compat.mode;
72816 + ip->type = ip_compat.type;
72817 +
72818 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72819 +
72820 + ip->prev = compat_ptr(ip_compat.prev);
72821 + ip->next = compat_ptr(ip_compat.next);
72822 +
72823 + return 0;
72824 +}
72825 +
72826 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72827 +{
72828 + struct sprole_pw_compat pw_compat;
72829 +
72830 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72831 + return -EFAULT;
72832 +
72833 + pw->rolename = compat_ptr(pw_compat.rolename);
72834 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72835 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72836 +
72837 + return 0;
72838 +}
72839 +
72840 +size_t get_gr_arg_wrapper_size_compat(void)
72841 +{
72842 + return sizeof(struct gr_arg_wrapper_compat);
72843 +}
72844 +
72845 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72846 new file mode 100644
72847 index 0000000..8ee8e4f
72848 --- /dev/null
72849 +++ b/grsecurity/gracl_fs.c
72850 @@ -0,0 +1,447 @@
72851 +#include <linux/kernel.h>
72852 +#include <linux/sched.h>
72853 +#include <linux/types.h>
72854 +#include <linux/fs.h>
72855 +#include <linux/file.h>
72856 +#include <linux/stat.h>
72857 +#include <linux/grsecurity.h>
72858 +#include <linux/grinternal.h>
72859 +#include <linux/gracl.h>
72860 +
72861 +umode_t
72862 +gr_acl_umask(void)
72863 +{
72864 + if (unlikely(!gr_acl_is_enabled()))
72865 + return 0;
72866 +
72867 + return current->role->umask;
72868 +}
72869 +
72870 +__u32
72871 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72872 + const struct vfsmount * mnt)
72873 +{
72874 + __u32 mode;
72875 +
72876 + if (unlikely(d_is_negative(dentry)))
72877 + return GR_FIND;
72878 +
72879 + mode =
72880 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72881 +
72882 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72883 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72884 + return mode;
72885 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72886 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72887 + return 0;
72888 + } else if (unlikely(!(mode & GR_FIND)))
72889 + return 0;
72890 +
72891 + return GR_FIND;
72892 +}
72893 +
72894 +__u32
72895 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72896 + int acc_mode)
72897 +{
72898 + __u32 reqmode = GR_FIND;
72899 + __u32 mode;
72900 +
72901 + if (unlikely(d_is_negative(dentry)))
72902 + return reqmode;
72903 +
72904 + if (acc_mode & MAY_APPEND)
72905 + reqmode |= GR_APPEND;
72906 + else if (acc_mode & MAY_WRITE)
72907 + reqmode |= GR_WRITE;
72908 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72909 + reqmode |= GR_READ;
72910 +
72911 + mode =
72912 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72913 + mnt);
72914 +
72915 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72916 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72917 + reqmode & GR_READ ? " reading" : "",
72918 + reqmode & GR_WRITE ? " writing" : reqmode &
72919 + GR_APPEND ? " appending" : "");
72920 + return reqmode;
72921 + } else
72922 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72923 + {
72924 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72925 + reqmode & GR_READ ? " reading" : "",
72926 + reqmode & GR_WRITE ? " writing" : reqmode &
72927 + GR_APPEND ? " appending" : "");
72928 + return 0;
72929 + } else if (unlikely((mode & reqmode) != reqmode))
72930 + return 0;
72931 +
72932 + return reqmode;
72933 +}
72934 +
72935 +__u32
72936 +gr_acl_handle_creat(const struct dentry * dentry,
72937 + const struct dentry * p_dentry,
72938 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72939 + const int imode)
72940 +{
72941 + __u32 reqmode = GR_WRITE | GR_CREATE;
72942 + __u32 mode;
72943 +
72944 + if (acc_mode & MAY_APPEND)
72945 + reqmode |= GR_APPEND;
72946 + // if a directory was required or the directory already exists, then
72947 + // don't count this open as a read
72948 + if ((acc_mode & MAY_READ) &&
72949 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72950 + reqmode |= GR_READ;
72951 + if ((open_flags & O_CREAT) &&
72952 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72953 + reqmode |= GR_SETID;
72954 +
72955 + mode =
72956 + gr_check_create(dentry, p_dentry, p_mnt,
72957 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72958 +
72959 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72960 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72961 + reqmode & GR_READ ? " reading" : "",
72962 + reqmode & GR_WRITE ? " writing" : reqmode &
72963 + GR_APPEND ? " appending" : "");
72964 + return reqmode;
72965 + } else
72966 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72967 + {
72968 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72969 + reqmode & GR_READ ? " reading" : "",
72970 + reqmode & GR_WRITE ? " writing" : reqmode &
72971 + GR_APPEND ? " appending" : "");
72972 + return 0;
72973 + } else if (unlikely((mode & reqmode) != reqmode))
72974 + return 0;
72975 +
72976 + return reqmode;
72977 +}
72978 +
72979 +__u32
72980 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72981 + const int fmode)
72982 +{
72983 + __u32 mode, reqmode = GR_FIND;
72984 +
72985 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72986 + reqmode |= GR_EXEC;
72987 + if (fmode & S_IWOTH)
72988 + reqmode |= GR_WRITE;
72989 + if (fmode & S_IROTH)
72990 + reqmode |= GR_READ;
72991 +
72992 + mode =
72993 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72994 + mnt);
72995 +
72996 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72997 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72998 + reqmode & GR_READ ? " reading" : "",
72999 + reqmode & GR_WRITE ? " writing" : "",
73000 + reqmode & GR_EXEC ? " executing" : "");
73001 + return reqmode;
73002 + } else
73003 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73004 + {
73005 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73006 + reqmode & GR_READ ? " reading" : "",
73007 + reqmode & GR_WRITE ? " writing" : "",
73008 + reqmode & GR_EXEC ? " executing" : "");
73009 + return 0;
73010 + } else if (unlikely((mode & reqmode) != reqmode))
73011 + return 0;
73012 +
73013 + return reqmode;
73014 +}
73015 +
73016 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73017 +{
73018 + __u32 mode;
73019 +
73020 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73021 +
73022 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73023 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73024 + return mode;
73025 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73026 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73027 + return 0;
73028 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73029 + return 0;
73030 +
73031 + return (reqmode);
73032 +}
73033 +
73034 +__u32
73035 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73036 +{
73037 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73038 +}
73039 +
73040 +__u32
73041 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73042 +{
73043 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73044 +}
73045 +
73046 +__u32
73047 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73048 +{
73049 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73050 +}
73051 +
73052 +__u32
73053 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73054 +{
73055 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73056 +}
73057 +
73058 +__u32
73059 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73060 + umode_t *modeptr)
73061 +{
73062 + umode_t mode;
73063 +
73064 + *modeptr &= ~gr_acl_umask();
73065 + mode = *modeptr;
73066 +
73067 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73068 + return 1;
73069 +
73070 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73071 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73072 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73073 + GR_CHMOD_ACL_MSG);
73074 + } else {
73075 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73076 + }
73077 +}
73078 +
73079 +__u32
73080 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73081 +{
73082 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73083 +}
73084 +
73085 +__u32
73086 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73087 +{
73088 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73089 +}
73090 +
73091 +__u32
73092 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73093 +{
73094 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73095 +}
73096 +
73097 +__u32
73098 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73099 +{
73100 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73101 +}
73102 +
73103 +__u32
73104 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73105 +{
73106 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73107 + GR_UNIXCONNECT_ACL_MSG);
73108 +}
73109 +
73110 +/* hardlinks require at minimum create and link permission,
73111 + any additional privilege required is based on the
73112 + privilege of the file being linked to
73113 +*/
73114 +__u32
73115 +gr_acl_handle_link(const struct dentry * new_dentry,
73116 + const struct dentry * parent_dentry,
73117 + const struct vfsmount * parent_mnt,
73118 + const struct dentry * old_dentry,
73119 + const struct vfsmount * old_mnt, const struct filename *to)
73120 +{
73121 + __u32 mode;
73122 + __u32 needmode = GR_CREATE | GR_LINK;
73123 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73124 +
73125 + mode =
73126 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73127 + old_mnt);
73128 +
73129 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73130 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73131 + return mode;
73132 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73133 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73134 + return 0;
73135 + } else if (unlikely((mode & needmode) != needmode))
73136 + return 0;
73137 +
73138 + return 1;
73139 +}
73140 +
73141 +__u32
73142 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73143 + const struct dentry * parent_dentry,
73144 + const struct vfsmount * parent_mnt, const struct filename *from)
73145 +{
73146 + __u32 needmode = GR_WRITE | GR_CREATE;
73147 + __u32 mode;
73148 +
73149 + mode =
73150 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73151 + GR_CREATE | GR_AUDIT_CREATE |
73152 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73153 +
73154 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73155 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73156 + return mode;
73157 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73158 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73159 + return 0;
73160 + } else if (unlikely((mode & needmode) != needmode))
73161 + return 0;
73162 +
73163 + return (GR_WRITE | GR_CREATE);
73164 +}
73165 +
73166 +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)
73167 +{
73168 + __u32 mode;
73169 +
73170 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73171 +
73172 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73173 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73174 + return mode;
73175 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73176 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73177 + return 0;
73178 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73179 + return 0;
73180 +
73181 + return (reqmode);
73182 +}
73183 +
73184 +__u32
73185 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73186 + const struct dentry * parent_dentry,
73187 + const struct vfsmount * parent_mnt,
73188 + const int mode)
73189 +{
73190 + __u32 reqmode = GR_WRITE | GR_CREATE;
73191 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73192 + reqmode |= GR_SETID;
73193 +
73194 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73195 + reqmode, GR_MKNOD_ACL_MSG);
73196 +}
73197 +
73198 +__u32
73199 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73200 + const struct dentry *parent_dentry,
73201 + const struct vfsmount *parent_mnt)
73202 +{
73203 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73204 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73205 +}
73206 +
73207 +#define RENAME_CHECK_SUCCESS(old, new) \
73208 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73209 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73210 +
73211 +int
73212 +gr_acl_handle_rename(struct dentry *new_dentry,
73213 + struct dentry *parent_dentry,
73214 + const struct vfsmount *parent_mnt,
73215 + struct dentry *old_dentry,
73216 + struct inode *old_parent_inode,
73217 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73218 +{
73219 + __u32 comp1, comp2;
73220 + int error = 0;
73221 +
73222 + if (unlikely(!gr_acl_is_enabled()))
73223 + return 0;
73224 +
73225 + if (flags & RENAME_EXCHANGE) {
73226 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73227 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73228 + GR_SUPPRESS, parent_mnt);
73229 + comp2 =
73230 + gr_search_file(old_dentry,
73231 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73232 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73233 + } else if (d_is_negative(new_dentry)) {
73234 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73235 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73236 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73237 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73238 + GR_DELETE | GR_AUDIT_DELETE |
73239 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73240 + GR_SUPPRESS, old_mnt);
73241 + } else {
73242 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73243 + GR_CREATE | GR_DELETE |
73244 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73245 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73246 + GR_SUPPRESS, parent_mnt);
73247 + comp2 =
73248 + gr_search_file(old_dentry,
73249 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73250 + GR_DELETE | GR_AUDIT_DELETE |
73251 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73252 + }
73253 +
73254 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73255 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73256 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73257 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73258 + && !(comp2 & GR_SUPPRESS)) {
73259 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73260 + error = -EACCES;
73261 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73262 + error = -EACCES;
73263 +
73264 + return error;
73265 +}
73266 +
73267 +void
73268 +gr_acl_handle_exit(void)
73269 +{
73270 + u16 id;
73271 + char *rolename;
73272 +
73273 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73274 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73275 + id = current->acl_role_id;
73276 + rolename = current->role->rolename;
73277 + gr_set_acls(1);
73278 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73279 + }
73280 +
73281 + gr_put_exec_file(current);
73282 + return;
73283 +}
73284 +
73285 +int
73286 +gr_acl_handle_procpidmem(const struct task_struct *task)
73287 +{
73288 + if (unlikely(!gr_acl_is_enabled()))
73289 + return 0;
73290 +
73291 + if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
73292 + !(current->acl->mode & GR_POVERRIDE) &&
73293 + !(current->role->roletype & GR_ROLE_GOD))
73294 + return -EACCES;
73295 +
73296 + return 0;
73297 +}
73298 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73299 new file mode 100644
73300 index 0000000..f056b81
73301 --- /dev/null
73302 +++ b/grsecurity/gracl_ip.c
73303 @@ -0,0 +1,386 @@
73304 +#include <linux/kernel.h>
73305 +#include <asm/uaccess.h>
73306 +#include <asm/errno.h>
73307 +#include <net/sock.h>
73308 +#include <linux/file.h>
73309 +#include <linux/fs.h>
73310 +#include <linux/net.h>
73311 +#include <linux/in.h>
73312 +#include <linux/skbuff.h>
73313 +#include <linux/ip.h>
73314 +#include <linux/udp.h>
73315 +#include <linux/types.h>
73316 +#include <linux/sched.h>
73317 +#include <linux/netdevice.h>
73318 +#include <linux/inetdevice.h>
73319 +#include <linux/gracl.h>
73320 +#include <linux/grsecurity.h>
73321 +#include <linux/grinternal.h>
73322 +
73323 +#define GR_BIND 0x01
73324 +#define GR_CONNECT 0x02
73325 +#define GR_INVERT 0x04
73326 +#define GR_BINDOVERRIDE 0x08
73327 +#define GR_CONNECTOVERRIDE 0x10
73328 +#define GR_SOCK_FAMILY 0x20
73329 +
73330 +static const char * gr_protocols[IPPROTO_MAX] = {
73331 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73332 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73333 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73334 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73335 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73336 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73337 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73338 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73339 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73340 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73341 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73342 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73343 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73344 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73345 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73346 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73347 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73348 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73349 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73350 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73351 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73352 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73353 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73354 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73355 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73356 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73357 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73358 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73359 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73360 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73361 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73362 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73363 + };
73364 +
73365 +static const char * gr_socktypes[SOCK_MAX] = {
73366 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73367 + "unknown:7", "unknown:8", "unknown:9", "packet"
73368 + };
73369 +
73370 +static const char * gr_sockfamilies[AF_MAX+1] = {
73371 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73372 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73373 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73374 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73375 + };
73376 +
73377 +const char *
73378 +gr_proto_to_name(unsigned char proto)
73379 +{
73380 + return gr_protocols[proto];
73381 +}
73382 +
73383 +const char *
73384 +gr_socktype_to_name(unsigned char type)
73385 +{
73386 + return gr_socktypes[type];
73387 +}
73388 +
73389 +const char *
73390 +gr_sockfamily_to_name(unsigned char family)
73391 +{
73392 + return gr_sockfamilies[family];
73393 +}
73394 +
73395 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73396 +
73397 +int
73398 +gr_search_socket(const int domain, const int type, const int protocol)
73399 +{
73400 + struct acl_subject_label *curr;
73401 + const struct cred *cred = current_cred();
73402 +
73403 + if (unlikely(!gr_acl_is_enabled()))
73404 + goto exit;
73405 +
73406 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73407 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73408 + goto exit; // let the kernel handle it
73409 +
73410 + curr = current->acl;
73411 +
73412 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73413 + /* the family is allowed, if this is PF_INET allow it only if
73414 + the extra sock type/protocol checks pass */
73415 + if (domain == PF_INET)
73416 + goto inet_check;
73417 + goto exit;
73418 + } else {
73419 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73420 + __u32 fakeip = 0;
73421 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73422 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73423 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73424 + gr_to_filename(current->exec_file->f_path.dentry,
73425 + current->exec_file->f_path.mnt) :
73426 + curr->filename, curr->filename,
73427 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73428 + &current->signal->saved_ip);
73429 + goto exit;
73430 + }
73431 + goto exit_fail;
73432 + }
73433 +
73434 +inet_check:
73435 + /* the rest of this checking is for IPv4 only */
73436 + if (!curr->ips)
73437 + goto exit;
73438 +
73439 + if ((curr->ip_type & (1U << type)) &&
73440 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73441 + goto exit;
73442 +
73443 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73444 + /* we don't place acls on raw sockets , and sometimes
73445 + dgram/ip sockets are opened for ioctl and not
73446 + bind/connect, so we'll fake a bind learn log */
73447 + if (type == SOCK_RAW || type == SOCK_PACKET) {
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, 0, type,
73456 + protocol, GR_CONNECT, &current->signal->saved_ip);
73457 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73458 + __u32 fakeip = 0;
73459 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73460 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73461 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73462 + gr_to_filename(current->exec_file->f_path.dentry,
73463 + current->exec_file->f_path.mnt) :
73464 + curr->filename, curr->filename,
73465 + &fakeip, 0, type,
73466 + protocol, GR_BIND, &current->signal->saved_ip);
73467 + }
73468 + /* we'll log when they use connect or bind */
73469 + goto exit;
73470 + }
73471 +
73472 +exit_fail:
73473 + if (domain == PF_INET)
73474 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73475 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73476 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73477 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73478 + gr_socktype_to_name(type), protocol);
73479 +
73480 + return 0;
73481 +exit:
73482 + return 1;
73483 +}
73484 +
73485 +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)
73486 +{
73487 + if ((ip->mode & mode) &&
73488 + (ip_port >= ip->low) &&
73489 + (ip_port <= ip->high) &&
73490 + ((ntohl(ip_addr) & our_netmask) ==
73491 + (ntohl(our_addr) & our_netmask))
73492 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73493 + && (ip->type & (1U << type))) {
73494 + if (ip->mode & GR_INVERT)
73495 + return 2; // specifically denied
73496 + else
73497 + return 1; // allowed
73498 + }
73499 +
73500 + return 0; // not specifically allowed, may continue parsing
73501 +}
73502 +
73503 +static int
73504 +gr_search_connectbind(const int full_mode, struct sock *sk,
73505 + struct sockaddr_in *addr, const int type)
73506 +{
73507 + char iface[IFNAMSIZ] = {0};
73508 + struct acl_subject_label *curr;
73509 + struct acl_ip_label *ip;
73510 + struct inet_sock *isk;
73511 + struct net_device *dev;
73512 + struct in_device *idev;
73513 + unsigned long i;
73514 + int ret;
73515 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73516 + __u32 ip_addr = 0;
73517 + __u32 our_addr;
73518 + __u32 our_netmask;
73519 + char *p;
73520 + __u16 ip_port = 0;
73521 + const struct cred *cred = current_cred();
73522 +
73523 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73524 + return 0;
73525 +
73526 + curr = current->acl;
73527 + isk = inet_sk(sk);
73528 +
73529 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73530 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73531 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73532 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73533 + struct sockaddr_in saddr;
73534 + int err;
73535 +
73536 + saddr.sin_family = AF_INET;
73537 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73538 + saddr.sin_port = isk->inet_sport;
73539 +
73540 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73541 + if (err)
73542 + return err;
73543 +
73544 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73545 + if (err)
73546 + return err;
73547 + }
73548 +
73549 + if (!curr->ips)
73550 + return 0;
73551 +
73552 + ip_addr = addr->sin_addr.s_addr;
73553 + ip_port = ntohs(addr->sin_port);
73554 +
73555 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73556 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73557 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73558 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73559 + gr_to_filename(current->exec_file->f_path.dentry,
73560 + current->exec_file->f_path.mnt) :
73561 + curr->filename, curr->filename,
73562 + &ip_addr, ip_port, type,
73563 + sk->sk_protocol, mode, &current->signal->saved_ip);
73564 + return 0;
73565 + }
73566 +
73567 + for (i = 0; i < curr->ip_num; i++) {
73568 + ip = *(curr->ips + i);
73569 + if (ip->iface != NULL) {
73570 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73571 + p = strchr(iface, ':');
73572 + if (p != NULL)
73573 + *p = '\0';
73574 + dev = dev_get_by_name(sock_net(sk), iface);
73575 + if (dev == NULL)
73576 + continue;
73577 + idev = in_dev_get(dev);
73578 + if (idev == NULL) {
73579 + dev_put(dev);
73580 + continue;
73581 + }
73582 + rcu_read_lock();
73583 + for_ifa(idev) {
73584 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73585 + our_addr = ifa->ifa_address;
73586 + our_netmask = 0xffffffff;
73587 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73588 + if (ret == 1) {
73589 + rcu_read_unlock();
73590 + in_dev_put(idev);
73591 + dev_put(dev);
73592 + return 0;
73593 + } else if (ret == 2) {
73594 + rcu_read_unlock();
73595 + in_dev_put(idev);
73596 + dev_put(dev);
73597 + goto denied;
73598 + }
73599 + }
73600 + } endfor_ifa(idev);
73601 + rcu_read_unlock();
73602 + in_dev_put(idev);
73603 + dev_put(dev);
73604 + } else {
73605 + our_addr = ip->addr;
73606 + our_netmask = ip->netmask;
73607 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73608 + if (ret == 1)
73609 + return 0;
73610 + else if (ret == 2)
73611 + goto denied;
73612 + }
73613 + }
73614 +
73615 +denied:
73616 + if (mode == GR_BIND)
73617 + 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));
73618 + else if (mode == GR_CONNECT)
73619 + 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));
73620 +
73621 + return -EACCES;
73622 +}
73623 +
73624 +int
73625 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73626 +{
73627 + /* always allow disconnection of dgram sockets with connect */
73628 + if (addr->sin_family == AF_UNSPEC)
73629 + return 0;
73630 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73631 +}
73632 +
73633 +int
73634 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73635 +{
73636 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73637 +}
73638 +
73639 +int gr_search_listen(struct socket *sock)
73640 +{
73641 + struct sock *sk = sock->sk;
73642 + struct sockaddr_in addr;
73643 +
73644 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73645 + addr.sin_port = inet_sk(sk)->inet_sport;
73646 +
73647 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73648 +}
73649 +
73650 +int gr_search_accept(struct socket *sock)
73651 +{
73652 + struct sock *sk = sock->sk;
73653 + struct sockaddr_in addr;
73654 +
73655 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73656 + addr.sin_port = inet_sk(sk)->inet_sport;
73657 +
73658 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73659 +}
73660 +
73661 +int
73662 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73663 +{
73664 + if (addr)
73665 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73666 + else {
73667 + struct sockaddr_in sin;
73668 + const struct inet_sock *inet = inet_sk(sk);
73669 +
73670 + sin.sin_addr.s_addr = inet->inet_daddr;
73671 + sin.sin_port = inet->inet_dport;
73672 +
73673 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73674 + }
73675 +}
73676 +
73677 +int
73678 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73679 +{
73680 + struct sockaddr_in sin;
73681 +
73682 + if (unlikely(skb->len < sizeof (struct udphdr)))
73683 + return 0; // skip this packet
73684 +
73685 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73686 + sin.sin_port = udp_hdr(skb)->source;
73687 +
73688 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73689 +}
73690 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73691 new file mode 100644
73692 index 0000000..25f54ef
73693 --- /dev/null
73694 +++ b/grsecurity/gracl_learn.c
73695 @@ -0,0 +1,207 @@
73696 +#include <linux/kernel.h>
73697 +#include <linux/mm.h>
73698 +#include <linux/sched.h>
73699 +#include <linux/poll.h>
73700 +#include <linux/string.h>
73701 +#include <linux/file.h>
73702 +#include <linux/types.h>
73703 +#include <linux/vmalloc.h>
73704 +#include <linux/grinternal.h>
73705 +
73706 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73707 + size_t count, loff_t *ppos);
73708 +extern int gr_acl_is_enabled(void);
73709 +
73710 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73711 +static int gr_learn_attached;
73712 +
73713 +/* use a 512k buffer */
73714 +#define LEARN_BUFFER_SIZE (512 * 1024)
73715 +
73716 +static DEFINE_SPINLOCK(gr_learn_lock);
73717 +static DEFINE_MUTEX(gr_learn_user_mutex);
73718 +
73719 +/* we need to maintain two buffers, so that the kernel context of grlearn
73720 + uses a semaphore around the userspace copying, and the other kernel contexts
73721 + use a spinlock when copying into the buffer, since they cannot sleep
73722 +*/
73723 +static char *learn_buffer;
73724 +static char *learn_buffer_user;
73725 +static int learn_buffer_len;
73726 +static int learn_buffer_user_len;
73727 +
73728 +static ssize_t
73729 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73730 +{
73731 + DECLARE_WAITQUEUE(wait, current);
73732 + ssize_t retval = 0;
73733 +
73734 + add_wait_queue(&learn_wait, &wait);
73735 + set_current_state(TASK_INTERRUPTIBLE);
73736 + do {
73737 + mutex_lock(&gr_learn_user_mutex);
73738 + spin_lock(&gr_learn_lock);
73739 + if (learn_buffer_len)
73740 + break;
73741 + spin_unlock(&gr_learn_lock);
73742 + mutex_unlock(&gr_learn_user_mutex);
73743 + if (file->f_flags & O_NONBLOCK) {
73744 + retval = -EAGAIN;
73745 + goto out;
73746 + }
73747 + if (signal_pending(current)) {
73748 + retval = -ERESTARTSYS;
73749 + goto out;
73750 + }
73751 +
73752 + schedule();
73753 + } while (1);
73754 +
73755 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73756 + learn_buffer_user_len = learn_buffer_len;
73757 + retval = learn_buffer_len;
73758 + learn_buffer_len = 0;
73759 +
73760 + spin_unlock(&gr_learn_lock);
73761 +
73762 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73763 + retval = -EFAULT;
73764 +
73765 + mutex_unlock(&gr_learn_user_mutex);
73766 +out:
73767 + set_current_state(TASK_RUNNING);
73768 + remove_wait_queue(&learn_wait, &wait);
73769 + return retval;
73770 +}
73771 +
73772 +static unsigned int
73773 +poll_learn(struct file * file, poll_table * wait)
73774 +{
73775 + poll_wait(file, &learn_wait, wait);
73776 +
73777 + if (learn_buffer_len)
73778 + return (POLLIN | POLLRDNORM);
73779 +
73780 + return 0;
73781 +}
73782 +
73783 +void
73784 +gr_clear_learn_entries(void)
73785 +{
73786 + char *tmp;
73787 +
73788 + mutex_lock(&gr_learn_user_mutex);
73789 + spin_lock(&gr_learn_lock);
73790 + tmp = learn_buffer;
73791 + learn_buffer = NULL;
73792 + spin_unlock(&gr_learn_lock);
73793 + if (tmp)
73794 + vfree(tmp);
73795 + if (learn_buffer_user != NULL) {
73796 + vfree(learn_buffer_user);
73797 + learn_buffer_user = NULL;
73798 + }
73799 + learn_buffer_len = 0;
73800 + mutex_unlock(&gr_learn_user_mutex);
73801 +
73802 + return;
73803 +}
73804 +
73805 +void
73806 +gr_add_learn_entry(const char *fmt, ...)
73807 +{
73808 + va_list args;
73809 + unsigned int len;
73810 +
73811 + if (!gr_learn_attached)
73812 + return;
73813 +
73814 + spin_lock(&gr_learn_lock);
73815 +
73816 + /* leave a gap at the end so we know when it's "full" but don't have to
73817 + compute the exact length of the string we're trying to append
73818 + */
73819 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73820 + spin_unlock(&gr_learn_lock);
73821 + wake_up_interruptible(&learn_wait);
73822 + return;
73823 + }
73824 + if (learn_buffer == NULL) {
73825 + spin_unlock(&gr_learn_lock);
73826 + return;
73827 + }
73828 +
73829 + va_start(args, fmt);
73830 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73831 + va_end(args);
73832 +
73833 + learn_buffer_len += len + 1;
73834 +
73835 + spin_unlock(&gr_learn_lock);
73836 + wake_up_interruptible(&learn_wait);
73837 +
73838 + return;
73839 +}
73840 +
73841 +static int
73842 +open_learn(struct inode *inode, struct file *file)
73843 +{
73844 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73845 + return -EBUSY;
73846 + if (file->f_mode & FMODE_READ) {
73847 + int retval = 0;
73848 + mutex_lock(&gr_learn_user_mutex);
73849 + if (learn_buffer == NULL)
73850 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73851 + if (learn_buffer_user == NULL)
73852 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73853 + if (learn_buffer == NULL) {
73854 + retval = -ENOMEM;
73855 + goto out_error;
73856 + }
73857 + if (learn_buffer_user == NULL) {
73858 + retval = -ENOMEM;
73859 + goto out_error;
73860 + }
73861 + learn_buffer_len = 0;
73862 + learn_buffer_user_len = 0;
73863 + gr_learn_attached = 1;
73864 +out_error:
73865 + mutex_unlock(&gr_learn_user_mutex);
73866 + return retval;
73867 + }
73868 + return 0;
73869 +}
73870 +
73871 +static int
73872 +close_learn(struct inode *inode, struct file *file)
73873 +{
73874 + if (file->f_mode & FMODE_READ) {
73875 + char *tmp = NULL;
73876 + mutex_lock(&gr_learn_user_mutex);
73877 + spin_lock(&gr_learn_lock);
73878 + tmp = learn_buffer;
73879 + learn_buffer = NULL;
73880 + spin_unlock(&gr_learn_lock);
73881 + if (tmp)
73882 + vfree(tmp);
73883 + if (learn_buffer_user != NULL) {
73884 + vfree(learn_buffer_user);
73885 + learn_buffer_user = NULL;
73886 + }
73887 + learn_buffer_len = 0;
73888 + learn_buffer_user_len = 0;
73889 + gr_learn_attached = 0;
73890 + mutex_unlock(&gr_learn_user_mutex);
73891 + }
73892 +
73893 + return 0;
73894 +}
73895 +
73896 +const struct file_operations grsec_fops = {
73897 + .read = read_learn,
73898 + .write = write_grsec_handler,
73899 + .open = open_learn,
73900 + .release = close_learn,
73901 + .poll = poll_learn,
73902 +};
73903 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73904 new file mode 100644
73905 index 0000000..fd26052
73906 --- /dev/null
73907 +++ b/grsecurity/gracl_policy.c
73908 @@ -0,0 +1,1781 @@
73909 +#include <linux/kernel.h>
73910 +#include <linux/module.h>
73911 +#include <linux/sched.h>
73912 +#include <linux/mm.h>
73913 +#include <linux/file.h>
73914 +#include <linux/fs.h>
73915 +#include <linux/namei.h>
73916 +#include <linux/mount.h>
73917 +#include <linux/tty.h>
73918 +#include <linux/proc_fs.h>
73919 +#include <linux/lglock.h>
73920 +#include <linux/slab.h>
73921 +#include <linux/vmalloc.h>
73922 +#include <linux/types.h>
73923 +#include <linux/sysctl.h>
73924 +#include <linux/netdevice.h>
73925 +#include <linux/ptrace.h>
73926 +#include <linux/gracl.h>
73927 +#include <linux/gralloc.h>
73928 +#include <linux/security.h>
73929 +#include <linux/grinternal.h>
73930 +#include <linux/pid_namespace.h>
73931 +#include <linux/stop_machine.h>
73932 +#include <linux/fdtable.h>
73933 +#include <linux/percpu.h>
73934 +#include <linux/lglock.h>
73935 +#include <linux/hugetlb.h>
73936 +#include <linux/posix-timers.h>
73937 +#include "../fs/mount.h"
73938 +
73939 +#include <asm/uaccess.h>
73940 +#include <asm/errno.h>
73941 +#include <asm/mman.h>
73942 +
73943 +extern struct gr_policy_state *polstate;
73944 +
73945 +#define FOR_EACH_ROLE_START(role) \
73946 + role = polstate->role_list; \
73947 + while (role) {
73948 +
73949 +#define FOR_EACH_ROLE_END(role) \
73950 + role = role->prev; \
73951 + }
73952 +
73953 +struct path gr_real_root;
73954 +
73955 +extern struct gr_alloc_state *current_alloc_state;
73956 +
73957 +u16 acl_sp_role_value;
73958 +
73959 +static DEFINE_MUTEX(gr_dev_mutex);
73960 +
73961 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73962 +extern void gr_clear_learn_entries(void);
73963 +
73964 +struct gr_arg *gr_usermode __read_only;
73965 +unsigned char *gr_system_salt __read_only;
73966 +unsigned char *gr_system_sum __read_only;
73967 +
73968 +static unsigned int gr_auth_attempts = 0;
73969 +static unsigned long gr_auth_expires = 0UL;
73970 +
73971 +struct acl_object_label *fakefs_obj_rw;
73972 +struct acl_object_label *fakefs_obj_rwx;
73973 +
73974 +extern int gr_init_uidset(void);
73975 +extern void gr_free_uidset(void);
73976 +extern void gr_remove_uid(uid_t uid);
73977 +extern int gr_find_uid(uid_t uid);
73978 +
73979 +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);
73980 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73981 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73982 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73983 +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);
73984 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73985 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73986 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73987 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73988 +extern struct acl_subject_label *lookup_acl_subj_label(const u64 ino, const dev_t dev, const struct acl_role_label *role);
73989 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const u64 ino, const dev_t dev, const struct acl_role_label *role);
73990 +extern void assign_special_role(const char *rolename);
73991 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73992 +extern int gr_rbac_disable(void *unused);
73993 +extern void gr_enable_rbac_system(void);
73994 +
73995 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73996 +{
73997 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73998 + return -EFAULT;
73999 +
74000 + return 0;
74001 +}
74002 +
74003 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74004 +{
74005 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74006 + return -EFAULT;
74007 +
74008 + return 0;
74009 +}
74010 +
74011 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74012 +{
74013 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74014 + return -EFAULT;
74015 +
74016 + return 0;
74017 +}
74018 +
74019 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74020 +{
74021 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74022 + return -EFAULT;
74023 +
74024 + return 0;
74025 +}
74026 +
74027 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74028 +{
74029 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74030 + return -EFAULT;
74031 +
74032 + return 0;
74033 +}
74034 +
74035 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74036 +{
74037 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74038 + return -EFAULT;
74039 +
74040 + return 0;
74041 +}
74042 +
74043 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74044 +{
74045 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74046 + return -EFAULT;
74047 +
74048 + return 0;
74049 +}
74050 +
74051 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74052 +{
74053 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74054 + return -EFAULT;
74055 +
74056 + return 0;
74057 +}
74058 +
74059 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74060 +{
74061 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74062 + return -EFAULT;
74063 +
74064 + return 0;
74065 +}
74066 +
74067 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74068 +{
74069 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74070 + return -EFAULT;
74071 +
74072 + if ((uwrap->version != GRSECURITY_VERSION) ||
74073 + (uwrap->size != sizeof(struct gr_arg)))
74074 + return -EINVAL;
74075 +
74076 + return 0;
74077 +}
74078 +
74079 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74080 +{
74081 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74082 + return -EFAULT;
74083 +
74084 + return 0;
74085 +}
74086 +
74087 +static size_t get_gr_arg_wrapper_size_normal(void)
74088 +{
74089 + return sizeof(struct gr_arg_wrapper);
74090 +}
74091 +
74092 +#ifdef CONFIG_COMPAT
74093 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74094 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74095 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74096 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74097 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74098 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74099 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74100 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74101 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74102 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74103 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74104 +extern size_t get_gr_arg_wrapper_size_compat(void);
74105 +
74106 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74107 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74108 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74109 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74110 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74111 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74112 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74113 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74114 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74115 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74116 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74117 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74118 +
74119 +#else
74120 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74121 +#define copy_gr_arg copy_gr_arg_normal
74122 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74123 +#define copy_acl_object_label copy_acl_object_label_normal
74124 +#define copy_acl_subject_label copy_acl_subject_label_normal
74125 +#define copy_acl_role_label copy_acl_role_label_normal
74126 +#define copy_acl_ip_label copy_acl_ip_label_normal
74127 +#define copy_pointer_from_array copy_pointer_from_array_normal
74128 +#define copy_sprole_pw copy_sprole_pw_normal
74129 +#define copy_role_transition copy_role_transition_normal
74130 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74131 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74132 +#endif
74133 +
74134 +static struct acl_subject_label *
74135 +lookup_subject_map(const struct acl_subject_label *userp)
74136 +{
74137 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74138 + struct subject_map *match;
74139 +
74140 + match = polstate->subj_map_set.s_hash[index];
74141 +
74142 + while (match && match->user != userp)
74143 + match = match->next;
74144 +
74145 + if (match != NULL)
74146 + return match->kernel;
74147 + else
74148 + return NULL;
74149 +}
74150 +
74151 +static void
74152 +insert_subj_map_entry(struct subject_map *subjmap)
74153 +{
74154 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74155 + struct subject_map **curr;
74156 +
74157 + subjmap->prev = NULL;
74158 +
74159 + curr = &polstate->subj_map_set.s_hash[index];
74160 + if (*curr != NULL)
74161 + (*curr)->prev = subjmap;
74162 +
74163 + subjmap->next = *curr;
74164 + *curr = subjmap;
74165 +
74166 + return;
74167 +}
74168 +
74169 +static void
74170 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74171 +{
74172 + unsigned int index =
74173 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74174 + struct acl_role_label **curr;
74175 + struct acl_role_label *tmp, *tmp2;
74176 +
74177 + curr = &polstate->acl_role_set.r_hash[index];
74178 +
74179 + /* simple case, slot is empty, just set it to our role */
74180 + if (*curr == NULL) {
74181 + *curr = role;
74182 + } else {
74183 + /* example:
74184 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74185 + 2 -> 3
74186 + */
74187 + /* first check to see if we can already be reached via this slot */
74188 + tmp = *curr;
74189 + while (tmp && tmp != role)
74190 + tmp = tmp->next;
74191 + if (tmp == role) {
74192 + /* we don't need to add ourselves to this slot's chain */
74193 + return;
74194 + }
74195 + /* we need to add ourselves to this chain, two cases */
74196 + if (role->next == NULL) {
74197 + /* simple case, append the current chain to our role */
74198 + role->next = *curr;
74199 + *curr = role;
74200 + } else {
74201 + /* 1 -> 2 -> 3 -> 4
74202 + 2 -> 3 -> 4
74203 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74204 + */
74205 + /* trickier case: walk our role's chain until we find
74206 + the role for the start of the current slot's chain */
74207 + tmp = role;
74208 + tmp2 = *curr;
74209 + while (tmp->next && tmp->next != tmp2)
74210 + tmp = tmp->next;
74211 + if (tmp->next == tmp2) {
74212 + /* from example above, we found 3, so just
74213 + replace this slot's chain with ours */
74214 + *curr = role;
74215 + } else {
74216 + /* we didn't find a subset of our role's chain
74217 + in the current slot's chain, so append their
74218 + chain to ours, and set us as the first role in
74219 + the slot's chain
74220 +
74221 + we could fold this case with the case above,
74222 + but making it explicit for clarity
74223 + */
74224 + tmp->next = tmp2;
74225 + *curr = role;
74226 + }
74227 + }
74228 + }
74229 +
74230 + return;
74231 +}
74232 +
74233 +static void
74234 +insert_acl_role_label(struct acl_role_label *role)
74235 +{
74236 + int i;
74237 +
74238 + if (polstate->role_list == NULL) {
74239 + polstate->role_list = role;
74240 + role->prev = NULL;
74241 + } else {
74242 + role->prev = polstate->role_list;
74243 + polstate->role_list = role;
74244 + }
74245 +
74246 + /* used for hash chains */
74247 + role->next = NULL;
74248 +
74249 + if (role->roletype & GR_ROLE_DOMAIN) {
74250 + for (i = 0; i < role->domain_child_num; i++)
74251 + __insert_acl_role_label(role, role->domain_children[i]);
74252 + } else
74253 + __insert_acl_role_label(role, role->uidgid);
74254 +}
74255 +
74256 +static int
74257 +insert_name_entry(char *name, const u64 inode, const dev_t device, __u8 deleted)
74258 +{
74259 + struct name_entry **curr, *nentry;
74260 + struct inodev_entry *ientry;
74261 + unsigned int len = strlen(name);
74262 + unsigned int key = full_name_hash(name, len);
74263 + unsigned int index = key % polstate->name_set.n_size;
74264 +
74265 + curr = &polstate->name_set.n_hash[index];
74266 +
74267 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74268 + curr = &((*curr)->next);
74269 +
74270 + if (*curr != NULL)
74271 + return 1;
74272 +
74273 + nentry = acl_alloc(sizeof (struct name_entry));
74274 + if (nentry == NULL)
74275 + return 0;
74276 + ientry = acl_alloc(sizeof (struct inodev_entry));
74277 + if (ientry == NULL)
74278 + return 0;
74279 + ientry->nentry = nentry;
74280 +
74281 + nentry->key = key;
74282 + nentry->name = name;
74283 + nentry->inode = inode;
74284 + nentry->device = device;
74285 + nentry->len = len;
74286 + nentry->deleted = deleted;
74287 +
74288 + nentry->prev = NULL;
74289 + curr = &polstate->name_set.n_hash[index];
74290 + if (*curr != NULL)
74291 + (*curr)->prev = nentry;
74292 + nentry->next = *curr;
74293 + *curr = nentry;
74294 +
74295 + /* insert us into the table searchable by inode/dev */
74296 + __insert_inodev_entry(polstate, ientry);
74297 +
74298 + return 1;
74299 +}
74300 +
74301 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74302 +
74303 +static void *
74304 +create_table(__u32 * len, int elementsize)
74305 +{
74306 + unsigned int table_sizes[] = {
74307 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74308 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74309 + 4194301, 8388593, 16777213, 33554393, 67108859
74310 + };
74311 + void *newtable = NULL;
74312 + unsigned int pwr = 0;
74313 +
74314 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74315 + table_sizes[pwr] <= *len)
74316 + pwr++;
74317 +
74318 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74319 + return newtable;
74320 +
74321 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74322 + newtable =
74323 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74324 + else
74325 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74326 +
74327 + *len = table_sizes[pwr];
74328 +
74329 + return newtable;
74330 +}
74331 +
74332 +static int
74333 +init_variables(const struct gr_arg *arg, bool reload)
74334 +{
74335 + struct task_struct *reaper = init_pid_ns.child_reaper;
74336 + unsigned int stacksize;
74337 +
74338 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74339 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74340 + polstate->name_set.n_size = arg->role_db.num_objects;
74341 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74342 +
74343 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74344 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74345 + return 1;
74346 +
74347 + if (!reload) {
74348 + if (!gr_init_uidset())
74349 + return 1;
74350 + }
74351 +
74352 + /* set up the stack that holds allocation info */
74353 +
74354 + stacksize = arg->role_db.num_pointers + 5;
74355 +
74356 + if (!acl_alloc_stack_init(stacksize))
74357 + return 1;
74358 +
74359 + if (!reload) {
74360 + /* grab reference for the real root dentry and vfsmount */
74361 + get_fs_root(reaper->fs, &gr_real_root);
74362 +
74363 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74364 + 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);
74365 +#endif
74366 +
74367 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74368 + if (fakefs_obj_rw == NULL)
74369 + return 1;
74370 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74371 +
74372 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74373 + if (fakefs_obj_rwx == NULL)
74374 + return 1;
74375 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74376 + }
74377 +
74378 + polstate->subj_map_set.s_hash =
74379 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74380 + polstate->acl_role_set.r_hash =
74381 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74382 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74383 + polstate->inodev_set.i_hash =
74384 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74385 +
74386 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74387 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74388 + return 1;
74389 +
74390 + memset(polstate->subj_map_set.s_hash, 0,
74391 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74392 + memset(polstate->acl_role_set.r_hash, 0,
74393 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74394 + memset(polstate->name_set.n_hash, 0,
74395 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74396 + memset(polstate->inodev_set.i_hash, 0,
74397 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74398 +
74399 + return 0;
74400 +}
74401 +
74402 +/* free information not needed after startup
74403 + currently contains user->kernel pointer mappings for subjects
74404 +*/
74405 +
74406 +static void
74407 +free_init_variables(void)
74408 +{
74409 + __u32 i;
74410 +
74411 + if (polstate->subj_map_set.s_hash) {
74412 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74413 + if (polstate->subj_map_set.s_hash[i]) {
74414 + kfree(polstate->subj_map_set.s_hash[i]);
74415 + polstate->subj_map_set.s_hash[i] = NULL;
74416 + }
74417 + }
74418 +
74419 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74420 + PAGE_SIZE)
74421 + kfree(polstate->subj_map_set.s_hash);
74422 + else
74423 + vfree(polstate->subj_map_set.s_hash);
74424 + }
74425 +
74426 + return;
74427 +}
74428 +
74429 +static void
74430 +free_variables(bool reload)
74431 +{
74432 + struct acl_subject_label *s;
74433 + struct acl_role_label *r;
74434 + struct task_struct *task, *task2;
74435 + unsigned int x;
74436 +
74437 + if (!reload) {
74438 + gr_clear_learn_entries();
74439 +
74440 + read_lock(&tasklist_lock);
74441 + do_each_thread(task2, task) {
74442 + task->acl_sp_role = 0;
74443 + task->acl_role_id = 0;
74444 + task->inherited = 0;
74445 + task->acl = NULL;
74446 + task->role = NULL;
74447 + } while_each_thread(task2, task);
74448 + read_unlock(&tasklist_lock);
74449 +
74450 + kfree(fakefs_obj_rw);
74451 + fakefs_obj_rw = NULL;
74452 + kfree(fakefs_obj_rwx);
74453 + fakefs_obj_rwx = NULL;
74454 +
74455 + /* release the reference to the real root dentry and vfsmount */
74456 + path_put(&gr_real_root);
74457 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74458 + }
74459 +
74460 + /* free all object hash tables */
74461 +
74462 + FOR_EACH_ROLE_START(r)
74463 + if (r->subj_hash == NULL)
74464 + goto next_role;
74465 + FOR_EACH_SUBJECT_START(r, s, x)
74466 + if (s->obj_hash == NULL)
74467 + break;
74468 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74469 + kfree(s->obj_hash);
74470 + else
74471 + vfree(s->obj_hash);
74472 + FOR_EACH_SUBJECT_END(s, x)
74473 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74474 + if (s->obj_hash == NULL)
74475 + break;
74476 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74477 + kfree(s->obj_hash);
74478 + else
74479 + vfree(s->obj_hash);
74480 + FOR_EACH_NESTED_SUBJECT_END(s)
74481 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74482 + kfree(r->subj_hash);
74483 + else
74484 + vfree(r->subj_hash);
74485 + r->subj_hash = NULL;
74486 +next_role:
74487 + FOR_EACH_ROLE_END(r)
74488 +
74489 + acl_free_all();
74490 +
74491 + if (polstate->acl_role_set.r_hash) {
74492 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74493 + PAGE_SIZE)
74494 + kfree(polstate->acl_role_set.r_hash);
74495 + else
74496 + vfree(polstate->acl_role_set.r_hash);
74497 + }
74498 + if (polstate->name_set.n_hash) {
74499 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74500 + PAGE_SIZE)
74501 + kfree(polstate->name_set.n_hash);
74502 + else
74503 + vfree(polstate->name_set.n_hash);
74504 + }
74505 +
74506 + if (polstate->inodev_set.i_hash) {
74507 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74508 + PAGE_SIZE)
74509 + kfree(polstate->inodev_set.i_hash);
74510 + else
74511 + vfree(polstate->inodev_set.i_hash);
74512 + }
74513 +
74514 + if (!reload)
74515 + gr_free_uidset();
74516 +
74517 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74518 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74519 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74520 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74521 +
74522 + polstate->default_role = NULL;
74523 + polstate->kernel_role = NULL;
74524 + polstate->role_list = NULL;
74525 +
74526 + return;
74527 +}
74528 +
74529 +static struct acl_subject_label *
74530 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74531 +
74532 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74533 +{
74534 + unsigned int len = strnlen_user(*name, maxlen);
74535 + char *tmp;
74536 +
74537 + if (!len || len >= maxlen)
74538 + return -EINVAL;
74539 +
74540 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74541 + return -ENOMEM;
74542 +
74543 + if (copy_from_user(tmp, *name, len))
74544 + return -EFAULT;
74545 +
74546 + tmp[len-1] = '\0';
74547 + *name = tmp;
74548 +
74549 + return 0;
74550 +}
74551 +
74552 +static int
74553 +copy_user_glob(struct acl_object_label *obj)
74554 +{
74555 + struct acl_object_label *g_tmp, **guser;
74556 + int error;
74557 +
74558 + if (obj->globbed == NULL)
74559 + return 0;
74560 +
74561 + guser = &obj->globbed;
74562 + while (*guser) {
74563 + g_tmp = (struct acl_object_label *)
74564 + acl_alloc(sizeof (struct acl_object_label));
74565 + if (g_tmp == NULL)
74566 + return -ENOMEM;
74567 +
74568 + if (copy_acl_object_label(g_tmp, *guser))
74569 + return -EFAULT;
74570 +
74571 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74572 + if (error)
74573 + return error;
74574 +
74575 + *guser = g_tmp;
74576 + guser = &(g_tmp->next);
74577 + }
74578 +
74579 + return 0;
74580 +}
74581 +
74582 +static int
74583 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74584 + struct acl_role_label *role)
74585 +{
74586 + struct acl_object_label *o_tmp;
74587 + int ret;
74588 +
74589 + while (userp) {
74590 + if ((o_tmp = (struct acl_object_label *)
74591 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74592 + return -ENOMEM;
74593 +
74594 + if (copy_acl_object_label(o_tmp, userp))
74595 + return -EFAULT;
74596 +
74597 + userp = o_tmp->prev;
74598 +
74599 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74600 + if (ret)
74601 + return ret;
74602 +
74603 + insert_acl_obj_label(o_tmp, subj);
74604 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74605 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74606 + return -ENOMEM;
74607 +
74608 + ret = copy_user_glob(o_tmp);
74609 + if (ret)
74610 + return ret;
74611 +
74612 + if (o_tmp->nested) {
74613 + int already_copied;
74614 +
74615 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74616 + if (IS_ERR(o_tmp->nested))
74617 + return PTR_ERR(o_tmp->nested);
74618 +
74619 + /* insert into nested subject list if we haven't copied this one yet
74620 + to prevent duplicate entries */
74621 + if (!already_copied) {
74622 + o_tmp->nested->next = role->hash->first;
74623 + role->hash->first = o_tmp->nested;
74624 + }
74625 + }
74626 + }
74627 +
74628 + return 0;
74629 +}
74630 +
74631 +static __u32
74632 +count_user_subjs(struct acl_subject_label *userp)
74633 +{
74634 + struct acl_subject_label s_tmp;
74635 + __u32 num = 0;
74636 +
74637 + while (userp) {
74638 + if (copy_acl_subject_label(&s_tmp, userp))
74639 + break;
74640 +
74641 + userp = s_tmp.prev;
74642 + }
74643 +
74644 + return num;
74645 +}
74646 +
74647 +static int
74648 +copy_user_allowedips(struct acl_role_label *rolep)
74649 +{
74650 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74651 +
74652 + ruserip = rolep->allowed_ips;
74653 +
74654 + while (ruserip) {
74655 + rlast = rtmp;
74656 +
74657 + if ((rtmp = (struct role_allowed_ip *)
74658 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74659 + return -ENOMEM;
74660 +
74661 + if (copy_role_allowed_ip(rtmp, ruserip))
74662 + return -EFAULT;
74663 +
74664 + ruserip = rtmp->prev;
74665 +
74666 + if (!rlast) {
74667 + rtmp->prev = NULL;
74668 + rolep->allowed_ips = rtmp;
74669 + } else {
74670 + rlast->next = rtmp;
74671 + rtmp->prev = rlast;
74672 + }
74673 +
74674 + if (!ruserip)
74675 + rtmp->next = NULL;
74676 + }
74677 +
74678 + return 0;
74679 +}
74680 +
74681 +static int
74682 +copy_user_transitions(struct acl_role_label *rolep)
74683 +{
74684 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74685 + int error;
74686 +
74687 + rusertp = rolep->transitions;
74688 +
74689 + while (rusertp) {
74690 + rlast = rtmp;
74691 +
74692 + if ((rtmp = (struct role_transition *)
74693 + acl_alloc(sizeof (struct role_transition))) == NULL)
74694 + return -ENOMEM;
74695 +
74696 + if (copy_role_transition(rtmp, rusertp))
74697 + return -EFAULT;
74698 +
74699 + rusertp = rtmp->prev;
74700 +
74701 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74702 + if (error)
74703 + return error;
74704 +
74705 + if (!rlast) {
74706 + rtmp->prev = NULL;
74707 + rolep->transitions = rtmp;
74708 + } else {
74709 + rlast->next = rtmp;
74710 + rtmp->prev = rlast;
74711 + }
74712 +
74713 + if (!rusertp)
74714 + rtmp->next = NULL;
74715 + }
74716 +
74717 + return 0;
74718 +}
74719 +
74720 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74721 +{
74722 + struct acl_object_label o_tmp;
74723 + __u32 num = 0;
74724 +
74725 + while (userp) {
74726 + if (copy_acl_object_label(&o_tmp, userp))
74727 + break;
74728 +
74729 + userp = o_tmp.prev;
74730 + num++;
74731 + }
74732 +
74733 + return num;
74734 +}
74735 +
74736 +static struct acl_subject_label *
74737 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74738 +{
74739 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74740 + __u32 num_objs;
74741 + struct acl_ip_label **i_tmp, *i_utmp2;
74742 + struct gr_hash_struct ghash;
74743 + struct subject_map *subjmap;
74744 + unsigned int i_num;
74745 + int err;
74746 +
74747 + if (already_copied != NULL)
74748 + *already_copied = 0;
74749 +
74750 + s_tmp = lookup_subject_map(userp);
74751 +
74752 + /* we've already copied this subject into the kernel, just return
74753 + the reference to it, and don't copy it over again
74754 + */
74755 + if (s_tmp) {
74756 + if (already_copied != NULL)
74757 + *already_copied = 1;
74758 + return(s_tmp);
74759 + }
74760 +
74761 + if ((s_tmp = (struct acl_subject_label *)
74762 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74763 + return ERR_PTR(-ENOMEM);
74764 +
74765 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74766 + if (subjmap == NULL)
74767 + return ERR_PTR(-ENOMEM);
74768 +
74769 + subjmap->user = userp;
74770 + subjmap->kernel = s_tmp;
74771 + insert_subj_map_entry(subjmap);
74772 +
74773 + if (copy_acl_subject_label(s_tmp, userp))
74774 + return ERR_PTR(-EFAULT);
74775 +
74776 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74777 + if (err)
74778 + return ERR_PTR(err);
74779 +
74780 + if (!strcmp(s_tmp->filename, "/"))
74781 + role->root_label = s_tmp;
74782 +
74783 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74784 + return ERR_PTR(-EFAULT);
74785 +
74786 + /* copy user and group transition tables */
74787 +
74788 + if (s_tmp->user_trans_num) {
74789 + uid_t *uidlist;
74790 +
74791 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74792 + if (uidlist == NULL)
74793 + return ERR_PTR(-ENOMEM);
74794 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74795 + return ERR_PTR(-EFAULT);
74796 +
74797 + s_tmp->user_transitions = uidlist;
74798 + }
74799 +
74800 + if (s_tmp->group_trans_num) {
74801 + gid_t *gidlist;
74802 +
74803 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74804 + if (gidlist == NULL)
74805 + return ERR_PTR(-ENOMEM);
74806 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74807 + return ERR_PTR(-EFAULT);
74808 +
74809 + s_tmp->group_transitions = gidlist;
74810 + }
74811 +
74812 + /* set up object hash table */
74813 + num_objs = count_user_objs(ghash.first);
74814 +
74815 + s_tmp->obj_hash_size = num_objs;
74816 + s_tmp->obj_hash =
74817 + (struct acl_object_label **)
74818 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74819 +
74820 + if (!s_tmp->obj_hash)
74821 + return ERR_PTR(-ENOMEM);
74822 +
74823 + memset(s_tmp->obj_hash, 0,
74824 + s_tmp->obj_hash_size *
74825 + sizeof (struct acl_object_label *));
74826 +
74827 + /* add in objects */
74828 + err = copy_user_objs(ghash.first, s_tmp, role);
74829 +
74830 + if (err)
74831 + return ERR_PTR(err);
74832 +
74833 + /* set pointer for parent subject */
74834 + if (s_tmp->parent_subject) {
74835 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74836 +
74837 + if (IS_ERR(s_tmp2))
74838 + return s_tmp2;
74839 +
74840 + s_tmp->parent_subject = s_tmp2;
74841 + }
74842 +
74843 + /* add in ip acls */
74844 +
74845 + if (!s_tmp->ip_num) {
74846 + s_tmp->ips = NULL;
74847 + goto insert;
74848 + }
74849 +
74850 + i_tmp =
74851 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74852 + sizeof (struct acl_ip_label *));
74853 +
74854 + if (!i_tmp)
74855 + return ERR_PTR(-ENOMEM);
74856 +
74857 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74858 + *(i_tmp + i_num) =
74859 + (struct acl_ip_label *)
74860 + acl_alloc(sizeof (struct acl_ip_label));
74861 + if (!*(i_tmp + i_num))
74862 + return ERR_PTR(-ENOMEM);
74863 +
74864 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74865 + return ERR_PTR(-EFAULT);
74866 +
74867 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74868 + return ERR_PTR(-EFAULT);
74869 +
74870 + if ((*(i_tmp + i_num))->iface == NULL)
74871 + continue;
74872 +
74873 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74874 + if (err)
74875 + return ERR_PTR(err);
74876 + }
74877 +
74878 + s_tmp->ips = i_tmp;
74879 +
74880 +insert:
74881 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74882 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74883 + return ERR_PTR(-ENOMEM);
74884 +
74885 + return s_tmp;
74886 +}
74887 +
74888 +static int
74889 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74890 +{
74891 + struct acl_subject_label s_pre;
74892 + struct acl_subject_label * ret;
74893 + int err;
74894 +
74895 + while (userp) {
74896 + if (copy_acl_subject_label(&s_pre, userp))
74897 + return -EFAULT;
74898 +
74899 + ret = do_copy_user_subj(userp, role, NULL);
74900 +
74901 + err = PTR_ERR(ret);
74902 + if (IS_ERR(ret))
74903 + return err;
74904 +
74905 + insert_acl_subj_label(ret, role);
74906 +
74907 + userp = s_pre.prev;
74908 + }
74909 +
74910 + return 0;
74911 +}
74912 +
74913 +static int
74914 +copy_user_acl(struct gr_arg *arg)
74915 +{
74916 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74917 + struct acl_subject_label *subj_list;
74918 + struct sprole_pw *sptmp;
74919 + struct gr_hash_struct *ghash;
74920 + uid_t *domainlist;
74921 + unsigned int r_num;
74922 + int err = 0;
74923 + __u16 i;
74924 + __u32 num_subjs;
74925 +
74926 + /* we need a default and kernel role */
74927 + if (arg->role_db.num_roles < 2)
74928 + return -EINVAL;
74929 +
74930 + /* copy special role authentication info from userspace */
74931 +
74932 + polstate->num_sprole_pws = arg->num_sprole_pws;
74933 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74934 +
74935 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74936 + return -ENOMEM;
74937 +
74938 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74939 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74940 + if (!sptmp)
74941 + return -ENOMEM;
74942 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74943 + return -EFAULT;
74944 +
74945 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74946 + if (err)
74947 + return err;
74948 +
74949 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74950 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74951 +#endif
74952 +
74953 + polstate->acl_special_roles[i] = sptmp;
74954 + }
74955 +
74956 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74957 +
74958 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74959 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74960 +
74961 + if (!r_tmp)
74962 + return -ENOMEM;
74963 +
74964 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74965 + return -EFAULT;
74966 +
74967 + if (copy_acl_role_label(r_tmp, r_utmp2))
74968 + return -EFAULT;
74969 +
74970 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74971 + if (err)
74972 + return err;
74973 +
74974 + if (!strcmp(r_tmp->rolename, "default")
74975 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74976 + polstate->default_role = r_tmp;
74977 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74978 + polstate->kernel_role = r_tmp;
74979 + }
74980 +
74981 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74982 + return -ENOMEM;
74983 +
74984 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74985 + return -EFAULT;
74986 +
74987 + r_tmp->hash = ghash;
74988 +
74989 + num_subjs = count_user_subjs(r_tmp->hash->first);
74990 +
74991 + r_tmp->subj_hash_size = num_subjs;
74992 + r_tmp->subj_hash =
74993 + (struct acl_subject_label **)
74994 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74995 +
74996 + if (!r_tmp->subj_hash)
74997 + return -ENOMEM;
74998 +
74999 + err = copy_user_allowedips(r_tmp);
75000 + if (err)
75001 + return err;
75002 +
75003 + /* copy domain info */
75004 + if (r_tmp->domain_children != NULL) {
75005 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75006 + if (domainlist == NULL)
75007 + return -ENOMEM;
75008 +
75009 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75010 + return -EFAULT;
75011 +
75012 + r_tmp->domain_children = domainlist;
75013 + }
75014 +
75015 + err = copy_user_transitions(r_tmp);
75016 + if (err)
75017 + return err;
75018 +
75019 + memset(r_tmp->subj_hash, 0,
75020 + r_tmp->subj_hash_size *
75021 + sizeof (struct acl_subject_label *));
75022 +
75023 + /* acquire the list of subjects, then NULL out
75024 + the list prior to parsing the subjects for this role,
75025 + as during this parsing the list is replaced with a list
75026 + of *nested* subjects for the role
75027 + */
75028 + subj_list = r_tmp->hash->first;
75029 +
75030 + /* set nested subject list to null */
75031 + r_tmp->hash->first = NULL;
75032 +
75033 + err = copy_user_subjs(subj_list, r_tmp);
75034 +
75035 + if (err)
75036 + return err;
75037 +
75038 + insert_acl_role_label(r_tmp);
75039 + }
75040 +
75041 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75042 + return -EINVAL;
75043 +
75044 + return err;
75045 +}
75046 +
75047 +static int gracl_reload_apply_policies(void *reload)
75048 +{
75049 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75050 + struct task_struct *task, *task2;
75051 + struct acl_role_label *role, *rtmp;
75052 + struct acl_subject_label *subj;
75053 + const struct cred *cred;
75054 + int role_applied;
75055 + int ret = 0;
75056 +
75057 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75058 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75059 +
75060 + /* first make sure we'll be able to apply the new policy cleanly */
75061 + do_each_thread(task2, task) {
75062 + if (task->exec_file == NULL)
75063 + continue;
75064 + role_applied = 0;
75065 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75066 + /* preserve special roles */
75067 + FOR_EACH_ROLE_START(role)
75068 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75069 + rtmp = task->role;
75070 + task->role = role;
75071 + role_applied = 1;
75072 + break;
75073 + }
75074 + FOR_EACH_ROLE_END(role)
75075 + }
75076 + if (!role_applied) {
75077 + cred = __task_cred(task);
75078 + rtmp = task->role;
75079 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75080 + }
75081 + /* this handles non-nested inherited subjects, nested subjects will still
75082 + be dropped currently */
75083 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75084 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL, 1);
75085 + /* change the role back so that we've made no modifications to the policy */
75086 + task->role = rtmp;
75087 +
75088 + if (subj == NULL || task->tmpacl == NULL) {
75089 + ret = -EINVAL;
75090 + goto out;
75091 + }
75092 + } while_each_thread(task2, task);
75093 +
75094 + /* now actually apply the policy */
75095 +
75096 + do_each_thread(task2, task) {
75097 + if (task->exec_file) {
75098 + role_applied = 0;
75099 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75100 + /* preserve special roles */
75101 + FOR_EACH_ROLE_START(role)
75102 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75103 + task->role = role;
75104 + role_applied = 1;
75105 + break;
75106 + }
75107 + FOR_EACH_ROLE_END(role)
75108 + }
75109 + if (!role_applied) {
75110 + cred = __task_cred(task);
75111 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75112 + }
75113 + /* this handles non-nested inherited subjects, nested subjects will still
75114 + be dropped currently */
75115 + if (!reload_state->oldmode && task->inherited)
75116 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75117 + else {
75118 + /* looked up and tagged to the task previously */
75119 + subj = task->tmpacl;
75120 + }
75121 + /* subj will be non-null */
75122 + __gr_apply_subject_to_task(polstate, task, subj);
75123 + if (reload_state->oldmode) {
75124 + task->acl_role_id = 0;
75125 + task->acl_sp_role = 0;
75126 + task->inherited = 0;
75127 + }
75128 + } else {
75129 + // it's a kernel process
75130 + task->role = polstate->kernel_role;
75131 + task->acl = polstate->kernel_role->root_label;
75132 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75133 + task->acl->mode &= ~GR_PROCFIND;
75134 +#endif
75135 + }
75136 + } while_each_thread(task2, task);
75137 +
75138 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75139 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75140 +
75141 +out:
75142 +
75143 + return ret;
75144 +}
75145 +
75146 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75147 +{
75148 + struct gr_reload_state new_reload_state = { };
75149 + int err;
75150 +
75151 + new_reload_state.oldpolicy_ptr = polstate;
75152 + new_reload_state.oldalloc_ptr = current_alloc_state;
75153 + new_reload_state.oldmode = oldmode;
75154 +
75155 + current_alloc_state = &new_reload_state.newalloc;
75156 + polstate = &new_reload_state.newpolicy;
75157 +
75158 + /* everything relevant is now saved off, copy in the new policy */
75159 + if (init_variables(args, true)) {
75160 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75161 + err = -ENOMEM;
75162 + goto error;
75163 + }
75164 +
75165 + err = copy_user_acl(args);
75166 + free_init_variables();
75167 + if (err)
75168 + goto error;
75169 + /* the new policy is copied in, with the old policy available via saved_state
75170 + first go through applying roles, making sure to preserve special roles
75171 + then apply new subjects, making sure to preserve inherited and nested subjects,
75172 + though currently only inherited subjects will be preserved
75173 + */
75174 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75175 + if (err)
75176 + goto error;
75177 +
75178 + /* we've now applied the new policy, so restore the old policy state to free it */
75179 + polstate = &new_reload_state.oldpolicy;
75180 + current_alloc_state = &new_reload_state.oldalloc;
75181 + free_variables(true);
75182 +
75183 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75184 + to running_polstate/current_alloc_state inside stop_machine
75185 + */
75186 + err = 0;
75187 + goto out;
75188 +error:
75189 + /* on error of loading the new policy, we'll just keep the previous
75190 + policy set around
75191 + */
75192 + free_variables(true);
75193 +
75194 + /* doesn't affect runtime, but maintains consistent state */
75195 +out:
75196 + polstate = new_reload_state.oldpolicy_ptr;
75197 + current_alloc_state = new_reload_state.oldalloc_ptr;
75198 +
75199 + return err;
75200 +}
75201 +
75202 +static int
75203 +gracl_init(struct gr_arg *args)
75204 +{
75205 + int error = 0;
75206 +
75207 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75208 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75209 +
75210 + if (init_variables(args, false)) {
75211 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75212 + error = -ENOMEM;
75213 + goto out;
75214 + }
75215 +
75216 + error = copy_user_acl(args);
75217 + free_init_variables();
75218 + if (error)
75219 + goto out;
75220 +
75221 + error = gr_set_acls(0);
75222 + if (error)
75223 + goto out;
75224 +
75225 + gr_enable_rbac_system();
75226 +
75227 + return 0;
75228 +
75229 +out:
75230 + free_variables(false);
75231 + return error;
75232 +}
75233 +
75234 +static int
75235 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75236 + unsigned char **sum)
75237 +{
75238 + struct acl_role_label *r;
75239 + struct role_allowed_ip *ipp;
75240 + struct role_transition *trans;
75241 + unsigned int i;
75242 + int found = 0;
75243 + u32 curr_ip = current->signal->curr_ip;
75244 +
75245 + current->signal->saved_ip = curr_ip;
75246 +
75247 + /* check transition table */
75248 +
75249 + for (trans = current->role->transitions; trans; trans = trans->next) {
75250 + if (!strcmp(rolename, trans->rolename)) {
75251 + found = 1;
75252 + break;
75253 + }
75254 + }
75255 +
75256 + if (!found)
75257 + return 0;
75258 +
75259 + /* handle special roles that do not require authentication
75260 + and check ip */
75261 +
75262 + FOR_EACH_ROLE_START(r)
75263 + if (!strcmp(rolename, r->rolename) &&
75264 + (r->roletype & GR_ROLE_SPECIAL)) {
75265 + found = 0;
75266 + if (r->allowed_ips != NULL) {
75267 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75268 + if ((ntohl(curr_ip) & ipp->netmask) ==
75269 + (ntohl(ipp->addr) & ipp->netmask))
75270 + found = 1;
75271 + }
75272 + } else
75273 + found = 2;
75274 + if (!found)
75275 + return 0;
75276 +
75277 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75278 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75279 + *salt = NULL;
75280 + *sum = NULL;
75281 + return 1;
75282 + }
75283 + }
75284 + FOR_EACH_ROLE_END(r)
75285 +
75286 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75287 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75288 + *salt = polstate->acl_special_roles[i]->salt;
75289 + *sum = polstate->acl_special_roles[i]->sum;
75290 + return 1;
75291 + }
75292 + }
75293 +
75294 + return 0;
75295 +}
75296 +
75297 +int gr_check_secure_terminal(struct task_struct *task)
75298 +{
75299 + struct task_struct *p, *p2, *p3;
75300 + struct files_struct *files;
75301 + struct fdtable *fdt;
75302 + struct file *our_file = NULL, *file;
75303 + int i;
75304 +
75305 + if (task->signal->tty == NULL)
75306 + return 1;
75307 +
75308 + files = get_files_struct(task);
75309 + if (files != NULL) {
75310 + rcu_read_lock();
75311 + fdt = files_fdtable(files);
75312 + for (i=0; i < fdt->max_fds; i++) {
75313 + file = fcheck_files(files, i);
75314 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75315 + get_file(file);
75316 + our_file = file;
75317 + }
75318 + }
75319 + rcu_read_unlock();
75320 + put_files_struct(files);
75321 + }
75322 +
75323 + if (our_file == NULL)
75324 + return 1;
75325 +
75326 + read_lock(&tasklist_lock);
75327 + do_each_thread(p2, p) {
75328 + files = get_files_struct(p);
75329 + if (files == NULL ||
75330 + (p->signal && p->signal->tty == task->signal->tty)) {
75331 + if (files != NULL)
75332 + put_files_struct(files);
75333 + continue;
75334 + }
75335 + rcu_read_lock();
75336 + fdt = files_fdtable(files);
75337 + for (i=0; i < fdt->max_fds; i++) {
75338 + file = fcheck_files(files, i);
75339 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75340 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75341 + p3 = task;
75342 + while (task_pid_nr(p3) > 0) {
75343 + if (p3 == p)
75344 + break;
75345 + p3 = p3->real_parent;
75346 + }
75347 + if (p3 == p)
75348 + break;
75349 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75350 + gr_handle_alertkill(p);
75351 + rcu_read_unlock();
75352 + put_files_struct(files);
75353 + read_unlock(&tasklist_lock);
75354 + fput(our_file);
75355 + return 0;
75356 + }
75357 + }
75358 + rcu_read_unlock();
75359 + put_files_struct(files);
75360 + } while_each_thread(p2, p);
75361 + read_unlock(&tasklist_lock);
75362 +
75363 + fput(our_file);
75364 + return 1;
75365 +}
75366 +
75367 +ssize_t
75368 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75369 +{
75370 + struct gr_arg_wrapper uwrap;
75371 + unsigned char *sprole_salt = NULL;
75372 + unsigned char *sprole_sum = NULL;
75373 + int error = 0;
75374 + int error2 = 0;
75375 + size_t req_count = 0;
75376 + unsigned char oldmode = 0;
75377 +
75378 + mutex_lock(&gr_dev_mutex);
75379 +
75380 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75381 + error = -EPERM;
75382 + goto out;
75383 + }
75384 +
75385 +#ifdef CONFIG_COMPAT
75386 + pax_open_kernel();
75387 + if (is_compat_task()) {
75388 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75389 + copy_gr_arg = &copy_gr_arg_compat;
75390 + copy_acl_object_label = &copy_acl_object_label_compat;
75391 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75392 + copy_acl_role_label = &copy_acl_role_label_compat;
75393 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75394 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75395 + copy_role_transition = &copy_role_transition_compat;
75396 + copy_sprole_pw = &copy_sprole_pw_compat;
75397 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75398 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75399 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75400 + } else {
75401 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75402 + copy_gr_arg = &copy_gr_arg_normal;
75403 + copy_acl_object_label = &copy_acl_object_label_normal;
75404 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75405 + copy_acl_role_label = &copy_acl_role_label_normal;
75406 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75407 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75408 + copy_role_transition = &copy_role_transition_normal;
75409 + copy_sprole_pw = &copy_sprole_pw_normal;
75410 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75411 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75412 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75413 + }
75414 + pax_close_kernel();
75415 +#endif
75416 +
75417 + req_count = get_gr_arg_wrapper_size();
75418 +
75419 + if (count != req_count) {
75420 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75421 + error = -EINVAL;
75422 + goto out;
75423 + }
75424 +
75425 +
75426 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75427 + gr_auth_expires = 0;
75428 + gr_auth_attempts = 0;
75429 + }
75430 +
75431 + error = copy_gr_arg_wrapper(buf, &uwrap);
75432 + if (error)
75433 + goto out;
75434 +
75435 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75436 + if (error)
75437 + goto out;
75438 +
75439 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75440 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75441 + time_after(gr_auth_expires, get_seconds())) {
75442 + error = -EBUSY;
75443 + goto out;
75444 + }
75445 +
75446 + /* if non-root trying to do anything other than use a special role,
75447 + do not attempt authentication, do not count towards authentication
75448 + locking
75449 + */
75450 +
75451 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75452 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75453 + gr_is_global_nonroot(current_uid())) {
75454 + error = -EPERM;
75455 + goto out;
75456 + }
75457 +
75458 + /* ensure pw and special role name are null terminated */
75459 +
75460 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75461 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75462 +
75463 + /* Okay.
75464 + * We have our enough of the argument structure..(we have yet
75465 + * to copy_from_user the tables themselves) . Copy the tables
75466 + * only if we need them, i.e. for loading operations. */
75467 +
75468 + switch (gr_usermode->mode) {
75469 + case GR_STATUS:
75470 + if (gr_acl_is_enabled()) {
75471 + error = 1;
75472 + if (!gr_check_secure_terminal(current))
75473 + error = 3;
75474 + } else
75475 + error = 2;
75476 + goto out;
75477 + case GR_SHUTDOWN:
75478 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75479 + stop_machine(gr_rbac_disable, NULL, NULL);
75480 + free_variables(false);
75481 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75482 + memset(gr_system_salt, 0, GR_SALT_LEN);
75483 + memset(gr_system_sum, 0, GR_SHA_LEN);
75484 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75485 + } else if (gr_acl_is_enabled()) {
75486 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75487 + error = -EPERM;
75488 + } else {
75489 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75490 + error = -EAGAIN;
75491 + }
75492 + break;
75493 + case GR_ENABLE:
75494 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75495 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75496 + else {
75497 + if (gr_acl_is_enabled())
75498 + error = -EAGAIN;
75499 + else
75500 + error = error2;
75501 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75502 + }
75503 + break;
75504 + case GR_OLDRELOAD:
75505 + oldmode = 1;
75506 + case GR_RELOAD:
75507 + if (!gr_acl_is_enabled()) {
75508 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75509 + error = -EAGAIN;
75510 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75511 + error2 = gracl_reload(gr_usermode, oldmode);
75512 + if (!error2)
75513 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75514 + else {
75515 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75516 + error = error2;
75517 + }
75518 + } else {
75519 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75520 + error = -EPERM;
75521 + }
75522 + break;
75523 + case GR_SEGVMOD:
75524 + if (unlikely(!gr_acl_is_enabled())) {
75525 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75526 + error = -EAGAIN;
75527 + break;
75528 + }
75529 +
75530 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75531 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75532 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75533 + struct acl_subject_label *segvacl;
75534 + segvacl =
75535 + lookup_acl_subj_label(gr_usermode->segv_inode,
75536 + gr_usermode->segv_device,
75537 + current->role);
75538 + if (segvacl) {
75539 + segvacl->crashes = 0;
75540 + segvacl->expires = 0;
75541 + }
75542 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75543 + gr_remove_uid(gr_usermode->segv_uid);
75544 + }
75545 + } else {
75546 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75547 + error = -EPERM;
75548 + }
75549 + break;
75550 + case GR_SPROLE:
75551 + case GR_SPROLEPAM:
75552 + if (unlikely(!gr_acl_is_enabled())) {
75553 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75554 + error = -EAGAIN;
75555 + break;
75556 + }
75557 +
75558 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75559 + current->role->expires = 0;
75560 + current->role->auth_attempts = 0;
75561 + }
75562 +
75563 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75564 + time_after(current->role->expires, get_seconds())) {
75565 + error = -EBUSY;
75566 + goto out;
75567 + }
75568 +
75569 + if (lookup_special_role_auth
75570 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75571 + && ((!sprole_salt && !sprole_sum)
75572 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75573 + char *p = "";
75574 + assign_special_role(gr_usermode->sp_role);
75575 + read_lock(&tasklist_lock);
75576 + if (current->real_parent)
75577 + p = current->real_parent->role->rolename;
75578 + read_unlock(&tasklist_lock);
75579 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75580 + p, acl_sp_role_value);
75581 + } else {
75582 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75583 + error = -EPERM;
75584 + if(!(current->role->auth_attempts++))
75585 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75586 +
75587 + goto out;
75588 + }
75589 + break;
75590 + case GR_UNSPROLE:
75591 + if (unlikely(!gr_acl_is_enabled())) {
75592 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75593 + error = -EAGAIN;
75594 + break;
75595 + }
75596 +
75597 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75598 + char *p = "";
75599 + int i = 0;
75600 +
75601 + read_lock(&tasklist_lock);
75602 + if (current->real_parent) {
75603 + p = current->real_parent->role->rolename;
75604 + i = current->real_parent->acl_role_id;
75605 + }
75606 + read_unlock(&tasklist_lock);
75607 +
75608 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75609 + gr_set_acls(1);
75610 + } else {
75611 + error = -EPERM;
75612 + goto out;
75613 + }
75614 + break;
75615 + default:
75616 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75617 + error = -EINVAL;
75618 + break;
75619 + }
75620 +
75621 + if (error != -EPERM)
75622 + goto out;
75623 +
75624 + if(!(gr_auth_attempts++))
75625 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75626 +
75627 + out:
75628 + mutex_unlock(&gr_dev_mutex);
75629 +
75630 + if (!error)
75631 + error = req_count;
75632 +
75633 + return error;
75634 +}
75635 +
75636 +int
75637 +gr_set_acls(const int type)
75638 +{
75639 + struct task_struct *task, *task2;
75640 + struct acl_role_label *role = current->role;
75641 + struct acl_subject_label *subj;
75642 + __u16 acl_role_id = current->acl_role_id;
75643 + const struct cred *cred;
75644 + int ret;
75645 +
75646 + rcu_read_lock();
75647 + read_lock(&tasklist_lock);
75648 + read_lock(&grsec_exec_file_lock);
75649 + do_each_thread(task2, task) {
75650 + /* check to see if we're called from the exit handler,
75651 + if so, only replace ACLs that have inherited the admin
75652 + ACL */
75653 +
75654 + if (type && (task->role != role ||
75655 + task->acl_role_id != acl_role_id))
75656 + continue;
75657 +
75658 + task->acl_role_id = 0;
75659 + task->acl_sp_role = 0;
75660 + task->inherited = 0;
75661 +
75662 + if (task->exec_file) {
75663 + cred = __task_cred(task);
75664 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75665 + subj = __gr_get_subject_for_task(polstate, task, NULL, 1);
75666 + if (subj == NULL) {
75667 + ret = -EINVAL;
75668 + read_unlock(&grsec_exec_file_lock);
75669 + read_unlock(&tasklist_lock);
75670 + rcu_read_unlock();
75671 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75672 + return ret;
75673 + }
75674 + __gr_apply_subject_to_task(polstate, task, subj);
75675 + } else {
75676 + // it's a kernel process
75677 + task->role = polstate->kernel_role;
75678 + task->acl = polstate->kernel_role->root_label;
75679 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75680 + task->acl->mode &= ~GR_PROCFIND;
75681 +#endif
75682 + }
75683 + } while_each_thread(task2, task);
75684 + read_unlock(&grsec_exec_file_lock);
75685 + read_unlock(&tasklist_lock);
75686 + rcu_read_unlock();
75687 +
75688 + return 0;
75689 +}
75690 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75691 new file mode 100644
75692 index 0000000..39645c9
75693 --- /dev/null
75694 +++ b/grsecurity/gracl_res.c
75695 @@ -0,0 +1,68 @@
75696 +#include <linux/kernel.h>
75697 +#include <linux/sched.h>
75698 +#include <linux/gracl.h>
75699 +#include <linux/grinternal.h>
75700 +
75701 +static const char *restab_log[] = {
75702 + [RLIMIT_CPU] = "RLIMIT_CPU",
75703 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75704 + [RLIMIT_DATA] = "RLIMIT_DATA",
75705 + [RLIMIT_STACK] = "RLIMIT_STACK",
75706 + [RLIMIT_CORE] = "RLIMIT_CORE",
75707 + [RLIMIT_RSS] = "RLIMIT_RSS",
75708 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75709 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75710 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75711 + [RLIMIT_AS] = "RLIMIT_AS",
75712 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75713 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75714 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75715 + [RLIMIT_NICE] = "RLIMIT_NICE",
75716 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75717 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75718 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75719 +};
75720 +
75721 +void
75722 +gr_log_resource(const struct task_struct *task,
75723 + const int res, const unsigned long wanted, const int gt)
75724 +{
75725 + const struct cred *cred;
75726 + unsigned long rlim;
75727 +
75728 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75729 + return;
75730 +
75731 + // not yet supported resource
75732 + if (unlikely(!restab_log[res]))
75733 + return;
75734 +
75735 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75736 + rlim = task_rlimit_max(task, res);
75737 + else
75738 + rlim = task_rlimit(task, res);
75739 +
75740 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75741 + return;
75742 +
75743 + rcu_read_lock();
75744 + cred = __task_cred(task);
75745 +
75746 + if (res == RLIMIT_NPROC &&
75747 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75748 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75749 + goto out_rcu_unlock;
75750 + else if (res == RLIMIT_MEMLOCK &&
75751 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75752 + goto out_rcu_unlock;
75753 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75754 + goto out_rcu_unlock;
75755 + rcu_read_unlock();
75756 +
75757 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75758 +
75759 + return;
75760 +out_rcu_unlock:
75761 + rcu_read_unlock();
75762 + return;
75763 +}
75764 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75765 new file mode 100644
75766 index 0000000..218b66b
75767 --- /dev/null
75768 +++ b/grsecurity/gracl_segv.c
75769 @@ -0,0 +1,324 @@
75770 +#include <linux/kernel.h>
75771 +#include <linux/mm.h>
75772 +#include <asm/uaccess.h>
75773 +#include <asm/errno.h>
75774 +#include <asm/mman.h>
75775 +#include <net/sock.h>
75776 +#include <linux/file.h>
75777 +#include <linux/fs.h>
75778 +#include <linux/net.h>
75779 +#include <linux/in.h>
75780 +#include <linux/slab.h>
75781 +#include <linux/types.h>
75782 +#include <linux/sched.h>
75783 +#include <linux/timer.h>
75784 +#include <linux/gracl.h>
75785 +#include <linux/grsecurity.h>
75786 +#include <linux/grinternal.h>
75787 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75788 +#include <linux/magic.h>
75789 +#include <linux/pagemap.h>
75790 +#include "../fs/btrfs/async-thread.h"
75791 +#include "../fs/btrfs/ctree.h"
75792 +#include "../fs/btrfs/btrfs_inode.h"
75793 +#endif
75794 +
75795 +static struct crash_uid *uid_set;
75796 +static unsigned short uid_used;
75797 +static DEFINE_SPINLOCK(gr_uid_lock);
75798 +extern rwlock_t gr_inode_lock;
75799 +extern struct acl_subject_label *
75800 + lookup_acl_subj_label(const u64 inode, const dev_t dev,
75801 + struct acl_role_label *role);
75802 +
75803 +static inline dev_t __get_dev(const struct dentry *dentry)
75804 +{
75805 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75806 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75807 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75808 + else
75809 +#endif
75810 + return dentry->d_sb->s_dev;
75811 +}
75812 +
75813 +static inline u64 __get_ino(const struct dentry *dentry)
75814 +{
75815 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75816 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75817 + return btrfs_ino(dentry->d_inode);
75818 + else
75819 +#endif
75820 + return dentry->d_inode->i_ino;
75821 +}
75822 +
75823 +int
75824 +gr_init_uidset(void)
75825 +{
75826 + uid_set =
75827 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75828 + uid_used = 0;
75829 +
75830 + return uid_set ? 1 : 0;
75831 +}
75832 +
75833 +void
75834 +gr_free_uidset(void)
75835 +{
75836 + if (uid_set) {
75837 + struct crash_uid *tmpset;
75838 + spin_lock(&gr_uid_lock);
75839 + tmpset = uid_set;
75840 + uid_set = NULL;
75841 + uid_used = 0;
75842 + spin_unlock(&gr_uid_lock);
75843 + if (tmpset)
75844 + kfree(tmpset);
75845 + }
75846 +
75847 + return;
75848 +}
75849 +
75850 +int
75851 +gr_find_uid(const uid_t uid)
75852 +{
75853 + struct crash_uid *tmp = uid_set;
75854 + uid_t buid;
75855 + int low = 0, high = uid_used - 1, mid;
75856 +
75857 + while (high >= low) {
75858 + mid = (low + high) >> 1;
75859 + buid = tmp[mid].uid;
75860 + if (buid == uid)
75861 + return mid;
75862 + if (buid > uid)
75863 + high = mid - 1;
75864 + if (buid < uid)
75865 + low = mid + 1;
75866 + }
75867 +
75868 + return -1;
75869 +}
75870 +
75871 +static __inline__ void
75872 +gr_insertsort(void)
75873 +{
75874 + unsigned short i, j;
75875 + struct crash_uid index;
75876 +
75877 + for (i = 1; i < uid_used; i++) {
75878 + index = uid_set[i];
75879 + j = i;
75880 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75881 + uid_set[j] = uid_set[j - 1];
75882 + j--;
75883 + }
75884 + uid_set[j] = index;
75885 + }
75886 +
75887 + return;
75888 +}
75889 +
75890 +static __inline__ void
75891 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75892 +{
75893 + int loc;
75894 + uid_t uid = GR_GLOBAL_UID(kuid);
75895 +
75896 + if (uid_used == GR_UIDTABLE_MAX)
75897 + return;
75898 +
75899 + loc = gr_find_uid(uid);
75900 +
75901 + if (loc >= 0) {
75902 + uid_set[loc].expires = expires;
75903 + return;
75904 + }
75905 +
75906 + uid_set[uid_used].uid = uid;
75907 + uid_set[uid_used].expires = expires;
75908 + uid_used++;
75909 +
75910 + gr_insertsort();
75911 +
75912 + return;
75913 +}
75914 +
75915 +void
75916 +gr_remove_uid(const unsigned short loc)
75917 +{
75918 + unsigned short i;
75919 +
75920 + for (i = loc + 1; i < uid_used; i++)
75921 + uid_set[i - 1] = uid_set[i];
75922 +
75923 + uid_used--;
75924 +
75925 + return;
75926 +}
75927 +
75928 +int
75929 +gr_check_crash_uid(const kuid_t kuid)
75930 +{
75931 + int loc;
75932 + int ret = 0;
75933 + uid_t uid;
75934 +
75935 + if (unlikely(!gr_acl_is_enabled()))
75936 + return 0;
75937 +
75938 + uid = GR_GLOBAL_UID(kuid);
75939 +
75940 + spin_lock(&gr_uid_lock);
75941 + loc = gr_find_uid(uid);
75942 +
75943 + if (loc < 0)
75944 + goto out_unlock;
75945 +
75946 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75947 + gr_remove_uid(loc);
75948 + else
75949 + ret = 1;
75950 +
75951 +out_unlock:
75952 + spin_unlock(&gr_uid_lock);
75953 + return ret;
75954 +}
75955 +
75956 +static __inline__ int
75957 +proc_is_setxid(const struct cred *cred)
75958 +{
75959 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75960 + !uid_eq(cred->uid, cred->fsuid))
75961 + return 1;
75962 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75963 + !gid_eq(cred->gid, cred->fsgid))
75964 + return 1;
75965 +
75966 + return 0;
75967 +}
75968 +
75969 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75970 +
75971 +void
75972 +gr_handle_crash(struct task_struct *task, const int sig)
75973 +{
75974 + struct acl_subject_label *curr;
75975 + struct task_struct *tsk, *tsk2;
75976 + const struct cred *cred;
75977 + const struct cred *cred2;
75978 +
75979 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75980 + return;
75981 +
75982 + if (unlikely(!gr_acl_is_enabled()))
75983 + return;
75984 +
75985 + curr = task->acl;
75986 +
75987 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75988 + return;
75989 +
75990 + if (time_before_eq(curr->expires, get_seconds())) {
75991 + curr->expires = 0;
75992 + curr->crashes = 0;
75993 + }
75994 +
75995 + curr->crashes++;
75996 +
75997 + if (!curr->expires)
75998 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75999 +
76000 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76001 + time_after(curr->expires, get_seconds())) {
76002 + rcu_read_lock();
76003 + cred = __task_cred(task);
76004 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76005 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76006 + spin_lock(&gr_uid_lock);
76007 + gr_insert_uid(cred->uid, curr->expires);
76008 + spin_unlock(&gr_uid_lock);
76009 + curr->expires = 0;
76010 + curr->crashes = 0;
76011 + read_lock(&tasklist_lock);
76012 + do_each_thread(tsk2, tsk) {
76013 + cred2 = __task_cred(tsk);
76014 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76015 + gr_fake_force_sig(SIGKILL, tsk);
76016 + } while_each_thread(tsk2, tsk);
76017 + read_unlock(&tasklist_lock);
76018 + } else {
76019 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76020 + read_lock(&tasklist_lock);
76021 + read_lock(&grsec_exec_file_lock);
76022 + do_each_thread(tsk2, tsk) {
76023 + if (likely(tsk != task)) {
76024 + // if this thread has the same subject as the one that triggered
76025 + // RES_CRASH and it's the same binary, kill it
76026 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76027 + gr_fake_force_sig(SIGKILL, tsk);
76028 + }
76029 + } while_each_thread(tsk2, tsk);
76030 + read_unlock(&grsec_exec_file_lock);
76031 + read_unlock(&tasklist_lock);
76032 + }
76033 + rcu_read_unlock();
76034 + }
76035 +
76036 + return;
76037 +}
76038 +
76039 +int
76040 +gr_check_crash_exec(const struct file *filp)
76041 +{
76042 + struct acl_subject_label *curr;
76043 + struct dentry *dentry;
76044 +
76045 + if (unlikely(!gr_acl_is_enabled()))
76046 + return 0;
76047 +
76048 + read_lock(&gr_inode_lock);
76049 + dentry = filp->f_path.dentry;
76050 + curr = lookup_acl_subj_label(__get_ino(dentry), __get_dev(dentry),
76051 + current->role);
76052 + read_unlock(&gr_inode_lock);
76053 +
76054 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76055 + (!curr->crashes && !curr->expires))
76056 + return 0;
76057 +
76058 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76059 + time_after(curr->expires, get_seconds()))
76060 + return 1;
76061 + else if (time_before_eq(curr->expires, get_seconds())) {
76062 + curr->crashes = 0;
76063 + curr->expires = 0;
76064 + }
76065 +
76066 + return 0;
76067 +}
76068 +
76069 +void
76070 +gr_handle_alertkill(struct task_struct *task)
76071 +{
76072 + struct acl_subject_label *curracl;
76073 + __u32 curr_ip;
76074 + struct task_struct *p, *p2;
76075 +
76076 + if (unlikely(!gr_acl_is_enabled()))
76077 + return;
76078 +
76079 + curracl = task->acl;
76080 + curr_ip = task->signal->curr_ip;
76081 +
76082 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76083 + read_lock(&tasklist_lock);
76084 + do_each_thread(p2, p) {
76085 + if (p->signal->curr_ip == curr_ip)
76086 + gr_fake_force_sig(SIGKILL, p);
76087 + } while_each_thread(p2, p);
76088 + read_unlock(&tasklist_lock);
76089 + } else if (curracl->mode & GR_KILLPROC)
76090 + gr_fake_force_sig(SIGKILL, task);
76091 +
76092 + return;
76093 +}
76094 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76095 new file mode 100644
76096 index 0000000..6b0c9cc
76097 --- /dev/null
76098 +++ b/grsecurity/gracl_shm.c
76099 @@ -0,0 +1,40 @@
76100 +#include <linux/kernel.h>
76101 +#include <linux/mm.h>
76102 +#include <linux/sched.h>
76103 +#include <linux/file.h>
76104 +#include <linux/ipc.h>
76105 +#include <linux/gracl.h>
76106 +#include <linux/grsecurity.h>
76107 +#include <linux/grinternal.h>
76108 +
76109 +int
76110 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76111 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76112 +{
76113 + struct task_struct *task;
76114 +
76115 + if (!gr_acl_is_enabled())
76116 + return 1;
76117 +
76118 + rcu_read_lock();
76119 + read_lock(&tasklist_lock);
76120 +
76121 + task = find_task_by_vpid(shm_cprid);
76122 +
76123 + if (unlikely(!task))
76124 + task = find_task_by_vpid(shm_lapid);
76125 +
76126 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76127 + (task_pid_nr(task) == shm_lapid)) &&
76128 + (task->acl->mode & GR_PROTSHM) &&
76129 + (task->acl != current->acl))) {
76130 + read_unlock(&tasklist_lock);
76131 + rcu_read_unlock();
76132 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76133 + return 0;
76134 + }
76135 + read_unlock(&tasklist_lock);
76136 + rcu_read_unlock();
76137 +
76138 + return 1;
76139 +}
76140 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76141 new file mode 100644
76142 index 0000000..bc0be01
76143 --- /dev/null
76144 +++ b/grsecurity/grsec_chdir.c
76145 @@ -0,0 +1,19 @@
76146 +#include <linux/kernel.h>
76147 +#include <linux/sched.h>
76148 +#include <linux/fs.h>
76149 +#include <linux/file.h>
76150 +#include <linux/grsecurity.h>
76151 +#include <linux/grinternal.h>
76152 +
76153 +void
76154 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76155 +{
76156 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76157 + if ((grsec_enable_chdir && grsec_enable_group &&
76158 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76159 + !grsec_enable_group)) {
76160 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76161 + }
76162 +#endif
76163 + return;
76164 +}
76165 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76166 new file mode 100644
76167 index 0000000..114ea4f
76168 --- /dev/null
76169 +++ b/grsecurity/grsec_chroot.c
76170 @@ -0,0 +1,467 @@
76171 +#include <linux/kernel.h>
76172 +#include <linux/module.h>
76173 +#include <linux/sched.h>
76174 +#include <linux/file.h>
76175 +#include <linux/fs.h>
76176 +#include <linux/mount.h>
76177 +#include <linux/types.h>
76178 +#include "../fs/mount.h"
76179 +#include <linux/grsecurity.h>
76180 +#include <linux/grinternal.h>
76181 +
76182 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76183 +int gr_init_ran;
76184 +#endif
76185 +
76186 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76187 +{
76188 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76189 + struct dentry *tmpd = dentry;
76190 +
76191 + read_seqlock_excl(&mount_lock);
76192 + write_seqlock(&rename_lock);
76193 +
76194 + while (tmpd != mnt->mnt_root) {
76195 + atomic_inc(&tmpd->chroot_refcnt);
76196 + tmpd = tmpd->d_parent;
76197 + }
76198 + atomic_inc(&tmpd->chroot_refcnt);
76199 +
76200 + write_sequnlock(&rename_lock);
76201 + read_sequnlock_excl(&mount_lock);
76202 +#endif
76203 +}
76204 +
76205 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76206 +{
76207 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76208 + struct dentry *tmpd = dentry;
76209 +
76210 + read_seqlock_excl(&mount_lock);
76211 + write_seqlock(&rename_lock);
76212 +
76213 + while (tmpd != mnt->mnt_root) {
76214 + atomic_dec(&tmpd->chroot_refcnt);
76215 + tmpd = tmpd->d_parent;
76216 + }
76217 + atomic_dec(&tmpd->chroot_refcnt);
76218 +
76219 + write_sequnlock(&rename_lock);
76220 + read_sequnlock_excl(&mount_lock);
76221 +#endif
76222 +}
76223 +
76224 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76225 +static struct dentry *get_closest_chroot(struct dentry *dentry)
76226 +{
76227 + write_seqlock(&rename_lock);
76228 + do {
76229 + if (atomic_read(&dentry->chroot_refcnt)) {
76230 + write_sequnlock(&rename_lock);
76231 + return dentry;
76232 + }
76233 + dentry = dentry->d_parent;
76234 + } while (!IS_ROOT(dentry));
76235 + write_sequnlock(&rename_lock);
76236 + return NULL;
76237 +}
76238 +#endif
76239 +
76240 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
76241 + struct dentry *newdentry, struct vfsmount *newmnt)
76242 +{
76243 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76244 + struct dentry *chroot;
76245 +
76246 + if (unlikely(!grsec_enable_chroot_rename))
76247 + return 0;
76248 +
76249 + if (likely(!proc_is_chrooted(current) && gr_is_global_root(current_uid())))
76250 + return 0;
76251 +
76252 + chroot = get_closest_chroot(olddentry);
76253 +
76254 + if (chroot == NULL)
76255 + return 0;
76256 +
76257 + if (is_subdir(newdentry, chroot))
76258 + return 0;
76259 +
76260 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_RENAME_MSG, olddentry, oldmnt);
76261 +
76262 + return 1;
76263 +#else
76264 + return 0;
76265 +#endif
76266 +}
76267 +
76268 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76269 +{
76270 +#ifdef CONFIG_GRKERNSEC
76271 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76272 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76273 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76274 + && gr_init_ran
76275 +#endif
76276 + )
76277 + task->gr_is_chrooted = 1;
76278 + else {
76279 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76280 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76281 + gr_init_ran = 1;
76282 +#endif
76283 + task->gr_is_chrooted = 0;
76284 + }
76285 +
76286 + task->gr_chroot_dentry = path->dentry;
76287 +#endif
76288 + return;
76289 +}
76290 +
76291 +void gr_clear_chroot_entries(struct task_struct *task)
76292 +{
76293 +#ifdef CONFIG_GRKERNSEC
76294 + task->gr_is_chrooted = 0;
76295 + task->gr_chroot_dentry = NULL;
76296 +#endif
76297 + return;
76298 +}
76299 +
76300 +int
76301 +gr_handle_chroot_unix(const pid_t pid)
76302 +{
76303 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76304 + struct task_struct *p;
76305 +
76306 + if (unlikely(!grsec_enable_chroot_unix))
76307 + return 1;
76308 +
76309 + if (likely(!proc_is_chrooted(current)))
76310 + return 1;
76311 +
76312 + rcu_read_lock();
76313 + read_lock(&tasklist_lock);
76314 + p = find_task_by_vpid_unrestricted(pid);
76315 + if (unlikely(p && !have_same_root(current, p))) {
76316 + read_unlock(&tasklist_lock);
76317 + rcu_read_unlock();
76318 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76319 + return 0;
76320 + }
76321 + read_unlock(&tasklist_lock);
76322 + rcu_read_unlock();
76323 +#endif
76324 + return 1;
76325 +}
76326 +
76327 +int
76328 +gr_handle_chroot_nice(void)
76329 +{
76330 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76331 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76332 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76333 + return -EPERM;
76334 + }
76335 +#endif
76336 + return 0;
76337 +}
76338 +
76339 +int
76340 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76341 +{
76342 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76343 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76344 + && proc_is_chrooted(current)) {
76345 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76346 + return -EACCES;
76347 + }
76348 +#endif
76349 + return 0;
76350 +}
76351 +
76352 +int
76353 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76354 +{
76355 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76356 + struct task_struct *p;
76357 + int ret = 0;
76358 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76359 + return ret;
76360 +
76361 + read_lock(&tasklist_lock);
76362 + do_each_pid_task(pid, type, p) {
76363 + if (!have_same_root(current, p)) {
76364 + ret = 1;
76365 + goto out;
76366 + }
76367 + } while_each_pid_task(pid, type, p);
76368 +out:
76369 + read_unlock(&tasklist_lock);
76370 + return ret;
76371 +#endif
76372 + return 0;
76373 +}
76374 +
76375 +int
76376 +gr_pid_is_chrooted(struct task_struct *p)
76377 +{
76378 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76379 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76380 + return 0;
76381 +
76382 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76383 + !have_same_root(current, p)) {
76384 + return 1;
76385 + }
76386 +#endif
76387 + return 0;
76388 +}
76389 +
76390 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76391 +
76392 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76393 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76394 +{
76395 + struct path path, currentroot;
76396 + int ret = 0;
76397 +
76398 + path.dentry = (struct dentry *)u_dentry;
76399 + path.mnt = (struct vfsmount *)u_mnt;
76400 + get_fs_root(current->fs, &currentroot);
76401 + if (path_is_under(&path, &currentroot))
76402 + ret = 1;
76403 + path_put(&currentroot);
76404 +
76405 + return ret;
76406 +}
76407 +#endif
76408 +
76409 +int
76410 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76411 +{
76412 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76413 + if (!grsec_enable_chroot_fchdir)
76414 + return 1;
76415 +
76416 + if (!proc_is_chrooted(current))
76417 + return 1;
76418 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76419 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76420 + return 0;
76421 + }
76422 +#endif
76423 + return 1;
76424 +}
76425 +
76426 +int
76427 +gr_chroot_fhandle(void)
76428 +{
76429 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76430 + if (!grsec_enable_chroot_fchdir)
76431 + return 1;
76432 +
76433 + if (!proc_is_chrooted(current))
76434 + return 1;
76435 + else {
76436 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76437 + return 0;
76438 + }
76439 +#endif
76440 + return 1;
76441 +}
76442 +
76443 +int
76444 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76445 + const u64 shm_createtime)
76446 +{
76447 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76448 + struct task_struct *p;
76449 +
76450 + if (unlikely(!grsec_enable_chroot_shmat))
76451 + return 1;
76452 +
76453 + if (likely(!proc_is_chrooted(current)))
76454 + return 1;
76455 +
76456 + rcu_read_lock();
76457 + read_lock(&tasklist_lock);
76458 +
76459 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76460 + if (time_before_eq64(p->start_time, shm_createtime)) {
76461 + if (have_same_root(current, p)) {
76462 + goto allow;
76463 + } else {
76464 + read_unlock(&tasklist_lock);
76465 + rcu_read_unlock();
76466 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76467 + return 0;
76468 + }
76469 + }
76470 + /* creator exited, pid reuse, fall through to next check */
76471 + }
76472 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76473 + if (unlikely(!have_same_root(current, p))) {
76474 + read_unlock(&tasklist_lock);
76475 + rcu_read_unlock();
76476 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76477 + return 0;
76478 + }
76479 + }
76480 +
76481 +allow:
76482 + read_unlock(&tasklist_lock);
76483 + rcu_read_unlock();
76484 +#endif
76485 + return 1;
76486 +}
76487 +
76488 +void
76489 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76490 +{
76491 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76492 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76493 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76494 +#endif
76495 + return;
76496 +}
76497 +
76498 +int
76499 +gr_handle_chroot_mknod(const struct dentry *dentry,
76500 + const struct vfsmount *mnt, const int mode)
76501 +{
76502 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76503 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76504 + proc_is_chrooted(current)) {
76505 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76506 + return -EPERM;
76507 + }
76508 +#endif
76509 + return 0;
76510 +}
76511 +
76512 +int
76513 +gr_handle_chroot_mount(const struct dentry *dentry,
76514 + const struct vfsmount *mnt, const char *dev_name)
76515 +{
76516 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76517 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76518 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76519 + return -EPERM;
76520 + }
76521 +#endif
76522 + return 0;
76523 +}
76524 +
76525 +int
76526 +gr_handle_chroot_pivot(void)
76527 +{
76528 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76529 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76530 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76531 + return -EPERM;
76532 + }
76533 +#endif
76534 + return 0;
76535 +}
76536 +
76537 +int
76538 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76539 +{
76540 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76541 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76542 + !gr_is_outside_chroot(dentry, mnt)) {
76543 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76544 + return -EPERM;
76545 + }
76546 +#endif
76547 + return 0;
76548 +}
76549 +
76550 +extern const char *captab_log[];
76551 +extern int captab_log_entries;
76552 +
76553 +int
76554 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76555 +{
76556 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76557 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76558 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76559 + if (cap_raised(chroot_caps, cap)) {
76560 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76561 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76562 + }
76563 + return 0;
76564 + }
76565 + }
76566 +#endif
76567 + return 1;
76568 +}
76569 +
76570 +int
76571 +gr_chroot_is_capable(const int cap)
76572 +{
76573 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76574 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76575 +#endif
76576 + return 1;
76577 +}
76578 +
76579 +int
76580 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76581 +{
76582 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76583 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76584 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76585 + if (cap_raised(chroot_caps, cap)) {
76586 + return 0;
76587 + }
76588 + }
76589 +#endif
76590 + return 1;
76591 +}
76592 +
76593 +int
76594 +gr_chroot_is_capable_nolog(const int cap)
76595 +{
76596 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76597 + return gr_task_chroot_is_capable_nolog(current, cap);
76598 +#endif
76599 + return 1;
76600 +}
76601 +
76602 +int
76603 +gr_handle_chroot_sysctl(const int op)
76604 +{
76605 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76606 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76607 + proc_is_chrooted(current))
76608 + return -EACCES;
76609 +#endif
76610 + return 0;
76611 +}
76612 +
76613 +void
76614 +gr_handle_chroot_chdir(const struct path *path)
76615 +{
76616 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76617 + if (grsec_enable_chroot_chdir)
76618 + set_fs_pwd(current->fs, path);
76619 +#endif
76620 + return;
76621 +}
76622 +
76623 +int
76624 +gr_handle_chroot_chmod(const struct dentry *dentry,
76625 + const struct vfsmount *mnt, const int mode)
76626 +{
76627 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76628 + /* allow chmod +s on directories, but not files */
76629 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76630 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76631 + proc_is_chrooted(current)) {
76632 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76633 + return -EPERM;
76634 + }
76635 +#endif
76636 + return 0;
76637 +}
76638 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76639 new file mode 100644
76640 index 0000000..946f750
76641 --- /dev/null
76642 +++ b/grsecurity/grsec_disabled.c
76643 @@ -0,0 +1,445 @@
76644 +#include <linux/kernel.h>
76645 +#include <linux/module.h>
76646 +#include <linux/sched.h>
76647 +#include <linux/file.h>
76648 +#include <linux/fs.h>
76649 +#include <linux/kdev_t.h>
76650 +#include <linux/net.h>
76651 +#include <linux/in.h>
76652 +#include <linux/ip.h>
76653 +#include <linux/skbuff.h>
76654 +#include <linux/sysctl.h>
76655 +
76656 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76657 +void
76658 +pax_set_initial_flags(struct linux_binprm *bprm)
76659 +{
76660 + return;
76661 +}
76662 +#endif
76663 +
76664 +#ifdef CONFIG_SYSCTL
76665 +__u32
76666 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76667 +{
76668 + return 0;
76669 +}
76670 +#endif
76671 +
76672 +#ifdef CONFIG_TASKSTATS
76673 +int gr_is_taskstats_denied(int pid)
76674 +{
76675 + return 0;
76676 +}
76677 +#endif
76678 +
76679 +int
76680 +gr_acl_is_enabled(void)
76681 +{
76682 + return 0;
76683 +}
76684 +
76685 +int
76686 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76687 +{
76688 + return 0;
76689 +}
76690 +
76691 +void
76692 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76693 +{
76694 + return;
76695 +}
76696 +
76697 +int
76698 +gr_handle_rawio(const struct inode *inode)
76699 +{
76700 + return 0;
76701 +}
76702 +
76703 +void
76704 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76705 +{
76706 + return;
76707 +}
76708 +
76709 +int
76710 +gr_handle_ptrace(struct task_struct *task, const long request)
76711 +{
76712 + return 0;
76713 +}
76714 +
76715 +int
76716 +gr_handle_proc_ptrace(struct task_struct *task)
76717 +{
76718 + return 0;
76719 +}
76720 +
76721 +int
76722 +gr_set_acls(const int type)
76723 +{
76724 + return 0;
76725 +}
76726 +
76727 +int
76728 +gr_check_hidden_task(const struct task_struct *tsk)
76729 +{
76730 + return 0;
76731 +}
76732 +
76733 +int
76734 +gr_check_protected_task(const struct task_struct *task)
76735 +{
76736 + return 0;
76737 +}
76738 +
76739 +int
76740 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76741 +{
76742 + return 0;
76743 +}
76744 +
76745 +void
76746 +gr_copy_label(struct task_struct *tsk)
76747 +{
76748 + return;
76749 +}
76750 +
76751 +void
76752 +gr_set_pax_flags(struct task_struct *task)
76753 +{
76754 + return;
76755 +}
76756 +
76757 +int
76758 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76759 + const int unsafe_share)
76760 +{
76761 + return 0;
76762 +}
76763 +
76764 +void
76765 +gr_handle_delete(const u64 ino, const dev_t dev)
76766 +{
76767 + return;
76768 +}
76769 +
76770 +void
76771 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76772 +{
76773 + return;
76774 +}
76775 +
76776 +void
76777 +gr_handle_crash(struct task_struct *task, const int sig)
76778 +{
76779 + return;
76780 +}
76781 +
76782 +int
76783 +gr_check_crash_exec(const struct file *filp)
76784 +{
76785 + return 0;
76786 +}
76787 +
76788 +int
76789 +gr_check_crash_uid(const kuid_t uid)
76790 +{
76791 + return 0;
76792 +}
76793 +
76794 +void
76795 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76796 + struct dentry *old_dentry,
76797 + struct dentry *new_dentry,
76798 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76799 +{
76800 + return;
76801 +}
76802 +
76803 +int
76804 +gr_search_socket(const int family, const int type, const int protocol)
76805 +{
76806 + return 1;
76807 +}
76808 +
76809 +int
76810 +gr_search_connectbind(const int mode, const struct socket *sock,
76811 + const struct sockaddr_in *addr)
76812 +{
76813 + return 0;
76814 +}
76815 +
76816 +void
76817 +gr_handle_alertkill(struct task_struct *task)
76818 +{
76819 + return;
76820 +}
76821 +
76822 +__u32
76823 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76824 +{
76825 + return 1;
76826 +}
76827 +
76828 +__u32
76829 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76830 + const struct vfsmount * mnt)
76831 +{
76832 + return 1;
76833 +}
76834 +
76835 +__u32
76836 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76837 + int acc_mode)
76838 +{
76839 + return 1;
76840 +}
76841 +
76842 +__u32
76843 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76844 +{
76845 + return 1;
76846 +}
76847 +
76848 +__u32
76849 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76850 +{
76851 + return 1;
76852 +}
76853 +
76854 +int
76855 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76856 + unsigned int *vm_flags)
76857 +{
76858 + return 1;
76859 +}
76860 +
76861 +__u32
76862 +gr_acl_handle_truncate(const struct dentry * dentry,
76863 + const struct vfsmount * mnt)
76864 +{
76865 + return 1;
76866 +}
76867 +
76868 +__u32
76869 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76870 +{
76871 + return 1;
76872 +}
76873 +
76874 +__u32
76875 +gr_acl_handle_access(const struct dentry * dentry,
76876 + const struct vfsmount * mnt, const int fmode)
76877 +{
76878 + return 1;
76879 +}
76880 +
76881 +__u32
76882 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76883 + umode_t *mode)
76884 +{
76885 + return 1;
76886 +}
76887 +
76888 +__u32
76889 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76890 +{
76891 + return 1;
76892 +}
76893 +
76894 +__u32
76895 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76896 +{
76897 + return 1;
76898 +}
76899 +
76900 +__u32
76901 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76902 +{
76903 + return 1;
76904 +}
76905 +
76906 +void
76907 +grsecurity_init(void)
76908 +{
76909 + return;
76910 +}
76911 +
76912 +umode_t gr_acl_umask(void)
76913 +{
76914 + return 0;
76915 +}
76916 +
76917 +__u32
76918 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76919 + const struct dentry * parent_dentry,
76920 + const struct vfsmount * parent_mnt,
76921 + const int mode)
76922 +{
76923 + return 1;
76924 +}
76925 +
76926 +__u32
76927 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76928 + const struct dentry * parent_dentry,
76929 + const struct vfsmount * parent_mnt)
76930 +{
76931 + return 1;
76932 +}
76933 +
76934 +__u32
76935 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76936 + const struct dentry * parent_dentry,
76937 + const struct vfsmount * parent_mnt, const struct filename *from)
76938 +{
76939 + return 1;
76940 +}
76941 +
76942 +__u32
76943 +gr_acl_handle_link(const struct dentry * new_dentry,
76944 + const struct dentry * parent_dentry,
76945 + const struct vfsmount * parent_mnt,
76946 + const struct dentry * old_dentry,
76947 + const struct vfsmount * old_mnt, const struct filename *to)
76948 +{
76949 + return 1;
76950 +}
76951 +
76952 +int
76953 +gr_acl_handle_rename(const struct dentry *new_dentry,
76954 + const struct dentry *parent_dentry,
76955 + const struct vfsmount *parent_mnt,
76956 + const struct dentry *old_dentry,
76957 + const struct inode *old_parent_inode,
76958 + const struct vfsmount *old_mnt, const struct filename *newname,
76959 + unsigned int flags)
76960 +{
76961 + return 0;
76962 +}
76963 +
76964 +int
76965 +gr_acl_handle_filldir(const struct file *file, const char *name,
76966 + const int namelen, const u64 ino)
76967 +{
76968 + return 1;
76969 +}
76970 +
76971 +int
76972 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76973 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76974 +{
76975 + return 1;
76976 +}
76977 +
76978 +int
76979 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76980 +{
76981 + return 0;
76982 +}
76983 +
76984 +int
76985 +gr_search_accept(const struct socket *sock)
76986 +{
76987 + return 0;
76988 +}
76989 +
76990 +int
76991 +gr_search_listen(const struct socket *sock)
76992 +{
76993 + return 0;
76994 +}
76995 +
76996 +int
76997 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76998 +{
76999 + return 0;
77000 +}
77001 +
77002 +__u32
77003 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77004 +{
77005 + return 1;
77006 +}
77007 +
77008 +__u32
77009 +gr_acl_handle_creat(const struct dentry * dentry,
77010 + const struct dentry * p_dentry,
77011 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77012 + const int imode)
77013 +{
77014 + return 1;
77015 +}
77016 +
77017 +void
77018 +gr_acl_handle_exit(void)
77019 +{
77020 + return;
77021 +}
77022 +
77023 +int
77024 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77025 +{
77026 + return 1;
77027 +}
77028 +
77029 +void
77030 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77031 +{
77032 + return;
77033 +}
77034 +
77035 +int
77036 +gr_acl_handle_procpidmem(const struct task_struct *task)
77037 +{
77038 + return 0;
77039 +}
77040 +
77041 +int
77042 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77043 +{
77044 + return 0;
77045 +}
77046 +
77047 +int
77048 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77049 +{
77050 + return 0;
77051 +}
77052 +
77053 +int
77054 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77055 +{
77056 + return 0;
77057 +}
77058 +
77059 +int
77060 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77061 +{
77062 + return 0;
77063 +}
77064 +
77065 +int gr_acl_enable_at_secure(void)
77066 +{
77067 + return 0;
77068 +}
77069 +
77070 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77071 +{
77072 + return dentry->d_sb->s_dev;
77073 +}
77074 +
77075 +u64 gr_get_ino_from_dentry(struct dentry *dentry)
77076 +{
77077 + return dentry->d_inode->i_ino;
77078 +}
77079 +
77080 +void gr_put_exec_file(struct task_struct *task)
77081 +{
77082 + return;
77083 +}
77084 +
77085 +#ifdef CONFIG_SECURITY
77086 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77087 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77088 +#endif
77089 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77090 new file mode 100644
77091 index 0000000..14638ff
77092 --- /dev/null
77093 +++ b/grsecurity/grsec_exec.c
77094 @@ -0,0 +1,188 @@
77095 +#include <linux/kernel.h>
77096 +#include <linux/sched.h>
77097 +#include <linux/file.h>
77098 +#include <linux/binfmts.h>
77099 +#include <linux/fs.h>
77100 +#include <linux/types.h>
77101 +#include <linux/grdefs.h>
77102 +#include <linux/grsecurity.h>
77103 +#include <linux/grinternal.h>
77104 +#include <linux/capability.h>
77105 +#include <linux/module.h>
77106 +#include <linux/compat.h>
77107 +
77108 +#include <asm/uaccess.h>
77109 +
77110 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77111 +static char gr_exec_arg_buf[132];
77112 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77113 +#endif
77114 +
77115 +struct user_arg_ptr {
77116 +#ifdef CONFIG_COMPAT
77117 + bool is_compat;
77118 +#endif
77119 + union {
77120 + const char __user *const __user *native;
77121 +#ifdef CONFIG_COMPAT
77122 + const compat_uptr_t __user *compat;
77123 +#endif
77124 + } ptr;
77125 +};
77126 +
77127 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77128 +
77129 +void
77130 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77131 +{
77132 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77133 + char *grarg = gr_exec_arg_buf;
77134 + unsigned int i, x, execlen = 0;
77135 + char c;
77136 +
77137 + if (!((grsec_enable_execlog && grsec_enable_group &&
77138 + in_group_p(grsec_audit_gid))
77139 + || (grsec_enable_execlog && !grsec_enable_group)))
77140 + return;
77141 +
77142 + mutex_lock(&gr_exec_arg_mutex);
77143 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77144 +
77145 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77146 + const char __user *p;
77147 + unsigned int len;
77148 +
77149 + p = get_user_arg_ptr(argv, i);
77150 + if (IS_ERR(p))
77151 + goto log;
77152 +
77153 + len = strnlen_user(p, 128 - execlen);
77154 + if (len > 128 - execlen)
77155 + len = 128 - execlen;
77156 + else if (len > 0)
77157 + len--;
77158 + if (copy_from_user(grarg + execlen, p, len))
77159 + goto log;
77160 +
77161 + /* rewrite unprintable characters */
77162 + for (x = 0; x < len; x++) {
77163 + c = *(grarg + execlen + x);
77164 + if (c < 32 || c > 126)
77165 + *(grarg + execlen + x) = ' ';
77166 + }
77167 +
77168 + execlen += len;
77169 + *(grarg + execlen) = ' ';
77170 + *(grarg + execlen + 1) = '\0';
77171 + execlen++;
77172 + }
77173 +
77174 + log:
77175 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77176 + bprm->file->f_path.mnt, grarg);
77177 + mutex_unlock(&gr_exec_arg_mutex);
77178 +#endif
77179 + return;
77180 +}
77181 +
77182 +#ifdef CONFIG_GRKERNSEC
77183 +extern int gr_acl_is_capable(const int cap);
77184 +extern int gr_acl_is_capable_nolog(const int cap);
77185 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77186 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77187 +extern int gr_chroot_is_capable(const int cap);
77188 +extern int gr_chroot_is_capable_nolog(const int cap);
77189 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77190 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77191 +#endif
77192 +
77193 +const char *captab_log[] = {
77194 + "CAP_CHOWN",
77195 + "CAP_DAC_OVERRIDE",
77196 + "CAP_DAC_READ_SEARCH",
77197 + "CAP_FOWNER",
77198 + "CAP_FSETID",
77199 + "CAP_KILL",
77200 + "CAP_SETGID",
77201 + "CAP_SETUID",
77202 + "CAP_SETPCAP",
77203 + "CAP_LINUX_IMMUTABLE",
77204 + "CAP_NET_BIND_SERVICE",
77205 + "CAP_NET_BROADCAST",
77206 + "CAP_NET_ADMIN",
77207 + "CAP_NET_RAW",
77208 + "CAP_IPC_LOCK",
77209 + "CAP_IPC_OWNER",
77210 + "CAP_SYS_MODULE",
77211 + "CAP_SYS_RAWIO",
77212 + "CAP_SYS_CHROOT",
77213 + "CAP_SYS_PTRACE",
77214 + "CAP_SYS_PACCT",
77215 + "CAP_SYS_ADMIN",
77216 + "CAP_SYS_BOOT",
77217 + "CAP_SYS_NICE",
77218 + "CAP_SYS_RESOURCE",
77219 + "CAP_SYS_TIME",
77220 + "CAP_SYS_TTY_CONFIG",
77221 + "CAP_MKNOD",
77222 + "CAP_LEASE",
77223 + "CAP_AUDIT_WRITE",
77224 + "CAP_AUDIT_CONTROL",
77225 + "CAP_SETFCAP",
77226 + "CAP_MAC_OVERRIDE",
77227 + "CAP_MAC_ADMIN",
77228 + "CAP_SYSLOG",
77229 + "CAP_WAKE_ALARM",
77230 + "CAP_BLOCK_SUSPEND"
77231 +};
77232 +
77233 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77234 +
77235 +int gr_is_capable(const int cap)
77236 +{
77237 +#ifdef CONFIG_GRKERNSEC
77238 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77239 + return 1;
77240 + return 0;
77241 +#else
77242 + return 1;
77243 +#endif
77244 +}
77245 +
77246 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77247 +{
77248 +#ifdef CONFIG_GRKERNSEC
77249 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77250 + return 1;
77251 + return 0;
77252 +#else
77253 + return 1;
77254 +#endif
77255 +}
77256 +
77257 +int gr_is_capable_nolog(const int cap)
77258 +{
77259 +#ifdef CONFIG_GRKERNSEC
77260 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77261 + return 1;
77262 + return 0;
77263 +#else
77264 + return 1;
77265 +#endif
77266 +}
77267 +
77268 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77269 +{
77270 +#ifdef CONFIG_GRKERNSEC
77271 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77272 + return 1;
77273 + return 0;
77274 +#else
77275 + return 1;
77276 +#endif
77277 +}
77278 +
77279 +EXPORT_SYMBOL_GPL(gr_is_capable);
77280 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77281 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77282 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77283 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77284 new file mode 100644
77285 index 0000000..06cc6ea
77286 --- /dev/null
77287 +++ b/grsecurity/grsec_fifo.c
77288 @@ -0,0 +1,24 @@
77289 +#include <linux/kernel.h>
77290 +#include <linux/sched.h>
77291 +#include <linux/fs.h>
77292 +#include <linux/file.h>
77293 +#include <linux/grinternal.h>
77294 +
77295 +int
77296 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77297 + const struct dentry *dir, const int flag, const int acc_mode)
77298 +{
77299 +#ifdef CONFIG_GRKERNSEC_FIFO
77300 + const struct cred *cred = current_cred();
77301 +
77302 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77303 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77304 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77305 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77306 + if (!inode_permission(dentry->d_inode, acc_mode))
77307 + 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));
77308 + return -EACCES;
77309 + }
77310 +#endif
77311 + return 0;
77312 +}
77313 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77314 new file mode 100644
77315 index 0000000..8ca18bf
77316 --- /dev/null
77317 +++ b/grsecurity/grsec_fork.c
77318 @@ -0,0 +1,23 @@
77319 +#include <linux/kernel.h>
77320 +#include <linux/sched.h>
77321 +#include <linux/grsecurity.h>
77322 +#include <linux/grinternal.h>
77323 +#include <linux/errno.h>
77324 +
77325 +void
77326 +gr_log_forkfail(const int retval)
77327 +{
77328 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77329 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77330 + switch (retval) {
77331 + case -EAGAIN:
77332 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77333 + break;
77334 + case -ENOMEM:
77335 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77336 + break;
77337 + }
77338 + }
77339 +#endif
77340 + return;
77341 +}
77342 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77343 new file mode 100644
77344 index 0000000..4ed9e7d
77345 --- /dev/null
77346 +++ b/grsecurity/grsec_init.c
77347 @@ -0,0 +1,290 @@
77348 +#include <linux/kernel.h>
77349 +#include <linux/sched.h>
77350 +#include <linux/mm.h>
77351 +#include <linux/gracl.h>
77352 +#include <linux/slab.h>
77353 +#include <linux/vmalloc.h>
77354 +#include <linux/percpu.h>
77355 +#include <linux/module.h>
77356 +
77357 +int grsec_enable_ptrace_readexec;
77358 +int grsec_enable_setxid;
77359 +int grsec_enable_symlinkown;
77360 +kgid_t grsec_symlinkown_gid;
77361 +int grsec_enable_brute;
77362 +int grsec_enable_link;
77363 +int grsec_enable_dmesg;
77364 +int grsec_enable_harden_ptrace;
77365 +int grsec_enable_harden_ipc;
77366 +int grsec_enable_fifo;
77367 +int grsec_enable_execlog;
77368 +int grsec_enable_signal;
77369 +int grsec_enable_forkfail;
77370 +int grsec_enable_audit_ptrace;
77371 +int grsec_enable_time;
77372 +int grsec_enable_group;
77373 +kgid_t grsec_audit_gid;
77374 +int grsec_enable_chdir;
77375 +int grsec_enable_mount;
77376 +int grsec_enable_rofs;
77377 +int grsec_deny_new_usb;
77378 +int grsec_enable_chroot_findtask;
77379 +int grsec_enable_chroot_mount;
77380 +int grsec_enable_chroot_shmat;
77381 +int grsec_enable_chroot_fchdir;
77382 +int grsec_enable_chroot_double;
77383 +int grsec_enable_chroot_pivot;
77384 +int grsec_enable_chroot_chdir;
77385 +int grsec_enable_chroot_chmod;
77386 +int grsec_enable_chroot_mknod;
77387 +int grsec_enable_chroot_nice;
77388 +int grsec_enable_chroot_execlog;
77389 +int grsec_enable_chroot_caps;
77390 +int grsec_enable_chroot_rename;
77391 +int grsec_enable_chroot_sysctl;
77392 +int grsec_enable_chroot_unix;
77393 +int grsec_enable_tpe;
77394 +kgid_t grsec_tpe_gid;
77395 +int grsec_enable_blackhole;
77396 +#ifdef CONFIG_IPV6_MODULE
77397 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77398 +#endif
77399 +int grsec_lastack_retries;
77400 +int grsec_enable_tpe_all;
77401 +int grsec_enable_tpe_invert;
77402 +int grsec_enable_socket_all;
77403 +kgid_t grsec_socket_all_gid;
77404 +int grsec_enable_socket_client;
77405 +kgid_t grsec_socket_client_gid;
77406 +int grsec_enable_socket_server;
77407 +kgid_t grsec_socket_server_gid;
77408 +int grsec_resource_logging;
77409 +int grsec_disable_privio;
77410 +int grsec_enable_log_rwxmaps;
77411 +int grsec_lock;
77412 +
77413 +DEFINE_SPINLOCK(grsec_alert_lock);
77414 +unsigned long grsec_alert_wtime = 0;
77415 +unsigned long grsec_alert_fyet = 0;
77416 +
77417 +DEFINE_SPINLOCK(grsec_audit_lock);
77418 +
77419 +DEFINE_RWLOCK(grsec_exec_file_lock);
77420 +
77421 +char *gr_shared_page[4];
77422 +
77423 +char *gr_alert_log_fmt;
77424 +char *gr_audit_log_fmt;
77425 +char *gr_alert_log_buf;
77426 +char *gr_audit_log_buf;
77427 +
77428 +extern struct gr_arg *gr_usermode;
77429 +extern unsigned char *gr_system_salt;
77430 +extern unsigned char *gr_system_sum;
77431 +
77432 +void __init
77433 +grsecurity_init(void)
77434 +{
77435 + int j;
77436 + /* create the per-cpu shared pages */
77437 +
77438 +#ifdef CONFIG_X86
77439 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77440 +#endif
77441 +
77442 + for (j = 0; j < 4; j++) {
77443 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77444 + if (gr_shared_page[j] == NULL) {
77445 + panic("Unable to allocate grsecurity shared page");
77446 + return;
77447 + }
77448 + }
77449 +
77450 + /* allocate log buffers */
77451 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77452 + if (!gr_alert_log_fmt) {
77453 + panic("Unable to allocate grsecurity alert log format buffer");
77454 + return;
77455 + }
77456 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77457 + if (!gr_audit_log_fmt) {
77458 + panic("Unable to allocate grsecurity audit log format buffer");
77459 + return;
77460 + }
77461 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77462 + if (!gr_alert_log_buf) {
77463 + panic("Unable to allocate grsecurity alert log buffer");
77464 + return;
77465 + }
77466 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77467 + if (!gr_audit_log_buf) {
77468 + panic("Unable to allocate grsecurity audit log buffer");
77469 + return;
77470 + }
77471 +
77472 + /* allocate memory for authentication structure */
77473 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77474 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77475 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77476 +
77477 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77478 + panic("Unable to allocate grsecurity authentication structure");
77479 + return;
77480 + }
77481 +
77482 +#ifdef CONFIG_GRKERNSEC_IO
77483 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77484 + grsec_disable_privio = 1;
77485 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77486 + grsec_disable_privio = 1;
77487 +#else
77488 + grsec_disable_privio = 0;
77489 +#endif
77490 +#endif
77491 +
77492 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77493 + /* for backward compatibility, tpe_invert always defaults to on if
77494 + enabled in the kernel
77495 + */
77496 + grsec_enable_tpe_invert = 1;
77497 +#endif
77498 +
77499 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77500 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77501 + grsec_lock = 1;
77502 +#endif
77503 +
77504 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77505 + grsec_enable_log_rwxmaps = 1;
77506 +#endif
77507 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77508 + grsec_enable_group = 1;
77509 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77510 +#endif
77511 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77512 + grsec_enable_ptrace_readexec = 1;
77513 +#endif
77514 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77515 + grsec_enable_chdir = 1;
77516 +#endif
77517 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77518 + grsec_enable_harden_ptrace = 1;
77519 +#endif
77520 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77521 + grsec_enable_harden_ipc = 1;
77522 +#endif
77523 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77524 + grsec_enable_mount = 1;
77525 +#endif
77526 +#ifdef CONFIG_GRKERNSEC_LINK
77527 + grsec_enable_link = 1;
77528 +#endif
77529 +#ifdef CONFIG_GRKERNSEC_BRUTE
77530 + grsec_enable_brute = 1;
77531 +#endif
77532 +#ifdef CONFIG_GRKERNSEC_DMESG
77533 + grsec_enable_dmesg = 1;
77534 +#endif
77535 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77536 + grsec_enable_blackhole = 1;
77537 + grsec_lastack_retries = 4;
77538 +#endif
77539 +#ifdef CONFIG_GRKERNSEC_FIFO
77540 + grsec_enable_fifo = 1;
77541 +#endif
77542 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77543 + grsec_enable_execlog = 1;
77544 +#endif
77545 +#ifdef CONFIG_GRKERNSEC_SETXID
77546 + grsec_enable_setxid = 1;
77547 +#endif
77548 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77549 + grsec_enable_signal = 1;
77550 +#endif
77551 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77552 + grsec_enable_forkfail = 1;
77553 +#endif
77554 +#ifdef CONFIG_GRKERNSEC_TIME
77555 + grsec_enable_time = 1;
77556 +#endif
77557 +#ifdef CONFIG_GRKERNSEC_RESLOG
77558 + grsec_resource_logging = 1;
77559 +#endif
77560 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77561 + grsec_enable_chroot_findtask = 1;
77562 +#endif
77563 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77564 + grsec_enable_chroot_unix = 1;
77565 +#endif
77566 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77567 + grsec_enable_chroot_mount = 1;
77568 +#endif
77569 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77570 + grsec_enable_chroot_fchdir = 1;
77571 +#endif
77572 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77573 + grsec_enable_chroot_shmat = 1;
77574 +#endif
77575 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77576 + grsec_enable_audit_ptrace = 1;
77577 +#endif
77578 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77579 + grsec_enable_chroot_double = 1;
77580 +#endif
77581 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77582 + grsec_enable_chroot_pivot = 1;
77583 +#endif
77584 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77585 + grsec_enable_chroot_chdir = 1;
77586 +#endif
77587 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77588 + grsec_enable_chroot_chmod = 1;
77589 +#endif
77590 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77591 + grsec_enable_chroot_mknod = 1;
77592 +#endif
77593 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77594 + grsec_enable_chroot_nice = 1;
77595 +#endif
77596 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77597 + grsec_enable_chroot_execlog = 1;
77598 +#endif
77599 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77600 + grsec_enable_chroot_caps = 1;
77601 +#endif
77602 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
77603 + grsec_enable_chroot_rename = 1;
77604 +#endif
77605 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77606 + grsec_enable_chroot_sysctl = 1;
77607 +#endif
77608 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77609 + grsec_enable_symlinkown = 1;
77610 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77611 +#endif
77612 +#ifdef CONFIG_GRKERNSEC_TPE
77613 + grsec_enable_tpe = 1;
77614 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77615 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77616 + grsec_enable_tpe_all = 1;
77617 +#endif
77618 +#endif
77619 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77620 + grsec_enable_socket_all = 1;
77621 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77622 +#endif
77623 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77624 + grsec_enable_socket_client = 1;
77625 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77626 +#endif
77627 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77628 + grsec_enable_socket_server = 1;
77629 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77630 +#endif
77631 +#endif
77632 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77633 + grsec_deny_new_usb = 1;
77634 +#endif
77635 +
77636 + return;
77637 +}
77638 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77639 new file mode 100644
77640 index 0000000..1773300
77641 --- /dev/null
77642 +++ b/grsecurity/grsec_ipc.c
77643 @@ -0,0 +1,48 @@
77644 +#include <linux/kernel.h>
77645 +#include <linux/mm.h>
77646 +#include <linux/sched.h>
77647 +#include <linux/file.h>
77648 +#include <linux/ipc.h>
77649 +#include <linux/ipc_namespace.h>
77650 +#include <linux/grsecurity.h>
77651 +#include <linux/grinternal.h>
77652 +
77653 +int
77654 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77655 +{
77656 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77657 + int write;
77658 + int orig_granted_mode;
77659 + kuid_t euid;
77660 + kgid_t egid;
77661 +
77662 + if (!grsec_enable_harden_ipc)
77663 + return 1;
77664 +
77665 + euid = current_euid();
77666 + egid = current_egid();
77667 +
77668 + write = requested_mode & 00002;
77669 + orig_granted_mode = ipcp->mode;
77670 +
77671 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77672 + orig_granted_mode >>= 6;
77673 + else {
77674 + /* if likely wrong permissions, lock to user */
77675 + if (orig_granted_mode & 0007)
77676 + orig_granted_mode = 0;
77677 + /* otherwise do a egid-only check */
77678 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77679 + orig_granted_mode >>= 3;
77680 + /* otherwise, no access */
77681 + else
77682 + orig_granted_mode = 0;
77683 + }
77684 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77685 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77686 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77687 + return 0;
77688 + }
77689 +#endif
77690 + return 1;
77691 +}
77692 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77693 new file mode 100644
77694 index 0000000..5e05e20
77695 --- /dev/null
77696 +++ b/grsecurity/grsec_link.c
77697 @@ -0,0 +1,58 @@
77698 +#include <linux/kernel.h>
77699 +#include <linux/sched.h>
77700 +#include <linux/fs.h>
77701 +#include <linux/file.h>
77702 +#include <linux/grinternal.h>
77703 +
77704 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77705 +{
77706 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77707 + const struct inode *link_inode = link->dentry->d_inode;
77708 +
77709 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77710 + /* ignore root-owned links, e.g. /proc/self */
77711 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77712 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77713 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77714 + return 1;
77715 + }
77716 +#endif
77717 + return 0;
77718 +}
77719 +
77720 +int
77721 +gr_handle_follow_link(const struct inode *parent,
77722 + const struct inode *inode,
77723 + const struct dentry *dentry, const struct vfsmount *mnt)
77724 +{
77725 +#ifdef CONFIG_GRKERNSEC_LINK
77726 + const struct cred *cred = current_cred();
77727 +
77728 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77729 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77730 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77731 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77732 + return -EACCES;
77733 + }
77734 +#endif
77735 + return 0;
77736 +}
77737 +
77738 +int
77739 +gr_handle_hardlink(const struct dentry *dentry,
77740 + const struct vfsmount *mnt,
77741 + struct inode *inode, const int mode, const struct filename *to)
77742 +{
77743 +#ifdef CONFIG_GRKERNSEC_LINK
77744 + const struct cred *cred = current_cred();
77745 +
77746 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77747 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77748 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77749 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77750 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77751 + return -EPERM;
77752 + }
77753 +#endif
77754 + return 0;
77755 +}
77756 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77757 new file mode 100644
77758 index 0000000..dbe0a6b
77759 --- /dev/null
77760 +++ b/grsecurity/grsec_log.c
77761 @@ -0,0 +1,341 @@
77762 +#include <linux/kernel.h>
77763 +#include <linux/sched.h>
77764 +#include <linux/file.h>
77765 +#include <linux/tty.h>
77766 +#include <linux/fs.h>
77767 +#include <linux/mm.h>
77768 +#include <linux/grinternal.h>
77769 +
77770 +#ifdef CONFIG_TREE_PREEMPT_RCU
77771 +#define DISABLE_PREEMPT() preempt_disable()
77772 +#define ENABLE_PREEMPT() preempt_enable()
77773 +#else
77774 +#define DISABLE_PREEMPT()
77775 +#define ENABLE_PREEMPT()
77776 +#endif
77777 +
77778 +#define BEGIN_LOCKS(x) \
77779 + DISABLE_PREEMPT(); \
77780 + rcu_read_lock(); \
77781 + read_lock(&tasklist_lock); \
77782 + read_lock(&grsec_exec_file_lock); \
77783 + if (x != GR_DO_AUDIT) \
77784 + spin_lock(&grsec_alert_lock); \
77785 + else \
77786 + spin_lock(&grsec_audit_lock)
77787 +
77788 +#define END_LOCKS(x) \
77789 + if (x != GR_DO_AUDIT) \
77790 + spin_unlock(&grsec_alert_lock); \
77791 + else \
77792 + spin_unlock(&grsec_audit_lock); \
77793 + read_unlock(&grsec_exec_file_lock); \
77794 + read_unlock(&tasklist_lock); \
77795 + rcu_read_unlock(); \
77796 + ENABLE_PREEMPT(); \
77797 + if (x == GR_DONT_AUDIT) \
77798 + gr_handle_alertkill(current)
77799 +
77800 +enum {
77801 + FLOODING,
77802 + NO_FLOODING
77803 +};
77804 +
77805 +extern char *gr_alert_log_fmt;
77806 +extern char *gr_audit_log_fmt;
77807 +extern char *gr_alert_log_buf;
77808 +extern char *gr_audit_log_buf;
77809 +
77810 +static int gr_log_start(int audit)
77811 +{
77812 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77813 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77814 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77815 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77816 + unsigned long curr_secs = get_seconds();
77817 +
77818 + if (audit == GR_DO_AUDIT)
77819 + goto set_fmt;
77820 +
77821 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77822 + grsec_alert_wtime = curr_secs;
77823 + grsec_alert_fyet = 0;
77824 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77825 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77826 + grsec_alert_fyet++;
77827 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77828 + grsec_alert_wtime = curr_secs;
77829 + grsec_alert_fyet++;
77830 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77831 + return FLOODING;
77832 + }
77833 + else return FLOODING;
77834 +
77835 +set_fmt:
77836 +#endif
77837 + memset(buf, 0, PAGE_SIZE);
77838 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77839 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77840 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77841 + } else if (current->signal->curr_ip) {
77842 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77843 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77844 + } else if (gr_acl_is_enabled()) {
77845 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77846 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77847 + } else {
77848 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77849 + strcpy(buf, fmt);
77850 + }
77851 +
77852 + return NO_FLOODING;
77853 +}
77854 +
77855 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77856 + __attribute__ ((format (printf, 2, 0)));
77857 +
77858 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77859 +{
77860 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77861 + unsigned int len = strlen(buf);
77862 +
77863 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77864 +
77865 + return;
77866 +}
77867 +
77868 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77869 + __attribute__ ((format (printf, 2, 3)));
77870 +
77871 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77872 +{
77873 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77874 + unsigned int len = strlen(buf);
77875 + va_list ap;
77876 +
77877 + va_start(ap, msg);
77878 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77879 + va_end(ap);
77880 +
77881 + return;
77882 +}
77883 +
77884 +static void gr_log_end(int audit, int append_default)
77885 +{
77886 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77887 + if (append_default) {
77888 + struct task_struct *task = current;
77889 + struct task_struct *parent = task->real_parent;
77890 + const struct cred *cred = __task_cred(task);
77891 + const struct cred *pcred = __task_cred(parent);
77892 + unsigned int len = strlen(buf);
77893 +
77894 + 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));
77895 + }
77896 +
77897 + printk("%s\n", buf);
77898 +
77899 + return;
77900 +}
77901 +
77902 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77903 +{
77904 + int logtype;
77905 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77906 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77907 + void *voidptr = NULL;
77908 + int num1 = 0, num2 = 0;
77909 + unsigned long ulong1 = 0, ulong2 = 0;
77910 + struct dentry *dentry = NULL;
77911 + struct vfsmount *mnt = NULL;
77912 + struct file *file = NULL;
77913 + struct task_struct *task = NULL;
77914 + struct vm_area_struct *vma = NULL;
77915 + const struct cred *cred, *pcred;
77916 + va_list ap;
77917 +
77918 + BEGIN_LOCKS(audit);
77919 + logtype = gr_log_start(audit);
77920 + if (logtype == FLOODING) {
77921 + END_LOCKS(audit);
77922 + return;
77923 + }
77924 + va_start(ap, argtypes);
77925 + switch (argtypes) {
77926 + case GR_TTYSNIFF:
77927 + task = va_arg(ap, struct task_struct *);
77928 + 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));
77929 + break;
77930 + case GR_SYSCTL_HIDDEN:
77931 + str1 = va_arg(ap, char *);
77932 + gr_log_middle_varargs(audit, msg, result, str1);
77933 + break;
77934 + case GR_RBAC:
77935 + dentry = va_arg(ap, struct dentry *);
77936 + mnt = va_arg(ap, struct vfsmount *);
77937 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77938 + break;
77939 + case GR_RBAC_STR:
77940 + dentry = va_arg(ap, struct dentry *);
77941 + mnt = va_arg(ap, struct vfsmount *);
77942 + str1 = va_arg(ap, char *);
77943 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77944 + break;
77945 + case GR_STR_RBAC:
77946 + str1 = va_arg(ap, char *);
77947 + dentry = va_arg(ap, struct dentry *);
77948 + mnt = va_arg(ap, struct vfsmount *);
77949 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77950 + break;
77951 + case GR_RBAC_MODE2:
77952 + dentry = va_arg(ap, struct dentry *);
77953 + mnt = va_arg(ap, struct vfsmount *);
77954 + str1 = va_arg(ap, char *);
77955 + str2 = va_arg(ap, char *);
77956 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77957 + break;
77958 + case GR_RBAC_MODE3:
77959 + dentry = va_arg(ap, struct dentry *);
77960 + mnt = va_arg(ap, struct vfsmount *);
77961 + str1 = va_arg(ap, char *);
77962 + str2 = va_arg(ap, char *);
77963 + str3 = va_arg(ap, char *);
77964 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77965 + break;
77966 + case GR_FILENAME:
77967 + dentry = va_arg(ap, struct dentry *);
77968 + mnt = va_arg(ap, struct vfsmount *);
77969 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77970 + break;
77971 + case GR_STR_FILENAME:
77972 + str1 = va_arg(ap, char *);
77973 + dentry = va_arg(ap, struct dentry *);
77974 + mnt = va_arg(ap, struct vfsmount *);
77975 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77976 + break;
77977 + case GR_FILENAME_STR:
77978 + dentry = va_arg(ap, struct dentry *);
77979 + mnt = va_arg(ap, struct vfsmount *);
77980 + str1 = va_arg(ap, char *);
77981 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77982 + break;
77983 + case GR_FILENAME_TWO_INT:
77984 + dentry = va_arg(ap, struct dentry *);
77985 + mnt = va_arg(ap, struct vfsmount *);
77986 + num1 = va_arg(ap, int);
77987 + num2 = va_arg(ap, int);
77988 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77989 + break;
77990 + case GR_FILENAME_TWO_INT_STR:
77991 + dentry = va_arg(ap, struct dentry *);
77992 + mnt = va_arg(ap, struct vfsmount *);
77993 + num1 = va_arg(ap, int);
77994 + num2 = va_arg(ap, int);
77995 + str1 = va_arg(ap, char *);
77996 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77997 + break;
77998 + case GR_TEXTREL:
77999 + file = va_arg(ap, struct file *);
78000 + ulong1 = va_arg(ap, unsigned long);
78001 + ulong2 = va_arg(ap, unsigned long);
78002 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78003 + break;
78004 + case GR_PTRACE:
78005 + task = va_arg(ap, struct task_struct *);
78006 + 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));
78007 + break;
78008 + case GR_RESOURCE:
78009 + task = va_arg(ap, struct task_struct *);
78010 + cred = __task_cred(task);
78011 + pcred = __task_cred(task->real_parent);
78012 + ulong1 = va_arg(ap, unsigned long);
78013 + str1 = va_arg(ap, char *);
78014 + ulong2 = va_arg(ap, unsigned long);
78015 + 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));
78016 + break;
78017 + case GR_CAP:
78018 + task = va_arg(ap, struct task_struct *);
78019 + cred = __task_cred(task);
78020 + pcred = __task_cred(task->real_parent);
78021 + str1 = va_arg(ap, char *);
78022 + 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));
78023 + break;
78024 + case GR_SIG:
78025 + str1 = va_arg(ap, char *);
78026 + voidptr = va_arg(ap, void *);
78027 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78028 + break;
78029 + case GR_SIG2:
78030 + task = va_arg(ap, struct task_struct *);
78031 + cred = __task_cred(task);
78032 + pcred = __task_cred(task->real_parent);
78033 + num1 = va_arg(ap, int);
78034 + 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));
78035 + break;
78036 + case GR_CRASH1:
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 + 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);
78042 + break;
78043 + case GR_CRASH2:
78044 + task = va_arg(ap, struct task_struct *);
78045 + cred = __task_cred(task);
78046 + pcred = __task_cred(task->real_parent);
78047 + ulong1 = va_arg(ap, unsigned long);
78048 + 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);
78049 + break;
78050 + case GR_RWXMAP:
78051 + file = va_arg(ap, struct file *);
78052 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78053 + break;
78054 + case GR_RWXMAPVMA:
78055 + vma = va_arg(ap, struct vm_area_struct *);
78056 + if (vma->vm_file)
78057 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78058 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78059 + str1 = "<stack>";
78060 + else if (vma->vm_start <= current->mm->brk &&
78061 + vma->vm_end >= current->mm->start_brk)
78062 + str1 = "<heap>";
78063 + else
78064 + str1 = "<anonymous mapping>";
78065 + gr_log_middle_varargs(audit, msg, str1);
78066 + break;
78067 + case GR_PSACCT:
78068 + {
78069 + unsigned int wday, cday;
78070 + __u8 whr, chr;
78071 + __u8 wmin, cmin;
78072 + __u8 wsec, csec;
78073 + char cur_tty[64] = { 0 };
78074 + char parent_tty[64] = { 0 };
78075 +
78076 + task = va_arg(ap, struct task_struct *);
78077 + wday = va_arg(ap, unsigned int);
78078 + cday = va_arg(ap, unsigned int);
78079 + whr = va_arg(ap, int);
78080 + chr = va_arg(ap, int);
78081 + wmin = va_arg(ap, int);
78082 + cmin = va_arg(ap, int);
78083 + wsec = va_arg(ap, int);
78084 + csec = va_arg(ap, int);
78085 + ulong1 = va_arg(ap, unsigned long);
78086 + cred = __task_cred(task);
78087 + pcred = __task_cred(task->real_parent);
78088 +
78089 + 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));
78090 + }
78091 + break;
78092 + default:
78093 + gr_log_middle(audit, msg, ap);
78094 + }
78095 + va_end(ap);
78096 + // these don't need DEFAULTSECARGS printed on the end
78097 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78098 + gr_log_end(audit, 0);
78099 + else
78100 + gr_log_end(audit, 1);
78101 + END_LOCKS(audit);
78102 +}
78103 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78104 new file mode 100644
78105 index 0000000..0e39d8c
78106 --- /dev/null
78107 +++ b/grsecurity/grsec_mem.c
78108 @@ -0,0 +1,48 @@
78109 +#include <linux/kernel.h>
78110 +#include <linux/sched.h>
78111 +#include <linux/mm.h>
78112 +#include <linux/mman.h>
78113 +#include <linux/module.h>
78114 +#include <linux/grinternal.h>
78115 +
78116 +void gr_handle_msr_write(void)
78117 +{
78118 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78119 + return;
78120 +}
78121 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78122 +
78123 +void
78124 +gr_handle_ioperm(void)
78125 +{
78126 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78127 + return;
78128 +}
78129 +
78130 +void
78131 +gr_handle_iopl(void)
78132 +{
78133 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78134 + return;
78135 +}
78136 +
78137 +void
78138 +gr_handle_mem_readwrite(u64 from, u64 to)
78139 +{
78140 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78141 + return;
78142 +}
78143 +
78144 +void
78145 +gr_handle_vm86(void)
78146 +{
78147 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78148 + return;
78149 +}
78150 +
78151 +void
78152 +gr_log_badprocpid(const char *entry)
78153 +{
78154 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78155 + return;
78156 +}
78157 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78158 new file mode 100644
78159 index 0000000..6f9eb73
78160 --- /dev/null
78161 +++ b/grsecurity/grsec_mount.c
78162 @@ -0,0 +1,65 @@
78163 +#include <linux/kernel.h>
78164 +#include <linux/sched.h>
78165 +#include <linux/mount.h>
78166 +#include <linux/major.h>
78167 +#include <linux/grsecurity.h>
78168 +#include <linux/grinternal.h>
78169 +
78170 +void
78171 +gr_log_remount(const char *devname, const int retval)
78172 +{
78173 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78174 + if (grsec_enable_mount && (retval >= 0))
78175 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78176 +#endif
78177 + return;
78178 +}
78179 +
78180 +void
78181 +gr_log_unmount(const char *devname, const int retval)
78182 +{
78183 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78184 + if (grsec_enable_mount && (retval >= 0))
78185 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78186 +#endif
78187 + return;
78188 +}
78189 +
78190 +void
78191 +gr_log_mount(const char *from, struct path *to, const int retval)
78192 +{
78193 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78194 + if (grsec_enable_mount && (retval >= 0))
78195 + gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
78196 +#endif
78197 + return;
78198 +}
78199 +
78200 +int
78201 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78202 +{
78203 +#ifdef CONFIG_GRKERNSEC_ROFS
78204 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78205 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78206 + return -EPERM;
78207 + } else
78208 + return 0;
78209 +#endif
78210 + return 0;
78211 +}
78212 +
78213 +int
78214 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78215 +{
78216 +#ifdef CONFIG_GRKERNSEC_ROFS
78217 + struct inode *inode = dentry->d_inode;
78218 +
78219 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78220 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78221 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78222 + return -EPERM;
78223 + } else
78224 + return 0;
78225 +#endif
78226 + return 0;
78227 +}
78228 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78229 new file mode 100644
78230 index 0000000..6ee9d50
78231 --- /dev/null
78232 +++ b/grsecurity/grsec_pax.c
78233 @@ -0,0 +1,45 @@
78234 +#include <linux/kernel.h>
78235 +#include <linux/sched.h>
78236 +#include <linux/mm.h>
78237 +#include <linux/file.h>
78238 +#include <linux/grinternal.h>
78239 +#include <linux/grsecurity.h>
78240 +
78241 +void
78242 +gr_log_textrel(struct vm_area_struct * vma)
78243 +{
78244 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78245 + if (grsec_enable_log_rwxmaps)
78246 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78247 +#endif
78248 + return;
78249 +}
78250 +
78251 +void gr_log_ptgnustack(struct file *file)
78252 +{
78253 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78254 + if (grsec_enable_log_rwxmaps)
78255 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78256 +#endif
78257 + return;
78258 +}
78259 +
78260 +void
78261 +gr_log_rwxmmap(struct file *file)
78262 +{
78263 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78264 + if (grsec_enable_log_rwxmaps)
78265 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78266 +#endif
78267 + return;
78268 +}
78269 +
78270 +void
78271 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78272 +{
78273 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78274 + if (grsec_enable_log_rwxmaps)
78275 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78276 +#endif
78277 + return;
78278 +}
78279 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78280 new file mode 100644
78281 index 0000000..2005a3a
78282 --- /dev/null
78283 +++ b/grsecurity/grsec_proc.c
78284 @@ -0,0 +1,20 @@
78285 +#include <linux/kernel.h>
78286 +#include <linux/sched.h>
78287 +#include <linux/grsecurity.h>
78288 +#include <linux/grinternal.h>
78289 +
78290 +int gr_proc_is_restricted(void)
78291 +{
78292 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78293 + const struct cred *cred = current_cred();
78294 +#endif
78295 +
78296 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78297 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78298 + return -EACCES;
78299 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78300 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78301 + return -EACCES;
78302 +#endif
78303 + return 0;
78304 +}
78305 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78306 new file mode 100644
78307 index 0000000..f7f29aa
78308 --- /dev/null
78309 +++ b/grsecurity/grsec_ptrace.c
78310 @@ -0,0 +1,30 @@
78311 +#include <linux/kernel.h>
78312 +#include <linux/sched.h>
78313 +#include <linux/grinternal.h>
78314 +#include <linux/security.h>
78315 +
78316 +void
78317 +gr_audit_ptrace(struct task_struct *task)
78318 +{
78319 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78320 + if (grsec_enable_audit_ptrace)
78321 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78322 +#endif
78323 + return;
78324 +}
78325 +
78326 +int
78327 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78328 +{
78329 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78330 + const struct dentry *dentry = file->f_path.dentry;
78331 + const struct vfsmount *mnt = file->f_path.mnt;
78332 +
78333 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78334 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78335 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78336 + return -EACCES;
78337 + }
78338 +#endif
78339 + return 0;
78340 +}
78341 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78342 new file mode 100644
78343 index 0000000..3860c7e
78344 --- /dev/null
78345 +++ b/grsecurity/grsec_sig.c
78346 @@ -0,0 +1,236 @@
78347 +#include <linux/kernel.h>
78348 +#include <linux/sched.h>
78349 +#include <linux/fs.h>
78350 +#include <linux/delay.h>
78351 +#include <linux/grsecurity.h>
78352 +#include <linux/grinternal.h>
78353 +#include <linux/hardirq.h>
78354 +
78355 +char *signames[] = {
78356 + [SIGSEGV] = "Segmentation fault",
78357 + [SIGILL] = "Illegal instruction",
78358 + [SIGABRT] = "Abort",
78359 + [SIGBUS] = "Invalid alignment/Bus error"
78360 +};
78361 +
78362 +void
78363 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78364 +{
78365 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78366 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78367 + (sig == SIGABRT) || (sig == SIGBUS))) {
78368 + if (task_pid_nr(t) == task_pid_nr(current)) {
78369 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78370 + } else {
78371 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78372 + }
78373 + }
78374 +#endif
78375 + return;
78376 +}
78377 +
78378 +int
78379 +gr_handle_signal(const struct task_struct *p, const int sig)
78380 +{
78381 +#ifdef CONFIG_GRKERNSEC
78382 + /* ignore the 0 signal for protected task checks */
78383 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78384 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78385 + return -EPERM;
78386 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78387 + return -EPERM;
78388 + }
78389 +#endif
78390 + return 0;
78391 +}
78392 +
78393 +#ifdef CONFIG_GRKERNSEC
78394 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78395 +
78396 +int gr_fake_force_sig(int sig, struct task_struct *t)
78397 +{
78398 + unsigned long int flags;
78399 + int ret, blocked, ignored;
78400 + struct k_sigaction *action;
78401 +
78402 + spin_lock_irqsave(&t->sighand->siglock, flags);
78403 + action = &t->sighand->action[sig-1];
78404 + ignored = action->sa.sa_handler == SIG_IGN;
78405 + blocked = sigismember(&t->blocked, sig);
78406 + if (blocked || ignored) {
78407 + action->sa.sa_handler = SIG_DFL;
78408 + if (blocked) {
78409 + sigdelset(&t->blocked, sig);
78410 + recalc_sigpending_and_wake(t);
78411 + }
78412 + }
78413 + if (action->sa.sa_handler == SIG_DFL)
78414 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78415 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78416 +
78417 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78418 +
78419 + return ret;
78420 +}
78421 +#endif
78422 +
78423 +#define GR_USER_BAN_TIME (15 * 60)
78424 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78425 +
78426 +void gr_handle_brute_attach(int dumpable)
78427 +{
78428 +#ifdef CONFIG_GRKERNSEC_BRUTE
78429 + struct task_struct *p = current;
78430 + kuid_t uid = GLOBAL_ROOT_UID;
78431 + int daemon = 0;
78432 +
78433 + if (!grsec_enable_brute)
78434 + return;
78435 +
78436 + rcu_read_lock();
78437 + read_lock(&tasklist_lock);
78438 + read_lock(&grsec_exec_file_lock);
78439 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78440 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78441 + p->real_parent->brute = 1;
78442 + daemon = 1;
78443 + } else {
78444 + const struct cred *cred = __task_cred(p), *cred2;
78445 + struct task_struct *tsk, *tsk2;
78446 +
78447 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78448 + struct user_struct *user;
78449 +
78450 + uid = cred->uid;
78451 +
78452 + /* this is put upon execution past expiration */
78453 + user = find_user(uid);
78454 + if (user == NULL)
78455 + goto unlock;
78456 + user->suid_banned = 1;
78457 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78458 + if (user->suid_ban_expires == ~0UL)
78459 + user->suid_ban_expires--;
78460 +
78461 + /* only kill other threads of the same binary, from the same user */
78462 + do_each_thread(tsk2, tsk) {
78463 + cred2 = __task_cred(tsk);
78464 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78465 + gr_fake_force_sig(SIGKILL, tsk);
78466 + } while_each_thread(tsk2, tsk);
78467 + }
78468 + }
78469 +unlock:
78470 + read_unlock(&grsec_exec_file_lock);
78471 + read_unlock(&tasklist_lock);
78472 + rcu_read_unlock();
78473 +
78474 + if (gr_is_global_nonroot(uid))
78475 + 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);
78476 + else if (daemon)
78477 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78478 +
78479 +#endif
78480 + return;
78481 +}
78482 +
78483 +void gr_handle_brute_check(void)
78484 +{
78485 +#ifdef CONFIG_GRKERNSEC_BRUTE
78486 + struct task_struct *p = current;
78487 +
78488 + if (unlikely(p->brute)) {
78489 + if (!grsec_enable_brute)
78490 + p->brute = 0;
78491 + else if (time_before(get_seconds(), p->brute_expires))
78492 + msleep(30 * 1000);
78493 + }
78494 +#endif
78495 + return;
78496 +}
78497 +
78498 +void gr_handle_kernel_exploit(void)
78499 +{
78500 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78501 + const struct cred *cred;
78502 + struct task_struct *tsk, *tsk2;
78503 + struct user_struct *user;
78504 + kuid_t uid;
78505 +
78506 + if (in_irq() || in_serving_softirq() || in_nmi())
78507 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78508 +
78509 + uid = current_uid();
78510 +
78511 + if (gr_is_global_root(uid))
78512 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78513 + else {
78514 + /* kill all the processes of this user, hold a reference
78515 + to their creds struct, and prevent them from creating
78516 + another process until system reset
78517 + */
78518 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78519 + GR_GLOBAL_UID(uid));
78520 + /* we intentionally leak this ref */
78521 + user = get_uid(current->cred->user);
78522 + if (user)
78523 + user->kernel_banned = 1;
78524 +
78525 + /* kill all processes of this user */
78526 + read_lock(&tasklist_lock);
78527 + do_each_thread(tsk2, tsk) {
78528 + cred = __task_cred(tsk);
78529 + if (uid_eq(cred->uid, uid))
78530 + gr_fake_force_sig(SIGKILL, tsk);
78531 + } while_each_thread(tsk2, tsk);
78532 + read_unlock(&tasklist_lock);
78533 + }
78534 +#endif
78535 +}
78536 +
78537 +#ifdef CONFIG_GRKERNSEC_BRUTE
78538 +static bool suid_ban_expired(struct user_struct *user)
78539 +{
78540 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78541 + user->suid_banned = 0;
78542 + user->suid_ban_expires = 0;
78543 + free_uid(user);
78544 + return true;
78545 + }
78546 +
78547 + return false;
78548 +}
78549 +#endif
78550 +
78551 +int gr_process_kernel_exec_ban(void)
78552 +{
78553 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78554 + if (unlikely(current->cred->user->kernel_banned))
78555 + return -EPERM;
78556 +#endif
78557 + return 0;
78558 +}
78559 +
78560 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78561 +{
78562 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78563 + if (unlikely(user->kernel_banned))
78564 + gr_fake_force_sig(SIGKILL, current);
78565 +#endif
78566 + return 0;
78567 +}
78568 +
78569 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78570 +{
78571 +#ifdef CONFIG_GRKERNSEC_BRUTE
78572 + struct user_struct *user = current->cred->user;
78573 + if (unlikely(user->suid_banned)) {
78574 + if (suid_ban_expired(user))
78575 + return 0;
78576 + /* disallow execution of suid binaries only */
78577 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78578 + return -EPERM;
78579 + }
78580 +#endif
78581 + return 0;
78582 +}
78583 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78584 new file mode 100644
78585 index 0000000..e3650b6
78586 --- /dev/null
78587 +++ b/grsecurity/grsec_sock.c
78588 @@ -0,0 +1,244 @@
78589 +#include <linux/kernel.h>
78590 +#include <linux/module.h>
78591 +#include <linux/sched.h>
78592 +#include <linux/file.h>
78593 +#include <linux/net.h>
78594 +#include <linux/in.h>
78595 +#include <linux/ip.h>
78596 +#include <net/sock.h>
78597 +#include <net/inet_sock.h>
78598 +#include <linux/grsecurity.h>
78599 +#include <linux/grinternal.h>
78600 +#include <linux/gracl.h>
78601 +
78602 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78603 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78604 +
78605 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78606 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78607 +
78608 +#ifdef CONFIG_UNIX_MODULE
78609 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78610 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78611 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78612 +EXPORT_SYMBOL_GPL(gr_handle_create);
78613 +#endif
78614 +
78615 +#ifdef CONFIG_GRKERNSEC
78616 +#define gr_conn_table_size 32749
78617 +struct conn_table_entry {
78618 + struct conn_table_entry *next;
78619 + struct signal_struct *sig;
78620 +};
78621 +
78622 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78623 +DEFINE_SPINLOCK(gr_conn_table_lock);
78624 +
78625 +extern const char * gr_socktype_to_name(unsigned char type);
78626 +extern const char * gr_proto_to_name(unsigned char proto);
78627 +extern const char * gr_sockfamily_to_name(unsigned char family);
78628 +
78629 +static __inline__ int
78630 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78631 +{
78632 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78633 +}
78634 +
78635 +static __inline__ int
78636 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78637 + __u16 sport, __u16 dport)
78638 +{
78639 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78640 + sig->gr_sport == sport && sig->gr_dport == dport))
78641 + return 1;
78642 + else
78643 + return 0;
78644 +}
78645 +
78646 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78647 +{
78648 + struct conn_table_entry **match;
78649 + unsigned int index;
78650 +
78651 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78652 + sig->gr_sport, sig->gr_dport,
78653 + gr_conn_table_size);
78654 +
78655 + newent->sig = sig;
78656 +
78657 + match = &gr_conn_table[index];
78658 + newent->next = *match;
78659 + *match = newent;
78660 +
78661 + return;
78662 +}
78663 +
78664 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78665 +{
78666 + struct conn_table_entry *match, *last = NULL;
78667 + unsigned int index;
78668 +
78669 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78670 + sig->gr_sport, sig->gr_dport,
78671 + gr_conn_table_size);
78672 +
78673 + match = gr_conn_table[index];
78674 + while (match && !conn_match(match->sig,
78675 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78676 + sig->gr_dport)) {
78677 + last = match;
78678 + match = match->next;
78679 + }
78680 +
78681 + if (match) {
78682 + if (last)
78683 + last->next = match->next;
78684 + else
78685 + gr_conn_table[index] = NULL;
78686 + kfree(match);
78687 + }
78688 +
78689 + return;
78690 +}
78691 +
78692 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78693 + __u16 sport, __u16 dport)
78694 +{
78695 + struct conn_table_entry *match;
78696 + unsigned int index;
78697 +
78698 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78699 +
78700 + match = gr_conn_table[index];
78701 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78702 + match = match->next;
78703 +
78704 + if (match)
78705 + return match->sig;
78706 + else
78707 + return NULL;
78708 +}
78709 +
78710 +#endif
78711 +
78712 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78713 +{
78714 +#ifdef CONFIG_GRKERNSEC
78715 + struct signal_struct *sig = current->signal;
78716 + struct conn_table_entry *newent;
78717 +
78718 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78719 + if (newent == NULL)
78720 + return;
78721 + /* no bh lock needed since we are called with bh disabled */
78722 + spin_lock(&gr_conn_table_lock);
78723 + gr_del_task_from_ip_table_nolock(sig);
78724 + sig->gr_saddr = inet->inet_rcv_saddr;
78725 + sig->gr_daddr = inet->inet_daddr;
78726 + sig->gr_sport = inet->inet_sport;
78727 + sig->gr_dport = inet->inet_dport;
78728 + gr_add_to_task_ip_table_nolock(sig, newent);
78729 + spin_unlock(&gr_conn_table_lock);
78730 +#endif
78731 + return;
78732 +}
78733 +
78734 +void gr_del_task_from_ip_table(struct task_struct *task)
78735 +{
78736 +#ifdef CONFIG_GRKERNSEC
78737 + spin_lock_bh(&gr_conn_table_lock);
78738 + gr_del_task_from_ip_table_nolock(task->signal);
78739 + spin_unlock_bh(&gr_conn_table_lock);
78740 +#endif
78741 + return;
78742 +}
78743 +
78744 +void
78745 +gr_attach_curr_ip(const struct sock *sk)
78746 +{
78747 +#ifdef CONFIG_GRKERNSEC
78748 + struct signal_struct *p, *set;
78749 + const struct inet_sock *inet = inet_sk(sk);
78750 +
78751 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78752 + return;
78753 +
78754 + set = current->signal;
78755 +
78756 + spin_lock_bh(&gr_conn_table_lock);
78757 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78758 + inet->inet_dport, inet->inet_sport);
78759 + if (unlikely(p != NULL)) {
78760 + set->curr_ip = p->curr_ip;
78761 + set->used_accept = 1;
78762 + gr_del_task_from_ip_table_nolock(p);
78763 + spin_unlock_bh(&gr_conn_table_lock);
78764 + return;
78765 + }
78766 + spin_unlock_bh(&gr_conn_table_lock);
78767 +
78768 + set->curr_ip = inet->inet_daddr;
78769 + set->used_accept = 1;
78770 +#endif
78771 + return;
78772 +}
78773 +
78774 +int
78775 +gr_handle_sock_all(const int family, const int type, const int protocol)
78776 +{
78777 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78778 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78779 + (family != AF_UNIX)) {
78780 + if (family == AF_INET)
78781 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78782 + else
78783 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78784 + return -EACCES;
78785 + }
78786 +#endif
78787 + return 0;
78788 +}
78789 +
78790 +int
78791 +gr_handle_sock_server(const struct sockaddr *sck)
78792 +{
78793 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78794 + if (grsec_enable_socket_server &&
78795 + in_group_p(grsec_socket_server_gid) &&
78796 + sck && (sck->sa_family != AF_UNIX) &&
78797 + (sck->sa_family != AF_LOCAL)) {
78798 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78799 + return -EACCES;
78800 + }
78801 +#endif
78802 + return 0;
78803 +}
78804 +
78805 +int
78806 +gr_handle_sock_server_other(const struct sock *sck)
78807 +{
78808 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78809 + if (grsec_enable_socket_server &&
78810 + in_group_p(grsec_socket_server_gid) &&
78811 + sck && (sck->sk_family != AF_UNIX) &&
78812 + (sck->sk_family != AF_LOCAL)) {
78813 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78814 + return -EACCES;
78815 + }
78816 +#endif
78817 + return 0;
78818 +}
78819 +
78820 +int
78821 +gr_handle_sock_client(const struct sockaddr *sck)
78822 +{
78823 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78824 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78825 + sck && (sck->sa_family != AF_UNIX) &&
78826 + (sck->sa_family != AF_LOCAL)) {
78827 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78828 + return -EACCES;
78829 + }
78830 +#endif
78831 + return 0;
78832 +}
78833 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78834 new file mode 100644
78835 index 0000000..cce889e
78836 --- /dev/null
78837 +++ b/grsecurity/grsec_sysctl.c
78838 @@ -0,0 +1,488 @@
78839 +#include <linux/kernel.h>
78840 +#include <linux/sched.h>
78841 +#include <linux/sysctl.h>
78842 +#include <linux/grsecurity.h>
78843 +#include <linux/grinternal.h>
78844 +
78845 +int
78846 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78847 +{
78848 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78849 + if (dirname == NULL || name == NULL)
78850 + return 0;
78851 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78852 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78853 + return -EACCES;
78854 + }
78855 +#endif
78856 + return 0;
78857 +}
78858 +
78859 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78860 +static int __maybe_unused __read_only one = 1;
78861 +#endif
78862 +
78863 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78864 + defined(CONFIG_GRKERNSEC_DENYUSB)
78865 +struct ctl_table grsecurity_table[] = {
78866 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78867 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78868 +#ifdef CONFIG_GRKERNSEC_IO
78869 + {
78870 + .procname = "disable_priv_io",
78871 + .data = &grsec_disable_privio,
78872 + .maxlen = sizeof(int),
78873 + .mode = 0600,
78874 + .proc_handler = &proc_dointvec,
78875 + },
78876 +#endif
78877 +#endif
78878 +#ifdef CONFIG_GRKERNSEC_LINK
78879 + {
78880 + .procname = "linking_restrictions",
78881 + .data = &grsec_enable_link,
78882 + .maxlen = sizeof(int),
78883 + .mode = 0600,
78884 + .proc_handler = &proc_dointvec,
78885 + },
78886 +#endif
78887 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78888 + {
78889 + .procname = "enforce_symlinksifowner",
78890 + .data = &grsec_enable_symlinkown,
78891 + .maxlen = sizeof(int),
78892 + .mode = 0600,
78893 + .proc_handler = &proc_dointvec,
78894 + },
78895 + {
78896 + .procname = "symlinkown_gid",
78897 + .data = &grsec_symlinkown_gid,
78898 + .maxlen = sizeof(int),
78899 + .mode = 0600,
78900 + .proc_handler = &proc_dointvec,
78901 + },
78902 +#endif
78903 +#ifdef CONFIG_GRKERNSEC_BRUTE
78904 + {
78905 + .procname = "deter_bruteforce",
78906 + .data = &grsec_enable_brute,
78907 + .maxlen = sizeof(int),
78908 + .mode = 0600,
78909 + .proc_handler = &proc_dointvec,
78910 + },
78911 +#endif
78912 +#ifdef CONFIG_GRKERNSEC_FIFO
78913 + {
78914 + .procname = "fifo_restrictions",
78915 + .data = &grsec_enable_fifo,
78916 + .maxlen = sizeof(int),
78917 + .mode = 0600,
78918 + .proc_handler = &proc_dointvec,
78919 + },
78920 +#endif
78921 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78922 + {
78923 + .procname = "ptrace_readexec",
78924 + .data = &grsec_enable_ptrace_readexec,
78925 + .maxlen = sizeof(int),
78926 + .mode = 0600,
78927 + .proc_handler = &proc_dointvec,
78928 + },
78929 +#endif
78930 +#ifdef CONFIG_GRKERNSEC_SETXID
78931 + {
78932 + .procname = "consistent_setxid",
78933 + .data = &grsec_enable_setxid,
78934 + .maxlen = sizeof(int),
78935 + .mode = 0600,
78936 + .proc_handler = &proc_dointvec,
78937 + },
78938 +#endif
78939 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78940 + {
78941 + .procname = "ip_blackhole",
78942 + .data = &grsec_enable_blackhole,
78943 + .maxlen = sizeof(int),
78944 + .mode = 0600,
78945 + .proc_handler = &proc_dointvec,
78946 + },
78947 + {
78948 + .procname = "lastack_retries",
78949 + .data = &grsec_lastack_retries,
78950 + .maxlen = sizeof(int),
78951 + .mode = 0600,
78952 + .proc_handler = &proc_dointvec,
78953 + },
78954 +#endif
78955 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78956 + {
78957 + .procname = "exec_logging",
78958 + .data = &grsec_enable_execlog,
78959 + .maxlen = sizeof(int),
78960 + .mode = 0600,
78961 + .proc_handler = &proc_dointvec,
78962 + },
78963 +#endif
78964 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78965 + {
78966 + .procname = "rwxmap_logging",
78967 + .data = &grsec_enable_log_rwxmaps,
78968 + .maxlen = sizeof(int),
78969 + .mode = 0600,
78970 + .proc_handler = &proc_dointvec,
78971 + },
78972 +#endif
78973 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78974 + {
78975 + .procname = "signal_logging",
78976 + .data = &grsec_enable_signal,
78977 + .maxlen = sizeof(int),
78978 + .mode = 0600,
78979 + .proc_handler = &proc_dointvec,
78980 + },
78981 +#endif
78982 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78983 + {
78984 + .procname = "forkfail_logging",
78985 + .data = &grsec_enable_forkfail,
78986 + .maxlen = sizeof(int),
78987 + .mode = 0600,
78988 + .proc_handler = &proc_dointvec,
78989 + },
78990 +#endif
78991 +#ifdef CONFIG_GRKERNSEC_TIME
78992 + {
78993 + .procname = "timechange_logging",
78994 + .data = &grsec_enable_time,
78995 + .maxlen = sizeof(int),
78996 + .mode = 0600,
78997 + .proc_handler = &proc_dointvec,
78998 + },
78999 +#endif
79000 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79001 + {
79002 + .procname = "chroot_deny_shmat",
79003 + .data = &grsec_enable_chroot_shmat,
79004 + .maxlen = sizeof(int),
79005 + .mode = 0600,
79006 + .proc_handler = &proc_dointvec,
79007 + },
79008 +#endif
79009 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79010 + {
79011 + .procname = "chroot_deny_unix",
79012 + .data = &grsec_enable_chroot_unix,
79013 + .maxlen = sizeof(int),
79014 + .mode = 0600,
79015 + .proc_handler = &proc_dointvec,
79016 + },
79017 +#endif
79018 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79019 + {
79020 + .procname = "chroot_deny_mount",
79021 + .data = &grsec_enable_chroot_mount,
79022 + .maxlen = sizeof(int),
79023 + .mode = 0600,
79024 + .proc_handler = &proc_dointvec,
79025 + },
79026 +#endif
79027 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79028 + {
79029 + .procname = "chroot_deny_fchdir",
79030 + .data = &grsec_enable_chroot_fchdir,
79031 + .maxlen = sizeof(int),
79032 + .mode = 0600,
79033 + .proc_handler = &proc_dointvec,
79034 + },
79035 +#endif
79036 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79037 + {
79038 + .procname = "chroot_deny_chroot",
79039 + .data = &grsec_enable_chroot_double,
79040 + .maxlen = sizeof(int),
79041 + .mode = 0600,
79042 + .proc_handler = &proc_dointvec,
79043 + },
79044 +#endif
79045 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79046 + {
79047 + .procname = "chroot_deny_pivot",
79048 + .data = &grsec_enable_chroot_pivot,
79049 + .maxlen = sizeof(int),
79050 + .mode = 0600,
79051 + .proc_handler = &proc_dointvec,
79052 + },
79053 +#endif
79054 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79055 + {
79056 + .procname = "chroot_enforce_chdir",
79057 + .data = &grsec_enable_chroot_chdir,
79058 + .maxlen = sizeof(int),
79059 + .mode = 0600,
79060 + .proc_handler = &proc_dointvec,
79061 + },
79062 +#endif
79063 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79064 + {
79065 + .procname = "chroot_deny_chmod",
79066 + .data = &grsec_enable_chroot_chmod,
79067 + .maxlen = sizeof(int),
79068 + .mode = 0600,
79069 + .proc_handler = &proc_dointvec,
79070 + },
79071 +#endif
79072 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79073 + {
79074 + .procname = "chroot_deny_mknod",
79075 + .data = &grsec_enable_chroot_mknod,
79076 + .maxlen = sizeof(int),
79077 + .mode = 0600,
79078 + .proc_handler = &proc_dointvec,
79079 + },
79080 +#endif
79081 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79082 + {
79083 + .procname = "chroot_restrict_nice",
79084 + .data = &grsec_enable_chroot_nice,
79085 + .maxlen = sizeof(int),
79086 + .mode = 0600,
79087 + .proc_handler = &proc_dointvec,
79088 + },
79089 +#endif
79090 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79091 + {
79092 + .procname = "chroot_execlog",
79093 + .data = &grsec_enable_chroot_execlog,
79094 + .maxlen = sizeof(int),
79095 + .mode = 0600,
79096 + .proc_handler = &proc_dointvec,
79097 + },
79098 +#endif
79099 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79100 + {
79101 + .procname = "chroot_caps",
79102 + .data = &grsec_enable_chroot_caps,
79103 + .maxlen = sizeof(int),
79104 + .mode = 0600,
79105 + .proc_handler = &proc_dointvec,
79106 + },
79107 +#endif
79108 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
79109 + {
79110 + .procname = "chroot_deny_bad_rename",
79111 + .data = &grsec_enable_chroot_rename,
79112 + .maxlen = sizeof(int),
79113 + .mode = 0600,
79114 + .proc_handler = &proc_dointvec,
79115 + },
79116 +#endif
79117 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79118 + {
79119 + .procname = "chroot_deny_sysctl",
79120 + .data = &grsec_enable_chroot_sysctl,
79121 + .maxlen = sizeof(int),
79122 + .mode = 0600,
79123 + .proc_handler = &proc_dointvec,
79124 + },
79125 +#endif
79126 +#ifdef CONFIG_GRKERNSEC_TPE
79127 + {
79128 + .procname = "tpe",
79129 + .data = &grsec_enable_tpe,
79130 + .maxlen = sizeof(int),
79131 + .mode = 0600,
79132 + .proc_handler = &proc_dointvec,
79133 + },
79134 + {
79135 + .procname = "tpe_gid",
79136 + .data = &grsec_tpe_gid,
79137 + .maxlen = sizeof(int),
79138 + .mode = 0600,
79139 + .proc_handler = &proc_dointvec,
79140 + },
79141 +#endif
79142 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79143 + {
79144 + .procname = "tpe_invert",
79145 + .data = &grsec_enable_tpe_invert,
79146 + .maxlen = sizeof(int),
79147 + .mode = 0600,
79148 + .proc_handler = &proc_dointvec,
79149 + },
79150 +#endif
79151 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79152 + {
79153 + .procname = "tpe_restrict_all",
79154 + .data = &grsec_enable_tpe_all,
79155 + .maxlen = sizeof(int),
79156 + .mode = 0600,
79157 + .proc_handler = &proc_dointvec,
79158 + },
79159 +#endif
79160 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79161 + {
79162 + .procname = "socket_all",
79163 + .data = &grsec_enable_socket_all,
79164 + .maxlen = sizeof(int),
79165 + .mode = 0600,
79166 + .proc_handler = &proc_dointvec,
79167 + },
79168 + {
79169 + .procname = "socket_all_gid",
79170 + .data = &grsec_socket_all_gid,
79171 + .maxlen = sizeof(int),
79172 + .mode = 0600,
79173 + .proc_handler = &proc_dointvec,
79174 + },
79175 +#endif
79176 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79177 + {
79178 + .procname = "socket_client",
79179 + .data = &grsec_enable_socket_client,
79180 + .maxlen = sizeof(int),
79181 + .mode = 0600,
79182 + .proc_handler = &proc_dointvec,
79183 + },
79184 + {
79185 + .procname = "socket_client_gid",
79186 + .data = &grsec_socket_client_gid,
79187 + .maxlen = sizeof(int),
79188 + .mode = 0600,
79189 + .proc_handler = &proc_dointvec,
79190 + },
79191 +#endif
79192 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79193 + {
79194 + .procname = "socket_server",
79195 + .data = &grsec_enable_socket_server,
79196 + .maxlen = sizeof(int),
79197 + .mode = 0600,
79198 + .proc_handler = &proc_dointvec,
79199 + },
79200 + {
79201 + .procname = "socket_server_gid",
79202 + .data = &grsec_socket_server_gid,
79203 + .maxlen = sizeof(int),
79204 + .mode = 0600,
79205 + .proc_handler = &proc_dointvec,
79206 + },
79207 +#endif
79208 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79209 + {
79210 + .procname = "audit_group",
79211 + .data = &grsec_enable_group,
79212 + .maxlen = sizeof(int),
79213 + .mode = 0600,
79214 + .proc_handler = &proc_dointvec,
79215 + },
79216 + {
79217 + .procname = "audit_gid",
79218 + .data = &grsec_audit_gid,
79219 + .maxlen = sizeof(int),
79220 + .mode = 0600,
79221 + .proc_handler = &proc_dointvec,
79222 + },
79223 +#endif
79224 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79225 + {
79226 + .procname = "audit_chdir",
79227 + .data = &grsec_enable_chdir,
79228 + .maxlen = sizeof(int),
79229 + .mode = 0600,
79230 + .proc_handler = &proc_dointvec,
79231 + },
79232 +#endif
79233 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79234 + {
79235 + .procname = "audit_mount",
79236 + .data = &grsec_enable_mount,
79237 + .maxlen = sizeof(int),
79238 + .mode = 0600,
79239 + .proc_handler = &proc_dointvec,
79240 + },
79241 +#endif
79242 +#ifdef CONFIG_GRKERNSEC_DMESG
79243 + {
79244 + .procname = "dmesg",
79245 + .data = &grsec_enable_dmesg,
79246 + .maxlen = sizeof(int),
79247 + .mode = 0600,
79248 + .proc_handler = &proc_dointvec,
79249 + },
79250 +#endif
79251 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79252 + {
79253 + .procname = "chroot_findtask",
79254 + .data = &grsec_enable_chroot_findtask,
79255 + .maxlen = sizeof(int),
79256 + .mode = 0600,
79257 + .proc_handler = &proc_dointvec,
79258 + },
79259 +#endif
79260 +#ifdef CONFIG_GRKERNSEC_RESLOG
79261 + {
79262 + .procname = "resource_logging",
79263 + .data = &grsec_resource_logging,
79264 + .maxlen = sizeof(int),
79265 + .mode = 0600,
79266 + .proc_handler = &proc_dointvec,
79267 + },
79268 +#endif
79269 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79270 + {
79271 + .procname = "audit_ptrace",
79272 + .data = &grsec_enable_audit_ptrace,
79273 + .maxlen = sizeof(int),
79274 + .mode = 0600,
79275 + .proc_handler = &proc_dointvec,
79276 + },
79277 +#endif
79278 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79279 + {
79280 + .procname = "harden_ptrace",
79281 + .data = &grsec_enable_harden_ptrace,
79282 + .maxlen = sizeof(int),
79283 + .mode = 0600,
79284 + .proc_handler = &proc_dointvec,
79285 + },
79286 +#endif
79287 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79288 + {
79289 + .procname = "harden_ipc",
79290 + .data = &grsec_enable_harden_ipc,
79291 + .maxlen = sizeof(int),
79292 + .mode = 0600,
79293 + .proc_handler = &proc_dointvec,
79294 + },
79295 +#endif
79296 + {
79297 + .procname = "grsec_lock",
79298 + .data = &grsec_lock,
79299 + .maxlen = sizeof(int),
79300 + .mode = 0600,
79301 + .proc_handler = &proc_dointvec,
79302 + },
79303 +#endif
79304 +#ifdef CONFIG_GRKERNSEC_ROFS
79305 + {
79306 + .procname = "romount_protect",
79307 + .data = &grsec_enable_rofs,
79308 + .maxlen = sizeof(int),
79309 + .mode = 0600,
79310 + .proc_handler = &proc_dointvec_minmax,
79311 + .extra1 = &one,
79312 + .extra2 = &one,
79313 + },
79314 +#endif
79315 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79316 + {
79317 + .procname = "deny_new_usb",
79318 + .data = &grsec_deny_new_usb,
79319 + .maxlen = sizeof(int),
79320 + .mode = 0600,
79321 + .proc_handler = &proc_dointvec,
79322 + },
79323 +#endif
79324 + { }
79325 +};
79326 +#endif
79327 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79328 new file mode 100644
79329 index 0000000..61b514e
79330 --- /dev/null
79331 +++ b/grsecurity/grsec_time.c
79332 @@ -0,0 +1,16 @@
79333 +#include <linux/kernel.h>
79334 +#include <linux/sched.h>
79335 +#include <linux/grinternal.h>
79336 +#include <linux/module.h>
79337 +
79338 +void
79339 +gr_log_timechange(void)
79340 +{
79341 +#ifdef CONFIG_GRKERNSEC_TIME
79342 + if (grsec_enable_time)
79343 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79344 +#endif
79345 + return;
79346 +}
79347 +
79348 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79349 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79350 new file mode 100644
79351 index 0000000..d1953de
79352 --- /dev/null
79353 +++ b/grsecurity/grsec_tpe.c
79354 @@ -0,0 +1,78 @@
79355 +#include <linux/kernel.h>
79356 +#include <linux/sched.h>
79357 +#include <linux/file.h>
79358 +#include <linux/fs.h>
79359 +#include <linux/grinternal.h>
79360 +
79361 +extern int gr_acl_tpe_check(void);
79362 +
79363 +int
79364 +gr_tpe_allow(const struct file *file)
79365 +{
79366 +#ifdef CONFIG_GRKERNSEC
79367 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79368 + struct inode *file_inode = file->f_path.dentry->d_inode;
79369 + const struct cred *cred = current_cred();
79370 + char *msg = NULL;
79371 + char *msg2 = NULL;
79372 +
79373 + // never restrict root
79374 + if (gr_is_global_root(cred->uid))
79375 + return 1;
79376 +
79377 + if (grsec_enable_tpe) {
79378 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79379 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79380 + msg = "not being in trusted group";
79381 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79382 + msg = "being in untrusted group";
79383 +#else
79384 + if (in_group_p(grsec_tpe_gid))
79385 + msg = "being in untrusted group";
79386 +#endif
79387 + }
79388 + if (!msg && gr_acl_tpe_check())
79389 + msg = "being in untrusted role";
79390 +
79391 + // not in any affected group/role
79392 + if (!msg)
79393 + goto next_check;
79394 +
79395 + if (gr_is_global_nonroot(inode->i_uid))
79396 + msg2 = "file in non-root-owned directory";
79397 + else if (inode->i_mode & S_IWOTH)
79398 + msg2 = "file in world-writable directory";
79399 + else if (inode->i_mode & S_IWGRP)
79400 + msg2 = "file in group-writable directory";
79401 + else if (file_inode->i_mode & S_IWOTH)
79402 + msg2 = "file is world-writable";
79403 +
79404 + if (msg && msg2) {
79405 + char fullmsg[70] = {0};
79406 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79407 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79408 + return 0;
79409 + }
79410 + msg = NULL;
79411 +next_check:
79412 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79413 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79414 + return 1;
79415 +
79416 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79417 + msg = "directory not owned by user";
79418 + else if (inode->i_mode & S_IWOTH)
79419 + msg = "file in world-writable directory";
79420 + else if (inode->i_mode & S_IWGRP)
79421 + msg = "file in group-writable directory";
79422 + else if (file_inode->i_mode & S_IWOTH)
79423 + msg = "file is world-writable";
79424 +
79425 + if (msg) {
79426 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79427 + return 0;
79428 + }
79429 +#endif
79430 +#endif
79431 + return 1;
79432 +}
79433 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79434 new file mode 100644
79435 index 0000000..ae02d8e
79436 --- /dev/null
79437 +++ b/grsecurity/grsec_usb.c
79438 @@ -0,0 +1,15 @@
79439 +#include <linux/kernel.h>
79440 +#include <linux/grinternal.h>
79441 +#include <linux/module.h>
79442 +
79443 +int gr_handle_new_usb(void)
79444 +{
79445 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79446 + if (grsec_deny_new_usb) {
79447 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79448 + return 1;
79449 + }
79450 +#endif
79451 + return 0;
79452 +}
79453 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79454 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79455 new file mode 100644
79456 index 0000000..158b330
79457 --- /dev/null
79458 +++ b/grsecurity/grsum.c
79459 @@ -0,0 +1,64 @@
79460 +#include <linux/err.h>
79461 +#include <linux/kernel.h>
79462 +#include <linux/sched.h>
79463 +#include <linux/mm.h>
79464 +#include <linux/scatterlist.h>
79465 +#include <linux/crypto.h>
79466 +#include <linux/gracl.h>
79467 +
79468 +
79469 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79470 +#error "crypto and sha256 must be built into the kernel"
79471 +#endif
79472 +
79473 +int
79474 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79475 +{
79476 + struct crypto_hash *tfm;
79477 + struct hash_desc desc;
79478 + struct scatterlist sg[2];
79479 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79480 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79481 + unsigned long *sumptr = (unsigned long *)sum;
79482 + int cryptres;
79483 + int retval = 1;
79484 + volatile int mismatched = 0;
79485 + volatile int dummy = 0;
79486 + unsigned int i;
79487 +
79488 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79489 + if (IS_ERR(tfm)) {
79490 + /* should never happen, since sha256 should be built in */
79491 + memset(entry->pw, 0, GR_PW_LEN);
79492 + return 1;
79493 + }
79494 +
79495 + sg_init_table(sg, 2);
79496 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79497 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79498 +
79499 + desc.tfm = tfm;
79500 + desc.flags = 0;
79501 +
79502 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79503 + temp_sum);
79504 +
79505 + memset(entry->pw, 0, GR_PW_LEN);
79506 +
79507 + if (cryptres)
79508 + goto out;
79509 +
79510 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79511 + if (sumptr[i] != tmpsumptr[i])
79512 + mismatched = 1;
79513 + else
79514 + dummy = 1; // waste a cycle
79515 +
79516 + if (!mismatched)
79517 + retval = dummy - 1;
79518 +
79519 +out:
79520 + crypto_free_hash(tfm);
79521 +
79522 + return retval;
79523 +}
79524 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79525 index 77ff547..181834f 100644
79526 --- a/include/asm-generic/4level-fixup.h
79527 +++ b/include/asm-generic/4level-fixup.h
79528 @@ -13,8 +13,10 @@
79529 #define pmd_alloc(mm, pud, address) \
79530 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79531 NULL: pmd_offset(pud, address))
79532 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79533
79534 #define pud_alloc(mm, pgd, address) (pgd)
79535 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79536 #define pud_offset(pgd, start) (pgd)
79537 #define pud_none(pud) 0
79538 #define pud_bad(pud) 0
79539 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79540 index b7babf0..1e4b4f1 100644
79541 --- a/include/asm-generic/atomic-long.h
79542 +++ b/include/asm-generic/atomic-long.h
79543 @@ -22,6 +22,12 @@
79544
79545 typedef atomic64_t atomic_long_t;
79546
79547 +#ifdef CONFIG_PAX_REFCOUNT
79548 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79549 +#else
79550 +typedef atomic64_t atomic_long_unchecked_t;
79551 +#endif
79552 +
79553 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79554
79555 static inline long atomic_long_read(atomic_long_t *l)
79556 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79557 return (long)atomic64_read(v);
79558 }
79559
79560 +#ifdef CONFIG_PAX_REFCOUNT
79561 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79562 +{
79563 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79564 +
79565 + return (long)atomic64_read_unchecked(v);
79566 +}
79567 +#endif
79568 +
79569 static inline void atomic_long_set(atomic_long_t *l, long i)
79570 {
79571 atomic64_t *v = (atomic64_t *)l;
79572 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79573 atomic64_set(v, i);
79574 }
79575
79576 +#ifdef CONFIG_PAX_REFCOUNT
79577 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79578 +{
79579 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79580 +
79581 + atomic64_set_unchecked(v, i);
79582 +}
79583 +#endif
79584 +
79585 static inline void atomic_long_inc(atomic_long_t *l)
79586 {
79587 atomic64_t *v = (atomic64_t *)l;
79588 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79589 atomic64_inc(v);
79590 }
79591
79592 +#ifdef CONFIG_PAX_REFCOUNT
79593 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79594 +{
79595 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79596 +
79597 + atomic64_inc_unchecked(v);
79598 +}
79599 +#endif
79600 +
79601 static inline void atomic_long_dec(atomic_long_t *l)
79602 {
79603 atomic64_t *v = (atomic64_t *)l;
79604 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79605 atomic64_dec(v);
79606 }
79607
79608 +#ifdef CONFIG_PAX_REFCOUNT
79609 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79610 +{
79611 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79612 +
79613 + atomic64_dec_unchecked(v);
79614 +}
79615 +#endif
79616 +
79617 static inline void atomic_long_add(long i, atomic_long_t *l)
79618 {
79619 atomic64_t *v = (atomic64_t *)l;
79620 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79621 atomic64_add(i, v);
79622 }
79623
79624 +#ifdef CONFIG_PAX_REFCOUNT
79625 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79626 +{
79627 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79628 +
79629 + atomic64_add_unchecked(i, v);
79630 +}
79631 +#endif
79632 +
79633 static inline void atomic_long_sub(long i, atomic_long_t *l)
79634 {
79635 atomic64_t *v = (atomic64_t *)l;
79636 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79637 atomic64_sub(i, v);
79638 }
79639
79640 +#ifdef CONFIG_PAX_REFCOUNT
79641 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79642 +{
79643 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79644 +
79645 + atomic64_sub_unchecked(i, v);
79646 +}
79647 +#endif
79648 +
79649 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79650 {
79651 atomic64_t *v = (atomic64_t *)l;
79652 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79653 return atomic64_add_negative(i, v);
79654 }
79655
79656 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79657 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79658 {
79659 atomic64_t *v = (atomic64_t *)l;
79660
79661 return (long)atomic64_add_return(i, v);
79662 }
79663
79664 +#ifdef CONFIG_PAX_REFCOUNT
79665 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79666 +{
79667 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79668 +
79669 + return (long)atomic64_add_return_unchecked(i, v);
79670 +}
79671 +#endif
79672 +
79673 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79674 {
79675 atomic64_t *v = (atomic64_t *)l;
79676 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79677 return (long)atomic64_inc_return(v);
79678 }
79679
79680 +#ifdef CONFIG_PAX_REFCOUNT
79681 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79682 +{
79683 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79684 +
79685 + return (long)atomic64_inc_return_unchecked(v);
79686 +}
79687 +#endif
79688 +
79689 static inline long atomic_long_dec_return(atomic_long_t *l)
79690 {
79691 atomic64_t *v = (atomic64_t *)l;
79692 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79693
79694 typedef atomic_t atomic_long_t;
79695
79696 +#ifdef CONFIG_PAX_REFCOUNT
79697 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79698 +#else
79699 +typedef atomic_t atomic_long_unchecked_t;
79700 +#endif
79701 +
79702 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79703 static inline long atomic_long_read(atomic_long_t *l)
79704 {
79705 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79706 return (long)atomic_read(v);
79707 }
79708
79709 +#ifdef CONFIG_PAX_REFCOUNT
79710 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79711 +{
79712 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79713 +
79714 + return (long)atomic_read_unchecked(v);
79715 +}
79716 +#endif
79717 +
79718 static inline void atomic_long_set(atomic_long_t *l, long i)
79719 {
79720 atomic_t *v = (atomic_t *)l;
79721 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79722 atomic_set(v, i);
79723 }
79724
79725 +#ifdef CONFIG_PAX_REFCOUNT
79726 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79727 +{
79728 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79729 +
79730 + atomic_set_unchecked(v, i);
79731 +}
79732 +#endif
79733 +
79734 static inline void atomic_long_inc(atomic_long_t *l)
79735 {
79736 atomic_t *v = (atomic_t *)l;
79737 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79738 atomic_inc(v);
79739 }
79740
79741 +#ifdef CONFIG_PAX_REFCOUNT
79742 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79743 +{
79744 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79745 +
79746 + atomic_inc_unchecked(v);
79747 +}
79748 +#endif
79749 +
79750 static inline void atomic_long_dec(atomic_long_t *l)
79751 {
79752 atomic_t *v = (atomic_t *)l;
79753 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79754 atomic_dec(v);
79755 }
79756
79757 +#ifdef CONFIG_PAX_REFCOUNT
79758 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79759 +{
79760 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79761 +
79762 + atomic_dec_unchecked(v);
79763 +}
79764 +#endif
79765 +
79766 static inline void atomic_long_add(long i, atomic_long_t *l)
79767 {
79768 atomic_t *v = (atomic_t *)l;
79769 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79770 atomic_add(i, v);
79771 }
79772
79773 +#ifdef CONFIG_PAX_REFCOUNT
79774 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79775 +{
79776 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79777 +
79778 + atomic_add_unchecked(i, v);
79779 +}
79780 +#endif
79781 +
79782 static inline void atomic_long_sub(long i, atomic_long_t *l)
79783 {
79784 atomic_t *v = (atomic_t *)l;
79785 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79786 atomic_sub(i, v);
79787 }
79788
79789 +#ifdef CONFIG_PAX_REFCOUNT
79790 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79791 +{
79792 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79793 +
79794 + atomic_sub_unchecked(i, v);
79795 +}
79796 +#endif
79797 +
79798 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79799 {
79800 atomic_t *v = (atomic_t *)l;
79801 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79802 return atomic_add_negative(i, v);
79803 }
79804
79805 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79806 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79807 {
79808 atomic_t *v = (atomic_t *)l;
79809
79810 return (long)atomic_add_return(i, v);
79811 }
79812
79813 +#ifdef CONFIG_PAX_REFCOUNT
79814 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79815 +{
79816 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79817 +
79818 + return (long)atomic_add_return_unchecked(i, v);
79819 +}
79820 +
79821 +#endif
79822 +
79823 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79824 {
79825 atomic_t *v = (atomic_t *)l;
79826 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79827 return (long)atomic_inc_return(v);
79828 }
79829
79830 +#ifdef CONFIG_PAX_REFCOUNT
79831 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79832 +{
79833 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79834 +
79835 + return (long)atomic_inc_return_unchecked(v);
79836 +}
79837 +#endif
79838 +
79839 static inline long atomic_long_dec_return(atomic_long_t *l)
79840 {
79841 atomic_t *v = (atomic_t *)l;
79842 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79843
79844 #endif /* BITS_PER_LONG == 64 */
79845
79846 +#ifdef CONFIG_PAX_REFCOUNT
79847 +static inline void pax_refcount_needs_these_functions(void)
79848 +{
79849 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79850 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79851 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79852 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79853 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79854 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79855 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79856 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79857 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79858 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79859 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79860 +#ifdef CONFIG_X86
79861 + atomic_clear_mask_unchecked(0, NULL);
79862 + atomic_set_mask_unchecked(0, NULL);
79863 +#endif
79864 +
79865 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79866 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79867 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79868 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79869 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79870 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79871 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79872 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79873 +}
79874 +#else
79875 +#define atomic_read_unchecked(v) atomic_read(v)
79876 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79877 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79878 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79879 +#define atomic_inc_unchecked(v) atomic_inc(v)
79880 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79881 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79882 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79883 +#define atomic_dec_unchecked(v) atomic_dec(v)
79884 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79885 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79886 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79887 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79888 +
79889 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79890 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79891 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79892 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79893 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79894 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79895 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79896 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79897 +#endif
79898 +
79899 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79900 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79901 index 30ad9c8..c70c170 100644
79902 --- a/include/asm-generic/atomic64.h
79903 +++ b/include/asm-generic/atomic64.h
79904 @@ -16,6 +16,8 @@ typedef struct {
79905 long long counter;
79906 } atomic64_t;
79907
79908 +typedef atomic64_t atomic64_unchecked_t;
79909 +
79910 #define ATOMIC64_INIT(i) { (i) }
79911
79912 extern long long atomic64_read(const atomic64_t *v);
79913 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79914 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79915 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79916
79917 +#define atomic64_read_unchecked(v) atomic64_read(v)
79918 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79919 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79920 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79921 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79922 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79923 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79924 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79925 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79926 +
79927 #endif /* _ASM_GENERIC_ATOMIC64_H */
79928 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79929 index 1402fa8..025a736 100644
79930 --- a/include/asm-generic/barrier.h
79931 +++ b/include/asm-generic/barrier.h
79932 @@ -74,7 +74,7 @@
79933 do { \
79934 compiletime_assert_atomic_type(*p); \
79935 smp_mb(); \
79936 - ACCESS_ONCE(*p) = (v); \
79937 + ACCESS_ONCE_RW(*p) = (v); \
79938 } while (0)
79939
79940 #define smp_load_acquire(p) \
79941 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79942 index a60a7cc..0fe12f2 100644
79943 --- a/include/asm-generic/bitops/__fls.h
79944 +++ b/include/asm-generic/bitops/__fls.h
79945 @@ -9,7 +9,7 @@
79946 *
79947 * Undefined if no set bit exists, so code should check against 0 first.
79948 */
79949 -static __always_inline unsigned long __fls(unsigned long word)
79950 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79951 {
79952 int num = BITS_PER_LONG - 1;
79953
79954 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79955 index 0576d1f..dad6c71 100644
79956 --- a/include/asm-generic/bitops/fls.h
79957 +++ b/include/asm-generic/bitops/fls.h
79958 @@ -9,7 +9,7 @@
79959 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79960 */
79961
79962 -static __always_inline int fls(int x)
79963 +static __always_inline int __intentional_overflow(-1) fls(int x)
79964 {
79965 int r = 32;
79966
79967 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79968 index b097cf8..3d40e14 100644
79969 --- a/include/asm-generic/bitops/fls64.h
79970 +++ b/include/asm-generic/bitops/fls64.h
79971 @@ -15,7 +15,7 @@
79972 * at position 64.
79973 */
79974 #if BITS_PER_LONG == 32
79975 -static __always_inline int fls64(__u64 x)
79976 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79977 {
79978 __u32 h = x >> 32;
79979 if (h)
79980 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79981 return fls(x);
79982 }
79983 #elif BITS_PER_LONG == 64
79984 -static __always_inline int fls64(__u64 x)
79985 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79986 {
79987 if (x == 0)
79988 return 0;
79989 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79990 index 1bfcfe5..e04c5c9 100644
79991 --- a/include/asm-generic/cache.h
79992 +++ b/include/asm-generic/cache.h
79993 @@ -6,7 +6,7 @@
79994 * cache lines need to provide their own cache.h.
79995 */
79996
79997 -#define L1_CACHE_SHIFT 5
79998 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79999 +#define L1_CACHE_SHIFT 5UL
80000 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80001
80002 #endif /* __ASM_GENERIC_CACHE_H */
80003 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80004 index 0d68a1e..b74a761 100644
80005 --- a/include/asm-generic/emergency-restart.h
80006 +++ b/include/asm-generic/emergency-restart.h
80007 @@ -1,7 +1,7 @@
80008 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80009 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80010
80011 -static inline void machine_emergency_restart(void)
80012 +static inline __noreturn void machine_emergency_restart(void)
80013 {
80014 machine_restart(NULL);
80015 }
80016 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80017 index b8fdc57..c6d5a5c 100644
80018 --- a/include/asm-generic/io.h
80019 +++ b/include/asm-generic/io.h
80020 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80021 * These are pretty trivial
80022 */
80023 #ifndef virt_to_phys
80024 -static inline unsigned long virt_to_phys(volatile void *address)
80025 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80026 {
80027 return __pa((unsigned long)address);
80028 }
80029 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80030 index 90f99c7..00ce236 100644
80031 --- a/include/asm-generic/kmap_types.h
80032 +++ b/include/asm-generic/kmap_types.h
80033 @@ -2,9 +2,9 @@
80034 #define _ASM_GENERIC_KMAP_TYPES_H
80035
80036 #ifdef __WITH_KM_FENCE
80037 -# define KM_TYPE_NR 41
80038 +# define KM_TYPE_NR 42
80039 #else
80040 -# define KM_TYPE_NR 20
80041 +# define KM_TYPE_NR 21
80042 #endif
80043
80044 #endif
80045 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80046 index 9ceb03b..62b0b8f 100644
80047 --- a/include/asm-generic/local.h
80048 +++ b/include/asm-generic/local.h
80049 @@ -23,24 +23,37 @@ typedef struct
80050 atomic_long_t a;
80051 } local_t;
80052
80053 +typedef struct {
80054 + atomic_long_unchecked_t a;
80055 +} local_unchecked_t;
80056 +
80057 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80058
80059 #define local_read(l) atomic_long_read(&(l)->a)
80060 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80061 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80062 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80063 #define local_inc(l) atomic_long_inc(&(l)->a)
80064 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80065 #define local_dec(l) atomic_long_dec(&(l)->a)
80066 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80067 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80068 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80069 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80070 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80071
80072 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80073 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80074 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80075 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80076 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80077 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80078 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80079 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80080 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80081
80082 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80083 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80084 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80085 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80086 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80087 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80088 index 725612b..9cc513a 100644
80089 --- a/include/asm-generic/pgtable-nopmd.h
80090 +++ b/include/asm-generic/pgtable-nopmd.h
80091 @@ -1,14 +1,19 @@
80092 #ifndef _PGTABLE_NOPMD_H
80093 #define _PGTABLE_NOPMD_H
80094
80095 -#ifndef __ASSEMBLY__
80096 -
80097 #include <asm-generic/pgtable-nopud.h>
80098
80099 -struct mm_struct;
80100 -
80101 #define __PAGETABLE_PMD_FOLDED
80102
80103 +#define PMD_SHIFT PUD_SHIFT
80104 +#define PTRS_PER_PMD 1
80105 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80106 +#define PMD_MASK (~(PMD_SIZE-1))
80107 +
80108 +#ifndef __ASSEMBLY__
80109 +
80110 +struct mm_struct;
80111 +
80112 /*
80113 * Having the pmd type consist of a pud gets the size right, and allows
80114 * us to conceptually access the pud entry that this pmd is folded into
80115 @@ -16,11 +21,6 @@ struct mm_struct;
80116 */
80117 typedef struct { pud_t pud; } pmd_t;
80118
80119 -#define PMD_SHIFT PUD_SHIFT
80120 -#define PTRS_PER_PMD 1
80121 -#define PMD_SIZE (1UL << PMD_SHIFT)
80122 -#define PMD_MASK (~(PMD_SIZE-1))
80123 -
80124 /*
80125 * The "pud_xxx()" functions here are trivial for a folded two-level
80126 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80127 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80128 index 810431d..0ec4804f 100644
80129 --- a/include/asm-generic/pgtable-nopud.h
80130 +++ b/include/asm-generic/pgtable-nopud.h
80131 @@ -1,10 +1,15 @@
80132 #ifndef _PGTABLE_NOPUD_H
80133 #define _PGTABLE_NOPUD_H
80134
80135 -#ifndef __ASSEMBLY__
80136 -
80137 #define __PAGETABLE_PUD_FOLDED
80138
80139 +#define PUD_SHIFT PGDIR_SHIFT
80140 +#define PTRS_PER_PUD 1
80141 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80142 +#define PUD_MASK (~(PUD_SIZE-1))
80143 +
80144 +#ifndef __ASSEMBLY__
80145 +
80146 /*
80147 * Having the pud type consist of a pgd gets the size right, and allows
80148 * us to conceptually access the pgd entry that this pud is folded into
80149 @@ -12,11 +17,6 @@
80150 */
80151 typedef struct { pgd_t pgd; } pud_t;
80152
80153 -#define PUD_SHIFT PGDIR_SHIFT
80154 -#define PTRS_PER_PUD 1
80155 -#define PUD_SIZE (1UL << PUD_SHIFT)
80156 -#define PUD_MASK (~(PUD_SIZE-1))
80157 -
80158 /*
80159 * The "pgd_xxx()" functions here are trivial for a folded two-level
80160 * setup: the pud is never bad, and a pud always exists (as it's folded
80161 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80162 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80163
80164 #define pgd_populate(mm, pgd, pud) do { } while (0)
80165 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80166 /*
80167 * (puds are folded into pgds so this doesn't get actually called,
80168 * but the define is needed for a generic inline function.)
80169 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80170 index 752e30d..87f172d 100644
80171 --- a/include/asm-generic/pgtable.h
80172 +++ b/include/asm-generic/pgtable.h
80173 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80174 }
80175 #endif /* CONFIG_NUMA_BALANCING */
80176
80177 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80178 +#ifdef CONFIG_PAX_KERNEXEC
80179 +#error KERNEXEC requires pax_open_kernel
80180 +#else
80181 +static inline unsigned long pax_open_kernel(void) { return 0; }
80182 +#endif
80183 +#endif
80184 +
80185 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80186 +#ifdef CONFIG_PAX_KERNEXEC
80187 +#error KERNEXEC requires pax_close_kernel
80188 +#else
80189 +static inline unsigned long pax_close_kernel(void) { return 0; }
80190 +#endif
80191 +#endif
80192 +
80193 #endif /* CONFIG_MMU */
80194
80195 #endif /* !__ASSEMBLY__ */
80196 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80197 index 72d8803..cb9749c 100644
80198 --- a/include/asm-generic/uaccess.h
80199 +++ b/include/asm-generic/uaccess.h
80200 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80201 return __clear_user(to, n);
80202 }
80203
80204 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80205 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80206 +#error UDEREF requires pax_open_userland
80207 +#else
80208 +static inline unsigned long pax_open_userland(void) { return 0; }
80209 +#endif
80210 +#endif
80211 +
80212 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80214 +#error UDEREF requires pax_close_userland
80215 +#else
80216 +static inline unsigned long pax_close_userland(void) { return 0; }
80217 +#endif
80218 +#endif
80219 +
80220 #endif /* __ASM_GENERIC_UACCESS_H */
80221 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80222 index aa70cbd..fd72c7a 100644
80223 --- a/include/asm-generic/vmlinux.lds.h
80224 +++ b/include/asm-generic/vmlinux.lds.h
80225 @@ -233,6 +233,7 @@
80226 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80227 VMLINUX_SYMBOL(__start_rodata) = .; \
80228 *(.rodata) *(.rodata.*) \
80229 + *(.data..read_only) \
80230 *(__vermagic) /* Kernel version magic */ \
80231 . = ALIGN(8); \
80232 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80233 @@ -724,17 +725,18 @@
80234 * section in the linker script will go there too. @phdr should have
80235 * a leading colon.
80236 *
80237 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80238 + * Note that this macros defines per_cpu_load as an absolute symbol.
80239 * If there is no need to put the percpu section at a predetermined
80240 * address, use PERCPU_SECTION.
80241 */
80242 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80243 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80244 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80245 + per_cpu_load = .; \
80246 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80247 - LOAD_OFFSET) { \
80248 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80249 PERCPU_INPUT(cacheline) \
80250 } phdr \
80251 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80252 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80253
80254 /**
80255 * PERCPU_SECTION - define output section for percpu area, simple version
80256 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80257 index 623a59c..1e79ab9 100644
80258 --- a/include/crypto/algapi.h
80259 +++ b/include/crypto/algapi.h
80260 @@ -34,7 +34,7 @@ struct crypto_type {
80261 unsigned int maskclear;
80262 unsigned int maskset;
80263 unsigned int tfmsize;
80264 -};
80265 +} __do_const;
80266
80267 struct crypto_instance {
80268 struct crypto_alg alg;
80269 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80270 index 53ed876..5bb09be 100644
80271 --- a/include/drm/drmP.h
80272 +++ b/include/drm/drmP.h
80273 @@ -59,6 +59,7 @@
80274
80275 #include <asm/mman.h>
80276 #include <asm/pgalloc.h>
80277 +#include <asm/local.h>
80278 #include <asm/uaccess.h>
80279
80280 #include <uapi/drm/drm.h>
80281 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80282 * \param cmd command.
80283 * \param arg argument.
80284 */
80285 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80286 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80287 + struct drm_file *file_priv);
80288 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80289 struct drm_file *file_priv);
80290
80291 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80292 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80293 unsigned long arg);
80294
80295 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80296 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80297 struct drm_ioctl_desc {
80298 unsigned int cmd;
80299 int flags;
80300 - drm_ioctl_t *func;
80301 + drm_ioctl_t func;
80302 unsigned int cmd_drv;
80303 const char *name;
80304 -};
80305 +} __do_const;
80306
80307 /**
80308 * Creates a driver or general drm_ioctl_desc array entry for the given
80309 @@ -629,7 +632,8 @@ struct drm_info_list {
80310 int (*show)(struct seq_file*, void*); /** show callback */
80311 u32 driver_features; /**< Required driver features for this entry */
80312 void *data;
80313 -};
80314 +} __do_const;
80315 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80316
80317 /**
80318 * debugfs node structure. This structure represents a debugfs file.
80319 @@ -713,7 +717,7 @@ struct drm_device {
80320
80321 /** \name Usage Counters */
80322 /*@{ */
80323 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80324 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80325 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80326 int buf_use; /**< Buffers in use -- cannot alloc */
80327 atomic_t buf_alloc; /**< Buffer allocation in progress */
80328 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80329 index a3d75fe..6802f9c 100644
80330 --- a/include/drm/drm_crtc_helper.h
80331 +++ b/include/drm/drm_crtc_helper.h
80332 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80333 struct drm_connector *connector);
80334 /* disable encoder when not in use - more explicit than dpms off */
80335 void (*disable)(struct drm_encoder *encoder);
80336 -};
80337 +} __no_const;
80338
80339 /**
80340 * drm_connector_helper_funcs - helper operations for connectors
80341 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80342 index a70d456..6ea07cd 100644
80343 --- a/include/drm/i915_pciids.h
80344 +++ b/include/drm/i915_pciids.h
80345 @@ -37,7 +37,7 @@
80346 */
80347 #define INTEL_VGA_DEVICE(id, info) { \
80348 0x8086, id, \
80349 - ~0, ~0, \
80350 + PCI_ANY_ID, PCI_ANY_ID, \
80351 0x030000, 0xff0000, \
80352 (unsigned long) info }
80353
80354 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80355 index 72dcbe8..8db58d7 100644
80356 --- a/include/drm/ttm/ttm_memory.h
80357 +++ b/include/drm/ttm/ttm_memory.h
80358 @@ -48,7 +48,7 @@
80359
80360 struct ttm_mem_shrink {
80361 int (*do_shrink) (struct ttm_mem_shrink *);
80362 -};
80363 +} __no_const;
80364
80365 /**
80366 * struct ttm_mem_global - Global memory accounting structure.
80367 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80368 index 49a8284..9643967 100644
80369 --- a/include/drm/ttm/ttm_page_alloc.h
80370 +++ b/include/drm/ttm/ttm_page_alloc.h
80371 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80372 */
80373 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80374
80375 +struct device;
80376 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80377 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80378
80379 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80380 index 4b840e8..155d235 100644
80381 --- a/include/keys/asymmetric-subtype.h
80382 +++ b/include/keys/asymmetric-subtype.h
80383 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80384 /* Verify the signature on a key of this subtype (optional) */
80385 int (*verify_signature)(const struct key *key,
80386 const struct public_key_signature *sig);
80387 -};
80388 +} __do_const;
80389
80390 /**
80391 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80392 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80393 index c1da539..1dcec55 100644
80394 --- a/include/linux/atmdev.h
80395 +++ b/include/linux/atmdev.h
80396 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80397 #endif
80398
80399 struct k_atm_aal_stats {
80400 -#define __HANDLE_ITEM(i) atomic_t i
80401 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80402 __AAL_STAT_ITEMS
80403 #undef __HANDLE_ITEM
80404 };
80405 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80406 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80407 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80408 struct module *owner;
80409 -};
80410 +} __do_const ;
80411
80412 struct atmphy_ops {
80413 int (*start)(struct atm_dev *dev);
80414 diff --git a/include/linux/audit.h b/include/linux/audit.h
80415 index 10f155b..6c73ffe 100644
80416 --- a/include/linux/audit.h
80417 +++ b/include/linux/audit.h
80418 @@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
80419 extern unsigned int audit_serial(void);
80420 extern int auditsc_get_stamp(struct audit_context *ctx,
80421 struct timespec *t, unsigned int *serial);
80422 -extern int audit_set_loginuid(kuid_t loginuid);
80423 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80424
80425 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80426 {
80427 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80428 index 61f29e5..e67c658 100644
80429 --- a/include/linux/binfmts.h
80430 +++ b/include/linux/binfmts.h
80431 @@ -44,7 +44,7 @@ struct linux_binprm {
80432 unsigned interp_flags;
80433 unsigned interp_data;
80434 unsigned long loader, exec;
80435 -};
80436 +} __randomize_layout;
80437
80438 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80439 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80440 @@ -73,8 +73,10 @@ struct linux_binfmt {
80441 int (*load_binary)(struct linux_binprm *);
80442 int (*load_shlib)(struct file *);
80443 int (*core_dump)(struct coredump_params *cprm);
80444 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80445 + void (*handle_mmap)(struct file *);
80446 unsigned long min_coredump; /* minimal dump size */
80447 -};
80448 +} __do_const __randomize_layout;
80449
80450 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80451
80452 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80453 index 5d858e0..336c1d9 100644
80454 --- a/include/linux/bitops.h
80455 +++ b/include/linux/bitops.h
80456 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80457 * @word: value to rotate
80458 * @shift: bits to roll
80459 */
80460 -static inline __u32 rol32(__u32 word, unsigned int shift)
80461 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80462 {
80463 return (word << shift) | (word >> (32 - shift));
80464 }
80465 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80466 * @word: value to rotate
80467 * @shift: bits to roll
80468 */
80469 -static inline __u32 ror32(__u32 word, unsigned int shift)
80470 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80471 {
80472 return (word >> shift) | (word << (32 - shift));
80473 }
80474 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80475 return (__s32)(value << shift) >> shift;
80476 }
80477
80478 -static inline unsigned fls_long(unsigned long l)
80479 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80480 {
80481 if (sizeof(l) == 4)
80482 return fls(l);
80483 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80484 index aac0f9e..73c9869 100644
80485 --- a/include/linux/blkdev.h
80486 +++ b/include/linux/blkdev.h
80487 @@ -1615,7 +1615,7 @@ struct block_device_operations {
80488 /* this callback is with swap_lock and sometimes page table lock held */
80489 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80490 struct module *owner;
80491 -};
80492 +} __do_const;
80493
80494 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80495 unsigned long);
80496 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80497 index afc1343..9735539 100644
80498 --- a/include/linux/blktrace_api.h
80499 +++ b/include/linux/blktrace_api.h
80500 @@ -25,7 +25,7 @@ struct blk_trace {
80501 struct dentry *dropped_file;
80502 struct dentry *msg_file;
80503 struct list_head running_list;
80504 - atomic_t dropped;
80505 + atomic_unchecked_t dropped;
80506 };
80507
80508 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80509 diff --git a/include/linux/cache.h b/include/linux/cache.h
80510 index 17e7e82..1d7da26 100644
80511 --- a/include/linux/cache.h
80512 +++ b/include/linux/cache.h
80513 @@ -16,6 +16,14 @@
80514 #define __read_mostly
80515 #endif
80516
80517 +#ifndef __read_only
80518 +#ifdef CONFIG_PAX_KERNEXEC
80519 +#error KERNEXEC requires __read_only
80520 +#else
80521 +#define __read_only __read_mostly
80522 +#endif
80523 +#endif
80524 +
80525 #ifndef ____cacheline_aligned
80526 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80527 #endif
80528 diff --git a/include/linux/capability.h b/include/linux/capability.h
80529 index aa93e5e..985a1b0 100644
80530 --- a/include/linux/capability.h
80531 +++ b/include/linux/capability.h
80532 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80533 extern bool capable(int cap);
80534 extern bool ns_capable(struct user_namespace *ns, int cap);
80535 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80536 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80537 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80538 +extern bool capable_nolog(int cap);
80539 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80540
80541 /* audit system wants to get cap info from files as well */
80542 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80543
80544 +extern int is_privileged_binary(const struct dentry *dentry);
80545 +
80546 #endif /* !_LINUX_CAPABILITY_H */
80547 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80548 index 8609d57..86e4d79 100644
80549 --- a/include/linux/cdrom.h
80550 +++ b/include/linux/cdrom.h
80551 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80552
80553 /* driver specifications */
80554 const int capability; /* capability flags */
80555 - int n_minors; /* number of active minor devices */
80556 /* handle uniform packets for scsi type devices (scsi,atapi) */
80557 int (*generic_packet) (struct cdrom_device_info *,
80558 struct packet_command *);
80559 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80560 index 4ce9056..86caac6 100644
80561 --- a/include/linux/cleancache.h
80562 +++ b/include/linux/cleancache.h
80563 @@ -31,7 +31,7 @@ struct cleancache_ops {
80564 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80565 void (*invalidate_inode)(int, struct cleancache_filekey);
80566 void (*invalidate_fs)(int);
80567 -};
80568 +} __no_const;
80569
80570 extern struct cleancache_ops *
80571 cleancache_register_ops(struct cleancache_ops *ops);
80572 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80573 index 2839c63..5b06b6b 100644
80574 --- a/include/linux/clk-provider.h
80575 +++ b/include/linux/clk-provider.h
80576 @@ -191,6 +191,7 @@ struct clk_ops {
80577 void (*init)(struct clk_hw *hw);
80578 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80579 };
80580 +typedef struct clk_ops __no_const clk_ops_no_const;
80581
80582 /**
80583 * struct clk_init_data - holds init data that's common to all clocks and is
80584 diff --git a/include/linux/compat.h b/include/linux/compat.h
80585 index e649426..a74047b 100644
80586 --- a/include/linux/compat.h
80587 +++ b/include/linux/compat.h
80588 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80589 compat_size_t __user *len_ptr);
80590
80591 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80592 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80593 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80594 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80595 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80596 compat_ssize_t msgsz, int msgflg);
80597 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80598 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80599 compat_ulong_t addr, compat_ulong_t data);
80600 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80601 - compat_long_t addr, compat_long_t data);
80602 + compat_ulong_t addr, compat_ulong_t data);
80603
80604 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80605 /*
80606 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80607 index d1a5582..4424efa 100644
80608 --- a/include/linux/compiler-gcc4.h
80609 +++ b/include/linux/compiler-gcc4.h
80610 @@ -39,9 +39,34 @@
80611 # define __compiletime_warning(message) __attribute__((warning(message)))
80612 # define __compiletime_error(message) __attribute__((error(message)))
80613 #endif /* __CHECKER__ */
80614 +
80615 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80616 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80617 +#define __bos0(ptr) __bos((ptr), 0)
80618 +#define __bos1(ptr) __bos((ptr), 1)
80619 #endif /* GCC_VERSION >= 40300 */
80620
80621 #if GCC_VERSION >= 40500
80622 +
80623 +#ifdef RANDSTRUCT_PLUGIN
80624 +#define __randomize_layout __attribute__((randomize_layout))
80625 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80626 +#endif
80627 +
80628 +#ifdef CONSTIFY_PLUGIN
80629 +#define __no_const __attribute__((no_const))
80630 +#define __do_const __attribute__((do_const))
80631 +#endif
80632 +
80633 +#ifdef SIZE_OVERFLOW_PLUGIN
80634 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80635 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80636 +#endif
80637 +
80638 +#ifdef LATENT_ENTROPY_PLUGIN
80639 +#define __latent_entropy __attribute__((latent_entropy))
80640 +#endif
80641 +
80642 /*
80643 * Mark a position in code as unreachable. This can be used to
80644 * suppress control flow warnings after asm blocks that transfer
80645 diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h
80646 index c8c5659..d09f2ad 100644
80647 --- a/include/linux/compiler-gcc5.h
80648 +++ b/include/linux/compiler-gcc5.h
80649 @@ -28,6 +28,28 @@
80650 # define __compiletime_error(message) __attribute__((error(message)))
80651 #endif /* __CHECKER__ */
80652
80653 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80654 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80655 +#define __bos0(ptr) __bos((ptr), 0)
80656 +#define __bos1(ptr) __bos((ptr), 1)
80657 +
80658 +#ifdef CONSTIFY_PLUGIN
80659 +#error not yet
80660 +#define __no_const __attribute__((no_const))
80661 +#define __do_const __attribute__((do_const))
80662 +#endif
80663 +
80664 +#ifdef SIZE_OVERFLOW_PLUGIN
80665 +#error not yet
80666 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80667 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80668 +#endif
80669 +
80670 +#ifdef LATENT_ENTROPY_PLUGIN
80671 +#error not yet
80672 +#define __latent_entropy __attribute__((latent_entropy))
80673 +#endif
80674 +
80675 /*
80676 * Mark a position in code as unreachable. This can be used to
80677 * suppress control flow warnings after asm blocks that transfer
80678 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80679 index d5ad7b1..3b74638 100644
80680 --- a/include/linux/compiler.h
80681 +++ b/include/linux/compiler.h
80682 @@ -5,11 +5,14 @@
80683
80684 #ifdef __CHECKER__
80685 # define __user __attribute__((noderef, address_space(1)))
80686 +# define __force_user __force __user
80687 # define __kernel __attribute__((address_space(0)))
80688 +# define __force_kernel __force __kernel
80689 # define __safe __attribute__((safe))
80690 # define __force __attribute__((force))
80691 # define __nocast __attribute__((nocast))
80692 # define __iomem __attribute__((noderef, address_space(2)))
80693 +# define __force_iomem __force __iomem
80694 # define __must_hold(x) __attribute__((context(x,1,1)))
80695 # define __acquires(x) __attribute__((context(x,0,1)))
80696 # define __releases(x) __attribute__((context(x,1,0)))
80697 @@ -17,20 +20,37 @@
80698 # define __release(x) __context__(x,-1)
80699 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80700 # define __percpu __attribute__((noderef, address_space(3)))
80701 +# define __force_percpu __force __percpu
80702 #ifdef CONFIG_SPARSE_RCU_POINTER
80703 # define __rcu __attribute__((noderef, address_space(4)))
80704 +# define __force_rcu __force __rcu
80705 #else
80706 # define __rcu
80707 +# define __force_rcu
80708 #endif
80709 extern void __chk_user_ptr(const volatile void __user *);
80710 extern void __chk_io_ptr(const volatile void __iomem *);
80711 #else
80712 -# define __user
80713 -# define __kernel
80714 +# ifdef CHECKER_PLUGIN
80715 +//# define __user
80716 +//# define __force_user
80717 +//# define __kernel
80718 +//# define __force_kernel
80719 +# else
80720 +# ifdef STRUCTLEAK_PLUGIN
80721 +# define __user __attribute__((user))
80722 +# else
80723 +# define __user
80724 +# endif
80725 +# define __force_user
80726 +# define __kernel
80727 +# define __force_kernel
80728 +# endif
80729 # define __safe
80730 # define __force
80731 # define __nocast
80732 # define __iomem
80733 +# define __force_iomem
80734 # define __chk_user_ptr(x) (void)0
80735 # define __chk_io_ptr(x) (void)0
80736 # define __builtin_warning(x, y...) (1)
80737 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80738 # define __release(x) (void)0
80739 # define __cond_lock(x,c) (c)
80740 # define __percpu
80741 +# define __force_percpu
80742 # define __rcu
80743 +# define __force_rcu
80744 #endif
80745
80746 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80747 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80748 # define __attribute_const__ /* unimplemented */
80749 #endif
80750
80751 +#ifndef __randomize_layout
80752 +# define __randomize_layout
80753 +#endif
80754 +
80755 +#ifndef __no_randomize_layout
80756 +# define __no_randomize_layout
80757 +#endif
80758 +
80759 +#ifndef __no_const
80760 +# define __no_const
80761 +#endif
80762 +
80763 +#ifndef __do_const
80764 +# define __do_const
80765 +#endif
80766 +
80767 +#ifndef __size_overflow
80768 +# define __size_overflow(...)
80769 +#endif
80770 +
80771 +#ifndef __intentional_overflow
80772 +# define __intentional_overflow(...)
80773 +#endif
80774 +
80775 +#ifndef __latent_entropy
80776 +# define __latent_entropy
80777 +#endif
80778 +
80779 /*
80780 * Tell gcc if a function is cold. The compiler will assume any path
80781 * directly leading to the call is unlikely.
80782 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80783 #define __cold
80784 #endif
80785
80786 +#ifndef __alloc_size
80787 +#define __alloc_size(...)
80788 +#endif
80789 +
80790 +#ifndef __bos
80791 +#define __bos(ptr, arg)
80792 +#endif
80793 +
80794 +#ifndef __bos0
80795 +#define __bos0(ptr)
80796 +#endif
80797 +
80798 +#ifndef __bos1
80799 +#define __bos1(ptr)
80800 +#endif
80801 +
80802 /* Simple shorthand for a section definition */
80803 #ifndef __section
80804 # define __section(S) __attribute__ ((__section__(#S)))
80805 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80806 * use is to mediate communication between process-level code and irq/NMI
80807 * handlers, all running on the same CPU.
80808 */
80809 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80810 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80811 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80812
80813 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80814 #ifdef CONFIG_KPROBES
80815 diff --git a/include/linux/completion.h b/include/linux/completion.h
80816 index 5d5aaae..0ea9b84 100644
80817 --- a/include/linux/completion.h
80818 +++ b/include/linux/completion.h
80819 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80820
80821 extern void wait_for_completion(struct completion *);
80822 extern void wait_for_completion_io(struct completion *);
80823 -extern int wait_for_completion_interruptible(struct completion *x);
80824 -extern int wait_for_completion_killable(struct completion *x);
80825 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80826 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80827 extern unsigned long wait_for_completion_timeout(struct completion *x,
80828 - unsigned long timeout);
80829 + unsigned long timeout) __intentional_overflow(-1);
80830 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80831 - unsigned long timeout);
80832 + unsigned long timeout) __intentional_overflow(-1);
80833 extern long wait_for_completion_interruptible_timeout(
80834 - struct completion *x, unsigned long timeout);
80835 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80836 extern long wait_for_completion_killable_timeout(
80837 - struct completion *x, unsigned long timeout);
80838 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80839 extern bool try_wait_for_completion(struct completion *x);
80840 extern bool completion_done(struct completion *x);
80841
80842 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80843 index 34025df..d94bbbc 100644
80844 --- a/include/linux/configfs.h
80845 +++ b/include/linux/configfs.h
80846 @@ -125,7 +125,7 @@ struct configfs_attribute {
80847 const char *ca_name;
80848 struct module *ca_owner;
80849 umode_t ca_mode;
80850 -};
80851 +} __do_const;
80852
80853 /*
80854 * Users often need to create attribute structures for their configurable
80855 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80856 index 503b085b..1638c9e 100644
80857 --- a/include/linux/cpufreq.h
80858 +++ b/include/linux/cpufreq.h
80859 @@ -206,6 +206,7 @@ struct global_attr {
80860 ssize_t (*store)(struct kobject *a, struct attribute *b,
80861 const char *c, size_t count);
80862 };
80863 +typedef struct global_attr __no_const global_attr_no_const;
80864
80865 #define define_one_global_ro(_name) \
80866 static struct global_attr _name = \
80867 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80868 bool boost_supported;
80869 bool boost_enabled;
80870 int (*set_boost) (int state);
80871 -};
80872 +} __do_const;
80873
80874 /* flags */
80875 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80876 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80877 index 25e0df6..952dffd 100644
80878 --- a/include/linux/cpuidle.h
80879 +++ b/include/linux/cpuidle.h
80880 @@ -50,7 +50,8 @@ struct cpuidle_state {
80881 int index);
80882
80883 int (*enter_dead) (struct cpuidle_device *dev, int index);
80884 -};
80885 +} __do_const;
80886 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80887
80888 /* Idle State Flags */
80889 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80890 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80891 void (*reflect) (struct cpuidle_device *dev, int index);
80892
80893 struct module *owner;
80894 -};
80895 +} __do_const;
80896
80897 #ifdef CONFIG_CPU_IDLE
80898 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80899 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80900 index 0a9a6da..ea597ca 100644
80901 --- a/include/linux/cpumask.h
80902 +++ b/include/linux/cpumask.h
80903 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80904 }
80905
80906 /* Valid inputs for n are -1 and 0. */
80907 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80908 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80909 {
80910 return n+1;
80911 }
80912
80913 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80914 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80915 {
80916 return n+1;
80917 }
80918
80919 -static inline unsigned int cpumask_next_and(int n,
80920 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80921 const struct cpumask *srcp,
80922 const struct cpumask *andp)
80923 {
80924 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80925 *
80926 * Returns >= nr_cpu_ids if no further cpus set.
80927 */
80928 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80929 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80930 {
80931 /* -1 is a legal arg here. */
80932 if (n != -1)
80933 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80934 *
80935 * Returns >= nr_cpu_ids if no further cpus unset.
80936 */
80937 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80938 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80939 {
80940 /* -1 is a legal arg here. */
80941 if (n != -1)
80942 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80943 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80944 }
80945
80946 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80947 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80948 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80949 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80950
80951 diff --git a/include/linux/cred.h b/include/linux/cred.h
80952 index 2fb2ca2..d6a3340 100644
80953 --- a/include/linux/cred.h
80954 +++ b/include/linux/cred.h
80955 @@ -35,7 +35,7 @@ struct group_info {
80956 int nblocks;
80957 kgid_t small_block[NGROUPS_SMALL];
80958 kgid_t *blocks[0];
80959 -};
80960 +} __randomize_layout;
80961
80962 /**
80963 * get_group_info - Get a reference to a group info structure
80964 @@ -137,7 +137,7 @@ struct cred {
80965 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80966 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80967 struct rcu_head rcu; /* RCU deletion hook */
80968 -};
80969 +} __randomize_layout;
80970
80971 extern void __put_cred(struct cred *);
80972 extern void exit_creds(struct task_struct *);
80973 @@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80974 static inline void validate_process_creds(void)
80975 {
80976 }
80977 +static inline void validate_task_creds(struct task_struct *task)
80978 +{
80979 +}
80980 #endif
80981
80982 /**
80983 @@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
80984
80985 #define task_uid(task) (task_cred_xxx((task), uid))
80986 #define task_euid(task) (task_cred_xxx((task), euid))
80987 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80988
80989 #define current_cred_xxx(xxx) \
80990 ({ \
80991 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80992 index dc34dfc..bdf9b5d 100644
80993 --- a/include/linux/crypto.h
80994 +++ b/include/linux/crypto.h
80995 @@ -386,7 +386,7 @@ struct cipher_tfm {
80996 const u8 *key, unsigned int keylen);
80997 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80998 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80999 -};
81000 +} __no_const;
81001
81002 struct hash_tfm {
81003 int (*init)(struct hash_desc *desc);
81004 @@ -407,13 +407,13 @@ struct compress_tfm {
81005 int (*cot_decompress)(struct crypto_tfm *tfm,
81006 const u8 *src, unsigned int slen,
81007 u8 *dst, unsigned int *dlen);
81008 -};
81009 +} __no_const;
81010
81011 struct rng_tfm {
81012 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81013 unsigned int dlen);
81014 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81015 -};
81016 +} __no_const;
81017
81018 #define crt_ablkcipher crt_u.ablkcipher
81019 #define crt_aead crt_u.aead
81020 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81021 index 653589e..4ef254a 100644
81022 --- a/include/linux/ctype.h
81023 +++ b/include/linux/ctype.h
81024 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81025 * Fast implementation of tolower() for internal usage. Do not use in your
81026 * code.
81027 */
81028 -static inline char _tolower(const char c)
81029 +static inline unsigned char _tolower(const unsigned char c)
81030 {
81031 return c | 0x20;
81032 }
81033 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81034 index 1c2f1b8..7b9f50c 100644
81035 --- a/include/linux/dcache.h
81036 +++ b/include/linux/dcache.h
81037 @@ -123,6 +123,9 @@ struct dentry {
81038 unsigned long d_time; /* used by d_revalidate */
81039 void *d_fsdata; /* fs-specific data */
81040
81041 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
81042 + atomic_t chroot_refcnt; /* tracks use of directory in chroot */
81043 +#endif
81044 struct list_head d_lru; /* LRU list */
81045 struct list_head d_child; /* child of parent list */
81046 struct list_head d_subdirs; /* our children */
81047 @@ -133,7 +136,7 @@ struct dentry {
81048 struct hlist_node d_alias; /* inode alias list */
81049 struct rcu_head d_rcu;
81050 } d_u;
81051 -};
81052 +} __randomize_layout;
81053
81054 /*
81055 * dentry->d_lock spinlock nesting subclasses:
81056 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81057 index 7925bf0..d5143d2 100644
81058 --- a/include/linux/decompress/mm.h
81059 +++ b/include/linux/decompress/mm.h
81060 @@ -77,7 +77,7 @@ static void free(void *where)
81061 * warnings when not needed (indeed large_malloc / large_free are not
81062 * needed by inflate */
81063
81064 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81065 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81066 #define free(a) kfree(a)
81067
81068 #define large_malloc(a) vmalloc(a)
81069 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81070 index f1863dc..5c26074 100644
81071 --- a/include/linux/devfreq.h
81072 +++ b/include/linux/devfreq.h
81073 @@ -114,7 +114,7 @@ struct devfreq_governor {
81074 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81075 int (*event_handler)(struct devfreq *devfreq,
81076 unsigned int event, void *data);
81077 -};
81078 +} __do_const;
81079
81080 /**
81081 * struct devfreq - Device devfreq structure
81082 diff --git a/include/linux/device.h b/include/linux/device.h
81083 index ce1f2160..189bc33 100644
81084 --- a/include/linux/device.h
81085 +++ b/include/linux/device.h
81086 @@ -311,7 +311,7 @@ struct subsys_interface {
81087 struct list_head node;
81088 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81089 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81090 -};
81091 +} __do_const;
81092
81093 int subsys_interface_register(struct subsys_interface *sif);
81094 void subsys_interface_unregister(struct subsys_interface *sif);
81095 @@ -507,7 +507,7 @@ struct device_type {
81096 void (*release)(struct device *dev);
81097
81098 const struct dev_pm_ops *pm;
81099 -};
81100 +} __do_const;
81101
81102 /* interface for exporting device attributes */
81103 struct device_attribute {
81104 @@ -517,11 +517,12 @@ struct device_attribute {
81105 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81106 const char *buf, size_t count);
81107 };
81108 +typedef struct device_attribute __no_const device_attribute_no_const;
81109
81110 struct dev_ext_attribute {
81111 struct device_attribute attr;
81112 void *var;
81113 -};
81114 +} __do_const;
81115
81116 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81117 char *buf);
81118 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81119 index d5d3881..7ed54af 100644
81120 --- a/include/linux/dma-mapping.h
81121 +++ b/include/linux/dma-mapping.h
81122 @@ -60,7 +60,7 @@ struct dma_map_ops {
81123 u64 (*get_required_mask)(struct device *dev);
81124 #endif
81125 int is_phys;
81126 -};
81127 +} __do_const;
81128
81129 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81130
81131 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81132 index 653a1fd..9133cd1 100644
81133 --- a/include/linux/dmaengine.h
81134 +++ b/include/linux/dmaengine.h
81135 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
81136 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81137 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81138
81139 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81140 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81141 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81142 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81143 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81144 struct dma_pinned_list *pinned_list, struct page *page,
81145 unsigned int offset, size_t len);
81146
81147 diff --git a/include/linux/efi.h b/include/linux/efi.h
81148 index 0949f9c..04cb9a5 100644
81149 --- a/include/linux/efi.h
81150 +++ b/include/linux/efi.h
81151 @@ -1050,6 +1050,7 @@ struct efivar_operations {
81152 efi_set_variable_nonblocking_t *set_variable_nonblocking;
81153 efi_query_variable_store_t *query_variable_store;
81154 };
81155 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81156
81157 struct efivars {
81158 /*
81159 diff --git a/include/linux/elf.h b/include/linux/elf.h
81160 index 67a5fa7..b817372 100644
81161 --- a/include/linux/elf.h
81162 +++ b/include/linux/elf.h
81163 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81164 #define elf_note elf32_note
81165 #define elf_addr_t Elf32_Off
81166 #define Elf_Half Elf32_Half
81167 +#define elf_dyn Elf32_Dyn
81168
81169 #else
81170
81171 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81172 #define elf_note elf64_note
81173 #define elf_addr_t Elf64_Off
81174 #define Elf_Half Elf64_Half
81175 +#define elf_dyn Elf64_Dyn
81176
81177 #endif
81178
81179 diff --git a/include/linux/err.h b/include/linux/err.h
81180 index a729120..6ede2c9 100644
81181 --- a/include/linux/err.h
81182 +++ b/include/linux/err.h
81183 @@ -20,12 +20,12 @@
81184
81185 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81186
81187 -static inline void * __must_check ERR_PTR(long error)
81188 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81189 {
81190 return (void *) error;
81191 }
81192
81193 -static inline long __must_check PTR_ERR(__force const void *ptr)
81194 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81195 {
81196 return (long) ptr;
81197 }
81198 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81199 index 36f49c4..a2a1f4c 100644
81200 --- a/include/linux/extcon.h
81201 +++ b/include/linux/extcon.h
81202 @@ -135,7 +135,7 @@ struct extcon_dev {
81203 /* /sys/class/extcon/.../mutually_exclusive/... */
81204 struct attribute_group attr_g_muex;
81205 struct attribute **attrs_muex;
81206 - struct device_attribute *d_attrs_muex;
81207 + device_attribute_no_const *d_attrs_muex;
81208 };
81209
81210 /**
81211 diff --git a/include/linux/fb.h b/include/linux/fb.h
81212 index 09bb7a1..d98870a 100644
81213 --- a/include/linux/fb.h
81214 +++ b/include/linux/fb.h
81215 @@ -305,7 +305,7 @@ struct fb_ops {
81216 /* called at KDB enter and leave time to prepare the console */
81217 int (*fb_debug_enter)(struct fb_info *info);
81218 int (*fb_debug_leave)(struct fb_info *info);
81219 -};
81220 +} __do_const;
81221
81222 #ifdef CONFIG_FB_TILEBLITTING
81223 #define FB_TILE_CURSOR_NONE 0
81224 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81225 index 230f87b..1fd0485 100644
81226 --- a/include/linux/fdtable.h
81227 +++ b/include/linux/fdtable.h
81228 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81229 void put_files_struct(struct files_struct *fs);
81230 void reset_files_struct(struct files_struct *);
81231 int unshare_files(struct files_struct **);
81232 -struct files_struct *dup_fd(struct files_struct *, int *);
81233 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81234 void do_close_on_exec(struct files_struct *);
81235 int iterate_fd(struct files_struct *, unsigned,
81236 int (*)(const void *, struct file *, unsigned),
81237 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81238 index 8293262..2b3b8bd 100644
81239 --- a/include/linux/frontswap.h
81240 +++ b/include/linux/frontswap.h
81241 @@ -11,7 +11,7 @@ struct frontswap_ops {
81242 int (*load)(unsigned, pgoff_t, struct page *);
81243 void (*invalidate_page)(unsigned, pgoff_t);
81244 void (*invalidate_area)(unsigned);
81245 -};
81246 +} __no_const;
81247
81248 extern bool frontswap_enabled;
81249 extern struct frontswap_ops *
81250 diff --git a/include/linux/fs.h b/include/linux/fs.h
81251 index 9ab779e..0c636f2 100644
81252 --- a/include/linux/fs.h
81253 +++ b/include/linux/fs.h
81254 @@ -412,7 +412,7 @@ struct address_space {
81255 spinlock_t private_lock; /* for use by the address_space */
81256 struct list_head private_list; /* ditto */
81257 void *private_data; /* ditto */
81258 -} __attribute__((aligned(sizeof(long))));
81259 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81260 /*
81261 * On most architectures that alignment is already the case; but
81262 * must be enforced here for CRIS, to let the least significant bit
81263 @@ -455,7 +455,7 @@ struct block_device {
81264 int bd_fsfreeze_count;
81265 /* Mutex for freeze */
81266 struct mutex bd_fsfreeze_mutex;
81267 -};
81268 +} __randomize_layout;
81269
81270 /*
81271 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81272 @@ -624,7 +624,7 @@ struct inode {
81273 #endif
81274
81275 void *i_private; /* fs or device private pointer */
81276 -};
81277 +} __randomize_layout;
81278
81279 static inline int inode_unhashed(struct inode *inode)
81280 {
81281 @@ -820,7 +820,7 @@ struct file {
81282 struct list_head f_tfile_llink;
81283 #endif /* #ifdef CONFIG_EPOLL */
81284 struct address_space *f_mapping;
81285 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81286 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81287
81288 struct file_handle {
81289 __u32 handle_bytes;
81290 @@ -945,7 +945,7 @@ struct file_lock {
81291 int state; /* state of grant or error if -ve */
81292 } afs;
81293 } fl_u;
81294 -};
81295 +} __randomize_layout;
81296
81297 /* The following constant reflects the upper bound of the file/locking space */
81298 #ifndef OFFSET_MAX
81299 @@ -1287,7 +1287,7 @@ struct super_block {
81300 * Indicates how deep in a filesystem stack this SB is
81301 */
81302 int s_stack_depth;
81303 -};
81304 +} __randomize_layout;
81305
81306 extern struct timespec current_fs_time(struct super_block *sb);
81307
81308 @@ -1514,7 +1514,8 @@ struct file_operations {
81309 long (*fallocate)(struct file *file, int mode, loff_t offset,
81310 loff_t len);
81311 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81312 -};
81313 +} __do_const __randomize_layout;
81314 +typedef struct file_operations __no_const file_operations_no_const;
81315
81316 struct inode_operations {
81317 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81318 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81319 return !IS_DEADDIR(inode);
81320 }
81321
81322 +static inline bool is_sidechannel_device(const struct inode *inode)
81323 +{
81324 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81325 + umode_t mode = inode->i_mode;
81326 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81327 +#else
81328 + return false;
81329 +#endif
81330 +}
81331 +
81332 #endif /* _LINUX_FS_H */
81333 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81334 index 0efc3e6..fd23610 100644
81335 --- a/include/linux/fs_struct.h
81336 +++ b/include/linux/fs_struct.h
81337 @@ -6,13 +6,13 @@
81338 #include <linux/seqlock.h>
81339
81340 struct fs_struct {
81341 - int users;
81342 + atomic_t users;
81343 spinlock_t lock;
81344 seqcount_t seq;
81345 int umask;
81346 int in_exec;
81347 struct path root, pwd;
81348 -};
81349 +} __randomize_layout;
81350
81351 extern struct kmem_cache *fs_cachep;
81352
81353 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81354 index 7714849..a4a5c7a 100644
81355 --- a/include/linux/fscache-cache.h
81356 +++ b/include/linux/fscache-cache.h
81357 @@ -113,7 +113,7 @@ struct fscache_operation {
81358 fscache_operation_release_t release;
81359 };
81360
81361 -extern atomic_t fscache_op_debug_id;
81362 +extern atomic_unchecked_t fscache_op_debug_id;
81363 extern void fscache_op_work_func(struct work_struct *work);
81364
81365 extern void fscache_enqueue_operation(struct fscache_operation *);
81366 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81367 INIT_WORK(&op->work, fscache_op_work_func);
81368 atomic_set(&op->usage, 1);
81369 op->state = FSCACHE_OP_ST_INITIALISED;
81370 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81371 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81372 op->processor = processor;
81373 op->release = release;
81374 INIT_LIST_HEAD(&op->pend_link);
81375 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81376 index 115bb81..e7b812b 100644
81377 --- a/include/linux/fscache.h
81378 +++ b/include/linux/fscache.h
81379 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81380 * - this is mandatory for any object that may have data
81381 */
81382 void (*now_uncached)(void *cookie_netfs_data);
81383 -};
81384 +} __do_const;
81385
81386 /*
81387 * fscache cached network filesystem type
81388 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81389 index 1c804b0..1432c2b 100644
81390 --- a/include/linux/fsnotify.h
81391 +++ b/include/linux/fsnotify.h
81392 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81393 struct inode *inode = file_inode(file);
81394 __u32 mask = FS_ACCESS;
81395
81396 + if (is_sidechannel_device(inode))
81397 + return;
81398 +
81399 if (S_ISDIR(inode->i_mode))
81400 mask |= FS_ISDIR;
81401
81402 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81403 struct inode *inode = file_inode(file);
81404 __u32 mask = FS_MODIFY;
81405
81406 + if (is_sidechannel_device(inode))
81407 + return;
81408 +
81409 if (S_ISDIR(inode->i_mode))
81410 mask |= FS_ISDIR;
81411
81412 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81413 */
81414 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81415 {
81416 - return kstrdup(name, GFP_KERNEL);
81417 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81418 }
81419
81420 /*
81421 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81422 index ec274e0..e678159 100644
81423 --- a/include/linux/genhd.h
81424 +++ b/include/linux/genhd.h
81425 @@ -194,7 +194,7 @@ struct gendisk {
81426 struct kobject *slave_dir;
81427
81428 struct timer_rand_state *random;
81429 - atomic_t sync_io; /* RAID */
81430 + atomic_unchecked_t sync_io; /* RAID */
81431 struct disk_events *ev;
81432 #ifdef CONFIG_BLK_DEV_INTEGRITY
81433 struct blk_integrity *integrity;
81434 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81435 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81436
81437 /* drivers/char/random.c */
81438 -extern void add_disk_randomness(struct gendisk *disk);
81439 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81440 extern void rand_initialize_disk(struct gendisk *disk);
81441
81442 static inline sector_t get_start_sect(struct block_device *bdev)
81443 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81444 index 667c311..abac2a7 100644
81445 --- a/include/linux/genl_magic_func.h
81446 +++ b/include/linux/genl_magic_func.h
81447 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81448 },
81449
81450 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81451 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81452 +static struct genl_ops ZZZ_genl_ops[] = {
81453 #include GENL_MAGIC_INCLUDE_FILE
81454 };
81455
81456 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81457 index 41b30fd..a3718cf 100644
81458 --- a/include/linux/gfp.h
81459 +++ b/include/linux/gfp.h
81460 @@ -34,6 +34,13 @@ struct vm_area_struct;
81461 #define ___GFP_NO_KSWAPD 0x400000u
81462 #define ___GFP_OTHER_NODE 0x800000u
81463 #define ___GFP_WRITE 0x1000000u
81464 +
81465 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81466 +#define ___GFP_USERCOPY 0x2000000u
81467 +#else
81468 +#define ___GFP_USERCOPY 0
81469 +#endif
81470 +
81471 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81472
81473 /*
81474 @@ -90,6 +97,7 @@ struct vm_area_struct;
81475 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81476 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81477 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81478 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81479
81480 /*
81481 * This may seem redundant, but it's a way of annotating false positives vs.
81482 @@ -97,7 +105,7 @@ struct vm_area_struct;
81483 */
81484 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81485
81486 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81487 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81488 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81489
81490 /* This equals 0, but use constants in case they ever change */
81491 @@ -155,6 +163,8 @@ struct vm_area_struct;
81492 /* 4GB DMA on some platforms */
81493 #define GFP_DMA32 __GFP_DMA32
81494
81495 +#define GFP_USERCOPY __GFP_USERCOPY
81496 +
81497 /* Convert GFP flags to their corresponding migrate type */
81498 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81499 {
81500 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81501 new file mode 100644
81502 index 0000000..91858e4
81503 --- /dev/null
81504 +++ b/include/linux/gracl.h
81505 @@ -0,0 +1,342 @@
81506 +#ifndef GR_ACL_H
81507 +#define GR_ACL_H
81508 +
81509 +#include <linux/grdefs.h>
81510 +#include <linux/resource.h>
81511 +#include <linux/capability.h>
81512 +#include <linux/dcache.h>
81513 +#include <asm/resource.h>
81514 +
81515 +/* Major status information */
81516 +
81517 +#define GR_VERSION "grsecurity 3.1"
81518 +#define GRSECURITY_VERSION 0x3100
81519 +
81520 +enum {
81521 + GR_SHUTDOWN = 0,
81522 + GR_ENABLE = 1,
81523 + GR_SPROLE = 2,
81524 + GR_OLDRELOAD = 3,
81525 + GR_SEGVMOD = 4,
81526 + GR_STATUS = 5,
81527 + GR_UNSPROLE = 6,
81528 + GR_PASSSET = 7,
81529 + GR_SPROLEPAM = 8,
81530 + GR_RELOAD = 9,
81531 +};
81532 +
81533 +/* Password setup definitions
81534 + * kernel/grhash.c */
81535 +enum {
81536 + GR_PW_LEN = 128,
81537 + GR_SALT_LEN = 16,
81538 + GR_SHA_LEN = 32,
81539 +};
81540 +
81541 +enum {
81542 + GR_SPROLE_LEN = 64,
81543 +};
81544 +
81545 +enum {
81546 + GR_NO_GLOB = 0,
81547 + GR_REG_GLOB,
81548 + GR_CREATE_GLOB
81549 +};
81550 +
81551 +#define GR_NLIMITS 32
81552 +
81553 +/* Begin Data Structures */
81554 +
81555 +struct sprole_pw {
81556 + unsigned char *rolename;
81557 + unsigned char salt[GR_SALT_LEN];
81558 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81559 +};
81560 +
81561 +struct name_entry {
81562 + __u32 key;
81563 + u64 inode;
81564 + dev_t device;
81565 + char *name;
81566 + __u16 len;
81567 + __u8 deleted;
81568 + struct name_entry *prev;
81569 + struct name_entry *next;
81570 +};
81571 +
81572 +struct inodev_entry {
81573 + struct name_entry *nentry;
81574 + struct inodev_entry *prev;
81575 + struct inodev_entry *next;
81576 +};
81577 +
81578 +struct acl_role_db {
81579 + struct acl_role_label **r_hash;
81580 + __u32 r_size;
81581 +};
81582 +
81583 +struct inodev_db {
81584 + struct inodev_entry **i_hash;
81585 + __u32 i_size;
81586 +};
81587 +
81588 +struct name_db {
81589 + struct name_entry **n_hash;
81590 + __u32 n_size;
81591 +};
81592 +
81593 +struct crash_uid {
81594 + uid_t uid;
81595 + unsigned long expires;
81596 +};
81597 +
81598 +struct gr_hash_struct {
81599 + void **table;
81600 + void **nametable;
81601 + void *first;
81602 + __u32 table_size;
81603 + __u32 used_size;
81604 + int type;
81605 +};
81606 +
81607 +/* Userspace Grsecurity ACL data structures */
81608 +
81609 +struct acl_subject_label {
81610 + char *filename;
81611 + u64 inode;
81612 + dev_t device;
81613 + __u32 mode;
81614 + kernel_cap_t cap_mask;
81615 + kernel_cap_t cap_lower;
81616 + kernel_cap_t cap_invert_audit;
81617 +
81618 + struct rlimit res[GR_NLIMITS];
81619 + __u32 resmask;
81620 +
81621 + __u8 user_trans_type;
81622 + __u8 group_trans_type;
81623 + uid_t *user_transitions;
81624 + gid_t *group_transitions;
81625 + __u16 user_trans_num;
81626 + __u16 group_trans_num;
81627 +
81628 + __u32 sock_families[2];
81629 + __u32 ip_proto[8];
81630 + __u32 ip_type;
81631 + struct acl_ip_label **ips;
81632 + __u32 ip_num;
81633 + __u32 inaddr_any_override;
81634 +
81635 + __u32 crashes;
81636 + unsigned long expires;
81637 +
81638 + struct acl_subject_label *parent_subject;
81639 + struct gr_hash_struct *hash;
81640 + struct acl_subject_label *prev;
81641 + struct acl_subject_label *next;
81642 +
81643 + struct acl_object_label **obj_hash;
81644 + __u32 obj_hash_size;
81645 + __u16 pax_flags;
81646 +};
81647 +
81648 +struct role_allowed_ip {
81649 + __u32 addr;
81650 + __u32 netmask;
81651 +
81652 + struct role_allowed_ip *prev;
81653 + struct role_allowed_ip *next;
81654 +};
81655 +
81656 +struct role_transition {
81657 + char *rolename;
81658 +
81659 + struct role_transition *prev;
81660 + struct role_transition *next;
81661 +};
81662 +
81663 +struct acl_role_label {
81664 + char *rolename;
81665 + uid_t uidgid;
81666 + __u16 roletype;
81667 +
81668 + __u16 auth_attempts;
81669 + unsigned long expires;
81670 +
81671 + struct acl_subject_label *root_label;
81672 + struct gr_hash_struct *hash;
81673 +
81674 + struct acl_role_label *prev;
81675 + struct acl_role_label *next;
81676 +
81677 + struct role_transition *transitions;
81678 + struct role_allowed_ip *allowed_ips;
81679 + uid_t *domain_children;
81680 + __u16 domain_child_num;
81681 +
81682 + umode_t umask;
81683 +
81684 + struct acl_subject_label **subj_hash;
81685 + __u32 subj_hash_size;
81686 +};
81687 +
81688 +struct user_acl_role_db {
81689 + struct acl_role_label **r_table;
81690 + __u32 num_pointers; /* Number of allocations to track */
81691 + __u32 num_roles; /* Number of roles */
81692 + __u32 num_domain_children; /* Number of domain children */
81693 + __u32 num_subjects; /* Number of subjects */
81694 + __u32 num_objects; /* Number of objects */
81695 +};
81696 +
81697 +struct acl_object_label {
81698 + char *filename;
81699 + u64 inode;
81700 + dev_t device;
81701 + __u32 mode;
81702 +
81703 + struct acl_subject_label *nested;
81704 + struct acl_object_label *globbed;
81705 +
81706 + /* next two structures not used */
81707 +
81708 + struct acl_object_label *prev;
81709 + struct acl_object_label *next;
81710 +};
81711 +
81712 +struct acl_ip_label {
81713 + char *iface;
81714 + __u32 addr;
81715 + __u32 netmask;
81716 + __u16 low, high;
81717 + __u8 mode;
81718 + __u32 type;
81719 + __u32 proto[8];
81720 +
81721 + /* next two structures not used */
81722 +
81723 + struct acl_ip_label *prev;
81724 + struct acl_ip_label *next;
81725 +};
81726 +
81727 +struct gr_arg {
81728 + struct user_acl_role_db role_db;
81729 + unsigned char pw[GR_PW_LEN];
81730 + unsigned char salt[GR_SALT_LEN];
81731 + unsigned char sum[GR_SHA_LEN];
81732 + unsigned char sp_role[GR_SPROLE_LEN];
81733 + struct sprole_pw *sprole_pws;
81734 + dev_t segv_device;
81735 + u64 segv_inode;
81736 + uid_t segv_uid;
81737 + __u16 num_sprole_pws;
81738 + __u16 mode;
81739 +};
81740 +
81741 +struct gr_arg_wrapper {
81742 + struct gr_arg *arg;
81743 + __u32 version;
81744 + __u32 size;
81745 +};
81746 +
81747 +struct subject_map {
81748 + struct acl_subject_label *user;
81749 + struct acl_subject_label *kernel;
81750 + struct subject_map *prev;
81751 + struct subject_map *next;
81752 +};
81753 +
81754 +struct acl_subj_map_db {
81755 + struct subject_map **s_hash;
81756 + __u32 s_size;
81757 +};
81758 +
81759 +struct gr_policy_state {
81760 + struct sprole_pw **acl_special_roles;
81761 + __u16 num_sprole_pws;
81762 + struct acl_role_label *kernel_role;
81763 + struct acl_role_label *role_list;
81764 + struct acl_role_label *default_role;
81765 + struct acl_role_db acl_role_set;
81766 + struct acl_subj_map_db subj_map_set;
81767 + struct name_db name_set;
81768 + struct inodev_db inodev_set;
81769 +};
81770 +
81771 +struct gr_alloc_state {
81772 + unsigned long alloc_stack_next;
81773 + unsigned long alloc_stack_size;
81774 + void **alloc_stack;
81775 +};
81776 +
81777 +struct gr_reload_state {
81778 + struct gr_policy_state oldpolicy;
81779 + struct gr_alloc_state oldalloc;
81780 + struct gr_policy_state newpolicy;
81781 + struct gr_alloc_state newalloc;
81782 + struct gr_policy_state *oldpolicy_ptr;
81783 + struct gr_alloc_state *oldalloc_ptr;
81784 + unsigned char oldmode;
81785 +};
81786 +
81787 +/* End Data Structures Section */
81788 +
81789 +/* Hash functions generated by empirical testing by Brad Spengler
81790 + Makes good use of the low bits of the inode. Generally 0-1 times
81791 + in loop for successful match. 0-3 for unsuccessful match.
81792 + Shift/add algorithm with modulus of table size and an XOR*/
81793 +
81794 +static __inline__ unsigned int
81795 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81796 +{
81797 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81798 +}
81799 +
81800 + static __inline__ unsigned int
81801 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81802 +{
81803 + return ((const unsigned long)userp % sz);
81804 +}
81805 +
81806 +static __inline__ unsigned int
81807 +gr_fhash(const u64 ino, const dev_t dev, const unsigned int sz)
81808 +{
81809 + unsigned int rem;
81810 + div_u64_rem((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9)), sz, &rem);
81811 + return rem;
81812 +}
81813 +
81814 +static __inline__ unsigned int
81815 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81816 +{
81817 + return full_name_hash((const unsigned char *)name, len) % sz;
81818 +}
81819 +
81820 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81821 + subj = NULL; \
81822 + iter = 0; \
81823 + while (iter < role->subj_hash_size) { \
81824 + if (subj == NULL) \
81825 + subj = role->subj_hash[iter]; \
81826 + if (subj == NULL) { \
81827 + iter++; \
81828 + continue; \
81829 + }
81830 +
81831 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81832 + subj = subj->next; \
81833 + if (subj == NULL) \
81834 + iter++; \
81835 + }
81836 +
81837 +
81838 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81839 + subj = role->hash->first; \
81840 + while (subj != NULL) {
81841 +
81842 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81843 + subj = subj->next; \
81844 + }
81845 +
81846 +#endif
81847 +
81848 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81849 new file mode 100644
81850 index 0000000..af64092
81851 --- /dev/null
81852 +++ b/include/linux/gracl_compat.h
81853 @@ -0,0 +1,156 @@
81854 +#ifndef GR_ACL_COMPAT_H
81855 +#define GR_ACL_COMPAT_H
81856 +
81857 +#include <linux/resource.h>
81858 +#include <asm/resource.h>
81859 +
81860 +struct sprole_pw_compat {
81861 + compat_uptr_t rolename;
81862 + unsigned char salt[GR_SALT_LEN];
81863 + unsigned char sum[GR_SHA_LEN];
81864 +};
81865 +
81866 +struct gr_hash_struct_compat {
81867 + compat_uptr_t table;
81868 + compat_uptr_t nametable;
81869 + compat_uptr_t first;
81870 + __u32 table_size;
81871 + __u32 used_size;
81872 + int type;
81873 +};
81874 +
81875 +struct acl_subject_label_compat {
81876 + compat_uptr_t filename;
81877 + compat_u64 inode;
81878 + __u32 device;
81879 + __u32 mode;
81880 + kernel_cap_t cap_mask;
81881 + kernel_cap_t cap_lower;
81882 + kernel_cap_t cap_invert_audit;
81883 +
81884 + struct compat_rlimit res[GR_NLIMITS];
81885 + __u32 resmask;
81886 +
81887 + __u8 user_trans_type;
81888 + __u8 group_trans_type;
81889 + compat_uptr_t user_transitions;
81890 + compat_uptr_t group_transitions;
81891 + __u16 user_trans_num;
81892 + __u16 group_trans_num;
81893 +
81894 + __u32 sock_families[2];
81895 + __u32 ip_proto[8];
81896 + __u32 ip_type;
81897 + compat_uptr_t ips;
81898 + __u32 ip_num;
81899 + __u32 inaddr_any_override;
81900 +
81901 + __u32 crashes;
81902 + compat_ulong_t expires;
81903 +
81904 + compat_uptr_t parent_subject;
81905 + compat_uptr_t hash;
81906 + compat_uptr_t prev;
81907 + compat_uptr_t next;
81908 +
81909 + compat_uptr_t obj_hash;
81910 + __u32 obj_hash_size;
81911 + __u16 pax_flags;
81912 +};
81913 +
81914 +struct role_allowed_ip_compat {
81915 + __u32 addr;
81916 + __u32 netmask;
81917 +
81918 + compat_uptr_t prev;
81919 + compat_uptr_t next;
81920 +};
81921 +
81922 +struct role_transition_compat {
81923 + compat_uptr_t rolename;
81924 +
81925 + compat_uptr_t prev;
81926 + compat_uptr_t next;
81927 +};
81928 +
81929 +struct acl_role_label_compat {
81930 + compat_uptr_t rolename;
81931 + uid_t uidgid;
81932 + __u16 roletype;
81933 +
81934 + __u16 auth_attempts;
81935 + compat_ulong_t expires;
81936 +
81937 + compat_uptr_t root_label;
81938 + compat_uptr_t hash;
81939 +
81940 + compat_uptr_t prev;
81941 + compat_uptr_t next;
81942 +
81943 + compat_uptr_t transitions;
81944 + compat_uptr_t allowed_ips;
81945 + compat_uptr_t domain_children;
81946 + __u16 domain_child_num;
81947 +
81948 + umode_t umask;
81949 +
81950 + compat_uptr_t subj_hash;
81951 + __u32 subj_hash_size;
81952 +};
81953 +
81954 +struct user_acl_role_db_compat {
81955 + compat_uptr_t r_table;
81956 + __u32 num_pointers;
81957 + __u32 num_roles;
81958 + __u32 num_domain_children;
81959 + __u32 num_subjects;
81960 + __u32 num_objects;
81961 +};
81962 +
81963 +struct acl_object_label_compat {
81964 + compat_uptr_t filename;
81965 + compat_u64 inode;
81966 + __u32 device;
81967 + __u32 mode;
81968 +
81969 + compat_uptr_t nested;
81970 + compat_uptr_t globbed;
81971 +
81972 + compat_uptr_t prev;
81973 + compat_uptr_t next;
81974 +};
81975 +
81976 +struct acl_ip_label_compat {
81977 + compat_uptr_t iface;
81978 + __u32 addr;
81979 + __u32 netmask;
81980 + __u16 low, high;
81981 + __u8 mode;
81982 + __u32 type;
81983 + __u32 proto[8];
81984 +
81985 + compat_uptr_t prev;
81986 + compat_uptr_t next;
81987 +};
81988 +
81989 +struct gr_arg_compat {
81990 + struct user_acl_role_db_compat role_db;
81991 + unsigned char pw[GR_PW_LEN];
81992 + unsigned char salt[GR_SALT_LEN];
81993 + unsigned char sum[GR_SHA_LEN];
81994 + unsigned char sp_role[GR_SPROLE_LEN];
81995 + compat_uptr_t sprole_pws;
81996 + __u32 segv_device;
81997 + compat_u64 segv_inode;
81998 + uid_t segv_uid;
81999 + __u16 num_sprole_pws;
82000 + __u16 mode;
82001 +};
82002 +
82003 +struct gr_arg_wrapper_compat {
82004 + compat_uptr_t arg;
82005 + __u32 version;
82006 + __u32 size;
82007 +};
82008 +
82009 +#endif
82010 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82011 new file mode 100644
82012 index 0000000..323ecf2
82013 --- /dev/null
82014 +++ b/include/linux/gralloc.h
82015 @@ -0,0 +1,9 @@
82016 +#ifndef __GRALLOC_H
82017 +#define __GRALLOC_H
82018 +
82019 +void acl_free_all(void);
82020 +int acl_alloc_stack_init(unsigned long size);
82021 +void *acl_alloc(unsigned long len);
82022 +void *acl_alloc_num(unsigned long num, unsigned long len);
82023 +
82024 +#endif
82025 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82026 new file mode 100644
82027 index 0000000..be66033
82028 --- /dev/null
82029 +++ b/include/linux/grdefs.h
82030 @@ -0,0 +1,140 @@
82031 +#ifndef GRDEFS_H
82032 +#define GRDEFS_H
82033 +
82034 +/* Begin grsecurity status declarations */
82035 +
82036 +enum {
82037 + GR_READY = 0x01,
82038 + GR_STATUS_INIT = 0x00 // disabled state
82039 +};
82040 +
82041 +/* Begin ACL declarations */
82042 +
82043 +/* Role flags */
82044 +
82045 +enum {
82046 + GR_ROLE_USER = 0x0001,
82047 + GR_ROLE_GROUP = 0x0002,
82048 + GR_ROLE_DEFAULT = 0x0004,
82049 + GR_ROLE_SPECIAL = 0x0008,
82050 + GR_ROLE_AUTH = 0x0010,
82051 + GR_ROLE_NOPW = 0x0020,
82052 + GR_ROLE_GOD = 0x0040,
82053 + GR_ROLE_LEARN = 0x0080,
82054 + GR_ROLE_TPE = 0x0100,
82055 + GR_ROLE_DOMAIN = 0x0200,
82056 + GR_ROLE_PAM = 0x0400,
82057 + GR_ROLE_PERSIST = 0x0800
82058 +};
82059 +
82060 +/* ACL Subject and Object mode flags */
82061 +enum {
82062 + GR_DELETED = 0x80000000
82063 +};
82064 +
82065 +/* ACL Object-only mode flags */
82066 +enum {
82067 + GR_READ = 0x00000001,
82068 + GR_APPEND = 0x00000002,
82069 + GR_WRITE = 0x00000004,
82070 + GR_EXEC = 0x00000008,
82071 + GR_FIND = 0x00000010,
82072 + GR_INHERIT = 0x00000020,
82073 + GR_SETID = 0x00000040,
82074 + GR_CREATE = 0x00000080,
82075 + GR_DELETE = 0x00000100,
82076 + GR_LINK = 0x00000200,
82077 + GR_AUDIT_READ = 0x00000400,
82078 + GR_AUDIT_APPEND = 0x00000800,
82079 + GR_AUDIT_WRITE = 0x00001000,
82080 + GR_AUDIT_EXEC = 0x00002000,
82081 + GR_AUDIT_FIND = 0x00004000,
82082 + GR_AUDIT_INHERIT= 0x00008000,
82083 + GR_AUDIT_SETID = 0x00010000,
82084 + GR_AUDIT_CREATE = 0x00020000,
82085 + GR_AUDIT_DELETE = 0x00040000,
82086 + GR_AUDIT_LINK = 0x00080000,
82087 + GR_PTRACERD = 0x00100000,
82088 + GR_NOPTRACE = 0x00200000,
82089 + GR_SUPPRESS = 0x00400000,
82090 + GR_NOLEARN = 0x00800000,
82091 + GR_INIT_TRANSFER= 0x01000000
82092 +};
82093 +
82094 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82095 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82096 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82097 +
82098 +/* ACL subject-only mode flags */
82099 +enum {
82100 + GR_KILL = 0x00000001,
82101 + GR_VIEW = 0x00000002,
82102 + GR_PROTECTED = 0x00000004,
82103 + GR_LEARN = 0x00000008,
82104 + GR_OVERRIDE = 0x00000010,
82105 + /* just a placeholder, this mode is only used in userspace */
82106 + GR_DUMMY = 0x00000020,
82107 + GR_PROTSHM = 0x00000040,
82108 + GR_KILLPROC = 0x00000080,
82109 + GR_KILLIPPROC = 0x00000100,
82110 + /* just a placeholder, this mode is only used in userspace */
82111 + GR_NOTROJAN = 0x00000200,
82112 + GR_PROTPROCFD = 0x00000400,
82113 + GR_PROCACCT = 0x00000800,
82114 + GR_RELAXPTRACE = 0x00001000,
82115 + //GR_NESTED = 0x00002000,
82116 + GR_INHERITLEARN = 0x00004000,
82117 + GR_PROCFIND = 0x00008000,
82118 + GR_POVERRIDE = 0x00010000,
82119 + GR_KERNELAUTH = 0x00020000,
82120 + GR_ATSECURE = 0x00040000,
82121 + GR_SHMEXEC = 0x00080000
82122 +};
82123 +
82124 +enum {
82125 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82126 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82127 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82128 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82129 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82130 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82131 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82132 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82133 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82134 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82135 +};
82136 +
82137 +enum {
82138 + GR_ID_USER = 0x01,
82139 + GR_ID_GROUP = 0x02,
82140 +};
82141 +
82142 +enum {
82143 + GR_ID_ALLOW = 0x01,
82144 + GR_ID_DENY = 0x02,
82145 +};
82146 +
82147 +#define GR_CRASH_RES 31
82148 +#define GR_UIDTABLE_MAX 500
82149 +
82150 +/* begin resource learning section */
82151 +enum {
82152 + GR_RLIM_CPU_BUMP = 60,
82153 + GR_RLIM_FSIZE_BUMP = 50000,
82154 + GR_RLIM_DATA_BUMP = 10000,
82155 + GR_RLIM_STACK_BUMP = 1000,
82156 + GR_RLIM_CORE_BUMP = 10000,
82157 + GR_RLIM_RSS_BUMP = 500000,
82158 + GR_RLIM_NPROC_BUMP = 1,
82159 + GR_RLIM_NOFILE_BUMP = 5,
82160 + GR_RLIM_MEMLOCK_BUMP = 50000,
82161 + GR_RLIM_AS_BUMP = 500000,
82162 + GR_RLIM_LOCKS_BUMP = 2,
82163 + GR_RLIM_SIGPENDING_BUMP = 5,
82164 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82165 + GR_RLIM_NICE_BUMP = 1,
82166 + GR_RLIM_RTPRIO_BUMP = 1,
82167 + GR_RLIM_RTTIME_BUMP = 1000000
82168 +};
82169 +
82170 +#endif
82171 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82172 new file mode 100644
82173 index 0000000..fb1de5d
82174 --- /dev/null
82175 +++ b/include/linux/grinternal.h
82176 @@ -0,0 +1,230 @@
82177 +#ifndef __GRINTERNAL_H
82178 +#define __GRINTERNAL_H
82179 +
82180 +#ifdef CONFIG_GRKERNSEC
82181 +
82182 +#include <linux/fs.h>
82183 +#include <linux/mnt_namespace.h>
82184 +#include <linux/nsproxy.h>
82185 +#include <linux/gracl.h>
82186 +#include <linux/grdefs.h>
82187 +#include <linux/grmsg.h>
82188 +
82189 +void gr_add_learn_entry(const char *fmt, ...)
82190 + __attribute__ ((format (printf, 1, 2)));
82191 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82192 + const struct vfsmount *mnt);
82193 +__u32 gr_check_create(const struct dentry *new_dentry,
82194 + const struct dentry *parent,
82195 + const struct vfsmount *mnt, const __u32 mode);
82196 +int gr_check_protected_task(const struct task_struct *task);
82197 +__u32 to_gr_audit(const __u32 reqmode);
82198 +int gr_set_acls(const int type);
82199 +int gr_acl_is_enabled(void);
82200 +char gr_roletype_to_char(void);
82201 +
82202 +void gr_handle_alertkill(struct task_struct *task);
82203 +char *gr_to_filename(const struct dentry *dentry,
82204 + const struct vfsmount *mnt);
82205 +char *gr_to_filename1(const struct dentry *dentry,
82206 + const struct vfsmount *mnt);
82207 +char *gr_to_filename2(const struct dentry *dentry,
82208 + const struct vfsmount *mnt);
82209 +char *gr_to_filename3(const struct dentry *dentry,
82210 + const struct vfsmount *mnt);
82211 +
82212 +extern int grsec_enable_ptrace_readexec;
82213 +extern int grsec_enable_harden_ptrace;
82214 +extern int grsec_enable_link;
82215 +extern int grsec_enable_fifo;
82216 +extern int grsec_enable_execve;
82217 +extern int grsec_enable_shm;
82218 +extern int grsec_enable_execlog;
82219 +extern int grsec_enable_signal;
82220 +extern int grsec_enable_audit_ptrace;
82221 +extern int grsec_enable_forkfail;
82222 +extern int grsec_enable_time;
82223 +extern int grsec_enable_rofs;
82224 +extern int grsec_deny_new_usb;
82225 +extern int grsec_enable_chroot_shmat;
82226 +extern int grsec_enable_chroot_mount;
82227 +extern int grsec_enable_chroot_double;
82228 +extern int grsec_enable_chroot_pivot;
82229 +extern int grsec_enable_chroot_chdir;
82230 +extern int grsec_enable_chroot_chmod;
82231 +extern int grsec_enable_chroot_mknod;
82232 +extern int grsec_enable_chroot_fchdir;
82233 +extern int grsec_enable_chroot_nice;
82234 +extern int grsec_enable_chroot_execlog;
82235 +extern int grsec_enable_chroot_caps;
82236 +extern int grsec_enable_chroot_rename;
82237 +extern int grsec_enable_chroot_sysctl;
82238 +extern int grsec_enable_chroot_unix;
82239 +extern int grsec_enable_symlinkown;
82240 +extern kgid_t grsec_symlinkown_gid;
82241 +extern int grsec_enable_tpe;
82242 +extern kgid_t grsec_tpe_gid;
82243 +extern int grsec_enable_tpe_all;
82244 +extern int grsec_enable_tpe_invert;
82245 +extern int grsec_enable_socket_all;
82246 +extern kgid_t grsec_socket_all_gid;
82247 +extern int grsec_enable_socket_client;
82248 +extern kgid_t grsec_socket_client_gid;
82249 +extern int grsec_enable_socket_server;
82250 +extern kgid_t grsec_socket_server_gid;
82251 +extern kgid_t grsec_audit_gid;
82252 +extern int grsec_enable_group;
82253 +extern int grsec_enable_log_rwxmaps;
82254 +extern int grsec_enable_mount;
82255 +extern int grsec_enable_chdir;
82256 +extern int grsec_resource_logging;
82257 +extern int grsec_enable_blackhole;
82258 +extern int grsec_lastack_retries;
82259 +extern int grsec_enable_brute;
82260 +extern int grsec_enable_harden_ipc;
82261 +extern int grsec_lock;
82262 +
82263 +extern spinlock_t grsec_alert_lock;
82264 +extern unsigned long grsec_alert_wtime;
82265 +extern unsigned long grsec_alert_fyet;
82266 +
82267 +extern spinlock_t grsec_audit_lock;
82268 +
82269 +extern rwlock_t grsec_exec_file_lock;
82270 +
82271 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82272 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82273 + (tsk)->exec_file->f_path.mnt) : "/")
82274 +
82275 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82276 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82277 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82278 +
82279 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82280 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82281 + (tsk)->exec_file->f_path.mnt) : "/")
82282 +
82283 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82284 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82285 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82286 +
82287 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82288 +
82289 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82290 +
82291 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82292 +{
82293 + if (file1 && file2) {
82294 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82295 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82296 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82297 + return true;
82298 + }
82299 +
82300 + return false;
82301 +}
82302 +
82303 +#define GR_CHROOT_CAPS {{ \
82304 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82305 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82306 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82307 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82308 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82309 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82310 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82311 +
82312 +#define security_learn(normal_msg,args...) \
82313 +({ \
82314 + read_lock(&grsec_exec_file_lock); \
82315 + gr_add_learn_entry(normal_msg "\n", ## args); \
82316 + read_unlock(&grsec_exec_file_lock); \
82317 +})
82318 +
82319 +enum {
82320 + GR_DO_AUDIT,
82321 + GR_DONT_AUDIT,
82322 + /* used for non-audit messages that we shouldn't kill the task on */
82323 + GR_DONT_AUDIT_GOOD
82324 +};
82325 +
82326 +enum {
82327 + GR_TTYSNIFF,
82328 + GR_RBAC,
82329 + GR_RBAC_STR,
82330 + GR_STR_RBAC,
82331 + GR_RBAC_MODE2,
82332 + GR_RBAC_MODE3,
82333 + GR_FILENAME,
82334 + GR_SYSCTL_HIDDEN,
82335 + GR_NOARGS,
82336 + GR_ONE_INT,
82337 + GR_ONE_INT_TWO_STR,
82338 + GR_ONE_STR,
82339 + GR_STR_INT,
82340 + GR_TWO_STR_INT,
82341 + GR_TWO_INT,
82342 + GR_TWO_U64,
82343 + GR_THREE_INT,
82344 + GR_FIVE_INT_TWO_STR,
82345 + GR_TWO_STR,
82346 + GR_THREE_STR,
82347 + GR_FOUR_STR,
82348 + GR_STR_FILENAME,
82349 + GR_FILENAME_STR,
82350 + GR_FILENAME_TWO_INT,
82351 + GR_FILENAME_TWO_INT_STR,
82352 + GR_TEXTREL,
82353 + GR_PTRACE,
82354 + GR_RESOURCE,
82355 + GR_CAP,
82356 + GR_SIG,
82357 + GR_SIG2,
82358 + GR_CRASH1,
82359 + GR_CRASH2,
82360 + GR_PSACCT,
82361 + GR_RWXMAP,
82362 + GR_RWXMAPVMA
82363 +};
82364 +
82365 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82366 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82367 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82368 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82369 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82370 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82371 +#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)
82372 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82373 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82374 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82375 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82376 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82377 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82378 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82379 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82380 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82381 +#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)
82382 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82383 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82384 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82385 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82386 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82387 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82388 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82389 +#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)
82390 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82391 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82392 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82393 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82394 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82395 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82396 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82397 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82398 +#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)
82399 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82400 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82401 +
82402 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82403 +
82404 +#endif
82405 +
82406 +#endif
82407 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82408 new file mode 100644
82409 index 0000000..26ef560
82410 --- /dev/null
82411 +++ b/include/linux/grmsg.h
82412 @@ -0,0 +1,118 @@
82413 +#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"
82414 +#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"
82415 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82416 +#define GR_STOPMOD_MSG "denied modification of module state by "
82417 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82418 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82419 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82420 +#define GR_IOPL_MSG "denied use of iopl() by "
82421 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82422 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82423 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82424 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82425 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82426 +#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"
82427 +#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"
82428 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82429 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82430 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82431 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82432 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82433 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82434 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82435 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82436 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82437 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82438 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82439 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82440 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82441 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82442 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82443 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82444 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82445 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82446 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82447 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82448 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82449 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82450 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82451 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82452 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82453 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82454 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82455 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82456 +#define GR_CHROOT_RENAME_MSG "denied bad rename of %.950s out of a chroot by "
82457 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82458 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82459 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82460 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82461 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82462 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82463 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82464 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82465 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82466 +#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"
82467 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82468 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82469 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82470 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82471 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82472 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82473 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82474 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82475 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82476 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82477 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82478 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82479 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82480 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82481 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82482 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82483 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82484 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82485 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82486 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82487 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82488 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82489 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82490 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82491 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82492 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82493 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82494 +#define GR_TIME_MSG "time set by "
82495 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82496 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82497 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82498 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82499 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82500 +#define GR_BIND_MSG "denied bind() by "
82501 +#define GR_CONNECT_MSG "denied connect() by "
82502 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82503 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82504 +#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"
82505 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82506 +#define GR_CAP_ACL_MSG "use of %s denied for "
82507 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82508 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82509 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82510 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82511 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82512 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82513 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82514 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82515 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82516 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82517 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82518 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82519 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82520 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82521 +#define GR_VM86_MSG "denied use of vm86 by "
82522 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82523 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82524 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82525 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82526 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82527 +#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 "
82528 +#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 "
82529 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82530 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82531 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82532 new file mode 100644
82533 index 0000000..63c1850
82534 --- /dev/null
82535 +++ b/include/linux/grsecurity.h
82536 @@ -0,0 +1,250 @@
82537 +#ifndef GR_SECURITY_H
82538 +#define GR_SECURITY_H
82539 +#include <linux/fs.h>
82540 +#include <linux/fs_struct.h>
82541 +#include <linux/binfmts.h>
82542 +#include <linux/gracl.h>
82543 +
82544 +/* notify of brain-dead configs */
82545 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82546 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82547 +#endif
82548 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82549 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82550 +#endif
82551 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82552 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82553 +#endif
82554 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82555 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82556 +#endif
82557 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82558 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82559 +#endif
82560 +
82561 +int gr_handle_new_usb(void);
82562 +
82563 +void gr_handle_brute_attach(int dumpable);
82564 +void gr_handle_brute_check(void);
82565 +void gr_handle_kernel_exploit(void);
82566 +
82567 +char gr_roletype_to_char(void);
82568 +
82569 +int gr_proc_is_restricted(void);
82570 +
82571 +int gr_acl_enable_at_secure(void);
82572 +
82573 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82574 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82575 +
82576 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82577 +
82578 +void gr_del_task_from_ip_table(struct task_struct *p);
82579 +
82580 +int gr_pid_is_chrooted(struct task_struct *p);
82581 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82582 +int gr_handle_chroot_nice(void);
82583 +int gr_handle_chroot_sysctl(const int op);
82584 +int gr_handle_chroot_setpriority(struct task_struct *p,
82585 + const int niceval);
82586 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82587 +int gr_chroot_fhandle(void);
82588 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82589 + const struct vfsmount *mnt);
82590 +void gr_handle_chroot_chdir(const struct path *path);
82591 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82592 + const struct vfsmount *mnt, const int mode);
82593 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82594 + const struct vfsmount *mnt, const int mode);
82595 +int gr_handle_chroot_mount(const struct dentry *dentry,
82596 + const struct vfsmount *mnt,
82597 + const char *dev_name);
82598 +int gr_handle_chroot_pivot(void);
82599 +int gr_handle_chroot_unix(const pid_t pid);
82600 +
82601 +int gr_handle_rawio(const struct inode *inode);
82602 +
82603 +void gr_handle_ioperm(void);
82604 +void gr_handle_iopl(void);
82605 +void gr_handle_msr_write(void);
82606 +
82607 +umode_t gr_acl_umask(void);
82608 +
82609 +int gr_tpe_allow(const struct file *file);
82610 +
82611 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82612 +void gr_clear_chroot_entries(struct task_struct *task);
82613 +
82614 +void gr_log_forkfail(const int retval);
82615 +void gr_log_timechange(void);
82616 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82617 +void gr_log_chdir(const struct dentry *dentry,
82618 + const struct vfsmount *mnt);
82619 +void gr_log_chroot_exec(const struct dentry *dentry,
82620 + const struct vfsmount *mnt);
82621 +void gr_log_remount(const char *devname, const int retval);
82622 +void gr_log_unmount(const char *devname, const int retval);
82623 +void gr_log_mount(const char *from, struct path *to, const int retval);
82624 +void gr_log_textrel(struct vm_area_struct *vma);
82625 +void gr_log_ptgnustack(struct file *file);
82626 +void gr_log_rwxmmap(struct file *file);
82627 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82628 +
82629 +int gr_handle_follow_link(const struct inode *parent,
82630 + const struct inode *inode,
82631 + const struct dentry *dentry,
82632 + const struct vfsmount *mnt);
82633 +int gr_handle_fifo(const struct dentry *dentry,
82634 + const struct vfsmount *mnt,
82635 + const struct dentry *dir, const int flag,
82636 + const int acc_mode);
82637 +int gr_handle_hardlink(const struct dentry *dentry,
82638 + const struct vfsmount *mnt,
82639 + struct inode *inode,
82640 + const int mode, const struct filename *to);
82641 +
82642 +int gr_is_capable(const int cap);
82643 +int gr_is_capable_nolog(const int cap);
82644 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82645 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82646 +
82647 +void gr_copy_label(struct task_struct *tsk);
82648 +void gr_handle_crash(struct task_struct *task, const int sig);
82649 +int gr_handle_signal(const struct task_struct *p, const int sig);
82650 +int gr_check_crash_uid(const kuid_t uid);
82651 +int gr_check_protected_task(const struct task_struct *task);
82652 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82653 +int gr_acl_handle_mmap(const struct file *file,
82654 + const unsigned long prot);
82655 +int gr_acl_handle_mprotect(const struct file *file,
82656 + const unsigned long prot);
82657 +int gr_check_hidden_task(const struct task_struct *tsk);
82658 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82659 + const struct vfsmount *mnt);
82660 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82661 + const struct vfsmount *mnt);
82662 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82663 + const struct vfsmount *mnt, const int fmode);
82664 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82665 + const struct vfsmount *mnt, umode_t *mode);
82666 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82667 + const struct vfsmount *mnt);
82668 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82669 + const struct vfsmount *mnt);
82670 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82671 + const struct vfsmount *mnt);
82672 +int gr_handle_ptrace(struct task_struct *task, const long request);
82673 +int gr_handle_proc_ptrace(struct task_struct *task);
82674 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82675 + const struct vfsmount *mnt);
82676 +int gr_check_crash_exec(const struct file *filp);
82677 +int gr_acl_is_enabled(void);
82678 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82679 + const kgid_t gid);
82680 +int gr_set_proc_label(const struct dentry *dentry,
82681 + const struct vfsmount *mnt,
82682 + const int unsafe_flags);
82683 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82684 + const struct vfsmount *mnt);
82685 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82686 + const struct vfsmount *mnt, int acc_mode);
82687 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82688 + const struct dentry *p_dentry,
82689 + const struct vfsmount *p_mnt,
82690 + int open_flags, int acc_mode, const int imode);
82691 +void gr_handle_create(const struct dentry *dentry,
82692 + const struct vfsmount *mnt);
82693 +void gr_handle_proc_create(const struct dentry *dentry,
82694 + const struct inode *inode);
82695 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82696 + const struct dentry *parent_dentry,
82697 + const struct vfsmount *parent_mnt,
82698 + const int mode);
82699 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82700 + const struct dentry *parent_dentry,
82701 + const struct vfsmount *parent_mnt);
82702 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82703 + const struct vfsmount *mnt);
82704 +void gr_handle_delete(const u64 ino, const dev_t dev);
82705 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82706 + const struct vfsmount *mnt);
82707 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82708 + const struct dentry *parent_dentry,
82709 + const struct vfsmount *parent_mnt,
82710 + const struct filename *from);
82711 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82712 + const struct dentry *parent_dentry,
82713 + const struct vfsmount *parent_mnt,
82714 + const struct dentry *old_dentry,
82715 + const struct vfsmount *old_mnt, const struct filename *to);
82716 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82717 +int gr_acl_handle_rename(struct dentry *new_dentry,
82718 + struct dentry *parent_dentry,
82719 + const struct vfsmount *parent_mnt,
82720 + struct dentry *old_dentry,
82721 + struct inode *old_parent_inode,
82722 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82723 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82724 + struct dentry *old_dentry,
82725 + struct dentry *new_dentry,
82726 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82727 +__u32 gr_check_link(const struct dentry *new_dentry,
82728 + const struct dentry *parent_dentry,
82729 + const struct vfsmount *parent_mnt,
82730 + const struct dentry *old_dentry,
82731 + const struct vfsmount *old_mnt);
82732 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82733 + const unsigned int namelen, const u64 ino);
82734 +
82735 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82736 + const struct vfsmount *mnt);
82737 +void gr_acl_handle_exit(void);
82738 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82739 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82740 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82741 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82742 +void gr_audit_ptrace(struct task_struct *task);
82743 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82744 +u64 gr_get_ino_from_dentry(struct dentry *dentry);
82745 +void gr_put_exec_file(struct task_struct *task);
82746 +
82747 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82748 +
82749 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82750 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82751 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
82752 + struct dentry *newdentry, struct vfsmount *newmnt);
82753 +
82754 +#ifdef CONFIG_GRKERNSEC_RESLOG
82755 +extern void gr_log_resource(const struct task_struct *task, const int res,
82756 + const unsigned long wanted, const int gt);
82757 +#else
82758 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82759 + const unsigned long wanted, const int gt)
82760 +{
82761 +}
82762 +#endif
82763 +
82764 +#ifdef CONFIG_GRKERNSEC
82765 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82766 +void gr_handle_vm86(void);
82767 +void gr_handle_mem_readwrite(u64 from, u64 to);
82768 +
82769 +void gr_log_badprocpid(const char *entry);
82770 +
82771 +extern int grsec_enable_dmesg;
82772 +extern int grsec_disable_privio;
82773 +
82774 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82775 +extern kgid_t grsec_proc_gid;
82776 +#endif
82777 +
82778 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82779 +extern int grsec_enable_chroot_findtask;
82780 +#endif
82781 +#ifdef CONFIG_GRKERNSEC_SETXID
82782 +extern int grsec_enable_setxid;
82783 +#endif
82784 +#endif
82785 +
82786 +#endif
82787 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82788 new file mode 100644
82789 index 0000000..e7ffaaf
82790 --- /dev/null
82791 +++ b/include/linux/grsock.h
82792 @@ -0,0 +1,19 @@
82793 +#ifndef __GRSOCK_H
82794 +#define __GRSOCK_H
82795 +
82796 +extern void gr_attach_curr_ip(const struct sock *sk);
82797 +extern int gr_handle_sock_all(const int family, const int type,
82798 + const int protocol);
82799 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82800 +extern int gr_handle_sock_server_other(const struct sock *sck);
82801 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82802 +extern int gr_search_connect(struct socket * sock,
82803 + struct sockaddr_in * addr);
82804 +extern int gr_search_bind(struct socket * sock,
82805 + struct sockaddr_in * addr);
82806 +extern int gr_search_listen(struct socket * sock);
82807 +extern int gr_search_accept(struct socket * sock);
82808 +extern int gr_search_socket(const int domain, const int type,
82809 + const int protocol);
82810 +
82811 +#endif
82812 diff --git a/include/linux/hash.h b/include/linux/hash.h
82813 index d0494c3..69b7715 100644
82814 --- a/include/linux/hash.h
82815 +++ b/include/linux/hash.h
82816 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82817 struct fast_hash_ops {
82818 u32 (*hash)(const void *data, u32 len, u32 seed);
82819 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82820 -};
82821 +} __no_const;
82822
82823 /**
82824 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82825 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82826 index 9286a46..373f27f 100644
82827 --- a/include/linux/highmem.h
82828 +++ b/include/linux/highmem.h
82829 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82830 kunmap_atomic(kaddr);
82831 }
82832
82833 +static inline void sanitize_highpage(struct page *page)
82834 +{
82835 + void *kaddr;
82836 + unsigned long flags;
82837 +
82838 + local_irq_save(flags);
82839 + kaddr = kmap_atomic(page);
82840 + clear_page(kaddr);
82841 + kunmap_atomic(kaddr);
82842 + local_irq_restore(flags);
82843 +}
82844 +
82845 static inline void zero_user_segments(struct page *page,
82846 unsigned start1, unsigned end1,
82847 unsigned start2, unsigned end2)
82848 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82849 index 1c7b89a..7dda400 100644
82850 --- a/include/linux/hwmon-sysfs.h
82851 +++ b/include/linux/hwmon-sysfs.h
82852 @@ -25,7 +25,8 @@
82853 struct sensor_device_attribute{
82854 struct device_attribute dev_attr;
82855 int index;
82856 -};
82857 +} __do_const;
82858 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82859 #define to_sensor_dev_attr(_dev_attr) \
82860 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82861
82862 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82863 struct device_attribute dev_attr;
82864 u8 index;
82865 u8 nr;
82866 -};
82867 +} __do_const;
82868 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82869 #define to_sensor_dev_attr_2(_dev_attr) \
82870 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82871
82872 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82873 index b556e0a..c10a515 100644
82874 --- a/include/linux/i2c.h
82875 +++ b/include/linux/i2c.h
82876 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82877 /* To determine what the adapter supports */
82878 u32 (*functionality) (struct i2c_adapter *);
82879 };
82880 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82881
82882 /**
82883 * struct i2c_bus_recovery_info - I2C bus recovery information
82884 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82885 index d23c3c2..eb63c81 100644
82886 --- a/include/linux/i2o.h
82887 +++ b/include/linux/i2o.h
82888 @@ -565,7 +565,7 @@ struct i2o_controller {
82889 struct i2o_device *exec; /* Executive */
82890 #if BITS_PER_LONG == 64
82891 spinlock_t context_list_lock; /* lock for context_list */
82892 - atomic_t context_list_counter; /* needed for unique contexts */
82893 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82894 struct list_head context_list; /* list of context id's
82895 and pointers */
82896 #endif
82897 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82898 index aff7ad8..3942bbd 100644
82899 --- a/include/linux/if_pppox.h
82900 +++ b/include/linux/if_pppox.h
82901 @@ -76,7 +76,7 @@ struct pppox_proto {
82902 int (*ioctl)(struct socket *sock, unsigned int cmd,
82903 unsigned long arg);
82904 struct module *owner;
82905 -};
82906 +} __do_const;
82907
82908 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82909 extern void unregister_pppox_proto(int proto_num);
82910 diff --git a/include/linux/init.h b/include/linux/init.h
82911 index 2df8e8d..3e1280d 100644
82912 --- a/include/linux/init.h
82913 +++ b/include/linux/init.h
82914 @@ -37,9 +37,17 @@
82915 * section.
82916 */
82917
82918 +#define add_init_latent_entropy __latent_entropy
82919 +
82920 +#ifdef CONFIG_MEMORY_HOTPLUG
82921 +#define add_meminit_latent_entropy
82922 +#else
82923 +#define add_meminit_latent_entropy __latent_entropy
82924 +#endif
82925 +
82926 /* These are for everybody (although not all archs will actually
82927 discard it in modules) */
82928 -#define __init __section(.init.text) __cold notrace
82929 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82930 #define __initdata __section(.init.data)
82931 #define __initconst __constsection(.init.rodata)
82932 #define __exitdata __section(.exit.data)
82933 @@ -100,7 +108,7 @@
82934 #define __cpuexitconst
82935
82936 /* Used for MEMORY_HOTPLUG */
82937 -#define __meminit __section(.meminit.text) __cold notrace
82938 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82939 #define __meminitdata __section(.meminit.data)
82940 #define __meminitconst __constsection(.meminit.rodata)
82941 #define __memexit __section(.memexit.text) __exitused __cold notrace
82942 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82943 index 77fc43f..73caf92 100644
82944 --- a/include/linux/init_task.h
82945 +++ b/include/linux/init_task.h
82946 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82947
82948 #define INIT_TASK_COMM "swapper"
82949
82950 +#ifdef CONFIG_X86
82951 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82952 +#else
82953 +#define INIT_TASK_THREAD_INFO
82954 +#endif
82955 +
82956 #ifdef CONFIG_RT_MUTEXES
82957 # define INIT_RT_MUTEXES(tsk) \
82958 .pi_waiters = RB_ROOT, \
82959 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82960 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82961 .comm = INIT_TASK_COMM, \
82962 .thread = INIT_THREAD, \
82963 + INIT_TASK_THREAD_INFO \
82964 .fs = &init_fs, \
82965 .files = &init_files, \
82966 .signal = &init_signals, \
82967 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82968 index 69517a2..6b12d37 100644
82969 --- a/include/linux/interrupt.h
82970 +++ b/include/linux/interrupt.h
82971 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82972
82973 struct softirq_action
82974 {
82975 - void (*action)(struct softirq_action *);
82976 -};
82977 + void (*action)(void);
82978 +} __no_const;
82979
82980 asmlinkage void do_softirq(void);
82981 asmlinkage void __do_softirq(void);
82982 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82983 }
82984 #endif
82985
82986 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82987 +extern void open_softirq(int nr, void (*action)(void));
82988 extern void softirq_init(void);
82989 extern void __raise_softirq_irqoff(unsigned int nr);
82990
82991 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82992 index e6a7c9f..5804745 100644
82993 --- a/include/linux/iommu.h
82994 +++ b/include/linux/iommu.h
82995 @@ -133,7 +133,7 @@ struct iommu_ops {
82996 u32 (*domain_get_windows)(struct iommu_domain *domain);
82997
82998 unsigned long pgsize_bitmap;
82999 -};
83000 +} __do_const;
83001
83002 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83003 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83004 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83005 index 2c525022..345b106 100644
83006 --- a/include/linux/ioport.h
83007 +++ b/include/linux/ioport.h
83008 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83009 int adjust_resource(struct resource *res, resource_size_t start,
83010 resource_size_t size);
83011 resource_size_t resource_alignment(struct resource *res);
83012 -static inline resource_size_t resource_size(const struct resource *res)
83013 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83014 {
83015 return res->end - res->start + 1;
83016 }
83017 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83018 index 35e7eca..6afb7ad 100644
83019 --- a/include/linux/ipc_namespace.h
83020 +++ b/include/linux/ipc_namespace.h
83021 @@ -69,7 +69,7 @@ struct ipc_namespace {
83022 struct user_namespace *user_ns;
83023
83024 unsigned int proc_inum;
83025 -};
83026 +} __randomize_layout;
83027
83028 extern struct ipc_namespace init_ipc_ns;
83029 extern atomic_t nr_ipc_ns;
83030 diff --git a/include/linux/irq.h b/include/linux/irq.h
83031 index 03f48d9..e86af0c 100644
83032 --- a/include/linux/irq.h
83033 +++ b/include/linux/irq.h
83034 @@ -352,7 +352,8 @@ struct irq_chip {
83035 void (*irq_release_resources)(struct irq_data *data);
83036
83037 unsigned long flags;
83038 -};
83039 +} __do_const;
83040 +typedef struct irq_chip __no_const irq_chip_no_const;
83041
83042 /*
83043 * irq_chip specific flags
83044 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83045 index 13eed92..3261c86 100644
83046 --- a/include/linux/irqchip/arm-gic.h
83047 +++ b/include/linux/irqchip/arm-gic.h
83048 @@ -91,9 +91,11 @@
83049
83050 #ifndef __ASSEMBLY__
83051
83052 +#include <linux/irq.h>
83053 +
83054 struct device_node;
83055
83056 -extern struct irq_chip gic_arch_extn;
83057 +extern irq_chip_no_const gic_arch_extn;
83058
83059 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83060 u32 offset, struct device_node *);
83061 diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
83062 index faf433a..7dcb186 100644
83063 --- a/include/linux/irqdesc.h
83064 +++ b/include/linux/irqdesc.h
83065 @@ -61,7 +61,7 @@ struct irq_desc {
83066 unsigned int irq_count; /* For detecting broken IRQs */
83067 unsigned long last_unhandled; /* Aging timer for unhandled count */
83068 unsigned int irqs_unhandled;
83069 - atomic_t threads_handled;
83070 + atomic_unchecked_t threads_handled;
83071 int threads_handled_last;
83072 raw_spinlock_t lock;
83073 struct cpumask *percpu_enabled;
83074 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83075 index c367cbd..c9b79e6 100644
83076 --- a/include/linux/jiffies.h
83077 +++ b/include/linux/jiffies.h
83078 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83079 /*
83080 * Convert various time units to each other:
83081 */
83082 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83083 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83084 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83085 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83086
83087 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83088 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83089 {
83090 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83091 }
83092
83093 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83094 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83095 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83096 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83097 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83098 extern void jiffies_to_timespec(const unsigned long jiffies,
83099 - struct timespec *value);
83100 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83101 + struct timespec *value) __intentional_overflow(-1);
83102 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83103 extern void jiffies_to_timeval(const unsigned long jiffies,
83104 struct timeval *value);
83105
83106 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83107 index 6883e19..e854fcb 100644
83108 --- a/include/linux/kallsyms.h
83109 +++ b/include/linux/kallsyms.h
83110 @@ -15,7 +15,8 @@
83111
83112 struct module;
83113
83114 -#ifdef CONFIG_KALLSYMS
83115 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83116 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83117 /* Lookup the address for a symbol. Returns 0 if not found. */
83118 unsigned long kallsyms_lookup_name(const char *name);
83119
83120 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83121 /* Stupid that this does nothing, but I didn't create this mess. */
83122 #define __print_symbol(fmt, addr)
83123 #endif /*CONFIG_KALLSYMS*/
83124 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83125 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83126 +extern unsigned long kallsyms_lookup_name(const char *name);
83127 +extern void __print_symbol(const char *fmt, unsigned long address);
83128 +extern int sprint_backtrace(char *buffer, unsigned long address);
83129 +extern int sprint_symbol(char *buffer, unsigned long address);
83130 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83131 +const char *kallsyms_lookup(unsigned long addr,
83132 + unsigned long *symbolsize,
83133 + unsigned long *offset,
83134 + char **modname, char *namebuf);
83135 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83136 + unsigned long *symbolsize,
83137 + unsigned long *offset);
83138 +#endif
83139
83140 /* This macro allows us to keep printk typechecking */
83141 static __printf(1, 2)
83142 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83143 index ff9f1d3..6712be5 100644
83144 --- a/include/linux/key-type.h
83145 +++ b/include/linux/key-type.h
83146 @@ -152,7 +152,7 @@ struct key_type {
83147 /* internal fields */
83148 struct list_head link; /* link in types list */
83149 struct lock_class_key lock_class; /* key->sem lock class */
83150 -};
83151 +} __do_const;
83152
83153 extern struct key_type key_type_keyring;
83154
83155 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83156 index e465bb1..19f605fd 100644
83157 --- a/include/linux/kgdb.h
83158 +++ b/include/linux/kgdb.h
83159 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83160 extern int kgdb_io_module_registered;
83161
83162 extern atomic_t kgdb_setting_breakpoint;
83163 -extern atomic_t kgdb_cpu_doing_single_step;
83164 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83165
83166 extern struct task_struct *kgdb_usethread;
83167 extern struct task_struct *kgdb_contthread;
83168 @@ -254,7 +254,7 @@ struct kgdb_arch {
83169 void (*correct_hw_break)(void);
83170
83171 void (*enable_nmi)(bool on);
83172 -};
83173 +} __do_const;
83174
83175 /**
83176 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83177 @@ -279,7 +279,7 @@ struct kgdb_io {
83178 void (*pre_exception) (void);
83179 void (*post_exception) (void);
83180 int is_console;
83181 -};
83182 +} __do_const;
83183
83184 extern struct kgdb_arch arch_kgdb_ops;
83185
83186 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83187 index 0555cc6..40116ce 100644
83188 --- a/include/linux/kmod.h
83189 +++ b/include/linux/kmod.h
83190 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83191 * usually useless though. */
83192 extern __printf(2, 3)
83193 int __request_module(bool wait, const char *name, ...);
83194 +extern __printf(3, 4)
83195 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83196 #define request_module(mod...) __request_module(true, mod)
83197 #define request_module_nowait(mod...) __request_module(false, mod)
83198 #define try_then_request_module(x, mod...) \
83199 @@ -57,6 +59,9 @@ struct subprocess_info {
83200 struct work_struct work;
83201 struct completion *complete;
83202 char *path;
83203 +#ifdef CONFIG_GRKERNSEC
83204 + char *origpath;
83205 +#endif
83206 char **argv;
83207 char **envp;
83208 int wait;
83209 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83210 index 2d61b90..a1d0a13 100644
83211 --- a/include/linux/kobject.h
83212 +++ b/include/linux/kobject.h
83213 @@ -118,7 +118,7 @@ struct kobj_type {
83214 struct attribute **default_attrs;
83215 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83216 const void *(*namespace)(struct kobject *kobj);
83217 -};
83218 +} __do_const;
83219
83220 struct kobj_uevent_env {
83221 char *argv[3];
83222 @@ -142,6 +142,7 @@ struct kobj_attribute {
83223 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83224 const char *buf, size_t count);
83225 };
83226 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83227
83228 extern const struct sysfs_ops kobj_sysfs_ops;
83229
83230 @@ -169,7 +170,7 @@ struct kset {
83231 spinlock_t list_lock;
83232 struct kobject kobj;
83233 const struct kset_uevent_ops *uevent_ops;
83234 -};
83235 +} __randomize_layout;
83236
83237 extern void kset_init(struct kset *kset);
83238 extern int __must_check kset_register(struct kset *kset);
83239 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83240 index df32d25..fb52e27 100644
83241 --- a/include/linux/kobject_ns.h
83242 +++ b/include/linux/kobject_ns.h
83243 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83244 const void *(*netlink_ns)(struct sock *sk);
83245 const void *(*initial_ns)(void);
83246 void (*drop_ns)(void *);
83247 -};
83248 +} __do_const;
83249
83250 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83251 int kobj_ns_type_registered(enum kobj_ns_type type);
83252 diff --git a/include/linux/kref.h b/include/linux/kref.h
83253 index 484604d..0f6c5b6 100644
83254 --- a/include/linux/kref.h
83255 +++ b/include/linux/kref.h
83256 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83257 static inline int kref_sub(struct kref *kref, unsigned int count,
83258 void (*release)(struct kref *kref))
83259 {
83260 - WARN_ON(release == NULL);
83261 + BUG_ON(release == NULL);
83262
83263 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83264 release(kref);
83265 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83266 index a6059bd..8126d5c 100644
83267 --- a/include/linux/kvm_host.h
83268 +++ b/include/linux/kvm_host.h
83269 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
83270 {
83271 }
83272 #endif
83273 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83274 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83275 struct module *module);
83276 void kvm_exit(void);
83277
83278 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83279 struct kvm_guest_debug *dbg);
83280 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83281
83282 -int kvm_arch_init(void *opaque);
83283 +int kvm_arch_init(const void *opaque);
83284 void kvm_arch_exit(void);
83285
83286 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83287 diff --git a/include/linux/libata.h b/include/linux/libata.h
83288 index fe0bf8d..c511ca6 100644
83289 --- a/include/linux/libata.h
83290 +++ b/include/linux/libata.h
83291 @@ -977,7 +977,7 @@ struct ata_port_operations {
83292 * fields must be pointers.
83293 */
83294 const struct ata_port_operations *inherits;
83295 -};
83296 +} __do_const;
83297
83298 struct ata_port_info {
83299 unsigned long flags;
83300 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83301 index a6a42dd..6c5ebce 100644
83302 --- a/include/linux/linkage.h
83303 +++ b/include/linux/linkage.h
83304 @@ -36,6 +36,7 @@
83305 #endif
83306
83307 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83308 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83309 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83310
83311 /*
83312 diff --git a/include/linux/list.h b/include/linux/list.h
83313 index f33f831..1ffe5e2 100644
83314 --- a/include/linux/list.h
83315 +++ b/include/linux/list.h
83316 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83317 extern void list_del(struct list_head *entry);
83318 #endif
83319
83320 +extern void __pax_list_add(struct list_head *new,
83321 + struct list_head *prev,
83322 + struct list_head *next);
83323 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83324 +{
83325 + __pax_list_add(new, head, head->next);
83326 +}
83327 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83328 +{
83329 + __pax_list_add(new, head->prev, head);
83330 +}
83331 +extern void pax_list_del(struct list_head *entry);
83332 +
83333 /**
83334 * list_replace - replace old entry by new one
83335 * @old : the element to be replaced
83336 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83337 INIT_LIST_HEAD(entry);
83338 }
83339
83340 +extern void pax_list_del_init(struct list_head *entry);
83341 +
83342 /**
83343 * list_move - delete from one list and add as another's head
83344 * @list: the entry to move
83345 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83346 index 4bfde0e..d6e2e09 100644
83347 --- a/include/linux/lockref.h
83348 +++ b/include/linux/lockref.h
83349 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83350 return ((int)l->count < 0);
83351 }
83352
83353 +static inline unsigned int __lockref_read(struct lockref *lockref)
83354 +{
83355 + return lockref->count;
83356 +}
83357 +
83358 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83359 +{
83360 + lockref->count = count;
83361 +}
83362 +
83363 +static inline void __lockref_inc(struct lockref *lockref)
83364 +{
83365 +
83366 +#ifdef CONFIG_PAX_REFCOUNT
83367 + atomic_inc((atomic_t *)&lockref->count);
83368 +#else
83369 + lockref->count++;
83370 +#endif
83371 +
83372 +}
83373 +
83374 +static inline void __lockref_dec(struct lockref *lockref)
83375 +{
83376 +
83377 +#ifdef CONFIG_PAX_REFCOUNT
83378 + atomic_dec((atomic_t *)&lockref->count);
83379 +#else
83380 + lockref->count--;
83381 +#endif
83382 +
83383 +}
83384 +
83385 #endif /* __LINUX_LOCKREF_H */
83386 diff --git a/include/linux/math64.h b/include/linux/math64.h
83387 index c45c089..298841c 100644
83388 --- a/include/linux/math64.h
83389 +++ b/include/linux/math64.h
83390 @@ -15,7 +15,7 @@
83391 * This is commonly provided by 32bit archs to provide an optimized 64bit
83392 * divide.
83393 */
83394 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83395 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83396 {
83397 *remainder = dividend % divisor;
83398 return dividend / divisor;
83399 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83400 /**
83401 * div64_u64 - unsigned 64bit divide with 64bit divisor
83402 */
83403 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83404 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83405 {
83406 return dividend / divisor;
83407 }
83408 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83409 #define div64_ul(x, y) div_u64((x), (y))
83410
83411 #ifndef div_u64_rem
83412 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83413 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83414 {
83415 *remainder = do_div(dividend, divisor);
83416 return dividend;
83417 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83418 #endif
83419
83420 #ifndef div64_u64
83421 -extern u64 div64_u64(u64 dividend, u64 divisor);
83422 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83423 #endif
83424
83425 #ifndef div64_s64
83426 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83427 * divide.
83428 */
83429 #ifndef div_u64
83430 -static inline u64 div_u64(u64 dividend, u32 divisor)
83431 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83432 {
83433 u32 remainder;
83434 return div_u64_rem(dividend, divisor, &remainder);
83435 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83436 index 3d385c8..deacb6a 100644
83437 --- a/include/linux/mempolicy.h
83438 +++ b/include/linux/mempolicy.h
83439 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83440 }
83441
83442 #define vma_policy(vma) ((vma)->vm_policy)
83443 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83444 +{
83445 + vma->vm_policy = pol;
83446 +}
83447
83448 static inline void mpol_get(struct mempolicy *pol)
83449 {
83450 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83451 }
83452
83453 #define vma_policy(vma) NULL
83454 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83455 +{
83456 +}
83457
83458 static inline int
83459 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83460 diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
83461 index 37e4404..26ebbd0 100644
83462 --- a/include/linux/mlx4/device.h
83463 +++ b/include/linux/mlx4/device.h
83464 @@ -97,7 +97,7 @@ enum {
83465 MLX4_MAX_NUM_PF = 16,
83466 MLX4_MAX_NUM_VF = 64,
83467 MLX4_MAX_NUM_VF_P_PORT = 64,
83468 - MLX4_MFUNC_MAX = 80,
83469 + MLX4_MFUNC_MAX = 128,
83470 MLX4_MAX_EQ_NUM = 1024,
83471 MLX4_MFUNC_EQ_NUM = 4,
83472 MLX4_MFUNC_MAX_EQES = 8,
83473 diff --git a/include/linux/mm.h b/include/linux/mm.h
83474 index 86a977b..8122960 100644
83475 --- a/include/linux/mm.h
83476 +++ b/include/linux/mm.h
83477 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83478 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83479 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83480 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83481 +
83482 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83483 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83484 +#endif
83485 +
83486 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83487
83488 #ifdef CONFIG_MEM_SOFT_DIRTY
83489 @@ -238,8 +243,8 @@ struct vm_operations_struct {
83490 /* called by access_process_vm when get_user_pages() fails, typically
83491 * for use by special VMAs that can switch between memory and hardware
83492 */
83493 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83494 - void *buf, int len, int write);
83495 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83496 + void *buf, size_t len, int write);
83497
83498 /* Called by the /proc/PID/maps code to ask the vma whether it
83499 * has a special name. Returning non-NULL will also cause this
83500 @@ -275,6 +280,7 @@ struct vm_operations_struct {
83501 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83502 unsigned long size, pgoff_t pgoff);
83503 };
83504 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83505
83506 struct mmu_gather;
83507 struct inode;
83508 @@ -1167,8 +1173,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83509 unsigned long *pfn);
83510 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83511 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83512 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83513 - void *buf, int len, int write);
83514 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83515 + void *buf, size_t len, int write);
83516
83517 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83518 loff_t const holebegin, loff_t const holelen)
83519 @@ -1208,9 +1214,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83520 }
83521 #endif
83522
83523 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83524 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83525 - void *buf, int len, int write);
83526 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83527 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83528 + void *buf, size_t len, int write);
83529
83530 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83531 unsigned long start, unsigned long nr_pages,
83532 @@ -1242,34 +1248,6 @@ int set_page_dirty_lock(struct page *page);
83533 int clear_page_dirty_for_io(struct page *page);
83534 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83535
83536 -/* Is the vma a continuation of the stack vma above it? */
83537 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83538 -{
83539 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83540 -}
83541 -
83542 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83543 - unsigned long addr)
83544 -{
83545 - return (vma->vm_flags & VM_GROWSDOWN) &&
83546 - (vma->vm_start == addr) &&
83547 - !vma_growsdown(vma->vm_prev, addr);
83548 -}
83549 -
83550 -/* Is the vma a continuation of the stack vma below it? */
83551 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83552 -{
83553 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83554 -}
83555 -
83556 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83557 - unsigned long addr)
83558 -{
83559 - return (vma->vm_flags & VM_GROWSUP) &&
83560 - (vma->vm_end == addr) &&
83561 - !vma_growsup(vma->vm_next, addr);
83562 -}
83563 -
83564 extern struct task_struct *task_of_stack(struct task_struct *task,
83565 struct vm_area_struct *vma, bool in_group);
83566
83567 @@ -1387,8 +1365,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83568 {
83569 return 0;
83570 }
83571 +
83572 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83573 + unsigned long address)
83574 +{
83575 + return 0;
83576 +}
83577 #else
83578 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83579 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83580 #endif
83581
83582 #ifdef __PAGETABLE_PMD_FOLDED
83583 @@ -1397,8 +1382,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83584 {
83585 return 0;
83586 }
83587 +
83588 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83589 + unsigned long address)
83590 +{
83591 + return 0;
83592 +}
83593 #else
83594 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83595 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83596 #endif
83597
83598 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83599 @@ -1416,11 +1408,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83600 NULL: pud_offset(pgd, address);
83601 }
83602
83603 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83604 +{
83605 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83606 + NULL: pud_offset(pgd, address);
83607 +}
83608 +
83609 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83610 {
83611 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83612 NULL: pmd_offset(pud, address);
83613 }
83614 +
83615 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83616 +{
83617 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83618 + NULL: pmd_offset(pud, address);
83619 +}
83620 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83621
83622 #if USE_SPLIT_PTE_PTLOCKS
83623 @@ -1803,12 +1807,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83624 bool *need_rmap_locks);
83625 extern void exit_mmap(struct mm_struct *);
83626
83627 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83628 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83629 + const unsigned long wanted, const int gt);
83630 +#else
83631 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83632 + const unsigned long wanted, const int gt)
83633 +{
83634 +}
83635 +#endif
83636 +
83637 static inline int check_data_rlimit(unsigned long rlim,
83638 unsigned long new,
83639 unsigned long start,
83640 unsigned long end_data,
83641 unsigned long start_data)
83642 {
83643 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83644 if (rlim < RLIM_INFINITY) {
83645 if (((new - start) + (end_data - start_data)) > rlim)
83646 return -ENOSPC;
83647 @@ -1833,7 +1848,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83648 unsigned long addr, unsigned long len,
83649 unsigned long flags, struct page **pages);
83650
83651 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83652 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83653
83654 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83655 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83656 @@ -1841,6 +1856,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83657 unsigned long len, unsigned long prot, unsigned long flags,
83658 unsigned long pgoff, unsigned long *populate);
83659 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83660 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83661
83662 #ifdef CONFIG_MMU
83663 extern int __mm_populate(unsigned long addr, unsigned long len,
83664 @@ -1869,10 +1885,11 @@ struct vm_unmapped_area_info {
83665 unsigned long high_limit;
83666 unsigned long align_mask;
83667 unsigned long align_offset;
83668 + unsigned long threadstack_offset;
83669 };
83670
83671 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83672 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83673 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83674 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83675
83676 /*
83677 * Search for an unmapped address range.
83678 @@ -1884,7 +1901,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83679 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83680 */
83681 static inline unsigned long
83682 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83683 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83684 {
83685 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83686 return unmapped_area(info);
83687 @@ -1946,6 +1963,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83688 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83689 struct vm_area_struct **pprev);
83690
83691 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83692 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83693 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83694 +
83695 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83696 NULL if none. Assume start_addr < end_addr. */
83697 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83698 @@ -1975,10 +1996,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83699 }
83700
83701 #ifdef CONFIG_MMU
83702 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83703 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83704 void vma_set_page_prot(struct vm_area_struct *vma);
83705 #else
83706 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83707 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83708 {
83709 return __pgprot(0);
83710 }
83711 @@ -2040,6 +2061,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83712 static inline void vm_stat_account(struct mm_struct *mm,
83713 unsigned long flags, struct file *file, long pages)
83714 {
83715 +
83716 +#ifdef CONFIG_PAX_RANDMMAP
83717 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83718 +#endif
83719 +
83720 mm->total_vm += pages;
83721 }
83722 #endif /* CONFIG_PROC_FS */
83723 @@ -2128,7 +2154,7 @@ extern int unpoison_memory(unsigned long pfn);
83724 extern int sysctl_memory_failure_early_kill;
83725 extern int sysctl_memory_failure_recovery;
83726 extern void shake_page(struct page *p, int access);
83727 -extern atomic_long_t num_poisoned_pages;
83728 +extern atomic_long_unchecked_t num_poisoned_pages;
83729 extern int soft_offline_page(struct page *page, int flags);
83730
83731 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83732 @@ -2163,5 +2189,11 @@ void __init setup_nr_node_ids(void);
83733 static inline void setup_nr_node_ids(void) {}
83734 #endif
83735
83736 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83737 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83738 +#else
83739 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83740 +#endif
83741 +
83742 #endif /* __KERNEL__ */
83743 #endif /* _LINUX_MM_H */
83744 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83745 index 6e0b286..90d9c0d 100644
83746 --- a/include/linux/mm_types.h
83747 +++ b/include/linux/mm_types.h
83748 @@ -308,7 +308,9 @@ struct vm_area_struct {
83749 #ifdef CONFIG_NUMA
83750 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83751 #endif
83752 -};
83753 +
83754 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83755 +} __randomize_layout;
83756
83757 struct core_thread {
83758 struct task_struct *task;
83759 @@ -454,7 +456,25 @@ struct mm_struct {
83760 bool tlb_flush_pending;
83761 #endif
83762 struct uprobes_state uprobes_state;
83763 -};
83764 +
83765 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83766 + unsigned long pax_flags;
83767 +#endif
83768 +
83769 +#ifdef CONFIG_PAX_DLRESOLVE
83770 + unsigned long call_dl_resolve;
83771 +#endif
83772 +
83773 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83774 + unsigned long call_syscall;
83775 +#endif
83776 +
83777 +#ifdef CONFIG_PAX_ASLR
83778 + unsigned long delta_mmap; /* randomized offset */
83779 + unsigned long delta_stack; /* randomized offset */
83780 +#endif
83781 +
83782 +} __randomize_layout;
83783
83784 static inline void mm_init_cpumask(struct mm_struct *mm)
83785 {
83786 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83787 index c5d5278..f0b68c8 100644
83788 --- a/include/linux/mmiotrace.h
83789 +++ b/include/linux/mmiotrace.h
83790 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83791 /* Called from ioremap.c */
83792 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83793 void __iomem *addr);
83794 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83795 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83796
83797 /* For anyone to insert markers. Remember trailing newline. */
83798 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83799 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83800 {
83801 }
83802
83803 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83804 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83805 {
83806 }
83807
83808 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83809 index ffe66e3..b310722 100644
83810 --- a/include/linux/mmzone.h
83811 +++ b/include/linux/mmzone.h
83812 @@ -527,7 +527,7 @@ struct zone {
83813
83814 ZONE_PADDING(_pad3_)
83815 /* Zone statistics */
83816 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83817 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83818 } ____cacheline_internodealigned_in_smp;
83819
83820 enum zone_flags {
83821 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83822 index 44eeef0..a92d3f9 100644
83823 --- a/include/linux/mod_devicetable.h
83824 +++ b/include/linux/mod_devicetable.h
83825 @@ -139,7 +139,7 @@ struct usb_device_id {
83826 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83827 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83828
83829 -#define HID_ANY_ID (~0)
83830 +#define HID_ANY_ID (~0U)
83831 #define HID_BUS_ANY 0xffff
83832 #define HID_GROUP_ANY 0x0000
83833
83834 @@ -475,7 +475,7 @@ struct dmi_system_id {
83835 const char *ident;
83836 struct dmi_strmatch matches[4];
83837 void *driver_data;
83838 -};
83839 +} __do_const;
83840 /*
83841 * struct dmi_device_id appears during expansion of
83842 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83843 diff --git a/include/linux/module.h b/include/linux/module.h
83844 index 71f282a..b2387e2 100644
83845 --- a/include/linux/module.h
83846 +++ b/include/linux/module.h
83847 @@ -17,9 +17,11 @@
83848 #include <linux/moduleparam.h>
83849 #include <linux/jump_label.h>
83850 #include <linux/export.h>
83851 +#include <linux/fs.h>
83852
83853 #include <linux/percpu.h>
83854 #include <asm/module.h>
83855 +#include <asm/pgtable.h>
83856
83857 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83858 #define MODULE_SIG_STRING "~Module signature appended~\n"
83859 @@ -42,7 +44,7 @@ struct module_kobject {
83860 struct kobject *drivers_dir;
83861 struct module_param_attrs *mp;
83862 struct completion *kobj_completion;
83863 -};
83864 +} __randomize_layout;
83865
83866 struct module_attribute {
83867 struct attribute attr;
83868 @@ -54,12 +56,13 @@ struct module_attribute {
83869 int (*test)(struct module *);
83870 void (*free)(struct module *);
83871 };
83872 +typedef struct module_attribute __no_const module_attribute_no_const;
83873
83874 struct module_version_attribute {
83875 struct module_attribute mattr;
83876 const char *module_name;
83877 const char *version;
83878 -} __attribute__ ((__aligned__(sizeof(void *))));
83879 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83880
83881 extern ssize_t __modver_version_show(struct module_attribute *,
83882 struct module_kobject *, char *);
83883 @@ -235,7 +238,7 @@ struct module {
83884
83885 /* Sysfs stuff. */
83886 struct module_kobject mkobj;
83887 - struct module_attribute *modinfo_attrs;
83888 + module_attribute_no_const *modinfo_attrs;
83889 const char *version;
83890 const char *srcversion;
83891 struct kobject *holders_dir;
83892 @@ -284,19 +287,16 @@ struct module {
83893 int (*init)(void);
83894
83895 /* If this is non-NULL, vfree after init() returns */
83896 - void *module_init;
83897 + void *module_init_rx, *module_init_rw;
83898
83899 /* Here is the actual code + data, vfree'd on unload. */
83900 - void *module_core;
83901 + void *module_core_rx, *module_core_rw;
83902
83903 /* Here are the sizes of the init and core sections */
83904 - unsigned int init_size, core_size;
83905 + unsigned int init_size_rw, core_size_rw;
83906
83907 /* The size of the executable code in each section. */
83908 - unsigned int init_text_size, core_text_size;
83909 -
83910 - /* Size of RO sections of the module (text+rodata) */
83911 - unsigned int init_ro_size, core_ro_size;
83912 + unsigned int init_size_rx, core_size_rx;
83913
83914 /* Arch-specific module values */
83915 struct mod_arch_specific arch;
83916 @@ -352,6 +352,10 @@ struct module {
83917 #ifdef CONFIG_EVENT_TRACING
83918 struct ftrace_event_call **trace_events;
83919 unsigned int num_trace_events;
83920 + struct file_operations trace_id;
83921 + struct file_operations trace_enable;
83922 + struct file_operations trace_format;
83923 + struct file_operations trace_filter;
83924 #endif
83925 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83926 unsigned int num_ftrace_callsites;
83927 @@ -375,7 +379,7 @@ struct module {
83928 ctor_fn_t *ctors;
83929 unsigned int num_ctors;
83930 #endif
83931 -};
83932 +} __randomize_layout;
83933 #ifndef MODULE_ARCH_INIT
83934 #define MODULE_ARCH_INIT {}
83935 #endif
83936 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83937 bool is_module_percpu_address(unsigned long addr);
83938 bool is_module_text_address(unsigned long addr);
83939
83940 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83941 +{
83942 +
83943 +#ifdef CONFIG_PAX_KERNEXEC
83944 + if (ktla_ktva(addr) >= (unsigned long)start &&
83945 + ktla_ktva(addr) < (unsigned long)start + size)
83946 + return 1;
83947 +#endif
83948 +
83949 + return ((void *)addr >= start && (void *)addr < start + size);
83950 +}
83951 +
83952 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83953 +{
83954 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83955 +}
83956 +
83957 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83958 +{
83959 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83960 +}
83961 +
83962 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83963 +{
83964 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83965 +}
83966 +
83967 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83968 +{
83969 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83970 +}
83971 +
83972 static inline bool within_module_core(unsigned long addr,
83973 const struct module *mod)
83974 {
83975 - return (unsigned long)mod->module_core <= addr &&
83976 - addr < (unsigned long)mod->module_core + mod->core_size;
83977 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83978 }
83979
83980 static inline bool within_module_init(unsigned long addr,
83981 const struct module *mod)
83982 {
83983 - return (unsigned long)mod->module_init <= addr &&
83984 - addr < (unsigned long)mod->module_init + mod->init_size;
83985 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83986 }
83987
83988 static inline bool within_module(unsigned long addr, const struct module *mod)
83989 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83990 index 7eeb9bb..68f37e0 100644
83991 --- a/include/linux/moduleloader.h
83992 +++ b/include/linux/moduleloader.h
83993 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83994 sections. Returns NULL on failure. */
83995 void *module_alloc(unsigned long size);
83996
83997 +#ifdef CONFIG_PAX_KERNEXEC
83998 +void *module_alloc_exec(unsigned long size);
83999 +#else
84000 +#define module_alloc_exec(x) module_alloc(x)
84001 +#endif
84002 +
84003 /* Free memory returned from module_alloc. */
84004 void module_free(struct module *mod, void *module_region);
84005
84006 +#ifdef CONFIG_PAX_KERNEXEC
84007 +void module_free_exec(struct module *mod, void *module_region);
84008 +#else
84009 +#define module_free_exec(x, y) module_free((x), (y))
84010 +#endif
84011 +
84012 /*
84013 * Apply the given relocation to the (simplified) ELF. Return -error
84014 * or 0.
84015 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84016 unsigned int relsec,
84017 struct module *me)
84018 {
84019 +#ifdef CONFIG_MODULES
84020 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84021 module_name(me));
84022 +#endif
84023 return -ENOEXEC;
84024 }
84025 #endif
84026 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84027 unsigned int relsec,
84028 struct module *me)
84029 {
84030 +#ifdef CONFIG_MODULES
84031 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84032 module_name(me));
84033 +#endif
84034 return -ENOEXEC;
84035 }
84036 #endif
84037 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84038 index 1c9effa..1160bdd 100644
84039 --- a/include/linux/moduleparam.h
84040 +++ b/include/linux/moduleparam.h
84041 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
84042 * @len is usually just sizeof(string).
84043 */
84044 #define module_param_string(name, string, len, perm) \
84045 - static const struct kparam_string __param_string_##name \
84046 + static const struct kparam_string __param_string_##name __used \
84047 = { len, string }; \
84048 __module_param_call(MODULE_PARAM_PREFIX, name, \
84049 &param_ops_string, \
84050 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84051 */
84052 #define module_param_array_named(name, array, type, nump, perm) \
84053 param_check_##type(name, &(array)[0]); \
84054 - static const struct kparam_array __param_arr_##name \
84055 + static const struct kparam_array __param_arr_##name __used \
84056 = { .max = ARRAY_SIZE(array), .num = nump, \
84057 .ops = &param_ops_##type, \
84058 .elemsize = sizeof(array[0]), .elem = array }; \
84059 diff --git a/include/linux/mount.h b/include/linux/mount.h
84060 index c2c561d..a5f2a8c 100644
84061 --- a/include/linux/mount.h
84062 +++ b/include/linux/mount.h
84063 @@ -66,7 +66,7 @@ struct vfsmount {
84064 struct dentry *mnt_root; /* root of the mounted tree */
84065 struct super_block *mnt_sb; /* pointer to superblock */
84066 int mnt_flags;
84067 -};
84068 +} __randomize_layout;
84069
84070 struct file; /* forward dec */
84071 struct path;
84072 diff --git a/include/linux/namei.h b/include/linux/namei.h
84073 index 492de72..1bddcd4 100644
84074 --- a/include/linux/namei.h
84075 +++ b/include/linux/namei.h
84076 @@ -19,7 +19,7 @@ struct nameidata {
84077 unsigned seq, m_seq;
84078 int last_type;
84079 unsigned depth;
84080 - char *saved_names[MAX_NESTED_LINKS + 1];
84081 + const char *saved_names[MAX_NESTED_LINKS + 1];
84082 };
84083
84084 /*
84085 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84086
84087 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84088
84089 -static inline void nd_set_link(struct nameidata *nd, char *path)
84090 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84091 {
84092 nd->saved_names[nd->depth] = path;
84093 }
84094
84095 -static inline char *nd_get_link(struct nameidata *nd)
84096 +static inline const char *nd_get_link(const struct nameidata *nd)
84097 {
84098 return nd->saved_names[nd->depth];
84099 }
84100 diff --git a/include/linux/net.h b/include/linux/net.h
84101 index 17d8339..81656c0 100644
84102 --- a/include/linux/net.h
84103 +++ b/include/linux/net.h
84104 @@ -192,7 +192,7 @@ struct net_proto_family {
84105 int (*create)(struct net *net, struct socket *sock,
84106 int protocol, int kern);
84107 struct module *owner;
84108 -};
84109 +} __do_const;
84110
84111 struct iovec;
84112 struct kvec;
84113 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84114 index 22339b4..4b4d5b3 100644
84115 --- a/include/linux/netdevice.h
84116 +++ b/include/linux/netdevice.h
84117 @@ -1160,6 +1160,7 @@ struct net_device_ops {
84118 struct net_device *dev,
84119 netdev_features_t features);
84120 };
84121 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84122
84123 /**
84124 * enum net_device_priv_flags - &struct net_device priv_flags
84125 @@ -1502,10 +1503,10 @@ struct net_device {
84126
84127 struct net_device_stats stats;
84128
84129 - atomic_long_t rx_dropped;
84130 - atomic_long_t tx_dropped;
84131 + atomic_long_unchecked_t rx_dropped;
84132 + atomic_long_unchecked_t tx_dropped;
84133
84134 - atomic_t carrier_changes;
84135 + atomic_unchecked_t carrier_changes;
84136
84137 #ifdef CONFIG_WIRELESS_EXT
84138 const struct iw_handler_def * wireless_handlers;
84139 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84140 index 2517ece..0bbfcfb 100644
84141 --- a/include/linux/netfilter.h
84142 +++ b/include/linux/netfilter.h
84143 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84144 #endif
84145 /* Use the module struct to lock set/get code in place */
84146 struct module *owner;
84147 -};
84148 +} __do_const;
84149
84150 /* Function to register/unregister hook points. */
84151 int nf_register_hook(struct nf_hook_ops *reg);
84152 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84153 index e955d47..04a5338 100644
84154 --- a/include/linux/netfilter/nfnetlink.h
84155 +++ b/include/linux/netfilter/nfnetlink.h
84156 @@ -19,7 +19,7 @@ struct nfnl_callback {
84157 const struct nlattr * const cda[]);
84158 const struct nla_policy *policy; /* netlink attribute policy */
84159 const u_int16_t attr_count; /* number of nlattr's */
84160 -};
84161 +} __do_const;
84162
84163 struct nfnetlink_subsystem {
84164 const char *name;
84165 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84166 new file mode 100644
84167 index 0000000..33f4af8
84168 --- /dev/null
84169 +++ b/include/linux/netfilter/xt_gradm.h
84170 @@ -0,0 +1,9 @@
84171 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84172 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84173 +
84174 +struct xt_gradm_mtinfo {
84175 + __u16 flags;
84176 + __u16 invflags;
84177 +};
84178 +
84179 +#endif
84180 diff --git a/include/linux/nls.h b/include/linux/nls.h
84181 index 520681b..2b7fabb 100644
84182 --- a/include/linux/nls.h
84183 +++ b/include/linux/nls.h
84184 @@ -31,7 +31,7 @@ struct nls_table {
84185 const unsigned char *charset2upper;
84186 struct module *owner;
84187 struct nls_table *next;
84188 -};
84189 +} __do_const;
84190
84191 /* this value hold the maximum octet of charset */
84192 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84193 @@ -46,7 +46,7 @@ enum utf16_endian {
84194 /* nls_base.c */
84195 extern int __register_nls(struct nls_table *, struct module *);
84196 extern int unregister_nls(struct nls_table *);
84197 -extern struct nls_table *load_nls(char *);
84198 +extern struct nls_table *load_nls(const char *);
84199 extern void unload_nls(struct nls_table *);
84200 extern struct nls_table *load_nls_default(void);
84201 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84202 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84203 index d14a4c3..a078786 100644
84204 --- a/include/linux/notifier.h
84205 +++ b/include/linux/notifier.h
84206 @@ -54,7 +54,8 @@ struct notifier_block {
84207 notifier_fn_t notifier_call;
84208 struct notifier_block __rcu *next;
84209 int priority;
84210 -};
84211 +} __do_const;
84212 +typedef struct notifier_block __no_const notifier_block_no_const;
84213
84214 struct atomic_notifier_head {
84215 spinlock_t lock;
84216 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84217 index b2a0f15..4d7da32 100644
84218 --- a/include/linux/oprofile.h
84219 +++ b/include/linux/oprofile.h
84220 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84221 int oprofilefs_create_ro_ulong(struct dentry * root,
84222 char const * name, ulong * val);
84223
84224 -/** Create a file for read-only access to an atomic_t. */
84225 +/** Create a file for read-only access to an atomic_unchecked_t. */
84226 int oprofilefs_create_ro_atomic(struct dentry * root,
84227 - char const * name, atomic_t * val);
84228 + char const * name, atomic_unchecked_t * val);
84229
84230 /** create a directory */
84231 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84232 diff --git a/include/linux/padata.h b/include/linux/padata.h
84233 index 4386946..f50c615 100644
84234 --- a/include/linux/padata.h
84235 +++ b/include/linux/padata.h
84236 @@ -129,7 +129,7 @@ struct parallel_data {
84237 struct padata_serial_queue __percpu *squeue;
84238 atomic_t reorder_objects;
84239 atomic_t refcnt;
84240 - atomic_t seq_nr;
84241 + atomic_unchecked_t seq_nr;
84242 struct padata_cpumask cpumask;
84243 spinlock_t lock ____cacheline_aligned;
84244 unsigned int processed;
84245 diff --git a/include/linux/path.h b/include/linux/path.h
84246 index d137218..be0c176 100644
84247 --- a/include/linux/path.h
84248 +++ b/include/linux/path.h
84249 @@ -1,13 +1,15 @@
84250 #ifndef _LINUX_PATH_H
84251 #define _LINUX_PATH_H
84252
84253 +#include <linux/compiler.h>
84254 +
84255 struct dentry;
84256 struct vfsmount;
84257
84258 struct path {
84259 struct vfsmount *mnt;
84260 struct dentry *dentry;
84261 -};
84262 +} __randomize_layout;
84263
84264 extern void path_get(const struct path *);
84265 extern void path_put(const struct path *);
84266 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84267 index 2706ee9..e691f7c 100644
84268 --- a/include/linux/pci_hotplug.h
84269 +++ b/include/linux/pci_hotplug.h
84270 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84271 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84272 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84273 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84274 -};
84275 +} __do_const;
84276 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84277
84278 /**
84279 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84280 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84281 index 893a0d0..d5f996e 100644
84282 --- a/include/linux/perf_event.h
84283 +++ b/include/linux/perf_event.h
84284 @@ -341,8 +341,8 @@ struct perf_event {
84285
84286 enum perf_event_active_state state;
84287 unsigned int attach_state;
84288 - local64_t count;
84289 - atomic64_t child_count;
84290 + local64_t count; /* PaX: fix it one day */
84291 + atomic64_unchecked_t child_count;
84292
84293 /*
84294 * These are the total time in nanoseconds that the event
84295 @@ -393,8 +393,8 @@ struct perf_event {
84296 * These accumulate total time (in nanoseconds) that children
84297 * events have been enabled and running, respectively.
84298 */
84299 - atomic64_t child_total_time_enabled;
84300 - atomic64_t child_total_time_running;
84301 + atomic64_unchecked_t child_total_time_enabled;
84302 + atomic64_unchecked_t child_total_time_running;
84303
84304 /*
84305 * Protect attach/detach and child_list:
84306 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84307 entry->ip[entry->nr++] = ip;
84308 }
84309
84310 -extern int sysctl_perf_event_paranoid;
84311 +extern int sysctl_perf_event_legitimately_concerned;
84312 extern int sysctl_perf_event_mlock;
84313 extern int sysctl_perf_event_sample_rate;
84314 extern int sysctl_perf_cpu_time_max_percent;
84315 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84316 loff_t *ppos);
84317
84318
84319 +static inline bool perf_paranoid_any(void)
84320 +{
84321 + return sysctl_perf_event_legitimately_concerned > 2;
84322 +}
84323 +
84324 static inline bool perf_paranoid_tracepoint_raw(void)
84325 {
84326 - return sysctl_perf_event_paranoid > -1;
84327 + return sysctl_perf_event_legitimately_concerned > -1;
84328 }
84329
84330 static inline bool perf_paranoid_cpu(void)
84331 {
84332 - return sysctl_perf_event_paranoid > 0;
84333 + return sysctl_perf_event_legitimately_concerned > 0;
84334 }
84335
84336 static inline bool perf_paranoid_kernel(void)
84337 {
84338 - return sysctl_perf_event_paranoid > 1;
84339 + return sysctl_perf_event_legitimately_concerned > 1;
84340 }
84341
84342 extern void perf_event_init(void);
84343 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84344 struct device_attribute attr;
84345 u64 id;
84346 const char *event_str;
84347 -};
84348 +} __do_const;
84349
84350 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84351 static struct perf_pmu_events_attr _var = { \
84352 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84353 index 1997ffc..4f1f44d 100644
84354 --- a/include/linux/pid_namespace.h
84355 +++ b/include/linux/pid_namespace.h
84356 @@ -44,7 +44,7 @@ struct pid_namespace {
84357 int hide_pid;
84358 int reboot; /* group exit code if this pidns was rebooted */
84359 unsigned int proc_inum;
84360 -};
84361 +} __randomize_layout;
84362
84363 extern struct pid_namespace init_pid_ns;
84364
84365 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84366 index eb8b8ac..62649e1 100644
84367 --- a/include/linux/pipe_fs_i.h
84368 +++ b/include/linux/pipe_fs_i.h
84369 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84370 struct mutex mutex;
84371 wait_queue_head_t wait;
84372 unsigned int nrbufs, curbuf, buffers;
84373 - unsigned int readers;
84374 - unsigned int writers;
84375 - unsigned int files;
84376 - unsigned int waiting_writers;
84377 + atomic_t readers;
84378 + atomic_t writers;
84379 + atomic_t files;
84380 + atomic_t waiting_writers;
84381 unsigned int r_counter;
84382 unsigned int w_counter;
84383 struct page *tmp_page;
84384 diff --git a/include/linux/pm.h b/include/linux/pm.h
84385 index 383fd68..7a11504 100644
84386 --- a/include/linux/pm.h
84387 +++ b/include/linux/pm.h
84388 @@ -621,6 +621,7 @@ struct dev_pm_domain {
84389 struct dev_pm_ops ops;
84390 void (*detach)(struct device *dev, bool power_off);
84391 };
84392 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84393
84394 /*
84395 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84396 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84397 index 2e0e06d..824cc9b 100644
84398 --- a/include/linux/pm_domain.h
84399 +++ b/include/linux/pm_domain.h
84400 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
84401 int (*save_state)(struct device *dev);
84402 int (*restore_state)(struct device *dev);
84403 bool (*active_wakeup)(struct device *dev);
84404 -};
84405 +} __no_const;
84406
84407 struct gpd_cpuidle_data {
84408 unsigned int saved_exit_latency;
84409 - struct cpuidle_state *idle_state;
84410 + cpuidle_state_no_const *idle_state;
84411 };
84412
84413 struct generic_pm_domain {
84414 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84415 index 367f49b..d2f5a14 100644
84416 --- a/include/linux/pm_runtime.h
84417 +++ b/include/linux/pm_runtime.h
84418 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84419
84420 static inline void pm_runtime_mark_last_busy(struct device *dev)
84421 {
84422 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84423 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84424 }
84425
84426 #else /* !CONFIG_PM_RUNTIME */
84427 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84428 index 195aafc..49a7bc2 100644
84429 --- a/include/linux/pnp.h
84430 +++ b/include/linux/pnp.h
84431 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84432 struct pnp_fixup {
84433 char id[7];
84434 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84435 -};
84436 +} __do_const;
84437
84438 /* config parameters */
84439 #define PNP_CONFIG_NORMAL 0x0001
84440 diff --git a/include/linux/poison.h b/include/linux/poison.h
84441 index 2110a81..13a11bb 100644
84442 --- a/include/linux/poison.h
84443 +++ b/include/linux/poison.h
84444 @@ -19,8 +19,8 @@
84445 * under normal circumstances, used to verify that nobody uses
84446 * non-initialized list entries.
84447 */
84448 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84449 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84450 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84451 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84452
84453 /********** include/linux/timer.h **********/
84454 /*
84455 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84456 index d8b187c3..9a9257a 100644
84457 --- a/include/linux/power/smartreflex.h
84458 +++ b/include/linux/power/smartreflex.h
84459 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84460 int (*notify)(struct omap_sr *sr, u32 status);
84461 u8 notify_flags;
84462 u8 class_type;
84463 -};
84464 +} __do_const;
84465
84466 /**
84467 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84468 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84469 index 4ea1d37..80f4b33 100644
84470 --- a/include/linux/ppp-comp.h
84471 +++ b/include/linux/ppp-comp.h
84472 @@ -84,7 +84,7 @@ struct compressor {
84473 struct module *owner;
84474 /* Extra skb space needed by the compressor algorithm */
84475 unsigned int comp_extra;
84476 -};
84477 +} __do_const;
84478
84479 /*
84480 * The return value from decompress routine is the length of the
84481 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84482 index de83b4e..c4b997d 100644
84483 --- a/include/linux/preempt.h
84484 +++ b/include/linux/preempt.h
84485 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84486 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84487 #endif
84488
84489 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84490 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84491 +
84492 #define __preempt_count_inc() __preempt_count_add(1)
84493 #define __preempt_count_dec() __preempt_count_sub(1)
84494
84495 #define preempt_count_inc() preempt_count_add(1)
84496 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84497 #define preempt_count_dec() preempt_count_sub(1)
84498 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84499
84500 #ifdef CONFIG_PREEMPT_COUNT
84501
84502 @@ -41,6 +46,12 @@ do { \
84503 barrier(); \
84504 } while (0)
84505
84506 +#define raw_preempt_disable() \
84507 +do { \
84508 + raw_preempt_count_inc(); \
84509 + barrier(); \
84510 +} while (0)
84511 +
84512 #define sched_preempt_enable_no_resched() \
84513 do { \
84514 barrier(); \
84515 @@ -49,6 +60,12 @@ do { \
84516
84517 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84518
84519 +#define raw_preempt_enable_no_resched() \
84520 +do { \
84521 + barrier(); \
84522 + raw_preempt_count_dec(); \
84523 +} while (0)
84524 +
84525 #ifdef CONFIG_PREEMPT
84526 #define preempt_enable() \
84527 do { \
84528 @@ -113,8 +130,10 @@ do { \
84529 * region.
84530 */
84531 #define preempt_disable() barrier()
84532 +#define raw_preempt_disable() barrier()
84533 #define sched_preempt_enable_no_resched() barrier()
84534 #define preempt_enable_no_resched() barrier()
84535 +#define raw_preempt_enable_no_resched() barrier()
84536 #define preempt_enable() barrier()
84537 #define preempt_check_resched() do { } while (0)
84538
84539 @@ -128,11 +147,13 @@ do { \
84540 /*
84541 * Modules have no business playing preemption tricks.
84542 */
84543 +#ifndef CONFIG_PAX_KERNEXEC
84544 #undef sched_preempt_enable_no_resched
84545 #undef preempt_enable_no_resched
84546 #undef preempt_enable_no_resched_notrace
84547 #undef preempt_check_resched
84548 #endif
84549 +#endif
84550
84551 #define preempt_set_need_resched() \
84552 do { \
84553 diff --git a/include/linux/printk.h b/include/linux/printk.h
84554 index d78125f..7f36596 100644
84555 --- a/include/linux/printk.h
84556 +++ b/include/linux/printk.h
84557 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84558 void early_printk(const char *s, ...) { }
84559 #endif
84560
84561 +extern int kptr_restrict;
84562 +
84563 #ifdef CONFIG_PRINTK
84564 asmlinkage __printf(5, 0)
84565 int vprintk_emit(int facility, int level,
84566 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84567
84568 extern int printk_delay_msec;
84569 extern int dmesg_restrict;
84570 -extern int kptr_restrict;
84571
84572 extern void wake_up_klogd(void);
84573
84574 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84575 index b97bf2e..f14c92d4 100644
84576 --- a/include/linux/proc_fs.h
84577 +++ b/include/linux/proc_fs.h
84578 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84579 extern struct proc_dir_entry *proc_symlink(const char *,
84580 struct proc_dir_entry *, const char *);
84581 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84582 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84583 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84584 struct proc_dir_entry *, void *);
84585 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84586 + struct proc_dir_entry *, void *);
84587 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84588 struct proc_dir_entry *);
84589
84590 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84591 return proc_create_data(name, mode, parent, proc_fops, NULL);
84592 }
84593
84594 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84595 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84596 +{
84597 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84598 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84599 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84600 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84601 +#else
84602 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84603 +#endif
84604 +}
84605 +
84606 +
84607 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84608 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84609 extern void *PDE_DATA(const struct inode *);
84610 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84611 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84612 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84613 struct proc_dir_entry *parent) {return NULL;}
84614 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84615 + struct proc_dir_entry *parent) { return NULL; }
84616 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84617 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84618 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84619 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84620 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84621 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84622 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84623 @@ -79,7 +99,7 @@ struct net;
84624 static inline struct proc_dir_entry *proc_net_mkdir(
84625 struct net *net, const char *name, struct proc_dir_entry *parent)
84626 {
84627 - return proc_mkdir_data(name, 0, parent, net);
84628 + return proc_mkdir_data_restrict(name, 0, parent, net);
84629 }
84630
84631 #endif /* _LINUX_PROC_FS_H */
84632 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84633 index 34a1e10..70f6bde 100644
84634 --- a/include/linux/proc_ns.h
84635 +++ b/include/linux/proc_ns.h
84636 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84637 void (*put)(void *ns);
84638 int (*install)(struct nsproxy *nsproxy, void *ns);
84639 unsigned int (*inum)(void *ns);
84640 -};
84641 +} __do_const __randomize_layout;
84642
84643 struct proc_ns {
84644 void *ns;
84645 diff --git a/include/linux/quota.h b/include/linux/quota.h
84646 index 224fb81..9d85c41 100644
84647 --- a/include/linux/quota.h
84648 +++ b/include/linux/quota.h
84649 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84650
84651 extern bool qid_eq(struct kqid left, struct kqid right);
84652 extern bool qid_lt(struct kqid left, struct kqid right);
84653 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84654 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84655 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84656 extern bool qid_valid(struct kqid qid);
84657
84658 diff --git a/include/linux/random.h b/include/linux/random.h
84659 index b05856e..0a9f14e 100644
84660 --- a/include/linux/random.h
84661 +++ b/include/linux/random.h
84662 @@ -9,9 +9,19 @@
84663 #include <uapi/linux/random.h>
84664
84665 extern void add_device_randomness(const void *, unsigned int);
84666 +
84667 +static inline void add_latent_entropy(void)
84668 +{
84669 +
84670 +#ifdef LATENT_ENTROPY_PLUGIN
84671 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84672 +#endif
84673 +
84674 +}
84675 +
84676 extern void add_input_randomness(unsigned int type, unsigned int code,
84677 - unsigned int value);
84678 -extern void add_interrupt_randomness(int irq, int irq_flags);
84679 + unsigned int value) __latent_entropy;
84680 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84681
84682 extern void get_random_bytes(void *buf, int nbytes);
84683 extern void get_random_bytes_arch(void *buf, int nbytes);
84684 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84685 extern const struct file_operations random_fops, urandom_fops;
84686 #endif
84687
84688 -unsigned int get_random_int(void);
84689 +unsigned int __intentional_overflow(-1) get_random_int(void);
84690 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84691
84692 -u32 prandom_u32(void);
84693 +u32 prandom_u32(void) __intentional_overflow(-1);
84694 void prandom_bytes(void *buf, size_t nbytes);
84695 void prandom_seed(u32 seed);
84696 void prandom_reseed_late(void);
84697 @@ -37,6 +47,11 @@ struct rnd_state {
84698 u32 prandom_u32_state(struct rnd_state *state);
84699 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84700
84701 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84702 +{
84703 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84704 +}
84705 +
84706 /**
84707 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84708 * @ep_ro: right open interval endpoint
84709 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84710 *
84711 * Returns: pseudo-random number in interval [0, ep_ro)
84712 */
84713 -static inline u32 prandom_u32_max(u32 ep_ro)
84714 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84715 {
84716 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84717 }
84718 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84719 index 378c5ee..aa84a47 100644
84720 --- a/include/linux/rbtree_augmented.h
84721 +++ b/include/linux/rbtree_augmented.h
84722 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84723 old->rbaugmented = rbcompute(old); \
84724 } \
84725 rbstatic const struct rb_augment_callbacks rbname = { \
84726 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84727 + .propagate = rbname ## _propagate, \
84728 + .copy = rbname ## _copy, \
84729 + .rotate = rbname ## _rotate \
84730 };
84731
84732
84733 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84734 index 372ad5e..d4373f8 100644
84735 --- a/include/linux/rculist.h
84736 +++ b/include/linux/rculist.h
84737 @@ -29,8 +29,8 @@
84738 */
84739 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84740 {
84741 - ACCESS_ONCE(list->next) = list;
84742 - ACCESS_ONCE(list->prev) = list;
84743 + ACCESS_ONCE_RW(list->next) = list;
84744 + ACCESS_ONCE_RW(list->prev) = list;
84745 }
84746
84747 /*
84748 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84749 struct list_head *prev, struct list_head *next);
84750 #endif
84751
84752 +void __pax_list_add_rcu(struct list_head *new,
84753 + struct list_head *prev, struct list_head *next);
84754 +
84755 /**
84756 * list_add_rcu - add a new entry to rcu-protected list
84757 * @new: new entry to be added
84758 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84759 __list_add_rcu(new, head, head->next);
84760 }
84761
84762 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84763 +{
84764 + __pax_list_add_rcu(new, head, head->next);
84765 +}
84766 +
84767 /**
84768 * list_add_tail_rcu - add a new entry to rcu-protected list
84769 * @new: new entry to be added
84770 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84771 __list_add_rcu(new, head->prev, head);
84772 }
84773
84774 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84775 + struct list_head *head)
84776 +{
84777 + __pax_list_add_rcu(new, head->prev, head);
84778 +}
84779 +
84780 /**
84781 * list_del_rcu - deletes entry from list without re-initialization
84782 * @entry: the element to delete from the list.
84783 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84784 entry->prev = LIST_POISON2;
84785 }
84786
84787 +extern void pax_list_del_rcu(struct list_head *entry);
84788 +
84789 /**
84790 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84791 * @n: the element to delete from the hash list.
84792 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84793 index 53ff1a7..c40f0ab 100644
84794 --- a/include/linux/rcupdate.h
84795 +++ b/include/linux/rcupdate.h
84796 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84797 #define rcu_note_voluntary_context_switch(t) \
84798 do { \
84799 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84800 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84801 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84802 } while (0)
84803 #else /* #ifdef CONFIG_TASKS_RCU */
84804 #define TASKS_RCU(x) do { } while (0)
84805 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84806 index 67fc8fc..a90f7d8 100644
84807 --- a/include/linux/reboot.h
84808 +++ b/include/linux/reboot.h
84809 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84810 */
84811
84812 extern void migrate_to_reboot_cpu(void);
84813 -extern void machine_restart(char *cmd);
84814 -extern void machine_halt(void);
84815 -extern void machine_power_off(void);
84816 +extern void machine_restart(char *cmd) __noreturn;
84817 +extern void machine_halt(void) __noreturn;
84818 +extern void machine_power_off(void) __noreturn;
84819
84820 extern void machine_shutdown(void);
84821 struct pt_regs;
84822 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84823 */
84824
84825 extern void kernel_restart_prepare(char *cmd);
84826 -extern void kernel_restart(char *cmd);
84827 -extern void kernel_halt(void);
84828 -extern void kernel_power_off(void);
84829 +extern void kernel_restart(char *cmd) __noreturn;
84830 +extern void kernel_halt(void) __noreturn;
84831 +extern void kernel_power_off(void) __noreturn;
84832
84833 extern int C_A_D; /* for sysctl */
84834 void ctrl_alt_del(void);
84835 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84836 * Emergency restart, callable from an interrupt handler.
84837 */
84838
84839 -extern void emergency_restart(void);
84840 +extern void emergency_restart(void) __noreturn;
84841 #include <asm/emergency-restart.h>
84842
84843 #endif /* _LINUX_REBOOT_H */
84844 diff --git a/include/linux/regset.h b/include/linux/regset.h
84845 index 8e0c9fe..ac4d221 100644
84846 --- a/include/linux/regset.h
84847 +++ b/include/linux/regset.h
84848 @@ -161,7 +161,8 @@ struct user_regset {
84849 unsigned int align;
84850 unsigned int bias;
84851 unsigned int core_note_type;
84852 -};
84853 +} __do_const;
84854 +typedef struct user_regset __no_const user_regset_no_const;
84855
84856 /**
84857 * struct user_regset_view - available regsets
84858 diff --git a/include/linux/relay.h b/include/linux/relay.h
84859 index d7c8359..818daf5 100644
84860 --- a/include/linux/relay.h
84861 +++ b/include/linux/relay.h
84862 @@ -157,7 +157,7 @@ struct rchan_callbacks
84863 * The callback should return 0 if successful, negative if not.
84864 */
84865 int (*remove_buf_file)(struct dentry *dentry);
84866 -};
84867 +} __no_const;
84868
84869 /*
84870 * CONFIG_RELAY kernel API, kernel/relay.c
84871 diff --git a/include/linux/rio.h b/include/linux/rio.h
84872 index 6bda06f..bf39a9b 100644
84873 --- a/include/linux/rio.h
84874 +++ b/include/linux/rio.h
84875 @@ -358,7 +358,7 @@ struct rio_ops {
84876 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84877 u64 rstart, u32 size, u32 flags);
84878 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84879 -};
84880 +} __no_const;
84881
84882 #define RIO_RESOURCE_MEM 0x00000100
84883 #define RIO_RESOURCE_DOORBELL 0x00000200
84884 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84885 index c0c2bce..4813524 100644
84886 --- a/include/linux/rmap.h
84887 +++ b/include/linux/rmap.h
84888 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84889 void anon_vma_init(void); /* create anon_vma_cachep */
84890 int anon_vma_prepare(struct vm_area_struct *);
84891 void unlink_anon_vmas(struct vm_area_struct *);
84892 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84893 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84894 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84895 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84896
84897 static inline void anon_vma_merge(struct vm_area_struct *vma,
84898 struct vm_area_struct *next)
84899 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84900 index ed8f9e7..999bc96 100644
84901 --- a/include/linux/scatterlist.h
84902 +++ b/include/linux/scatterlist.h
84903 @@ -1,6 +1,7 @@
84904 #ifndef _LINUX_SCATTERLIST_H
84905 #define _LINUX_SCATTERLIST_H
84906
84907 +#include <linux/sched.h>
84908 #include <linux/string.h>
84909 #include <linux/bug.h>
84910 #include <linux/mm.h>
84911 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84912 #ifdef CONFIG_DEBUG_SG
84913 BUG_ON(!virt_addr_valid(buf));
84914 #endif
84915 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84916 + if (object_starts_on_stack(buf)) {
84917 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84918 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84919 + } else
84920 +#endif
84921 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84922 }
84923
84924 diff --git a/include/linux/sched.h b/include/linux/sched.h
84925 index 5e344bb..0743255 100644
84926 --- a/include/linux/sched.h
84927 +++ b/include/linux/sched.h
84928 @@ -133,6 +133,7 @@ struct fs_struct;
84929 struct perf_event_context;
84930 struct blk_plug;
84931 struct filename;
84932 +struct linux_binprm;
84933
84934 #define VMACACHE_BITS 2
84935 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84936 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84937 extern int in_sched_functions(unsigned long addr);
84938
84939 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84940 -extern signed long schedule_timeout(signed long timeout);
84941 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84942 extern signed long schedule_timeout_interruptible(signed long timeout);
84943 extern signed long schedule_timeout_killable(signed long timeout);
84944 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84945 @@ -387,6 +388,19 @@ struct nsproxy;
84946 struct user_namespace;
84947
84948 #ifdef CONFIG_MMU
84949 +
84950 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84951 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84952 +#else
84953 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84954 +{
84955 + return 0;
84956 +}
84957 +#endif
84958 +
84959 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84960 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84961 +
84962 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84963 extern unsigned long
84964 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84965 @@ -685,6 +699,17 @@ struct signal_struct {
84966 #ifdef CONFIG_TASKSTATS
84967 struct taskstats *stats;
84968 #endif
84969 +
84970 +#ifdef CONFIG_GRKERNSEC
84971 + u32 curr_ip;
84972 + u32 saved_ip;
84973 + u32 gr_saddr;
84974 + u32 gr_daddr;
84975 + u16 gr_sport;
84976 + u16 gr_dport;
84977 + u8 used_accept:1;
84978 +#endif
84979 +
84980 #ifdef CONFIG_AUDIT
84981 unsigned audit_tty;
84982 unsigned audit_tty_log_passwd;
84983 @@ -711,7 +736,7 @@ struct signal_struct {
84984 struct mutex cred_guard_mutex; /* guard against foreign influences on
84985 * credential calculations
84986 * (notably. ptrace) */
84987 -};
84988 +} __randomize_layout;
84989
84990 /*
84991 * Bits in flags field of signal_struct.
84992 @@ -764,6 +789,14 @@ struct user_struct {
84993 struct key *session_keyring; /* UID's default session keyring */
84994 #endif
84995
84996 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84997 + unsigned char kernel_banned;
84998 +#endif
84999 +#ifdef CONFIG_GRKERNSEC_BRUTE
85000 + unsigned char suid_banned;
85001 + unsigned long suid_ban_expires;
85002 +#endif
85003 +
85004 /* Hash table maintenance information */
85005 struct hlist_node uidhash_node;
85006 kuid_t uid;
85007 @@ -771,7 +804,7 @@ struct user_struct {
85008 #ifdef CONFIG_PERF_EVENTS
85009 atomic_long_t locked_vm;
85010 #endif
85011 -};
85012 +} __randomize_layout;
85013
85014 extern int uids_sysfs_init(void);
85015
85016 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
85017 struct task_struct {
85018 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85019 void *stack;
85020 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85021 + void *lowmem_stack;
85022 +#endif
85023 atomic_t usage;
85024 unsigned int flags; /* per process flags, defined below */
85025 unsigned int ptrace;
85026 @@ -1362,8 +1398,8 @@ struct task_struct {
85027 struct list_head thread_node;
85028
85029 struct completion *vfork_done; /* for vfork() */
85030 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85031 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85032 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85033 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85034
85035 cputime_t utime, stime, utimescaled, stimescaled;
85036 cputime_t gtime;
85037 @@ -1388,11 +1424,6 @@ struct task_struct {
85038 struct task_cputime cputime_expires;
85039 struct list_head cpu_timers[3];
85040
85041 -/* process credentials */
85042 - const struct cred __rcu *real_cred; /* objective and real subjective task
85043 - * credentials (COW) */
85044 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85045 - * credentials (COW) */
85046 char comm[TASK_COMM_LEN]; /* executable name excluding path
85047 - access with [gs]et_task_comm (which lock
85048 it with task_lock())
85049 @@ -1410,6 +1441,10 @@ struct task_struct {
85050 #endif
85051 /* CPU-specific state of this task */
85052 struct thread_struct thread;
85053 +/* thread_info moved to task_struct */
85054 +#ifdef CONFIG_X86
85055 + struct thread_info tinfo;
85056 +#endif
85057 /* filesystem information */
85058 struct fs_struct *fs;
85059 /* open file information */
85060 @@ -1484,6 +1519,10 @@ struct task_struct {
85061 gfp_t lockdep_reclaim_gfp;
85062 #endif
85063
85064 +/* process credentials */
85065 + const struct cred __rcu *real_cred; /* objective and real subjective task
85066 + * credentials (COW) */
85067 +
85068 /* journalling filesystem info */
85069 void *journal_info;
85070
85071 @@ -1522,6 +1561,10 @@ struct task_struct {
85072 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85073 struct list_head cg_list;
85074 #endif
85075 +
85076 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85077 + * credentials (COW) */
85078 +
85079 #ifdef CONFIG_FUTEX
85080 struct robust_list_head __user *robust_list;
85081 #ifdef CONFIG_COMPAT
85082 @@ -1635,7 +1678,7 @@ struct task_struct {
85083 * Number of functions that haven't been traced
85084 * because of depth overrun.
85085 */
85086 - atomic_t trace_overrun;
85087 + atomic_unchecked_t trace_overrun;
85088 /* Pause for the tracing */
85089 atomic_t tracing_graph_pause;
85090 #endif
85091 @@ -1661,7 +1704,78 @@ struct task_struct {
85092 unsigned int sequential_io;
85093 unsigned int sequential_io_avg;
85094 #endif
85095 -};
85096 +
85097 +#ifdef CONFIG_GRKERNSEC
85098 + /* grsecurity */
85099 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85100 + u64 exec_id;
85101 +#endif
85102 +#ifdef CONFIG_GRKERNSEC_SETXID
85103 + const struct cred *delayed_cred;
85104 +#endif
85105 + struct dentry *gr_chroot_dentry;
85106 + struct acl_subject_label *acl;
85107 + struct acl_subject_label *tmpacl;
85108 + struct acl_role_label *role;
85109 + struct file *exec_file;
85110 + unsigned long brute_expires;
85111 + u16 acl_role_id;
85112 + u8 inherited;
85113 + /* is this the task that authenticated to the special role */
85114 + u8 acl_sp_role;
85115 + u8 is_writable;
85116 + u8 brute;
85117 + u8 gr_is_chrooted;
85118 +#endif
85119 +
85120 +} __randomize_layout;
85121 +
85122 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85123 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85124 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85125 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85126 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85127 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85128 +
85129 +#ifdef CONFIG_PAX_SOFTMODE
85130 +extern int pax_softmode;
85131 +#endif
85132 +
85133 +extern int pax_check_flags(unsigned long *);
85134 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85135 +
85136 +/* if tsk != current then task_lock must be held on it */
85137 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85138 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85139 +{
85140 + if (likely(tsk->mm))
85141 + return tsk->mm->pax_flags;
85142 + else
85143 + return 0UL;
85144 +}
85145 +
85146 +/* if tsk != current then task_lock must be held on it */
85147 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85148 +{
85149 + if (likely(tsk->mm)) {
85150 + tsk->mm->pax_flags = flags;
85151 + return 0;
85152 + }
85153 + return -EINVAL;
85154 +}
85155 +#endif
85156 +
85157 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85158 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85159 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85160 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85161 +#endif
85162 +
85163 +struct path;
85164 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85165 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85166 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85167 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85168
85169 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85170 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85171 @@ -1743,7 +1857,7 @@ struct pid_namespace;
85172 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85173 struct pid_namespace *ns);
85174
85175 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85176 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85177 {
85178 return tsk->pid;
85179 }
85180 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
85181
85182 extern void sched_clock_init(void);
85183
85184 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85185 +static inline void populate_stack(void)
85186 +{
85187 + struct task_struct *curtask = current;
85188 + int c;
85189 + int *ptr = curtask->stack;
85190 + int *end = curtask->stack + THREAD_SIZE;
85191 +
85192 + while (ptr < end) {
85193 + c = *(volatile int *)ptr;
85194 + ptr += PAGE_SIZE/sizeof(int);
85195 + }
85196 +}
85197 +#else
85198 +static inline void populate_stack(void)
85199 +{
85200 +}
85201 +#endif
85202 +
85203 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85204 static inline void sched_clock_tick(void)
85205 {
85206 @@ -2239,7 +2372,9 @@ void yield(void);
85207 extern struct exec_domain default_exec_domain;
85208
85209 union thread_union {
85210 +#ifndef CONFIG_X86
85211 struct thread_info thread_info;
85212 +#endif
85213 unsigned long stack[THREAD_SIZE/sizeof(long)];
85214 };
85215
85216 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
85217 */
85218
85219 extern struct task_struct *find_task_by_vpid(pid_t nr);
85220 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85221 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85222 struct pid_namespace *ns);
85223
85224 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85225 extern void exit_itimers(struct signal_struct *);
85226 extern void flush_itimer_signals(void);
85227
85228 -extern void do_group_exit(int);
85229 +extern __noreturn void do_group_exit(int);
85230
85231 extern int do_execve(struct filename *,
85232 const char __user * const __user *,
85233 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85234 #define task_stack_end_corrupted(task) \
85235 (*(end_of_stack(task)) != STACK_END_MAGIC)
85236
85237 -static inline int object_is_on_stack(void *obj)
85238 +static inline int object_starts_on_stack(const void *obj)
85239 {
85240 - void *stack = task_stack_page(current);
85241 + const void *stack = task_stack_page(current);
85242
85243 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85244 }
85245 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85246 index 596a0e0..bea77ec 100644
85247 --- a/include/linux/sched/sysctl.h
85248 +++ b/include/linux/sched/sysctl.h
85249 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85250 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85251
85252 extern int sysctl_max_map_count;
85253 +extern unsigned long sysctl_heap_stack_gap;
85254
85255 extern unsigned int sysctl_sched_latency;
85256 extern unsigned int sysctl_sched_min_granularity;
85257 diff --git a/include/linux/security.h b/include/linux/security.h
85258 index ba96471..74fb3f6 100644
85259 --- a/include/linux/security.h
85260 +++ b/include/linux/security.h
85261 @@ -27,6 +27,7 @@
85262 #include <linux/slab.h>
85263 #include <linux/err.h>
85264 #include <linux/string.h>
85265 +#include <linux/grsecurity.h>
85266
85267 struct linux_binprm;
85268 struct cred;
85269 @@ -116,8 +117,6 @@ struct seq_file;
85270
85271 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85272
85273 -void reset_security_ops(void);
85274 -
85275 #ifdef CONFIG_MMU
85276 extern unsigned long mmap_min_addr;
85277 extern unsigned long dac_mmap_min_addr;
85278 @@ -1729,7 +1728,7 @@ struct security_operations {
85279 struct audit_context *actx);
85280 void (*audit_rule_free) (void *lsmrule);
85281 #endif /* CONFIG_AUDIT */
85282 -};
85283 +} __randomize_layout;
85284
85285 /* prototypes */
85286 extern int security_init(void);
85287 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85288 index dc368b8..e895209 100644
85289 --- a/include/linux/semaphore.h
85290 +++ b/include/linux/semaphore.h
85291 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85292 }
85293
85294 extern void down(struct semaphore *sem);
85295 -extern int __must_check down_interruptible(struct semaphore *sem);
85296 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85297 extern int __must_check down_killable(struct semaphore *sem);
85298 extern int __must_check down_trylock(struct semaphore *sem);
85299 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85300 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85301 index 52e0097..383f21d 100644
85302 --- a/include/linux/seq_file.h
85303 +++ b/include/linux/seq_file.h
85304 @@ -27,6 +27,9 @@ struct seq_file {
85305 struct mutex lock;
85306 const struct seq_operations *op;
85307 int poll_event;
85308 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85309 + u64 exec_id;
85310 +#endif
85311 #ifdef CONFIG_USER_NS
85312 struct user_namespace *user_ns;
85313 #endif
85314 @@ -39,6 +42,7 @@ struct seq_operations {
85315 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85316 int (*show) (struct seq_file *m, void *v);
85317 };
85318 +typedef struct seq_operations __no_const seq_operations_no_const;
85319
85320 #define SEQ_SKIP 1
85321
85322 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85323
85324 char *mangle_path(char *s, const char *p, const char *esc);
85325 int seq_open(struct file *, const struct seq_operations *);
85326 +int seq_open_restrict(struct file *, const struct seq_operations *);
85327 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85328 loff_t seq_lseek(struct file *, loff_t, int);
85329 int seq_release(struct inode *, struct file *);
85330 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85331 }
85332
85333 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85334 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85335 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85336 int single_release(struct inode *, struct file *);
85337 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85338 diff --git a/include/linux/shm.h b/include/linux/shm.h
85339 index 6fb8016..ab4465e 100644
85340 --- a/include/linux/shm.h
85341 +++ b/include/linux/shm.h
85342 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85343 /* The task created the shm object. NULL if the task is dead. */
85344 struct task_struct *shm_creator;
85345 struct list_head shm_clist; /* list by creator */
85346 +#ifdef CONFIG_GRKERNSEC
85347 + u64 shm_createtime;
85348 + pid_t shm_lapid;
85349 +#endif
85350 };
85351
85352 /* shm_mode upper byte flags */
85353 diff --git a/include/linux/signal.h b/include/linux/signal.h
85354 index ab1e039..ad4229e 100644
85355 --- a/include/linux/signal.h
85356 +++ b/include/linux/signal.h
85357 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85358 * know it'll be handled, so that they don't get converted to
85359 * SIGKILL or just silently dropped.
85360 */
85361 - kernel_sigaction(sig, (__force __sighandler_t)2);
85362 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85363 }
85364
85365 static inline void disallow_signal(int sig)
85366 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85367 index 6c8b6f6..5a0f4bd 100644
85368 --- a/include/linux/skbuff.h
85369 +++ b/include/linux/skbuff.h
85370 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85371 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85372 int node);
85373 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85374 -static inline struct sk_buff *alloc_skb(unsigned int size,
85375 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85376 gfp_t priority)
85377 {
85378 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85379 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85380 return skb->inner_transport_header - skb->inner_network_header;
85381 }
85382
85383 -static inline int skb_network_offset(const struct sk_buff *skb)
85384 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85385 {
85386 return skb_network_header(skb) - skb->data;
85387 }
85388 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85389 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85390 */
85391 #ifndef NET_SKB_PAD
85392 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85393 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85394 #endif
85395
85396 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85397 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85398 int *err);
85399 unsigned int datagram_poll(struct file *file, struct socket *sock,
85400 struct poll_table_struct *wait);
85401 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85402 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85403 struct iovec *to, int size);
85404 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85405 struct iovec *iov);
85406 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85407 nf_bridge_put(skb->nf_bridge);
85408 skb->nf_bridge = NULL;
85409 #endif
85410 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85411 + skb->nf_trace = 0;
85412 +#endif
85413 }
85414
85415 static inline void nf_reset_trace(struct sk_buff *skb)
85416 diff --git a/include/linux/slab.h b/include/linux/slab.h
85417 index c265bec..4867d28 100644
85418 --- a/include/linux/slab.h
85419 +++ b/include/linux/slab.h
85420 @@ -14,15 +14,29 @@
85421 #include <linux/gfp.h>
85422 #include <linux/types.h>
85423 #include <linux/workqueue.h>
85424 -
85425 +#include <linux/err.h>
85426
85427 /*
85428 * Flags to pass to kmem_cache_create().
85429 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85430 */
85431 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85432 +
85433 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85434 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85435 +#else
85436 +#define SLAB_USERCOPY 0x00000000UL
85437 +#endif
85438 +
85439 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85440 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85441 +
85442 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85443 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85444 +#else
85445 +#define SLAB_NO_SANITIZE 0x00000000UL
85446 +#endif
85447 +
85448 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85449 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85450 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85451 @@ -98,10 +112,13 @@
85452 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85453 * Both make kfree a no-op.
85454 */
85455 -#define ZERO_SIZE_PTR ((void *)16)
85456 +#define ZERO_SIZE_PTR \
85457 +({ \
85458 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85459 + (void *)(-MAX_ERRNO-1L); \
85460 +})
85461
85462 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85463 - (unsigned long)ZERO_SIZE_PTR)
85464 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85465
85466 #include <linux/kmemleak.h>
85467
85468 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85469 void kfree(const void *);
85470 void kzfree(const void *);
85471 size_t ksize(const void *);
85472 +const char *check_heap_object(const void *ptr, unsigned long n);
85473 +bool is_usercopy_object(const void *ptr);
85474
85475 /*
85476 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85477 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85478 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85479 #endif
85480
85481 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85482 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85483 +#endif
85484 +
85485 /*
85486 * Figure out which kmalloc slab an allocation of a certain size
85487 * belongs to.
85488 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85489 * 2 = 120 .. 192 bytes
85490 * n = 2^(n-1) .. 2^n -1
85491 */
85492 -static __always_inline int kmalloc_index(size_t size)
85493 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85494 {
85495 if (!size)
85496 return 0;
85497 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85498 }
85499 #endif /* !CONFIG_SLOB */
85500
85501 -void *__kmalloc(size_t size, gfp_t flags);
85502 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85503 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85504
85505 #ifdef CONFIG_NUMA
85506 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85507 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85508 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85509 #else
85510 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85511 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85512 index b869d16..1453c73 100644
85513 --- a/include/linux/slab_def.h
85514 +++ b/include/linux/slab_def.h
85515 @@ -40,7 +40,7 @@ struct kmem_cache {
85516 /* 4) cache creation/removal */
85517 const char *name;
85518 struct list_head list;
85519 - int refcount;
85520 + atomic_t refcount;
85521 int object_size;
85522 int align;
85523
85524 @@ -56,10 +56,14 @@ struct kmem_cache {
85525 unsigned long node_allocs;
85526 unsigned long node_frees;
85527 unsigned long node_overflow;
85528 - atomic_t allochit;
85529 - atomic_t allocmiss;
85530 - atomic_t freehit;
85531 - atomic_t freemiss;
85532 + atomic_unchecked_t allochit;
85533 + atomic_unchecked_t allocmiss;
85534 + atomic_unchecked_t freehit;
85535 + atomic_unchecked_t freemiss;
85536 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85537 + atomic_unchecked_t sanitized;
85538 + atomic_unchecked_t not_sanitized;
85539 +#endif
85540
85541 /*
85542 * If debugging is enabled, then the allocator can add additional
85543 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85544 index d82abd4..408c3a0 100644
85545 --- a/include/linux/slub_def.h
85546 +++ b/include/linux/slub_def.h
85547 @@ -74,7 +74,7 @@ struct kmem_cache {
85548 struct kmem_cache_order_objects max;
85549 struct kmem_cache_order_objects min;
85550 gfp_t allocflags; /* gfp flags to use on each alloc */
85551 - int refcount; /* Refcount for slab cache destroy */
85552 + atomic_t refcount; /* Refcount for slab cache destroy */
85553 void (*ctor)(void *);
85554 int inuse; /* Offset to metadata */
85555 int align; /* Alignment */
85556 diff --git a/include/linux/smp.h b/include/linux/smp.h
85557 index 93dff5f..933c561 100644
85558 --- a/include/linux/smp.h
85559 +++ b/include/linux/smp.h
85560 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85561 #endif
85562
85563 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85564 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85565 #define put_cpu() preempt_enable()
85566 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85567
85568 /*
85569 * Callback to arch code if there's nosmp or maxcpus=0 on the
85570 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85571 index 46cca4c..3323536 100644
85572 --- a/include/linux/sock_diag.h
85573 +++ b/include/linux/sock_diag.h
85574 @@ -11,7 +11,7 @@ struct sock;
85575 struct sock_diag_handler {
85576 __u8 family;
85577 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85578 -};
85579 +} __do_const;
85580
85581 int sock_diag_register(const struct sock_diag_handler *h);
85582 void sock_diag_unregister(const struct sock_diag_handler *h);
85583 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85584 index 680f9a3..f13aeb0 100644
85585 --- a/include/linux/sonet.h
85586 +++ b/include/linux/sonet.h
85587 @@ -7,7 +7,7 @@
85588 #include <uapi/linux/sonet.h>
85589
85590 struct k_sonet_stats {
85591 -#define __HANDLE_ITEM(i) atomic_t i
85592 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85593 __SONET_ITEMS
85594 #undef __HANDLE_ITEM
85595 };
85596 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85597 index 07d8e53..dc934c9 100644
85598 --- a/include/linux/sunrpc/addr.h
85599 +++ b/include/linux/sunrpc/addr.h
85600 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85601 {
85602 switch (sap->sa_family) {
85603 case AF_INET:
85604 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85605 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85606 case AF_INET6:
85607 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85608 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85609 }
85610 return 0;
85611 }
85612 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85613 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85614 const struct sockaddr *src)
85615 {
85616 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85617 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85618 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85619
85620 dsin->sin_family = ssin->sin_family;
85621 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85622 if (sa->sa_family != AF_INET6)
85623 return 0;
85624
85625 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85626 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85627 }
85628
85629 #endif /* _LINUX_SUNRPC_ADDR_H */
85630 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85631 index 70736b9..37f33db 100644
85632 --- a/include/linux/sunrpc/clnt.h
85633 +++ b/include/linux/sunrpc/clnt.h
85634 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85635 unsigned int p_timer; /* Which RTT timer to use */
85636 u32 p_statidx; /* Which procedure to account */
85637 const char * p_name; /* name of procedure */
85638 -};
85639 +} __do_const;
85640
85641 #ifdef __KERNEL__
85642
85643 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85644 index 2167846..0648fc3 100644
85645 --- a/include/linux/sunrpc/svc.h
85646 +++ b/include/linux/sunrpc/svc.h
85647 @@ -416,7 +416,7 @@ struct svc_procedure {
85648 unsigned int pc_count; /* call count */
85649 unsigned int pc_cachetype; /* cache info (NFS) */
85650 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85651 -};
85652 +} __do_const;
85653
85654 /*
85655 * Function prototypes.
85656 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85657 index 975da75..318c083 100644
85658 --- a/include/linux/sunrpc/svc_rdma.h
85659 +++ b/include/linux/sunrpc/svc_rdma.h
85660 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85661 extern unsigned int svcrdma_max_requests;
85662 extern unsigned int svcrdma_max_req_size;
85663
85664 -extern atomic_t rdma_stat_recv;
85665 -extern atomic_t rdma_stat_read;
85666 -extern atomic_t rdma_stat_write;
85667 -extern atomic_t rdma_stat_sq_starve;
85668 -extern atomic_t rdma_stat_rq_starve;
85669 -extern atomic_t rdma_stat_rq_poll;
85670 -extern atomic_t rdma_stat_rq_prod;
85671 -extern atomic_t rdma_stat_sq_poll;
85672 -extern atomic_t rdma_stat_sq_prod;
85673 +extern atomic_unchecked_t rdma_stat_recv;
85674 +extern atomic_unchecked_t rdma_stat_read;
85675 +extern atomic_unchecked_t rdma_stat_write;
85676 +extern atomic_unchecked_t rdma_stat_sq_starve;
85677 +extern atomic_unchecked_t rdma_stat_rq_starve;
85678 +extern atomic_unchecked_t rdma_stat_rq_poll;
85679 +extern atomic_unchecked_t rdma_stat_rq_prod;
85680 +extern atomic_unchecked_t rdma_stat_sq_poll;
85681 +extern atomic_unchecked_t rdma_stat_sq_prod;
85682
85683 #define RPCRDMA_VERSION 1
85684
85685 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85686 index 8d71d65..f79586e 100644
85687 --- a/include/linux/sunrpc/svcauth.h
85688 +++ b/include/linux/sunrpc/svcauth.h
85689 @@ -120,7 +120,7 @@ struct auth_ops {
85690 int (*release)(struct svc_rqst *rq);
85691 void (*domain_release)(struct auth_domain *);
85692 int (*set_client)(struct svc_rqst *rq);
85693 -};
85694 +} __do_const;
85695
85696 #define SVC_GARBAGE 1
85697 #define SVC_SYSERR 2
85698 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85699 index e7a018e..49f8b17 100644
85700 --- a/include/linux/swiotlb.h
85701 +++ b/include/linux/swiotlb.h
85702 @@ -60,7 +60,8 @@ extern void
85703
85704 extern void
85705 swiotlb_free_coherent(struct device *hwdev, size_t size,
85706 - void *vaddr, dma_addr_t dma_handle);
85707 + void *vaddr, dma_addr_t dma_handle,
85708 + struct dma_attrs *attrs);
85709
85710 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85711 unsigned long offset, size_t size,
85712 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85713 index bda9b81..629e06e 100644
85714 --- a/include/linux/syscalls.h
85715 +++ b/include/linux/syscalls.h
85716 @@ -99,10 +99,16 @@ union bpf_attr;
85717 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85718
85719 #define __SC_DECL(t, a) t a
85720 +#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))
85721 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85722 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85723 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85724 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85725 +#define __SC_LONG(t, a) __typeof( \
85726 + __builtin_choose_expr( \
85727 + sizeof(t) > sizeof(int), \
85728 + (t) 0, \
85729 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85730 + )) a
85731 #define __SC_CAST(t, a) (t) a
85732 #define __SC_ARGS(t, a) a
85733 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85734 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85735 asmlinkage long sys_fsync(unsigned int fd);
85736 asmlinkage long sys_fdatasync(unsigned int fd);
85737 asmlinkage long sys_bdflush(int func, long data);
85738 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85739 - char __user *type, unsigned long flags,
85740 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85741 + const char __user *type, unsigned long flags,
85742 void __user *data);
85743 -asmlinkage long sys_umount(char __user *name, int flags);
85744 -asmlinkage long sys_oldumount(char __user *name);
85745 +asmlinkage long sys_umount(const char __user *name, int flags);
85746 +asmlinkage long sys_oldumount(const char __user *name);
85747 asmlinkage long sys_truncate(const char __user *path, long length);
85748 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85749 asmlinkage long sys_stat(const char __user *filename,
85750 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85751 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85752 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85753 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85754 - struct sockaddr __user *, int);
85755 + struct sockaddr __user *, int) __intentional_overflow(0);
85756 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85757 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85758 unsigned int vlen, unsigned flags);
85759 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85760 index 27b3b0b..e093dd9 100644
85761 --- a/include/linux/syscore_ops.h
85762 +++ b/include/linux/syscore_ops.h
85763 @@ -16,7 +16,7 @@ struct syscore_ops {
85764 int (*suspend)(void);
85765 void (*resume)(void);
85766 void (*shutdown)(void);
85767 -};
85768 +} __do_const;
85769
85770 extern void register_syscore_ops(struct syscore_ops *ops);
85771 extern void unregister_syscore_ops(struct syscore_ops *ops);
85772 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85773 index b7361f8..341a15a 100644
85774 --- a/include/linux/sysctl.h
85775 +++ b/include/linux/sysctl.h
85776 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85777
85778 extern int proc_dostring(struct ctl_table *, int,
85779 void __user *, size_t *, loff_t *);
85780 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85781 + void __user *, size_t *, loff_t *);
85782 extern int proc_dointvec(struct ctl_table *, int,
85783 void __user *, size_t *, loff_t *);
85784 extern int proc_dointvec_minmax(struct ctl_table *, int,
85785 @@ -113,7 +115,8 @@ struct ctl_table
85786 struct ctl_table_poll *poll;
85787 void *extra1;
85788 void *extra2;
85789 -};
85790 +} __do_const __randomize_layout;
85791 +typedef struct ctl_table __no_const ctl_table_no_const;
85792
85793 struct ctl_node {
85794 struct rb_node node;
85795 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85796 index f97d0db..c1187dc 100644
85797 --- a/include/linux/sysfs.h
85798 +++ b/include/linux/sysfs.h
85799 @@ -34,7 +34,8 @@ struct attribute {
85800 struct lock_class_key *key;
85801 struct lock_class_key skey;
85802 #endif
85803 -};
85804 +} __do_const;
85805 +typedef struct attribute __no_const attribute_no_const;
85806
85807 /**
85808 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85809 @@ -63,7 +64,8 @@ struct attribute_group {
85810 struct attribute *, int);
85811 struct attribute **attrs;
85812 struct bin_attribute **bin_attrs;
85813 -};
85814 +} __do_const;
85815 +typedef struct attribute_group __no_const attribute_group_no_const;
85816
85817 /**
85818 * Use these macros to make defining attributes easier. See include/linux/device.h
85819 @@ -128,7 +130,8 @@ struct bin_attribute {
85820 char *, loff_t, size_t);
85821 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85822 struct vm_area_struct *vma);
85823 -};
85824 +} __do_const;
85825 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85826
85827 /**
85828 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85829 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85830 index 387fa7d..3fcde6b 100644
85831 --- a/include/linux/sysrq.h
85832 +++ b/include/linux/sysrq.h
85833 @@ -16,6 +16,7 @@
85834
85835 #include <linux/errno.h>
85836 #include <linux/types.h>
85837 +#include <linux/compiler.h>
85838
85839 /* Possible values of bitmask for enabling sysrq functions */
85840 /* 0x0001 is reserved for enable everything */
85841 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85842 char *help_msg;
85843 char *action_msg;
85844 int enable_mask;
85845 -};
85846 +} __do_const;
85847
85848 #ifdef CONFIG_MAGIC_SYSRQ
85849
85850 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85851 index ff307b5..f1a4468 100644
85852 --- a/include/linux/thread_info.h
85853 +++ b/include/linux/thread_info.h
85854 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85855 #error "no set_restore_sigmask() provided and default one won't work"
85856 #endif
85857
85858 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85859 +
85860 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85861 +{
85862 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85863 +}
85864 +
85865 #endif /* __KERNEL__ */
85866
85867 #endif /* _LINUX_THREAD_INFO_H */
85868 diff --git a/include/linux/tty.h b/include/linux/tty.h
85869 index 5171ef8..1048d83e 100644
85870 --- a/include/linux/tty.h
85871 +++ b/include/linux/tty.h
85872 @@ -202,7 +202,7 @@ struct tty_port {
85873 const struct tty_port_operations *ops; /* Port operations */
85874 spinlock_t lock; /* Lock protecting tty field */
85875 int blocked_open; /* Waiting to open */
85876 - int count; /* Usage count */
85877 + atomic_t count; /* Usage count */
85878 wait_queue_head_t open_wait; /* Open waiters */
85879 wait_queue_head_t close_wait; /* Close waiters */
85880 wait_queue_head_t delta_msr_wait; /* Modem status change */
85881 @@ -290,7 +290,7 @@ struct tty_struct {
85882 /* If the tty has a pending do_SAK, queue it here - akpm */
85883 struct work_struct SAK_work;
85884 struct tty_port *port;
85885 -};
85886 +} __randomize_layout;
85887
85888 /* Each of a tty's open files has private_data pointing to tty_file_private */
85889 struct tty_file_private {
85890 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85891 struct tty_struct *tty, struct file *filp);
85892 static inline int tty_port_users(struct tty_port *port)
85893 {
85894 - return port->count + port->blocked_open;
85895 + return atomic_read(&port->count) + port->blocked_open;
85896 }
85897
85898 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85899 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85900 index 92e337c..f46757b 100644
85901 --- a/include/linux/tty_driver.h
85902 +++ b/include/linux/tty_driver.h
85903 @@ -291,7 +291,7 @@ struct tty_operations {
85904 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85905 #endif
85906 const struct file_operations *proc_fops;
85907 -};
85908 +} __do_const __randomize_layout;
85909
85910 struct tty_driver {
85911 int magic; /* magic number for this structure */
85912 @@ -325,7 +325,7 @@ struct tty_driver {
85913
85914 const struct tty_operations *ops;
85915 struct list_head tty_drivers;
85916 -};
85917 +} __randomize_layout;
85918
85919 extern struct list_head tty_drivers;
85920
85921 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85922 index 00c9d68..bc0188b 100644
85923 --- a/include/linux/tty_ldisc.h
85924 +++ b/include/linux/tty_ldisc.h
85925 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85926
85927 struct module *owner;
85928
85929 - int refcount;
85930 + atomic_t refcount;
85931 };
85932
85933 struct tty_ldisc {
85934 diff --git a/include/linux/types.h b/include/linux/types.h
85935 index a0bb704..f511c77 100644
85936 --- a/include/linux/types.h
85937 +++ b/include/linux/types.h
85938 @@ -177,10 +177,26 @@ typedef struct {
85939 int counter;
85940 } atomic_t;
85941
85942 +#ifdef CONFIG_PAX_REFCOUNT
85943 +typedef struct {
85944 + int counter;
85945 +} atomic_unchecked_t;
85946 +#else
85947 +typedef atomic_t atomic_unchecked_t;
85948 +#endif
85949 +
85950 #ifdef CONFIG_64BIT
85951 typedef struct {
85952 long counter;
85953 } atomic64_t;
85954 +
85955 +#ifdef CONFIG_PAX_REFCOUNT
85956 +typedef struct {
85957 + long counter;
85958 +} atomic64_unchecked_t;
85959 +#else
85960 +typedef atomic64_t atomic64_unchecked_t;
85961 +#endif
85962 #endif
85963
85964 struct list_head {
85965 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85966 index ecd3319..8a36ded 100644
85967 --- a/include/linux/uaccess.h
85968 +++ b/include/linux/uaccess.h
85969 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85970 long ret; \
85971 mm_segment_t old_fs = get_fs(); \
85972 \
85973 - set_fs(KERNEL_DS); \
85974 pagefault_disable(); \
85975 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85976 - pagefault_enable(); \
85977 + set_fs(KERNEL_DS); \
85978 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85979 set_fs(old_fs); \
85980 + pagefault_enable(); \
85981 ret; \
85982 })
85983
85984 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85985 index 2d1f9b6..d7a9fce 100644
85986 --- a/include/linux/uidgid.h
85987 +++ b/include/linux/uidgid.h
85988 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85989
85990 #endif /* CONFIG_USER_NS */
85991
85992 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85993 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85994 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85995 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85996 +
85997 #endif /* _LINUX_UIDGID_H */
85998 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85999 index baa8171..9ca98ba 100644
86000 --- a/include/linux/uio_driver.h
86001 +++ b/include/linux/uio_driver.h
86002 @@ -67,7 +67,7 @@ struct uio_device {
86003 struct module *owner;
86004 struct device *dev;
86005 int minor;
86006 - atomic_t event;
86007 + atomic_unchecked_t event;
86008 struct fasync_struct *async_queue;
86009 wait_queue_head_t wait;
86010 struct uio_info *info;
86011 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86012 index 99c1b4d..562e6f3 100644
86013 --- a/include/linux/unaligned/access_ok.h
86014 +++ b/include/linux/unaligned/access_ok.h
86015 @@ -4,34 +4,34 @@
86016 #include <linux/kernel.h>
86017 #include <asm/byteorder.h>
86018
86019 -static inline u16 get_unaligned_le16(const void *p)
86020 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86021 {
86022 - return le16_to_cpup((__le16 *)p);
86023 + return le16_to_cpup((const __le16 *)p);
86024 }
86025
86026 -static inline u32 get_unaligned_le32(const void *p)
86027 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86028 {
86029 - return le32_to_cpup((__le32 *)p);
86030 + return le32_to_cpup((const __le32 *)p);
86031 }
86032
86033 -static inline u64 get_unaligned_le64(const void *p)
86034 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86035 {
86036 - return le64_to_cpup((__le64 *)p);
86037 + return le64_to_cpup((const __le64 *)p);
86038 }
86039
86040 -static inline u16 get_unaligned_be16(const void *p)
86041 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86042 {
86043 - return be16_to_cpup((__be16 *)p);
86044 + return be16_to_cpup((const __be16 *)p);
86045 }
86046
86047 -static inline u32 get_unaligned_be32(const void *p)
86048 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86049 {
86050 - return be32_to_cpup((__be32 *)p);
86051 + return be32_to_cpup((const __be32 *)p);
86052 }
86053
86054 -static inline u64 get_unaligned_be64(const void *p)
86055 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86056 {
86057 - return be64_to_cpup((__be64 *)p);
86058 + return be64_to_cpup((const __be64 *)p);
86059 }
86060
86061 static inline void put_unaligned_le16(u16 val, void *p)
86062 diff --git a/include/linux/usb.h b/include/linux/usb.h
86063 index 447a7e2..9cea7e9 100644
86064 --- a/include/linux/usb.h
86065 +++ b/include/linux/usb.h
86066 @@ -571,7 +571,7 @@ struct usb_device {
86067 int maxchild;
86068
86069 u32 quirks;
86070 - atomic_t urbnum;
86071 + atomic_unchecked_t urbnum;
86072
86073 unsigned long active_duration;
86074
86075 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86076
86077 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86078 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86079 - void *data, __u16 size, int timeout);
86080 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
86081 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86082 void *data, int len, int *actual_length, int timeout);
86083 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86084 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86085 index d5952bb..9a626d4 100644
86086 --- a/include/linux/usb/renesas_usbhs.h
86087 +++ b/include/linux/usb/renesas_usbhs.h
86088 @@ -39,7 +39,7 @@ enum {
86089 */
86090 struct renesas_usbhs_driver_callback {
86091 int (*notify_hotplug)(struct platform_device *pdev);
86092 -};
86093 +} __no_const;
86094
86095 /*
86096 * callback functions for platform
86097 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86098 index 9f3579f..3b2afa5 100644
86099 --- a/include/linux/user_namespace.h
86100 +++ b/include/linux/user_namespace.h
86101 @@ -38,7 +38,7 @@ struct user_namespace {
86102 struct key *persistent_keyring_register;
86103 struct rw_semaphore persistent_keyring_register_sem;
86104 #endif
86105 -};
86106 +} __randomize_layout;
86107
86108 extern struct user_namespace init_user_ns;
86109
86110 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86111 index 239e277..22a5cf5 100644
86112 --- a/include/linux/utsname.h
86113 +++ b/include/linux/utsname.h
86114 @@ -24,7 +24,7 @@ struct uts_namespace {
86115 struct new_utsname name;
86116 struct user_namespace *user_ns;
86117 unsigned int proc_inum;
86118 -};
86119 +} __randomize_layout;
86120 extern struct uts_namespace init_uts_ns;
86121
86122 #ifdef CONFIG_UTS_NS
86123 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86124 index 6f8fbcf..4efc177 100644
86125 --- a/include/linux/vermagic.h
86126 +++ b/include/linux/vermagic.h
86127 @@ -25,9 +25,42 @@
86128 #define MODULE_ARCH_VERMAGIC ""
86129 #endif
86130
86131 +#ifdef CONFIG_PAX_REFCOUNT
86132 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86133 +#else
86134 +#define MODULE_PAX_REFCOUNT ""
86135 +#endif
86136 +
86137 +#ifdef CONSTIFY_PLUGIN
86138 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86139 +#else
86140 +#define MODULE_CONSTIFY_PLUGIN ""
86141 +#endif
86142 +
86143 +#ifdef STACKLEAK_PLUGIN
86144 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86145 +#else
86146 +#define MODULE_STACKLEAK_PLUGIN ""
86147 +#endif
86148 +
86149 +#ifdef RANDSTRUCT_PLUGIN
86150 +#include <generated/randomize_layout_hash.h>
86151 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86152 +#else
86153 +#define MODULE_RANDSTRUCT_PLUGIN
86154 +#endif
86155 +
86156 +#ifdef CONFIG_GRKERNSEC
86157 +#define MODULE_GRSEC "GRSEC "
86158 +#else
86159 +#define MODULE_GRSEC ""
86160 +#endif
86161 +
86162 #define VERMAGIC_STRING \
86163 UTS_RELEASE " " \
86164 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86165 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86166 - MODULE_ARCH_VERMAGIC
86167 + MODULE_ARCH_VERMAGIC \
86168 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86169 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86170
86171 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86172 index b483abd..af305ad 100644
86173 --- a/include/linux/vga_switcheroo.h
86174 +++ b/include/linux/vga_switcheroo.h
86175 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86176
86177 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86178
86179 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86180 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86181 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86182 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86183 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86184 #else
86185
86186 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86187 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86188
86189 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86190
86191 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86192 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86193 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86194 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86195 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86196
86197 #endif
86198 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86199 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86200 index b87696f..1d11de7 100644
86201 --- a/include/linux/vmalloc.h
86202 +++ b/include/linux/vmalloc.h
86203 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86204 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86205 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86206 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86207 +
86208 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86209 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86210 +#endif
86211 +
86212 /* bits [20..32] reserved for arch specific ioremap internals */
86213
86214 /*
86215 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86216 unsigned long flags, pgprot_t prot);
86217 extern void vunmap(const void *addr);
86218
86219 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86220 +extern void unmap_process_stacks(struct task_struct *task);
86221 +#endif
86222 +
86223 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86224 unsigned long uaddr, void *kaddr,
86225 unsigned long size);
86226 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86227
86228 /* for /dev/kmem */
86229 extern long vread(char *buf, char *addr, unsigned long count);
86230 -extern long vwrite(char *buf, char *addr, unsigned long count);
86231 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86232
86233 /*
86234 * Internals. Dont't use..
86235 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86236 index 82e7db7..f8ce3d0 100644
86237 --- a/include/linux/vmstat.h
86238 +++ b/include/linux/vmstat.h
86239 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86240 /*
86241 * Zone based page accounting with per cpu differentials.
86242 */
86243 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86244 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86245
86246 static inline void zone_page_state_add(long x, struct zone *zone,
86247 enum zone_stat_item item)
86248 {
86249 - atomic_long_add(x, &zone->vm_stat[item]);
86250 - atomic_long_add(x, &vm_stat[item]);
86251 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86252 + atomic_long_add_unchecked(x, &vm_stat[item]);
86253 }
86254
86255 -static inline unsigned long global_page_state(enum zone_stat_item item)
86256 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86257 {
86258 - long x = atomic_long_read(&vm_stat[item]);
86259 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86260 #ifdef CONFIG_SMP
86261 if (x < 0)
86262 x = 0;
86263 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86264 return x;
86265 }
86266
86267 -static inline unsigned long zone_page_state(struct zone *zone,
86268 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86269 enum zone_stat_item item)
86270 {
86271 - long x = atomic_long_read(&zone->vm_stat[item]);
86272 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86273 #ifdef CONFIG_SMP
86274 if (x < 0)
86275 x = 0;
86276 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86277 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86278 enum zone_stat_item item)
86279 {
86280 - long x = atomic_long_read(&zone->vm_stat[item]);
86281 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86282
86283 #ifdef CONFIG_SMP
86284 int cpu;
86285 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86286
86287 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86288 {
86289 - atomic_long_inc(&zone->vm_stat[item]);
86290 - atomic_long_inc(&vm_stat[item]);
86291 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86292 + atomic_long_inc_unchecked(&vm_stat[item]);
86293 }
86294
86295 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86296 {
86297 - atomic_long_dec(&zone->vm_stat[item]);
86298 - atomic_long_dec(&vm_stat[item]);
86299 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86300 + atomic_long_dec_unchecked(&vm_stat[item]);
86301 }
86302
86303 static inline void __inc_zone_page_state(struct page *page,
86304 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86305 index 91b0a68..0e9adf6 100644
86306 --- a/include/linux/xattr.h
86307 +++ b/include/linux/xattr.h
86308 @@ -28,7 +28,7 @@ struct xattr_handler {
86309 size_t size, int handler_flags);
86310 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86311 size_t size, int flags, int handler_flags);
86312 -};
86313 +} __do_const;
86314
86315 struct xattr {
86316 const char *name;
86317 @@ -37,6 +37,9 @@ struct xattr {
86318 };
86319
86320 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86321 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86322 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86323 +#endif
86324 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86325 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86326 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86327 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86328 index 92dbbd3..13ab0b3 100644
86329 --- a/include/linux/zlib.h
86330 +++ b/include/linux/zlib.h
86331 @@ -31,6 +31,7 @@
86332 #define _ZLIB_H
86333
86334 #include <linux/zconf.h>
86335 +#include <linux/compiler.h>
86336
86337 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86338 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86339 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86340
86341 /* basic functions */
86342
86343 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86344 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86345 /*
86346 Returns the number of bytes that needs to be allocated for a per-
86347 stream workspace with the specified parameters. A pointer to this
86348 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86349 index eb76cfd..9fd0e7c 100644
86350 --- a/include/media/v4l2-dev.h
86351 +++ b/include/media/v4l2-dev.h
86352 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86353 int (*mmap) (struct file *, struct vm_area_struct *);
86354 int (*open) (struct file *);
86355 int (*release) (struct file *);
86356 -};
86357 +} __do_const;
86358
86359 /*
86360 * Newer version of video_device, handled by videodev2.c
86361 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86362 index ffb69da..040393e 100644
86363 --- a/include/media/v4l2-device.h
86364 +++ b/include/media/v4l2-device.h
86365 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86366 this function returns 0. If the name ends with a digit (e.g. cx18),
86367 then the name will be set to cx18-0 since cx180 looks really odd. */
86368 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86369 - atomic_t *instance);
86370 + atomic_unchecked_t *instance);
86371
86372 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86373 Since the parent disappears this ensures that v4l2_dev doesn't have an
86374 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86375 index 2a25dec..bf6dd8a 100644
86376 --- a/include/net/9p/transport.h
86377 +++ b/include/net/9p/transport.h
86378 @@ -62,7 +62,7 @@ struct p9_trans_module {
86379 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86380 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86381 char *, char *, int , int, int, int);
86382 -};
86383 +} __do_const;
86384
86385 void v9fs_register_trans(struct p9_trans_module *m);
86386 void v9fs_unregister_trans(struct p9_trans_module *m);
86387 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86388 index a175ba4..196eb8242 100644
86389 --- a/include/net/af_unix.h
86390 +++ b/include/net/af_unix.h
86391 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86392 u32 secid; /* Security ID */
86393 #endif
86394 u32 consumed;
86395 -};
86396 +} __randomize_layout;
86397
86398 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86399 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86400 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86401 index ead99f0..6263c4b 100644
86402 --- a/include/net/bluetooth/l2cap.h
86403 +++ b/include/net/bluetooth/l2cap.h
86404 @@ -608,7 +608,7 @@ struct l2cap_ops {
86405 unsigned char *kdata,
86406 struct iovec *iov,
86407 int len);
86408 -};
86409 +} __do_const;
86410
86411 struct l2cap_conn {
86412 struct hci_conn *hcon;
86413 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86414 index f2ae33d..c457cf0 100644
86415 --- a/include/net/caif/cfctrl.h
86416 +++ b/include/net/caif/cfctrl.h
86417 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86418 void (*radioset_rsp)(void);
86419 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86420 struct cflayer *client_layer);
86421 -};
86422 +} __no_const;
86423
86424 /* Link Setup Parameters for CAIF-Links. */
86425 struct cfctrl_link_param {
86426 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86427 struct cfctrl {
86428 struct cfsrvl serv;
86429 struct cfctrl_rsp res;
86430 - atomic_t req_seq_no;
86431 - atomic_t rsp_seq_no;
86432 + atomic_unchecked_t req_seq_no;
86433 + atomic_unchecked_t rsp_seq_no;
86434 struct list_head list;
86435 /* Protects from simultaneous access to first_req list */
86436 spinlock_t info_list_lock;
86437 diff --git a/include/net/flow.h b/include/net/flow.h
86438 index 8109a15..504466d 100644
86439 --- a/include/net/flow.h
86440 +++ b/include/net/flow.h
86441 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86442
86443 void flow_cache_flush(struct net *net);
86444 void flow_cache_flush_deferred(struct net *net);
86445 -extern atomic_t flow_cache_genid;
86446 +extern atomic_unchecked_t flow_cache_genid;
86447
86448 #endif
86449 diff --git a/include/net/flow_keys.h b/include/net/flow_keys.h
86450 index 7ee2df0..dc8fd81 100644
86451 --- a/include/net/flow_keys.h
86452 +++ b/include/net/flow_keys.h
86453 @@ -22,9 +22,9 @@ struct flow_keys {
86454 __be32 ports;
86455 __be16 port16[2];
86456 };
86457 - u16 thoff;
86458 - u16 n_proto;
86459 - u8 ip_proto;
86460 + u16 thoff;
86461 + __be16 n_proto;
86462 + u8 ip_proto;
86463 };
86464
86465 bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
86466 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86467 index af10c2c..a431cc5 100644
86468 --- a/include/net/genetlink.h
86469 +++ b/include/net/genetlink.h
86470 @@ -120,7 +120,7 @@ struct genl_ops {
86471 u8 cmd;
86472 u8 internal_flags;
86473 u8 flags;
86474 -};
86475 +} __do_const;
86476
86477 int __genl_register_family(struct genl_family *family);
86478
86479 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86480 index 734d9b5..48a9a4b 100644
86481 --- a/include/net/gro_cells.h
86482 +++ b/include/net/gro_cells.h
86483 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86484 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86485
86486 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86487 - atomic_long_inc(&dev->rx_dropped);
86488 + atomic_long_inc_unchecked(&dev->rx_dropped);
86489 kfree_skb(skb);
86490 return;
86491 }
86492 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86493 index 848e85c..051c7de 100644
86494 --- a/include/net/inet_connection_sock.h
86495 +++ b/include/net/inet_connection_sock.h
86496 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86497 int (*bind_conflict)(const struct sock *sk,
86498 const struct inet_bind_bucket *tb, bool relax);
86499 void (*mtu_reduced)(struct sock *sk);
86500 -};
86501 +} __do_const;
86502
86503 /** inet_connection_sock - INET connection oriented sock
86504 *
86505 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86506 index 80479ab..0c3f647 100644
86507 --- a/include/net/inetpeer.h
86508 +++ b/include/net/inetpeer.h
86509 @@ -47,7 +47,7 @@ struct inet_peer {
86510 */
86511 union {
86512 struct {
86513 - atomic_t rid; /* Frag reception counter */
86514 + atomic_unchecked_t rid; /* Frag reception counter */
86515 };
86516 struct rcu_head rcu;
86517 struct inet_peer *gc_next;
86518 diff --git a/include/net/ip.h b/include/net/ip.h
86519 index 09cf5ae..ab62fcf 100644
86520 --- a/include/net/ip.h
86521 +++ b/include/net/ip.h
86522 @@ -317,7 +317,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86523 }
86524 }
86525
86526 -u32 ip_idents_reserve(u32 hash, int segs);
86527 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86528 void __ip_select_ident(struct iphdr *iph, int segs);
86529
86530 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86531 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86532 index dc9d2a2..d985691 100644
86533 --- a/include/net/ip_fib.h
86534 +++ b/include/net/ip_fib.h
86535 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86536
86537 #define FIB_RES_SADDR(net, res) \
86538 ((FIB_RES_NH(res).nh_saddr_genid == \
86539 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86540 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86541 FIB_RES_NH(res).nh_saddr : \
86542 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86543 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86544 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86545 index 615b20b..fd4cbd8 100644
86546 --- a/include/net/ip_vs.h
86547 +++ b/include/net/ip_vs.h
86548 @@ -534,7 +534,7 @@ struct ip_vs_conn {
86549 struct ip_vs_conn *control; /* Master control connection */
86550 atomic_t n_control; /* Number of controlled ones */
86551 struct ip_vs_dest *dest; /* real server */
86552 - atomic_t in_pkts; /* incoming packet counter */
86553 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86554
86555 /* Packet transmitter for different forwarding methods. If it
86556 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86557 @@ -682,7 +682,7 @@ struct ip_vs_dest {
86558 __be16 port; /* port number of the server */
86559 union nf_inet_addr addr; /* IP address of the server */
86560 volatile unsigned int flags; /* dest status flags */
86561 - atomic_t conn_flags; /* flags to copy to conn */
86562 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86563 atomic_t weight; /* server weight */
86564
86565 atomic_t refcnt; /* reference counter */
86566 @@ -928,11 +928,11 @@ struct netns_ipvs {
86567 /* ip_vs_lblc */
86568 int sysctl_lblc_expiration;
86569 struct ctl_table_header *lblc_ctl_header;
86570 - struct ctl_table *lblc_ctl_table;
86571 + ctl_table_no_const *lblc_ctl_table;
86572 /* ip_vs_lblcr */
86573 int sysctl_lblcr_expiration;
86574 struct ctl_table_header *lblcr_ctl_header;
86575 - struct ctl_table *lblcr_ctl_table;
86576 + ctl_table_no_const *lblcr_ctl_table;
86577 /* ip_vs_est */
86578 struct list_head est_list; /* estimator list */
86579 spinlock_t est_lock;
86580 diff --git a/include/net/ipv6.h b/include/net/ipv6.h
86581 index 4292929..7e21d2e 100644
86582 --- a/include/net/ipv6.h
86583 +++ b/include/net/ipv6.h
86584 @@ -708,7 +708,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86585 __be32 flowlabel, bool autolabel)
86586 {
86587 if (!flowlabel && (autolabel || net->ipv6.sysctl.auto_flowlabels)) {
86588 - __be32 hash;
86589 + u32 hash;
86590
86591 hash = skb_get_hash(skb);
86592
86593 @@ -718,7 +718,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86594 */
86595 hash ^= hash >> 12;
86596
86597 - flowlabel = hash & IPV6_FLOWLABEL_MASK;
86598 + flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
86599 }
86600
86601 return flowlabel;
86602 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86603 index 8d4f588..2e37ad2 100644
86604 --- a/include/net/irda/ircomm_tty.h
86605 +++ b/include/net/irda/ircomm_tty.h
86606 @@ -33,6 +33,7 @@
86607 #include <linux/termios.h>
86608 #include <linux/timer.h>
86609 #include <linux/tty.h> /* struct tty_struct */
86610 +#include <asm/local.h>
86611
86612 #include <net/irda/irias_object.h>
86613 #include <net/irda/ircomm_core.h>
86614 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86615 index 714cc9a..ea05f3e 100644
86616 --- a/include/net/iucv/af_iucv.h
86617 +++ b/include/net/iucv/af_iucv.h
86618 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86619 struct iucv_sock_list {
86620 struct hlist_head head;
86621 rwlock_t lock;
86622 - atomic_t autobind_name;
86623 + atomic_unchecked_t autobind_name;
86624 };
86625
86626 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86627 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86628 index f3be818..bf46196 100644
86629 --- a/include/net/llc_c_ac.h
86630 +++ b/include/net/llc_c_ac.h
86631 @@ -87,7 +87,7 @@
86632 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86633 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86634
86635 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86636 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86637
86638 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86639 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86640 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86641 index 3948cf1..83b28c4 100644
86642 --- a/include/net/llc_c_ev.h
86643 +++ b/include/net/llc_c_ev.h
86644 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86645 return (struct llc_conn_state_ev *)skb->cb;
86646 }
86647
86648 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86649 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86650 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86651 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86652
86653 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86654 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86655 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86656 index 0e79cfb..f46db31 100644
86657 --- a/include/net/llc_c_st.h
86658 +++ b/include/net/llc_c_st.h
86659 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86660 u8 next_state;
86661 llc_conn_ev_qfyr_t *ev_qualifiers;
86662 llc_conn_action_t *ev_actions;
86663 -};
86664 +} __do_const;
86665
86666 struct llc_conn_state {
86667 u8 current_state;
86668 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86669 index a61b98c..aade1eb 100644
86670 --- a/include/net/llc_s_ac.h
86671 +++ b/include/net/llc_s_ac.h
86672 @@ -23,7 +23,7 @@
86673 #define SAP_ACT_TEST_IND 9
86674
86675 /* All action functions must look like this */
86676 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86677 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86678
86679 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86680 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86681 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86682 index 567c681..cd73ac02 100644
86683 --- a/include/net/llc_s_st.h
86684 +++ b/include/net/llc_s_st.h
86685 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86686 llc_sap_ev_t ev;
86687 u8 next_state;
86688 llc_sap_action_t *ev_actions;
86689 -};
86690 +} __do_const;
86691
86692 struct llc_sap_state {
86693 u8 curr_state;
86694 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86695 index a9de1da..df72057 100644
86696 --- a/include/net/mac80211.h
86697 +++ b/include/net/mac80211.h
86698 @@ -4645,7 +4645,7 @@ struct rate_control_ops {
86699 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86700
86701 u32 (*get_expected_throughput)(void *priv_sta);
86702 -};
86703 +} __do_const;
86704
86705 static inline int rate_supported(struct ieee80211_sta *sta,
86706 enum ieee80211_band band,
86707 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86708 index f60558d..e5ed9bd 100644
86709 --- a/include/net/neighbour.h
86710 +++ b/include/net/neighbour.h
86711 @@ -163,7 +163,7 @@ struct neigh_ops {
86712 void (*error_report)(struct neighbour *, struct sk_buff *);
86713 int (*output)(struct neighbour *, struct sk_buff *);
86714 int (*connected_output)(struct neighbour *, struct sk_buff *);
86715 -};
86716 +} __do_const;
86717
86718 struct pneigh_entry {
86719 struct pneigh_entry *next;
86720 @@ -217,7 +217,7 @@ struct neigh_table {
86721 struct neigh_statistics __percpu *stats;
86722 struct neigh_hash_table __rcu *nht;
86723 struct pneigh_entry **phash_buckets;
86724 -};
86725 +} __randomize_layout;
86726
86727 static inline int neigh_parms_family(struct neigh_parms *p)
86728 {
86729 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86730 index e0d6466..e2f3003 100644
86731 --- a/include/net/net_namespace.h
86732 +++ b/include/net/net_namespace.h
86733 @@ -129,8 +129,8 @@ struct net {
86734 struct netns_ipvs *ipvs;
86735 #endif
86736 struct sock *diag_nlsk;
86737 - atomic_t fnhe_genid;
86738 -};
86739 + atomic_unchecked_t fnhe_genid;
86740 +} __randomize_layout;
86741
86742 #include <linux/seq_file_net.h>
86743
86744 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86745 #define __net_init __init
86746 #define __net_exit __exit_refok
86747 #define __net_initdata __initdata
86748 +#ifdef CONSTIFY_PLUGIN
86749 #define __net_initconst __initconst
86750 +#else
86751 +#define __net_initconst __initdata
86752 +#endif
86753 #endif
86754
86755 struct pernet_operations {
86756 @@ -296,7 +300,7 @@ struct pernet_operations {
86757 void (*exit_batch)(struct list_head *net_exit_list);
86758 int *id;
86759 size_t size;
86760 -};
86761 +} __do_const;
86762
86763 /*
86764 * Use these carefully. If you implement a network device and it
86765 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86766
86767 static inline int rt_genid_ipv4(struct net *net)
86768 {
86769 - return atomic_read(&net->ipv4.rt_genid);
86770 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86771 }
86772
86773 static inline void rt_genid_bump_ipv4(struct net *net)
86774 {
86775 - atomic_inc(&net->ipv4.rt_genid);
86776 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86777 }
86778
86779 extern void (*__fib6_flush_trees)(struct net *net);
86780 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86781
86782 static inline int fnhe_genid(struct net *net)
86783 {
86784 - return atomic_read(&net->fnhe_genid);
86785 + return atomic_read_unchecked(&net->fnhe_genid);
86786 }
86787
86788 static inline void fnhe_genid_bump(struct net *net)
86789 {
86790 - atomic_inc(&net->fnhe_genid);
86791 + atomic_inc_unchecked(&net->fnhe_genid);
86792 }
86793
86794 #endif /* __NET_NET_NAMESPACE_H */
86795 diff --git a/include/net/netlink.h b/include/net/netlink.h
86796 index 7b903e1..ad9ca4b 100644
86797 --- a/include/net/netlink.h
86798 +++ b/include/net/netlink.h
86799 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86800 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86801 {
86802 if (mark)
86803 - skb_trim(skb, (unsigned char *) mark - skb->data);
86804 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86805 }
86806
86807 /**
86808 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86809 index 29d6a94..235d3d84 100644
86810 --- a/include/net/netns/conntrack.h
86811 +++ b/include/net/netns/conntrack.h
86812 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86813 struct nf_proto_net {
86814 #ifdef CONFIG_SYSCTL
86815 struct ctl_table_header *ctl_table_header;
86816 - struct ctl_table *ctl_table;
86817 + ctl_table_no_const *ctl_table;
86818 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86819 struct ctl_table_header *ctl_compat_header;
86820 - struct ctl_table *ctl_compat_table;
86821 + ctl_table_no_const *ctl_compat_table;
86822 #endif
86823 #endif
86824 unsigned int users;
86825 @@ -60,7 +60,7 @@ struct nf_ip_net {
86826 struct nf_icmp_net icmpv6;
86827 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86828 struct ctl_table_header *ctl_table_header;
86829 - struct ctl_table *ctl_table;
86830 + ctl_table_no_const *ctl_table;
86831 #endif
86832 };
86833
86834 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86835 index 0ffef1a..2ce1ceb 100644
86836 --- a/include/net/netns/ipv4.h
86837 +++ b/include/net/netns/ipv4.h
86838 @@ -84,7 +84,7 @@ struct netns_ipv4 {
86839
86840 struct ping_group_range ping_group_range;
86841
86842 - atomic_t dev_addr_genid;
86843 + atomic_unchecked_t dev_addr_genid;
86844
86845 #ifdef CONFIG_SYSCTL
86846 unsigned long *sysctl_local_reserved_ports;
86847 @@ -98,6 +98,6 @@ struct netns_ipv4 {
86848 struct fib_rules_ops *mr_rules_ops;
86849 #endif
86850 #endif
86851 - atomic_t rt_genid;
86852 + atomic_unchecked_t rt_genid;
86853 };
86854 #endif
86855 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86856 index 69ae41f..4f94868 100644
86857 --- a/include/net/netns/ipv6.h
86858 +++ b/include/net/netns/ipv6.h
86859 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86860 struct fib_rules_ops *mr6_rules_ops;
86861 #endif
86862 #endif
86863 - atomic_t dev_addr_genid;
86864 - atomic_t fib6_sernum;
86865 + atomic_unchecked_t dev_addr_genid;
86866 + atomic_unchecked_t fib6_sernum;
86867 };
86868
86869 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86870 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86871 index 9da7982..099321b9 100644
86872 --- a/include/net/netns/xfrm.h
86873 +++ b/include/net/netns/xfrm.h
86874 @@ -78,7 +78,7 @@ struct netns_xfrm {
86875
86876 /* flow cache part */
86877 struct flow_cache flow_cache_global;
86878 - atomic_t flow_cache_genid;
86879 + atomic_unchecked_t flow_cache_genid;
86880 struct list_head flow_cache_gc_list;
86881 spinlock_t flow_cache_gc_lock;
86882 struct work_struct flow_cache_gc_work;
86883 diff --git a/include/net/ping.h b/include/net/ping.h
86884 index 026479b..d9b2829 100644
86885 --- a/include/net/ping.h
86886 +++ b/include/net/ping.h
86887 @@ -54,7 +54,7 @@ struct ping_iter_state {
86888
86889 extern struct proto ping_prot;
86890 #if IS_ENABLED(CONFIG_IPV6)
86891 -extern struct pingv6_ops pingv6_ops;
86892 +extern struct pingv6_ops *pingv6_ops;
86893 #endif
86894
86895 struct pingfakehdr {
86896 diff --git a/include/net/protocol.h b/include/net/protocol.h
86897 index d6fcc1f..ca277058 100644
86898 --- a/include/net/protocol.h
86899 +++ b/include/net/protocol.h
86900 @@ -49,7 +49,7 @@ struct net_protocol {
86901 * socket lookup?
86902 */
86903 icmp_strict_tag_validation:1;
86904 -};
86905 +} __do_const;
86906
86907 #if IS_ENABLED(CONFIG_IPV6)
86908 struct inet6_protocol {
86909 @@ -62,7 +62,7 @@ struct inet6_protocol {
86910 u8 type, u8 code, int offset,
86911 __be32 info);
86912 unsigned int flags; /* INET6_PROTO_xxx */
86913 -};
86914 +} __do_const;
86915
86916 #define INET6_PROTO_NOPOLICY 0x1
86917 #define INET6_PROTO_FINAL 0x2
86918 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86919 index e21b9f9..0191ef0 100644
86920 --- a/include/net/rtnetlink.h
86921 +++ b/include/net/rtnetlink.h
86922 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86923 int (*fill_slave_info)(struct sk_buff *skb,
86924 const struct net_device *dev,
86925 const struct net_device *slave_dev);
86926 -};
86927 +} __do_const;
86928
86929 int __rtnl_link_register(struct rtnl_link_ops *ops);
86930 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86931 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86932 index 4a5b9a3..ca27d73 100644
86933 --- a/include/net/sctp/checksum.h
86934 +++ b/include/net/sctp/checksum.h
86935 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86936 unsigned int offset)
86937 {
86938 struct sctphdr *sh = sctp_hdr(skb);
86939 - __le32 ret, old = sh->checksum;
86940 - const struct skb_checksum_ops ops = {
86941 + __le32 ret, old = sh->checksum;
86942 + static const struct skb_checksum_ops ops = {
86943 .update = sctp_csum_update,
86944 .combine = sctp_csum_combine,
86945 };
86946 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86947 index 72a31db..aaa63d9 100644
86948 --- a/include/net/sctp/sm.h
86949 +++ b/include/net/sctp/sm.h
86950 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86951 typedef struct {
86952 sctp_state_fn_t *fn;
86953 const char *name;
86954 -} sctp_sm_table_entry_t;
86955 +} __do_const sctp_sm_table_entry_t;
86956
86957 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86958 * currently in use.
86959 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86960 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86961
86962 /* Extern declarations for major data structures. */
86963 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86964 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86965
86966
86967 /* Get the size of a DATA chunk payload. */
86968 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86969 index 4ff3f67..89ae38e 100644
86970 --- a/include/net/sctp/structs.h
86971 +++ b/include/net/sctp/structs.h
86972 @@ -509,7 +509,7 @@ struct sctp_pf {
86973 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86974 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86975 struct sctp_af *af;
86976 -};
86977 +} __do_const;
86978
86979
86980 /* Structure to track chunk fragments that have been acked, but peer
86981 diff --git a/include/net/sock.h b/include/net/sock.h
86982 index 7db3db1..a915cca 100644
86983 --- a/include/net/sock.h
86984 +++ b/include/net/sock.h
86985 @@ -355,7 +355,7 @@ struct sock {
86986 unsigned int sk_napi_id;
86987 unsigned int sk_ll_usec;
86988 #endif
86989 - atomic_t sk_drops;
86990 + atomic_unchecked_t sk_drops;
86991 int sk_rcvbuf;
86992
86993 struct sk_filter __rcu *sk_filter;
86994 @@ -1048,7 +1048,7 @@ struct proto {
86995 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86996 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86997 #endif
86998 -};
86999 +} __randomize_layout;
87000
87001 /*
87002 * Bits in struct cg_proto.flags
87003 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87004 return ret >> PAGE_SHIFT;
87005 }
87006
87007 -static inline long
87008 +static inline long __intentional_overflow(-1)
87009 sk_memory_allocated(const struct sock *sk)
87010 {
87011 struct proto *prot = sk->sk_prot;
87012 @@ -1380,7 +1380,7 @@ struct sock_iocb {
87013 struct scm_cookie *scm;
87014 struct msghdr *msg, async_msg;
87015 struct kiocb *kiocb;
87016 -};
87017 +} __randomize_layout;
87018
87019 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87020 {
87021 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87022 }
87023
87024 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87025 - char __user *from, char *to,
87026 + char __user *from, unsigned char *to,
87027 int copy, int offset)
87028 {
87029 if (skb->ip_summed == CHECKSUM_NONE) {
87030 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87031 }
87032 }
87033
87034 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87035 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87036
87037 /**
87038 * sk_page_frag - return an appropriate page_frag
87039 diff --git a/include/net/tcp.h b/include/net/tcp.h
87040 index 4062b4f..9ff45e7 100644
87041 --- a/include/net/tcp.h
87042 +++ b/include/net/tcp.h
87043 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
87044 void tcp_xmit_retransmit_queue(struct sock *);
87045 void tcp_simple_retransmit(struct sock *);
87046 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87047 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87048 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87049
87050 void tcp_send_probe0(struct sock *);
87051 void tcp_send_partial(struct sock *);
87052 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
87053 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
87054 */
87055 struct tcp_skb_cb {
87056 - __u32 seq; /* Starting sequence number */
87057 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87058 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
87059 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87060 union {
87061 /* Note : tcp_tw_isn is used in input path only
87062 * (isn chosen by tcp_timewait_state_process())
87063 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
87064
87065 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87066 /* 1 byte hole */
87067 - __u32 ack_seq; /* Sequence number ACK'd */
87068 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87069 union {
87070 struct inet_skb_parm h4;
87071 #if IS_ENABLED(CONFIG_IPV6)
87072 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87073 index dc4865e..152ee4c 100644
87074 --- a/include/net/xfrm.h
87075 +++ b/include/net/xfrm.h
87076 @@ -285,7 +285,6 @@ struct xfrm_dst;
87077 struct xfrm_policy_afinfo {
87078 unsigned short family;
87079 struct dst_ops *dst_ops;
87080 - void (*garbage_collect)(struct net *net);
87081 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87082 const xfrm_address_t *saddr,
87083 const xfrm_address_t *daddr);
87084 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87085 struct net_device *dev,
87086 const struct flowi *fl);
87087 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87088 -};
87089 +} __do_const;
87090
87091 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87092 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87093 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87094 int (*transport_finish)(struct sk_buff *skb,
87095 int async);
87096 void (*local_error)(struct sk_buff *skb, u32 mtu);
87097 -};
87098 +} __do_const;
87099
87100 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87101 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87102 @@ -437,7 +436,7 @@ struct xfrm_mode {
87103 struct module *owner;
87104 unsigned int encap;
87105 int flags;
87106 -};
87107 +} __do_const;
87108
87109 /* Flags for xfrm_mode. */
87110 enum {
87111 @@ -534,7 +533,7 @@ struct xfrm_policy {
87112 struct timer_list timer;
87113
87114 struct flow_cache_object flo;
87115 - atomic_t genid;
87116 + atomic_unchecked_t genid;
87117 u32 priority;
87118 u32 index;
87119 struct xfrm_mark mark;
87120 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87121 }
87122
87123 void xfrm_garbage_collect(struct net *net);
87124 +void xfrm_garbage_collect_deferred(struct net *net);
87125
87126 #else
87127
87128 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87129 static inline void xfrm_garbage_collect(struct net *net)
87130 {
87131 }
87132 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87133 +{
87134 +}
87135 #endif
87136
87137 static __inline__
87138 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87139 index 1017e0b..227aa4d 100644
87140 --- a/include/rdma/iw_cm.h
87141 +++ b/include/rdma/iw_cm.h
87142 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87143 int backlog);
87144
87145 int (*destroy_listen)(struct iw_cm_id *cm_id);
87146 -};
87147 +} __no_const;
87148
87149 /**
87150 * iw_create_cm_id - Create an IW CM identifier.
87151 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87152 index 52beadf..598734c 100644
87153 --- a/include/scsi/libfc.h
87154 +++ b/include/scsi/libfc.h
87155 @@ -771,6 +771,7 @@ struct libfc_function_template {
87156 */
87157 void (*disc_stop_final) (struct fc_lport *);
87158 };
87159 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87160
87161 /**
87162 * struct fc_disc - Discovery context
87163 @@ -875,7 +876,7 @@ struct fc_lport {
87164 struct fc_vport *vport;
87165
87166 /* Operational Information */
87167 - struct libfc_function_template tt;
87168 + libfc_function_template_no_const tt;
87169 u8 link_up;
87170 u8 qfull;
87171 enum fc_lport_state state;
87172 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87173 index 27ecee7..5f42632 100644
87174 --- a/include/scsi/scsi_device.h
87175 +++ b/include/scsi/scsi_device.h
87176 @@ -186,9 +186,9 @@ struct scsi_device {
87177 unsigned int max_device_blocked; /* what device_blocked counts down from */
87178 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87179
87180 - atomic_t iorequest_cnt;
87181 - atomic_t iodone_cnt;
87182 - atomic_t ioerr_cnt;
87183 + atomic_unchecked_t iorequest_cnt;
87184 + atomic_unchecked_t iodone_cnt;
87185 + atomic_unchecked_t ioerr_cnt;
87186
87187 struct device sdev_gendev,
87188 sdev_dev;
87189 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87190 index 007a0bc..7188db8 100644
87191 --- a/include/scsi/scsi_transport_fc.h
87192 +++ b/include/scsi/scsi_transport_fc.h
87193 @@ -756,7 +756,8 @@ struct fc_function_template {
87194 unsigned long show_host_system_hostname:1;
87195
87196 unsigned long disable_target_scan:1;
87197 -};
87198 +} __do_const;
87199 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87200
87201
87202 /**
87203 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87204 index ae6c3b8..fd748ac 100644
87205 --- a/include/sound/compress_driver.h
87206 +++ b/include/sound/compress_driver.h
87207 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87208 struct snd_compr_caps *caps);
87209 int (*get_codec_caps) (struct snd_compr_stream *stream,
87210 struct snd_compr_codec_caps *codec);
87211 -};
87212 +} __no_const;
87213
87214 /**
87215 * struct snd_compr: Compressed device
87216 diff --git a/include/sound/soc.h b/include/sound/soc.h
87217 index 7ba7130..d46594d 100644
87218 --- a/include/sound/soc.h
87219 +++ b/include/sound/soc.h
87220 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
87221 enum snd_soc_dapm_type, int);
87222
87223 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
87224 -};
87225 +} __do_const;
87226
87227 /* SoC platform interface */
87228 struct snd_soc_platform_driver {
87229 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
87230 const struct snd_compr_ops *compr_ops;
87231
87232 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87233 -};
87234 +} __do_const;
87235
87236 struct snd_soc_dai_link_component {
87237 const char *name;
87238 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87239 index 23c518a..d6ef510 100644
87240 --- a/include/target/target_core_base.h
87241 +++ b/include/target/target_core_base.h
87242 @@ -764,7 +764,7 @@ struct se_device {
87243 atomic_long_t write_bytes;
87244 /* Active commands on this virtual SE device */
87245 atomic_t simple_cmds;
87246 - atomic_t dev_ordered_id;
87247 + atomic_unchecked_t dev_ordered_id;
87248 atomic_t dev_ordered_sync;
87249 atomic_t dev_qf_count;
87250 int export_count;
87251 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87252 new file mode 100644
87253 index 0000000..fb634b7
87254 --- /dev/null
87255 +++ b/include/trace/events/fs.h
87256 @@ -0,0 +1,53 @@
87257 +#undef TRACE_SYSTEM
87258 +#define TRACE_SYSTEM fs
87259 +
87260 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87261 +#define _TRACE_FS_H
87262 +
87263 +#include <linux/fs.h>
87264 +#include <linux/tracepoint.h>
87265 +
87266 +TRACE_EVENT(do_sys_open,
87267 +
87268 + TP_PROTO(const char *filename, int flags, int mode),
87269 +
87270 + TP_ARGS(filename, flags, mode),
87271 +
87272 + TP_STRUCT__entry(
87273 + __string( filename, filename )
87274 + __field( int, flags )
87275 + __field( int, mode )
87276 + ),
87277 +
87278 + TP_fast_assign(
87279 + __assign_str(filename, filename);
87280 + __entry->flags = flags;
87281 + __entry->mode = mode;
87282 + ),
87283 +
87284 + TP_printk("\"%s\" %x %o",
87285 + __get_str(filename), __entry->flags, __entry->mode)
87286 +);
87287 +
87288 +TRACE_EVENT(open_exec,
87289 +
87290 + TP_PROTO(const char *filename),
87291 +
87292 + TP_ARGS(filename),
87293 +
87294 + TP_STRUCT__entry(
87295 + __string( filename, filename )
87296 + ),
87297 +
87298 + TP_fast_assign(
87299 + __assign_str(filename, filename);
87300 + ),
87301 +
87302 + TP_printk("\"%s\"",
87303 + __get_str(filename))
87304 +);
87305 +
87306 +#endif /* _TRACE_FS_H */
87307 +
87308 +/* This part must be outside protection */
87309 +#include <trace/define_trace.h>
87310 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87311 index 3608beb..df39d8a 100644
87312 --- a/include/trace/events/irq.h
87313 +++ b/include/trace/events/irq.h
87314 @@ -36,7 +36,7 @@ struct softirq_action;
87315 */
87316 TRACE_EVENT(irq_handler_entry,
87317
87318 - TP_PROTO(int irq, struct irqaction *action),
87319 + TP_PROTO(int irq, const struct irqaction *action),
87320
87321 TP_ARGS(irq, action),
87322
87323 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87324 */
87325 TRACE_EVENT(irq_handler_exit,
87326
87327 - TP_PROTO(int irq, struct irqaction *action, int ret),
87328 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87329
87330 TP_ARGS(irq, action, ret),
87331
87332 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87333 index 7caf44c..23c6f27 100644
87334 --- a/include/uapi/linux/a.out.h
87335 +++ b/include/uapi/linux/a.out.h
87336 @@ -39,6 +39,14 @@ enum machine_type {
87337 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87338 };
87339
87340 +/* Constants for the N_FLAGS field */
87341 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87342 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87343 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87344 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87345 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87346 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87347 +
87348 #if !defined (N_MAGIC)
87349 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87350 #endif
87351 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87352 index 22b6ad3..aeba37e 100644
87353 --- a/include/uapi/linux/bcache.h
87354 +++ b/include/uapi/linux/bcache.h
87355 @@ -5,6 +5,7 @@
87356 * Bcache on disk data structures
87357 */
87358
87359 +#include <linux/compiler.h>
87360 #include <asm/types.h>
87361
87362 #define BITMASK(name, type, field, offset, size) \
87363 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87364 /* Btree keys - all units are in sectors */
87365
87366 struct bkey {
87367 - __u64 high;
87368 - __u64 low;
87369 + __u64 high __intentional_overflow(-1);
87370 + __u64 low __intentional_overflow(-1);
87371 __u64 ptr[];
87372 };
87373
87374 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87375 index d876736..ccce5c0 100644
87376 --- a/include/uapi/linux/byteorder/little_endian.h
87377 +++ b/include/uapi/linux/byteorder/little_endian.h
87378 @@ -42,51 +42,51 @@
87379
87380 static inline __le64 __cpu_to_le64p(const __u64 *p)
87381 {
87382 - return (__force __le64)*p;
87383 + return (__force const __le64)*p;
87384 }
87385 -static inline __u64 __le64_to_cpup(const __le64 *p)
87386 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87387 {
87388 - return (__force __u64)*p;
87389 + return (__force const __u64)*p;
87390 }
87391 static inline __le32 __cpu_to_le32p(const __u32 *p)
87392 {
87393 - return (__force __le32)*p;
87394 + return (__force const __le32)*p;
87395 }
87396 static inline __u32 __le32_to_cpup(const __le32 *p)
87397 {
87398 - return (__force __u32)*p;
87399 + return (__force const __u32)*p;
87400 }
87401 static inline __le16 __cpu_to_le16p(const __u16 *p)
87402 {
87403 - return (__force __le16)*p;
87404 + return (__force const __le16)*p;
87405 }
87406 static inline __u16 __le16_to_cpup(const __le16 *p)
87407 {
87408 - return (__force __u16)*p;
87409 + return (__force const __u16)*p;
87410 }
87411 static inline __be64 __cpu_to_be64p(const __u64 *p)
87412 {
87413 - return (__force __be64)__swab64p(p);
87414 + return (__force const __be64)__swab64p(p);
87415 }
87416 static inline __u64 __be64_to_cpup(const __be64 *p)
87417 {
87418 - return __swab64p((__u64 *)p);
87419 + return __swab64p((const __u64 *)p);
87420 }
87421 static inline __be32 __cpu_to_be32p(const __u32 *p)
87422 {
87423 - return (__force __be32)__swab32p(p);
87424 + return (__force const __be32)__swab32p(p);
87425 }
87426 -static inline __u32 __be32_to_cpup(const __be32 *p)
87427 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87428 {
87429 - return __swab32p((__u32 *)p);
87430 + return __swab32p((const __u32 *)p);
87431 }
87432 static inline __be16 __cpu_to_be16p(const __u16 *p)
87433 {
87434 - return (__force __be16)__swab16p(p);
87435 + return (__force const __be16)__swab16p(p);
87436 }
87437 static inline __u16 __be16_to_cpup(const __be16 *p)
87438 {
87439 - return __swab16p((__u16 *)p);
87440 + return __swab16p((const __u16 *)p);
87441 }
87442 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87443 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87444 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87445 index ea9bf25..5140c61 100644
87446 --- a/include/uapi/linux/elf.h
87447 +++ b/include/uapi/linux/elf.h
87448 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87449 #define PT_GNU_EH_FRAME 0x6474e550
87450
87451 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87452 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87453 +
87454 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87455 +
87456 +/* Constants for the e_flags field */
87457 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87458 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87459 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87460 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87461 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87462 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87463
87464 /*
87465 * Extended Numbering
87466 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87467 #define DT_DEBUG 21
87468 #define DT_TEXTREL 22
87469 #define DT_JMPREL 23
87470 +#define DT_FLAGS 30
87471 + #define DF_TEXTREL 0x00000004
87472 #define DT_ENCODING 32
87473 #define OLD_DT_LOOS 0x60000000
87474 #define DT_LOOS 0x6000000d
87475 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87476 #define PF_W 0x2
87477 #define PF_X 0x1
87478
87479 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87480 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87481 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87482 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87483 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87484 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87485 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87486 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87487 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87488 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87489 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87490 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87491 +
87492 typedef struct elf32_phdr{
87493 Elf32_Word p_type;
87494 Elf32_Off p_offset;
87495 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87496 #define EI_OSABI 7
87497 #define EI_PAD 8
87498
87499 +#define EI_PAX 14
87500 +
87501 #define ELFMAG0 0x7f /* EI_MAG */
87502 #define ELFMAG1 'E'
87503 #define ELFMAG2 'L'
87504 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87505 index aa169c4..6a2771d 100644
87506 --- a/include/uapi/linux/personality.h
87507 +++ b/include/uapi/linux/personality.h
87508 @@ -30,6 +30,7 @@ enum {
87509 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87510 ADDR_NO_RANDOMIZE | \
87511 ADDR_COMPAT_LAYOUT | \
87512 + ADDR_LIMIT_3GB | \
87513 MMAP_PAGE_ZERO)
87514
87515 /*
87516 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87517 index 7530e74..e714828 100644
87518 --- a/include/uapi/linux/screen_info.h
87519 +++ b/include/uapi/linux/screen_info.h
87520 @@ -43,7 +43,8 @@ struct screen_info {
87521 __u16 pages; /* 0x32 */
87522 __u16 vesa_attributes; /* 0x34 */
87523 __u32 capabilities; /* 0x36 */
87524 - __u8 _reserved[6]; /* 0x3a */
87525 + __u16 vesapm_size; /* 0x3a */
87526 + __u8 _reserved[4]; /* 0x3c */
87527 } __attribute__((packed));
87528
87529 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87530 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87531 index 0e011eb..82681b1 100644
87532 --- a/include/uapi/linux/swab.h
87533 +++ b/include/uapi/linux/swab.h
87534 @@ -43,7 +43,7 @@
87535 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87536 */
87537
87538 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87539 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87540 {
87541 #ifdef __HAVE_BUILTIN_BSWAP16__
87542 return __builtin_bswap16(val);
87543 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87544 #endif
87545 }
87546
87547 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87548 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87549 {
87550 #ifdef __HAVE_BUILTIN_BSWAP32__
87551 return __builtin_bswap32(val);
87552 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87553 #endif
87554 }
87555
87556 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87557 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87558 {
87559 #ifdef __HAVE_BUILTIN_BSWAP64__
87560 return __builtin_bswap64(val);
87561 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87562 index 43aaba1..1c30b48 100644
87563 --- a/include/uapi/linux/sysctl.h
87564 +++ b/include/uapi/linux/sysctl.h
87565 @@ -155,8 +155,6 @@ enum
87566 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87567 };
87568
87569 -
87570 -
87571 /* CTL_VM names: */
87572 enum
87573 {
87574 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87575 index 1590c49..5eab462 100644
87576 --- a/include/uapi/linux/xattr.h
87577 +++ b/include/uapi/linux/xattr.h
87578 @@ -73,5 +73,9 @@
87579 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87580 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87581
87582 +/* User namespace */
87583 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87584 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87585 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87586
87587 #endif /* _UAPI_LINUX_XATTR_H */
87588 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87589 index f9466fa..f4e2b81 100644
87590 --- a/include/video/udlfb.h
87591 +++ b/include/video/udlfb.h
87592 @@ -53,10 +53,10 @@ struct dlfb_data {
87593 u32 pseudo_palette[256];
87594 int blank_mode; /*one of FB_BLANK_ */
87595 /* blit-only rendering path metrics, exposed through sysfs */
87596 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87597 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87598 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87599 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87600 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87601 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87602 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87603 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87604 };
87605
87606 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87607 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87608 index 30f5362..8ed8ac9 100644
87609 --- a/include/video/uvesafb.h
87610 +++ b/include/video/uvesafb.h
87611 @@ -122,6 +122,7 @@ struct uvesafb_par {
87612 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87613 u8 pmi_setpal; /* PMI for palette changes */
87614 u16 *pmi_base; /* protected mode interface location */
87615 + u8 *pmi_code; /* protected mode code location */
87616 void *pmi_start;
87617 void *pmi_pal;
87618 u8 *vbe_state_orig; /*
87619 diff --git a/init/Kconfig b/init/Kconfig
87620 index 2081a4d..98d1149 100644
87621 --- a/init/Kconfig
87622 +++ b/init/Kconfig
87623 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87624
87625 config CHECKPOINT_RESTORE
87626 bool "Checkpoint/restore support" if EXPERT
87627 + depends on !GRKERNSEC
87628 default n
87629 help
87630 Enables additional kernel features in a sake of checkpoint/restore.
87631 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87632
87633 config COMPAT_BRK
87634 bool "Disable heap randomization"
87635 - default y
87636 + default n
87637 help
87638 Randomizing heap placement makes heap exploits harder, but it
87639 also breaks ancient binaries (including anything libc5 based).
87640 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87641 config STOP_MACHINE
87642 bool
87643 default y
87644 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87645 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87646 help
87647 Need stop_machine() primitive.
87648
87649 diff --git a/init/Makefile b/init/Makefile
87650 index 7bc47ee..6da2dc7 100644
87651 --- a/init/Makefile
87652 +++ b/init/Makefile
87653 @@ -2,6 +2,9 @@
87654 # Makefile for the linux kernel.
87655 #
87656
87657 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87658 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87659 +
87660 obj-y := main.o version.o mounts.o
87661 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87662 obj-y += noinitramfs.o
87663 diff --git a/init/do_mounts.c b/init/do_mounts.c
87664 index 9b3565c..3f90cf9 100644
87665 --- a/init/do_mounts.c
87666 +++ b/init/do_mounts.c
87667 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87668 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87669 {
87670 struct super_block *s;
87671 - int err = sys_mount(name, "/root", fs, flags, data);
87672 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87673 if (err)
87674 return err;
87675
87676 - sys_chdir("/root");
87677 + sys_chdir((const char __force_user *)"/root");
87678 s = current->fs->pwd.dentry->d_sb;
87679 ROOT_DEV = s->s_dev;
87680 printk(KERN_INFO
87681 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87682 va_start(args, fmt);
87683 vsprintf(buf, fmt, args);
87684 va_end(args);
87685 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87686 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87687 if (fd >= 0) {
87688 sys_ioctl(fd, FDEJECT, 0);
87689 sys_close(fd);
87690 }
87691 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87692 - fd = sys_open("/dev/console", O_RDWR, 0);
87693 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87694 if (fd >= 0) {
87695 sys_ioctl(fd, TCGETS, (long)&termios);
87696 termios.c_lflag &= ~ICANON;
87697 sys_ioctl(fd, TCSETSF, (long)&termios);
87698 - sys_read(fd, &c, 1);
87699 + sys_read(fd, (char __user *)&c, 1);
87700 termios.c_lflag |= ICANON;
87701 sys_ioctl(fd, TCSETSF, (long)&termios);
87702 sys_close(fd);
87703 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87704 mount_root();
87705 out:
87706 devtmpfs_mount("dev");
87707 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87708 - sys_chroot(".");
87709 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87710 + sys_chroot((const char __force_user *)".");
87711 }
87712
87713 static bool is_tmpfs;
87714 diff --git a/init/do_mounts.h b/init/do_mounts.h
87715 index f5b978a..69dbfe8 100644
87716 --- a/init/do_mounts.h
87717 +++ b/init/do_mounts.h
87718 @@ -15,15 +15,15 @@ extern int root_mountflags;
87719
87720 static inline int create_dev(char *name, dev_t dev)
87721 {
87722 - sys_unlink(name);
87723 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87724 + sys_unlink((char __force_user *)name);
87725 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87726 }
87727
87728 #if BITS_PER_LONG == 32
87729 static inline u32 bstat(char *name)
87730 {
87731 struct stat64 stat;
87732 - if (sys_stat64(name, &stat) != 0)
87733 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87734 return 0;
87735 if (!S_ISBLK(stat.st_mode))
87736 return 0;
87737 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87738 static inline u32 bstat(char *name)
87739 {
87740 struct stat stat;
87741 - if (sys_newstat(name, &stat) != 0)
87742 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87743 return 0;
87744 if (!S_ISBLK(stat.st_mode))
87745 return 0;
87746 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87747 index 3e0878e..8a9d7a0 100644
87748 --- a/init/do_mounts_initrd.c
87749 +++ b/init/do_mounts_initrd.c
87750 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87751 {
87752 sys_unshare(CLONE_FS | CLONE_FILES);
87753 /* stdin/stdout/stderr for /linuxrc */
87754 - sys_open("/dev/console", O_RDWR, 0);
87755 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87756 sys_dup(0);
87757 sys_dup(0);
87758 /* move initrd over / and chdir/chroot in initrd root */
87759 - sys_chdir("/root");
87760 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87761 - sys_chroot(".");
87762 + sys_chdir((const char __force_user *)"/root");
87763 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87764 + sys_chroot((const char __force_user *)".");
87765 sys_setsid();
87766 return 0;
87767 }
87768 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87769 create_dev("/dev/root.old", Root_RAM0);
87770 /* mount initrd on rootfs' /root */
87771 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87772 - sys_mkdir("/old", 0700);
87773 - sys_chdir("/old");
87774 + sys_mkdir((const char __force_user *)"/old", 0700);
87775 + sys_chdir((const char __force_user *)"/old");
87776
87777 /* try loading default modules from initrd */
87778 load_default_modules();
87779 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87780 current->flags &= ~PF_FREEZER_SKIP;
87781
87782 /* move initrd to rootfs' /old */
87783 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87784 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87785 /* switch root and cwd back to / of rootfs */
87786 - sys_chroot("..");
87787 + sys_chroot((const char __force_user *)"..");
87788
87789 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87790 - sys_chdir("/old");
87791 + sys_chdir((const char __force_user *)"/old");
87792 return;
87793 }
87794
87795 - sys_chdir("/");
87796 + sys_chdir((const char __force_user *)"/");
87797 ROOT_DEV = new_decode_dev(real_root_dev);
87798 mount_root();
87799
87800 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87801 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87802 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87803 if (!error)
87804 printk("okay\n");
87805 else {
87806 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87807 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87808 if (error == -ENOENT)
87809 printk("/initrd does not exist. Ignored.\n");
87810 else
87811 printk("failed\n");
87812 printk(KERN_NOTICE "Unmounting old root\n");
87813 - sys_umount("/old", MNT_DETACH);
87814 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87815 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87816 if (fd < 0) {
87817 error = fd;
87818 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87819 * mounted in the normal path.
87820 */
87821 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87822 - sys_unlink("/initrd.image");
87823 + sys_unlink((const char __force_user *)"/initrd.image");
87824 handle_initrd();
87825 return 1;
87826 }
87827 }
87828 - sys_unlink("/initrd.image");
87829 + sys_unlink((const char __force_user *)"/initrd.image");
87830 return 0;
87831 }
87832 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87833 index 8cb6db5..d729f50 100644
87834 --- a/init/do_mounts_md.c
87835 +++ b/init/do_mounts_md.c
87836 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87837 partitioned ? "_d" : "", minor,
87838 md_setup_args[ent].device_names);
87839
87840 - fd = sys_open(name, 0, 0);
87841 + fd = sys_open((char __force_user *)name, 0, 0);
87842 if (fd < 0) {
87843 printk(KERN_ERR "md: open failed - cannot start "
87844 "array %s\n", name);
87845 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87846 * array without it
87847 */
87848 sys_close(fd);
87849 - fd = sys_open(name, 0, 0);
87850 + fd = sys_open((char __force_user *)name, 0, 0);
87851 sys_ioctl(fd, BLKRRPART, 0);
87852 }
87853 sys_close(fd);
87854 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87855
87856 wait_for_device_probe();
87857
87858 - fd = sys_open("/dev/md0", 0, 0);
87859 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87860 if (fd >= 0) {
87861 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87862 sys_close(fd);
87863 diff --git a/init/init_task.c b/init/init_task.c
87864 index ba0a7f36..2bcf1d5 100644
87865 --- a/init/init_task.c
87866 +++ b/init/init_task.c
87867 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87868 * Initial thread structure. Alignment of this is handled by a special
87869 * linker map entry.
87870 */
87871 +#ifdef CONFIG_X86
87872 +union thread_union init_thread_union __init_task_data;
87873 +#else
87874 union thread_union init_thread_union __init_task_data =
87875 { INIT_THREAD_INFO(init_task) };
87876 +#endif
87877 diff --git a/init/initramfs.c b/init/initramfs.c
87878 index ad1bd77..dca2c1b 100644
87879 --- a/init/initramfs.c
87880 +++ b/init/initramfs.c
87881 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87882
87883 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87884 while (count) {
87885 - ssize_t rv = sys_write(fd, p, count);
87886 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87887
87888 if (rv < 0) {
87889 if (rv == -EINTR || rv == -EAGAIN)
87890 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87891 }
87892 }
87893
87894 -static long __init do_utime(char *filename, time_t mtime)
87895 +static long __init do_utime(char __force_user *filename, time_t mtime)
87896 {
87897 struct timespec t[2];
87898
87899 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87900 struct dir_entry *de, *tmp;
87901 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87902 list_del(&de->list);
87903 - do_utime(de->name, de->mtime);
87904 + do_utime((char __force_user *)de->name, de->mtime);
87905 kfree(de->name);
87906 kfree(de);
87907 }
87908 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87909 if (nlink >= 2) {
87910 char *old = find_link(major, minor, ino, mode, collected);
87911 if (old)
87912 - return (sys_link(old, collected) < 0) ? -1 : 1;
87913 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87914 }
87915 return 0;
87916 }
87917 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87918 {
87919 struct stat st;
87920
87921 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87922 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87923 if (S_ISDIR(st.st_mode))
87924 - sys_rmdir(path);
87925 + sys_rmdir((char __force_user *)path);
87926 else
87927 - sys_unlink(path);
87928 + sys_unlink((char __force_user *)path);
87929 }
87930 }
87931
87932 @@ -338,7 +338,7 @@ static int __init do_name(void)
87933 int openflags = O_WRONLY|O_CREAT;
87934 if (ml != 1)
87935 openflags |= O_TRUNC;
87936 - wfd = sys_open(collected, openflags, mode);
87937 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87938
87939 if (wfd >= 0) {
87940 sys_fchown(wfd, uid, gid);
87941 @@ -350,17 +350,17 @@ static int __init do_name(void)
87942 }
87943 }
87944 } else if (S_ISDIR(mode)) {
87945 - sys_mkdir(collected, mode);
87946 - sys_chown(collected, uid, gid);
87947 - sys_chmod(collected, mode);
87948 + sys_mkdir((char __force_user *)collected, mode);
87949 + sys_chown((char __force_user *)collected, uid, gid);
87950 + sys_chmod((char __force_user *)collected, mode);
87951 dir_add(collected, mtime);
87952 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87953 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87954 if (maybe_link() == 0) {
87955 - sys_mknod(collected, mode, rdev);
87956 - sys_chown(collected, uid, gid);
87957 - sys_chmod(collected, mode);
87958 - do_utime(collected, mtime);
87959 + sys_mknod((char __force_user *)collected, mode, rdev);
87960 + sys_chown((char __force_user *)collected, uid, gid);
87961 + sys_chmod((char __force_user *)collected, mode);
87962 + do_utime((char __force_user *)collected, mtime);
87963 }
87964 }
87965 return 0;
87966 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87967 if (xwrite(wfd, victim, body_len) != body_len)
87968 error("write error");
87969 sys_close(wfd);
87970 - do_utime(vcollected, mtime);
87971 + do_utime((char __force_user *)vcollected, mtime);
87972 kfree(vcollected);
87973 eat(body_len);
87974 state = SkipIt;
87975 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87976 {
87977 collected[N_ALIGN(name_len) + body_len] = '\0';
87978 clean_path(collected, 0);
87979 - sys_symlink(collected + N_ALIGN(name_len), collected);
87980 - sys_lchown(collected, uid, gid);
87981 - do_utime(collected, mtime);
87982 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87983 + sys_lchown((char __force_user *)collected, uid, gid);
87984 + do_utime((char __force_user *)collected, mtime);
87985 state = SkipIt;
87986 next_state = Reset;
87987 return 0;
87988 diff --git a/init/main.c b/init/main.c
87989 index 321d0ce..91b53e5 100644
87990 --- a/init/main.c
87991 +++ b/init/main.c
87992 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87993 static inline void mark_rodata_ro(void) { }
87994 #endif
87995
87996 +extern void grsecurity_init(void);
87997 +
87998 /*
87999 * Debug helper: via this flag we know that we are in 'early bootup code'
88000 * where only the boot processor is running with IRQ disabled. This means
88001 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88002
88003 __setup("reset_devices", set_reset_devices);
88004
88005 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88006 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88007 +static int __init setup_grsec_proc_gid(char *str)
88008 +{
88009 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88010 + return 1;
88011 +}
88012 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88013 +#endif
88014 +
88015 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88016 +unsigned long pax_user_shadow_base __read_only;
88017 +EXPORT_SYMBOL(pax_user_shadow_base);
88018 +extern char pax_enter_kernel_user[];
88019 +extern char pax_exit_kernel_user[];
88020 +#endif
88021 +
88022 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88023 +static int __init setup_pax_nouderef(char *str)
88024 +{
88025 +#ifdef CONFIG_X86_32
88026 + unsigned int cpu;
88027 + struct desc_struct *gdt;
88028 +
88029 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88030 + gdt = get_cpu_gdt_table(cpu);
88031 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88032 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88033 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88034 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88035 + }
88036 + loadsegment(ds, __KERNEL_DS);
88037 + loadsegment(es, __KERNEL_DS);
88038 + loadsegment(ss, __KERNEL_DS);
88039 +#else
88040 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88041 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88042 + clone_pgd_mask = ~(pgdval_t)0UL;
88043 + pax_user_shadow_base = 0UL;
88044 + setup_clear_cpu_cap(X86_FEATURE_PCID);
88045 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88046 +#endif
88047 +
88048 + return 0;
88049 +}
88050 +early_param("pax_nouderef", setup_pax_nouderef);
88051 +
88052 +#ifdef CONFIG_X86_64
88053 +static int __init setup_pax_weakuderef(char *str)
88054 +{
88055 + if (clone_pgd_mask != ~(pgdval_t)0UL)
88056 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88057 + return 1;
88058 +}
88059 +__setup("pax_weakuderef", setup_pax_weakuderef);
88060 +#endif
88061 +#endif
88062 +
88063 +#ifdef CONFIG_PAX_SOFTMODE
88064 +int pax_softmode;
88065 +
88066 +static int __init setup_pax_softmode(char *str)
88067 +{
88068 + get_option(&str, &pax_softmode);
88069 + return 1;
88070 +}
88071 +__setup("pax_softmode=", setup_pax_softmode);
88072 +#endif
88073 +
88074 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88075 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88076 static const char *panic_later, *panic_param;
88077 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88078 struct blacklist_entry *entry;
88079 char *fn_name;
88080
88081 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88082 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88083 if (!fn_name)
88084 return false;
88085
88086 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88087 {
88088 int count = preempt_count();
88089 int ret;
88090 - char msgbuf[64];
88091 + const char *msg1 = "", *msg2 = "";
88092
88093 if (initcall_blacklisted(fn))
88094 return -EPERM;
88095 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88096 else
88097 ret = fn();
88098
88099 - msgbuf[0] = 0;
88100 -
88101 if (preempt_count() != count) {
88102 - sprintf(msgbuf, "preemption imbalance ");
88103 + msg1 = " preemption imbalance";
88104 preempt_count_set(count);
88105 }
88106 if (irqs_disabled()) {
88107 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88108 + msg2 = " disabled interrupts";
88109 local_irq_enable();
88110 }
88111 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88112 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88113
88114 + add_latent_entropy();
88115 return ret;
88116 }
88117
88118 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
88119 {
88120 argv_init[0] = init_filename;
88121 return do_execve(getname_kernel(init_filename),
88122 - (const char __user *const __user *)argv_init,
88123 - (const char __user *const __user *)envp_init);
88124 + (const char __user *const __force_user *)argv_init,
88125 + (const char __user *const __force_user *)envp_init);
88126 }
88127
88128 static int try_to_run_init_process(const char *init_filename)
88129 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
88130 return ret;
88131 }
88132
88133 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88134 +extern int gr_init_ran;
88135 +#endif
88136 +
88137 static noinline void __init kernel_init_freeable(void);
88138
88139 static int __ref kernel_init(void *unused)
88140 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
88141 ramdisk_execute_command, ret);
88142 }
88143
88144 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88145 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88146 + gr_init_ran = 1;
88147 +#endif
88148 +
88149 /*
88150 * We try each of these until one succeeds.
88151 *
88152 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
88153 do_basic_setup();
88154
88155 /* Open the /dev/console on the rootfs, this should never fail */
88156 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88157 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88158 pr_err("Warning: unable to open an initial console.\n");
88159
88160 (void) sys_dup(0);
88161 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
88162 if (!ramdisk_execute_command)
88163 ramdisk_execute_command = "/init";
88164
88165 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88166 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88167 ramdisk_execute_command = NULL;
88168 prepare_namespace();
88169 }
88170
88171 + grsecurity_init();
88172 +
88173 /*
88174 * Ok, we have completed the initial bootup, and
88175 * we're essentially up and running. Get rid of the
88176 diff --git a/ipc/compat.c b/ipc/compat.c
88177 index 9b3c85f..1c4d897 100644
88178 --- a/ipc/compat.c
88179 +++ b/ipc/compat.c
88180 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88181 COMPAT_SHMLBA);
88182 if (err < 0)
88183 return err;
88184 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88185 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88186 }
88187 case SHMDT:
88188 return sys_shmdt(compat_ptr(ptr));
88189 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88190 index e8075b2..76f2c6a 100644
88191 --- a/ipc/ipc_sysctl.c
88192 +++ b/ipc/ipc_sysctl.c
88193 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88194 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88195 void __user *buffer, size_t *lenp, loff_t *ppos)
88196 {
88197 - struct ctl_table ipc_table;
88198 + ctl_table_no_const ipc_table;
88199
88200 memcpy(&ipc_table, table, sizeof(ipc_table));
88201 ipc_table.data = get_ipc(table);
88202 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88203 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88204 void __user *buffer, size_t *lenp, loff_t *ppos)
88205 {
88206 - struct ctl_table ipc_table;
88207 + ctl_table_no_const ipc_table;
88208
88209 memcpy(&ipc_table, table, sizeof(ipc_table));
88210 ipc_table.data = get_ipc(table);
88211 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88212 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88213 void __user *buffer, size_t *lenp, loff_t *ppos)
88214 {
88215 - struct ctl_table ipc_table;
88216 + ctl_table_no_const ipc_table;
88217 size_t lenp_bef = *lenp;
88218 int rc;
88219
88220 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88221 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88222 void __user *buffer, size_t *lenp, loff_t *ppos)
88223 {
88224 - struct ctl_table ipc_table;
88225 + ctl_table_no_const ipc_table;
88226 memcpy(&ipc_table, table, sizeof(ipc_table));
88227 ipc_table.data = get_ipc(table);
88228
88229 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88230 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88231 void __user *buffer, size_t *lenp, loff_t *ppos)
88232 {
88233 - struct ctl_table ipc_table;
88234 + ctl_table_no_const ipc_table;
88235 int oldval;
88236 int rc;
88237
88238 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88239 index 68d4e95..1477ded 100644
88240 --- a/ipc/mq_sysctl.c
88241 +++ b/ipc/mq_sysctl.c
88242 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88243 static int proc_mq_dointvec(struct ctl_table *table, int write,
88244 void __user *buffer, size_t *lenp, loff_t *ppos)
88245 {
88246 - struct ctl_table mq_table;
88247 + ctl_table_no_const mq_table;
88248 memcpy(&mq_table, table, sizeof(mq_table));
88249 mq_table.data = get_mq(table);
88250
88251 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88252 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88253 void __user *buffer, size_t *lenp, loff_t *ppos)
88254 {
88255 - struct ctl_table mq_table;
88256 + ctl_table_no_const mq_table;
88257 memcpy(&mq_table, table, sizeof(mq_table));
88258 mq_table.data = get_mq(table);
88259
88260 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88261 index 4fcf39a..d3cc2ec 100644
88262 --- a/ipc/mqueue.c
88263 +++ b/ipc/mqueue.c
88264 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88265 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88266 info->attr.mq_msgsize);
88267
88268 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88269 spin_lock(&mq_lock);
88270 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88271 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88272 diff --git a/ipc/shm.c b/ipc/shm.c
88273 index 0145479..3d27947 100644
88274 --- a/ipc/shm.c
88275 +++ b/ipc/shm.c
88276 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88277 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88278 #endif
88279
88280 +#ifdef CONFIG_GRKERNSEC
88281 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88282 + const u64 shm_createtime, const kuid_t cuid,
88283 + const int shmid);
88284 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88285 + const u64 shm_createtime);
88286 +#endif
88287 +
88288 void shm_init_ns(struct ipc_namespace *ns)
88289 {
88290 ns->shm_ctlmax = SHMMAX;
88291 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88292 shp->shm_lprid = 0;
88293 shp->shm_atim = shp->shm_dtim = 0;
88294 shp->shm_ctim = get_seconds();
88295 +#ifdef CONFIG_GRKERNSEC
88296 + shp->shm_createtime = ktime_get_ns();
88297 +#endif
88298 shp->shm_segsz = size;
88299 shp->shm_nattch = 0;
88300 shp->shm_file = file;
88301 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88302 f_mode = FMODE_READ | FMODE_WRITE;
88303 }
88304 if (shmflg & SHM_EXEC) {
88305 +
88306 +#ifdef CONFIG_PAX_MPROTECT
88307 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88308 + goto out;
88309 +#endif
88310 +
88311 prot |= PROT_EXEC;
88312 acc_mode |= S_IXUGO;
88313 }
88314 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88315 if (err)
88316 goto out_unlock;
88317
88318 +#ifdef CONFIG_GRKERNSEC
88319 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88320 + shp->shm_perm.cuid, shmid) ||
88321 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88322 + err = -EACCES;
88323 + goto out_unlock;
88324 + }
88325 +#endif
88326 +
88327 ipc_lock_object(&shp->shm_perm);
88328
88329 /* check if shm_destroy() is tearing down shp */
88330 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88331 path = shp->shm_file->f_path;
88332 path_get(&path);
88333 shp->shm_nattch++;
88334 +#ifdef CONFIG_GRKERNSEC
88335 + shp->shm_lapid = current->pid;
88336 +#endif
88337 size = i_size_read(path.dentry->d_inode);
88338 ipc_unlock_object(&shp->shm_perm);
88339 rcu_read_unlock();
88340 diff --git a/ipc/util.c b/ipc/util.c
88341 index 88adc32..3867c68 100644
88342 --- a/ipc/util.c
88343 +++ b/ipc/util.c
88344 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88345 int (*show)(struct seq_file *, void *);
88346 };
88347
88348 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88349 +
88350 static void ipc_memory_notifier(struct work_struct *work)
88351 {
88352 ipcns_notify(IPCNS_MEMCHANGED);
88353 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88354 granted_mode >>= 6;
88355 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88356 granted_mode >>= 3;
88357 +
88358 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88359 + return -1;
88360 +
88361 /* is there some bit set in requested_mode but not in granted_mode? */
88362 if ((requested_mode & ~granted_mode & 0007) &&
88363 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88364 diff --git a/kernel/audit.c b/kernel/audit.c
88365 index c6df990..fde80b4 100644
88366 --- a/kernel/audit.c
88367 +++ b/kernel/audit.c
88368 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88369 3) suppressed due to audit_rate_limit
88370 4) suppressed due to audit_backlog_limit
88371 */
88372 -static atomic_t audit_lost = ATOMIC_INIT(0);
88373 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88374
88375 /* The netlink socket. */
88376 static struct sock *audit_sock;
88377 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88378 unsigned long now;
88379 int print;
88380
88381 - atomic_inc(&audit_lost);
88382 + atomic_inc_unchecked(&audit_lost);
88383
88384 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88385
88386 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88387 if (print) {
88388 if (printk_ratelimit())
88389 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88390 - atomic_read(&audit_lost),
88391 + atomic_read_unchecked(&audit_lost),
88392 audit_rate_limit,
88393 audit_backlog_limit);
88394 audit_panic(message);
88395 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88396 s.pid = audit_pid;
88397 s.rate_limit = audit_rate_limit;
88398 s.backlog_limit = audit_backlog_limit;
88399 - s.lost = atomic_read(&audit_lost);
88400 + s.lost = atomic_read_unchecked(&audit_lost);
88401 s.backlog = skb_queue_len(&audit_skb_queue);
88402 s.version = AUDIT_VERSION_LATEST;
88403 s.backlog_wait_time = audit_backlog_wait_time;
88404 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88405 index e420a0c..38137fa 100644
88406 --- a/kernel/auditsc.c
88407 +++ b/kernel/auditsc.c
88408 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88409 }
88410
88411 /* global counter which is incremented every time something logs in */
88412 -static atomic_t session_id = ATOMIC_INIT(0);
88413 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88414
88415 static int audit_set_loginuid_perm(kuid_t loginuid)
88416 {
88417 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88418
88419 /* are we setting or clearing? */
88420 if (uid_valid(loginuid))
88421 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88422 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88423
88424 task->sessionid = sessionid;
88425 task->loginuid = loginuid;
88426 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88427 index d6594e4..597264b 100644
88428 --- a/kernel/bpf/core.c
88429 +++ b/kernel/bpf/core.c
88430 @@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88431 * random section of illegal instructions.
88432 */
88433 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88434 - hdr = module_alloc(size);
88435 + hdr = module_alloc_exec(size);
88436 if (hdr == NULL)
88437 return NULL;
88438
88439 /* Fill space with illegal/arch-dep instructions. */
88440 bpf_fill_ill_insns(hdr, size);
88441
88442 + pax_open_kernel();
88443 hdr->pages = size / PAGE_SIZE;
88444 + pax_close_kernel();
88445 +
88446 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88447 PAGE_SIZE - sizeof(*hdr));
88448 start = (prandom_u32() % hole) & ~(alignment - 1);
88449 @@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88450
88451 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88452 {
88453 - module_free(NULL, hdr);
88454 + module_free_exec(NULL, hdr);
88455 }
88456 #endif /* CONFIG_BPF_JIT */
88457
88458 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88459 index ba61c8c..c60c486 100644
88460 --- a/kernel/bpf/syscall.c
88461 +++ b/kernel/bpf/syscall.c
88462 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88463 int err;
88464
88465 /* the syscall is limited to root temporarily. This restriction will be
88466 - * lifted when security audit is clean. Note that eBPF+tracing must have
88467 - * this restriction, since it may pass kernel data to user space
88468 + * lifted by upstream when a half-assed security audit is clean. Note
88469 + * that eBPF+tracing must have this restriction, since it may pass
88470 + * kernel data to user space
88471 */
88472 if (!capable(CAP_SYS_ADMIN))
88473 return -EPERM;
88474 +#ifdef CONFIG_GRKERNSEC
88475 + return -EPERM;
88476 +#endif
88477
88478 if (!access_ok(VERIFY_READ, uattr, 1))
88479 return -EFAULT;
88480 diff --git a/kernel/capability.c b/kernel/capability.c
88481 index 989f5bf..d317ca0 100644
88482 --- a/kernel/capability.c
88483 +++ b/kernel/capability.c
88484 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88485 * before modification is attempted and the application
88486 * fails.
88487 */
88488 + if (tocopy > ARRAY_SIZE(kdata))
88489 + return -EFAULT;
88490 +
88491 if (copy_to_user(dataptr, kdata, tocopy
88492 * sizeof(struct __user_cap_data_struct))) {
88493 return -EFAULT;
88494 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88495 int ret;
88496
88497 rcu_read_lock();
88498 - ret = security_capable(__task_cred(t), ns, cap);
88499 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88500 + gr_task_is_capable(t, __task_cred(t), cap);
88501 rcu_read_unlock();
88502
88503 - return (ret == 0);
88504 + return ret;
88505 }
88506
88507 /**
88508 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88509 int ret;
88510
88511 rcu_read_lock();
88512 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88513 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88514 rcu_read_unlock();
88515
88516 - return (ret == 0);
88517 + return ret;
88518 }
88519
88520 /**
88521 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88522 BUG();
88523 }
88524
88525 - if (security_capable(current_cred(), ns, cap) == 0) {
88526 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88527 current->flags |= PF_SUPERPRIV;
88528 return true;
88529 }
88530 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88531 }
88532 EXPORT_SYMBOL(ns_capable);
88533
88534 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88535 +{
88536 + if (unlikely(!cap_valid(cap))) {
88537 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88538 + BUG();
88539 + }
88540 +
88541 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88542 + current->flags |= PF_SUPERPRIV;
88543 + return true;
88544 + }
88545 + return false;
88546 +}
88547 +EXPORT_SYMBOL(ns_capable_nolog);
88548 +
88549 /**
88550 * file_ns_capable - Determine if the file's opener had a capability in effect
88551 * @file: The file we want to check
88552 @@ -427,6 +446,12 @@ bool capable(int cap)
88553 }
88554 EXPORT_SYMBOL(capable);
88555
88556 +bool capable_nolog(int cap)
88557 +{
88558 + return ns_capable_nolog(&init_user_ns, cap);
88559 +}
88560 +EXPORT_SYMBOL(capable_nolog);
88561 +
88562 /**
88563 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88564 * @inode: The inode in question
88565 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88566 kgid_has_mapping(ns, inode->i_gid);
88567 }
88568 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88569 +
88570 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88571 +{
88572 + struct user_namespace *ns = current_user_ns();
88573 +
88574 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88575 + kgid_has_mapping(ns, inode->i_gid);
88576 +}
88577 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88578 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88579 index 136ecea..45157a6 100644
88580 --- a/kernel/cgroup.c
88581 +++ b/kernel/cgroup.c
88582 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88583 if (!pathbuf || !agentbuf)
88584 goto out;
88585
88586 + if (agentbuf[0] == '\0')
88587 + goto out;
88588 +
88589 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88590 if (!path)
88591 goto out;
88592 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88593 struct task_struct *task;
88594 int count = 0;
88595
88596 - seq_printf(seq, "css_set %p\n", cset);
88597 + seq_printf(seq, "css_set %pK\n", cset);
88598
88599 list_for_each_entry(task, &cset->tasks, cg_list) {
88600 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88601 diff --git a/kernel/compat.c b/kernel/compat.c
88602 index ebb3c36..1df606e 100644
88603 --- a/kernel/compat.c
88604 +++ b/kernel/compat.c
88605 @@ -13,6 +13,7 @@
88606
88607 #include <linux/linkage.h>
88608 #include <linux/compat.h>
88609 +#include <linux/module.h>
88610 #include <linux/errno.h>
88611 #include <linux/time.h>
88612 #include <linux/signal.h>
88613 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88614 mm_segment_t oldfs;
88615 long ret;
88616
88617 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88618 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88619 oldfs = get_fs();
88620 set_fs(KERNEL_DS);
88621 ret = hrtimer_nanosleep_restart(restart);
88622 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88623 oldfs = get_fs();
88624 set_fs(KERNEL_DS);
88625 ret = hrtimer_nanosleep(&tu,
88626 - rmtp ? (struct timespec __user *)&rmt : NULL,
88627 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88628 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88629 set_fs(oldfs);
88630
88631 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88632 mm_segment_t old_fs = get_fs();
88633
88634 set_fs(KERNEL_DS);
88635 - ret = sys_sigpending((old_sigset_t __user *) &s);
88636 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88637 set_fs(old_fs);
88638 if (ret == 0)
88639 ret = put_user(s, set);
88640 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88641 mm_segment_t old_fs = get_fs();
88642
88643 set_fs(KERNEL_DS);
88644 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88645 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88646 set_fs(old_fs);
88647
88648 if (!ret) {
88649 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88650 set_fs (KERNEL_DS);
88651 ret = sys_wait4(pid,
88652 (stat_addr ?
88653 - (unsigned int __user *) &status : NULL),
88654 - options, (struct rusage __user *) &r);
88655 + (unsigned int __force_user *) &status : NULL),
88656 + options, (struct rusage __force_user *) &r);
88657 set_fs (old_fs);
88658
88659 if (ret > 0) {
88660 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88661 memset(&info, 0, sizeof(info));
88662
88663 set_fs(KERNEL_DS);
88664 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88665 - uru ? (struct rusage __user *)&ru : NULL);
88666 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88667 + uru ? (struct rusage __force_user *)&ru : NULL);
88668 set_fs(old_fs);
88669
88670 if ((ret < 0) || (info.si_signo == 0))
88671 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88672 oldfs = get_fs();
88673 set_fs(KERNEL_DS);
88674 err = sys_timer_settime(timer_id, flags,
88675 - (struct itimerspec __user *) &newts,
88676 - (struct itimerspec __user *) &oldts);
88677 + (struct itimerspec __force_user *) &newts,
88678 + (struct itimerspec __force_user *) &oldts);
88679 set_fs(oldfs);
88680 if (!err && old && put_compat_itimerspec(old, &oldts))
88681 return -EFAULT;
88682 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88683 oldfs = get_fs();
88684 set_fs(KERNEL_DS);
88685 err = sys_timer_gettime(timer_id,
88686 - (struct itimerspec __user *) &ts);
88687 + (struct itimerspec __force_user *) &ts);
88688 set_fs(oldfs);
88689 if (!err && put_compat_itimerspec(setting, &ts))
88690 return -EFAULT;
88691 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88692 oldfs = get_fs();
88693 set_fs(KERNEL_DS);
88694 err = sys_clock_settime(which_clock,
88695 - (struct timespec __user *) &ts);
88696 + (struct timespec __force_user *) &ts);
88697 set_fs(oldfs);
88698 return err;
88699 }
88700 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88701 oldfs = get_fs();
88702 set_fs(KERNEL_DS);
88703 err = sys_clock_gettime(which_clock,
88704 - (struct timespec __user *) &ts);
88705 + (struct timespec __force_user *) &ts);
88706 set_fs(oldfs);
88707 if (!err && compat_put_timespec(&ts, tp))
88708 return -EFAULT;
88709 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88710
88711 oldfs = get_fs();
88712 set_fs(KERNEL_DS);
88713 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88714 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88715 set_fs(oldfs);
88716
88717 err = compat_put_timex(utp, &txc);
88718 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88719 oldfs = get_fs();
88720 set_fs(KERNEL_DS);
88721 err = sys_clock_getres(which_clock,
88722 - (struct timespec __user *) &ts);
88723 + (struct timespec __force_user *) &ts);
88724 set_fs(oldfs);
88725 if (!err && tp && compat_put_timespec(&ts, tp))
88726 return -EFAULT;
88727 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88728 struct timespec tu;
88729 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88730
88731 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88732 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88733 oldfs = get_fs();
88734 set_fs(KERNEL_DS);
88735 err = clock_nanosleep_restart(restart);
88736 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88737 oldfs = get_fs();
88738 set_fs(KERNEL_DS);
88739 err = sys_clock_nanosleep(which_clock, flags,
88740 - (struct timespec __user *) &in,
88741 - (struct timespec __user *) &out);
88742 + (struct timespec __force_user *) &in,
88743 + (struct timespec __force_user *) &out);
88744 set_fs(oldfs);
88745
88746 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88747 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88748 mm_segment_t old_fs = get_fs();
88749
88750 set_fs(KERNEL_DS);
88751 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88752 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88753 set_fs(old_fs);
88754 if (compat_put_timespec(&t, interval))
88755 return -EFAULT;
88756 diff --git a/kernel/configs.c b/kernel/configs.c
88757 index c18b1f1..b9a0132 100644
88758 --- a/kernel/configs.c
88759 +++ b/kernel/configs.c
88760 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88761 struct proc_dir_entry *entry;
88762
88763 /* create the current config file */
88764 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88765 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88766 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88767 + &ikconfig_file_ops);
88768 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88769 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88770 + &ikconfig_file_ops);
88771 +#endif
88772 +#else
88773 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88774 &ikconfig_file_ops);
88775 +#endif
88776 +
88777 if (!entry)
88778 return -ENOMEM;
88779
88780 diff --git a/kernel/cred.c b/kernel/cred.c
88781 index e0573a4..26c0fd3 100644
88782 --- a/kernel/cred.c
88783 +++ b/kernel/cred.c
88784 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88785 validate_creds(cred);
88786 alter_cred_subscribers(cred, -1);
88787 put_cred(cred);
88788 +
88789 +#ifdef CONFIG_GRKERNSEC_SETXID
88790 + cred = (struct cred *) tsk->delayed_cred;
88791 + if (cred != NULL) {
88792 + tsk->delayed_cred = NULL;
88793 + validate_creds(cred);
88794 + alter_cred_subscribers(cred, -1);
88795 + put_cred(cred);
88796 + }
88797 +#endif
88798 }
88799
88800 /**
88801 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88802 * Always returns 0 thus allowing this function to be tail-called at the end
88803 * of, say, sys_setgid().
88804 */
88805 -int commit_creds(struct cred *new)
88806 +static int __commit_creds(struct cred *new)
88807 {
88808 struct task_struct *task = current;
88809 const struct cred *old = task->real_cred;
88810 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88811
88812 get_cred(new); /* we will require a ref for the subj creds too */
88813
88814 + gr_set_role_label(task, new->uid, new->gid);
88815 +
88816 /* dumpability changes */
88817 if (!uid_eq(old->euid, new->euid) ||
88818 !gid_eq(old->egid, new->egid) ||
88819 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88820 put_cred(old);
88821 return 0;
88822 }
88823 +#ifdef CONFIG_GRKERNSEC_SETXID
88824 +extern int set_user(struct cred *new);
88825 +
88826 +void gr_delayed_cred_worker(void)
88827 +{
88828 + const struct cred *new = current->delayed_cred;
88829 + struct cred *ncred;
88830 +
88831 + current->delayed_cred = NULL;
88832 +
88833 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88834 + // from doing get_cred on it when queueing this
88835 + put_cred(new);
88836 + return;
88837 + } else if (new == NULL)
88838 + return;
88839 +
88840 + ncred = prepare_creds();
88841 + if (!ncred)
88842 + goto die;
88843 + // uids
88844 + ncred->uid = new->uid;
88845 + ncred->euid = new->euid;
88846 + ncred->suid = new->suid;
88847 + ncred->fsuid = new->fsuid;
88848 + // gids
88849 + ncred->gid = new->gid;
88850 + ncred->egid = new->egid;
88851 + ncred->sgid = new->sgid;
88852 + ncred->fsgid = new->fsgid;
88853 + // groups
88854 + set_groups(ncred, new->group_info);
88855 + // caps
88856 + ncred->securebits = new->securebits;
88857 + ncred->cap_inheritable = new->cap_inheritable;
88858 + ncred->cap_permitted = new->cap_permitted;
88859 + ncred->cap_effective = new->cap_effective;
88860 + ncred->cap_bset = new->cap_bset;
88861 +
88862 + if (set_user(ncred)) {
88863 + abort_creds(ncred);
88864 + goto die;
88865 + }
88866 +
88867 + // from doing get_cred on it when queueing this
88868 + put_cred(new);
88869 +
88870 + __commit_creds(ncred);
88871 + return;
88872 +die:
88873 + // from doing get_cred on it when queueing this
88874 + put_cred(new);
88875 + do_group_exit(SIGKILL);
88876 +}
88877 +#endif
88878 +
88879 +int commit_creds(struct cred *new)
88880 +{
88881 +#ifdef CONFIG_GRKERNSEC_SETXID
88882 + int ret;
88883 + int schedule_it = 0;
88884 + struct task_struct *t;
88885 + unsigned oldsecurebits = current_cred()->securebits;
88886 +
88887 + /* we won't get called with tasklist_lock held for writing
88888 + and interrupts disabled as the cred struct in that case is
88889 + init_cred
88890 + */
88891 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88892 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88893 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88894 + schedule_it = 1;
88895 + }
88896 + ret = __commit_creds(new);
88897 + if (schedule_it) {
88898 + rcu_read_lock();
88899 + read_lock(&tasklist_lock);
88900 + for (t = next_thread(current); t != current;
88901 + t = next_thread(t)) {
88902 + /* we'll check if the thread has uid 0 in
88903 + * the delayed worker routine
88904 + */
88905 + if (task_securebits(t) == oldsecurebits &&
88906 + t->delayed_cred == NULL) {
88907 + t->delayed_cred = get_cred(new);
88908 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88909 + set_tsk_need_resched(t);
88910 + }
88911 + }
88912 + read_unlock(&tasklist_lock);
88913 + rcu_read_unlock();
88914 + }
88915 +
88916 + return ret;
88917 +#else
88918 + return __commit_creds(new);
88919 +#endif
88920 +}
88921 +
88922 EXPORT_SYMBOL(commit_creds);
88923
88924 /**
88925 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88926 index 1adf62b..7736e06 100644
88927 --- a/kernel/debug/debug_core.c
88928 +++ b/kernel/debug/debug_core.c
88929 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88930 */
88931 static atomic_t masters_in_kgdb;
88932 static atomic_t slaves_in_kgdb;
88933 -static atomic_t kgdb_break_tasklet_var;
88934 +static atomic_unchecked_t kgdb_break_tasklet_var;
88935 atomic_t kgdb_setting_breakpoint;
88936
88937 struct task_struct *kgdb_usethread;
88938 @@ -134,7 +134,7 @@ int kgdb_single_step;
88939 static pid_t kgdb_sstep_pid;
88940
88941 /* to keep track of the CPU which is doing the single stepping*/
88942 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88943 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88944
88945 /*
88946 * If you are debugging a problem where roundup (the collection of
88947 @@ -549,7 +549,7 @@ return_normal:
88948 * kernel will only try for the value of sstep_tries before
88949 * giving up and continuing on.
88950 */
88951 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88952 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88953 (kgdb_info[cpu].task &&
88954 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88955 atomic_set(&kgdb_active, -1);
88956 @@ -647,8 +647,8 @@ cpu_master_loop:
88957 }
88958
88959 kgdb_restore:
88960 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88961 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88962 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88963 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88964 if (kgdb_info[sstep_cpu].task)
88965 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88966 else
88967 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88968 static void kgdb_tasklet_bpt(unsigned long ing)
88969 {
88970 kgdb_breakpoint();
88971 - atomic_set(&kgdb_break_tasklet_var, 0);
88972 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88973 }
88974
88975 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88976
88977 void kgdb_schedule_breakpoint(void)
88978 {
88979 - if (atomic_read(&kgdb_break_tasklet_var) ||
88980 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88981 atomic_read(&kgdb_active) != -1 ||
88982 atomic_read(&kgdb_setting_breakpoint))
88983 return;
88984 - atomic_inc(&kgdb_break_tasklet_var);
88985 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88986 tasklet_schedule(&kgdb_tasklet_breakpoint);
88987 }
88988 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88989 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88990 index 379650b..30c5180 100644
88991 --- a/kernel/debug/kdb/kdb_main.c
88992 +++ b/kernel/debug/kdb/kdb_main.c
88993 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88994 continue;
88995
88996 kdb_printf("%-20s%8u 0x%p ", mod->name,
88997 - mod->core_size, (void *)mod);
88998 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88999 #ifdef CONFIG_MODULE_UNLOAD
89000 kdb_printf("%4ld ", module_refcount(mod));
89001 #endif
89002 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89003 kdb_printf(" (Loading)");
89004 else
89005 kdb_printf(" (Live)");
89006 - kdb_printf(" 0x%p", mod->module_core);
89007 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89008
89009 #ifdef CONFIG_MODULE_UNLOAD
89010 {
89011 diff --git a/kernel/events/core.c b/kernel/events/core.c
89012 index 2ab0238..bf89262f5 100644
89013 --- a/kernel/events/core.c
89014 +++ b/kernel/events/core.c
89015 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
89016 * 0 - disallow raw tracepoint access for unpriv
89017 * 1 - disallow cpu events for unpriv
89018 * 2 - disallow kernel profiling for unpriv
89019 + * 3 - disallow all unpriv perf event use
89020 */
89021 -int sysctl_perf_event_paranoid __read_mostly = 1;
89022 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89023 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89024 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89025 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89026 +#else
89027 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89028 +#endif
89029
89030 /* Minimum for 512 kiB + 1 user control page */
89031 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89032 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
89033
89034 tmp *= sysctl_perf_cpu_time_max_percent;
89035 do_div(tmp, 100);
89036 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89037 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89038 }
89039
89040 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89041 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89042 }
89043 }
89044
89045 -static atomic64_t perf_event_id;
89046 +static atomic64_unchecked_t perf_event_id;
89047
89048 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89049 enum event_type_t event_type);
89050 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
89051
89052 static inline u64 perf_event_count(struct perf_event *event)
89053 {
89054 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89055 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89056 }
89057
89058 static u64 perf_event_read(struct perf_event *event)
89059 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89060 mutex_lock(&event->child_mutex);
89061 total += perf_event_read(event);
89062 *enabled += event->total_time_enabled +
89063 - atomic64_read(&event->child_total_time_enabled);
89064 + atomic64_read_unchecked(&event->child_total_time_enabled);
89065 *running += event->total_time_running +
89066 - atomic64_read(&event->child_total_time_running);
89067 + atomic64_read_unchecked(&event->child_total_time_running);
89068
89069 list_for_each_entry(child, &event->child_list, child_list) {
89070 total += perf_event_read(child);
89071 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
89072 userpg->offset -= local64_read(&event->hw.prev_count);
89073
89074 userpg->time_enabled = enabled +
89075 - atomic64_read(&event->child_total_time_enabled);
89076 + atomic64_read_unchecked(&event->child_total_time_enabled);
89077
89078 userpg->time_running = running +
89079 - atomic64_read(&event->child_total_time_running);
89080 + atomic64_read_unchecked(&event->child_total_time_running);
89081
89082 arch_perf_update_userpage(userpg, now);
89083
89084 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89085
89086 /* Data. */
89087 sp = perf_user_stack_pointer(regs);
89088 - rem = __output_copy_user(handle, (void *) sp, dump_size);
89089 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89090 dyn_size = dump_size - rem;
89091
89092 perf_output_skip(handle, rem);
89093 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89094 values[n++] = perf_event_count(event);
89095 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89096 values[n++] = enabled +
89097 - atomic64_read(&event->child_total_time_enabled);
89098 + atomic64_read_unchecked(&event->child_total_time_enabled);
89099 }
89100 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89101 values[n++] = running +
89102 - atomic64_read(&event->child_total_time_running);
89103 + atomic64_read_unchecked(&event->child_total_time_running);
89104 }
89105 if (read_format & PERF_FORMAT_ID)
89106 values[n++] = primary_event_id(event);
89107 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89108 event->parent = parent_event;
89109
89110 event->ns = get_pid_ns(task_active_pid_ns(current));
89111 - event->id = atomic64_inc_return(&perf_event_id);
89112 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89113
89114 event->state = PERF_EVENT_STATE_INACTIVE;
89115
89116 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
89117 if (flags & ~PERF_FLAG_ALL)
89118 return -EINVAL;
89119
89120 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89121 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89122 + return -EACCES;
89123 +#endif
89124 +
89125 err = perf_copy_attr(attr_uptr, &attr);
89126 if (err)
89127 return err;
89128 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
89129 /*
89130 * Add back the child's count to the parent's count:
89131 */
89132 - atomic64_add(child_val, &parent_event->child_count);
89133 - atomic64_add(child_event->total_time_enabled,
89134 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89135 + atomic64_add_unchecked(child_event->total_time_enabled,
89136 &parent_event->child_total_time_enabled);
89137 - atomic64_add(child_event->total_time_running,
89138 + atomic64_add_unchecked(child_event->total_time_running,
89139 &parent_event->child_total_time_running);
89140
89141 /*
89142 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89143 index 569b2187..19940d9 100644
89144 --- a/kernel/events/internal.h
89145 +++ b/kernel/events/internal.h
89146 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89147 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89148 }
89149
89150 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89151 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89152 static inline unsigned long \
89153 func_name(struct perf_output_handle *handle, \
89154 - const void *buf, unsigned long len) \
89155 + const void user *buf, unsigned long len) \
89156 { \
89157 unsigned long size, written; \
89158 \
89159 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89160 return 0;
89161 }
89162
89163 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89164 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89165
89166 static inline unsigned long
89167 memcpy_skip(void *dst, const void *src, unsigned long n)
89168 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89169 return 0;
89170 }
89171
89172 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89173 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89174
89175 #ifndef arch_perf_out_copy_user
89176 #define arch_perf_out_copy_user arch_perf_out_copy_user
89177 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89178 }
89179 #endif
89180
89181 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89182 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89183
89184 /* Callchain handling */
89185 extern struct perf_callchain_entry *
89186 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89187 index ed8f2cd..fe8030c 100644
89188 --- a/kernel/events/uprobes.c
89189 +++ b/kernel/events/uprobes.c
89190 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89191 {
89192 struct page *page;
89193 uprobe_opcode_t opcode;
89194 - int result;
89195 + long result;
89196
89197 pagefault_disable();
89198 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89199 diff --git a/kernel/exit.c b/kernel/exit.c
89200 index 2116aac..d95df2a 100644
89201 --- a/kernel/exit.c
89202 +++ b/kernel/exit.c
89203 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
89204 struct task_struct *leader;
89205 int zap_leader;
89206 repeat:
89207 +#ifdef CONFIG_NET
89208 + gr_del_task_from_ip_table(p);
89209 +#endif
89210 +
89211 /* don't need to get the RCU readlock here - the process is dead and
89212 * can't be modifying its own credentials. But shut RCU-lockdep up */
89213 rcu_read_lock();
89214 @@ -670,6 +674,8 @@ void do_exit(long code)
89215 int group_dead;
89216 TASKS_RCU(int tasks_rcu_i);
89217
89218 + set_fs(USER_DS);
89219 +
89220 profile_task_exit(tsk);
89221
89222 WARN_ON(blk_needs_flush_plug(tsk));
89223 @@ -686,7 +692,6 @@ void do_exit(long code)
89224 * mm_release()->clear_child_tid() from writing to a user-controlled
89225 * kernel address.
89226 */
89227 - set_fs(USER_DS);
89228
89229 ptrace_event(PTRACE_EVENT_EXIT, code);
89230
89231 @@ -744,6 +749,9 @@ void do_exit(long code)
89232 tsk->exit_code = code;
89233 taskstats_exit(tsk, group_dead);
89234
89235 + gr_acl_handle_psacct(tsk, code);
89236 + gr_acl_handle_exit();
89237 +
89238 exit_mm(tsk);
89239
89240 if (group_dead)
89241 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89242 * Take down every thread in the group. This is called by fatal signals
89243 * as well as by sys_exit_group (below).
89244 */
89245 -void
89246 +__noreturn void
89247 do_group_exit(int exit_code)
89248 {
89249 struct signal_struct *sig = current->signal;
89250 diff --git a/kernel/fork.c b/kernel/fork.c
89251 index 9b7d746..5b898ab 100644
89252 --- a/kernel/fork.c
89253 +++ b/kernel/fork.c
89254 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89255 # endif
89256 #endif
89257
89258 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89259 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89260 + int node, void **lowmem_stack)
89261 +{
89262 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89263 + void *ret = NULL;
89264 + unsigned int i;
89265 +
89266 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89267 + if (*lowmem_stack == NULL)
89268 + goto out;
89269 +
89270 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89271 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89272 +
89273 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89274 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89275 + if (ret == NULL) {
89276 + free_thread_info(*lowmem_stack);
89277 + *lowmem_stack = NULL;
89278 + }
89279 +
89280 +out:
89281 + return ret;
89282 +}
89283 +
89284 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89285 +{
89286 + unmap_process_stacks(tsk);
89287 +}
89288 +#else
89289 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89290 + int node, void **lowmem_stack)
89291 +{
89292 + return alloc_thread_info_node(tsk, node);
89293 +}
89294 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89295 +{
89296 + free_thread_info(ti);
89297 +}
89298 +#endif
89299 +
89300 /* SLAB cache for signal_struct structures (tsk->signal) */
89301 static struct kmem_cache *signal_cachep;
89302
89303 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89304 /* SLAB cache for mm_struct structures (tsk->mm) */
89305 static struct kmem_cache *mm_cachep;
89306
89307 -static void account_kernel_stack(struct thread_info *ti, int account)
89308 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89309 {
89310 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89311 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89312 +#else
89313 struct zone *zone = page_zone(virt_to_page(ti));
89314 +#endif
89315
89316 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89317 }
89318
89319 void free_task(struct task_struct *tsk)
89320 {
89321 - account_kernel_stack(tsk->stack, -1);
89322 + account_kernel_stack(tsk, tsk->stack, -1);
89323 arch_release_thread_info(tsk->stack);
89324 - free_thread_info(tsk->stack);
89325 + gr_free_thread_info(tsk, tsk->stack);
89326 rt_mutex_debug_task_free(tsk);
89327 ftrace_graph_exit_task(tsk);
89328 put_seccomp_filter(tsk);
89329 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89330 {
89331 struct task_struct *tsk;
89332 struct thread_info *ti;
89333 + void *lowmem_stack;
89334 int node = tsk_fork_get_node(orig);
89335 int err;
89336
89337 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89338 if (!tsk)
89339 return NULL;
89340
89341 - ti = alloc_thread_info_node(tsk, node);
89342 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89343 if (!ti)
89344 goto free_tsk;
89345
89346 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89347 goto free_ti;
89348
89349 tsk->stack = ti;
89350 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89351 + tsk->lowmem_stack = lowmem_stack;
89352 +#endif
89353 #ifdef CONFIG_SECCOMP
89354 /*
89355 * We must handle setting up seccomp filters once we're under
89356 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89357 set_task_stack_end_magic(tsk);
89358
89359 #ifdef CONFIG_CC_STACKPROTECTOR
89360 - tsk->stack_canary = get_random_int();
89361 + tsk->stack_canary = pax_get_random_long();
89362 #endif
89363
89364 /*
89365 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89366 tsk->splice_pipe = NULL;
89367 tsk->task_frag.page = NULL;
89368
89369 - account_kernel_stack(ti, 1);
89370 + account_kernel_stack(tsk, ti, 1);
89371
89372 return tsk;
89373
89374 free_ti:
89375 - free_thread_info(ti);
89376 + gr_free_thread_info(tsk, ti);
89377 free_tsk:
89378 free_task_struct(tsk);
89379 return NULL;
89380 }
89381
89382 #ifdef CONFIG_MMU
89383 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89384 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89385 +{
89386 + struct vm_area_struct *tmp;
89387 + unsigned long charge;
89388 + struct file *file;
89389 + int retval;
89390 +
89391 + charge = 0;
89392 + if (mpnt->vm_flags & VM_ACCOUNT) {
89393 + unsigned long len = vma_pages(mpnt);
89394 +
89395 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89396 + goto fail_nomem;
89397 + charge = len;
89398 + }
89399 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89400 + if (!tmp)
89401 + goto fail_nomem;
89402 + *tmp = *mpnt;
89403 + tmp->vm_mm = mm;
89404 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89405 + retval = vma_dup_policy(mpnt, tmp);
89406 + if (retval)
89407 + goto fail_nomem_policy;
89408 + if (anon_vma_fork(tmp, mpnt))
89409 + goto fail_nomem_anon_vma_fork;
89410 + tmp->vm_flags &= ~VM_LOCKED;
89411 + tmp->vm_next = tmp->vm_prev = NULL;
89412 + tmp->vm_mirror = NULL;
89413 + file = tmp->vm_file;
89414 + if (file) {
89415 + struct inode *inode = file_inode(file);
89416 + struct address_space *mapping = file->f_mapping;
89417 +
89418 + get_file(file);
89419 + if (tmp->vm_flags & VM_DENYWRITE)
89420 + atomic_dec(&inode->i_writecount);
89421 + mutex_lock(&mapping->i_mmap_mutex);
89422 + if (tmp->vm_flags & VM_SHARED)
89423 + atomic_inc(&mapping->i_mmap_writable);
89424 + flush_dcache_mmap_lock(mapping);
89425 + /* insert tmp into the share list, just after mpnt */
89426 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89427 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89428 + else
89429 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89430 + flush_dcache_mmap_unlock(mapping);
89431 + mutex_unlock(&mapping->i_mmap_mutex);
89432 + }
89433 +
89434 + /*
89435 + * Clear hugetlb-related page reserves for children. This only
89436 + * affects MAP_PRIVATE mappings. Faults generated by the child
89437 + * are not guaranteed to succeed, even if read-only
89438 + */
89439 + if (is_vm_hugetlb_page(tmp))
89440 + reset_vma_resv_huge_pages(tmp);
89441 +
89442 + return tmp;
89443 +
89444 +fail_nomem_anon_vma_fork:
89445 + mpol_put(vma_policy(tmp));
89446 +fail_nomem_policy:
89447 + kmem_cache_free(vm_area_cachep, tmp);
89448 +fail_nomem:
89449 + vm_unacct_memory(charge);
89450 + return NULL;
89451 +}
89452 +
89453 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89454 {
89455 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89456 struct rb_node **rb_link, *rb_parent;
89457 int retval;
89458 - unsigned long charge;
89459
89460 uprobe_start_dup_mmap();
89461 down_write(&oldmm->mmap_sem);
89462 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89463
89464 prev = NULL;
89465 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89466 - struct file *file;
89467 -
89468 if (mpnt->vm_flags & VM_DONTCOPY) {
89469 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89470 -vma_pages(mpnt));
89471 continue;
89472 }
89473 - charge = 0;
89474 - if (mpnt->vm_flags & VM_ACCOUNT) {
89475 - unsigned long len = vma_pages(mpnt);
89476 -
89477 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89478 - goto fail_nomem;
89479 - charge = len;
89480 - }
89481 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89482 - if (!tmp)
89483 - goto fail_nomem;
89484 - *tmp = *mpnt;
89485 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89486 - retval = vma_dup_policy(mpnt, tmp);
89487 - if (retval)
89488 - goto fail_nomem_policy;
89489 - tmp->vm_mm = mm;
89490 - if (anon_vma_fork(tmp, mpnt))
89491 - goto fail_nomem_anon_vma_fork;
89492 - tmp->vm_flags &= ~VM_LOCKED;
89493 - tmp->vm_next = tmp->vm_prev = NULL;
89494 - file = tmp->vm_file;
89495 - if (file) {
89496 - struct inode *inode = file_inode(file);
89497 - struct address_space *mapping = file->f_mapping;
89498 -
89499 - get_file(file);
89500 - if (tmp->vm_flags & VM_DENYWRITE)
89501 - atomic_dec(&inode->i_writecount);
89502 - mutex_lock(&mapping->i_mmap_mutex);
89503 - if (tmp->vm_flags & VM_SHARED)
89504 - atomic_inc(&mapping->i_mmap_writable);
89505 - flush_dcache_mmap_lock(mapping);
89506 - /* insert tmp into the share list, just after mpnt */
89507 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89508 - vma_nonlinear_insert(tmp,
89509 - &mapping->i_mmap_nonlinear);
89510 - else
89511 - vma_interval_tree_insert_after(tmp, mpnt,
89512 - &mapping->i_mmap);
89513 - flush_dcache_mmap_unlock(mapping);
89514 - mutex_unlock(&mapping->i_mmap_mutex);
89515 + tmp = dup_vma(mm, oldmm, mpnt);
89516 + if (!tmp) {
89517 + retval = -ENOMEM;
89518 + goto out;
89519 }
89520
89521 /*
89522 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89523 if (retval)
89524 goto out;
89525 }
89526 +
89527 +#ifdef CONFIG_PAX_SEGMEXEC
89528 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89529 + struct vm_area_struct *mpnt_m;
89530 +
89531 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89532 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89533 +
89534 + if (!mpnt->vm_mirror)
89535 + continue;
89536 +
89537 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89538 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89539 + mpnt->vm_mirror = mpnt_m;
89540 + } else {
89541 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89542 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89543 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89544 + mpnt->vm_mirror->vm_mirror = mpnt;
89545 + }
89546 + }
89547 + BUG_ON(mpnt_m);
89548 + }
89549 +#endif
89550 +
89551 /* a new mm has just been created */
89552 arch_dup_mmap(oldmm, mm);
89553 retval = 0;
89554 @@ -486,14 +589,6 @@ out:
89555 up_write(&oldmm->mmap_sem);
89556 uprobe_end_dup_mmap();
89557 return retval;
89558 -fail_nomem_anon_vma_fork:
89559 - mpol_put(vma_policy(tmp));
89560 -fail_nomem_policy:
89561 - kmem_cache_free(vm_area_cachep, tmp);
89562 -fail_nomem:
89563 - retval = -ENOMEM;
89564 - vm_unacct_memory(charge);
89565 - goto out;
89566 }
89567
89568 static inline int mm_alloc_pgd(struct mm_struct *mm)
89569 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89570 return ERR_PTR(err);
89571
89572 mm = get_task_mm(task);
89573 - if (mm && mm != current->mm &&
89574 - !ptrace_may_access(task, mode)) {
89575 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89576 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89577 mmput(mm);
89578 mm = ERR_PTR(-EACCES);
89579 }
89580 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89581 spin_unlock(&fs->lock);
89582 return -EAGAIN;
89583 }
89584 - fs->users++;
89585 + atomic_inc(&fs->users);
89586 spin_unlock(&fs->lock);
89587 return 0;
89588 }
89589 tsk->fs = copy_fs_struct(fs);
89590 if (!tsk->fs)
89591 return -ENOMEM;
89592 + /* Carry through gr_chroot_dentry and is_chrooted instead
89593 + of recomputing it here. Already copied when the task struct
89594 + is duplicated. This allows pivot_root to not be treated as
89595 + a chroot
89596 + */
89597 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89598 +
89599 return 0;
89600 }
89601
89602 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89603 * parts of the process environment (as per the clone
89604 * flags). The actual kick-off is left to the caller.
89605 */
89606 -static struct task_struct *copy_process(unsigned long clone_flags,
89607 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89608 unsigned long stack_start,
89609 unsigned long stack_size,
89610 int __user *child_tidptr,
89611 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89612 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89613 #endif
89614 retval = -EAGAIN;
89615 +
89616 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89617 +
89618 if (atomic_read(&p->real_cred->user->processes) >=
89619 task_rlimit(p, RLIMIT_NPROC)) {
89620 if (p->real_cred->user != INIT_USER &&
89621 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89622 goto bad_fork_free_pid;
89623 }
89624
89625 + /* synchronizes with gr_set_acls()
89626 + we need to call this past the point of no return for fork()
89627 + */
89628 + gr_copy_label(p);
89629 +
89630 if (likely(p->pid)) {
89631 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89632
89633 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89634 bad_fork_free:
89635 free_task(p);
89636 fork_out:
89637 + gr_log_forkfail(retval);
89638 +
89639 return ERR_PTR(retval);
89640 }
89641
89642 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89643
89644 p = copy_process(clone_flags, stack_start, stack_size,
89645 child_tidptr, NULL, trace);
89646 + add_latent_entropy();
89647 /*
89648 * Do this prior waking up the new thread - the thread pointer
89649 * might get invalid after that point, if the thread exits quickly.
89650 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89651 if (clone_flags & CLONE_PARENT_SETTID)
89652 put_user(nr, parent_tidptr);
89653
89654 + gr_handle_brute_check();
89655 +
89656 if (clone_flags & CLONE_VFORK) {
89657 p->vfork_done = &vfork;
89658 init_completion(&vfork);
89659 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89660 mm_cachep = kmem_cache_create("mm_struct",
89661 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89662 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89663 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89664 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89665 mmap_init();
89666 nsproxy_cache_init();
89667 }
89668 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89669 return 0;
89670
89671 /* don't need lock here; in the worst case we'll do useless copy */
89672 - if (fs->users == 1)
89673 + if (atomic_read(&fs->users) == 1)
89674 return 0;
89675
89676 *new_fsp = copy_fs_struct(fs);
89677 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89678 fs = current->fs;
89679 spin_lock(&fs->lock);
89680 current->fs = new_fs;
89681 - if (--fs->users)
89682 + gr_set_chroot_entries(current, &current->fs->root);
89683 + if (atomic_dec_return(&fs->users))
89684 new_fs = NULL;
89685 else
89686 new_fs = fs;
89687 diff --git a/kernel/futex.c b/kernel/futex.c
89688 index 63678b5..512f9af 100644
89689 --- a/kernel/futex.c
89690 +++ b/kernel/futex.c
89691 @@ -201,7 +201,7 @@ struct futex_pi_state {
89692 atomic_t refcount;
89693
89694 union futex_key key;
89695 -};
89696 +} __randomize_layout;
89697
89698 /**
89699 * struct futex_q - The hashed futex queue entry, one per waiting task
89700 @@ -235,7 +235,7 @@ struct futex_q {
89701 struct rt_mutex_waiter *rt_waiter;
89702 union futex_key *requeue_pi_key;
89703 u32 bitset;
89704 -};
89705 +} __randomize_layout;
89706
89707 static const struct futex_q futex_q_init = {
89708 /* list gets initialized in queue_me()*/
89709 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89710 struct page *page, *page_head;
89711 int err, ro = 0;
89712
89713 +#ifdef CONFIG_PAX_SEGMEXEC
89714 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89715 + return -EFAULT;
89716 +#endif
89717 +
89718 /*
89719 * The futex address must be "naturally" aligned.
89720 */
89721 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89722
89723 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89724 {
89725 - int ret;
89726 + unsigned long ret;
89727
89728 pagefault_disable();
89729 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89730 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89731 {
89732 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89733 u32 curval;
89734 + mm_segment_t oldfs;
89735
89736 /*
89737 * This will fail and we want it. Some arch implementations do
89738 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89739 * implementation, the non-functional ones will return
89740 * -ENOSYS.
89741 */
89742 + oldfs = get_fs();
89743 + set_fs(USER_DS);
89744 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89745 futex_cmpxchg_enabled = 1;
89746 + set_fs(oldfs);
89747 #endif
89748 }
89749
89750 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89751 index 55c8c93..9ba7ad6 100644
89752 --- a/kernel/futex_compat.c
89753 +++ b/kernel/futex_compat.c
89754 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89755 return 0;
89756 }
89757
89758 -static void __user *futex_uaddr(struct robust_list __user *entry,
89759 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89760 compat_long_t futex_offset)
89761 {
89762 compat_uptr_t base = ptr_to_compat(entry);
89763 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89764 index b358a80..fc25240 100644
89765 --- a/kernel/gcov/base.c
89766 +++ b/kernel/gcov/base.c
89767 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89768 }
89769
89770 #ifdef CONFIG_MODULES
89771 -static inline int within(void *addr, void *start, unsigned long size)
89772 -{
89773 - return ((addr >= start) && (addr < start + size));
89774 -}
89775 -
89776 /* Update list and generate events when modules are unloaded. */
89777 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89778 void *data)
89779 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89780
89781 /* Remove entries located in module from linked list. */
89782 while ((info = gcov_info_next(info))) {
89783 - if (within(info, mod->module_core, mod->core_size)) {
89784 + if (within_module_core_rw((unsigned long)info, mod)) {
89785 gcov_info_unlink(prev, info);
89786 if (gcov_events_enabled)
89787 gcov_event(GCOV_REMOVE, info);
89788 diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
89789 index 0a9104b..fc260e4 100644
89790 --- a/kernel/irq/manage.c
89791 +++ b/kernel/irq/manage.c
89792 @@ -869,7 +869,7 @@ static int irq_thread(void *data)
89793
89794 action_ret = handler_fn(desc, action);
89795 if (action_ret == IRQ_HANDLED)
89796 - atomic_inc(&desc->threads_handled);
89797 + atomic_inc_unchecked(&desc->threads_handled);
89798
89799 wake_threads_waitq(desc);
89800 }
89801 diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
89802 index e2514b0..de3dfe0 100644
89803 --- a/kernel/irq/spurious.c
89804 +++ b/kernel/irq/spurious.c
89805 @@ -337,7 +337,7 @@ void note_interrupt(unsigned int irq, struct irq_desc *desc,
89806 * count. We just care about the count being
89807 * different than the one we saw before.
89808 */
89809 - handled = atomic_read(&desc->threads_handled);
89810 + handled = atomic_read_unchecked(&desc->threads_handled);
89811 handled |= SPURIOUS_DEFERRED;
89812 if (handled != desc->threads_handled_last) {
89813 action_ret = IRQ_HANDLED;
89814 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89815 index 9019f15..9a3c42e 100644
89816 --- a/kernel/jump_label.c
89817 +++ b/kernel/jump_label.c
89818 @@ -14,6 +14,7 @@
89819 #include <linux/err.h>
89820 #include <linux/static_key.h>
89821 #include <linux/jump_label_ratelimit.h>
89822 +#include <linux/mm.h>
89823
89824 #ifdef HAVE_JUMP_LABEL
89825
89826 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89827
89828 size = (((unsigned long)stop - (unsigned long)start)
89829 / sizeof(struct jump_entry));
89830 + pax_open_kernel();
89831 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89832 + pax_close_kernel();
89833 }
89834
89835 static void jump_label_update(struct static_key *key, int enable);
89836 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89837 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89838 struct jump_entry *iter;
89839
89840 + pax_open_kernel();
89841 for (iter = iter_start; iter < iter_stop; iter++) {
89842 if (within_module_init(iter->code, mod))
89843 iter->code = 0;
89844 }
89845 + pax_close_kernel();
89846 }
89847
89848 static int
89849 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89850 index 5c5987f..bc502b0 100644
89851 --- a/kernel/kallsyms.c
89852 +++ b/kernel/kallsyms.c
89853 @@ -11,6 +11,9 @@
89854 * Changed the compression method from stem compression to "table lookup"
89855 * compression (see scripts/kallsyms.c for a more complete description)
89856 */
89857 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89858 +#define __INCLUDED_BY_HIDESYM 1
89859 +#endif
89860 #include <linux/kallsyms.h>
89861 #include <linux/module.h>
89862 #include <linux/init.h>
89863 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89864
89865 static inline int is_kernel_inittext(unsigned long addr)
89866 {
89867 + if (system_state != SYSTEM_BOOTING)
89868 + return 0;
89869 +
89870 if (addr >= (unsigned long)_sinittext
89871 && addr <= (unsigned long)_einittext)
89872 return 1;
89873 return 0;
89874 }
89875
89876 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89877 +#ifdef CONFIG_MODULES
89878 +static inline int is_module_text(unsigned long addr)
89879 +{
89880 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89881 + return 1;
89882 +
89883 + addr = ktla_ktva(addr);
89884 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89885 +}
89886 +#else
89887 +static inline int is_module_text(unsigned long addr)
89888 +{
89889 + return 0;
89890 +}
89891 +#endif
89892 +#endif
89893 +
89894 static inline int is_kernel_text(unsigned long addr)
89895 {
89896 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89897 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89898
89899 static inline int is_kernel(unsigned long addr)
89900 {
89901 +
89902 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89903 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89904 + return 1;
89905 +
89906 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89907 +#else
89908 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89909 +#endif
89910 +
89911 return 1;
89912 return in_gate_area_no_mm(addr);
89913 }
89914
89915 static int is_ksym_addr(unsigned long addr)
89916 {
89917 +
89918 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89919 + if (is_module_text(addr))
89920 + return 0;
89921 +#endif
89922 +
89923 if (all_var)
89924 return is_kernel(addr);
89925
89926 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89927
89928 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89929 {
89930 - iter->name[0] = '\0';
89931 iter->nameoff = get_symbol_offset(new_pos);
89932 iter->pos = new_pos;
89933 }
89934 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89935 {
89936 struct kallsym_iter *iter = m->private;
89937
89938 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89939 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89940 + return 0;
89941 +#endif
89942 +
89943 /* Some debugging symbols have no name. Ignore them. */
89944 if (!iter->name[0])
89945 return 0;
89946 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89947 */
89948 type = iter->exported ? toupper(iter->type) :
89949 tolower(iter->type);
89950 +
89951 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89952 type, iter->name, iter->module_name);
89953 } else
89954 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89955 index 0aa69ea..a7fcafb 100644
89956 --- a/kernel/kcmp.c
89957 +++ b/kernel/kcmp.c
89958 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89959 struct task_struct *task1, *task2;
89960 int ret;
89961
89962 +#ifdef CONFIG_GRKERNSEC
89963 + return -ENOSYS;
89964 +#endif
89965 +
89966 rcu_read_lock();
89967
89968 /*
89969 diff --git a/kernel/kexec.c b/kernel/kexec.c
89970 index 2abf9f6..c40cf85 100644
89971 --- a/kernel/kexec.c
89972 +++ b/kernel/kexec.c
89973 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89974 compat_ulong_t, flags)
89975 {
89976 struct compat_kexec_segment in;
89977 - struct kexec_segment out, __user *ksegments;
89978 + struct kexec_segment out;
89979 + struct kexec_segment __user *ksegments;
89980 unsigned long i, result;
89981
89982 /* Don't allow clients that don't understand the native
89983 diff --git a/kernel/kmod.c b/kernel/kmod.c
89984 index 80f7a6d..3c476d3 100644
89985 --- a/kernel/kmod.c
89986 +++ b/kernel/kmod.c
89987 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89988 kfree(info->argv);
89989 }
89990
89991 -static int call_modprobe(char *module_name, int wait)
89992 +static int call_modprobe(char *module_name, char *module_param, int wait)
89993 {
89994 struct subprocess_info *info;
89995 static char *envp[] = {
89996 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89997 NULL
89998 };
89999
90000 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90001 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90002 if (!argv)
90003 goto out;
90004
90005 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90006 argv[1] = "-q";
90007 argv[2] = "--";
90008 argv[3] = module_name; /* check free_modprobe_argv() */
90009 - argv[4] = NULL;
90010 + argv[4] = module_param;
90011 + argv[5] = NULL;
90012
90013 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90014 NULL, free_modprobe_argv, NULL);
90015 @@ -129,9 +130,8 @@ out:
90016 * If module auto-loading support is disabled then this function
90017 * becomes a no-operation.
90018 */
90019 -int __request_module(bool wait, const char *fmt, ...)
90020 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90021 {
90022 - va_list args;
90023 char module_name[MODULE_NAME_LEN];
90024 unsigned int max_modprobes;
90025 int ret;
90026 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90027 if (!modprobe_path[0])
90028 return 0;
90029
90030 - va_start(args, fmt);
90031 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90032 - va_end(args);
90033 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90034 if (ret >= MODULE_NAME_LEN)
90035 return -ENAMETOOLONG;
90036
90037 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90038 if (ret)
90039 return ret;
90040
90041 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90042 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90043 + /* hack to workaround consolekit/udisks stupidity */
90044 + read_lock(&tasklist_lock);
90045 + if (!strcmp(current->comm, "mount") &&
90046 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90047 + read_unlock(&tasklist_lock);
90048 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90049 + return -EPERM;
90050 + }
90051 + read_unlock(&tasklist_lock);
90052 + }
90053 +#endif
90054 +
90055 /* If modprobe needs a service that is in a module, we get a recursive
90056 * loop. Limit the number of running kmod threads to max_threads/2 or
90057 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90058 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
90059
90060 trace_module_request(module_name, wait, _RET_IP_);
90061
90062 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90063 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90064
90065 atomic_dec(&kmod_concurrent);
90066 return ret;
90067 }
90068 +
90069 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90070 +{
90071 + va_list args;
90072 + int ret;
90073 +
90074 + va_start(args, fmt);
90075 + ret = ____request_module(wait, module_param, fmt, args);
90076 + va_end(args);
90077 +
90078 + return ret;
90079 +}
90080 +
90081 +int __request_module(bool wait, const char *fmt, ...)
90082 +{
90083 + va_list args;
90084 + int ret;
90085 +
90086 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90087 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90088 + char module_param[MODULE_NAME_LEN];
90089 +
90090 + memset(module_param, 0, sizeof(module_param));
90091 +
90092 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90093 +
90094 + va_start(args, fmt);
90095 + ret = ____request_module(wait, module_param, fmt, args);
90096 + va_end(args);
90097 +
90098 + return ret;
90099 + }
90100 +#endif
90101 +
90102 + va_start(args, fmt);
90103 + ret = ____request_module(wait, NULL, fmt, args);
90104 + va_end(args);
90105 +
90106 + return ret;
90107 +}
90108 +
90109 EXPORT_SYMBOL(__request_module);
90110 #endif /* CONFIG_MODULES */
90111
90112 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90113 {
90114 +#ifdef CONFIG_GRKERNSEC
90115 + kfree(info->path);
90116 + info->path = info->origpath;
90117 +#endif
90118 if (info->cleanup)
90119 (*info->cleanup)(info);
90120 kfree(info);
90121 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
90122 */
90123 set_user_nice(current, 0);
90124
90125 +#ifdef CONFIG_GRKERNSEC
90126 + /* this is race-free as far as userland is concerned as we copied
90127 + out the path to be used prior to this point and are now operating
90128 + on that copy
90129 + */
90130 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90131 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90132 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90133 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90134 + retval = -EPERM;
90135 + goto out;
90136 + }
90137 +#endif
90138 +
90139 retval = -ENOMEM;
90140 new = prepare_kernel_cred(current);
90141 if (!new)
90142 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
90143 commit_creds(new);
90144
90145 retval = do_execve(getname_kernel(sub_info->path),
90146 - (const char __user *const __user *)sub_info->argv,
90147 - (const char __user *const __user *)sub_info->envp);
90148 + (const char __user *const __force_user *)sub_info->argv,
90149 + (const char __user *const __force_user *)sub_info->envp);
90150 out:
90151 sub_info->retval = retval;
90152 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
90153 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
90154 *
90155 * Thus the __user pointer cast is valid here.
90156 */
90157 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90158 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90159
90160 /*
90161 * If ret is 0, either ____call_usermodehelper failed and the
90162 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90163 goto out;
90164
90165 INIT_WORK(&sub_info->work, __call_usermodehelper);
90166 +#ifdef CONFIG_GRKERNSEC
90167 + sub_info->origpath = path;
90168 + sub_info->path = kstrdup(path, gfp_mask);
90169 +#else
90170 sub_info->path = path;
90171 +#endif
90172 sub_info->argv = argv;
90173 sub_info->envp = envp;
90174
90175 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90176 static int proc_cap_handler(struct ctl_table *table, int write,
90177 void __user *buffer, size_t *lenp, loff_t *ppos)
90178 {
90179 - struct ctl_table t;
90180 + ctl_table_no_const t;
90181 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90182 kernel_cap_t new_cap;
90183 int err, i;
90184 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90185 index 3995f54..e247879 100644
90186 --- a/kernel/kprobes.c
90187 +++ b/kernel/kprobes.c
90188 @@ -31,6 +31,9 @@
90189 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90190 * <prasanna@in.ibm.com> added function-return probes.
90191 */
90192 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90193 +#define __INCLUDED_BY_HIDESYM 1
90194 +#endif
90195 #include <linux/kprobes.h>
90196 #include <linux/hash.h>
90197 #include <linux/init.h>
90198 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90199
90200 static void *alloc_insn_page(void)
90201 {
90202 - return module_alloc(PAGE_SIZE);
90203 + return module_alloc_exec(PAGE_SIZE);
90204 }
90205
90206 static void free_insn_page(void *page)
90207 {
90208 - module_free(NULL, page);
90209 + module_free_exec(NULL, page);
90210 }
90211
90212 struct kprobe_insn_cache kprobe_insn_slots = {
90213 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90214 kprobe_type = "k";
90215
90216 if (sym)
90217 - seq_printf(pi, "%p %s %s+0x%x %s ",
90218 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90219 p->addr, kprobe_type, sym, offset,
90220 (modname ? modname : " "));
90221 else
90222 - seq_printf(pi, "%p %s %p ",
90223 + seq_printf(pi, "%pK %s %pK ",
90224 p->addr, kprobe_type, p->addr);
90225
90226 if (!pp)
90227 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90228 index 6683cce..daf8999 100644
90229 --- a/kernel/ksysfs.c
90230 +++ b/kernel/ksysfs.c
90231 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90232 {
90233 if (count+1 > UEVENT_HELPER_PATH_LEN)
90234 return -ENOENT;
90235 + if (!capable(CAP_SYS_ADMIN))
90236 + return -EPERM;
90237 memcpy(uevent_helper, buf, count);
90238 uevent_helper[count] = '\0';
90239 if (count && uevent_helper[count-1] == '\n')
90240 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90241 return count;
90242 }
90243
90244 -static struct bin_attribute notes_attr = {
90245 +static bin_attribute_no_const notes_attr __read_only = {
90246 .attr = {
90247 .name = "notes",
90248 .mode = S_IRUGO,
90249 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90250 index 88d0d44..e9ce0ee 100644
90251 --- a/kernel/locking/lockdep.c
90252 +++ b/kernel/locking/lockdep.c
90253 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90254 end = (unsigned long) &_end,
90255 addr = (unsigned long) obj;
90256
90257 +#ifdef CONFIG_PAX_KERNEXEC
90258 + start = ktla_ktva(start);
90259 +#endif
90260 +
90261 /*
90262 * static variable?
90263 */
90264 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90265 if (!static_obj(lock->key)) {
90266 debug_locks_off();
90267 printk("INFO: trying to register non-static key.\n");
90268 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90269 printk("the code is fine but needs lockdep annotation.\n");
90270 printk("turning off the locking correctness validator.\n");
90271 dump_stack();
90272 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90273 if (!class)
90274 return 0;
90275 }
90276 - atomic_inc((atomic_t *)&class->ops);
90277 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90278 if (very_verbose(class)) {
90279 printk("\nacquire class [%p] %s", class->key, class->name);
90280 if (class->name_version > 1)
90281 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90282 index ef43ac4..2720dfa 100644
90283 --- a/kernel/locking/lockdep_proc.c
90284 +++ b/kernel/locking/lockdep_proc.c
90285 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90286 return 0;
90287 }
90288
90289 - seq_printf(m, "%p", class->key);
90290 + seq_printf(m, "%pK", class->key);
90291 #ifdef CONFIG_DEBUG_LOCKDEP
90292 seq_printf(m, " OPS:%8ld", class->ops);
90293 #endif
90294 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90295
90296 list_for_each_entry(entry, &class->locks_after, entry) {
90297 if (entry->distance == 1) {
90298 - seq_printf(m, " -> [%p] ", entry->class->key);
90299 + seq_printf(m, " -> [%pK] ", entry->class->key);
90300 print_name(m, entry->class);
90301 seq_puts(m, "\n");
90302 }
90303 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90304 if (!class->key)
90305 continue;
90306
90307 - seq_printf(m, "[%p] ", class->key);
90308 + seq_printf(m, "[%pK] ", class->key);
90309 print_name(m, class);
90310 seq_puts(m, "\n");
90311 }
90312 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90313 if (!i)
90314 seq_line(m, '-', 40-namelen, namelen);
90315
90316 - snprintf(ip, sizeof(ip), "[<%p>]",
90317 + snprintf(ip, sizeof(ip), "[<%pK>]",
90318 (void *)class->contention_point[i]);
90319 seq_printf(m, "%40s %14lu %29s %pS\n",
90320 name, stats->contention_point[i],
90321 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90322 if (!i)
90323 seq_line(m, '-', 40-namelen, namelen);
90324
90325 - snprintf(ip, sizeof(ip), "[<%p>]",
90326 + snprintf(ip, sizeof(ip), "[<%pK>]",
90327 (void *)class->contending_point[i]);
90328 seq_printf(m, "%40s %14lu %29s %pS\n",
90329 name, stats->contending_point[i],
90330 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90331 index 9887a90..0cd2b1d 100644
90332 --- a/kernel/locking/mcs_spinlock.c
90333 +++ b/kernel/locking/mcs_spinlock.c
90334 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90335
90336 prev = decode_cpu(old);
90337 node->prev = prev;
90338 - ACCESS_ONCE(prev->next) = node;
90339 + ACCESS_ONCE_RW(prev->next) = node;
90340
90341 /*
90342 * Normally @prev is untouchable after the above store; because at that
90343 @@ -172,8 +172,8 @@ unqueue:
90344 * it will wait in Step-A.
90345 */
90346
90347 - ACCESS_ONCE(next->prev) = prev;
90348 - ACCESS_ONCE(prev->next) = next;
90349 + ACCESS_ONCE_RW(next->prev) = prev;
90350 + ACCESS_ONCE_RW(prev->next) = next;
90351
90352 return false;
90353 }
90354 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90355 node = this_cpu_ptr(&osq_node);
90356 next = xchg(&node->next, NULL);
90357 if (next) {
90358 - ACCESS_ONCE(next->locked) = 1;
90359 + ACCESS_ONCE_RW(next->locked) = 1;
90360 return;
90361 }
90362
90363 next = osq_wait_next(lock, node, NULL);
90364 if (next)
90365 - ACCESS_ONCE(next->locked) = 1;
90366 + ACCESS_ONCE_RW(next->locked) = 1;
90367 }
90368
90369 #endif
90370 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90371 index 4d60986..5d351c1 100644
90372 --- a/kernel/locking/mcs_spinlock.h
90373 +++ b/kernel/locking/mcs_spinlock.h
90374 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90375 */
90376 return;
90377 }
90378 - ACCESS_ONCE(prev->next) = node;
90379 + ACCESS_ONCE_RW(prev->next) = node;
90380
90381 /* Wait until the lock holder passes the lock down. */
90382 arch_mcs_spin_lock_contended(&node->locked);
90383 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90384 index 5cf6731..ce3bc5a 100644
90385 --- a/kernel/locking/mutex-debug.c
90386 +++ b/kernel/locking/mutex-debug.c
90387 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90388 }
90389
90390 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90391 - struct thread_info *ti)
90392 + struct task_struct *task)
90393 {
90394 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90395
90396 /* Mark the current thread as blocked on the lock: */
90397 - ti->task->blocked_on = waiter;
90398 + task->blocked_on = waiter;
90399 }
90400
90401 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90402 - struct thread_info *ti)
90403 + struct task_struct *task)
90404 {
90405 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90406 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90407 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90408 - ti->task->blocked_on = NULL;
90409 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90410 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90411 + task->blocked_on = NULL;
90412
90413 list_del_init(&waiter->list);
90414 waiter->task = NULL;
90415 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90416 index 0799fd3..d06ae3b 100644
90417 --- a/kernel/locking/mutex-debug.h
90418 +++ b/kernel/locking/mutex-debug.h
90419 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90420 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90421 extern void debug_mutex_add_waiter(struct mutex *lock,
90422 struct mutex_waiter *waiter,
90423 - struct thread_info *ti);
90424 + struct task_struct *task);
90425 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90426 - struct thread_info *ti);
90427 + struct task_struct *task);
90428 extern void debug_mutex_unlock(struct mutex *lock);
90429 extern void debug_mutex_init(struct mutex *lock, const char *name,
90430 struct lock_class_key *key);
90431 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90432 index dadbf88..4500507 100644
90433 --- a/kernel/locking/mutex.c
90434 +++ b/kernel/locking/mutex.c
90435 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90436 goto skip_wait;
90437
90438 debug_mutex_lock_common(lock, &waiter);
90439 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90440 + debug_mutex_add_waiter(lock, &waiter, task);
90441
90442 /* add waiting tasks to the end of the waitqueue (FIFO): */
90443 list_add_tail(&waiter.list, &lock->wait_list);
90444 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90445 schedule_preempt_disabled();
90446 spin_lock_mutex(&lock->wait_lock, flags);
90447 }
90448 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90449 + mutex_remove_waiter(lock, &waiter, task);
90450 /* set it to 0 if there are no waiters left: */
90451 if (likely(list_empty(&lock->wait_list)))
90452 atomic_set(&lock->count, 0);
90453 @@ -600,7 +600,7 @@ skip_wait:
90454 return 0;
90455
90456 err:
90457 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90458 + mutex_remove_waiter(lock, &waiter, task);
90459 spin_unlock_mutex(&lock->wait_lock, flags);
90460 debug_mutex_free_waiter(&waiter);
90461 mutex_release(&lock->dep_map, 1, ip);
90462 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90463 index 1d96dd0..994ff19 100644
90464 --- a/kernel/locking/rtmutex-tester.c
90465 +++ b/kernel/locking/rtmutex-tester.c
90466 @@ -22,7 +22,7 @@
90467 #define MAX_RT_TEST_MUTEXES 8
90468
90469 static spinlock_t rttest_lock;
90470 -static atomic_t rttest_event;
90471 +static atomic_unchecked_t rttest_event;
90472
90473 struct test_thread_data {
90474 int opcode;
90475 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90476
90477 case RTTEST_LOCKCONT:
90478 td->mutexes[td->opdata] = 1;
90479 - td->event = atomic_add_return(1, &rttest_event);
90480 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90481 return 0;
90482
90483 case RTTEST_RESET:
90484 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90485 return 0;
90486
90487 case RTTEST_RESETEVENT:
90488 - atomic_set(&rttest_event, 0);
90489 + atomic_set_unchecked(&rttest_event, 0);
90490 return 0;
90491
90492 default:
90493 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90494 return ret;
90495
90496 td->mutexes[id] = 1;
90497 - td->event = atomic_add_return(1, &rttest_event);
90498 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90499 rt_mutex_lock(&mutexes[id]);
90500 - td->event = atomic_add_return(1, &rttest_event);
90501 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90502 td->mutexes[id] = 4;
90503 return 0;
90504
90505 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90506 return ret;
90507
90508 td->mutexes[id] = 1;
90509 - td->event = atomic_add_return(1, &rttest_event);
90510 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90511 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90512 - td->event = atomic_add_return(1, &rttest_event);
90513 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90514 td->mutexes[id] = ret ? 0 : 4;
90515 return ret ? -EINTR : 0;
90516
90517 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90518 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90519 return ret;
90520
90521 - td->event = atomic_add_return(1, &rttest_event);
90522 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90523 rt_mutex_unlock(&mutexes[id]);
90524 - td->event = atomic_add_return(1, &rttest_event);
90525 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90526 td->mutexes[id] = 0;
90527 return 0;
90528
90529 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90530 break;
90531
90532 td->mutexes[dat] = 2;
90533 - td->event = atomic_add_return(1, &rttest_event);
90534 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90535 break;
90536
90537 default:
90538 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90539 return;
90540
90541 td->mutexes[dat] = 3;
90542 - td->event = atomic_add_return(1, &rttest_event);
90543 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90544 break;
90545
90546 case RTTEST_LOCKNOWAIT:
90547 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90548 return;
90549
90550 td->mutexes[dat] = 1;
90551 - td->event = atomic_add_return(1, &rttest_event);
90552 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90553 return;
90554
90555 default:
90556 diff --git a/kernel/module.c b/kernel/module.c
90557 index 88cec1d..d097c28 100644
90558 --- a/kernel/module.c
90559 +++ b/kernel/module.c
90560 @@ -60,6 +60,7 @@
90561 #include <linux/jump_label.h>
90562 #include <linux/pfn.h>
90563 #include <linux/bsearch.h>
90564 +#include <linux/grsecurity.h>
90565 #include <uapi/linux/module.h>
90566 #include "module-internal.h"
90567
90568 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90569
90570 /* Bounds of module allocation, for speeding __module_address.
90571 * Protected by module_mutex. */
90572 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90573 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90574 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90575
90576 int register_module_notifier(struct notifier_block * nb)
90577 {
90578 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90579 return true;
90580
90581 list_for_each_entry_rcu(mod, &modules, list) {
90582 - struct symsearch arr[] = {
90583 + struct symsearch modarr[] = {
90584 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90585 NOT_GPL_ONLY, false },
90586 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90587 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90588 if (mod->state == MODULE_STATE_UNFORMED)
90589 continue;
90590
90591 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90592 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90593 return true;
90594 }
90595 return false;
90596 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90597 if (!pcpusec->sh_size)
90598 return 0;
90599
90600 - if (align > PAGE_SIZE) {
90601 + if (align-1 >= PAGE_SIZE) {
90602 pr_warn("%s: per-cpu alignment %li > %li\n",
90603 mod->name, align, PAGE_SIZE);
90604 align = PAGE_SIZE;
90605 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90606 static ssize_t show_coresize(struct module_attribute *mattr,
90607 struct module_kobject *mk, char *buffer)
90608 {
90609 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90610 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90611 }
90612
90613 static struct module_attribute modinfo_coresize =
90614 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90615 static ssize_t show_initsize(struct module_attribute *mattr,
90616 struct module_kobject *mk, char *buffer)
90617 {
90618 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90619 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90620 }
90621
90622 static struct module_attribute modinfo_initsize =
90623 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90624 goto bad_version;
90625 }
90626
90627 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90628 + /*
90629 + * avoid potentially printing jibberish on attempted load
90630 + * of a module randomized with a different seed
90631 + */
90632 + pr_warn("no symbol version for %s\n", symname);
90633 +#else
90634 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90635 +#endif
90636 return 0;
90637
90638 bad_version:
90639 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90640 + /*
90641 + * avoid potentially printing jibberish on attempted load
90642 + * of a module randomized with a different seed
90643 + */
90644 + printk("attempted module disagrees about version of symbol %s\n",
90645 + symname);
90646 +#else
90647 printk("%s: disagrees about version of symbol %s\n",
90648 mod->name, symname);
90649 +#endif
90650 return 0;
90651 }
90652
90653 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90654 */
90655 #ifdef CONFIG_SYSFS
90656
90657 -#ifdef CONFIG_KALLSYMS
90658 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90659 static inline bool sect_empty(const Elf_Shdr *sect)
90660 {
90661 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90662 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90663 {
90664 unsigned int notes, loaded, i;
90665 struct module_notes_attrs *notes_attrs;
90666 - struct bin_attribute *nattr;
90667 + bin_attribute_no_const *nattr;
90668
90669 /* failed to create section attributes, so can't create notes */
90670 if (!mod->sect_attrs)
90671 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90672 static int module_add_modinfo_attrs(struct module *mod)
90673 {
90674 struct module_attribute *attr;
90675 - struct module_attribute *temp_attr;
90676 + module_attribute_no_const *temp_attr;
90677 int error = 0;
90678 int i;
90679
90680 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90681
90682 static void unset_module_core_ro_nx(struct module *mod)
90683 {
90684 - set_page_attributes(mod->module_core + mod->core_text_size,
90685 - mod->module_core + mod->core_size,
90686 + set_page_attributes(mod->module_core_rw,
90687 + mod->module_core_rw + mod->core_size_rw,
90688 set_memory_x);
90689 - set_page_attributes(mod->module_core,
90690 - mod->module_core + mod->core_ro_size,
90691 + set_page_attributes(mod->module_core_rx,
90692 + mod->module_core_rx + mod->core_size_rx,
90693 set_memory_rw);
90694 }
90695
90696 static void unset_module_init_ro_nx(struct module *mod)
90697 {
90698 - set_page_attributes(mod->module_init + mod->init_text_size,
90699 - mod->module_init + mod->init_size,
90700 + set_page_attributes(mod->module_init_rw,
90701 + mod->module_init_rw + mod->init_size_rw,
90702 set_memory_x);
90703 - set_page_attributes(mod->module_init,
90704 - mod->module_init + mod->init_ro_size,
90705 + set_page_attributes(mod->module_init_rx,
90706 + mod->module_init_rx + mod->init_size_rx,
90707 set_memory_rw);
90708 }
90709
90710 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90711 list_for_each_entry_rcu(mod, &modules, list) {
90712 if (mod->state == MODULE_STATE_UNFORMED)
90713 continue;
90714 - if ((mod->module_core) && (mod->core_text_size)) {
90715 - set_page_attributes(mod->module_core,
90716 - mod->module_core + mod->core_text_size,
90717 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90718 + set_page_attributes(mod->module_core_rx,
90719 + mod->module_core_rx + mod->core_size_rx,
90720 set_memory_rw);
90721 }
90722 - if ((mod->module_init) && (mod->init_text_size)) {
90723 - set_page_attributes(mod->module_init,
90724 - mod->module_init + mod->init_text_size,
90725 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90726 + set_page_attributes(mod->module_init_rx,
90727 + mod->module_init_rx + mod->init_size_rx,
90728 set_memory_rw);
90729 }
90730 }
90731 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90732 list_for_each_entry_rcu(mod, &modules, list) {
90733 if (mod->state == MODULE_STATE_UNFORMED)
90734 continue;
90735 - if ((mod->module_core) && (mod->core_text_size)) {
90736 - set_page_attributes(mod->module_core,
90737 - mod->module_core + mod->core_text_size,
90738 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90739 + set_page_attributes(mod->module_core_rx,
90740 + mod->module_core_rx + mod->core_size_rx,
90741 set_memory_ro);
90742 }
90743 - if ((mod->module_init) && (mod->init_text_size)) {
90744 - set_page_attributes(mod->module_init,
90745 - mod->module_init + mod->init_text_size,
90746 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90747 + set_page_attributes(mod->module_init_rx,
90748 + mod->module_init_rx + mod->init_size_rx,
90749 set_memory_ro);
90750 }
90751 }
90752 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90753
90754 /* This may be NULL, but that's OK */
90755 unset_module_init_ro_nx(mod);
90756 - module_free(mod, mod->module_init);
90757 + module_free(mod, mod->module_init_rw);
90758 + module_free_exec(mod, mod->module_init_rx);
90759 kfree(mod->args);
90760 percpu_modfree(mod);
90761
90762 /* Free lock-classes: */
90763 - lockdep_free_key_range(mod->module_core, mod->core_size);
90764 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90765 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90766
90767 /* Finally, free the core (containing the module structure) */
90768 unset_module_core_ro_nx(mod);
90769 - module_free(mod, mod->module_core);
90770 + module_free_exec(mod, mod->module_core_rx);
90771 + module_free(mod, mod->module_core_rw);
90772
90773 #ifdef CONFIG_MPU
90774 update_protections(current->mm);
90775 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90776 int ret = 0;
90777 const struct kernel_symbol *ksym;
90778
90779 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90780 + int is_fs_load = 0;
90781 + int register_filesystem_found = 0;
90782 + char *p;
90783 +
90784 + p = strstr(mod->args, "grsec_modharden_fs");
90785 + if (p) {
90786 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90787 + /* copy \0 as well */
90788 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90789 + is_fs_load = 1;
90790 + }
90791 +#endif
90792 +
90793 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90794 const char *name = info->strtab + sym[i].st_name;
90795
90796 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90797 + /* it's a real shame this will never get ripped and copied
90798 + upstream! ;(
90799 + */
90800 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90801 + register_filesystem_found = 1;
90802 +#endif
90803 +
90804 switch (sym[i].st_shndx) {
90805 case SHN_COMMON:
90806 /* Ignore common symbols */
90807 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90808 ksym = resolve_symbol_wait(mod, info, name);
90809 /* Ok if resolved. */
90810 if (ksym && !IS_ERR(ksym)) {
90811 + pax_open_kernel();
90812 sym[i].st_value = ksym->value;
90813 + pax_close_kernel();
90814 break;
90815 }
90816
90817 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90818 secbase = (unsigned long)mod_percpu(mod);
90819 else
90820 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90821 + pax_open_kernel();
90822 sym[i].st_value += secbase;
90823 + pax_close_kernel();
90824 break;
90825 }
90826 }
90827
90828 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90829 + if (is_fs_load && !register_filesystem_found) {
90830 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90831 + ret = -EPERM;
90832 + }
90833 +#endif
90834 +
90835 return ret;
90836 }
90837
90838 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90839 || s->sh_entsize != ~0UL
90840 || strstarts(sname, ".init"))
90841 continue;
90842 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90843 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90844 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90845 + else
90846 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90847 pr_debug("\t%s\n", sname);
90848 }
90849 - switch (m) {
90850 - case 0: /* executable */
90851 - mod->core_size = debug_align(mod->core_size);
90852 - mod->core_text_size = mod->core_size;
90853 - break;
90854 - case 1: /* RO: text and ro-data */
90855 - mod->core_size = debug_align(mod->core_size);
90856 - mod->core_ro_size = mod->core_size;
90857 - break;
90858 - case 3: /* whole core */
90859 - mod->core_size = debug_align(mod->core_size);
90860 - break;
90861 - }
90862 }
90863
90864 pr_debug("Init section allocation order:\n");
90865 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90866 || s->sh_entsize != ~0UL
90867 || !strstarts(sname, ".init"))
90868 continue;
90869 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90870 - | INIT_OFFSET_MASK);
90871 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90872 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90873 + else
90874 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90875 + s->sh_entsize |= INIT_OFFSET_MASK;
90876 pr_debug("\t%s\n", sname);
90877 }
90878 - switch (m) {
90879 - case 0: /* executable */
90880 - mod->init_size = debug_align(mod->init_size);
90881 - mod->init_text_size = mod->init_size;
90882 - break;
90883 - case 1: /* RO: text and ro-data */
90884 - mod->init_size = debug_align(mod->init_size);
90885 - mod->init_ro_size = mod->init_size;
90886 - break;
90887 - case 3: /* whole init */
90888 - mod->init_size = debug_align(mod->init_size);
90889 - break;
90890 - }
90891 }
90892 }
90893
90894 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90895
90896 /* Put symbol section at end of init part of module. */
90897 symsect->sh_flags |= SHF_ALLOC;
90898 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90899 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90900 info->index.sym) | INIT_OFFSET_MASK;
90901 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90902
90903 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90904 }
90905
90906 /* Append room for core symbols at end of core part. */
90907 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90908 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90909 - mod->core_size += strtab_size;
90910 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90911 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90912 + mod->core_size_rx += strtab_size;
90913
90914 /* Put string table section at end of init part of module. */
90915 strsect->sh_flags |= SHF_ALLOC;
90916 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90917 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90918 info->index.str) | INIT_OFFSET_MASK;
90919 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90920 }
90921 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90922 /* Make sure we get permanent strtab: don't use info->strtab. */
90923 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90924
90925 + pax_open_kernel();
90926 +
90927 /* Set types up while we still have access to sections. */
90928 for (i = 0; i < mod->num_symtab; i++)
90929 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90930
90931 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90932 - mod->core_strtab = s = mod->module_core + info->stroffs;
90933 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90934 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90935 src = mod->symtab;
90936 for (ndst = i = 0; i < mod->num_symtab; i++) {
90937 if (i == 0 ||
90938 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90939 }
90940 }
90941 mod->core_num_syms = ndst;
90942 +
90943 + pax_close_kernel();
90944 }
90945 #else
90946 static inline void layout_symtab(struct module *mod, struct load_info *info)
90947 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90948 return vmalloc_exec(size);
90949 }
90950
90951 -static void *module_alloc_update_bounds(unsigned long size)
90952 +static void *module_alloc_update_bounds_rw(unsigned long size)
90953 {
90954 void *ret = module_alloc(size);
90955
90956 if (ret) {
90957 mutex_lock(&module_mutex);
90958 /* Update module bounds. */
90959 - if ((unsigned long)ret < module_addr_min)
90960 - module_addr_min = (unsigned long)ret;
90961 - if ((unsigned long)ret + size > module_addr_max)
90962 - module_addr_max = (unsigned long)ret + size;
90963 + if ((unsigned long)ret < module_addr_min_rw)
90964 + module_addr_min_rw = (unsigned long)ret;
90965 + if ((unsigned long)ret + size > module_addr_max_rw)
90966 + module_addr_max_rw = (unsigned long)ret + size;
90967 + mutex_unlock(&module_mutex);
90968 + }
90969 + return ret;
90970 +}
90971 +
90972 +static void *module_alloc_update_bounds_rx(unsigned long size)
90973 +{
90974 + void *ret = module_alloc_exec(size);
90975 +
90976 + if (ret) {
90977 + mutex_lock(&module_mutex);
90978 + /* Update module bounds. */
90979 + if ((unsigned long)ret < module_addr_min_rx)
90980 + module_addr_min_rx = (unsigned long)ret;
90981 + if ((unsigned long)ret + size > module_addr_max_rx)
90982 + module_addr_max_rx = (unsigned long)ret + size;
90983 mutex_unlock(&module_mutex);
90984 }
90985 return ret;
90986 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90987 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90988
90989 if (info->index.sym == 0) {
90990 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90991 + /*
90992 + * avoid potentially printing jibberish on attempted load
90993 + * of a module randomized with a different seed
90994 + */
90995 + pr_warn("module has no symbols (stripped?)\n");
90996 +#else
90997 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90998 +#endif
90999 return ERR_PTR(-ENOEXEC);
91000 }
91001
91002 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91003 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91004 {
91005 const char *modmagic = get_modinfo(info, "vermagic");
91006 + const char *license = get_modinfo(info, "license");
91007 int err;
91008
91009 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91010 + if (!license || !license_is_gpl_compatible(license))
91011 + return -ENOEXEC;
91012 +#endif
91013 +
91014 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91015 modmagic = NULL;
91016
91017 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91018 }
91019
91020 /* Set up license info based on the info section */
91021 - set_license(mod, get_modinfo(info, "license"));
91022 + set_license(mod, license);
91023
91024 return 0;
91025 }
91026 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91027 void *ptr;
91028
91029 /* Do the allocs. */
91030 - ptr = module_alloc_update_bounds(mod->core_size);
91031 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91032 /*
91033 * The pointer to this block is stored in the module structure
91034 * which is inside the block. Just mark it as not being a
91035 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91036 if (!ptr)
91037 return -ENOMEM;
91038
91039 - memset(ptr, 0, mod->core_size);
91040 - mod->module_core = ptr;
91041 + memset(ptr, 0, mod->core_size_rw);
91042 + mod->module_core_rw = ptr;
91043
91044 - if (mod->init_size) {
91045 - ptr = module_alloc_update_bounds(mod->init_size);
91046 + if (mod->init_size_rw) {
91047 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91048 /*
91049 * The pointer to this block is stored in the module structure
91050 * which is inside the block. This block doesn't need to be
91051 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91052 */
91053 kmemleak_ignore(ptr);
91054 if (!ptr) {
91055 - module_free(mod, mod->module_core);
91056 + module_free(mod, mod->module_core_rw);
91057 return -ENOMEM;
91058 }
91059 - memset(ptr, 0, mod->init_size);
91060 - mod->module_init = ptr;
91061 + memset(ptr, 0, mod->init_size_rw);
91062 + mod->module_init_rw = ptr;
91063 } else
91064 - mod->module_init = NULL;
91065 + mod->module_init_rw = NULL;
91066 +
91067 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91068 + kmemleak_not_leak(ptr);
91069 + if (!ptr) {
91070 + if (mod->module_init_rw)
91071 + module_free(mod, mod->module_init_rw);
91072 + module_free(mod, mod->module_core_rw);
91073 + return -ENOMEM;
91074 + }
91075 +
91076 + pax_open_kernel();
91077 + memset(ptr, 0, mod->core_size_rx);
91078 + pax_close_kernel();
91079 + mod->module_core_rx = ptr;
91080 +
91081 + if (mod->init_size_rx) {
91082 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91083 + kmemleak_ignore(ptr);
91084 + if (!ptr && mod->init_size_rx) {
91085 + module_free_exec(mod, mod->module_core_rx);
91086 + if (mod->module_init_rw)
91087 + module_free(mod, mod->module_init_rw);
91088 + module_free(mod, mod->module_core_rw);
91089 + return -ENOMEM;
91090 + }
91091 +
91092 + pax_open_kernel();
91093 + memset(ptr, 0, mod->init_size_rx);
91094 + pax_close_kernel();
91095 + mod->module_init_rx = ptr;
91096 + } else
91097 + mod->module_init_rx = NULL;
91098
91099 /* Transfer each section which specifies SHF_ALLOC */
91100 pr_debug("final section addresses:\n");
91101 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91102 if (!(shdr->sh_flags & SHF_ALLOC))
91103 continue;
91104
91105 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
91106 - dest = mod->module_init
91107 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91108 - else
91109 - dest = mod->module_core + shdr->sh_entsize;
91110 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91111 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91112 + dest = mod->module_init_rw
91113 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91114 + else
91115 + dest = mod->module_init_rx
91116 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91117 + } else {
91118 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91119 + dest = mod->module_core_rw + shdr->sh_entsize;
91120 + else
91121 + dest = mod->module_core_rx + shdr->sh_entsize;
91122 + }
91123 +
91124 + if (shdr->sh_type != SHT_NOBITS) {
91125 +
91126 +#ifdef CONFIG_PAX_KERNEXEC
91127 +#ifdef CONFIG_X86_64
91128 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91129 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91130 +#endif
91131 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91132 + pax_open_kernel();
91133 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91134 + pax_close_kernel();
91135 + } else
91136 +#endif
91137
91138 - if (shdr->sh_type != SHT_NOBITS)
91139 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91140 + }
91141 /* Update sh_addr to point to copy in image. */
91142 - shdr->sh_addr = (unsigned long)dest;
91143 +
91144 +#ifdef CONFIG_PAX_KERNEXEC
91145 + if (shdr->sh_flags & SHF_EXECINSTR)
91146 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91147 + else
91148 +#endif
91149 +
91150 + shdr->sh_addr = (unsigned long)dest;
91151 pr_debug("\t0x%lx %s\n",
91152 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91153 }
91154 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91155 * Do it before processing of module parameters, so the module
91156 * can provide parameter accessor functions of its own.
91157 */
91158 - if (mod->module_init)
91159 - flush_icache_range((unsigned long)mod->module_init,
91160 - (unsigned long)mod->module_init
91161 - + mod->init_size);
91162 - flush_icache_range((unsigned long)mod->module_core,
91163 - (unsigned long)mod->module_core + mod->core_size);
91164 + if (mod->module_init_rx)
91165 + flush_icache_range((unsigned long)mod->module_init_rx,
91166 + (unsigned long)mod->module_init_rx
91167 + + mod->init_size_rx);
91168 + flush_icache_range((unsigned long)mod->module_core_rx,
91169 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91170
91171 set_fs(old_fs);
91172 }
91173 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91174 static void module_deallocate(struct module *mod, struct load_info *info)
91175 {
91176 percpu_modfree(mod);
91177 - module_free(mod, mod->module_init);
91178 - module_free(mod, mod->module_core);
91179 + module_free_exec(mod, mod->module_init_rx);
91180 + module_free_exec(mod, mod->module_core_rx);
91181 + module_free(mod, mod->module_init_rw);
91182 + module_free(mod, mod->module_core_rw);
91183 }
91184
91185 int __weak module_finalize(const Elf_Ehdr *hdr,
91186 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91187 static int post_relocation(struct module *mod, const struct load_info *info)
91188 {
91189 /* Sort exception table now relocations are done. */
91190 + pax_open_kernel();
91191 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91192 + pax_close_kernel();
91193
91194 /* Copy relocated percpu area over. */
91195 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91196 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91197 mod->strtab = mod->core_strtab;
91198 #endif
91199 unset_module_init_ro_nx(mod);
91200 - module_free(mod, mod->module_init);
91201 - mod->module_init = NULL;
91202 - mod->init_size = 0;
91203 - mod->init_ro_size = 0;
91204 - mod->init_text_size = 0;
91205 + module_free(mod, mod->module_init_rw);
91206 + module_free_exec(mod, mod->module_init_rx);
91207 + mod->module_init_rw = NULL;
91208 + mod->module_init_rx = NULL;
91209 + mod->init_size_rw = 0;
91210 + mod->init_size_rx = 0;
91211 mutex_unlock(&module_mutex);
91212 wake_up_all(&module_wq);
91213
91214 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91215 module_bug_finalize(info->hdr, info->sechdrs, mod);
91216
91217 /* Set RO and NX regions for core */
91218 - set_section_ro_nx(mod->module_core,
91219 - mod->core_text_size,
91220 - mod->core_ro_size,
91221 - mod->core_size);
91222 + set_section_ro_nx(mod->module_core_rx,
91223 + mod->core_size_rx,
91224 + mod->core_size_rx,
91225 + mod->core_size_rx);
91226
91227 /* Set RO and NX regions for init */
91228 - set_section_ro_nx(mod->module_init,
91229 - mod->init_text_size,
91230 - mod->init_ro_size,
91231 - mod->init_size);
91232 + set_section_ro_nx(mod->module_init_rx,
91233 + mod->init_size_rx,
91234 + mod->init_size_rx,
91235 + mod->init_size_rx);
91236
91237 /* Mark state as coming so strong_try_module_get() ignores us,
91238 * but kallsyms etc. can see us. */
91239 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91240 if (err)
91241 goto free_unload;
91242
91243 + /* Now copy in args */
91244 + mod->args = strndup_user(uargs, ~0UL >> 1);
91245 + if (IS_ERR(mod->args)) {
91246 + err = PTR_ERR(mod->args);
91247 + goto free_unload;
91248 + }
91249 +
91250 /* Set up MODINFO_ATTR fields */
91251 setup_modinfo(mod, info);
91252
91253 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91254 + {
91255 + char *p, *p2;
91256 +
91257 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91258 + 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);
91259 + err = -EPERM;
91260 + goto free_modinfo;
91261 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91262 + p += sizeof("grsec_modharden_normal") - 1;
91263 + p2 = strstr(p, "_");
91264 + if (p2) {
91265 + *p2 = '\0';
91266 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91267 + *p2 = '_';
91268 + }
91269 + err = -EPERM;
91270 + goto free_modinfo;
91271 + }
91272 + }
91273 +#endif
91274 +
91275 /* Fix up syms, so that st_value is a pointer to location. */
91276 err = simplify_symbols(mod, info);
91277 if (err < 0)
91278 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91279
91280 flush_module_icache(mod);
91281
91282 - /* Now copy in args */
91283 - mod->args = strndup_user(uargs, ~0UL >> 1);
91284 - if (IS_ERR(mod->args)) {
91285 - err = PTR_ERR(mod->args);
91286 - goto free_arch_cleanup;
91287 - }
91288 -
91289 dynamic_debug_setup(info->debug, info->num_debug);
91290
91291 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91292 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91293 ddebug_cleanup:
91294 dynamic_debug_remove(info->debug);
91295 synchronize_sched();
91296 - kfree(mod->args);
91297 - free_arch_cleanup:
91298 module_arch_cleanup(mod);
91299 free_modinfo:
91300 free_modinfo(mod);
91301 + kfree(mod->args);
91302 free_unload:
91303 module_unload_free(mod);
91304 unlink_mod:
91305 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91306 unsigned long nextval;
91307
91308 /* At worse, next value is at end of module */
91309 - if (within_module_init(addr, mod))
91310 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91311 + if (within_module_init_rx(addr, mod))
91312 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91313 + else if (within_module_init_rw(addr, mod))
91314 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91315 + else if (within_module_core_rx(addr, mod))
91316 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91317 + else if (within_module_core_rw(addr, mod))
91318 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91319 else
91320 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91321 + return NULL;
91322
91323 /* Scan for closest preceding symbol, and next symbol. (ELF
91324 starts real symbols at 1). */
91325 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91326 return 0;
91327
91328 seq_printf(m, "%s %u",
91329 - mod->name, mod->init_size + mod->core_size);
91330 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91331 print_unload_info(m, mod);
91332
91333 /* Informative for users. */
91334 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91335 mod->state == MODULE_STATE_COMING ? "Loading":
91336 "Live");
91337 /* Used by oprofile and other similar tools. */
91338 - seq_printf(m, " 0x%pK", mod->module_core);
91339 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91340
91341 /* Taints info */
91342 if (mod->taints)
91343 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91344
91345 static int __init proc_modules_init(void)
91346 {
91347 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91348 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91349 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91350 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91351 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91352 +#else
91353 proc_create("modules", 0, NULL, &proc_modules_operations);
91354 +#endif
91355 +#else
91356 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91357 +#endif
91358 return 0;
91359 }
91360 module_init(proc_modules_init);
91361 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91362 {
91363 struct module *mod;
91364
91365 - if (addr < module_addr_min || addr > module_addr_max)
91366 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91367 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91368 return NULL;
91369
91370 list_for_each_entry_rcu(mod, &modules, list) {
91371 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91372 */
91373 struct module *__module_text_address(unsigned long addr)
91374 {
91375 - struct module *mod = __module_address(addr);
91376 + struct module *mod;
91377 +
91378 +#ifdef CONFIG_X86_32
91379 + addr = ktla_ktva(addr);
91380 +#endif
91381 +
91382 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91383 + return NULL;
91384 +
91385 + mod = __module_address(addr);
91386 +
91387 if (mod) {
91388 /* Make sure it's within the text section. */
91389 - if (!within(addr, mod->module_init, mod->init_text_size)
91390 - && !within(addr, mod->module_core, mod->core_text_size))
91391 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91392 mod = NULL;
91393 }
91394 return mod;
91395 diff --git a/kernel/notifier.c b/kernel/notifier.c
91396 index 4803da6..1c5eea6 100644
91397 --- a/kernel/notifier.c
91398 +++ b/kernel/notifier.c
91399 @@ -5,6 +5,7 @@
91400 #include <linux/rcupdate.h>
91401 #include <linux/vmalloc.h>
91402 #include <linux/reboot.h>
91403 +#include <linux/mm.h>
91404
91405 /*
91406 * Notifier list for kernel code which wants to be called
91407 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91408 while ((*nl) != NULL) {
91409 if (n->priority > (*nl)->priority)
91410 break;
91411 - nl = &((*nl)->next);
91412 + nl = (struct notifier_block **)&((*nl)->next);
91413 }
91414 - n->next = *nl;
91415 + pax_open_kernel();
91416 + *(const void **)&n->next = *nl;
91417 rcu_assign_pointer(*nl, n);
91418 + pax_close_kernel();
91419 return 0;
91420 }
91421
91422 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91423 return 0;
91424 if (n->priority > (*nl)->priority)
91425 break;
91426 - nl = &((*nl)->next);
91427 + nl = (struct notifier_block **)&((*nl)->next);
91428 }
91429 - n->next = *nl;
91430 + pax_open_kernel();
91431 + *(const void **)&n->next = *nl;
91432 rcu_assign_pointer(*nl, n);
91433 + pax_close_kernel();
91434 return 0;
91435 }
91436
91437 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91438 {
91439 while ((*nl) != NULL) {
91440 if ((*nl) == n) {
91441 + pax_open_kernel();
91442 rcu_assign_pointer(*nl, n->next);
91443 + pax_close_kernel();
91444 return 0;
91445 }
91446 - nl = &((*nl)->next);
91447 + nl = (struct notifier_block **)&((*nl)->next);
91448 }
91449 return -ENOENT;
91450 }
91451 diff --git a/kernel/padata.c b/kernel/padata.c
91452 index 161402f..598814c 100644
91453 --- a/kernel/padata.c
91454 +++ b/kernel/padata.c
91455 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91456 * seq_nr mod. number of cpus in use.
91457 */
91458
91459 - seq_nr = atomic_inc_return(&pd->seq_nr);
91460 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91461 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91462
91463 return padata_index_to_cpu(pd, cpu_index);
91464 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91465 padata_init_pqueues(pd);
91466 padata_init_squeues(pd);
91467 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91468 - atomic_set(&pd->seq_nr, -1);
91469 + atomic_set_unchecked(&pd->seq_nr, -1);
91470 atomic_set(&pd->reorder_objects, 0);
91471 atomic_set(&pd->refcnt, 0);
91472 pd->pinst = pinst;
91473 diff --git a/kernel/panic.c b/kernel/panic.c
91474 index cf80672..f6771b2 100644
91475 --- a/kernel/panic.c
91476 +++ b/kernel/panic.c
91477 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91478 /*
91479 * Stop ourself in panic -- architecture code may override this
91480 */
91481 -void __weak panic_smp_self_stop(void)
91482 +void __weak __noreturn panic_smp_self_stop(void)
91483 {
91484 while (1)
91485 cpu_relax();
91486 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91487 disable_trace_on_warning();
91488
91489 pr_warn("------------[ cut here ]------------\n");
91490 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91491 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91492 raw_smp_processor_id(), current->pid, file, line, caller);
91493
91494 if (args)
91495 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91496 */
91497 __visible void __stack_chk_fail(void)
91498 {
91499 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91500 + dump_stack();
91501 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91502 __builtin_return_address(0));
91503 }
91504 EXPORT_SYMBOL(__stack_chk_fail);
91505 diff --git a/kernel/pid.c b/kernel/pid.c
91506 index 82430c8..53d7793 100644
91507 --- a/kernel/pid.c
91508 +++ b/kernel/pid.c
91509 @@ -33,6 +33,7 @@
91510 #include <linux/rculist.h>
91511 #include <linux/bootmem.h>
91512 #include <linux/hash.h>
91513 +#include <linux/security.h>
91514 #include <linux/pid_namespace.h>
91515 #include <linux/init_task.h>
91516 #include <linux/syscalls.h>
91517 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91518
91519 int pid_max = PID_MAX_DEFAULT;
91520
91521 -#define RESERVED_PIDS 300
91522 +#define RESERVED_PIDS 500
91523
91524 int pid_max_min = RESERVED_PIDS + 1;
91525 int pid_max_max = PID_MAX_LIMIT;
91526 @@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
91527 */
91528 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91529 {
91530 + struct task_struct *task;
91531 +
91532 rcu_lockdep_assert(rcu_read_lock_held(),
91533 "find_task_by_pid_ns() needs rcu_read_lock()"
91534 " protection");
91535 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91536 +
91537 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91538 +
91539 + if (gr_pid_is_chrooted(task))
91540 + return NULL;
91541 +
91542 + return task;
91543 }
91544
91545 struct task_struct *find_task_by_vpid(pid_t vnr)
91546 @@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91547 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91548 }
91549
91550 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91551 +{
91552 + rcu_lockdep_assert(rcu_read_lock_held(),
91553 + "find_task_by_pid_ns() needs rcu_read_lock()"
91554 + " protection");
91555 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91556 +}
91557 +
91558 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91559 {
91560 struct pid *pid;
91561 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91562 index db95d8e..a0ca23f 100644
91563 --- a/kernel/pid_namespace.c
91564 +++ b/kernel/pid_namespace.c
91565 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91566 void __user *buffer, size_t *lenp, loff_t *ppos)
91567 {
91568 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91569 - struct ctl_table tmp = *table;
91570 + ctl_table_no_const tmp = *table;
91571
91572 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91573 return -EPERM;
91574 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91575 index bbef57f..5f94462 100644
91576 --- a/kernel/power/Kconfig
91577 +++ b/kernel/power/Kconfig
91578 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91579 config HIBERNATION
91580 bool "Hibernation (aka 'suspend to disk')"
91581 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91582 + depends on !GRKERNSEC_KMEM
91583 + depends on !PAX_MEMORY_SANITIZE
91584 select HIBERNATE_CALLBACKS
91585 select LZO_COMPRESS
91586 select LZO_DECOMPRESS
91587 diff --git a/kernel/power/process.c b/kernel/power/process.c
91588 index 5a6ec86..3a8c884 100644
91589 --- a/kernel/power/process.c
91590 +++ b/kernel/power/process.c
91591 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91592 unsigned int elapsed_msecs;
91593 bool wakeup = false;
91594 int sleep_usecs = USEC_PER_MSEC;
91595 + bool timedout = false;
91596
91597 do_gettimeofday(&start);
91598
91599 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91600
91601 while (true) {
91602 todo = 0;
91603 + if (time_after(jiffies, end_time))
91604 + timedout = true;
91605 read_lock(&tasklist_lock);
91606 for_each_process_thread(g, p) {
91607 if (p == current || !freeze_task(p))
91608 continue;
91609
91610 - if (!freezer_should_skip(p))
91611 + if (!freezer_should_skip(p)) {
91612 todo++;
91613 + if (timedout) {
91614 + printk(KERN_ERR "Task refusing to freeze:\n");
91615 + sched_show_task(p);
91616 + }
91617 + }
91618 }
91619 read_unlock(&tasklist_lock);
91620
91621 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91622 todo += wq_busy;
91623 }
91624
91625 - if (!todo || time_after(jiffies, end_time))
91626 + if (!todo || timedout)
91627 break;
91628
91629 if (pm_wakeup_pending()) {
91630 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91631 index ced2b84..ffc4791 100644
91632 --- a/kernel/printk/printk.c
91633 +++ b/kernel/printk/printk.c
91634 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91635 if (from_file && type != SYSLOG_ACTION_OPEN)
91636 return 0;
91637
91638 +#ifdef CONFIG_GRKERNSEC_DMESG
91639 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91640 + return -EPERM;
91641 +#endif
91642 +
91643 if (syslog_action_restricted(type)) {
91644 if (capable(CAP_SYSLOG))
91645 return 0;
91646 diff --git a/kernel/profile.c b/kernel/profile.c
91647 index 54bf5ba..df6e0a2 100644
91648 --- a/kernel/profile.c
91649 +++ b/kernel/profile.c
91650 @@ -37,7 +37,7 @@ struct profile_hit {
91651 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91652 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91653
91654 -static atomic_t *prof_buffer;
91655 +static atomic_unchecked_t *prof_buffer;
91656 static unsigned long prof_len, prof_shift;
91657
91658 int prof_on __read_mostly;
91659 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91660 hits[i].pc = 0;
91661 continue;
91662 }
91663 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91664 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91665 hits[i].hits = hits[i].pc = 0;
91666 }
91667 }
91668 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91669 * Add the current hit(s) and flush the write-queue out
91670 * to the global buffer:
91671 */
91672 - atomic_add(nr_hits, &prof_buffer[pc]);
91673 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91674 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91675 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91676 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91677 hits[i].pc = hits[i].hits = 0;
91678 }
91679 out:
91680 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91681 {
91682 unsigned long pc;
91683 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91684 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91685 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91686 }
91687 #endif /* !CONFIG_SMP */
91688
91689 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91690 return -EFAULT;
91691 buf++; p++; count--; read++;
91692 }
91693 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91694 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91695 if (copy_to_user(buf, (void *)pnt, count))
91696 return -EFAULT;
91697 read += count;
91698 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91699 }
91700 #endif
91701 profile_discard_flip_buffers();
91702 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91703 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91704 return count;
91705 }
91706
91707 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91708 index 54e7522..5b82dd6 100644
91709 --- a/kernel/ptrace.c
91710 +++ b/kernel/ptrace.c
91711 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91712 if (seize)
91713 flags |= PT_SEIZED;
91714 rcu_read_lock();
91715 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91716 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91717 flags |= PT_PTRACE_CAP;
91718 rcu_read_unlock();
91719 task->ptrace = flags;
91720 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91721 break;
91722 return -EIO;
91723 }
91724 - if (copy_to_user(dst, buf, retval))
91725 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91726 return -EFAULT;
91727 copied += retval;
91728 src += retval;
91729 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91730 bool seized = child->ptrace & PT_SEIZED;
91731 int ret = -EIO;
91732 siginfo_t siginfo, *si;
91733 - void __user *datavp = (void __user *) data;
91734 + void __user *datavp = (__force void __user *) data;
91735 unsigned long __user *datalp = datavp;
91736 unsigned long flags;
91737
91738 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91739 goto out;
91740 }
91741
91742 + if (gr_handle_ptrace(child, request)) {
91743 + ret = -EPERM;
91744 + goto out_put_task_struct;
91745 + }
91746 +
91747 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91748 ret = ptrace_attach(child, request, addr, data);
91749 /*
91750 * Some architectures need to do book-keeping after
91751 * a ptrace attach.
91752 */
91753 - if (!ret)
91754 + if (!ret) {
91755 arch_ptrace_attach(child);
91756 + gr_audit_ptrace(child);
91757 + }
91758 goto out_put_task_struct;
91759 }
91760
91761 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91762 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91763 if (copied != sizeof(tmp))
91764 return -EIO;
91765 - return put_user(tmp, (unsigned long __user *)data);
91766 + return put_user(tmp, (__force unsigned long __user *)data);
91767 }
91768
91769 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91770 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91771 }
91772
91773 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91774 - compat_long_t, addr, compat_long_t, data)
91775 + compat_ulong_t, addr, compat_ulong_t, data)
91776 {
91777 struct task_struct *child;
91778 long ret;
91779 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91780 goto out;
91781 }
91782
91783 + if (gr_handle_ptrace(child, request)) {
91784 + ret = -EPERM;
91785 + goto out_put_task_struct;
91786 + }
91787 +
91788 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91789 ret = ptrace_attach(child, request, addr, data);
91790 /*
91791 * Some architectures need to do book-keeping after
91792 * a ptrace attach.
91793 */
91794 - if (!ret)
91795 + if (!ret) {
91796 arch_ptrace_attach(child);
91797 + gr_audit_ptrace(child);
91798 + }
91799 goto out_put_task_struct;
91800 }
91801
91802 diff --git a/kernel/range.c b/kernel/range.c
91803 index 322ea8e..82cfc28 100644
91804 --- a/kernel/range.c
91805 +++ b/kernel/range.c
91806 @@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
91807 {
91808 const struct range *r1 = x1;
91809 const struct range *r2 = x2;
91810 - s64 start1, start2;
91811
91812 - start1 = r1->start;
91813 - start2 = r2->start;
91814 -
91815 - return start1 - start2;
91816 + if (r1->start < r2->start)
91817 + return -1;
91818 + if (r1->start > r2->start)
91819 + return 1;
91820 + return 0;
91821 }
91822
91823 int clean_sort_range(struct range *range, int az)
91824 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91825 index 240fa90..5fa56bd 100644
91826 --- a/kernel/rcu/rcutorture.c
91827 +++ b/kernel/rcu/rcutorture.c
91828 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91829 rcu_torture_count) = { 0 };
91830 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91831 rcu_torture_batch) = { 0 };
91832 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91833 -static atomic_t n_rcu_torture_alloc;
91834 -static atomic_t n_rcu_torture_alloc_fail;
91835 -static atomic_t n_rcu_torture_free;
91836 -static atomic_t n_rcu_torture_mberror;
91837 -static atomic_t n_rcu_torture_error;
91838 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91839 +static atomic_unchecked_t n_rcu_torture_alloc;
91840 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91841 +static atomic_unchecked_t n_rcu_torture_free;
91842 +static atomic_unchecked_t n_rcu_torture_mberror;
91843 +static atomic_unchecked_t n_rcu_torture_error;
91844 static long n_rcu_torture_barrier_error;
91845 static long n_rcu_torture_boost_ktrerror;
91846 static long n_rcu_torture_boost_rterror;
91847 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91848 static long n_rcu_torture_timers;
91849 static long n_barrier_attempts;
91850 static long n_barrier_successes;
91851 -static atomic_long_t n_cbfloods;
91852 +static atomic_long_unchecked_t n_cbfloods;
91853 static struct list_head rcu_torture_removed;
91854
91855 static int rcu_torture_writer_state;
91856 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91857
91858 spin_lock_bh(&rcu_torture_lock);
91859 if (list_empty(&rcu_torture_freelist)) {
91860 - atomic_inc(&n_rcu_torture_alloc_fail);
91861 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91862 spin_unlock_bh(&rcu_torture_lock);
91863 return NULL;
91864 }
91865 - atomic_inc(&n_rcu_torture_alloc);
91866 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91867 p = rcu_torture_freelist.next;
91868 list_del_init(p);
91869 spin_unlock_bh(&rcu_torture_lock);
91870 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91871 static void
91872 rcu_torture_free(struct rcu_torture *p)
91873 {
91874 - atomic_inc(&n_rcu_torture_free);
91875 + atomic_inc_unchecked(&n_rcu_torture_free);
91876 spin_lock_bh(&rcu_torture_lock);
91877 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91878 spin_unlock_bh(&rcu_torture_lock);
91879 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91880 i = rp->rtort_pipe_count;
91881 if (i > RCU_TORTURE_PIPE_LEN)
91882 i = RCU_TORTURE_PIPE_LEN;
91883 - atomic_inc(&rcu_torture_wcount[i]);
91884 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91885 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91886 rp->rtort_mbtest = 0;
91887 return true;
91888 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91889 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91890 do {
91891 schedule_timeout_interruptible(cbflood_inter_holdoff);
91892 - atomic_long_inc(&n_cbfloods);
91893 + atomic_long_inc_unchecked(&n_cbfloods);
91894 WARN_ON(signal_pending(current));
91895 for (i = 0; i < cbflood_n_burst; i++) {
91896 for (j = 0; j < cbflood_n_per_burst; j++) {
91897 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91898 i = old_rp->rtort_pipe_count;
91899 if (i > RCU_TORTURE_PIPE_LEN)
91900 i = RCU_TORTURE_PIPE_LEN;
91901 - atomic_inc(&rcu_torture_wcount[i]);
91902 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91903 old_rp->rtort_pipe_count++;
91904 switch (synctype[torture_random(&rand) % nsynctypes]) {
91905 case RTWS_DEF_FREE:
91906 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91907 return;
91908 }
91909 if (p->rtort_mbtest == 0)
91910 - atomic_inc(&n_rcu_torture_mberror);
91911 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91912 spin_lock(&rand_lock);
91913 cur_ops->read_delay(&rand);
91914 n_rcu_torture_timers++;
91915 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91916 continue;
91917 }
91918 if (p->rtort_mbtest == 0)
91919 - atomic_inc(&n_rcu_torture_mberror);
91920 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91921 cur_ops->read_delay(&rand);
91922 preempt_disable();
91923 pipe_count = p->rtort_pipe_count;
91924 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91925 rcu_torture_current,
91926 rcu_torture_current_version,
91927 list_empty(&rcu_torture_freelist),
91928 - atomic_read(&n_rcu_torture_alloc),
91929 - atomic_read(&n_rcu_torture_alloc_fail),
91930 - atomic_read(&n_rcu_torture_free));
91931 + atomic_read_unchecked(&n_rcu_torture_alloc),
91932 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91933 + atomic_read_unchecked(&n_rcu_torture_free));
91934 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91935 - atomic_read(&n_rcu_torture_mberror),
91936 + atomic_read_unchecked(&n_rcu_torture_mberror),
91937 n_rcu_torture_boost_ktrerror,
91938 n_rcu_torture_boost_rterror);
91939 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91940 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91941 n_barrier_successes,
91942 n_barrier_attempts,
91943 n_rcu_torture_barrier_error);
91944 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91945 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91946
91947 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91948 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91949 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91950 n_rcu_torture_barrier_error != 0 ||
91951 n_rcu_torture_boost_ktrerror != 0 ||
91952 n_rcu_torture_boost_rterror != 0 ||
91953 n_rcu_torture_boost_failure != 0 ||
91954 i > 1) {
91955 pr_cont("%s", "!!! ");
91956 - atomic_inc(&n_rcu_torture_error);
91957 + atomic_inc_unchecked(&n_rcu_torture_error);
91958 WARN_ON_ONCE(1);
91959 }
91960 pr_cont("Reader Pipe: ");
91961 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91962 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91963 pr_cont("Free-Block Circulation: ");
91964 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91965 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91966 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91967 }
91968 pr_cont("\n");
91969
91970 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91971
91972 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91973
91974 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91975 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91976 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91977 else if (torture_onoff_failures())
91978 rcu_torture_print_module_parms(cur_ops,
91979 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91980
91981 rcu_torture_current = NULL;
91982 rcu_torture_current_version = 0;
91983 - atomic_set(&n_rcu_torture_alloc, 0);
91984 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91985 - atomic_set(&n_rcu_torture_free, 0);
91986 - atomic_set(&n_rcu_torture_mberror, 0);
91987 - atomic_set(&n_rcu_torture_error, 0);
91988 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91989 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91990 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91991 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91992 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91993 n_rcu_torture_barrier_error = 0;
91994 n_rcu_torture_boost_ktrerror = 0;
91995 n_rcu_torture_boost_rterror = 0;
91996 n_rcu_torture_boost_failure = 0;
91997 n_rcu_torture_boosts = 0;
91998 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91999 - atomic_set(&rcu_torture_wcount[i], 0);
92000 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92001 for_each_possible_cpu(cpu) {
92002 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92003 per_cpu(rcu_torture_count, cpu)[i] = 0;
92004 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92005 index c0623fc..329c091 100644
92006 --- a/kernel/rcu/tiny.c
92007 +++ b/kernel/rcu/tiny.c
92008 @@ -42,7 +42,7 @@
92009 /* Forward declarations for tiny_plugin.h. */
92010 struct rcu_ctrlblk;
92011 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92012 -static void rcu_process_callbacks(struct softirq_action *unused);
92013 +static void rcu_process_callbacks(void);
92014 static void __call_rcu(struct rcu_head *head,
92015 void (*func)(struct rcu_head *rcu),
92016 struct rcu_ctrlblk *rcp);
92017 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92018 false));
92019 }
92020
92021 -static void rcu_process_callbacks(struct softirq_action *unused)
92022 +static __latent_entropy void rcu_process_callbacks(void)
92023 {
92024 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92025 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92026 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92027 index 858c565..7efd915 100644
92028 --- a/kernel/rcu/tiny_plugin.h
92029 +++ b/kernel/rcu/tiny_plugin.h
92030 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92031 dump_stack();
92032 }
92033 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92034 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92035 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92036 3 * rcu_jiffies_till_stall_check() + 3;
92037 else if (ULONG_CMP_GE(j, js))
92038 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92039 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92040 }
92041
92042 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92043 {
92044 rcp->ticks_this_gp = 0;
92045 rcp->gp_start = jiffies;
92046 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92047 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92048 }
92049
92050 static void check_cpu_stalls(void)
92051 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92052 index 9815447..2cdf92a 100644
92053 --- a/kernel/rcu/tree.c
92054 +++ b/kernel/rcu/tree.c
92055 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
92056 */
92057 rdtp = this_cpu_ptr(&rcu_dynticks);
92058 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92059 - atomic_add(2, &rdtp->dynticks); /* QS. */
92060 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92061 smp_mb__after_atomic(); /* Later stuff after QS. */
92062 break;
92063 }
92064 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92065 rcu_prepare_for_idle(smp_processor_id());
92066 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92067 smp_mb__before_atomic(); /* See above. */
92068 - atomic_inc(&rdtp->dynticks);
92069 + atomic_inc_unchecked(&rdtp->dynticks);
92070 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92071 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92072 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92073 rcu_dynticks_task_enter();
92074
92075 /*
92076 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92077 {
92078 rcu_dynticks_task_exit();
92079 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92080 - atomic_inc(&rdtp->dynticks);
92081 + atomic_inc_unchecked(&rdtp->dynticks);
92082 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92083 smp_mb__after_atomic(); /* See above. */
92084 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92085 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92086 rcu_cleanup_after_idle(smp_processor_id());
92087 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92088 if (!user && !is_idle_task(current)) {
92089 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
92090 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92091
92092 if (rdtp->dynticks_nmi_nesting == 0 &&
92093 - (atomic_read(&rdtp->dynticks) & 0x1))
92094 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92095 return;
92096 rdtp->dynticks_nmi_nesting++;
92097 smp_mb__before_atomic(); /* Force delay from prior write. */
92098 - atomic_inc(&rdtp->dynticks);
92099 + atomic_inc_unchecked(&rdtp->dynticks);
92100 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92101 smp_mb__after_atomic(); /* See above. */
92102 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92103 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92104 }
92105
92106 /**
92107 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
92108 return;
92109 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92110 smp_mb__before_atomic(); /* See above. */
92111 - atomic_inc(&rdtp->dynticks);
92112 + atomic_inc_unchecked(&rdtp->dynticks);
92113 smp_mb__after_atomic(); /* Force delay to next write. */
92114 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92115 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92116 }
92117
92118 /**
92119 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
92120 */
92121 bool notrace __rcu_is_watching(void)
92122 {
92123 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92124 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92125 }
92126
92127 /**
92128 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92129 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92130 bool *isidle, unsigned long *maxj)
92131 {
92132 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92133 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92134 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92135 if ((rdp->dynticks_snap & 0x1) == 0) {
92136 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92137 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92138 int *rcrmp;
92139 unsigned int snap;
92140
92141 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92142 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92143 snap = (unsigned int)rdp->dynticks_snap;
92144
92145 /*
92146 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92147 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92148 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92149 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92150 - ACCESS_ONCE(rdp->cond_resched_completed) =
92151 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92152 ACCESS_ONCE(rdp->mynode->completed);
92153 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92154 - ACCESS_ONCE(*rcrmp) =
92155 + ACCESS_ONCE_RW(*rcrmp) =
92156 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92157 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92158 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92159 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92160 rsp->gp_start = j;
92161 smp_wmb(); /* Record start time before stall time. */
92162 j1 = rcu_jiffies_till_stall_check();
92163 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92164 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92165 rsp->jiffies_resched = j + j1 / 2;
92166 }
92167
92168 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92169 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92170 return;
92171 }
92172 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92173 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92174 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92175
92176 /*
92177 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92178
92179 raw_spin_lock_irqsave(&rnp->lock, flags);
92180 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92181 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92182 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92183 3 * rcu_jiffies_till_stall_check() + 3;
92184 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92185
92186 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
92187 struct rcu_state *rsp;
92188
92189 for_each_rcu_flavor(rsp)
92190 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92191 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92192 }
92193
92194 /*
92195 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92196 raw_spin_unlock_irq(&rnp->lock);
92197 return 0;
92198 }
92199 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92200 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92201
92202 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92203 /*
92204 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92205 rdp = this_cpu_ptr(rsp->rda);
92206 rcu_preempt_check_blocked_tasks(rnp);
92207 rnp->qsmask = rnp->qsmaskinit;
92208 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92209 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92210 WARN_ON_ONCE(rnp->completed != rsp->completed);
92211 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92212 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92213 if (rnp == rdp->mynode)
92214 (void)__note_gp_changes(rsp, rnp, rdp);
92215 rcu_preempt_boost_start_gp(rnp);
92216 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92217 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92218 raw_spin_lock_irq(&rnp->lock);
92219 smp_mb__after_unlock_lock();
92220 - ACCESS_ONCE(rsp->gp_flags) =
92221 + ACCESS_ONCE_RW(rsp->gp_flags) =
92222 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
92223 raw_spin_unlock_irq(&rnp->lock);
92224 }
92225 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92226 rcu_for_each_node_breadth_first(rsp, rnp) {
92227 raw_spin_lock_irq(&rnp->lock);
92228 smp_mb__after_unlock_lock();
92229 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92230 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92231 rdp = this_cpu_ptr(rsp->rda);
92232 if (rnp == rdp->mynode)
92233 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92234 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92235 rcu_nocb_gp_set(rnp, nocb);
92236
92237 /* Declare grace period done. */
92238 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92239 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92240 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92241 rsp->fqs_state = RCU_GP_IDLE;
92242 rdp = this_cpu_ptr(rsp->rda);
92243 /* Advance CBs to reduce false positives below. */
92244 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92245 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92246 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92247 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92248 trace_rcu_grace_period(rsp->name,
92249 ACCESS_ONCE(rsp->gpnum),
92250 TPS("newreq"));
92251 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92252 */
92253 return false;
92254 }
92255 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92256 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92257 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92258 TPS("newreq"));
92259
92260 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92261 rsp->qlen += rdp->qlen;
92262 rdp->n_cbs_orphaned += rdp->qlen;
92263 rdp->qlen_lazy = 0;
92264 - ACCESS_ONCE(rdp->qlen) = 0;
92265 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92266 }
92267
92268 /*
92269 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92270 }
92271 smp_mb(); /* List handling before counting for rcu_barrier(). */
92272 rdp->qlen_lazy -= count_lazy;
92273 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92274 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92275 rdp->n_cbs_invoked += count;
92276
92277 /* Reinstate batch limit if we have worked down the excess. */
92278 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92279 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92280 return; /* Someone beat us to it. */
92281 }
92282 - ACCESS_ONCE(rsp->gp_flags) =
92283 + ACCESS_ONCE_RW(rsp->gp_flags) =
92284 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
92285 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92286 rcu_gp_kthread_wake(rsp);
92287 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92288 /*
92289 * Do RCU core processing for the current CPU.
92290 */
92291 -static void rcu_process_callbacks(struct softirq_action *unused)
92292 +static void rcu_process_callbacks(void)
92293 {
92294 struct rcu_state *rsp;
92295
92296 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92297 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92298 if (debug_rcu_head_queue(head)) {
92299 /* Probable double call_rcu(), so leak the callback. */
92300 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92301 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92302 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92303 return;
92304 }
92305 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92306 local_irq_restore(flags);
92307 return;
92308 }
92309 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92310 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92311 if (lazy)
92312 rdp->qlen_lazy++;
92313 else
92314 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
92315 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92316 * course be required on a 64-bit system.
92317 */
92318 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92319 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92320 (ulong)atomic_long_read(&rsp->expedited_done) +
92321 ULONG_MAX / 8)) {
92322 synchronize_sched();
92323 - atomic_long_inc(&rsp->expedited_wrap);
92324 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92325 return;
92326 }
92327
92328 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
92329 * Take a ticket. Note that atomic_inc_return() implies a
92330 * full memory barrier.
92331 */
92332 - snap = atomic_long_inc_return(&rsp->expedited_start);
92333 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92334 firstsnap = snap;
92335 if (!try_get_online_cpus()) {
92336 /* CPU hotplug operation in flight, fall back to normal GP. */
92337 wait_rcu_gp(call_rcu_sched);
92338 - atomic_long_inc(&rsp->expedited_normal);
92339 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92340 return;
92341 }
92342 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92343 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
92344 synchronize_sched_expedited_cpu_stop,
92345 NULL) == -EAGAIN) {
92346 put_online_cpus();
92347 - atomic_long_inc(&rsp->expedited_tryfail);
92348 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92349
92350 /* Check to see if someone else did our work for us. */
92351 s = atomic_long_read(&rsp->expedited_done);
92352 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92353 /* ensure test happens before caller kfree */
92354 smp_mb__before_atomic(); /* ^^^ */
92355 - atomic_long_inc(&rsp->expedited_workdone1);
92356 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92357 return;
92358 }
92359
92360 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
92361 udelay(trycount * num_online_cpus());
92362 } else {
92363 wait_rcu_gp(call_rcu_sched);
92364 - atomic_long_inc(&rsp->expedited_normal);
92365 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92366 return;
92367 }
92368
92369 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
92370 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92371 /* ensure test happens before caller kfree */
92372 smp_mb__before_atomic(); /* ^^^ */
92373 - atomic_long_inc(&rsp->expedited_workdone2);
92374 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92375 return;
92376 }
92377
92378 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
92379 if (!try_get_online_cpus()) {
92380 /* CPU hotplug operation in flight, use normal GP. */
92381 wait_rcu_gp(call_rcu_sched);
92382 - atomic_long_inc(&rsp->expedited_normal);
92383 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92384 return;
92385 }
92386 - snap = atomic_long_read(&rsp->expedited_start);
92387 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92388 smp_mb(); /* ensure read is before try_stop_cpus(). */
92389 }
92390 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92391 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92392
92393 /*
92394 * Everyone up to our most recent fetch is covered by our grace
92395 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92396 * than we did already did their update.
92397 */
92398 do {
92399 - atomic_long_inc(&rsp->expedited_done_tries);
92400 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92401 s = atomic_long_read(&rsp->expedited_done);
92402 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92403 /* ensure test happens before caller kfree */
92404 smp_mb__before_atomic(); /* ^^^ */
92405 - atomic_long_inc(&rsp->expedited_done_lost);
92406 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92407 break;
92408 }
92409 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92410 - atomic_long_inc(&rsp->expedited_done_exit);
92411 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92412
92413 put_online_cpus();
92414 }
92415 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92416 * ACCESS_ONCE() to prevent the compiler from speculating
92417 * the increment to precede the early-exit check.
92418 */
92419 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92420 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92421 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92422 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92423 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92424 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92425
92426 /* Increment ->n_barrier_done to prevent duplicate work. */
92427 smp_mb(); /* Keep increment after above mechanism. */
92428 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92429 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92430 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92431 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92432 smp_mb(); /* Keep increment before caller's subsequent code. */
92433 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92434 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92435 init_callback_list(rdp);
92436 rdp->qlen_lazy = 0;
92437 - ACCESS_ONCE(rdp->qlen) = 0;
92438 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92439 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92440 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92441 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92442 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92443 rdp->cpu = cpu;
92444 rdp->rsp = rsp;
92445 rcu_boot_init_nocb_percpu_data(rdp);
92446 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92447 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92448 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92449 rcu_sysidle_init_percpu_data(rdp->dynticks);
92450 - atomic_set(&rdp->dynticks->dynticks,
92451 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92452 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92453 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92454 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92455
92456 /* Add CPU to rcu_node bitmasks. */
92457 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92458 index bbdc45d..c882ccb 100644
92459 --- a/kernel/rcu/tree.h
92460 +++ b/kernel/rcu/tree.h
92461 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92462 long long dynticks_nesting; /* Track irq/process nesting level. */
92463 /* Process level is worth LLONG_MAX/2. */
92464 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92465 - atomic_t dynticks; /* Even value for idle, else odd. */
92466 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92467 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92468 long long dynticks_idle_nesting;
92469 /* irq/process nesting level from idle. */
92470 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92471 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92472 /* "Idle" excludes userspace execution. */
92473 unsigned long dynticks_idle_jiffies;
92474 /* End of last non-NMI non-idle period. */
92475 @@ -466,17 +466,17 @@ struct rcu_state {
92476 /* _rcu_barrier(). */
92477 /* End of fields guarded by barrier_mutex. */
92478
92479 - atomic_long_t expedited_start; /* Starting ticket. */
92480 - atomic_long_t expedited_done; /* Done ticket. */
92481 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92482 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92483 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92484 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92485 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92486 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92487 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92488 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92489 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92490 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92491 + atomic_long_t expedited_done; /* Done ticket. */
92492 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92493 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92494 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92495 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92496 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92497 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92498 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92499 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92500 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92501
92502 unsigned long jiffies_force_qs; /* Time at which to invoke */
92503 /* force_quiescent_state(). */
92504 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92505 index c1d7f27..a64bf49 100644
92506 --- a/kernel/rcu/tree_plugin.h
92507 +++ b/kernel/rcu/tree_plugin.h
92508 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92509 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92510 {
92511 return !rcu_preempted_readers_exp(rnp) &&
92512 - ACCESS_ONCE(rnp->expmask) == 0;
92513 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92514 }
92515
92516 /*
92517 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92518
92519 /* Clean up and exit. */
92520 smp_mb(); /* ensure expedited GP seen before counter increment. */
92521 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92522 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92523 sync_rcu_preempt_exp_count + 1;
92524 unlock_mb_ret:
92525 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92526 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92527 free_cpumask_var(cm);
92528 }
92529
92530 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92531 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92532 .store = &rcu_cpu_kthread_task,
92533 .thread_should_run = rcu_cpu_kthread_should_run,
92534 .thread_fn = rcu_cpu_kthread,
92535 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92536 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92537 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92538 cpu, ticks_value, ticks_title,
92539 - atomic_read(&rdtp->dynticks) & 0xfff,
92540 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92541 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92542 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92543 fast_no_hz);
92544 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92545 return;
92546 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92547 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92548 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92549 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92550 wake_up(&rdp_leader->nocb_wq);
92551 }
92552 }
92553 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92554
92555 /* Enqueue the callback on the nocb list and update counts. */
92556 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92557 - ACCESS_ONCE(*old_rhpp) = rhp;
92558 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92559 atomic_long_add(rhcount, &rdp->nocb_q_count);
92560 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92561 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92562 @@ -2286,7 +2286,7 @@ wait_again:
92563 continue; /* No CBs here, try next follower. */
92564
92565 /* Move callbacks to wait-for-GP list, which is empty. */
92566 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92567 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92568 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92569 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92570 rdp->nocb_gp_count_lazy =
92571 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92572 list = ACCESS_ONCE(rdp->nocb_follower_head);
92573 BUG_ON(!list);
92574 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92575 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92576 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92577 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92578 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92579 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92580 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92581 list = next;
92582 }
92583 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92584 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92585 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92586 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92587 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92588 rdp->nocb_p_count_lazy - cl;
92589 rdp->n_nocbs_invoked += c;
92590 }
92591 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92592 if (!rcu_nocb_need_deferred_wakeup(rdp))
92593 return;
92594 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92595 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92596 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92597 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92598 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92599 }
92600 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92601 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92602 "rcuo%c/%d", rsp->abbr, cpu);
92603 BUG_ON(IS_ERR(t));
92604 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92605 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92606 }
92607
92608 /*
92609 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92610
92611 /* Record start of fully idle period. */
92612 j = jiffies;
92613 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92614 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92615 smp_mb__before_atomic();
92616 - atomic_inc(&rdtp->dynticks_idle);
92617 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92618 smp_mb__after_atomic();
92619 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92620 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92621 }
92622
92623 /*
92624 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92625
92626 /* Record end of idle period. */
92627 smp_mb__before_atomic();
92628 - atomic_inc(&rdtp->dynticks_idle);
92629 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92630 smp_mb__after_atomic();
92631 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92632 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92633
92634 /*
92635 * If we are the timekeeping CPU, we are permitted to be non-idle
92636 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92637 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92638
92639 /* Pick up current idle and NMI-nesting counter and check. */
92640 - cur = atomic_read(&rdtp->dynticks_idle);
92641 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92642 if (cur & 0x1) {
92643 *isidle = false; /* We are not idle! */
92644 return;
92645 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92646 case RCU_SYSIDLE_NOT:
92647
92648 /* First time all are idle, so note a short idle period. */
92649 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92650 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92651 break;
92652
92653 case RCU_SYSIDLE_SHORT:
92654 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92655 {
92656 smp_mb();
92657 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92658 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92659 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92660 }
92661
92662 /*
92663 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92664 smp_mb(); /* grace period precedes setting inuse. */
92665
92666 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92667 - ACCESS_ONCE(rshp->inuse) = 0;
92668 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92669 }
92670
92671 /*
92672 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92673 static void rcu_dynticks_task_enter(void)
92674 {
92675 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92676 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92677 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92678 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92679 }
92680
92681 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92682 static void rcu_dynticks_task_exit(void)
92683 {
92684 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92685 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92686 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92687 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92688 }
92689 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92690 index 5cdc62e..cc52e88 100644
92691 --- a/kernel/rcu/tree_trace.c
92692 +++ b/kernel/rcu/tree_trace.c
92693 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92694 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92695 rdp->passed_quiesce, rdp->qs_pending);
92696 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92697 - atomic_read(&rdp->dynticks->dynticks),
92698 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92699 rdp->dynticks->dynticks_nesting,
92700 rdp->dynticks->dynticks_nmi_nesting,
92701 rdp->dynticks_fqs);
92702 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92703 struct rcu_state *rsp = (struct rcu_state *)m->private;
92704
92705 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",
92706 - atomic_long_read(&rsp->expedited_start),
92707 + atomic_long_read_unchecked(&rsp->expedited_start),
92708 atomic_long_read(&rsp->expedited_done),
92709 - atomic_long_read(&rsp->expedited_wrap),
92710 - atomic_long_read(&rsp->expedited_tryfail),
92711 - atomic_long_read(&rsp->expedited_workdone1),
92712 - atomic_long_read(&rsp->expedited_workdone2),
92713 - atomic_long_read(&rsp->expedited_normal),
92714 - atomic_long_read(&rsp->expedited_stoppedcpus),
92715 - atomic_long_read(&rsp->expedited_done_tries),
92716 - atomic_long_read(&rsp->expedited_done_lost),
92717 - atomic_long_read(&rsp->expedited_done_exit));
92718 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92719 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92720 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92721 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92722 + atomic_long_read_unchecked(&rsp->expedited_normal),
92723 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92724 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92725 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92726 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92727 return 0;
92728 }
92729
92730 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92731 index 3ef8ba5..8c5ebfb6 100644
92732 --- a/kernel/rcu/update.c
92733 +++ b/kernel/rcu/update.c
92734 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92735 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92736 */
92737 if (till_stall_check < 3) {
92738 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92739 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92740 till_stall_check = 3;
92741 } else if (till_stall_check > 300) {
92742 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92743 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92744 till_stall_check = 300;
92745 }
92746 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92747 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92748 !ACCESS_ONCE(t->on_rq) ||
92749 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92750 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92751 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92752 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92753 list_del_init(&t->rcu_tasks_holdout_list);
92754 put_task_struct(t);
92755 return;
92756 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92757 !is_idle_task(t)) {
92758 get_task_struct(t);
92759 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92760 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92761 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92762 list_add(&t->rcu_tasks_holdout_list,
92763 &rcu_tasks_holdouts);
92764 }
92765 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92766 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92767 BUG_ON(IS_ERR(t));
92768 smp_mb(); /* Ensure others see full kthread. */
92769 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92770 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92771 mutex_unlock(&rcu_tasks_kthread_mutex);
92772 }
92773
92774 diff --git a/kernel/resource.c b/kernel/resource.c
92775 index 0bcebff..e7cd5b2 100644
92776 --- a/kernel/resource.c
92777 +++ b/kernel/resource.c
92778 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92779
92780 static int __init ioresources_init(void)
92781 {
92782 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92783 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92784 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92785 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92786 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92787 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92788 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92789 +#endif
92790 +#else
92791 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92792 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92793 +#endif
92794 return 0;
92795 }
92796 __initcall(ioresources_init);
92797 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92798 index 8a2e230..6020954 100644
92799 --- a/kernel/sched/auto_group.c
92800 +++ b/kernel/sched/auto_group.c
92801 @@ -11,7 +11,7 @@
92802
92803 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92804 static struct autogroup autogroup_default;
92805 -static atomic_t autogroup_seq_nr;
92806 +static atomic_unchecked_t autogroup_seq_nr;
92807
92808 void __init autogroup_init(struct task_struct *init_task)
92809 {
92810 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92811
92812 kref_init(&ag->kref);
92813 init_rwsem(&ag->lock);
92814 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92815 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92816 ag->tg = tg;
92817 #ifdef CONFIG_RT_GROUP_SCHED
92818 /*
92819 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92820 index a63f4dc..349bbb0 100644
92821 --- a/kernel/sched/completion.c
92822 +++ b/kernel/sched/completion.c
92823 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92824 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92825 * or number of jiffies left till timeout) if completed.
92826 */
92827 -long __sched
92828 +long __sched __intentional_overflow(-1)
92829 wait_for_completion_interruptible_timeout(struct completion *x,
92830 unsigned long timeout)
92831 {
92832 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92833 *
92834 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92835 */
92836 -int __sched wait_for_completion_killable(struct completion *x)
92837 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92838 {
92839 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92840 if (t == -ERESTARTSYS)
92841 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92842 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92843 * or number of jiffies left till timeout) if completed.
92844 */
92845 -long __sched
92846 +long __sched __intentional_overflow(-1)
92847 wait_for_completion_killable_timeout(struct completion *x,
92848 unsigned long timeout)
92849 {
92850 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92851 index efdca2f..e361dfb 100644
92852 --- a/kernel/sched/core.c
92853 +++ b/kernel/sched/core.c
92854 @@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92855 int sysctl_numa_balancing(struct ctl_table *table, int write,
92856 void __user *buffer, size_t *lenp, loff_t *ppos)
92857 {
92858 - struct ctl_table t;
92859 + ctl_table_no_const t;
92860 int err;
92861 int state = numabalancing_enabled;
92862
92863 @@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92864 next->active_mm = oldmm;
92865 atomic_inc(&oldmm->mm_count);
92866 enter_lazy_tlb(oldmm, next);
92867 - } else
92868 + } else {
92869 switch_mm(oldmm, mm, next);
92870 + populate_stack();
92871 + }
92872
92873 if (!prev->mm) {
92874 prev->active_mm = NULL;
92875 @@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92876 /* convert nice value [19,-20] to rlimit style value [1,40] */
92877 int nice_rlim = nice_to_rlimit(nice);
92878
92879 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92880 +
92881 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92882 capable(CAP_SYS_NICE));
92883 }
92884 @@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92885 nice = task_nice(current) + increment;
92886
92887 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92888 - if (increment < 0 && !can_nice(current, nice))
92889 + if (increment < 0 && (!can_nice(current, nice) ||
92890 + gr_handle_chroot_nice()))
92891 return -EPERM;
92892
92893 retval = security_task_setnice(current, nice);
92894 @@ -3470,6 +3475,7 @@ recheck:
92895 if (policy != p->policy && !rlim_rtprio)
92896 return -EPERM;
92897
92898 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92899 /* can't increase priority */
92900 if (attr->sched_priority > p->rt_priority &&
92901 attr->sched_priority > rlim_rtprio)
92902 @@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92903
92904 if (mm != &init_mm) {
92905 switch_mm(mm, &init_mm, current);
92906 + populate_stack();
92907 finish_arch_post_lock_switch();
92908 }
92909 mmdrop(mm);
92910 @@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92911
92912 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92913
92914 -static struct ctl_table sd_ctl_dir[] = {
92915 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92916 {
92917 .procname = "sched_domain",
92918 .mode = 0555,
92919 @@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92920 {}
92921 };
92922
92923 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92924 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92925 {
92926 - struct ctl_table *entry =
92927 + ctl_table_no_const *entry =
92928 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92929
92930 return entry;
92931 }
92932
92933 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92934 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92935 {
92936 - struct ctl_table *entry;
92937 + ctl_table_no_const *entry;
92938
92939 /*
92940 * In the intermediate directories, both the child directory and
92941 @@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92942 * will always be set. In the lowest directory the names are
92943 * static strings and all have proc handlers.
92944 */
92945 - for (entry = *tablep; entry->mode; entry++) {
92946 - if (entry->child)
92947 - sd_free_ctl_entry(&entry->child);
92948 + for (entry = tablep; entry->mode; entry++) {
92949 + if (entry->child) {
92950 + sd_free_ctl_entry(entry->child);
92951 + pax_open_kernel();
92952 + entry->child = NULL;
92953 + pax_close_kernel();
92954 + }
92955 if (entry->proc_handler == NULL)
92956 kfree(entry->procname);
92957 }
92958
92959 - kfree(*tablep);
92960 - *tablep = NULL;
92961 + kfree(tablep);
92962 }
92963
92964 static int min_load_idx = 0;
92965 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92966
92967 static void
92968 -set_table_entry(struct ctl_table *entry,
92969 +set_table_entry(ctl_table_no_const *entry,
92970 const char *procname, void *data, int maxlen,
92971 umode_t mode, proc_handler *proc_handler,
92972 bool load_idx)
92973 @@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
92974 static struct ctl_table *
92975 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92976 {
92977 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92978 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92979
92980 if (table == NULL)
92981 return NULL;
92982 @@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92983 return table;
92984 }
92985
92986 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92987 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92988 {
92989 - struct ctl_table *entry, *table;
92990 + ctl_table_no_const *entry, *table;
92991 struct sched_domain *sd;
92992 int domain_num = 0, i;
92993 char buf[32];
92994 @@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
92995 static void register_sched_domain_sysctl(void)
92996 {
92997 int i, cpu_num = num_possible_cpus();
92998 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92999 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93000 char buf[32];
93001
93002 WARN_ON(sd_ctl_dir[0].child);
93003 + pax_open_kernel();
93004 sd_ctl_dir[0].child = entry;
93005 + pax_close_kernel();
93006
93007 if (entry == NULL)
93008 return;
93009 @@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
93010 if (sd_sysctl_header)
93011 unregister_sysctl_table(sd_sysctl_header);
93012 sd_sysctl_header = NULL;
93013 - if (sd_ctl_dir[0].child)
93014 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
93015 + if (sd_ctl_dir[0].child) {
93016 + sd_free_ctl_entry(sd_ctl_dir[0].child);
93017 + pax_open_kernel();
93018 + sd_ctl_dir[0].child = NULL;
93019 + pax_close_kernel();
93020 + }
93021 }
93022 #else
93023 static void register_sched_domain_sysctl(void)
93024 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93025 index ef2b104..69961f6 100644
93026 --- a/kernel/sched/fair.c
93027 +++ b/kernel/sched/fair.c
93028 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93029
93030 static void reset_ptenuma_scan(struct task_struct *p)
93031 {
93032 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
93033 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93034 p->mm->numa_scan_offset = 0;
93035 }
93036
93037 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93038 * run_rebalance_domains is triggered when needed from the scheduler tick.
93039 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93040 */
93041 -static void run_rebalance_domains(struct softirq_action *h)
93042 +static __latent_entropy void run_rebalance_domains(void)
93043 {
93044 struct rq *this_rq = this_rq();
93045 enum cpu_idle_type idle = this_rq->idle_balance ?
93046 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93047 index 2df8ef0..aae070f 100644
93048 --- a/kernel/sched/sched.h
93049 +++ b/kernel/sched/sched.h
93050 @@ -1140,7 +1140,7 @@ struct sched_class {
93051 #ifdef CONFIG_FAIR_GROUP_SCHED
93052 void (*task_move_group) (struct task_struct *p, int on_rq);
93053 #endif
93054 -};
93055 +} __do_const;
93056
93057 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93058 {
93059 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93060 index 4ef9687..4f44028 100644
93061 --- a/kernel/seccomp.c
93062 +++ b/kernel/seccomp.c
93063 @@ -629,7 +629,9 @@ static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)
93064
93065 switch (action) {
93066 case SECCOMP_RET_ERRNO:
93067 - /* Set the low-order 16-bits as a errno. */
93068 + /* Set low-order bits as an errno, capped at MAX_ERRNO. */
93069 + if (data > MAX_ERRNO)
93070 + data = MAX_ERRNO;
93071 syscall_set_return_value(current, task_pt_regs(current),
93072 -data, 0);
93073 goto skip;
93074 diff --git a/kernel/signal.c b/kernel/signal.c
93075 index 8f0876f..1153a5a 100644
93076 --- a/kernel/signal.c
93077 +++ b/kernel/signal.c
93078 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93079
93080 int print_fatal_signals __read_mostly;
93081
93082 -static void __user *sig_handler(struct task_struct *t, int sig)
93083 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
93084 {
93085 return t->sighand->action[sig - 1].sa.sa_handler;
93086 }
93087
93088 -static int sig_handler_ignored(void __user *handler, int sig)
93089 +static int sig_handler_ignored(__sighandler_t handler, int sig)
93090 {
93091 /* Is it explicitly or implicitly ignored? */
93092 return handler == SIG_IGN ||
93093 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93094
93095 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93096 {
93097 - void __user *handler;
93098 + __sighandler_t handler;
93099
93100 handler = sig_handler(t, sig);
93101
93102 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93103 atomic_inc(&user->sigpending);
93104 rcu_read_unlock();
93105
93106 + if (!override_rlimit)
93107 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93108 +
93109 if (override_rlimit ||
93110 atomic_read(&user->sigpending) <=
93111 task_rlimit(t, RLIMIT_SIGPENDING)) {
93112 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93113
93114 int unhandled_signal(struct task_struct *tsk, int sig)
93115 {
93116 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93117 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93118 if (is_global_init(tsk))
93119 return 1;
93120 if (handler != SIG_IGN && handler != SIG_DFL)
93121 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93122 }
93123 }
93124
93125 + /* allow glibc communication via tgkill to other threads in our
93126 + thread group */
93127 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93128 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93129 + && gr_handle_signal(t, sig))
93130 + return -EPERM;
93131 +
93132 return security_task_kill(t, info, sig, 0);
93133 }
93134
93135 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93136 return send_signal(sig, info, p, 1);
93137 }
93138
93139 -static int
93140 +int
93141 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93142 {
93143 return send_signal(sig, info, t, 0);
93144 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93145 unsigned long int flags;
93146 int ret, blocked, ignored;
93147 struct k_sigaction *action;
93148 + int is_unhandled = 0;
93149
93150 spin_lock_irqsave(&t->sighand->siglock, flags);
93151 action = &t->sighand->action[sig-1];
93152 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93153 }
93154 if (action->sa.sa_handler == SIG_DFL)
93155 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93156 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93157 + is_unhandled = 1;
93158 ret = specific_send_sig_info(sig, info, t);
93159 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93160
93161 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93162 + normal operation */
93163 + if (is_unhandled) {
93164 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93165 + gr_handle_crash(t, sig);
93166 + }
93167 +
93168 return ret;
93169 }
93170
93171 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93172 ret = check_kill_permission(sig, info, p);
93173 rcu_read_unlock();
93174
93175 - if (!ret && sig)
93176 + if (!ret && sig) {
93177 ret = do_send_sig_info(sig, info, p, true);
93178 + if (!ret)
93179 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93180 + }
93181
93182 return ret;
93183 }
93184 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93185 int error = -ESRCH;
93186
93187 rcu_read_lock();
93188 - p = find_task_by_vpid(pid);
93189 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93190 + /* allow glibc communication via tgkill to other threads in our
93191 + thread group */
93192 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93193 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93194 + p = find_task_by_vpid_unrestricted(pid);
93195 + else
93196 +#endif
93197 + p = find_task_by_vpid(pid);
93198 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93199 error = check_kill_permission(sig, info, p);
93200 /*
93201 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93202 }
93203 seg = get_fs();
93204 set_fs(KERNEL_DS);
93205 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93206 - (stack_t __force __user *) &uoss,
93207 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93208 + (stack_t __force_user *) &uoss,
93209 compat_user_stack_pointer());
93210 set_fs(seg);
93211 if (ret >= 0 && uoss_ptr) {
93212 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93213 index 60d35ac5..59d289f 100644
93214 --- a/kernel/smpboot.c
93215 +++ b/kernel/smpboot.c
93216 @@ -289,7 +289,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93217 }
93218 smpboot_unpark_thread(plug_thread, cpu);
93219 }
93220 - list_add(&plug_thread->list, &hotplug_threads);
93221 + pax_list_add(&plug_thread->list, &hotplug_threads);
93222 out:
93223 mutex_unlock(&smpboot_threads_lock);
93224 put_online_cpus();
93225 @@ -307,7 +307,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93226 {
93227 get_online_cpus();
93228 mutex_lock(&smpboot_threads_lock);
93229 - list_del(&plug_thread->list);
93230 + pax_list_del(&plug_thread->list);
93231 smpboot_destroy_threads(plug_thread);
93232 mutex_unlock(&smpboot_threads_lock);
93233 put_online_cpus();
93234 diff --git a/kernel/softirq.c b/kernel/softirq.c
93235 index 0699add..d365ad8 100644
93236 --- a/kernel/softirq.c
93237 +++ b/kernel/softirq.c
93238 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93239 EXPORT_SYMBOL(irq_stat);
93240 #endif
93241
93242 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93243 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93244
93245 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93246
93247 @@ -266,7 +266,7 @@ restart:
93248 kstat_incr_softirqs_this_cpu(vec_nr);
93249
93250 trace_softirq_entry(vec_nr);
93251 - h->action(h);
93252 + h->action();
93253 trace_softirq_exit(vec_nr);
93254 if (unlikely(prev_count != preempt_count())) {
93255 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93256 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93257 or_softirq_pending(1UL << nr);
93258 }
93259
93260 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93261 +void __init open_softirq(int nr, void (*action)(void))
93262 {
93263 softirq_vec[nr].action = action;
93264 }
93265 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93266 }
93267 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93268
93269 -static void tasklet_action(struct softirq_action *a)
93270 +static void tasklet_action(void)
93271 {
93272 struct tasklet_struct *list;
93273
93274 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93275 }
93276 }
93277
93278 -static void tasklet_hi_action(struct softirq_action *a)
93279 +static __latent_entropy void tasklet_hi_action(void)
93280 {
93281 struct tasklet_struct *list;
93282
93283 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93284 .notifier_call = cpu_callback
93285 };
93286
93287 -static struct smp_hotplug_thread softirq_threads = {
93288 +static struct smp_hotplug_thread softirq_threads __read_only = {
93289 .store = &ksoftirqd,
93290 .thread_should_run = ksoftirqd_should_run,
93291 .thread_fn = run_ksoftirqd,
93292 diff --git a/kernel/sys.c b/kernel/sys.c
93293 index 1eaa2f0..d80d27c 100644
93294 --- a/kernel/sys.c
93295 +++ b/kernel/sys.c
93296 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93297 error = -EACCES;
93298 goto out;
93299 }
93300 +
93301 + if (gr_handle_chroot_setpriority(p, niceval)) {
93302 + error = -EACCES;
93303 + goto out;
93304 + }
93305 +
93306 no_nice = security_task_setnice(p, niceval);
93307 if (no_nice) {
93308 error = no_nice;
93309 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93310 goto error;
93311 }
93312
93313 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93314 + goto error;
93315 +
93316 + if (!gid_eq(new->gid, old->gid)) {
93317 + /* make sure we generate a learn log for what will
93318 + end up being a role transition after a full-learning
93319 + policy is generated
93320 + CAP_SETGID is required to perform a transition
93321 + we may not log a CAP_SETGID check above, e.g.
93322 + in the case where new rgid = old egid
93323 + */
93324 + gr_learn_cap(current, new, CAP_SETGID);
93325 + }
93326 +
93327 if (rgid != (gid_t) -1 ||
93328 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93329 new->sgid = new->egid;
93330 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93331 old = current_cred();
93332
93333 retval = -EPERM;
93334 +
93335 + if (gr_check_group_change(kgid, kgid, kgid))
93336 + goto error;
93337 +
93338 if (ns_capable(old->user_ns, CAP_SETGID))
93339 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93340 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93341 @@ -405,7 +429,7 @@ error:
93342 /*
93343 * change the user struct in a credentials set to match the new UID
93344 */
93345 -static int set_user(struct cred *new)
93346 +int set_user(struct cred *new)
93347 {
93348 struct user_struct *new_user;
93349
93350 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93351 goto error;
93352 }
93353
93354 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93355 + goto error;
93356 +
93357 if (!uid_eq(new->uid, old->uid)) {
93358 + /* make sure we generate a learn log for what will
93359 + end up being a role transition after a full-learning
93360 + policy is generated
93361 + CAP_SETUID is required to perform a transition
93362 + we may not log a CAP_SETUID check above, e.g.
93363 + in the case where new ruid = old euid
93364 + */
93365 + gr_learn_cap(current, new, CAP_SETUID);
93366 retval = set_user(new);
93367 if (retval < 0)
93368 goto error;
93369 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93370 old = current_cred();
93371
93372 retval = -EPERM;
93373 +
93374 + if (gr_check_crash_uid(kuid))
93375 + goto error;
93376 + if (gr_check_user_change(kuid, kuid, kuid))
93377 + goto error;
93378 +
93379 if (ns_capable(old->user_ns, CAP_SETUID)) {
93380 new->suid = new->uid = kuid;
93381 if (!uid_eq(kuid, old->uid)) {
93382 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93383 goto error;
93384 }
93385
93386 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93387 + goto error;
93388 +
93389 if (ruid != (uid_t) -1) {
93390 new->uid = kruid;
93391 if (!uid_eq(kruid, old->uid)) {
93392 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93393 goto error;
93394 }
93395
93396 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93397 + goto error;
93398 +
93399 if (rgid != (gid_t) -1)
93400 new->gid = krgid;
93401 if (egid != (gid_t) -1)
93402 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93403 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93404 ns_capable(old->user_ns, CAP_SETUID)) {
93405 if (!uid_eq(kuid, old->fsuid)) {
93406 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93407 + goto error;
93408 +
93409 new->fsuid = kuid;
93410 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93411 goto change_okay;
93412 }
93413 }
93414
93415 +error:
93416 abort_creds(new);
93417 return old_fsuid;
93418
93419 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93420 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93421 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93422 ns_capable(old->user_ns, CAP_SETGID)) {
93423 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93424 + goto error;
93425 +
93426 if (!gid_eq(kgid, old->fsgid)) {
93427 new->fsgid = kgid;
93428 goto change_okay;
93429 }
93430 }
93431
93432 +error:
93433 abort_creds(new);
93434 return old_fsgid;
93435
93436 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93437 return -EFAULT;
93438
93439 down_read(&uts_sem);
93440 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93441 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93442 __OLD_UTS_LEN);
93443 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93444 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93445 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93446 __OLD_UTS_LEN);
93447 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93448 - error |= __copy_to_user(&name->release, &utsname()->release,
93449 + error |= __copy_to_user(name->release, &utsname()->release,
93450 __OLD_UTS_LEN);
93451 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93452 - error |= __copy_to_user(&name->version, &utsname()->version,
93453 + error |= __copy_to_user(name->version, &utsname()->version,
93454 __OLD_UTS_LEN);
93455 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93456 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93457 + error |= __copy_to_user(name->machine, &utsname()->machine,
93458 __OLD_UTS_LEN);
93459 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93460 up_read(&uts_sem);
93461 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93462 */
93463 new_rlim->rlim_cur = 1;
93464 }
93465 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93466 + is changed to a lower value. Since tasks can be created by the same
93467 + user in between this limit change and an execve by this task, force
93468 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93469 + */
93470 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93471 + tsk->flags |= PF_NPROC_EXCEEDED;
93472 }
93473 if (!retval) {
93474 if (old_rlim)
93475 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93476 index 15f2511..181b356 100644
93477 --- a/kernel/sysctl.c
93478 +++ b/kernel/sysctl.c
93479 @@ -94,7 +94,6 @@
93480
93481
93482 #if defined(CONFIG_SYSCTL)
93483 -
93484 /* External variables not in a header file. */
93485 extern int max_threads;
93486 extern int suid_dumpable;
93487 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93488
93489 /* Constants used for minimum and maximum */
93490 #ifdef CONFIG_LOCKUP_DETECTOR
93491 -static int sixty = 60;
93492 +static int sixty __read_only = 60;
93493 #endif
93494
93495 -static int __maybe_unused neg_one = -1;
93496 +static int __maybe_unused neg_one __read_only = -1;
93497
93498 -static int zero;
93499 -static int __maybe_unused one = 1;
93500 -static int __maybe_unused two = 2;
93501 -static int __maybe_unused four = 4;
93502 -static unsigned long one_ul = 1;
93503 -static int one_hundred = 100;
93504 +static int zero __read_only = 0;
93505 +static int __maybe_unused one __read_only = 1;
93506 +static int __maybe_unused two __read_only = 2;
93507 +static int __maybe_unused three __read_only = 3;
93508 +static int __maybe_unused four __read_only = 4;
93509 +static unsigned long one_ul __read_only = 1;
93510 +static int one_hundred __read_only = 100;
93511 #ifdef CONFIG_PRINTK
93512 -static int ten_thousand = 10000;
93513 +static int ten_thousand __read_only = 10000;
93514 #endif
93515
93516 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93517 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93518 void __user *buffer, size_t *lenp, loff_t *ppos);
93519 #endif
93520
93521 -#ifdef CONFIG_PRINTK
93522 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93523 void __user *buffer, size_t *lenp, loff_t *ppos);
93524 -#endif
93525
93526 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93527 void __user *buffer, size_t *lenp, loff_t *ppos);
93528 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93529
93530 #endif
93531
93532 +extern struct ctl_table grsecurity_table[];
93533 +
93534 static struct ctl_table kern_table[];
93535 static struct ctl_table vm_table[];
93536 static struct ctl_table fs_table[];
93537 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93538 int sysctl_legacy_va_layout;
93539 #endif
93540
93541 +#ifdef CONFIG_PAX_SOFTMODE
93542 +static struct ctl_table pax_table[] = {
93543 + {
93544 + .procname = "softmode",
93545 + .data = &pax_softmode,
93546 + .maxlen = sizeof(unsigned int),
93547 + .mode = 0600,
93548 + .proc_handler = &proc_dointvec,
93549 + },
93550 +
93551 + { }
93552 +};
93553 +#endif
93554 +
93555 /* The default sysctl tables: */
93556
93557 static struct ctl_table sysctl_base_table[] = {
93558 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93559 #endif
93560
93561 static struct ctl_table kern_table[] = {
93562 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93563 + {
93564 + .procname = "grsecurity",
93565 + .mode = 0500,
93566 + .child = grsecurity_table,
93567 + },
93568 +#endif
93569 +
93570 +#ifdef CONFIG_PAX_SOFTMODE
93571 + {
93572 + .procname = "pax",
93573 + .mode = 0500,
93574 + .child = pax_table,
93575 + },
93576 +#endif
93577 +
93578 {
93579 .procname = "sched_child_runs_first",
93580 .data = &sysctl_sched_child_runs_first,
93581 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93582 .data = &modprobe_path,
93583 .maxlen = KMOD_PATH_LEN,
93584 .mode = 0644,
93585 - .proc_handler = proc_dostring,
93586 + .proc_handler = proc_dostring_modpriv,
93587 },
93588 {
93589 .procname = "modules_disabled",
93590 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93591 .extra1 = &zero,
93592 .extra2 = &one,
93593 },
93594 +#endif
93595 {
93596 .procname = "kptr_restrict",
93597 .data = &kptr_restrict,
93598 .maxlen = sizeof(int),
93599 .mode = 0644,
93600 .proc_handler = proc_dointvec_minmax_sysadmin,
93601 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93602 + .extra1 = &two,
93603 +#else
93604 .extra1 = &zero,
93605 +#endif
93606 .extra2 = &two,
93607 },
93608 -#endif
93609 {
93610 .procname = "ngroups_max",
93611 .data = &ngroups_max,
93612 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93613 */
93614 {
93615 .procname = "perf_event_paranoid",
93616 - .data = &sysctl_perf_event_paranoid,
93617 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93618 + .data = &sysctl_perf_event_legitimately_concerned,
93619 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93620 .mode = 0644,
93621 - .proc_handler = proc_dointvec,
93622 + /* go ahead, be a hero */
93623 + .proc_handler = proc_dointvec_minmax_sysadmin,
93624 + .extra1 = &neg_one,
93625 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93626 + .extra2 = &three,
93627 +#else
93628 + .extra2 = &two,
93629 +#endif
93630 },
93631 {
93632 .procname = "perf_event_mlock_kb",
93633 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93634 .proc_handler = proc_dointvec_minmax,
93635 .extra1 = &zero,
93636 },
93637 + {
93638 + .procname = "heap_stack_gap",
93639 + .data = &sysctl_heap_stack_gap,
93640 + .maxlen = sizeof(sysctl_heap_stack_gap),
93641 + .mode = 0644,
93642 + .proc_handler = proc_doulongvec_minmax,
93643 + },
93644 #else
93645 {
93646 .procname = "nr_trim_pages",
93647 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93648 (char __user *)buffer, lenp, ppos);
93649 }
93650
93651 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93652 + void __user *buffer, size_t *lenp, loff_t *ppos)
93653 +{
93654 + if (write && !capable(CAP_SYS_MODULE))
93655 + return -EPERM;
93656 +
93657 + return _proc_do_string(table->data, table->maxlen, write,
93658 + buffer, lenp, ppos);
93659 +}
93660 +
93661 static size_t proc_skip_spaces(char **buf)
93662 {
93663 size_t ret;
93664 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93665 len = strlen(tmp);
93666 if (len > *size)
93667 len = *size;
93668 + if (len > sizeof(tmp))
93669 + len = sizeof(tmp);
93670 if (copy_to_user(*buf, tmp, len))
93671 return -EFAULT;
93672 *size -= len;
93673 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93674 static int proc_taint(struct ctl_table *table, int write,
93675 void __user *buffer, size_t *lenp, loff_t *ppos)
93676 {
93677 - struct ctl_table t;
93678 + ctl_table_no_const t;
93679 unsigned long tmptaint = get_taint();
93680 int err;
93681
93682 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93683 return err;
93684 }
93685
93686 -#ifdef CONFIG_PRINTK
93687 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93688 void __user *buffer, size_t *lenp, loff_t *ppos)
93689 {
93690 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93691
93692 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93693 }
93694 -#endif
93695
93696 struct do_proc_dointvec_minmax_conv_param {
93697 int *min;
93698 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93699 return -ENOSYS;
93700 }
93701
93702 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93703 + void __user *buffer, size_t *lenp, loff_t *ppos)
93704 +{
93705 + return -ENOSYS;
93706 +}
93707 +
93708 int proc_dointvec(struct ctl_table *table, int write,
93709 void __user *buffer, size_t *lenp, loff_t *ppos)
93710 {
93711 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93712 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93713 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93714 EXPORT_SYMBOL(proc_dostring);
93715 +EXPORT_SYMBOL(proc_dostring_modpriv);
93716 EXPORT_SYMBOL(proc_doulongvec_minmax);
93717 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93718 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93719 index b312fcc7..753d72d 100644
93720 --- a/kernel/taskstats.c
93721 +++ b/kernel/taskstats.c
93722 @@ -28,9 +28,12 @@
93723 #include <linux/fs.h>
93724 #include <linux/file.h>
93725 #include <linux/pid_namespace.h>
93726 +#include <linux/grsecurity.h>
93727 #include <net/genetlink.h>
93728 #include <linux/atomic.h>
93729
93730 +extern int gr_is_taskstats_denied(int pid);
93731 +
93732 /*
93733 * Maximum length of a cpumask that can be specified in
93734 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93735 @@ -576,6 +579,9 @@ err:
93736
93737 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93738 {
93739 + if (gr_is_taskstats_denied(current->pid))
93740 + return -EACCES;
93741 +
93742 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93743 return cmd_attr_register_cpumask(info);
93744 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93745 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93746 index a7077d3..dd48a49 100644
93747 --- a/kernel/time/alarmtimer.c
93748 +++ b/kernel/time/alarmtimer.c
93749 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93750 struct platform_device *pdev;
93751 int error = 0;
93752 int i;
93753 - struct k_clock alarm_clock = {
93754 + static struct k_clock alarm_clock = {
93755 .clock_getres = alarm_clock_getres,
93756 .clock_get = alarm_clock_get,
93757 .timer_create = alarm_timer_create,
93758 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93759 index d8c724c..6b331a4 100644
93760 --- a/kernel/time/hrtimer.c
93761 +++ b/kernel/time/hrtimer.c
93762 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93763 local_irq_restore(flags);
93764 }
93765
93766 -static void run_hrtimer_softirq(struct softirq_action *h)
93767 +static __latent_entropy void run_hrtimer_softirq(void)
93768 {
93769 hrtimer_peek_ahead_timers();
93770 }
93771 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93772 index a16b678..8c5bd9d 100644
93773 --- a/kernel/time/posix-cpu-timers.c
93774 +++ b/kernel/time/posix-cpu-timers.c
93775 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93776
93777 static __init int init_posix_cpu_timers(void)
93778 {
93779 - struct k_clock process = {
93780 + static struct k_clock process = {
93781 .clock_getres = process_cpu_clock_getres,
93782 .clock_get = process_cpu_clock_get,
93783 .timer_create = process_cpu_timer_create,
93784 .nsleep = process_cpu_nsleep,
93785 .nsleep_restart = process_cpu_nsleep_restart,
93786 };
93787 - struct k_clock thread = {
93788 + static struct k_clock thread = {
93789 .clock_getres = thread_cpu_clock_getres,
93790 .clock_get = thread_cpu_clock_get,
93791 .timer_create = thread_cpu_timer_create,
93792 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93793 index 31ea01f..7fc61ef 100644
93794 --- a/kernel/time/posix-timers.c
93795 +++ b/kernel/time/posix-timers.c
93796 @@ -43,6 +43,7 @@
93797 #include <linux/hash.h>
93798 #include <linux/posix-clock.h>
93799 #include <linux/posix-timers.h>
93800 +#include <linux/grsecurity.h>
93801 #include <linux/syscalls.h>
93802 #include <linux/wait.h>
93803 #include <linux/workqueue.h>
93804 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93805 * which we beg off on and pass to do_sys_settimeofday().
93806 */
93807
93808 -static struct k_clock posix_clocks[MAX_CLOCKS];
93809 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93810
93811 /*
93812 * These ones are defined below.
93813 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93814 */
93815 static __init int init_posix_timers(void)
93816 {
93817 - struct k_clock clock_realtime = {
93818 + static struct k_clock clock_realtime = {
93819 .clock_getres = hrtimer_get_res,
93820 .clock_get = posix_clock_realtime_get,
93821 .clock_set = posix_clock_realtime_set,
93822 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93823 .timer_get = common_timer_get,
93824 .timer_del = common_timer_del,
93825 };
93826 - struct k_clock clock_monotonic = {
93827 + static struct k_clock clock_monotonic = {
93828 .clock_getres = hrtimer_get_res,
93829 .clock_get = posix_ktime_get_ts,
93830 .nsleep = common_nsleep,
93831 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93832 .timer_get = common_timer_get,
93833 .timer_del = common_timer_del,
93834 };
93835 - struct k_clock clock_monotonic_raw = {
93836 + static struct k_clock clock_monotonic_raw = {
93837 .clock_getres = hrtimer_get_res,
93838 .clock_get = posix_get_monotonic_raw,
93839 };
93840 - struct k_clock clock_realtime_coarse = {
93841 + static struct k_clock clock_realtime_coarse = {
93842 .clock_getres = posix_get_coarse_res,
93843 .clock_get = posix_get_realtime_coarse,
93844 };
93845 - struct k_clock clock_monotonic_coarse = {
93846 + static struct k_clock clock_monotonic_coarse = {
93847 .clock_getres = posix_get_coarse_res,
93848 .clock_get = posix_get_monotonic_coarse,
93849 };
93850 - struct k_clock clock_tai = {
93851 + static struct k_clock clock_tai = {
93852 .clock_getres = hrtimer_get_res,
93853 .clock_get = posix_get_tai,
93854 .nsleep = common_nsleep,
93855 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93856 .timer_get = common_timer_get,
93857 .timer_del = common_timer_del,
93858 };
93859 - struct k_clock clock_boottime = {
93860 + static struct k_clock clock_boottime = {
93861 .clock_getres = hrtimer_get_res,
93862 .clock_get = posix_get_boottime,
93863 .nsleep = common_nsleep,
93864 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93865 return;
93866 }
93867
93868 - posix_clocks[clock_id] = *new_clock;
93869 + posix_clocks[clock_id] = new_clock;
93870 }
93871 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93872
93873 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93874 return (id & CLOCKFD_MASK) == CLOCKFD ?
93875 &clock_posix_dynamic : &clock_posix_cpu;
93876
93877 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93878 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93879 return NULL;
93880 - return &posix_clocks[id];
93881 + return posix_clocks[id];
93882 }
93883
93884 static int common_timer_create(struct k_itimer *new_timer)
93885 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93886 struct k_clock *kc = clockid_to_kclock(which_clock);
93887 struct k_itimer *new_timer;
93888 int error, new_timer_id;
93889 - sigevent_t event;
93890 + sigevent_t event = { };
93891 int it_id_set = IT_ID_NOT_SET;
93892
93893 if (!kc)
93894 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93895 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93896 return -EFAULT;
93897
93898 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93899 + have their clock_set fptr set to a nosettime dummy function
93900 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93901 + call common_clock_set, which calls do_sys_settimeofday, which
93902 + we hook
93903 + */
93904 +
93905 return kc->clock_set(which_clock, &new_tp);
93906 }
93907
93908 diff --git a/kernel/time/time.c b/kernel/time/time.c
93909 index 22d5d3b..70caeb2 100644
93910 --- a/kernel/time/time.c
93911 +++ b/kernel/time/time.c
93912 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93913 return error;
93914
93915 if (tz) {
93916 + /* we log in do_settimeofday called below, so don't log twice
93917 + */
93918 + if (!tv)
93919 + gr_log_timechange();
93920 +
93921 sys_tz = *tz;
93922 update_vsyscall_tz();
93923 if (firsttime) {
93924 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93925 index ec1791f..6a086cd 100644
93926 --- a/kernel/time/timekeeping.c
93927 +++ b/kernel/time/timekeeping.c
93928 @@ -15,6 +15,7 @@
93929 #include <linux/init.h>
93930 #include <linux/mm.h>
93931 #include <linux/sched.h>
93932 +#include <linux/grsecurity.h>
93933 #include <linux/syscore_ops.h>
93934 #include <linux/clocksource.h>
93935 #include <linux/jiffies.h>
93936 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93937 if (!timespec_valid_strict(tv))
93938 return -EINVAL;
93939
93940 + gr_log_timechange();
93941 +
93942 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93943 write_seqcount_begin(&tk_core.seq);
93944
93945 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93946 index 3260ffd..c93cd5e 100644
93947 --- a/kernel/time/timer.c
93948 +++ b/kernel/time/timer.c
93949 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93950 /*
93951 * This function runs timers and the timer-tq in bottom half context.
93952 */
93953 -static void run_timer_softirq(struct softirq_action *h)
93954 +static __latent_entropy void run_timer_softirq(void)
93955 {
93956 struct tvec_base *base = __this_cpu_read(tvec_bases);
93957
93958 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93959 *
93960 * In all cases the return value is guaranteed to be non-negative.
93961 */
93962 -signed long __sched schedule_timeout(signed long timeout)
93963 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93964 {
93965 struct timer_list timer;
93966 unsigned long expire;
93967 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93968 index 61ed862..3b52c65 100644
93969 --- a/kernel/time/timer_list.c
93970 +++ b/kernel/time/timer_list.c
93971 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93972
93973 static void print_name_offset(struct seq_file *m, void *sym)
93974 {
93975 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93976 + SEQ_printf(m, "<%p>", NULL);
93977 +#else
93978 char symname[KSYM_NAME_LEN];
93979
93980 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93981 SEQ_printf(m, "<%pK>", sym);
93982 else
93983 SEQ_printf(m, "%s", symname);
93984 +#endif
93985 }
93986
93987 static void
93988 @@ -119,7 +123,11 @@ next_one:
93989 static void
93990 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93991 {
93992 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93993 + SEQ_printf(m, " .base: %p\n", NULL);
93994 +#else
93995 SEQ_printf(m, " .base: %pK\n", base);
93996 +#endif
93997 SEQ_printf(m, " .index: %d\n",
93998 base->index);
93999 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94000 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94001 {
94002 struct proc_dir_entry *pe;
94003
94004 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94005 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94006 +#else
94007 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94008 +#endif
94009 if (!pe)
94010 return -ENOMEM;
94011 return 0;
94012 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94013 index 1fb08f2..ca4bb1e 100644
94014 --- a/kernel/time/timer_stats.c
94015 +++ b/kernel/time/timer_stats.c
94016 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94017 static unsigned long nr_entries;
94018 static struct entry entries[MAX_ENTRIES];
94019
94020 -static atomic_t overflow_count;
94021 +static atomic_unchecked_t overflow_count;
94022
94023 /*
94024 * The entries are in a hash-table, for fast lookup:
94025 @@ -140,7 +140,7 @@ static void reset_entries(void)
94026 nr_entries = 0;
94027 memset(entries, 0, sizeof(entries));
94028 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94029 - atomic_set(&overflow_count, 0);
94030 + atomic_set_unchecked(&overflow_count, 0);
94031 }
94032
94033 static struct entry *alloc_entry(void)
94034 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94035 if (likely(entry))
94036 entry->count++;
94037 else
94038 - atomic_inc(&overflow_count);
94039 + atomic_inc_unchecked(&overflow_count);
94040
94041 out_unlock:
94042 raw_spin_unlock_irqrestore(lock, flags);
94043 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94044
94045 static void print_name_offset(struct seq_file *m, unsigned long addr)
94046 {
94047 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94048 + seq_printf(m, "<%p>", NULL);
94049 +#else
94050 char symname[KSYM_NAME_LEN];
94051
94052 if (lookup_symbol_name(addr, symname) < 0)
94053 - seq_printf(m, "<%p>", (void *)addr);
94054 + seq_printf(m, "<%pK>", (void *)addr);
94055 else
94056 seq_printf(m, "%s", symname);
94057 +#endif
94058 }
94059
94060 static int tstats_show(struct seq_file *m, void *v)
94061 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94062
94063 seq_puts(m, "Timer Stats Version: v0.3\n");
94064 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94065 - if (atomic_read(&overflow_count))
94066 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94067 + if (atomic_read_unchecked(&overflow_count))
94068 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94069 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94070
94071 for (i = 0; i < nr_entries; i++) {
94072 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94073 {
94074 struct proc_dir_entry *pe;
94075
94076 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94077 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94078 +#else
94079 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94080 +#endif
94081 if (!pe)
94082 return -ENOMEM;
94083 return 0;
94084 diff --git a/kernel/torture.c b/kernel/torture.c
94085 index dd70993..0bf694b 100644
94086 --- a/kernel/torture.c
94087 +++ b/kernel/torture.c
94088 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94089 mutex_lock(&fullstop_mutex);
94090 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94091 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94092 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94093 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94094 } else {
94095 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94096 }
94097 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
94098 if (!torture_must_stop()) {
94099 if (stutter > 1) {
94100 schedule_timeout_interruptible(stutter - 1);
94101 - ACCESS_ONCE(stutter_pause_test) = 2;
94102 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
94103 }
94104 schedule_timeout_interruptible(1);
94105 - ACCESS_ONCE(stutter_pause_test) = 1;
94106 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
94107 }
94108 if (!torture_must_stop())
94109 schedule_timeout_interruptible(stutter);
94110 - ACCESS_ONCE(stutter_pause_test) = 0;
94111 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
94112 torture_shutdown_absorb("torture_stutter");
94113 } while (!torture_must_stop());
94114 torture_kthread_stopping("torture_stutter");
94115 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
94116 schedule_timeout_uninterruptible(10);
94117 return true;
94118 }
94119 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94120 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94121 mutex_unlock(&fullstop_mutex);
94122 torture_shutdown_cleanup();
94123 torture_shuffle_cleanup();
94124 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94125 index c1bd4ad..4b861dc 100644
94126 --- a/kernel/trace/blktrace.c
94127 +++ b/kernel/trace/blktrace.c
94128 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94129 struct blk_trace *bt = filp->private_data;
94130 char buf[16];
94131
94132 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94133 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94134
94135 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94136 }
94137 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94138 return 1;
94139
94140 bt = buf->chan->private_data;
94141 - atomic_inc(&bt->dropped);
94142 + atomic_inc_unchecked(&bt->dropped);
94143 return 0;
94144 }
94145
94146 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94147
94148 bt->dir = dir;
94149 bt->dev = dev;
94150 - atomic_set(&bt->dropped, 0);
94151 + atomic_set_unchecked(&bt->dropped, 0);
94152 INIT_LIST_HEAD(&bt->running_list);
94153
94154 ret = -EIO;
94155 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94156 index 124e2c7..762ca29 100644
94157 --- a/kernel/trace/ftrace.c
94158 +++ b/kernel/trace/ftrace.c
94159 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94160 if (unlikely(ftrace_disabled))
94161 return 0;
94162
94163 + ret = ftrace_arch_code_modify_prepare();
94164 + FTRACE_WARN_ON(ret);
94165 + if (ret)
94166 + return 0;
94167 +
94168 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94169 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94170 if (ret) {
94171 ftrace_bug(ret, ip);
94172 - return 0;
94173 }
94174 - return 1;
94175 + return ret ? 0 : 1;
94176 }
94177
94178 /*
94179 @@ -4529,8 +4534,10 @@ static int ftrace_process_locs(struct module *mod,
94180 if (!count)
94181 return 0;
94182
94183 + pax_open_kernel();
94184 sort(start, count, sizeof(*start),
94185 ftrace_cmp_ips, ftrace_swap_ips);
94186 + pax_close_kernel();
94187
94188 start_pg = ftrace_allocate_pages(count);
94189 if (!start_pg)
94190 @@ -5377,7 +5384,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94191
94192 if (t->ret_stack == NULL) {
94193 atomic_set(&t->tracing_graph_pause, 0);
94194 - atomic_set(&t->trace_overrun, 0);
94195 + atomic_set_unchecked(&t->trace_overrun, 0);
94196 t->curr_ret_stack = -1;
94197 /* Make sure the tasks see the -1 first: */
94198 smp_wmb();
94199 @@ -5590,7 +5597,7 @@ static void
94200 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94201 {
94202 atomic_set(&t->tracing_graph_pause, 0);
94203 - atomic_set(&t->trace_overrun, 0);
94204 + atomic_set_unchecked(&t->trace_overrun, 0);
94205 t->ftrace_timestamp = 0;
94206 /* make curr_ret_stack visible before we add the ret_stack */
94207 smp_wmb();
94208 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94209 index a56e07c..d46f0ba 100644
94210 --- a/kernel/trace/ring_buffer.c
94211 +++ b/kernel/trace/ring_buffer.c
94212 @@ -352,9 +352,9 @@ struct buffer_data_page {
94213 */
94214 struct buffer_page {
94215 struct list_head list; /* list of buffer pages */
94216 - local_t write; /* index for next write */
94217 + local_unchecked_t write; /* index for next write */
94218 unsigned read; /* index for next read */
94219 - local_t entries; /* entries on this page */
94220 + local_unchecked_t entries; /* entries on this page */
94221 unsigned long real_end; /* real end of data */
94222 struct buffer_data_page *page; /* Actual data page */
94223 };
94224 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94225 unsigned long last_overrun;
94226 local_t entries_bytes;
94227 local_t entries;
94228 - local_t overrun;
94229 - local_t commit_overrun;
94230 + local_unchecked_t overrun;
94231 + local_unchecked_t commit_overrun;
94232 local_t dropped_events;
94233 local_t committing;
94234 local_t commits;
94235 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94236 *
94237 * We add a counter to the write field to denote this.
94238 */
94239 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94240 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94241 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94242 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94243
94244 /*
94245 * Just make sure we have seen our old_write and synchronize
94246 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94247 * cmpxchg to only update if an interrupt did not already
94248 * do it for us. If the cmpxchg fails, we don't care.
94249 */
94250 - (void)local_cmpxchg(&next_page->write, old_write, val);
94251 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94252 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94253 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94254
94255 /*
94256 * No need to worry about races with clearing out the commit.
94257 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94258
94259 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94260 {
94261 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94262 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94263 }
94264
94265 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94266 {
94267 - return local_read(&bpage->write) & RB_WRITE_MASK;
94268 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94269 }
94270
94271 static int
94272 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94273 * bytes consumed in ring buffer from here.
94274 * Increment overrun to account for the lost events.
94275 */
94276 - local_add(page_entries, &cpu_buffer->overrun);
94277 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94278 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94279 }
94280
94281 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94282 * it is our responsibility to update
94283 * the counters.
94284 */
94285 - local_add(entries, &cpu_buffer->overrun);
94286 + local_add_unchecked(entries, &cpu_buffer->overrun);
94287 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94288
94289 /*
94290 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94291 if (tail == BUF_PAGE_SIZE)
94292 tail_page->real_end = 0;
94293
94294 - local_sub(length, &tail_page->write);
94295 + local_sub_unchecked(length, &tail_page->write);
94296 return;
94297 }
94298
94299 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94300 rb_event_set_padding(event);
94301
94302 /* Set the write back to the previous setting */
94303 - local_sub(length, &tail_page->write);
94304 + local_sub_unchecked(length, &tail_page->write);
94305 return;
94306 }
94307
94308 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94309
94310 /* Set write to end of buffer */
94311 length = (tail + length) - BUF_PAGE_SIZE;
94312 - local_sub(length, &tail_page->write);
94313 + local_sub_unchecked(length, &tail_page->write);
94314 }
94315
94316 /*
94317 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94318 * about it.
94319 */
94320 if (unlikely(next_page == commit_page)) {
94321 - local_inc(&cpu_buffer->commit_overrun);
94322 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94323 goto out_reset;
94324 }
94325
94326 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94327 cpu_buffer->tail_page) &&
94328 (cpu_buffer->commit_page ==
94329 cpu_buffer->reader_page))) {
94330 - local_inc(&cpu_buffer->commit_overrun);
94331 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94332 goto out_reset;
94333 }
94334 }
94335 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94336 length += RB_LEN_TIME_EXTEND;
94337
94338 tail_page = cpu_buffer->tail_page;
94339 - write = local_add_return(length, &tail_page->write);
94340 + write = local_add_return_unchecked(length, &tail_page->write);
94341
94342 /* set write to only the index of the write */
94343 write &= RB_WRITE_MASK;
94344 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94345 kmemcheck_annotate_bitfield(event, bitfield);
94346 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94347
94348 - local_inc(&tail_page->entries);
94349 + local_inc_unchecked(&tail_page->entries);
94350
94351 /*
94352 * If this is the first commit on the page, then update
94353 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94354
94355 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94356 unsigned long write_mask =
94357 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94358 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94359 unsigned long event_length = rb_event_length(event);
94360 /*
94361 * This is on the tail page. It is possible that
94362 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94363 */
94364 old_index += write_mask;
94365 new_index += write_mask;
94366 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94367 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94368 if (index == old_index) {
94369 /* update counters */
94370 local_sub(event_length, &cpu_buffer->entries_bytes);
94371 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94372
94373 /* Do the likely case first */
94374 if (likely(bpage->page == (void *)addr)) {
94375 - local_dec(&bpage->entries);
94376 + local_dec_unchecked(&bpage->entries);
94377 return;
94378 }
94379
94380 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94381 start = bpage;
94382 do {
94383 if (bpage->page == (void *)addr) {
94384 - local_dec(&bpage->entries);
94385 + local_dec_unchecked(&bpage->entries);
94386 return;
94387 }
94388 rb_inc_page(cpu_buffer, &bpage);
94389 @@ -3173,7 +3173,7 @@ static inline unsigned long
94390 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94391 {
94392 return local_read(&cpu_buffer->entries) -
94393 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94394 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94395 }
94396
94397 /**
94398 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94399 return 0;
94400
94401 cpu_buffer = buffer->buffers[cpu];
94402 - ret = local_read(&cpu_buffer->overrun);
94403 + ret = local_read_unchecked(&cpu_buffer->overrun);
94404
94405 return ret;
94406 }
94407 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94408 return 0;
94409
94410 cpu_buffer = buffer->buffers[cpu];
94411 - ret = local_read(&cpu_buffer->commit_overrun);
94412 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94413
94414 return ret;
94415 }
94416 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94417 /* if you care about this being correct, lock the buffer */
94418 for_each_buffer_cpu(buffer, cpu) {
94419 cpu_buffer = buffer->buffers[cpu];
94420 - overruns += local_read(&cpu_buffer->overrun);
94421 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94422 }
94423
94424 return overruns;
94425 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94426 /*
94427 * Reset the reader page to size zero.
94428 */
94429 - local_set(&cpu_buffer->reader_page->write, 0);
94430 - local_set(&cpu_buffer->reader_page->entries, 0);
94431 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94432 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94433 local_set(&cpu_buffer->reader_page->page->commit, 0);
94434 cpu_buffer->reader_page->real_end = 0;
94435
94436 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94437 * want to compare with the last_overrun.
94438 */
94439 smp_mb();
94440 - overwrite = local_read(&(cpu_buffer->overrun));
94441 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94442
94443 /*
94444 * Here's the tricky part.
94445 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94446
94447 cpu_buffer->head_page
94448 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94449 - local_set(&cpu_buffer->head_page->write, 0);
94450 - local_set(&cpu_buffer->head_page->entries, 0);
94451 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94452 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94453 local_set(&cpu_buffer->head_page->page->commit, 0);
94454
94455 cpu_buffer->head_page->read = 0;
94456 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94457
94458 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94459 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94460 - local_set(&cpu_buffer->reader_page->write, 0);
94461 - local_set(&cpu_buffer->reader_page->entries, 0);
94462 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94463 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94464 local_set(&cpu_buffer->reader_page->page->commit, 0);
94465 cpu_buffer->reader_page->read = 0;
94466
94467 local_set(&cpu_buffer->entries_bytes, 0);
94468 - local_set(&cpu_buffer->overrun, 0);
94469 - local_set(&cpu_buffer->commit_overrun, 0);
94470 + local_set_unchecked(&cpu_buffer->overrun, 0);
94471 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94472 local_set(&cpu_buffer->dropped_events, 0);
94473 local_set(&cpu_buffer->entries, 0);
94474 local_set(&cpu_buffer->committing, 0);
94475 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94476 rb_init_page(bpage);
94477 bpage = reader->page;
94478 reader->page = *data_page;
94479 - local_set(&reader->write, 0);
94480 - local_set(&reader->entries, 0);
94481 + local_set_unchecked(&reader->write, 0);
94482 + local_set_unchecked(&reader->entries, 0);
94483 reader->read = 0;
94484 *data_page = bpage;
94485
94486 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94487 index 426962b..e8e2d9a 100644
94488 --- a/kernel/trace/trace.c
94489 +++ b/kernel/trace/trace.c
94490 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94491 return 0;
94492 }
94493
94494 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94495 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94496 {
94497 /* do nothing if flag is already set */
94498 if (!!(trace_flags & mask) == !!enabled)
94499 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94500 index 385391f..8d2250f 100644
94501 --- a/kernel/trace/trace.h
94502 +++ b/kernel/trace/trace.h
94503 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94504 void trace_printk_init_buffers(void);
94505 void trace_printk_start_comm(void);
94506 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94507 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94508 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94509
94510 /*
94511 * Normal trace_printk() and friends allocates special buffers
94512 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94513 index 57b67b1..66082a9 100644
94514 --- a/kernel/trace/trace_clock.c
94515 +++ b/kernel/trace/trace_clock.c
94516 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94517 return now;
94518 }
94519
94520 -static atomic64_t trace_counter;
94521 +static atomic64_unchecked_t trace_counter;
94522
94523 /*
94524 * trace_clock_counter(): simply an atomic counter.
94525 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94526 */
94527 u64 notrace trace_clock_counter(void)
94528 {
94529 - return atomic64_add_return(1, &trace_counter);
94530 + return atomic64_inc_return_unchecked(&trace_counter);
94531 }
94532 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94533 index 1b0df1e..4ebb965 100644
94534 --- a/kernel/trace/trace_events.c
94535 +++ b/kernel/trace/trace_events.c
94536 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94537 return 0;
94538 }
94539
94540 -struct ftrace_module_file_ops;
94541 static void __add_event_to_tracers(struct ftrace_event_call *call);
94542
94543 /* Add an additional event_call dynamically */
94544 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94545 index f0a0c98..3692dc8 100644
94546 --- a/kernel/trace/trace_functions_graph.c
94547 +++ b/kernel/trace/trace_functions_graph.c
94548 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94549
94550 /* The return trace stack is full */
94551 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94552 - atomic_inc(&current->trace_overrun);
94553 + atomic_inc_unchecked(&current->trace_overrun);
94554 return -EBUSY;
94555 }
94556
94557 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94558 *ret = current->ret_stack[index].ret;
94559 trace->func = current->ret_stack[index].func;
94560 trace->calltime = current->ret_stack[index].calltime;
94561 - trace->overrun = atomic_read(&current->trace_overrun);
94562 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94563 trace->depth = index;
94564 }
94565
94566 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94567 index 0abd9b8..6a663a2 100644
94568 --- a/kernel/trace/trace_mmiotrace.c
94569 +++ b/kernel/trace/trace_mmiotrace.c
94570 @@ -24,7 +24,7 @@ struct header_iter {
94571 static struct trace_array *mmio_trace_array;
94572 static bool overrun_detected;
94573 static unsigned long prev_overruns;
94574 -static atomic_t dropped_count;
94575 +static atomic_unchecked_t dropped_count;
94576
94577 static void mmio_reset_data(struct trace_array *tr)
94578 {
94579 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94580
94581 static unsigned long count_overruns(struct trace_iterator *iter)
94582 {
94583 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94584 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94585 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94586
94587 if (over > prev_overruns)
94588 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94589 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94590 sizeof(*entry), 0, pc);
94591 if (!event) {
94592 - atomic_inc(&dropped_count);
94593 + atomic_inc_unchecked(&dropped_count);
94594 return;
94595 }
94596 entry = ring_buffer_event_data(event);
94597 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94598 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94599 sizeof(*entry), 0, pc);
94600 if (!event) {
94601 - atomic_inc(&dropped_count);
94602 + atomic_inc_unchecked(&dropped_count);
94603 return;
94604 }
94605 entry = ring_buffer_event_data(event);
94606 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94607 index c6977d5..d243785 100644
94608 --- a/kernel/trace/trace_output.c
94609 +++ b/kernel/trace/trace_output.c
94610 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94611 goto out;
94612 }
94613
94614 + pax_open_kernel();
94615 if (event->funcs->trace == NULL)
94616 - event->funcs->trace = trace_nop_print;
94617 + *(void **)&event->funcs->trace = trace_nop_print;
94618 if (event->funcs->raw == NULL)
94619 - event->funcs->raw = trace_nop_print;
94620 + *(void **)&event->funcs->raw = trace_nop_print;
94621 if (event->funcs->hex == NULL)
94622 - event->funcs->hex = trace_nop_print;
94623 + *(void **)&event->funcs->hex = trace_nop_print;
94624 if (event->funcs->binary == NULL)
94625 - event->funcs->binary = trace_nop_print;
94626 + *(void **)&event->funcs->binary = trace_nop_print;
94627 + pax_close_kernel();
94628
94629 key = event->type & (EVENT_HASHSIZE - 1);
94630
94631 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94632 index 1f24ed9..10407ec 100644
94633 --- a/kernel/trace/trace_seq.c
94634 +++ b/kernel/trace/trace_seq.c
94635 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94636
94637 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94638 if (!IS_ERR(p)) {
94639 - p = mangle_path(s->buffer + s->len, p, "\n");
94640 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94641 if (p) {
94642 s->len = p - s->buffer;
94643 return 1;
94644 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94645 index 16eddb3..758b308 100644
94646 --- a/kernel/trace/trace_stack.c
94647 +++ b/kernel/trace/trace_stack.c
94648 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94649 return;
94650
94651 /* we do not handle interrupt stacks yet */
94652 - if (!object_is_on_stack(stack))
94653 + if (!object_starts_on_stack(stack))
94654 return;
94655
94656 local_irq_save(flags);
94657 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94658 index 29228c4..301bc8c 100644
94659 --- a/kernel/trace/trace_syscalls.c
94660 +++ b/kernel/trace/trace_syscalls.c
94661 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94662 int num;
94663
94664 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94665 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94666 + return -EINVAL;
94667
94668 mutex_lock(&syscall_trace_lock);
94669 if (!sys_perf_refcount_enter)
94670 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94671 int num;
94672
94673 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94674 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94675 + return;
94676
94677 mutex_lock(&syscall_trace_lock);
94678 sys_perf_refcount_enter--;
94679 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94680 int num;
94681
94682 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94683 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94684 + return -EINVAL;
94685
94686 mutex_lock(&syscall_trace_lock);
94687 if (!sys_perf_refcount_exit)
94688 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94689 int num;
94690
94691 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94692 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94693 + return;
94694
94695 mutex_lock(&syscall_trace_lock);
94696 sys_perf_refcount_exit--;
94697 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94698 index a2e37c5..4fa859b 100644
94699 --- a/kernel/user_namespace.c
94700 +++ b/kernel/user_namespace.c
94701 @@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
94702 !kgid_has_mapping(parent_ns, group))
94703 return -EPERM;
94704
94705 +#ifdef CONFIG_GRKERNSEC
94706 + /*
94707 + * This doesn't really inspire confidence:
94708 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94709 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94710 + * Increases kernel attack surface in areas developers
94711 + * previously cared little about ("low importance due
94712 + * to requiring "root" capability")
94713 + * To be removed when this code receives *proper* review
94714 + */
94715 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94716 + !capable(CAP_SETGID))
94717 + return -EPERM;
94718 +#endif
94719 +
94720 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94721 if (!ns)
94722 return -ENOMEM;
94723 @@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94724 if (atomic_read(&current->mm->mm_users) > 1)
94725 return -EINVAL;
94726
94727 - if (current->fs->users != 1)
94728 + if (atomic_read(&current->fs->users) != 1)
94729 return -EINVAL;
94730
94731 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94732 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94733 index c8eac43..4b5f08f 100644
94734 --- a/kernel/utsname_sysctl.c
94735 +++ b/kernel/utsname_sysctl.c
94736 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94737 static int proc_do_uts_string(struct ctl_table *table, int write,
94738 void __user *buffer, size_t *lenp, loff_t *ppos)
94739 {
94740 - struct ctl_table uts_table;
94741 + ctl_table_no_const uts_table;
94742 int r;
94743 memcpy(&uts_table, table, sizeof(uts_table));
94744 uts_table.data = get_uts(table, write);
94745 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94746 index 70bf118..4be3c37 100644
94747 --- a/kernel/watchdog.c
94748 +++ b/kernel/watchdog.c
94749 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94750 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94751 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94752
94753 -static struct smp_hotplug_thread watchdog_threads = {
94754 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94755 .store = &softlockup_watchdog,
94756 .thread_should_run = watchdog_should_run,
94757 .thread_fn = watchdog,
94758 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94759 index 66940a5..a44fed0 100644
94760 --- a/kernel/workqueue.c
94761 +++ b/kernel/workqueue.c
94762 @@ -4499,7 +4499,7 @@ static void rebind_workers(struct worker_pool *pool)
94763 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94764 worker_flags |= WORKER_REBOUND;
94765 worker_flags &= ~WORKER_UNBOUND;
94766 - ACCESS_ONCE(worker->flags) = worker_flags;
94767 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94768 }
94769
94770 spin_unlock_irq(&pool->lock);
94771 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94772 index 4e35a5d..8a1f3f0 100644
94773 --- a/lib/Kconfig.debug
94774 +++ b/lib/Kconfig.debug
94775 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94776
94777 config DEBUG_WW_MUTEX_SLOWPATH
94778 bool "Wait/wound mutex debugging: Slowpath testing"
94779 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94780 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94781 select DEBUG_LOCK_ALLOC
94782 select DEBUG_SPINLOCK
94783 select DEBUG_MUTEXES
94784 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94785
94786 config DEBUG_LOCK_ALLOC
94787 bool "Lock debugging: detect incorrect freeing of live locks"
94788 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94789 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94790 select DEBUG_SPINLOCK
94791 select DEBUG_MUTEXES
94792 select LOCKDEP
94793 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94794
94795 config PROVE_LOCKING
94796 bool "Lock debugging: prove locking correctness"
94797 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94798 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94799 select LOCKDEP
94800 select DEBUG_SPINLOCK
94801 select DEBUG_MUTEXES
94802 @@ -976,7 +976,7 @@ config LOCKDEP
94803
94804 config LOCK_STAT
94805 bool "Lock usage statistics"
94806 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94807 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94808 select LOCKDEP
94809 select DEBUG_SPINLOCK
94810 select DEBUG_MUTEXES
94811 @@ -1449,6 +1449,7 @@ config LATENCYTOP
94812 depends on DEBUG_KERNEL
94813 depends on STACKTRACE_SUPPORT
94814 depends on PROC_FS
94815 + depends on !GRKERNSEC_HIDESYM
94816 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94817 select KALLSYMS
94818 select KALLSYMS_ALL
94819 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94820 config DEBUG_STRICT_USER_COPY_CHECKS
94821 bool "Strict user copy size checks"
94822 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94823 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94824 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94825 help
94826 Enabling this option turns a certain set of sanity checks for user
94827 copy operations into compile time failures.
94828 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94829
94830 config PROVIDE_OHCI1394_DMA_INIT
94831 bool "Remote debugging over FireWire early on boot"
94832 - depends on PCI && X86
94833 + depends on PCI && X86 && !GRKERNSEC
94834 help
94835 If you want to debug problems which hang or crash the kernel early
94836 on boot and the crashing machine has a FireWire port, you can use
94837 diff --git a/lib/Makefile b/lib/Makefile
94838 index 0211d2b..93f5cc3 100644
94839 --- a/lib/Makefile
94840 +++ b/lib/Makefile
94841 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94842 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94843 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94844 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94845 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94846 +obj-y += list_debug.o
94847 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94848
94849 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94850 diff --git a/lib/average.c b/lib/average.c
94851 index 114d1be..ab0350c 100644
94852 --- a/lib/average.c
94853 +++ b/lib/average.c
94854 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94855 {
94856 unsigned long internal = ACCESS_ONCE(avg->internal);
94857
94858 - ACCESS_ONCE(avg->internal) = internal ?
94859 + ACCESS_ONCE_RW(avg->internal) = internal ?
94860 (((internal << avg->weight) - internal) +
94861 (val << avg->factor)) >> avg->weight :
94862 (val << avg->factor);
94863 diff --git a/lib/bitmap.c b/lib/bitmap.c
94864 index b499ab6..fbdb76c 100644
94865 --- a/lib/bitmap.c
94866 +++ b/lib/bitmap.c
94867 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94868 {
94869 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94870 u32 chunk;
94871 - const char __user __force *ubuf = (const char __user __force *)buf;
94872 + const char __user *ubuf = (const char __force_user *)buf;
94873
94874 bitmap_zero(maskp, nmaskbits);
94875
94876 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94877 {
94878 if (!access_ok(VERIFY_READ, ubuf, ulen))
94879 return -EFAULT;
94880 - return __bitmap_parse((const char __force *)ubuf,
94881 + return __bitmap_parse((const char __force_kernel *)ubuf,
94882 ulen, 1, maskp, nmaskbits);
94883
94884 }
94885 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94886 {
94887 unsigned a, b;
94888 int c, old_c, totaldigits;
94889 - const char __user __force *ubuf = (const char __user __force *)buf;
94890 + const char __user *ubuf = (const char __force_user *)buf;
94891 int exp_digit, in_range;
94892
94893 totaldigits = c = 0;
94894 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94895 {
94896 if (!access_ok(VERIFY_READ, ubuf, ulen))
94897 return -EFAULT;
94898 - return __bitmap_parselist((const char __force *)ubuf,
94899 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94900 ulen, 1, maskp, nmaskbits);
94901 }
94902 EXPORT_SYMBOL(bitmap_parselist_user);
94903 diff --git a/lib/bug.c b/lib/bug.c
94904 index d1d7c78..b354235 100644
94905 --- a/lib/bug.c
94906 +++ b/lib/bug.c
94907 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94908 return BUG_TRAP_TYPE_NONE;
94909
94910 bug = find_bug(bugaddr);
94911 + if (!bug)
94912 + return BUG_TRAP_TYPE_NONE;
94913
94914 file = NULL;
94915 line = 0;
94916 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94917 index 547f7f9..a6d4ba0 100644
94918 --- a/lib/debugobjects.c
94919 +++ b/lib/debugobjects.c
94920 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94921 if (limit > 4)
94922 return;
94923
94924 - is_on_stack = object_is_on_stack(addr);
94925 + is_on_stack = object_starts_on_stack(addr);
94926 if (is_on_stack == onstack)
94927 return;
94928
94929 diff --git a/lib/div64.c b/lib/div64.c
94930 index 4382ad7..08aa558 100644
94931 --- a/lib/div64.c
94932 +++ b/lib/div64.c
94933 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94934 EXPORT_SYMBOL(__div64_32);
94935
94936 #ifndef div_s64_rem
94937 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94938 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94939 {
94940 u64 quotient;
94941
94942 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94943 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94944 */
94945 #ifndef div64_u64
94946 -u64 div64_u64(u64 dividend, u64 divisor)
94947 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94948 {
94949 u32 high = divisor >> 32;
94950 u64 quot;
94951 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94952 index add80cc..0d27550 100644
94953 --- a/lib/dma-debug.c
94954 +++ b/lib/dma-debug.c
94955 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94956
94957 void dma_debug_add_bus(struct bus_type *bus)
94958 {
94959 - struct notifier_block *nb;
94960 + notifier_block_no_const *nb;
94961
94962 if (global_disable)
94963 return;
94964 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94965
94966 static void check_for_stack(struct device *dev, void *addr)
94967 {
94968 - if (object_is_on_stack(addr))
94969 + if (object_starts_on_stack(addr))
94970 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94971 "stack [addr=%p]\n", addr);
94972 }
94973 diff --git a/lib/hash.c b/lib/hash.c
94974 index fea973f..386626f 100644
94975 --- a/lib/hash.c
94976 +++ b/lib/hash.c
94977 @@ -14,7 +14,7 @@
94978 #include <linux/hash.h>
94979 #include <linux/cache.h>
94980
94981 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94982 +static struct fast_hash_ops arch_hash_ops __read_only = {
94983 .hash = jhash,
94984 .hash2 = jhash2,
94985 };
94986 diff --git a/lib/inflate.c b/lib/inflate.c
94987 index 013a761..c28f3fc 100644
94988 --- a/lib/inflate.c
94989 +++ b/lib/inflate.c
94990 @@ -269,7 +269,7 @@ static void free(void *where)
94991 malloc_ptr = free_mem_ptr;
94992 }
94993 #else
94994 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94995 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94996 #define free(a) kfree(a)
94997 #endif
94998
94999 diff --git a/lib/ioremap.c b/lib/ioremap.c
95000 index 0c9216c..863bd89 100644
95001 --- a/lib/ioremap.c
95002 +++ b/lib/ioremap.c
95003 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95004 unsigned long next;
95005
95006 phys_addr -= addr;
95007 - pmd = pmd_alloc(&init_mm, pud, addr);
95008 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95009 if (!pmd)
95010 return -ENOMEM;
95011 do {
95012 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95013 unsigned long next;
95014
95015 phys_addr -= addr;
95016 - pud = pud_alloc(&init_mm, pgd, addr);
95017 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95018 if (!pud)
95019 return -ENOMEM;
95020 do {
95021 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95022 index bd2bea9..6b3c95e 100644
95023 --- a/lib/is_single_threaded.c
95024 +++ b/lib/is_single_threaded.c
95025 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95026 struct task_struct *p, *t;
95027 bool ret;
95028
95029 + if (!mm)
95030 + return true;
95031 +
95032 if (atomic_read(&task->signal->live) != 1)
95033 return false;
95034
95035 diff --git a/lib/kobject.c b/lib/kobject.c
95036 index 58751bb..93a1853 100644
95037 --- a/lib/kobject.c
95038 +++ b/lib/kobject.c
95039 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95040
95041
95042 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95043 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95044 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95045
95046 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95047 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95048 {
95049 enum kobj_ns_type type = ops->type;
95050 int error;
95051 diff --git a/lib/list_debug.c b/lib/list_debug.c
95052 index c24c2f7..f0296f4 100644
95053 --- a/lib/list_debug.c
95054 +++ b/lib/list_debug.c
95055 @@ -11,7 +11,9 @@
95056 #include <linux/bug.h>
95057 #include <linux/kernel.h>
95058 #include <linux/rculist.h>
95059 +#include <linux/mm.h>
95060
95061 +#ifdef CONFIG_DEBUG_LIST
95062 /*
95063 * Insert a new entry between two known consecutive entries.
95064 *
95065 @@ -19,21 +21,40 @@
95066 * the prev/next entries already!
95067 */
95068
95069 +static bool __list_add_debug(struct list_head *new,
95070 + struct list_head *prev,
95071 + struct list_head *next)
95072 +{
95073 + if (unlikely(next->prev != prev)) {
95074 + printk(KERN_ERR "list_add corruption. next->prev should be "
95075 + "prev (%p), but was %p. (next=%p).\n",
95076 + prev, next->prev, next);
95077 + BUG();
95078 + return false;
95079 + }
95080 + if (unlikely(prev->next != next)) {
95081 + printk(KERN_ERR "list_add corruption. prev->next should be "
95082 + "next (%p), but was %p. (prev=%p).\n",
95083 + next, prev->next, prev);
95084 + BUG();
95085 + return false;
95086 + }
95087 + if (unlikely(new == prev || new == next)) {
95088 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95089 + new, prev, next);
95090 + BUG();
95091 + return false;
95092 + }
95093 + return true;
95094 +}
95095 +
95096 void __list_add(struct list_head *new,
95097 - struct list_head *prev,
95098 - struct list_head *next)
95099 + struct list_head *prev,
95100 + struct list_head *next)
95101 {
95102 - WARN(next->prev != prev,
95103 - "list_add corruption. next->prev should be "
95104 - "prev (%p), but was %p. (next=%p).\n",
95105 - prev, next->prev, next);
95106 - WARN(prev->next != next,
95107 - "list_add corruption. prev->next should be "
95108 - "next (%p), but was %p. (prev=%p).\n",
95109 - next, prev->next, prev);
95110 - WARN(new == prev || new == next,
95111 - "list_add double add: new=%p, prev=%p, next=%p.\n",
95112 - new, prev, next);
95113 + if (!__list_add_debug(new, prev, next))
95114 + return;
95115 +
95116 next->prev = new;
95117 new->next = next;
95118 new->prev = prev;
95119 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95120 }
95121 EXPORT_SYMBOL(__list_add);
95122
95123 -void __list_del_entry(struct list_head *entry)
95124 +static bool __list_del_entry_debug(struct list_head *entry)
95125 {
95126 struct list_head *prev, *next;
95127
95128 prev = entry->prev;
95129 next = entry->next;
95130
95131 - if (WARN(next == LIST_POISON1,
95132 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95133 - entry, LIST_POISON1) ||
95134 - WARN(prev == LIST_POISON2,
95135 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95136 - entry, LIST_POISON2) ||
95137 - WARN(prev->next != entry,
95138 - "list_del corruption. prev->next should be %p, "
95139 - "but was %p\n", entry, prev->next) ||
95140 - WARN(next->prev != entry,
95141 - "list_del corruption. next->prev should be %p, "
95142 - "but was %p\n", entry, next->prev))
95143 + if (unlikely(next == LIST_POISON1)) {
95144 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95145 + entry, LIST_POISON1);
95146 + BUG();
95147 + return false;
95148 + }
95149 + if (unlikely(prev == LIST_POISON2)) {
95150 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95151 + entry, LIST_POISON2);
95152 + BUG();
95153 + return false;
95154 + }
95155 + if (unlikely(entry->prev->next != entry)) {
95156 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95157 + "but was %p\n", entry, prev->next);
95158 + BUG();
95159 + return false;
95160 + }
95161 + if (unlikely(entry->next->prev != entry)) {
95162 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95163 + "but was %p\n", entry, next->prev);
95164 + BUG();
95165 + return false;
95166 + }
95167 + return true;
95168 +}
95169 +
95170 +void __list_del_entry(struct list_head *entry)
95171 +{
95172 + if (!__list_del_entry_debug(entry))
95173 return;
95174
95175 - __list_del(prev, next);
95176 + __list_del(entry->prev, entry->next);
95177 }
95178 EXPORT_SYMBOL(__list_del_entry);
95179
95180 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95181 void __list_add_rcu(struct list_head *new,
95182 struct list_head *prev, struct list_head *next)
95183 {
95184 - WARN(next->prev != prev,
95185 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95186 - prev, next->prev, next);
95187 - WARN(prev->next != next,
95188 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95189 - next, prev->next, prev);
95190 + if (!__list_add_debug(new, prev, next))
95191 + return;
95192 +
95193 new->next = next;
95194 new->prev = prev;
95195 rcu_assign_pointer(list_next_rcu(prev), new);
95196 next->prev = new;
95197 }
95198 EXPORT_SYMBOL(__list_add_rcu);
95199 +#endif
95200 +
95201 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95202 +{
95203 +#ifdef CONFIG_DEBUG_LIST
95204 + if (!__list_add_debug(new, prev, next))
95205 + return;
95206 +#endif
95207 +
95208 + pax_open_kernel();
95209 + next->prev = new;
95210 + new->next = next;
95211 + new->prev = prev;
95212 + prev->next = new;
95213 + pax_close_kernel();
95214 +}
95215 +EXPORT_SYMBOL(__pax_list_add);
95216 +
95217 +void pax_list_del(struct list_head *entry)
95218 +{
95219 +#ifdef CONFIG_DEBUG_LIST
95220 + if (!__list_del_entry_debug(entry))
95221 + return;
95222 +#endif
95223 +
95224 + pax_open_kernel();
95225 + __list_del(entry->prev, entry->next);
95226 + entry->next = LIST_POISON1;
95227 + entry->prev = LIST_POISON2;
95228 + pax_close_kernel();
95229 +}
95230 +EXPORT_SYMBOL(pax_list_del);
95231 +
95232 +void pax_list_del_init(struct list_head *entry)
95233 +{
95234 + pax_open_kernel();
95235 + __list_del(entry->prev, entry->next);
95236 + INIT_LIST_HEAD(entry);
95237 + pax_close_kernel();
95238 +}
95239 +EXPORT_SYMBOL(pax_list_del_init);
95240 +
95241 +void __pax_list_add_rcu(struct list_head *new,
95242 + struct list_head *prev, struct list_head *next)
95243 +{
95244 +#ifdef CONFIG_DEBUG_LIST
95245 + if (!__list_add_debug(new, prev, next))
95246 + return;
95247 +#endif
95248 +
95249 + pax_open_kernel();
95250 + new->next = next;
95251 + new->prev = prev;
95252 + rcu_assign_pointer(list_next_rcu(prev), new);
95253 + next->prev = new;
95254 + pax_close_kernel();
95255 +}
95256 +EXPORT_SYMBOL(__pax_list_add_rcu);
95257 +
95258 +void pax_list_del_rcu(struct list_head *entry)
95259 +{
95260 +#ifdef CONFIG_DEBUG_LIST
95261 + if (!__list_del_entry_debug(entry))
95262 + return;
95263 +#endif
95264 +
95265 + pax_open_kernel();
95266 + __list_del(entry->prev, entry->next);
95267 + entry->next = LIST_POISON1;
95268 + entry->prev = LIST_POISON2;
95269 + pax_close_kernel();
95270 +}
95271 +EXPORT_SYMBOL(pax_list_del_rcu);
95272 diff --git a/lib/lockref.c b/lib/lockref.c
95273 index d2233de..fa1a2f6 100644
95274 --- a/lib/lockref.c
95275 +++ b/lib/lockref.c
95276 @@ -48,13 +48,13 @@
95277 void lockref_get(struct lockref *lockref)
95278 {
95279 CMPXCHG_LOOP(
95280 - new.count++;
95281 + __lockref_inc(&new);
95282 ,
95283 return;
95284 );
95285
95286 spin_lock(&lockref->lock);
95287 - lockref->count++;
95288 + __lockref_inc(lockref);
95289 spin_unlock(&lockref->lock);
95290 }
95291 EXPORT_SYMBOL(lockref_get);
95292 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95293 int retval;
95294
95295 CMPXCHG_LOOP(
95296 - new.count++;
95297 + __lockref_inc(&new);
95298 if (!old.count)
95299 return 0;
95300 ,
95301 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95302 spin_lock(&lockref->lock);
95303 retval = 0;
95304 if (lockref->count) {
95305 - lockref->count++;
95306 + __lockref_inc(lockref);
95307 retval = 1;
95308 }
95309 spin_unlock(&lockref->lock);
95310 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95311 int lockref_get_or_lock(struct lockref *lockref)
95312 {
95313 CMPXCHG_LOOP(
95314 - new.count++;
95315 + __lockref_inc(&new);
95316 if (!old.count)
95317 break;
95318 ,
95319 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95320 spin_lock(&lockref->lock);
95321 if (!lockref->count)
95322 return 0;
95323 - lockref->count++;
95324 + __lockref_inc(lockref);
95325 spin_unlock(&lockref->lock);
95326 return 1;
95327 }
95328 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95329 int lockref_put_or_lock(struct lockref *lockref)
95330 {
95331 CMPXCHG_LOOP(
95332 - new.count--;
95333 + __lockref_dec(&new);
95334 if (old.count <= 1)
95335 break;
95336 ,
95337 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95338 spin_lock(&lockref->lock);
95339 if (lockref->count <= 1)
95340 return 0;
95341 - lockref->count--;
95342 + __lockref_dec(lockref);
95343 spin_unlock(&lockref->lock);
95344 return 1;
95345 }
95346 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95347 int retval;
95348
95349 CMPXCHG_LOOP(
95350 - new.count++;
95351 + __lockref_inc(&new);
95352 if ((int)old.count < 0)
95353 return 0;
95354 ,
95355 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95356 spin_lock(&lockref->lock);
95357 retval = 0;
95358 if ((int) lockref->count >= 0) {
95359 - lockref->count++;
95360 + __lockref_inc(lockref);
95361 retval = 1;
95362 }
95363 spin_unlock(&lockref->lock);
95364 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95365 index 6111bcb..02e816b 100644
95366 --- a/lib/percpu-refcount.c
95367 +++ b/lib/percpu-refcount.c
95368 @@ -31,7 +31,7 @@
95369 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
95370 */
95371
95372 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
95373 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
95374
95375 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
95376
95377 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95378 index 3291a8e..346a91e 100644
95379 --- a/lib/radix-tree.c
95380 +++ b/lib/radix-tree.c
95381 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95382 int nr;
95383 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95384 };
95385 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95386 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95387
95388 static inline void *ptr_to_indirect(void *ptr)
95389 {
95390 diff --git a/lib/random32.c b/lib/random32.c
95391 index 0bee183..526f12f 100644
95392 --- a/lib/random32.c
95393 +++ b/lib/random32.c
95394 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
95395 }
95396 #endif
95397
95398 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95399 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95400
95401 /**
95402 * prandom_u32_state - seeded pseudo-random number generator.
95403 diff --git a/lib/rbtree.c b/lib/rbtree.c
95404 index c16c81a..4dcbda1 100644
95405 --- a/lib/rbtree.c
95406 +++ b/lib/rbtree.c
95407 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95408 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95409
95410 static const struct rb_augment_callbacks dummy_callbacks = {
95411 - dummy_propagate, dummy_copy, dummy_rotate
95412 + .propagate = dummy_propagate,
95413 + .copy = dummy_copy,
95414 + .rotate = dummy_rotate
95415 };
95416
95417 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95418 diff --git a/lib/show_mem.c b/lib/show_mem.c
95419 index 5e25627..3ed9d7f 100644
95420 --- a/lib/show_mem.c
95421 +++ b/lib/show_mem.c
95422 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95423 quicklist_total_size());
95424 #endif
95425 #ifdef CONFIG_MEMORY_FAILURE
95426 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95427 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95428 #endif
95429 }
95430 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95431 index bb2b201..46abaf9 100644
95432 --- a/lib/strncpy_from_user.c
95433 +++ b/lib/strncpy_from_user.c
95434 @@ -21,7 +21,7 @@
95435 */
95436 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95437 {
95438 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95439 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95440 long res = 0;
95441
95442 /*
95443 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95444 index a28df52..3d55877 100644
95445 --- a/lib/strnlen_user.c
95446 +++ b/lib/strnlen_user.c
95447 @@ -26,7 +26,7 @@
95448 */
95449 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95450 {
95451 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95452 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95453 long align, res = 0;
95454 unsigned long c;
95455
95456 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95457 index 4abda07..b9d3765 100644
95458 --- a/lib/swiotlb.c
95459 +++ b/lib/swiotlb.c
95460 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95461
95462 void
95463 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95464 - dma_addr_t dev_addr)
95465 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95466 {
95467 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95468
95469 diff --git a/lib/usercopy.c b/lib/usercopy.c
95470 index 4f5b1dd..7cab418 100644
95471 --- a/lib/usercopy.c
95472 +++ b/lib/usercopy.c
95473 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95474 WARN(1, "Buffer overflow detected!\n");
95475 }
95476 EXPORT_SYMBOL(copy_from_user_overflow);
95477 +
95478 +void copy_to_user_overflow(void)
95479 +{
95480 + WARN(1, "Buffer overflow detected!\n");
95481 +}
95482 +EXPORT_SYMBOL(copy_to_user_overflow);
95483 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95484 index ec337f6..8484eb2 100644
95485 --- a/lib/vsprintf.c
95486 +++ b/lib/vsprintf.c
95487 @@ -16,6 +16,9 @@
95488 * - scnprintf and vscnprintf
95489 */
95490
95491 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95492 +#define __INCLUDED_BY_HIDESYM 1
95493 +#endif
95494 #include <stdarg.h>
95495 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95496 #include <linux/types.h>
95497 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95498 #ifdef CONFIG_KALLSYMS
95499 if (*fmt == 'B')
95500 sprint_backtrace(sym, value);
95501 - else if (*fmt != 'f' && *fmt != 's')
95502 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95503 sprint_symbol(sym, value);
95504 else
95505 sprint_symbol_no_offset(sym, value);
95506 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95507 return number(buf, end, num, spec);
95508 }
95509
95510 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95511 +int kptr_restrict __read_mostly = 2;
95512 +#else
95513 int kptr_restrict __read_mostly;
95514 +#endif
95515
95516 /*
95517 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95518 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95519 *
95520 * - 'F' For symbolic function descriptor pointers with offset
95521 * - 'f' For simple symbolic function names without offset
95522 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95523 * - 'S' For symbolic direct pointers with offset
95524 * - 's' For symbolic direct pointers without offset
95525 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95526 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95527 * - 'B' For backtraced symbolic direct pointers with offset
95528 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95529 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95530
95531 if (!ptr && *fmt != 'K') {
95532 /*
95533 - * Print (null) with the same width as a pointer so it makes
95534 + * Print (nil) with the same width as a pointer so it makes
95535 * tabular output look nice.
95536 */
95537 if (spec.field_width == -1)
95538 spec.field_width = default_width;
95539 - return string(buf, end, "(null)", spec);
95540 + return string(buf, end, "(nil)", spec);
95541 }
95542
95543 switch (*fmt) {
95544 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95545 /* Fallthrough */
95546 case 'S':
95547 case 's':
95548 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95549 + break;
95550 +#else
95551 + return symbol_string(buf, end, ptr, spec, fmt);
95552 +#endif
95553 + case 'X':
95554 + ptr = dereference_function_descriptor(ptr);
95555 + case 'A':
95556 case 'B':
95557 return symbol_string(buf, end, ptr, spec, fmt);
95558 case 'R':
95559 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95560 va_end(va);
95561 return buf;
95562 }
95563 + case 'P':
95564 + break;
95565 case 'K':
95566 /*
95567 * %pK cannot be used in IRQ context because its test
95568 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95569 ((const struct file *)ptr)->f_path.dentry,
95570 spec, fmt);
95571 }
95572 +
95573 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95574 + /* 'P' = approved pointers to copy to userland,
95575 + as in the /proc/kallsyms case, as we make it display nothing
95576 + for non-root users, and the real contents for root users
95577 + 'X' = approved simple symbols
95578 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95579 + above
95580 + */
95581 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95582 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95583 + dump_stack();
95584 + ptr = NULL;
95585 + }
95586 +#endif
95587 +
95588 spec.flags |= SMALL;
95589 if (spec.field_width == -1) {
95590 spec.field_width = default_width;
95591 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95592 typeof(type) value; \
95593 if (sizeof(type) == 8) { \
95594 args = PTR_ALIGN(args, sizeof(u32)); \
95595 - *(u32 *)&value = *(u32 *)args; \
95596 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95597 + *(u32 *)&value = *(const u32 *)args; \
95598 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95599 } else { \
95600 args = PTR_ALIGN(args, sizeof(type)); \
95601 - value = *(typeof(type) *)args; \
95602 + value = *(const typeof(type) *)args; \
95603 } \
95604 args += sizeof(type); \
95605 value; \
95606 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95607 case FORMAT_TYPE_STR: {
95608 const char *str_arg = args;
95609 args += strlen(str_arg) + 1;
95610 - str = string(str, end, (char *)str_arg, spec);
95611 + str = string(str, end, str_arg, spec);
95612 break;
95613 }
95614
95615 diff --git a/localversion-grsec b/localversion-grsec
95616 new file mode 100644
95617 index 0000000..7cd6065
95618 --- /dev/null
95619 +++ b/localversion-grsec
95620 @@ -0,0 +1 @@
95621 +-grsec
95622 diff --git a/mm/Kconfig b/mm/Kconfig
95623 index 1d1ae6b..0f05885 100644
95624 --- a/mm/Kconfig
95625 +++ b/mm/Kconfig
95626 @@ -341,10 +341,11 @@ config KSM
95627 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95628
95629 config DEFAULT_MMAP_MIN_ADDR
95630 - int "Low address space to protect from user allocation"
95631 + int "Low address space to protect from user allocation"
95632 depends on MMU
95633 - default 4096
95634 - help
95635 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95636 + default 65536
95637 + help
95638 This is the portion of low virtual memory which should be protected
95639 from userspace allocation. Keeping a user from writing to low pages
95640 can help reduce the impact of kernel NULL pointer bugs.
95641 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
95642
95643 config HWPOISON_INJECT
95644 tristate "HWPoison pages injector"
95645 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95646 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95647 select PROC_PAGE_MONITOR
95648
95649 config NOMMU_INITIAL_TRIM_EXCESS
95650 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95651 index 0ae0df5..82ac56b 100644
95652 --- a/mm/backing-dev.c
95653 +++ b/mm/backing-dev.c
95654 @@ -12,7 +12,7 @@
95655 #include <linux/device.h>
95656 #include <trace/events/writeback.h>
95657
95658 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95659 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95660
95661 struct backing_dev_info default_backing_dev_info = {
95662 .name = "default",
95663 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95664 return err;
95665
95666 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95667 - atomic_long_inc_return(&bdi_seq));
95668 + atomic_long_inc_return_unchecked(&bdi_seq));
95669 if (err) {
95670 bdi_destroy(bdi);
95671 return err;
95672 diff --git a/mm/filemap.c b/mm/filemap.c
95673 index 37beab9..2c55a85 100644
95674 --- a/mm/filemap.c
95675 +++ b/mm/filemap.c
95676 @@ -2097,7 +2097,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95677 struct address_space *mapping = file->f_mapping;
95678
95679 if (!mapping->a_ops->readpage)
95680 - return -ENOEXEC;
95681 + return -ENODEV;
95682 file_accessed(file);
95683 vma->vm_ops = &generic_file_vm_ops;
95684 return 0;
95685 @@ -2275,6 +2275,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95686 *pos = i_size_read(inode);
95687
95688 if (limit != RLIM_INFINITY) {
95689 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95690 if (*pos >= limit) {
95691 send_sig(SIGXFSZ, current, 0);
95692 return -EFBIG;
95693 diff --git a/mm/fremap.c b/mm/fremap.c
95694 index 72b8fa3..c5b39f1 100644
95695 --- a/mm/fremap.c
95696 +++ b/mm/fremap.c
95697 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95698 retry:
95699 vma = find_vma(mm, start);
95700
95701 +#ifdef CONFIG_PAX_SEGMEXEC
95702 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95703 + goto out;
95704 +#endif
95705 +
95706 /*
95707 * Make sure the vma is shared, that it supports prefaulting,
95708 * and that the remapped range is valid and fully within
95709 diff --git a/mm/gup.c b/mm/gup.c
95710 index a0d57ec..79d469ce 100644
95711 --- a/mm/gup.c
95712 +++ b/mm/gup.c
95713 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95714 unsigned int fault_flags = 0;
95715 int ret;
95716
95717 - /* For mlock, just skip the stack guard page. */
95718 - if ((*flags & FOLL_MLOCK) &&
95719 - (stack_guard_page_start(vma, address) ||
95720 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95721 - return -ENOENT;
95722 if (*flags & FOLL_WRITE)
95723 fault_flags |= FAULT_FLAG_WRITE;
95724 if (nonblocking)
95725 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95726 if (!(gup_flags & FOLL_FORCE))
95727 gup_flags |= FOLL_NUMA;
95728
95729 - do {
95730 + while (nr_pages) {
95731 struct page *page;
95732 unsigned int foll_flags = gup_flags;
95733 unsigned int page_increm;
95734
95735 /* first iteration or cross vma bound */
95736 if (!vma || start >= vma->vm_end) {
95737 - vma = find_extend_vma(mm, start);
95738 + vma = find_vma(mm, start);
95739 if (!vma && in_gate_area(mm, start)) {
95740 int ret;
95741 ret = get_gate_page(mm, start & PAGE_MASK,
95742 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95743 goto next_page;
95744 }
95745
95746 - if (!vma || check_vma_flags(vma, gup_flags))
95747 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95748 return i ? : -EFAULT;
95749 if (is_vm_hugetlb_page(vma)) {
95750 i = follow_hugetlb_page(mm, vma, pages, vmas,
95751 @@ -518,7 +513,7 @@ next_page:
95752 i += page_increm;
95753 start += page_increm * PAGE_SIZE;
95754 nr_pages -= page_increm;
95755 - } while (nr_pages);
95756 + }
95757 return i;
95758 }
95759 EXPORT_SYMBOL(__get_user_pages);
95760 diff --git a/mm/highmem.c b/mm/highmem.c
95761 index 123bcd3..0de52ba 100644
95762 --- a/mm/highmem.c
95763 +++ b/mm/highmem.c
95764 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95765 * So no dangers, even with speculative execution.
95766 */
95767 page = pte_page(pkmap_page_table[i]);
95768 + pax_open_kernel();
95769 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95770 -
95771 + pax_close_kernel();
95772 set_page_address(page, NULL);
95773 need_flush = 1;
95774 }
95775 @@ -259,9 +260,11 @@ start:
95776 }
95777 }
95778 vaddr = PKMAP_ADDR(last_pkmap_nr);
95779 +
95780 + pax_open_kernel();
95781 set_pte_at(&init_mm, vaddr,
95782 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95783 -
95784 + pax_close_kernel();
95785 pkmap_count[last_pkmap_nr] = 1;
95786 set_page_address(page, (void *)vaddr);
95787
95788 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95789 index 9fd7227..5628939 100644
95790 --- a/mm/hugetlb.c
95791 +++ b/mm/hugetlb.c
95792 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95793 struct ctl_table *table, int write,
95794 void __user *buffer, size_t *length, loff_t *ppos)
95795 {
95796 + ctl_table_no_const t;
95797 struct hstate *h = &default_hstate;
95798 unsigned long tmp = h->max_huge_pages;
95799 int ret;
95800 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95801 if (!hugepages_supported())
95802 return -ENOTSUPP;
95803
95804 - table->data = &tmp;
95805 - table->maxlen = sizeof(unsigned long);
95806 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95807 + t = *table;
95808 + t.data = &tmp;
95809 + t.maxlen = sizeof(unsigned long);
95810 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95811 if (ret)
95812 goto out;
95813
95814 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95815 struct hstate *h = &default_hstate;
95816 unsigned long tmp;
95817 int ret;
95818 + ctl_table_no_const hugetlb_table;
95819
95820 if (!hugepages_supported())
95821 return -ENOTSUPP;
95822 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95823 if (write && hstate_is_gigantic(h))
95824 return -EINVAL;
95825
95826 - table->data = &tmp;
95827 - table->maxlen = sizeof(unsigned long);
95828 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95829 + hugetlb_table = *table;
95830 + hugetlb_table.data = &tmp;
95831 + hugetlb_table.maxlen = sizeof(unsigned long);
95832 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95833 if (ret)
95834 goto out;
95835
95836 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95837 mutex_unlock(&mapping->i_mmap_mutex);
95838 }
95839
95840 +#ifdef CONFIG_PAX_SEGMEXEC
95841 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95842 +{
95843 + struct mm_struct *mm = vma->vm_mm;
95844 + struct vm_area_struct *vma_m;
95845 + unsigned long address_m;
95846 + pte_t *ptep_m;
95847 +
95848 + vma_m = pax_find_mirror_vma(vma);
95849 + if (!vma_m)
95850 + return;
95851 +
95852 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95853 + address_m = address + SEGMEXEC_TASK_SIZE;
95854 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95855 + get_page(page_m);
95856 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95857 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95858 +}
95859 +#endif
95860 +
95861 /*
95862 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95863 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95864 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95865 make_huge_pte(vma, new_page, 1));
95866 page_remove_rmap(old_page);
95867 hugepage_add_new_anon_rmap(new_page, vma, address);
95868 +
95869 +#ifdef CONFIG_PAX_SEGMEXEC
95870 + pax_mirror_huge_pte(vma, address, new_page);
95871 +#endif
95872 +
95873 /* Make the old page be freed below */
95874 new_page = old_page;
95875 }
95876 @@ -3063,6 +3093,10 @@ retry:
95877 && (vma->vm_flags & VM_SHARED)));
95878 set_huge_pte_at(mm, address, ptep, new_pte);
95879
95880 +#ifdef CONFIG_PAX_SEGMEXEC
95881 + pax_mirror_huge_pte(vma, address, page);
95882 +#endif
95883 +
95884 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95885 /* Optimization, do the COW without a second fault */
95886 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95887 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95888 struct hstate *h = hstate_vma(vma);
95889 struct address_space *mapping;
95890
95891 +#ifdef CONFIG_PAX_SEGMEXEC
95892 + struct vm_area_struct *vma_m;
95893 +#endif
95894 +
95895 address &= huge_page_mask(h);
95896
95897 ptep = huge_pte_offset(mm, address);
95898 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95899 VM_FAULT_SET_HINDEX(hstate_index(h));
95900 }
95901
95902 +#ifdef CONFIG_PAX_SEGMEXEC
95903 + vma_m = pax_find_mirror_vma(vma);
95904 + if (vma_m) {
95905 + unsigned long address_m;
95906 +
95907 + if (vma->vm_start > vma_m->vm_start) {
95908 + address_m = address;
95909 + address -= SEGMEXEC_TASK_SIZE;
95910 + vma = vma_m;
95911 + h = hstate_vma(vma);
95912 + } else
95913 + address_m = address + SEGMEXEC_TASK_SIZE;
95914 +
95915 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95916 + return VM_FAULT_OOM;
95917 + address_m &= HPAGE_MASK;
95918 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95919 + }
95920 +#endif
95921 +
95922 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95923 if (!ptep)
95924 return VM_FAULT_OOM;
95925 diff --git a/mm/internal.h b/mm/internal.h
95926 index a4f90ba..fbdc32b 100644
95927 --- a/mm/internal.h
95928 +++ b/mm/internal.h
95929 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95930
95931 extern int __isolate_free_page(struct page *page, unsigned int order);
95932 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95933 +extern void free_compound_page(struct page *page);
95934 extern void prep_compound_page(struct page *page, unsigned long order);
95935 #ifdef CONFIG_MEMORY_FAILURE
95936 extern bool is_free_buddy_page(struct page *page);
95937 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95938
95939 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95940 unsigned long, unsigned long,
95941 - unsigned long, unsigned long);
95942 + unsigned long, unsigned long) __intentional_overflow(-1);
95943
95944 extern void set_pageblock_order(void);
95945 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95946 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95947 index e34a3cb..a810efe 100644
95948 --- a/mm/iov_iter.c
95949 +++ b/mm/iov_iter.c
95950 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95951
95952 while (bytes) {
95953 char __user *buf = iov->iov_base + base;
95954 - int copy = min(bytes, iov->iov_len - base);
95955 + size_t copy = min(bytes, iov->iov_len - base);
95956
95957 base = 0;
95958 left = __copy_from_user_inatomic(vaddr, buf, copy);
95959 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95960
95961 kaddr = kmap_atomic(page);
95962 if (likely(i->nr_segs == 1)) {
95963 - int left;
95964 + size_t left;
95965 char __user *buf = i->iov->iov_base + i->iov_offset;
95966 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95967 copied = bytes - left;
95968 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95969 * zero-length segments (without overruning the iovec).
95970 */
95971 while (bytes || unlikely(i->count && !iov->iov_len)) {
95972 - int copy;
95973 + size_t copy;
95974
95975 copy = min(bytes, iov->iov_len - base);
95976 BUG_ON(!i->count || i->count < copy);
95977 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95978 index 3cda50c..032ba634 100644
95979 --- a/mm/kmemleak.c
95980 +++ b/mm/kmemleak.c
95981 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95982
95983 for (i = 0; i < object->trace_len; i++) {
95984 void *ptr = (void *)object->trace[i];
95985 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95986 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95987 }
95988 }
95989
95990 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95991 return -ENOMEM;
95992 }
95993
95994 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95995 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95996 &kmemleak_fops);
95997 if (!dentry)
95998 pr_warning("Failed to create the debugfs kmemleak file\n");
95999 diff --git a/mm/maccess.c b/mm/maccess.c
96000 index d53adf9..03a24bf 100644
96001 --- a/mm/maccess.c
96002 +++ b/mm/maccess.c
96003 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96004 set_fs(KERNEL_DS);
96005 pagefault_disable();
96006 ret = __copy_from_user_inatomic(dst,
96007 - (__force const void __user *)src, size);
96008 + (const void __force_user *)src, size);
96009 pagefault_enable();
96010 set_fs(old_fs);
96011
96012 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96013
96014 set_fs(KERNEL_DS);
96015 pagefault_disable();
96016 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96017 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96018 pagefault_enable();
96019 set_fs(old_fs);
96020
96021 diff --git a/mm/madvise.c b/mm/madvise.c
96022 index 0938b30..199abe8 100644
96023 --- a/mm/madvise.c
96024 +++ b/mm/madvise.c
96025 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96026 pgoff_t pgoff;
96027 unsigned long new_flags = vma->vm_flags;
96028
96029 +#ifdef CONFIG_PAX_SEGMEXEC
96030 + struct vm_area_struct *vma_m;
96031 +#endif
96032 +
96033 switch (behavior) {
96034 case MADV_NORMAL:
96035 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96036 @@ -126,6 +130,13 @@ success:
96037 /*
96038 * vm_flags is protected by the mmap_sem held in write mode.
96039 */
96040 +
96041 +#ifdef CONFIG_PAX_SEGMEXEC
96042 + vma_m = pax_find_mirror_vma(vma);
96043 + if (vma_m)
96044 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96045 +#endif
96046 +
96047 vma->vm_flags = new_flags;
96048
96049 out:
96050 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96051 struct vm_area_struct **prev,
96052 unsigned long start, unsigned long end)
96053 {
96054 +
96055 +#ifdef CONFIG_PAX_SEGMEXEC
96056 + struct vm_area_struct *vma_m;
96057 +#endif
96058 +
96059 *prev = vma;
96060 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96061 return -EINVAL;
96062 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96063 zap_page_range(vma, start, end - start, &details);
96064 } else
96065 zap_page_range(vma, start, end - start, NULL);
96066 +
96067 +#ifdef CONFIG_PAX_SEGMEXEC
96068 + vma_m = pax_find_mirror_vma(vma);
96069 + if (vma_m) {
96070 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96071 + struct zap_details details = {
96072 + .nonlinear_vma = vma_m,
96073 + .last_index = ULONG_MAX,
96074 + };
96075 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96076 + } else
96077 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96078 + }
96079 +#endif
96080 +
96081 return 0;
96082 }
96083
96084 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96085 if (end < start)
96086 return error;
96087
96088 +#ifdef CONFIG_PAX_SEGMEXEC
96089 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96090 + if (end > SEGMEXEC_TASK_SIZE)
96091 + return error;
96092 + } else
96093 +#endif
96094 +
96095 + if (end > TASK_SIZE)
96096 + return error;
96097 +
96098 error = 0;
96099 if (end == start)
96100 return error;
96101 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96102 index 8639f6b..b623882a 100644
96103 --- a/mm/memory-failure.c
96104 +++ b/mm/memory-failure.c
96105 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96106
96107 int sysctl_memory_failure_recovery __read_mostly = 1;
96108
96109 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96110 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96111
96112 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96113
96114 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96115 pfn, t->comm, t->pid);
96116 si.si_signo = SIGBUS;
96117 si.si_errno = 0;
96118 - si.si_addr = (void *)addr;
96119 + si.si_addr = (void __user *)addr;
96120 #ifdef __ARCH_SI_TRAPNO
96121 si.si_trapno = trapno;
96122 #endif
96123 @@ -791,7 +791,7 @@ static struct page_state {
96124 unsigned long res;
96125 char *msg;
96126 int (*action)(struct page *p, unsigned long pfn);
96127 -} error_states[] = {
96128 +} __do_const error_states[] = {
96129 { reserved, reserved, "reserved kernel", me_kernel },
96130 /*
96131 * free pages are specially detected outside this table:
96132 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96133 nr_pages = 1 << compound_order(hpage);
96134 else /* normal page or thp */
96135 nr_pages = 1;
96136 - atomic_long_add(nr_pages, &num_poisoned_pages);
96137 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96138
96139 /*
96140 * We need/can do nothing about count=0 pages.
96141 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96142 if (PageHWPoison(hpage)) {
96143 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96144 || (p != hpage && TestSetPageHWPoison(hpage))) {
96145 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96146 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96147 unlock_page(hpage);
96148 return 0;
96149 }
96150 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96151 */
96152 if (!PageHWPoison(p)) {
96153 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96154 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96155 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96156 put_page(hpage);
96157 res = 0;
96158 goto out;
96159 }
96160 if (hwpoison_filter(p)) {
96161 if (TestClearPageHWPoison(p))
96162 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96163 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96164 unlock_page(hpage);
96165 put_page(hpage);
96166 return 0;
96167 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96168 return 0;
96169 }
96170 if (TestClearPageHWPoison(p))
96171 - atomic_long_dec(&num_poisoned_pages);
96172 + atomic_long_dec_unchecked(&num_poisoned_pages);
96173 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96174 return 0;
96175 }
96176 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96177 */
96178 if (TestClearPageHWPoison(page)) {
96179 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96180 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96181 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96182 freeit = 1;
96183 if (PageHuge(page))
96184 clear_page_hwpoison_huge_page(page);
96185 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96186 if (PageHuge(page)) {
96187 set_page_hwpoison_huge_page(hpage);
96188 dequeue_hwpoisoned_huge_page(hpage);
96189 - atomic_long_add(1 << compound_order(hpage),
96190 + atomic_long_add_unchecked(1 << compound_order(hpage),
96191 &num_poisoned_pages);
96192 } else {
96193 SetPageHWPoison(page);
96194 - atomic_long_inc(&num_poisoned_pages);
96195 + atomic_long_inc_unchecked(&num_poisoned_pages);
96196 }
96197 }
96198 return ret;
96199 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96200 put_page(page);
96201 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96202 SetPageHWPoison(page);
96203 - atomic_long_inc(&num_poisoned_pages);
96204 + atomic_long_inc_unchecked(&num_poisoned_pages);
96205 return 0;
96206 }
96207
96208 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96209 if (!is_free_buddy_page(page))
96210 pr_info("soft offline: %#lx: page leaked\n",
96211 pfn);
96212 - atomic_long_inc(&num_poisoned_pages);
96213 + atomic_long_inc_unchecked(&num_poisoned_pages);
96214 }
96215 } else {
96216 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96217 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96218 if (PageHuge(page)) {
96219 set_page_hwpoison_huge_page(hpage);
96220 dequeue_hwpoisoned_huge_page(hpage);
96221 - atomic_long_add(1 << compound_order(hpage),
96222 + atomic_long_add_unchecked(1 << compound_order(hpage),
96223 &num_poisoned_pages);
96224 } else {
96225 SetPageHWPoison(page);
96226 - atomic_long_inc(&num_poisoned_pages);
96227 + atomic_long_inc_unchecked(&num_poisoned_pages);
96228 }
96229 }
96230 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96231 diff --git a/mm/memory.c b/mm/memory.c
96232 index d442584..0600e22 100644
96233 --- a/mm/memory.c
96234 +++ b/mm/memory.c
96235 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96236 free_pte_range(tlb, pmd, addr);
96237 } while (pmd++, addr = next, addr != end);
96238
96239 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96240 start &= PUD_MASK;
96241 if (start < floor)
96242 return;
96243 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96244 pmd = pmd_offset(pud, start);
96245 pud_clear(pud);
96246 pmd_free_tlb(tlb, pmd, start);
96247 +#endif
96248 +
96249 }
96250
96251 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96252 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96253 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96254 } while (pud++, addr = next, addr != end);
96255
96256 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96257 start &= PGDIR_MASK;
96258 if (start < floor)
96259 return;
96260 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96261 pud = pud_offset(pgd, start);
96262 pgd_clear(pgd);
96263 pud_free_tlb(tlb, pud, start);
96264 +#endif
96265 +
96266 }
96267
96268 /*
96269 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96270 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96271 */
96272 if (vma->vm_ops)
96273 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96274 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96275 vma->vm_ops->fault);
96276 if (vma->vm_file)
96277 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96278 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96279 vma->vm_file->f_op->mmap);
96280 dump_stack();
96281 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96282 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96283 page_add_file_rmap(page);
96284 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96285
96286 +#ifdef CONFIG_PAX_SEGMEXEC
96287 + pax_mirror_file_pte(vma, addr, page, ptl);
96288 +#endif
96289 +
96290 retval = 0;
96291 pte_unmap_unlock(pte, ptl);
96292 return retval;
96293 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96294 if (!page_count(page))
96295 return -EINVAL;
96296 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96297 +
96298 +#ifdef CONFIG_PAX_SEGMEXEC
96299 + struct vm_area_struct *vma_m;
96300 +#endif
96301 +
96302 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96303 BUG_ON(vma->vm_flags & VM_PFNMAP);
96304 vma->vm_flags |= VM_MIXEDMAP;
96305 +
96306 +#ifdef CONFIG_PAX_SEGMEXEC
96307 + vma_m = pax_find_mirror_vma(vma);
96308 + if (vma_m)
96309 + vma_m->vm_flags |= VM_MIXEDMAP;
96310 +#endif
96311 +
96312 }
96313 return insert_page(vma, addr, page, vma->vm_page_prot);
96314 }
96315 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96316 unsigned long pfn)
96317 {
96318 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96319 + BUG_ON(vma->vm_mirror);
96320
96321 if (addr < vma->vm_start || addr >= vma->vm_end)
96322 return -EFAULT;
96323 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96324
96325 BUG_ON(pud_huge(*pud));
96326
96327 - pmd = pmd_alloc(mm, pud, addr);
96328 + pmd = (mm == &init_mm) ?
96329 + pmd_alloc_kernel(mm, pud, addr) :
96330 + pmd_alloc(mm, pud, addr);
96331 if (!pmd)
96332 return -ENOMEM;
96333 do {
96334 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96335 unsigned long next;
96336 int err;
96337
96338 - pud = pud_alloc(mm, pgd, addr);
96339 + pud = (mm == &init_mm) ?
96340 + pud_alloc_kernel(mm, pgd, addr) :
96341 + pud_alloc(mm, pgd, addr);
96342 if (!pud)
96343 return -ENOMEM;
96344 do {
96345 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96346 return ret;
96347 }
96348
96349 +#ifdef CONFIG_PAX_SEGMEXEC
96350 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96351 +{
96352 + struct mm_struct *mm = vma->vm_mm;
96353 + spinlock_t *ptl;
96354 + pte_t *pte, entry;
96355 +
96356 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96357 + entry = *pte;
96358 + if (!pte_present(entry)) {
96359 + if (!pte_none(entry)) {
96360 + BUG_ON(pte_file(entry));
96361 + free_swap_and_cache(pte_to_swp_entry(entry));
96362 + pte_clear_not_present_full(mm, address, pte, 0);
96363 + }
96364 + } else {
96365 + struct page *page;
96366 +
96367 + flush_cache_page(vma, address, pte_pfn(entry));
96368 + entry = ptep_clear_flush(vma, address, pte);
96369 + BUG_ON(pte_dirty(entry));
96370 + page = vm_normal_page(vma, address, entry);
96371 + if (page) {
96372 + update_hiwater_rss(mm);
96373 + if (PageAnon(page))
96374 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96375 + else
96376 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96377 + page_remove_rmap(page);
96378 + page_cache_release(page);
96379 + }
96380 + }
96381 + pte_unmap_unlock(pte, ptl);
96382 +}
96383 +
96384 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96385 + *
96386 + * the ptl of the lower mapped page is held on entry and is not released on exit
96387 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96388 + */
96389 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96390 +{
96391 + struct mm_struct *mm = vma->vm_mm;
96392 + unsigned long address_m;
96393 + spinlock_t *ptl_m;
96394 + struct vm_area_struct *vma_m;
96395 + pmd_t *pmd_m;
96396 + pte_t *pte_m, entry_m;
96397 +
96398 + BUG_ON(!page_m || !PageAnon(page_m));
96399 +
96400 + vma_m = pax_find_mirror_vma(vma);
96401 + if (!vma_m)
96402 + return;
96403 +
96404 + BUG_ON(!PageLocked(page_m));
96405 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96406 + address_m = address + SEGMEXEC_TASK_SIZE;
96407 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96408 + pte_m = pte_offset_map(pmd_m, address_m);
96409 + ptl_m = pte_lockptr(mm, pmd_m);
96410 + if (ptl != ptl_m) {
96411 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96412 + if (!pte_none(*pte_m))
96413 + goto out;
96414 + }
96415 +
96416 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96417 + page_cache_get(page_m);
96418 + page_add_anon_rmap(page_m, vma_m, address_m);
96419 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96420 + set_pte_at(mm, address_m, pte_m, entry_m);
96421 + update_mmu_cache(vma_m, address_m, pte_m);
96422 +out:
96423 + if (ptl != ptl_m)
96424 + spin_unlock(ptl_m);
96425 + pte_unmap(pte_m);
96426 + unlock_page(page_m);
96427 +}
96428 +
96429 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96430 +{
96431 + struct mm_struct *mm = vma->vm_mm;
96432 + unsigned long address_m;
96433 + spinlock_t *ptl_m;
96434 + struct vm_area_struct *vma_m;
96435 + pmd_t *pmd_m;
96436 + pte_t *pte_m, entry_m;
96437 +
96438 + BUG_ON(!page_m || PageAnon(page_m));
96439 +
96440 + vma_m = pax_find_mirror_vma(vma);
96441 + if (!vma_m)
96442 + return;
96443 +
96444 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96445 + address_m = address + SEGMEXEC_TASK_SIZE;
96446 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96447 + pte_m = pte_offset_map(pmd_m, address_m);
96448 + ptl_m = pte_lockptr(mm, pmd_m);
96449 + if (ptl != ptl_m) {
96450 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96451 + if (!pte_none(*pte_m))
96452 + goto out;
96453 + }
96454 +
96455 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96456 + page_cache_get(page_m);
96457 + page_add_file_rmap(page_m);
96458 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96459 + set_pte_at(mm, address_m, pte_m, entry_m);
96460 + update_mmu_cache(vma_m, address_m, pte_m);
96461 +out:
96462 + if (ptl != ptl_m)
96463 + spin_unlock(ptl_m);
96464 + pte_unmap(pte_m);
96465 +}
96466 +
96467 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96468 +{
96469 + struct mm_struct *mm = vma->vm_mm;
96470 + unsigned long address_m;
96471 + spinlock_t *ptl_m;
96472 + struct vm_area_struct *vma_m;
96473 + pmd_t *pmd_m;
96474 + pte_t *pte_m, entry_m;
96475 +
96476 + vma_m = pax_find_mirror_vma(vma);
96477 + if (!vma_m)
96478 + return;
96479 +
96480 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96481 + address_m = address + SEGMEXEC_TASK_SIZE;
96482 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96483 + pte_m = pte_offset_map(pmd_m, address_m);
96484 + ptl_m = pte_lockptr(mm, pmd_m);
96485 + if (ptl != ptl_m) {
96486 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96487 + if (!pte_none(*pte_m))
96488 + goto out;
96489 + }
96490 +
96491 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96492 + set_pte_at(mm, address_m, pte_m, entry_m);
96493 +out:
96494 + if (ptl != ptl_m)
96495 + spin_unlock(ptl_m);
96496 + pte_unmap(pte_m);
96497 +}
96498 +
96499 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96500 +{
96501 + struct page *page_m;
96502 + pte_t entry;
96503 +
96504 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96505 + goto out;
96506 +
96507 + entry = *pte;
96508 + page_m = vm_normal_page(vma, address, entry);
96509 + if (!page_m)
96510 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96511 + else if (PageAnon(page_m)) {
96512 + if (pax_find_mirror_vma(vma)) {
96513 + pte_unmap_unlock(pte, ptl);
96514 + lock_page(page_m);
96515 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96516 + if (pte_same(entry, *pte))
96517 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96518 + else
96519 + unlock_page(page_m);
96520 + }
96521 + } else
96522 + pax_mirror_file_pte(vma, address, page_m, ptl);
96523 +
96524 +out:
96525 + pte_unmap_unlock(pte, ptl);
96526 +}
96527 +#endif
96528 +
96529 /*
96530 * This routine handles present pages, when users try to write
96531 * to a shared page. It is done by copying the page to a new address
96532 @@ -2225,6 +2432,12 @@ gotten:
96533 */
96534 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96535 if (likely(pte_same(*page_table, orig_pte))) {
96536 +
96537 +#ifdef CONFIG_PAX_SEGMEXEC
96538 + if (pax_find_mirror_vma(vma))
96539 + BUG_ON(!trylock_page(new_page));
96540 +#endif
96541 +
96542 if (old_page) {
96543 if (!PageAnon(old_page)) {
96544 dec_mm_counter_fast(mm, MM_FILEPAGES);
96545 @@ -2278,6 +2491,10 @@ gotten:
96546 page_remove_rmap(old_page);
96547 }
96548
96549 +#ifdef CONFIG_PAX_SEGMEXEC
96550 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96551 +#endif
96552 +
96553 /* Free the old page.. */
96554 new_page = old_page;
96555 ret |= VM_FAULT_WRITE;
96556 @@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96557 swap_free(entry);
96558 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96559 try_to_free_swap(page);
96560 +
96561 +#ifdef CONFIG_PAX_SEGMEXEC
96562 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96563 +#endif
96564 +
96565 unlock_page(page);
96566 if (page != swapcache) {
96567 /*
96568 @@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96569
96570 /* No need to invalidate - it was non-present before */
96571 update_mmu_cache(vma, address, page_table);
96572 +
96573 +#ifdef CONFIG_PAX_SEGMEXEC
96574 + pax_mirror_anon_pte(vma, address, page, ptl);
96575 +#endif
96576 +
96577 unlock:
96578 pte_unmap_unlock(page_table, ptl);
96579 out:
96580 @@ -2594,40 +2821,6 @@ out_release:
96581 }
96582
96583 /*
96584 - * This is like a special single-page "expand_{down|up}wards()",
96585 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96586 - * doesn't hit another vma.
96587 - */
96588 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96589 -{
96590 - address &= PAGE_MASK;
96591 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96592 - struct vm_area_struct *prev = vma->vm_prev;
96593 -
96594 - /*
96595 - * Is there a mapping abutting this one below?
96596 - *
96597 - * That's only ok if it's the same stack mapping
96598 - * that has gotten split..
96599 - */
96600 - if (prev && prev->vm_end == address)
96601 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96602 -
96603 - return expand_downwards(vma, address - PAGE_SIZE);
96604 - }
96605 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96606 - struct vm_area_struct *next = vma->vm_next;
96607 -
96608 - /* As VM_GROWSDOWN but s/below/above/ */
96609 - if (next && next->vm_start == address + PAGE_SIZE)
96610 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96611 -
96612 - return expand_upwards(vma, address + PAGE_SIZE);
96613 - }
96614 - return 0;
96615 -}
96616 -
96617 -/*
96618 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96619 * but allow concurrent faults), and pte mapped but not yet locked.
96620 * We return with mmap_sem still held, but pte unmapped and unlocked.
96621 @@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96622 unsigned int flags)
96623 {
96624 struct mem_cgroup *memcg;
96625 - struct page *page;
96626 + struct page *page = NULL;
96627 spinlock_t *ptl;
96628 pte_t entry;
96629
96630 - pte_unmap(page_table);
96631 -
96632 - /* Check if we need to add a guard page to the stack */
96633 - if (check_stack_guard_page(vma, address) < 0)
96634 - return VM_FAULT_SIGSEGV;
96635 -
96636 - /* Use the zero-page for reads */
96637 if (!(flags & FAULT_FLAG_WRITE)) {
96638 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96639 vma->vm_page_prot));
96640 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96641 + ptl = pte_lockptr(mm, pmd);
96642 + spin_lock(ptl);
96643 if (!pte_none(*page_table))
96644 goto unlock;
96645 goto setpte;
96646 }
96647
96648 /* Allocate our own private page. */
96649 + pte_unmap(page_table);
96650 +
96651 if (unlikely(anon_vma_prepare(vma)))
96652 goto oom;
96653 page = alloc_zeroed_user_highpage_movable(vma, address);
96654 @@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96655 if (!pte_none(*page_table))
96656 goto release;
96657
96658 +#ifdef CONFIG_PAX_SEGMEXEC
96659 + if (pax_find_mirror_vma(vma))
96660 + BUG_ON(!trylock_page(page));
96661 +#endif
96662 +
96663 inc_mm_counter_fast(mm, MM_ANONPAGES);
96664 page_add_new_anon_rmap(page, vma, address);
96665 mem_cgroup_commit_charge(page, memcg, false);
96666 @@ -2690,6 +2884,12 @@ setpte:
96667
96668 /* No need to invalidate - it was non-present before */
96669 update_mmu_cache(vma, address, page_table);
96670 +
96671 +#ifdef CONFIG_PAX_SEGMEXEC
96672 + if (page)
96673 + pax_mirror_anon_pte(vma, address, page, ptl);
96674 +#endif
96675 +
96676 unlock:
96677 pte_unmap_unlock(page_table, ptl);
96678 return 0;
96679 @@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96680 return ret;
96681 }
96682 do_set_pte(vma, address, fault_page, pte, false, false);
96683 +
96684 +#ifdef CONFIG_PAX_SEGMEXEC
96685 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96686 +#endif
96687 +
96688 unlock_page(fault_page);
96689 unlock_out:
96690 pte_unmap_unlock(pte, ptl);
96691 @@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96692 page_cache_release(fault_page);
96693 goto uncharge_out;
96694 }
96695 +
96696 +#ifdef CONFIG_PAX_SEGMEXEC
96697 + if (pax_find_mirror_vma(vma))
96698 + BUG_ON(!trylock_page(new_page));
96699 +#endif
96700 +
96701 do_set_pte(vma, address, new_page, pte, true, true);
96702 +
96703 +#ifdef CONFIG_PAX_SEGMEXEC
96704 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96705 +#endif
96706 +
96707 mem_cgroup_commit_charge(new_page, memcg, false);
96708 lru_cache_add_active_or_unevictable(new_page, vma);
96709 pte_unmap_unlock(pte, ptl);
96710 @@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96711 return ret;
96712 }
96713 do_set_pte(vma, address, fault_page, pte, true, false);
96714 +
96715 +#ifdef CONFIG_PAX_SEGMEXEC
96716 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96717 +#endif
96718 +
96719 pte_unmap_unlock(pte, ptl);
96720
96721 if (set_page_dirty(fault_page))
96722 @@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96723 if (flags & FAULT_FLAG_WRITE)
96724 flush_tlb_fix_spurious_fault(vma, address);
96725 }
96726 +
96727 +#ifdef CONFIG_PAX_SEGMEXEC
96728 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96729 + return 0;
96730 +#endif
96731 +
96732 unlock:
96733 pte_unmap_unlock(pte, ptl);
96734 return 0;
96735 @@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96736 pmd_t *pmd;
96737 pte_t *pte;
96738
96739 +#ifdef CONFIG_PAX_SEGMEXEC
96740 + struct vm_area_struct *vma_m;
96741 +#endif
96742 +
96743 if (unlikely(is_vm_hugetlb_page(vma)))
96744 return hugetlb_fault(mm, vma, address, flags);
96745
96746 +#ifdef CONFIG_PAX_SEGMEXEC
96747 + vma_m = pax_find_mirror_vma(vma);
96748 + if (vma_m) {
96749 + unsigned long address_m;
96750 + pgd_t *pgd_m;
96751 + pud_t *pud_m;
96752 + pmd_t *pmd_m;
96753 +
96754 + if (vma->vm_start > vma_m->vm_start) {
96755 + address_m = address;
96756 + address -= SEGMEXEC_TASK_SIZE;
96757 + vma = vma_m;
96758 + } else
96759 + address_m = address + SEGMEXEC_TASK_SIZE;
96760 +
96761 + pgd_m = pgd_offset(mm, address_m);
96762 + pud_m = pud_alloc(mm, pgd_m, address_m);
96763 + if (!pud_m)
96764 + return VM_FAULT_OOM;
96765 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96766 + if (!pmd_m)
96767 + return VM_FAULT_OOM;
96768 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96769 + return VM_FAULT_OOM;
96770 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96771 + }
96772 +#endif
96773 +
96774 pgd = pgd_offset(mm, address);
96775 pud = pud_alloc(mm, pgd, address);
96776 if (!pud)
96777 @@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96778 spin_unlock(&mm->page_table_lock);
96779 return 0;
96780 }
96781 +
96782 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96783 +{
96784 + pud_t *new = pud_alloc_one(mm, address);
96785 + if (!new)
96786 + return -ENOMEM;
96787 +
96788 + smp_wmb(); /* See comment in __pte_alloc */
96789 +
96790 + spin_lock(&mm->page_table_lock);
96791 + if (pgd_present(*pgd)) /* Another has populated it */
96792 + pud_free(mm, new);
96793 + else
96794 + pgd_populate_kernel(mm, pgd, new);
96795 + spin_unlock(&mm->page_table_lock);
96796 + return 0;
96797 +}
96798 #endif /* __PAGETABLE_PUD_FOLDED */
96799
96800 #ifndef __PAGETABLE_PMD_FOLDED
96801 @@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96802 spin_unlock(&mm->page_table_lock);
96803 return 0;
96804 }
96805 +
96806 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96807 +{
96808 + pmd_t *new = pmd_alloc_one(mm, address);
96809 + if (!new)
96810 + return -ENOMEM;
96811 +
96812 + smp_wmb(); /* See comment in __pte_alloc */
96813 +
96814 + spin_lock(&mm->page_table_lock);
96815 +#ifndef __ARCH_HAS_4LEVEL_HACK
96816 + if (pud_present(*pud)) /* Another has populated it */
96817 + pmd_free(mm, new);
96818 + else
96819 + pud_populate_kernel(mm, pud, new);
96820 +#else
96821 + if (pgd_present(*pud)) /* Another has populated it */
96822 + pmd_free(mm, new);
96823 + else
96824 + pgd_populate_kernel(mm, pud, new);
96825 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96826 + spin_unlock(&mm->page_table_lock);
96827 + return 0;
96828 +}
96829 #endif /* __PAGETABLE_PMD_FOLDED */
96830
96831 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96832 @@ -3547,8 +3847,8 @@ out:
96833 return ret;
96834 }
96835
96836 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96837 - void *buf, int len, int write)
96838 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96839 + void *buf, size_t len, int write)
96840 {
96841 resource_size_t phys_addr;
96842 unsigned long prot = 0;
96843 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96844 * Access another process' address space as given in mm. If non-NULL, use the
96845 * given task for page fault accounting.
96846 */
96847 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96848 - unsigned long addr, void *buf, int len, int write)
96849 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96850 + unsigned long addr, void *buf, size_t len, int write)
96851 {
96852 struct vm_area_struct *vma;
96853 void *old_buf = buf;
96854 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96855 down_read(&mm->mmap_sem);
96856 /* ignore errors, just check how much was successfully transferred */
96857 while (len) {
96858 - int bytes, ret, offset;
96859 + ssize_t bytes, ret, offset;
96860 void *maddr;
96861 struct page *page = NULL;
96862
96863 @@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96864 *
96865 * The caller must hold a reference on @mm.
96866 */
96867 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96868 - void *buf, int len, int write)
96869 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96870 + void *buf, size_t len, int write)
96871 {
96872 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96873 }
96874 @@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96875 * Source/target buffer must be kernel space,
96876 * Do not walk the page table directly, use get_user_pages
96877 */
96878 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96879 - void *buf, int len, int write)
96880 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96881 + void *buf, size_t len, int write)
96882 {
96883 struct mm_struct *mm;
96884 - int ret;
96885 + ssize_t ret;
96886
96887 mm = get_task_mm(tsk);
96888 if (!mm)
96889 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96890 index e58725a..e0be017 100644
96891 --- a/mm/mempolicy.c
96892 +++ b/mm/mempolicy.c
96893 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96894 unsigned long vmstart;
96895 unsigned long vmend;
96896
96897 +#ifdef CONFIG_PAX_SEGMEXEC
96898 + struct vm_area_struct *vma_m;
96899 +#endif
96900 +
96901 vma = find_vma(mm, start);
96902 if (!vma || vma->vm_start > start)
96903 return -EFAULT;
96904 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96905 err = vma_replace_policy(vma, new_pol);
96906 if (err)
96907 goto out;
96908 +
96909 +#ifdef CONFIG_PAX_SEGMEXEC
96910 + vma_m = pax_find_mirror_vma(vma);
96911 + if (vma_m) {
96912 + err = vma_replace_policy(vma_m, new_pol);
96913 + if (err)
96914 + goto out;
96915 + }
96916 +#endif
96917 +
96918 }
96919
96920 out:
96921 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96922
96923 if (end < start)
96924 return -EINVAL;
96925 +
96926 +#ifdef CONFIG_PAX_SEGMEXEC
96927 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96928 + if (end > SEGMEXEC_TASK_SIZE)
96929 + return -EINVAL;
96930 + } else
96931 +#endif
96932 +
96933 + if (end > TASK_SIZE)
96934 + return -EINVAL;
96935 +
96936 if (end == start)
96937 return 0;
96938
96939 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96940 */
96941 tcred = __task_cred(task);
96942 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96943 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96944 - !capable(CAP_SYS_NICE)) {
96945 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96946 rcu_read_unlock();
96947 err = -EPERM;
96948 goto out_put;
96949 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96950 goto out;
96951 }
96952
96953 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96954 + if (mm != current->mm &&
96955 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96956 + mmput(mm);
96957 + err = -EPERM;
96958 + goto out;
96959 + }
96960 +#endif
96961 +
96962 err = do_migrate_pages(mm, old, new,
96963 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96964
96965 diff --git a/mm/migrate.c b/mm/migrate.c
96966 index 0143995..b294728 100644
96967 --- a/mm/migrate.c
96968 +++ b/mm/migrate.c
96969 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96970 */
96971 tcred = __task_cred(task);
96972 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96973 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96974 - !capable(CAP_SYS_NICE)) {
96975 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96976 rcu_read_unlock();
96977 err = -EPERM;
96978 goto out;
96979 diff --git a/mm/mlock.c b/mm/mlock.c
96980 index 73cf098..ab547c7 100644
96981 --- a/mm/mlock.c
96982 +++ b/mm/mlock.c
96983 @@ -14,6 +14,7 @@
96984 #include <linux/pagevec.h>
96985 #include <linux/mempolicy.h>
96986 #include <linux/syscalls.h>
96987 +#include <linux/security.h>
96988 #include <linux/sched.h>
96989 #include <linux/export.h>
96990 #include <linux/rmap.h>
96991 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96992 {
96993 unsigned long nstart, end, tmp;
96994 struct vm_area_struct * vma, * prev;
96995 - int error;
96996 + int error = 0;
96997
96998 VM_BUG_ON(start & ~PAGE_MASK);
96999 VM_BUG_ON(len != PAGE_ALIGN(len));
97000 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97001 return -EINVAL;
97002 if (end == start)
97003 return 0;
97004 + if (end > TASK_SIZE)
97005 + return -EINVAL;
97006 +
97007 vma = find_vma(current->mm, start);
97008 if (!vma || vma->vm_start > start)
97009 return -ENOMEM;
97010 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97011 for (nstart = start ; ; ) {
97012 vm_flags_t newflags;
97013
97014 +#ifdef CONFIG_PAX_SEGMEXEC
97015 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97016 + break;
97017 +#endif
97018 +
97019 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97020
97021 newflags = vma->vm_flags & ~VM_LOCKED;
97022 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97023 locked += current->mm->locked_vm;
97024
97025 /* check against resource limits */
97026 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97027 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97028 error = do_mlock(start, len, 1);
97029
97030 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97031 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97032 vm_flags_t newflags;
97033
97034 +#ifdef CONFIG_PAX_SEGMEXEC
97035 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97036 + break;
97037 +#endif
97038 +
97039 newflags = vma->vm_flags & ~VM_LOCKED;
97040 if (flags & MCL_CURRENT)
97041 newflags |= VM_LOCKED;
97042 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97043 lock_limit >>= PAGE_SHIFT;
97044
97045 ret = -ENOMEM;
97046 +
97047 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97048 +
97049 down_write(&current->mm->mmap_sem);
97050 -
97051 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97052 capable(CAP_IPC_LOCK))
97053 ret = do_mlockall(flags);
97054 diff --git a/mm/mmap.c b/mm/mmap.c
97055 index 1620adb..6b35ac8 100644
97056 --- a/mm/mmap.c
97057 +++ b/mm/mmap.c
97058 @@ -41,6 +41,7 @@
97059 #include <linux/notifier.h>
97060 #include <linux/memory.h>
97061 #include <linux/printk.h>
97062 +#include <linux/random.h>
97063
97064 #include <asm/uaccess.h>
97065 #include <asm/cacheflush.h>
97066 @@ -57,6 +58,16 @@
97067 #define arch_rebalance_pgtables(addr, len) (addr)
97068 #endif
97069
97070 +static inline void verify_mm_writelocked(struct mm_struct *mm)
97071 +{
97072 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97073 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97074 + up_read(&mm->mmap_sem);
97075 + BUG();
97076 + }
97077 +#endif
97078 +}
97079 +
97080 static void unmap_region(struct mm_struct *mm,
97081 struct vm_area_struct *vma, struct vm_area_struct *prev,
97082 unsigned long start, unsigned long end);
97083 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97084 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97085 *
97086 */
97087 -pgprot_t protection_map[16] = {
97088 +pgprot_t protection_map[16] __read_only = {
97089 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97090 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97091 };
97092
97093 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
97094 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97095 {
97096 - return __pgprot(pgprot_val(protection_map[vm_flags &
97097 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97098 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97099 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97100 +
97101 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97102 + if (!(__supported_pte_mask & _PAGE_NX) &&
97103 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97104 + (vm_flags & (VM_READ | VM_WRITE)))
97105 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97106 +#endif
97107 +
97108 + return prot;
97109 }
97110 EXPORT_SYMBOL(vm_get_page_prot);
97111
97112 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97113 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97114 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97115 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97116 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97117 /*
97118 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97119 * other variables. It can be updated by several CPUs frequently.
97120 @@ -152,7 +173,7 @@ EXPORT_SYMBOL_GPL(vm_memory_committed);
97121 */
97122 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
97123 {
97124 - unsigned long free, allowed, reserve;
97125 + long free, allowed, reserve;
97126
97127 VM_WARN_ONCE(percpu_counter_read(&vm_committed_as) <
97128 -(s64)vm_committed_as_batch * num_online_cpus(),
97129 @@ -220,7 +241,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
97130 */
97131 if (mm) {
97132 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
97133 - allowed -= min(mm->total_vm / 32, reserve);
97134 + allowed -= min_t(long, mm->total_vm / 32, reserve);
97135 }
97136
97137 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
97138 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97139 struct vm_area_struct *next = vma->vm_next;
97140
97141 might_sleep();
97142 + BUG_ON(vma->vm_mirror);
97143 if (vma->vm_ops && vma->vm_ops->close)
97144 vma->vm_ops->close(vma);
97145 if (vma->vm_file)
97146 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
97147
97148 SYSCALL_DEFINE1(brk, unsigned long, brk)
97149 {
97150 + unsigned long rlim;
97151 unsigned long retval;
97152 unsigned long newbrk, oldbrk;
97153 struct mm_struct *mm = current->mm;
97154 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97155 * segment grow beyond its set limit the in case where the limit is
97156 * not page aligned -Ram Gupta
97157 */
97158 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
97159 + rlim = rlimit(RLIMIT_DATA);
97160 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97161 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97162 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97163 + rlim = 4096 * PAGE_SIZE;
97164 +#endif
97165 + if (check_data_rlimit(rlim, brk, mm->start_brk,
97166 mm->end_data, mm->start_data))
97167 goto out;
97168
97169 @@ -976,6 +1005,12 @@ static int
97170 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97171 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97172 {
97173 +
97174 +#ifdef CONFIG_PAX_SEGMEXEC
97175 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97176 + return 0;
97177 +#endif
97178 +
97179 if (is_mergeable_vma(vma, file, vm_flags) &&
97180 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97181 if (vma->vm_pgoff == vm_pgoff)
97182 @@ -995,6 +1030,12 @@ static int
97183 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97184 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97185 {
97186 +
97187 +#ifdef CONFIG_PAX_SEGMEXEC
97188 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97189 + return 0;
97190 +#endif
97191 +
97192 if (is_mergeable_vma(vma, file, vm_flags) &&
97193 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97194 pgoff_t vm_pglen;
97195 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97196 struct vm_area_struct *area, *next;
97197 int err;
97198
97199 +#ifdef CONFIG_PAX_SEGMEXEC
97200 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97201 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97202 +
97203 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97204 +#endif
97205 +
97206 /*
97207 * We later require that vma->vm_flags == vm_flags,
97208 * so this tests vma->vm_flags & VM_SPECIAL, too.
97209 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97210 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97211 next = next->vm_next;
97212
97213 +#ifdef CONFIG_PAX_SEGMEXEC
97214 + if (prev)
97215 + prev_m = pax_find_mirror_vma(prev);
97216 + if (area)
97217 + area_m = pax_find_mirror_vma(area);
97218 + if (next)
97219 + next_m = pax_find_mirror_vma(next);
97220 +#endif
97221 +
97222 /*
97223 * Can it merge with the predecessor?
97224 */
97225 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97226 /* cases 1, 6 */
97227 err = vma_adjust(prev, prev->vm_start,
97228 next->vm_end, prev->vm_pgoff, NULL);
97229 - } else /* cases 2, 5, 7 */
97230 +
97231 +#ifdef CONFIG_PAX_SEGMEXEC
97232 + if (!err && prev_m)
97233 + err = vma_adjust(prev_m, prev_m->vm_start,
97234 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97235 +#endif
97236 +
97237 + } else { /* cases 2, 5, 7 */
97238 err = vma_adjust(prev, prev->vm_start,
97239 end, prev->vm_pgoff, NULL);
97240 +
97241 +#ifdef CONFIG_PAX_SEGMEXEC
97242 + if (!err && prev_m)
97243 + err = vma_adjust(prev_m, prev_m->vm_start,
97244 + end_m, prev_m->vm_pgoff, NULL);
97245 +#endif
97246 +
97247 + }
97248 if (err)
97249 return NULL;
97250 khugepaged_enter_vma_merge(prev, vm_flags);
97251 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97252 mpol_equal(policy, vma_policy(next)) &&
97253 can_vma_merge_before(next, vm_flags,
97254 anon_vma, file, pgoff+pglen)) {
97255 - if (prev && addr < prev->vm_end) /* case 4 */
97256 + if (prev && addr < prev->vm_end) { /* case 4 */
97257 err = vma_adjust(prev, prev->vm_start,
97258 addr, prev->vm_pgoff, NULL);
97259 - else /* cases 3, 8 */
97260 +
97261 +#ifdef CONFIG_PAX_SEGMEXEC
97262 + if (!err && prev_m)
97263 + err = vma_adjust(prev_m, prev_m->vm_start,
97264 + addr_m, prev_m->vm_pgoff, NULL);
97265 +#endif
97266 +
97267 + } else { /* cases 3, 8 */
97268 err = vma_adjust(area, addr, next->vm_end,
97269 next->vm_pgoff - pglen, NULL);
97270 +
97271 +#ifdef CONFIG_PAX_SEGMEXEC
97272 + if (!err && area_m)
97273 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97274 + next_m->vm_pgoff - pglen, NULL);
97275 +#endif
97276 +
97277 + }
97278 if (err)
97279 return NULL;
97280 khugepaged_enter_vma_merge(area, vm_flags);
97281 @@ -1208,8 +1295,10 @@ none:
97282 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97283 struct file *file, long pages)
97284 {
97285 - const unsigned long stack_flags
97286 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97287 +
97288 +#ifdef CONFIG_PAX_RANDMMAP
97289 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97290 +#endif
97291
97292 mm->total_vm += pages;
97293
97294 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97295 mm->shared_vm += pages;
97296 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97297 mm->exec_vm += pages;
97298 - } else if (flags & stack_flags)
97299 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97300 mm->stack_vm += pages;
97301 }
97302 #endif /* CONFIG_PROC_FS */
97303 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97304 locked += mm->locked_vm;
97305 lock_limit = rlimit(RLIMIT_MEMLOCK);
97306 lock_limit >>= PAGE_SHIFT;
97307 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97308 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97309 return -EAGAIN;
97310 }
97311 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97312 * (the exception is when the underlying filesystem is noexec
97313 * mounted, in which case we dont add PROT_EXEC.)
97314 */
97315 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97316 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97317 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97318 prot |= PROT_EXEC;
97319
97320 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97321 /* Obtain the address to map to. we verify (or select) it and ensure
97322 * that it represents a valid section of the address space.
97323 */
97324 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97325 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97326 if (addr & ~PAGE_MASK)
97327 return addr;
97328
97329 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97330 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97331 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97332
97333 +#ifdef CONFIG_PAX_MPROTECT
97334 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97335 +
97336 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97337 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97338 + mm->binfmt->handle_mmap)
97339 + mm->binfmt->handle_mmap(file);
97340 +#endif
97341 +
97342 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97343 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97344 + gr_log_rwxmmap(file);
97345 +
97346 +#ifdef CONFIG_PAX_EMUPLT
97347 + vm_flags &= ~VM_EXEC;
97348 +#else
97349 + return -EPERM;
97350 +#endif
97351 +
97352 + }
97353 +
97354 + if (!(vm_flags & VM_EXEC))
97355 + vm_flags &= ~VM_MAYEXEC;
97356 +#else
97357 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97358 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97359 +#endif
97360 + else
97361 + vm_flags &= ~VM_MAYWRITE;
97362 + }
97363 +#endif
97364 +
97365 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97366 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97367 + vm_flags &= ~VM_PAGEEXEC;
97368 +#endif
97369 +
97370 if (flags & MAP_LOCKED)
97371 if (!can_do_mlock())
97372 return -EPERM;
97373 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97374 vm_flags |= VM_NORESERVE;
97375 }
97376
97377 + if (!gr_acl_handle_mmap(file, prot))
97378 + return -EACCES;
97379 +
97380 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97381 if (!IS_ERR_VALUE(addr) &&
97382 ((vm_flags & VM_LOCKED) ||
97383 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97384 vm_flags_t vm_flags = vma->vm_flags;
97385
97386 /* If it was private or non-writable, the write bit is already clear */
97387 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97388 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97389 return 0;
97390
97391 /* The backer wishes to know when pages are first written to? */
97392 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97393 struct rb_node **rb_link, *rb_parent;
97394 unsigned long charged = 0;
97395
97396 +#ifdef CONFIG_PAX_SEGMEXEC
97397 + struct vm_area_struct *vma_m = NULL;
97398 +#endif
97399 +
97400 + /*
97401 + * mm->mmap_sem is required to protect against another thread
97402 + * changing the mappings in case we sleep.
97403 + */
97404 + verify_mm_writelocked(mm);
97405 +
97406 /* Check against address space limit. */
97407 +
97408 +#ifdef CONFIG_PAX_RANDMMAP
97409 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97410 +#endif
97411 +
97412 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97413 unsigned long nr_pages;
97414
97415 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97416
97417 /* Clear old maps */
97418 error = -ENOMEM;
97419 -munmap_back:
97420 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97421 if (do_munmap(mm, addr, len))
97422 return -ENOMEM;
97423 - goto munmap_back;
97424 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97425 }
97426
97427 /*
97428 @@ -1595,6 +1739,16 @@ munmap_back:
97429 goto unacct_error;
97430 }
97431
97432 +#ifdef CONFIG_PAX_SEGMEXEC
97433 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97434 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97435 + if (!vma_m) {
97436 + error = -ENOMEM;
97437 + goto free_vma;
97438 + }
97439 + }
97440 +#endif
97441 +
97442 vma->vm_mm = mm;
97443 vma->vm_start = addr;
97444 vma->vm_end = addr + len;
97445 @@ -1625,6 +1779,13 @@ munmap_back:
97446 if (error)
97447 goto unmap_and_free_vma;
97448
97449 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97450 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97451 + vma->vm_flags |= VM_PAGEEXEC;
97452 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97453 + }
97454 +#endif
97455 +
97456 /* Can addr have changed??
97457 *
97458 * Answer: Yes, several device drivers can do it in their
97459 @@ -1643,6 +1804,12 @@ munmap_back:
97460 }
97461
97462 vma_link(mm, vma, prev, rb_link, rb_parent);
97463 +
97464 +#ifdef CONFIG_PAX_SEGMEXEC
97465 + if (vma_m)
97466 + BUG_ON(pax_mirror_vma(vma_m, vma));
97467 +#endif
97468 +
97469 /* Once vma denies write, undo our temporary denial count */
97470 if (file) {
97471 if (vm_flags & VM_SHARED)
97472 @@ -1655,6 +1822,7 @@ out:
97473 perf_event_mmap(vma);
97474
97475 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97476 + track_exec_limit(mm, addr, addr + len, vm_flags);
97477 if (vm_flags & VM_LOCKED) {
97478 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97479 vma == get_gate_vma(current->mm)))
97480 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97481 if (vm_flags & VM_DENYWRITE)
97482 allow_write_access(file);
97483 free_vma:
97484 +
97485 +#ifdef CONFIG_PAX_SEGMEXEC
97486 + if (vma_m)
97487 + kmem_cache_free(vm_area_cachep, vma_m);
97488 +#endif
97489 +
97490 kmem_cache_free(vm_area_cachep, vma);
97491 unacct_error:
97492 if (charged)
97493 @@ -1699,7 +1873,63 @@ unacct_error:
97494 return error;
97495 }
97496
97497 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97498 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97499 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97500 +{
97501 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97502 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97503 +
97504 + return 0;
97505 +}
97506 +#endif
97507 +
97508 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97509 +{
97510 + if (!vma) {
97511 +#ifdef CONFIG_STACK_GROWSUP
97512 + if (addr > sysctl_heap_stack_gap)
97513 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97514 + else
97515 + vma = find_vma(current->mm, 0);
97516 + if (vma && (vma->vm_flags & VM_GROWSUP))
97517 + return false;
97518 +#endif
97519 + return true;
97520 + }
97521 +
97522 + if (addr + len > vma->vm_start)
97523 + return false;
97524 +
97525 + if (vma->vm_flags & VM_GROWSDOWN)
97526 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97527 +#ifdef CONFIG_STACK_GROWSUP
97528 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97529 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97530 +#endif
97531 + else if (offset)
97532 + return offset <= vma->vm_start - addr - len;
97533 +
97534 + return true;
97535 +}
97536 +
97537 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97538 +{
97539 + if (vma->vm_start < len)
97540 + return -ENOMEM;
97541 +
97542 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97543 + if (offset <= vma->vm_start - len)
97544 + return vma->vm_start - len - offset;
97545 + else
97546 + return -ENOMEM;
97547 + }
97548 +
97549 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97550 + return vma->vm_start - len - sysctl_heap_stack_gap;
97551 + return -ENOMEM;
97552 +}
97553 +
97554 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97555 {
97556 /*
97557 * We implement the search by looking for an rbtree node that
97558 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97559 }
97560 }
97561
97562 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97563 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97564 check_current:
97565 /* Check if current node has a suitable gap */
97566 if (gap_start > high_limit)
97567 return -ENOMEM;
97568 +
97569 + if (gap_end - gap_start > info->threadstack_offset)
97570 + gap_start += info->threadstack_offset;
97571 + else
97572 + gap_start = gap_end;
97573 +
97574 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97575 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97576 + gap_start += sysctl_heap_stack_gap;
97577 + else
97578 + gap_start = gap_end;
97579 + }
97580 + if (vma->vm_flags & VM_GROWSDOWN) {
97581 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97582 + gap_end -= sysctl_heap_stack_gap;
97583 + else
97584 + gap_end = gap_start;
97585 + }
97586 if (gap_end >= low_limit && gap_end - gap_start >= length)
97587 goto found;
97588
97589 @@ -1801,7 +2049,7 @@ found:
97590 return gap_start;
97591 }
97592
97593 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97594 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97595 {
97596 struct mm_struct *mm = current->mm;
97597 struct vm_area_struct *vma;
97598 @@ -1855,6 +2103,24 @@ check_current:
97599 gap_end = vma->vm_start;
97600 if (gap_end < low_limit)
97601 return -ENOMEM;
97602 +
97603 + if (gap_end - gap_start > info->threadstack_offset)
97604 + gap_end -= info->threadstack_offset;
97605 + else
97606 + gap_end = gap_start;
97607 +
97608 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97609 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97610 + gap_start += sysctl_heap_stack_gap;
97611 + else
97612 + gap_start = gap_end;
97613 + }
97614 + if (vma->vm_flags & VM_GROWSDOWN) {
97615 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97616 + gap_end -= sysctl_heap_stack_gap;
97617 + else
97618 + gap_end = gap_start;
97619 + }
97620 if (gap_start <= high_limit && gap_end - gap_start >= length)
97621 goto found;
97622
97623 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97624 struct mm_struct *mm = current->mm;
97625 struct vm_area_struct *vma;
97626 struct vm_unmapped_area_info info;
97627 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97628
97629 if (len > TASK_SIZE - mmap_min_addr)
97630 return -ENOMEM;
97631 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97632 if (flags & MAP_FIXED)
97633 return addr;
97634
97635 +#ifdef CONFIG_PAX_RANDMMAP
97636 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97637 +#endif
97638 +
97639 if (addr) {
97640 addr = PAGE_ALIGN(addr);
97641 vma = find_vma(mm, addr);
97642 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97643 - (!vma || addr + len <= vma->vm_start))
97644 + check_heap_stack_gap(vma, addr, len, offset))
97645 return addr;
97646 }
97647
97648 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97649 info.low_limit = mm->mmap_base;
97650 info.high_limit = TASK_SIZE;
97651 info.align_mask = 0;
97652 + info.threadstack_offset = offset;
97653 return vm_unmapped_area(&info);
97654 }
97655 #endif
97656 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97657 struct mm_struct *mm = current->mm;
97658 unsigned long addr = addr0;
97659 struct vm_unmapped_area_info info;
97660 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97661
97662 /* requested length too big for entire address space */
97663 if (len > TASK_SIZE - mmap_min_addr)
97664 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97665 if (flags & MAP_FIXED)
97666 return addr;
97667
97668 +#ifdef CONFIG_PAX_RANDMMAP
97669 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97670 +#endif
97671 +
97672 /* requesting a specific address */
97673 if (addr) {
97674 addr = PAGE_ALIGN(addr);
97675 vma = find_vma(mm, addr);
97676 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97677 - (!vma || addr + len <= vma->vm_start))
97678 + check_heap_stack_gap(vma, addr, len, offset))
97679 return addr;
97680 }
97681
97682 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97683 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97684 info.high_limit = mm->mmap_base;
97685 info.align_mask = 0;
97686 + info.threadstack_offset = offset;
97687 addr = vm_unmapped_area(&info);
97688
97689 /*
97690 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97691 VM_BUG_ON(addr != -ENOMEM);
97692 info.flags = 0;
97693 info.low_limit = TASK_UNMAPPED_BASE;
97694 +
97695 +#ifdef CONFIG_PAX_RANDMMAP
97696 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97697 + info.low_limit += mm->delta_mmap;
97698 +#endif
97699 +
97700 info.high_limit = TASK_SIZE;
97701 addr = vm_unmapped_area(&info);
97702 }
97703 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97704 return vma;
97705 }
97706
97707 +#ifdef CONFIG_PAX_SEGMEXEC
97708 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97709 +{
97710 + struct vm_area_struct *vma_m;
97711 +
97712 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97713 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97714 + BUG_ON(vma->vm_mirror);
97715 + return NULL;
97716 + }
97717 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97718 + vma_m = vma->vm_mirror;
97719 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97720 + BUG_ON(vma->vm_file != vma_m->vm_file);
97721 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97722 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97723 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97724 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97725 + return vma_m;
97726 +}
97727 +#endif
97728 +
97729 /*
97730 * Verify that the stack growth is acceptable and
97731 * update accounting. This is shared with both the
97732 @@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97733
97734 /* Stack limit test */
97735 actual_size = size;
97736 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
97737 - actual_size -= PAGE_SIZE;
97738 + gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
97739 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97740 return -ENOMEM;
97741
97742 @@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97743 locked = mm->locked_vm + grow;
97744 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97745 limit >>= PAGE_SHIFT;
97746 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97747 if (locked > limit && !capable(CAP_IPC_LOCK))
97748 return -ENOMEM;
97749 }
97750 @@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97751 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97752 * vma is the last one with address > vma->vm_end. Have to extend vma.
97753 */
97754 +#ifndef CONFIG_IA64
97755 +static
97756 +#endif
97757 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97758 {
97759 int error;
97760 + bool locknext;
97761
97762 if (!(vma->vm_flags & VM_GROWSUP))
97763 return -EFAULT;
97764
97765 + /* Also guard against wrapping around to address 0. */
97766 + if (address < PAGE_ALIGN(address+1))
97767 + address = PAGE_ALIGN(address+1);
97768 + else
97769 + return -ENOMEM;
97770 +
97771 /*
97772 * We must make sure the anon_vma is allocated
97773 * so that the anon_vma locking is not a noop.
97774 */
97775 if (unlikely(anon_vma_prepare(vma)))
97776 return -ENOMEM;
97777 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97778 + if (locknext && anon_vma_prepare(vma->vm_next))
97779 + return -ENOMEM;
97780 vma_lock_anon_vma(vma);
97781 + if (locknext)
97782 + vma_lock_anon_vma(vma->vm_next);
97783
97784 /*
97785 * vma->vm_start/vm_end cannot change under us because the caller
97786 * is required to hold the mmap_sem in read mode. We need the
97787 - * anon_vma lock to serialize against concurrent expand_stacks.
97788 - * Also guard against wrapping around to address 0.
97789 + * anon_vma locks to serialize against concurrent expand_stacks
97790 + * and expand_upwards.
97791 */
97792 - if (address < PAGE_ALIGN(address+4))
97793 - address = PAGE_ALIGN(address+4);
97794 - else {
97795 - vma_unlock_anon_vma(vma);
97796 - return -ENOMEM;
97797 - }
97798 error = 0;
97799
97800 /* Somebody else might have raced and expanded it already */
97801 - if (address > vma->vm_end) {
97802 + 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)
97803 + error = -ENOMEM;
97804 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97805 unsigned long size, grow;
97806
97807 size = address - vma->vm_start;
97808 @@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97809 }
97810 }
97811 }
97812 + if (locknext)
97813 + vma_unlock_anon_vma(vma->vm_next);
97814 vma_unlock_anon_vma(vma);
97815 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97816 validate_mm(vma->vm_mm);
97817 @@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97818 unsigned long address)
97819 {
97820 int error;
97821 + bool lockprev = false;
97822 + struct vm_area_struct *prev;
97823
97824 /*
97825 * We must make sure the anon_vma is allocated
97826 @@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97827 if (error)
97828 return error;
97829
97830 + prev = vma->vm_prev;
97831 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97832 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97833 +#endif
97834 + if (lockprev && anon_vma_prepare(prev))
97835 + return -ENOMEM;
97836 + if (lockprev)
97837 + vma_lock_anon_vma(prev);
97838 +
97839 vma_lock_anon_vma(vma);
97840
97841 /*
97842 @@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97843 */
97844
97845 /* Somebody else might have raced and expanded it already */
97846 - if (address < vma->vm_start) {
97847 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97848 + error = -ENOMEM;
97849 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97850 unsigned long size, grow;
97851
97852 +#ifdef CONFIG_PAX_SEGMEXEC
97853 + struct vm_area_struct *vma_m;
97854 +
97855 + vma_m = pax_find_mirror_vma(vma);
97856 +#endif
97857 +
97858 size = vma->vm_end - address;
97859 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97860
97861 @@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97862 vma->vm_pgoff -= grow;
97863 anon_vma_interval_tree_post_update_vma(vma);
97864 vma_gap_update(vma);
97865 +
97866 +#ifdef CONFIG_PAX_SEGMEXEC
97867 + if (vma_m) {
97868 + anon_vma_interval_tree_pre_update_vma(vma_m);
97869 + vma_m->vm_start -= grow << PAGE_SHIFT;
97870 + vma_m->vm_pgoff -= grow;
97871 + anon_vma_interval_tree_post_update_vma(vma_m);
97872 + vma_gap_update(vma_m);
97873 + }
97874 +#endif
97875 +
97876 spin_unlock(&vma->vm_mm->page_table_lock);
97877
97878 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97879 perf_event_mmap(vma);
97880 }
97881 }
97882 }
97883 vma_unlock_anon_vma(vma);
97884 + if (lockprev)
97885 + vma_unlock_anon_vma(prev);
97886 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97887 validate_mm(vma->vm_mm);
97888 return error;
97889 @@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97890 do {
97891 long nrpages = vma_pages(vma);
97892
97893 +#ifdef CONFIG_PAX_SEGMEXEC
97894 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97895 + vma = remove_vma(vma);
97896 + continue;
97897 + }
97898 +#endif
97899 +
97900 if (vma->vm_flags & VM_ACCOUNT)
97901 nr_accounted += nrpages;
97902 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97903 @@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97904 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97905 vma->vm_prev = NULL;
97906 do {
97907 +
97908 +#ifdef CONFIG_PAX_SEGMEXEC
97909 + if (vma->vm_mirror) {
97910 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97911 + vma->vm_mirror->vm_mirror = NULL;
97912 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97913 + vma->vm_mirror = NULL;
97914 + }
97915 +#endif
97916 +
97917 vma_rb_erase(vma, &mm->mm_rb);
97918 mm->map_count--;
97919 tail_vma = vma;
97920 @@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97921 struct vm_area_struct *new;
97922 int err = -ENOMEM;
97923
97924 +#ifdef CONFIG_PAX_SEGMEXEC
97925 + struct vm_area_struct *vma_m, *new_m = NULL;
97926 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97927 +#endif
97928 +
97929 if (is_vm_hugetlb_page(vma) && (addr &
97930 ~(huge_page_mask(hstate_vma(vma)))))
97931 return -EINVAL;
97932
97933 +#ifdef CONFIG_PAX_SEGMEXEC
97934 + vma_m = pax_find_mirror_vma(vma);
97935 +#endif
97936 +
97937 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97938 if (!new)
97939 goto out_err;
97940
97941 +#ifdef CONFIG_PAX_SEGMEXEC
97942 + if (vma_m) {
97943 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97944 + if (!new_m) {
97945 + kmem_cache_free(vm_area_cachep, new);
97946 + goto out_err;
97947 + }
97948 + }
97949 +#endif
97950 +
97951 /* most fields are the same, copy all, and then fixup */
97952 *new = *vma;
97953
97954 @@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97955 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97956 }
97957
97958 +#ifdef CONFIG_PAX_SEGMEXEC
97959 + if (vma_m) {
97960 + *new_m = *vma_m;
97961 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97962 + new_m->vm_mirror = new;
97963 + new->vm_mirror = new_m;
97964 +
97965 + if (new_below)
97966 + new_m->vm_end = addr_m;
97967 + else {
97968 + new_m->vm_start = addr_m;
97969 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97970 + }
97971 + }
97972 +#endif
97973 +
97974 err = vma_dup_policy(vma, new);
97975 if (err)
97976 goto out_free_vma;
97977 @@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97978 else
97979 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97980
97981 +#ifdef CONFIG_PAX_SEGMEXEC
97982 + if (!err && vma_m) {
97983 + struct mempolicy *pol = vma_policy(new);
97984 +
97985 + if (anon_vma_clone(new_m, vma_m))
97986 + goto out_free_mpol;
97987 +
97988 + mpol_get(pol);
97989 + set_vma_policy(new_m, pol);
97990 +
97991 + if (new_m->vm_file)
97992 + get_file(new_m->vm_file);
97993 +
97994 + if (new_m->vm_ops && new_m->vm_ops->open)
97995 + new_m->vm_ops->open(new_m);
97996 +
97997 + if (new_below)
97998 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97999 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98000 + else
98001 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98002 +
98003 + if (err) {
98004 + if (new_m->vm_ops && new_m->vm_ops->close)
98005 + new_m->vm_ops->close(new_m);
98006 + if (new_m->vm_file)
98007 + fput(new_m->vm_file);
98008 + mpol_put(pol);
98009 + }
98010 + }
98011 +#endif
98012 +
98013 /* Success. */
98014 if (!err)
98015 return 0;
98016 @@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98017 new->vm_ops->close(new);
98018 if (new->vm_file)
98019 fput(new->vm_file);
98020 - unlink_anon_vmas(new);
98021 out_free_mpol:
98022 mpol_put(vma_policy(new));
98023 out_free_vma:
98024 +
98025 +#ifdef CONFIG_PAX_SEGMEXEC
98026 + if (new_m) {
98027 + unlink_anon_vmas(new_m);
98028 + kmem_cache_free(vm_area_cachep, new_m);
98029 + }
98030 +#endif
98031 +
98032 + unlink_anon_vmas(new);
98033 kmem_cache_free(vm_area_cachep, new);
98034 out_err:
98035 return err;
98036 @@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98037 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98038 unsigned long addr, int new_below)
98039 {
98040 +
98041 +#ifdef CONFIG_PAX_SEGMEXEC
98042 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98043 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98044 + if (mm->map_count >= sysctl_max_map_count-1)
98045 + return -ENOMEM;
98046 + } else
98047 +#endif
98048 +
98049 if (mm->map_count >= sysctl_max_map_count)
98050 return -ENOMEM;
98051
98052 @@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98053 * work. This now handles partial unmappings.
98054 * Jeremy Fitzhardinge <jeremy@goop.org>
98055 */
98056 +#ifdef CONFIG_PAX_SEGMEXEC
98057 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98058 {
98059 + int ret = __do_munmap(mm, start, len);
98060 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98061 + return ret;
98062 +
98063 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98064 +}
98065 +
98066 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98067 +#else
98068 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98069 +#endif
98070 +{
98071 unsigned long end;
98072 struct vm_area_struct *vma, *prev, *last;
98073
98074 + /*
98075 + * mm->mmap_sem is required to protect against another thread
98076 + * changing the mappings in case we sleep.
98077 + */
98078 + verify_mm_writelocked(mm);
98079 +
98080 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98081 return -EINVAL;
98082
98083 @@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98084 /* Fix up all other VM information */
98085 remove_vma_list(mm, vma);
98086
98087 + track_exec_limit(mm, start, end, 0UL);
98088 +
98089 return 0;
98090 }
98091
98092 @@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
98093 int ret;
98094 struct mm_struct *mm = current->mm;
98095
98096 +
98097 +#ifdef CONFIG_PAX_SEGMEXEC
98098 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98099 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98100 + return -EINVAL;
98101 +#endif
98102 +
98103 down_write(&mm->mmap_sem);
98104 ret = do_munmap(mm, start, len);
98105 up_write(&mm->mmap_sem);
98106 @@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98107 return vm_munmap(addr, len);
98108 }
98109
98110 -static inline void verify_mm_writelocked(struct mm_struct *mm)
98111 -{
98112 -#ifdef CONFIG_DEBUG_VM
98113 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98114 - WARN_ON(1);
98115 - up_read(&mm->mmap_sem);
98116 - }
98117 -#endif
98118 -}
98119 -
98120 /*
98121 * this is really a simplified "do_mmap". it only handles
98122 * anonymous maps. eventually we may be able to do some
98123 @@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98124 struct rb_node **rb_link, *rb_parent;
98125 pgoff_t pgoff = addr >> PAGE_SHIFT;
98126 int error;
98127 + unsigned long charged;
98128
98129 len = PAGE_ALIGN(len);
98130 if (!len)
98131 @@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98132
98133 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98134
98135 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98136 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98137 + flags &= ~VM_EXEC;
98138 +
98139 +#ifdef CONFIG_PAX_MPROTECT
98140 + if (mm->pax_flags & MF_PAX_MPROTECT)
98141 + flags &= ~VM_MAYEXEC;
98142 +#endif
98143 +
98144 + }
98145 +#endif
98146 +
98147 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98148 if (error & ~PAGE_MASK)
98149 return error;
98150
98151 + charged = len >> PAGE_SHIFT;
98152 +
98153 error = mlock_future_check(mm, mm->def_flags, len);
98154 if (error)
98155 return error;
98156 @@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98157 /*
98158 * Clear old maps. this also does some error checking for us
98159 */
98160 - munmap_back:
98161 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98162 if (do_munmap(mm, addr, len))
98163 return -ENOMEM;
98164 - goto munmap_back;
98165 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98166 }
98167
98168 /* Check against address space limits *after* clearing old maps... */
98169 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98170 + if (!may_expand_vm(mm, charged))
98171 return -ENOMEM;
98172
98173 if (mm->map_count > sysctl_max_map_count)
98174 return -ENOMEM;
98175
98176 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98177 + if (security_vm_enough_memory_mm(mm, charged))
98178 return -ENOMEM;
98179
98180 /* Can we just expand an old private anonymous mapping? */
98181 @@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98182 */
98183 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98184 if (!vma) {
98185 - vm_unacct_memory(len >> PAGE_SHIFT);
98186 + vm_unacct_memory(charged);
98187 return -ENOMEM;
98188 }
98189
98190 @@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98191 vma_link(mm, vma, prev, rb_link, rb_parent);
98192 out:
98193 perf_event_mmap(vma);
98194 - mm->total_vm += len >> PAGE_SHIFT;
98195 + mm->total_vm += charged;
98196 if (flags & VM_LOCKED)
98197 - mm->locked_vm += (len >> PAGE_SHIFT);
98198 + mm->locked_vm += charged;
98199 vma->vm_flags |= VM_SOFTDIRTY;
98200 + track_exec_limit(mm, addr, addr + len, flags);
98201 return addr;
98202 }
98203
98204 @@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
98205 while (vma) {
98206 if (vma->vm_flags & VM_ACCOUNT)
98207 nr_accounted += vma_pages(vma);
98208 + vma->vm_mirror = NULL;
98209 vma = remove_vma(vma);
98210 }
98211 vm_unacct_memory(nr_accounted);
98212 @@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98213 struct vm_area_struct *prev;
98214 struct rb_node **rb_link, *rb_parent;
98215
98216 +#ifdef CONFIG_PAX_SEGMEXEC
98217 + struct vm_area_struct *vma_m = NULL;
98218 +#endif
98219 +
98220 + if (security_mmap_addr(vma->vm_start))
98221 + return -EPERM;
98222 +
98223 /*
98224 * The vm_pgoff of a purely anonymous vma should be irrelevant
98225 * until its first write fault, when page's anon_vma and index
98226 @@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98227 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98228 return -ENOMEM;
98229
98230 +#ifdef CONFIG_PAX_SEGMEXEC
98231 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98232 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98233 + if (!vma_m)
98234 + return -ENOMEM;
98235 + }
98236 +#endif
98237 +
98238 vma_link(mm, vma, prev, rb_link, rb_parent);
98239 +
98240 +#ifdef CONFIG_PAX_SEGMEXEC
98241 + if (vma_m)
98242 + BUG_ON(pax_mirror_vma(vma_m, vma));
98243 +#endif
98244 +
98245 return 0;
98246 }
98247
98248 @@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98249 struct rb_node **rb_link, *rb_parent;
98250 bool faulted_in_anon_vma = true;
98251
98252 + BUG_ON(vma->vm_mirror);
98253 +
98254 /*
98255 * If anonymous vma has not yet been faulted, update new pgoff
98256 * to match new location, to increase its chance of merging.
98257 @@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98258 return NULL;
98259 }
98260
98261 +#ifdef CONFIG_PAX_SEGMEXEC
98262 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98263 +{
98264 + struct vm_area_struct *prev_m;
98265 + struct rb_node **rb_link_m, *rb_parent_m;
98266 + struct mempolicy *pol_m;
98267 +
98268 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98269 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98270 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98271 + *vma_m = *vma;
98272 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98273 + if (anon_vma_clone(vma_m, vma))
98274 + return -ENOMEM;
98275 + pol_m = vma_policy(vma_m);
98276 + mpol_get(pol_m);
98277 + set_vma_policy(vma_m, pol_m);
98278 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98279 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98280 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98281 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98282 + if (vma_m->vm_file)
98283 + get_file(vma_m->vm_file);
98284 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98285 + vma_m->vm_ops->open(vma_m);
98286 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98287 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98288 + vma_m->vm_mirror = vma;
98289 + vma->vm_mirror = vma_m;
98290 + return 0;
98291 +}
98292 +#endif
98293 +
98294 /*
98295 * Return true if the calling process may expand its vm space by the passed
98296 * number of pages
98297 @@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98298
98299 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98300
98301 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98302 if (cur + npages > lim)
98303 return 0;
98304 return 1;
98305 @@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
98306 vma->vm_start = addr;
98307 vma->vm_end = addr + len;
98308
98309 +#ifdef CONFIG_PAX_MPROTECT
98310 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98311 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98312 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98313 + return ERR_PTR(-EPERM);
98314 + if (!(vm_flags & VM_EXEC))
98315 + vm_flags &= ~VM_MAYEXEC;
98316 +#else
98317 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98318 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98319 +#endif
98320 + else
98321 + vm_flags &= ~VM_MAYWRITE;
98322 + }
98323 +#endif
98324 +
98325 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98326 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98327
98328 diff --git a/mm/mprotect.c b/mm/mprotect.c
98329 index ace9345..63320dc 100644
98330 --- a/mm/mprotect.c
98331 +++ b/mm/mprotect.c
98332 @@ -24,10 +24,18 @@
98333 #include <linux/migrate.h>
98334 #include <linux/perf_event.h>
98335 #include <linux/ksm.h>
98336 +#include <linux/sched/sysctl.h>
98337 +
98338 +#ifdef CONFIG_PAX_MPROTECT
98339 +#include <linux/elf.h>
98340 +#include <linux/binfmts.h>
98341 +#endif
98342 +
98343 #include <asm/uaccess.h>
98344 #include <asm/pgtable.h>
98345 #include <asm/cacheflush.h>
98346 #include <asm/tlbflush.h>
98347 +#include <asm/mmu_context.h>
98348
98349 /*
98350 * For a prot_numa update we only hold mmap_sem for read so there is a
98351 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98352 return pages;
98353 }
98354
98355 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98356 +/* called while holding the mmap semaphor for writing except stack expansion */
98357 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98358 +{
98359 + unsigned long oldlimit, newlimit = 0UL;
98360 +
98361 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98362 + return;
98363 +
98364 + spin_lock(&mm->page_table_lock);
98365 + oldlimit = mm->context.user_cs_limit;
98366 + if ((prot & VM_EXEC) && oldlimit < end)
98367 + /* USER_CS limit moved up */
98368 + newlimit = end;
98369 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98370 + /* USER_CS limit moved down */
98371 + newlimit = start;
98372 +
98373 + if (newlimit) {
98374 + mm->context.user_cs_limit = newlimit;
98375 +
98376 +#ifdef CONFIG_SMP
98377 + wmb();
98378 + cpus_clear(mm->context.cpu_user_cs_mask);
98379 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98380 +#endif
98381 +
98382 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98383 + }
98384 + spin_unlock(&mm->page_table_lock);
98385 + if (newlimit == end) {
98386 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98387 +
98388 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98389 + if (is_vm_hugetlb_page(vma))
98390 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98391 + else
98392 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98393 + }
98394 +}
98395 +#endif
98396 +
98397 int
98398 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98399 unsigned long start, unsigned long end, unsigned long newflags)
98400 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98401 int error;
98402 int dirty_accountable = 0;
98403
98404 +#ifdef CONFIG_PAX_SEGMEXEC
98405 + struct vm_area_struct *vma_m = NULL;
98406 + unsigned long start_m, end_m;
98407 +
98408 + start_m = start + SEGMEXEC_TASK_SIZE;
98409 + end_m = end + SEGMEXEC_TASK_SIZE;
98410 +#endif
98411 +
98412 if (newflags == oldflags) {
98413 *pprev = vma;
98414 return 0;
98415 }
98416
98417 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98418 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98419 +
98420 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98421 + return -ENOMEM;
98422 +
98423 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98424 + return -ENOMEM;
98425 + }
98426 +
98427 /*
98428 * If we make a private mapping writable we increase our commit;
98429 * but (without finer accounting) cannot reduce our commit if we
98430 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98431 }
98432 }
98433
98434 +#ifdef CONFIG_PAX_SEGMEXEC
98435 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98436 + if (start != vma->vm_start) {
98437 + error = split_vma(mm, vma, start, 1);
98438 + if (error)
98439 + goto fail;
98440 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98441 + *pprev = (*pprev)->vm_next;
98442 + }
98443 +
98444 + if (end != vma->vm_end) {
98445 + error = split_vma(mm, vma, end, 0);
98446 + if (error)
98447 + goto fail;
98448 + }
98449 +
98450 + if (pax_find_mirror_vma(vma)) {
98451 + error = __do_munmap(mm, start_m, end_m - start_m);
98452 + if (error)
98453 + goto fail;
98454 + } else {
98455 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98456 + if (!vma_m) {
98457 + error = -ENOMEM;
98458 + goto fail;
98459 + }
98460 + vma->vm_flags = newflags;
98461 + error = pax_mirror_vma(vma_m, vma);
98462 + if (error) {
98463 + vma->vm_flags = oldflags;
98464 + goto fail;
98465 + }
98466 + }
98467 + }
98468 +#endif
98469 +
98470 /*
98471 * First try to merge with previous and/or next vma.
98472 */
98473 @@ -314,7 +418,19 @@ success:
98474 * vm_flags and vm_page_prot are protected by the mmap_sem
98475 * held in write mode.
98476 */
98477 +
98478 +#ifdef CONFIG_PAX_SEGMEXEC
98479 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98480 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98481 +#endif
98482 +
98483 vma->vm_flags = newflags;
98484 +
98485 +#ifdef CONFIG_PAX_MPROTECT
98486 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98487 + mm->binfmt->handle_mprotect(vma, newflags);
98488 +#endif
98489 +
98490 dirty_accountable = vma_wants_writenotify(vma);
98491 vma_set_page_prot(vma);
98492
98493 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98494 end = start + len;
98495 if (end <= start)
98496 return -ENOMEM;
98497 +
98498 +#ifdef CONFIG_PAX_SEGMEXEC
98499 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98500 + if (end > SEGMEXEC_TASK_SIZE)
98501 + return -EINVAL;
98502 + } else
98503 +#endif
98504 +
98505 + if (end > TASK_SIZE)
98506 + return -EINVAL;
98507 +
98508 if (!arch_validate_prot(prot))
98509 return -EINVAL;
98510
98511 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98512 /*
98513 * Does the application expect PROT_READ to imply PROT_EXEC:
98514 */
98515 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98516 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98517 prot |= PROT_EXEC;
98518
98519 vm_flags = calc_vm_prot_bits(prot);
98520 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98521 if (start > vma->vm_start)
98522 prev = vma;
98523
98524 +#ifdef CONFIG_PAX_MPROTECT
98525 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98526 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98527 +#endif
98528 +
98529 for (nstart = start ; ; ) {
98530 unsigned long newflags;
98531
98532 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98533
98534 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98535 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98536 + if (prot & (PROT_WRITE | PROT_EXEC))
98537 + gr_log_rwxmprotect(vma);
98538 +
98539 + error = -EACCES;
98540 + goto out;
98541 + }
98542 +
98543 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98544 error = -EACCES;
98545 goto out;
98546 }
98547 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98548 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98549 if (error)
98550 goto out;
98551 +
98552 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98553 +
98554 nstart = tmp;
98555
98556 if (nstart < prev->vm_end)
98557 diff --git a/mm/mremap.c b/mm/mremap.c
98558 index b147f66..98a695ab 100644
98559 --- a/mm/mremap.c
98560 +++ b/mm/mremap.c
98561 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98562 continue;
98563 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98564 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98565 +
98566 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98567 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98568 + pte = pte_exprotect(pte);
98569 +#endif
98570 +
98571 pte = move_soft_dirty_pte(pte);
98572 set_pte_at(mm, new_addr, new_pte, pte);
98573 }
98574 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98575 if (is_vm_hugetlb_page(vma))
98576 goto Einval;
98577
98578 +#ifdef CONFIG_PAX_SEGMEXEC
98579 + if (pax_find_mirror_vma(vma))
98580 + goto Einval;
98581 +#endif
98582 +
98583 /* We can't remap across vm area boundaries */
98584 if (old_len > vma->vm_end - addr)
98585 goto Efault;
98586 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98587 unsigned long ret = -EINVAL;
98588 unsigned long charged = 0;
98589 unsigned long map_flags;
98590 + unsigned long pax_task_size = TASK_SIZE;
98591
98592 if (new_addr & ~PAGE_MASK)
98593 goto out;
98594
98595 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98596 +#ifdef CONFIG_PAX_SEGMEXEC
98597 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98598 + pax_task_size = SEGMEXEC_TASK_SIZE;
98599 +#endif
98600 +
98601 + pax_task_size -= PAGE_SIZE;
98602 +
98603 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98604 goto out;
98605
98606 /* Check if the location we're moving into overlaps the
98607 * old location at all, and fail if it does.
98608 */
98609 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98610 - goto out;
98611 -
98612 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98613 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98614 goto out;
98615
98616 ret = do_munmap(mm, new_addr, new_len);
98617 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98618 unsigned long ret = -EINVAL;
98619 unsigned long charged = 0;
98620 bool locked = false;
98621 + unsigned long pax_task_size = TASK_SIZE;
98622
98623 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98624 return ret;
98625 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98626 if (!new_len)
98627 return ret;
98628
98629 +#ifdef CONFIG_PAX_SEGMEXEC
98630 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98631 + pax_task_size = SEGMEXEC_TASK_SIZE;
98632 +#endif
98633 +
98634 + pax_task_size -= PAGE_SIZE;
98635 +
98636 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98637 + old_len > pax_task_size || addr > pax_task_size-old_len)
98638 + return ret;
98639 +
98640 down_write(&current->mm->mmap_sem);
98641
98642 if (flags & MREMAP_FIXED) {
98643 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98644 new_addr = addr;
98645 }
98646 ret = addr;
98647 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98648 goto out;
98649 }
98650 }
98651 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98652 goto out;
98653 }
98654
98655 + map_flags = vma->vm_flags;
98656 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98657 + if (!(ret & ~PAGE_MASK)) {
98658 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98659 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98660 + }
98661 }
98662 out:
98663 if (ret & ~PAGE_MASK)
98664 diff --git a/mm/nommu.c b/mm/nommu.c
98665 index bd1808e..22cbc6a 100644
98666 --- a/mm/nommu.c
98667 +++ b/mm/nommu.c
98668 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98669 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98670 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98671 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98672 -int heap_stack_gap = 0;
98673
98674 atomic_long_t mmap_pages_allocated;
98675
98676 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98677 EXPORT_SYMBOL(find_vma);
98678
98679 /*
98680 - * find a VMA
98681 - * - we don't extend stack VMAs under NOMMU conditions
98682 - */
98683 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98684 -{
98685 - return find_vma(mm, addr);
98686 -}
98687 -
98688 -/*
98689 * expand a stack to a given address
98690 * - not supported under NOMMU conditions
98691 */
98692 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98693
98694 /* most fields are the same, copy all, and then fixup */
98695 *new = *vma;
98696 + INIT_LIST_HEAD(&new->anon_vma_chain);
98697 *region = *vma->vm_region;
98698 new->vm_region = region;
98699
98700 @@ -1905,7 +1896,7 @@ EXPORT_SYMBOL(unmap_mapping_range);
98701 */
98702 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98703 {
98704 - unsigned long free, allowed, reserve;
98705 + long free, allowed, reserve;
98706
98707 vm_acct_memory(pages);
98708
98709 @@ -1969,7 +1960,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98710 */
98711 if (mm) {
98712 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
98713 - allowed -= min(mm->total_vm / 32, reserve);
98714 + allowed -= min_t(long, mm->total_vm / 32, reserve);
98715 }
98716
98717 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
98718 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98719 }
98720 EXPORT_SYMBOL(generic_file_remap_pages);
98721
98722 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98723 - unsigned long addr, void *buf, int len, int write)
98724 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98725 + unsigned long addr, void *buf, size_t len, int write)
98726 {
98727 struct vm_area_struct *vma;
98728
98729 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98730 *
98731 * The caller must hold a reference on @mm.
98732 */
98733 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98734 - void *buf, int len, int write)
98735 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98736 + void *buf, size_t len, int write)
98737 {
98738 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98739 }
98740 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98741 * Access another process' address space.
98742 * - source/target buffer must be kernel space
98743 */
98744 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98745 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98746 {
98747 struct mm_struct *mm;
98748
98749 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98750 index 437174a..8b86707 100644
98751 --- a/mm/page-writeback.c
98752 +++ b/mm/page-writeback.c
98753 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98754 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98755 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98756 */
98757 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98758 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98759 unsigned long thresh,
98760 unsigned long bg_thresh,
98761 unsigned long dirty,
98762 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98763 index 616a2c9..0e755f6 100644
98764 --- a/mm/page_alloc.c
98765 +++ b/mm/page_alloc.c
98766 @@ -59,6 +59,7 @@
98767 #include <linux/page-debug-flags.h>
98768 #include <linux/hugetlb.h>
98769 #include <linux/sched/rt.h>
98770 +#include <linux/random.h>
98771
98772 #include <asm/sections.h>
98773 #include <asm/tlbflush.h>
98774 @@ -356,7 +357,7 @@ out:
98775 * This usage means that zero-order pages may not be compound.
98776 */
98777
98778 -static void free_compound_page(struct page *page)
98779 +void free_compound_page(struct page *page)
98780 {
98781 __free_pages_ok(page, compound_order(page));
98782 }
98783 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98784 int i;
98785 int bad = 0;
98786
98787 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98788 + unsigned long index = 1UL << order;
98789 +#endif
98790 +
98791 trace_mm_page_free(page, order);
98792 kmemcheck_free_shadow(page, order);
98793
98794 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98795 debug_check_no_obj_freed(page_address(page),
98796 PAGE_SIZE << order);
98797 }
98798 +
98799 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98800 + for (; index; --index)
98801 + sanitize_highpage(page + index - 1);
98802 +#endif
98803 +
98804 arch_free_page(page, order);
98805 kernel_map_pages(page, 1 << order, 0);
98806
98807 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98808 local_irq_restore(flags);
98809 }
98810
98811 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98812 +bool __meminitdata extra_latent_entropy;
98813 +
98814 +static int __init setup_pax_extra_latent_entropy(char *str)
98815 +{
98816 + extra_latent_entropy = true;
98817 + return 0;
98818 +}
98819 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98820 +
98821 +volatile u64 latent_entropy __latent_entropy;
98822 +EXPORT_SYMBOL(latent_entropy);
98823 +#endif
98824 +
98825 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98826 {
98827 unsigned int nr_pages = 1 << order;
98828 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98829 __ClearPageReserved(p);
98830 set_page_count(p, 0);
98831
98832 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98833 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98834 + u64 hash = 0;
98835 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98836 + const u64 *data = lowmem_page_address(page);
98837 +
98838 + for (index = 0; index < end; index++)
98839 + hash ^= hash + data[index];
98840 + latent_entropy ^= hash;
98841 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98842 + }
98843 +#endif
98844 +
98845 page_zone(page)->managed_pages += nr_pages;
98846 set_page_refcounted(page);
98847 __free_pages(page, order);
98848 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98849 arch_alloc_page(page, order);
98850 kernel_map_pages(page, 1 << order, 1);
98851
98852 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98853 if (gfp_flags & __GFP_ZERO)
98854 prep_zero_page(page, order, gfp_flags);
98855 +#endif
98856
98857 if (order && (gfp_flags & __GFP_COMP))
98858 prep_compound_page(page, order);
98859 @@ -1602,7 +1642,7 @@ again:
98860 }
98861
98862 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98863 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98864 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98865 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98866 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98867
98868 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98869 do {
98870 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98871 high_wmark_pages(zone) - low_wmark_pages(zone) -
98872 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98873 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98874 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98875 } while (zone++ != preferred_zone);
98876 }
98877 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98878
98879 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98880 high_wmark_pages(zone) - low_wmark_pages(zone) -
98881 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98882 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98883
98884 setup_zone_migrate_reserve(zone);
98885 spin_unlock_irqrestore(&zone->lock, flags);
98886 diff --git a/mm/percpu.c b/mm/percpu.c
98887 index 014bab6..db5a76f 100644
98888 --- a/mm/percpu.c
98889 +++ b/mm/percpu.c
98890 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98891 static unsigned int pcpu_high_unit_cpu __read_mostly;
98892
98893 /* the address of the first chunk which starts with the kernel static area */
98894 -void *pcpu_base_addr __read_mostly;
98895 +void *pcpu_base_addr __read_only;
98896 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98897
98898 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98899 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98900 index 5077afc..846c9ef 100644
98901 --- a/mm/process_vm_access.c
98902 +++ b/mm/process_vm_access.c
98903 @@ -13,6 +13,7 @@
98904 #include <linux/uio.h>
98905 #include <linux/sched.h>
98906 #include <linux/highmem.h>
98907 +#include <linux/security.h>
98908 #include <linux/ptrace.h>
98909 #include <linux/slab.h>
98910 #include <linux/syscalls.h>
98911 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98912 ssize_t iov_len;
98913 size_t total_len = iov_iter_count(iter);
98914
98915 + return -ENOSYS; // PaX: until properly audited
98916 +
98917 /*
98918 * Work out how many pages of struct pages we're going to need
98919 * when eventually calling get_user_pages
98920 */
98921 for (i = 0; i < riovcnt; i++) {
98922 iov_len = rvec[i].iov_len;
98923 - if (iov_len > 0) {
98924 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98925 - + iov_len)
98926 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98927 - / PAGE_SIZE + 1;
98928 - nr_pages = max(nr_pages, nr_pages_iov);
98929 - }
98930 + if (iov_len <= 0)
98931 + continue;
98932 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98933 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98934 + nr_pages = max(nr_pages, nr_pages_iov);
98935 }
98936
98937 if (nr_pages == 0)
98938 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98939 goto free_proc_pages;
98940 }
98941
98942 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98943 + rc = -EPERM;
98944 + goto put_task_struct;
98945 + }
98946 +
98947 mm = mm_access(task, PTRACE_MODE_ATTACH);
98948 if (!mm || IS_ERR(mm)) {
98949 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98950 diff --git a/mm/rmap.c b/mm/rmap.c
98951 index 3e4c721..a5e3e39 100644
98952 --- a/mm/rmap.c
98953 +++ b/mm/rmap.c
98954 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98955 struct anon_vma *anon_vma = vma->anon_vma;
98956 struct anon_vma_chain *avc;
98957
98958 +#ifdef CONFIG_PAX_SEGMEXEC
98959 + struct anon_vma_chain *avc_m = NULL;
98960 +#endif
98961 +
98962 might_sleep();
98963 if (unlikely(!anon_vma)) {
98964 struct mm_struct *mm = vma->vm_mm;
98965 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98966 if (!avc)
98967 goto out_enomem;
98968
98969 +#ifdef CONFIG_PAX_SEGMEXEC
98970 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98971 + if (!avc_m)
98972 + goto out_enomem_free_avc;
98973 +#endif
98974 +
98975 anon_vma = find_mergeable_anon_vma(vma);
98976 allocated = NULL;
98977 if (!anon_vma) {
98978 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98979 /* page_table_lock to protect against threads */
98980 spin_lock(&mm->page_table_lock);
98981 if (likely(!vma->anon_vma)) {
98982 +
98983 +#ifdef CONFIG_PAX_SEGMEXEC
98984 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98985 +
98986 + if (vma_m) {
98987 + BUG_ON(vma_m->anon_vma);
98988 + vma_m->anon_vma = anon_vma;
98989 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98990 + avc_m = NULL;
98991 + }
98992 +#endif
98993 +
98994 vma->anon_vma = anon_vma;
98995 anon_vma_chain_link(vma, avc, anon_vma);
98996 allocated = NULL;
98997 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98998
98999 if (unlikely(allocated))
99000 put_anon_vma(allocated);
99001 +
99002 +#ifdef CONFIG_PAX_SEGMEXEC
99003 + if (unlikely(avc_m))
99004 + anon_vma_chain_free(avc_m);
99005 +#endif
99006 +
99007 if (unlikely(avc))
99008 anon_vma_chain_free(avc);
99009 }
99010 return 0;
99011
99012 out_enomem_free_avc:
99013 +
99014 +#ifdef CONFIG_PAX_SEGMEXEC
99015 + if (avc_m)
99016 + anon_vma_chain_free(avc_m);
99017 +#endif
99018 +
99019 anon_vma_chain_free(avc);
99020 out_enomem:
99021 return -ENOMEM;
99022 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99023 * Attach the anon_vmas from src to dst.
99024 * Returns 0 on success, -ENOMEM on failure.
99025 */
99026 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99027 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99028 {
99029 struct anon_vma_chain *avc, *pavc;
99030 struct anon_vma *root = NULL;
99031 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99032 * the corresponding VMA in the parent process is attached to.
99033 * Returns 0 on success, non-zero on failure.
99034 */
99035 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99036 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99037 {
99038 struct anon_vma_chain *avc;
99039 struct anon_vma *anon_vma;
99040 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
99041 void __init anon_vma_init(void)
99042 {
99043 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99044 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99045 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99046 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99047 + anon_vma_ctor);
99048 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99049 + SLAB_PANIC|SLAB_NO_SANITIZE);
99050 }
99051
99052 /*
99053 diff --git a/mm/shmem.c b/mm/shmem.c
99054 index 0b4ba55..bcef4ae 100644
99055 --- a/mm/shmem.c
99056 +++ b/mm/shmem.c
99057 @@ -33,7 +33,7 @@
99058 #include <linux/swap.h>
99059 #include <linux/aio.h>
99060
99061 -static struct vfsmount *shm_mnt;
99062 +struct vfsmount *shm_mnt;
99063
99064 #ifdef CONFIG_SHMEM
99065 /*
99066 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99067 #define BOGO_DIRENT_SIZE 20
99068
99069 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99070 -#define SHORT_SYMLINK_LEN 128
99071 +#define SHORT_SYMLINK_LEN 64
99072
99073 /*
99074 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99075 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99076 static int shmem_xattr_validate(const char *name)
99077 {
99078 struct { const char *prefix; size_t len; } arr[] = {
99079 +
99080 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99081 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99082 +#endif
99083 +
99084 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99085 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99086 };
99087 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99088 if (err)
99089 return err;
99090
99091 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99092 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99093 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99094 + return -EOPNOTSUPP;
99095 + if (size > 8)
99096 + return -EINVAL;
99097 + }
99098 +#endif
99099 +
99100 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99101 }
99102
99103 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99104 int err = -ENOMEM;
99105
99106 /* Round up to L1_CACHE_BYTES to resist false sharing */
99107 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99108 - L1_CACHE_BYTES), GFP_KERNEL);
99109 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99110 if (!sbinfo)
99111 return -ENOMEM;
99112
99113 diff --git a/mm/slab.c b/mm/slab.c
99114 index f34e053..78a3839 100644
99115 --- a/mm/slab.c
99116 +++ b/mm/slab.c
99117 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99118 if ((x)->max_freeable < i) \
99119 (x)->max_freeable = i; \
99120 } while (0)
99121 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99122 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99123 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99124 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99125 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99126 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99127 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99128 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99129 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99130 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99131 #else
99132 #define STATS_INC_ACTIVE(x) do { } while (0)
99133 #define STATS_DEC_ACTIVE(x) do { } while (0)
99134 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99135 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99136 #define STATS_INC_FREEHIT(x) do { } while (0)
99137 #define STATS_INC_FREEMISS(x) do { } while (0)
99138 +#define STATS_INC_SANITIZED(x) do { } while (0)
99139 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99140 #endif
99141
99142 #if DEBUG
99143 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99144 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99145 */
99146 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99147 - const struct page *page, void *obj)
99148 + const struct page *page, const void *obj)
99149 {
99150 u32 offset = (obj - page->s_mem);
99151 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99152 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
99153 * structures first. Without this, further allocations will bug.
99154 */
99155 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
99156 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99157 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99158 slab_state = PARTIAL_NODE;
99159
99160 slab_early_init = 0;
99161 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99162
99163 cachep = find_mergeable(size, align, flags, name, ctor);
99164 if (cachep) {
99165 - cachep->refcount++;
99166 + atomic_inc(&cachep->refcount);
99167
99168 /*
99169 * Adjust the object sizes so that we clear
99170 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99171 struct array_cache *ac = cpu_cache_get(cachep);
99172
99173 check_irq_off();
99174 +
99175 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99176 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99177 + STATS_INC_NOT_SANITIZED(cachep);
99178 + else {
99179 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99180 +
99181 + if (cachep->ctor)
99182 + cachep->ctor(objp);
99183 +
99184 + STATS_INC_SANITIZED(cachep);
99185 + }
99186 +#endif
99187 +
99188 kmemleak_free_recursive(objp, cachep->flags);
99189 objp = cache_free_debugcheck(cachep, objp, caller);
99190
99191 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
99192
99193 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99194 return;
99195 + VM_BUG_ON(!virt_addr_valid(objp));
99196 local_irq_save(flags);
99197 kfree_debugcheck(objp);
99198 c = virt_to_cache(objp);
99199 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99200 }
99201 /* cpu stats */
99202 {
99203 - unsigned long allochit = atomic_read(&cachep->allochit);
99204 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99205 - unsigned long freehit = atomic_read(&cachep->freehit);
99206 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99207 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99208 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99209 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99210 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99211
99212 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99213 allochit, allocmiss, freehit, freemiss);
99214 }
99215 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99216 + {
99217 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99218 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99219 +
99220 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99221 + }
99222 +#endif
99223 #endif
99224 }
99225
99226 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
99227 static int __init slab_proc_init(void)
99228 {
99229 #ifdef CONFIG_DEBUG_SLAB_LEAK
99230 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99231 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99232 #endif
99233 return 0;
99234 }
99235 module_init(slab_proc_init);
99236 #endif
99237
99238 +bool is_usercopy_object(const void *ptr)
99239 +{
99240 + struct page *page;
99241 + struct kmem_cache *cachep;
99242 +
99243 + if (ZERO_OR_NULL_PTR(ptr))
99244 + return false;
99245 +
99246 + if (!slab_is_available())
99247 + return false;
99248 +
99249 + if (!virt_addr_valid(ptr))
99250 + return false;
99251 +
99252 + page = virt_to_head_page(ptr);
99253 +
99254 + if (!PageSlab(page))
99255 + return false;
99256 +
99257 + cachep = page->slab_cache;
99258 + return cachep->flags & SLAB_USERCOPY;
99259 +}
99260 +
99261 +#ifdef CONFIG_PAX_USERCOPY
99262 +const char *check_heap_object(const void *ptr, unsigned long n)
99263 +{
99264 + struct page *page;
99265 + struct kmem_cache *cachep;
99266 + unsigned int objnr;
99267 + unsigned long offset;
99268 +
99269 + if (ZERO_OR_NULL_PTR(ptr))
99270 + return "<null>";
99271 +
99272 + if (!virt_addr_valid(ptr))
99273 + return NULL;
99274 +
99275 + page = virt_to_head_page(ptr);
99276 +
99277 + if (!PageSlab(page))
99278 + return NULL;
99279 +
99280 + cachep = page->slab_cache;
99281 + if (!(cachep->flags & SLAB_USERCOPY))
99282 + return cachep->name;
99283 +
99284 + objnr = obj_to_index(cachep, page, ptr);
99285 + BUG_ON(objnr >= cachep->num);
99286 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99287 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99288 + return NULL;
99289 +
99290 + return cachep->name;
99291 +}
99292 +#endif
99293 +
99294 /**
99295 * ksize - get the actual amount of memory allocated for a given object
99296 * @objp: Pointer to the object
99297 diff --git a/mm/slab.h b/mm/slab.h
99298 index ab019e6..fbcac34 100644
99299 --- a/mm/slab.h
99300 +++ b/mm/slab.h
99301 @@ -22,7 +22,7 @@ struct kmem_cache {
99302 unsigned int align; /* Alignment as calculated */
99303 unsigned long flags; /* Active flags on the slab */
99304 const char *name; /* Slab name for sysfs */
99305 - int refcount; /* Use counter */
99306 + atomic_t refcount; /* Use counter */
99307 void (*ctor)(void *); /* Called on object slot creation */
99308 struct list_head list; /* List of all slab caches on the system */
99309 };
99310 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
99311 /* The slab cache that manages slab cache information */
99312 extern struct kmem_cache *kmem_cache;
99313
99314 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99315 +#ifdef CONFIG_X86_64
99316 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99317 +#else
99318 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99319 +#endif
99320 +enum pax_sanitize_mode {
99321 + PAX_SANITIZE_SLAB_OFF = 0,
99322 + PAX_SANITIZE_SLAB_FAST,
99323 + PAX_SANITIZE_SLAB_FULL,
99324 +};
99325 +extern enum pax_sanitize_mode pax_sanitize_slab;
99326 +#endif
99327 +
99328 unsigned long calculate_alignment(unsigned long flags,
99329 unsigned long align, unsigned long size);
99330
99331 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
99332
99333 /* Legal flag mask for kmem_cache_create(), for various configurations */
99334 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99335 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99336 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99337 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99338
99339 #if defined(CONFIG_DEBUG_SLAB)
99340 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99341 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99342 return s;
99343
99344 page = virt_to_head_page(x);
99345 +
99346 + BUG_ON(!PageSlab(page));
99347 +
99348 cachep = page->slab_cache;
99349 if (slab_equal_or_root(cachep, s))
99350 return cachep;
99351 diff --git a/mm/slab_common.c b/mm/slab_common.c
99352 index dcdab81..3576646 100644
99353 --- a/mm/slab_common.c
99354 +++ b/mm/slab_common.c
99355 @@ -25,11 +25,35 @@
99356
99357 #include "slab.h"
99358
99359 -enum slab_state slab_state;
99360 +enum slab_state slab_state __read_only;
99361 LIST_HEAD(slab_caches);
99362 DEFINE_MUTEX(slab_mutex);
99363 struct kmem_cache *kmem_cache;
99364
99365 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99366 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99367 +static int __init pax_sanitize_slab_setup(char *str)
99368 +{
99369 + if (!str)
99370 + return 0;
99371 +
99372 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99373 + pr_info("PaX slab sanitization: %s\n", "disabled");
99374 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99375 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99376 + pr_info("PaX slab sanitization: %s\n", "fast");
99377 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99378 + } else if (!strcmp(str, "full")) {
99379 + pr_info("PaX slab sanitization: %s\n", "full");
99380 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99381 + } else
99382 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99383 +
99384 + return 0;
99385 +}
99386 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99387 +#endif
99388 +
99389 /*
99390 * Set of flags that will prevent slab merging
99391 */
99392 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
99393 * Merge control. If this is set then no merging of slab caches will occur.
99394 * (Could be removed. This was introduced to pacify the merge skeptics.)
99395 */
99396 -static int slab_nomerge;
99397 +static int slab_nomerge = 1;
99398
99399 static int __init setup_slab_nomerge(char *str)
99400 {
99401 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
99402 /*
99403 * We may have set a slab to be unmergeable during bootstrap.
99404 */
99405 - if (s->refcount < 0)
99406 + if (atomic_read(&s->refcount) < 0)
99407 return 1;
99408
99409 return 0;
99410 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99411 if (err)
99412 goto out_free_cache;
99413
99414 - s->refcount = 1;
99415 + atomic_set(&s->refcount, 1);
99416 list_add(&s->list, &slab_caches);
99417 out:
99418 if (err)
99419 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99420 */
99421 flags &= CACHE_CREATE_MASK;
99422
99423 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99424 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99425 + flags |= SLAB_NO_SANITIZE;
99426 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99427 + flags &= ~SLAB_NO_SANITIZE;
99428 +#endif
99429 +
99430 s = __kmem_cache_alias(name, size, align, flags, ctor);
99431 if (s)
99432 goto out_unlock;
99433 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99434
99435 mutex_lock(&slab_mutex);
99436
99437 - s->refcount--;
99438 - if (s->refcount)
99439 + if (!atomic_dec_and_test(&s->refcount))
99440 goto out_unlock;
99441
99442 if (memcg_cleanup_cache_params(s) != 0)
99443 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99444 rcu_barrier();
99445
99446 memcg_free_cache_params(s);
99447 -#ifdef SLAB_SUPPORTS_SYSFS
99448 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99449 sysfs_slab_remove(s);
99450 #else
99451 slab_kmem_cache_release(s);
99452 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99453 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99454 name, size, err);
99455
99456 - s->refcount = -1; /* Exempt from merging for now */
99457 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99458 }
99459
99460 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99461 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99462
99463 create_boot_cache(s, name, size, flags);
99464 list_add(&s->list, &slab_caches);
99465 - s->refcount = 1;
99466 + atomic_set(&s->refcount, 1);
99467 return s;
99468 }
99469
99470 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99471 EXPORT_SYMBOL(kmalloc_dma_caches);
99472 #endif
99473
99474 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99475 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99476 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99477 +#endif
99478 +
99479 /*
99480 * Conversion table for small slabs sizes / 8 to the index in the
99481 * kmalloc array. This is necessary for slabs < 192 since we have non power
99482 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99483 return kmalloc_dma_caches[index];
99484
99485 #endif
99486 +
99487 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99488 + if (unlikely((flags & GFP_USERCOPY)))
99489 + return kmalloc_usercopy_caches[index];
99490 +
99491 +#endif
99492 +
99493 return kmalloc_caches[index];
99494 }
99495
99496 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99497 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99498 if (!kmalloc_caches[i]) {
99499 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99500 - 1 << i, flags);
99501 + 1 << i, SLAB_USERCOPY | flags);
99502 }
99503
99504 /*
99505 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99506 * earlier power of two caches
99507 */
99508 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99509 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99510 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99511
99512 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99513 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99514 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99515 }
99516
99517 /* Kmalloc array is now usable */
99518 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99519 }
99520 }
99521 #endif
99522 +
99523 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99524 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99525 + struct kmem_cache *s = kmalloc_caches[i];
99526 +
99527 + if (s) {
99528 + int size = kmalloc_size(i);
99529 + char *n = kasprintf(GFP_NOWAIT,
99530 + "usercopy-kmalloc-%d", size);
99531 +
99532 + BUG_ON(!n);
99533 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99534 + size, SLAB_USERCOPY | flags);
99535 + }
99536 + }
99537 +#endif
99538 +
99539 }
99540 #endif /* !CONFIG_SLOB */
99541
99542 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99543 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99544 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99545 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99546 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99547 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99548 +#endif
99549 #endif
99550 seq_putc(m, '\n');
99551 }
99552 diff --git a/mm/slob.c b/mm/slob.c
99553 index 96a8620..3e7e663 100644
99554 --- a/mm/slob.c
99555 +++ b/mm/slob.c
99556 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99557 /*
99558 * Return the size of a slob block.
99559 */
99560 -static slobidx_t slob_units(slob_t *s)
99561 +static slobidx_t slob_units(const slob_t *s)
99562 {
99563 if (s->units > 0)
99564 return s->units;
99565 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99566 /*
99567 * Return the next free slob block pointer after this one.
99568 */
99569 -static slob_t *slob_next(slob_t *s)
99570 +static slob_t *slob_next(const slob_t *s)
99571 {
99572 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99573 slobidx_t next;
99574 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99575 /*
99576 * Returns true if s is the last free block in its page.
99577 */
99578 -static int slob_last(slob_t *s)
99579 +static int slob_last(const slob_t *s)
99580 {
99581 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99582 }
99583
99584 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99585 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99586 {
99587 - void *page;
99588 + struct page *page;
99589
99590 #ifdef CONFIG_NUMA
99591 if (node != NUMA_NO_NODE)
99592 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99593 if (!page)
99594 return NULL;
99595
99596 - return page_address(page);
99597 + __SetPageSlab(page);
99598 + return page;
99599 }
99600
99601 -static void slob_free_pages(void *b, int order)
99602 +static void slob_free_pages(struct page *sp, int order)
99603 {
99604 if (current->reclaim_state)
99605 current->reclaim_state->reclaimed_slab += 1 << order;
99606 - free_pages((unsigned long)b, order);
99607 + __ClearPageSlab(sp);
99608 + page_mapcount_reset(sp);
99609 + sp->private = 0;
99610 + __free_pages(sp, order);
99611 }
99612
99613 /*
99614 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99615
99616 /* Not enough space: must allocate a new page */
99617 if (!b) {
99618 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99619 - if (!b)
99620 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99621 + if (!sp)
99622 return NULL;
99623 - sp = virt_to_page(b);
99624 - __SetPageSlab(sp);
99625 + b = page_address(sp);
99626
99627 spin_lock_irqsave(&slob_lock, flags);
99628 sp->units = SLOB_UNITS(PAGE_SIZE);
99629 sp->freelist = b;
99630 + sp->private = 0;
99631 INIT_LIST_HEAD(&sp->lru);
99632 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99633 set_slob_page_free(sp, slob_list);
99634 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99635 /*
99636 * slob_free: entry point into the slob allocator.
99637 */
99638 -static void slob_free(void *block, int size)
99639 +static void slob_free(struct kmem_cache *c, void *block, int size)
99640 {
99641 struct page *sp;
99642 slob_t *prev, *next, *b = (slob_t *)block;
99643 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99644 if (slob_page_free(sp))
99645 clear_slob_page_free(sp);
99646 spin_unlock_irqrestore(&slob_lock, flags);
99647 - __ClearPageSlab(sp);
99648 - page_mapcount_reset(sp);
99649 - slob_free_pages(b, 0);
99650 + slob_free_pages(sp, 0);
99651 return;
99652 }
99653
99654 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99655 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99656 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99657 +#endif
99658 +
99659 if (!slob_page_free(sp)) {
99660 /* This slob page is about to become partially free. Easy! */
99661 sp->units = units;
99662 @@ -424,11 +431,10 @@ out:
99663 */
99664
99665 static __always_inline void *
99666 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99667 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99668 {
99669 - unsigned int *m;
99670 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99671 - void *ret;
99672 + slob_t *m;
99673 + void *ret = NULL;
99674
99675 gfp &= gfp_allowed_mask;
99676
99677 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99678
99679 if (!m)
99680 return NULL;
99681 - *m = size;
99682 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99683 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99684 + m[0].units = size;
99685 + m[1].units = align;
99686 ret = (void *)m + align;
99687
99688 trace_kmalloc_node(caller, ret,
99689 size, size + align, gfp, node);
99690 } else {
99691 unsigned int order = get_order(size);
99692 + struct page *page;
99693
99694 if (likely(order))
99695 gfp |= __GFP_COMP;
99696 - ret = slob_new_pages(gfp, order, node);
99697 + page = slob_new_pages(gfp, order, node);
99698 + if (page) {
99699 + ret = page_address(page);
99700 + page->private = size;
99701 + }
99702
99703 trace_kmalloc_node(caller, ret,
99704 size, PAGE_SIZE << order, gfp, node);
99705 }
99706
99707 - kmemleak_alloc(ret, size, 1, gfp);
99708 + return ret;
99709 +}
99710 +
99711 +static __always_inline void *
99712 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99713 +{
99714 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99715 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99716 +
99717 + if (!ZERO_OR_NULL_PTR(ret))
99718 + kmemleak_alloc(ret, size, 1, gfp);
99719 return ret;
99720 }
99721
99722 @@ -491,34 +515,112 @@ void kfree(const void *block)
99723 return;
99724 kmemleak_free(block);
99725
99726 + VM_BUG_ON(!virt_addr_valid(block));
99727 sp = virt_to_page(block);
99728 - if (PageSlab(sp)) {
99729 + VM_BUG_ON(!PageSlab(sp));
99730 + if (!sp->private) {
99731 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99732 - unsigned int *m = (unsigned int *)(block - align);
99733 - slob_free(m, *m + align);
99734 - } else
99735 + slob_t *m = (slob_t *)(block - align);
99736 + slob_free(NULL, m, m[0].units + align);
99737 + } else {
99738 + __ClearPageSlab(sp);
99739 + page_mapcount_reset(sp);
99740 + sp->private = 0;
99741 __free_pages(sp, compound_order(sp));
99742 + }
99743 }
99744 EXPORT_SYMBOL(kfree);
99745
99746 +bool is_usercopy_object(const void *ptr)
99747 +{
99748 + if (!slab_is_available())
99749 + return false;
99750 +
99751 + // PAX: TODO
99752 +
99753 + return false;
99754 +}
99755 +
99756 +#ifdef CONFIG_PAX_USERCOPY
99757 +const char *check_heap_object(const void *ptr, unsigned long n)
99758 +{
99759 + struct page *page;
99760 + const slob_t *free;
99761 + const void *base;
99762 + unsigned long flags;
99763 +
99764 + if (ZERO_OR_NULL_PTR(ptr))
99765 + return "<null>";
99766 +
99767 + if (!virt_addr_valid(ptr))
99768 + return NULL;
99769 +
99770 + page = virt_to_head_page(ptr);
99771 + if (!PageSlab(page))
99772 + return NULL;
99773 +
99774 + if (page->private) {
99775 + base = page;
99776 + if (base <= ptr && n <= page->private - (ptr - base))
99777 + return NULL;
99778 + return "<slob>";
99779 + }
99780 +
99781 + /* some tricky double walking to find the chunk */
99782 + spin_lock_irqsave(&slob_lock, flags);
99783 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99784 + free = page->freelist;
99785 +
99786 + while (!slob_last(free) && (void *)free <= ptr) {
99787 + base = free + slob_units(free);
99788 + free = slob_next(free);
99789 + }
99790 +
99791 + while (base < (void *)free) {
99792 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99793 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99794 + int offset;
99795 +
99796 + if (ptr < base + align)
99797 + break;
99798 +
99799 + offset = ptr - base - align;
99800 + if (offset >= m) {
99801 + base += size;
99802 + continue;
99803 + }
99804 +
99805 + if (n > m - offset)
99806 + break;
99807 +
99808 + spin_unlock_irqrestore(&slob_lock, flags);
99809 + return NULL;
99810 + }
99811 +
99812 + spin_unlock_irqrestore(&slob_lock, flags);
99813 + return "<slob>";
99814 +}
99815 +#endif
99816 +
99817 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99818 size_t ksize(const void *block)
99819 {
99820 struct page *sp;
99821 int align;
99822 - unsigned int *m;
99823 + slob_t *m;
99824
99825 BUG_ON(!block);
99826 if (unlikely(block == ZERO_SIZE_PTR))
99827 return 0;
99828
99829 sp = virt_to_page(block);
99830 - if (unlikely(!PageSlab(sp)))
99831 - return PAGE_SIZE << compound_order(sp);
99832 + VM_BUG_ON(!PageSlab(sp));
99833 + if (sp->private)
99834 + return sp->private;
99835
99836 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99837 - m = (unsigned int *)(block - align);
99838 - return SLOB_UNITS(*m) * SLOB_UNIT;
99839 + m = (slob_t *)(block - align);
99840 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99841 }
99842 EXPORT_SYMBOL(ksize);
99843
99844 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99845
99846 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99847 {
99848 - void *b;
99849 + void *b = NULL;
99850
99851 flags &= gfp_allowed_mask;
99852
99853 lockdep_trace_alloc(flags);
99854
99855 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99856 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99857 +#else
99858 if (c->size < PAGE_SIZE) {
99859 b = slob_alloc(c->size, flags, c->align, node);
99860 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99861 SLOB_UNITS(c->size) * SLOB_UNIT,
99862 flags, node);
99863 } else {
99864 - b = slob_new_pages(flags, get_order(c->size), node);
99865 + struct page *sp;
99866 +
99867 + sp = slob_new_pages(flags, get_order(c->size), node);
99868 + if (sp) {
99869 + b = page_address(sp);
99870 + sp->private = c->size;
99871 + }
99872 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99873 PAGE_SIZE << get_order(c->size),
99874 flags, node);
99875 }
99876 +#endif
99877
99878 if (b && c->ctor)
99879 c->ctor(b);
99880 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99881 EXPORT_SYMBOL(kmem_cache_alloc_node);
99882 #endif
99883
99884 -static void __kmem_cache_free(void *b, int size)
99885 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99886 {
99887 - if (size < PAGE_SIZE)
99888 - slob_free(b, size);
99889 + struct page *sp;
99890 +
99891 + sp = virt_to_page(b);
99892 + BUG_ON(!PageSlab(sp));
99893 + if (!sp->private)
99894 + slob_free(c, b, size);
99895 else
99896 - slob_free_pages(b, get_order(size));
99897 + slob_free_pages(sp, get_order(size));
99898 }
99899
99900 static void kmem_rcu_free(struct rcu_head *head)
99901 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99902 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99903 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99904
99905 - __kmem_cache_free(b, slob_rcu->size);
99906 + __kmem_cache_free(NULL, b, slob_rcu->size);
99907 }
99908
99909 void kmem_cache_free(struct kmem_cache *c, void *b)
99910 {
99911 + int size = c->size;
99912 +
99913 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99914 + if (size + c->align < PAGE_SIZE) {
99915 + size += c->align;
99916 + b -= c->align;
99917 + }
99918 +#endif
99919 +
99920 kmemleak_free_recursive(b, c->flags);
99921 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99922 struct slob_rcu *slob_rcu;
99923 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99924 - slob_rcu->size = c->size;
99925 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99926 + slob_rcu->size = size;
99927 call_rcu(&slob_rcu->head, kmem_rcu_free);
99928 } else {
99929 - __kmem_cache_free(b, c->size);
99930 + __kmem_cache_free(c, b, size);
99931 }
99932
99933 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99934 + trace_kfree(_RET_IP_, b);
99935 +#else
99936 trace_kmem_cache_free(_RET_IP_, b);
99937 +#endif
99938 +
99939 }
99940 EXPORT_SYMBOL(kmem_cache_free);
99941
99942 diff --git a/mm/slub.c b/mm/slub.c
99943 index ae7b9f1..7b3fdbe 100644
99944 --- a/mm/slub.c
99945 +++ b/mm/slub.c
99946 @@ -197,7 +197,7 @@ struct track {
99947
99948 enum track_item { TRACK_ALLOC, TRACK_FREE };
99949
99950 -#ifdef CONFIG_SYSFS
99951 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99952 static int sysfs_slab_add(struct kmem_cache *);
99953 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99954 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99955 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99956 if (!t->addr)
99957 return;
99958
99959 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99960 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99961 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99962 #ifdef CONFIG_STACKTRACE
99963 {
99964 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99965
99966 slab_free_hook(s, x);
99967
99968 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99969 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99970 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99971 + if (s->ctor)
99972 + s->ctor(x);
99973 + }
99974 +#endif
99975 +
99976 redo:
99977 /*
99978 * Determine the currently cpus per cpu slab.
99979 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99980 s->inuse = size;
99981
99982 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99983 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99984 + (!(flags & SLAB_NO_SANITIZE)) ||
99985 +#endif
99986 s->ctor)) {
99987 /*
99988 * Relocate free pointer after the object if it is not
99989 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99990 EXPORT_SYMBOL(__kmalloc_node);
99991 #endif
99992
99993 +bool is_usercopy_object(const void *ptr)
99994 +{
99995 + struct page *page;
99996 + struct kmem_cache *s;
99997 +
99998 + if (ZERO_OR_NULL_PTR(ptr))
99999 + return false;
100000 +
100001 + if (!slab_is_available())
100002 + return false;
100003 +
100004 + if (!virt_addr_valid(ptr))
100005 + return false;
100006 +
100007 + page = virt_to_head_page(ptr);
100008 +
100009 + if (!PageSlab(page))
100010 + return false;
100011 +
100012 + s = page->slab_cache;
100013 + return s->flags & SLAB_USERCOPY;
100014 +}
100015 +
100016 +#ifdef CONFIG_PAX_USERCOPY
100017 +const char *check_heap_object(const void *ptr, unsigned long n)
100018 +{
100019 + struct page *page;
100020 + struct kmem_cache *s;
100021 + unsigned long offset;
100022 +
100023 + if (ZERO_OR_NULL_PTR(ptr))
100024 + return "<null>";
100025 +
100026 + if (!virt_addr_valid(ptr))
100027 + return NULL;
100028 +
100029 + page = virt_to_head_page(ptr);
100030 +
100031 + if (!PageSlab(page))
100032 + return NULL;
100033 +
100034 + s = page->slab_cache;
100035 + if (!(s->flags & SLAB_USERCOPY))
100036 + return s->name;
100037 +
100038 + offset = (ptr - page_address(page)) % s->size;
100039 + if (offset <= s->object_size && n <= s->object_size - offset)
100040 + return NULL;
100041 +
100042 + return s->name;
100043 +}
100044 +#endif
100045 +
100046 size_t ksize(const void *object)
100047 {
100048 struct page *page;
100049 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
100050 if (unlikely(ZERO_OR_NULL_PTR(x)))
100051 return;
100052
100053 + VM_BUG_ON(!virt_addr_valid(x));
100054 page = virt_to_head_page(x);
100055 if (unlikely(!PageSlab(page))) {
100056 BUG_ON(!PageCompound(page));
100057 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100058 int i;
100059 struct kmem_cache *c;
100060
100061 - s->refcount++;
100062 + atomic_inc(&s->refcount);
100063
100064 /*
100065 * Adjust the object sizes so that we clear
100066 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100067 }
100068
100069 if (sysfs_slab_alias(s, name)) {
100070 - s->refcount--;
100071 + atomic_dec(&s->refcount);
100072 s = NULL;
100073 }
100074 }
100075 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100076 }
100077 #endif
100078
100079 -#ifdef CONFIG_SYSFS
100080 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100081 static int count_inuse(struct page *page)
100082 {
100083 return page->inuse;
100084 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100085 len += sprintf(buf + len, "%7ld ", l->count);
100086
100087 if (l->addr)
100088 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100089 + len += sprintf(buf + len, "%pS", NULL);
100090 +#else
100091 len += sprintf(buf + len, "%pS", (void *)l->addr);
100092 +#endif
100093 else
100094 len += sprintf(buf + len, "<not-available>");
100095
100096 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
100097 validate_slab_cache(kmalloc_caches[9]);
100098 }
100099 #else
100100 -#ifdef CONFIG_SYSFS
100101 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100102 static void resiliency_test(void) {};
100103 #endif
100104 #endif
100105
100106 -#ifdef CONFIG_SYSFS
100107 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100108 enum slab_stat_type {
100109 SL_ALL, /* All slabs */
100110 SL_PARTIAL, /* Only partially allocated slabs */
100111 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100112 {
100113 if (!s->ctor)
100114 return 0;
100115 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100116 + return sprintf(buf, "%pS\n", NULL);
100117 +#else
100118 return sprintf(buf, "%pS\n", s->ctor);
100119 +#endif
100120 }
100121 SLAB_ATTR_RO(ctor);
100122
100123 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100124 {
100125 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100126 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100127 }
100128 SLAB_ATTR_RO(aliases);
100129
100130 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100131 SLAB_ATTR_RO(cache_dma);
100132 #endif
100133
100134 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100135 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100136 +{
100137 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100138 +}
100139 +SLAB_ATTR_RO(usercopy);
100140 +#endif
100141 +
100142 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100143 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100144 +{
100145 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100146 +}
100147 +SLAB_ATTR_RO(sanitize);
100148 +#endif
100149 +
100150 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100151 {
100152 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100153 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
100154 * as well as cause other issues like converting a mergeable
100155 * cache into an umergeable one.
100156 */
100157 - if (s->refcount > 1)
100158 + if (atomic_read(&s->refcount) > 1)
100159 return -EINVAL;
100160
100161 s->flags &= ~SLAB_TRACE;
100162 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
100163 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
100164 size_t length)
100165 {
100166 - if (s->refcount > 1)
100167 + if (atomic_read(&s->refcount) > 1)
100168 return -EINVAL;
100169
100170 s->flags &= ~SLAB_FAILSLAB;
100171 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
100172 #ifdef CONFIG_ZONE_DMA
100173 &cache_dma_attr.attr,
100174 #endif
100175 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100176 + &usercopy_attr.attr,
100177 +#endif
100178 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100179 + &sanitize_attr.attr,
100180 +#endif
100181 #ifdef CONFIG_NUMA
100182 &remote_node_defrag_ratio_attr.attr,
100183 #endif
100184 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
100185 return name;
100186 }
100187
100188 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100189 static int sysfs_slab_add(struct kmem_cache *s)
100190 {
100191 int err;
100192 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100193 kobject_del(&s->kobj);
100194 kobject_put(&s->kobj);
100195 }
100196 +#endif
100197
100198 /*
100199 * Need to buffer aliases during bootup until sysfs becomes
100200 @@ -5154,6 +5251,7 @@ struct saved_alias {
100201
100202 static struct saved_alias *alias_list;
100203
100204 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100205 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100206 {
100207 struct saved_alias *al;
100208 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100209 alias_list = al;
100210 return 0;
100211 }
100212 +#endif
100213
100214 static int __init slab_sysfs_init(void)
100215 {
100216 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100217 index 4cba9c2..b4f9fcc 100644
100218 --- a/mm/sparse-vmemmap.c
100219 +++ b/mm/sparse-vmemmap.c
100220 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100221 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100222 if (!p)
100223 return NULL;
100224 - pud_populate(&init_mm, pud, p);
100225 + pud_populate_kernel(&init_mm, pud, p);
100226 }
100227 return pud;
100228 }
100229 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100230 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100231 if (!p)
100232 return NULL;
100233 - pgd_populate(&init_mm, pgd, p);
100234 + pgd_populate_kernel(&init_mm, pgd, p);
100235 }
100236 return pgd;
100237 }
100238 diff --git a/mm/sparse.c b/mm/sparse.c
100239 index d1b48b6..6e8590e 100644
100240 --- a/mm/sparse.c
100241 +++ b/mm/sparse.c
100242 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100243
100244 for (i = 0; i < PAGES_PER_SECTION; i++) {
100245 if (PageHWPoison(&memmap[i])) {
100246 - atomic_long_sub(1, &num_poisoned_pages);
100247 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100248 ClearPageHWPoison(&memmap[i]);
100249 }
100250 }
100251 diff --git a/mm/swap.c b/mm/swap.c
100252 index 8a12b33..7068e78 100644
100253 --- a/mm/swap.c
100254 +++ b/mm/swap.c
100255 @@ -31,6 +31,7 @@
100256 #include <linux/memcontrol.h>
100257 #include <linux/gfp.h>
100258 #include <linux/uio.h>
100259 +#include <linux/hugetlb.h>
100260
100261 #include "internal.h"
100262
100263 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100264
100265 __page_cache_release(page);
100266 dtor = get_compound_page_dtor(page);
100267 + if (!PageHuge(page))
100268 + BUG_ON(dtor != free_compound_page);
100269 (*dtor)(page);
100270 }
100271
100272 diff --git a/mm/swapfile.c b/mm/swapfile.c
100273 index 8798b2e..348f9dd 100644
100274 --- a/mm/swapfile.c
100275 +++ b/mm/swapfile.c
100276 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100277
100278 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100279 /* Activity counter to indicate that a swapon or swapoff has occurred */
100280 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100281 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100282
100283 static inline unsigned char swap_count(unsigned char ent)
100284 {
100285 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100286 spin_unlock(&swap_lock);
100287
100288 err = 0;
100289 - atomic_inc(&proc_poll_event);
100290 + atomic_inc_unchecked(&proc_poll_event);
100291 wake_up_interruptible(&proc_poll_wait);
100292
100293 out_dput:
100294 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100295
100296 poll_wait(file, &proc_poll_wait, wait);
100297
100298 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100299 - seq->poll_event = atomic_read(&proc_poll_event);
100300 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100301 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100302 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100303 }
100304
100305 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100306 return ret;
100307
100308 seq = file->private_data;
100309 - seq->poll_event = atomic_read(&proc_poll_event);
100310 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100311 return 0;
100312 }
100313
100314 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100315 (frontswap_map) ? "FS" : "");
100316
100317 mutex_unlock(&swapon_mutex);
100318 - atomic_inc(&proc_poll_event);
100319 + atomic_inc_unchecked(&proc_poll_event);
100320 wake_up_interruptible(&proc_poll_wait);
100321
100322 if (S_ISREG(inode->i_mode))
100323 diff --git a/mm/util.c b/mm/util.c
100324 index fec39d4..3e60325 100644
100325 --- a/mm/util.c
100326 +++ b/mm/util.c
100327 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
100328 void arch_pick_mmap_layout(struct mm_struct *mm)
100329 {
100330 mm->mmap_base = TASK_UNMAPPED_BASE;
100331 +
100332 +#ifdef CONFIG_PAX_RANDMMAP
100333 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100334 + mm->mmap_base += mm->delta_mmap;
100335 +#endif
100336 +
100337 mm->get_unmapped_area = arch_get_unmapped_area;
100338 }
100339 #endif
100340 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100341 if (!mm->arg_end)
100342 goto out_mm; /* Shh! No looking before we're done */
100343
100344 + if (gr_acl_handle_procpidmem(task))
100345 + goto out_mm;
100346 +
100347 len = mm->arg_end - mm->arg_start;
100348
100349 if (len > buflen)
100350 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100351 index 90520af..24231aa 100644
100352 --- a/mm/vmalloc.c
100353 +++ b/mm/vmalloc.c
100354 @@ -40,6 +40,21 @@ struct vfree_deferred {
100355 };
100356 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100357
100358 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100359 +struct stack_deferred_llist {
100360 + struct llist_head list;
100361 + void *stack;
100362 + void *lowmem_stack;
100363 +};
100364 +
100365 +struct stack_deferred {
100366 + struct stack_deferred_llist list;
100367 + struct work_struct wq;
100368 +};
100369 +
100370 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100371 +#endif
100372 +
100373 static void __vunmap(const void *, int);
100374
100375 static void free_work(struct work_struct *w)
100376 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100377 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100378 struct llist_node *llnode = llist_del_all(&p->list);
100379 while (llnode) {
100380 - void *p = llnode;
100381 + void *x = llnode;
100382 llnode = llist_next(llnode);
100383 - __vunmap(p, 1);
100384 + __vunmap(x, 1);
100385 }
100386 }
100387
100388 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100389 +static void unmap_work(struct work_struct *w)
100390 +{
100391 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100392 + struct llist_node *llnode = llist_del_all(&p->list.list);
100393 + while (llnode) {
100394 + struct stack_deferred_llist *x =
100395 + llist_entry((struct llist_head *)llnode,
100396 + struct stack_deferred_llist, list);
100397 + void *stack = ACCESS_ONCE(x->stack);
100398 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100399 + llnode = llist_next(llnode);
100400 + __vunmap(stack, 0);
100401 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100402 + }
100403 +}
100404 +#endif
100405 +
100406 /*** Page table manipulation functions ***/
100407
100408 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100409 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100410
100411 pte = pte_offset_kernel(pmd, addr);
100412 do {
100413 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100414 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100415 +
100416 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100417 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100418 + BUG_ON(!pte_exec(*pte));
100419 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100420 + continue;
100421 + }
100422 +#endif
100423 +
100424 + {
100425 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100426 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100427 + }
100428 } while (pte++, addr += PAGE_SIZE, addr != end);
100429 }
100430
100431 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100432 pte = pte_alloc_kernel(pmd, addr);
100433 if (!pte)
100434 return -ENOMEM;
100435 +
100436 + pax_open_kernel();
100437 do {
100438 struct page *page = pages[*nr];
100439
100440 - if (WARN_ON(!pte_none(*pte)))
100441 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100442 + if (pgprot_val(prot) & _PAGE_NX)
100443 +#endif
100444 +
100445 + if (!pte_none(*pte)) {
100446 + pax_close_kernel();
100447 + WARN_ON(1);
100448 return -EBUSY;
100449 - if (WARN_ON(!page))
100450 + }
100451 + if (!page) {
100452 + pax_close_kernel();
100453 + WARN_ON(1);
100454 return -ENOMEM;
100455 + }
100456 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100457 (*nr)++;
100458 } while (pte++, addr += PAGE_SIZE, addr != end);
100459 + pax_close_kernel();
100460 return 0;
100461 }
100462
100463 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100464 pmd_t *pmd;
100465 unsigned long next;
100466
100467 - pmd = pmd_alloc(&init_mm, pud, addr);
100468 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100469 if (!pmd)
100470 return -ENOMEM;
100471 do {
100472 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100473 pud_t *pud;
100474 unsigned long next;
100475
100476 - pud = pud_alloc(&init_mm, pgd, addr);
100477 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100478 if (!pud)
100479 return -ENOMEM;
100480 do {
100481 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100482 if (addr >= MODULES_VADDR && addr < MODULES_END)
100483 return 1;
100484 #endif
100485 +
100486 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100487 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100488 + return 1;
100489 +#endif
100490 +
100491 return is_vmalloc_addr(x);
100492 }
100493
100494 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100495
100496 if (!pgd_none(*pgd)) {
100497 pud_t *pud = pud_offset(pgd, addr);
100498 +#ifdef CONFIG_X86
100499 + if (!pud_large(*pud))
100500 +#endif
100501 if (!pud_none(*pud)) {
100502 pmd_t *pmd = pmd_offset(pud, addr);
100503 +#ifdef CONFIG_X86
100504 + if (!pmd_large(*pmd))
100505 +#endif
100506 if (!pmd_none(*pmd)) {
100507 pte_t *ptep, pte;
100508
100509 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100510 for_each_possible_cpu(i) {
100511 struct vmap_block_queue *vbq;
100512 struct vfree_deferred *p;
100513 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100514 + struct stack_deferred *p2;
100515 +#endif
100516
100517 vbq = &per_cpu(vmap_block_queue, i);
100518 spin_lock_init(&vbq->lock);
100519 INIT_LIST_HEAD(&vbq->free);
100520 +
100521 p = &per_cpu(vfree_deferred, i);
100522 init_llist_head(&p->list);
100523 INIT_WORK(&p->wq, free_work);
100524 +
100525 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100526 + p2 = &per_cpu(stack_deferred, i);
100527 + init_llist_head(&p2->list.list);
100528 + INIT_WORK(&p2->wq, unmap_work);
100529 +#endif
100530 }
100531
100532 /* Import existing vmlist entries. */
100533 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100534 struct vm_struct *area;
100535
100536 BUG_ON(in_interrupt());
100537 +
100538 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100539 + if (flags & VM_KERNEXEC) {
100540 + if (start != VMALLOC_START || end != VMALLOC_END)
100541 + return NULL;
100542 + start = (unsigned long)MODULES_EXEC_VADDR;
100543 + end = (unsigned long)MODULES_EXEC_END;
100544 + }
100545 +#endif
100546 +
100547 if (flags & VM_IOREMAP)
100548 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100549
100550 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100551 }
100552 EXPORT_SYMBOL(vunmap);
100553
100554 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100555 +void unmap_process_stacks(struct task_struct *task)
100556 +{
100557 + if (unlikely(in_interrupt())) {
100558 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100559 + struct stack_deferred_llist *list = task->stack;
100560 + list->stack = task->stack;
100561 + list->lowmem_stack = task->lowmem_stack;
100562 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100563 + schedule_work(&p->wq);
100564 + } else {
100565 + __vunmap(task->stack, 0);
100566 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100567 + }
100568 +}
100569 +#endif
100570 +
100571 /**
100572 * vmap - map an array of pages into virtually contiguous space
100573 * @pages: array of page pointers
100574 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100575 if (count > totalram_pages)
100576 return NULL;
100577
100578 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100579 + if (!(pgprot_val(prot) & _PAGE_NX))
100580 + flags |= VM_KERNEXEC;
100581 +#endif
100582 +
100583 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100584 __builtin_return_address(0));
100585 if (!area)
100586 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100587 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100588 goto fail;
100589
100590 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100591 + if (!(pgprot_val(prot) & _PAGE_NX))
100592 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100593 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100594 + else
100595 +#endif
100596 +
100597 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100598 start, end, node, gfp_mask, caller);
100599 if (!area)
100600 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100601 * For tight control over page level allocator and protection flags
100602 * use __vmalloc() instead.
100603 */
100604 -
100605 void *vmalloc_exec(unsigned long size)
100606 {
100607 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100608 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100609 NUMA_NO_NODE, __builtin_return_address(0));
100610 }
100611
100612 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100613 {
100614 struct vm_struct *area;
100615
100616 + BUG_ON(vma->vm_mirror);
100617 +
100618 size = PAGE_ALIGN(size);
100619
100620 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100621 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100622 v->addr, v->addr + v->size, v->size);
100623
100624 if (v->caller)
100625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100626 + seq_printf(m, " %pK", v->caller);
100627 +#else
100628 seq_printf(m, " %pS", v->caller);
100629 +#endif
100630
100631 if (v->nr_pages)
100632 seq_printf(m, " pages=%d", v->nr_pages);
100633 diff --git a/mm/vmstat.c b/mm/vmstat.c
100634 index 1b12d39..57b29b2 100644
100635 --- a/mm/vmstat.c
100636 +++ b/mm/vmstat.c
100637 @@ -22,6 +22,7 @@
100638 #include <linux/writeback.h>
100639 #include <linux/compaction.h>
100640 #include <linux/mm_inline.h>
100641 +#include <linux/grsecurity.h>
100642
100643 #include "internal.h"
100644
100645 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100646 *
100647 * vm_stat contains the global counters
100648 */
100649 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100650 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100651 EXPORT_SYMBOL(vm_stat);
100652
100653 #ifdef CONFIG_SMP
100654 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100655
100656 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100657 if (diff[i]) {
100658 - atomic_long_add(diff[i], &vm_stat[i]);
100659 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100660 changes++;
100661 }
100662 return changes;
100663 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100664 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100665 if (v) {
100666
100667 - atomic_long_add(v, &zone->vm_stat[i]);
100668 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100669 global_diff[i] += v;
100670 #ifdef CONFIG_NUMA
100671 /* 3 seconds idle till flush */
100672 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100673
100674 v = p->vm_stat_diff[i];
100675 p->vm_stat_diff[i] = 0;
100676 - atomic_long_add(v, &zone->vm_stat[i]);
100677 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100678 global_diff[i] += v;
100679 }
100680 }
100681 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100682 if (pset->vm_stat_diff[i]) {
100683 int v = pset->vm_stat_diff[i];
100684 pset->vm_stat_diff[i] = 0;
100685 - atomic_long_add(v, &zone->vm_stat[i]);
100686 - atomic_long_add(v, &vm_stat[i]);
100687 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100688 + atomic_long_add_unchecked(v, &vm_stat[i]);
100689 }
100690 }
100691 #endif
100692 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100693 stat_items_size += sizeof(struct vm_event_state);
100694 #endif
100695
100696 - v = kmalloc(stat_items_size, GFP_KERNEL);
100697 + v = kzalloc(stat_items_size, GFP_KERNEL);
100698 m->private = v;
100699 if (!v)
100700 return ERR_PTR(-ENOMEM);
100701 +
100702 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100703 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100704 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100705 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100706 + && !in_group_p(grsec_proc_gid)
100707 +#endif
100708 + )
100709 + return (unsigned long *)m->private + *pos;
100710 +#endif
100711 +#endif
100712 +
100713 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100714 v[i] = global_page_state(i);
100715 v += NR_VM_ZONE_STAT_ITEMS;
100716 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100717 cpu_notifier_register_done();
100718 #endif
100719 #ifdef CONFIG_PROC_FS
100720 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100721 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100722 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100723 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100724 + {
100725 + mode_t gr_mode = S_IRUGO;
100726 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100727 + gr_mode = S_IRUSR;
100728 +#endif
100729 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100730 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100731 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100732 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100733 + }
100734 #endif
100735 return 0;
100736 }
100737 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100738 index 64c6bed..b79a5de 100644
100739 --- a/net/8021q/vlan.c
100740 +++ b/net/8021q/vlan.c
100741 @@ -481,7 +481,7 @@ out:
100742 return NOTIFY_DONE;
100743 }
100744
100745 -static struct notifier_block vlan_notifier_block __read_mostly = {
100746 +static struct notifier_block vlan_notifier_block = {
100747 .notifier_call = vlan_device_event,
100748 };
100749
100750 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100751 err = -EPERM;
100752 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100753 break;
100754 - if ((args.u.name_type >= 0) &&
100755 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100756 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100757 struct vlan_net *vn;
100758
100759 vn = net_generic(net, vlan_net_id);
100760 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100761 index 8ac8a5c..991defc 100644
100762 --- a/net/8021q/vlan_netlink.c
100763 +++ b/net/8021q/vlan_netlink.c
100764 @@ -238,7 +238,7 @@ nla_put_failure:
100765 return -EMSGSIZE;
100766 }
100767
100768 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100769 +struct rtnl_link_ops vlan_link_ops = {
100770 .kind = "vlan",
100771 .maxtype = IFLA_VLAN_MAX,
100772 .policy = vlan_policy,
100773 diff --git a/net/9p/client.c b/net/9p/client.c
100774 index e86a9bea..e91f70e 100644
100775 --- a/net/9p/client.c
100776 +++ b/net/9p/client.c
100777 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100778 len - inline_len);
100779 } else {
100780 err = copy_from_user(ename + inline_len,
100781 - uidata, len - inline_len);
100782 + (char __force_user *)uidata, len - inline_len);
100783 if (err) {
100784 err = -EFAULT;
100785 goto out_err;
100786 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100787 kernel_buf = 1;
100788 indata = data;
100789 } else
100790 - indata = (__force char *)udata;
100791 + indata = (__force_kernel char *)udata;
100792 /*
100793 * response header len is 11
100794 * PDU Header(7) + IO Size (4)
100795 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100796 kernel_buf = 1;
100797 odata = data;
100798 } else
100799 - odata = (char *)udata;
100800 + odata = (char __force_kernel *)udata;
100801 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100802 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100803 fid->fid, offset, rsize);
100804 diff --git a/net/9p/mod.c b/net/9p/mod.c
100805 index 6ab36ae..6f1841b 100644
100806 --- a/net/9p/mod.c
100807 +++ b/net/9p/mod.c
100808 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100809 void v9fs_register_trans(struct p9_trans_module *m)
100810 {
100811 spin_lock(&v9fs_trans_lock);
100812 - list_add_tail(&m->list, &v9fs_trans_list);
100813 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100814 spin_unlock(&v9fs_trans_lock);
100815 }
100816 EXPORT_SYMBOL(v9fs_register_trans);
100817 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100818 void v9fs_unregister_trans(struct p9_trans_module *m)
100819 {
100820 spin_lock(&v9fs_trans_lock);
100821 - list_del_init(&m->list);
100822 + pax_list_del_init((struct list_head *)&m->list);
100823 spin_unlock(&v9fs_trans_lock);
100824 }
100825 EXPORT_SYMBOL(v9fs_unregister_trans);
100826 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100827 index 80d08f6..de63fd1 100644
100828 --- a/net/9p/trans_fd.c
100829 +++ b/net/9p/trans_fd.c
100830 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100831 oldfs = get_fs();
100832 set_fs(get_ds());
100833 /* The cast to a user pointer is valid due to the set_fs() */
100834 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100835 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100836 set_fs(oldfs);
100837
100838 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100839 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100840 index af46bc4..f9adfcd 100644
100841 --- a/net/appletalk/atalk_proc.c
100842 +++ b/net/appletalk/atalk_proc.c
100843 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100844 struct proc_dir_entry *p;
100845 int rc = -ENOMEM;
100846
100847 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100848 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100849 if (!atalk_proc_dir)
100850 goto out;
100851
100852 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100853 index 876fbe8..8bbea9f 100644
100854 --- a/net/atm/atm_misc.c
100855 +++ b/net/atm/atm_misc.c
100856 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100857 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100858 return 1;
100859 atm_return(vcc, truesize);
100860 - atomic_inc(&vcc->stats->rx_drop);
100861 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100862 return 0;
100863 }
100864 EXPORT_SYMBOL(atm_charge);
100865 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100866 }
100867 }
100868 atm_return(vcc, guess);
100869 - atomic_inc(&vcc->stats->rx_drop);
100870 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100871 return NULL;
100872 }
100873 EXPORT_SYMBOL(atm_alloc_charge);
100874 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100875
100876 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100877 {
100878 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100879 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100880 __SONET_ITEMS
100881 #undef __HANDLE_ITEM
100882 }
100883 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100884
100885 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100886 {
100887 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100888 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100889 __SONET_ITEMS
100890 #undef __HANDLE_ITEM
100891 }
100892 diff --git a/net/atm/lec.c b/net/atm/lec.c
100893 index 4b98f89..5a2f6cb 100644
100894 --- a/net/atm/lec.c
100895 +++ b/net/atm/lec.c
100896 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100897 }
100898
100899 static struct lane2_ops lane2_ops = {
100900 - lane2_resolve, /* resolve, spec 3.1.3 */
100901 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100902 - NULL /* associate indicator, spec 3.1.5 */
100903 + .resolve = lane2_resolve,
100904 + .associate_req = lane2_associate_req,
100905 + .associate_indicator = NULL
100906 };
100907
100908 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100909 diff --git a/net/atm/lec.h b/net/atm/lec.h
100910 index 4149db1..f2ab682 100644
100911 --- a/net/atm/lec.h
100912 +++ b/net/atm/lec.h
100913 @@ -48,7 +48,7 @@ struct lane2_ops {
100914 const u8 *tlvs, u32 sizeoftlvs);
100915 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100916 const u8 *tlvs, u32 sizeoftlvs);
100917 -};
100918 +} __no_const;
100919
100920 /*
100921 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100922 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100923 index d1b2d9a..d549f7f 100644
100924 --- a/net/atm/mpoa_caches.c
100925 +++ b/net/atm/mpoa_caches.c
100926 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100927
100928
100929 static struct in_cache_ops ingress_ops = {
100930 - in_cache_add_entry, /* add_entry */
100931 - in_cache_get, /* get */
100932 - in_cache_get_with_mask, /* get_with_mask */
100933 - in_cache_get_by_vcc, /* get_by_vcc */
100934 - in_cache_put, /* put */
100935 - in_cache_remove_entry, /* remove_entry */
100936 - cache_hit, /* cache_hit */
100937 - clear_count_and_expired, /* clear_count */
100938 - check_resolving_entries, /* check_resolving */
100939 - refresh_entries, /* refresh */
100940 - in_destroy_cache /* destroy_cache */
100941 + .add_entry = in_cache_add_entry,
100942 + .get = in_cache_get,
100943 + .get_with_mask = in_cache_get_with_mask,
100944 + .get_by_vcc = in_cache_get_by_vcc,
100945 + .put = in_cache_put,
100946 + .remove_entry = in_cache_remove_entry,
100947 + .cache_hit = cache_hit,
100948 + .clear_count = clear_count_and_expired,
100949 + .check_resolving = check_resolving_entries,
100950 + .refresh = refresh_entries,
100951 + .destroy_cache = in_destroy_cache
100952 };
100953
100954 static struct eg_cache_ops egress_ops = {
100955 - eg_cache_add_entry, /* add_entry */
100956 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100957 - eg_cache_get_by_tag, /* get_by_tag */
100958 - eg_cache_get_by_vcc, /* get_by_vcc */
100959 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100960 - eg_cache_put, /* put */
100961 - eg_cache_remove_entry, /* remove_entry */
100962 - update_eg_cache_entry, /* update */
100963 - clear_expired, /* clear_expired */
100964 - eg_destroy_cache /* destroy_cache */
100965 + .add_entry = eg_cache_add_entry,
100966 + .get_by_cache_id = eg_cache_get_by_cache_id,
100967 + .get_by_tag = eg_cache_get_by_tag,
100968 + .get_by_vcc = eg_cache_get_by_vcc,
100969 + .get_by_src_ip = eg_cache_get_by_src_ip,
100970 + .put = eg_cache_put,
100971 + .remove_entry = eg_cache_remove_entry,
100972 + .update = update_eg_cache_entry,
100973 + .clear_expired = clear_expired,
100974 + .destroy_cache = eg_destroy_cache
100975 };
100976
100977
100978 diff --git a/net/atm/proc.c b/net/atm/proc.c
100979 index bbb6461..cf04016 100644
100980 --- a/net/atm/proc.c
100981 +++ b/net/atm/proc.c
100982 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100983 const struct k_atm_aal_stats *stats)
100984 {
100985 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100986 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100987 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100988 - atomic_read(&stats->rx_drop));
100989 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100990 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100991 + atomic_read_unchecked(&stats->rx_drop));
100992 }
100993
100994 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100995 diff --git a/net/atm/resources.c b/net/atm/resources.c
100996 index 0447d5d..3cf4728 100644
100997 --- a/net/atm/resources.c
100998 +++ b/net/atm/resources.c
100999 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
101000 static void copy_aal_stats(struct k_atm_aal_stats *from,
101001 struct atm_aal_stats *to)
101002 {
101003 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101004 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101005 __AAL_STAT_ITEMS
101006 #undef __HANDLE_ITEM
101007 }
101008 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
101009 static void subtract_aal_stats(struct k_atm_aal_stats *from,
101010 struct atm_aal_stats *to)
101011 {
101012 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101013 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
101014 __AAL_STAT_ITEMS
101015 #undef __HANDLE_ITEM
101016 }
101017 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
101018 index 919a5ce..cc6b444 100644
101019 --- a/net/ax25/sysctl_net_ax25.c
101020 +++ b/net/ax25/sysctl_net_ax25.c
101021 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
101022 {
101023 char path[sizeof("net/ax25/") + IFNAMSIZ];
101024 int k;
101025 - struct ctl_table *table;
101026 + ctl_table_no_const *table;
101027
101028 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
101029 if (!table)
101030 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
101031 index 1e80539..676c37a 100644
101032 --- a/net/batman-adv/bat_iv_ogm.c
101033 +++ b/net/batman-adv/bat_iv_ogm.c
101034 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
101035
101036 /* randomize initial seqno to avoid collision */
101037 get_random_bytes(&random_seqno, sizeof(random_seqno));
101038 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101039 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101040
101041 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
101042 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
101043 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
101044 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
101045
101046 /* change sequence number to network order */
101047 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
101048 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
101049 batadv_ogm_packet->seqno = htonl(seqno);
101050 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
101051 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
101052
101053 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
101054
101055 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
101056 return;
101057
101058 /* could be changed by schedule_own_packet() */
101059 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
101060 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
101061
101062 if (ogm_packet->flags & BATADV_DIRECTLINK)
101063 has_directlink_flag = true;
101064 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
101065 index 00f9e14..e1c7203 100644
101066 --- a/net/batman-adv/fragmentation.c
101067 +++ b/net/batman-adv/fragmentation.c
101068 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101069 frag_header.packet_type = BATADV_UNICAST_FRAG;
101070 frag_header.version = BATADV_COMPAT_VERSION;
101071 frag_header.ttl = BATADV_TTL;
101072 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101073 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101074 frag_header.reserved = 0;
101075 frag_header.no = 0;
101076 frag_header.total_size = htons(skb->len);
101077 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101078 index 5467955..75ad4e3 100644
101079 --- a/net/batman-adv/soft-interface.c
101080 +++ b/net/batman-adv/soft-interface.c
101081 @@ -296,7 +296,7 @@ send:
101082 primary_if->net_dev->dev_addr);
101083
101084 /* set broadcast sequence number */
101085 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101086 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101087 bcast_packet->seqno = htonl(seqno);
101088
101089 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101090 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101091 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101092
101093 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101094 - atomic_set(&bat_priv->bcast_seqno, 1);
101095 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101096 atomic_set(&bat_priv->tt.vn, 0);
101097 atomic_set(&bat_priv->tt.local_changes, 0);
101098 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101099 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101100
101101 /* randomize initial seqno to avoid collision */
101102 get_random_bytes(&random_seqno, sizeof(random_seqno));
101103 - atomic_set(&bat_priv->frag_seqno, random_seqno);
101104 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101105
101106 bat_priv->primary_if = NULL;
101107 bat_priv->num_ifaces = 0;
101108 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
101109 return 0;
101110 }
101111
101112 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
101113 +struct rtnl_link_ops batadv_link_ops = {
101114 .kind = "batadv",
101115 .priv_size = sizeof(struct batadv_priv),
101116 .setup = batadv_softif_init_early,
101117 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101118 index 8854c05..ee5d5497 100644
101119 --- a/net/batman-adv/types.h
101120 +++ b/net/batman-adv/types.h
101121 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101122 struct batadv_hard_iface_bat_iv {
101123 unsigned char *ogm_buff;
101124 int ogm_buff_len;
101125 - atomic_t ogm_seqno;
101126 + atomic_unchecked_t ogm_seqno;
101127 };
101128
101129 /**
101130 @@ -768,7 +768,7 @@ struct batadv_priv {
101131 atomic_t bonding;
101132 atomic_t fragmentation;
101133 atomic_t packet_size_max;
101134 - atomic_t frag_seqno;
101135 + atomic_unchecked_t frag_seqno;
101136 #ifdef CONFIG_BATMAN_ADV_BLA
101137 atomic_t bridge_loop_avoidance;
101138 #endif
101139 @@ -787,7 +787,7 @@ struct batadv_priv {
101140 #endif
101141 uint32_t isolation_mark;
101142 uint32_t isolation_mark_mask;
101143 - atomic_t bcast_seqno;
101144 + atomic_unchecked_t bcast_seqno;
101145 atomic_t bcast_queue_left;
101146 atomic_t batman_queue_left;
101147 char num_ifaces;
101148 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
101149 index cfbb39e..0bbfc9d 100644
101150 --- a/net/bluetooth/6lowpan.c
101151 +++ b/net/bluetooth/6lowpan.c
101152 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
101153
101154 drop:
101155 dev->stats.rx_dropped++;
101156 - kfree_skb(skb);
101157 return NET_RX_DROP;
101158 }
101159
101160 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
101161 index 85bcc21..ce82722d 100644
101162 --- a/net/bluetooth/bnep/core.c
101163 +++ b/net/bluetooth/bnep/core.c
101164 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
101165
101166 BT_DBG("");
101167
101168 + if (!l2cap_is_socket(sock))
101169 + return -EBADFD;
101170 +
101171 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
101172 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
101173
101174 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
101175 index 67fe5e8..278a194 100644
101176 --- a/net/bluetooth/cmtp/core.c
101177 +++ b/net/bluetooth/cmtp/core.c
101178 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
101179
101180 BT_DBG("");
101181
101182 + if (!l2cap_is_socket(sock))
101183 + return -EBADFD;
101184 +
101185 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
101186 if (!session)
101187 return -ENOMEM;
101188 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101189 index 115f149..f0ba286 100644
101190 --- a/net/bluetooth/hci_sock.c
101191 +++ b/net/bluetooth/hci_sock.c
101192 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101193 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101194 }
101195
101196 - len = min_t(unsigned int, len, sizeof(uf));
101197 + len = min((size_t)len, sizeof(uf));
101198 if (copy_from_user(&uf, optval, len)) {
101199 err = -EFAULT;
101200 break;
101201 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
101202 index 1b7d605..02ebd10 100644
101203 --- a/net/bluetooth/hidp/core.c
101204 +++ b/net/bluetooth/hidp/core.c
101205 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
101206 {
101207 struct hidp_session *session;
101208 struct l2cap_conn *conn;
101209 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
101210 + struct l2cap_chan *chan;
101211 int ret;
101212
101213 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
101214 if (ret)
101215 return ret;
101216
101217 + chan = l2cap_pi(ctrl_sock->sk)->chan;
101218 conn = NULL;
101219 l2cap_chan_lock(chan);
101220 if (chan->conn)
101221 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101222 index b6f9777..36d3039 100644
101223 --- a/net/bluetooth/l2cap_core.c
101224 +++ b/net/bluetooth/l2cap_core.c
101225 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101226 break;
101227
101228 case L2CAP_CONF_RFC:
101229 - if (olen == sizeof(rfc))
101230 - memcpy(&rfc, (void *)val, olen);
101231 + if (olen != sizeof(rfc))
101232 + break;
101233 +
101234 + memcpy(&rfc, (void *)val, olen);
101235
101236 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101237 rfc.mode != chan->mode)
101238 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101239 index 31f106e..323f606 100644
101240 --- a/net/bluetooth/l2cap_sock.c
101241 +++ b/net/bluetooth/l2cap_sock.c
101242 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101243 struct sock *sk = sock->sk;
101244 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101245 struct l2cap_options opts;
101246 - int len, err = 0;
101247 + int err = 0;
101248 + size_t len = optlen;
101249 u32 opt;
101250
101251 BT_DBG("sk %p", sk);
101252 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101253 opts.max_tx = chan->max_tx;
101254 opts.txwin_size = chan->tx_win;
101255
101256 - len = min_t(unsigned int, sizeof(opts), optlen);
101257 + len = min(sizeof(opts), len);
101258 if (copy_from_user((char *) &opts, optval, len)) {
101259 err = -EFAULT;
101260 break;
101261 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101262 struct bt_security sec;
101263 struct bt_power pwr;
101264 struct l2cap_conn *conn;
101265 - int len, err = 0;
101266 + int err = 0;
101267 + size_t len = optlen;
101268 u32 opt;
101269
101270 BT_DBG("sk %p", sk);
101271 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101272
101273 sec.level = BT_SECURITY_LOW;
101274
101275 - len = min_t(unsigned int, sizeof(sec), optlen);
101276 + len = min(sizeof(sec), len);
101277 if (copy_from_user((char *) &sec, optval, len)) {
101278 err = -EFAULT;
101279 break;
101280 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101281
101282 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101283
101284 - len = min_t(unsigned int, sizeof(pwr), optlen);
101285 + len = min(sizeof(pwr), len);
101286 if (copy_from_user((char *) &pwr, optval, len)) {
101287 err = -EFAULT;
101288 break;
101289 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101290 index 8bbbb5e..6fc0950 100644
101291 --- a/net/bluetooth/rfcomm/sock.c
101292 +++ b/net/bluetooth/rfcomm/sock.c
101293 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101294 struct sock *sk = sock->sk;
101295 struct bt_security sec;
101296 int err = 0;
101297 - size_t len;
101298 + size_t len = optlen;
101299 u32 opt;
101300
101301 BT_DBG("sk %p", sk);
101302 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101303
101304 sec.level = BT_SECURITY_LOW;
101305
101306 - len = min_t(unsigned int, sizeof(sec), optlen);
101307 + len = min(sizeof(sec), len);
101308 if (copy_from_user((char *) &sec, optval, len)) {
101309 err = -EFAULT;
101310 break;
101311 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101312 index 8e385a0..a5bdd8e 100644
101313 --- a/net/bluetooth/rfcomm/tty.c
101314 +++ b/net/bluetooth/rfcomm/tty.c
101315 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101316 BT_DBG("tty %p id %d", tty, tty->index);
101317
101318 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101319 - dev->channel, dev->port.count);
101320 + dev->channel, atomic_read(&dev->port.count));
101321
101322 err = tty_port_open(&dev->port, tty, filp);
101323 if (err)
101324 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101325 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101326
101327 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101328 - dev->port.count);
101329 + atomic_read(&dev->port.count));
101330
101331 tty_port_close(&dev->port, tty, filp);
101332 }
101333 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101334 index e5ec470..cbfabd1 100644
101335 --- a/net/bridge/br_netlink.c
101336 +++ b/net/bridge/br_netlink.c
101337 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
101338 .get_link_af_size = br_get_link_af_size,
101339 };
101340
101341 -struct rtnl_link_ops br_link_ops __read_mostly = {
101342 +struct rtnl_link_ops br_link_ops = {
101343 .kind = "bridge",
101344 .priv_size = sizeof(struct net_bridge),
101345 .setup = br_dev_setup,
101346 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101347 index d9a8c05..8dadc6c6 100644
101348 --- a/net/bridge/netfilter/ebtables.c
101349 +++ b/net/bridge/netfilter/ebtables.c
101350 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101351 tmp.valid_hooks = t->table->valid_hooks;
101352 }
101353 mutex_unlock(&ebt_mutex);
101354 - if (copy_to_user(user, &tmp, *len) != 0) {
101355 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101356 BUGPRINT("c2u Didn't work\n");
101357 ret = -EFAULT;
101358 break;
101359 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101360 goto out;
101361 tmp.valid_hooks = t->valid_hooks;
101362
101363 - if (copy_to_user(user, &tmp, *len) != 0) {
101364 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101365 ret = -EFAULT;
101366 break;
101367 }
101368 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101369 tmp.entries_size = t->table->entries_size;
101370 tmp.valid_hooks = t->table->valid_hooks;
101371
101372 - if (copy_to_user(user, &tmp, *len) != 0) {
101373 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101374 ret = -EFAULT;
101375 break;
101376 }
101377 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101378 index f5afda1..dcf770a 100644
101379 --- a/net/caif/cfctrl.c
101380 +++ b/net/caif/cfctrl.c
101381 @@ -10,6 +10,7 @@
101382 #include <linux/spinlock.h>
101383 #include <linux/slab.h>
101384 #include <linux/pkt_sched.h>
101385 +#include <linux/sched.h>
101386 #include <net/caif/caif_layer.h>
101387 #include <net/caif/cfpkt.h>
101388 #include <net/caif/cfctrl.h>
101389 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101390 memset(&dev_info, 0, sizeof(dev_info));
101391 dev_info.id = 0xff;
101392 cfsrvl_init(&this->serv, 0, &dev_info, false);
101393 - atomic_set(&this->req_seq_no, 1);
101394 - atomic_set(&this->rsp_seq_no, 1);
101395 + atomic_set_unchecked(&this->req_seq_no, 1);
101396 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101397 this->serv.layer.receive = cfctrl_recv;
101398 sprintf(this->serv.layer.name, "ctrl");
101399 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101400 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101401 struct cfctrl_request_info *req)
101402 {
101403 spin_lock_bh(&ctrl->info_list_lock);
101404 - atomic_inc(&ctrl->req_seq_no);
101405 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101406 + atomic_inc_unchecked(&ctrl->req_seq_no);
101407 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101408 list_add_tail(&req->list, &ctrl->list);
101409 spin_unlock_bh(&ctrl->info_list_lock);
101410 }
101411 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101412 if (p != first)
101413 pr_warn("Requests are not received in order\n");
101414
101415 - atomic_set(&ctrl->rsp_seq_no,
101416 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101417 p->sequence_no);
101418 list_del(&p->list);
101419 goto out;
101420 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101421 index 4589ff67..46d6b8f 100644
101422 --- a/net/caif/chnl_net.c
101423 +++ b/net/caif/chnl_net.c
101424 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101425 };
101426
101427
101428 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101429 +static struct rtnl_link_ops ipcaif_link_ops = {
101430 .kind = "caif",
101431 .priv_size = sizeof(struct chnl_net),
101432 .setup = ipcaif_net_setup,
101433 diff --git a/net/can/af_can.c b/net/can/af_can.c
101434 index ce82337..5d17b4d 100644
101435 --- a/net/can/af_can.c
101436 +++ b/net/can/af_can.c
101437 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101438 };
101439
101440 /* notifier block for netdevice event */
101441 -static struct notifier_block can_netdev_notifier __read_mostly = {
101442 +static struct notifier_block can_netdev_notifier = {
101443 .notifier_call = can_notifier,
101444 };
101445
101446 diff --git a/net/can/bcm.c b/net/can/bcm.c
101447 index dcb75c0..24b1b43 100644
101448 --- a/net/can/bcm.c
101449 +++ b/net/can/bcm.c
101450 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101451 }
101452
101453 /* create /proc/net/can-bcm directory */
101454 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101455 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101456 return 0;
101457 }
101458
101459 diff --git a/net/can/gw.c b/net/can/gw.c
101460 index 050a211..bb9fe33 100644
101461 --- a/net/can/gw.c
101462 +++ b/net/can/gw.c
101463 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101464 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101465
101466 static HLIST_HEAD(cgw_list);
101467 -static struct notifier_block notifier;
101468
101469 static struct kmem_cache *cgw_cache __read_mostly;
101470
101471 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101472 return err;
101473 }
101474
101475 +static struct notifier_block notifier = {
101476 + .notifier_call = cgw_notifier
101477 +};
101478 +
101479 static __init int cgw_module_init(void)
101480 {
101481 /* sanitize given module parameter */
101482 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101483 return -ENOMEM;
101484
101485 /* set notifier */
101486 - notifier.notifier_call = cgw_notifier;
101487 register_netdevice_notifier(&notifier);
101488
101489 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101490 diff --git a/net/can/proc.c b/net/can/proc.c
101491 index 1a19b98..df2b4ec 100644
101492 --- a/net/can/proc.c
101493 +++ b/net/can/proc.c
101494 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101495 void can_init_proc(void)
101496 {
101497 /* create /proc/net/can directory */
101498 - can_dir = proc_mkdir("can", init_net.proc_net);
101499 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101500
101501 if (!can_dir) {
101502 printk(KERN_INFO "can: failed to create /proc/net/can . "
101503 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101504 index 8d1653c..77ad145 100644
101505 --- a/net/ceph/messenger.c
101506 +++ b/net/ceph/messenger.c
101507 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101508 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101509
101510 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101511 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101512 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101513
101514 static struct page *zero_page; /* used in certain error cases */
101515
101516 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101517 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101518 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101519
101520 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101521 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101522 s = addr_str[i];
101523
101524 switch (ss->ss_family) {
101525 diff --git a/net/compat.c b/net/compat.c
101526 index bc8aeef..f9c070c 100644
101527 --- a/net/compat.c
101528 +++ b/net/compat.c
101529 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101530 return -EFAULT;
101531 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101532 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101533 - kmsg->msg_name = compat_ptr(tmp1);
101534 - kmsg->msg_iov = compat_ptr(tmp2);
101535 - kmsg->msg_control = compat_ptr(tmp3);
101536 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101537 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101538 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101539 return 0;
101540 }
101541
101542 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101543
101544 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101545 if (mode == VERIFY_READ) {
101546 - int err = move_addr_to_kernel(kern_msg->msg_name,
101547 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101548 kern_msg->msg_namelen,
101549 kern_address);
101550 if (err < 0)
101551 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101552 }
101553
101554 tot_len = iov_from_user_compat_to_kern(kern_iov,
101555 - (struct compat_iovec __user *)kern_msg->msg_iov,
101556 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101557 kern_msg->msg_iovlen);
101558 if (tot_len >= 0)
101559 kern_msg->msg_iov = kern_iov;
101560 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101561
101562 #define CMSG_COMPAT_FIRSTHDR(msg) \
101563 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101564 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101565 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101566 (struct compat_cmsghdr __user *)NULL)
101567
101568 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101569 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101570 (ucmlen) <= (unsigned long) \
101571 ((mhdr)->msg_controllen - \
101572 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101573 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101574
101575 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101576 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101577 {
101578 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101579 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101580 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101581 msg->msg_controllen)
101582 return NULL;
101583 return (struct compat_cmsghdr __user *)ptr;
101584 @@ -223,7 +223,7 @@ Efault:
101585
101586 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101587 {
101588 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101589 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101590 struct compat_cmsghdr cmhdr;
101591 struct compat_timeval ctv;
101592 struct compat_timespec cts[3];
101593 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101594
101595 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101596 {
101597 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101598 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101599 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101600 int fdnum = scm->fp->count;
101601 struct file **fp = scm->fp->fp;
101602 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101603 return -EFAULT;
101604 old_fs = get_fs();
101605 set_fs(KERNEL_DS);
101606 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101607 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101608 set_fs(old_fs);
101609
101610 return err;
101611 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101612 len = sizeof(ktime);
101613 old_fs = get_fs();
101614 set_fs(KERNEL_DS);
101615 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101616 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101617 set_fs(old_fs);
101618
101619 if (!err) {
101620 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101621 case MCAST_JOIN_GROUP:
101622 case MCAST_LEAVE_GROUP:
101623 {
101624 - struct compat_group_req __user *gr32 = (void *)optval;
101625 + struct compat_group_req __user *gr32 = (void __user *)optval;
101626 struct group_req __user *kgr =
101627 compat_alloc_user_space(sizeof(struct group_req));
101628 u32 interface;
101629 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101630 case MCAST_BLOCK_SOURCE:
101631 case MCAST_UNBLOCK_SOURCE:
101632 {
101633 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101634 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101635 struct group_source_req __user *kgsr = compat_alloc_user_space(
101636 sizeof(struct group_source_req));
101637 u32 interface;
101638 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101639 }
101640 case MCAST_MSFILTER:
101641 {
101642 - struct compat_group_filter __user *gf32 = (void *)optval;
101643 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101644 struct group_filter __user *kgf;
101645 u32 interface, fmode, numsrc;
101646
101647 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101648 char __user *optval, int __user *optlen,
101649 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101650 {
101651 - struct compat_group_filter __user *gf32 = (void *)optval;
101652 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101653 struct group_filter __user *kgf;
101654 int __user *koptlen;
101655 u32 interface, fmode, numsrc;
101656 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101657
101658 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101659 return -EINVAL;
101660 - if (copy_from_user(a, args, nas[call]))
101661 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101662 return -EFAULT;
101663 a0 = a[0];
101664 a1 = a[1];
101665 diff --git a/net/core/datagram.c b/net/core/datagram.c
101666 index fdbc9a8..cd6972c 100644
101667 --- a/net/core/datagram.c
101668 +++ b/net/core/datagram.c
101669 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101670 }
101671
101672 kfree_skb(skb);
101673 - atomic_inc(&sk->sk_drops);
101674 + atomic_inc_unchecked(&sk->sk_drops);
101675 sk_mem_reclaim_partial(sk);
101676
101677 return err;
101678 diff --git a/net/core/dev.c b/net/core/dev.c
101679 index 9704a5c..1f363d0d 100644
101680 --- a/net/core/dev.c
101681 +++ b/net/core/dev.c
101682 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101683 {
101684 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101685 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101686 - atomic_long_inc(&dev->rx_dropped);
101687 + atomic_long_inc_unchecked(&dev->rx_dropped);
101688 kfree_skb(skb);
101689 return NET_RX_DROP;
101690 }
101691 }
101692
101693 if (unlikely(!is_skb_forwardable(dev, skb))) {
101694 - atomic_long_inc(&dev->rx_dropped);
101695 + atomic_long_inc_unchecked(&dev->rx_dropped);
101696 kfree_skb(skb);
101697 return NET_RX_DROP;
101698 }
101699 @@ -2994,7 +2994,7 @@ recursion_alert:
101700 drop:
101701 rcu_read_unlock_bh();
101702
101703 - atomic_long_inc(&dev->tx_dropped);
101704 + atomic_long_inc_unchecked(&dev->tx_dropped);
101705 kfree_skb_list(skb);
101706 return rc;
101707 out:
101708 @@ -3337,7 +3337,7 @@ enqueue:
101709
101710 local_irq_restore(flags);
101711
101712 - atomic_long_inc(&skb->dev->rx_dropped);
101713 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101714 kfree_skb(skb);
101715 return NET_RX_DROP;
101716 }
101717 @@ -3414,7 +3414,7 @@ int netif_rx_ni(struct sk_buff *skb)
101718 }
101719 EXPORT_SYMBOL(netif_rx_ni);
101720
101721 -static void net_tx_action(struct softirq_action *h)
101722 +static __latent_entropy void net_tx_action(void)
101723 {
101724 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101725
101726 @@ -3747,7 +3747,7 @@ ncls:
101727 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101728 } else {
101729 drop:
101730 - atomic_long_inc(&skb->dev->rx_dropped);
101731 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101732 kfree_skb(skb);
101733 /* Jamal, now you will not able to escape explaining
101734 * me how you were going to use this. :-)
101735 @@ -4511,7 +4511,7 @@ void netif_napi_del(struct napi_struct *napi)
101736 }
101737 EXPORT_SYMBOL(netif_napi_del);
101738
101739 -static void net_rx_action(struct softirq_action *h)
101740 +static __latent_entropy void net_rx_action(void)
101741 {
101742 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101743 unsigned long time_limit = jiffies + 2;
101744 @@ -5247,7 +5247,7 @@ void netdev_upper_dev_unlink(struct net_device *dev,
101745 }
101746 EXPORT_SYMBOL(netdev_upper_dev_unlink);
101747
101748 -void netdev_adjacent_add_links(struct net_device *dev)
101749 +static void netdev_adjacent_add_links(struct net_device *dev)
101750 {
101751 struct netdev_adjacent *iter;
101752
101753 @@ -5272,7 +5272,7 @@ void netdev_adjacent_add_links(struct net_device *dev)
101754 }
101755 }
101756
101757 -void netdev_adjacent_del_links(struct net_device *dev)
101758 +static void netdev_adjacent_del_links(struct net_device *dev)
101759 {
101760 struct netdev_adjacent *iter;
101761
101762 @@ -6557,8 +6557,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101763 } else {
101764 netdev_stats_to_stats64(storage, &dev->stats);
101765 }
101766 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101767 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101768 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101769 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101770 return storage;
101771 }
101772 EXPORT_SYMBOL(dev_get_stats);
101773 @@ -6574,7 +6574,7 @@ struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
101774 if (!queue)
101775 return NULL;
101776 netdev_init_one_queue(dev, queue, NULL);
101777 - queue->qdisc = &noop_qdisc;
101778 + RCU_INIT_POINTER(queue->qdisc, &noop_qdisc);
101779 queue->qdisc_sleeping = &noop_qdisc;
101780 rcu_assign_pointer(dev->ingress_queue, queue);
101781 #endif
101782 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101783 index 72e899a..79a9409 100644
101784 --- a/net/core/dev_ioctl.c
101785 +++ b/net/core/dev_ioctl.c
101786 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101787 no_module = !dev;
101788 if (no_module && capable(CAP_NET_ADMIN))
101789 no_module = request_module("netdev-%s", name);
101790 - if (no_module && capable(CAP_SYS_MODULE))
101791 + if (no_module && capable(CAP_SYS_MODULE)) {
101792 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101793 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101794 +#else
101795 request_module("%s", name);
101796 +#endif
101797 + }
101798 }
101799 EXPORT_SYMBOL(dev_load);
101800
101801 diff --git a/net/core/filter.c b/net/core/filter.c
101802 index 647b122..18a7ff6 100644
101803 --- a/net/core/filter.c
101804 +++ b/net/core/filter.c
101805 @@ -532,7 +532,11 @@ do_pass:
101806
101807 /* Unkown instruction. */
101808 default:
101809 - goto err;
101810 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101811 + fp->code, fp->jt, fp->jf, fp->k);
101812 + kfree(addrs);
101813 + BUG();
101814 + return -EINVAL;
101815 }
101816
101817 insn++;
101818 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101819 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101820 int pc, ret = 0;
101821
101822 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101823 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101824
101825 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101826 if (!masks)
101827 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101828 if (!fp)
101829 return -ENOMEM;
101830
101831 - memcpy(fp->insns, fprog->filter, fsize);
101832 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101833
101834 fp->len = fprog->len;
101835 /* Since unattached filters are not copied back to user
101836 diff --git a/net/core/flow.c b/net/core/flow.c
101837 index a0348fd..340f65d 100644
101838 --- a/net/core/flow.c
101839 +++ b/net/core/flow.c
101840 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101841 static int flow_entry_valid(struct flow_cache_entry *fle,
101842 struct netns_xfrm *xfrm)
101843 {
101844 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101845 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101846 return 0;
101847 if (fle->object && !fle->object->ops->check(fle->object))
101848 return 0;
101849 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101850 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101851 fcp->hash_count++;
101852 }
101853 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101854 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101855 flo = fle->object;
101856 if (!flo)
101857 goto ret_object;
101858 @@ -263,7 +263,7 @@ nocache:
101859 }
101860 flo = resolver(net, key, family, dir, flo, ctx);
101861 if (fle) {
101862 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101863 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101864 if (!IS_ERR(flo))
101865 fle->object = flo;
101866 else
101867 @@ -379,7 +379,7 @@ done:
101868 static void flow_cache_flush_task(struct work_struct *work)
101869 {
101870 struct netns_xfrm *xfrm = container_of(work, struct netns_xfrm,
101871 - flow_cache_gc_work);
101872 + flow_cache_flush_work);
101873 struct net *net = container_of(xfrm, struct net, xfrm);
101874
101875 flow_cache_flush(net);
101876 diff --git a/net/core/iovec.c b/net/core/iovec.c
101877 index e1ec45a..e5c6f16 100644
101878 --- a/net/core/iovec.c
101879 +++ b/net/core/iovec.c
101880 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101881 if (m->msg_name && m->msg_namelen) {
101882 if (mode == VERIFY_READ) {
101883 void __user *namep;
101884 - namep = (void __user __force *) m->msg_name;
101885 + namep = (void __force_user *) m->msg_name;
101886 err = move_addr_to_kernel(namep, m->msg_namelen,
101887 address);
101888 if (err < 0)
101889 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101890 }
101891
101892 size = m->msg_iovlen * sizeof(struct iovec);
101893 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101894 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101895 return -EFAULT;
101896
101897 m->msg_iov = iov;
101898 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101899 index ef31fef..8be66d9 100644
101900 --- a/net/core/neighbour.c
101901 +++ b/net/core/neighbour.c
101902 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101903 void __user *buffer, size_t *lenp, loff_t *ppos)
101904 {
101905 int size, ret;
101906 - struct ctl_table tmp = *ctl;
101907 + ctl_table_no_const tmp = *ctl;
101908
101909 tmp.extra1 = &zero;
101910 tmp.extra2 = &unres_qlen_max;
101911 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101912 void __user *buffer,
101913 size_t *lenp, loff_t *ppos)
101914 {
101915 - struct ctl_table tmp = *ctl;
101916 + ctl_table_no_const tmp = *ctl;
101917 int ret;
101918
101919 tmp.extra1 = &zero;
101920 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101921 index 2bf8329..2eb1423 100644
101922 --- a/net/core/net-procfs.c
101923 +++ b/net/core/net-procfs.c
101924 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101925 struct rtnl_link_stats64 temp;
101926 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101927
101928 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101929 + if (gr_proc_is_restricted())
101930 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101931 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101932 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101933 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101934 + else
101935 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101936 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101937 dev->name, stats->rx_bytes, stats->rx_packets,
101938 stats->rx_errors,
101939 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101940 return 0;
101941 }
101942
101943 -static const struct seq_operations dev_seq_ops = {
101944 +const struct seq_operations dev_seq_ops = {
101945 .start = dev_seq_start,
101946 .next = dev_seq_next,
101947 .stop = dev_seq_stop,
101948 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101949
101950 static int softnet_seq_open(struct inode *inode, struct file *file)
101951 {
101952 - return seq_open(file, &softnet_seq_ops);
101953 + return seq_open_restrict(file, &softnet_seq_ops);
101954 }
101955
101956 static const struct file_operations softnet_seq_fops = {
101957 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101958 else
101959 seq_printf(seq, "%04x", ntohs(pt->type));
101960
101961 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101962 + seq_printf(seq, " %-8s %pf\n",
101963 + pt->dev ? pt->dev->name : "", NULL);
101964 +#else
101965 seq_printf(seq, " %-8s %pf\n",
101966 pt->dev ? pt->dev->name : "", pt->func);
101967 +#endif
101968 }
101969
101970 return 0;
101971 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101972 index 9dd0669..c52fb1b 100644
101973 --- a/net/core/net-sysfs.c
101974 +++ b/net/core/net-sysfs.c
101975 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101976 {
101977 struct net_device *netdev = to_net_dev(dev);
101978 return sprintf(buf, fmt_dec,
101979 - atomic_read(&netdev->carrier_changes));
101980 + atomic_read_unchecked(&netdev->carrier_changes));
101981 }
101982 static DEVICE_ATTR_RO(carrier_changes);
101983
101984 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101985 index 7f15517..f7d65c0 100644
101986 --- a/net/core/net_namespace.c
101987 +++ b/net/core/net_namespace.c
101988 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101989 int error;
101990 LIST_HEAD(net_exit_list);
101991
101992 - list_add_tail(&ops->list, list);
101993 + pax_list_add_tail((struct list_head *)&ops->list, list);
101994 if (ops->init || (ops->id && ops->size)) {
101995 for_each_net(net) {
101996 error = ops_init(ops, net);
101997 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101998
101999 out_undo:
102000 /* If I have an error cleanup all namespaces I initialized */
102001 - list_del(&ops->list);
102002 + pax_list_del((struct list_head *)&ops->list);
102003 ops_exit_list(ops, &net_exit_list);
102004 ops_free_list(ops, &net_exit_list);
102005 return error;
102006 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102007 struct net *net;
102008 LIST_HEAD(net_exit_list);
102009
102010 - list_del(&ops->list);
102011 + pax_list_del((struct list_head *)&ops->list);
102012 for_each_net(net)
102013 list_add_tail(&net->exit_list, &net_exit_list);
102014 ops_exit_list(ops, &net_exit_list);
102015 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102016 mutex_lock(&net_mutex);
102017 error = register_pernet_operations(&pernet_list, ops);
102018 if (!error && (first_device == &pernet_list))
102019 - first_device = &ops->list;
102020 + first_device = (struct list_head *)&ops->list;
102021 mutex_unlock(&net_mutex);
102022 return error;
102023 }
102024 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102025 index e6645b4..43e1af9 100644
102026 --- a/net/core/netpoll.c
102027 +++ b/net/core/netpoll.c
102028 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102029 struct udphdr *udph;
102030 struct iphdr *iph;
102031 struct ethhdr *eth;
102032 - static atomic_t ip_ident;
102033 + static atomic_unchecked_t ip_ident;
102034 struct ipv6hdr *ip6h;
102035
102036 udp_len = len + sizeof(*udph);
102037 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102038 put_unaligned(0x45, (unsigned char *)iph);
102039 iph->tos = 0;
102040 put_unaligned(htons(ip_len), &(iph->tot_len));
102041 - iph->id = htons(atomic_inc_return(&ip_ident));
102042 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102043 iph->frag_off = 0;
102044 iph->ttl = 64;
102045 iph->protocol = IPPROTO_UDP;
102046 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102047 index 443256b..bbff424 100644
102048 --- a/net/core/pktgen.c
102049 +++ b/net/core/pktgen.c
102050 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
102051 pn->net = net;
102052 INIT_LIST_HEAD(&pn->pktgen_threads);
102053 pn->pktgen_exiting = false;
102054 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102055 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102056 if (!pn->proc_dir) {
102057 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102058 return -ENODEV;
102059 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102060 index ca82629..66264f7 100644
102061 --- a/net/core/rtnetlink.c
102062 +++ b/net/core/rtnetlink.c
102063 @@ -58,7 +58,7 @@ struct rtnl_link {
102064 rtnl_doit_func doit;
102065 rtnl_dumpit_func dumpit;
102066 rtnl_calcit_func calcit;
102067 -};
102068 +} __no_const;
102069
102070 static DEFINE_MUTEX(rtnl_mutex);
102071
102072 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102073 * to use the ops for creating device. So do not
102074 * fill up dellink as well. That disables rtnl_dellink.
102075 */
102076 - if (ops->setup && !ops->dellink)
102077 - ops->dellink = unregister_netdevice_queue;
102078 + if (ops->setup && !ops->dellink) {
102079 + pax_open_kernel();
102080 + *(void **)&ops->dellink = unregister_netdevice_queue;
102081 + pax_close_kernel();
102082 + }
102083
102084 - list_add_tail(&ops->list, &link_ops);
102085 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102086 return 0;
102087 }
102088 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102089 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102090 for_each_net(net) {
102091 __rtnl_kill_links(net, ops);
102092 }
102093 - list_del(&ops->list);
102094 + pax_list_del((struct list_head *)&ops->list);
102095 }
102096 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102097
102098 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102099 (dev->ifalias &&
102100 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102101 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102102 - atomic_read(&dev->carrier_changes)))
102103 + atomic_read_unchecked(&dev->carrier_changes)))
102104 goto nla_put_failure;
102105
102106 if (1) {
102107 diff --git a/net/core/scm.c b/net/core/scm.c
102108 index b442e7e..6f5b5a2 100644
102109 --- a/net/core/scm.c
102110 +++ b/net/core/scm.c
102111 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102112 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102113 {
102114 struct cmsghdr __user *cm
102115 - = (__force struct cmsghdr __user *)msg->msg_control;
102116 + = (struct cmsghdr __force_user *)msg->msg_control;
102117 struct cmsghdr cmhdr;
102118 int cmlen = CMSG_LEN(len);
102119 int err;
102120 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102121 err = -EFAULT;
102122 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102123 goto out;
102124 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102125 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102126 goto out;
102127 cmlen = CMSG_SPACE(len);
102128 if (msg->msg_controllen < cmlen)
102129 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102130 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102131 {
102132 struct cmsghdr __user *cm
102133 - = (__force struct cmsghdr __user*)msg->msg_control;
102134 + = (struct cmsghdr __force_user *)msg->msg_control;
102135
102136 int fdmax = 0;
102137 int fdnum = scm->fp->count;
102138 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102139 if (fdnum < fdmax)
102140 fdmax = fdnum;
102141
102142 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102143 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102144 i++, cmfptr++)
102145 {
102146 struct socket *sock;
102147 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102148 index d7543d0..ff96aec 100644
102149 --- a/net/core/skbuff.c
102150 +++ b/net/core/skbuff.c
102151 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
102152 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102153 int len, __wsum csum)
102154 {
102155 - const struct skb_checksum_ops ops = {
102156 + static const struct skb_checksum_ops ops = {
102157 .update = csum_partial_ext,
102158 .combine = csum_block_add_ext,
102159 };
102160 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
102161 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102162 sizeof(struct sk_buff),
102163 0,
102164 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102165 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102166 + SLAB_NO_SANITIZE,
102167 NULL);
102168 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102169 sizeof(struct sk_buff_fclones),
102170 0,
102171 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102172 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102173 + SLAB_NO_SANITIZE,
102174 NULL);
102175 }
102176
102177 diff --git a/net/core/sock.c b/net/core/sock.c
102178 index 15e0c67..0310f4a 100644
102179 --- a/net/core/sock.c
102180 +++ b/net/core/sock.c
102181 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102182 struct sk_buff_head *list = &sk->sk_receive_queue;
102183
102184 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102185 - atomic_inc(&sk->sk_drops);
102186 + atomic_inc_unchecked(&sk->sk_drops);
102187 trace_sock_rcvqueue_full(sk, skb);
102188 return -ENOMEM;
102189 }
102190 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102191 return err;
102192
102193 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102194 - atomic_inc(&sk->sk_drops);
102195 + atomic_inc_unchecked(&sk->sk_drops);
102196 return -ENOBUFS;
102197 }
102198
102199 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102200 skb_dst_force(skb);
102201
102202 spin_lock_irqsave(&list->lock, flags);
102203 - skb->dropcount = atomic_read(&sk->sk_drops);
102204 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102205 __skb_queue_tail(list, skb);
102206 spin_unlock_irqrestore(&list->lock, flags);
102207
102208 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102209 skb->dev = NULL;
102210
102211 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102212 - atomic_inc(&sk->sk_drops);
102213 + atomic_inc_unchecked(&sk->sk_drops);
102214 goto discard_and_relse;
102215 }
102216 if (nested)
102217 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102218 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102219 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102220 bh_unlock_sock(sk);
102221 - atomic_inc(&sk->sk_drops);
102222 + atomic_inc_unchecked(&sk->sk_drops);
102223 goto discard_and_relse;
102224 }
102225
102226 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102227 struct timeval tm;
102228 } v;
102229
102230 - int lv = sizeof(int);
102231 - int len;
102232 + unsigned int lv = sizeof(int);
102233 + unsigned int len;
102234
102235 if (get_user(len, optlen))
102236 return -EFAULT;
102237 - if (len < 0)
102238 + if (len > INT_MAX)
102239 return -EINVAL;
102240
102241 memset(&v, 0, sizeof(v));
102242 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102243
102244 case SO_PEERNAME:
102245 {
102246 - char address[128];
102247 + char address[_K_SS_MAXSIZE];
102248
102249 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102250 return -ENOTCONN;
102251 - if (lv < len)
102252 + if (lv < len || sizeof address < len)
102253 return -EINVAL;
102254 if (copy_to_user(optval, address, len))
102255 return -EFAULT;
102256 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102257
102258 if (len > lv)
102259 len = lv;
102260 - if (copy_to_user(optval, &v, len))
102261 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102262 return -EFAULT;
102263 lenout:
102264 if (put_user(len, optlen))
102265 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102266 */
102267 smp_wmb();
102268 atomic_set(&sk->sk_refcnt, 1);
102269 - atomic_set(&sk->sk_drops, 0);
102270 + atomic_set_unchecked(&sk->sk_drops, 0);
102271 }
102272 EXPORT_SYMBOL(sock_init_data);
102273
102274 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102275 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102276 int level, int type)
102277 {
102278 + struct sock_extended_err ee;
102279 struct sock_exterr_skb *serr;
102280 struct sk_buff *skb;
102281 int copied, err;
102282 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102283 sock_recv_timestamp(msg, sk, skb);
102284
102285 serr = SKB_EXT_ERR(skb);
102286 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102287 + ee = serr->ee;
102288 + put_cmsg(msg, level, type, sizeof ee, &ee);
102289
102290 msg->msg_flags |= MSG_ERRQUEUE;
102291 err = copied;
102292 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102293 index ad704c7..ca48aff 100644
102294 --- a/net/core/sock_diag.c
102295 +++ b/net/core/sock_diag.c
102296 @@ -9,26 +9,33 @@
102297 #include <linux/inet_diag.h>
102298 #include <linux/sock_diag.h>
102299
102300 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102301 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102302 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102303 static DEFINE_MUTEX(sock_diag_table_mutex);
102304
102305 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102306 {
102307 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102308 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102309 cookie[1] != INET_DIAG_NOCOOKIE) &&
102310 ((u32)(unsigned long)sk != cookie[0] ||
102311 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102312 return -ESTALE;
102313 else
102314 +#endif
102315 return 0;
102316 }
102317 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102318
102319 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102320 {
102321 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102322 + cookie[0] = 0;
102323 + cookie[1] = 0;
102324 +#else
102325 cookie[0] = (u32)(unsigned long)sk;
102326 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102327 +#endif
102328 }
102329 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102330
102331 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102332 mutex_lock(&sock_diag_table_mutex);
102333 if (sock_diag_handlers[hndl->family])
102334 err = -EBUSY;
102335 - else
102336 + else {
102337 + pax_open_kernel();
102338 sock_diag_handlers[hndl->family] = hndl;
102339 + pax_close_kernel();
102340 + }
102341 mutex_unlock(&sock_diag_table_mutex);
102342
102343 return err;
102344 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102345
102346 mutex_lock(&sock_diag_table_mutex);
102347 BUG_ON(sock_diag_handlers[family] != hnld);
102348 + pax_open_kernel();
102349 sock_diag_handlers[family] = NULL;
102350 + pax_close_kernel();
102351 mutex_unlock(&sock_diag_table_mutex);
102352 }
102353 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102354 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102355 index cf9cd13..50683950 100644
102356 --- a/net/core/sysctl_net_core.c
102357 +++ b/net/core/sysctl_net_core.c
102358 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102359 {
102360 unsigned int orig_size, size;
102361 int ret, i;
102362 - struct ctl_table tmp = {
102363 + ctl_table_no_const tmp = {
102364 .data = &size,
102365 .maxlen = sizeof(size),
102366 .mode = table->mode
102367 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102368 void __user *buffer, size_t *lenp, loff_t *ppos)
102369 {
102370 char id[IFNAMSIZ];
102371 - struct ctl_table tbl = {
102372 + ctl_table_no_const tbl = {
102373 .data = id,
102374 .maxlen = IFNAMSIZ,
102375 };
102376 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102377 .mode = 0644,
102378 .proc_handler = proc_dointvec
102379 },
102380 -#ifdef CONFIG_BPF_JIT
102381 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102382 {
102383 .procname = "bpf_jit_enable",
102384 .data = &bpf_jit_enable,
102385 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102386
102387 static __net_init int sysctl_core_net_init(struct net *net)
102388 {
102389 - struct ctl_table *tbl;
102390 + ctl_table_no_const *tbl = NULL;
102391
102392 net->core.sysctl_somaxconn = SOMAXCONN;
102393
102394 - tbl = netns_core_table;
102395 if (!net_eq(net, &init_net)) {
102396 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102397 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102398 if (tbl == NULL)
102399 goto err_dup;
102400
102401 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102402 if (net->user_ns != &init_user_ns) {
102403 tbl[0].procname = NULL;
102404 }
102405 - }
102406 -
102407 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102408 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102409 + } else
102410 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102411 if (net->core.sysctl_hdr == NULL)
102412 goto err_reg;
102413
102414 return 0;
102415
102416 err_reg:
102417 - if (tbl != netns_core_table)
102418 - kfree(tbl);
102419 + kfree(tbl);
102420 err_dup:
102421 return -ENOMEM;
102422 }
102423 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102424 kfree(tbl);
102425 }
102426
102427 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102428 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102429 .init = sysctl_core_net_init,
102430 .exit = sysctl_core_net_exit,
102431 };
102432 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102433 index 25733d5..b9360f0 100644
102434 --- a/net/decnet/af_decnet.c
102435 +++ b/net/decnet/af_decnet.c
102436 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
102437 .sysctl_rmem = sysctl_decnet_rmem,
102438 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102439 .obj_size = sizeof(struct dn_sock),
102440 + .slab_flags = SLAB_USERCOPY,
102441 };
102442
102443 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102444 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102445 index 4400da7..3429972 100644
102446 --- a/net/decnet/dn_dev.c
102447 +++ b/net/decnet/dn_dev.c
102448 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
102449 .extra1 = &min_t3,
102450 .extra2 = &max_t3
102451 },
102452 - {0}
102453 + { }
102454 },
102455 };
102456
102457 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102458 index 5325b54..a0d4d69 100644
102459 --- a/net/decnet/sysctl_net_decnet.c
102460 +++ b/net/decnet/sysctl_net_decnet.c
102461 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102462
102463 if (len > *lenp) len = *lenp;
102464
102465 - if (copy_to_user(buffer, addr, len))
102466 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102467 return -EFAULT;
102468
102469 *lenp = len;
102470 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102471
102472 if (len > *lenp) len = *lenp;
102473
102474 - if (copy_to_user(buffer, devname, len))
102475 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102476 return -EFAULT;
102477
102478 *lenp = len;
102479 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102480 index a2c7e4c..3dc9f67 100644
102481 --- a/net/hsr/hsr_netlink.c
102482 +++ b/net/hsr/hsr_netlink.c
102483 @@ -102,7 +102,7 @@ nla_put_failure:
102484 return -EMSGSIZE;
102485 }
102486
102487 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102488 +static struct rtnl_link_ops hsr_link_ops = {
102489 .kind = "hsr",
102490 .maxtype = IFLA_HSR_MAX,
102491 .policy = hsr_policy,
102492 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102493 index 4413629..dea596a 100644
102494 --- a/net/ieee802154/6lowpan_rtnl.c
102495 +++ b/net/ieee802154/6lowpan_rtnl.c
102496 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102497 dev_put(real_dev);
102498 }
102499
102500 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102501 +static struct rtnl_link_ops lowpan_link_ops = {
102502 .kind = "lowpan",
102503 .priv_size = sizeof(struct lowpan_dev_info),
102504 .setup = lowpan_setup,
102505 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102506 index 7cfcd68..84ca5b7 100644
102507 --- a/net/ieee802154/reassembly.c
102508 +++ b/net/ieee802154/reassembly.c
102509 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102510
102511 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102512 {
102513 - struct ctl_table *table;
102514 + ctl_table_no_const *table = NULL;
102515 struct ctl_table_header *hdr;
102516 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102517 net_ieee802154_lowpan(net);
102518
102519 - table = lowpan_frags_ns_ctl_table;
102520 if (!net_eq(net, &init_net)) {
102521 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102522 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102523 GFP_KERNEL);
102524 if (table == NULL)
102525 goto err_alloc;
102526 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102527 /* Don't export sysctls to unprivileged users */
102528 if (net->user_ns != &init_user_ns)
102529 table[0].procname = NULL;
102530 - }
102531 -
102532 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102533 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102534 + } else
102535 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102536 if (hdr == NULL)
102537 goto err_reg;
102538
102539 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102540 return 0;
102541
102542 err_reg:
102543 - if (!net_eq(net, &init_net))
102544 - kfree(table);
102545 + kfree(table);
102546 err_alloc:
102547 return -ENOMEM;
102548 }
102549 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102550 index e67da4e..da217942 100644
102551 --- a/net/ipv4/af_inet.c
102552 +++ b/net/ipv4/af_inet.c
102553 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102554 return ip_recv_error(sk, msg, len, addr_len);
102555 #if IS_ENABLED(CONFIG_IPV6)
102556 if (sk->sk_family == AF_INET6)
102557 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102558 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102559 #endif
102560 return -EINVAL;
102561 }
102562 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102563 index 214882e..ec032f6 100644
102564 --- a/net/ipv4/devinet.c
102565 +++ b/net/ipv4/devinet.c
102566 @@ -69,7 +69,8 @@
102567
102568 static struct ipv4_devconf ipv4_devconf = {
102569 .data = {
102570 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102571 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102572 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102573 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102574 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102575 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102576 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102577
102578 static struct ipv4_devconf ipv4_devconf_dflt = {
102579 .data = {
102580 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102581 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102582 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102583 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102584 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102585 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102586 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102587 idx = 0;
102588 head = &net->dev_index_head[h];
102589 rcu_read_lock();
102590 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102591 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102592 net->dev_base_seq;
102593 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102594 if (idx < s_idx)
102595 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102596 idx = 0;
102597 head = &net->dev_index_head[h];
102598 rcu_read_lock();
102599 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102600 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102601 net->dev_base_seq;
102602 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102603 if (idx < s_idx)
102604 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102605 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102606 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102607
102608 -static struct devinet_sysctl_table {
102609 +static const struct devinet_sysctl_table {
102610 struct ctl_table_header *sysctl_header;
102611 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102612 } devinet_sysctl = {
102613 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102614 int err;
102615 struct ipv4_devconf *all, *dflt;
102616 #ifdef CONFIG_SYSCTL
102617 - struct ctl_table *tbl = ctl_forward_entry;
102618 + ctl_table_no_const *tbl = NULL;
102619 struct ctl_table_header *forw_hdr;
102620 #endif
102621
102622 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102623 goto err_alloc_dflt;
102624
102625 #ifdef CONFIG_SYSCTL
102626 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102627 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102628 if (tbl == NULL)
102629 goto err_alloc_ctl;
102630
102631 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102632 goto err_reg_dflt;
102633
102634 err = -ENOMEM;
102635 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102636 + if (!net_eq(net, &init_net))
102637 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102638 + else
102639 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102640 if (forw_hdr == NULL)
102641 goto err_reg_ctl;
102642 net->ipv4.forw_hdr = forw_hdr;
102643 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102644 err_reg_dflt:
102645 __devinet_sysctl_unregister(all);
102646 err_reg_all:
102647 - if (tbl != ctl_forward_entry)
102648 - kfree(tbl);
102649 + kfree(tbl);
102650 err_alloc_ctl:
102651 #endif
102652 if (dflt != &ipv4_devconf_dflt)
102653 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102654 index 23104a3..9f5570b 100644
102655 --- a/net/ipv4/fib_frontend.c
102656 +++ b/net/ipv4/fib_frontend.c
102657 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102658 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102659 fib_sync_up(dev);
102660 #endif
102661 - atomic_inc(&net->ipv4.dev_addr_genid);
102662 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102663 rt_cache_flush(dev_net(dev));
102664 break;
102665 case NETDEV_DOWN:
102666 fib_del_ifaddr(ifa, NULL);
102667 - atomic_inc(&net->ipv4.dev_addr_genid);
102668 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102669 if (ifa->ifa_dev->ifa_list == NULL) {
102670 /* Last address was deleted from this interface.
102671 * Disable IP.
102672 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102673 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102674 fib_sync_up(dev);
102675 #endif
102676 - atomic_inc(&net->ipv4.dev_addr_genid);
102677 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102678 rt_cache_flush(net);
102679 break;
102680 case NETDEV_DOWN:
102681 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102682 index f99f41b..1879da9 100644
102683 --- a/net/ipv4/fib_semantics.c
102684 +++ b/net/ipv4/fib_semantics.c
102685 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102686 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102687 nh->nh_gw,
102688 nh->nh_parent->fib_scope);
102689 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102690 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102691
102692 return nh->nh_saddr;
102693 }
102694 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102695 index 9111a4e..3576905 100644
102696 --- a/net/ipv4/inet_hashtables.c
102697 +++ b/net/ipv4/inet_hashtables.c
102698 @@ -18,6 +18,7 @@
102699 #include <linux/sched.h>
102700 #include <linux/slab.h>
102701 #include <linux/wait.h>
102702 +#include <linux/security.h>
102703
102704 #include <net/inet_connection_sock.h>
102705 #include <net/inet_hashtables.h>
102706 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102707 return inet_ehashfn(net, laddr, lport, faddr, fport);
102708 }
102709
102710 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102711 +
102712 /*
102713 * Allocate and initialize a new local port bind bucket.
102714 * The bindhash mutex for snum's hash chain must be held here.
102715 @@ -554,6 +557,8 @@ ok:
102716 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102717 spin_unlock(&head->lock);
102718
102719 + gr_update_task_in_ip_table(inet_sk(sk));
102720 +
102721 if (tw) {
102722 inet_twsk_deschedule(tw, death_row);
102723 while (twrefcnt) {
102724 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102725 index 241afd7..31b95d5 100644
102726 --- a/net/ipv4/inetpeer.c
102727 +++ b/net/ipv4/inetpeer.c
102728 @@ -461,7 +461,7 @@ relookup:
102729 if (p) {
102730 p->daddr = *daddr;
102731 atomic_set(&p->refcnt, 1);
102732 - atomic_set(&p->rid, 0);
102733 + atomic_set_unchecked(&p->rid, 0);
102734 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102735 p->rate_tokens = 0;
102736 /* 60*HZ is arbitrary, but chosen enough high so that the first
102737 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102738 index 2811cc1..ad5a534 100644
102739 --- a/net/ipv4/ip_fragment.c
102740 +++ b/net/ipv4/ip_fragment.c
102741 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102742 return 0;
102743
102744 start = qp->rid;
102745 - end = atomic_inc_return(&peer->rid);
102746 + end = atomic_inc_return_unchecked(&peer->rid);
102747 qp->rid = end;
102748
102749 rc = qp->q.fragments && (end - start) > max;
102750 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102751
102752 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102753 {
102754 - struct ctl_table *table;
102755 + ctl_table_no_const *table = NULL;
102756 struct ctl_table_header *hdr;
102757
102758 - table = ip4_frags_ns_ctl_table;
102759 if (!net_eq(net, &init_net)) {
102760 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102761 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102762 if (table == NULL)
102763 goto err_alloc;
102764
102765 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102766 /* Don't export sysctls to unprivileged users */
102767 if (net->user_ns != &init_user_ns)
102768 table[0].procname = NULL;
102769 - }
102770 + hdr = register_net_sysctl(net, "net/ipv4", table);
102771 + } else
102772 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102773
102774 - hdr = register_net_sysctl(net, "net/ipv4", table);
102775 if (hdr == NULL)
102776 goto err_reg;
102777
102778 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102779 return 0;
102780
102781 err_reg:
102782 - if (!net_eq(net, &init_net))
102783 - kfree(table);
102784 + kfree(table);
102785 err_alloc:
102786 return -ENOMEM;
102787 }
102788 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102789 index 69aaf0a..8298c029 100644
102790 --- a/net/ipv4/ip_gre.c
102791 +++ b/net/ipv4/ip_gre.c
102792 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102793 module_param(log_ecn_error, bool, 0644);
102794 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102795
102796 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102797 +static struct rtnl_link_ops ipgre_link_ops;
102798 static int ipgre_tunnel_init(struct net_device *dev);
102799
102800 static int ipgre_net_id __read_mostly;
102801 @@ -816,7 +816,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102802 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102803 };
102804
102805 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102806 +static struct rtnl_link_ops ipgre_link_ops = {
102807 .kind = "gre",
102808 .maxtype = IFLA_GRE_MAX,
102809 .policy = ipgre_policy,
102810 @@ -830,7 +830,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102811 .fill_info = ipgre_fill_info,
102812 };
102813
102814 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102815 +static struct rtnl_link_ops ipgre_tap_ops = {
102816 .kind = "gretap",
102817 .maxtype = IFLA_GRE_MAX,
102818 .policy = ipgre_policy,
102819 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102820 index 3d4da2c..40f9c29 100644
102821 --- a/net/ipv4/ip_input.c
102822 +++ b/net/ipv4/ip_input.c
102823 @@ -147,6 +147,10 @@
102824 #include <linux/mroute.h>
102825 #include <linux/netlink.h>
102826
102827 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102828 +extern int grsec_enable_blackhole;
102829 +#endif
102830 +
102831 /*
102832 * Process Router Attention IP option (RFC 2113)
102833 */
102834 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102835 if (!raw) {
102836 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102837 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102838 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102839 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102840 +#endif
102841 icmp_send(skb, ICMP_DEST_UNREACH,
102842 ICMP_PROT_UNREACH, 0);
102843 }
102844 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102845 index 046fce0..4b28126 100644
102846 --- a/net/ipv4/ip_sockglue.c
102847 +++ b/net/ipv4/ip_sockglue.c
102848 @@ -1173,7 +1173,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102849 len = min_t(unsigned int, len, opt->optlen);
102850 if (put_user(len, optlen))
102851 return -EFAULT;
102852 - if (copy_to_user(optval, opt->__data, len))
102853 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102854 + copy_to_user(optval, opt->__data, len))
102855 return -EFAULT;
102856 return 0;
102857 }
102858 @@ -1304,7 +1305,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102859 if (sk->sk_type != SOCK_STREAM)
102860 return -ENOPROTOOPT;
102861
102862 - msg.msg_control = (__force void *) optval;
102863 + msg.msg_control = (__force_kernel void *) optval;
102864 msg.msg_controllen = len;
102865 msg.msg_flags = flags;
102866
102867 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102868 index 1a7e979..fd05aa4 100644
102869 --- a/net/ipv4/ip_vti.c
102870 +++ b/net/ipv4/ip_vti.c
102871 @@ -45,7 +45,7 @@
102872 #include <net/net_namespace.h>
102873 #include <net/netns/generic.h>
102874
102875 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102876 +static struct rtnl_link_ops vti_link_ops;
102877
102878 static int vti_net_id __read_mostly;
102879 static int vti_tunnel_init(struct net_device *dev);
102880 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102881 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102882 };
102883
102884 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102885 +static struct rtnl_link_ops vti_link_ops = {
102886 .kind = "vti",
102887 .maxtype = IFLA_VTI_MAX,
102888 .policy = vti_policy,
102889 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102890 index 648fa14..97864d0 100644
102891 --- a/net/ipv4/ipconfig.c
102892 +++ b/net/ipv4/ipconfig.c
102893 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102894
102895 mm_segment_t oldfs = get_fs();
102896 set_fs(get_ds());
102897 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102898 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102899 set_fs(oldfs);
102900 return res;
102901 }
102902 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102903
102904 mm_segment_t oldfs = get_fs();
102905 set_fs(get_ds());
102906 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102907 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102908 set_fs(oldfs);
102909 return res;
102910 }
102911 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102912
102913 mm_segment_t oldfs = get_fs();
102914 set_fs(get_ds());
102915 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102916 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102917 set_fs(oldfs);
102918 return res;
102919 }
102920 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102921 index 37096d6..86abb03 100644
102922 --- a/net/ipv4/ipip.c
102923 +++ b/net/ipv4/ipip.c
102924 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102925 static int ipip_net_id __read_mostly;
102926
102927 static int ipip_tunnel_init(struct net_device *dev);
102928 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102929 +static struct rtnl_link_ops ipip_link_ops;
102930
102931 static int ipip_err(struct sk_buff *skb, u32 info)
102932 {
102933 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102934 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102935 };
102936
102937 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102938 +static struct rtnl_link_ops ipip_link_ops = {
102939 .kind = "ipip",
102940 .maxtype = IFLA_IPTUN_MAX,
102941 .policy = ipip_policy,
102942 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102943 index f95b6f9..2ee2097 100644
102944 --- a/net/ipv4/netfilter/arp_tables.c
102945 +++ b/net/ipv4/netfilter/arp_tables.c
102946 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102947 #endif
102948
102949 static int get_info(struct net *net, void __user *user,
102950 - const int *len, int compat)
102951 + int len, int compat)
102952 {
102953 char name[XT_TABLE_MAXNAMELEN];
102954 struct xt_table *t;
102955 int ret;
102956
102957 - if (*len != sizeof(struct arpt_getinfo)) {
102958 - duprintf("length %u != %Zu\n", *len,
102959 + if (len != sizeof(struct arpt_getinfo)) {
102960 + duprintf("length %u != %Zu\n", len,
102961 sizeof(struct arpt_getinfo));
102962 return -EINVAL;
102963 }
102964 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102965 info.size = private->size;
102966 strcpy(info.name, name);
102967
102968 - if (copy_to_user(user, &info, *len) != 0)
102969 + if (copy_to_user(user, &info, len) != 0)
102970 ret = -EFAULT;
102971 else
102972 ret = 0;
102973 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102974
102975 switch (cmd) {
102976 case ARPT_SO_GET_INFO:
102977 - ret = get_info(sock_net(sk), user, len, 1);
102978 + ret = get_info(sock_net(sk), user, *len, 1);
102979 break;
102980 case ARPT_SO_GET_ENTRIES:
102981 ret = compat_get_entries(sock_net(sk), user, len);
102982 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102983
102984 switch (cmd) {
102985 case ARPT_SO_GET_INFO:
102986 - ret = get_info(sock_net(sk), user, len, 0);
102987 + ret = get_info(sock_net(sk), user, *len, 0);
102988 break;
102989
102990 case ARPT_SO_GET_ENTRIES:
102991 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102992 index 99e810f..3711b81 100644
102993 --- a/net/ipv4/netfilter/ip_tables.c
102994 +++ b/net/ipv4/netfilter/ip_tables.c
102995 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102996 #endif
102997
102998 static int get_info(struct net *net, void __user *user,
102999 - const int *len, int compat)
103000 + int len, int compat)
103001 {
103002 char name[XT_TABLE_MAXNAMELEN];
103003 struct xt_table *t;
103004 int ret;
103005
103006 - if (*len != sizeof(struct ipt_getinfo)) {
103007 - duprintf("length %u != %zu\n", *len,
103008 + if (len != sizeof(struct ipt_getinfo)) {
103009 + duprintf("length %u != %zu\n", len,
103010 sizeof(struct ipt_getinfo));
103011 return -EINVAL;
103012 }
103013 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103014 info.size = private->size;
103015 strcpy(info.name, name);
103016
103017 - if (copy_to_user(user, &info, *len) != 0)
103018 + if (copy_to_user(user, &info, len) != 0)
103019 ret = -EFAULT;
103020 else
103021 ret = 0;
103022 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103023
103024 switch (cmd) {
103025 case IPT_SO_GET_INFO:
103026 - ret = get_info(sock_net(sk), user, len, 1);
103027 + ret = get_info(sock_net(sk), user, *len, 1);
103028 break;
103029 case IPT_SO_GET_ENTRIES:
103030 ret = compat_get_entries(sock_net(sk), user, len);
103031 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103032
103033 switch (cmd) {
103034 case IPT_SO_GET_INFO:
103035 - ret = get_info(sock_net(sk), user, len, 0);
103036 + ret = get_info(sock_net(sk), user, *len, 0);
103037 break;
103038
103039 case IPT_SO_GET_ENTRIES:
103040 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103041 index e90f83a..3e6acca 100644
103042 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103043 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103044 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103045 spin_lock_init(&cn->lock);
103046
103047 #ifdef CONFIG_PROC_FS
103048 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103049 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103050 if (!cn->procdir) {
103051 pr_err("Unable to proc dir entry\n");
103052 return -ENOMEM;
103053 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103054 index 5638b17..22c8e65 100644
103055 --- a/net/ipv4/ping.c
103056 +++ b/net/ipv4/ping.c
103057 @@ -59,7 +59,7 @@ struct ping_table {
103058 };
103059
103060 static struct ping_table ping_table;
103061 -struct pingv6_ops pingv6_ops;
103062 +struct pingv6_ops *pingv6_ops;
103063 EXPORT_SYMBOL_GPL(pingv6_ops);
103064
103065 static u16 ping_port_rover;
103066 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103067 return -ENODEV;
103068 }
103069 }
103070 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103071 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103072 scoped);
103073 rcu_read_unlock();
103074
103075 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103076 }
103077 #if IS_ENABLED(CONFIG_IPV6)
103078 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103079 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103080 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103081 #endif
103082 }
103083
103084 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103085 info, (u8 *)icmph);
103086 #if IS_ENABLED(CONFIG_IPV6)
103087 } else if (family == AF_INET6) {
103088 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103089 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103090 info, (u8 *)icmph);
103091 #endif
103092 }
103093 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103094 }
103095
103096 if (inet6_sk(sk)->rxopt.all)
103097 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103098 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103099 if (skb->protocol == htons(ETH_P_IPV6) &&
103100 inet6_sk(sk)->rxopt.all)
103101 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103102 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103103 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103104 ip_cmsg_recv(msg, skb);
103105 #endif
103106 @@ -1108,7 +1108,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103107 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103108 0, sock_i_ino(sp),
103109 atomic_read(&sp->sk_refcnt), sp,
103110 - atomic_read(&sp->sk_drops));
103111 + atomic_read_unchecked(&sp->sk_drops));
103112 }
103113
103114 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103115 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103116 index 739db31..74f0210 100644
103117 --- a/net/ipv4/raw.c
103118 +++ b/net/ipv4/raw.c
103119 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103120 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103121 {
103122 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103123 - atomic_inc(&sk->sk_drops);
103124 + atomic_inc_unchecked(&sk->sk_drops);
103125 kfree_skb(skb);
103126 return NET_RX_DROP;
103127 }
103128 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103129
103130 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103131 {
103132 + struct icmp_filter filter;
103133 +
103134 if (optlen > sizeof(struct icmp_filter))
103135 optlen = sizeof(struct icmp_filter);
103136 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103137 + if (copy_from_user(&filter, optval, optlen))
103138 return -EFAULT;
103139 + raw_sk(sk)->filter = filter;
103140 return 0;
103141 }
103142
103143 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103144 {
103145 int len, ret = -EFAULT;
103146 + struct icmp_filter filter;
103147
103148 if (get_user(len, optlen))
103149 goto out;
103150 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103151 if (len > sizeof(struct icmp_filter))
103152 len = sizeof(struct icmp_filter);
103153 ret = -EFAULT;
103154 - if (put_user(len, optlen) ||
103155 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103156 + filter = raw_sk(sk)->filter;
103157 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103158 goto out;
103159 ret = 0;
103160 out: return ret;
103161 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103162 0, 0L, 0,
103163 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103164 0, sock_i_ino(sp),
103165 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103166 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103167 }
103168
103169 static int raw_seq_show(struct seq_file *seq, void *v)
103170 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103171 index d58dd0e..47de388 100644
103172 --- a/net/ipv4/route.c
103173 +++ b/net/ipv4/route.c
103174 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103175
103176 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103177 {
103178 - return seq_open(file, &rt_cache_seq_ops);
103179 + return seq_open_restrict(file, &rt_cache_seq_ops);
103180 }
103181
103182 static const struct file_operations rt_cache_seq_fops = {
103183 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103184
103185 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103186 {
103187 - return seq_open(file, &rt_cpu_seq_ops);
103188 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103189 }
103190
103191 static const struct file_operations rt_cpu_seq_fops = {
103192 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103193
103194 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103195 {
103196 - return single_open(file, rt_acct_proc_show, NULL);
103197 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103198 }
103199
103200 static const struct file_operations rt_acct_proc_fops = {
103201 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103202
103203 #define IP_IDENTS_SZ 2048u
103204 struct ip_ident_bucket {
103205 - atomic_t id;
103206 + atomic_unchecked_t id;
103207 u32 stamp32;
103208 };
103209
103210 -static struct ip_ident_bucket *ip_idents __read_mostly;
103211 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103212
103213 /* In order to protect privacy, we add a perturbation to identifiers
103214 * if one generator is seldom used. This makes hard for an attacker
103215 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103216 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103217 delta = prandom_u32_max(now - old);
103218
103219 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103220 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103221 }
103222 EXPORT_SYMBOL(ip_idents_reserve);
103223
103224 @@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103225 .maxlen = sizeof(int),
103226 .mode = 0200,
103227 .proc_handler = ipv4_sysctl_rtcache_flush,
103228 + .extra1 = &init_net,
103229 },
103230 { },
103231 };
103232
103233 static __net_init int sysctl_route_net_init(struct net *net)
103234 {
103235 - struct ctl_table *tbl;
103236 + ctl_table_no_const *tbl = NULL;
103237
103238 - tbl = ipv4_route_flush_table;
103239 if (!net_eq(net, &init_net)) {
103240 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103241 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103242 if (tbl == NULL)
103243 goto err_dup;
103244
103245 /* Don't export sysctls to unprivileged users */
103246 if (net->user_ns != &init_user_ns)
103247 tbl[0].procname = NULL;
103248 - }
103249 - tbl[0].extra1 = net;
103250 + tbl[0].extra1 = net;
103251 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103252 + } else
103253 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103254
103255 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103256 if (net->ipv4.route_hdr == NULL)
103257 goto err_reg;
103258 return 0;
103259
103260 err_reg:
103261 - if (tbl != ipv4_route_flush_table)
103262 - kfree(tbl);
103263 + kfree(tbl);
103264 err_dup:
103265 return -ENOMEM;
103266 }
103267 @@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103268
103269 static __net_init int rt_genid_init(struct net *net)
103270 {
103271 - atomic_set(&net->ipv4.rt_genid, 0);
103272 - atomic_set(&net->fnhe_genid, 0);
103273 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103274 + atomic_set_unchecked(&net->fnhe_genid, 0);
103275 get_random_bytes(&net->ipv4.dev_addr_genid,
103276 sizeof(net->ipv4.dev_addr_genid));
103277 return 0;
103278 @@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
103279 {
103280 int rc = 0;
103281
103282 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103283 - if (!ip_idents)
103284 - panic("IP: failed to allocate ip_idents\n");
103285 -
103286 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103287 + prandom_bytes(ip_idents, sizeof(ip_idents));
103288
103289 #ifdef CONFIG_IP_ROUTE_CLASSID
103290 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103291 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103292 index b3c53c8..35cc18d 100644
103293 --- a/net/ipv4/sysctl_net_ipv4.c
103294 +++ b/net/ipv4/sysctl_net_ipv4.c
103295 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103296 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103297 int ret;
103298 int range[2];
103299 - struct ctl_table tmp = {
103300 + ctl_table_no_const tmp = {
103301 .data = &range,
103302 .maxlen = sizeof(range),
103303 .mode = table->mode,
103304 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103305 int ret;
103306 gid_t urange[2];
103307 kgid_t low, high;
103308 - struct ctl_table tmp = {
103309 + ctl_table_no_const tmp = {
103310 .data = &urange,
103311 .maxlen = sizeof(urange),
103312 .mode = table->mode,
103313 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103314 void __user *buffer, size_t *lenp, loff_t *ppos)
103315 {
103316 char val[TCP_CA_NAME_MAX];
103317 - struct ctl_table tbl = {
103318 + ctl_table_no_const tbl = {
103319 .data = val,
103320 .maxlen = TCP_CA_NAME_MAX,
103321 };
103322 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103323 void __user *buffer, size_t *lenp,
103324 loff_t *ppos)
103325 {
103326 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103327 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103328 int ret;
103329
103330 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103331 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103332 void __user *buffer, size_t *lenp,
103333 loff_t *ppos)
103334 {
103335 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103336 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103337 int ret;
103338
103339 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103340 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103341 void __user *buffer, size_t *lenp,
103342 loff_t *ppos)
103343 {
103344 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103345 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103346 struct tcp_fastopen_context *ctxt;
103347 int ret;
103348 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103349 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
103350
103351 static __net_init int ipv4_sysctl_init_net(struct net *net)
103352 {
103353 - struct ctl_table *table;
103354 + ctl_table_no_const *table = NULL;
103355
103356 - table = ipv4_net_table;
103357 if (!net_eq(net, &init_net)) {
103358 int i;
103359
103360 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103361 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103362 if (table == NULL)
103363 goto err_alloc;
103364
103365 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103366 table[i].data += (void *)net - (void *)&init_net;
103367 }
103368
103369 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103370 + if (!net_eq(net, &init_net))
103371 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103372 + else
103373 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103374 if (net->ipv4.ipv4_hdr == NULL)
103375 goto err_reg;
103376
103377 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103378 index d107ee2..bcebf11 100644
103379 --- a/net/ipv4/tcp_input.c
103380 +++ b/net/ipv4/tcp_input.c
103381 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103382 * without any lock. We want to make sure compiler wont store
103383 * intermediate values in this location.
103384 */
103385 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103386 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103387 sk->sk_max_pacing_rate);
103388 }
103389
103390 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103391 * simplifies code)
103392 */
103393 static void
103394 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103395 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103396 struct sk_buff *head, struct sk_buff *tail,
103397 u32 start, u32 end)
103398 {
103399 @@ -5506,6 +5506,7 @@ discard:
103400 tcp_paws_reject(&tp->rx_opt, 0))
103401 goto discard_and_undo;
103402
103403 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103404 if (th->syn) {
103405 /* We see SYN without ACK. It is attempt of
103406 * simultaneous connect with crossed SYNs.
103407 @@ -5556,6 +5557,7 @@ discard:
103408 goto discard;
103409 #endif
103410 }
103411 +#endif
103412 /* "fifth, if neither of the SYN or RST bits is set then
103413 * drop the segment and return."
103414 */
103415 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103416 goto discard;
103417
103418 if (th->syn) {
103419 - if (th->fin)
103420 + if (th->fin || th->urg || th->psh)
103421 goto discard;
103422 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103423 return 1;
103424 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103425 index 944ce5e..5b83585 100644
103426 --- a/net/ipv4/tcp_ipv4.c
103427 +++ b/net/ipv4/tcp_ipv4.c
103428 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
103429 int sysctl_tcp_low_latency __read_mostly;
103430 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103431
103432 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103433 +extern int grsec_enable_blackhole;
103434 +#endif
103435 +
103436 #ifdef CONFIG_TCP_MD5SIG
103437 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103438 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103439 @@ -1471,6 +1475,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103440 return 0;
103441
103442 reset:
103443 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103444 + if (!grsec_enable_blackhole)
103445 +#endif
103446 tcp_v4_send_reset(rsk, skb);
103447 discard:
103448 kfree_skb(skb);
103449 @@ -1635,12 +1642,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103450 TCP_SKB_CB(skb)->sacked = 0;
103451
103452 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103453 - if (!sk)
103454 + if (!sk) {
103455 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103456 + ret = 1;
103457 +#endif
103458 goto no_tcp_socket;
103459 -
103460 + }
103461 process:
103462 - if (sk->sk_state == TCP_TIME_WAIT)
103463 + if (sk->sk_state == TCP_TIME_WAIT) {
103464 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103465 + ret = 2;
103466 +#endif
103467 goto do_time_wait;
103468 + }
103469
103470 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103471 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103472 @@ -1696,6 +1710,10 @@ csum_error:
103473 bad_packet:
103474 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103475 } else {
103476 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103477 + if (!grsec_enable_blackhole || (ret == 1 &&
103478 + (skb->dev->flags & IFF_LOOPBACK)))
103479 +#endif
103480 tcp_v4_send_reset(NULL, skb);
103481 }
103482
103483 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103484 index 63d2680..2db9d6b 100644
103485 --- a/net/ipv4/tcp_minisocks.c
103486 +++ b/net/ipv4/tcp_minisocks.c
103487 @@ -27,6 +27,10 @@
103488 #include <net/inet_common.h>
103489 #include <net/xfrm.h>
103490
103491 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103492 +extern int grsec_enable_blackhole;
103493 +#endif
103494 +
103495 int sysctl_tcp_syncookies __read_mostly = 1;
103496 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103497
103498 @@ -739,7 +743,10 @@ embryonic_reset:
103499 * avoid becoming vulnerable to outside attack aiming at
103500 * resetting legit local connections.
103501 */
103502 - req->rsk_ops->send_reset(sk, skb);
103503 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103504 + if (!grsec_enable_blackhole)
103505 +#endif
103506 + req->rsk_ops->send_reset(sk, skb);
103507 } else if (fastopen) { /* received a valid RST pkt */
103508 reqsk_fastopen_remove(sk, req, true);
103509 tcp_reset(sk);
103510 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103511 index ebf5ff5..4d1ff32 100644
103512 --- a/net/ipv4/tcp_probe.c
103513 +++ b/net/ipv4/tcp_probe.c
103514 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103515 if (cnt + width >= len)
103516 break;
103517
103518 - if (copy_to_user(buf + cnt, tbuf, width))
103519 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103520 return -EFAULT;
103521 cnt += width;
103522 }
103523 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103524 index 9b21ae8..4eb67df 100644
103525 --- a/net/ipv4/tcp_timer.c
103526 +++ b/net/ipv4/tcp_timer.c
103527 @@ -22,6 +22,10 @@
103528 #include <linux/gfp.h>
103529 #include <net/tcp.h>
103530
103531 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103532 +extern int grsec_lastack_retries;
103533 +#endif
103534 +
103535 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103536 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103537 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103538 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103539 }
103540 }
103541
103542 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103543 + if ((sk->sk_state == TCP_LAST_ACK) &&
103544 + (grsec_lastack_retries > 0) &&
103545 + (grsec_lastack_retries < retry_until))
103546 + retry_until = grsec_lastack_retries;
103547 +#endif
103548 +
103549 if (retransmits_timed_out(sk, retry_until,
103550 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103551 /* Has it gone just too far? */
103552 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103553 index cd0db54..93a6518 100644
103554 --- a/net/ipv4/udp.c
103555 +++ b/net/ipv4/udp.c
103556 @@ -87,6 +87,7 @@
103557 #include <linux/types.h>
103558 #include <linux/fcntl.h>
103559 #include <linux/module.h>
103560 +#include <linux/security.h>
103561 #include <linux/socket.h>
103562 #include <linux/sockios.h>
103563 #include <linux/igmp.h>
103564 @@ -114,6 +115,10 @@
103565 #include <net/busy_poll.h>
103566 #include "udp_impl.h"
103567
103568 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103569 +extern int grsec_enable_blackhole;
103570 +#endif
103571 +
103572 struct udp_table udp_table __read_mostly;
103573 EXPORT_SYMBOL(udp_table);
103574
103575 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103576 return true;
103577 }
103578
103579 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103580 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103581 +
103582 /*
103583 * This routine is called by the ICMP module when it gets some
103584 * sort of error condition. If err < 0 then the socket should
103585 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103586 dport = usin->sin_port;
103587 if (dport == 0)
103588 return -EINVAL;
103589 +
103590 + err = gr_search_udp_sendmsg(sk, usin);
103591 + if (err)
103592 + return err;
103593 } else {
103594 if (sk->sk_state != TCP_ESTABLISHED)
103595 return -EDESTADDRREQ;
103596 +
103597 + err = gr_search_udp_sendmsg(sk, NULL);
103598 + if (err)
103599 + return err;
103600 +
103601 daddr = inet->inet_daddr;
103602 dport = inet->inet_dport;
103603 /* Open fast path for connected socket.
103604 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103605 IS_UDPLITE(sk));
103606 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103607 IS_UDPLITE(sk));
103608 - atomic_inc(&sk->sk_drops);
103609 + atomic_inc_unchecked(&sk->sk_drops);
103610 __skb_unlink(skb, rcvq);
103611 __skb_queue_tail(&list_kill, skb);
103612 }
103613 @@ -1262,6 +1279,10 @@ try_again:
103614 if (!skb)
103615 goto out;
103616
103617 + err = gr_search_udp_recvmsg(sk, skb);
103618 + if (err)
103619 + goto out_free;
103620 +
103621 ulen = skb->len - sizeof(struct udphdr);
103622 copied = len;
103623 if (copied > ulen)
103624 @@ -1295,7 +1316,7 @@ try_again:
103625 if (unlikely(err)) {
103626 trace_kfree_skb(skb, udp_recvmsg);
103627 if (!peeked) {
103628 - atomic_inc(&sk->sk_drops);
103629 + atomic_inc_unchecked(&sk->sk_drops);
103630 UDP_INC_STATS_USER(sock_net(sk),
103631 UDP_MIB_INERRORS, is_udplite);
103632 }
103633 @@ -1592,7 +1613,7 @@ csum_error:
103634 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103635 drop:
103636 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103637 - atomic_inc(&sk->sk_drops);
103638 + atomic_inc_unchecked(&sk->sk_drops);
103639 kfree_skb(skb);
103640 return -1;
103641 }
103642 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103643 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103644
103645 if (!skb1) {
103646 - atomic_inc(&sk->sk_drops);
103647 + atomic_inc_unchecked(&sk->sk_drops);
103648 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103649 IS_UDPLITE(sk));
103650 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103651 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103652 goto csum_error;
103653
103654 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103655 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103656 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103657 +#endif
103658 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103659
103660 /*
103661 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103662 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103663 0, sock_i_ino(sp),
103664 atomic_read(&sp->sk_refcnt), sp,
103665 - atomic_read(&sp->sk_drops));
103666 + atomic_read_unchecked(&sp->sk_drops));
103667 }
103668
103669 int udp4_seq_show(struct seq_file *seq, void *v)
103670 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103671 index 6156f68..d6ab46d 100644
103672 --- a/net/ipv4/xfrm4_policy.c
103673 +++ b/net/ipv4/xfrm4_policy.c
103674 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103675 fl4->flowi4_tos = iph->tos;
103676 }
103677
103678 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103679 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103680 {
103681 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103682
103683 - xfrm4_policy_afinfo.garbage_collect(net);
103684 + xfrm_garbage_collect_deferred(net);
103685 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103686 }
103687
103688 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103689
103690 static int __net_init xfrm4_net_init(struct net *net)
103691 {
103692 - struct ctl_table *table;
103693 + ctl_table_no_const *table = NULL;
103694 struct ctl_table_header *hdr;
103695
103696 - table = xfrm4_policy_table;
103697 if (!net_eq(net, &init_net)) {
103698 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103699 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103700 if (!table)
103701 goto err_alloc;
103702
103703 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103704 - }
103705 -
103706 - hdr = register_net_sysctl(net, "net/ipv4", table);
103707 + hdr = register_net_sysctl(net, "net/ipv4", table);
103708 + } else
103709 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103710 if (!hdr)
103711 goto err_reg;
103712
103713 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103714 return 0;
103715
103716 err_reg:
103717 - if (!net_eq(net, &init_net))
103718 - kfree(table);
103719 + kfree(table);
103720 err_alloc:
103721 return -ENOMEM;
103722 }
103723 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103724 index 0169ccf..6f14338 100644
103725 --- a/net/ipv6/addrconf.c
103726 +++ b/net/ipv6/addrconf.c
103727 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103728 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103729 .mtu6 = IPV6_MIN_MTU,
103730 .accept_ra = 1,
103731 - .accept_redirects = 1,
103732 + .accept_redirects = 0,
103733 .autoconf = 1,
103734 .force_mld_version = 0,
103735 .mldv1_unsolicited_report_interval = 10 * HZ,
103736 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103737 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103738 .mtu6 = IPV6_MIN_MTU,
103739 .accept_ra = 1,
103740 - .accept_redirects = 1,
103741 + .accept_redirects = 0,
103742 .autoconf = 1,
103743 .force_mld_version = 0,
103744 .mldv1_unsolicited_report_interval = 10 * HZ,
103745 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103746 idx = 0;
103747 head = &net->dev_index_head[h];
103748 rcu_read_lock();
103749 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103750 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103751 net->dev_base_seq;
103752 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103753 if (idx < s_idx)
103754 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103755 p.iph.ihl = 5;
103756 p.iph.protocol = IPPROTO_IPV6;
103757 p.iph.ttl = 64;
103758 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103759 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103760
103761 if (ops->ndo_do_ioctl) {
103762 mm_segment_t oldfs = get_fs();
103763 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103764 .release = seq_release_net,
103765 };
103766
103767 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103768 +extern void unregister_ipv6_seq_ops_addr(void);
103769 +
103770 static int __net_init if6_proc_net_init(struct net *net)
103771 {
103772 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103773 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103774 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103775 + unregister_ipv6_seq_ops_addr();
103776 return -ENOMEM;
103777 + }
103778 return 0;
103779 }
103780
103781 static void __net_exit if6_proc_net_exit(struct net *net)
103782 {
103783 remove_proc_entry("if_inet6", net->proc_net);
103784 + unregister_ipv6_seq_ops_addr();
103785 }
103786
103787 static struct pernet_operations if6_proc_net_ops = {
103788 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103789 s_ip_idx = ip_idx = cb->args[2];
103790
103791 rcu_read_lock();
103792 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103793 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103794 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103795 idx = 0;
103796 head = &net->dev_index_head[h];
103797 @@ -4536,6 +4543,22 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
103798 return 0;
103799 }
103800
103801 +static const struct nla_policy inet6_af_policy[IFLA_INET6_MAX + 1] = {
103802 + [IFLA_INET6_ADDR_GEN_MODE] = { .type = NLA_U8 },
103803 + [IFLA_INET6_TOKEN] = { .len = sizeof(struct in6_addr) },
103804 +};
103805 +
103806 +static int inet6_validate_link_af(const struct net_device *dev,
103807 + const struct nlattr *nla)
103808 +{
103809 + struct nlattr *tb[IFLA_INET6_MAX + 1];
103810 +
103811 + if (dev && !__in6_dev_get(dev))
103812 + return -EAFNOSUPPORT;
103813 +
103814 + return nla_parse_nested(tb, IFLA_INET6_MAX, nla, inet6_af_policy);
103815 +}
103816 +
103817 static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
103818 {
103819 int err = -EINVAL;
103820 @@ -4788,7 +4811,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103821 rt_genid_bump_ipv6(net);
103822 break;
103823 }
103824 - atomic_inc(&net->ipv6.dev_addr_genid);
103825 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103826 }
103827
103828 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103829 @@ -4808,7 +4831,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103830 int *valp = ctl->data;
103831 int val = *valp;
103832 loff_t pos = *ppos;
103833 - struct ctl_table lctl;
103834 + ctl_table_no_const lctl;
103835 int ret;
103836
103837 /*
103838 @@ -4893,7 +4916,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103839 int *valp = ctl->data;
103840 int val = *valp;
103841 loff_t pos = *ppos;
103842 - struct ctl_table lctl;
103843 + ctl_table_no_const lctl;
103844 int ret;
103845
103846 /*
103847 @@ -5351,6 +5374,7 @@ static struct rtnl_af_ops inet6_ops = {
103848 .family = AF_INET6,
103849 .fill_link_af = inet6_fill_link_af,
103850 .get_link_af_size = inet6_get_link_af_size,
103851 + .validate_link_af = inet6_validate_link_af,
103852 .set_link_af = inet6_set_link_af,
103853 };
103854
103855 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103856 index e8c4400..a4cd5da 100644
103857 --- a/net/ipv6/af_inet6.c
103858 +++ b/net/ipv6/af_inet6.c
103859 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103860 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103861 net->ipv6.sysctl.flowlabel_consistency = 1;
103862 net->ipv6.sysctl.auto_flowlabels = 0;
103863 - atomic_set(&net->ipv6.fib6_sernum, 1);
103864 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103865
103866 err = ipv6_init_mibs(net);
103867 if (err)
103868 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103869 index 11e3945..4f1b785 100644
103870 --- a/net/ipv6/datagram.c
103871 +++ b/net/ipv6/datagram.c
103872 @@ -924,5 +924,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103873 0,
103874 sock_i_ino(sp),
103875 atomic_read(&sp->sk_refcnt), sp,
103876 - atomic_read(&sp->sk_drops));
103877 + atomic_read_unchecked(&sp->sk_drops));
103878 }
103879 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103880 index 97ae700..18dcae0 100644
103881 --- a/net/ipv6/icmp.c
103882 +++ b/net/ipv6/icmp.c
103883 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103884
103885 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103886 {
103887 - struct ctl_table *table;
103888 + ctl_table_no_const *table;
103889
103890 table = kmemdup(ipv6_icmp_table_template,
103891 sizeof(ipv6_icmp_table_template),
103892 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103893 index f1c6d5e..faabef6 100644
103894 --- a/net/ipv6/ip6_fib.c
103895 +++ b/net/ipv6/ip6_fib.c
103896 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103897 int new, old;
103898
103899 do {
103900 - old = atomic_read(&net->ipv6.fib6_sernum);
103901 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103902 new = old < INT_MAX ? old + 1 : 1;
103903 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103904 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103905 old, new) != old);
103906 return new;
103907 }
103908 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103909 index 0e32d2e..dd45cdc 100644
103910 --- a/net/ipv6/ip6_gre.c
103911 +++ b/net/ipv6/ip6_gre.c
103912 @@ -71,8 +71,8 @@ struct ip6gre_net {
103913 struct net_device *fb_tunnel_dev;
103914 };
103915
103916 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103917 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103918 +static struct rtnl_link_ops ip6gre_link_ops;
103919 +static struct rtnl_link_ops ip6gre_tap_ops;
103920 static int ip6gre_tunnel_init(struct net_device *dev);
103921 static void ip6gre_tunnel_setup(struct net_device *dev);
103922 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103923 @@ -417,7 +417,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103924 if (code == ICMPV6_HDR_FIELD)
103925 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
103926
103927 - if (teli && teli == info - 2) {
103928 + if (teli && teli == be32_to_cpu(info) - 2) {
103929 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
103930 if (tel->encap_limit == 0) {
103931 net_warn_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
103932 @@ -429,7 +429,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
103933 }
103934 break;
103935 case ICMPV6_PKT_TOOBIG:
103936 - mtu = info - offset;
103937 + mtu = be32_to_cpu(info) - offset;
103938 if (mtu < IPV6_MIN_MTU)
103939 mtu = IPV6_MIN_MTU;
103940 t->dev->mtu = mtu;
103941 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103942 }
103943
103944
103945 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103946 +static struct inet6_protocol ip6gre_protocol = {
103947 .handler = ip6gre_rcv,
103948 .err_handler = ip6gre_err,
103949 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103950 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103951 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103952 };
103953
103954 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103955 +static struct rtnl_link_ops ip6gre_link_ops = {
103956 .kind = "ip6gre",
103957 .maxtype = IFLA_GRE_MAX,
103958 .policy = ip6gre_policy,
103959 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103960 .fill_info = ip6gre_fill_info,
103961 };
103962
103963 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103964 +static struct rtnl_link_ops ip6gre_tap_ops = {
103965 .kind = "ip6gretap",
103966 .maxtype = IFLA_GRE_MAX,
103967 .policy = ip6gre_policy,
103968 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103969 index 9cb94cf..5678108 100644
103970 --- a/net/ipv6/ip6_tunnel.c
103971 +++ b/net/ipv6/ip6_tunnel.c
103972 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103973
103974 static int ip6_tnl_dev_init(struct net_device *dev);
103975 static void ip6_tnl_dev_setup(struct net_device *dev);
103976 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103977 +static struct rtnl_link_ops ip6_link_ops;
103978
103979 static int ip6_tnl_net_id __read_mostly;
103980 struct ip6_tnl_net {
103981 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103982 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103983 };
103984
103985 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103986 +static struct rtnl_link_ops ip6_link_ops = {
103987 .kind = "ip6tnl",
103988 .maxtype = IFLA_IPTUN_MAX,
103989 .policy = ip6_tnl_policy,
103990 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103991 index bcda14d..49378c9 100644
103992 --- a/net/ipv6/ip6_vti.c
103993 +++ b/net/ipv6/ip6_vti.c
103994 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103995
103996 static int vti6_dev_init(struct net_device *dev);
103997 static void vti6_dev_setup(struct net_device *dev);
103998 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103999 +static struct rtnl_link_ops vti6_link_ops;
104000
104001 static int vti6_net_id __read_mostly;
104002 struct vti6_net {
104003 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
104004 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
104005 };
104006
104007 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
104008 +static struct rtnl_link_ops vti6_link_ops = {
104009 .kind = "vti6",
104010 .maxtype = IFLA_VTI_MAX,
104011 .policy = vti6_policy,
104012 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
104013 index e1a9583..7dd8f4d 100644
104014 --- a/net/ipv6/ipv6_sockglue.c
104015 +++ b/net/ipv6/ipv6_sockglue.c
104016 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104017 if (sk->sk_type != SOCK_STREAM)
104018 return -ENOPROTOOPT;
104019
104020 - msg.msg_control = optval;
104021 + msg.msg_control = (void __force_kernel *)optval;
104022 msg.msg_controllen = len;
104023 msg.msg_flags = flags;
104024
104025 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104026 index e080fbb..412b3cf 100644
104027 --- a/net/ipv6/netfilter/ip6_tables.c
104028 +++ b/net/ipv6/netfilter/ip6_tables.c
104029 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104030 #endif
104031
104032 static int get_info(struct net *net, void __user *user,
104033 - const int *len, int compat)
104034 + int len, int compat)
104035 {
104036 char name[XT_TABLE_MAXNAMELEN];
104037 struct xt_table *t;
104038 int ret;
104039
104040 - if (*len != sizeof(struct ip6t_getinfo)) {
104041 - duprintf("length %u != %zu\n", *len,
104042 + if (len != sizeof(struct ip6t_getinfo)) {
104043 + duprintf("length %u != %zu\n", len,
104044 sizeof(struct ip6t_getinfo));
104045 return -EINVAL;
104046 }
104047 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104048 info.size = private->size;
104049 strcpy(info.name, name);
104050
104051 - if (copy_to_user(user, &info, *len) != 0)
104052 + if (copy_to_user(user, &info, len) != 0)
104053 ret = -EFAULT;
104054 else
104055 ret = 0;
104056 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104057
104058 switch (cmd) {
104059 case IP6T_SO_GET_INFO:
104060 - ret = get_info(sock_net(sk), user, len, 1);
104061 + ret = get_info(sock_net(sk), user, *len, 1);
104062 break;
104063 case IP6T_SO_GET_ENTRIES:
104064 ret = compat_get_entries(sock_net(sk), user, len);
104065 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104066
104067 switch (cmd) {
104068 case IP6T_SO_GET_INFO:
104069 - ret = get_info(sock_net(sk), user, len, 0);
104070 + ret = get_info(sock_net(sk), user, *len, 0);
104071 break;
104072
104073 case IP6T_SO_GET_ENTRIES:
104074 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104075 index 6f187c8..34b367f 100644
104076 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104077 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104078 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104079
104080 static int nf_ct_frag6_sysctl_register(struct net *net)
104081 {
104082 - struct ctl_table *table;
104083 + ctl_table_no_const *table = NULL;
104084 struct ctl_table_header *hdr;
104085
104086 - table = nf_ct_frag6_sysctl_table;
104087 if (!net_eq(net, &init_net)) {
104088 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104089 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104090 GFP_KERNEL);
104091 if (table == NULL)
104092 goto err_alloc;
104093 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104094 table[2].data = &net->nf_frag.frags.high_thresh;
104095 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104096 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104097 - }
104098 -
104099 - hdr = register_net_sysctl(net, "net/netfilter", table);
104100 + hdr = register_net_sysctl(net, "net/netfilter", table);
104101 + } else
104102 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104103 if (hdr == NULL)
104104 goto err_reg;
104105
104106 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104107 return 0;
104108
104109 err_reg:
104110 - if (!net_eq(net, &init_net))
104111 - kfree(table);
104112 + kfree(table);
104113 err_alloc:
104114 return -ENOMEM;
104115 }
104116 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104117 index 5b7a1ed..d9da205 100644
104118 --- a/net/ipv6/ping.c
104119 +++ b/net/ipv6/ping.c
104120 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104121 };
104122 #endif
104123
104124 +static struct pingv6_ops real_pingv6_ops = {
104125 + .ipv6_recv_error = ipv6_recv_error,
104126 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104127 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104128 + .icmpv6_err_convert = icmpv6_err_convert,
104129 + .ipv6_icmp_error = ipv6_icmp_error,
104130 + .ipv6_chk_addr = ipv6_chk_addr,
104131 +};
104132 +
104133 +static struct pingv6_ops dummy_pingv6_ops = {
104134 + .ipv6_recv_error = dummy_ipv6_recv_error,
104135 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104136 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104137 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104138 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104139 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104140 +};
104141 +
104142 int __init pingv6_init(void)
104143 {
104144 #ifdef CONFIG_PROC_FS
104145 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
104146 if (ret)
104147 return ret;
104148 #endif
104149 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104150 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104151 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104152 - ip6_datagram_recv_specific_ctl;
104153 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104154 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104155 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104156 + pingv6_ops = &real_pingv6_ops;
104157 return inet6_register_protosw(&pingv6_protosw);
104158 }
104159
104160 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
104161 */
104162 void pingv6_exit(void)
104163 {
104164 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104165 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104166 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104167 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104168 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104169 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104170 #ifdef CONFIG_PROC_FS
104171 unregister_pernet_subsys(&ping_v6_net_ops);
104172 #endif
104173 + pingv6_ops = &dummy_pingv6_ops;
104174 inet6_unregister_protosw(&pingv6_protosw);
104175 }
104176 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104177 index 1752cd0..3c6af41 100644
104178 --- a/net/ipv6/proc.c
104179 +++ b/net/ipv6/proc.c
104180 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104181 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104182 goto proc_snmp6_fail;
104183
104184 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104185 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104186 if (!net->mib.proc_net_devsnmp6)
104187 goto proc_dev_snmp6_fail;
104188 return 0;
104189 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104190 index 896af88..6e2ba628 100644
104191 --- a/net/ipv6/raw.c
104192 +++ b/net/ipv6/raw.c
104193 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104194 {
104195 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104196 skb_checksum_complete(skb)) {
104197 - atomic_inc(&sk->sk_drops);
104198 + atomic_inc_unchecked(&sk->sk_drops);
104199 kfree_skb(skb);
104200 return NET_RX_DROP;
104201 }
104202 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104203 struct raw6_sock *rp = raw6_sk(sk);
104204
104205 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104206 - atomic_inc(&sk->sk_drops);
104207 + atomic_inc_unchecked(&sk->sk_drops);
104208 kfree_skb(skb);
104209 return NET_RX_DROP;
104210 }
104211 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104212
104213 if (inet->hdrincl) {
104214 if (skb_checksum_complete(skb)) {
104215 - atomic_inc(&sk->sk_drops);
104216 + atomic_inc_unchecked(&sk->sk_drops);
104217 kfree_skb(skb);
104218 return NET_RX_DROP;
104219 }
104220 @@ -608,7 +608,7 @@ out:
104221 return err;
104222 }
104223
104224 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104225 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104226 struct flowi6 *fl6, struct dst_entry **dstp,
104227 unsigned int flags)
104228 {
104229 @@ -914,12 +914,15 @@ do_confirm:
104230 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104231 char __user *optval, int optlen)
104232 {
104233 + struct icmp6_filter filter;
104234 +
104235 switch (optname) {
104236 case ICMPV6_FILTER:
104237 if (optlen > sizeof(struct icmp6_filter))
104238 optlen = sizeof(struct icmp6_filter);
104239 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104240 + if (copy_from_user(&filter, optval, optlen))
104241 return -EFAULT;
104242 + raw6_sk(sk)->filter = filter;
104243 return 0;
104244 default:
104245 return -ENOPROTOOPT;
104246 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104247 char __user *optval, int __user *optlen)
104248 {
104249 int len;
104250 + struct icmp6_filter filter;
104251
104252 switch (optname) {
104253 case ICMPV6_FILTER:
104254 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104255 len = sizeof(struct icmp6_filter);
104256 if (put_user(len, optlen))
104257 return -EFAULT;
104258 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104259 + filter = raw6_sk(sk)->filter;
104260 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104261 return -EFAULT;
104262 return 0;
104263 default:
104264 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104265 index 1a157ca..9fc05f4 100644
104266 --- a/net/ipv6/reassembly.c
104267 +++ b/net/ipv6/reassembly.c
104268 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104269
104270 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104271 {
104272 - struct ctl_table *table;
104273 + ctl_table_no_const *table = NULL;
104274 struct ctl_table_header *hdr;
104275
104276 - table = ip6_frags_ns_ctl_table;
104277 if (!net_eq(net, &init_net)) {
104278 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104279 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104280 if (table == NULL)
104281 goto err_alloc;
104282
104283 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104284 /* Don't export sysctls to unprivileged users */
104285 if (net->user_ns != &init_user_ns)
104286 table[0].procname = NULL;
104287 - }
104288 + hdr = register_net_sysctl(net, "net/ipv6", table);
104289 + } else
104290 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104291
104292 - hdr = register_net_sysctl(net, "net/ipv6", table);
104293 if (hdr == NULL)
104294 goto err_reg;
104295
104296 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104297 return 0;
104298
104299 err_reg:
104300 - if (!net_eq(net, &init_net))
104301 - kfree(table);
104302 + kfree(table);
104303 err_alloc:
104304 return -ENOMEM;
104305 }
104306 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104307 index d02ee01..42a612c 100644
104308 --- a/net/ipv6/route.c
104309 +++ b/net/ipv6/route.c
104310 @@ -2962,7 +2962,7 @@ struct ctl_table ipv6_route_table_template[] = {
104311
104312 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104313 {
104314 - struct ctl_table *table;
104315 + ctl_table_no_const *table;
104316
104317 table = kmemdup(ipv6_route_table_template,
104318 sizeof(ipv6_route_table_template),
104319 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104320 index a24557a..ade77d3 100644
104321 --- a/net/ipv6/sit.c
104322 +++ b/net/ipv6/sit.c
104323 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104324 static void ipip6_dev_free(struct net_device *dev);
104325 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104326 __be32 *v4dst);
104327 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104328 +static struct rtnl_link_ops sit_link_ops;
104329
104330 static int sit_net_id __read_mostly;
104331 struct sit_net {
104332 @@ -1505,12 +1505,12 @@ static bool ipip6_netlink_encap_parms(struct nlattr *data[],
104333
104334 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
104335 ret = true;
104336 - ipencap->sport = nla_get_u16(data[IFLA_IPTUN_ENCAP_SPORT]);
104337 + ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
104338 }
104339
104340 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
104341 ret = true;
104342 - ipencap->dport = nla_get_u16(data[IFLA_IPTUN_ENCAP_DPORT]);
104343 + ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
104344 }
104345
104346 return ret;
104347 @@ -1706,9 +1706,9 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
104348
104349 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE,
104350 tunnel->encap.type) ||
104351 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_SPORT,
104352 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT,
104353 tunnel->encap.sport) ||
104354 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_DPORT,
104355 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT,
104356 tunnel->encap.dport) ||
104357 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS,
104358 tunnel->encap.dport))
104359 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104360 unregister_netdevice_queue(dev, head);
104361 }
104362
104363 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104364 +static struct rtnl_link_ops sit_link_ops = {
104365 .kind = "sit",
104366 .maxtype = IFLA_IPTUN_MAX,
104367 .policy = ipip6_policy,
104368 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104369 index c5c10fa..2577d51 100644
104370 --- a/net/ipv6/sysctl_net_ipv6.c
104371 +++ b/net/ipv6/sysctl_net_ipv6.c
104372 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
104373
104374 static int __net_init ipv6_sysctl_net_init(struct net *net)
104375 {
104376 - struct ctl_table *ipv6_table;
104377 + ctl_table_no_const *ipv6_table;
104378 struct ctl_table *ipv6_route_table;
104379 struct ctl_table *ipv6_icmp_table;
104380 int err;
104381 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104382 index c113602..0cccb46 100644
104383 --- a/net/ipv6/tcp_ipv6.c
104384 +++ b/net/ipv6/tcp_ipv6.c
104385 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104386 }
104387 }
104388
104389 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104390 +extern int grsec_enable_blackhole;
104391 +#endif
104392 +
104393 static void tcp_v6_hash(struct sock *sk)
104394 {
104395 if (sk->sk_state != TCP_CLOSE) {
104396 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104397 return 0;
104398
104399 reset:
104400 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104401 + if (!grsec_enable_blackhole)
104402 +#endif
104403 tcp_v6_send_reset(sk, skb);
104404 discard:
104405 if (opt_skb)
104406 @@ -1441,12 +1448,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104407
104408 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
104409 inet6_iif(skb));
104410 - if (!sk)
104411 + if (!sk) {
104412 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104413 + ret = 1;
104414 +#endif
104415 goto no_tcp_socket;
104416 + }
104417
104418 process:
104419 - if (sk->sk_state == TCP_TIME_WAIT)
104420 + if (sk->sk_state == TCP_TIME_WAIT) {
104421 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104422 + ret = 2;
104423 +#endif
104424 goto do_time_wait;
104425 + }
104426
104427 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104428 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104429 @@ -1497,6 +1512,10 @@ csum_error:
104430 bad_packet:
104431 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104432 } else {
104433 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104434 + if (!grsec_enable_blackhole || (ret == 1 &&
104435 + (skb->dev->flags & IFF_LOOPBACK)))
104436 +#endif
104437 tcp_v6_send_reset(NULL, skb);
104438 }
104439
104440 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104441 index f6ba535..b41033f 100644
104442 --- a/net/ipv6/udp.c
104443 +++ b/net/ipv6/udp.c
104444 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104445 udp_ipv6_hash_secret + net_hash_mix(net));
104446 }
104447
104448 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104449 +extern int grsec_enable_blackhole;
104450 +#endif
104451 +
104452 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104453 {
104454 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104455 @@ -434,7 +438,7 @@ try_again:
104456 if (unlikely(err)) {
104457 trace_kfree_skb(skb, udpv6_recvmsg);
104458 if (!peeked) {
104459 - atomic_inc(&sk->sk_drops);
104460 + atomic_inc_unchecked(&sk->sk_drops);
104461 if (is_udp4)
104462 UDP_INC_STATS_USER(sock_net(sk),
104463 UDP_MIB_INERRORS,
104464 @@ -701,7 +705,7 @@ csum_error:
104465 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104466 drop:
104467 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104468 - atomic_inc(&sk->sk_drops);
104469 + atomic_inc_unchecked(&sk->sk_drops);
104470 kfree_skb(skb);
104471 return -1;
104472 }
104473 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104474 if (likely(skb1 == NULL))
104475 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104476 if (!skb1) {
104477 - atomic_inc(&sk->sk_drops);
104478 + atomic_inc_unchecked(&sk->sk_drops);
104479 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104480 IS_UDPLITE(sk));
104481 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104482 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104483 goto csum_error;
104484
104485 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104486 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104487 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104488 +#endif
104489 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104490
104491 kfree_skb(skb);
104492 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104493 index 5f98364..691985a 100644
104494 --- a/net/ipv6/xfrm6_policy.c
104495 +++ b/net/ipv6/xfrm6_policy.c
104496 @@ -130,12 +130,18 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104497 {
104498 struct flowi6 *fl6 = &fl->u.ip6;
104499 int onlyproto = 0;
104500 - u16 offset = skb_network_header_len(skb);
104501 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104502 + u16 offset = sizeof(*hdr);
104503 struct ipv6_opt_hdr *exthdr;
104504 const unsigned char *nh = skb_network_header(skb);
104505 - u8 nexthdr = nh[IP6CB(skb)->nhoff];
104506 + u16 nhoff = IP6CB(skb)->nhoff;
104507 int oif = 0;
104508 + u8 nexthdr;
104509 +
104510 + if (!nhoff)
104511 + nhoff = offsetof(struct ipv6hdr, nexthdr);
104512 +
104513 + nexthdr = nh[nhoff];
104514
104515 if (skb_dst(skb))
104516 oif = skb_dst(skb)->dev->ifindex;
104517 @@ -217,11 +223,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104518 }
104519 }
104520
104521 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104522 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104523 {
104524 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104525
104526 - xfrm6_policy_afinfo.garbage_collect(net);
104527 + xfrm_garbage_collect_deferred(net);
104528 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104529 }
104530
104531 @@ -334,19 +340,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104532
104533 static int __net_init xfrm6_net_init(struct net *net)
104534 {
104535 - struct ctl_table *table;
104536 + ctl_table_no_const *table = NULL;
104537 struct ctl_table_header *hdr;
104538
104539 - table = xfrm6_policy_table;
104540 if (!net_eq(net, &init_net)) {
104541 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104542 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104543 if (!table)
104544 goto err_alloc;
104545
104546 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104547 - }
104548 + hdr = register_net_sysctl(net, "net/ipv6", table);
104549 + } else
104550 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104551
104552 - hdr = register_net_sysctl(net, "net/ipv6", table);
104553 if (!hdr)
104554 goto err_reg;
104555
104556 @@ -354,8 +360,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104557 return 0;
104558
104559 err_reg:
104560 - if (!net_eq(net, &init_net))
104561 - kfree(table);
104562 + kfree(table);
104563 err_alloc:
104564 return -ENOMEM;
104565 }
104566 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104567 index e15c16a..7cf07aa 100644
104568 --- a/net/ipx/ipx_proc.c
104569 +++ b/net/ipx/ipx_proc.c
104570 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104571 struct proc_dir_entry *p;
104572 int rc = -ENOMEM;
104573
104574 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104575 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104576
104577 if (!ipx_proc_dir)
104578 goto out;
104579 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104580 index 61ceb4c..e788eb8 100644
104581 --- a/net/irda/ircomm/ircomm_tty.c
104582 +++ b/net/irda/ircomm/ircomm_tty.c
104583 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104584 add_wait_queue(&port->open_wait, &wait);
104585
104586 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104587 - __FILE__, __LINE__, tty->driver->name, port->count);
104588 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104589
104590 spin_lock_irqsave(&port->lock, flags);
104591 - port->count--;
104592 + atomic_dec(&port->count);
104593 port->blocked_open++;
104594 spin_unlock_irqrestore(&port->lock, flags);
104595
104596 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104597 }
104598
104599 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104600 - __FILE__, __LINE__, tty->driver->name, port->count);
104601 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104602
104603 schedule();
104604 }
104605 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104606
104607 spin_lock_irqsave(&port->lock, flags);
104608 if (!tty_hung_up_p(filp))
104609 - port->count++;
104610 + atomic_inc(&port->count);
104611 port->blocked_open--;
104612 spin_unlock_irqrestore(&port->lock, flags);
104613
104614 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104615 - __FILE__, __LINE__, tty->driver->name, port->count);
104616 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104617
104618 if (!retval)
104619 port->flags |= ASYNC_NORMAL_ACTIVE;
104620 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104621
104622 /* ++ is not atomic, so this should be protected - Jean II */
104623 spin_lock_irqsave(&self->port.lock, flags);
104624 - self->port.count++;
104625 + atomic_inc(&self->port.count);
104626 spin_unlock_irqrestore(&self->port.lock, flags);
104627 tty_port_tty_set(&self->port, tty);
104628
104629 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104630 - self->line, self->port.count);
104631 + self->line, atomic_read(&self->port.count));
104632
104633 /* Not really used by us, but lets do it anyway */
104634 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104635 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104636 tty_kref_put(port->tty);
104637 }
104638 port->tty = NULL;
104639 - port->count = 0;
104640 + atomic_set(&port->count, 0);
104641 spin_unlock_irqrestore(&port->lock, flags);
104642
104643 wake_up_interruptible(&port->open_wait);
104644 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104645 seq_putc(m, '\n');
104646
104647 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104648 - seq_printf(m, "Open count: %d\n", self->port.count);
104649 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104650 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104651 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104652
104653 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104654 index b9ac598..f88cc56 100644
104655 --- a/net/irda/irproc.c
104656 +++ b/net/irda/irproc.c
104657 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104658 {
104659 int i;
104660
104661 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104662 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104663 if (proc_irda == NULL)
104664 return;
104665
104666 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104667 index a089b6b..3ca3b60 100644
104668 --- a/net/iucv/af_iucv.c
104669 +++ b/net/iucv/af_iucv.c
104670 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104671 {
104672 char name[12];
104673
104674 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104675 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104676 while (__iucv_get_sock_by_name(name)) {
104677 sprintf(name, "%08x",
104678 - atomic_inc_return(&iucv_sk_list.autobind_name));
104679 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104680 }
104681 memcpy(iucv->src_name, name, 8);
104682 }
104683 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104684 index 2a6a1fd..6c112b0 100644
104685 --- a/net/iucv/iucv.c
104686 +++ b/net/iucv/iucv.c
104687 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104688 return NOTIFY_OK;
104689 }
104690
104691 -static struct notifier_block __refdata iucv_cpu_notifier = {
104692 +static struct notifier_block iucv_cpu_notifier = {
104693 .notifier_call = iucv_cpu_notify,
104694 };
104695
104696 diff --git a/net/key/af_key.c b/net/key/af_key.c
104697 index 1847ec4..26ef732 100644
104698 --- a/net/key/af_key.c
104699 +++ b/net/key/af_key.c
104700 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104701 static u32 get_acqseq(void)
104702 {
104703 u32 res;
104704 - static atomic_t acqseq;
104705 + static atomic_unchecked_t acqseq;
104706
104707 do {
104708 - res = atomic_inc_return(&acqseq);
104709 + res = atomic_inc_return_unchecked(&acqseq);
104710 } while (!res);
104711 return res;
104712 }
104713 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104714 index edb78e6..8dc654a 100644
104715 --- a/net/l2tp/l2tp_eth.c
104716 +++ b/net/l2tp/l2tp_eth.c
104717 @@ -42,12 +42,12 @@ struct l2tp_eth {
104718 struct sock *tunnel_sock;
104719 struct l2tp_session *session;
104720 struct list_head list;
104721 - atomic_long_t tx_bytes;
104722 - atomic_long_t tx_packets;
104723 - atomic_long_t tx_dropped;
104724 - atomic_long_t rx_bytes;
104725 - atomic_long_t rx_packets;
104726 - atomic_long_t rx_errors;
104727 + atomic_long_unchecked_t tx_bytes;
104728 + atomic_long_unchecked_t tx_packets;
104729 + atomic_long_unchecked_t tx_dropped;
104730 + atomic_long_unchecked_t rx_bytes;
104731 + atomic_long_unchecked_t rx_packets;
104732 + atomic_long_unchecked_t rx_errors;
104733 };
104734
104735 /* via l2tp_session_priv() */
104736 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104737 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104738
104739 if (likely(ret == NET_XMIT_SUCCESS)) {
104740 - atomic_long_add(len, &priv->tx_bytes);
104741 - atomic_long_inc(&priv->tx_packets);
104742 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104743 + atomic_long_inc_unchecked(&priv->tx_packets);
104744 } else {
104745 - atomic_long_inc(&priv->tx_dropped);
104746 + atomic_long_inc_unchecked(&priv->tx_dropped);
104747 }
104748 return NETDEV_TX_OK;
104749 }
104750 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104751 {
104752 struct l2tp_eth *priv = netdev_priv(dev);
104753
104754 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104755 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104756 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104757 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104758 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104759 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104760 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104761 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104762 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104763 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104764 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104765 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104766 return stats;
104767 }
104768
104769 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104770 nf_reset(skb);
104771
104772 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104773 - atomic_long_inc(&priv->rx_packets);
104774 - atomic_long_add(data_len, &priv->rx_bytes);
104775 + atomic_long_inc_unchecked(&priv->rx_packets);
104776 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104777 } else {
104778 - atomic_long_inc(&priv->rx_errors);
104779 + atomic_long_inc_unchecked(&priv->rx_errors);
104780 }
104781 return;
104782
104783 error:
104784 - atomic_long_inc(&priv->rx_errors);
104785 + atomic_long_inc_unchecked(&priv->rx_errors);
104786 kfree_skb(skb);
104787 }
104788
104789 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104790 index 1a3c7e0..80f8b0c 100644
104791 --- a/net/llc/llc_proc.c
104792 +++ b/net/llc/llc_proc.c
104793 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104794 int rc = -ENOMEM;
104795 struct proc_dir_entry *p;
104796
104797 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104798 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104799 if (!llc_proc_dir)
104800 goto out;
104801
104802 diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c
104803 index 612a5dd..799bafc 100644
104804 --- a/net/llc/sysctl_net_llc.c
104805 +++ b/net/llc/sysctl_net_llc.c
104806 @@ -18,28 +18,28 @@ static struct ctl_table llc2_timeout_table[] = {
104807 {
104808 .procname = "ack",
104809 .data = &sysctl_llc2_ack_timeout,
104810 - .maxlen = sizeof(long),
104811 + .maxlen = sizeof(sysctl_llc2_ack_timeout),
104812 .mode = 0644,
104813 .proc_handler = proc_dointvec_jiffies,
104814 },
104815 {
104816 .procname = "busy",
104817 .data = &sysctl_llc2_busy_timeout,
104818 - .maxlen = sizeof(long),
104819 + .maxlen = sizeof(sysctl_llc2_busy_timeout),
104820 .mode = 0644,
104821 .proc_handler = proc_dointvec_jiffies,
104822 },
104823 {
104824 .procname = "p",
104825 .data = &sysctl_llc2_p_timeout,
104826 - .maxlen = sizeof(long),
104827 + .maxlen = sizeof(sysctl_llc2_p_timeout),
104828 .mode = 0644,
104829 .proc_handler = proc_dointvec_jiffies,
104830 },
104831 {
104832 .procname = "rej",
104833 .data = &sysctl_llc2_rej_timeout,
104834 - .maxlen = sizeof(long),
104835 + .maxlen = sizeof(sysctl_llc2_rej_timeout),
104836 .mode = 0644,
104837 .proc_handler = proc_dointvec_jiffies,
104838 },
104839 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104840 index 343da1e..509873f 100644
104841 --- a/net/mac80211/cfg.c
104842 +++ b/net/mac80211/cfg.c
104843 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104844 ret = ieee80211_vif_use_channel(sdata, chandef,
104845 IEEE80211_CHANCTX_EXCLUSIVE);
104846 }
104847 - } else if (local->open_count == local->monitors) {
104848 + } else if (local_read(&local->open_count) == local->monitors) {
104849 local->_oper_chandef = *chandef;
104850 ieee80211_hw_config(local, 0);
104851 }
104852 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104853 else
104854 local->probe_req_reg--;
104855
104856 - if (!local->open_count)
104857 + if (!local_read(&local->open_count))
104858 break;
104859
104860 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104861 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104862 if (chanctx_conf) {
104863 *chandef = sdata->vif.bss_conf.chandef;
104864 ret = 0;
104865 - } else if (local->open_count > 0 &&
104866 - local->open_count == local->monitors &&
104867 + } else if (local_read(&local->open_count) > 0 &&
104868 + local_read(&local->open_count) == local->monitors &&
104869 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104870 if (local->use_chanctx)
104871 *chandef = local->monitor_chandef;
104872 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104873 index 8c68da3..0695016 100644
104874 --- a/net/mac80211/ieee80211_i.h
104875 +++ b/net/mac80211/ieee80211_i.h
104876 @@ -29,6 +29,7 @@
104877 #include <net/ieee80211_radiotap.h>
104878 #include <net/cfg80211.h>
104879 #include <net/mac80211.h>
104880 +#include <asm/local.h>
104881 #include "key.h"
104882 #include "sta_info.h"
104883 #include "debug.h"
104884 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
104885 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104886 spinlock_t queue_stop_reason_lock;
104887
104888 - int open_count;
104889 + local_t open_count;
104890 int monitors, cooked_mntrs;
104891 /* number of interfaces with corresponding FIF_ flags */
104892 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104893 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104894 index eeae0ab..0f24585 100644
104895 --- a/net/mac80211/iface.c
104896 +++ b/net/mac80211/iface.c
104897 @@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104898 break;
104899 }
104900
104901 - if (local->open_count == 0) {
104902 + if (local_read(&local->open_count) == 0) {
104903 res = drv_start(local);
104904 if (res)
104905 goto err_del_bss;
104906 @@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104907 res = drv_add_interface(local, sdata);
104908 if (res)
104909 goto err_stop;
104910 - } else if (local->monitors == 0 && local->open_count == 0) {
104911 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104912 res = ieee80211_add_virtual_monitor(local);
104913 if (res)
104914 goto err_stop;
104915 @@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104916 atomic_inc(&local->iff_promiscs);
104917
104918 if (coming_up)
104919 - local->open_count++;
104920 + local_inc(&local->open_count);
104921
104922 if (hw_reconf_flags)
104923 ieee80211_hw_config(local, hw_reconf_flags);
104924 @@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104925 err_del_interface:
104926 drv_remove_interface(local, sdata);
104927 err_stop:
104928 - if (!local->open_count)
104929 + if (!local_read(&local->open_count))
104930 drv_stop(local);
104931 err_del_bss:
104932 sdata->bss = NULL;
104933 @@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104934 }
104935
104936 if (going_down)
104937 - local->open_count--;
104938 + local_dec(&local->open_count);
104939
104940 switch (sdata->vif.type) {
104941 case NL80211_IFTYPE_AP_VLAN:
104942 @@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104943 }
104944 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104945
104946 - if (local->open_count == 0)
104947 + if (local_read(&local->open_count) == 0)
104948 ieee80211_clear_tx_pending(local);
104949
104950 /*
104951 @@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104952 if (cancel_scan)
104953 flush_delayed_work(&local->scan_work);
104954
104955 - if (local->open_count == 0) {
104956 + if (local_read(&local->open_count) == 0) {
104957 ieee80211_stop_device(local);
104958
104959 /* no reconfiguring after stop! */
104960 @@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104961 ieee80211_configure_filter(local);
104962 ieee80211_hw_config(local, hw_reconf_flags);
104963
104964 - if (local->monitors == local->open_count)
104965 + if (local->monitors == local_read(&local->open_count))
104966 ieee80211_add_virtual_monitor(local);
104967 }
104968
104969 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104970 index 0de7c93..884b2ca 100644
104971 --- a/net/mac80211/main.c
104972 +++ b/net/mac80211/main.c
104973 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104974 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104975 IEEE80211_CONF_CHANGE_POWER);
104976
104977 - if (changed && local->open_count) {
104978 + if (changed && local_read(&local->open_count)) {
104979 ret = drv_config(local, changed);
104980 /*
104981 * Goal:
104982 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104983 index 4a95fe3..0bfd713 100644
104984 --- a/net/mac80211/pm.c
104985 +++ b/net/mac80211/pm.c
104986 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104987 struct ieee80211_sub_if_data *sdata;
104988 struct sta_info *sta;
104989
104990 - if (!local->open_count)
104991 + if (!local_read(&local->open_count))
104992 goto suspend;
104993
104994 ieee80211_scan_cancel(local);
104995 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104996 cancel_work_sync(&local->dynamic_ps_enable_work);
104997 del_timer_sync(&local->dynamic_ps_timer);
104998
104999 - local->wowlan = wowlan && local->open_count;
105000 + local->wowlan = wowlan && local_read(&local->open_count);
105001 if (local->wowlan) {
105002 int err = drv_suspend(local, wowlan);
105003 if (err < 0) {
105004 @@ -126,7 +126,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105005 WARN_ON(!list_empty(&local->chanctx_list));
105006
105007 /* stop hardware - this must stop RX */
105008 - if (local->open_count)
105009 + if (local_read(&local->open_count))
105010 ieee80211_stop_device(local);
105011
105012 suspend:
105013 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
105014 index 6081329..ab23834 100644
105015 --- a/net/mac80211/rate.c
105016 +++ b/net/mac80211/rate.c
105017 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
105018
105019 ASSERT_RTNL();
105020
105021 - if (local->open_count)
105022 + if (local_read(&local->open_count))
105023 return -EBUSY;
105024
105025 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
105026 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
105027 index 3c61060..7bed2e3 100644
105028 --- a/net/mac80211/util.c
105029 +++ b/net/mac80211/util.c
105030 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105031 }
105032 #endif
105033 /* everything else happens only if HW was up & running */
105034 - if (!local->open_count)
105035 + if (!local_read(&local->open_count))
105036 goto wake_up;
105037
105038 /*
105039 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105040 local->in_reconfig = false;
105041 barrier();
105042
105043 - if (local->monitors == local->open_count && local->monitors > 0)
105044 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105045 ieee80211_add_virtual_monitor(local);
105046
105047 /*
105048 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105049 index ae5096ab..e5aa70a 100644
105050 --- a/net/netfilter/Kconfig
105051 +++ b/net/netfilter/Kconfig
105052 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
105053
105054 To compile it as a module, choose M here. If unsure, say N.
105055
105056 +config NETFILTER_XT_MATCH_GRADM
105057 + tristate '"gradm" match support'
105058 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105059 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105060 + ---help---
105061 + The gradm match allows to match on grsecurity RBAC being enabled.
105062 + It is useful when iptables rules are applied early on bootup to
105063 + prevent connections to the machine (except from a trusted host)
105064 + while the RBAC system is disabled.
105065 +
105066 config NETFILTER_XT_MATCH_HASHLIMIT
105067 tristate '"hashlimit" match support'
105068 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105069 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105070 index a9571be..c59e173 100644
105071 --- a/net/netfilter/Makefile
105072 +++ b/net/netfilter/Makefile
105073 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105074 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105075 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105076 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105077 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105078 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105079 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105080 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105081 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105082 index d259da3..6a32b2c 100644
105083 --- a/net/netfilter/ipset/ip_set_core.c
105084 +++ b/net/netfilter/ipset/ip_set_core.c
105085 @@ -1952,7 +1952,7 @@ done:
105086 return ret;
105087 }
105088
105089 -static struct nf_sockopt_ops so_set __read_mostly = {
105090 +static struct nf_sockopt_ops so_set = {
105091 .pf = PF_INET,
105092 .get_optmin = SO_IP_SET,
105093 .get_optmax = SO_IP_SET + 1,
105094 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105095 index b0f7b62..0541842 100644
105096 --- a/net/netfilter/ipvs/ip_vs_conn.c
105097 +++ b/net/netfilter/ipvs/ip_vs_conn.c
105098 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105099 /* Increase the refcnt counter of the dest */
105100 ip_vs_dest_hold(dest);
105101
105102 - conn_flags = atomic_read(&dest->conn_flags);
105103 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
105104 if (cp->protocol != IPPROTO_UDP)
105105 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105106 flags = cp->flags;
105107 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
105108
105109 cp->control = NULL;
105110 atomic_set(&cp->n_control, 0);
105111 - atomic_set(&cp->in_pkts, 0);
105112 + atomic_set_unchecked(&cp->in_pkts, 0);
105113
105114 cp->packet_xmit = NULL;
105115 cp->app = NULL;
105116 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105117
105118 /* Don't drop the entry if its number of incoming packets is not
105119 located in [0, 8] */
105120 - i = atomic_read(&cp->in_pkts);
105121 + i = atomic_read_unchecked(&cp->in_pkts);
105122 if (i > 8 || i < 0) return 0;
105123
105124 if (!todrop_rate[i]) return 0;
105125 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105126 index 990decb..5075248 100644
105127 --- a/net/netfilter/ipvs/ip_vs_core.c
105128 +++ b/net/netfilter/ipvs/ip_vs_core.c
105129 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105130 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105131 /* do not touch skb anymore */
105132
105133 - atomic_inc(&cp->in_pkts);
105134 + atomic_inc_unchecked(&cp->in_pkts);
105135 ip_vs_conn_put(cp);
105136 return ret;
105137 }
105138 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105139 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105140 pkts = sysctl_sync_threshold(ipvs);
105141 else
105142 - pkts = atomic_add_return(1, &cp->in_pkts);
105143 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105144
105145 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105146 ip_vs_sync_conn(net, cp, pkts);
105147 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105148 index ac7ba68..9735acb9 100644
105149 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105150 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105151 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105152 */
105153 ip_vs_rs_hash(ipvs, dest);
105154 }
105155 - atomic_set(&dest->conn_flags, conn_flags);
105156 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105157
105158 /* bind the service */
105159 old_svc = rcu_dereference_protected(dest->svc, 1);
105160 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105161 * align with netns init in ip_vs_control_net_init()
105162 */
105163
105164 -static struct ctl_table vs_vars[] = {
105165 +static ctl_table_no_const vs_vars[] __read_only = {
105166 {
105167 .procname = "amemthresh",
105168 .maxlen = sizeof(int),
105169 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105170 " %-7s %-6d %-10d %-10d\n",
105171 &dest->addr.in6,
105172 ntohs(dest->port),
105173 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105174 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105175 atomic_read(&dest->weight),
105176 atomic_read(&dest->activeconns),
105177 atomic_read(&dest->inactconns));
105178 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105179 "%-7s %-6d %-10d %-10d\n",
105180 ntohl(dest->addr.ip),
105181 ntohs(dest->port),
105182 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105183 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105184 atomic_read(&dest->weight),
105185 atomic_read(&dest->activeconns),
105186 atomic_read(&dest->inactconns));
105187 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105188
105189 entry.addr = dest->addr.ip;
105190 entry.port = dest->port;
105191 - entry.conn_flags = atomic_read(&dest->conn_flags);
105192 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105193 entry.weight = atomic_read(&dest->weight);
105194 entry.u_threshold = dest->u_threshold;
105195 entry.l_threshold = dest->l_threshold;
105196 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105197 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105198 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105199 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105200 - (atomic_read(&dest->conn_flags) &
105201 + (atomic_read_unchecked(&dest->conn_flags) &
105202 IP_VS_CONN_F_FWD_MASK)) ||
105203 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105204 atomic_read(&dest->weight)) ||
105205 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105206 {
105207 int idx;
105208 struct netns_ipvs *ipvs = net_ipvs(net);
105209 - struct ctl_table *tbl;
105210 + ctl_table_no_const *tbl;
105211
105212 atomic_set(&ipvs->dropentry, 0);
105213 spin_lock_init(&ipvs->dropentry_lock);
105214 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105215 index 127f140..553d652 100644
105216 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105217 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105218 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105219 * IPVS LBLC sysctl table
105220 */
105221 #ifdef CONFIG_SYSCTL
105222 -static struct ctl_table vs_vars_table[] = {
105223 +static ctl_table_no_const vs_vars_table[] __read_only = {
105224 {
105225 .procname = "lblc_expiration",
105226 .data = NULL,
105227 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105228 index 2229d2d..b32b785 100644
105229 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105230 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105231 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105232 * IPVS LBLCR sysctl table
105233 */
105234
105235 -static struct ctl_table vs_vars_table[] = {
105236 +static ctl_table_no_const vs_vars_table[] __read_only = {
105237 {
105238 .procname = "lblcr_expiration",
105239 .data = NULL,
105240 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105241 index 7162c86..9eeb60e 100644
105242 --- a/net/netfilter/ipvs/ip_vs_sync.c
105243 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105244 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105245 cp = cp->control;
105246 if (cp) {
105247 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105248 - pkts = atomic_add_return(1, &cp->in_pkts);
105249 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105250 else
105251 pkts = sysctl_sync_threshold(ipvs);
105252 ip_vs_sync_conn(net, cp->control, pkts);
105253 @@ -771,7 +771,7 @@ control:
105254 if (!cp)
105255 return;
105256 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105257 - pkts = atomic_add_return(1, &cp->in_pkts);
105258 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105259 else
105260 pkts = sysctl_sync_threshold(ipvs);
105261 goto sloop;
105262 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105263
105264 if (opt)
105265 memcpy(&cp->in_seq, opt, sizeof(*opt));
105266 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105267 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105268 cp->state = state;
105269 cp->old_state = cp->state;
105270 /*
105271 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105272 index bd90bf8..816a020d 100644
105273 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105274 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105275 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105276 else
105277 rc = NF_ACCEPT;
105278 /* do not touch skb anymore */
105279 - atomic_inc(&cp->in_pkts);
105280 + atomic_inc_unchecked(&cp->in_pkts);
105281 goto out;
105282 }
105283
105284 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105285 else
105286 rc = NF_ACCEPT;
105287 /* do not touch skb anymore */
105288 - atomic_inc(&cp->in_pkts);
105289 + atomic_inc_unchecked(&cp->in_pkts);
105290 goto out;
105291 }
105292
105293 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105294 index a4b5e2a..13b1de3 100644
105295 --- a/net/netfilter/nf_conntrack_acct.c
105296 +++ b/net/netfilter/nf_conntrack_acct.c
105297 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105298 #ifdef CONFIG_SYSCTL
105299 static int nf_conntrack_acct_init_sysctl(struct net *net)
105300 {
105301 - struct ctl_table *table;
105302 + ctl_table_no_const *table;
105303
105304 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105305 GFP_KERNEL);
105306 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105307 index c588012..b0d4ef8 100644
105308 --- a/net/netfilter/nf_conntrack_core.c
105309 +++ b/net/netfilter/nf_conntrack_core.c
105310 @@ -1737,6 +1737,10 @@ void nf_conntrack_init_end(void)
105311 #define DYING_NULLS_VAL ((1<<30)+1)
105312 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105313
105314 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105315 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105316 +#endif
105317 +
105318 int nf_conntrack_init_net(struct net *net)
105319 {
105320 int ret = -ENOMEM;
105321 @@ -1762,7 +1766,11 @@ int nf_conntrack_init_net(struct net *net)
105322 if (!net->ct.stat)
105323 goto err_pcpu_lists;
105324
105325 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105326 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105327 +#else
105328 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105329 +#endif
105330 if (!net->ct.slabname)
105331 goto err_slabname;
105332
105333 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105334 index 4e78c57..ec8fb74 100644
105335 --- a/net/netfilter/nf_conntrack_ecache.c
105336 +++ b/net/netfilter/nf_conntrack_ecache.c
105337 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105338 #ifdef CONFIG_SYSCTL
105339 static int nf_conntrack_event_init_sysctl(struct net *net)
105340 {
105341 - struct ctl_table *table;
105342 + ctl_table_no_const *table;
105343
105344 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105345 GFP_KERNEL);
105346 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105347 index 5b3eae7..dd4b8fe 100644
105348 --- a/net/netfilter/nf_conntrack_helper.c
105349 +++ b/net/netfilter/nf_conntrack_helper.c
105350 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105351
105352 static int nf_conntrack_helper_init_sysctl(struct net *net)
105353 {
105354 - struct ctl_table *table;
105355 + ctl_table_no_const *table;
105356
105357 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105358 GFP_KERNEL);
105359 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105360 index b65d586..beec902 100644
105361 --- a/net/netfilter/nf_conntrack_proto.c
105362 +++ b/net/netfilter/nf_conntrack_proto.c
105363 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105364
105365 static void
105366 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105367 - struct ctl_table **table,
105368 + ctl_table_no_const **table,
105369 unsigned int users)
105370 {
105371 if (users > 0)
105372 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105373 index cf65a1e..2f291e9 100644
105374 --- a/net/netfilter/nf_conntrack_standalone.c
105375 +++ b/net/netfilter/nf_conntrack_standalone.c
105376 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105377
105378 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105379 {
105380 - struct ctl_table *table;
105381 + ctl_table_no_const *table;
105382
105383 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105384 GFP_KERNEL);
105385 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105386 index 7a394df..bd91a8a 100644
105387 --- a/net/netfilter/nf_conntrack_timestamp.c
105388 +++ b/net/netfilter/nf_conntrack_timestamp.c
105389 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105390 #ifdef CONFIG_SYSCTL
105391 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105392 {
105393 - struct ctl_table *table;
105394 + ctl_table_no_const *table;
105395
105396 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105397 GFP_KERNEL);
105398 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105399 index d719764..311bc60 100644
105400 --- a/net/netfilter/nf_log.c
105401 +++ b/net/netfilter/nf_log.c
105402 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105403
105404 #ifdef CONFIG_SYSCTL
105405 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105406 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105407 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105408
105409 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105410 void __user *buffer, size_t *lenp, loff_t *ppos)
105411 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105412 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105413 mutex_unlock(&nf_log_mutex);
105414 } else {
105415 + ctl_table_no_const nf_log_table = *table;
105416 +
105417 mutex_lock(&nf_log_mutex);
105418 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105419 lockdep_is_held(&nf_log_mutex));
105420 if (!logger)
105421 - table->data = "NONE";
105422 + nf_log_table.data = "NONE";
105423 else
105424 - table->data = logger->name;
105425 - r = proc_dostring(table, write, buffer, lenp, ppos);
105426 + nf_log_table.data = logger->name;
105427 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105428 mutex_unlock(&nf_log_mutex);
105429 }
105430
105431 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105432 index c68c1e5..8b5d670 100644
105433 --- a/net/netfilter/nf_sockopt.c
105434 +++ b/net/netfilter/nf_sockopt.c
105435 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105436 }
105437 }
105438
105439 - list_add(&reg->list, &nf_sockopts);
105440 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105441 out:
105442 mutex_unlock(&nf_sockopt_mutex);
105443 return ret;
105444 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105445 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105446 {
105447 mutex_lock(&nf_sockopt_mutex);
105448 - list_del(&reg->list);
105449 + pax_list_del((struct list_head *)&reg->list);
105450 mutex_unlock(&nf_sockopt_mutex);
105451 }
105452 EXPORT_SYMBOL(nf_unregister_sockopt);
105453 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
105454 index 71b574c..d319e8b 100644
105455 --- a/net/netfilter/nf_tables_api.c
105456 +++ b/net/netfilter/nf_tables_api.c
105457 @@ -1134,9 +1134,11 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr)
105458 /* Restore old counters on this cpu, no problem. Per-cpu statistics
105459 * are not exposed to userspace.
105460 */
105461 + preempt_disable();
105462 stats = this_cpu_ptr(newstats);
105463 stats->bytes = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
105464 stats->pkts = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
105465 + preempt_enable();
105466
105467 return newstats;
105468 }
105469 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105470 index 5f1be5b..2cba8cd 100644
105471 --- a/net/netfilter/nfnetlink_log.c
105472 +++ b/net/netfilter/nfnetlink_log.c
105473 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105474 struct nfnl_log_net {
105475 spinlock_t instances_lock;
105476 struct hlist_head instance_table[INSTANCE_BUCKETS];
105477 - atomic_t global_seq;
105478 + atomic_unchecked_t global_seq;
105479 };
105480
105481 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105482 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105483 /* global sequence number */
105484 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105485 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105486 - htonl(atomic_inc_return(&log->global_seq))))
105487 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105488 goto nla_put_failure;
105489
105490 if (data_len) {
105491 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105492 new file mode 100644
105493 index 0000000..c566332
105494 --- /dev/null
105495 +++ b/net/netfilter/xt_gradm.c
105496 @@ -0,0 +1,51 @@
105497 +/*
105498 + * gradm match for netfilter
105499 + * Copyright © Zbigniew Krzystolik, 2010
105500 + *
105501 + * This program is free software; you can redistribute it and/or modify
105502 + * it under the terms of the GNU General Public License; either version
105503 + * 2 or 3 as published by the Free Software Foundation.
105504 + */
105505 +#include <linux/module.h>
105506 +#include <linux/moduleparam.h>
105507 +#include <linux/skbuff.h>
105508 +#include <linux/netfilter/x_tables.h>
105509 +#include <linux/grsecurity.h>
105510 +#include <linux/netfilter/xt_gradm.h>
105511 +
105512 +static bool
105513 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105514 +{
105515 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105516 + bool retval = false;
105517 + if (gr_acl_is_enabled())
105518 + retval = true;
105519 + return retval ^ info->invflags;
105520 +}
105521 +
105522 +static struct xt_match gradm_mt_reg __read_mostly = {
105523 + .name = "gradm",
105524 + .revision = 0,
105525 + .family = NFPROTO_UNSPEC,
105526 + .match = gradm_mt,
105527 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105528 + .me = THIS_MODULE,
105529 +};
105530 +
105531 +static int __init gradm_mt_init(void)
105532 +{
105533 + return xt_register_match(&gradm_mt_reg);
105534 +}
105535 +
105536 +static void __exit gradm_mt_exit(void)
105537 +{
105538 + xt_unregister_match(&gradm_mt_reg);
105539 +}
105540 +
105541 +module_init(gradm_mt_init);
105542 +module_exit(gradm_mt_exit);
105543 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105544 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105545 +MODULE_LICENSE("GPL");
105546 +MODULE_ALIAS("ipt_gradm");
105547 +MODULE_ALIAS("ip6t_gradm");
105548 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105549 index 05fbc2a..4424b5c 100644
105550 --- a/net/netfilter/xt_hashlimit.c
105551 +++ b/net/netfilter/xt_hashlimit.c
105552 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105553 {
105554 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105555
105556 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105557 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105558 if (!hashlimit_net->ipt_hashlimit)
105559 return -ENOMEM;
105560 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105561 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105562 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105563 if (!hashlimit_net->ip6t_hashlimit) {
105564 remove_proc_entry("ipt_hashlimit", net->proc_net);
105565 return -ENOMEM;
105566 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105567 index a9faae8..1ea30e0 100644
105568 --- a/net/netfilter/xt_recent.c
105569 +++ b/net/netfilter/xt_recent.c
105570 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105571 {
105572 struct recent_net *recent_net = recent_pernet(net);
105573
105574 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105575 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105576 if (!recent_net->xt_recent)
105577 return -ENOMEM;
105578 return 0;
105579 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105580 index 11de55e..f25e448 100644
105581 --- a/net/netfilter/xt_statistic.c
105582 +++ b/net/netfilter/xt_statistic.c
105583 @@ -19,7 +19,7 @@
105584 #include <linux/module.h>
105585
105586 struct xt_statistic_priv {
105587 - atomic_t count;
105588 + atomic_unchecked_t count;
105589 } ____cacheline_aligned_in_smp;
105590
105591 MODULE_LICENSE("GPL");
105592 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105593 break;
105594 case XT_STATISTIC_MODE_NTH:
105595 do {
105596 - oval = atomic_read(&info->master->count);
105597 + oval = atomic_read_unchecked(&info->master->count);
105598 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105599 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105600 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105601 if (nval == 0)
105602 ret = !ret;
105603 break;
105604 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105605 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105606 if (info->master == NULL)
105607 return -ENOMEM;
105608 - atomic_set(&info->master->count, info->u.nth.count);
105609 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105610
105611 return 0;
105612 }
105613 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105614 index 79c965a..ee2b76d 100644
105615 --- a/net/netlink/af_netlink.c
105616 +++ b/net/netlink/af_netlink.c
105617 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105618 sk->sk_error_report(sk);
105619 }
105620 }
105621 - atomic_inc(&sk->sk_drops);
105622 + atomic_inc_unchecked(&sk->sk_drops);
105623 }
105624
105625 static void netlink_rcv_wake(struct sock *sk)
105626 @@ -2990,7 +2990,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105627 sk_wmem_alloc_get(s),
105628 nlk->cb_running,
105629 atomic_read(&s->sk_refcnt),
105630 - atomic_read(&s->sk_drops),
105631 + atomic_read_unchecked(&s->sk_drops),
105632 sock_i_ino(s)
105633 );
105634
105635 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105636 index 8451612..c8872bc 100644
105637 --- a/net/openvswitch/vport-internal_dev.c
105638 +++ b/net/openvswitch/vport-internal_dev.c
105639 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105640 .ndo_get_stats64 = internal_dev_get_stats,
105641 };
105642
105643 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105644 +static struct rtnl_link_ops internal_dev_link_ops = {
105645 .kind = "openvswitch",
105646 };
105647
105648 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
105649 index 6015802..e81e8bf 100644
105650 --- a/net/openvswitch/vport.c
105651 +++ b/net/openvswitch/vport.c
105652 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
105653 * netdev-stats can be directly read over netlink-ioctl.
105654 */
105655
105656 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
105657 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
105658 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
105659 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
105660 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
105661 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
105662 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
105663 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
105664
105665 for_each_possible_cpu(i) {
105666 const struct pcpu_sw_netstats *percpu_stats;
105667 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
105668 {
105669 switch (err_type) {
105670 case VPORT_E_RX_DROPPED:
105671 - atomic_long_inc(&vport->err_stats.rx_dropped);
105672 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
105673 break;
105674
105675 case VPORT_E_RX_ERROR:
105676 - atomic_long_inc(&vport->err_stats.rx_errors);
105677 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
105678 break;
105679
105680 case VPORT_E_TX_DROPPED:
105681 - atomic_long_inc(&vport->err_stats.tx_dropped);
105682 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
105683 break;
105684
105685 case VPORT_E_TX_ERROR:
105686 - atomic_long_inc(&vport->err_stats.tx_errors);
105687 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
105688 break;
105689 }
105690
105691 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
105692 index 8942125..03ed887 100644
105693 --- a/net/openvswitch/vport.h
105694 +++ b/net/openvswitch/vport.h
105695 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
105696 /* The following definitions are for implementers of vport devices: */
105697
105698 struct vport_err_stats {
105699 - atomic_long_t rx_dropped;
105700 - atomic_long_t rx_errors;
105701 - atomic_long_t tx_dropped;
105702 - atomic_long_t tx_errors;
105703 + atomic_long_unchecked_t rx_dropped;
105704 + atomic_long_unchecked_t rx_errors;
105705 + atomic_long_unchecked_t tx_dropped;
105706 + atomic_long_unchecked_t tx_errors;
105707 };
105708 /**
105709 * struct vport_portids - array of netlink portids of a vport.
105710 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105711 index 07c04a8..3ca11eb 100644
105712 --- a/net/packet/af_packet.c
105713 +++ b/net/packet/af_packet.c
105714 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105715
105716 return ret;
105717 drop:
105718 - atomic_long_inc(&dev->tx_dropped);
105719 + atomic_long_inc_unchecked(&dev->tx_dropped);
105720 kfree_skb(skb);
105721 return NET_XMIT_DROP;
105722 }
105723 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105724
105725 spin_lock(&sk->sk_receive_queue.lock);
105726 po->stats.stats1.tp_packets++;
105727 - skb->dropcount = atomic_read(&sk->sk_drops);
105728 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105729 __skb_queue_tail(&sk->sk_receive_queue, skb);
105730 spin_unlock(&sk->sk_receive_queue.lock);
105731 sk->sk_data_ready(sk);
105732 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105733 drop_n_acct:
105734 spin_lock(&sk->sk_receive_queue.lock);
105735 po->stats.stats1.tp_drops++;
105736 - atomic_inc(&sk->sk_drops);
105737 + atomic_inc_unchecked(&sk->sk_drops);
105738 spin_unlock(&sk->sk_receive_queue.lock);
105739
105740 drop_n_restore:
105741 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105742 case PACKET_HDRLEN:
105743 if (len > sizeof(int))
105744 len = sizeof(int);
105745 - if (copy_from_user(&val, optval, len))
105746 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105747 return -EFAULT;
105748 switch (val) {
105749 case TPACKET_V1:
105750 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105751 len = lv;
105752 if (put_user(len, optlen))
105753 return -EFAULT;
105754 - if (copy_to_user(optval, data, len))
105755 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105756 return -EFAULT;
105757 return 0;
105758 }
105759 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105760 index 70a547e..23477fe 100644
105761 --- a/net/phonet/pep.c
105762 +++ b/net/phonet/pep.c
105763 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105764
105765 case PNS_PEP_CTRL_REQ:
105766 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105767 - atomic_inc(&sk->sk_drops);
105768 + atomic_inc_unchecked(&sk->sk_drops);
105769 break;
105770 }
105771 __skb_pull(skb, 4);
105772 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105773 }
105774
105775 if (pn->rx_credits == 0) {
105776 - atomic_inc(&sk->sk_drops);
105777 + atomic_inc_unchecked(&sk->sk_drops);
105778 err = -ENOBUFS;
105779 break;
105780 }
105781 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105782 }
105783
105784 if (pn->rx_credits == 0) {
105785 - atomic_inc(&sk->sk_drops);
105786 + atomic_inc_unchecked(&sk->sk_drops);
105787 err = NET_RX_DROP;
105788 break;
105789 }
105790 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105791 index 008214a..bb68240 100644
105792 --- a/net/phonet/socket.c
105793 +++ b/net/phonet/socket.c
105794 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105795 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105796 sock_i_ino(sk),
105797 atomic_read(&sk->sk_refcnt), sk,
105798 - atomic_read(&sk->sk_drops));
105799 + atomic_read_unchecked(&sk->sk_drops));
105800 }
105801 seq_pad(seq, '\n');
105802 return 0;
105803 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105804 index c02a8c4..3c5b600 100644
105805 --- a/net/phonet/sysctl.c
105806 +++ b/net/phonet/sysctl.c
105807 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105808 {
105809 int ret;
105810 int range[2] = {local_port_range[0], local_port_range[1]};
105811 - struct ctl_table tmp = {
105812 + ctl_table_no_const tmp = {
105813 .data = &range,
105814 .maxlen = sizeof(range),
105815 .mode = table->mode,
105816 diff --git a/net/rds/cong.c b/net/rds/cong.c
105817 index e5b65ac..f3b6fb7 100644
105818 --- a/net/rds/cong.c
105819 +++ b/net/rds/cong.c
105820 @@ -78,7 +78,7 @@
105821 * finds that the saved generation number is smaller than the global generation
105822 * number, it wakes up the process.
105823 */
105824 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105825 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105826
105827 /*
105828 * Congestion monitoring
105829 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105830 rdsdebug("waking map %p for %pI4\n",
105831 map, &map->m_addr);
105832 rds_stats_inc(s_cong_update_received);
105833 - atomic_inc(&rds_cong_generation);
105834 + atomic_inc_unchecked(&rds_cong_generation);
105835 if (waitqueue_active(&map->m_waitq))
105836 wake_up(&map->m_waitq);
105837 if (waitqueue_active(&rds_poll_waitq))
105838 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105839
105840 int rds_cong_updated_since(unsigned long *recent)
105841 {
105842 - unsigned long gen = atomic_read(&rds_cong_generation);
105843 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105844
105845 if (likely(*recent == gen))
105846 return 0;
105847 diff --git a/net/rds/ib.h b/net/rds/ib.h
105848 index 7280ab8..e04f4ea 100644
105849 --- a/net/rds/ib.h
105850 +++ b/net/rds/ib.h
105851 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105852 /* sending acks */
105853 unsigned long i_ack_flags;
105854 #ifdef KERNEL_HAS_ATOMIC64
105855 - atomic64_t i_ack_next; /* next ACK to send */
105856 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105857 #else
105858 spinlock_t i_ack_lock; /* protect i_ack_next */
105859 u64 i_ack_next; /* next ACK to send */
105860 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105861 index 31b74f5..dc1fbfa 100644
105862 --- a/net/rds/ib_cm.c
105863 +++ b/net/rds/ib_cm.c
105864 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105865 /* Clear the ACK state */
105866 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105867 #ifdef KERNEL_HAS_ATOMIC64
105868 - atomic64_set(&ic->i_ack_next, 0);
105869 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105870 #else
105871 ic->i_ack_next = 0;
105872 #endif
105873 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105874 index d67de45..73dbf51 100644
105875 --- a/net/rds/ib_recv.c
105876 +++ b/net/rds/ib_recv.c
105877 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105878 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105879 int ack_required)
105880 {
105881 - atomic64_set(&ic->i_ack_next, seq);
105882 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105883 if (ack_required) {
105884 smp_mb__before_atomic();
105885 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105886 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105887 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105888 smp_mb__after_atomic();
105889
105890 - return atomic64_read(&ic->i_ack_next);
105891 + return atomic64_read_unchecked(&ic->i_ack_next);
105892 }
105893 #endif
105894
105895 diff --git a/net/rds/iw.h b/net/rds/iw.h
105896 index 04ce3b1..48119a6 100644
105897 --- a/net/rds/iw.h
105898 +++ b/net/rds/iw.h
105899 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105900 /* sending acks */
105901 unsigned long i_ack_flags;
105902 #ifdef KERNEL_HAS_ATOMIC64
105903 - atomic64_t i_ack_next; /* next ACK to send */
105904 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105905 #else
105906 spinlock_t i_ack_lock; /* protect i_ack_next */
105907 u64 i_ack_next; /* next ACK to send */
105908 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105909 index a91e1db..cf3053f 100644
105910 --- a/net/rds/iw_cm.c
105911 +++ b/net/rds/iw_cm.c
105912 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105913 /* Clear the ACK state */
105914 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105915 #ifdef KERNEL_HAS_ATOMIC64
105916 - atomic64_set(&ic->i_ack_next, 0);
105917 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105918 #else
105919 ic->i_ack_next = 0;
105920 #endif
105921 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105922 index aa8bf67..b70133c 100644
105923 --- a/net/rds/iw_recv.c
105924 +++ b/net/rds/iw_recv.c
105925 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105926 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105927 int ack_required)
105928 {
105929 - atomic64_set(&ic->i_ack_next, seq);
105930 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105931 if (ack_required) {
105932 smp_mb__before_atomic();
105933 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105934 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105935 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105936 smp_mb__after_atomic();
105937
105938 - return atomic64_read(&ic->i_ack_next);
105939 + return atomic64_read_unchecked(&ic->i_ack_next);
105940 }
105941 #endif
105942
105943 diff --git a/net/rds/rds.h b/net/rds/rds.h
105944 index 48f8ffc..0ef3eec 100644
105945 --- a/net/rds/rds.h
105946 +++ b/net/rds/rds.h
105947 @@ -449,7 +449,7 @@ struct rds_transport {
105948 void (*sync_mr)(void *trans_private, int direction);
105949 void (*free_mr)(void *trans_private, int invalidate);
105950 void (*flush_mrs)(void);
105951 -};
105952 +} __do_const;
105953
105954 struct rds_sock {
105955 struct sock rs_sk;
105956 diff --git a/net/rds/sysctl.c b/net/rds/sysctl.c
105957 index c3b0cd4..c173f69 100644
105958 --- a/net/rds/sysctl.c
105959 +++ b/net/rds/sysctl.c
105960 @@ -71,14 +71,14 @@ static struct ctl_table rds_sysctl_rds_table[] = {
105961 {
105962 .procname = "max_unacked_packets",
105963 .data = &rds_sysctl_max_unacked_packets,
105964 - .maxlen = sizeof(unsigned long),
105965 + .maxlen = sizeof(int),
105966 .mode = 0644,
105967 .proc_handler = proc_dointvec,
105968 },
105969 {
105970 .procname = "max_unacked_bytes",
105971 .data = &rds_sysctl_max_unacked_bytes,
105972 - .maxlen = sizeof(unsigned long),
105973 + .maxlen = sizeof(int),
105974 .mode = 0644,
105975 .proc_handler = proc_dointvec,
105976 },
105977 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105978 index edac9ef..16bcb98 100644
105979 --- a/net/rds/tcp.c
105980 +++ b/net/rds/tcp.c
105981 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105982 int val = 1;
105983
105984 set_fs(KERNEL_DS);
105985 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105986 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105987 sizeof(val));
105988 set_fs(oldfs);
105989 }
105990 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105991 index 53b17ca..45463e7 100644
105992 --- a/net/rds/tcp_send.c
105993 +++ b/net/rds/tcp_send.c
105994 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105995
105996 oldfs = get_fs();
105997 set_fs(KERNEL_DS);
105998 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105999 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
106000 sizeof(val));
106001 set_fs(oldfs);
106002 }
106003 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
106004 index 7b16704..9628ec6 100644
106005 --- a/net/rxrpc/af_rxrpc.c
106006 +++ b/net/rxrpc/af_rxrpc.c
106007 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
106008 __be32 rxrpc_epoch;
106009
106010 /* current debugging ID */
106011 -atomic_t rxrpc_debug_id;
106012 +atomic_unchecked_t rxrpc_debug_id;
106013
106014 /* count of skbs currently in use */
106015 atomic_t rxrpc_n_skbs;
106016 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
106017 index c6be17a..2a6200a 100644
106018 --- a/net/rxrpc/ar-ack.c
106019 +++ b/net/rxrpc/ar-ack.c
106020 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106021
106022 _enter("{%d,%d,%d,%d},",
106023 call->acks_hard, call->acks_unacked,
106024 - atomic_read(&call->sequence),
106025 + atomic_read_unchecked(&call->sequence),
106026 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
106027
106028 stop = 0;
106029 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106030
106031 /* each Tx packet has a new serial number */
106032 sp->hdr.serial =
106033 - htonl(atomic_inc_return(&call->conn->serial));
106034 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
106035
106036 hdr = (struct rxrpc_header *) txb->head;
106037 hdr->serial = sp->hdr.serial;
106038 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
106039 */
106040 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
106041 {
106042 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
106043 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
106044 }
106045
106046 /*
106047 @@ -677,7 +677,7 @@ process_further:
106048
106049 latest = ntohl(sp->hdr.serial);
106050 hard = ntohl(ack.firstPacket);
106051 - tx = atomic_read(&call->sequence);
106052 + tx = atomic_read_unchecked(&call->sequence);
106053
106054 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106055 latest,
106056 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
106057 goto maybe_reschedule;
106058
106059 send_ACK_with_skew:
106060 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
106061 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
106062 ntohl(ack.serial));
106063 send_ACK:
106064 mtu = call->conn->trans->peer->if_mtu;
106065 @@ -1221,7 +1221,7 @@ send_ACK:
106066 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
106067 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
106068
106069 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106070 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106071 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106072 ntohl(hdr.serial),
106073 ntohs(ack.maxSkew),
106074 @@ -1239,7 +1239,7 @@ send_ACK:
106075 send_message:
106076 _debug("send message");
106077
106078 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106079 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106080 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
106081 send_message_2:
106082
106083 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
106084 index a9e05db..194e793 100644
106085 --- a/net/rxrpc/ar-call.c
106086 +++ b/net/rxrpc/ar-call.c
106087 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
106088 spin_lock_init(&call->lock);
106089 rwlock_init(&call->state_lock);
106090 atomic_set(&call->usage, 1);
106091 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
106092 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106093 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
106094
106095 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
106096 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
106097 index 6631f4f..bfdf056 100644
106098 --- a/net/rxrpc/ar-connection.c
106099 +++ b/net/rxrpc/ar-connection.c
106100 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
106101 rwlock_init(&conn->lock);
106102 spin_lock_init(&conn->state_lock);
106103 atomic_set(&conn->usage, 1);
106104 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
106105 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106106 conn->avail_calls = RXRPC_MAXCALLS;
106107 conn->size_align = 4;
106108 conn->header_size = sizeof(struct rxrpc_header);
106109 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
106110 index e7ed43a..6afa140 100644
106111 --- a/net/rxrpc/ar-connevent.c
106112 +++ b/net/rxrpc/ar-connevent.c
106113 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
106114
106115 len = iov[0].iov_len + iov[1].iov_len;
106116
106117 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106118 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106119 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106120
106121 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106122 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106123 index 481f89f..ceeaf8d 100644
106124 --- a/net/rxrpc/ar-input.c
106125 +++ b/net/rxrpc/ar-input.c
106126 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106127 /* track the latest serial number on this connection for ACK packet
106128 * information */
106129 serial = ntohl(sp->hdr.serial);
106130 - hi_serial = atomic_read(&call->conn->hi_serial);
106131 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106132 while (serial > hi_serial)
106133 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106134 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106135 serial);
106136
106137 /* request ACK generation for any ACK or DATA packet that requests
106138 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106139 index ba9fd36..9bbfe01 100644
106140 --- a/net/rxrpc/ar-internal.h
106141 +++ b/net/rxrpc/ar-internal.h
106142 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106143 int error; /* error code for local abort */
106144 int debug_id; /* debug ID for printks */
106145 unsigned int call_counter; /* call ID counter */
106146 - atomic_t serial; /* packet serial number counter */
106147 - atomic_t hi_serial; /* highest serial number received */
106148 + atomic_unchecked_t serial; /* packet serial number counter */
106149 + atomic_unchecked_t hi_serial; /* highest serial number received */
106150 u8 avail_calls; /* number of calls available */
106151 u8 size_align; /* data size alignment (for security) */
106152 u8 header_size; /* rxrpc + security header size */
106153 @@ -346,7 +346,7 @@ struct rxrpc_call {
106154 spinlock_t lock;
106155 rwlock_t state_lock; /* lock for state transition */
106156 atomic_t usage;
106157 - atomic_t sequence; /* Tx data packet sequence counter */
106158 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106159 u32 abort_code; /* local/remote abort code */
106160 enum { /* current state of call */
106161 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106162 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106163 */
106164 extern atomic_t rxrpc_n_skbs;
106165 extern __be32 rxrpc_epoch;
106166 -extern atomic_t rxrpc_debug_id;
106167 +extern atomic_unchecked_t rxrpc_debug_id;
106168 extern struct workqueue_struct *rxrpc_workqueue;
106169
106170 /*
106171 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106172 index 87f7135..74d3703 100644
106173 --- a/net/rxrpc/ar-local.c
106174 +++ b/net/rxrpc/ar-local.c
106175 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106176 spin_lock_init(&local->lock);
106177 rwlock_init(&local->services_lock);
106178 atomic_set(&local->usage, 1);
106179 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106180 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106181 memcpy(&local->srx, srx, sizeof(*srx));
106182 }
106183
106184 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106185 index 0b4b9a7..966ffbb 100644
106186 --- a/net/rxrpc/ar-output.c
106187 +++ b/net/rxrpc/ar-output.c
106188 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106189 memset(skb_put(skb, pad), 0, pad);
106190 }
106191
106192 - seq = atomic_inc_return(&call->sequence);
106193 + seq = atomic_inc_return_unchecked(&call->sequence);
106194
106195 sp->hdr.epoch = conn->epoch;
106196 sp->hdr.cid = call->cid;
106197 sp->hdr.callNumber = call->call_id;
106198 sp->hdr.seq = htonl(seq);
106199 sp->hdr.serial =
106200 - htonl(atomic_inc_return(&conn->serial));
106201 + htonl(atomic_inc_return_unchecked(&conn->serial));
106202 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106203 sp->hdr.userStatus = 0;
106204 sp->hdr.securityIndex = conn->security_ix;
106205 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106206 index bebaa43..2644591 100644
106207 --- a/net/rxrpc/ar-peer.c
106208 +++ b/net/rxrpc/ar-peer.c
106209 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106210 INIT_LIST_HEAD(&peer->error_targets);
106211 spin_lock_init(&peer->lock);
106212 atomic_set(&peer->usage, 1);
106213 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106214 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106215 memcpy(&peer->srx, srx, sizeof(*srx));
106216
106217 rxrpc_assess_MTU_size(peer);
106218 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106219 index 38047f7..9f48511 100644
106220 --- a/net/rxrpc/ar-proc.c
106221 +++ b/net/rxrpc/ar-proc.c
106222 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106223 atomic_read(&conn->usage),
106224 rxrpc_conn_states[conn->state],
106225 key_serial(conn->key),
106226 - atomic_read(&conn->serial),
106227 - atomic_read(&conn->hi_serial));
106228 + atomic_read_unchecked(&conn->serial),
106229 + atomic_read_unchecked(&conn->hi_serial));
106230
106231 return 0;
106232 }
106233 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106234 index 1976dec..aa70be5 100644
106235 --- a/net/rxrpc/ar-transport.c
106236 +++ b/net/rxrpc/ar-transport.c
106237 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106238 spin_lock_init(&trans->client_lock);
106239 rwlock_init(&trans->conn_lock);
106240 atomic_set(&trans->usage, 1);
106241 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106242 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106243
106244 if (peer->srx.transport.family == AF_INET) {
106245 switch (peer->srx.transport_type) {
106246 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106247 index f226709..0e735a8 100644
106248 --- a/net/rxrpc/rxkad.c
106249 +++ b/net/rxrpc/rxkad.c
106250 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106251
106252 len = iov[0].iov_len + iov[1].iov_len;
106253
106254 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106255 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106256 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106257
106258 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106259 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106260
106261 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106262
106263 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106264 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106265 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106266
106267 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106268 diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
106269 index aad6a67..baef987 100644
106270 --- a/net/sched/cls_api.c
106271 +++ b/net/sched/cls_api.c
106272 @@ -556,8 +556,9 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
106273 }
106274 EXPORT_SYMBOL(tcf_exts_change);
106275
106276 -#define tcf_exts_first_act(ext) \
106277 - list_first_entry(&(exts)->actions, struct tc_action, list)
106278 +#define tcf_exts_first_act(ext) \
106279 + list_first_entry_or_null(&(exts)->actions, \
106280 + struct tc_action, list)
106281
106282 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
106283 {
106284 @@ -603,7 +604,7 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
106285 {
106286 #ifdef CONFIG_NET_CLS_ACT
106287 struct tc_action *a = tcf_exts_first_act(exts);
106288 - if (tcf_action_copy_stats(skb, a, 1) < 0)
106289 + if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
106290 return -1;
106291 #endif
106292 return 0;
106293 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
106294 index eed49d1..ce22514 100644
106295 --- a/net/sched/cls_bpf.c
106296 +++ b/net/sched/cls_bpf.c
106297 @@ -191,6 +191,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
106298 }
106299
106300 bpf_size = bpf_len * sizeof(*bpf_ops);
106301 + if (bpf_size != nla_len(tb[TCA_BPF_OPS])) {
106302 + ret = -EINVAL;
106303 + goto errout;
106304 + }
106305 +
106306 bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
106307 if (bpf_ops == NULL) {
106308 ret = -ENOMEM;
106309 @@ -226,15 +231,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
106310 struct cls_bpf_head *head)
106311 {
106312 unsigned int i = 0x80000000;
106313 + u32 handle;
106314
106315 do {
106316 if (++head->hgen == 0x7FFFFFFF)
106317 head->hgen = 1;
106318 } while (--i > 0 && cls_bpf_get(tp, head->hgen));
106319 - if (i == 0)
106320 +
106321 + if (unlikely(i == 0)) {
106322 pr_err("Insufficient number of handles\n");
106323 + handle = 0;
106324 + } else {
106325 + handle = head->hgen;
106326 + }
106327
106328 - return i;
106329 + return handle;
106330 }
106331
106332 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
106333 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106334 index 6efca30..1259f82 100644
106335 --- a/net/sched/sch_generic.c
106336 +++ b/net/sched/sch_generic.c
106337 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
106338 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106339 if (dev->reg_state == NETREG_UNINITIALIZED)
106340 return;
106341 - atomic_inc(&dev->carrier_changes);
106342 + atomic_inc_unchecked(&dev->carrier_changes);
106343 linkwatch_fire_event(dev);
106344 if (netif_running(dev))
106345 __netdev_watchdog_up(dev);
106346 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
106347 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106348 if (dev->reg_state == NETREG_UNINITIALIZED)
106349 return;
106350 - atomic_inc(&dev->carrier_changes);
106351 + atomic_inc_unchecked(&dev->carrier_changes);
106352 linkwatch_fire_event(dev);
106353 }
106354 }
106355 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106356 index 0e4198e..f94193e 100644
106357 --- a/net/sctp/ipv6.c
106358 +++ b/net/sctp/ipv6.c
106359 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106360 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106361 };
106362
106363 -static struct sctp_af sctp_af_inet6 = {
106364 +static struct sctp_af sctp_af_inet6 __read_only = {
106365 .sa_family = AF_INET6,
106366 .sctp_xmit = sctp_v6_xmit,
106367 .setsockopt = ipv6_setsockopt,
106368 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106369 #endif
106370 };
106371
106372 -static struct sctp_pf sctp_pf_inet6 = {
106373 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106374 .event_msgname = sctp_inet6_event_msgname,
106375 .skb_msgname = sctp_inet6_skb_msgname,
106376 .af_supported = sctp_inet6_af_supported,
106377 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106378
106379 void sctp_v6_pf_exit(void)
106380 {
106381 - list_del(&sctp_af_inet6.list);
106382 + pax_list_del(&sctp_af_inet6.list);
106383 }
106384
106385 /* Initialize IPv6 support and register with socket layer. */
106386 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106387 index 8f34b27..b105385 100644
106388 --- a/net/sctp/protocol.c
106389 +++ b/net/sctp/protocol.c
106390 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106391 return 0;
106392 }
106393
106394 + pax_open_kernel();
106395 INIT_LIST_HEAD(&af->list);
106396 - list_add_tail(&af->list, &sctp_address_families);
106397 + pax_close_kernel();
106398 + pax_list_add_tail(&af->list, &sctp_address_families);
106399 return 1;
106400 }
106401
106402 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106403
106404 static struct sctp_af sctp_af_inet;
106405
106406 -static struct sctp_pf sctp_pf_inet = {
106407 +static struct sctp_pf sctp_pf_inet __read_only = {
106408 .event_msgname = sctp_inet_event_msgname,
106409 .skb_msgname = sctp_inet_skb_msgname,
106410 .af_supported = sctp_inet_af_supported,
106411 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106412 };
106413
106414 /* IPv4 address related functions. */
106415 -static struct sctp_af sctp_af_inet = {
106416 +static struct sctp_af sctp_af_inet __read_only = {
106417 .sa_family = AF_INET,
106418 .sctp_xmit = sctp_v4_xmit,
106419 .setsockopt = ip_setsockopt,
106420 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106421
106422 static void sctp_v4_pf_exit(void)
106423 {
106424 - list_del(&sctp_af_inet.list);
106425 + pax_list_del(&sctp_af_inet.list);
106426 }
106427
106428 static int sctp_v4_protosw_init(void)
106429 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106430 index fef2acd..c705c4f 100644
106431 --- a/net/sctp/sm_sideeffect.c
106432 +++ b/net/sctp/sm_sideeffect.c
106433 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106434 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106435 }
106436
106437 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106438 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106439 NULL,
106440 sctp_generate_t1_cookie_event,
106441 sctp_generate_t1_init_event,
106442 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106443 index 634a2ab..dfdaf9b 100644
106444 --- a/net/sctp/socket.c
106445 +++ b/net/sctp/socket.c
106446 @@ -1603,7 +1603,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106447 sctp_assoc_t associd = 0;
106448 sctp_cmsgs_t cmsgs = { NULL };
106449 sctp_scope_t scope;
106450 - bool fill_sinfo_ttl = false;
106451 + bool fill_sinfo_ttl = false, wait_connect = false;
106452 struct sctp_datamsg *datamsg;
106453 int msg_flags = msg->msg_flags;
106454 __u16 sinfo_flags = 0;
106455 @@ -1943,6 +1943,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106456 if (err < 0)
106457 goto out_free;
106458
106459 + wait_connect = true;
106460 pr_debug("%s: we associated primitively\n", __func__);
106461 }
106462
106463 @@ -1980,6 +1981,11 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106464 sctp_datamsg_put(datamsg);
106465 err = msg_len;
106466
106467 + if (unlikely(wait_connect)) {
106468 + timeo = sock_sndtimeo(sk, msg_flags & MSG_DONTWAIT);
106469 + sctp_wait_for_connect(asoc, &timeo);
106470 + }
106471 +
106472 /* If we are already past ASSOCIATE, the lower
106473 * layers are responsible for association cleanup.
106474 */
106475 @@ -2199,11 +2205,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106476 {
106477 struct sctp_association *asoc;
106478 struct sctp_ulpevent *event;
106479 + struct sctp_event_subscribe subscribe;
106480
106481 if (optlen > sizeof(struct sctp_event_subscribe))
106482 return -EINVAL;
106483 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106484 + if (copy_from_user(&subscribe, optval, optlen))
106485 return -EFAULT;
106486 + sctp_sk(sk)->subscribe = subscribe;
106487
106488 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106489 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106490 @@ -4372,13 +4380,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106491 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106492 int __user *optlen)
106493 {
106494 + struct sctp_event_subscribe subscribe;
106495 +
106496 if (len <= 0)
106497 return -EINVAL;
106498 if (len > sizeof(struct sctp_event_subscribe))
106499 len = sizeof(struct sctp_event_subscribe);
106500 if (put_user(len, optlen))
106501 return -EFAULT;
106502 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106503 + subscribe = sctp_sk(sk)->subscribe;
106504 + if (copy_to_user(optval, &subscribe, len))
106505 return -EFAULT;
106506 return 0;
106507 }
106508 @@ -4396,6 +4407,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106509 */
106510 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106511 {
106512 + __u32 autoclose;
106513 +
106514 /* Applicable to UDP-style socket only */
106515 if (sctp_style(sk, TCP))
106516 return -EOPNOTSUPP;
106517 @@ -4404,7 +4417,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106518 len = sizeof(int);
106519 if (put_user(len, optlen))
106520 return -EFAULT;
106521 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106522 + autoclose = sctp_sk(sk)->autoclose;
106523 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106524 return -EFAULT;
106525 return 0;
106526 }
106527 @@ -4778,12 +4792,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106528 */
106529 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106530 {
106531 + struct sctp_initmsg initmsg;
106532 +
106533 if (len < sizeof(struct sctp_initmsg))
106534 return -EINVAL;
106535 len = sizeof(struct sctp_initmsg);
106536 if (put_user(len, optlen))
106537 return -EFAULT;
106538 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106539 + initmsg = sctp_sk(sk)->initmsg;
106540 + if (copy_to_user(optval, &initmsg, len))
106541 return -EFAULT;
106542 return 0;
106543 }
106544 @@ -4824,6 +4841,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106545 ->addr_to_user(sp, &temp);
106546 if (space_left < addrlen)
106547 return -ENOMEM;
106548 + if (addrlen > sizeof(temp) || addrlen < 0)
106549 + return -EFAULT;
106550 if (copy_to_user(to, &temp, addrlen))
106551 return -EFAULT;
106552 to += addrlen;
106553 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106554 index 2e9ada1..40f425d 100644
106555 --- a/net/sctp/sysctl.c
106556 +++ b/net/sctp/sysctl.c
106557 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106558 loff_t *ppos)
106559 {
106560 struct net *net = current->nsproxy->net_ns;
106561 - struct ctl_table tbl;
106562 + ctl_table_no_const tbl;
106563 bool changed = false;
106564 char *none = "none";
106565 char tmp[8];
106566 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106567 struct net *net = current->nsproxy->net_ns;
106568 unsigned int min = *(unsigned int *) ctl->extra1;
106569 unsigned int max = *(unsigned int *) ctl->extra2;
106570 - struct ctl_table tbl;
106571 + ctl_table_no_const tbl;
106572 int ret, new_value;
106573
106574 memset(&tbl, 0, sizeof(struct ctl_table));
106575 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106576 struct net *net = current->nsproxy->net_ns;
106577 unsigned int min = *(unsigned int *) ctl->extra1;
106578 unsigned int max = *(unsigned int *) ctl->extra2;
106579 - struct ctl_table tbl;
106580 + ctl_table_no_const tbl;
106581 int ret, new_value;
106582
106583 memset(&tbl, 0, sizeof(struct ctl_table));
106584 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106585 loff_t *ppos)
106586 {
106587 struct net *net = current->nsproxy->net_ns;
106588 - struct ctl_table tbl;
106589 + ctl_table_no_const tbl;
106590 int new_value, ret;
106591
106592 memset(&tbl, 0, sizeof(struct ctl_table));
106593 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106594
106595 int sctp_sysctl_net_register(struct net *net)
106596 {
106597 - struct ctl_table *table;
106598 + ctl_table_no_const *table;
106599 int i;
106600
106601 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106602 diff --git a/net/socket.c b/net/socket.c
106603 index cf9ebf1..9522714 100644
106604 --- a/net/socket.c
106605 +++ b/net/socket.c
106606 @@ -89,6 +89,7 @@
106607 #include <linux/magic.h>
106608 #include <linux/slab.h>
106609 #include <linux/xattr.h>
106610 +#include <linux/in.h>
106611
106612 #include <asm/uaccess.h>
106613 #include <asm/unistd.h>
106614 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106615 unsigned int sysctl_net_busy_poll __read_mostly;
106616 #endif
106617
106618 +#include <linux/grsock.h>
106619 +
106620 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106621 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106622 unsigned long nr_segs, loff_t pos);
106623 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106624 */
106625
106626 static DEFINE_SPINLOCK(net_family_lock);
106627 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106628 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106629
106630 /*
106631 * Statistics counters of the socket lists
106632 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106633 &sockfs_dentry_operations, SOCKFS_MAGIC);
106634 }
106635
106636 -static struct vfsmount *sock_mnt __read_mostly;
106637 +struct vfsmount *sock_mnt __read_mostly;
106638
106639 static struct file_system_type sock_fs_type = {
106640 .name = "sockfs",
106641 @@ -1260,6 +1263,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106642 return -EAFNOSUPPORT;
106643 if (type < 0 || type >= SOCK_MAX)
106644 return -EINVAL;
106645 + if (protocol < 0)
106646 + return -EINVAL;
106647
106648 /* Compatibility.
106649
106650 @@ -1280,6 +1285,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106651 if (err)
106652 return err;
106653
106654 + if(!kern && !gr_search_socket(family, type, protocol)) {
106655 + if (rcu_access_pointer(net_families[family]) == NULL)
106656 + return -EAFNOSUPPORT;
106657 + else
106658 + return -EACCES;
106659 + }
106660 +
106661 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106662 + if (rcu_access_pointer(net_families[family]) == NULL)
106663 + return -EAFNOSUPPORT;
106664 + else
106665 + return -EACCES;
106666 + }
106667 +
106668 /*
106669 * Allocate the socket and allow the family to set things up. if
106670 * the protocol is 0, the family is instructed to select an appropriate
106671 @@ -1531,6 +1550,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106672 if (sock) {
106673 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106674 if (err >= 0) {
106675 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106676 + err = -EACCES;
106677 + goto error;
106678 + }
106679 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106680 + if (err)
106681 + goto error;
106682 +
106683 err = security_socket_bind(sock,
106684 (struct sockaddr *)&address,
106685 addrlen);
106686 @@ -1539,6 +1566,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106687 (struct sockaddr *)
106688 &address, addrlen);
106689 }
106690 +error:
106691 fput_light(sock->file, fput_needed);
106692 }
106693 return err;
106694 @@ -1562,10 +1590,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106695 if ((unsigned int)backlog > somaxconn)
106696 backlog = somaxconn;
106697
106698 + if (gr_handle_sock_server_other(sock->sk)) {
106699 + err = -EPERM;
106700 + goto error;
106701 + }
106702 +
106703 + err = gr_search_listen(sock);
106704 + if (err)
106705 + goto error;
106706 +
106707 err = security_socket_listen(sock, backlog);
106708 if (!err)
106709 err = sock->ops->listen(sock, backlog);
106710
106711 +error:
106712 fput_light(sock->file, fput_needed);
106713 }
106714 return err;
106715 @@ -1609,6 +1647,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106716 newsock->type = sock->type;
106717 newsock->ops = sock->ops;
106718
106719 + if (gr_handle_sock_server_other(sock->sk)) {
106720 + err = -EPERM;
106721 + sock_release(newsock);
106722 + goto out_put;
106723 + }
106724 +
106725 + err = gr_search_accept(sock);
106726 + if (err) {
106727 + sock_release(newsock);
106728 + goto out_put;
106729 + }
106730 +
106731 /*
106732 * We don't need try_module_get here, as the listening socket (sock)
106733 * has the protocol module (sock->ops->owner) held.
106734 @@ -1654,6 +1704,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106735 fd_install(newfd, newfile);
106736 err = newfd;
106737
106738 + gr_attach_curr_ip(newsock->sk);
106739 +
106740 out_put:
106741 fput_light(sock->file, fput_needed);
106742 out:
106743 @@ -1686,6 +1738,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106744 int, addrlen)
106745 {
106746 struct socket *sock;
106747 + struct sockaddr *sck;
106748 struct sockaddr_storage address;
106749 int err, fput_needed;
106750
106751 @@ -1696,6 +1749,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106752 if (err < 0)
106753 goto out_put;
106754
106755 + sck = (struct sockaddr *)&address;
106756 +
106757 + if (gr_handle_sock_client(sck)) {
106758 + err = -EACCES;
106759 + goto out_put;
106760 + }
106761 +
106762 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106763 + if (err)
106764 + goto out_put;
106765 +
106766 err =
106767 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106768 if (err)
106769 @@ -1777,6 +1841,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106770 * the protocol.
106771 */
106772
106773 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106774 +
106775 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106776 unsigned int, flags, struct sockaddr __user *, addr,
106777 int, addr_len)
106778 @@ -1843,7 +1909,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106779 struct socket *sock;
106780 struct iovec iov;
106781 struct msghdr msg;
106782 - struct sockaddr_storage address;
106783 + struct sockaddr_storage address = { };
106784 int err, err2;
106785 int fput_needed;
106786
106787 @@ -2072,7 +2138,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106788 * checking falls down on this.
106789 */
106790 if (copy_from_user(ctl_buf,
106791 - (void __user __force *)msg_sys->msg_control,
106792 + (void __force_user *)msg_sys->msg_control,
106793 ctl_len))
106794 goto out_freectl;
106795 msg_sys->msg_control = ctl_buf;
106796 @@ -2223,7 +2289,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106797 int err, total_len, len;
106798
106799 /* kernel mode address */
106800 - struct sockaddr_storage addr;
106801 + struct sockaddr_storage addr = { };
106802
106803 /* user mode address pointers */
106804 struct sockaddr __user *uaddr;
106805 @@ -2252,7 +2318,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106806 /* Save the user-mode address (verify_iovec will change the
106807 * kernel msghdr to use the kernel address space)
106808 */
106809 - uaddr = (__force void __user *)msg_sys->msg_name;
106810 + uaddr = (void __force_user *)msg_sys->msg_name;
106811 uaddr_len = COMPAT_NAMELEN(msg);
106812 if (MSG_CMSG_COMPAT & flags)
106813 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106814 @@ -2893,7 +2959,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106815 ifr = compat_alloc_user_space(buf_size);
106816 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106817
106818 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106819 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106820 return -EFAULT;
106821
106822 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106823 @@ -3004,7 +3070,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106824 old_fs = get_fs();
106825 set_fs(KERNEL_DS);
106826 err = dev_ioctl(net, cmd,
106827 - (struct ifreq __user __force *) &kifr);
106828 + (struct ifreq __force_user *) &kifr);
106829 set_fs(old_fs);
106830
106831 return err;
106832 @@ -3097,7 +3163,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106833
106834 old_fs = get_fs();
106835 set_fs(KERNEL_DS);
106836 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106837 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106838 set_fs(old_fs);
106839
106840 if (cmd == SIOCGIFMAP && !err) {
106841 @@ -3181,7 +3247,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106842 ret |= get_user(rtdev, &(ur4->rt_dev));
106843 if (rtdev) {
106844 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106845 - r4.rt_dev = (char __user __force *)devname;
106846 + r4.rt_dev = (char __force_user *)devname;
106847 devname[15] = 0;
106848 } else
106849 r4.rt_dev = NULL;
106850 @@ -3408,8 +3474,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106851 int __user *uoptlen;
106852 int err;
106853
106854 - uoptval = (char __user __force *) optval;
106855 - uoptlen = (int __user __force *) optlen;
106856 + uoptval = (char __force_user *) optval;
106857 + uoptlen = (int __force_user *) optlen;
106858
106859 set_fs(KERNEL_DS);
106860 if (level == SOL_SOCKET)
106861 @@ -3429,7 +3495,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106862 char __user *uoptval;
106863 int err;
106864
106865 - uoptval = (char __user __force *) optval;
106866 + uoptval = (char __force_user *) optval;
106867
106868 set_fs(KERNEL_DS);
106869 if (level == SOL_SOCKET)
106870 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106871 index c548ab2..4e1b68b 100644
106872 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106873 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106874 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106875 uint64_t *handle)
106876 {
106877 struct rsc rsci, *rscp = NULL;
106878 - static atomic64_t ctxhctr;
106879 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106880 long long ctxh;
106881 struct gss_api_mech *gm = NULL;
106882 time_t expiry;
106883 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106884 status = -ENOMEM;
106885 /* the handle needs to be just a unique id,
106886 * use a static counter */
106887 - ctxh = atomic64_inc_return(&ctxhctr);
106888 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106889
106890 /* make a copy for the caller */
106891 *handle = ctxh;
106892 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106893 index 0663621..c4928d4 100644
106894 --- a/net/sunrpc/cache.c
106895 +++ b/net/sunrpc/cache.c
106896 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106897 struct sunrpc_net *sn;
106898
106899 sn = net_generic(net, sunrpc_net_id);
106900 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106901 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106902 if (cd->u.procfs.proc_ent == NULL)
106903 goto out_nomem;
106904 cd->u.procfs.channel_ent = NULL;
106905 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106906 index 9acd6ce..4353a72 100644
106907 --- a/net/sunrpc/clnt.c
106908 +++ b/net/sunrpc/clnt.c
106909 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106910 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106911
106912 /* Increment call count */
106913 - task->tk_msg.rpc_proc->p_count++;
106914 + pax_open_kernel();
106915 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106916 + pax_close_kernel();
106917 clnt->cl_stats->rpccnt++;
106918 task->tk_action = call_reserve;
106919 }
106920 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106921 index fe3441a..922c29e 100644
106922 --- a/net/sunrpc/sched.c
106923 +++ b/net/sunrpc/sched.c
106924 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106925 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106926 static void rpc_task_set_debuginfo(struct rpc_task *task)
106927 {
106928 - static atomic_t rpc_pid;
106929 + static atomic_unchecked_t rpc_pid;
106930
106931 - task->tk_pid = atomic_inc_return(&rpc_pid);
106932 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106933 }
106934 #else
106935 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106936 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106937 index 5453049..465669a 100644
106938 --- a/net/sunrpc/stats.c
106939 +++ b/net/sunrpc/stats.c
106940 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106941
106942 dprintk("RPC: registering /proc/net/rpc\n");
106943 sn = net_generic(net, sunrpc_net_id);
106944 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106945 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106946 if (sn->proc_net_rpc == NULL)
106947 return -ENOMEM;
106948
106949 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106950 index ca8a795..ddfc41b 100644
106951 --- a/net/sunrpc/svc.c
106952 +++ b/net/sunrpc/svc.c
106953 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106954 svc_putnl(resv, RPC_SUCCESS);
106955
106956 /* Bump per-procedure stats counter */
106957 - procp->pc_count++;
106958 + pax_open_kernel();
106959 + (*(unsigned int *)&procp->pc_count)++;
106960 + pax_close_kernel();
106961
106962 /* Initialize storage for argp and resp */
106963 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106964 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106965 index 621ca7b..59421dd 100644
106966 --- a/net/sunrpc/svcauth_unix.c
106967 +++ b/net/sunrpc/svcauth_unix.c
106968 @@ -414,7 +414,7 @@ struct unix_gid {
106969 struct group_info *gi;
106970 };
106971
106972 -static int unix_gid_hash(kuid_t uid)
106973 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106974 {
106975 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106976 }
106977 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106978 (*bpp)[-1] = '\n';
106979 }
106980
106981 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106982 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106983
106984 static int unix_gid_parse(struct cache_detail *cd,
106985 char *mesg, int mlen)
106986 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106987 index c1b6270..05089c1 100644
106988 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106989 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106990 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106991 static unsigned int min_max_inline = 4096;
106992 static unsigned int max_max_inline = 65536;
106993
106994 -atomic_t rdma_stat_recv;
106995 -atomic_t rdma_stat_read;
106996 -atomic_t rdma_stat_write;
106997 -atomic_t rdma_stat_sq_starve;
106998 -atomic_t rdma_stat_rq_starve;
106999 -atomic_t rdma_stat_rq_poll;
107000 -atomic_t rdma_stat_rq_prod;
107001 -atomic_t rdma_stat_sq_poll;
107002 -atomic_t rdma_stat_sq_prod;
107003 +atomic_unchecked_t rdma_stat_recv;
107004 +atomic_unchecked_t rdma_stat_read;
107005 +atomic_unchecked_t rdma_stat_write;
107006 +atomic_unchecked_t rdma_stat_sq_starve;
107007 +atomic_unchecked_t rdma_stat_rq_starve;
107008 +atomic_unchecked_t rdma_stat_rq_poll;
107009 +atomic_unchecked_t rdma_stat_rq_prod;
107010 +atomic_unchecked_t rdma_stat_sq_poll;
107011 +atomic_unchecked_t rdma_stat_sq_prod;
107012
107013 /* Temporary NFS request map and context caches */
107014 struct kmem_cache *svc_rdma_map_cachep;
107015 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
107016 len -= *ppos;
107017 if (len > *lenp)
107018 len = *lenp;
107019 - if (len && copy_to_user(buffer, str_buf, len))
107020 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
107021 return -EFAULT;
107022 *lenp = len;
107023 *ppos += len;
107024 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
107025 {
107026 .procname = "rdma_stat_read",
107027 .data = &rdma_stat_read,
107028 - .maxlen = sizeof(atomic_t),
107029 + .maxlen = sizeof(atomic_unchecked_t),
107030 .mode = 0644,
107031 .proc_handler = read_reset_stat,
107032 },
107033 {
107034 .procname = "rdma_stat_recv",
107035 .data = &rdma_stat_recv,
107036 - .maxlen = sizeof(atomic_t),
107037 + .maxlen = sizeof(atomic_unchecked_t),
107038 .mode = 0644,
107039 .proc_handler = read_reset_stat,
107040 },
107041 {
107042 .procname = "rdma_stat_write",
107043 .data = &rdma_stat_write,
107044 - .maxlen = sizeof(atomic_t),
107045 + .maxlen = sizeof(atomic_unchecked_t),
107046 .mode = 0644,
107047 .proc_handler = read_reset_stat,
107048 },
107049 {
107050 .procname = "rdma_stat_sq_starve",
107051 .data = &rdma_stat_sq_starve,
107052 - .maxlen = sizeof(atomic_t),
107053 + .maxlen = sizeof(atomic_unchecked_t),
107054 .mode = 0644,
107055 .proc_handler = read_reset_stat,
107056 },
107057 {
107058 .procname = "rdma_stat_rq_starve",
107059 .data = &rdma_stat_rq_starve,
107060 - .maxlen = sizeof(atomic_t),
107061 + .maxlen = sizeof(atomic_unchecked_t),
107062 .mode = 0644,
107063 .proc_handler = read_reset_stat,
107064 },
107065 {
107066 .procname = "rdma_stat_rq_poll",
107067 .data = &rdma_stat_rq_poll,
107068 - .maxlen = sizeof(atomic_t),
107069 + .maxlen = sizeof(atomic_unchecked_t),
107070 .mode = 0644,
107071 .proc_handler = read_reset_stat,
107072 },
107073 {
107074 .procname = "rdma_stat_rq_prod",
107075 .data = &rdma_stat_rq_prod,
107076 - .maxlen = sizeof(atomic_t),
107077 + .maxlen = sizeof(atomic_unchecked_t),
107078 .mode = 0644,
107079 .proc_handler = read_reset_stat,
107080 },
107081 {
107082 .procname = "rdma_stat_sq_poll",
107083 .data = &rdma_stat_sq_poll,
107084 - .maxlen = sizeof(atomic_t),
107085 + .maxlen = sizeof(atomic_unchecked_t),
107086 .mode = 0644,
107087 .proc_handler = read_reset_stat,
107088 },
107089 {
107090 .procname = "rdma_stat_sq_prod",
107091 .data = &rdma_stat_sq_prod,
107092 - .maxlen = sizeof(atomic_t),
107093 + .maxlen = sizeof(atomic_unchecked_t),
107094 .mode = 0644,
107095 .proc_handler = read_reset_stat,
107096 },
107097 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107098 index e011027..9d3c4e1 100644
107099 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107100 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107101 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
107102 *page_no = pg_no;
107103 *page_offset = pg_off;
107104 ret = read;
107105 - atomic_inc(&rdma_stat_read);
107106 + atomic_inc_unchecked(&rdma_stat_read);
107107 return ret;
107108 err:
107109 svc_rdma_unmap_dma(ctxt);
107110 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107111 *page_no = pg_no;
107112 *page_offset = pg_off;
107113 ret = read;
107114 - atomic_inc(&rdma_stat_read);
107115 + atomic_inc_unchecked(&rdma_stat_read);
107116 return ret;
107117 err:
107118 svc_rdma_unmap_dma(ctxt);
107119 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107120 dto_q);
107121 list_del_init(&ctxt->dto_q);
107122 } else {
107123 - atomic_inc(&rdma_stat_rq_starve);
107124 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107125 clear_bit(XPT_DATA, &xprt->xpt_flags);
107126 ctxt = NULL;
107127 }
107128 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107129 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107130 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107131 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107132 - atomic_inc(&rdma_stat_recv);
107133 + atomic_inc_unchecked(&rdma_stat_recv);
107134
107135 /* Build up the XDR from the receive buffers. */
107136 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107137 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107138 index 9f1b506..2e0b321 100644
107139 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107140 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107141 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107142 write_wr.wr.rdma.remote_addr = to;
107143
107144 /* Post It */
107145 - atomic_inc(&rdma_stat_write);
107146 + atomic_inc_unchecked(&rdma_stat_write);
107147 if (svc_rdma_send(xprt, &write_wr))
107148 goto err;
107149 return write_len - bc;
107150 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107151 index 4e61880..1f0d963 100644
107152 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107153 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107154 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107155 return;
107156
107157 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107158 - atomic_inc(&rdma_stat_rq_poll);
107159 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107160
107161 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107162 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107163 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107164 }
107165
107166 if (ctxt)
107167 - atomic_inc(&rdma_stat_rq_prod);
107168 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107169
107170 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107171 /*
107172 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107173 return;
107174
107175 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107176 - atomic_inc(&rdma_stat_sq_poll);
107177 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107178 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107179 int i;
107180
107181 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107182 }
107183
107184 if (ctxt)
107185 - atomic_inc(&rdma_stat_sq_prod);
107186 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107187 }
107188
107189 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107190 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107191 spin_lock_bh(&xprt->sc_lock);
107192 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107193 spin_unlock_bh(&xprt->sc_lock);
107194 - atomic_inc(&rdma_stat_sq_starve);
107195 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107196
107197 /* See if we can opportunistically reap SQ WR to make room */
107198 sq_cq_reap(xprt);
107199 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107200 index e7000be..e3b0ba7 100644
107201 --- a/net/sysctl_net.c
107202 +++ b/net/sysctl_net.c
107203 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107204 kgid_t root_gid = make_kgid(net->user_ns, 0);
107205
107206 /* Allow network administrator to have same access as root. */
107207 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107208 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107209 uid_eq(root_uid, current_euid())) {
107210 int mode = (table->mode >> 6) & 7;
107211 return (mode << 6) | (mode << 3) | mode;
107212 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107213 index 31b5cb2..566ff01 100644
107214 --- a/net/tipc/subscr.c
107215 +++ b/net/tipc/subscr.c
107216 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107217 struct tipc_subscriber *subscriber = sub->subscriber;
107218 struct kvec msg_sect;
107219
107220 - msg_sect.iov_base = (void *)&sub->evt;
107221 + msg_sect.iov_base = &sub->evt;
107222 msg_sect.iov_len = sizeof(struct tipc_event);
107223 sub->evt.event = htohl(event, sub->swap);
107224 sub->evt.found_lower = htohl(found_lower, sub->swap);
107225 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107226 index e968843..bc95776 100644
107227 --- a/net/unix/af_unix.c
107228 +++ b/net/unix/af_unix.c
107229 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107230 err = -ECONNREFUSED;
107231 if (!S_ISSOCK(inode->i_mode))
107232 goto put_fail;
107233 +
107234 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107235 + err = -EACCES;
107236 + goto put_fail;
107237 + }
107238 +
107239 u = unix_find_socket_byinode(inode);
107240 if (!u)
107241 goto put_fail;
107242 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107243 if (u) {
107244 struct dentry *dentry;
107245 dentry = unix_sk(u)->path.dentry;
107246 +
107247 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107248 + err = -EPERM;
107249 + sock_put(u);
107250 + goto fail;
107251 + }
107252 +
107253 if (dentry)
107254 touch_atime(&unix_sk(u)->path);
107255 } else
107256 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107257 */
107258 err = security_path_mknod(&path, dentry, mode, 0);
107259 if (!err) {
107260 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107261 + err = -EACCES;
107262 + goto out;
107263 + }
107264 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107265 if (!err) {
107266 res->mnt = mntget(path.mnt);
107267 res->dentry = dget(dentry);
107268 + gr_handle_create(dentry, path.mnt);
107269 }
107270 }
107271 +out:
107272 done_path_create(&path, dentry);
107273 return err;
107274 }
107275 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107276 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107277 "Inode Path\n");
107278 else {
107279 - struct sock *s = v;
107280 + struct sock *s = v, *peer;
107281 struct unix_sock *u = unix_sk(s);
107282 unix_state_lock(s);
107283 + peer = unix_peer(s);
107284 + unix_state_unlock(s);
107285 +
107286 + unix_state_double_lock(s, peer);
107287
107288 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107289 s,
107290 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107291 }
107292 for ( ; i < len; i++)
107293 seq_putc(seq, u->addr->name->sun_path[i]);
107294 - }
107295 - unix_state_unlock(s);
107296 + } else if (peer)
107297 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107298 +
107299 + unix_state_double_unlock(s, peer);
107300 seq_putc(seq, '\n');
107301 }
107302
107303 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107304 index b3d5150..ff3a837 100644
107305 --- a/net/unix/sysctl_net_unix.c
107306 +++ b/net/unix/sysctl_net_unix.c
107307 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107308
107309 int __net_init unix_sysctl_register(struct net *net)
107310 {
107311 - struct ctl_table *table;
107312 + ctl_table_no_const *table;
107313
107314 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107315 if (table == NULL)
107316 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107317 index 9b7f207..2596621 100644
107318 --- a/net/vmw_vsock/vmci_transport_notify.c
107319 +++ b/net/vmw_vsock/vmci_transport_notify.c
107320 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107321
107322 /* Socket control packet based operations. */
107323 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107324 - vmci_transport_notify_pkt_socket_init,
107325 - vmci_transport_notify_pkt_socket_destruct,
107326 - vmci_transport_notify_pkt_poll_in,
107327 - vmci_transport_notify_pkt_poll_out,
107328 - vmci_transport_notify_pkt_handle_pkt,
107329 - vmci_transport_notify_pkt_recv_init,
107330 - vmci_transport_notify_pkt_recv_pre_block,
107331 - vmci_transport_notify_pkt_recv_pre_dequeue,
107332 - vmci_transport_notify_pkt_recv_post_dequeue,
107333 - vmci_transport_notify_pkt_send_init,
107334 - vmci_transport_notify_pkt_send_pre_block,
107335 - vmci_transport_notify_pkt_send_pre_enqueue,
107336 - vmci_transport_notify_pkt_send_post_enqueue,
107337 - vmci_transport_notify_pkt_process_request,
107338 - vmci_transport_notify_pkt_process_negotiate,
107339 + .socket_init = vmci_transport_notify_pkt_socket_init,
107340 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107341 + .poll_in = vmci_transport_notify_pkt_poll_in,
107342 + .poll_out = vmci_transport_notify_pkt_poll_out,
107343 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107344 + .recv_init = vmci_transport_notify_pkt_recv_init,
107345 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107346 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107347 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107348 + .send_init = vmci_transport_notify_pkt_send_init,
107349 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107350 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107351 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107352 + .process_request = vmci_transport_notify_pkt_process_request,
107353 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107354 };
107355 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107356 index dc9c792..3089de0 100644
107357 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107358 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107359 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107360
107361 /* Socket always on control packet based operations. */
107362 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107363 - vmci_transport_notify_pkt_socket_init,
107364 - vmci_transport_notify_pkt_socket_destruct,
107365 - vmci_transport_notify_pkt_poll_in,
107366 - vmci_transport_notify_pkt_poll_out,
107367 - vmci_transport_notify_pkt_handle_pkt,
107368 - vmci_transport_notify_pkt_recv_init,
107369 - vmci_transport_notify_pkt_recv_pre_block,
107370 - vmci_transport_notify_pkt_recv_pre_dequeue,
107371 - vmci_transport_notify_pkt_recv_post_dequeue,
107372 - vmci_transport_notify_pkt_send_init,
107373 - vmci_transport_notify_pkt_send_pre_block,
107374 - vmci_transport_notify_pkt_send_pre_enqueue,
107375 - vmci_transport_notify_pkt_send_post_enqueue,
107376 - vmci_transport_notify_pkt_process_request,
107377 - vmci_transport_notify_pkt_process_negotiate,
107378 + .socket_init = vmci_transport_notify_pkt_socket_init,
107379 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107380 + .poll_in = vmci_transport_notify_pkt_poll_in,
107381 + .poll_out = vmci_transport_notify_pkt_poll_out,
107382 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107383 + .recv_init = vmci_transport_notify_pkt_recv_init,
107384 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107385 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107386 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107387 + .send_init = vmci_transport_notify_pkt_send_init,
107388 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107389 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107390 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107391 + .process_request = vmci_transport_notify_pkt_process_request,
107392 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107393 };
107394 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107395 index c8717c1..08539f5 100644
107396 --- a/net/wireless/wext-core.c
107397 +++ b/net/wireless/wext-core.c
107398 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107399 */
107400
107401 /* Support for very large requests */
107402 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107403 - (user_length > descr->max_tokens)) {
107404 + if (user_length > descr->max_tokens) {
107405 /* Allow userspace to GET more than max so
107406 * we can support any size GET requests.
107407 * There is still a limit : -ENOMEM.
107408 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107409 }
107410 }
107411
107412 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107413 - /*
107414 - * If this is a GET, but not NOMAX, it means that the extra
107415 - * data is not bounded by userspace, but by max_tokens. Thus
107416 - * set the length to max_tokens. This matches the extra data
107417 - * allocation.
107418 - * The driver should fill it with the number of tokens it
107419 - * provided, and it may check iwp->length rather than having
107420 - * knowledge of max_tokens. If the driver doesn't change the
107421 - * iwp->length, this ioctl just copies back max_token tokens
107422 - * filled with zeroes. Hopefully the driver isn't claiming
107423 - * them to be valid data.
107424 - */
107425 - iwp->length = descr->max_tokens;
107426 - }
107427 -
107428 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107429
107430 iwp->length += essid_compat;
107431 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107432 index 4323952..a06dfe1 100644
107433 --- a/net/x25/sysctl_net_x25.c
107434 +++ b/net/x25/sysctl_net_x25.c
107435 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107436 .mode = 0644,
107437 .proc_handler = proc_dointvec,
107438 },
107439 - { 0, },
107440 + { },
107441 };
107442
107443 void __init x25_register_sysctl(void)
107444 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107445 index 0917f04..f4e3d8c 100644
107446 --- a/net/x25/x25_proc.c
107447 +++ b/net/x25/x25_proc.c
107448 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107449
107450 int __init x25_proc_init(void)
107451 {
107452 - if (!proc_mkdir("x25", init_net.proc_net))
107453 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107454 return -ENOMEM;
107455
107456 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107457 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107458 index 88bf289..7b0741b 100644
107459 --- a/net/xfrm/xfrm_policy.c
107460 +++ b/net/xfrm/xfrm_policy.c
107461 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107462 {
107463 policy->walk.dead = 1;
107464
107465 - atomic_inc(&policy->genid);
107466 + atomic_inc_unchecked(&policy->genid);
107467
107468 if (del_timer(&policy->polq.hold_timer))
107469 xfrm_pol_put(policy);
107470 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107471 hlist_add_head(&policy->bydst, chain);
107472 xfrm_pol_hold(policy);
107473 net->xfrm.policy_count[dir]++;
107474 - atomic_inc(&net->xfrm.flow_cache_genid);
107475 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107476
107477 /* After previous checking, family can either be AF_INET or AF_INET6 */
107478 if (policy->family == AF_INET)
107479 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107480
107481 xdst->num_pols = num_pols;
107482 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107483 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107484 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107485
107486 return xdst;
107487 }
107488 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
107489 }
107490 EXPORT_SYMBOL(xfrm_garbage_collect);
107491
107492 -static void xfrm_garbage_collect_deferred(struct net *net)
107493 +void xfrm_garbage_collect_deferred(struct net *net)
107494 {
107495 flow_cache_flush_deferred(net);
107496 }
107497 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107498
107499 static void xfrm_init_pmtu(struct dst_entry *dst)
107500 {
107501 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107502 if (xdst->xfrm_genid != dst->xfrm->genid)
107503 return 0;
107504 if (xdst->num_pols > 0 &&
107505 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107506 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107507 return 0;
107508
107509 mtu = dst_mtu(dst->child);
107510 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107511 dst_ops->link_failure = xfrm_link_failure;
107512 if (likely(dst_ops->neigh_lookup == NULL))
107513 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107514 - if (likely(afinfo->garbage_collect == NULL))
107515 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107516 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107517 }
107518 spin_unlock(&xfrm_policy_afinfo_lock);
107519 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107520 dst_ops->check = NULL;
107521 dst_ops->negative_advice = NULL;
107522 dst_ops->link_failure = NULL;
107523 - afinfo->garbage_collect = NULL;
107524 }
107525 return err;
107526 }
107527 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107528 sizeof(pol->xfrm_vec[i].saddr));
107529 pol->xfrm_vec[i].encap_family = mp->new_family;
107530 /* flush bundles */
107531 - atomic_inc(&pol->genid);
107532 + atomic_inc_unchecked(&pol->genid);
107533 }
107534 }
107535
107536 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107537 index de971b6..b843409 100644
107538 --- a/net/xfrm/xfrm_state.c
107539 +++ b/net/xfrm/xfrm_state.c
107540 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107541
107542 if (unlikely(afinfo == NULL))
107543 return -EAFNOSUPPORT;
107544 - typemap = afinfo->type_map;
107545 + typemap = (const struct xfrm_type **)afinfo->type_map;
107546 spin_lock_bh(&xfrm_type_lock);
107547
107548 - if (likely(typemap[type->proto] == NULL))
107549 + if (likely(typemap[type->proto] == NULL)) {
107550 + pax_open_kernel();
107551 typemap[type->proto] = type;
107552 - else
107553 + pax_close_kernel();
107554 + } else
107555 err = -EEXIST;
107556 spin_unlock_bh(&xfrm_type_lock);
107557 xfrm_state_put_afinfo(afinfo);
107558 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107559
107560 if (unlikely(afinfo == NULL))
107561 return -EAFNOSUPPORT;
107562 - typemap = afinfo->type_map;
107563 + typemap = (const struct xfrm_type **)afinfo->type_map;
107564 spin_lock_bh(&xfrm_type_lock);
107565
107566 if (unlikely(typemap[type->proto] != type))
107567 err = -ENOENT;
107568 - else
107569 + else {
107570 + pax_open_kernel();
107571 typemap[type->proto] = NULL;
107572 + pax_close_kernel();
107573 + }
107574 spin_unlock_bh(&xfrm_type_lock);
107575 xfrm_state_put_afinfo(afinfo);
107576 return err;
107577 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107578 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107579 {
107580 struct xfrm_state_afinfo *afinfo;
107581 - const struct xfrm_type **typemap;
107582 const struct xfrm_type *type;
107583 int modload_attempted = 0;
107584
107585 @@ -211,9 +215,8 @@ retry:
107586 afinfo = xfrm_state_get_afinfo(family);
107587 if (unlikely(afinfo == NULL))
107588 return NULL;
107589 - typemap = afinfo->type_map;
107590
107591 - type = typemap[proto];
107592 + type = afinfo->type_map[proto];
107593 if (unlikely(type && !try_module_get(type->owner)))
107594 type = NULL;
107595 if (!type && !modload_attempted) {
107596 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107597 return -EAFNOSUPPORT;
107598
107599 err = -EEXIST;
107600 - modemap = afinfo->mode_map;
107601 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107602 spin_lock_bh(&xfrm_mode_lock);
107603 if (modemap[mode->encap])
107604 goto out;
107605 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107606 if (!try_module_get(afinfo->owner))
107607 goto out;
107608
107609 - mode->afinfo = afinfo;
107610 + pax_open_kernel();
107611 + *(const void **)&mode->afinfo = afinfo;
107612 modemap[mode->encap] = mode;
107613 + pax_close_kernel();
107614 err = 0;
107615
107616 out:
107617 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107618 return -EAFNOSUPPORT;
107619
107620 err = -ENOENT;
107621 - modemap = afinfo->mode_map;
107622 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107623 spin_lock_bh(&xfrm_mode_lock);
107624 if (likely(modemap[mode->encap] == mode)) {
107625 + pax_open_kernel();
107626 modemap[mode->encap] = NULL;
107627 + pax_close_kernel();
107628 module_put(mode->afinfo->owner);
107629 err = 0;
107630 }
107631 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107632 u32 xfrm_get_acqseq(void)
107633 {
107634 u32 res;
107635 - static atomic_t acqseq;
107636 + static atomic_unchecked_t acqseq;
107637
107638 do {
107639 - res = atomic_inc_return(&acqseq);
107640 + res = atomic_inc_return_unchecked(&acqseq);
107641 } while (!res);
107642
107643 return res;
107644 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107645 index 05a6e3d..6716ec9 100644
107646 --- a/net/xfrm/xfrm_sysctl.c
107647 +++ b/net/xfrm/xfrm_sysctl.c
107648 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107649
107650 int __net_init xfrm_sysctl_init(struct net *net)
107651 {
107652 - struct ctl_table *table;
107653 + ctl_table_no_const *table;
107654
107655 __xfrm_sysctl_init(net);
107656
107657 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
107658 index 65e7b08..1b868d5 100644
107659 --- a/scripts/Kbuild.include
107660 +++ b/scripts/Kbuild.include
107661 @@ -144,7 +144,7 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
107662 # cc-ldoption
107663 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
107664 cc-ldoption = $(call try-run,\
107665 - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107666 + $(CC) $(1) -Wl,-r -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107667
107668 # ld-option
107669 # Usage: LDFLAGS += $(call ld-option, -X)
107670 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107671 index 649ce68..f6bc05c 100644
107672 --- a/scripts/Makefile.build
107673 +++ b/scripts/Makefile.build
107674 @@ -60,7 +60,7 @@ endif
107675 endif
107676
107677 # Do not include host rules unless needed
107678 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107679 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107680 include scripts/Makefile.host
107681 endif
107682
107683 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107684 index a609552..fde19cd 100644
107685 --- a/scripts/Makefile.clean
107686 +++ b/scripts/Makefile.clean
107687 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107688 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107689 $(always) $(targets) $(clean-files) \
107690 $(host-progs) \
107691 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107692 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107693 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107694
107695 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107696
107697 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107698 index 133edfa..c9aa07f 100644
107699 --- a/scripts/Makefile.host
107700 +++ b/scripts/Makefile.host
107701 @@ -20,7 +20,19 @@
107702 # Will compile qconf as a C++ program, and menu as a C program.
107703 # They are linked as C++ code to the executable qconf
107704
107705 +# hostprogs-y := conf
107706 +# conf-objs := conf.o libkconfig.so
107707 +# libkconfig-objs := expr.o type.o
107708 +# Will create a shared library named libkconfig.so that consists of
107709 +# expr.o and type.o (they are both compiled as C code and the object files
107710 +# are made as position independent code).
107711 +# conf.c is compiled as a C program, and conf.o is linked together with
107712 +# libkconfig.so as the executable conf.
107713 +# Note: Shared libraries consisting of C++ files are not supported
107714 +
107715 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107716 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107717 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107718
107719 # C code
107720 # Executables compiled from a single .c file
107721 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107722 # C++ Object (.o) files compiled from .cc files
107723 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107724
107725 +# Shared libaries (only .c supported)
107726 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107727 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107728 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107729 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107730 +# Remove .so files from "xxx-objs"
107731 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107732 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107733 +
107734 +# Object (.o) files used by the shared libaries
107735 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107736 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107737 +
107738 # output directory for programs/.o files
107739 # hostprogs-y := tools/build may have been specified.
107740 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107741 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107742 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107743 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107744 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107745 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107746 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107747 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107748 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107749 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107750
107751 obj-dirs += $(host-objdirs)
107752 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107753 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107754 $(call if_changed_dep,host-cxxobjs)
107755
107756 +# Compile .c file, create position independent .o file
107757 +# host-cshobjs -> .o
107758 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107759 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107760 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107761 + $(call if_changed_dep,host-cshobjs)
107762 +
107763 +# Compile .c file, create position independent .o file
107764 +# host-cxxshobjs -> .o
107765 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107766 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107767 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107768 + $(call if_changed_dep,host-cxxshobjs)
107769 +
107770 +# Link a shared library, based on position independent .o files
107771 +# *.o -> .so shared library (host-cshlib)
107772 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107773 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107774 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107775 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107776 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107777 + $(call if_changed,host-cshlib)
107778 +
107779 +# Link a shared library, based on position independent .o files
107780 +# *.o -> .so shared library (host-cxxshlib)
107781 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107782 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107783 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107784 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107785 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107786 + $(call if_changed,host-cxxshlib)
107787 +
107788 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107789 - $(host-cxxmulti) $(host-cxxobjs)
107790 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107791 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107792 index b304068..462d24e 100644
107793 --- a/scripts/basic/fixdep.c
107794 +++ b/scripts/basic/fixdep.c
107795 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107796 /*
107797 * Lookup a value in the configuration string.
107798 */
107799 -static int is_defined_config(const char *name, int len, unsigned int hash)
107800 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107801 {
107802 struct item *aux;
107803
107804 @@ -211,10 +211,10 @@ static void clear_config(void)
107805 /*
107806 * Record the use of a CONFIG_* word.
107807 */
107808 -static void use_config(const char *m, int slen)
107809 +static void use_config(const char *m, unsigned int slen)
107810 {
107811 unsigned int hash = strhash(m, slen);
107812 - int c, i;
107813 + unsigned int c, i;
107814
107815 if (is_defined_config(m, slen, hash))
107816 return;
107817 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107818
107819 static void parse_config_file(const char *map, size_t len)
107820 {
107821 - const int *end = (const int *) (map + len);
107822 + const unsigned int *end = (const unsigned int *) (map + len);
107823 /* start at +1, so that p can never be < map */
107824 - const int *m = (const int *) map + 1;
107825 + const unsigned int *m = (const unsigned int *) map + 1;
107826 const char *p, *q;
107827
107828 for (; m < end; m++) {
107829 @@ -435,7 +435,7 @@ static void print_deps(void)
107830 static void traps(void)
107831 {
107832 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107833 - int *p = (int *)test;
107834 + unsigned int *p = (unsigned int *)test;
107835
107836 if (*p != INT_CONF) {
107837 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107838 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107839 new file mode 100644
107840 index 0000000..822fa9e
107841 --- /dev/null
107842 +++ b/scripts/gcc-plugin.sh
107843 @@ -0,0 +1,51 @@
107844 +#!/bin/sh
107845 +srctree=$(dirname "$0")
107846 +gccplugins_dir=$($3 -print-file-name=plugin)
107847 +plugincc=$($1 -E - -o /dev/null -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
107848 +#include "gcc-common.h"
107849 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107850 +#warning $2 CXX
107851 +#else
107852 +#warning $1 CC
107853 +#endif
107854 +EOF
107855 +)
107856 +
107857 +if [ $? -ne 0 ]
107858 +then
107859 + exit 1
107860 +fi
107861 +
107862 +case "$plugincc" in
107863 + *"$1 CC"*)
107864 + echo "$1"
107865 + exit 0
107866 + ;;
107867 +
107868 + *"$2 CXX"*)
107869 + # the c++ compiler needs another test, see below
107870 + ;;
107871 +
107872 + *)
107873 + exit 1
107874 + ;;
107875 +esac
107876 +
107877 +# we need a c++ compiler that supports the designated initializer GNU extension
107878 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
107879 +#include "gcc-common.h"
107880 +class test {
107881 +public:
107882 + int test;
107883 +} test = {
107884 + .test = 1
107885 +};
107886 +EOF
107887 +)
107888 +
107889 +if [ $? -eq 0 ]
107890 +then
107891 + echo "$2"
107892 + exit 0
107893 +fi
107894 +exit 1
107895 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107896 index fdebd66..a349e33 100755
107897 --- a/scripts/headers_install.sh
107898 +++ b/scripts/headers_install.sh
107899 @@ -32,6 +32,7 @@ do
107900 FILE="$(basename "$i")"
107901 sed -r \
107902 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107903 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107904 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107905 -e 's@^#include <linux/compiler.h>@@' \
107906 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107907 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107908 index 86a4fe7..99e91f9 100755
107909 --- a/scripts/link-vmlinux.sh
107910 +++ b/scripts/link-vmlinux.sh
107911 @@ -166,7 +166,7 @@ else
107912 fi;
107913
107914 # final build of init/
107915 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107916 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107917
107918 kallsymso=""
107919 kallsyms_vmlinux=""
107920 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107921 index e614ef6..d9d2b01 100644
107922 --- a/scripts/mod/file2alias.c
107923 +++ b/scripts/mod/file2alias.c
107924 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107925 unsigned long size, unsigned long id_size,
107926 void *symval)
107927 {
107928 - int i;
107929 + unsigned int i;
107930
107931 if (size % id_size || size < id_size) {
107932 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107933 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107934 /* USB is special because the bcdDevice can be matched against a numeric range */
107935 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107936 static void do_usb_entry(void *symval,
107937 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107938 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107939 unsigned char range_lo, unsigned char range_hi,
107940 unsigned char max, struct module *mod)
107941 {
107942 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107943 {
107944 unsigned int devlo, devhi;
107945 unsigned char chi, clo, max;
107946 - int ndigits;
107947 + unsigned int ndigits;
107948
107949 DEF_FIELD(symval, usb_device_id, match_flags);
107950 DEF_FIELD(symval, usb_device_id, idVendor);
107951 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107952 for (i = 0; i < count; i++) {
107953 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107954 char acpi_id[sizeof(*id)];
107955 - int j;
107956 + unsigned int j;
107957
107958 buf_printf(&mod->dev_table_buf,
107959 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107960 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107961
107962 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107963 const char *id = (char *)(*devs)[j].id;
107964 - int i2, j2;
107965 + unsigned int i2, j2;
107966 int dup = 0;
107967
107968 if (!id[0])
107969 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107970 /* add an individual alias for every device entry */
107971 if (!dup) {
107972 char acpi_id[PNP_ID_LEN];
107973 - int k;
107974 + unsigned int k;
107975
107976 buf_printf(&mod->dev_table_buf,
107977 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107978 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107979 static int do_dmi_entry(const char *filename, void *symval,
107980 char *alias)
107981 {
107982 - int i, j;
107983 + unsigned int i, j;
107984 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107985 sprintf(alias, "dmi*");
107986
107987 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107988 index d439856..10c1eac 100644
107989 --- a/scripts/mod/modpost.c
107990 +++ b/scripts/mod/modpost.c
107991 @@ -921,6 +921,7 @@ enum mismatch {
107992 ANY_INIT_TO_ANY_EXIT,
107993 ANY_EXIT_TO_ANY_INIT,
107994 EXPORT_TO_INIT_EXIT,
107995 + DATA_TO_TEXT
107996 };
107997
107998 struct sectioncheck {
107999 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
108000 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
108001 .mismatch = EXPORT_TO_INIT_EXIT,
108002 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
108003 +},
108004 +/* Do not reference code from writable data */
108005 +{
108006 + .fromsec = { DATA_SECTIONS, NULL },
108007 + .tosec = { TEXT_SECTIONS, NULL },
108008 + .mismatch = DATA_TO_TEXT
108009 }
108010 };
108011
108012 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
108013 continue;
108014 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
108015 continue;
108016 - if (sym->st_value == addr)
108017 - return sym;
108018 /* Find a symbol nearby - addr are maybe negative */
108019 d = sym->st_value - addr;
108020 + if (d == 0)
108021 + return sym;
108022 if (d < 0)
108023 d = addr - sym->st_value;
108024 if (d < distance) {
108025 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
108026 tosym, prl_to, prl_to, tosym);
108027 free(prl_to);
108028 break;
108029 + case DATA_TO_TEXT:
108030 +#if 0
108031 + fprintf(stderr,
108032 + "The %s %s:%s references\n"
108033 + "the %s %s:%s%s\n",
108034 + from, fromsec, fromsym, to, tosec, tosym, to_p);
108035 +#endif
108036 + break;
108037 }
108038 fprintf(stderr, "\n");
108039 }
108040 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
108041 static void check_sec_ref(struct module *mod, const char *modname,
108042 struct elf_info *elf)
108043 {
108044 - int i;
108045 + unsigned int i;
108046 Elf_Shdr *sechdrs = elf->sechdrs;
108047
108048 /* Walk through all sections */
108049 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
108050 va_end(ap);
108051 }
108052
108053 -void buf_write(struct buffer *buf, const char *s, int len)
108054 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
108055 {
108056 if (buf->size - buf->pos < len) {
108057 buf->size += len + SZ;
108058 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
108059 if (fstat(fileno(file), &st) < 0)
108060 goto close_write;
108061
108062 - if (st.st_size != b->pos)
108063 + if (st.st_size != (off_t)b->pos)
108064 goto close_write;
108065
108066 tmp = NOFAIL(malloc(b->pos));
108067 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
108068 index 168b43d..77914bf 100644
108069 --- a/scripts/mod/modpost.h
108070 +++ b/scripts/mod/modpost.h
108071 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
108072
108073 struct buffer {
108074 char *p;
108075 - int pos;
108076 - int size;
108077 + unsigned int pos;
108078 + unsigned int size;
108079 };
108080
108081 void __attribute__((format(printf, 2, 3)))
108082 buf_printf(struct buffer *buf, const char *fmt, ...);
108083
108084 void
108085 -buf_write(struct buffer *buf, const char *s, int len);
108086 +buf_write(struct buffer *buf, const char *s, unsigned int len);
108087
108088 struct module {
108089 struct module *next;
108090 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
108091 index 944418d..15291e4 100644
108092 --- a/scripts/mod/sumversion.c
108093 +++ b/scripts/mod/sumversion.c
108094 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
108095 goto out;
108096 }
108097
108098 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
108099 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
108100 warn("writing sum in %s failed: %s\n",
108101 filename, strerror(errno));
108102 goto out;
108103 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
108104 index 0865b3e..7235dd4 100644
108105 --- a/scripts/module-common.lds
108106 +++ b/scripts/module-common.lds
108107 @@ -6,6 +6,10 @@
108108 SECTIONS {
108109 /DISCARD/ : { *(.discard) }
108110
108111 + .rodata : {
108112 + *(.rodata) *(.rodata.*)
108113 + *(.data..read_only)
108114 + }
108115 __ksymtab : { *(SORT(___ksymtab+*)) }
108116 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108117 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108118 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108119 index 99ca6e7..3a1a1a1 100644
108120 --- a/scripts/package/Makefile
108121 +++ b/scripts/package/Makefile
108122 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108123 ln -sf $(srctree) $(KERNELPATH)
108124 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108125 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108126 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108127 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108128 rm $(KERNELPATH)
108129 rm -f $(objtree)/.scmversion
108130 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108131 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108132 index 5972624..4028795 100755
108133 --- a/scripts/package/builddeb
108134 +++ b/scripts/package/builddeb
108135 @@ -293,6 +293,7 @@ fi
108136 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108137 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108138 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108139 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108140 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108141 mkdir -p "$destdir"
108142 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108143 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108144 index 1395760..bca2734 100755
108145 --- a/scripts/package/mkspec
108146 +++ b/scripts/package/mkspec
108147 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108148 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108149 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\""
108150 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108151 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108152 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108153 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108154
108155 echo ""
108156 echo "%clean"
108157 echo 'rm -rf $RPM_BUILD_ROOT'
108158 echo ""
108159 +echo "%pre"
108160 +echo 'chmod -f 0500 /boot'
108161 +echo 'if [ -d /lib/modules ]; then'
108162 +echo 'chmod -f 0500 /lib/modules'
108163 +echo 'fi'
108164 +echo 'if [ -d /lib32/modules ]; then'
108165 +echo 'chmod -f 0500 /lib32/modules'
108166 +echo 'fi'
108167 +echo 'if [ -d /lib64/modules ]; then'
108168 +echo 'chmod -f 0500 /lib64/modules'
108169 +echo 'fi'
108170 +echo ""
108171 +echo "%post devel"
108172 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108173 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108174 +echo ""
108175 echo "%post"
108176 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108177 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108178 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
108179 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
108180 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108181 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108182 +echo "if [ -x /sbin/dracut ]; then"
108183 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108184 +echo "else"
108185 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108186 echo "fi"
108187 echo ""
108188 echo "%files"
108189 -echo '%defattr (-, root, root)'
108190 +echo '%defattr (400, root, root, 500)'
108191 echo "%dir /lib/modules"
108192 -echo "/lib/modules/$KERNELRELEASE"
108193 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108194 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108195 +echo "/lib/modules/$KERNELRELEASE"
108196 echo "/lib/firmware/$KERNELRELEASE"
108197 echo "/boot/*"
108198 echo ""
108199 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
108200 echo "/usr/include"
108201 echo ""
108202 echo "%files devel"
108203 -echo '%defattr (-, root, root)'
108204 +echo '%defattr (400, root, root, 500)'
108205 +echo "%dir /lib/modules/$KERNELRELEASE"
108206 echo "/usr/src/kernels/$KERNELRELEASE"
108207 -echo "/lib/modules/$KERNELRELEASE/build"
108208 -echo "/lib/modules/$KERNELRELEASE/source"
108209 echo ""
108210 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108211 index 4718d78..9220d58 100644
108212 --- a/scripts/pnmtologo.c
108213 +++ b/scripts/pnmtologo.c
108214 @@ -244,14 +244,14 @@ static void write_header(void)
108215 fprintf(out, " * Linux logo %s\n", logoname);
108216 fputs(" */\n\n", out);
108217 fputs("#include <linux/linux_logo.h>\n\n", out);
108218 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108219 + fprintf(out, "static unsigned char %s_data[] = {\n",
108220 logoname);
108221 }
108222
108223 static void write_footer(void)
108224 {
108225 fputs("\n};\n\n", out);
108226 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108227 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108228 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108229 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108230 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108231 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108232 fputs("\n};\n\n", out);
108233
108234 /* write logo clut */
108235 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108236 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108237 logoname);
108238 write_hex_cnt = 0;
108239 for (i = 0; i < logo_clutsize; i++) {
108240 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108241 index ba87004..3f4852c 100644
108242 --- a/scripts/sortextable.h
108243 +++ b/scripts/sortextable.h
108244 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108245 const char *secstrtab;
108246 const char *strtab;
108247 char *extab_image;
108248 - int extab_index = 0;
108249 - int i;
108250 - int idx;
108251 + unsigned int extab_index = 0;
108252 + unsigned int i;
108253 + unsigned int idx;
108254 unsigned int num_sections;
108255 unsigned int secindex_strings;
108256
108257 diff --git a/scripts/tags.sh b/scripts/tags.sh
108258 index cdb491d..8d32bfc 100755
108259 --- a/scripts/tags.sh
108260 +++ b/scripts/tags.sh
108261 @@ -26,7 +26,7 @@ else
108262 fi
108263
108264 # ignore userspace tools
108265 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108266 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108267
108268 # Find all available archs
108269 find_all_archs()
108270 diff --git a/security/Kconfig b/security/Kconfig
108271 index beb86b5..1a953b1 100644
108272 --- a/security/Kconfig
108273 +++ b/security/Kconfig
108274 @@ -4,6 +4,974 @@
108275
108276 menu "Security options"
108277
108278 +menu "Grsecurity"
108279 +
108280 + config ARCH_TRACK_EXEC_LIMIT
108281 + bool
108282 +
108283 + config PAX_KERNEXEC_PLUGIN
108284 + bool
108285 +
108286 + config PAX_PER_CPU_PGD
108287 + bool
108288 +
108289 + config TASK_SIZE_MAX_SHIFT
108290 + int
108291 + depends on X86_64
108292 + default 47 if !PAX_PER_CPU_PGD
108293 + default 42 if PAX_PER_CPU_PGD
108294 +
108295 + config PAX_ENABLE_PAE
108296 + bool
108297 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108298 +
108299 + config PAX_USERCOPY_SLABS
108300 + bool
108301 +
108302 +config GRKERNSEC
108303 + bool "Grsecurity"
108304 + select CRYPTO
108305 + select CRYPTO_SHA256
108306 + select PROC_FS
108307 + select STOP_MACHINE
108308 + select TTY
108309 + select DEBUG_KERNEL
108310 + select DEBUG_LIST
108311 + help
108312 + If you say Y here, you will be able to configure many features
108313 + that will enhance the security of your system. It is highly
108314 + recommended that you say Y here and read through the help
108315 + for each option so that you fully understand the features and
108316 + can evaluate their usefulness for your machine.
108317 +
108318 +choice
108319 + prompt "Configuration Method"
108320 + depends on GRKERNSEC
108321 + default GRKERNSEC_CONFIG_CUSTOM
108322 + help
108323 +
108324 +config GRKERNSEC_CONFIG_AUTO
108325 + bool "Automatic"
108326 + help
108327 + If you choose this configuration method, you'll be able to answer a small
108328 + number of simple questions about how you plan to use this kernel.
108329 + The settings of grsecurity and PaX will be automatically configured for
108330 + the highest commonly-used settings within the provided constraints.
108331 +
108332 + If you require additional configuration, custom changes can still be made
108333 + from the "custom configuration" menu.
108334 +
108335 +config GRKERNSEC_CONFIG_CUSTOM
108336 + bool "Custom"
108337 + help
108338 + If you choose this configuration method, you'll be able to configure all
108339 + grsecurity and PaX settings manually. Via this method, no options are
108340 + automatically enabled.
108341 +
108342 +endchoice
108343 +
108344 +choice
108345 + prompt "Usage Type"
108346 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108347 + default GRKERNSEC_CONFIG_SERVER
108348 + help
108349 +
108350 +config GRKERNSEC_CONFIG_SERVER
108351 + bool "Server"
108352 + help
108353 + Choose this option if you plan to use this kernel on a server.
108354 +
108355 +config GRKERNSEC_CONFIG_DESKTOP
108356 + bool "Desktop"
108357 + help
108358 + Choose this option if you plan to use this kernel on a desktop.
108359 +
108360 +endchoice
108361 +
108362 +choice
108363 + prompt "Virtualization Type"
108364 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108365 + default GRKERNSEC_CONFIG_VIRT_NONE
108366 + help
108367 +
108368 +config GRKERNSEC_CONFIG_VIRT_NONE
108369 + bool "None"
108370 + help
108371 + Choose this option if this kernel will be run on bare metal.
108372 +
108373 +config GRKERNSEC_CONFIG_VIRT_GUEST
108374 + bool "Guest"
108375 + help
108376 + Choose this option if this kernel will be run as a VM guest.
108377 +
108378 +config GRKERNSEC_CONFIG_VIRT_HOST
108379 + bool "Host"
108380 + help
108381 + Choose this option if this kernel will be run as a VM host.
108382 +
108383 +endchoice
108384 +
108385 +choice
108386 + prompt "Virtualization Hardware"
108387 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108388 + help
108389 +
108390 +config GRKERNSEC_CONFIG_VIRT_EPT
108391 + bool "EPT/RVI Processor Support"
108392 + depends on X86
108393 + help
108394 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108395 + hardware virtualization. This allows for additional kernel hardening protections
108396 + to operate without additional performance impact.
108397 +
108398 + To see if your Intel processor supports EPT, see:
108399 + http://ark.intel.com/Products/VirtualizationTechnology
108400 + (Most Core i3/5/7 support EPT)
108401 +
108402 + To see if your AMD processor supports RVI, see:
108403 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108404 +
108405 +config GRKERNSEC_CONFIG_VIRT_SOFT
108406 + bool "First-gen/No Hardware Virtualization"
108407 + help
108408 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108409 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108410 +
108411 +endchoice
108412 +
108413 +choice
108414 + prompt "Virtualization Software"
108415 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108416 + help
108417 +
108418 +config GRKERNSEC_CONFIG_VIRT_XEN
108419 + bool "Xen"
108420 + help
108421 + Choose this option if this kernel is running as a Xen guest or host.
108422 +
108423 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108424 + bool "VMWare"
108425 + help
108426 + Choose this option if this kernel is running as a VMWare guest or host.
108427 +
108428 +config GRKERNSEC_CONFIG_VIRT_KVM
108429 + bool "KVM"
108430 + help
108431 + Choose this option if this kernel is running as a KVM guest or host.
108432 +
108433 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108434 + bool "VirtualBox"
108435 + help
108436 + Choose this option if this kernel is running as a VirtualBox guest or host.
108437 +
108438 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108439 + bool "Hyper-V"
108440 + help
108441 + Choose this option if this kernel is running as a Hyper-V guest.
108442 +
108443 +endchoice
108444 +
108445 +choice
108446 + prompt "Required Priorities"
108447 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108448 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108449 + help
108450 +
108451 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108452 + bool "Performance"
108453 + help
108454 + Choose this option if performance is of highest priority for this deployment
108455 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108456 + clearing of structures intended for userland, and freed memory sanitizing will
108457 + be disabled.
108458 +
108459 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108460 + bool "Security"
108461 + help
108462 + Choose this option if security is of highest priority for this deployment of
108463 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108464 + for userland, and freed memory sanitizing will be enabled for this kernel.
108465 + In a worst-case scenario, these features can introduce a 20% performance hit
108466 + (UDEREF on x64 contributing half of this hit).
108467 +
108468 +endchoice
108469 +
108470 +menu "Default Special Groups"
108471 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108472 +
108473 +config GRKERNSEC_PROC_GID
108474 + int "GID exempted from /proc restrictions"
108475 + default 1001
108476 + help
108477 + Setting this GID determines which group will be exempted from
108478 + grsecurity's /proc restrictions, allowing users of the specified
108479 + group to view network statistics and the existence of other users'
108480 + processes on the system. This GID may also be chosen at boot time
108481 + via "grsec_proc_gid=" on the kernel commandline.
108482 +
108483 +config GRKERNSEC_TPE_UNTRUSTED_GID
108484 + int "GID for TPE-untrusted users"
108485 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108486 + default 1005
108487 + help
108488 + Setting this GID determines which group untrusted users should
108489 + be added to. These users will be placed under grsecurity's Trusted Path
108490 + Execution mechanism, preventing them from executing their own binaries.
108491 + The users will only be able to execute binaries in directories owned and
108492 + writable only by the root user. If the sysctl option is enabled, a sysctl
108493 + option with name "tpe_gid" is created.
108494 +
108495 +config GRKERNSEC_TPE_TRUSTED_GID
108496 + int "GID for TPE-trusted users"
108497 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108498 + default 1005
108499 + help
108500 + Setting this GID determines what group TPE restrictions will be
108501 + *disabled* for. If the sysctl option is enabled, a sysctl option
108502 + with name "tpe_gid" is created.
108503 +
108504 +config GRKERNSEC_SYMLINKOWN_GID
108505 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108506 + depends on GRKERNSEC_CONFIG_SERVER
108507 + default 1006
108508 + help
108509 + Setting this GID determines what group kernel-enforced
108510 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108511 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108512 +
108513 +
108514 +endmenu
108515 +
108516 +menu "Customize Configuration"
108517 +depends on GRKERNSEC
108518 +
108519 +menu "PaX"
108520 +
108521 +config PAX
108522 + bool "Enable various PaX features"
108523 + default y if GRKERNSEC_CONFIG_AUTO
108524 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108525 + help
108526 + This allows you to enable various PaX features. PaX adds
108527 + intrusion prevention mechanisms to the kernel that reduce
108528 + the risks posed by exploitable memory corruption bugs.
108529 +
108530 +menu "PaX Control"
108531 + depends on PAX
108532 +
108533 +config PAX_SOFTMODE
108534 + bool 'Support soft mode'
108535 + help
108536 + Enabling this option will allow you to run PaX in soft mode, that
108537 + is, PaX features will not be enforced by default, only on executables
108538 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108539 + support as they are the only way to mark executables for soft mode use.
108540 +
108541 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108542 + line option on boot. Furthermore you can control various PaX features
108543 + at runtime via the entries in /proc/sys/kernel/pax.
108544 +
108545 +config PAX_EI_PAX
108546 + bool 'Use legacy ELF header marking'
108547 + default y if GRKERNSEC_CONFIG_AUTO
108548 + help
108549 + Enabling this option will allow you to control PaX features on
108550 + a per executable basis via the 'chpax' utility available at
108551 + http://pax.grsecurity.net/. The control flags will be read from
108552 + an otherwise reserved part of the ELF header. This marking has
108553 + numerous drawbacks (no support for soft-mode, toolchain does not
108554 + know about the non-standard use of the ELF header) therefore it
108555 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108556 + support.
108557 +
108558 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108559 + support as well, they will override the legacy EI_PAX marks.
108560 +
108561 + If you enable none of the marking options then all applications
108562 + will run with PaX enabled on them by default.
108563 +
108564 +config PAX_PT_PAX_FLAGS
108565 + bool 'Use ELF program header marking'
108566 + default y if GRKERNSEC_CONFIG_AUTO
108567 + help
108568 + Enabling this option will allow you to control PaX features on
108569 + a per executable basis via the 'paxctl' utility available at
108570 + http://pax.grsecurity.net/. The control flags will be read from
108571 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108572 + has the benefits of supporting both soft mode and being fully
108573 + integrated into the toolchain (the binutils patch is available
108574 + from http://pax.grsecurity.net).
108575 +
108576 + Note that if you enable the legacy EI_PAX marking support as well,
108577 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108578 +
108579 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108580 + must make sure that the marks are the same if a binary has both marks.
108581 +
108582 + If you enable none of the marking options then all applications
108583 + will run with PaX enabled on them by default.
108584 +
108585 +config PAX_XATTR_PAX_FLAGS
108586 + bool 'Use filesystem extended attributes marking'
108587 + default y if GRKERNSEC_CONFIG_AUTO
108588 + select CIFS_XATTR if CIFS
108589 + select F2FS_FS_XATTR if F2FS_FS
108590 + select EXT2_FS_XATTR if EXT2_FS
108591 + select EXT3_FS_XATTR if EXT3_FS
108592 + select JFFS2_FS_XATTR if JFFS2_FS
108593 + select REISERFS_FS_XATTR if REISERFS_FS
108594 + select SQUASHFS_XATTR if SQUASHFS
108595 + select TMPFS_XATTR if TMPFS
108596 + help
108597 + Enabling this option will allow you to control PaX features on
108598 + a per executable basis via the 'setfattr' utility. The control
108599 + flags will be read from the user.pax.flags extended attribute of
108600 + the file. This marking has the benefit of supporting binary-only
108601 + applications that self-check themselves (e.g., skype) and would
108602 + not tolerate chpax/paxctl changes. The main drawback is that
108603 + extended attributes are not supported by some filesystems (e.g.,
108604 + isofs, udf, vfat) so copying files through such filesystems will
108605 + lose the extended attributes and these PaX markings.
108606 +
108607 + Note that if you enable the legacy EI_PAX marking support as well,
108608 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108609 +
108610 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108611 + must make sure that the marks are the same if a binary has both marks.
108612 +
108613 + If you enable none of the marking options then all applications
108614 + will run with PaX enabled on them by default.
108615 +
108616 +choice
108617 + prompt 'MAC system integration'
108618 + default PAX_HAVE_ACL_FLAGS
108619 + help
108620 + Mandatory Access Control systems have the option of controlling
108621 + PaX flags on a per executable basis, choose the method supported
108622 + by your particular system.
108623 +
108624 + - "none": if your MAC system does not interact with PaX,
108625 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108626 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108627 +
108628 + NOTE: this option is for developers/integrators only.
108629 +
108630 + config PAX_NO_ACL_FLAGS
108631 + bool 'none'
108632 +
108633 + config PAX_HAVE_ACL_FLAGS
108634 + bool 'direct'
108635 +
108636 + config PAX_HOOK_ACL_FLAGS
108637 + bool 'hook'
108638 +endchoice
108639 +
108640 +endmenu
108641 +
108642 +menu "Non-executable pages"
108643 + depends on PAX
108644 +
108645 +config PAX_NOEXEC
108646 + bool "Enforce non-executable pages"
108647 + default y if GRKERNSEC_CONFIG_AUTO
108648 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108649 + help
108650 + By design some architectures do not allow for protecting memory
108651 + pages against execution or even if they do, Linux does not make
108652 + use of this feature. In practice this means that if a page is
108653 + readable (such as the stack or heap) it is also executable.
108654 +
108655 + There is a well known exploit technique that makes use of this
108656 + fact and a common programming mistake where an attacker can
108657 + introduce code of his choice somewhere in the attacked program's
108658 + memory (typically the stack or the heap) and then execute it.
108659 +
108660 + If the attacked program was running with different (typically
108661 + higher) privileges than that of the attacker, then he can elevate
108662 + his own privilege level (e.g. get a root shell, write to files for
108663 + which he does not have write access to, etc).
108664 +
108665 + Enabling this option will let you choose from various features
108666 + that prevent the injection and execution of 'foreign' code in
108667 + a program.
108668 +
108669 + This will also break programs that rely on the old behaviour and
108670 + expect that dynamically allocated memory via the malloc() family
108671 + of functions is executable (which it is not). Notable examples
108672 + are the XFree86 4.x server, the java runtime and wine.
108673 +
108674 +config PAX_PAGEEXEC
108675 + bool "Paging based non-executable pages"
108676 + default y if GRKERNSEC_CONFIG_AUTO
108677 + 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)
108678 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108679 + help
108680 + This implementation is based on the paging feature of the CPU.
108681 + On i386 without hardware non-executable bit support there is a
108682 + variable but usually low performance impact, however on Intel's
108683 + P4 core based CPUs it is very high so you should not enable this
108684 + for kernels meant to be used on such CPUs.
108685 +
108686 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108687 + with hardware non-executable bit support there is no performance
108688 + impact, on ppc the impact is negligible.
108689 +
108690 + Note that several architectures require various emulations due to
108691 + badly designed userland ABIs, this will cause a performance impact
108692 + but will disappear as soon as userland is fixed. For example, ppc
108693 + userland MUST have been built with secure-plt by a recent toolchain.
108694 +
108695 +config PAX_SEGMEXEC
108696 + bool "Segmentation based non-executable pages"
108697 + default y if GRKERNSEC_CONFIG_AUTO
108698 + depends on PAX_NOEXEC && X86_32
108699 + help
108700 + This implementation is based on the segmentation feature of the
108701 + CPU and has a very small performance impact, however applications
108702 + will be limited to a 1.5 GB address space instead of the normal
108703 + 3 GB.
108704 +
108705 +config PAX_EMUTRAMP
108706 + bool "Emulate trampolines"
108707 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108708 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108709 + help
108710 + There are some programs and libraries that for one reason or
108711 + another attempt to execute special small code snippets from
108712 + non-executable memory pages. Most notable examples are the
108713 + signal handler return code generated by the kernel itself and
108714 + the GCC trampolines.
108715 +
108716 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108717 + such programs will no longer work under your kernel.
108718 +
108719 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108720 + utilities to enable trampoline emulation for the affected programs
108721 + yet still have the protection provided by the non-executable pages.
108722 +
108723 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108724 + your system will not even boot.
108725 +
108726 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108727 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108728 + for the affected files.
108729 +
108730 + NOTE: enabling this feature *may* open up a loophole in the
108731 + protection provided by non-executable pages that an attacker
108732 + could abuse. Therefore the best solution is to not have any
108733 + files on your system that would require this option. This can
108734 + be achieved by not using libc5 (which relies on the kernel
108735 + signal handler return code) and not using or rewriting programs
108736 + that make use of the nested function implementation of GCC.
108737 + Skilled users can just fix GCC itself so that it implements
108738 + nested function calls in a way that does not interfere with PaX.
108739 +
108740 +config PAX_EMUSIGRT
108741 + bool "Automatically emulate sigreturn trampolines"
108742 + depends on PAX_EMUTRAMP && PARISC
108743 + default y
108744 + help
108745 + Enabling this option will have the kernel automatically detect
108746 + and emulate signal return trampolines executing on the stack
108747 + that would otherwise lead to task termination.
108748 +
108749 + This solution is intended as a temporary one for users with
108750 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108751 + Modula-3 runtime, etc) or executables linked to such, basically
108752 + everything that does not specify its own SA_RESTORER function in
108753 + normal executable memory like glibc 2.1+ does.
108754 +
108755 + On parisc you MUST enable this option, otherwise your system will
108756 + not even boot.
108757 +
108758 + NOTE: this feature cannot be disabled on a per executable basis
108759 + and since it *does* open up a loophole in the protection provided
108760 + by non-executable pages, the best solution is to not have any
108761 + files on your system that would require this option.
108762 +
108763 +config PAX_MPROTECT
108764 + bool "Restrict mprotect()"
108765 + default y if GRKERNSEC_CONFIG_AUTO
108766 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108767 + help
108768 + Enabling this option will prevent programs from
108769 + - changing the executable status of memory pages that were
108770 + not originally created as executable,
108771 + - making read-only executable pages writable again,
108772 + - creating executable pages from anonymous memory,
108773 + - making read-only-after-relocations (RELRO) data pages writable again.
108774 +
108775 + You should say Y here to complete the protection provided by
108776 + the enforcement of non-executable pages.
108777 +
108778 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108779 + this feature on a per file basis.
108780 +
108781 +config PAX_MPROTECT_COMPAT
108782 + bool "Use legacy/compat protection demoting (read help)"
108783 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108784 + depends on PAX_MPROTECT
108785 + help
108786 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108787 + by sending the proper error code to the application. For some broken
108788 + userland, this can cause problems with Python or other applications. The
108789 + current implementation however allows for applications like clamav to
108790 + detect if JIT compilation/execution is allowed and to fall back gracefully
108791 + to an interpreter-based mode if it does not. While we encourage everyone
108792 + to use the current implementation as-is and push upstream to fix broken
108793 + userland (note that the RWX logging option can assist with this), in some
108794 + environments this may not be possible. Having to disable MPROTECT
108795 + completely on certain binaries reduces the security benefit of PaX,
108796 + so this option is provided for those environments to revert to the old
108797 + behavior.
108798 +
108799 +config PAX_ELFRELOCS
108800 + bool "Allow ELF text relocations (read help)"
108801 + depends on PAX_MPROTECT
108802 + default n
108803 + help
108804 + Non-executable pages and mprotect() restrictions are effective
108805 + in preventing the introduction of new executable code into an
108806 + attacked task's address space. There remain only two venues
108807 + for this kind of attack: if the attacker can execute already
108808 + existing code in the attacked task then he can either have it
108809 + create and mmap() a file containing his code or have it mmap()
108810 + an already existing ELF library that does not have position
108811 + independent code in it and use mprotect() on it to make it
108812 + writable and copy his code there. While protecting against
108813 + the former approach is beyond PaX, the latter can be prevented
108814 + by having only PIC ELF libraries on one's system (which do not
108815 + need to relocate their code). If you are sure this is your case,
108816 + as is the case with all modern Linux distributions, then leave
108817 + this option disabled. You should say 'n' here.
108818 +
108819 +config PAX_ETEXECRELOCS
108820 + bool "Allow ELF ET_EXEC text relocations"
108821 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108822 + select PAX_ELFRELOCS
108823 + default y
108824 + help
108825 + On some architectures there are incorrectly created applications
108826 + that require text relocations and would not work without enabling
108827 + this option. If you are an alpha, ia64 or parisc user, you should
108828 + enable this option and disable it once you have made sure that
108829 + none of your applications need it.
108830 +
108831 +config PAX_EMUPLT
108832 + bool "Automatically emulate ELF PLT"
108833 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108834 + default y
108835 + help
108836 + Enabling this option will have the kernel automatically detect
108837 + and emulate the Procedure Linkage Table entries in ELF files.
108838 + On some architectures such entries are in writable memory, and
108839 + become non-executable leading to task termination. Therefore
108840 + it is mandatory that you enable this option on alpha, parisc,
108841 + sparc and sparc64, otherwise your system would not even boot.
108842 +
108843 + NOTE: this feature *does* open up a loophole in the protection
108844 + provided by the non-executable pages, therefore the proper
108845 + solution is to modify the toolchain to produce a PLT that does
108846 + not need to be writable.
108847 +
108848 +config PAX_DLRESOLVE
108849 + bool 'Emulate old glibc resolver stub'
108850 + depends on PAX_EMUPLT && SPARC
108851 + default n
108852 + help
108853 + This option is needed if userland has an old glibc (before 2.4)
108854 + that puts a 'save' instruction into the runtime generated resolver
108855 + stub that needs special emulation.
108856 +
108857 +config PAX_KERNEXEC
108858 + bool "Enforce non-executable kernel pages"
108859 + 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))
108860 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108861 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108862 + select PAX_KERNEXEC_PLUGIN if X86_64
108863 + help
108864 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108865 + that is, enabling this option will make it harder to inject
108866 + and execute 'foreign' code in kernel memory itself.
108867 +
108868 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108869 + the kernel command-line will result in an RWX physical map.
108870 +
108871 + Likewise, the EFI runtime services are necessarily mapped as
108872 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108873 + is recommended that you boot with "noefi" on the kernel
108874 + command-line if possible to eliminate the mapping.
108875 +
108876 +choice
108877 + prompt "Return Address Instrumentation Method"
108878 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108879 + depends on PAX_KERNEXEC_PLUGIN
108880 + help
108881 + Select the method used to instrument function pointer dereferences.
108882 + Note that binary modules cannot be instrumented by this approach.
108883 +
108884 + Note that the implementation requires a gcc with plugin support,
108885 + i.e., gcc 4.5 or newer. You may need to install the supporting
108886 + headers explicitly in addition to the normal gcc package.
108887 +
108888 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108889 + bool "bts"
108890 + help
108891 + This method is compatible with binary only modules but has
108892 + a higher runtime overhead.
108893 +
108894 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108895 + bool "or"
108896 + depends on !PARAVIRT
108897 + help
108898 + This method is incompatible with binary only modules but has
108899 + a lower runtime overhead.
108900 +endchoice
108901 +
108902 +config PAX_KERNEXEC_PLUGIN_METHOD
108903 + string
108904 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108905 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108906 + default ""
108907 +
108908 +config PAX_KERNEXEC_MODULE_TEXT
108909 + int "Minimum amount of memory reserved for module code"
108910 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108911 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108912 + depends on PAX_KERNEXEC && X86_32
108913 + help
108914 + Due to implementation details the kernel must reserve a fixed
108915 + amount of memory for runtime allocated code (such as modules)
108916 + at compile time that cannot be changed at runtime. Here you
108917 + can specify the minimum amount in MB that will be reserved.
108918 + Due to the same implementation details this size will always
108919 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108920 + the actually available memory for runtime allocated code will
108921 + usually be more than this minimum.
108922 +
108923 + The default 4 MB should be enough for most users but if you have
108924 + an excessive number of modules (e.g., most distribution configs
108925 + compile many drivers as modules) or use huge modules such as
108926 + nvidia's kernel driver, you will need to adjust this amount.
108927 + A good rule of thumb is to look at your currently loaded kernel
108928 + modules and add up their sizes.
108929 +
108930 +endmenu
108931 +
108932 +menu "Address Space Layout Randomization"
108933 + depends on PAX
108934 +
108935 +config PAX_ASLR
108936 + bool "Address Space Layout Randomization"
108937 + default y if GRKERNSEC_CONFIG_AUTO
108938 + help
108939 + Many if not most exploit techniques rely on the knowledge of
108940 + certain addresses in the attacked program. The following options
108941 + will allow the kernel to apply a certain amount of randomization
108942 + to specific parts of the program thereby forcing an attacker to
108943 + guess them in most cases. Any failed guess will most likely crash
108944 + the attacked program which allows the kernel to detect such attempts
108945 + and react on them. PaX itself provides no reaction mechanisms,
108946 + instead it is strongly encouraged that you make use of grsecurity's
108947 + (http://www.grsecurity.net/) built-in crash detection features or
108948 + develop one yourself.
108949 +
108950 + By saying Y here you can choose to randomize the following areas:
108951 + - top of the task's kernel stack
108952 + - top of the task's userland stack
108953 + - base address for mmap() requests that do not specify one
108954 + (this includes all libraries)
108955 + - base address of the main executable
108956 +
108957 + It is strongly recommended to say Y here as address space layout
108958 + randomization has negligible impact on performance yet it provides
108959 + a very effective protection.
108960 +
108961 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108962 + this feature on a per file basis.
108963 +
108964 +config PAX_RANDKSTACK
108965 + bool "Randomize kernel stack base"
108966 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108967 + depends on X86_TSC && X86
108968 + help
108969 + By saying Y here the kernel will randomize every task's kernel
108970 + stack on every system call. This will not only force an attacker
108971 + to guess it but also prevent him from making use of possible
108972 + leaked information about it.
108973 +
108974 + Since the kernel stack is a rather scarce resource, randomization
108975 + may cause unexpected stack overflows, therefore you should very
108976 + carefully test your system. Note that once enabled in the kernel
108977 + configuration, this feature cannot be disabled on a per file basis.
108978 +
108979 +config PAX_RANDUSTACK
108980 + bool
108981 +
108982 +config PAX_RANDMMAP
108983 + bool "Randomize user stack and mmap() bases"
108984 + default y if GRKERNSEC_CONFIG_AUTO
108985 + depends on PAX_ASLR
108986 + select PAX_RANDUSTACK
108987 + help
108988 + By saying Y here the kernel will randomize every task's userland
108989 + stack and use a randomized base address for mmap() requests that
108990 + do not specify one themselves.
108991 +
108992 + The stack randomization is done in two steps where the second
108993 + one may apply a big amount of shift to the top of the stack and
108994 + cause problems for programs that want to use lots of memory (more
108995 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108996 +
108997 + As a result of mmap randomization all dynamically loaded libraries
108998 + will appear at random addresses and therefore be harder to exploit
108999 + by a technique where an attacker attempts to execute library code
109000 + for his purposes (e.g. spawn a shell from an exploited program that
109001 + is running at an elevated privilege level).
109002 +
109003 + Furthermore, if a program is relinked as a dynamic ELF file, its
109004 + base address will be randomized as well, completing the full
109005 + randomization of the address space layout. Attacking such programs
109006 + becomes a guess game. You can find an example of doing this at
109007 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
109008 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
109009 +
109010 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
109011 + feature on a per file basis.
109012 +
109013 +endmenu
109014 +
109015 +menu "Miscellaneous hardening features"
109016 +
109017 +config PAX_MEMORY_SANITIZE
109018 + bool "Sanitize all freed memory"
109019 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109020 + help
109021 + By saying Y here the kernel will erase memory pages and slab objects
109022 + as soon as they are freed. This in turn reduces the lifetime of data
109023 + stored in them, making it less likely that sensitive information such
109024 + as passwords, cryptographic secrets, etc stay in memory for too long.
109025 +
109026 + This is especially useful for programs whose runtime is short, long
109027 + lived processes and the kernel itself benefit from this as long as
109028 + they ensure timely freeing of memory that may hold sensitive
109029 + information.
109030 +
109031 + A nice side effect of the sanitization of slab objects is the
109032 + reduction of possible info leaks caused by padding bytes within the
109033 + leaky structures. Use-after-free bugs for structures containing
109034 + pointers can also be detected as dereferencing the sanitized pointer
109035 + will generate an access violation.
109036 +
109037 + The tradeoff is performance impact, on a single CPU system kernel
109038 + compilation sees a 3% slowdown, other systems and workloads may vary
109039 + and you are advised to test this feature on your expected workload
109040 + before deploying it.
109041 +
109042 + The slab sanitization feature excludes a few slab caches per default
109043 + for performance reasons. To extend the feature to cover those as
109044 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
109045 +
109046 + To reduce the performance penalty by sanitizing pages only, albeit
109047 + limiting the effectiveness of this feature at the same time, slab
109048 + sanitization can be disabled with the kernel command line parameter
109049 + "pax_sanitize_slab=off".
109050 +
109051 + Note that this feature does not protect data stored in live pages,
109052 + e.g., process memory swapped to disk may stay there for a long time.
109053 +
109054 +config PAX_MEMORY_STACKLEAK
109055 + bool "Sanitize kernel stack"
109056 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109057 + depends on X86
109058 + help
109059 + By saying Y here the kernel will erase the kernel stack before it
109060 + returns from a system call. This in turn reduces the information
109061 + that a kernel stack leak bug can reveal.
109062 +
109063 + Note that such a bug can still leak information that was put on
109064 + the stack by the current system call (the one eventually triggering
109065 + the bug) but traces of earlier system calls on the kernel stack
109066 + cannot leak anymore.
109067 +
109068 + The tradeoff is performance impact: on a single CPU system kernel
109069 + compilation sees a 1% slowdown, other systems and workloads may vary
109070 + and you are advised to test this feature on your expected workload
109071 + before deploying it.
109072 +
109073 + Note that the full feature requires a gcc with plugin support,
109074 + i.e., gcc 4.5 or newer. You may need to install the supporting
109075 + headers explicitly in addition to the normal gcc package. Using
109076 + older gcc versions means that functions with large enough stack
109077 + frames may leave uninitialized memory behind that may be exposed
109078 + to a later syscall leaking the stack.
109079 +
109080 +config PAX_MEMORY_STRUCTLEAK
109081 + bool "Forcibly initialize local variables copied to userland"
109082 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109083 + help
109084 + By saying Y here the kernel will zero initialize some local
109085 + variables that are going to be copied to userland. This in
109086 + turn prevents unintended information leakage from the kernel
109087 + stack should later code forget to explicitly set all parts of
109088 + the copied variable.
109089 +
109090 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
109091 + at a much smaller coverage.
109092 +
109093 + Note that the implementation requires a gcc with plugin support,
109094 + i.e., gcc 4.5 or newer. You may need to install the supporting
109095 + headers explicitly in addition to the normal gcc package.
109096 +
109097 +config PAX_MEMORY_UDEREF
109098 + bool "Prevent invalid userland pointer dereference"
109099 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
109100 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
109101 + select PAX_PER_CPU_PGD if X86_64
109102 + help
109103 + By saying Y here the kernel will be prevented from dereferencing
109104 + userland pointers in contexts where the kernel expects only kernel
109105 + pointers. This is both a useful runtime debugging feature and a
109106 + security measure that prevents exploiting a class of kernel bugs.
109107 +
109108 + The tradeoff is that some virtualization solutions may experience
109109 + a huge slowdown and therefore you should not enable this feature
109110 + for kernels meant to run in such environments. Whether a given VM
109111 + solution is affected or not is best determined by simply trying it
109112 + out, the performance impact will be obvious right on boot as this
109113 + mechanism engages from very early on. A good rule of thumb is that
109114 + VMs running on CPUs without hardware virtualization support (i.e.,
109115 + the majority of IA-32 CPUs) will likely experience the slowdown.
109116 +
109117 + On X86_64 the kernel will make use of PCID support when available
109118 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109119 + or performance impact. Pass pax_weakuderef on the kernel command
109120 + line to choose the latter.
109121 +
109122 +config PAX_REFCOUNT
109123 + bool "Prevent various kernel object reference counter overflows"
109124 + default y if GRKERNSEC_CONFIG_AUTO
109125 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109126 + help
109127 + By saying Y here the kernel will detect and prevent overflowing
109128 + various (but not all) kinds of object reference counters. Such
109129 + overflows can normally occur due to bugs only and are often, if
109130 + not always, exploitable.
109131 +
109132 + The tradeoff is that data structures protected by an overflowed
109133 + refcount will never be freed and therefore will leak memory. Note
109134 + that this leak also happens even without this protection but in
109135 + that case the overflow can eventually trigger the freeing of the
109136 + data structure while it is still being used elsewhere, resulting
109137 + in the exploitable situation that this feature prevents.
109138 +
109139 + Since this has a negligible performance impact, you should enable
109140 + this feature.
109141 +
109142 +config PAX_CONSTIFY_PLUGIN
109143 + bool "Automatically constify eligible structures"
109144 + default y
109145 + depends on !UML && PAX_KERNEXEC
109146 + help
109147 + By saying Y here the compiler will automatically constify a class
109148 + of types that contain only function pointers. This reduces the
109149 + kernel's attack surface and also produces a better memory layout.
109150 +
109151 + Note that the implementation requires a gcc with plugin support,
109152 + i.e., gcc 4.5 or newer. You may need to install the supporting
109153 + headers explicitly in addition to the normal gcc package.
109154 +
109155 + Note that if some code really has to modify constified variables
109156 + then the source code will have to be patched to allow it. Examples
109157 + can be found in PaX itself (the no_const attribute) and for some
109158 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109159 +
109160 +config PAX_USERCOPY
109161 + bool "Harden heap object copies between kernel and userland"
109162 + default y if GRKERNSEC_CONFIG_AUTO
109163 + depends on ARM || IA64 || PPC || SPARC || X86
109164 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109165 + select PAX_USERCOPY_SLABS
109166 + help
109167 + By saying Y here the kernel will enforce the size of heap objects
109168 + when they are copied in either direction between the kernel and
109169 + userland, even if only a part of the heap object is copied.
109170 +
109171 + Specifically, this checking prevents information leaking from the
109172 + kernel heap during kernel to userland copies (if the kernel heap
109173 + object is otherwise fully initialized) and prevents kernel heap
109174 + overflows during userland to kernel copies.
109175 +
109176 + Note that the current implementation provides the strictest bounds
109177 + checks for the SLUB allocator.
109178 +
109179 + Enabling this option also enables per-slab cache protection against
109180 + data in a given cache being copied into/out of via userland
109181 + accessors. Though the whitelist of regions will be reduced over
109182 + time, it notably protects important data structures like task structs.
109183 +
109184 + If frame pointers are enabled on x86, this option will also restrict
109185 + copies into and out of the kernel stack to local variables within a
109186 + single frame.
109187 +
109188 + Since this has a negligible performance impact, you should enable
109189 + this feature.
109190 +
109191 +config PAX_USERCOPY_DEBUG
109192 + bool
109193 + depends on X86 && PAX_USERCOPY
109194 + default n
109195 +
109196 +config PAX_SIZE_OVERFLOW
109197 + bool "Prevent various integer overflows in function size parameters"
109198 + default y if GRKERNSEC_CONFIG_AUTO
109199 + depends on X86
109200 + help
109201 + By saying Y here the kernel recomputes expressions of function
109202 + arguments marked by a size_overflow attribute with double integer
109203 + precision (DImode/TImode for 32/64 bit integer types).
109204 +
109205 + The recomputed argument is checked against TYPE_MAX and an event
109206 + is logged on overflow and the triggering process is killed.
109207 +
109208 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109209 +
109210 + Note that the implementation requires a gcc with plugin support,
109211 + i.e., gcc 4.5 or newer. You may need to install the supporting
109212 + headers explicitly in addition to the normal gcc package.
109213 +
109214 +config PAX_LATENT_ENTROPY
109215 + bool "Generate some entropy during boot and runtime"
109216 + default y if GRKERNSEC_CONFIG_AUTO
109217 + help
109218 + By saying Y here the kernel will instrument some kernel code to
109219 + extract some entropy from both original and artificially created
109220 + program state. This will help especially embedded systems where
109221 + there is little 'natural' source of entropy normally. The cost
109222 + is some slowdown of the boot process and fork and irq processing.
109223 +
109224 + When pax_extra_latent_entropy is passed on the kernel command line,
109225 + entropy will be extracted from up to the first 4GB of RAM while the
109226 + runtime memory allocator is being initialized. This costs even more
109227 + slowdown of the boot process.
109228 +
109229 + Note that the implementation requires a gcc with plugin support,
109230 + i.e., gcc 4.5 or newer. You may need to install the supporting
109231 + headers explicitly in addition to the normal gcc package.
109232 +
109233 + Note that entropy extracted this way is not cryptographically
109234 + secure!
109235 +
109236 +endmenu
109237 +
109238 +endmenu
109239 +
109240 +source grsecurity/Kconfig
109241 +
109242 +endmenu
109243 +
109244 +endmenu
109245 +
109246 source security/keys/Kconfig
109247
109248 config SECURITY_DMESG_RESTRICT
109249 @@ -103,7 +1071,7 @@ config INTEL_TXT
109250 config LSM_MMAP_MIN_ADDR
109251 int "Low address space for LSM to protect from user allocation"
109252 depends on SECURITY && SECURITY_SELINUX
109253 - default 32768 if ARM || (ARM64 && COMPAT)
109254 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109255 default 65536
109256 help
109257 This is the portion of low virtual memory which should be protected
109258 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109259 index fdaa50c..2761dcb 100644
109260 --- a/security/apparmor/file.c
109261 +++ b/security/apparmor/file.c
109262 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109263 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109264 struct path *new_dir, struct dentry *new_dentry)
109265 {
109266 - struct path link = { new_dir->mnt, new_dentry };
109267 - struct path target = { new_dir->mnt, old_dentry };
109268 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109269 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109270 struct path_cond cond = {
109271 old_dentry->d_inode->i_uid,
109272 old_dentry->d_inode->i_mode
109273 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109274 index 65ca451..ad6f22d 100644
109275 --- a/security/apparmor/lsm.c
109276 +++ b/security/apparmor/lsm.c
109277 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109278 struct dentry *dentry, u32 mask,
109279 struct path_cond *cond)
109280 {
109281 - struct path path = { dir->mnt, dentry };
109282 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109283
109284 return common_perm(op, &path, mask, cond);
109285 }
109286 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109287 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109288 struct dentry *dentry, u32 mask)
109289 {
109290 - struct path path = { mnt, dentry };
109291 + struct path path = { .mnt = mnt, .dentry = dentry };
109292 struct path_cond cond = { dentry->d_inode->i_uid,
109293 dentry->d_inode->i_mode
109294 };
109295 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109296
109297 profile = aa_current_profile();
109298 if (!unconfined(profile)) {
109299 - struct path old_path = { old_dir->mnt, old_dentry };
109300 - struct path new_path = { new_dir->mnt, new_dentry };
109301 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109302 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109303 struct path_cond cond = { old_dentry->d_inode->i_uid,
109304 old_dentry->d_inode->i_mode
109305 };
109306 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109307 return error;
109308 }
109309
109310 -static struct security_operations apparmor_ops = {
109311 +static struct security_operations apparmor_ops __read_only = {
109312 .name = "apparmor",
109313
109314 .ptrace_access_check = apparmor_ptrace_access_check,
109315 diff --git a/security/commoncap.c b/security/commoncap.c
109316 index bab0611..f9a0ff5 100644
109317 --- a/security/commoncap.c
109318 +++ b/security/commoncap.c
109319 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109320 return 0;
109321 }
109322
109323 +/* returns:
109324 + 1 for suid privilege
109325 + 2 for sgid privilege
109326 + 3 for fscap privilege
109327 +*/
109328 +int is_privileged_binary(const struct dentry *dentry)
109329 +{
109330 + struct cpu_vfs_cap_data capdata;
109331 + struct inode *inode = dentry->d_inode;
109332 +
109333 + if (!inode || S_ISDIR(inode->i_mode))
109334 + return 0;
109335 +
109336 + if (inode->i_mode & S_ISUID)
109337 + return 1;
109338 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109339 + return 2;
109340 +
109341 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109342 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109343 + return 3;
109344 + }
109345 +
109346 + return 0;
109347 +}
109348 +
109349 /*
109350 * Attempt to get the on-exec apply capability sets for an executable file from
109351 * its xattrs and, if present, apply them to the proposed credentials being
109352 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109353 const struct cred *cred = current_cred();
109354 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109355
109356 + if (gr_acl_enable_at_secure())
109357 + return 1;
109358 +
109359 if (!uid_eq(cred->uid, root_uid)) {
109360 if (bprm->cap_effective)
109361 return 1;
109362 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109363 index 8ee997d..24c174b 100644
109364 --- a/security/integrity/ima/ima.h
109365 +++ b/security/integrity/ima/ima.h
109366 @@ -116,8 +116,8 @@ int ima_init_template(void);
109367 extern spinlock_t ima_queue_lock;
109368
109369 struct ima_h_table {
109370 - atomic_long_t len; /* number of stored measurements in the list */
109371 - atomic_long_t violations;
109372 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109373 + atomic_long_unchecked_t violations;
109374 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109375 };
109376 extern struct ima_h_table ima_htable;
109377 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109378 index 8688597..9fa80d2 100644
109379 --- a/security/integrity/ima/ima_api.c
109380 +++ b/security/integrity/ima/ima_api.c
109381 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109382 int result;
109383
109384 /* can overflow, only indicator */
109385 - atomic_long_inc(&ima_htable.violations);
109386 + atomic_long_inc_unchecked(&ima_htable.violations);
109387
109388 result = ima_alloc_init_template(NULL, file, filename,
109389 NULL, 0, &entry);
109390 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109391 index da92fcc..8a5d390 100644
109392 --- a/security/integrity/ima/ima_fs.c
109393 +++ b/security/integrity/ima/ima_fs.c
109394 @@ -28,12 +28,12 @@
109395 static int valid_policy = 1;
109396 #define TMPBUFLEN 12
109397 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109398 - loff_t *ppos, atomic_long_t *val)
109399 + loff_t *ppos, atomic_long_unchecked_t *val)
109400 {
109401 char tmpbuf[TMPBUFLEN];
109402 ssize_t len;
109403
109404 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109405 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109406 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109407 }
109408
109409 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109410 index 552705d..9920f4fb 100644
109411 --- a/security/integrity/ima/ima_queue.c
109412 +++ b/security/integrity/ima/ima_queue.c
109413 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109414 INIT_LIST_HEAD(&qe->later);
109415 list_add_tail_rcu(&qe->later, &ima_measurements);
109416
109417 - atomic_long_inc(&ima_htable.len);
109418 + atomic_long_inc_unchecked(&ima_htable.len);
109419 key = ima_hash_key(entry->digest);
109420 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109421 return 0;
109422 diff --git a/security/keys/compat.c b/security/keys/compat.c
109423 index 3478965..ec7bb9e 100644
109424 --- a/security/keys/compat.c
109425 +++ b/security/keys/compat.c
109426 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109427 if (ret == 0)
109428 goto no_payload_free;
109429
109430 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109431 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109432 err:
109433 if (iov != iovstack)
109434 kfree(iov);
109435 diff --git a/security/keys/internal.h b/security/keys/internal.h
109436 index 200e378..cdc74b5 100644
109437 --- a/security/keys/internal.h
109438 +++ b/security/keys/internal.h
109439 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109440 extern long keyctl_invalidate_key(key_serial_t);
109441
109442 extern long keyctl_instantiate_key_common(key_serial_t,
109443 - const struct iovec *,
109444 + const struct iovec __user *,
109445 unsigned, size_t, key_serial_t);
109446 #ifdef CONFIG_PERSISTENT_KEYRINGS
109447 extern long keyctl_get_persistent(uid_t, key_serial_t);
109448 diff --git a/security/keys/key.c b/security/keys/key.c
109449 index e17ba6a..2cc04a6 100644
109450 --- a/security/keys/key.c
109451 +++ b/security/keys/key.c
109452 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109453
109454 atomic_set(&key->usage, 1);
109455 init_rwsem(&key->sem);
109456 - lockdep_set_class(&key->sem, &type->lock_class);
109457 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109458 key->index_key.type = type;
109459 key->user = user;
109460 key->quotalen = quotalen;
109461 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109462 struct key_type *p;
109463 int ret;
109464
109465 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109466 + pax_open_kernel();
109467 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109468 + pax_close_kernel();
109469
109470 ret = -EEXIST;
109471 down_write(&key_types_sem);
109472 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109473 }
109474
109475 /* store the type */
109476 - list_add(&ktype->link, &key_types_list);
109477 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109478
109479 pr_notice("Key type %s registered\n", ktype->name);
109480 ret = 0;
109481 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109482 void unregister_key_type(struct key_type *ktype)
109483 {
109484 down_write(&key_types_sem);
109485 - list_del_init(&ktype->link);
109486 + pax_list_del_init((struct list_head *)&ktype->link);
109487 downgrade_write(&key_types_sem);
109488 key_gc_keytype(ktype);
109489 pr_notice("Key type %s unregistered\n", ktype->name);
109490 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109491 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109492
109493 /* add the special key types */
109494 - list_add_tail(&key_type_keyring.link, &key_types_list);
109495 - list_add_tail(&key_type_dead.link, &key_types_list);
109496 - list_add_tail(&key_type_user.link, &key_types_list);
109497 - list_add_tail(&key_type_logon.link, &key_types_list);
109498 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109499 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109500 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109501 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109502
109503 /* record the root user tracking */
109504 rb_link_node(&root_key_user.node,
109505 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109506 index 4743d71..170a185 100644
109507 --- a/security/keys/keyctl.c
109508 +++ b/security/keys/keyctl.c
109509 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109510 /*
109511 * Copy the iovec data from userspace
109512 */
109513 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109514 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109515 unsigned ioc)
109516 {
109517 for (; ioc > 0; ioc--) {
109518 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109519 * If successful, 0 will be returned.
109520 */
109521 long keyctl_instantiate_key_common(key_serial_t id,
109522 - const struct iovec *payload_iov,
109523 + const struct iovec __user *payload_iov,
109524 unsigned ioc,
109525 size_t plen,
109526 key_serial_t ringid)
109527 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
109528 [0].iov_len = plen
109529 };
109530
109531 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109532 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109533 }
109534
109535 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109536 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109537 if (ret == 0)
109538 goto no_payload_free;
109539
109540 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109541 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109542 err:
109543 if (iov != iovstack)
109544 kfree(iov);
109545 diff --git a/security/keys/request_key.c b/security/keys/request_key.c
109546 index 0c7aea4..486ef6f 100644
109547 --- a/security/keys/request_key.c
109548 +++ b/security/keys/request_key.c
109549 @@ -414,6 +414,7 @@ link_check_failed:
109550
109551 link_prealloc_failed:
109552 mutex_unlock(&user->cons_lock);
109553 + key_put(key);
109554 kleave(" = %d [prelink]", ret);
109555 return ret;
109556
109557 diff --git a/security/min_addr.c b/security/min_addr.c
109558 index f728728..6457a0c 100644
109559 --- a/security/min_addr.c
109560 +++ b/security/min_addr.c
109561 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109562 */
109563 static void update_mmap_min_addr(void)
109564 {
109565 +#ifndef SPARC
109566 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109567 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109568 mmap_min_addr = dac_mmap_min_addr;
109569 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109570 #else
109571 mmap_min_addr = dac_mmap_min_addr;
109572 #endif
109573 +#endif
109574 }
109575
109576 /*
109577 diff --git a/security/security.c b/security/security.c
109578 index 18b35c6..c9fbc92 100644
109579 --- a/security/security.c
109580 +++ b/security/security.c
109581 @@ -33,8 +33,8 @@
109582 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109583 CONFIG_DEFAULT_SECURITY;
109584
109585 -static struct security_operations *security_ops;
109586 -static struct security_operations default_security_ops = {
109587 +struct security_operations *security_ops __read_only;
109588 +struct security_operations default_security_ops __read_only = {
109589 .name = "default",
109590 };
109591
109592 @@ -73,11 +73,6 @@ int __init security_init(void)
109593 return 0;
109594 }
109595
109596 -void reset_security_ops(void)
109597 -{
109598 - security_ops = &default_security_ops;
109599 -}
109600 -
109601 /* Save user chosen LSM */
109602 static int __init choose_lsm(char *str)
109603 {
109604 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109605 index a18f1fa..c9b9fc4 100644
109606 --- a/security/selinux/avc.c
109607 +++ b/security/selinux/avc.c
109608 @@ -59,7 +59,7 @@ struct avc_node {
109609 struct avc_cache {
109610 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109611 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109612 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109613 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109614 atomic_t active_nodes;
109615 u32 latest_notif; /* latest revocation notification */
109616 };
109617 @@ -167,7 +167,7 @@ void __init avc_init(void)
109618 spin_lock_init(&avc_cache.slots_lock[i]);
109619 }
109620 atomic_set(&avc_cache.active_nodes, 0);
109621 - atomic_set(&avc_cache.lru_hint, 0);
109622 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109623
109624 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109625 0, SLAB_PANIC, NULL);
109626 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109627 spinlock_t *lock;
109628
109629 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109630 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109631 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109632 head = &avc_cache.slots[hvalue];
109633 lock = &avc_cache.slots_lock[hvalue];
109634
109635 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109636 index c603b20..8716ec9 100644
109637 --- a/security/selinux/hooks.c
109638 +++ b/security/selinux/hooks.c
109639 @@ -95,8 +95,6 @@
109640 #include "audit.h"
109641 #include "avc_ss.h"
109642
109643 -extern struct security_operations *security_ops;
109644 -
109645 /* SECMARK reference count */
109646 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109647
109648 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109649
109650 #endif
109651
109652 -static struct security_operations selinux_ops = {
109653 +static struct security_operations selinux_ops __read_only = {
109654 .name = "selinux",
109655
109656 .ptrace_access_check = selinux_ptrace_access_check,
109657 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
109658 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109659 static int selinux_disabled;
109660
109661 +extern struct security_operations *security_ops;
109662 +extern struct security_operations default_security_ops;
109663 +
109664 int selinux_disable(void)
109665 {
109666 if (ss_initialized) {
109667 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
109668 selinux_disabled = 1;
109669 selinux_enabled = 0;
109670
109671 - reset_security_ops();
109672 + pax_open_kernel();
109673 + security_ops = &default_security_ops;
109674 + pax_close_kernel();
109675
109676 /* Try to destroy the avc node cache */
109677 avc_disable();
109678 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109679 index 1450f85..a91e0bc 100644
109680 --- a/security/selinux/include/xfrm.h
109681 +++ b/security/selinux/include/xfrm.h
109682 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109683
109684 rtnl_lock();
109685 for_each_net(net) {
109686 - atomic_inc(&net->xfrm.flow_cache_genid);
109687 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109688 rt_genid_bump_all(net);
109689 }
109690 rtnl_unlock();
109691 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109692 index d515ec2..8a4ca71 100644
109693 --- a/security/smack/smack_lsm.c
109694 +++ b/security/smack/smack_lsm.c
109695 @@ -4079,7 +4079,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109696 return 0;
109697 }
109698
109699 -struct security_operations smack_ops = {
109700 +struct security_operations smack_ops __read_only = {
109701 .name = "smack",
109702
109703 .ptrace_access_check = smack_ptrace_access_check,
109704 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109705 index 4003907..13a2b55 100644
109706 --- a/security/tomoyo/file.c
109707 +++ b/security/tomoyo/file.c
109708 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109709 {
109710 struct tomoyo_request_info r;
109711 struct tomoyo_obj_info obj = {
109712 - .path1 = *path,
109713 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109714 };
109715 int error = -ENOMEM;
109716 struct tomoyo_path_info buf;
109717 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109718 struct tomoyo_path_info buf;
109719 struct tomoyo_request_info r;
109720 struct tomoyo_obj_info obj = {
109721 - .path1 = *path,
109722 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109723 };
109724 int idx;
109725
109726 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109727 {
109728 struct tomoyo_request_info r;
109729 struct tomoyo_obj_info obj = {
109730 - .path1 = *path,
109731 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109732 };
109733 int error;
109734 struct tomoyo_path_info buf;
109735 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109736 {
109737 struct tomoyo_request_info r;
109738 struct tomoyo_obj_info obj = {
109739 - .path1 = *path,
109740 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109741 };
109742 int error = -ENOMEM;
109743 struct tomoyo_path_info buf;
109744 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109745 struct tomoyo_path_info buf2;
109746 struct tomoyo_request_info r;
109747 struct tomoyo_obj_info obj = {
109748 - .path1 = *path1,
109749 - .path2 = *path2,
109750 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109751 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109752 };
109753 int idx;
109754
109755 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109756 index 390c646..f2f8db3 100644
109757 --- a/security/tomoyo/mount.c
109758 +++ b/security/tomoyo/mount.c
109759 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109760 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109761 need_dev = -1; /* dev_name is a directory */
109762 } else {
109763 + if (!capable(CAP_SYS_ADMIN)) {
109764 + error = -EPERM;
109765 + goto out;
109766 + }
109767 fstype = get_fs_type(type);
109768 if (!fstype) {
109769 error = -ENODEV;
109770 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109771 index f0b756e..8aa497b 100644
109772 --- a/security/tomoyo/tomoyo.c
109773 +++ b/security/tomoyo/tomoyo.c
109774 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109775 */
109776 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109777 {
109778 - struct path path = { mnt, dentry };
109779 + struct path path = { .mnt = mnt, .dentry = dentry };
109780 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109781 }
109782
109783 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109784 */
109785 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109786 {
109787 - struct path path = { parent->mnt, dentry };
109788 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109789 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109790 }
109791
109792 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109793 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109794 umode_t mode)
109795 {
109796 - struct path path = { parent->mnt, dentry };
109797 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109798 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109799 mode & S_IALLUGO);
109800 }
109801 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109802 */
109803 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109804 {
109805 - struct path path = { parent->mnt, dentry };
109806 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109807 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109808 }
109809
109810 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109811 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109812 const char *old_name)
109813 {
109814 - struct path path = { parent->mnt, dentry };
109815 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109816 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109817 }
109818
109819 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109820 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109821 umode_t mode, unsigned int dev)
109822 {
109823 - struct path path = { parent->mnt, dentry };
109824 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109825 int type = TOMOYO_TYPE_CREATE;
109826 const unsigned int perm = mode & S_IALLUGO;
109827
109828 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109829 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109830 struct dentry *new_dentry)
109831 {
109832 - struct path path1 = { new_dir->mnt, old_dentry };
109833 - struct path path2 = { new_dir->mnt, new_dentry };
109834 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109835 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109836 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109837 }
109838
109839 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109840 struct path *new_parent,
109841 struct dentry *new_dentry)
109842 {
109843 - struct path path1 = { old_parent->mnt, old_dentry };
109844 - struct path path2 = { new_parent->mnt, new_dentry };
109845 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109846 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109847 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109848 }
109849
109850 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109851 */
109852 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109853 {
109854 - struct path path = { mnt, mnt->mnt_root };
109855 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109856 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109857 }
109858
109859 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109860 * tomoyo_security_ops is a "struct security_operations" which is used for
109861 * registering TOMOYO.
109862 */
109863 -static struct security_operations tomoyo_security_ops = {
109864 +static struct security_operations tomoyo_security_ops __read_only = {
109865 .name = "tomoyo",
109866 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109867 .cred_prepare = tomoyo_cred_prepare,
109868 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109869 index 20ef514..4182bed 100644
109870 --- a/security/yama/Kconfig
109871 +++ b/security/yama/Kconfig
109872 @@ -1,6 +1,6 @@
109873 config SECURITY_YAMA
109874 bool "Yama support"
109875 - depends on SECURITY
109876 + depends on SECURITY && !GRKERNSEC
109877 select SECURITYFS
109878 select SECURITY_PATH
109879 default n
109880 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109881 index 13c88fbc..f8c115e 100644
109882 --- a/security/yama/yama_lsm.c
109883 +++ b/security/yama/yama_lsm.c
109884 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109885 }
109886
109887 #ifndef CONFIG_SECURITY_YAMA_STACKED
109888 -static struct security_operations yama_ops = {
109889 +static struct security_operations yama_ops __read_only = {
109890 .name = "yama",
109891
109892 .ptrace_access_check = yama_ptrace_access_check,
109893 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109894 #endif
109895
109896 #ifdef CONFIG_SYSCTL
109897 +static int zero __read_only;
109898 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109899 +
109900 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109901 void __user *buffer, size_t *lenp, loff_t *ppos)
109902 {
109903 - int rc;
109904 + ctl_table_no_const yama_table;
109905
109906 if (write && !capable(CAP_SYS_PTRACE))
109907 return -EPERM;
109908
109909 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109910 - if (rc)
109911 - return rc;
109912 -
109913 + yama_table = *table;
109914 /* Lock the max value if it ever gets set. */
109915 - if (write && *(int *)table->data == *(int *)table->extra2)
109916 - table->extra1 = table->extra2;
109917 -
109918 - return rc;
109919 + if (ptrace_scope == max_scope)
109920 + yama_table.extra1 = &max_scope;
109921 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109922 }
109923
109924 -static int zero;
109925 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109926 -
109927 struct ctl_path yama_sysctl_path[] = {
109928 { .procname = "kernel", },
109929 { .procname = "yama", },
109930 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109931 index 401107b..b9c47c6 100644
109932 --- a/sound/aoa/codecs/onyx.c
109933 +++ b/sound/aoa/codecs/onyx.c
109934 @@ -54,7 +54,7 @@ struct onyx {
109935 spdif_locked:1,
109936 analog_locked:1,
109937 original_mute:2;
109938 - int open_count;
109939 + local_t open_count;
109940 struct codec_info *codec_info;
109941
109942 /* mutex serializes concurrent access to the device
109943 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109944 struct onyx *onyx = cii->codec_data;
109945
109946 mutex_lock(&onyx->mutex);
109947 - onyx->open_count++;
109948 + local_inc(&onyx->open_count);
109949 mutex_unlock(&onyx->mutex);
109950
109951 return 0;
109952 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109953 struct onyx *onyx = cii->codec_data;
109954
109955 mutex_lock(&onyx->mutex);
109956 - onyx->open_count--;
109957 - if (!onyx->open_count)
109958 + if (local_dec_and_test(&onyx->open_count))
109959 onyx->spdif_locked = onyx->analog_locked = 0;
109960 mutex_unlock(&onyx->mutex);
109961
109962 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109963 index ffd2025..df062c9 100644
109964 --- a/sound/aoa/codecs/onyx.h
109965 +++ b/sound/aoa/codecs/onyx.h
109966 @@ -11,6 +11,7 @@
109967 #include <linux/i2c.h>
109968 #include <asm/pmac_low_i2c.h>
109969 #include <asm/prom.h>
109970 +#include <asm/local.h>
109971
109972 /* PCM3052 register definitions */
109973
109974 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109975 index ada69d7..5f65386 100644
109976 --- a/sound/core/oss/pcm_oss.c
109977 +++ b/sound/core/oss/pcm_oss.c
109978 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109979 if (in_kernel) {
109980 mm_segment_t fs;
109981 fs = snd_enter_user();
109982 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109983 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109984 snd_leave_user(fs);
109985 } else {
109986 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109987 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109988 }
109989 if (ret != -EPIPE && ret != -ESTRPIPE)
109990 break;
109991 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109992 if (in_kernel) {
109993 mm_segment_t fs;
109994 fs = snd_enter_user();
109995 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109996 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109997 snd_leave_user(fs);
109998 } else {
109999 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110000 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110001 }
110002 if (ret == -EPIPE) {
110003 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
110004 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
110005 struct snd_pcm_plugin_channel *channels;
110006 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
110007 if (!in_kernel) {
110008 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
110009 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
110010 return -EFAULT;
110011 buf = runtime->oss.buffer;
110012 }
110013 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
110014 }
110015 } else {
110016 tmp = snd_pcm_oss_write2(substream,
110017 - (const char __force *)buf,
110018 + (const char __force_kernel *)buf,
110019 runtime->oss.period_bytes, 0);
110020 if (tmp <= 0)
110021 goto err;
110022 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
110023 struct snd_pcm_runtime *runtime = substream->runtime;
110024 snd_pcm_sframes_t frames, frames1;
110025 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
110026 - char __user *final_dst = (char __force __user *)buf;
110027 + char __user *final_dst = (char __force_user *)buf;
110028 if (runtime->oss.plugin_first) {
110029 struct snd_pcm_plugin_channel *channels;
110030 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
110031 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
110032 xfer += tmp;
110033 runtime->oss.buffer_used -= tmp;
110034 } else {
110035 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
110036 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
110037 runtime->oss.period_bytes, 0);
110038 if (tmp <= 0)
110039 goto err;
110040 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
110041 size1);
110042 size1 /= runtime->channels; /* frames */
110043 fs = snd_enter_user();
110044 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
110045 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
110046 snd_leave_user(fs);
110047 }
110048 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
110049 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
110050 index 2d957ba..fda022c 100644
110051 --- a/sound/core/pcm_compat.c
110052 +++ b/sound/core/pcm_compat.c
110053 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
110054 int err;
110055
110056 fs = snd_enter_user();
110057 - err = snd_pcm_delay(substream, &delay);
110058 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
110059 snd_leave_user(fs);
110060 if (err < 0)
110061 return err;
110062 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
110063 index 166d59c..89e3889 100644
110064 --- a/sound/core/pcm_native.c
110065 +++ b/sound/core/pcm_native.c
110066 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
110067 switch (substream->stream) {
110068 case SNDRV_PCM_STREAM_PLAYBACK:
110069 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
110070 - (void __user *)arg);
110071 + (void __force_user *)arg);
110072 break;
110073 case SNDRV_PCM_STREAM_CAPTURE:
110074 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
110075 - (void __user *)arg);
110076 + (void __force_user *)arg);
110077 break;
110078 default:
110079 result = -EINVAL;
110080 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
110081 index 16d4267..fe8b49b 100644
110082 --- a/sound/core/seq/oss/seq_oss.c
110083 +++ b/sound/core/seq/oss/seq_oss.c
110084 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
110085 {
110086 int rc;
110087 static struct snd_seq_dev_ops ops = {
110088 - snd_seq_oss_synth_register,
110089 - snd_seq_oss_synth_unregister,
110090 + .init_device = snd_seq_oss_synth_register,
110091 + .free_device = snd_seq_oss_synth_unregister,
110092 };
110093
110094 snd_seq_autoload_lock();
110095 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
110096 index 91a786a..4c07ed4 100644
110097 --- a/sound/core/seq/seq_device.c
110098 +++ b/sound/core/seq/seq_device.c
110099 @@ -64,7 +64,7 @@ struct ops_list {
110100 int argsize; /* argument size */
110101
110102 /* operators */
110103 - struct snd_seq_dev_ops ops;
110104 + struct snd_seq_dev_ops *ops;
110105
110106 /* registered devices */
110107 struct list_head dev_list; /* list of devices */
110108 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
110109
110110 mutex_lock(&ops->reg_mutex);
110111 /* copy driver operators */
110112 - ops->ops = *entry;
110113 + ops->ops = entry;
110114 ops->driver |= DRIVER_LOADED;
110115 ops->argsize = argsize;
110116
110117 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110118 dev->name, ops->id, ops->argsize, dev->argsize);
110119 return -EINVAL;
110120 }
110121 - if (ops->ops.init_device(dev) >= 0) {
110122 + if (ops->ops->init_device(dev) >= 0) {
110123 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110124 ops->num_init_devices++;
110125 } else {
110126 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110127 dev->name, ops->id, ops->argsize, dev->argsize);
110128 return -EINVAL;
110129 }
110130 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110131 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110132 dev->status = SNDRV_SEQ_DEVICE_FREE;
110133 dev->driver_data = NULL;
110134 ops->num_init_devices--;
110135 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110136 index a1fd77a..69cd659 100644
110137 --- a/sound/core/seq/seq_midi.c
110138 +++ b/sound/core/seq/seq_midi.c
110139 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110140 static int __init alsa_seq_midi_init(void)
110141 {
110142 static struct snd_seq_dev_ops ops = {
110143 - snd_seq_midisynth_register_port,
110144 - snd_seq_midisynth_unregister_port,
110145 + .init_device = snd_seq_midisynth_register_port,
110146 + .free_device = snd_seq_midisynth_unregister_port,
110147 };
110148 memset(&synths, 0, sizeof(synths));
110149 snd_seq_autoload_lock();
110150 diff --git a/sound/core/sound.c b/sound/core/sound.c
110151 index 38ad1a0..5010a40 100644
110152 --- a/sound/core/sound.c
110153 +++ b/sound/core/sound.c
110154 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110155 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110156 default: return;
110157 }
110158 - request_module(str);
110159 + request_module("%s", str);
110160 }
110161
110162 #endif /* modular kernel */
110163 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110164 index f5fd448..6ae276da 100644
110165 --- a/sound/drivers/mts64.c
110166 +++ b/sound/drivers/mts64.c
110167 @@ -29,6 +29,7 @@
110168 #include <sound/initval.h>
110169 #include <sound/rawmidi.h>
110170 #include <sound/control.h>
110171 +#include <asm/local.h>
110172
110173 #define CARD_NAME "Miditerminal 4140"
110174 #define DRIVER_NAME "MTS64"
110175 @@ -67,7 +68,7 @@ struct mts64 {
110176 struct pardevice *pardev;
110177 int pardev_claimed;
110178
110179 - int open_count;
110180 + local_t open_count;
110181 int current_midi_output_port;
110182 int current_midi_input_port;
110183 u8 mode[MTS64_NUM_INPUT_PORTS];
110184 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110185 {
110186 struct mts64 *mts = substream->rmidi->private_data;
110187
110188 - if (mts->open_count == 0) {
110189 + if (local_read(&mts->open_count) == 0) {
110190 /* We don't need a spinlock here, because this is just called
110191 if the device has not been opened before.
110192 So there aren't any IRQs from the device */
110193 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110194
110195 msleep(50);
110196 }
110197 - ++(mts->open_count);
110198 + local_inc(&mts->open_count);
110199
110200 return 0;
110201 }
110202 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110203 struct mts64 *mts = substream->rmidi->private_data;
110204 unsigned long flags;
110205
110206 - --(mts->open_count);
110207 - if (mts->open_count == 0) {
110208 + if (local_dec_return(&mts->open_count) == 0) {
110209 /* We need the spinlock_irqsave here because we can still
110210 have IRQs at this point */
110211 spin_lock_irqsave(&mts->lock, flags);
110212 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110213
110214 msleep(500);
110215
110216 - } else if (mts->open_count < 0)
110217 - mts->open_count = 0;
110218 + } else if (local_read(&mts->open_count) < 0)
110219 + local_set(&mts->open_count, 0);
110220
110221 return 0;
110222 }
110223 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110224 index 6839953..7a0f4b9 100644
110225 --- a/sound/drivers/opl3/opl3_seq.c
110226 +++ b/sound/drivers/opl3/opl3_seq.c
110227 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110228 {
110229 static struct snd_seq_dev_ops ops =
110230 {
110231 - snd_opl3_seq_new_device,
110232 - snd_opl3_seq_delete_device
110233 + .init_device = snd_opl3_seq_new_device,
110234 + .free_device = snd_opl3_seq_delete_device
110235 };
110236
110237 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110238 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110239 index b953fb4..1999c01 100644
110240 --- a/sound/drivers/opl4/opl4_lib.c
110241 +++ b/sound/drivers/opl4/opl4_lib.c
110242 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110243 MODULE_DESCRIPTION("OPL4 driver");
110244 MODULE_LICENSE("GPL");
110245
110246 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110247 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110248 {
110249 int timeout = 10;
110250 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110251 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110252 index 9919769..d7de36c 100644
110253 --- a/sound/drivers/opl4/opl4_seq.c
110254 +++ b/sound/drivers/opl4/opl4_seq.c
110255 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110256 static int __init alsa_opl4_synth_init(void)
110257 {
110258 static struct snd_seq_dev_ops ops = {
110259 - snd_opl4_seq_new_device,
110260 - snd_opl4_seq_delete_device
110261 + .init_device = snd_opl4_seq_new_device,
110262 + .free_device = snd_opl4_seq_delete_device
110263 };
110264
110265 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110266 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110267 index 78ccfa4..7a0857b 100644
110268 --- a/sound/drivers/portman2x4.c
110269 +++ b/sound/drivers/portman2x4.c
110270 @@ -48,6 +48,7 @@
110271 #include <sound/initval.h>
110272 #include <sound/rawmidi.h>
110273 #include <sound/control.h>
110274 +#include <asm/local.h>
110275
110276 #define CARD_NAME "Portman 2x4"
110277 #define DRIVER_NAME "portman"
110278 @@ -85,7 +86,7 @@ struct portman {
110279 struct pardevice *pardev;
110280 int pardev_claimed;
110281
110282 - int open_count;
110283 + local_t open_count;
110284 int mode[PORTMAN_NUM_INPUT_PORTS];
110285 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110286 };
110287 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110288 index 95fc2eaf..ea5d6a7 100644
110289 --- a/sound/firewire/amdtp.c
110290 +++ b/sound/firewire/amdtp.c
110291 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110292 ptr = s->pcm_buffer_pointer + frames;
110293 if (ptr >= pcm->runtime->buffer_size)
110294 ptr -= pcm->runtime->buffer_size;
110295 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110296 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110297
110298 s->pcm_period_pointer += frames;
110299 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110300 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110301 */
110302 void amdtp_stream_update(struct amdtp_stream *s)
110303 {
110304 - ACCESS_ONCE(s->source_node_id_field) =
110305 + ACCESS_ONCE_RW(s->source_node_id_field) =
110306 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110307 }
110308 EXPORT_SYMBOL(amdtp_stream_update);
110309 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110310 index 4823c08..47a5f7c 100644
110311 --- a/sound/firewire/amdtp.h
110312 +++ b/sound/firewire/amdtp.h
110313 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110314 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110315 struct snd_pcm_substream *pcm)
110316 {
110317 - ACCESS_ONCE(s->pcm) = pcm;
110318 + ACCESS_ONCE_RW(s->pcm) = pcm;
110319 }
110320
110321 /**
110322 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110323 struct snd_rawmidi_substream *midi)
110324 {
110325 if (port < s->midi_ports)
110326 - ACCESS_ONCE(s->midi[port]) = midi;
110327 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110328 }
110329
110330 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110331 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110332 index 7ac9443..0ec6274 100644
110333 --- a/sound/firewire/isight.c
110334 +++ b/sound/firewire/isight.c
110335 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110336 ptr += count;
110337 if (ptr >= runtime->buffer_size)
110338 ptr -= runtime->buffer_size;
110339 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110340 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110341
110342 isight->period_counter += count;
110343 if (isight->period_counter >= runtime->period_size) {
110344 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110345 if (err < 0)
110346 return err;
110347
110348 - ACCESS_ONCE(isight->pcm_active) = true;
110349 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110350
110351 return 0;
110352 }
110353 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110354 {
110355 struct isight *isight = substream->private_data;
110356
110357 - ACCESS_ONCE(isight->pcm_active) = false;
110358 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110359
110360 mutex_lock(&isight->mutex);
110361 isight_stop_streaming(isight);
110362 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110363
110364 switch (cmd) {
110365 case SNDRV_PCM_TRIGGER_START:
110366 - ACCESS_ONCE(isight->pcm_running) = true;
110367 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110368 break;
110369 case SNDRV_PCM_TRIGGER_STOP:
110370 - ACCESS_ONCE(isight->pcm_running) = false;
110371 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110372 break;
110373 default:
110374 return -EINVAL;
110375 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110376 index 2dba848..c682aef 100644
110377 --- a/sound/firewire/scs1x.c
110378 +++ b/sound/firewire/scs1x.c
110379 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110380 {
110381 struct scs *scs = stream->rmidi->private_data;
110382
110383 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110384 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110385 if (up) {
110386 scs->output_idle = false;
110387 tasklet_schedule(&scs->tasklet);
110388 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110389 {
110390 struct scs *scs = stream->rmidi->private_data;
110391
110392 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110393 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110394 }
110395
110396 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110397 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110398
110399 snd_card_disconnect(scs->card);
110400
110401 - ACCESS_ONCE(scs->output) = NULL;
110402 - ACCESS_ONCE(scs->input) = NULL;
110403 + ACCESS_ONCE_RW(scs->output) = NULL;
110404 + ACCESS_ONCE_RW(scs->input) = NULL;
110405
110406 wait_event(scs->idle_wait, scs->output_idle);
110407
110408 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110409 index 4e3fcfb..ab45a9d 100644
110410 --- a/sound/isa/sb/emu8000_synth.c
110411 +++ b/sound/isa/sb/emu8000_synth.c
110412 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110413 {
110414
110415 static struct snd_seq_dev_ops ops = {
110416 - snd_emu8000_new_device,
110417 - snd_emu8000_delete_device,
110418 + .init_device = snd_emu8000_new_device,
110419 + .free_device = snd_emu8000_delete_device,
110420 };
110421 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110422 sizeof(struct snd_emu8000*));
110423 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110424 index 048439a..3be9f6f 100644
110425 --- a/sound/oss/sb_audio.c
110426 +++ b/sound/oss/sb_audio.c
110427 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110428 buf16 = (signed short *)(localbuf + localoffs);
110429 while (c)
110430 {
110431 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110432 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110433 if (copy_from_user(lbuf8,
110434 userbuf+useroffs + p,
110435 locallen))
110436 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110437 index a33e8ce..2262303 100644
110438 --- a/sound/oss/swarm_cs4297a.c
110439 +++ b/sound/oss/swarm_cs4297a.c
110440 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110441 {
110442 struct cs4297a_state *s;
110443 u32 pwr, id;
110444 - mm_segment_t fs;
110445 int rval;
110446 u64 cfg;
110447 int mdio_val;
110448 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110449 if (!rval) {
110450 char *sb1250_duart_present;
110451
110452 +#if 0
110453 + mm_segment_t fs;
110454 fs = get_fs();
110455 set_fs(KERNEL_DS);
110456 -#if 0
110457 val = SOUND_MASK_LINE;
110458 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110459 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110460 val = initvol[i].vol;
110461 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110462 }
110463 + set_fs(fs);
110464 // cs4297a_write_ac97(s, 0x18, 0x0808);
110465 #else
110466 // cs4297a_write_ac97(s, 0x5e, 0x180);
110467 cs4297a_write_ac97(s, 0x02, 0x0808);
110468 cs4297a_write_ac97(s, 0x18, 0x0808);
110469 #endif
110470 - set_fs(fs);
110471
110472 list_add(&s->list, &cs4297a_devs);
110473
110474 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110475 index 4c41c90..37f3631 100644
110476 --- a/sound/pci/emu10k1/emu10k1_synth.c
110477 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110478 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110479 {
110480
110481 static struct snd_seq_dev_ops ops = {
110482 - snd_emu10k1_synth_new_device,
110483 - snd_emu10k1_synth_delete_device,
110484 + .init_device = snd_emu10k1_synth_new_device,
110485 + .free_device = snd_emu10k1_synth_delete_device,
110486 };
110487 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110488 sizeof(struct snd_emu10k1_synth_arg));
110489 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110490 index e708368..764dffe 100644
110491 --- a/sound/pci/hda/hda_codec.c
110492 +++ b/sound/pci/hda/hda_codec.c
110493 @@ -968,14 +968,10 @@ find_codec_preset(struct hda_codec *codec)
110494 mutex_unlock(&preset_mutex);
110495
110496 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110497 - char name[32];
110498 if (!mod_requested)
110499 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110500 - codec->vendor_id);
110501 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110502 else
110503 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110504 - (codec->vendor_id >> 16) & 0xffff);
110505 - request_module(name);
110506 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110507 mod_requested++;
110508 goto again;
110509 }
110510 @@ -2802,7 +2798,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110511 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110512 mm_segment_t fs = get_fs();
110513 set_fs(get_ds());
110514 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110515 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110516 tlv = _tlv;
110517 set_fs(fs);
110518 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110519 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110520 index 4631a23..001ae57 100644
110521 --- a/sound/pci/ymfpci/ymfpci.h
110522 +++ b/sound/pci/ymfpci/ymfpci.h
110523 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110524 spinlock_t reg_lock;
110525 spinlock_t voice_lock;
110526 wait_queue_head_t interrupt_sleep;
110527 - atomic_t interrupt_sleep_count;
110528 + atomic_unchecked_t interrupt_sleep_count;
110529 struct snd_info_entry *proc_entry;
110530 const struct firmware *dsp_microcode;
110531 const struct firmware *controller_microcode;
110532 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110533 index 81c916a..516f0bf 100644
110534 --- a/sound/pci/ymfpci/ymfpci_main.c
110535 +++ b/sound/pci/ymfpci/ymfpci_main.c
110536 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110537 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110538 break;
110539 }
110540 - if (atomic_read(&chip->interrupt_sleep_count)) {
110541 - atomic_set(&chip->interrupt_sleep_count, 0);
110542 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110543 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110544 wake_up(&chip->interrupt_sleep);
110545 }
110546 __end:
110547 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110548 continue;
110549 init_waitqueue_entry(&wait, current);
110550 add_wait_queue(&chip->interrupt_sleep, &wait);
110551 - atomic_inc(&chip->interrupt_sleep_count);
110552 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110553 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110554 remove_wait_queue(&chip->interrupt_sleep, &wait);
110555 }
110556 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110557 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110558 spin_unlock(&chip->reg_lock);
110559
110560 - if (atomic_read(&chip->interrupt_sleep_count)) {
110561 - atomic_set(&chip->interrupt_sleep_count, 0);
110562 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110563 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110564 wake_up(&chip->interrupt_sleep);
110565 }
110566 }
110567 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110568 spin_lock_init(&chip->reg_lock);
110569 spin_lock_init(&chip->voice_lock);
110570 init_waitqueue_head(&chip->interrupt_sleep);
110571 - atomic_set(&chip->interrupt_sleep_count, 0);
110572 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110573 chip->card = card;
110574 chip->pci = pci;
110575 chip->irq = -1;
110576 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110577 index b60ff56..7307f0f 100644
110578 --- a/sound/soc/soc-core.c
110579 +++ b/sound/soc/soc-core.c
110580 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110581 if (ret)
110582 return ret;
110583
110584 - ops->warm_reset = snd_soc_ac97_warm_reset;
110585 - ops->reset = snd_soc_ac97_reset;
110586 + pax_open_kernel();
110587 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110588 + *(void **)&ops->reset = snd_soc_ac97_reset;
110589 + pax_close_kernel();
110590
110591 snd_ac97_rst_cfg = cfg;
110592 return 0;
110593 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110594 index 7778b8e..3d619fc 100644
110595 --- a/sound/synth/emux/emux_seq.c
110596 +++ b/sound/synth/emux/emux_seq.c
110597 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110598 * MIDI emulation operators
110599 */
110600 static struct snd_midi_op emux_ops = {
110601 - snd_emux_note_on,
110602 - snd_emux_note_off,
110603 - snd_emux_key_press,
110604 - snd_emux_terminate_note,
110605 - snd_emux_control,
110606 - snd_emux_nrpn,
110607 - snd_emux_sysex,
110608 + .note_on = snd_emux_note_on,
110609 + .note_off = snd_emux_note_off,
110610 + .key_press = snd_emux_key_press,
110611 + .note_terminate = snd_emux_terminate_note,
110612 + .control = snd_emux_control,
110613 + .nrpn = snd_emux_nrpn,
110614 + .sysex = snd_emux_sysex,
110615 };
110616
110617
110618 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110619 new file mode 100644
110620 index 0000000..de92ed9
110621 --- /dev/null
110622 +++ b/tools/gcc/.gitignore
110623 @@ -0,0 +1 @@
110624 +randomize_layout_seed.h
110625 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110626 new file mode 100644
110627 index 0000000..7b8921f
110628 --- /dev/null
110629 +++ b/tools/gcc/Makefile
110630 @@ -0,0 +1,52 @@
110631 +#CC := gcc
110632 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110633 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110634 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110635 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110636 +
110637 +ifeq ($(PLUGINCC),$(HOSTCC))
110638 +HOSTLIBS := hostlibs
110639 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110640 +export HOST_EXTRACFLAGS
110641 +else
110642 +HOSTLIBS := hostcxxlibs
110643 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110644 +export HOST_EXTRACXXFLAGS
110645 +endif
110646 +
110647 +export GCCPLUGINS_DIR HOSTLIBS
110648 +
110649 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110650 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110651 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110652 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110653 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110654 +$(HOSTLIBS)-y += colorize_plugin.so
110655 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110656 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110657 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110658 +
110659 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110660 +subdir- += size_overflow_plugin
110661 +
110662 +always := $($(HOSTLIBS)-y)
110663 +
110664 +constify_plugin-objs := constify_plugin.o
110665 +stackleak_plugin-objs := stackleak_plugin.o
110666 +kallocstat_plugin-objs := kallocstat_plugin.o
110667 +kernexec_plugin-objs := kernexec_plugin.o
110668 +checker_plugin-objs := checker_plugin.o
110669 +colorize_plugin-objs := colorize_plugin.o
110670 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110671 +structleak_plugin-objs := structleak_plugin.o
110672 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110673 +
110674 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110675 +
110676 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110677 + cmd_create_randomize_layout_seed = \
110678 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110679 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110680 + $(call if_changed,create_randomize_layout_seed)
110681 +
110682 +targets += randomize_layout_seed.h randomize_layout_hash.h
110683 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110684 new file mode 100644
110685 index 0000000..5452feea
110686 --- /dev/null
110687 +++ b/tools/gcc/checker_plugin.c
110688 @@ -0,0 +1,150 @@
110689 +/*
110690 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110691 + * Licensed under the GPL v2
110692 + *
110693 + * Note: the choice of the license means that the compilation process is
110694 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110695 + * but for the kernel it doesn't matter since it doesn't link against
110696 + * any of the gcc libraries
110697 + *
110698 + * gcc plugin to implement various sparse (source code checker) features
110699 + *
110700 + * TODO:
110701 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110702 + *
110703 + * BUGS:
110704 + * - none known
110705 + */
110706 +
110707 +#include "gcc-common.h"
110708 +
110709 +extern void c_register_addr_space (const char *str, addr_space_t as);
110710 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110711 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110712 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110713 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110714 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110715 +
110716 +int plugin_is_GPL_compatible;
110717 +
110718 +static struct plugin_info checker_plugin_info = {
110719 + .version = "201304082245",
110720 + .help = NULL,
110721 +};
110722 +
110723 +#define ADDR_SPACE_KERNEL 0
110724 +#define ADDR_SPACE_FORCE_KERNEL 1
110725 +#define ADDR_SPACE_USER 2
110726 +#define ADDR_SPACE_FORCE_USER 3
110727 +#define ADDR_SPACE_IOMEM 0
110728 +#define ADDR_SPACE_FORCE_IOMEM 0
110729 +#define ADDR_SPACE_PERCPU 0
110730 +#define ADDR_SPACE_FORCE_PERCPU 0
110731 +#define ADDR_SPACE_RCU 0
110732 +#define ADDR_SPACE_FORCE_RCU 0
110733 +
110734 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110735 +{
110736 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110737 +}
110738 +
110739 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110740 +{
110741 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110742 +}
110743 +
110744 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110745 +{
110746 + return default_addr_space_valid_pointer_mode(mode, as);
110747 +}
110748 +
110749 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110750 +{
110751 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110752 +}
110753 +
110754 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110755 +{
110756 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110757 +}
110758 +
110759 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110760 +{
110761 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110762 + return true;
110763 +
110764 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110765 + return true;
110766 +
110767 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110768 + return true;
110769 +
110770 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110771 + return true;
110772 +
110773 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110774 + return true;
110775 +
110776 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110777 + return true;
110778 +
110779 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110780 + return true;
110781 +
110782 + return subset == superset;
110783 +}
110784 +
110785 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110786 +{
110787 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110788 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110789 +
110790 + return op;
110791 +}
110792 +
110793 +static void register_checker_address_spaces(void *event_data, void *data)
110794 +{
110795 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110796 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110797 + c_register_addr_space("__user", ADDR_SPACE_USER);
110798 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110799 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110800 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110801 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110802 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110803 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110804 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110805 +
110806 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110807 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110808 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110809 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110810 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110811 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110812 + targetm.addr_space.convert = checker_addr_space_convert;
110813 +}
110814 +
110815 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110816 +{
110817 + const char * const plugin_name = plugin_info->base_name;
110818 + const int argc = plugin_info->argc;
110819 + const struct plugin_argument * const argv = plugin_info->argv;
110820 + int i;
110821 +
110822 + if (!plugin_default_version_check(version, &gcc_version)) {
110823 + error(G_("incompatible gcc/plugin versions"));
110824 + return 1;
110825 + }
110826 +
110827 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110828 +
110829 + for (i = 0; i < argc; ++i)
110830 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110831 +
110832 + if (TARGET_64BIT == 0)
110833 + return 0;
110834 +
110835 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110836 +
110837 + return 0;
110838 +}
110839 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110840 new file mode 100644
110841 index 0000000..54461af
110842 --- /dev/null
110843 +++ b/tools/gcc/colorize_plugin.c
110844 @@ -0,0 +1,210 @@
110845 +/*
110846 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110847 + * Licensed under the GPL v2
110848 + *
110849 + * Note: the choice of the license means that the compilation process is
110850 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110851 + * but for the kernel it doesn't matter since it doesn't link against
110852 + * any of the gcc libraries
110853 + *
110854 + * gcc plugin to colorize diagnostic output
110855 + *
110856 + */
110857 +
110858 +#include "gcc-common.h"
110859 +
110860 +int plugin_is_GPL_compatible;
110861 +
110862 +static struct plugin_info colorize_plugin_info = {
110863 + .version = "201404202350",
110864 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110865 +};
110866 +
110867 +#define GREEN "\033[32m\033[K"
110868 +#define LIGHTGREEN "\033[1;32m\033[K"
110869 +#define YELLOW "\033[33m\033[K"
110870 +#define LIGHTYELLOW "\033[1;33m\033[K"
110871 +#define RED "\033[31m\033[K"
110872 +#define LIGHTRED "\033[1;31m\033[K"
110873 +#define BLUE "\033[34m\033[K"
110874 +#define LIGHTBLUE "\033[1;34m\033[K"
110875 +#define BRIGHT "\033[1;m\033[K"
110876 +#define NORMAL "\033[m\033[K"
110877 +
110878 +static diagnostic_starter_fn old_starter;
110879 +static diagnostic_finalizer_fn old_finalizer;
110880 +
110881 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110882 +{
110883 + const char *color;
110884 + char *newprefix;
110885 +
110886 + switch (diagnostic->kind) {
110887 + case DK_NOTE:
110888 + color = LIGHTBLUE;
110889 + break;
110890 +
110891 + case DK_PEDWARN:
110892 + case DK_WARNING:
110893 + color = LIGHTYELLOW;
110894 + break;
110895 +
110896 + case DK_ERROR:
110897 + case DK_FATAL:
110898 + case DK_ICE:
110899 + case DK_PERMERROR:
110900 + case DK_SORRY:
110901 + color = LIGHTRED;
110902 + break;
110903 +
110904 + default:
110905 + color = NORMAL;
110906 + }
110907 +
110908 + old_starter(context, diagnostic);
110909 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110910 + return;
110911 + pp_destroy_prefix(context->printer);
110912 + pp_set_prefix(context->printer, newprefix);
110913 +}
110914 +
110915 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110916 +{
110917 + old_finalizer(context, diagnostic);
110918 +}
110919 +
110920 +static void colorize_arm(void)
110921 +{
110922 + old_starter = diagnostic_starter(global_dc);
110923 + old_finalizer = diagnostic_finalizer(global_dc);
110924 +
110925 + diagnostic_starter(global_dc) = start_colorize;
110926 + diagnostic_finalizer(global_dc) = finalize_colorize;
110927 +}
110928 +
110929 +static unsigned int execute_colorize_rearm(void)
110930 +{
110931 + if (diagnostic_starter(global_dc) == start_colorize)
110932 + return 0;
110933 +
110934 + colorize_arm();
110935 + return 0;
110936 +}
110937 +
110938 +#if BUILDING_GCC_VERSION >= 4009
110939 +static const struct pass_data colorize_rearm_pass_data = {
110940 +#else
110941 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110942 + .pass = {
110943 +#endif
110944 + .type = SIMPLE_IPA_PASS,
110945 + .name = "colorize_rearm",
110946 +#if BUILDING_GCC_VERSION >= 4008
110947 + .optinfo_flags = OPTGROUP_NONE,
110948 +#endif
110949 +#if BUILDING_GCC_VERSION >= 4009
110950 + .has_gate = false,
110951 + .has_execute = true,
110952 +#else
110953 + .gate = NULL,
110954 + .execute = execute_colorize_rearm,
110955 + .sub = NULL,
110956 + .next = NULL,
110957 + .static_pass_number = 0,
110958 +#endif
110959 + .tv_id = TV_NONE,
110960 + .properties_required = 0,
110961 + .properties_provided = 0,
110962 + .properties_destroyed = 0,
110963 + .todo_flags_start = 0,
110964 + .todo_flags_finish = 0
110965 +#if BUILDING_GCC_VERSION < 4009
110966 + }
110967 +#endif
110968 +};
110969 +
110970 +#if BUILDING_GCC_VERSION >= 4009
110971 +namespace {
110972 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110973 +public:
110974 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110975 + unsigned int execute() { return execute_colorize_rearm(); }
110976 +};
110977 +}
110978 +
110979 +static opt_pass *make_colorize_rearm_pass(void)
110980 +{
110981 + return new colorize_rearm_pass();
110982 +}
110983 +#else
110984 +static struct opt_pass *make_colorize_rearm_pass(void)
110985 +{
110986 + return &colorize_rearm_pass.pass;
110987 +}
110988 +#endif
110989 +
110990 +static void colorize_start_unit(void *gcc_data, void *user_data)
110991 +{
110992 + colorize_arm();
110993 +}
110994 +
110995 +static bool should_colorize(void)
110996 +{
110997 +#if BUILDING_GCC_VERSION >= 4009
110998 + return false;
110999 +#else
111000 + char const *t = getenv("TERM");
111001 +
111002 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
111003 +#endif
111004 +}
111005 +
111006 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111007 +{
111008 + const char * const plugin_name = plugin_info->base_name;
111009 + const int argc = plugin_info->argc;
111010 + const struct plugin_argument * const argv = plugin_info->argv;
111011 + int i;
111012 + struct register_pass_info colorize_rearm_pass_info;
111013 + bool colorize;
111014 +
111015 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
111016 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
111017 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
111018 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111019 +
111020 + if (!plugin_default_version_check(version, &gcc_version)) {
111021 + error(G_("incompatible gcc/plugin versions"));
111022 + return 1;
111023 + }
111024 +
111025 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
111026 +
111027 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
111028 +
111029 + for (i = 0; i < argc; ++i) {
111030 + if (!strcmp(argv[i].key, "color")) {
111031 + if (!argv[i].value) {
111032 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111033 + continue;
111034 + }
111035 + if (!strcmp(argv[i].value, "always"))
111036 + colorize = true;
111037 + else if (!strcmp(argv[i].value, "never"))
111038 + colorize = false;
111039 + else if (!strcmp(argv[i].value, "auto"))
111040 + colorize = should_colorize();
111041 + else
111042 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111043 + continue;
111044 + }
111045 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111046 + }
111047 +
111048 + if (colorize) {
111049 + // TODO: parse GCC_COLORS as used by gcc 4.9+
111050 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
111051 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
111052 + }
111053 + return 0;
111054 +}
111055 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
111056 new file mode 100644
111057 index 0000000..3b5af59
111058 --- /dev/null
111059 +++ b/tools/gcc/constify_plugin.c
111060 @@ -0,0 +1,558 @@
111061 +/*
111062 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
111063 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
111064 + * Licensed under the GPL v2, or (at your option) v3
111065 + *
111066 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
111067 + *
111068 + * Homepage:
111069 + * http://www.grsecurity.net/~ephox/const_plugin/
111070 + *
111071 + * Usage:
111072 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
111073 + * $ gcc -fplugin=constify_plugin.so test.c -O2
111074 + */
111075 +
111076 +#include "gcc-common.h"
111077 +
111078 +// unused C type flag in all versions 4.5-4.9
111079 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
111080 +
111081 +int plugin_is_GPL_compatible;
111082 +
111083 +static struct plugin_info const_plugin_info = {
111084 + .version = "201401270210",
111085 + .help = "no-constify\tturn off constification\n",
111086 +};
111087 +
111088 +typedef struct {
111089 + bool has_fptr_field;
111090 + bool has_writable_field;
111091 + bool has_do_const_field;
111092 + bool has_no_const_field;
111093 +} constify_info;
111094 +
111095 +static const_tree get_field_type(const_tree field)
111096 +{
111097 + return strip_array_types(TREE_TYPE(field));
111098 +}
111099 +
111100 +static bool is_fptr(const_tree field)
111101 +{
111102 + const_tree ptr = get_field_type(field);
111103 +
111104 + if (TREE_CODE(ptr) != POINTER_TYPE)
111105 + return false;
111106 +
111107 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
111108 +}
111109 +
111110 +/*
111111 + * determine whether the given structure type meets the requirements for automatic constification,
111112 + * including the constification attributes on nested structure types
111113 + */
111114 +static void constifiable(const_tree node, constify_info *cinfo)
111115 +{
111116 + const_tree field;
111117 +
111118 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111119 +
111120 + // e.g., pointer to structure fields while still constructing the structure type
111121 + if (TYPE_FIELDS(node) == NULL_TREE)
111122 + return;
111123 +
111124 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111125 + const_tree type = get_field_type(field);
111126 + enum tree_code code = TREE_CODE(type);
111127 +
111128 + if (node == type)
111129 + continue;
111130 +
111131 + if (is_fptr(field))
111132 + cinfo->has_fptr_field = true;
111133 + else if (!TREE_READONLY(field))
111134 + cinfo->has_writable_field = true;
111135 +
111136 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111137 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111138 + cinfo->has_do_const_field = true;
111139 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111140 + cinfo->has_no_const_field = true;
111141 + else
111142 + constifiable(type, cinfo);
111143 + }
111144 + }
111145 +}
111146 +
111147 +static bool constified(const_tree node)
111148 +{
111149 + constify_info cinfo = {
111150 + .has_fptr_field = false,
111151 + .has_writable_field = false,
111152 + .has_do_const_field = false,
111153 + .has_no_const_field = false
111154 + };
111155 +
111156 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111157 +
111158 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111159 +// gcc_assert(!TYPE_READONLY(node));
111160 + return false;
111161 + }
111162 +
111163 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111164 + gcc_assert(TYPE_READONLY(node));
111165 + return true;
111166 + }
111167 +
111168 + constifiable(node, &cinfo);
111169 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111170 + return false;
111171 +
111172 + return TYPE_READONLY(node);
111173 +}
111174 +
111175 +static void deconstify_tree(tree node);
111176 +
111177 +static void deconstify_type(tree type)
111178 +{
111179 + tree field;
111180 +
111181 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111182 +
111183 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111184 + const_tree fieldtype = get_field_type(field);
111185 +
111186 + // special case handling of simple ptr-to-same-array-type members
111187 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111188 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111189 +
111190 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111191 + continue;
111192 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111193 + continue;
111194 + if (!constified(ptrtype))
111195 + continue;
111196 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111197 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111198 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111199 + }
111200 + continue;
111201 + }
111202 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111203 + continue;
111204 + if (!constified(fieldtype))
111205 + continue;
111206 +
111207 + deconstify_tree(field);
111208 + TREE_READONLY(field) = 0;
111209 + }
111210 + TYPE_READONLY(type) = 0;
111211 + C_TYPE_FIELDS_READONLY(type) = 0;
111212 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111213 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111214 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111215 + }
111216 +}
111217 +
111218 +static void deconstify_tree(tree node)
111219 +{
111220 + tree old_type, new_type, field;
111221 +
111222 + old_type = TREE_TYPE(node);
111223 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111224 + node = TREE_TYPE(node) = copy_node(old_type);
111225 + old_type = TREE_TYPE(old_type);
111226 + }
111227 +
111228 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111229 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111230 +
111231 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111232 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111233 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111234 + DECL_FIELD_CONTEXT(field) = new_type;
111235 +
111236 + deconstify_type(new_type);
111237 +
111238 + TREE_TYPE(node) = new_type;
111239 +}
111240 +
111241 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111242 +{
111243 + tree type;
111244 + constify_info cinfo = {
111245 + .has_fptr_field = false,
111246 + .has_writable_field = false,
111247 + .has_do_const_field = false,
111248 + .has_no_const_field = false
111249 + };
111250 +
111251 + *no_add_attrs = true;
111252 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111253 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111254 + return NULL_TREE;
111255 + }
111256 +
111257 + if (TREE_CODE(*node) == PARM_DECL) {
111258 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111259 + return NULL_TREE;
111260 + }
111261 +
111262 + if (TREE_CODE(*node) == VAR_DECL) {
111263 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111264 + return NULL_TREE;
111265 + }
111266 +
111267 + if (TYPE_P(*node)) {
111268 + type = *node;
111269 + } else {
111270 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111271 + type = TREE_TYPE(*node);
111272 + }
111273 +
111274 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111275 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111276 + return NULL_TREE;
111277 + }
111278 +
111279 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111280 + error("%qE attribute is already applied to the type %qT", name, type);
111281 + return NULL_TREE;
111282 + }
111283 +
111284 + if (TYPE_P(*node)) {
111285 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111286 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111287 + else
111288 + *no_add_attrs = false;
111289 + return NULL_TREE;
111290 + }
111291 +
111292 + constifiable(type, &cinfo);
111293 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111294 + deconstify_tree(*node);
111295 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111296 + return NULL_TREE;
111297 + }
111298 +
111299 + error("%qE attribute used on type %qT that is not constified", name, type);
111300 + return NULL_TREE;
111301 +}
111302 +
111303 +static void constify_type(tree type)
111304 +{
111305 + TYPE_READONLY(type) = 1;
111306 + C_TYPE_FIELDS_READONLY(type) = 1;
111307 + TYPE_CONSTIFY_VISITED(type) = 1;
111308 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111309 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111310 +}
111311 +
111312 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111313 +{
111314 + *no_add_attrs = true;
111315 + if (!TYPE_P(*node)) {
111316 + error("%qE attribute applies to types only (%qD)", name, *node);
111317 + return NULL_TREE;
111318 + }
111319 +
111320 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111321 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111322 + return NULL_TREE;
111323 + }
111324 +
111325 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111326 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111327 + return NULL_TREE;
111328 + }
111329 +
111330 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111331 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111332 + return NULL_TREE;
111333 + }
111334 +
111335 + *no_add_attrs = false;
111336 + return NULL_TREE;
111337 +}
111338 +
111339 +static struct attribute_spec no_const_attr = {
111340 + .name = "no_const",
111341 + .min_length = 0,
111342 + .max_length = 0,
111343 + .decl_required = false,
111344 + .type_required = false,
111345 + .function_type_required = false,
111346 + .handler = handle_no_const_attribute,
111347 +#if BUILDING_GCC_VERSION >= 4007
111348 + .affects_type_identity = true
111349 +#endif
111350 +};
111351 +
111352 +static struct attribute_spec do_const_attr = {
111353 + .name = "do_const",
111354 + .min_length = 0,
111355 + .max_length = 0,
111356 + .decl_required = false,
111357 + .type_required = false,
111358 + .function_type_required = false,
111359 + .handler = handle_do_const_attribute,
111360 +#if BUILDING_GCC_VERSION >= 4007
111361 + .affects_type_identity = true
111362 +#endif
111363 +};
111364 +
111365 +static void register_attributes(void *event_data, void *data)
111366 +{
111367 + register_attribute(&no_const_attr);
111368 + register_attribute(&do_const_attr);
111369 +}
111370 +
111371 +static void finish_type(void *event_data, void *data)
111372 +{
111373 + tree type = (tree)event_data;
111374 + constify_info cinfo = {
111375 + .has_fptr_field = false,
111376 + .has_writable_field = false,
111377 + .has_do_const_field = false,
111378 + .has_no_const_field = false
111379 + };
111380 +
111381 + if (type == NULL_TREE || type == error_mark_node)
111382 + return;
111383 +
111384 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111385 + return;
111386 +
111387 + constifiable(type, &cinfo);
111388 +
111389 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111390 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111391 + deconstify_type(type);
111392 + TYPE_CONSTIFY_VISITED(type) = 1;
111393 + } else
111394 + error("'no_const' attribute used on type %qT that is not constified", type);
111395 + return;
111396 + }
111397 +
111398 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111399 + if (!cinfo.has_writable_field) {
111400 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111401 + return;
111402 + }
111403 + constify_type(type);
111404 + return;
111405 + }
111406 +
111407 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111408 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111409 + error("'do_const' attribute used on type %qT that is constified", type);
111410 + return;
111411 + }
111412 + constify_type(type);
111413 + return;
111414 + }
111415 +
111416 + deconstify_type(type);
111417 + TYPE_CONSTIFY_VISITED(type) = 1;
111418 +}
111419 +
111420 +static void check_global_variables(void *event_data, void *data)
111421 +{
111422 +#if BUILDING_GCC_VERSION >= 4009
111423 + varpool_node *node;
111424 +#else
111425 + struct varpool_node *node;
111426 +#endif
111427 +
111428 + FOR_EACH_VARIABLE(node) {
111429 + tree var = NODE_DECL(node);
111430 + tree type = TREE_TYPE(var);
111431 +
111432 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111433 + continue;
111434 +
111435 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111436 + continue;
111437 +
111438 + if (!TYPE_CONSTIFY_VISITED(type))
111439 + continue;
111440 +
111441 + if (DECL_EXTERNAL(var))
111442 + continue;
111443 +
111444 + if (DECL_INITIAL(var))
111445 + continue;
111446 +
111447 + // this works around a gcc bug/feature where uninitialized globals
111448 + // are moved into the .bss section regardless of any constification
111449 + DECL_INITIAL(var) = build_constructor(type, NULL);
111450 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111451 + }
111452 +}
111453 +
111454 +static unsigned int check_local_variables(void)
111455 +{
111456 + unsigned int ret = 0;
111457 + tree var;
111458 +
111459 + unsigned int i;
111460 +
111461 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111462 + tree type = TREE_TYPE(var);
111463 +
111464 + gcc_assert(DECL_P(var));
111465 + if (is_global_var(var))
111466 + continue;
111467 +
111468 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111469 + continue;
111470 +
111471 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111472 + continue;
111473 +
111474 + if (!TYPE_CONSTIFY_VISITED(type))
111475 + continue;
111476 +
111477 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111478 + ret = 1;
111479 + }
111480 + return ret;
111481 +}
111482 +
111483 +#if BUILDING_GCC_VERSION >= 4009
111484 +static const struct pass_data check_local_variables_pass_data = {
111485 +#else
111486 +static struct gimple_opt_pass check_local_variables_pass = {
111487 + .pass = {
111488 +#endif
111489 + .type = GIMPLE_PASS,
111490 + .name = "check_local_variables",
111491 +#if BUILDING_GCC_VERSION >= 4008
111492 + .optinfo_flags = OPTGROUP_NONE,
111493 +#endif
111494 +#if BUILDING_GCC_VERSION >= 5000
111495 +#elif BUILDING_GCC_VERSION >= 4009
111496 + .has_gate = false,
111497 + .has_execute = true,
111498 +#else
111499 + .gate = NULL,
111500 + .execute = check_local_variables,
111501 + .sub = NULL,
111502 + .next = NULL,
111503 + .static_pass_number = 0,
111504 +#endif
111505 + .tv_id = TV_NONE,
111506 + .properties_required = 0,
111507 + .properties_provided = 0,
111508 + .properties_destroyed = 0,
111509 + .todo_flags_start = 0,
111510 + .todo_flags_finish = 0
111511 +#if BUILDING_GCC_VERSION < 4009
111512 + }
111513 +#endif
111514 +};
111515 +
111516 +#if BUILDING_GCC_VERSION >= 4009
111517 +namespace {
111518 +class check_local_variables_pass : public gimple_opt_pass {
111519 +public:
111520 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111521 + unsigned int execute() { return check_local_variables(); }
111522 +};
111523 +}
111524 +
111525 +static opt_pass *make_check_local_variables_pass(void)
111526 +{
111527 + return new check_local_variables_pass();
111528 +}
111529 +#else
111530 +static struct opt_pass *make_check_local_variables_pass(void)
111531 +{
111532 + return &check_local_variables_pass.pass;
111533 +}
111534 +#endif
111535 +
111536 +static struct {
111537 + const char *name;
111538 + const char *asm_op;
111539 +} sections[] = {
111540 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111541 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111542 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111543 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111544 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111545 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111546 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111547 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111548 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111549 +};
111550 +
111551 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111552 +
111553 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111554 +{
111555 + size_t i;
111556 +
111557 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111558 + if (!strcmp(sections[i].name, name))
111559 + return 0;
111560 + return old_section_type_flags(decl, name, reloc);
111561 +}
111562 +
111563 +static void constify_start_unit(void *gcc_data, void *user_data)
111564 +{
111565 +// size_t i;
111566 +
111567 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111568 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111569 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111570 +
111571 + old_section_type_flags = targetm.section_type_flags;
111572 + targetm.section_type_flags = constify_section_type_flags;
111573 +}
111574 +
111575 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111576 +{
111577 + const char * const plugin_name = plugin_info->base_name;
111578 + const int argc = plugin_info->argc;
111579 + const struct plugin_argument * const argv = plugin_info->argv;
111580 + int i;
111581 + bool constify = true;
111582 +
111583 + struct register_pass_info check_local_variables_pass_info;
111584 +
111585 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111586 + check_local_variables_pass_info.reference_pass_name = "ssa";
111587 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111588 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111589 +
111590 + if (!plugin_default_version_check(version, &gcc_version)) {
111591 + error(G_("incompatible gcc/plugin versions"));
111592 + return 1;
111593 + }
111594 +
111595 + for (i = 0; i < argc; ++i) {
111596 + if (!(strcmp(argv[i].key, "no-constify"))) {
111597 + constify = false;
111598 + continue;
111599 + }
111600 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111601 + }
111602 +
111603 + if (strncmp(lang_hooks.name, "GNU C", 5) && !strncmp(lang_hooks.name, "GNU C+", 6)) {
111604 + inform(UNKNOWN_LOCATION, G_("%s supports C only, not %s"), plugin_name, lang_hooks.name);
111605 + constify = false;
111606 + }
111607 +
111608 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111609 + if (constify) {
111610 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111611 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111612 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111613 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111614 + }
111615 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111616 +
111617 + return 0;
111618 +}
111619 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111620 new file mode 100644
111621 index 0000000..e90c205
111622 --- /dev/null
111623 +++ b/tools/gcc/gcc-common.h
111624 @@ -0,0 +1,295 @@
111625 +#ifndef GCC_COMMON_H_INCLUDED
111626 +#define GCC_COMMON_H_INCLUDED
111627 +
111628 +#include "plugin.h"
111629 +#include "bversion.h"
111630 +#include "plugin-version.h"
111631 +#include "config.h"
111632 +#include "system.h"
111633 +#include "coretypes.h"
111634 +#include "tm.h"
111635 +#include "line-map.h"
111636 +#include "input.h"
111637 +#include "tree.h"
111638 +
111639 +#include "tree-inline.h"
111640 +#include "version.h"
111641 +#include "rtl.h"
111642 +#include "tm_p.h"
111643 +#include "flags.h"
111644 +//#include "insn-attr.h"
111645 +//#include "insn-config.h"
111646 +//#include "insn-flags.h"
111647 +#include "hard-reg-set.h"
111648 +//#include "recog.h"
111649 +#include "output.h"
111650 +#include "except.h"
111651 +#include "function.h"
111652 +#include "toplev.h"
111653 +//#include "expr.h"
111654 +#include "basic-block.h"
111655 +#include "intl.h"
111656 +#include "ggc.h"
111657 +//#include "regs.h"
111658 +#include "timevar.h"
111659 +
111660 +#include "params.h"
111661 +#include "pointer-set.h"
111662 +#include "emit-rtl.h"
111663 +//#include "reload.h"
111664 +//#include "ira.h"
111665 +//#include "dwarf2asm.h"
111666 +#include "debug.h"
111667 +#include "target.h"
111668 +#include "langhooks.h"
111669 +#include "cfgloop.h"
111670 +//#include "hosthooks.h"
111671 +#include "cgraph.h"
111672 +#include "opts.h"
111673 +//#include "coverage.h"
111674 +//#include "value-prof.h"
111675 +
111676 +#if BUILDING_GCC_VERSION >= 4007
111677 +#include "tree-pretty-print.h"
111678 +#include "gimple-pretty-print.h"
111679 +#include "c-tree.h"
111680 +//#include "alloc-pool.h"
111681 +#endif
111682 +
111683 +#if BUILDING_GCC_VERSION <= 4008
111684 +#include "tree-flow.h"
111685 +#else
111686 +#include "tree-cfgcleanup.h"
111687 +#endif
111688 +
111689 +#include "diagnostic.h"
111690 +//#include "tree-diagnostic.h"
111691 +#include "tree-dump.h"
111692 +#include "tree-pass.h"
111693 +//#include "df.h"
111694 +#include "predict.h"
111695 +#include "ipa-utils.h"
111696 +
111697 +#if BUILDING_GCC_VERSION >= 4009
111698 +#include "varasm.h"
111699 +#include "stor-layout.h"
111700 +#include "internal-fn.h"
111701 +#include "gimple-expr.h"
111702 +//#include "diagnostic-color.h"
111703 +#include "context.h"
111704 +#include "tree-ssa-alias.h"
111705 +#include "stringpool.h"
111706 +#include "tree-ssanames.h"
111707 +#include "print-tree.h"
111708 +#include "tree-eh.h"
111709 +#include "stmt.h"
111710 +#endif
111711 +
111712 +#include "gimple.h"
111713 +
111714 +#if BUILDING_GCC_VERSION >= 4009
111715 +#include "tree-ssa-operands.h"
111716 +#include "tree-phinodes.h"
111717 +#include "tree-cfg.h"
111718 +#include "gimple-iterator.h"
111719 +#include "gimple-ssa.h"
111720 +#include "ssa-iterators.h"
111721 +#endif
111722 +
111723 +//#include "lto/lto.h"
111724 +//#include "data-streamer.h"
111725 +//#include "lto-compress.h"
111726 +
111727 +//#include "expr.h" where are you...
111728 +extern rtx emit_move_insn(rtx x, rtx y);
111729 +
111730 +// missing from basic_block.h...
111731 +extern void debug_dominance_info(enum cdi_direction dir);
111732 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111733 +
111734 +#define __unused __attribute__((__unused__))
111735 +
111736 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111737 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111738 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111739 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111740 +
111741 +#if BUILDING_GCC_VERSION == 4005
111742 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111743 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111744 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111745 +#define TODO_rebuild_cgraph_edges 0
111746 +
111747 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111748 +{
111749 + tree fndecl;
111750 +
111751 + if (!is_gimple_call(stmt))
111752 + return false;
111753 + fndecl = gimple_call_fndecl(stmt);
111754 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111755 + return false;
111756 +// print_node(stderr, "pax", fndecl, 4);
111757 + return DECL_FUNCTION_CODE(fndecl) == code;
111758 +}
111759 +
111760 +static inline bool is_simple_builtin(tree decl)
111761 +{
111762 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111763 + return false;
111764 +
111765 + switch (DECL_FUNCTION_CODE(decl)) {
111766 + /* Builtins that expand to constants. */
111767 + case BUILT_IN_CONSTANT_P:
111768 + case BUILT_IN_EXPECT:
111769 + case BUILT_IN_OBJECT_SIZE:
111770 + case BUILT_IN_UNREACHABLE:
111771 + /* Simple register moves or loads from stack. */
111772 + case BUILT_IN_RETURN_ADDRESS:
111773 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111774 + case BUILT_IN_FROB_RETURN_ADDR:
111775 + case BUILT_IN_RETURN:
111776 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111777 + case BUILT_IN_FRAME_ADDRESS:
111778 + case BUILT_IN_VA_END:
111779 + case BUILT_IN_STACK_SAVE:
111780 + case BUILT_IN_STACK_RESTORE:
111781 + /* Exception state returns or moves registers around. */
111782 + case BUILT_IN_EH_FILTER:
111783 + case BUILT_IN_EH_POINTER:
111784 + case BUILT_IN_EH_COPY_VALUES:
111785 + return true;
111786 +
111787 + default:
111788 + return false;
111789 + }
111790 +}
111791 +#endif
111792 +
111793 +#if BUILDING_GCC_VERSION <= 4006
111794 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111795 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111796 +
111797 +// should come from c-tree.h if only it were installed for gcc 4.5...
111798 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111799 +
111800 +#define get_random_seed(noinit) ({ \
111801 + unsigned HOST_WIDE_INT seed; \
111802 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111803 + seed * seed; })
111804 +
111805 +static inline bool gimple_clobber_p(gimple s)
111806 +{
111807 + return false;
111808 +}
111809 +
111810 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111811 +{
111812 + return implicit_built_in_decls[fncode];
111813 +}
111814 +
111815 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111816 +{
111817 + struct cgraph_node *node = cgraph_get_node(decl);
111818 +
111819 + return node ? node : cgraph_node(decl);
111820 +}
111821 +
111822 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111823 +{
111824 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111825 +}
111826 +
111827 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111828 +{
111829 + struct cgraph_node *node;
111830 +
111831 + for (node = cgraph_nodes; node; node = node->next)
111832 + if (cgraph_function_with_gimple_body_p(node))
111833 + return node;
111834 + return NULL;
111835 +}
111836 +
111837 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111838 +{
111839 + for (node = node->next; node; node = node->next)
111840 + if (cgraph_function_with_gimple_body_p(node))
111841 + return node;
111842 + return NULL;
111843 +}
111844 +
111845 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111846 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111847 + (node) = cgraph_next_function_with_gimple_body(node))
111848 +#endif
111849 +
111850 +#if BUILDING_GCC_VERSION == 4006
111851 +extern void debug_gimple_stmt(gimple);
111852 +extern void debug_gimple_seq(gimple_seq);
111853 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111854 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111855 +extern void print_gimple_expr(FILE *, gimple, int, int);
111856 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111857 +#endif
111858 +
111859 +#if BUILDING_GCC_VERSION <= 4007
111860 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111861 +#define PROP_loops 0
111862 +
111863 +static inline int bb_loop_depth(const_basic_block bb)
111864 +{
111865 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111866 +}
111867 +
111868 +static inline bool gimple_store_p(gimple gs)
111869 +{
111870 + tree lhs = gimple_get_lhs(gs);
111871 + return lhs && !is_gimple_reg(lhs);
111872 +}
111873 +#endif
111874 +
111875 +#if BUILDING_GCC_VERSION >= 4007
111876 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111877 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111878 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111879 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111880 +#endif
111881 +
111882 +#if BUILDING_GCC_VERSION <= 4008
111883 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111884 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111885 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111886 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111887 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111888 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111889 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111890 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111891 +
111892 +static inline const char *get_tree_code_name(enum tree_code code)
111893 +{
111894 + gcc_assert(code < MAX_TREE_CODES);
111895 + return tree_code_name[code];
111896 +}
111897 +
111898 +#define ipa_remove_stmt_references(cnode, stmt)
111899 +#endif
111900 +
111901 +#if BUILDING_GCC_VERSION == 4008
111902 +#define NODE_DECL(node) node->symbol.decl
111903 +#else
111904 +#define NODE_DECL(node) node->decl
111905 +#endif
111906 +
111907 +#if BUILDING_GCC_VERSION >= 4008
111908 +#define add_referenced_var(var)
111909 +#define mark_sym_for_renaming(var)
111910 +#define varpool_mark_needed_node(node)
111911 +#define TODO_dump_func 0
111912 +#define TODO_dump_cgraph 0
111913 +#endif
111914 +
111915 +#if BUILDING_GCC_VERSION >= 4009
111916 +#define TODO_ggc_collect 0
111917 +#endif
111918 +
111919 +#endif
111920 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111921 new file mode 100644
111922 index 0000000..7514850
111923 --- /dev/null
111924 +++ b/tools/gcc/gen-random-seed.sh
111925 @@ -0,0 +1,8 @@
111926 +#!/bin/sh
111927 +
111928 +if [ ! -f "$1" ]; then
111929 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111930 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111931 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111932 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111933 +fi
111934 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111935 new file mode 100644
111936 index 0000000..d81c094
111937 --- /dev/null
111938 +++ b/tools/gcc/kallocstat_plugin.c
111939 @@ -0,0 +1,183 @@
111940 +/*
111941 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111942 + * Licensed under the GPL v2
111943 + *
111944 + * Note: the choice of the license means that the compilation process is
111945 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111946 + * but for the kernel it doesn't matter since it doesn't link against
111947 + * any of the gcc libraries
111948 + *
111949 + * gcc plugin to find the distribution of k*alloc sizes
111950 + *
111951 + * TODO:
111952 + *
111953 + * BUGS:
111954 + * - none known
111955 + */
111956 +
111957 +#include "gcc-common.h"
111958 +
111959 +int plugin_is_GPL_compatible;
111960 +
111961 +static struct plugin_info kallocstat_plugin_info = {
111962 + .version = "201401260140",
111963 + .help = NULL
111964 +};
111965 +
111966 +static const char * const kalloc_functions[] = {
111967 + "__kmalloc",
111968 + "kmalloc",
111969 + "kmalloc_large",
111970 + "kmalloc_node",
111971 + "kmalloc_order",
111972 + "kmalloc_order_trace",
111973 + "kmalloc_slab",
111974 + "kzalloc",
111975 + "kzalloc_node",
111976 +};
111977 +
111978 +static bool is_kalloc(const char *fnname)
111979 +{
111980 + size_t i;
111981 +
111982 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111983 + if (!strcmp(fnname, kalloc_functions[i]))
111984 + return true;
111985 + return false;
111986 +}
111987 +
111988 +static unsigned int execute_kallocstat(void)
111989 +{
111990 + basic_block bb;
111991 +
111992 + // 1. loop through BBs and GIMPLE statements
111993 + FOR_EACH_BB_FN(bb, cfun) {
111994 + gimple_stmt_iterator gsi;
111995 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111996 + // gimple match:
111997 + tree fndecl, size;
111998 + gimple stmt;
111999 + const char *fnname;
112000 +
112001 + // is it a call
112002 + stmt = gsi_stmt(gsi);
112003 + if (!is_gimple_call(stmt))
112004 + continue;
112005 + fndecl = gimple_call_fndecl(stmt);
112006 + if (fndecl == NULL_TREE)
112007 + continue;
112008 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
112009 + continue;
112010 +
112011 + // is it a call to k*alloc
112012 + fnname = DECL_NAME_POINTER(fndecl);
112013 + if (!is_kalloc(fnname))
112014 + continue;
112015 +
112016 + // is the size arg const or the result of a simple const assignment
112017 + size = gimple_call_arg(stmt, 0);
112018 + while (true) {
112019 + expanded_location xloc;
112020 + size_t size_val;
112021 +
112022 + if (TREE_CONSTANT(size)) {
112023 + xloc = expand_location(gimple_location(stmt));
112024 + if (!xloc.file)
112025 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112026 + size_val = TREE_INT_CST_LOW(size);
112027 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
112028 + break;
112029 + }
112030 +
112031 + if (TREE_CODE(size) != SSA_NAME)
112032 + break;
112033 + stmt = SSA_NAME_DEF_STMT(size);
112034 +//debug_gimple_stmt(stmt);
112035 +//debug_tree(size);
112036 + if (!stmt || !is_gimple_assign(stmt))
112037 + break;
112038 + if (gimple_num_ops(stmt) != 2)
112039 + break;
112040 + size = gimple_assign_rhs1(stmt);
112041 + }
112042 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112043 +//debug_tree(gimple_call_fn(call_stmt));
112044 +//print_node(stderr, "pax", fndecl, 4);
112045 + }
112046 + }
112047 +
112048 + return 0;
112049 +}
112050 +
112051 +#if BUILDING_GCC_VERSION >= 4009
112052 +static const struct pass_data kallocstat_pass_data = {
112053 +#else
112054 +static struct gimple_opt_pass kallocstat_pass = {
112055 + .pass = {
112056 +#endif
112057 + .type = GIMPLE_PASS,
112058 + .name = "kallocstat",
112059 +#if BUILDING_GCC_VERSION >= 4008
112060 + .optinfo_flags = OPTGROUP_NONE,
112061 +#endif
112062 +#if BUILDING_GCC_VERSION >= 4009
112063 + .has_gate = false,
112064 + .has_execute = true,
112065 +#else
112066 + .gate = NULL,
112067 + .execute = execute_kallocstat,
112068 + .sub = NULL,
112069 + .next = NULL,
112070 + .static_pass_number = 0,
112071 +#endif
112072 + .tv_id = TV_NONE,
112073 + .properties_required = 0,
112074 + .properties_provided = 0,
112075 + .properties_destroyed = 0,
112076 + .todo_flags_start = 0,
112077 + .todo_flags_finish = 0
112078 +#if BUILDING_GCC_VERSION < 4009
112079 + }
112080 +#endif
112081 +};
112082 +
112083 +#if BUILDING_GCC_VERSION >= 4009
112084 +namespace {
112085 +class kallocstat_pass : public gimple_opt_pass {
112086 +public:
112087 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
112088 + unsigned int execute() { return execute_kallocstat(); }
112089 +};
112090 +}
112091 +
112092 +static opt_pass *make_kallocstat_pass(void)
112093 +{
112094 + return new kallocstat_pass();
112095 +}
112096 +#else
112097 +static struct opt_pass *make_kallocstat_pass(void)
112098 +{
112099 + return &kallocstat_pass.pass;
112100 +}
112101 +#endif
112102 +
112103 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112104 +{
112105 + const char * const plugin_name = plugin_info->base_name;
112106 + struct register_pass_info kallocstat_pass_info;
112107 +
112108 + kallocstat_pass_info.pass = make_kallocstat_pass();
112109 + kallocstat_pass_info.reference_pass_name = "ssa";
112110 + kallocstat_pass_info.ref_pass_instance_number = 1;
112111 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112112 +
112113 + if (!plugin_default_version_check(version, &gcc_version)) {
112114 + error(G_("incompatible gcc/plugin versions"));
112115 + return 1;
112116 + }
112117 +
112118 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112119 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112120 +
112121 + return 0;
112122 +}
112123 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112124 new file mode 100644
112125 index 0000000..89f256d
112126 --- /dev/null
112127 +++ b/tools/gcc/kernexec_plugin.c
112128 @@ -0,0 +1,522 @@
112129 +/*
112130 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112131 + * Licensed under the GPL v2
112132 + *
112133 + * Note: the choice of the license means that the compilation process is
112134 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112135 + * but for the kernel it doesn't matter since it doesn't link against
112136 + * any of the gcc libraries
112137 + *
112138 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112139 + *
112140 + * TODO:
112141 + *
112142 + * BUGS:
112143 + * - none known
112144 + */
112145 +
112146 +#include "gcc-common.h"
112147 +
112148 +int plugin_is_GPL_compatible;
112149 +
112150 +static struct plugin_info kernexec_plugin_info = {
112151 + .version = "201401260140",
112152 + .help = "method=[bts|or]\tinstrumentation method\n"
112153 +};
112154 +
112155 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112156 +static void (*kernexec_instrument_retaddr)(rtx);
112157 +
112158 +/*
112159 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112160 + */
112161 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112162 +{
112163 + gimple asm_movabs_stmt;
112164 +
112165 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112166 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112167 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112168 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112169 + update_stmt(asm_movabs_stmt);
112170 +}
112171 +
112172 +/*
112173 + * find all asm() stmts that clobber r12 and add a reload of r12
112174 + */
112175 +static unsigned int execute_kernexec_reload(void)
112176 +{
112177 + basic_block bb;
112178 +
112179 + // 1. loop through BBs and GIMPLE statements
112180 + FOR_EACH_BB_FN(bb, cfun) {
112181 + gimple_stmt_iterator gsi;
112182 +
112183 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112184 + // gimple match: __asm__ ("" : : : "r12");
112185 + gimple asm_stmt;
112186 + size_t nclobbers;
112187 +
112188 + // is it an asm ...
112189 + asm_stmt = gsi_stmt(gsi);
112190 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112191 + continue;
112192 +
112193 + // ... clobbering r12
112194 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112195 + while (nclobbers--) {
112196 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112197 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112198 + continue;
112199 + kernexec_reload_fptr_mask(&gsi);
112200 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112201 + break;
112202 + }
112203 + }
112204 + }
112205 +
112206 + return 0;
112207 +}
112208 +
112209 +/*
112210 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112211 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112212 + */
112213 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112214 +{
112215 + gimple assign_intptr, assign_new_fptr, call_stmt;
112216 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112217 +
112218 + call_stmt = gsi_stmt(*gsi);
112219 + old_fptr = gimple_call_fn(call_stmt);
112220 +
112221 + // create temporary unsigned long variable used for bitops and cast fptr to it
112222 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112223 + add_referenced_var(intptr);
112224 + intptr = make_ssa_name(intptr, NULL);
112225 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112226 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112227 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112228 + update_stmt(assign_intptr);
112229 +
112230 + // apply logical or to temporary unsigned long and bitmask
112231 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112232 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112233 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112234 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112235 + assign_intptr = gimple_build_assign(intptr, orptr);
112236 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112237 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112238 + update_stmt(assign_intptr);
112239 +
112240 + // cast temporary unsigned long back to a temporary fptr variable
112241 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112242 + add_referenced_var(new_fptr);
112243 + new_fptr = make_ssa_name(new_fptr, NULL);
112244 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112245 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112246 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112247 + update_stmt(assign_new_fptr);
112248 +
112249 + // replace call stmt fn with the new fptr
112250 + gimple_call_set_fn(call_stmt, new_fptr);
112251 + update_stmt(call_stmt);
112252 +}
112253 +
112254 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112255 +{
112256 + gimple asm_or_stmt, call_stmt;
112257 + tree old_fptr, new_fptr, input, output;
112258 +#if BUILDING_GCC_VERSION <= 4007
112259 + VEC(tree, gc) *inputs = NULL;
112260 + VEC(tree, gc) *outputs = NULL;
112261 +#else
112262 + vec<tree, va_gc> *inputs = NULL;
112263 + vec<tree, va_gc> *outputs = NULL;
112264 +#endif
112265 +
112266 + call_stmt = gsi_stmt(*gsi);
112267 + old_fptr = gimple_call_fn(call_stmt);
112268 +
112269 + // create temporary fptr variable
112270 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112271 + add_referenced_var(new_fptr);
112272 + new_fptr = make_ssa_name(new_fptr, NULL);
112273 +
112274 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112275 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112276 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112277 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112278 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112279 +#if BUILDING_GCC_VERSION <= 4007
112280 + VEC_safe_push(tree, gc, inputs, input);
112281 + VEC_safe_push(tree, gc, outputs, output);
112282 +#else
112283 + vec_safe_push(inputs, input);
112284 + vec_safe_push(outputs, output);
112285 +#endif
112286 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112287 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112288 + gimple_asm_set_volatile(asm_or_stmt, true);
112289 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112290 + update_stmt(asm_or_stmt);
112291 +
112292 + // replace call stmt fn with the new fptr
112293 + gimple_call_set_fn(call_stmt, new_fptr);
112294 + update_stmt(call_stmt);
112295 +}
112296 +
112297 +/*
112298 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112299 + */
112300 +static unsigned int execute_kernexec_fptr(void)
112301 +{
112302 + basic_block bb;
112303 +
112304 + // 1. loop through BBs and GIMPLE statements
112305 + FOR_EACH_BB_FN(bb, cfun) {
112306 + gimple_stmt_iterator gsi;
112307 +
112308 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112309 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112310 + tree fn;
112311 + gimple call_stmt;
112312 +
112313 + // is it a call ...
112314 + call_stmt = gsi_stmt(gsi);
112315 + if (!is_gimple_call(call_stmt))
112316 + continue;
112317 + fn = gimple_call_fn(call_stmt);
112318 + if (TREE_CODE(fn) == ADDR_EXPR)
112319 + continue;
112320 + if (TREE_CODE(fn) != SSA_NAME)
112321 + gcc_unreachable();
112322 +
112323 + // ... through a function pointer
112324 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112325 + fn = SSA_NAME_VAR(fn);
112326 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112327 + debug_tree(fn);
112328 + gcc_unreachable();
112329 + }
112330 + }
112331 + fn = TREE_TYPE(fn);
112332 + if (TREE_CODE(fn) != POINTER_TYPE)
112333 + continue;
112334 + fn = TREE_TYPE(fn);
112335 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112336 + continue;
112337 +
112338 + kernexec_instrument_fptr(&gsi);
112339 +
112340 +//debug_tree(gimple_call_fn(call_stmt));
112341 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112342 + }
112343 + }
112344 +
112345 + return 0;
112346 +}
112347 +
112348 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112349 +static void kernexec_instrument_retaddr_bts(rtx insn)
112350 +{
112351 + rtx btsq;
112352 + rtvec argvec, constraintvec, labelvec;
112353 + int line;
112354 +
112355 + // create asm volatile("btsq $63,(%%rsp)":::)
112356 + argvec = rtvec_alloc(0);
112357 + constraintvec = rtvec_alloc(0);
112358 + labelvec = rtvec_alloc(0);
112359 + line = expand_location(RTL_LOCATION(insn)).line;
112360 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112361 + MEM_VOLATILE_P(btsq) = 1;
112362 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112363 + emit_insn_before(btsq, insn);
112364 +}
112365 +
112366 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112367 +static void kernexec_instrument_retaddr_or(rtx insn)
112368 +{
112369 + rtx orq;
112370 + rtvec argvec, constraintvec, labelvec;
112371 + int line;
112372 +
112373 + // create asm volatile("orq %%r12,(%%rsp)":::)
112374 + argvec = rtvec_alloc(0);
112375 + constraintvec = rtvec_alloc(0);
112376 + labelvec = rtvec_alloc(0);
112377 + line = expand_location(RTL_LOCATION(insn)).line;
112378 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112379 + MEM_VOLATILE_P(orq) = 1;
112380 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112381 + emit_insn_before(orq, insn);
112382 +}
112383 +
112384 +/*
112385 + * find all asm level function returns and forcibly set the highest bit of the return address
112386 + */
112387 +static unsigned int execute_kernexec_retaddr(void)
112388 +{
112389 + rtx insn;
112390 +
112391 +// if (stack_realign_drap)
112392 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112393 +
112394 + // 1. find function returns
112395 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112396 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112397 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112398 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112399 + rtx body;
112400 +
112401 + // is it a retn
112402 + if (!JUMP_P(insn))
112403 + continue;
112404 + body = PATTERN(insn);
112405 + if (GET_CODE(body) == PARALLEL)
112406 + body = XVECEXP(body, 0, 0);
112407 + if (!ANY_RETURN_P(body))
112408 + continue;
112409 + kernexec_instrument_retaddr(insn);
112410 + }
112411 +
112412 +// print_simple_rtl(stderr, get_insns());
112413 +// print_rtl(stderr, get_insns());
112414 +
112415 + return 0;
112416 +}
112417 +
112418 +static bool kernexec_cmodel_check(void)
112419 +{
112420 + tree section;
112421 +
112422 + if (ix86_cmodel != CM_KERNEL)
112423 + return false;
112424 +
112425 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112426 + if (!section || !TREE_VALUE(section))
112427 + return true;
112428 +
112429 + section = TREE_VALUE(TREE_VALUE(section));
112430 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112431 + return true;
112432 +
112433 + return false;
112434 +}
112435 +
112436 +#if BUILDING_GCC_VERSION >= 4009
112437 +static const struct pass_data kernexec_reload_pass_data = {
112438 +#else
112439 +static struct gimple_opt_pass kernexec_reload_pass = {
112440 + .pass = {
112441 +#endif
112442 + .type = GIMPLE_PASS,
112443 + .name = "kernexec_reload",
112444 +#if BUILDING_GCC_VERSION >= 4008
112445 + .optinfo_flags = OPTGROUP_NONE,
112446 +#endif
112447 +#if BUILDING_GCC_VERSION >= 4009
112448 + .has_gate = true,
112449 + .has_execute = true,
112450 +#else
112451 + .gate = kernexec_cmodel_check,
112452 + .execute = execute_kernexec_reload,
112453 + .sub = NULL,
112454 + .next = NULL,
112455 + .static_pass_number = 0,
112456 +#endif
112457 + .tv_id = TV_NONE,
112458 + .properties_required = 0,
112459 + .properties_provided = 0,
112460 + .properties_destroyed = 0,
112461 + .todo_flags_start = 0,
112462 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112463 +#if BUILDING_GCC_VERSION < 4009
112464 + }
112465 +#endif
112466 +};
112467 +
112468 +#if BUILDING_GCC_VERSION >= 4009
112469 +static const struct pass_data kernexec_fptr_pass_data = {
112470 +#else
112471 +static struct gimple_opt_pass kernexec_fptr_pass = {
112472 + .pass = {
112473 +#endif
112474 + .type = GIMPLE_PASS,
112475 + .name = "kernexec_fptr",
112476 +#if BUILDING_GCC_VERSION >= 4008
112477 + .optinfo_flags = OPTGROUP_NONE,
112478 +#endif
112479 +#if BUILDING_GCC_VERSION >= 4009
112480 + .has_gate = true,
112481 + .has_execute = true,
112482 +#else
112483 + .gate = kernexec_cmodel_check,
112484 + .execute = execute_kernexec_fptr,
112485 + .sub = NULL,
112486 + .next = NULL,
112487 + .static_pass_number = 0,
112488 +#endif
112489 + .tv_id = TV_NONE,
112490 + .properties_required = 0,
112491 + .properties_provided = 0,
112492 + .properties_destroyed = 0,
112493 + .todo_flags_start = 0,
112494 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112495 +#if BUILDING_GCC_VERSION < 4009
112496 + }
112497 +#endif
112498 +};
112499 +
112500 +#if BUILDING_GCC_VERSION >= 4009
112501 +static const struct pass_data kernexec_retaddr_pass_data = {
112502 +#else
112503 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112504 + .pass = {
112505 +#endif
112506 + .type = RTL_PASS,
112507 + .name = "kernexec_retaddr",
112508 +#if BUILDING_GCC_VERSION >= 4008
112509 + .optinfo_flags = OPTGROUP_NONE,
112510 +#endif
112511 +#if BUILDING_GCC_VERSION >= 4009
112512 + .has_gate = true,
112513 + .has_execute = true,
112514 +#else
112515 + .gate = kernexec_cmodel_check,
112516 + .execute = execute_kernexec_retaddr,
112517 + .sub = NULL,
112518 + .next = NULL,
112519 + .static_pass_number = 0,
112520 +#endif
112521 + .tv_id = TV_NONE,
112522 + .properties_required = 0,
112523 + .properties_provided = 0,
112524 + .properties_destroyed = 0,
112525 + .todo_flags_start = 0,
112526 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112527 +#if BUILDING_GCC_VERSION < 4009
112528 + }
112529 +#endif
112530 +};
112531 +
112532 +#if BUILDING_GCC_VERSION >= 4009
112533 +namespace {
112534 +class kernexec_reload_pass : public gimple_opt_pass {
112535 +public:
112536 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112537 + bool gate() { return kernexec_cmodel_check(); }
112538 + unsigned int execute() { return execute_kernexec_reload(); }
112539 +};
112540 +
112541 +class kernexec_fptr_pass : public gimple_opt_pass {
112542 +public:
112543 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112544 + bool gate() { return kernexec_cmodel_check(); }
112545 + unsigned int execute() { return execute_kernexec_fptr(); }
112546 +};
112547 +
112548 +class kernexec_retaddr_pass : public rtl_opt_pass {
112549 +public:
112550 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112551 + bool gate() { return kernexec_cmodel_check(); }
112552 + unsigned int execute() { return execute_kernexec_retaddr(); }
112553 +};
112554 +}
112555 +
112556 +static opt_pass *make_kernexec_reload_pass(void)
112557 +{
112558 + return new kernexec_reload_pass();
112559 +}
112560 +
112561 +static opt_pass *make_kernexec_fptr_pass(void)
112562 +{
112563 + return new kernexec_fptr_pass();
112564 +}
112565 +
112566 +static opt_pass *make_kernexec_retaddr_pass(void)
112567 +{
112568 + return new kernexec_retaddr_pass();
112569 +}
112570 +#else
112571 +static struct opt_pass *make_kernexec_reload_pass(void)
112572 +{
112573 + return &kernexec_reload_pass.pass;
112574 +}
112575 +
112576 +static struct opt_pass *make_kernexec_fptr_pass(void)
112577 +{
112578 + return &kernexec_fptr_pass.pass;
112579 +}
112580 +
112581 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112582 +{
112583 + return &kernexec_retaddr_pass.pass;
112584 +}
112585 +#endif
112586 +
112587 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112588 +{
112589 + const char * const plugin_name = plugin_info->base_name;
112590 + const int argc = plugin_info->argc;
112591 + const struct plugin_argument * const argv = plugin_info->argv;
112592 + int i;
112593 + struct register_pass_info kernexec_reload_pass_info;
112594 + struct register_pass_info kernexec_fptr_pass_info;
112595 + struct register_pass_info kernexec_retaddr_pass_info;
112596 +
112597 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112598 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112599 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112600 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112601 +
112602 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112603 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112604 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112605 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112606 +
112607 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112608 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112609 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112610 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112611 +
112612 + if (!plugin_default_version_check(version, &gcc_version)) {
112613 + error(G_("incompatible gcc/plugin versions"));
112614 + return 1;
112615 + }
112616 +
112617 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112618 +
112619 + if (TARGET_64BIT == 0)
112620 + return 0;
112621 +
112622 + for (i = 0; i < argc; ++i) {
112623 + if (!strcmp(argv[i].key, "method")) {
112624 + if (!argv[i].value) {
112625 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112626 + continue;
112627 + }
112628 + if (!strcmp(argv[i].value, "bts")) {
112629 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112630 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112631 + } else if (!strcmp(argv[i].value, "or")) {
112632 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112633 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112634 + fix_register("r12", 1, 1);
112635 + } else
112636 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112637 + continue;
112638 + }
112639 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112640 + }
112641 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112642 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112643 +
112644 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112645 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112646 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112647 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112648 +
112649 + return 0;
112650 +}
112651 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112652 new file mode 100644
112653 index 0000000..e48b323
112654 --- /dev/null
112655 +++ b/tools/gcc/latent_entropy_plugin.c
112656 @@ -0,0 +1,466 @@
112657 +/*
112658 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112659 + * Licensed under the GPL v2
112660 + *
112661 + * Note: the choice of the license means that the compilation process is
112662 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112663 + * but for the kernel it doesn't matter since it doesn't link against
112664 + * any of the gcc libraries
112665 + *
112666 + * gcc plugin to help generate a little bit of entropy from program state,
112667 + * used throughout the uptime of the kernel
112668 + *
112669 + * TODO:
112670 + * - add ipa pass to identify not explicitly marked candidate functions
112671 + * - mix in more program state (function arguments/return values, loop variables, etc)
112672 + * - more instrumentation control via attribute parameters
112673 + *
112674 + * BUGS:
112675 + * - LTO needs -flto-partition=none for now
112676 + */
112677 +
112678 +#include "gcc-common.h"
112679 +
112680 +int plugin_is_GPL_compatible;
112681 +
112682 +static tree latent_entropy_decl;
112683 +
112684 +static struct plugin_info latent_entropy_plugin_info = {
112685 + .version = "201409101820",
112686 + .help = NULL
112687 +};
112688 +
112689 +static unsigned HOST_WIDE_INT seed;
112690 +static unsigned HOST_WIDE_INT get_random_const(void)
112691 +{
112692 + unsigned int i;
112693 + unsigned HOST_WIDE_INT ret = 0;
112694 +
112695 + for (i = 0; i < 8 * sizeof ret; i++) {
112696 + ret = (ret << 1) | (seed & 1);
112697 + seed >>= 1;
112698 + if (ret & 1)
112699 + seed ^= 0xD800000000000000ULL;
112700 + }
112701 +
112702 + return ret;
112703 +}
112704 +
112705 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112706 +{
112707 + tree type;
112708 + unsigned long long mask;
112709 +#if BUILDING_GCC_VERSION <= 4007
112710 + VEC(constructor_elt, gc) *vals;
112711 +#else
112712 + vec<constructor_elt, va_gc> *vals;
112713 +#endif
112714 +
112715 + switch (TREE_CODE(*node)) {
112716 + default:
112717 + *no_add_attrs = true;
112718 + error("%qE attribute only applies to functions and variables", name);
112719 + break;
112720 +
112721 + case VAR_DECL:
112722 + if (DECL_INITIAL(*node)) {
112723 + *no_add_attrs = true;
112724 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112725 + break;
112726 + }
112727 +
112728 + if (!TREE_STATIC(*node)) {
112729 + *no_add_attrs = true;
112730 + error("variable %qD with %qE attribute must not be local", *node, name);
112731 + break;
112732 + }
112733 +
112734 + type = TREE_TYPE(*node);
112735 + switch (TREE_CODE(type)) {
112736 + default:
112737 + *no_add_attrs = true;
112738 + 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);
112739 + break;
112740 +
112741 + case RECORD_TYPE: {
112742 + tree field;
112743 + unsigned int nelt = 0;
112744 +
112745 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112746 + tree fieldtype;
112747 +
112748 + fieldtype = TREE_TYPE(field);
112749 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112750 + *no_add_attrs = true;
112751 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112752 + break;
112753 + }
112754 + }
112755 +
112756 + if (field)
112757 + break;
112758 +
112759 +#if BUILDING_GCC_VERSION <= 4007
112760 + vals = VEC_alloc(constructor_elt, gc, nelt);
112761 +#else
112762 + vec_alloc(vals, nelt);
112763 +#endif
112764 +
112765 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112766 + tree fieldtype;
112767 +
112768 + fieldtype = TREE_TYPE(field);
112769 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112770 + mask = 2 * (mask - 1) + 1;
112771 +
112772 + if (TYPE_UNSIGNED(fieldtype))
112773 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112774 + else
112775 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112776 + }
112777 +
112778 + DECL_INITIAL(*node) = build_constructor(type, vals);
112779 +//debug_tree(DECL_INITIAL(*node));
112780 + break;
112781 + }
112782 +
112783 + case INTEGER_TYPE:
112784 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112785 + mask = 2 * (mask - 1) + 1;
112786 +
112787 + if (TYPE_UNSIGNED(type))
112788 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112789 + else
112790 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112791 + break;
112792 +
112793 + case ARRAY_TYPE: {
112794 + tree elt_type, array_size, elt_size;
112795 + unsigned int i, nelt;
112796 +
112797 + elt_type = TREE_TYPE(type);
112798 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112799 + array_size = TYPE_SIZE_UNIT(type);
112800 +
112801 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112802 + *no_add_attrs = true;
112803 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112804 + break;
112805 + }
112806 +
112807 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112808 +#if BUILDING_GCC_VERSION <= 4007
112809 + vals = VEC_alloc(constructor_elt, gc, nelt);
112810 +#else
112811 + vec_alloc(vals, nelt);
112812 +#endif
112813 +
112814 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112815 + mask = 2 * (mask - 1) + 1;
112816 +
112817 + for (i = 0; i < nelt; i++)
112818 + if (TYPE_UNSIGNED(elt_type))
112819 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112820 + else
112821 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112822 +
112823 + DECL_INITIAL(*node) = build_constructor(type, vals);
112824 +//debug_tree(DECL_INITIAL(*node));
112825 + break;
112826 + }
112827 + }
112828 + break;
112829 +
112830 + case FUNCTION_DECL:
112831 + break;
112832 + }
112833 +
112834 + return NULL_TREE;
112835 +}
112836 +
112837 +static struct attribute_spec latent_entropy_attr = {
112838 + .name = "latent_entropy",
112839 + .min_length = 0,
112840 + .max_length = 0,
112841 + .decl_required = true,
112842 + .type_required = false,
112843 + .function_type_required = false,
112844 + .handler = handle_latent_entropy_attribute,
112845 +#if BUILDING_GCC_VERSION >= 4007
112846 + .affects_type_identity = false
112847 +#endif
112848 +};
112849 +
112850 +static void register_attributes(void *event_data, void *data)
112851 +{
112852 + register_attribute(&latent_entropy_attr);
112853 +}
112854 +
112855 +static bool gate_latent_entropy(void)
112856 +{
112857 + // don't bother with noreturn functions for now
112858 + if (TREE_THIS_VOLATILE(current_function_decl))
112859 + return false;
112860 +
112861 + // gcc-4.5 doesn't discover some trivial noreturn functions
112862 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112863 + return false;
112864 +
112865 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112866 +}
112867 +
112868 +static enum tree_code get_op(tree *rhs)
112869 +{
112870 + static enum tree_code op;
112871 + unsigned HOST_WIDE_INT random_const;
112872 +
112873 + random_const = get_random_const();
112874 +
112875 + switch (op) {
112876 + case BIT_XOR_EXPR:
112877 + op = PLUS_EXPR;
112878 + break;
112879 +
112880 + case PLUS_EXPR:
112881 + if (rhs) {
112882 + op = LROTATE_EXPR;
112883 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112884 + break;
112885 + }
112886 +
112887 + case LROTATE_EXPR:
112888 + default:
112889 + op = BIT_XOR_EXPR;
112890 + break;
112891 + }
112892 + if (rhs)
112893 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112894 + return op;
112895 +}
112896 +
112897 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112898 +{
112899 + gimple_stmt_iterator gsi;
112900 + gimple assign;
112901 + tree addxorrol, rhs;
112902 + enum tree_code op;
112903 +
112904 + op = get_op(&rhs);
112905 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112906 + assign = gimple_build_assign(local_entropy, addxorrol);
112907 + gsi = gsi_after_labels(bb);
112908 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112909 + update_stmt(assign);
112910 +//debug_bb(bb);
112911 +}
112912 +
112913 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112914 +{
112915 + gimple_stmt_iterator gsi;
112916 + gimple assign;
112917 + tree addxorrol, temp;
112918 +
112919 + // 1. create temporary copy of latent_entropy
112920 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112921 + add_referenced_var(temp);
112922 +
112923 + // 2. read...
112924 + temp = make_ssa_name(temp, NULL);
112925 + assign = gimple_build_assign(temp, latent_entropy_decl);
112926 + SSA_NAME_DEF_STMT(temp) = assign;
112927 + add_referenced_var(latent_entropy_decl);
112928 + gsi = gsi_after_labels(bb);
112929 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112930 + update_stmt(assign);
112931 +
112932 + // 3. ...modify...
112933 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112934 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112935 + assign = gimple_build_assign(temp, addxorrol);
112936 + SSA_NAME_DEF_STMT(temp) = assign;
112937 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112938 + update_stmt(assign);
112939 +
112940 + // 4. ...write latent_entropy
112941 + assign = gimple_build_assign(latent_entropy_decl, temp);
112942 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112943 + update_stmt(assign);
112944 +}
112945 +
112946 +static unsigned int execute_latent_entropy(void)
112947 +{
112948 + basic_block bb;
112949 + gimple assign;
112950 + gimple_stmt_iterator gsi;
112951 + tree local_entropy;
112952 +
112953 + if (!latent_entropy_decl) {
112954 +#if BUILDING_GCC_VERSION >= 4009
112955 + varpool_node *node;
112956 +#else
112957 + struct varpool_node *node;
112958 +#endif
112959 +
112960 + FOR_EACH_VARIABLE(node) {
112961 + tree var = NODE_DECL(node);
112962 +
112963 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112964 + continue;
112965 + latent_entropy_decl = var;
112966 +// debug_tree(var);
112967 + break;
112968 + }
112969 + if (!latent_entropy_decl) {
112970 +// debug_tree(current_function_decl);
112971 + return 0;
112972 + }
112973 + }
112974 +
112975 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112976 +
112977 + // 1. create local entropy variable
112978 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112979 + add_referenced_var(local_entropy);
112980 + mark_sym_for_renaming(local_entropy);
112981 +
112982 + // 2. initialize local entropy variable
112983 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112984 + if (dom_info_available_p(CDI_DOMINATORS))
112985 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112986 + gsi = gsi_start_bb(bb);
112987 +
112988 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112989 +// gimple_set_location(assign, loc);
112990 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112991 + update_stmt(assign);
112992 +//debug_bb(bb);
112993 + gcc_assert(single_succ_p(bb));
112994 + bb = single_succ(bb);
112995 +
112996 + // 3. instrument each BB with an operation on the local entropy variable
112997 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112998 + perturb_local_entropy(bb, local_entropy);
112999 +//debug_bb(bb);
113000 + bb = bb->next_bb;
113001 + };
113002 +
113003 + // 4. mix local entropy into the global entropy variable
113004 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113005 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
113006 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113007 + return 0;
113008 +}
113009 +
113010 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
113011 +{
113012 + tree latent_entropy_type;
113013 +
113014 + seed = get_random_seed(false);
113015 +
113016 + if (in_lto_p)
113017 + return;
113018 +
113019 + // extern volatile u64 latent_entropy
113020 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
113021 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
113022 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
113023 +
113024 + TREE_STATIC(latent_entropy_decl) = 1;
113025 + TREE_PUBLIC(latent_entropy_decl) = 1;
113026 + TREE_USED(latent_entropy_decl) = 1;
113027 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
113028 + DECL_EXTERNAL(latent_entropy_decl) = 1;
113029 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
113030 + lang_hooks.decls.pushdecl(latent_entropy_decl);
113031 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
113032 +// varpool_finalize_decl(latent_entropy_decl);
113033 +// varpool_mark_needed_node(latent_entropy_decl);
113034 +}
113035 +
113036 +#if BUILDING_GCC_VERSION >= 4009
113037 +static const struct pass_data latent_entropy_pass_data = {
113038 +#else
113039 +static struct gimple_opt_pass latent_entropy_pass = {
113040 + .pass = {
113041 +#endif
113042 + .type = GIMPLE_PASS,
113043 + .name = "latent_entropy",
113044 +#if BUILDING_GCC_VERSION >= 4008
113045 + .optinfo_flags = OPTGROUP_NONE,
113046 +#endif
113047 +#if BUILDING_GCC_VERSION >= 4009
113048 + .has_gate = true,
113049 + .has_execute = true,
113050 +#else
113051 + .gate = gate_latent_entropy,
113052 + .execute = execute_latent_entropy,
113053 + .sub = NULL,
113054 + .next = NULL,
113055 + .static_pass_number = 0,
113056 +#endif
113057 + .tv_id = TV_NONE,
113058 + .properties_required = PROP_gimple_leh | PROP_cfg,
113059 + .properties_provided = 0,
113060 + .properties_destroyed = 0,
113061 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
113062 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
113063 +#if BUILDING_GCC_VERSION < 4009
113064 + }
113065 +#endif
113066 +};
113067 +
113068 +#if BUILDING_GCC_VERSION >= 4009
113069 +namespace {
113070 +class latent_entropy_pass : public gimple_opt_pass {
113071 +public:
113072 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
113073 + bool gate() { return gate_latent_entropy(); }
113074 + unsigned int execute() { return execute_latent_entropy(); }
113075 +};
113076 +}
113077 +
113078 +static opt_pass *make_latent_entropy_pass(void)
113079 +{
113080 + return new latent_entropy_pass();
113081 +}
113082 +#else
113083 +static struct opt_pass *make_latent_entropy_pass(void)
113084 +{
113085 + return &latent_entropy_pass.pass;
113086 +}
113087 +#endif
113088 +
113089 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113090 +{
113091 + const char * const plugin_name = plugin_info->base_name;
113092 + struct register_pass_info latent_entropy_pass_info;
113093 +
113094 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
113095 + latent_entropy_pass_info.reference_pass_name = "optimized";
113096 + latent_entropy_pass_info.ref_pass_instance_number = 1;
113097 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
113098 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
113099 + {
113100 + .base = &latent_entropy_decl,
113101 + .nelt = 1,
113102 + .stride = sizeof(latent_entropy_decl),
113103 + .cb = &gt_ggc_mx_tree_node,
113104 + .pchw = &gt_pch_nx_tree_node
113105 + },
113106 + LAST_GGC_ROOT_TAB
113107 + };
113108 +
113109 + if (!plugin_default_version_check(version, &gcc_version)) {
113110 + error(G_("incompatible gcc/plugin versions"));
113111 + return 1;
113112 + }
113113 +
113114 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
113115 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
113116 + if (!in_lto_p)
113117 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
113118 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113119 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113120 +
113121 + return 0;
113122 +}
113123 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113124 new file mode 100644
113125 index 0000000..a5cb46b
113126 --- /dev/null
113127 +++ b/tools/gcc/randomize_layout_plugin.c
113128 @@ -0,0 +1,915 @@
113129 +/*
113130 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113131 + * and PaX Team <pageexec@freemail.hu>
113132 + * Licensed under the GPL v2
113133 + *
113134 + * Usage:
113135 + * $ # for 4.5/4.6/C based 4.7
113136 + * $ 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
113137 + * $ # for C++ based 4.7/4.8+
113138 + * $ 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
113139 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113140 + */
113141 +
113142 +#include "gcc-common.h"
113143 +#include "randomize_layout_seed.h"
113144 +
113145 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113146 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113147 +#endif
113148 +
113149 +#define ORIG_TYPE_NAME(node) \
113150 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113151 +
113152 +int plugin_is_GPL_compatible;
113153 +
113154 +static int performance_mode;
113155 +
113156 +static struct plugin_info randomize_layout_plugin_info = {
113157 + .version = "201402201816",
113158 + .help = "disable\t\t\tdo not activate plugin\n"
113159 + "performance-mode\tenable cacheline-aware layout randomization\n"
113160 +};
113161 +
113162 +/* from old Linux dcache.h */
113163 +static inline unsigned long
113164 +partial_name_hash(unsigned long c, unsigned long prevhash)
113165 +{
113166 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113167 +}
113168 +static inline unsigned int
113169 +name_hash(const unsigned char *name)
113170 +{
113171 + unsigned long hash = 0;
113172 + unsigned int len = strlen((const char *)name);
113173 + while (len--)
113174 + hash = partial_name_hash(*name++, hash);
113175 + return (unsigned int)hash;
113176 +}
113177 +
113178 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113179 +{
113180 + tree type;
113181 +
113182 + *no_add_attrs = true;
113183 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113184 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113185 + return NULL_TREE;
113186 + }
113187 +
113188 + if (TREE_CODE(*node) == PARM_DECL) {
113189 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113190 + return NULL_TREE;
113191 + }
113192 +
113193 + if (TREE_CODE(*node) == VAR_DECL) {
113194 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113195 + return NULL_TREE;
113196 + }
113197 +
113198 + if (TYPE_P(*node)) {
113199 + type = *node;
113200 + } else {
113201 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113202 + type = TREE_TYPE(*node);
113203 + }
113204 +
113205 + if (TREE_CODE(type) != RECORD_TYPE) {
113206 + error("%qE attribute used on %qT applies to struct types only", name, type);
113207 + return NULL_TREE;
113208 + }
113209 +
113210 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113211 + error("%qE attribute is already applied to the type %qT", name, type);
113212 + return NULL_TREE;
113213 + }
113214 +
113215 + *no_add_attrs = false;
113216 +
113217 + return NULL_TREE;
113218 +}
113219 +
113220 +/* set on complete types that we don't need to inspect further at all */
113221 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113222 +{
113223 + *no_add_attrs = false;
113224 + return NULL_TREE;
113225 +}
113226 +
113227 +/*
113228 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113229 + * this does not preclude us from inspecting its fields for potential shuffles
113230 + */
113231 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113232 +{
113233 + *no_add_attrs = false;
113234 + return NULL_TREE;
113235 +}
113236 +
113237 +/*
113238 + * 64bit variant of Bob Jenkins' public domain PRNG
113239 + * 256 bits of internal state
113240 + */
113241 +
113242 +typedef unsigned long long u64;
113243 +
113244 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113245 +
113246 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113247 +static u64 ranval(ranctx *x) {
113248 + u64 e = x->a - rot(x->b, 7);
113249 + x->a = x->b ^ rot(x->c, 13);
113250 + x->b = x->c + rot(x->d, 37);
113251 + x->c = x->d + e;
113252 + x->d = e + x->a;
113253 + return x->d;
113254 +}
113255 +
113256 +static void raninit(ranctx *x, u64 *seed) {
113257 + int i;
113258 +
113259 + x->a = seed[0];
113260 + x->b = seed[1];
113261 + x->c = seed[2];
113262 + x->d = seed[3];
113263 +
113264 + for (i=0; i < 30; ++i)
113265 + (void)ranval(x);
113266 +}
113267 +
113268 +static u64 shuffle_seed[4];
113269 +
113270 +struct partition_group {
113271 + tree tree_start;
113272 + unsigned long start;
113273 + unsigned long length;
113274 +};
113275 +
113276 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113277 +{
113278 + unsigned long i;
113279 + unsigned long accum_size = 0;
113280 + unsigned long accum_length = 0;
113281 + unsigned long group_idx = 0;
113282 +
113283 + gcc_assert(length < INT_MAX);
113284 +
113285 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113286 +
113287 + for (i = 0; i < length; i++) {
113288 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113289 + size_groups[group_idx].tree_start = fields[i];
113290 + size_groups[group_idx].start = i;
113291 + accum_length = 0;
113292 + accum_size = 0;
113293 + }
113294 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113295 + accum_length++;
113296 + if (accum_size >= 64) {
113297 + size_groups[group_idx].length = accum_length;
113298 + accum_length = 0;
113299 + group_idx++;
113300 + }
113301 + }
113302 +
113303 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113304 + !size_groups[group_idx].length) {
113305 + size_groups[group_idx].length = accum_length;
113306 + group_idx++;
113307 + }
113308 +
113309 + *num_groups = group_idx;
113310 +}
113311 +
113312 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113313 +{
113314 + unsigned long i, x;
113315 + struct partition_group size_group[length];
113316 + unsigned long num_groups = 0;
113317 + unsigned long randnum;
113318 +
113319 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113320 + for (i = num_groups - 1; i > 0; i--) {
113321 + struct partition_group tmp;
113322 + randnum = ranval(prng_state) % (i + 1);
113323 + tmp = size_group[i];
113324 + size_group[i] = size_group[randnum];
113325 + size_group[randnum] = tmp;
113326 + }
113327 +
113328 + for (x = 0; x < num_groups; x++) {
113329 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113330 + tree tmp;
113331 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113332 + continue;
113333 + randnum = ranval(prng_state) % (i + 1);
113334 + // we could handle this case differently if desired
113335 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113336 + continue;
113337 + tmp = newtree[i];
113338 + newtree[i] = newtree[randnum];
113339 + newtree[randnum] = tmp;
113340 + }
113341 + }
113342 +}
113343 +
113344 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113345 +{
113346 + unsigned long i, randnum;
113347 +
113348 + for (i = length - 1; i > 0; i--) {
113349 + tree tmp;
113350 + randnum = ranval(prng_state) % (i + 1);
113351 + tmp = newtree[i];
113352 + newtree[i] = newtree[randnum];
113353 + newtree[randnum] = tmp;
113354 + }
113355 +}
113356 +
113357 +/* modern in-place Fisher-Yates shuffle */
113358 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113359 +{
113360 + unsigned long i;
113361 + u64 seed[4];
113362 + ranctx prng_state;
113363 + const unsigned char *structname;
113364 +
113365 + if (length == 0)
113366 + return;
113367 +
113368 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113369 +
113370 + structname = ORIG_TYPE_NAME(type);
113371 +
113372 +#ifdef __DEBUG_PLUGIN
113373 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113374 +#ifdef __DEBUG_VERBOSE
113375 + debug_tree((tree)type);
113376 +#endif
113377 +#endif
113378 +
113379 + for (i = 0; i < 4; i++) {
113380 + seed[i] = shuffle_seed[i];
113381 + seed[i] ^= name_hash(structname);
113382 + }
113383 +
113384 + raninit(&prng_state, (u64 *)&seed);
113385 +
113386 + if (performance_mode)
113387 + performance_shuffle(newtree, length, &prng_state);
113388 + else
113389 + full_shuffle(newtree, length, &prng_state);
113390 +}
113391 +
113392 +static bool is_flexible_array(const_tree field)
113393 +{
113394 + const_tree fieldtype;
113395 + const_tree typesize;
113396 + const_tree elemtype;
113397 + const_tree elemsize;
113398 +
113399 + fieldtype = TREE_TYPE(field);
113400 + typesize = TYPE_SIZE(fieldtype);
113401 +
113402 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113403 + return false;
113404 +
113405 + elemtype = TREE_TYPE(fieldtype);
113406 + elemsize = TYPE_SIZE(elemtype);
113407 +
113408 + /* size of type is represented in bits */
113409 +
113410 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113411 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113412 + return true;
113413 +
113414 + if (typesize != NULL_TREE &&
113415 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113416 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113417 + return true;
113418 +
113419 + return false;
113420 +}
113421 +
113422 +static int relayout_struct(tree type)
113423 +{
113424 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113425 + unsigned long shuffle_length = num_fields;
113426 + tree field;
113427 + tree newtree[num_fields];
113428 + unsigned long i;
113429 + tree list;
113430 + tree variant;
113431 + expanded_location xloc;
113432 +
113433 + if (TYPE_FIELDS(type) == NULL_TREE)
113434 + return 0;
113435 +
113436 + if (num_fields < 2)
113437 + return 0;
113438 +
113439 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113440 +
113441 + gcc_assert(num_fields < INT_MAX);
113442 +
113443 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113444 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113445 + return 0;
113446 +
113447 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113448 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113449 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113450 + return 0;
113451 +
113452 + /* throw out any structs in uapi */
113453 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113454 +
113455 + if (strstr(xloc.file, "/uapi/"))
113456 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113457 +
113458 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113459 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113460 + newtree[i] = field;
113461 + }
113462 +
113463 + /*
113464 + * enforce that we don't randomize the layout of the last
113465 + * element of a struct if it's a 0 or 1-length array
113466 + * or a proper flexible array
113467 + */
113468 + if (is_flexible_array(newtree[num_fields - 1]))
113469 + shuffle_length--;
113470 +
113471 + shuffle(type, (tree *)newtree, shuffle_length);
113472 +
113473 + /*
113474 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113475 + * as gcc provides no other way to detect such code
113476 + */
113477 + list = make_node(FIELD_DECL);
113478 + TREE_CHAIN(list) = newtree[0];
113479 + TREE_TYPE(list) = void_type_node;
113480 + DECL_SIZE(list) = bitsize_zero_node;
113481 + DECL_NONADDRESSABLE_P(list) = 1;
113482 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113483 + DECL_SIZE_UNIT(list) = size_zero_node;
113484 + DECL_FIELD_OFFSET(list) = size_zero_node;
113485 + // to satisfy the constify plugin
113486 + TREE_READONLY(list) = 1;
113487 +
113488 + for (i = 0; i < num_fields - 1; i++)
113489 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113490 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113491 +
113492 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113493 + TYPE_FIELDS(variant) = list;
113494 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113495 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113496 + // force a re-layout
113497 + TYPE_SIZE(variant) = NULL_TREE;
113498 + layout_type(variant);
113499 + }
113500 +
113501 + return 1;
113502 +}
113503 +
113504 +/* from constify plugin */
113505 +static const_tree get_field_type(const_tree field)
113506 +{
113507 + return strip_array_types(TREE_TYPE(field));
113508 +}
113509 +
113510 +/* from constify plugin */
113511 +static bool is_fptr(const_tree fieldtype)
113512 +{
113513 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113514 + return false;
113515 +
113516 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113517 +}
113518 +
113519 +/* derived from constify plugin */
113520 +static int is_pure_ops_struct(const_tree node)
113521 +{
113522 + const_tree field;
113523 +
113524 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113525 +
113526 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113527 + const_tree fieldtype = get_field_type(field);
113528 + enum tree_code code = TREE_CODE(fieldtype);
113529 +
113530 + if (node == fieldtype)
113531 + continue;
113532 +
113533 + if (!is_fptr(fieldtype))
113534 + return 0;
113535 +
113536 + if (code != RECORD_TYPE && code != UNION_TYPE)
113537 + continue;
113538 +
113539 + if (!is_pure_ops_struct(fieldtype))
113540 + return 0;
113541 + }
113542 +
113543 + return 1;
113544 +}
113545 +
113546 +static void randomize_type(tree type)
113547 +{
113548 + tree variant;
113549 +
113550 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113551 +
113552 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113553 + return;
113554 +
113555 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113556 + relayout_struct(type);
113557 +
113558 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113559 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113560 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113561 + }
113562 +#ifdef __DEBUG_PLUGIN
113563 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113564 +#ifdef __DEBUG_VERBOSE
113565 + debug_tree(type);
113566 +#endif
113567 +#endif
113568 +}
113569 +
113570 +static void randomize_layout_finish_decl(void *event_data, void *data)
113571 +{
113572 + tree decl = (tree)event_data;
113573 + tree type;
113574 +
113575 + if (decl == NULL_TREE || decl == error_mark_node)
113576 + return;
113577 +
113578 + type = TREE_TYPE(decl);
113579 +
113580 + if (TREE_CODE(decl) != VAR_DECL)
113581 + return;
113582 +
113583 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113584 + return;
113585 +
113586 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113587 + return;
113588 +
113589 + relayout_decl(decl);
113590 +}
113591 +
113592 +static void finish_type(void *event_data, void *data)
113593 +{
113594 + tree type = (tree)event_data;
113595 +
113596 + if (type == NULL_TREE || type == error_mark_node)
113597 + return;
113598 +
113599 + if (TREE_CODE(type) != RECORD_TYPE)
113600 + return;
113601 +
113602 + if (TYPE_FIELDS(type) == NULL_TREE)
113603 + return;
113604 +
113605 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113606 + return;
113607 +
113608 +#ifdef __DEBUG_PLUGIN
113609 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113610 +#endif
113611 +#ifdef __DEBUG_VERBOSE
113612 + debug_tree(type);
113613 +#endif
113614 + randomize_type(type);
113615 +
113616 + return;
113617 +}
113618 +
113619 +static struct attribute_spec randomize_layout_attr = {
113620 + .name = "randomize_layout",
113621 + // related to args
113622 + .min_length = 0,
113623 + .max_length = 0,
113624 + .decl_required = false,
113625 + // need type declaration
113626 + .type_required = true,
113627 + .function_type_required = false,
113628 + .handler = handle_randomize_layout_attr,
113629 +#if BUILDING_GCC_VERSION >= 4007
113630 + .affects_type_identity = true
113631 +#endif
113632 +};
113633 +
113634 +static struct attribute_spec no_randomize_layout_attr = {
113635 + .name = "no_randomize_layout",
113636 + // related to args
113637 + .min_length = 0,
113638 + .max_length = 0,
113639 + .decl_required = false,
113640 + // need type declaration
113641 + .type_required = true,
113642 + .function_type_required = false,
113643 + .handler = handle_randomize_layout_attr,
113644 +#if BUILDING_GCC_VERSION >= 4007
113645 + .affects_type_identity = true
113646 +#endif
113647 +};
113648 +
113649 +static struct attribute_spec randomize_considered_attr = {
113650 + .name = "randomize_considered",
113651 + // related to args
113652 + .min_length = 0,
113653 + .max_length = 0,
113654 + .decl_required = false,
113655 + // need type declaration
113656 + .type_required = true,
113657 + .function_type_required = false,
113658 + .handler = handle_randomize_considered_attr,
113659 +#if BUILDING_GCC_VERSION >= 4007
113660 + .affects_type_identity = false
113661 +#endif
113662 +};
113663 +
113664 +static struct attribute_spec randomize_performed_attr = {
113665 + .name = "randomize_performed",
113666 + // related to args
113667 + .min_length = 0,
113668 + .max_length = 0,
113669 + .decl_required = false,
113670 + // need type declaration
113671 + .type_required = true,
113672 + .function_type_required = false,
113673 + .handler = handle_randomize_performed_attr,
113674 +#if BUILDING_GCC_VERSION >= 4007
113675 + .affects_type_identity = false
113676 +#endif
113677 +};
113678 +
113679 +static void register_attributes(void *event_data, void *data)
113680 +{
113681 + register_attribute(&randomize_layout_attr);
113682 + register_attribute(&no_randomize_layout_attr);
113683 + register_attribute(&randomize_considered_attr);
113684 + register_attribute(&randomize_performed_attr);
113685 +}
113686 +
113687 +static void check_bad_casts_in_constructor(tree var, tree init)
113688 +{
113689 + unsigned HOST_WIDE_INT idx;
113690 + tree field, val;
113691 + tree field_type, val_type;
113692 +
113693 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113694 + if (TREE_CODE(val) == CONSTRUCTOR) {
113695 + check_bad_casts_in_constructor(var, val);
113696 + continue;
113697 + }
113698 +
113699 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113700 + normal code which all have valid 'field' trees. work around this */
113701 + if (field == NULL_TREE)
113702 + continue;
113703 + field_type = TREE_TYPE(field);
113704 + val_type = TREE_TYPE(val);
113705 +
113706 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113707 + continue;
113708 +
113709 + if (field_type == val_type)
113710 + continue;
113711 +
113712 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113713 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113714 +
113715 + if (field_type == void_type_node)
113716 + continue;
113717 + if (field_type == val_type)
113718 + continue;
113719 + if (TREE_CODE(val_type) != RECORD_TYPE)
113720 + continue;
113721 +
113722 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113723 + continue;
113724 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113725 + }
113726 +}
113727 +
113728 +/* derived from the constify plugin */
113729 +static void check_global_variables(void *event_data, void *data)
113730 +{
113731 + struct varpool_node *node;
113732 + tree init;
113733 +
113734 + FOR_EACH_VARIABLE(node) {
113735 + tree var = NODE_DECL(node);
113736 + init = DECL_INITIAL(var);
113737 + if (init == NULL_TREE)
113738 + continue;
113739 +
113740 + if (TREE_CODE(init) != CONSTRUCTOR)
113741 + continue;
113742 +
113743 + check_bad_casts_in_constructor(var, init);
113744 + }
113745 +}
113746 +
113747 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113748 +{
113749 + basic_block dom;
113750 + gimple dom_stmt;
113751 + gimple call_stmt;
113752 + const_tree dom_lhs;
113753 + const_tree poss_is_err_cond;
113754 + const_tree poss_is_err_func;
113755 + const_tree is_err_arg;
113756 +
113757 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113758 + if (!dom)
113759 + return false;
113760 +
113761 + dom_stmt = last_stmt(dom);
113762 + if (!dom_stmt)
113763 + return false;
113764 +
113765 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113766 + return false;
113767 +
113768 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113769 + return false;
113770 +
113771 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113772 + return false;
113773 +
113774 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113775 +
113776 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113777 + return false;
113778 +
113779 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113780 +
113781 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113782 + return false;
113783 +
113784 + dom_lhs = gimple_get_lhs(call_stmt);
113785 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113786 + if (!poss_is_err_func)
113787 + return false;
113788 + if (dom_lhs != poss_is_err_cond)
113789 + return false;
113790 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113791 + return false;
113792 +
113793 + is_err_arg = gimple_call_arg(call_stmt, 0);
113794 + if (!is_err_arg)
113795 + return false;
113796 +
113797 + if (is_err_arg != rhs)
113798 + return false;
113799 +
113800 + return true;
113801 +}
113802 +
113803 +static void handle_local_var_initializers(void)
113804 +{
113805 + tree var;
113806 + unsigned int i;
113807 +
113808 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113809 + tree init = DECL_INITIAL(var);
113810 + if (!init)
113811 + continue;
113812 + if (TREE_CODE(init) != CONSTRUCTOR)
113813 + continue;
113814 + check_bad_casts_in_constructor(var, init);
113815 + }
113816 +}
113817 +
113818 +/*
113819 + * iterate over all statements to find "bad" casts:
113820 + * those where the address of the start of a structure is cast
113821 + * to a pointer of a structure of a different type, or a
113822 + * structure pointer type is cast to a different structure pointer type
113823 + */
113824 +static unsigned int find_bad_casts(void)
113825 +{
113826 + basic_block bb;
113827 +
113828 + handle_local_var_initializers();
113829 +
113830 + FOR_ALL_BB_FN(bb, cfun) {
113831 + gimple_stmt_iterator gsi;
113832 +
113833 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113834 + gimple stmt;
113835 + const_tree lhs;
113836 + const_tree lhs_type;
113837 + const_tree rhs1;
113838 + const_tree rhs_type;
113839 + const_tree ptr_lhs_type;
113840 + const_tree ptr_rhs_type;
113841 + const_tree op0;
113842 + const_tree op0_type;
113843 + enum tree_code rhs_code;
113844 +
113845 + stmt = gsi_stmt(gsi);
113846 +
113847 +#ifdef __DEBUG_PLUGIN
113848 +#ifdef __DEBUG_VERBOSE
113849 + debug_gimple_stmt(stmt);
113850 + debug_tree(gimple_get_lhs(stmt));
113851 +#endif
113852 +#endif
113853 +
113854 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113855 + continue;
113856 +
113857 +#ifdef __DEBUG_PLUGIN
113858 +#ifdef __DEBUG_VERBOSE
113859 + debug_tree(gimple_assign_rhs1(stmt));
113860 +#endif
113861 +#endif
113862 +
113863 + rhs_code = gimple_assign_rhs_code(stmt);
113864 +
113865 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113866 + continue;
113867 +
113868 + lhs = gimple_get_lhs(stmt);
113869 + lhs_type = TREE_TYPE(lhs);
113870 + rhs1 = gimple_assign_rhs1(stmt);
113871 + rhs_type = TREE_TYPE(rhs1);
113872 +
113873 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113874 + TREE_CODE(lhs_type) != POINTER_TYPE)
113875 + continue;
113876 +
113877 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113878 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113879 +
113880 + if (ptr_rhs_type == void_type_node)
113881 + continue;
113882 +
113883 + if (ptr_lhs_type == void_type_node)
113884 + continue;
113885 +
113886 + if (dominated_by_is_err(rhs1, bb))
113887 + continue;
113888 +
113889 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113890 +#ifndef __DEBUG_PLUGIN
113891 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113892 +#endif
113893 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113894 + continue;
113895 + }
113896 +
113897 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113898 + continue;
113899 +
113900 + if (rhs_code == ADDR_EXPR) {
113901 + op0 = TREE_OPERAND(rhs1, 0);
113902 +
113903 + if (op0 == NULL_TREE)
113904 + continue;
113905 +
113906 + if (TREE_CODE(op0) != VAR_DECL)
113907 + continue;
113908 +
113909 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113910 + if (op0_type == ptr_lhs_type)
113911 + continue;
113912 +
113913 +#ifndef __DEBUG_PLUGIN
113914 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113915 +#endif
113916 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113917 + } else {
113918 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113919 + /* skip bogus type casts introduced by container_of */
113920 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113921 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113922 + continue;
113923 +#ifndef __DEBUG_PLUGIN
113924 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113925 +#endif
113926 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113927 + }
113928 +
113929 + }
113930 + }
113931 + return 0;
113932 +}
113933 +
113934 +#if BUILDING_GCC_VERSION >= 4009
113935 +static const struct pass_data randomize_layout_bad_cast_data = {
113936 +#else
113937 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113938 + .pass = {
113939 +#endif
113940 + .type = GIMPLE_PASS,
113941 + .name = "randomize_layout_bad_cast",
113942 +#if BUILDING_GCC_VERSION >= 4008
113943 + .optinfo_flags = OPTGROUP_NONE,
113944 +#endif
113945 +#if BUILDING_GCC_VERSION >= 4009
113946 + .has_gate = false,
113947 + .has_execute = true,
113948 +#else
113949 + .gate = NULL,
113950 + .execute = find_bad_casts,
113951 + .sub = NULL,
113952 + .next = NULL,
113953 + .static_pass_number = 0,
113954 +#endif
113955 + .tv_id = TV_NONE,
113956 + .properties_required = PROP_cfg,
113957 + .properties_provided = 0,
113958 + .properties_destroyed = 0,
113959 + .todo_flags_start = 0,
113960 + .todo_flags_finish = TODO_dump_func
113961 +#if BUILDING_GCC_VERSION < 4009
113962 + }
113963 +#endif
113964 +};
113965 +
113966 +#if BUILDING_GCC_VERSION >= 4009
113967 +namespace {
113968 +class randomize_layout_bad_cast : public gimple_opt_pass {
113969 +public:
113970 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113971 + unsigned int execute() { return find_bad_casts(); }
113972 +};
113973 +}
113974 +#endif
113975 +
113976 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113977 +{
113978 +#if BUILDING_GCC_VERSION >= 4009
113979 + return new randomize_layout_bad_cast();
113980 +#else
113981 + return &randomize_layout_bad_cast.pass;
113982 +#endif
113983 +}
113984 +
113985 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113986 +{
113987 + int i;
113988 + const char * const plugin_name = plugin_info->base_name;
113989 + const int argc = plugin_info->argc;
113990 + const struct plugin_argument * const argv = plugin_info->argv;
113991 + bool enable = true;
113992 + int obtained_seed = 0;
113993 + struct register_pass_info randomize_layout_bad_cast_info;
113994 +
113995 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113996 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113997 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113998 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113999 +
114000 + if (!plugin_default_version_check(version, &gcc_version)) {
114001 + error(G_("incompatible gcc/plugin versions"));
114002 + return 1;
114003 + }
114004 +
114005 + if (strcmp(lang_hooks.name, "GNU C")) {
114006 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
114007 + enable = false;
114008 + }
114009 +
114010 + for (i = 0; i < argc; ++i) {
114011 + if (!strcmp(argv[i].key, "disable")) {
114012 + enable = false;
114013 + continue;
114014 + }
114015 + if (!strcmp(argv[i].key, "performance-mode")) {
114016 + performance_mode = 1;
114017 + continue;
114018 + }
114019 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
114020 + }
114021 +
114022 + if (strlen(randstruct_seed) != 64) {
114023 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
114024 + return 1;
114025 + }
114026 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
114027 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
114028 + if (obtained_seed != 4) {
114029 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
114030 + return 1;
114031 + }
114032 +
114033 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
114034 + if (enable) {
114035 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
114036 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
114037 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
114038 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
114039 + }
114040 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
114041 +
114042 + return 0;
114043 +}
114044 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
114045 new file mode 100644
114046 index 0000000..1f0214f
114047 --- /dev/null
114048 +++ b/tools/gcc/size_overflow_plugin/.gitignore
114049 @@ -0,0 +1,3 @@
114050 +randomize_layout_seed.h
114051 +size_overflow_hash.h
114052 +size_overflow_hash_aux.h
114053 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
114054 new file mode 100644
114055 index 0000000..1ae2ed5
114056 --- /dev/null
114057 +++ b/tools/gcc/size_overflow_plugin/Makefile
114058 @@ -0,0 +1,20 @@
114059 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
114060 +always := $($(HOSTLIBS)-y)
114061 +
114062 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
114063 +
114064 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
114065 +
114066 +quiet_cmd_build_size_overflow_hash = GENHASH $@
114067 + cmd_build_size_overflow_hash = \
114068 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
114069 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
114070 + $(call if_changed,build_size_overflow_hash)
114071 +
114072 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
114073 + cmd_build_size_overflow_hash_aux = \
114074 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
114075 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
114076 + $(call if_changed,build_size_overflow_hash_aux)
114077 +
114078 +targets += size_overflow_hash.h size_overflow_hash_aux.h
114079 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114080 new file mode 100644
114081 index 0000000..12b1e3b
114082 --- /dev/null
114083 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114084 @@ -0,0 +1,102 @@
114085 +#!/bin/bash
114086 +
114087 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
114088 +
114089 +header1="size_overflow_hash.h"
114090 +database="size_overflow_hash.data"
114091 +n=65536
114092 +hashtable_name="size_overflow_hash"
114093 +
114094 +usage() {
114095 +cat <<EOF
114096 +usage: $0 options
114097 +OPTIONS:
114098 + -h|--help help
114099 + -o header file
114100 + -d database file
114101 + -n hash array size
114102 + -s name of the hash table
114103 +EOF
114104 + return 0
114105 +}
114106 +
114107 +while true
114108 +do
114109 + case "$1" in
114110 + -h|--help) usage && exit 0;;
114111 + -n) n=$2; shift 2;;
114112 + -o) header1="$2"; shift 2;;
114113 + -d) database="$2"; shift 2;;
114114 + -s) hashtable_name="$2"; shift 2;;
114115 + --) shift 1; break ;;
114116 + *) break ;;
114117 + esac
114118 +done
114119 +
114120 +create_defines() {
114121 + for i in `seq 0 31`
114122 + do
114123 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114124 + done
114125 + echo >> "$header1"
114126 +}
114127 +
114128 +create_structs() {
114129 + rm -f "$header1"
114130 +
114131 + create_defines
114132 +
114133 + cat "$database" | while read data
114134 + do
114135 + data_array=($data)
114136 + struct_hash_name="${data_array[0]}"
114137 + funcn="${data_array[1]}"
114138 + params="${data_array[2]}"
114139 + next="${data_array[4]}"
114140 +
114141 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114142 +
114143 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114144 + echo -en "\t.param\t= " >> "$header1"
114145 + line=
114146 + for param_num in ${params//-/ };
114147 + do
114148 + line="${line}PARAM"$param_num"|"
114149 + done
114150 +
114151 + echo -e "${line%?},\n};\n" >> "$header1"
114152 + done
114153 +}
114154 +
114155 +create_headers() {
114156 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114157 +}
114158 +
114159 +create_array_elements() {
114160 + index=0
114161 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114162 + do
114163 + data_array=($data)
114164 + i="${data_array[3]}"
114165 + hash="${data_array[0]}"
114166 + while [[ $index -lt $i ]]
114167 + do
114168 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114169 + index=$(($index + 1))
114170 + done
114171 + index=$(($index + 1))
114172 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114173 + done
114174 + echo '};' >> $header1
114175 +}
114176 +
114177 +size_overflow_plugin_dir=`dirname $header1`
114178 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114179 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114180 +fi
114181 +
114182 +create_structs
114183 +create_headers
114184 +create_array_elements
114185 +
114186 +exit 0
114187 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114188 new file mode 100644
114189 index 0000000..c43901f
114190 --- /dev/null
114191 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114192 @@ -0,0 +1,748 @@
114193 +/*
114194 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114195 + * Licensed under the GPL v2, or (at your option) v3
114196 + *
114197 + * Homepage:
114198 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114199 + *
114200 + * Documentation:
114201 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114202 + *
114203 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114204 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114205 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114206 + *
114207 + * Usage:
114208 + * $ make
114209 + * $ make run
114210 + */
114211 +
114212 +#include "gcc-common.h"
114213 +#include "size_overflow.h"
114214 +
114215 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114216 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114217 +
114218 +// data for the size_overflow asm stmt
114219 +struct asm_data {
114220 + gimple def_stmt;
114221 + tree input;
114222 + tree output;
114223 +};
114224 +
114225 +#if BUILDING_GCC_VERSION <= 4007
114226 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114227 +#else
114228 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114229 +#endif
114230 +{
114231 + tree list;
114232 +#if BUILDING_GCC_VERSION <= 4007
114233 + VEC(tree, gc) *vec_list = NULL;
114234 +#else
114235 + vec<tree, va_gc> *vec_list = NULL;
114236 +#endif
114237 +
114238 + list = build_tree_list(NULL_TREE, string);
114239 + list = chainon(NULL_TREE, build_tree_list(list, io));
114240 +#if BUILDING_GCC_VERSION <= 4007
114241 + VEC_safe_push(tree, gc, vec_list, list);
114242 +#else
114243 + vec_safe_push(vec_list, list);
114244 +#endif
114245 + return vec_list;
114246 +}
114247 +
114248 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114249 +{
114250 + gimple asm_stmt;
114251 + gimple_stmt_iterator gsi;
114252 +#if BUILDING_GCC_VERSION <= 4007
114253 + VEC(tree, gc) *input, *output = NULL;
114254 +#else
114255 + vec<tree, va_gc> *input, *output = NULL;
114256 +#endif
114257 +
114258 + input = create_asm_io_list(str_input, asm_data->input);
114259 +
114260 + if (asm_data->output)
114261 + output = create_asm_io_list(str_output, asm_data->output);
114262 +
114263 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114264 + gsi = gsi_for_stmt(asm_data->def_stmt);
114265 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114266 +
114267 + if (asm_data->output)
114268 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114269 +}
114270 +
114271 +static void replace_call_lhs(const struct asm_data *asm_data)
114272 +{
114273 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114274 + update_stmt(asm_data->def_stmt);
114275 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114276 +}
114277 +
114278 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114279 +{
114280 + enum mark cur_fndecl_attr;
114281 + gimple phi = get_def_stmt(result);
114282 + unsigned int i, n = gimple_phi_num_args(phi);
114283 +
114284 + pointer_set_insert(visited, phi);
114285 + for (i = 0; i < n; i++) {
114286 + tree arg = gimple_phi_arg_def(phi, i);
114287 +
114288 + cur_fndecl_attr = search_intentional(visited, arg);
114289 + if (cur_fndecl_attr != MARK_NO)
114290 + return cur_fndecl_attr;
114291 + }
114292 + return MARK_NO;
114293 +}
114294 +
114295 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114296 +{
114297 + enum mark cur_fndecl_attr;
114298 + const_tree rhs1, rhs2;
114299 + gimple def_stmt = get_def_stmt(lhs);
114300 +
114301 + rhs1 = gimple_assign_rhs1(def_stmt);
114302 + rhs2 = gimple_assign_rhs2(def_stmt);
114303 +
114304 + cur_fndecl_attr = search_intentional(visited, rhs1);
114305 + if (cur_fndecl_attr != MARK_NO)
114306 + return cur_fndecl_attr;
114307 + return search_intentional(visited, rhs2);
114308 +}
114309 +
114310 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114311 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114312 +{
114313 + const_gimple def_stmt;
114314 +
114315 + if (TREE_CODE(lhs) != SSA_NAME)
114316 + return get_intentional_attr_type(lhs);
114317 +
114318 + def_stmt = get_def_stmt(lhs);
114319 + if (!def_stmt)
114320 + return MARK_NO;
114321 +
114322 + if (pointer_set_contains(visited, def_stmt))
114323 + return MARK_NO;
114324 +
114325 + switch (gimple_code(def_stmt)) {
114326 + case GIMPLE_NOP:
114327 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114328 + case GIMPLE_ASM:
114329 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114330 + return MARK_TURN_OFF;
114331 + return MARK_NO;
114332 + case GIMPLE_CALL:
114333 + return MARK_NO;
114334 + case GIMPLE_PHI:
114335 + return search_intentional_phi(visited, lhs);
114336 + case GIMPLE_ASSIGN:
114337 + switch (gimple_num_ops(def_stmt)) {
114338 + case 2:
114339 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114340 + case 3:
114341 + return search_intentional_binary(visited, lhs);
114342 + }
114343 + case GIMPLE_RETURN:
114344 + return MARK_NO;
114345 + default:
114346 + debug_gimple_stmt((gimple)def_stmt);
114347 + error("%s: unknown gimple code", __func__);
114348 + gcc_unreachable();
114349 + }
114350 +}
114351 +
114352 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114353 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114354 +{
114355 + const_tree fndecl;
114356 + struct pointer_set_t *visited;
114357 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114358 +
114359 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114360 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114361 + decl_attr = MARK_NOT_INTENTIONAL;
114362 + else if (is_yes_intentional_attr(fndecl, argnum))
114363 + decl_attr = MARK_YES;
114364 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114365 + return MARK_TURN_OFF;
114366 + }
114367 +
114368 + visited = pointer_set_create();
114369 + cur_fndecl_attr = search_intentional(visited, arg);
114370 + pointer_set_destroy(visited);
114371 +
114372 + switch (cur_fndecl_attr) {
114373 + case MARK_NO:
114374 + case MARK_TURN_OFF:
114375 + return cur_fndecl_attr;
114376 + default:
114377 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114378 + return MARK_YES;
114379 + }
114380 +}
114381 +
114382 +static void check_missing_size_overflow_attribute(tree var)
114383 +{
114384 + tree orig_fndecl;
114385 + unsigned int num;
114386 +
114387 + if (is_a_return_check(var))
114388 + orig_fndecl = DECL_ORIGIN(var);
114389 + else
114390 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114391 +
114392 + num = get_function_num(var, orig_fndecl);
114393 + if (num == CANNOT_FIND_ARG)
114394 + return;
114395 +
114396 + is_missing_function(orig_fndecl, num);
114397 +}
114398 +
114399 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114400 +{
114401 + gimple phi = get_def_stmt(result);
114402 + unsigned int i, n = gimple_phi_num_args(phi);
114403 +
114404 + pointer_set_insert(visited, phi);
114405 + for (i = 0; i < n; i++) {
114406 + tree arg = gimple_phi_arg_def(phi, i);
114407 +
114408 + search_size_overflow_attribute(visited, arg);
114409 + }
114410 +}
114411 +
114412 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114413 +{
114414 + const_gimple def_stmt = get_def_stmt(lhs);
114415 + tree rhs1, rhs2;
114416 +
114417 + rhs1 = gimple_assign_rhs1(def_stmt);
114418 + rhs2 = gimple_assign_rhs2(def_stmt);
114419 +
114420 + search_size_overflow_attribute(visited, rhs1);
114421 + search_size_overflow_attribute(visited, rhs2);
114422 +}
114423 +
114424 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114425 +{
114426 + const_gimple def_stmt;
114427 +
114428 + if (TREE_CODE(lhs) == PARM_DECL) {
114429 + check_missing_size_overflow_attribute(lhs);
114430 + return;
114431 + }
114432 +
114433 + def_stmt = get_def_stmt(lhs);
114434 + if (!def_stmt)
114435 + return;
114436 +
114437 + if (pointer_set_insert(visited, def_stmt))
114438 + return;
114439 +
114440 + switch (gimple_code(def_stmt)) {
114441 + case GIMPLE_NOP:
114442 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114443 + case GIMPLE_ASM:
114444 + return;
114445 + case GIMPLE_CALL: {
114446 + tree fndecl = gimple_call_fndecl(def_stmt);
114447 +
114448 + if (fndecl == NULL_TREE)
114449 + return;
114450 + check_missing_size_overflow_attribute(fndecl);
114451 + return;
114452 + }
114453 + case GIMPLE_PHI:
114454 + return search_size_overflow_attribute_phi(visited, lhs);
114455 + case GIMPLE_ASSIGN:
114456 + switch (gimple_num_ops(def_stmt)) {
114457 + case 2:
114458 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114459 + case 3:
114460 + return search_size_overflow_attribute_binary(visited, lhs);
114461 + }
114462 + default:
114463 + debug_gimple_stmt((gimple)def_stmt);
114464 + error("%s: unknown gimple code", __func__);
114465 + gcc_unreachable();
114466 + }
114467 +}
114468 +
114469 +// Search missing entries in the hash table (invoked from the gimple pass)
114470 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114471 +{
114472 + tree fndecl = NULL_TREE;
114473 + tree lhs;
114474 + struct pointer_set_t *visited;
114475 +
114476 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114477 + return;
114478 +
114479 + if (num == 0) {
114480 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114481 + lhs = gimple_return_retval(stmt);
114482 + } else {
114483 + gcc_assert(is_gimple_call(stmt));
114484 + lhs = gimple_call_arg(stmt, num - 1);
114485 + fndecl = gimple_call_fndecl(stmt);
114486 + }
114487 +
114488 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114489 + return;
114490 +
114491 + visited = pointer_set_create();
114492 + search_size_overflow_attribute(visited, lhs);
114493 + pointer_set_destroy(visited);
114494 +}
114495 +
114496 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114497 +{
114498 + gimple_stmt_iterator gsi;
114499 + gimple assign;
114500 +
114501 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114502 + gsi = gsi_for_stmt(stmt);
114503 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114504 + asm_data->def_stmt = assign;
114505 +
114506 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114507 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114508 + if (gimple_code(stmt) == GIMPLE_RETURN)
114509 + gimple_return_set_retval(stmt, asm_data->output);
114510 + else
114511 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114512 + update_stmt(stmt);
114513 +}
114514 +
114515 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114516 +{
114517 + const char *fn_name;
114518 + char *asm_comment;
114519 + unsigned int len;
114520 +
114521 + if (argnum == 0)
114522 + fn_name = DECL_NAME_POINTER(current_function_decl);
114523 + else
114524 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114525 +
114526 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114527 + gcc_assert(len > 0);
114528 +
114529 + return asm_comment;
114530 +}
114531 +
114532 +static const char *convert_mark_to_str(enum mark mark)
114533 +{
114534 + switch (mark) {
114535 + case MARK_NO:
114536 + return OK_ASM_STR;
114537 + case MARK_YES:
114538 + case MARK_NOT_INTENTIONAL:
114539 + return YES_ASM_STR;
114540 + case MARK_TURN_OFF:
114541 + return TURN_OFF_ASM_STR;
114542 + }
114543 +
114544 + gcc_unreachable();
114545 +}
114546 +
114547 +/* Create the input of the size_overflow asm stmt.
114548 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114549 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114550 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114551 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114552 + */
114553 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114554 +{
114555 + if (!asm_data->def_stmt) {
114556 + asm_data->input = NULL_TREE;
114557 + return;
114558 + }
114559 +
114560 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114561 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114562 +
114563 + switch (gimple_code(asm_data->def_stmt)) {
114564 + case GIMPLE_ASSIGN:
114565 + case GIMPLE_CALL:
114566 + replace_call_lhs(asm_data);
114567 + break;
114568 + case GIMPLE_PHI:
114569 + create_output_from_phi(stmt, argnum, asm_data);
114570 + break;
114571 + case GIMPLE_NOP: {
114572 + enum mark mark;
114573 + const char *mark_str;
114574 + char *asm_comment;
114575 +
114576 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114577 +
114578 + asm_data->input = asm_data->output;
114579 + asm_data->output = NULL;
114580 + asm_data->def_stmt = stmt;
114581 +
114582 + mark_str = convert_mark_to_str(mark);
114583 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114584 +
114585 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114586 + free(asm_comment);
114587 + asm_data->input = NULL_TREE;
114588 + break;
114589 + }
114590 + case GIMPLE_ASM:
114591 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114592 + asm_data->input = NULL_TREE;
114593 + break;
114594 + }
114595 + default:
114596 + debug_gimple_stmt(asm_data->def_stmt);
114597 + gcc_unreachable();
114598 + }
114599 +}
114600 +
114601 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114602 + * is of the right kind create the appropriate size_overflow asm stmts:
114603 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114604 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114605 + */
114606 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114607 +{
114608 + struct asm_data asm_data;
114609 + const char *mark_str;
114610 + char *asm_comment;
114611 + enum mark mark;
114612 +
114613 + if (is_gimple_constant(output_node))
114614 + return;
114615 +
114616 + asm_data.output = output_node;
114617 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114618 + if (mark != MARK_TURN_OFF)
114619 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114620 +
114621 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114622 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114623 + return;
114624 +
114625 + create_asm_input(stmt, argnum, &asm_data);
114626 + if (asm_data.input == NULL_TREE)
114627 + return;
114628 +
114629 + mark_str = convert_mark_to_str(mark);
114630 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114631 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114632 + free(asm_comment);
114633 +}
114634 +
114635 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114636 +static bool create_mark_asm(gimple stmt, enum mark mark)
114637 +{
114638 + struct asm_data asm_data;
114639 + const char *asm_str;
114640 +
114641 + switch (mark) {
114642 + case MARK_TURN_OFF:
114643 + asm_str = TURN_OFF_ASM_STR;
114644 + break;
114645 + case MARK_NOT_INTENTIONAL:
114646 + case MARK_YES:
114647 + asm_str = YES_ASM_STR;
114648 + break;
114649 + default:
114650 + gcc_unreachable();
114651 + }
114652 +
114653 + asm_data.def_stmt = stmt;
114654 + asm_data.output = gimple_call_lhs(stmt);
114655 +
114656 + if (asm_data.output == NULL_TREE) {
114657 + asm_data.input = gimple_call_arg(stmt, 0);
114658 + if (is_gimple_constant(asm_data.input))
114659 + return false;
114660 + asm_data.output = NULL;
114661 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114662 + return true;
114663 + }
114664 +
114665 + create_asm_input(stmt, 0, &asm_data);
114666 + gcc_assert(asm_data.input != NULL_TREE);
114667 +
114668 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114669 + return true;
114670 +}
114671 +
114672 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114673 +{
114674 + gimple def_stmt;
114675 +
114676 + def_stmt = get_def_stmt(lhs);
114677 + if (!def_stmt)
114678 + return;
114679 +
114680 + if (pointer_set_insert(visited, def_stmt))
114681 + return;
114682 +
114683 + switch (gimple_code(def_stmt)) {
114684 + case GIMPLE_NOP:
114685 + case GIMPLE_ASM:
114686 + case GIMPLE_CALL:
114687 + break;
114688 + case GIMPLE_PHI: {
114689 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114690 +
114691 + pointer_set_insert(visited, def_stmt);
114692 +
114693 + for (i = 0; i < n; i++) {
114694 + tree arg = gimple_phi_arg_def(def_stmt, i);
114695 +
114696 + walk_use_def_ptr(visited, arg);
114697 + }
114698 + }
114699 + case GIMPLE_ASSIGN:
114700 + switch (gimple_num_ops(def_stmt)) {
114701 + case 2:
114702 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114703 + return;
114704 + case 3:
114705 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114706 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114707 + return;
114708 + default:
114709 + return;
114710 + }
114711 + default:
114712 + debug_gimple_stmt((gimple)def_stmt);
114713 + error("%s: unknown gimple code", __func__);
114714 + gcc_unreachable();
114715 + }
114716 +}
114717 +
114718 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114719 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114720 +{
114721 + struct pointer_set_t *visited;
114722 +
114723 + visited = pointer_set_create();
114724 + walk_use_def_ptr(visited, arg);
114725 + pointer_set_destroy(visited);
114726 +}
114727 +
114728 +// Determine the return value and insert the asm stmt to mark the return stmt.
114729 +static void insert_asm_ret(gimple stmt)
114730 +{
114731 + tree ret;
114732 +
114733 + ret = gimple_return_retval(stmt);
114734 + create_size_overflow_asm(stmt, ret, 0);
114735 +}
114736 +
114737 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114738 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114739 +{
114740 + tree arg;
114741 + unsigned int argnum;
114742 +
114743 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114744 + gcc_assert(argnum != 0);
114745 + if (argnum == CANNOT_FIND_ARG)
114746 + return;
114747 +
114748 + arg = gimple_call_arg(stmt, argnum - 1);
114749 + gcc_assert(arg != NULL_TREE);
114750 +
114751 + // skip all ptr - ptr expressions
114752 + insert_mark_not_intentional_asm_at_ptr(arg);
114753 +
114754 + create_size_overflow_asm(stmt, arg, argnum);
114755 +}
114756 +
114757 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114758 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114759 +{
114760 + unsigned int argnum;
114761 + tree attr_value;
114762 +
114763 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114764 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114765 + argnums[argnum] = true;
114766 + }
114767 +}
114768 +
114769 +// If a function arg or the return value is in the hash table then set its index in the array.
114770 +static void set_argnum_hash(tree fndecl, bool *argnums)
114771 +{
114772 + unsigned int num;
114773 + const struct size_overflow_hash *hash;
114774 +
114775 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114776 + if (!hash)
114777 + return;
114778 +
114779 + for (num = 0; num <= MAX_PARAM; num++) {
114780 + if (!(hash->param & (1U << num)))
114781 + continue;
114782 +
114783 + argnums[num] = true;
114784 + }
114785 +}
114786 +
114787 +static bool is_all_the_argnums_empty(bool *argnums)
114788 +{
114789 + unsigned int i;
114790 +
114791 + for (i = 0; i <= MAX_PARAM; i++)
114792 + if (argnums[i])
114793 + return false;
114794 + return true;
114795 +}
114796 +
114797 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114798 +static void search_interesting_args(tree fndecl, bool *argnums)
114799 +{
114800 + const_tree attr;
114801 +
114802 + set_argnum_hash(fndecl, argnums);
114803 + if (!is_all_the_argnums_empty(argnums))
114804 + return;
114805 +
114806 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114807 + if (attr && TREE_VALUE(attr))
114808 + set_argnum_attribute(attr, argnums);
114809 +}
114810 +
114811 +/*
114812 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114813 + * on the callee function.
114814 + */
114815 +static bool is_mark_turn_off_attribute(gimple stmt)
114816 +{
114817 + enum mark mark;
114818 + const_tree fndecl = gimple_call_fndecl(stmt);
114819 +
114820 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114821 + if (mark == MARK_TURN_OFF)
114822 + return true;
114823 + return false;
114824 +}
114825 +
114826 +// 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
114827 +static void handle_interesting_function(gimple stmt)
114828 +{
114829 + unsigned int argnum;
114830 + tree fndecl;
114831 + bool orig_argnums[MAX_PARAM + 1] = {false};
114832 +
114833 + if (gimple_call_num_args(stmt) == 0)
114834 + return;
114835 + fndecl = gimple_call_fndecl(stmt);
114836 + if (fndecl == NULL_TREE)
114837 + return;
114838 + fndecl = DECL_ORIGIN(fndecl);
114839 +
114840 + if (is_mark_turn_off_attribute(stmt)) {
114841 + create_mark_asm(stmt, MARK_TURN_OFF);
114842 + return;
114843 + }
114844 +
114845 + search_interesting_args(fndecl, orig_argnums);
114846 +
114847 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114848 + if (orig_argnums[argnum])
114849 + insert_asm_arg(stmt, argnum);
114850 +}
114851 +
114852 +// 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
114853 +static void handle_interesting_ret(gimple stmt)
114854 +{
114855 + bool orig_argnums[MAX_PARAM + 1] = {false};
114856 +
114857 + search_interesting_args(current_function_decl, orig_argnums);
114858 +
114859 + if (orig_argnums[0])
114860 + insert_asm_ret(stmt);
114861 +}
114862 +
114863 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114864 +static unsigned int search_interesting_functions(void)
114865 +{
114866 + basic_block bb;
114867 +
114868 + FOR_ALL_BB_FN(bb, cfun) {
114869 + gimple_stmt_iterator gsi;
114870 +
114871 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114872 + gimple stmt = gsi_stmt(gsi);
114873 +
114874 + if (is_size_overflow_asm(stmt))
114875 + continue;
114876 +
114877 + if (is_gimple_call(stmt))
114878 + handle_interesting_function(stmt);
114879 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114880 + handle_interesting_ret(stmt);
114881 + }
114882 + }
114883 + return 0;
114884 +}
114885 +
114886 +/*
114887 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114888 + * this pass inserts asm stmts to mark the interesting args
114889 + * that the ipa pass will detect and insert the size overflow checks for.
114890 + */
114891 +#if BUILDING_GCC_VERSION >= 4009
114892 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114893 +#else
114894 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114895 + .pass = {
114896 +#endif
114897 + .type = GIMPLE_PASS,
114898 + .name = "insert_size_overflow_asm",
114899 +#if BUILDING_GCC_VERSION >= 4008
114900 + .optinfo_flags = OPTGROUP_NONE,
114901 +#endif
114902 +#if BUILDING_GCC_VERSION >= 4009
114903 + .has_gate = false,
114904 + .has_execute = true,
114905 +#else
114906 + .gate = NULL,
114907 + .execute = search_interesting_functions,
114908 + .sub = NULL,
114909 + .next = NULL,
114910 + .static_pass_number = 0,
114911 +#endif
114912 + .tv_id = TV_NONE,
114913 + .properties_required = PROP_cfg,
114914 + .properties_provided = 0,
114915 + .properties_destroyed = 0,
114916 + .todo_flags_start = 0,
114917 + .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
114918 +#if BUILDING_GCC_VERSION < 4009
114919 + }
114920 +#endif
114921 +};
114922 +
114923 +#if BUILDING_GCC_VERSION >= 4009
114924 +namespace {
114925 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114926 +public:
114927 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114928 + unsigned int execute() { return search_interesting_functions(); }
114929 +};
114930 +}
114931 +#endif
114932 +
114933 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114934 +{
114935 +#if BUILDING_GCC_VERSION >= 4009
114936 + return new insert_size_overflow_asm_pass();
114937 +#else
114938 + return &insert_size_overflow_asm_pass.pass;
114939 +#endif
114940 +}
114941 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
114942 new file mode 100644
114943 index 0000000..73f0a12
114944 --- /dev/null
114945 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114946 @@ -0,0 +1,943 @@
114947 +/*
114948 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114949 + * Licensed under the GPL v2, or (at your option) v3
114950 + *
114951 + * Homepage:
114952 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114953 + *
114954 + * Documentation:
114955 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114956 + *
114957 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114958 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114959 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114960 + *
114961 + * Usage:
114962 + * $ make
114963 + * $ make run
114964 + */
114965 +
114966 +#include "gcc-common.h"
114967 +#include "size_overflow.h"
114968 +
114969 +#define MIN_CHECK true
114970 +#define MAX_CHECK false
114971 +
114972 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114973 +{
114974 + const_tree type;
114975 + tree new_type;
114976 +
114977 + gcc_assert(node != NULL_TREE);
114978 +
114979 + type = TREE_TYPE(node);
114980 +
114981 + if (pointer_set_contains(visited->my_stmts, stmt))
114982 + return TREE_TYPE(node);
114983 +
114984 + switch (TYPE_MODE(type)) {
114985 + case QImode:
114986 + new_type = size_overflow_type_HI;
114987 + break;
114988 + case HImode:
114989 + new_type = size_overflow_type_SI;
114990 + break;
114991 + case SImode:
114992 + new_type = size_overflow_type_DI;
114993 + break;
114994 + case DImode:
114995 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114996 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114997 + else
114998 + new_type = size_overflow_type_TI;
114999 + break;
115000 + case TImode:
115001 + gcc_assert(!TYPE_UNSIGNED(type));
115002 + new_type = size_overflow_type_TI;
115003 + break;
115004 + default:
115005 + debug_tree((tree)node);
115006 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
115007 + gcc_unreachable();
115008 + }
115009 +
115010 + if (TYPE_QUALS(type) != 0)
115011 + return build_qualified_type(new_type, TYPE_QUALS(type));
115012 + return new_type;
115013 +}
115014 +
115015 +static tree get_lhs(const_gimple stmt)
115016 +{
115017 + switch (gimple_code(stmt)) {
115018 + case GIMPLE_ASSIGN:
115019 + case GIMPLE_CALL:
115020 + return gimple_get_lhs(stmt);
115021 + case GIMPLE_PHI:
115022 + return gimple_phi_result(stmt);
115023 + default:
115024 + return NULL_TREE;
115025 + }
115026 +}
115027 +
115028 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
115029 +{
115030 + gimple_stmt_iterator gsi;
115031 + tree lhs;
115032 + gimple new_stmt;
115033 +
115034 + if (rhs == NULL_TREE)
115035 + return NULL_TREE;
115036 +
115037 + gsi = gsi_for_stmt(stmt);
115038 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115039 + pointer_set_insert(visited->my_stmts, new_stmt);
115040 +
115041 + lhs = get_lhs(new_stmt);
115042 + gcc_assert(lhs != NULL_TREE);
115043 + return lhs;
115044 +}
115045 +
115046 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
115047 +{
115048 + tree lhs, dst_type;
115049 + gimple_stmt_iterator gsi;
115050 +
115051 + if (rhs1 == NULL_TREE) {
115052 + debug_gimple_stmt(oldstmt);
115053 + error("%s: rhs1 is NULL_TREE", __func__);
115054 + gcc_unreachable();
115055 + }
115056 +
115057 + switch (gimple_code(oldstmt)) {
115058 + case GIMPLE_ASM:
115059 + lhs = rhs1;
115060 + break;
115061 + case GIMPLE_CALL:
115062 + case GIMPLE_ASSIGN:
115063 + lhs = gimple_get_lhs(oldstmt);
115064 + break;
115065 + default:
115066 + debug_gimple_stmt(oldstmt);
115067 + gcc_unreachable();
115068 + }
115069 +
115070 + gsi = gsi_for_stmt(oldstmt);
115071 + pointer_set_insert(visited->stmts, oldstmt);
115072 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115073 + basic_block next_bb, cur_bb;
115074 + const_edge e;
115075 +
115076 + gcc_assert(before == false);
115077 + gcc_assert(stmt_can_throw_internal(oldstmt));
115078 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115079 + gcc_assert(!gsi_end_p(gsi));
115080 +
115081 + cur_bb = gimple_bb(oldstmt);
115082 + next_bb = cur_bb->next_bb;
115083 + e = find_edge(cur_bb, next_bb);
115084 + gcc_assert(e != NULL);
115085 + gcc_assert(e->flags & EDGE_FALLTHRU);
115086 +
115087 + gsi = gsi_after_labels(next_bb);
115088 + gcc_assert(!gsi_end_p(gsi));
115089 +
115090 + before = true;
115091 + oldstmt = gsi_stmt(gsi);
115092 + }
115093 +
115094 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
115095 +
115096 + if (is_gimple_constant(rhs1))
115097 + return cast_a_tree(dst_type, rhs1);
115098 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
115099 +}
115100 +
115101 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115102 +{
115103 + gimple stmt;
115104 + gimple_stmt_iterator gsi;
115105 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115106 +
115107 + if (pointer_set_contains(visited->my_stmts, oldstmt))
115108 + return lhs;
115109 +
115110 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115111 + rhs1 = gimple_assign_rhs1(oldstmt);
115112 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115113 + }
115114 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115115 + rhs2 = gimple_assign_rhs2(oldstmt);
115116 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115117 + }
115118 +
115119 + stmt = gimple_copy(oldstmt);
115120 + gimple_set_location(stmt, gimple_location(oldstmt));
115121 + pointer_set_insert(visited->my_stmts, stmt);
115122 +
115123 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115124 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115125 +
115126 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115127 +
115128 + new_var = create_new_var(size_overflow_type);
115129 + new_var = make_ssa_name(new_var, stmt);
115130 + gimple_assign_set_lhs(stmt, new_var);
115131 +
115132 + if (rhs1 != NULL_TREE)
115133 + gimple_assign_set_rhs1(stmt, rhs1);
115134 +
115135 + if (rhs2 != NULL_TREE)
115136 + gimple_assign_set_rhs2(stmt, rhs2);
115137 +#if BUILDING_GCC_VERSION >= 4006
115138 + if (rhs3 != NULL_TREE)
115139 + gimple_assign_set_rhs3(stmt, rhs3);
115140 +#endif
115141 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115142 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115143 +
115144 + gsi = gsi_for_stmt(oldstmt);
115145 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115146 + update_stmt(stmt);
115147 + pointer_set_insert(visited->stmts, oldstmt);
115148 + return gimple_assign_lhs(stmt);
115149 +}
115150 +
115151 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115152 +{
115153 + gimple assign;
115154 + gimple_stmt_iterator gsi;
115155 + basic_block first_bb;
115156 +
115157 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115158 +
115159 + if (bb->index == 0) {
115160 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115161 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115162 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115163 + bb = first_bb;
115164 + }
115165 +
115166 + gsi = gsi_after_labels(bb);
115167 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115168 + pointer_set_insert(visited->my_stmts, assign);
115169 +
115170 + return gimple_assign_lhs(assign);
115171 +}
115172 +
115173 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115174 +{
115175 + gimple_stmt_iterator gsi;
115176 + gimple assign, def_stmt = get_def_stmt(new_arg);
115177 +
115178 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115179 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115180 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115181 + } else {
115182 + gsi = gsi_for_stmt(def_stmt);
115183 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115184 + }
115185 +
115186 + pointer_set_insert(visited->my_stmts, assign);
115187 + return gimple_assign_lhs(assign);
115188 +}
115189 +
115190 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115191 +{
115192 + basic_block bb;
115193 + gimple_stmt_iterator gsi;
115194 + const_gimple def_stmt;
115195 + gimple assign;
115196 +
115197 + def_stmt = get_def_stmt(arg);
115198 + bb = gimple_bb(def_stmt);
115199 + gcc_assert(bb->index != 0);
115200 + gsi = gsi_after_labels(bb);
115201 +
115202 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115203 + pointer_set_insert(visited->my_stmts, assign);
115204 + return gimple_assign_lhs(assign);
115205 +}
115206 +
115207 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115208 +{
115209 + tree size_overflow_type;
115210 + tree arg;
115211 + const_gimple def_stmt;
115212 +
115213 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115214 + return new_arg;
115215 +
115216 + arg = gimple_phi_arg_def(oldstmt, i);
115217 + def_stmt = get_def_stmt(arg);
115218 + gcc_assert(def_stmt != NULL);
115219 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115220 +
115221 + switch (gimple_code(def_stmt)) {
115222 + case GIMPLE_PHI:
115223 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115224 + case GIMPLE_NOP: {
115225 + basic_block bb;
115226 +
115227 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115228 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115229 + }
115230 + case GIMPLE_ASM: {
115231 + gimple_stmt_iterator gsi;
115232 + gimple assign, stmt = get_def_stmt(arg);
115233 +
115234 + gsi = gsi_for_stmt(stmt);
115235 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115236 + pointer_set_insert(visited->my_stmts, assign);
115237 + return gimple_assign_lhs(assign);
115238 + }
115239 + default:
115240 + gcc_assert(new_arg != NULL_TREE);
115241 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115242 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115243 + }
115244 +}
115245 +
115246 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115247 +{
115248 + basic_block bb;
115249 + gimple phi;
115250 + gimple_seq seq;
115251 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115252 +
115253 + bb = gsi_bb(gsi);
115254 +
115255 + if (result == NULL_TREE) {
115256 + tree old_result = gimple_phi_result(oldstmt);
115257 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115258 +
115259 + result = create_new_var(size_overflow_type);
115260 + }
115261 +
115262 + phi = create_phi_node(result, bb);
115263 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115264 + seq = phi_nodes(bb);
115265 + gsi = gsi_last(seq);
115266 + gsi_remove(&gsi, false);
115267 +
115268 + gsi = gsi_for_stmt(oldstmt);
115269 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115270 + gimple_set_bb(phi, bb);
115271 + return phi;
115272 +}
115273 +
115274 +#if BUILDING_GCC_VERSION <= 4007
115275 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115276 +#else
115277 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115278 +#endif
115279 +{
115280 + gimple new_phi;
115281 + unsigned int i;
115282 + tree arg, result;
115283 + location_t loc = gimple_location(oldstmt);
115284 +
115285 +#if BUILDING_GCC_VERSION <= 4007
115286 + gcc_assert(!VEC_empty(tree, *args));
115287 +#else
115288 + gcc_assert(!args->is_empty());
115289 +#endif
115290 +
115291 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115292 + result = gimple_phi_result(new_phi);
115293 + ssa_name_var = SSA_NAME_VAR(result);
115294 +
115295 +#if BUILDING_GCC_VERSION <= 4007
115296 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115297 +#else
115298 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115299 +#endif
115300 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115301 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115302 + }
115303 +
115304 +#if BUILDING_GCC_VERSION <= 4007
115305 + VEC_free(tree, heap, *args);
115306 +#else
115307 + vec_free(args);
115308 +#endif
115309 + update_stmt(new_phi);
115310 + pointer_set_insert(visited->my_stmts, new_phi);
115311 + return result;
115312 +}
115313 +
115314 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115315 +{
115316 + tree ssa_name_var = NULL_TREE;
115317 +#if BUILDING_GCC_VERSION <= 4007
115318 + VEC(tree, heap) *args = NULL;
115319 +#else
115320 + vec<tree, va_heap, vl_embed> *args = NULL;
115321 +#endif
115322 + gimple oldstmt = get_def_stmt(orig_result);
115323 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115324 +
115325 + pointer_set_insert(visited->stmts, oldstmt);
115326 + for (i = 0; i < len; i++) {
115327 + tree arg, new_arg;
115328 +
115329 + arg = gimple_phi_arg_def(oldstmt, i);
115330 + new_arg = expand(visited, caller_node, arg);
115331 +
115332 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115333 + ssa_name_var = SSA_NAME_VAR(new_arg);
115334 +
115335 + if (is_gimple_constant(arg)) {
115336 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115337 +
115338 + new_arg = cast_a_tree(size_overflow_type, arg);
115339 + }
115340 +
115341 +#if BUILDING_GCC_VERSION <= 4007
115342 + VEC_safe_push(tree, heap, args, new_arg);
115343 +#else
115344 + vec_safe_push(args, new_arg);
115345 +#endif
115346 + }
115347 +
115348 +#if BUILDING_GCC_VERSION <= 4007
115349 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115350 +#else
115351 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115352 +#endif
115353 +}
115354 +
115355 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115356 +{
115357 + tree rhs1 = gimple_assign_rhs1(stmt);
115358 + tree lhs = gimple_assign_lhs(stmt);
115359 + const_tree rhs1_type = TREE_TYPE(rhs1);
115360 + const_tree lhs_type = TREE_TYPE(lhs);
115361 +
115362 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115363 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115364 +
115365 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115366 +}
115367 +
115368 +static bool skip_lhs_cast_check(const_gimple stmt)
115369 +{
115370 + const_tree rhs = gimple_assign_rhs1(stmt);
115371 + const_gimple def_stmt = get_def_stmt(rhs);
115372 +
115373 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115374 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115375 + return true;
115376 +
115377 + if (is_const_plus_unsigned_signed_truncation(rhs))
115378 + return true;
115379 +
115380 + return false;
115381 +}
115382 +
115383 +static tree create_string_param(tree string)
115384 +{
115385 + tree i_type, a_type;
115386 + const int length = TREE_STRING_LENGTH(string);
115387 +
115388 + gcc_assert(length > 0);
115389 +
115390 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115391 + a_type = build_array_type(char_type_node, i_type);
115392 +
115393 + TREE_TYPE(string) = a_type;
115394 + TREE_CONSTANT(string) = 1;
115395 + TREE_READONLY(string) = 1;
115396 +
115397 + return build1(ADDR_EXPR, ptr_type_node, string);
115398 +}
115399 +
115400 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115401 +{
115402 + gimple cond_stmt;
115403 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115404 +
115405 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115406 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115407 + update_stmt(cond_stmt);
115408 +}
115409 +
115410 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115411 +{
115412 + gimple func_stmt;
115413 + const_gimple def_stmt;
115414 + const_tree loc_line;
115415 + tree loc_file, ssa_name, current_func;
115416 + expanded_location xloc;
115417 + char *ssa_name_buf;
115418 + int len;
115419 + struct cgraph_edge *edge;
115420 + struct cgraph_node *callee_node;
115421 + int frequency;
115422 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115423 +
115424 + def_stmt = get_def_stmt(arg);
115425 + xloc = expand_location(gimple_location(def_stmt));
115426 +
115427 + if (!gimple_has_location(def_stmt)) {
115428 + xloc = expand_location(gimple_location(stmt));
115429 + if (!gimple_has_location(stmt))
115430 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115431 + }
115432 +
115433 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115434 +
115435 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115436 + loc_file = create_string_param(loc_file);
115437 +
115438 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115439 + current_func = create_string_param(current_func);
115440 +
115441 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115442 + call_count++;
115443 + 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);
115444 + gcc_assert(len > 0);
115445 + ssa_name = build_string(len + 1, ssa_name_buf);
115446 + free(ssa_name_buf);
115447 + ssa_name = create_string_param(ssa_name);
115448 +
115449 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115450 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115451 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115452 +
115453 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115454 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115455 +
115456 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115457 + gcc_assert(edge != NULL);
115458 +}
115459 +
115460 +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)
115461 +{
115462 + basic_block cond_bb, join_bb, bb_true;
115463 + edge e;
115464 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115465 +
115466 + cond_bb = gimple_bb(stmt);
115467 + if (before)
115468 + gsi_prev(&gsi);
115469 + if (gsi_end_p(gsi))
115470 + e = split_block_after_labels(cond_bb);
115471 + else
115472 + e = split_block(cond_bb, gsi_stmt(gsi));
115473 + cond_bb = e->src;
115474 + join_bb = e->dest;
115475 + e->flags = EDGE_FALSE_VALUE;
115476 + e->probability = REG_BR_PROB_BASE;
115477 +
115478 + bb_true = create_empty_bb(cond_bb);
115479 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115480 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115481 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115482 +
115483 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115484 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115485 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115486 +
115487 + if (current_loops != NULL) {
115488 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115489 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115490 + }
115491 +
115492 + insert_cond(cond_bb, arg, cond_code, type_value);
115493 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115494 +
115495 +// print_the_code_insertions(stmt);
115496 +}
115497 +
115498 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115499 +{
115500 + const_tree rhs_type = TREE_TYPE(rhs);
115501 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115502 +
115503 + gcc_assert(rhs_type != NULL_TREE);
115504 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115505 + return;
115506 +
115507 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115508 +
115509 + if (is_const_plus_unsigned_signed_truncation(rhs))
115510 + return;
115511 +
115512 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115513 + // typemax (-1) < typemin (0)
115514 + if (TREE_OVERFLOW(type_max))
115515 + return;
115516 +
115517 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115518 +
115519 + cast_rhs_type = TREE_TYPE(cast_rhs);
115520 + type_max_type = TREE_TYPE(type_max);
115521 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115522 +
115523 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115524 +
115525 + // special case: get_size_overflow_type(), 32, u64->s
115526 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115527 + return;
115528 +
115529 + type_min_type = TREE_TYPE(type_min);
115530 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115531 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115532 +}
115533 +
115534 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115535 +{
115536 + bool cast_lhs, cast_rhs;
115537 + tree lhs = gimple_assign_lhs(stmt);
115538 + tree rhs = gimple_assign_rhs1(stmt);
115539 + const_tree lhs_type = TREE_TYPE(lhs);
115540 + const_tree rhs_type = TREE_TYPE(rhs);
115541 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115542 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115543 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115544 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115545 +
115546 + static bool check_lhs[3][4] = {
115547 + // ss su us uu
115548 + { false, true, true, false }, // lhs > rhs
115549 + { false, false, false, false }, // lhs = rhs
115550 + { true, true, true, true }, // lhs < rhs
115551 + };
115552 +
115553 + static bool check_rhs[3][4] = {
115554 + // ss su us uu
115555 + { true, false, true, true }, // lhs > rhs
115556 + { true, false, true, true }, // lhs = rhs
115557 + { true, false, true, true }, // lhs < rhs
115558 + };
115559 +
115560 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115561 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115562 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115563 +
115564 + if (lhs_size > rhs_size) {
115565 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115566 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115567 + } else if (lhs_size == rhs_size) {
115568 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115569 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115570 + } else {
115571 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115572 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115573 + }
115574 +
115575 + if (!cast_lhs && !cast_rhs)
115576 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115577 +
115578 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115579 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115580 +
115581 + if (cast_rhs)
115582 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115583 +
115584 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115585 +}
115586 +
115587 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115588 +{
115589 + enum tree_code rhs_code;
115590 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115591 +
115592 + if (pointer_set_contains(visited->my_stmts, stmt))
115593 + return lhs;
115594 +
115595 + rhs1 = gimple_assign_rhs1(stmt);
115596 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115597 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115598 +
115599 + new_rhs1 = expand(visited, caller_node, rhs1);
115600 +
115601 + if (new_rhs1 == NULL_TREE)
115602 + return create_cast_assign(visited, stmt);
115603 +
115604 + if (pointer_set_contains(visited->no_cast_check, stmt))
115605 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115606 +
115607 + rhs_code = gimple_assign_rhs_code(stmt);
115608 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115609 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115610 +
115611 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115612 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115613 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115614 + }
115615 +
115616 + if (!gimple_assign_cast_p(stmt))
115617 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115618 +
115619 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115620 +}
115621 +
115622 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115623 +{
115624 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115625 + gimple def_stmt = get_def_stmt(lhs);
115626 +
115627 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115628 + rhs1 = gimple_assign_rhs1(def_stmt);
115629 +
115630 + if (is_gimple_constant(rhs1))
115631 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115632 +
115633 + switch (TREE_CODE(rhs1)) {
115634 + case SSA_NAME: {
115635 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115636 +
115637 + if (gimple_assign_cast_p(stmt))
115638 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115639 + return ret;
115640 + }
115641 + case ARRAY_REF:
115642 + case BIT_FIELD_REF:
115643 + case ADDR_EXPR:
115644 + case COMPONENT_REF:
115645 + case INDIRECT_REF:
115646 +#if BUILDING_GCC_VERSION >= 4006
115647 + case MEM_REF:
115648 +#endif
115649 + case TARGET_MEM_REF:
115650 + case VIEW_CONVERT_EXPR:
115651 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115652 + case PARM_DECL:
115653 + case VAR_DECL:
115654 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115655 +
115656 + default:
115657 + debug_gimple_stmt(def_stmt);
115658 + debug_tree(rhs1);
115659 + gcc_unreachable();
115660 + }
115661 +}
115662 +
115663 +static void __unused print_the_code_insertions(const_gimple stmt)
115664 +{
115665 + location_t loc = gimple_location(stmt);
115666 +
115667 + inform(loc, "Integer size_overflow check applied here.");
115668 +}
115669 +
115670 +static bool is_from_cast(const_tree node)
115671 +{
115672 + gimple def_stmt = get_def_stmt(node);
115673 +
115674 + if (!def_stmt)
115675 + return false;
115676 +
115677 + if (gimple_assign_cast_p(def_stmt))
115678 + return true;
115679 +
115680 + return false;
115681 +}
115682 +
115683 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115684 +static bool is_a_ptr_minus(gimple stmt)
115685 +{
115686 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115687 +
115688 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115689 + return false;
115690 +
115691 + rhs1 = gimple_assign_rhs1(stmt);
115692 + if (!is_from_cast(rhs1))
115693 + return false;
115694 +
115695 + rhs2 = gimple_assign_rhs2(stmt);
115696 + if (!is_from_cast(rhs2))
115697 + return false;
115698 +
115699 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115700 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115701 +
115702 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115703 + return false;
115704 +
115705 + return true;
115706 +}
115707 +
115708 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115709 +{
115710 + enum intentional_overflow_type res;
115711 + tree rhs1, rhs2, new_lhs;
115712 + gimple def_stmt = get_def_stmt(lhs);
115713 + tree new_rhs1 = NULL_TREE;
115714 + tree new_rhs2 = NULL_TREE;
115715 +
115716 + if (is_a_ptr_minus(def_stmt))
115717 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115718 +
115719 + rhs1 = gimple_assign_rhs1(def_stmt);
115720 + rhs2 = gimple_assign_rhs2(def_stmt);
115721 +
115722 + /* no DImode/TImode division in the 32/64 bit kernel */
115723 + switch (gimple_assign_rhs_code(def_stmt)) {
115724 + case RDIV_EXPR:
115725 + case TRUNC_DIV_EXPR:
115726 + case CEIL_DIV_EXPR:
115727 + case FLOOR_DIV_EXPR:
115728 + case ROUND_DIV_EXPR:
115729 + case TRUNC_MOD_EXPR:
115730 + case CEIL_MOD_EXPR:
115731 + case FLOOR_MOD_EXPR:
115732 + case ROUND_MOD_EXPR:
115733 + case EXACT_DIV_EXPR:
115734 + case POINTER_PLUS_EXPR:
115735 + case BIT_AND_EXPR:
115736 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115737 + default:
115738 + break;
115739 + }
115740 +
115741 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115742 + if (new_lhs != NULL_TREE)
115743 + return new_lhs;
115744 +
115745 + if (TREE_CODE(rhs1) == SSA_NAME)
115746 + new_rhs1 = expand(visited, caller_node, rhs1);
115747 + if (TREE_CODE(rhs2) == SSA_NAME)
115748 + new_rhs2 = expand(visited, caller_node, rhs2);
115749 +
115750 + res = add_mul_intentional_overflow(def_stmt);
115751 + if (res != NO_INTENTIONAL_OVERFLOW) {
115752 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115753 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115754 + return new_lhs;
115755 + }
115756 +
115757 + if (skip_expr_on_double_type(def_stmt)) {
115758 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115759 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115760 + return new_lhs;
115761 + }
115762 +
115763 + if (is_a_neg_overflow(def_stmt, rhs2))
115764 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115765 + if (is_a_neg_overflow(def_stmt, rhs1))
115766 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115767 +
115768 +
115769 + if (is_a_constant_overflow(def_stmt, rhs2))
115770 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115771 + if (is_a_constant_overflow(def_stmt, rhs1))
115772 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115773 +
115774 + // the const is between 0 and (signed) MAX
115775 + if (is_gimple_constant(rhs1))
115776 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115777 + if (is_gimple_constant(rhs2))
115778 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115779 +
115780 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115781 +}
115782 +
115783 +#if BUILDING_GCC_VERSION >= 4006
115784 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115785 +{
115786 + if (is_gimple_constant(rhs))
115787 + return cast_a_tree(size_overflow_type, rhs);
115788 + if (TREE_CODE(rhs) != SSA_NAME)
115789 + return NULL_TREE;
115790 + return expand(visited, caller_node, rhs);
115791 +}
115792 +
115793 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115794 +{
115795 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115796 + gimple def_stmt = get_def_stmt(lhs);
115797 +
115798 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115799 +
115800 + rhs1 = gimple_assign_rhs1(def_stmt);
115801 + rhs2 = gimple_assign_rhs2(def_stmt);
115802 + rhs3 = gimple_assign_rhs3(def_stmt);
115803 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115804 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115805 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115806 +
115807 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115808 +}
115809 +#endif
115810 +
115811 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115812 +{
115813 + gimple_stmt_iterator gsi;
115814 + gimple next_stmt = NULL;
115815 +
115816 + gsi = gsi_for_stmt(stmt);
115817 +
115818 + do {
115819 + gsi_next(&gsi);
115820 + next_stmt = gsi_stmt(gsi);
115821 +
115822 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115823 + return NULL_TREE;
115824 +
115825 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115826 + break;
115827 +
115828 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115829 + } while (!gsi_end_p(gsi));
115830 +
115831 + gcc_assert(next_stmt);
115832 + return get_lhs(next_stmt);
115833 +}
115834 +
115835 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115836 +{
115837 + gimple_stmt_iterator gsi;
115838 + enum gimple_code code = gimple_code(def_stmt);
115839 +
115840 + if (code == GIMPLE_ASM)
115841 + return NULL_TREE;
115842 +
115843 + gsi = gsi_for_stmt(def_stmt);
115844 + gsi_next(&gsi);
115845 +
115846 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115847 + return NULL_TREE;
115848 + return get_my_stmt_lhs(visited, def_stmt);
115849 +}
115850 +
115851 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115852 +{
115853 + gimple def_stmt;
115854 +
115855 + def_stmt = get_def_stmt(lhs);
115856 +
115857 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115858 + return NULL_TREE;
115859 +
115860 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115861 + return lhs;
115862 +
115863 + if (pointer_set_contains(visited->stmts, def_stmt))
115864 + return expand_visited(visited, def_stmt);
115865 +
115866 + switch (gimple_code(def_stmt)) {
115867 + case GIMPLE_PHI:
115868 + return handle_phi(visited, caller_node, lhs);
115869 + case GIMPLE_CALL:
115870 + case GIMPLE_ASM:
115871 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115872 + case GIMPLE_ASSIGN:
115873 + switch (gimple_num_ops(def_stmt)) {
115874 + case 2:
115875 + return handle_unary_ops(visited, caller_node, def_stmt);
115876 + case 3:
115877 + return handle_binary_ops(visited, caller_node, lhs);
115878 +#if BUILDING_GCC_VERSION >= 4006
115879 + case 4:
115880 + return handle_ternary_ops(visited, caller_node, lhs);
115881 +#endif
115882 + }
115883 + default:
115884 + debug_gimple_stmt(def_stmt);
115885 + error("%s: unknown gimple code", __func__);
115886 + gcc_unreachable();
115887 + }
115888 +}
115889 +
115890 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
115891 new file mode 100644
115892 index 0000000..df50164
115893 --- /dev/null
115894 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115895 @@ -0,0 +1,1141 @@
115896 +/*
115897 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115898 + * Licensed under the GPL v2, or (at your option) v3
115899 + *
115900 + * Homepage:
115901 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115902 + *
115903 + * Documentation:
115904 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115905 + *
115906 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115907 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115908 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115909 + *
115910 + * Usage:
115911 + * $ make
115912 + * $ make run
115913 + */
115914 +
115915 +#include "gcc-common.h"
115916 +#include "size_overflow.h"
115917 +
115918 +#define VEC_LEN 128
115919 +#define RET_CHECK NULL_TREE
115920 +#define WRONG_NODE 32
115921 +#define NOT_INTENTIONAL_ASM NULL
115922 +
115923 +unsigned int call_count;
115924 +
115925 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115926 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115927 +
115928 +struct visited_fns {
115929 + struct visited_fns *next;
115930 + const_tree fndecl;
115931 + unsigned int num;
115932 + const_gimple first_stmt;
115933 +};
115934 +
115935 +struct next_cgraph_node {
115936 + struct next_cgraph_node *next;
115937 + struct cgraph_node *current_function;
115938 + tree callee_fndecl;
115939 + unsigned int num;
115940 +};
115941 +
115942 +// Don't want to duplicate entries in next_cgraph_node
115943 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115944 +{
115945 + const_tree new_callee_fndecl;
115946 + struct next_cgraph_node *cur_node;
115947 +
115948 + if (fndecl == RET_CHECK)
115949 + new_callee_fndecl = NODE_DECL(node);
115950 + else
115951 + new_callee_fndecl = fndecl;
115952 +
115953 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115954 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115955 + continue;
115956 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115957 + continue;
115958 + if (num == cur_node->num)
115959 + return true;
115960 + }
115961 + return false;
115962 +}
115963 +
115964 +/* Add a next_cgraph_node into the list for handle_function().
115965 + * handle_function() iterates over all the next cgraph nodes and
115966 + * starts the overflow check insertion process.
115967 + */
115968 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115969 +{
115970 + struct next_cgraph_node *new_node;
115971 +
115972 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115973 + return head;
115974 +
115975 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115976 + new_node->current_function = node;
115977 + new_node->next = NULL;
115978 + new_node->num = num;
115979 + if (fndecl == RET_CHECK)
115980 + new_node->callee_fndecl = NODE_DECL(node);
115981 + else
115982 + new_node->callee_fndecl = fndecl;
115983 +
115984 + if (!head)
115985 + return new_node;
115986 +
115987 + new_node->next = head;
115988 + return new_node;
115989 +}
115990 +
115991 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115992 +{
115993 + struct cgraph_edge *e;
115994 +
115995 + if (num == 0)
115996 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115997 +
115998 + for (e = node->callers; e; e = e->next_caller) {
115999 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116000 +
116001 + gcc_assert(fndecl != NULL_TREE);
116002 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116003 + }
116004 +
116005 + return head;
116006 +}
116007 +
116008 +struct missing_functions {
116009 + struct missing_functions *next;
116010 + const_tree node;
116011 + tree fndecl;
116012 +};
116013 +
116014 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116015 +{
116016 + struct missing_functions *new_function;
116017 +
116018 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116019 + new_function->node = node;
116020 + new_function->next = NULL;
116021 +
116022 + if (TREE_CODE(node) == FUNCTION_DECL)
116023 + new_function->fndecl = node;
116024 + else
116025 + new_function->fndecl = current_function_decl;
116026 + gcc_assert(new_function->fndecl);
116027 +
116028 + if (!missing_fn_head)
116029 + return new_function;
116030 +
116031 + new_function->next = missing_fn_head;
116032 + return new_function;
116033 +}
116034 +
116035 +/* If the function is missing from the hash table and it is a static function
116036 + * then create a next_cgraph_node from it for handle_function()
116037 + */
116038 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116039 +{
116040 + unsigned int num;
116041 + const_tree orig_fndecl;
116042 + struct cgraph_node *next_node = NULL;
116043 +
116044 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116045 +
116046 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116047 + if (num == CANNOT_FIND_ARG)
116048 + return cnodes;
116049 +
116050 + if (!is_missing_function(orig_fndecl, num))
116051 + return cnodes;
116052 +
116053 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116054 + if (next_node && next_node->local.local)
116055 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116056 + return cnodes;
116057 +}
116058 +
116059 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116060 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116061 + */
116062 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116063 +{
116064 + unsigned int i;
116065 + tree node;
116066 + struct missing_functions *cur, *missing_fn_head = NULL;
116067 +
116068 +#if BUILDING_GCC_VERSION <= 4007
116069 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116070 +#else
116071 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116072 +#endif
116073 + switch (TREE_CODE(node)) {
116074 + case PARM_DECL:
116075 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116076 + break;
116077 + case FUNCTION_DECL:
116078 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116079 + break;
116080 + default:
116081 + break;
116082 + }
116083 + }
116084 +
116085 + while (missing_fn_head) {
116086 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116087 +
116088 + cur = missing_fn_head->next;
116089 + free(missing_fn_head);
116090 + missing_fn_head = cur;
116091 + }
116092 +
116093 + return cnodes;
116094 +}
116095 +
116096 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116097 +{
116098 + gimple phi = get_def_stmt(result);
116099 + unsigned int i, n = gimple_phi_num_args(phi);
116100 +
116101 + pointer_set_insert(visited, phi);
116102 + for (i = 0; i < n; i++) {
116103 + const_tree arg = gimple_phi_arg_def(phi, i);
116104 +
116105 + set_conditions(visited, interesting_conditions, arg);
116106 + }
116107 +}
116108 +
116109 +enum conditions {
116110 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
116111 +};
116112 +
116113 +// Search for constants, cast assignments and binary/ternary assignments
116114 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116115 +{
116116 + gimple def_stmt = get_def_stmt(lhs);
116117 +
116118 + if (is_gimple_constant(lhs)) {
116119 + interesting_conditions[FROM_CONST] = true;
116120 + return;
116121 + }
116122 +
116123 + if (!def_stmt)
116124 + return;
116125 +
116126 + if (pointer_set_contains(visited, def_stmt))
116127 + return;
116128 +
116129 + switch (gimple_code(def_stmt)) {
116130 + case GIMPLE_CALL:
116131 + if (lhs == gimple_call_lhs(def_stmt))
116132 + interesting_conditions[RET] = true;
116133 + return;
116134 + case GIMPLE_NOP:
116135 + case GIMPLE_ASM:
116136 + return;
116137 + case GIMPLE_PHI:
116138 + interesting_conditions[PHI] = true;
116139 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116140 + case GIMPLE_ASSIGN:
116141 + if (gimple_num_ops(def_stmt) == 2) {
116142 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116143 +
116144 + if (gimple_assign_cast_p(def_stmt))
116145 + interesting_conditions[CAST] = true;
116146 +
116147 + return set_conditions(visited, interesting_conditions, rhs);
116148 + } else {
116149 + interesting_conditions[NOT_UNARY] = true;
116150 + return;
116151 + }
116152 + default:
116153 + debug_gimple_stmt(def_stmt);
116154 + gcc_unreachable();
116155 + }
116156 +}
116157 +
116158 +// determine whether duplication will be necessary or not.
116159 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116160 +{
116161 + struct pointer_set_t *visited;
116162 +
116163 + if (gimple_assign_cast_p(cur_node->first_stmt))
116164 + interesting_conditions[CAST] = true;
116165 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116166 + interesting_conditions[NOT_UNARY] = true;
116167 +
116168 + visited = pointer_set_create();
116169 + set_conditions(visited, interesting_conditions, cur_node->node);
116170 + pointer_set_destroy(visited);
116171 +}
116172 +
116173 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116174 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116175 +{
116176 + gimple assign;
116177 + gimple_stmt_iterator gsi;
116178 +
116179 + // already removed
116180 + if (gimple_bb(asm_stmt) == NULL)
116181 + return;
116182 + gsi = gsi_for_stmt(asm_stmt);
116183 +
116184 + assign = gimple_build_assign(lhs, rhs);
116185 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116186 + SSA_NAME_DEF_STMT(lhs) = assign;
116187 +
116188 + gsi_remove(&gsi, true);
116189 +}
116190 +
116191 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116192 + * stmt is a return otherwise it is the callee function.
116193 + */
116194 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116195 +{
116196 + const_tree fndecl;
116197 +
116198 + if (argnum == 0)
116199 + fndecl = current_function_decl;
116200 + else
116201 + fndecl = gimple_call_fndecl(stmt);
116202 +
116203 + if (fndecl == NULL_TREE)
116204 + return NULL_TREE;
116205 +
116206 + return DECL_ORIGIN(fndecl);
116207 +}
116208 +
116209 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116210 +static bool skip_asm(const_tree arg)
116211 +{
116212 + gimple def_stmt = get_def_stmt(arg);
116213 +
116214 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116215 + return false;
116216 +
116217 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116218 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116219 +}
116220 +
116221 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116222 +{
116223 + gimple phi = get_def_stmt(result);
116224 + unsigned int i, n = gimple_phi_num_args(phi);
116225 +
116226 + pointer_set_insert(visited, phi);
116227 + for (i = 0; i < n; i++) {
116228 + tree arg = gimple_phi_arg_def(phi, i);
116229 +
116230 + walk_use_def(visited, cur_node, arg);
116231 + }
116232 +}
116233 +
116234 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116235 +{
116236 + gimple def_stmt = get_def_stmt(lhs);
116237 + tree rhs1, rhs2;
116238 +
116239 + rhs1 = gimple_assign_rhs1(def_stmt);
116240 + rhs2 = gimple_assign_rhs2(def_stmt);
116241 +
116242 + walk_use_def(visited, cur_node, rhs1);
116243 + walk_use_def(visited, cur_node, rhs2);
116244 +}
116245 +
116246 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116247 +{
116248 + unsigned int i;
116249 + tree element;
116250 + enum tree_code code;
116251 +
116252 + gcc_assert(node != NULL_TREE);
116253 +
116254 + if (is_gimple_constant(node))
116255 + return;
116256 +
116257 + code = TREE_CODE(node);
116258 + if (code == VAR_DECL) {
116259 + node = DECL_ORIGIN(node);
116260 + code = TREE_CODE(node);
116261 + }
116262 +
116263 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116264 + return;
116265 +
116266 +#if BUILDING_GCC_VERSION <= 4007
116267 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116268 +#else
116269 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116270 +#endif
116271 + if (operand_equal_p(node, element, 0))
116272 + return;
116273 + }
116274 +
116275 +#if BUILDING_GCC_VERSION <= 4007
116276 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116277 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116278 +#else
116279 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116280 + vec_safe_push(cur_node->last_nodes, node);
116281 +#endif
116282 +}
116283 +
116284 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116285 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116286 +{
116287 + if (!is_size_overflow_asm(stmt))
116288 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116289 +}
116290 +
116291 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116292 + * and component refs (for checking the intentional_overflow attribute).
116293 + */
116294 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116295 +{
116296 + const_gimple def_stmt;
116297 +
116298 + if (TREE_CODE(lhs) != SSA_NAME) {
116299 + insert_last_node(cur_node, lhs);
116300 + return;
116301 + }
116302 +
116303 + def_stmt = get_def_stmt(lhs);
116304 + if (!def_stmt)
116305 + return;
116306 +
116307 + if (pointer_set_insert(visited, def_stmt))
116308 + return;
116309 +
116310 + switch (gimple_code(def_stmt)) {
116311 + case GIMPLE_NOP:
116312 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116313 + case GIMPLE_ASM:
116314 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116315 + case GIMPLE_CALL: {
116316 + tree fndecl = gimple_call_fndecl(def_stmt);
116317 +
116318 + if (fndecl == NULL_TREE)
116319 + return;
116320 + insert_last_node(cur_node, fndecl);
116321 + return;
116322 + }
116323 + case GIMPLE_PHI:
116324 + return walk_use_def_phi(visited, cur_node, lhs);
116325 + case GIMPLE_ASSIGN:
116326 + switch (gimple_num_ops(def_stmt)) {
116327 + case 2:
116328 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116329 + case 3:
116330 + return walk_use_def_binary(visited, cur_node, lhs);
116331 + }
116332 + default:
116333 + debug_gimple_stmt((gimple)def_stmt);
116334 + error("%s: unknown gimple code", __func__);
116335 + gcc_unreachable();
116336 + }
116337 +}
116338 +
116339 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116340 +static void set_last_nodes(struct interesting_node *cur_node)
116341 +{
116342 + struct pointer_set_t *visited;
116343 +
116344 + visited = pointer_set_create();
116345 + walk_use_def(visited, cur_node, cur_node->node);
116346 + pointer_set_destroy(visited);
116347 +}
116348 +
116349 +enum precond {
116350 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116351 +};
116352 +
116353 +/* 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.
116354 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116355 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116356 + * It skips the possible error codes too.
116357 + */
116358 +static enum precond check_preconditions(struct interesting_node *cur_node)
116359 +{
116360 + bool interesting_conditions[5] = {false, false, false, false, false};
116361 +
116362 + set_last_nodes(cur_node);
116363 +
116364 + check_intentional_attribute_ipa(cur_node);
116365 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116366 + return NO_ATTRIBUTE_SEARCH;
116367 +
116368 + search_interesting_conditions(cur_node, interesting_conditions);
116369 +
116370 + // error code: a phi, unary assign (not cast) and returns only
116371 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116372 + return NO_ATTRIBUTE_SEARCH;
116373 +
116374 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116375 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116376 + return NO_ATTRIBUTE_SEARCH;
116377 +
116378 + // unnecessary overflow check
116379 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116380 + return NO_CHECK_INSERT;
116381 +
116382 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116383 + return NO_CHECK_INSERT;
116384 +
116385 + return NONE;
116386 +}
116387 +
116388 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116389 +{
116390 + const_gimple assign;
116391 + tree orig_type = TREE_TYPE(orig_node);
116392 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116393 +
116394 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116395 + return gimple_assign_lhs(assign);
116396 +}
116397 +
116398 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116399 +{
116400 + void (*set_rhs)(gimple, tree);
116401 + gimple stmt = cur_node->first_stmt;
116402 + const_tree orig_node = cur_node->node;
116403 +
116404 + switch (gimple_code(stmt)) {
116405 + case GIMPLE_RETURN:
116406 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116407 + break;
116408 + case GIMPLE_CALL:
116409 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116410 + break;
116411 + case GIMPLE_ASSIGN:
116412 + switch (cur_node->num) {
116413 + case 1:
116414 + set_rhs = &gimple_assign_set_rhs1;
116415 + break;
116416 + case 2:
116417 + set_rhs = &gimple_assign_set_rhs2;
116418 + break;
116419 +#if BUILDING_GCC_VERSION >= 4006
116420 + case 3:
116421 + set_rhs = &gimple_assign_set_rhs3;
116422 + break;
116423 +#endif
116424 + default:
116425 + gcc_unreachable();
116426 + }
116427 +
116428 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116429 + break;
116430 + default:
116431 + debug_gimple_stmt(stmt);
116432 + gcc_unreachable();
116433 + }
116434 +
116435 + update_stmt(stmt);
116436 +}
116437 +
116438 +static struct visited *create_visited(void)
116439 +{
116440 + struct visited *new_node;
116441 +
116442 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116443 + new_node->stmts = pointer_set_create();
116444 + new_node->my_stmts = pointer_set_create();
116445 + new_node->skip_expr_casts = pointer_set_create();
116446 + new_node->no_cast_check = pointer_set_create();
116447 + return new_node;
116448 +}
116449 +
116450 +static void free_visited(struct visited *visited)
116451 +{
116452 + pointer_set_destroy(visited->stmts);
116453 + pointer_set_destroy(visited->my_stmts);
116454 + pointer_set_destroy(visited->skip_expr_casts);
116455 + pointer_set_destroy(visited->no_cast_check);
116456 +
116457 + free(visited);
116458 +}
116459 +
116460 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116461 + * 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
116462 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116463 + */
116464 +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)
116465 +{
116466 + enum precond ret;
116467 + tree new_node, orig_node = cur_node->node;
116468 +
116469 + ret = check_preconditions(cur_node);
116470 + if (ret == NO_ATTRIBUTE_SEARCH)
116471 + return cnodes;
116472 +
116473 + cnodes = search_overflow_attribute(cnodes, cur_node);
116474 +
116475 + if (ret == NO_CHECK_INSERT)
116476 + return cnodes;
116477 +
116478 + new_node = expand(visited, caller_node, orig_node);
116479 + if (new_node == NULL_TREE)
116480 + return cnodes;
116481 +
116482 + change_orig_node(visited, cur_node, new_node);
116483 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116484 +
116485 + return cnodes;
116486 +}
116487 +
116488 +// Check visited_fns interesting nodes.
116489 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116490 +{
116491 + struct interesting_node *cur;
116492 +
116493 + for (cur = head; cur; cur = cur->next) {
116494 + if (!operand_equal_p(node, cur->node, 0))
116495 + continue;
116496 + if (num != cur->num)
116497 + continue;
116498 + if (first_stmt == cur->first_stmt)
116499 + return true;
116500 + }
116501 + return false;
116502 +}
116503 +
116504 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116505 + 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
116506 + 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
116507 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116508 + num: arg count of a call stmt or 0 when it is a ret
116509 + node: the recursion starts from here, it is a call arg or a return value
116510 + 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.
116511 + intentional_attr_decl: intentional_overflow attribute of the callee function
116512 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116513 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116514 + */
116515 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116516 +{
116517 + struct interesting_node *new_node;
116518 + tree fndecl;
116519 + enum gimple_code code;
116520 +
116521 + gcc_assert(node != NULL_TREE);
116522 + code = gimple_code(first_stmt);
116523 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116524 +
116525 + if (num == CANNOT_FIND_ARG)
116526 + return head;
116527 +
116528 + if (skip_types(node))
116529 + return head;
116530 +
116531 + if (skip_asm(node))
116532 + return head;
116533 +
116534 + if (is_gimple_call(first_stmt))
116535 + fndecl = gimple_call_fndecl(first_stmt);
116536 + else
116537 + fndecl = current_function_decl;
116538 +
116539 + if (fndecl == NULL_TREE)
116540 + return head;
116541 +
116542 + if (is_in_interesting_node(head, first_stmt, node, num))
116543 + return head;
116544 +
116545 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116546 +
116547 + new_node->next = NULL;
116548 + new_node->first_stmt = first_stmt;
116549 +#if BUILDING_GCC_VERSION <= 4007
116550 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116551 +#else
116552 + vec_alloc(new_node->last_nodes, VEC_LEN);
116553 +#endif
116554 + new_node->num = num;
116555 + new_node->node = node;
116556 + new_node->fndecl = fndecl;
116557 + new_node->intentional_attr_decl = MARK_NO;
116558 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116559 + new_node->intentional_mark_from_gimple = asm_stmt;
116560 +
116561 + if (!head)
116562 + return new_node;
116563 +
116564 + new_node->next = head;
116565 + return new_node;
116566 +}
116567 +
116568 +/* 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).
116569 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116570 + */
116571 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116572 +{
116573 + struct next_cgraph_node *cur_node;
116574 + tree ret = gimple_return_retval(stmt);
116575 +
116576 + if (ret == NULL_TREE)
116577 + return head;
116578 +
116579 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116580 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116581 + continue;
116582 + if (cur_node->num == 0)
116583 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116584 + }
116585 +
116586 + return head;
116587 +}
116588 +
116589 +/* 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).
116590 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116591 + */
116592 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116593 +{
116594 + unsigned int argnum;
116595 + tree arg;
116596 + const_tree fndecl;
116597 + struct next_cgraph_node *cur_node;
116598 +
116599 + fndecl = gimple_call_fndecl(stmt);
116600 + if (fndecl == NULL_TREE)
116601 + return head;
116602 +
116603 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116604 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116605 + continue;
116606 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116607 + gcc_assert(argnum != CANNOT_FIND_ARG);
116608 + if (argnum == 0)
116609 + continue;
116610 +
116611 + arg = gimple_call_arg(stmt, argnum - 1);
116612 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116613 + }
116614 +
116615 + return head;
116616 +}
116617 +
116618 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116619 +{
116620 + if (!operand_equal_p(orig_node, node, 0))
116621 + return WRONG_NODE;
116622 + if (skip_types(node))
116623 + return WRONG_NODE;
116624 + return ret_count;
116625 +}
116626 +
116627 +// Get the index of the rhs node in an assignment
116628 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116629 +{
116630 + const_tree rhs1, rhs2;
116631 + unsigned int ret;
116632 +
116633 + gcc_assert(stmt);
116634 + gcc_assert(is_gimple_assign(stmt));
116635 +
116636 + rhs1 = gimple_assign_rhs1(stmt);
116637 + gcc_assert(rhs1 != NULL_TREE);
116638 +
116639 + switch (gimple_num_ops(stmt)) {
116640 + case 2:
116641 + return check_ops(node, rhs1, 1);
116642 + case 3:
116643 + ret = check_ops(node, rhs1, 1);
116644 + if (ret != WRONG_NODE)
116645 + return ret;
116646 +
116647 + rhs2 = gimple_assign_rhs2(stmt);
116648 + gcc_assert(rhs2 != NULL_TREE);
116649 + return check_ops(node, rhs2, 2);
116650 + default:
116651 + gcc_unreachable();
116652 + }
116653 +}
116654 +
116655 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116656 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116657 +{
116658 + unsigned int i;
116659 +
116660 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116661 + return CANNOT_FIND_ARG;
116662 +
116663 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116664 + tree node;
116665 +
116666 + node = gimple_call_arg(stmt, i);
116667 + if (!operand_equal_p(arg, node, 0))
116668 + continue;
116669 + if (!skip_types(node))
116670 + return i + 1;
116671 + }
116672 +
116673 + return CANNOT_FIND_ARG;
116674 +}
116675 +
116676 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116677 + * any of return, call or assignment stmts (because of inlining).
116678 + */
116679 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116680 +{
116681 + use_operand_p use_p;
116682 + imm_use_iterator imm_iter;
116683 + unsigned int argnum;
116684 +
116685 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116686 +
116687 + if (pointer_set_insert(visited, node))
116688 + return head;
116689 +
116690 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116691 + gimple stmt = USE_STMT(use_p);
116692 +
116693 + if (stmt == NULL)
116694 + return head;
116695 + if (is_gimple_debug(stmt))
116696 + continue;
116697 +
116698 + switch (gimple_code(stmt)) {
116699 + case GIMPLE_CALL:
116700 + argnum = find_arg_number_gimple(node, stmt);
116701 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116702 + break;
116703 + case GIMPLE_RETURN:
116704 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116705 + break;
116706 + case GIMPLE_ASSIGN:
116707 + argnum = get_assign_ops_count(stmt, node);
116708 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116709 + break;
116710 + case GIMPLE_PHI: {
116711 + tree result = gimple_phi_result(stmt);
116712 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116713 + break;
116714 + }
116715 + case GIMPLE_ASM:
116716 + if (gimple_asm_noutputs(stmt) != 0)
116717 + break;
116718 + if (!is_size_overflow_asm(stmt))
116719 + break;
116720 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116721 + break;
116722 + case GIMPLE_COND:
116723 + case GIMPLE_SWITCH:
116724 + break;
116725 + default:
116726 + debug_gimple_stmt(stmt);
116727 + gcc_unreachable();
116728 + break;
116729 + }
116730 + }
116731 + return head;
116732 +}
116733 +
116734 +static void remove_size_overflow_asm(gimple stmt)
116735 +{
116736 + gimple_stmt_iterator gsi;
116737 + tree input, output;
116738 +
116739 + if (!is_size_overflow_asm(stmt))
116740 + return;
116741 +
116742 + if (gimple_asm_noutputs(stmt) == 0) {
116743 + gsi = gsi_for_stmt(stmt);
116744 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116745 + gsi_remove(&gsi, true);
116746 + return;
116747 + }
116748 +
116749 + input = gimple_asm_input_op(stmt, 0);
116750 + output = gimple_asm_output_op(stmt, 0);
116751 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116752 +}
116753 +
116754 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116755 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116756 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116757 + */
116758 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116759 +{
116760 + const_tree output;
116761 + struct pointer_set_t *visited;
116762 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116763 +
116764 + if (!is_size_overflow_asm(stmt))
116765 + return head;
116766 +
116767 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116768 + intentional_asm = stmt;
116769 +
116770 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116771 +
116772 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116773 + return head;
116774 +
116775 + if (gimple_asm_noutputs(stmt) == 0) {
116776 + const_tree input;
116777 +
116778 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116779 + return head;
116780 +
116781 + input = gimple_asm_input_op(stmt, 0);
116782 + remove_size_overflow_asm(stmt);
116783 + if (is_gimple_constant(TREE_VALUE(input)))
116784 + return head;
116785 + visited = pointer_set_create();
116786 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116787 + pointer_set_destroy(visited);
116788 + return head;
116789 + }
116790 +
116791 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116792 + remove_size_overflow_asm(stmt);
116793 +
116794 + visited = pointer_set_create();
116795 + output = gimple_asm_output_op(stmt, 0);
116796 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116797 + pointer_set_destroy(visited);
116798 + return head;
116799 +}
116800 +
116801 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116802 + * or a call stmt or a return stmt and store them in the interesting_node list
116803 + */
116804 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116805 +{
116806 + basic_block bb;
116807 + struct interesting_node *head = NULL;
116808 +
116809 + FOR_ALL_BB_FN(bb, cfun) {
116810 + gimple_stmt_iterator gsi;
116811 +
116812 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116813 + enum gimple_code code;
116814 + gimple stmt = gsi_stmt(gsi);
116815 +
116816 + code = gimple_code(stmt);
116817 +
116818 + if (code == GIMPLE_ASM)
116819 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116820 +
116821 + if (!next_node)
116822 + continue;
116823 + if (code == GIMPLE_CALL)
116824 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116825 + if (code == GIMPLE_RETURN)
116826 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116827 + }
116828 + }
116829 + return head;
116830 +}
116831 +
116832 +static void free_interesting_node(struct interesting_node *head)
116833 +{
116834 + struct interesting_node *cur;
116835 +
116836 + while (head) {
116837 + cur = head->next;
116838 +#if BUILDING_GCC_VERSION <= 4007
116839 + VEC_free(tree, gc, head->last_nodes);
116840 +#else
116841 + vec_free(head->last_nodes);
116842 +#endif
116843 + free(head);
116844 + head = cur;
116845 + }
116846 +}
116847 +
116848 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116849 +{
116850 + struct visited_fns *new_visited_fns;
116851 +
116852 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116853 + new_visited_fns->fndecl = cur_node->fndecl;
116854 + new_visited_fns->num = cur_node->num;
116855 + new_visited_fns->first_stmt = cur_node->first_stmt;
116856 + new_visited_fns->next = NULL;
116857 +
116858 + if (!head)
116859 + return new_visited_fns;
116860 +
116861 + new_visited_fns->next = head;
116862 + return new_visited_fns;
116863 +}
116864 +
116865 +/* 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
116866 + * it is a visited_fns function.
116867 + */
116868 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116869 +{
116870 + struct visited_fns *cur;
116871 +
116872 + if (!head)
116873 + return false;
116874 +
116875 + for (cur = head; cur; cur = cur->next) {
116876 + if (cur_node->first_stmt != cur->first_stmt)
116877 + continue;
116878 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116879 + continue;
116880 + if (cur_node->num == cur->num)
116881 + return true;
116882 + }
116883 + return false;
116884 +}
116885 +
116886 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116887 +{
116888 + struct next_cgraph_node *cur;
116889 +
116890 + while (head) {
116891 + cur = head->next;
116892 + free(head);
116893 + head = cur;
116894 + }
116895 +}
116896 +
116897 +static void remove_all_size_overflow_asm(void)
116898 +{
116899 + basic_block bb;
116900 +
116901 + FOR_ALL_BB_FN(bb, cfun) {
116902 + gimple_stmt_iterator si;
116903 +
116904 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116905 + remove_size_overflow_asm(gsi_stmt(si));
116906 + }
116907 +}
116908 +
116909 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116910 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116911 + * the newly collected interesting functions (they are interesting if there is control flow between
116912 + * the interesting stmts and them).
116913 + */
116914 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116915 +{
116916 + struct visited *visited;
116917 + struct interesting_node *head, *cur_node;
116918 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116919 +
116920 + set_current_function_decl(NODE_DECL(node));
116921 + call_count = 0;
116922 +
116923 + head = collect_interesting_stmts(next_node);
116924 +
116925 + visited = create_visited();
116926 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116927 + if (is_visited_fns_function(visited_fns, cur_node))
116928 + continue;
116929 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116930 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116931 + }
116932 +
116933 + free_visited(visited);
116934 + free_interesting_node(head);
116935 + remove_all_size_overflow_asm();
116936 + unset_current_function_decl();
116937 +
116938 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116939 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116940 +
116941 + free_next_cgraph_node(cnodes_head);
116942 + return visited_fns;
116943 +}
116944 +
116945 +static void free_visited_fns(struct visited_fns *head)
116946 +{
116947 + struct visited_fns *cur;
116948 +
116949 + while (head) {
116950 + cur = head->next;
116951 + free(head);
116952 + head = cur;
116953 + }
116954 +}
116955 +
116956 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116957 +unsigned int search_function(void)
116958 +{
116959 + struct cgraph_node *node;
116960 + struct visited_fns *visited_fns = NULL;
116961 +
116962 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116963 + gcc_assert(cgraph_function_flags_ready);
116964 +#if BUILDING_GCC_VERSION <= 4007
116965 + gcc_assert(node->reachable);
116966 +#endif
116967 +
116968 + visited_fns = handle_function(node, NULL, visited_fns);
116969 + }
116970 +
116971 + free_visited_fns(visited_fns);
116972 + return 0;
116973 +}
116974 +
116975 +#if BUILDING_GCC_VERSION >= 4009
116976 +static const struct pass_data insert_size_overflow_check_data = {
116977 +#else
116978 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116979 + .pass = {
116980 +#endif
116981 + .type = SIMPLE_IPA_PASS,
116982 + .name = "size_overflow",
116983 +#if BUILDING_GCC_VERSION >= 4008
116984 + .optinfo_flags = OPTGROUP_NONE,
116985 +#endif
116986 +#if BUILDING_GCC_VERSION >= 4009
116987 + .has_gate = false,
116988 + .has_execute = true,
116989 +#else
116990 + .gate = NULL,
116991 + .execute = search_function,
116992 + .sub = NULL,
116993 + .next = NULL,
116994 + .static_pass_number = 0,
116995 +#endif
116996 + .tv_id = TV_NONE,
116997 + .properties_required = 0,
116998 + .properties_provided = 0,
116999 + .properties_destroyed = 0,
117000 + .todo_flags_start = 0,
117001 + .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,
117002 +#if BUILDING_GCC_VERSION < 4009
117003 + },
117004 + .generate_summary = NULL,
117005 + .write_summary = NULL,
117006 + .read_summary = NULL,
117007 +#if BUILDING_GCC_VERSION >= 4006
117008 + .write_optimization_summary = NULL,
117009 + .read_optimization_summary = NULL,
117010 +#endif
117011 + .stmt_fixup = NULL,
117012 + .function_transform_todo_flags_start = 0,
117013 + .function_transform = NULL,
117014 + .variable_transform = NULL,
117015 +#endif
117016 +};
117017 +
117018 +#if BUILDING_GCC_VERSION >= 4009
117019 +namespace {
117020 +class insert_size_overflow_check : public ipa_opt_pass_d {
117021 +public:
117022 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117023 + unsigned int execute() { return search_function(); }
117024 +};
117025 +}
117026 +#endif
117027 +
117028 +struct opt_pass *make_insert_size_overflow_check(void)
117029 +{
117030 +#if BUILDING_GCC_VERSION >= 4009
117031 + return new insert_size_overflow_check();
117032 +#else
117033 + return &insert_size_overflow_check.pass;
117034 +#endif
117035 +}
117036 +
117037 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117038 new file mode 100644
117039 index 0000000..d71d72a
117040 --- /dev/null
117041 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117042 @@ -0,0 +1,736 @@
117043 +/*
117044 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117045 + * Licensed under the GPL v2, or (at your option) v3
117046 + *
117047 + * Homepage:
117048 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117049 + *
117050 + * Documentation:
117051 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117052 + *
117053 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117054 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117055 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117056 + *
117057 + * Usage:
117058 + * $ make
117059 + * $ make run
117060 + */
117061 +
117062 +#include "gcc-common.h"
117063 +#include "size_overflow.h"
117064 +
117065 +/* Get the param of the intentional_overflow attribute.
117066 + * * 0: MARK_NOT_INTENTIONAL
117067 + * * 1..MAX_PARAM: MARK_YES
117068 + * * -1: MARK_TURN_OFF
117069 + */
117070 +static tree get_attribute_param(const_tree decl)
117071 +{
117072 + const_tree attr;
117073 +
117074 + if (decl == NULL_TREE)
117075 + return NULL_TREE;
117076 +
117077 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117078 + if (!attr || !TREE_VALUE(attr))
117079 + return NULL_TREE;
117080 +
117081 + return TREE_VALUE(attr);
117082 +}
117083 +
117084 +// MARK_TURN_OFF
117085 +bool is_turn_off_intentional_attr(const_tree decl)
117086 +{
117087 + const_tree param_head;
117088 +
117089 + param_head = get_attribute_param(decl);
117090 + if (param_head == NULL_TREE)
117091 + return false;
117092 +
117093 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117094 + return true;
117095 + return false;
117096 +}
117097 +
117098 +// MARK_NOT_INTENTIONAL
117099 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117100 +{
117101 + const_tree param_head;
117102 +
117103 + if (argnum == 0)
117104 + return false;
117105 +
117106 + param_head = get_attribute_param(decl);
117107 + if (param_head == NULL_TREE)
117108 + return false;
117109 +
117110 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117111 + return true;
117112 + return false;
117113 +}
117114 +
117115 +// MARK_YES
117116 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117117 +{
117118 + tree param, param_head;
117119 +
117120 + if (argnum == 0)
117121 + return false;
117122 +
117123 + param_head = get_attribute_param(decl);
117124 + for (param = param_head; param; param = TREE_CHAIN(param))
117125 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117126 + return true;
117127 + return false;
117128 +}
117129 +
117130 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117131 +{
117132 + location_t loc;
117133 +
117134 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117135 + return;
117136 +
117137 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117138 + return;
117139 +
117140 + loc = DECL_SOURCE_LOCATION(decl);
117141 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117142 +}
117143 +
117144 +// Get the field decl of a component ref for intentional_overflow checking
117145 +static const_tree search_field_decl(const_tree comp_ref)
117146 +{
117147 + const_tree field = NULL_TREE;
117148 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117149 +
117150 + for (i = 0; i < len; i++) {
117151 + field = TREE_OPERAND(comp_ref, i);
117152 + if (TREE_CODE(field) == FIELD_DECL)
117153 + break;
117154 + }
117155 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117156 + return field;
117157 +}
117158 +
117159 +/* Get the type of the intentional_overflow attribute of a node
117160 + * * MARK_TURN_OFF
117161 + * * MARK_YES
117162 + * * MARK_NO
117163 + * * MARK_NOT_INTENTIONAL
117164 + */
117165 +enum mark get_intentional_attr_type(const_tree node)
117166 +{
117167 + const_tree cur_decl;
117168 +
117169 + if (node == NULL_TREE)
117170 + return MARK_NO;
117171 +
117172 + switch (TREE_CODE(node)) {
117173 + case COMPONENT_REF:
117174 + cur_decl = search_field_decl(node);
117175 + if (is_turn_off_intentional_attr(cur_decl))
117176 + return MARK_TURN_OFF;
117177 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117178 + return MARK_YES;
117179 + break;
117180 + case PARM_DECL: {
117181 + unsigned int argnum;
117182 +
117183 + cur_decl = DECL_ORIGIN(current_function_decl);
117184 + argnum = find_arg_number_tree(node, cur_decl);
117185 + if (argnum == CANNOT_FIND_ARG)
117186 + return MARK_NO;
117187 + if (is_yes_intentional_attr(cur_decl, argnum))
117188 + return MARK_YES;
117189 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117190 + return MARK_NOT_INTENTIONAL;
117191 + break;
117192 + }
117193 + case FUNCTION_DECL:
117194 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117195 + return MARK_TURN_OFF;
117196 + break;
117197 + default:
117198 + break;
117199 + }
117200 + return MARK_NO;
117201 +}
117202 +
117203 +// Search for the intentional_overflow attribute on the last nodes
117204 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117205 +{
117206 + unsigned int i;
117207 + tree last_node;
117208 + enum mark mark = MARK_NO;
117209 +
117210 +#if BUILDING_GCC_VERSION <= 4007
117211 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117212 +#else
117213 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117214 +#endif
117215 + mark = get_intentional_attr_type(last_node);
117216 + if (mark != MARK_NO)
117217 + break;
117218 + }
117219 + return mark;
117220 +}
117221 +
117222 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117223 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117224 + */
117225 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117226 +{
117227 + if (!cur_node->intentional_mark_from_gimple)
117228 + return false;
117229 +
117230 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117231 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117232 + else
117233 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117234 +
117235 + // skip param decls
117236 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117237 + return true;
117238 + return true;
117239 +}
117240 +
117241 +/* Search intentional_overflow attribute on caller and on callee too.
117242 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117243 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117244 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117245 +*/
117246 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117247 +{
117248 + const_tree fndecl;
117249 +
117250 + if (is_intentional_attribute_from_gimple(cur_node))
117251 + return;
117252 +
117253 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117254 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117255 + return;
117256 + }
117257 +
117258 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117259 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117260 + return;
117261 + }
117262 +
117263 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117264 + return;
117265 +
117266 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117267 + if (is_turn_off_intentional_attr(fndecl)) {
117268 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117269 + return;
117270 + }
117271 +
117272 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117273 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117274 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117275 + cur_node->intentional_attr_decl = MARK_YES;
117276 +
117277 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117278 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117279 +}
117280 +
117281 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117282 +{
117283 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117284 + enum machine_mode lhs_mode, rhs_mode;
117285 + gimple def_stmt = get_def_stmt(no_const_rhs);
117286 +
117287 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117288 + return false;
117289 +
117290 + rhs1 = gimple_assign_rhs1(def_stmt);
117291 + lhs = gimple_assign_lhs(def_stmt);
117292 + rhs1_type = TREE_TYPE(rhs1);
117293 + lhs_type = TREE_TYPE(lhs);
117294 + rhs_mode = TYPE_MODE(rhs1_type);
117295 + lhs_mode = TYPE_MODE(lhs_type);
117296 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117297 + return false;
117298 +
117299 + return true;
117300 +}
117301 +
117302 +static unsigned int uses_num(tree node)
117303 +{
117304 + imm_use_iterator imm_iter;
117305 + use_operand_p use_p;
117306 + unsigned int num = 0;
117307 +
117308 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117309 + gimple use_stmt = USE_STMT(use_p);
117310 +
117311 + if (use_stmt == NULL)
117312 + return num;
117313 + if (is_gimple_debug(use_stmt))
117314 + continue;
117315 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117316 + continue;
117317 + num++;
117318 + }
117319 + return num;
117320 +}
117321 +
117322 +static bool no_uses(tree node)
117323 +{
117324 + return !uses_num(node);
117325 +}
117326 +
117327 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117328 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117329 +{
117330 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117331 + gimple def_stmt = get_def_stmt(lhs);
117332 +
117333 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117334 + return false;
117335 +
117336 + rhs1 = gimple_assign_rhs1(def_stmt);
117337 + rhs_type = TREE_TYPE(rhs1);
117338 + lhs_type = TREE_TYPE(lhs);
117339 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117340 + return false;
117341 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117342 + return false;
117343 +
117344 + def_stmt = get_def_stmt(rhs1);
117345 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117346 + return false;
117347 +
117348 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117349 + return false;
117350 +
117351 + rhs1 = gimple_assign_rhs1(def_stmt);
117352 + rhs2 = gimple_assign_rhs2(def_stmt);
117353 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117354 + return false;
117355 +
117356 + if (is_gimple_constant(rhs2))
117357 + not_const_rhs = rhs1;
117358 + else
117359 + not_const_rhs = rhs2;
117360 +
117361 + return no_uses(not_const_rhs);
117362 +}
117363 +
117364 +static bool is_lt_signed_type_max(const_tree rhs)
117365 +{
117366 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117367 +
117368 + if (!TYPE_UNSIGNED(type))
117369 + return true;
117370 +
117371 + switch (TYPE_MODE(type)) {
117372 + case QImode:
117373 + new_type = intQI_type_node;
117374 + break;
117375 + case HImode:
117376 + new_type = intHI_type_node;
117377 + break;
117378 + case SImode:
117379 + new_type = intSI_type_node;
117380 + break;
117381 + case DImode:
117382 + new_type = intDI_type_node;
117383 + break;
117384 + default:
117385 + debug_tree((tree)type);
117386 + gcc_unreachable();
117387 + }
117388 +
117389 + type_max = TYPE_MAX_VALUE(new_type);
117390 + if (!tree_int_cst_lt(type_max, rhs))
117391 + return true;
117392 +
117393 + return false;
117394 +}
117395 +
117396 +static bool is_gt_zero(const_tree rhs)
117397 +{
117398 + const_tree type = TREE_TYPE(rhs);
117399 +
117400 + if (TYPE_UNSIGNED(type))
117401 + return true;
117402 +
117403 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117404 + return true;
117405 +
117406 + return false;
117407 +}
117408 +
117409 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117410 +{
117411 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117412 + return false;
117413 + if (!is_gimple_constant(rhs))
117414 + return false;
117415 +
117416 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117417 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117418 + return false;
117419 +
117420 + return true;
117421 +}
117422 +
117423 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117424 +{
117425 + gimple assign;
117426 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117427 + tree origtype = TREE_TYPE(orig_rhs);
117428 +
117429 + gcc_assert(is_gimple_assign(stmt));
117430 +
117431 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117432 + pointer_set_insert(visited->my_stmts, assign);
117433 + return gimple_assign_lhs(assign);
117434 +}
117435 +
117436 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117437 +{
117438 + tree new_rhs, orig_rhs;
117439 + void (*gimple_assign_set_rhs)(gimple, tree);
117440 + tree rhs1 = gimple_assign_rhs1(stmt);
117441 + tree rhs2 = gimple_assign_rhs2(stmt);
117442 + tree lhs = gimple_assign_lhs(stmt);
117443 +
117444 + if (!check_overflow)
117445 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117446 +
117447 + if (change_rhs == NULL_TREE)
117448 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117449 +
117450 + if (new_rhs2 == NULL_TREE) {
117451 + orig_rhs = rhs1;
117452 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117453 + } else {
117454 + orig_rhs = rhs2;
117455 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117456 + }
117457 +
117458 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117459 +
117460 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117461 + gimple_assign_set_rhs(stmt, new_rhs);
117462 + update_stmt(stmt);
117463 +
117464 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117465 +}
117466 +
117467 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117468 +{
117469 + gimple rhs1_def_stmt, rhs2_def_stmt;
117470 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117471 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117472 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117473 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117474 +
117475 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117476 + return false;
117477 +
117478 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117479 +
117480 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117481 + return false;
117482 +
117483 + rhs1_def_stmt = get_def_stmt(rhs1);
117484 + rhs2_def_stmt = get_def_stmt(rhs2);
117485 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117486 + return false;
117487 +
117488 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117489 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117490 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117491 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117492 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117493 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117494 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117495 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117496 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117497 + return false;
117498 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117499 + return false;
117500 +
117501 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117502 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117503 + return true;
117504 +}
117505 +
117506 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117507 +{
117508 + gimple assign;
117509 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117510 + tree type = TREE_TYPE(rhs1);
117511 + tree lhs = create_new_var(type);
117512 +
117513 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117514 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117515 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117516 +
117517 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117518 + update_stmt(assign);
117519 + pointer_set_insert(visited->my_stmts, assign);
117520 + return assign;
117521 +}
117522 +
117523 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117524 +{
117525 + gimple_stmt_iterator gsi;
117526 + gimple cast_stmt;
117527 + tree type = TREE_TYPE(node);
117528 +
117529 + if (types_compatible_p(type, intTI_type_node))
117530 + return node;
117531 +
117532 + gsi = gsi_for_stmt(stmt);
117533 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117534 + pointer_set_insert(visited->my_stmts, cast_stmt);
117535 + return gimple_assign_lhs(cast_stmt);
117536 +}
117537 +
117538 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117539 +{
117540 + tree rhs1, def_stmt_rhs1;
117541 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117542 +
117543 + def_stmt = get_def_stmt(var);
117544 + if (!gimple_assign_cast_p(def_stmt))
117545 + return NULL_TREE;
117546 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117547 +
117548 + rhs1 = gimple_assign_rhs1(def_stmt);
117549 + rhs1_def_stmt = get_def_stmt(rhs1);
117550 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117551 + return rhs1;
117552 +
117553 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117554 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117555 +
117556 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117557 + case GIMPLE_CALL:
117558 + case GIMPLE_NOP:
117559 + case GIMPLE_ASM:
117560 + case GIMPLE_PHI:
117561 + return def_stmt_rhs1;
117562 + case GIMPLE_ASSIGN:
117563 + return rhs1;
117564 + default:
117565 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117566 + gcc_unreachable();
117567 + }
117568 +}
117569 +
117570 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117571 +{
117572 + tree new_rhs1, new_rhs2;
117573 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117574 + gimple assign, stmt = get_def_stmt(lhs);
117575 + tree rhs1 = gimple_assign_rhs1(stmt);
117576 + tree rhs2 = gimple_assign_rhs2(stmt);
117577 +
117578 + if (!is_subtraction_special(visited, stmt))
117579 + return NULL_TREE;
117580 +
117581 + new_rhs1 = expand(visited, caller_node, rhs1);
117582 + new_rhs2 = expand(visited, caller_node, rhs2);
117583 +
117584 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117585 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117586 +
117587 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117588 + return NULL_TREE;
117589 +
117590 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117591 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117592 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117593 + }
117594 +
117595 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117596 + new_lhs = gimple_assign_lhs(assign);
117597 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117598 +
117599 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117600 +}
117601 +
117602 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117603 +{
117604 + const_gimple def_stmt;
117605 +
117606 + if (TREE_CODE(rhs) != SSA_NAME)
117607 + return false;
117608 +
117609 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117610 + return false;
117611 +
117612 + def_stmt = get_def_stmt(rhs);
117613 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117614 + return false;
117615 +
117616 + return true;
117617 +}
117618 +
117619 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117620 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117621 + * fffffff * 16 > signed max -> truncate
117622 + */
117623 +static bool look_for_mult_and_add(const_gimple stmt)
117624 +{
117625 + const_tree res;
117626 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117627 + const_gimple def_stmt;
117628 +
117629 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117630 + return false;
117631 + if (!is_gimple_assign(stmt))
117632 + return false;
117633 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117634 + return false;
117635 +
117636 + rhs1 = gimple_assign_rhs1(stmt);
117637 + rhs2 = gimple_assign_rhs2(stmt);
117638 + if (is_gimple_constant(rhs1)) {
117639 + const_rhs = rhs1;
117640 + def_stmt = get_def_stmt(rhs2);
117641 + } else if (is_gimple_constant(rhs2)) {
117642 + const_rhs = rhs2;
117643 + def_stmt = get_def_stmt(rhs1);
117644 + } else
117645 + return false;
117646 +
117647 + if (!is_gimple_assign(def_stmt))
117648 + return false;
117649 +
117650 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117651 + return false;
117652 +
117653 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117654 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117655 + if (is_gimple_constant(def_rhs1))
117656 + def_const_rhs = def_rhs1;
117657 + else if (is_gimple_constant(def_rhs2))
117658 + def_const_rhs = def_rhs2;
117659 + else
117660 + return false;
117661 +
117662 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117663 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117664 + return false;
117665 + return true;
117666 +}
117667 +
117668 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117669 +{
117670 + const_gimple def_stmt_1, def_stmt_2;
117671 + const_tree rhs1, rhs2;
117672 + bool add_mul_rhs1, add_mul_rhs2;
117673 +
117674 + rhs1 = gimple_assign_rhs1(stmt);
117675 + def_stmt_1 = get_def_stmt(rhs1);
117676 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117677 +
117678 + rhs2 = gimple_assign_rhs2(stmt);
117679 + def_stmt_2 = get_def_stmt(rhs2);
117680 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117681 +
117682 + if (add_mul_rhs1)
117683 + return RHS1_INTENTIONAL_OVERFLOW;
117684 + if (add_mul_rhs2)
117685 + return RHS2_INTENTIONAL_OVERFLOW;
117686 + return NO_INTENTIONAL_OVERFLOW;
117687 +}
117688 +
117689 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117690 +{
117691 + gimple my_stmt;
117692 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117693 +
117694 + gsi_next(&gsi);
117695 + my_stmt = gsi_stmt(gsi);
117696 +
117697 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117698 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117699 +
117700 + return my_stmt;
117701 +}
117702 +
117703 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117704 + * unsigned type cast to signed type, unsigned type: no more uses
117705 + * e.g., lib/vsprintf.c:simple_strtol()
117706 + * _10 = (unsigned long int) _9
117707 + * _11 = -_10;
117708 + * _12 = (long int) _11; (_11_ no more uses)
117709 + */
117710 +static bool is_call_or_cast(gimple stmt)
117711 +{
117712 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117713 +}
117714 +
117715 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117716 +{
117717 + const_tree rhs;
117718 + gimple def_stmt;
117719 +
117720 + if (node == NULL_TREE)
117721 + return true;
117722 + if (is_gimple_constant(node))
117723 + return true;
117724 +
117725 + def_stmt = get_def_stmt(node);
117726 + if (!def_stmt)
117727 + return false;
117728 +
117729 + if (is_call_or_cast(def_stmt))
117730 + return true;
117731 +
117732 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117733 + return false;
117734 + rhs = gimple_assign_rhs1(def_stmt);
117735 + def_stmt = get_def_stmt(rhs);
117736 + if (!def_stmt)
117737 + return false;
117738 + return is_call_or_cast(def_stmt);
117739 +}
117740 +
117741 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117742 +{
117743 + unsigned int use_num;
117744 + gimple so_stmt;
117745 + const_gimple def_stmt;
117746 + const_tree rhs1, rhs2;
117747 + tree rhs = gimple_assign_rhs1(stmt);
117748 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117749 + const_tree rhs_type = TREE_TYPE(rhs);
117750 +
117751 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117752 + return;
117753 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117754 + return;
117755 + use_num = uses_num(rhs);
117756 + if (use_num != 1)
117757 + return;
117758 +
117759 + def_stmt = get_def_stmt(rhs);
117760 + if (!def_stmt)
117761 + return;
117762 + if (!is_gimple_assign(def_stmt))
117763 + return;
117764 +
117765 + rhs1 = gimple_assign_rhs1(def_stmt);
117766 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117767 + return;
117768 +
117769 + rhs2 = gimple_assign_rhs2(def_stmt);
117770 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117771 + return;
117772 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117773 + return;
117774 +
117775 + so_stmt = get_dup_stmt(visited, stmt);
117776 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117777 +}
117778 +
117779 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117780 new file mode 100644
117781 index 0000000..4bddad2
117782 --- /dev/null
117783 +++ b/tools/gcc/size_overflow_plugin/misc.c
117784 @@ -0,0 +1,203 @@
117785 +/*
117786 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117787 + * Licensed under the GPL v2, or (at your option) v3
117788 + *
117789 + * Homepage:
117790 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117791 + *
117792 + * Documentation:
117793 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117794 + *
117795 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117796 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117797 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117798 + *
117799 + * Usage:
117800 + * $ make
117801 + * $ make run
117802 + */
117803 +
117804 +#include "gcc-common.h"
117805 +#include "size_overflow.h"
117806 +
117807 +void set_current_function_decl(tree fndecl)
117808 +{
117809 + gcc_assert(fndecl != NULL_TREE);
117810 +
117811 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117812 + calculate_dominance_info(CDI_DOMINATORS);
117813 + current_function_decl = fndecl;
117814 +}
117815 +
117816 +void unset_current_function_decl(void)
117817 +{
117818 + free_dominance_info(CDI_DOMINATORS);
117819 + pop_cfun();
117820 + current_function_decl = NULL_TREE;
117821 +}
117822 +
117823 +static bool is_bool(const_tree node)
117824 +{
117825 + const_tree type;
117826 +
117827 + if (node == NULL_TREE)
117828 + return false;
117829 +
117830 + type = TREE_TYPE(node);
117831 + if (!INTEGRAL_TYPE_P(type))
117832 + return false;
117833 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117834 + return true;
117835 + if (TYPE_PRECISION(type) == 1)
117836 + return true;
117837 + return false;
117838 +}
117839 +
117840 +bool skip_types(const_tree var)
117841 +{
117842 + tree type;
117843 + enum tree_code code;
117844 +
117845 + if (is_gimple_constant(var))
117846 + return true;
117847 +
117848 + switch (TREE_CODE(var)) {
117849 + case ADDR_EXPR:
117850 +#if BUILDING_GCC_VERSION >= 4006
117851 + case MEM_REF:
117852 +#endif
117853 + case ARRAY_REF:
117854 + case BIT_FIELD_REF:
117855 + case INDIRECT_REF:
117856 + case TARGET_MEM_REF:
117857 + case COMPONENT_REF:
117858 + case VAR_DECL:
117859 + case VIEW_CONVERT_EXPR:
117860 + return true;
117861 + default:
117862 + break;
117863 + }
117864 +
117865 + code = TREE_CODE(var);
117866 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117867 +
117868 + type = TREE_TYPE(var);
117869 + switch (TREE_CODE(type)) {
117870 + case INTEGER_TYPE:
117871 + case ENUMERAL_TYPE:
117872 + return false;
117873 + case BOOLEAN_TYPE:
117874 + return is_bool(var);
117875 + default:
117876 + return true;
117877 + }
117878 +}
117879 +
117880 +gimple get_def_stmt(const_tree node)
117881 +{
117882 + gcc_assert(node != NULL_TREE);
117883 +
117884 + if (skip_types(node))
117885 + return NULL;
117886 +
117887 + if (TREE_CODE(node) != SSA_NAME)
117888 + return NULL;
117889 + return SSA_NAME_DEF_STMT(node);
117890 +}
117891 +
117892 +tree create_new_var(tree type)
117893 +{
117894 + tree new_var = create_tmp_var(type, "cicus");
117895 +
117896 + add_referenced_var(new_var);
117897 + return new_var;
117898 +}
117899 +
117900 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117901 +{
117902 + const_gimple def_stmt = get_def_stmt(rhs);
117903 +
117904 + if (force)
117905 + return false;
117906 +
117907 + if (is_gimple_constant(rhs))
117908 + return false;
117909 +
117910 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117911 + return false;
117912 +
117913 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117914 + return false;
117915 +
117916 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117917 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117918 + return false;
117919 +
117920 + return true;
117921 +}
117922 +
117923 +tree cast_a_tree(tree type, tree var)
117924 +{
117925 + gcc_assert(type != NULL_TREE);
117926 + gcc_assert(var != NULL_TREE);
117927 + gcc_assert(fold_convertible_p(type, var));
117928 +
117929 + return fold_convert(type, var);
117930 +}
117931 +
117932 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117933 +{
117934 + gimple assign, def_stmt;
117935 +
117936 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117937 + gcc_assert(!is_gimple_constant(rhs));
117938 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117939 + gcc_unreachable();
117940 +
117941 + def_stmt = get_def_stmt(rhs);
117942 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117943 + return def_stmt;
117944 +
117945 + if (lhs == CREATE_NEW_VAR)
117946 + lhs = create_new_var(dst_type);
117947 +
117948 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117949 +
117950 + if (!gsi_end_p(*gsi)) {
117951 + location_t loc = gimple_location(gsi_stmt(*gsi));
117952 + gimple_set_location(assign, loc);
117953 + }
117954 +
117955 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117956 +
117957 + if (before)
117958 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117959 + else
117960 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117961 + update_stmt(assign);
117962 + return assign;
117963 +}
117964 +
117965 +bool is_size_overflow_type(const_tree var)
117966 +{
117967 + const char *name;
117968 + const_tree type_name, type;
117969 +
117970 + if (var == NULL_TREE)
117971 + return false;
117972 +
117973 + type = TREE_TYPE(var);
117974 + type_name = TYPE_NAME(type);
117975 + if (type_name == NULL_TREE)
117976 + return false;
117977 +
117978 + if (DECL_P(type_name))
117979 + name = DECL_NAME_POINTER(type_name);
117980 + else
117981 + name = IDENTIFIER_POINTER(type_name);
117982 +
117983 + if (!strncmp(name, "size_overflow_type", 18))
117984 + return true;
117985 + return false;
117986 +}
117987 +
117988 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117989 new file mode 100644
117990 index 0000000..7c9e6d1
117991 --- /dev/null
117992 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117993 @@ -0,0 +1,138 @@
117994 +/*
117995 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117996 + * Licensed under the GPL v2, or (at your option) v3
117997 + *
117998 + * Homepage:
117999 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118000 + *
118001 + * Documentation:
118002 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118003 + *
118004 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118005 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118006 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118007 + *
118008 + * Usage:
118009 + * $ make
118010 + * $ make run
118011 + */
118012 +
118013 +#include "gcc-common.h"
118014 +#include "size_overflow.h"
118015 +
118016 +bool skip_expr_on_double_type(const_gimple stmt)
118017 +{
118018 + enum tree_code code = gimple_assign_rhs_code(stmt);
118019 +
118020 + switch (code) {
118021 + case RSHIFT_EXPR:
118022 + case TRUNC_DIV_EXPR:
118023 + case CEIL_DIV_EXPR:
118024 + case FLOOR_DIV_EXPR:
118025 + case ROUND_DIV_EXPR:
118026 + case EXACT_DIV_EXPR:
118027 + case RDIV_EXPR:
118028 + case TRUNC_MOD_EXPR:
118029 + case CEIL_MOD_EXPR:
118030 + case FLOOR_MOD_EXPR:
118031 + case ROUND_MOD_EXPR:
118032 + return true;
118033 + default:
118034 + return false;
118035 + }
118036 +}
118037 +
118038 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
118039 +{
118040 + const_tree orig_rhs1;
118041 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
118042 + gimple down_cast, up_cast;
118043 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
118044 +
118045 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118046 + down_lhs = gimple_assign_lhs(down_cast);
118047 +
118048 + gsi = gsi_for_stmt(use_stmt);
118049 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118050 + new_lhs = gimple_assign_lhs(up_cast);
118051 +
118052 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
118053 + if (operand_equal_p(orig_rhs1, rhs, 0))
118054 + gimple_assign_set_rhs1(use_stmt, new_lhs);
118055 + else
118056 + gimple_assign_set_rhs2(use_stmt, new_lhs);
118057 + update_stmt(use_stmt);
118058 +
118059 + pointer_set_insert(visited->my_stmts, up_cast);
118060 + pointer_set_insert(visited->my_stmts, down_cast);
118061 + pointer_set_insert(visited->skip_expr_casts, up_cast);
118062 + pointer_set_insert(visited->skip_expr_casts, down_cast);
118063 +}
118064 +
118065 +static tree get_proper_unsigned_half_type(const_tree node)
118066 +{
118067 + tree new_type, type;
118068 +
118069 + gcc_assert(is_size_overflow_type(node));
118070 +
118071 + type = TREE_TYPE(node);
118072 + switch (TYPE_MODE(type)) {
118073 + case HImode:
118074 + new_type = unsigned_intQI_type_node;
118075 + break;
118076 + case SImode:
118077 + new_type = unsigned_intHI_type_node;
118078 + break;
118079 + case DImode:
118080 + new_type = unsigned_intSI_type_node;
118081 + break;
118082 + case TImode:
118083 + new_type = unsigned_intDI_type_node;
118084 + break;
118085 + default:
118086 + gcc_unreachable();
118087 + }
118088 +
118089 + if (TYPE_QUALS(type) != 0)
118090 + return build_qualified_type(new_type, TYPE_QUALS(type));
118091 + return new_type;
118092 +}
118093 +
118094 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
118095 +{
118096 + tree type;
118097 +
118098 + if (rhs == NULL_TREE)
118099 + return;
118100 + if (!is_size_overflow_type(rhs))
118101 + return;
118102 +
118103 + type = get_proper_unsigned_half_type(rhs);
118104 + if (is_gimple_constant(rhs))
118105 + return;
118106 + create_up_and_down_cast(visited, stmt, type, rhs);
118107 +}
118108 +
118109 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
118110 +{
118111 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
118112 + return;
118113 + gcc_assert(is_size_overflow_type(rhs));
118114 + insert_cast_rhs(visited, stmt, rhs);
118115 +}
118116 +
118117 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
118118 +{
118119 + tree rhs1, rhs2;
118120 +
118121 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118122 + rhs1 = gimple_assign_rhs1(stmt);
118123 + insert_cast(visited, stmt, rhs1);
118124 + }
118125 +
118126 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118127 + rhs2 = gimple_assign_rhs2(stmt);
118128 + insert_cast(visited, stmt, rhs2);
118129 + }
118130 +}
118131 +
118132 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118133 new file mode 100644
118134 index 0000000..e5b4e50
118135 --- /dev/null
118136 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118137 @@ -0,0 +1,127 @@
118138 +#ifndef SIZE_OVERFLOW_H
118139 +#define SIZE_OVERFLOW_H
118140 +
118141 +#define CREATE_NEW_VAR NULL_TREE
118142 +#define CANNOT_FIND_ARG 32
118143 +#define MAX_PARAM 31
118144 +#define BEFORE_STMT true
118145 +#define AFTER_STMT false
118146 +
118147 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118148 +#define YES_ASM_STR "# size_overflow MARK_YES "
118149 +#define OK_ASM_STR "# size_overflow "
118150 +
118151 +enum mark {
118152 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118153 +};
118154 +
118155 +enum intentional_overflow_type {
118156 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118157 +};
118158 +
118159 +struct visited {
118160 + struct pointer_set_t *stmts;
118161 + struct pointer_set_t *my_stmts;
118162 + struct pointer_set_t *skip_expr_casts;
118163 + struct pointer_set_t *no_cast_check;
118164 +};
118165 +
118166 +// size_overflow_plugin.c
118167 +extern tree report_size_overflow_decl;
118168 +extern tree size_overflow_type_HI;
118169 +extern tree size_overflow_type_SI;
118170 +extern tree size_overflow_type_DI;
118171 +extern tree size_overflow_type_TI;
118172 +
118173 +
118174 +// size_overflow_plugin_hash.c
118175 +struct size_overflow_hash {
118176 + const struct size_overflow_hash * const next;
118177 + const char * const name;
118178 + const unsigned int param;
118179 +};
118180 +
118181 +struct interesting_node {
118182 + struct interesting_node *next;
118183 + gimple first_stmt;
118184 + const_tree fndecl;
118185 + tree node;
118186 +#if BUILDING_GCC_VERSION <= 4007
118187 + VEC(tree, gc) *last_nodes;
118188 +#else
118189 + vec<tree, va_gc> *last_nodes;
118190 +#endif
118191 + unsigned int num;
118192 + enum mark intentional_attr_decl;
118193 + enum mark intentional_attr_cur_fndecl;
118194 + gimple intentional_mark_from_gimple;
118195 +};
118196 +
118197 +extern bool is_size_overflow_asm(const_gimple stmt);
118198 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118199 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118200 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118201 +extern bool is_a_return_check(const_tree node);
118202 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118203 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118204 +
118205 +
118206 +// size_overflow_debug.c
118207 +extern struct opt_pass *make_dump_pass(void);
118208 +
118209 +
118210 +// intentional_overflow.c
118211 +extern enum mark get_intentional_attr_type(const_tree node);
118212 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118213 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118214 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118215 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118216 +extern bool is_turn_off_intentional_attr(const_tree decl);
118217 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118218 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118219 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118220 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118221 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118222 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118223 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118224 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118225 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118226 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118227 +
118228 +
118229 +// insert_size_overflow_check_ipa.c
118230 +extern unsigned int search_function(void);
118231 +extern unsigned int call_count;
118232 +extern struct opt_pass *make_insert_size_overflow_check(void);
118233 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118234 +
118235 +
118236 +// insert_size_overflow_asm.c
118237 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118238 +
118239 +
118240 +// misc.c
118241 +extern void set_current_function_decl(tree fndecl);
118242 +extern void unset_current_function_decl(void);
118243 +extern gimple get_def_stmt(const_tree node);
118244 +extern tree create_new_var(tree type);
118245 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118246 +extern bool skip_types(const_tree var);
118247 +extern tree cast_a_tree(tree type, tree var);
118248 +extern bool is_size_overflow_type(const_tree var);
118249 +
118250 +
118251 +// insert_size_overflow_check_core.c
118252 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118253 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118254 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118255 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118256 +
118257 +
118258 +// remove_unnecessary_dup.c
118259 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118260 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118261 +extern bool skip_expr_on_double_type(const_gimple stmt);
118262 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118263 +
118264 +#endif
118265 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118266 new file mode 100644
118267 index 0000000..4378111
118268 --- /dev/null
118269 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118270 @@ -0,0 +1,116 @@
118271 +/*
118272 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118273 + * Licensed under the GPL v2, or (at your option) v3
118274 + *
118275 + * Homepage:
118276 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118277 + *
118278 + * Documentation:
118279 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118280 + *
118281 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118282 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118283 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118284 + *
118285 + * Usage:
118286 + * $ make
118287 + * $ make run
118288 + */
118289 +
118290 +#include "gcc-common.h"
118291 +
118292 +static unsigned int dump_functions(void)
118293 +{
118294 + struct cgraph_node *node;
118295 +
118296 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118297 + basic_block bb;
118298 +
118299 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118300 + current_function_decl = NODE_DECL(node);
118301 +
118302 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118303 +
118304 + FOR_ALL_BB_FN(bb, cfun) {
118305 + gimple_stmt_iterator si;
118306 +
118307 + fprintf(stderr, "<bb %u>:\n", bb->index);
118308 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118309 + debug_gimple_stmt(gsi_stmt(si));
118310 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118311 + debug_gimple_stmt(gsi_stmt(si));
118312 + fprintf(stderr, "\n");
118313 + }
118314 +
118315 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118316 +
118317 + pop_cfun();
118318 + current_function_decl = NULL_TREE;
118319 + }
118320 +
118321 + fprintf(stderr, "###############################################################################\n");
118322 +
118323 + return 0;
118324 +}
118325 +
118326 +#if BUILDING_GCC_VERSION >= 4009
118327 +static const struct pass_data dump_pass_data = {
118328 +#else
118329 +static struct ipa_opt_pass_d dump_pass = {
118330 + .pass = {
118331 +#endif
118332 + .type = SIMPLE_IPA_PASS,
118333 + .name = "dump",
118334 +#if BUILDING_GCC_VERSION >= 4008
118335 + .optinfo_flags = OPTGROUP_NONE,
118336 +#endif
118337 +#if BUILDING_GCC_VERSION >= 4009
118338 + .has_gate = false,
118339 + .has_execute = true,
118340 +#else
118341 + .gate = NULL,
118342 + .execute = dump_functions,
118343 + .sub = NULL,
118344 + .next = NULL,
118345 + .static_pass_number = 0,
118346 +#endif
118347 + .tv_id = TV_NONE,
118348 + .properties_required = 0,
118349 + .properties_provided = 0,
118350 + .properties_destroyed = 0,
118351 + .todo_flags_start = 0,
118352 + .todo_flags_finish = 0,
118353 +#if BUILDING_GCC_VERSION < 4009
118354 + },
118355 + .generate_summary = NULL,
118356 + .write_summary = NULL,
118357 + .read_summary = NULL,
118358 +#if BUILDING_GCC_VERSION >= 4006
118359 + .write_optimization_summary = NULL,
118360 + .read_optimization_summary = NULL,
118361 +#endif
118362 + .stmt_fixup = NULL,
118363 + .function_transform_todo_flags_start = 0,
118364 + .function_transform = NULL,
118365 + .variable_transform = NULL,
118366 +#endif
118367 +};
118368 +
118369 +#if BUILDING_GCC_VERSION >= 4009
118370 +namespace {
118371 +class dump_pass : public ipa_opt_pass_d {
118372 +public:
118373 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118374 + unsigned int execute() { return dump_functions(); }
118375 +};
118376 +}
118377 +#endif
118378 +
118379 +struct opt_pass *make_dump_pass(void)
118380 +{
118381 +#if BUILDING_GCC_VERSION >= 4009
118382 + return new dump_pass();
118383 +#else
118384 + return &dump_pass.pass;
118385 +#endif
118386 +}
118387 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118388 new file mode 100644
118389 index 0000000..f2bd55d
118390 --- /dev/null
118391 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118392 @@ -0,0 +1,6031 @@
118393 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118394 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118395 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118396 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118397 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118398 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118399 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118400 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118401 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118402 +load_msg_95 load_msg 2 95 NULL
118403 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118404 +init_q_132 init_q 4 132 NULL
118405 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118406 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118407 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118408 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118409 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118410 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118411 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118412 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118413 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118414 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
118415 +br_port_info_size_268 br_port_info_size 0 268 NULL
118416 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118417 +SYSC_connect_304 SYSC_connect 3 304 NULL
118418 +syslog_print_307 syslog_print 2 307 NULL
118419 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118420 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118421 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118422 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118423 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118424 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118425 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118426 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118427 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118428 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
118429 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118430 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118431 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118432 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118433 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118434 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118435 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118436 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118437 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118438 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118439 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118440 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118441 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118442 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118443 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118444 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118445 +unlink_queued_645 unlink_queued 4 645 NULL
118446 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118447 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118448 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118449 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118450 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118451 +dvb_video_write_754 dvb_video_write 3 754 NULL
118452 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118453 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118454 +if_writecmd_815 if_writecmd 2 815 NULL
118455 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118456 +error_state_read_859 error_state_read 6 859 NULL
118457 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118458 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118459 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118460 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118461 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118462 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118463 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118464 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118465 +readreg_1017 readreg 0-1 1017 NULL
118466 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118467 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118468 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118469 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118470 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118471 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118472 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118473 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118474 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118475 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118476 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118477 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118478 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118479 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118480 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118481 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118482 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118483 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118484 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118485 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118486 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118487 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118488 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118489 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118490 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118491 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118492 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118493 +ffs_1322 ffs 0 1322 NULL
118494 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118495 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118496 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118497 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118498 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118499 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118500 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118501 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118502 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118503 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118504 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118505 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118506 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118507 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118508 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118509 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118510 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118511 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118512 +fpregs_set_1497 fpregs_set 4 1497 NULL
118513 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118514 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118515 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118516 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118517 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118518 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118519 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118520 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118521 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118522 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118523 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118524 +rmap_add_1677 rmap_add 3 1677 NULL
118525 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118526 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118527 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118528 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118529 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118530 +internal_create_group_1733 internal_create_group 0 1733 NULL
118531 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118532 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118533 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118534 +cosa_write_1774 cosa_write 3 1774 NULL
118535 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118536 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118537 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118538 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118539 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118540 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118541 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118542 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118543 +azx_get_position_1927 azx_get_position 0 1927 NULL
118544 +bdev_erase_1933 bdev_erase 3 1933 NULL
118545 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118546 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118547 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118548 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118549 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118550 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
118551 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118552 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118553 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118554 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118555 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118556 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118557 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118558 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118559 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118560 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118561 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118562 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118563 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118564 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118565 +audit_expand_2098 audit_expand 0 2098 NULL
118566 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118567 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118568 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118569 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118570 +enable_read_2117 enable_read 3 2117 NULL
118571 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118572 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118573 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118574 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118575 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118576 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118577 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118578 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118579 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118580 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118581 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118582 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118583 +do_update_counters_2259 do_update_counters 4 2259 NULL
118584 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118585 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
118586 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118587 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118588 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118589 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118590 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118591 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118592 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118593 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118594 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118595 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118596 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118597 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118598 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118599 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118600 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118601 +raid1_size_2419 raid1_size 0-2 2419 NULL
118602 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118603 +wiphy_new_2482 wiphy_new 2 2482 NULL
118604 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118605 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118606 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118607 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118608 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118609 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118610 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118611 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118612 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118613 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118614 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118615 +slot_bytes_2609 slot_bytes 0 2609 NULL
118616 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118617 +switch_status_2629 switch_status 5 2629 NULL
118618 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118619 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118620 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118621 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118622 +oti6858_write_2692 oti6858_write 4 2692 NULL
118623 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
118624 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118625 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118626 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118627 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118628 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118629 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118630 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118631 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118632 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118633 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118634 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118635 +sock_create_2838 sock_create 0 2838 NULL
118636 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118637 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118638 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118639 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118640 +nla_padlen_2883 nla_padlen 1 2883 NULL
118641 +cmm_write_2896 cmm_write 3 2896 NULL
118642 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118643 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118644 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118645 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118646 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118647 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118648 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118649 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118650 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118651 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118652 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118653 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118654 +depth_write_3021 depth_write 3 3021 NULL
118655 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118656 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118657 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118658 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118659 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118660 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118661 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118662 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118663 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118664 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118665 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118666 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118667 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118668 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
118669 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118670 +rb_alloc_3102 rb_alloc 1 3102 NULL
118671 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118672 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118673 +print_time_3132 print_time 0 3132 NULL
118674 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118675 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118676 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118677 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118678 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118679 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118680 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118681 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118682 +alloc_context_3194 alloc_context 1 3194 NULL
118683 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
118684 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118685 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118686 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118687 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118688 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118689 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118690 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118691 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118692 +key_key_read_3241 key_key_read 3 3241 NULL
118693 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118694 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118695 +cgroup_name_3300 cgroup_name 3 3300 NULL
118696 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118697 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118698 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118699 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118700 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118701 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118702 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118703 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118704 +scnprintf_3360 scnprintf 0-2 3360 NULL
118705 +sr_read_3366 sr_read 3 3366 NULL
118706 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118707 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118708 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118709 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118710 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118711 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118712 +softsynth_write_3455 softsynth_write 3 3455 NULL
118713 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118714 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118715 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118716 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118717 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118718 +SyS_readv_3539 SyS_readv 3 3539 NULL
118719 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
118720 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118721 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118722 +evtchn_read_3569 evtchn_read 3 3569 NULL
118723 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118724 +vc_resize_3585 vc_resize 3-2 3585 NULL
118725 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118726 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118727 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118728 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118729 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118730 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
118731 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118732 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118733 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118734 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118735 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118736 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118737 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118738 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118739 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118740 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
118741 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118742 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118743 +get_fd_set_3866 get_fd_set 1 3866 NULL
118744 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118745 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118746 +nvram_write_3894 nvram_write 3 3894 NULL
118747 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118748 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118749 +vcs_write_3910 vcs_write 3 3910 NULL
118750 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118751 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118752 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118753 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118754 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118755 +do_add_counters_3992 do_add_counters 3 3992 NULL
118756 +userspace_status_4004 userspace_status 4 4004 NULL
118757 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118758 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118759 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118760 +blk_end_request_4024 blk_end_request 3 4024 NULL
118761 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118762 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118763 +read_file_queues_4078 read_file_queues 3 4078 NULL
118764 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118765 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118766 +tm6000_read_4151 tm6000_read 3 4151 NULL
118767 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118768 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118769 +get_alua_req_4166 get_alua_req 3 4166 NULL
118770 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118771 +read_file_bool_4180 read_file_bool 3 4180 NULL
118772 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118773 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118774 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118775 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118776 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118777 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118778 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118779 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118780 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118781 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118782 +count_strings_4315 count_strings 0 4315 NULL nohasharray
118783 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
118784 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118785 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118786 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118787 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118788 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118789 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118790 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118791 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118792 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118793 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118794 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118795 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118796 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118797 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118798 +set_link_security_4502 set_link_security 4 4502 NULL
118799 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118800 +tty_register_device_4544 tty_register_device 2 4544 NULL
118801 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118802 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118803 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118804 +bch_alloc_4593 bch_alloc 1 4593 NULL
118805 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118806 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118807 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118808 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118809 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118810 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118811 +kone_receive_4690 kone_receive 4 4690 NULL
118812 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118813 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118814 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118815 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118816 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118817 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118818 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118819 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118820 +create_subvol_4791 create_subvol 4 4791 NULL
118821 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118822 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118823 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118824 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118825 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118826 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118827 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118828 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118829 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118830 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118831 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118832 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118833 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118834 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118835 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118836 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118837 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118838 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118839 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118840 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118841 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118842 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118843 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118844 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118845 +sound_write_5102 sound_write 3 5102 NULL
118846 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118847 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118848 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118849 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118850 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118851 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118852 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118853 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118854 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118855 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118856 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
118857 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
118858 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118859 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118860 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118861 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118862 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118863 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118864 +cq_free_res_5355 cq_free_res 5 5355 NULL
118865 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118866 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118867 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118868 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118869 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118870 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118871 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
118872 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118873 +tty_write_5494 tty_write 3 5494 NULL
118874 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118875 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118876 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118877 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118878 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118879 +le_readq_5557 le_readq 0 5557 NULL
118880 +inw_5558 inw 0 5558 NULL
118881 +bioset_create_5580 bioset_create 1 5580 NULL
118882 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118883 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118884 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118885 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118886 +get_arg_5694 get_arg 3 5694 NULL
118887 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118888 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118889 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118890 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118891 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118892 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
118893 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
118894 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118895 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118896 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118897 +setup_req_5848 setup_req 3 5848 NULL
118898 +ria_page_count_5849 ria_page_count 0 5849 NULL
118899 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118900 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118901 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118902 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118903 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118904 +port_show_regs_5904 port_show_regs 3 5904 NULL
118905 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118906 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118907 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118908 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118909 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118910 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118911 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118912 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118913 +SyS_semop_5980 SyS_semop 3 5980 NULL
118914 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118915 +alloc_msg_6072 alloc_msg 1 6072 NULL
118916 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118917 +_random_read_6098 _random_read 3 6098 NULL
118918 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118919 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118920 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118921 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118922 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118923 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118924 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118925 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118926 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118927 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118928 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118929 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118930 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118931 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118932 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118933 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118934 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118935 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118936 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118937 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118938 +serial_port_in_6291 serial_port_in 0 6291 NULL
118939 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118940 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118941 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118942 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118943 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118944 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118945 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118946 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118947 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118948 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118949 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118950 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118951 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118952 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118953 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118954 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118955 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118956 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118957 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118958 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118959 +mei_read_6507 mei_read 3 6507 NULL
118960 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118961 +wdm_read_6549 wdm_read 3 6549 NULL
118962 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118963 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118964 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118965 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118966 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118967 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118968 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118969 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118970 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118971 +mpeg_read_6708 mpeg_read 3 6708 NULL
118972 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118973 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118974 +video_proc_write_6724 video_proc_write 3 6724 NULL
118975 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118976 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
118977 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118978 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118979 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118980 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118981 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118982 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118983 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118984 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
118985 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118986 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118987 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
118988 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118989 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118990 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118991 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118992 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118993 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118994 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118995 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118996 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118997 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118998 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118999 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
119000 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
119001 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
119002 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
119003 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
119004 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
119005 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
119006 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
119007 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
119008 +request_key_async_6990 request_key_async 4 6990 NULL
119009 +tpl_write_6998 tpl_write 3 6998 NULL
119010 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
119011 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
119012 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
119013 +wimax_msg_7030 wimax_msg 4 7030 NULL
119014 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
119015 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
119016 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
119017 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
119018 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
119019 +event_enable_read_7074 event_enable_read 3 7074 NULL
119020 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
119021 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
119022 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
119023 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
119024 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
119025 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
119026 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
119027 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
119028 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
119029 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
119030 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
119031 +get_string_7302 get_string 0 7302 NULL
119032 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
119033 +mgmt_control_7349 mgmt_control 3 7349 NULL
119034 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
119035 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
119036 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
119037 +hweight_long_7388 hweight_long 0-1 7388 NULL
119038 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
119039 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
119040 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
119041 +readb_7401 readb 0 7401 NULL
119042 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
119043 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
119044 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
119045 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
119046 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
119047 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
119048 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
119049 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
119050 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
119051 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
119052 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
119053 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
119054 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
119055 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
119056 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
119057 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
119058 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
119059 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
119060 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
119061 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
119062 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
119063 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
119064 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
119065 +dev_write_7708 dev_write 3 7708 NULL
119066 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
119067 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
119068 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
119069 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
119070 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
119071 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
119072 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
119073 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
119074 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
119075 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
119076 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
119077 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
119078 +config_desc_7878 config_desc 0 7878 NULL
119079 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
119080 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
119081 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
119082 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
119083 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
119084 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
119085 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
119086 +vcs_read_8017 vcs_read 3 8017 NULL
119087 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
119088 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
119089 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
119090 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
119091 +venus_lookup_8121 venus_lookup 4 8121 NULL
119092 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
119093 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
119094 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
119095 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
119096 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
119097 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
119098 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
119099 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
119100 +play_iframe_8219 play_iframe 3 8219 NULL
119101 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
119102 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
119103 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
119104 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
119105 +init_cdev_8274 init_cdev 1 8274 NULL
119106 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
119107 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
119108 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
119109 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
119110 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
119111 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
119112 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
119113 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
119114 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
119115 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
119116 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
119117 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
119118 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119119 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119120 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119121 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119122 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119123 +dev_config_8506 dev_config 3 8506 NULL
119124 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119125 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119126 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119127 +user_on_off_8552 user_on_off 2 8552 NULL
119128 +profile_remove_8556 profile_remove 3 8556 NULL
119129 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119130 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119131 +tower_write_8580 tower_write 3 8580 NULL
119132 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119133 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119134 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119135 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119136 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119137 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119138 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119139 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119140 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119141 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119142 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119143 +arcfb_write_8702 arcfb_write 3 8702 NULL
119144 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119145 +init_header_8703 init_header 0 8703 &i_size_read_8703
119146 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119147 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119148 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119149 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119150 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119151 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
119152 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119153 +compound_order_8750 compound_order 0 8750 NULL
119154 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
119155 +yurex_write_8761 yurex_write 3 8761 NULL
119156 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119157 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119158 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119159 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119160 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119161 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119162 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119163 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119164 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119165 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119166 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119167 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119168 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119169 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119170 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119171 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119172 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119173 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119174 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119175 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119176 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119177 +write_file_ani_8918 write_file_ani 3 8918 NULL
119178 +layout_commit_8926 layout_commit 3 8926 NULL
119179 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119180 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119181 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119182 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119183 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119184 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119185 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119186 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119187 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119188 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119189 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119190 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119191 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119192 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119193 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119194 +nla_put_9042 nla_put 3 9042 NULL
119195 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119196 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119197 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119198 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119199 +create_queues_9088 create_queues 2-3 9088 NULL
119200 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119201 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119202 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119203 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119204 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119205 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119206 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119207 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119208 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119209 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119210 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119211 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119212 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119213 +card_send_command_9215 card_send_command 3 9215 NULL
119214 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119215 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119216 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119217 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119218 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119219 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119220 +flakey_status_9274 flakey_status 5 9274 NULL
119221 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119222 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119223 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119224 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119225 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119226 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119227 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119228 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119229 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119230 +read_9397 read 3 9397 NULL
119231 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119232 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119233 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119234 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119235 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119236 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119237 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119238 +crypt_status_9492 crypt_status 5 9492 NULL
119239 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119240 +lp_write_9511 lp_write 3 9511 NULL
119241 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119242 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119243 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119244 +read_file_dma_9530 read_file_dma 3 9530 NULL
119245 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119246 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119247 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119248 +fw_node_create_9559 fw_node_create 2 9559 NULL
119249 +kobj_map_9566 kobj_map 2-3 9566 NULL
119250 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119251 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119252 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119253 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119254 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119255 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119256 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119257 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119258 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119259 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119260 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119261 +dns_query_9676 dns_query 3 9676 NULL
119262 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119263 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119264 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119265 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119266 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119267 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119268 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119269 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119270 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119271 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119272 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119273 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119274 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119275 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119276 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119277 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119278 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119279 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119280 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119281 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119282 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119283 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119284 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119285 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119286 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119287 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119288 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119289 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119290 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119291 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119292 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119293 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119294 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119295 +read_file_misc_9948 read_file_misc 3 9948 NULL
119296 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119297 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119298 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119299 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119300 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119301 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119302 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119303 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
119304 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119305 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119306 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119307 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119308 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119309 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119310 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119311 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119312 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119313 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119314 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119315 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119316 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119317 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119318 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119319 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119320 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119321 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119322 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119323 +read_emulate_10310 read_emulate 2-4 10310 NULL
119324 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119325 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119326 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119327 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119328 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119329 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119330 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119331 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119332 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119333 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119334 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119335 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119336 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119337 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119338 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119339 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119340 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119341 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119342 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119343 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119344 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119345 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119346 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119347 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119348 +otp_read_10594 otp_read 2-4-5 10594 NULL
119349 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119350 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119351 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119352 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119353 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119354 +parport_write_10669 parport_write 0 10669 NULL
119355 +edge_write_10692 edge_write 4 10692 NULL
119356 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119357 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119358 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119359 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119360 +spi_sync_10731 spi_sync 0 10731 NULL
119361 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119362 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119363 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119364 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119365 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119366 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119367 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119368 +ttm_dma_page_pool_free_10796 ttm_dma_page_pool_free 2-0 10796 NULL
119369 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119370 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119371 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119372 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119373 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119374 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119375 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119376 +get_scq_10897 get_scq 2 10897 NULL
119377 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119378 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119379 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119380 +kobject_add_10919 kobject_add 0 10919 NULL
119381 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119382 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119383 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119384 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119385 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119386 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119387 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119388 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119389 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119390 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
119391 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
119392 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119393 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119394 +count_argc_11083 count_argc 0 11083 NULL
119395 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119396 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119397 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
119398 +page_offset_11120 page_offset 0 11120 NULL
119399 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119400 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119401 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119402 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
119403 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119404 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119405 +of_irq_count_11253 of_irq_count 0 11253 NULL
119406 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119407 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119408 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119409 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119410 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119411 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119412 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119413 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119414 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119415 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119416 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119417 +next_segment_11330 next_segment 0-2-1 11330 NULL
119418 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119419 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119420 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119421 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119422 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119423 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119424 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119425 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119426 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119427 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119428 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119429 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119430 +str_to_user_11411 str_to_user 2 11411 NULL
119431 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119432 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119433 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119434 +trace_options_read_11419 trace_options_read 3 11419 NULL
119435 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119436 +bttv_read_11432 bttv_read 3 11432 NULL
119437 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119438 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119439 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119440 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119441 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119442 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119443 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119444 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119445 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119446 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119447 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119448 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119449 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119450 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119451 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119452 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119453 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119454 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119455 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119456 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119457 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119458 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119459 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119460 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119461 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119462 +split_11691 split 2 11691 NULL
119463 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119464 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119465 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119466 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119467 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119468 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119469 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119470 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119471 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119472 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119473 +umc_device_register_11824 umc_device_register 0 11824 NULL
119474 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119475 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119476 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119477 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119478 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
119479 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119480 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119481 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119482 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119483 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119484 +ti_write_11916 ti_write 4 11916 NULL
119485 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119486 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119487 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119488 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119489 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119490 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119491 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119492 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119493 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119494 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119495 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119496 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119497 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119498 +set_powered_12129 set_powered 4 12129 NULL
119499 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119500 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119501 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119502 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119503 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119504 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119505 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119506 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119507 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119508 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119509 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119510 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119511 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119512 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119513 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119514 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119515 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119516 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119517 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119518 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119519 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119520 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119521 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119522 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119523 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119524 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119525 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119526 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119527 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119528 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119529 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119530 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119531 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119532 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119533 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119534 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119535 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119536 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119537 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119538 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119539 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119540 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119541 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119542 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119543 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119544 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119545 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119546 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119547 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119548 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119549 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119550 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119551 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119552 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119553 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119554 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119555 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119556 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119557 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119558 +ivtv_write_12721 ivtv_write 3 12721 NULL
119559 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119560 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119561 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119562 +listxattr_12769 listxattr 3 12769 NULL
119563 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119564 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119565 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119566 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119567 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119568 +spidev_sync_12842 spidev_sync 0 12842 NULL
119569 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119570 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119571 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119572 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119573 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119574 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119575 +bm_status_write_12964 bm_status_write 3 12964 NULL
119576 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119577 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119578 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119579 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119580 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119581 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119582 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119583 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119584 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119585 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119586 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119587 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119588 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119589 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119590 +blk_update_request_13146 blk_update_request 3 13146 NULL
119591 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119592 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119593 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119594 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119595 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119596 +comedi_read_13199 comedi_read 3 13199 NULL
119597 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119598 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119599 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119600 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119601 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119602 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119603 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119604 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119605 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119606 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119607 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119608 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119609 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119610 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119611 +sd_major_13294 sd_major 0-1 13294 NULL
119612 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119613 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119614 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119615 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119616 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119617 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119618 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119619 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119620 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119621 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119622 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119623 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119624 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119625 +data_read_13494 data_read 3 13494 NULL nohasharray
119626 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119627 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119628 +core_status_13515 core_status 4 13515 NULL
119629 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119630 +bm_init_13529 bm_init 2 13529 NULL
119631 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119632 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119633 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119634 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119635 +cache_write_13589 cache_write 3 13589 NULL
119636 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119637 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119638 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119639 +packet_snd_13634 packet_snd 3 13634 NULL
119640 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119641 +cache_downcall_13666 cache_downcall 3 13666 NULL
119642 +usb_get_string_13693 usb_get_string 0 13693 NULL
119643 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119644 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119645 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119646 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119647 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119648 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
119649 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119650 +random_read_13815 random_read 3 13815 NULL
119651 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119652 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119653 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119654 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119655 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119656 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119657 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119658 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119659 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119660 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119661 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119662 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119663 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119664 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119665 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119666 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119667 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119668 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119669 +qcam_read_13977 qcam_read 3 13977 NULL
119670 +dsp_read_13980 dsp_read 2 13980 NULL
119671 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119672 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119673 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119674 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119675 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119676 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119677 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119678 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119679 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119680 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119681 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119682 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119683 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119684 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119685 +em_canid_change_14150 em_canid_change 3 14150 NULL
119686 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119687 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119688 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119689 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119690 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119691 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119692 +alloc_async_14208 alloc_async 1 14208 NULL
119693 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119694 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119695 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119696 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119697 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119698 +rr_status_14293 rr_status 5 14293 NULL
119699 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119700 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119701 +oo_objects_14319 oo_objects 0 14319 NULL
119702 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119703 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119704 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119705 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119706 +lowpan_read_14369 lowpan_read 3 14369 NULL
119707 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119708 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119709 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119710 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119711 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119712 +block_size_14443 block_size 0 14443 NULL
119713 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119714 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119715 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119716 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119717 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119718 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119719 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119720 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119721 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119722 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119723 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119724 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119725 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119726 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119727 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119728 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119729 +dbJoin_14644 dbJoin 0 14644 NULL
119730 +profile_replace_14652 profile_replace 3 14652 NULL
119731 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119732 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119733 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119734 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119735 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119736 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119737 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119738 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119739 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119740 +vfd_write_14717 vfd_write 3 14717 NULL
119741 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119742 +raid1_resize_14740 raid1_resize 2 14740 NULL
119743 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119744 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119745 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119746 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119747 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119748 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119749 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119750 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119751 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119752 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119753 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119754 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119755 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119756 +lcd_write_14857 lcd_write 3 14857 NULL
119757 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119758 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119759 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119760 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119761 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119762 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119763 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119764 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119765 +queue_cnt_14951 queue_cnt 0 14951 NULL
119766 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119767 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119768 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119769 +setkey_14987 setkey 3 14987 NULL nohasharray
119770 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119771 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119772 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119773 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119774 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119775 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119776 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119777 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119778 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119779 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119780 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119781 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119782 +start_port_15124 start_port 0 15124 NULL
119783 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119784 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119785 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119786 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119787 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119788 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119789 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119790 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119791 +simple_strtol_15273 simple_strtol 0 15273 NULL
119792 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119793 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119794 +ioread16_15342 ioread16 0 15342 NULL
119795 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119796 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
119797 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119798 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119799 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119800 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119801 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119802 +get_modalias_15406 get_modalias 2 15406 NULL
119803 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119804 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119805 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119806 +memweight_15450 memweight 2 15450 NULL
119807 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119808 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119809 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119810 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119811 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119812 +persistent_status_15574 persistent_status 4 15574 NULL
119813 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119814 +vme_user_write_15587 vme_user_write 3 15587 NULL
119815 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119816 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119817 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119818 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119819 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119820 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119821 +fs_path_add_15648 fs_path_add 3 15648 NULL
119822 +xsd_read_15653 xsd_read 3 15653 NULL
119823 +unix_bind_15668 unix_bind 3 15668 NULL
119824 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119825 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119826 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119827 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119828 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119829 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119830 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119831 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119832 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119833 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119834 +table_size_15851 table_size 0-1-2 15851 NULL
119835 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119836 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119837 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119838 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119839 +power_read_15939 power_read 3 15939 NULL
119840 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119841 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119842 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119843 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119844 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119845 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119846 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119847 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119848 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119849 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119850 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119851 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119852 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119853 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119854 +fsm_init_16134 fsm_init 2 16134 NULL
119855 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119856 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119857 +mapping_level_16188 mapping_level 2-0 16188 NULL
119858 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119859 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119860 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119861 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119862 +create_table_16213 create_table 2 16213 NULL
119863 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119864 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119865 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119866 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119867 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119868 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119869 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119870 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119871 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119872 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119873 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119874 +account_16283 account 0-4-2 16283 NULL nohasharray
119875 +mirror_status_16283 mirror_status 5 16283 &account_16283
119876 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119877 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119878 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119879 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119880 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119881 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119882 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119883 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119884 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119885 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119886 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119887 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119888 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119889 +cmdline_store_16442 cmdline_store 4 16442 NULL
119890 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119891 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119892 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119893 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119894 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119895 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119896 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119897 +raid10_resize_16537 raid10_resize 2 16537 NULL
119898 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119899 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119900 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119901 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119902 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119903 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119904 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119905 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119906 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119907 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119908 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119909 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119910 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119911 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119912 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119913 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119914 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119915 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119916 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119917 +st_write_16874 st_write 3 16874 NULL
119918 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119919 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119920 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119921 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119922 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119923 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119924 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119925 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119926 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119927 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119928 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119929 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119930 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119931 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119932 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119933 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119934 +entry_length_17093 entry_length 0 17093 NULL
119935 +write_mem_17114 write_mem 3 17114 NULL
119936 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119937 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119938 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119939 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119940 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119941 +sep_read_17161 sep_read 3 17161 NULL
119942 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119943 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119944 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119945 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119946 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119947 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119948 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119949 +sync_request_17208 sync_request 2 17208 NULL
119950 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119951 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119952 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119953 +alloc_ep_17269 alloc_ep 1 17269 NULL
119954 +pg_read_17276 pg_read 3 17276 NULL
119955 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119956 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119957 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119958 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119959 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119960 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119961 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119962 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119963 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119964 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119965 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119966 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119967 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
119968 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119969 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119970 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119971 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119972 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119973 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119974 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119975 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119976 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119977 +qp_free_res_17541 qp_free_res 5 17541 NULL
119978 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119979 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119980 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119981 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119982 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119983 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119984 +osst_execute_17607 osst_execute 7-6 17607 NULL
119985 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119986 +dma_map_page_17628 dma_map_page 0 17628 NULL
119987 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119988 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119989 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119990 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119991 +venus_rename_17707 venus_rename 4-5 17707 NULL
119992 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119993 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119994 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119995 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119996 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119997 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
119998 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119999 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
120000 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
120001 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
120002 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
120003 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
120004 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
120005 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
120006 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
120007 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
120008 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
120009 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
120010 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
120011 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
120012 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
120013 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
120014 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
120015 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
120016 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
120017 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
120018 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
120019 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
120020 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
120021 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
120022 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
120023 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
120024 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
120025 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
120026 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
120027 +fpregs_get_18066 fpregs_get 4 18066 NULL
120028 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
120029 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
120030 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
120031 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
120032 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
120033 +svc_getnl_18120 svc_getnl 0 18120 NULL
120034 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
120035 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
120036 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
120037 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
120038 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
120039 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
120040 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
120041 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
120042 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
120043 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
120044 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
120045 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
120046 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
120047 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
120048 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
120049 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
120050 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
120051 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
120052 +um_idi_write_18293 um_idi_write 3 18293 NULL
120053 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
120054 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
120055 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
120056 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
120057 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
120058 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
120059 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
120060 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
120061 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
120062 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
120063 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
120064 +ep_io_18367 ep_io 0 18367 NULL
120065 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
120066 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
120067 +ci_role_write_18388 ci_role_write 3 18388 NULL
120068 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
120069 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
120070 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
120071 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
120072 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
120073 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
120074 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
120075 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
120076 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
120077 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
120078 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
120079 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
120080 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
120081 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
120082 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
120083 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
120084 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
120085 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
120086 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
120087 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
120088 +debug_output_18575 debug_output 3 18575 NULL
120089 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
120090 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
120091 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
120092 +from_buffer_18625 from_buffer 3 18625 NULL
120093 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
120094 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
120095 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
120096 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
120097 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
120098 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
120099 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
120100 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
120101 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
120102 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
120103 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
120104 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
120105 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
120106 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
120107 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
120108 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
120109 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
120110 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
120111 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
120112 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
120113 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
120114 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
120115 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
120116 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
120117 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
120118 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120119 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120120 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
120121 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120122 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120123 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120124 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120125 +huge_page_size_19008 huge_page_size 0 19008 NULL
120126 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120127 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120128 +revalidate_19043 revalidate 2 19043 NULL
120129 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120130 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120131 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120132 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120133 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120134 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120135 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120136 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120137 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120138 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120139 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120140 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120141 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120142 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120143 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120144 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120145 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120146 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120147 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120148 +ucma_query_19260 ucma_query 4 19260 NULL
120149 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120150 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120151 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120152 +qc_capture_19298 qc_capture 3 19298 NULL
120153 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120154 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120155 +debug_read_19322 debug_read 3 19322 NULL
120156 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120157 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120158 +closure_sub_19359 closure_sub 2 19359 NULL
120159 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120160 +read_zero_19366 read_zero 3 19366 NULL
120161 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120162 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120163 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120164 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120165 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120166 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120167 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120168 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120169 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120170 +sky2_read16_19475 sky2_read16 0 19475 NULL
120171 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120172 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120173 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120174 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120175 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120176 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120177 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120178 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120179 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120180 +nfsd_read_19568 nfsd_read 5 19568 NULL
120181 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120182 +bm_status_read_19583 bm_status_read 3 19583 NULL
120183 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120184 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120185 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120186 +parser_init_19651 parser_init 2 19651 NULL
120187 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120188 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120189 +read_reg_19723 read_reg 0 19723 NULL
120190 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120191 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120192 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120193 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120194 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120195 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120196 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120197 +readhscx_19769 readhscx 0 19769 NULL
120198 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120199 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120200 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120201 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120202 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120203 +__nla_put_19857 __nla_put 3 19857 NULL
120204 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120205 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120206 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120207 +mangle_name_19923 mangle_name 0 19923 NULL
120208 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
120209 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120210 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120211 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120212 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120213 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120214 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120215 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120216 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120217 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120218 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
120219 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
120220 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120221 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120222 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120223 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120224 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120225 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120226 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120227 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120228 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120229 +target_message_20072 target_message 2 20072 NULL
120230 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120231 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120232 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120233 +team_options_register_20091 team_options_register 3 20091 NULL
120234 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120235 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120236 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120237 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120238 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120239 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120240 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120241 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120242 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120243 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120244 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120245 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120246 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120247 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120248 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120249 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120250 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120251 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120252 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120253 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120254 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120255 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120256 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120257 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120258 +read_buf_20469 read_buf 2 20469 NULL
120259 +bio_trim_20472 bio_trim 2 20472 NULL
120260 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120261 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120262 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120263 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120264 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120265 +venus_create_20555 venus_create 4 20555 NULL
120266 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120267 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120268 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120269 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120270 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120271 +lirc_write_20604 lirc_write 3 20604 NULL
120272 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120273 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120274 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120275 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120276 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120277 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120278 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120279 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120280 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120281 +cpumask_size_20683 cpumask_size 0 20683 NULL
120282 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120283 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120284 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120285 +__maestro_read_20700 __maestro_read 0 20700 NULL
120286 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120287 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120288 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120289 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120290 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120291 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120292 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120293 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120294 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120295 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120296 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120297 +edid_write_20797 edid_write 3 20797 NULL
120298 +lowpan_write_20800 lowpan_write 3 20800 NULL
120299 +strndup_user_20819 strndup_user 2 20819 NULL
120300 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120301 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120302 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120303 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120304 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120305 +get_name_20855 get_name 4 20855 NULL
120306 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120307 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120308 +srq_free_res_20868 srq_free_res 5 20868 NULL
120309 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120310 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120311 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120312 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120313 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120314 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120315 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120316 +htable_bits_20933 htable_bits 0 20933 NULL
120317 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
120318 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120319 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120320 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120321 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120322 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120323 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120324 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120325 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120326 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120327 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120328 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120329 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120330 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120331 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120332 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120333 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120334 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120335 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120336 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120337 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120338 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120339 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120340 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120341 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
120342 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120343 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120344 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120345 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120346 +input_ff_create_21240 input_ff_create 2 21240 NULL
120347 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120348 +fru_length_21257 fru_length 0 21257 NULL
120349 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120350 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120351 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120352 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120353 +add_res_range_21310 add_res_range 4 21310 NULL
120354 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120355 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120356 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120357 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120358 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120359 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120360 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120361 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120362 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120363 +insert_ptr_21386 insert_ptr 6 21386 NULL
120364 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120365 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120366 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120367 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120368 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120369 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120370 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120371 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120372 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120373 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120374 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120375 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120376 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120377 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120378 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120379 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120380 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120381 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120382 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120383 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120384 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120385 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120386 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120387 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120388 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
120389 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
120390 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120391 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120392 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120393 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120394 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120395 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120396 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120397 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120398 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120399 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120400 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120401 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120402 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
120403 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120404 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120405 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120406 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
120407 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
120408 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120409 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120410 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120411 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120412 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120413 +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
120414 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120415 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120416 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120417 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120418 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120419 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120420 +mem_rw_22085 mem_rw 3 22085 NULL
120421 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120422 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120423 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120424 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120425 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120426 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120427 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120428 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120429 +mem_write_22232 mem_write 3 22232 NULL
120430 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120431 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120432 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120433 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120434 +add_res_tree_22263 add_res_tree 7 22263 NULL
120435 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120436 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120437 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120438 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120439 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120440 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120441 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120442 +atomic_read_22342 atomic_read 0 22342 NULL
120443 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120444 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120445 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120446 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120447 +zoran_write_22404 zoran_write 3 22404 NULL
120448 +queue_reply_22416 queue_reply 3 22416 NULL
120449 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120450 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120451 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120452 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120453 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
120454 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
120455 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120456 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120457 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120458 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
120459 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120460 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120461 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120462 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120463 +snapshot_read_22601 snapshot_read 3 22601 NULL
120464 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120465 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120466 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120467 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120468 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120469 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120470 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120471 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120472 +reg_umr_22686 reg_umr 5 22686 NULL
120473 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120474 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120475 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120476 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120477 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120478 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120479 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120480 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120481 +print_frame_22769 print_frame 0 22769 NULL
120482 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120483 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120484 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120485 +create_attr_set_22861 create_attr_set 1 22861 NULL
120486 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120487 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120488 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120489 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120490 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120491 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120492 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120493 +__set_xattr_22923 __set_xattr 0 22923 NULL
120494 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120495 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120496 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120497 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120498 +vme_get_size_22964 vme_get_size 0 22964 NULL
120499 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120500 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120501 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120502 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120503 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120504 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120505 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120506 +st_status_23032 st_status 5 23032 NULL
120507 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120508 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120509 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120510 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120511 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120512 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120513 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120514 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120515 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120516 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120517 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120518 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120519 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120520 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120521 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120522 +__clear_user_23118 __clear_user 0-2 23118 NULL
120523 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120524 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120525 +read_file_ani_23161 read_file_ani 3 23161 NULL
120526 +usblp_write_23178 usblp_write 3 23178 NULL
120527 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120528 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120529 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120530 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
120531 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120532 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120533 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120534 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120535 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120536 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120537 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120538 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120539 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120540 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120541 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120542 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120543 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120544 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120545 +page_readlink_23346 page_readlink 3 23346 NULL
120546 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120547 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120548 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120549 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120550 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120551 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120552 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120553 +linear_conf_23485 linear_conf 2 23485 NULL
120554 +event_filter_read_23494 event_filter_read 3 23494 NULL
120555 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120556 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120557 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120558 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120559 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120560 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120561 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120562 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120563 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120564 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120565 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120566 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120567 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120568 +sInW_23663 sInW 0 23663 NULL
120569 +SyS_connect_23669 SyS_connect 3 23669 NULL
120570 +cx18_read_23699 cx18_read 3 23699 NULL
120571 +at_get_23708 at_get 0 23708 NULL
120572 +get_conn_info_23723 get_conn_info 4 23723 NULL
120573 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120574 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120575 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120576 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120577 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120578 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120579 +map_write_23795 map_write 3 23795 NULL
120580 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120581 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120582 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120583 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120584 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120585 +p54_init_common_23850 p54_init_common 1 23850 NULL
120586 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120587 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120588 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120589 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120590 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120591 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120592 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120593 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120594 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120595 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120596 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120597 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120598 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120599 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120600 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120601 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120602 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
120603 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120604 +give_pages_24021 give_pages 3 24021 NULL
120605 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120606 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120607 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120608 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120609 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120610 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120611 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120612 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120613 +lov_brw_24122 lov_brw 4 24122 NULL
120614 +mpu401_read_24126 mpu401_read 3 24126 NULL
120615 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120616 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120617 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120618 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120619 +adu_read_24177 adu_read 3 24177 NULL
120620 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120621 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120622 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120623 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
120624 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120625 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120626 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120627 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120628 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120629 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120630 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120631 +thin_status_24278 thin_status 5 24278 NULL
120632 +msg_size_24288 msg_size 0 24288 NULL
120633 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120634 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120635 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120636 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120637 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120638 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120639 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120640 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120641 +igetword_24373 igetword 0 24373 NULL
120642 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120643 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120644 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120645 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120646 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
120647 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120648 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120649 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120650 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120651 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120652 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120653 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120654 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120655 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120656 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120657 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120658 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120659 +ttm_page_pool_free_24486 ttm_page_pool_free 2-0 24486 NULL
120660 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120661 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120662 +pd_video_read_24510 pd_video_read 3 24510 NULL
120663 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120664 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120665 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120666 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120667 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120668 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120669 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120670 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
120671 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
120672 +SyS_poll_24620 SyS_poll 2 24620 NULL
120673 +context_alloc_24645 context_alloc 3 24645 NULL
120674 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120675 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120676 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120677 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120678 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120679 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120680 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120681 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120682 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120683 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120684 +cache_read_24790 cache_read 3 24790 NULL
120685 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120686 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120687 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120688 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120689 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120690 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120691 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120692 +queues_read_24877 queues_read 3 24877 NULL
120693 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120694 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120695 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120696 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120697 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120698 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120699 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120700 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
120701 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
120702 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120703 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120704 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120705 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120706 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120707 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120708 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120709 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120710 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120711 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
120712 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120713 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120714 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120715 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120716 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120717 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120718 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120719 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120720 +stripe_status_25259 stripe_status 5 25259 NULL
120721 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120722 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120723 +vfs_writev_25278 vfs_writev 3 25278 NULL
120724 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120725 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
120726 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120727 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120728 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120729 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120730 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120731 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120732 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120733 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120734 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120735 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120736 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120737 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120738 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120739 +sb_permission_25523 sb_permission 0 25523 NULL
120740 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120741 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120742 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120743 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120744 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120745 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120746 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120747 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120748 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120749 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120750 +__direct_map_25647 __direct_map 6-5 25647 NULL
120751 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120752 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120753 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120754 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120755 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120756 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120757 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120758 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120759 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120760 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120761 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120762 +sg_read_25799 sg_read 3 25799 NULL
120763 +system_enable_read_25815 system_enable_read 3 25815 NULL
120764 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120765 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120766 +parport_read_25855 parport_read 0 25855 NULL
120767 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120768 +key_attr_size_25865 key_attr_size 0 25865 NULL
120769 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120770 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120771 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120772 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120773 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120774 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120775 +rcname_read_25919 rcname_read 3 25919 NULL
120776 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120777 +key_flags_read_25931 key_flags_read 3 25931 NULL
120778 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120779 +flush_25957 flush 2 25957 NULL
120780 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120781 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120782 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120783 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120784 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120785 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120786 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120787 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120788 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120789 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120790 +read_sb_page_26119 read_sb_page 5 26119 NULL
120791 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120792 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120793 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120794 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120795 +disk_devt_26180 disk_devt 0 26180 NULL
120796 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120797 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120798 +mce_write_26201 mce_write 3 26201 NULL
120799 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120800 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120801 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120802 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
120803 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120804 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120805 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120806 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120807 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120808 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120809 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120810 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120811 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120812 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120813 +ntty_write_26404 ntty_write 3 26404 NULL
120814 +firmware_store_26408 firmware_store 4 26408 NULL
120815 +pagemap_read_26441 pagemap_read 3 26441 NULL
120816 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120817 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120818 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120819 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120820 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
120821 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
120822 +read_vmcore_26501 read_vmcore 3 26501 NULL
120823 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120824 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120825 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120826 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120827 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120828 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120829 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120830 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120831 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120832 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120833 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120834 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120835 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120836 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120837 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120838 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120839 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120840 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120841 +bos_desc_26752 bos_desc 0 26752 NULL
120842 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120843 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120844 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120845 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120846 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120847 +smk_write_load_26829 smk_write_load 3 26829 NULL
120848 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
120849 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120850 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120851 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120852 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120853 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120854 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120855 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120856 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120857 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120858 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120859 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120860 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120861 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120862 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120863 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120864 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120865 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120866 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120867 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120868 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120869 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120870 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120871 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120872 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120873 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120874 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120875 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120876 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120877 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120878 +pms_capture_27142 pms_capture 4 27142 NULL
120879 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120880 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120881 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120882 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120883 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120884 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120885 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120886 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120887 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120888 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120889 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120890 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120891 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120892 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120893 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120894 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120895 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120896 +seq_read_27411 seq_read 3 27411 NULL
120897 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120898 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120899 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120900 +cypress_write_27423 cypress_write 4 27423 NULL
120901 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120902 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120903 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120904 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120905 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120906 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
120907 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
120908 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120909 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120910 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120911 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120912 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120913 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120914 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120915 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120916 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120917 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120918 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120919 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120920 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120921 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120922 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120923 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120924 +evm_write_key_27715 evm_write_key 3 27715 NULL
120925 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120926 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120927 +load_scode_27738 load_scode 2 27738 NULL
120928 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120929 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120930 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120931 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120932 +SyS_readv_27804 SyS_readv 3 27804 NULL
120933 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120934 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120935 +init_header_complete_27833 init_header_complete 0 27833 NULL
120936 +read_profile_27859 read_profile 3 27859 NULL
120937 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120938 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120939 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120940 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120941 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120942 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120943 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120944 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120945 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120946 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120947 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120948 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120949 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120950 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120951 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120952 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120953 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120954 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120955 +pool_status_28055 pool_status 5 28055 NULL
120956 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120957 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120958 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120959 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120960 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120961 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120962 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120963 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120964 +video_read_28148 video_read 3 28148 NULL
120965 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120966 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120967 +vread_28173 vread 0-3 28173 NULL
120968 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120969 +counter_free_res_28187 counter_free_res 5 28187 NULL
120970 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120971 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120972 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120973 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120974 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120975 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120976 +usemap_size_28281 usemap_size 0 28281 NULL
120977 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120978 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120979 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120980 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120981 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120982 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120983 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120984 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120985 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120986 +snapshot_write_28351 snapshot_write 3 28351 NULL
120987 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120988 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120989 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120990 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120991 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120992 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120993 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120994 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120995 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120996 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120997 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120998 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120999 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
121000 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
121001 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
121002 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
121003 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
121004 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
121005 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
121006 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
121007 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
121008 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
121009 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
121010 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
121011 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
121012 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
121013 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
121014 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
121015 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
121016 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
121017 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
121018 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
121019 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
121020 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
121021 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
121022 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
121023 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
121024 +spi_execute_28736 spi_execute 5 28736 NULL
121025 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
121026 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
121027 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
121028 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
121029 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
121030 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
121031 +sel_write_member_28800 sel_write_member 3 28800 NULL
121032 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
121033 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
121034 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
121035 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
121036 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
121037 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
121038 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
121039 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
121040 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
121041 +push_rx_28939 push_rx 3 28939 NULL
121042 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
121043 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
121044 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
121045 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
121046 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
121047 +bin_uuid_28999 bin_uuid 3 28999 NULL
121048 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
121049 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
121050 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
121051 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
121052 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
121053 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
121054 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
121055 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
121056 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
121057 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
121058 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
121059 +snprintf_29125 snprintf 0 29125 NULL
121060 +iov_shorten_29130 iov_shorten 0 29130 NULL
121061 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
121062 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
121063 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
121064 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
121065 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
121066 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
121067 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
121068 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
121069 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
121070 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
121071 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
121072 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
121073 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
121074 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
121075 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
121076 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
121077 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
121078 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
121079 +tun_put_user_29337 tun_put_user 5 29337 NULL
121080 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
121081 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
121082 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
121083 +mempool_create_29437 mempool_create 1 29437 NULL
121084 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
121085 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
121086 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
121087 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
121088 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
121089 +do_register_entry_29478 do_register_entry 4 29478 NULL
121090 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
121091 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
121092 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
121093 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
121094 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
121095 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
121096 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
121097 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
121098 +ftrace_write_29551 ftrace_write 3 29551 NULL
121099 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
121100 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
121101 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
121102 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
121103 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
121104 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
121105 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
121106 +slots_per_page_29601 slots_per_page 0 29601 NULL
121107 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
121108 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
121109 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
121110 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
121111 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
121112 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
121113 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
121114 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
121115 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
121116 +probes_write_29711 probes_write 3 29711 NULL
121117 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
121118 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121119 +std_nic_write_29752 std_nic_write 3 29752 NULL
121120 +static_key_count_29771 static_key_count 0 29771 NULL
121121 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
121122 +dbAlloc_29794 dbAlloc 0 29794 NULL
121123 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121124 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121125 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121126 +count_partial_29850 count_partial 0 29850 NULL
121127 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121128 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121129 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121130 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121131 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121132 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121133 +write_file_queue_29922 write_file_queue 3 29922 NULL
121134 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121135 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121136 +zero_iovec_29955 zero_iovec 1 29955 NULL
121137 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121138 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121139 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121140 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121141 +drp_wmove_30043 drp_wmove 4 30043 NULL
121142 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121143 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121144 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121145 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121146 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121147 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121148 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121149 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121150 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121151 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121152 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121153 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121154 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121155 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121156 +SyS_semop_30227 SyS_semop 3 30227 NULL
121157 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121158 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121159 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121160 +compat_readv_30273 compat_readv 3 30273 NULL
121161 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121162 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121163 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121164 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121165 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121166 +i8254_read_30330 i8254_read 0 30330 NULL
121167 +resource_from_user_30341 resource_from_user 3 30341 NULL
121168 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121169 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121170 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121171 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121172 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121173 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121174 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121175 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121176 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121177 +enable_write_30456 enable_write 3 30456 NULL
121178 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121179 +urandom_read_30462 urandom_read 3 30462 NULL
121180 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121181 +adu_write_30487 adu_write 3 30487 NULL
121182 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121183 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121184 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121185 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121186 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121187 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121188 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
121189 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
121190 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121191 +set_le_30581 set_le 4 30581 NULL
121192 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121193 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121194 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121195 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121196 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121197 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121198 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121199 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121200 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121201 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121202 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121203 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121204 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121205 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121206 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121207 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121208 +snapshot_status_30744 snapshot_status 5 30744 NULL
121209 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121210 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121211 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121212 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121213 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121214 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121215 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121216 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121217 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
121218 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121219 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121220 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121221 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
121222 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121223 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121224 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121225 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121226 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121227 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121228 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121229 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121230 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121231 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121232 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121233 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121234 +depth_read_31112 depth_read 3 31112 NULL
121235 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121236 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121237 +size_inside_page_31141 size_inside_page 0 31141 NULL
121238 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121239 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
121240 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121241 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121242 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121243 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121244 +__read_reg_31216 __read_reg 0 31216 NULL
121245 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121246 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121247 +cyy_readb_31240 cyy_readb 0 31240 NULL
121248 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121249 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121250 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121251 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
121252 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121253 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121254 +command_file_write_31318 command_file_write 3 31318 NULL
121255 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121256 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121257 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121258 +outlen_write_31358 outlen_write 3 31358 NULL
121259 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121260 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121261 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121262 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121263 +inb_31388 inb 0 31388 NULL
121264 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121265 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121266 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121267 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121268 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121269 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121270 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121271 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121272 +alg_setkey_31485 alg_setkey 3 31485 NULL
121273 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121274 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121275 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121276 +hidraw_write_31536 hidraw_write 3 31536 NULL
121277 +usbvision_read_31555 usbvision_read 3 31555 NULL
121278 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121279 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121280 +osst_write_31581 osst_write 3 31581 NULL
121281 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121282 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121283 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121284 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121285 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121286 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121287 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121288 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121289 +__lgread_31668 __lgread 4 31668 NULL
121290 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121291 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121292 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121293 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121294 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121295 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121296 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121297 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121298 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121299 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121300 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121301 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121302 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121303 +get_count_order_31800 get_count_order 0 31800 NULL
121304 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121305 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121306 +data_write_31805 data_write 3 31805 NULL
121307 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121308 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121309 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121310 +clone_bio_31854 clone_bio 4-3 31854 NULL
121311 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121312 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121313 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121314 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121315 +xattr_permission_31907 xattr_permission 0 31907 NULL
121316 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121317 +new_dir_31919 new_dir 3 31919 NULL
121318 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121319 +era_status_31934 era_status 5 31934 NULL
121320 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121321 +read_mem_31942 read_mem 3 31942 NULL
121322 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121323 +vb2_write_31948 vb2_write 3 31948 NULL
121324 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121325 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121326 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121327 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121328 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121329 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121330 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121331 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121332 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121333 +calc_hmac_32010 calc_hmac 3 32010 NULL
121334 +aead_len_32021 aead_len 0 32021 NULL
121335 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121336 +stk_read_32038 stk_read 3 32038 NULL
121337 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121338 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121339 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121340 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121341 +bio_alloc_32095 bio_alloc 2 32095 NULL
121342 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121343 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
121344 +disk_status_32120 disk_status 4 32120 NULL
121345 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121346 +venus_link_32165 venus_link 5 32165 NULL
121347 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121348 +do_writepages_32173 do_writepages 0 32173 NULL
121349 +del_ptr_32197 del_ptr 4 32197 NULL
121350 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121351 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121352 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121353 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121354 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121355 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121356 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121357 +SyS_select_32319 SyS_select 1 32319 NULL
121358 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121359 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121360 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121361 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121362 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121363 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121364 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121365 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121366 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121367 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121368 +cache_status_32462 cache_status 5 32462 NULL
121369 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121370 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121371 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121372 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121373 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121374 +disconnect_32521 disconnect 4 32521 NULL
121375 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121376 +ilo_read_32531 ilo_read 3 32531 NULL
121377 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121378 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121379 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121380 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121381 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121382 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121383 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121384 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121385 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121386 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121387 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121388 +kvmalloc_32646 kvmalloc 1 32646 NULL
121389 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121390 +generic_readlink_32654 generic_readlink 3 32654 NULL
121391 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121392 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121393 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121394 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121395 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121396 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121397 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121398 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121399 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121400 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121401 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121402 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121403 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121404 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121405 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121406 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121407 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121408 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121409 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121410 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121411 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121412 +compat_filldir_32999 compat_filldir 3 32999 NULL
121413 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121414 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121415 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121416 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121417 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121418 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121419 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121420 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121421 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121422 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121423 +alloc_tio_33077 alloc_tio 3 33077 NULL
121424 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121425 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121426 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121427 +SyS_poll_33152 SyS_poll 2 33152 NULL
121428 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121429 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121430 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121431 +pp_read_33210 pp_read 3 33210 NULL
121432 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121433 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121434 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121435 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121436 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121437 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121438 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121439 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121440 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121441 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121442 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121443 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121444 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121445 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121446 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121447 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121448 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121449 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121450 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121451 +message_stats_list_33440 message_stats_list 5 33440 NULL
121452 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121453 +create_entry_33479 create_entry 2 33479 NULL
121454 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121455 +res_counter_read_33499 res_counter_read 4 33499 NULL
121456 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121457 +fb_read_33506 fb_read 3 33506 NULL
121458 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121459 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121460 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121461 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121462 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121463 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121464 +count_subheaders_33591 count_subheaders 0 33591 NULL
121465 +scsi_execute_33596 scsi_execute 5 33596 NULL
121466 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121467 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121468 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121469 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121470 +stride_page_count_33641 stride_page_count 2 33641 NULL
121471 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121472 +inw_p_33668 inw_p 0 33668 NULL
121473 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121474 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121475 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121476 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121477 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121478 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121479 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121480 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121481 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121482 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121483 +hashtab_create_33769 hashtab_create 3 33769 NULL
121484 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121485 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121486 +filter_write_33819 filter_write 3 33819 NULL
121487 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121488 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121489 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121490 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121491 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121492 +get_user_pages_33908 get_user_pages 0 33908 NULL
121493 +sg_nents_33909 sg_nents 0 33909 NULL
121494 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121495 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121496 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121497 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121498 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121499 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121500 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121501 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121502 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121503 +ppp_write_34034 ppp_write 3 34034 NULL
121504 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121505 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121506 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121507 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121508 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121509 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121510 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121511 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121512 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121513 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121514 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121515 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121516 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
121517 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
121518 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121519 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121520 +device_private_init_34279 device_private_init 0 34279 NULL
121521 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121522 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121523 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121524 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121525 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121526 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121527 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121528 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121529 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121530 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121531 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121532 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121533 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121534 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121535 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121536 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121537 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121538 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121539 +security_socket_create_34439 security_socket_create 0 34439 NULL
121540 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121541 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121542 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121543 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121544 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121545 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121546 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121547 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121548 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121549 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121550 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121551 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121552 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121553 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121554 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121555 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121556 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121557 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121558 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121559 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121560 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121561 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121562 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121563 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121564 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121565 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121566 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121567 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121568 +port_print_34704 port_print 3 34704 NULL
121569 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121570 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121571 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121572 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121573 +bootmode_store_34762 bootmode_store 4 34762 NULL
121574 +device_add_34766 device_add 0 34766 NULL
121575 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121576 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121577 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121578 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121579 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121580 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121581 +file_page_index_34820 file_page_index 0-2 34820 NULL
121582 +bio_segments_34832 bio_segments 0 34832 NULL
121583 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121584 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121585 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121586 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121587 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121588 +msg_print_text_34889 msg_print_text 0 34889 NULL
121589 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121590 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121591 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121592 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121593 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121594 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121595 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121596 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121597 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121598 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121599 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121600 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121601 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121602 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121603 +proc_setgroups_write_35039 proc_setgroups_write 3 35039 NULL
121604 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121605 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121606 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121607 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121608 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121609 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121610 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121611 +message_stats_print_35158 message_stats_print 6 35158 NULL
121612 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121613 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121614 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121615 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121616 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121617 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121618 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121619 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121620 +set_fd_set_35249 set_fd_set 1 35249 NULL
121621 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121622 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121623 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121624 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121625 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121626 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
121627 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
121628 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121629 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121630 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121631 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121632 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121633 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121634 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121635 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121636 +read_kmem_35372 read_kmem 3 35372 NULL
121637 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121638 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121639 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121640 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121641 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121642 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121643 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121644 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121645 +async_setkey_35521 async_setkey 3 35521 NULL
121646 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121647 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121648 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121649 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121650 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121651 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121652 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121653 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121654 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121655 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121656 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121657 +kernel_readv_35617 kernel_readv 3 35617 NULL
121658 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121659 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121660 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121661 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121662 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121663 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121664 +md_super_write_35703 md_super_write 4 35703 NULL
121665 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121666 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121667 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121668 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121669 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121670 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121671 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121672 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121673 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121674 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121675 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121676 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121677 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121678 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121679 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121680 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121681 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121682 +acl_alloc_35979 acl_alloc 1 35979 NULL
121683 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121684 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121685 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121686 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121687 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121688 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121689 +account_shadowed_36048 account_shadowed 2 36048 NULL
121690 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121691 +write_emulate_36065 write_emulate 2-4 36065 NULL
121692 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121693 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121694 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121695 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121696 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121697 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121698 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121699 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121700 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121701 +twl_set_36154 twl_set 2 36154 NULL
121702 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121703 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121704 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121705 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121706 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121707 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121708 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121709 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121710 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121711 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121712 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121713 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121714 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121715 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121716 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121717 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121718 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121719 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121720 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121721 +lc_create_36332 lc_create 4 36332 NULL
121722 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121723 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121724 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121725 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121726 +to_sector_36361 to_sector 0-1 36361 NULL
121727 +tunables_read_36385 tunables_read 3 36385 NULL
121728 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121729 +sierra_write_36402 sierra_write 4 36402 NULL
121730 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121731 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121732 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121733 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121734 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121735 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121736 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121737 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121738 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121739 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121740 +cmd_loop_36491 cmd_loop 0 36491 NULL
121741 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121742 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121743 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121744 +get_param_l_36518 get_param_l 0 36518 NULL
121745 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121746 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121747 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121748 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121749 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121750 +__erst_read_36579 __erst_read 0 36579 NULL
121751 +put_cmsg_36589 put_cmsg 4 36589 NULL
121752 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121753 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121754 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121755 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121756 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121757 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121758 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121759 +xillybus_read_36678 xillybus_read 3 36678 NULL
121760 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121761 +path_getxattr_36717 path_getxattr 4 36717 NULL
121762 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121763 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121764 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121765 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121766 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121767 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121768 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121769 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121770 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121771 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121772 +cm_write_36858 cm_write 3 36858 NULL
121773 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121774 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121775 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121776 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121777 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121778 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121779 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121780 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121781 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121782 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121783 +setxattr_37006 setxattr 4 37006 NULL
121784 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121785 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121786 +command_file_read_37038 command_file_read 3 37038 NULL
121787 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121788 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121789 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121790 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121791 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121792 +parse_command_37079 parse_command 2 37079 NULL
121793 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121794 +tun_get_user_37094 tun_get_user 5 37094 NULL
121795 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121796 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121797 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121798 +msg_word_37164 msg_word 0 37164 NULL
121799 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121800 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121801 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121802 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121803 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121804 +__do_replace_37227 __do_replace 5 37227 NULL
121805 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121806 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121807 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121808 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121809 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121810 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121811 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121812 +tipc_send_37315 tipc_send 3 37315 NULL
121813 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121814 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121815 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121816 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121817 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121818 +seek_firmware_37372 seek_firmware 2 37372 NULL
121819 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121820 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121821 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121822 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121823 +fru_alloc_37442 fru_alloc 1 37442 NULL
121824 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121825 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121826 +get_est_timing_37484 get_est_timing 0 37484 NULL
121827 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121828 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121829 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121830 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121831 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121832 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121833 +hdr_size_37536 hdr_size 0 37536 NULL
121834 +extent_map_end_37550 extent_map_end 0 37550 NULL
121835 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121836 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121837 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121838 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121839 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121840 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121841 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121842 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121843 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121844 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121845 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121846 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121847 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121848 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121849 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121850 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121851 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121852 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121853 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121854 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121855 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121856 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121857 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121858 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121859 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121860 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121861 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121862 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121863 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121864 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121865 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121866 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121867 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121868 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121869 +write_file_bool_37957 write_file_bool 3 37957 NULL
121870 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121871 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121872 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121873 +vfs_readv_38011 vfs_readv 3 38011 NULL
121874 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121875 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121876 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121877 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121878 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121879 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121880 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121881 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121882 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121883 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121884 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121885 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121886 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121887 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121888 +ep0_read_38095 ep0_read 3 38095 NULL
121889 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121890 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121891 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121892 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121893 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121894 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121895 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121896 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121897 +cdev_add_38176 cdev_add 2-3 38176 NULL
121898 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121899 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121900 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121901 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121902 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121903 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121904 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121905 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121906 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121907 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121908 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121909 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121910 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121911 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121912 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121913 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121914 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121915 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121916 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121917 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121918 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121919 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121920 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121921 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121922 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121923 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121924 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121925 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121926 +dev_names_read_38509 dev_names_read 3 38509 NULL
121927 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121928 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121929 +set_queue_count_38519 set_queue_count 0 38519 NULL
121930 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121931 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121932 +kuc_len_38557 kuc_len 0-1 38557 NULL
121933 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121934 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121935 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121936 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121937 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121938 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121939 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121940 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121941 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121942 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121943 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121944 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121945 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121946 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121947 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121948 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121949 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121950 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121951 +udf_readpages_38761 udf_readpages 4 38761 NULL
121952 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121953 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121954 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121955 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121956 +err_decode_38804 err_decode 2 38804 NULL
121957 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121958 +direct_entry_38836 direct_entry 3 38836 NULL
121959 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121960 +interfaces_38859 interfaces 2 38859 NULL
121961 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121962 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121963 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121964 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121965 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121966 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121967 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121968 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121969 +get_nodes_39012 get_nodes 3 39012 NULL
121970 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121971 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121972 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121973 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121974 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121975 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121976 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121977 +ea_foreach_39133 ea_foreach 0 39133 NULL
121978 +generic_permission_39150 generic_permission 0 39150 NULL
121979 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121980 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121981 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121982 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121983 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
121984 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121985 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121986 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121987 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121988 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121989 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121990 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121991 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121992 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121993 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121994 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121995 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121996 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121997 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121998 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121999 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
122000 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
122001 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
122002 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
122003 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
122004 +__send_to_port_39386 __send_to_port 3 39386 NULL
122005 +user_power_read_39414 user_power_read 3 39414 NULL
122006 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
122007 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
122008 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
122009 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
122010 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
122011 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
122012 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
122013 +int_proc_write_39542 int_proc_write 3 39542 NULL
122014 +pp_write_39554 pp_write 3 39554 NULL
122015 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
122016 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
122017 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
122018 +ext_depth_39607 ext_depth 0 39607 NULL
122019 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
122020 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
122021 +sdio_readb_39618 sdio_readb 0 39618 NULL
122022 +set_dev_class_39645 set_dev_class 4 39645 NULL
122023 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
122024 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
122025 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
122026 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
122027 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
122028 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
122029 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
122030 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
122031 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
122032 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
122033 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
122034 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
122035 +pkt_add_39897 pkt_add 3 39897 NULL
122036 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
122037 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
122038 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
122039 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
122040 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
122041 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
122042 +__spi_async_39932 __spi_async 0 39932 NULL
122043 +__get_order_39935 __get_order 0 39935 NULL
122044 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
122045 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
122046 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
122047 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
122048 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
122049 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
122050 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
122051 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
122052 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
122053 +server_name2svname_39998 server_name2svname 4 39998 NULL
122054 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
122055 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
122056 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
122057 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
122058 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
122059 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
122060 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
122061 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
122062 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
122063 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
122064 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
122065 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
122066 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
122067 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
122068 +pt_write_40159 pt_write 3 40159 NULL
122069 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
122070 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
122071 +allocate_probes_40204 allocate_probes 1 40204 NULL
122072 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
122073 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
122074 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
122075 +osst_read_40237 osst_read 3 40237 NULL
122076 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
122077 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
122078 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
122079 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
122080 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
122081 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
122082 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
122083 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
122084 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
122085 +SyS_bind_40303 SyS_bind 3 40303 NULL
122086 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
122087 +mmio_read_40348 mmio_read 4 40348 NULL
122088 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
122089 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
122090 +get_chars_40373 get_chars 3 40373 NULL
122091 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
122092 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
122093 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
122094 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
122095 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
122096 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
122097 +SyS_writev_40467 SyS_writev 3 40467 NULL
122098 +SyS_select_40473 SyS_select 1 40473 NULL
122099 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
122100 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
122101 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
122102 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
122103 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
122104 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
122105 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
122106 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
122107 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
122108 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
122109 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
122110 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
122111 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
122112 +fops_read_40672 fops_read 3 40672 NULL
122113 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
122114 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
122115 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
122116 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
122117 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
122118 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122119 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122120 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122121 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122122 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122123 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122124 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122125 +card_send_command_40757 card_send_command 3 40757 NULL
122126 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122127 +pg_write_40766 pg_write 3 40766 NULL
122128 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122129 +show_list_40775 show_list 3-0 40775 NULL
122130 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122131 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122132 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122133 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122134 +add_action_40811 add_action 4 40811 NULL
122135 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122136 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122137 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122138 +read_file_queue_40895 read_file_queue 3 40895 NULL
122139 +waiters_read_40902 waiters_read 3 40902 NULL
122140 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122141 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122142 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122143 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122144 +path_listxattr_40949 path_listxattr 3 40949 NULL
122145 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122146 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122147 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122148 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122149 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122150 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122151 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122152 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122153 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122154 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122155 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122156 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122157 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122158 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122159 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122160 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122161 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122162 +dma_attach_41094 dma_attach 5-6 41094 NULL
122163 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
122164 +provide_user_output_41105 provide_user_output 3 41105 NULL
122165 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122166 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122167 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122168 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122169 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122170 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
122171 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122172 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122173 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122174 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122175 +erst_read_41260 erst_read 0 41260 NULL
122176 +alloc_context_41283 alloc_context 1 41283 NULL
122177 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122178 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122179 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122180 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122181 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122182 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122183 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122184 +kmp_init_41373 kmp_init 2 41373 NULL
122185 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122186 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122187 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122188 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122189 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122190 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122191 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122192 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122193 +se_io_cb_41461 se_io_cb 3 41461 NULL
122194 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122195 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122196 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122197 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122198 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122199 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122200 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122201 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122202 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122203 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122204 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122205 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122206 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122207 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122208 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122209 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122210 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122211 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122212 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122213 +a2mp_send_41615 a2mp_send 4 41615 NULL
122214 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122215 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122216 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122217 +get_std_timing_41654 get_std_timing 0 41654 NULL
122218 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122219 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122220 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122221 +connector_write_41709 connector_write 3 41709 NULL
122222 +fillonedir_41746 fillonedir 3 41746 NULL
122223 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122224 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122225 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122226 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122227 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122228 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122229 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122230 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122231 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122232 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122233 +pci_map_single_41869 pci_map_single 0 41869 NULL
122234 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122235 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122236 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122237 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122238 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122239 +read_gssp_41947 read_gssp 3 41947 NULL
122240 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122241 +portnames_read_41958 portnames_read 3 41958 NULL
122242 +dst_mtu_41969 dst_mtu 0 41969 NULL
122243 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122244 +pool_allocate_42012 pool_allocate 3 42012 NULL
122245 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122246 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122247 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122248 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122249 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122250 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122251 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122252 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122253 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122254 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122255 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122256 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122257 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122258 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122259 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122260 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122261 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122262 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122263 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122264 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122265 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122266 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122267 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122268 +find_last_bit_42260 find_last_bit 0 42260 NULL
122269 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122270 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122271 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122272 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122273 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122274 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122275 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122276 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122277 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122278 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122279 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122280 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122281 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122282 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122283 +krng_get_random_42420 krng_get_random 3 42420 NULL
122284 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122285 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122286 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122287 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122288 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122289 +kuc_free_42455 kuc_free 2 42455 NULL
122290 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122291 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122292 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122293 +bypass_write_42498 bypass_write 3 42498 NULL
122294 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122295 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122296 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122297 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122298 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122299 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122300 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122301 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122302 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122303 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122304 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122305 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122306 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122307 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
122308 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
122309 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122310 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122311 +vb2_read_42703 vb2_read 3 42703 NULL
122312 +read_status_42722 read_status 0 42722 NULL
122313 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122314 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122315 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122316 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122317 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122318 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122319 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122320 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122321 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122322 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122323 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122324 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122325 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122326 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122327 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122328 +set_arg_42824 set_arg 3 42824 NULL
122329 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122330 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122331 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122332 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122333 +hd_end_request_42904 hd_end_request 2 42904 NULL
122334 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122335 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122336 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122337 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
122338 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122339 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122340 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122341 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122342 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122343 +__bioset_create_43059 __bioset_create 1 43059 NULL
122344 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122345 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122346 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122347 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122348 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122349 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122350 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122351 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122352 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122353 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122354 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122355 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122356 +uio_write_43202 uio_write 3 43202 NULL
122357 +iso_callback_43208 iso_callback 3 43208 NULL
122358 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122359 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122360 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122361 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122362 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122363 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122364 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122365 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122366 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122367 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122368 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122369 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122370 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122371 +xenfb_write_43412 xenfb_write 3 43412 NULL
122372 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122373 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122374 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122375 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122376 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122377 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122378 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122379 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122380 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122381 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122382 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122383 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122384 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122385 +read_events_43534 read_events 3 43534 NULL
122386 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122387 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122388 +request_resource_43548 request_resource 0 43548 NULL
122389 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122390 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122391 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122392 +proc_read_43614 proc_read 3 43614 NULL
122393 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122394 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122395 +random_write_43656 random_write 3 43656 NULL
122396 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122397 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122398 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122399 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122400 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122401 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122402 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122403 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122404 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122405 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122406 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122407 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122408 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122409 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122410 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122411 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122412 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122413 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122414 +read_flush_43851 read_flush 3 43851 NULL
122415 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122416 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122417 +SendString_43928 SendString 3 43928 NULL
122418 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122419 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122420 +nla_reserve_43984 nla_reserve 3 43984 NULL
122421 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122422 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122423 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122424 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122425 +emit_flags_44006 emit_flags 4-3 44006 NULL
122426 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122427 +fru_strlen_44046 fru_strlen 0 44046 NULL
122428 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122429 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122430 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122431 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122432 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122433 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122434 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122435 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122436 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122437 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122438 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122439 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122440 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122441 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122442 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122443 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122444 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122445 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122446 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122447 +device_create_file_44285 device_create_file 0 44285 NULL
122448 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122449 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122450 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122451 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122452 +rs_init_44327 rs_init 1 44327 NULL
122453 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122454 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122455 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122456 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122457 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122458 +strlcpy_44400 strlcpy 3 44400 NULL
122459 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122460 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122461 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122462 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122463 +write_file_debug_44476 write_file_debug 3 44476 NULL
122464 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122465 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122466 +bio_advance_44496 bio_advance 2 44496 NULL
122467 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122468 +ac_register_board_44504 ac_register_board 3 44504 NULL
122469 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122470 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122471 +spidev_write_44510 spidev_write 3 44510 NULL
122472 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122473 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122474 +comm_write_44537 comm_write 3 44537 NULL
122475 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122476 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122477 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122478 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122479 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122480 +mpi_resize_44674 mpi_resize 2 44674 NULL
122481 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122482 +ts_read_44687 ts_read 3 44687 NULL
122483 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
122484 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122485 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122486 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122487 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122488 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122489 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122490 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122491 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122492 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
122493 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122494 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122495 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122496 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122497 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122498 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122499 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122500 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122501 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122502 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122503 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122504 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122505 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122506 +sisusb_write_44834 sisusb_write 3 44834 NULL
122507 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122508 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122509 +copydesc_user_44855 copydesc_user 3 44855 NULL
122510 +set_advertising_44870 set_advertising 4 44870 NULL
122511 +init_rs_44873 init_rs 1 44873 NULL
122512 +skb_availroom_44883 skb_availroom 0 44883 NULL
122513 +do_tty_write_44896 do_tty_write 5 44896 NULL
122514 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122515 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122516 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122517 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122518 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122519 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122520 +sel_write_user_45060 sel_write_user 3 45060 NULL
122521 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122522 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122523 +snd_card_new_45104 snd_card_new 5 45104 NULL
122524 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122525 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122526 +usbdev_read_45114 usbdev_read 3 45114 NULL
122527 +send_to_tty_45141 send_to_tty 3 45141 NULL
122528 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122529 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122530 +device_write_45156 device_write 3 45156 NULL nohasharray
122531 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122532 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122533 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122534 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122535 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122536 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122537 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122538 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122539 +event_enable_write_45238 event_enable_write 3 45238 NULL
122540 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122541 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122542 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122543 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122544 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122545 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122546 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122547 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122548 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122549 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122550 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122551 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122552 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122553 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122554 +__node_remap_45458 __node_remap 4 45458 NULL
122555 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122556 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122557 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122558 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122559 +copy_macs_45534 copy_macs 4 45534 NULL
122560 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122561 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122562 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122563 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122564 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122565 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122566 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122567 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122568 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122569 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122570 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122571 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122572 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122573 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122574 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122575 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122576 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122577 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122578 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122579 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122580 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122581 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122582 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122583 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122584 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122585 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122586 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122587 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122588 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122589 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122590 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122591 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122592 +isdn_write_45863 isdn_write 3 45863 NULL
122593 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122594 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122595 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122596 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122597 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122598 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122599 +alloc_mr_45935 alloc_mr 1 45935 NULL
122600 +copy_to_45969 copy_to 3 45969 NULL
122601 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122602 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122603 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122604 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122605 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122606 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122607 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122608 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122609 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122610 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122611 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122612 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122613 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122614 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122615 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122616 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122617 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122618 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122619 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122620 +fq_resize_46195 fq_resize 2 46195 NULL
122621 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122622 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122623 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122624 +dsp_write_46218 dsp_write 2 46218 NULL
122625 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122626 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122627 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122628 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122629 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122630 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122631 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122632 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122633 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122634 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122635 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122636 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122637 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122638 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122639 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122640 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122641 +filldir64_46469 filldir64 3 46469 NULL
122642 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122643 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122644 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122645 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122646 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122647 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
122648 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122649 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122650 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122651 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122652 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122653 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122654 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122655 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122656 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122657 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122658 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122659 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122660 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122661 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122662 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122663 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122664 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122665 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122666 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122667 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122668 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122669 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122670 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122671 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122672 +readreg_46845 readreg 0 46845 NULL
122673 +spi_async_46857 spi_async 0 46857 NULL
122674 +vsnprintf_46863 vsnprintf 0 46863 NULL
122675 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122676 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122677 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122678 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122679 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122680 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
122681 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122682 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122683 +fb_write_46924 fb_write 3 46924 NULL
122684 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122685 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122686 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122687 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122688 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122689 +strlcat_46985 strlcat 3 46985 NULL
122690 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122691 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122692 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122693 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122694 +fs_path_len_47060 fs_path_len 0 47060 NULL
122695 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122696 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122697 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122698 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122699 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122700 +mousedev_read_47123 mousedev_read 3 47123 NULL
122701 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122702 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122703 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122704 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122705 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122706 +options_write_47243 options_write 3 47243 NULL
122707 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122708 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122709 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122710 +vsnprintf_47291 vsnprintf 0 47291 NULL
122711 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122712 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122713 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
122714 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122715 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122716 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
122717 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122718 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122719 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122720 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122721 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122722 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122723 +nametbl_list_47391 nametbl_list 2 47391 NULL
122724 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122725 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122726 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122727 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122728 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122729 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122730 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122731 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122732 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122733 +newpart_47485 newpart 6-4 47485 NULL
122734 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122735 +core_sys_select_47494 core_sys_select 1 47494 NULL
122736 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122737 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122738 +unlink_simple_47506 unlink_simple 3 47506 NULL
122739 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122740 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122741 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122742 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122743 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122744 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122745 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122746 +read_ldt_47570 read_ldt 2 47570 NULL
122747 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122748 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122749 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122750 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122751 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122752 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122753 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122754 +get_size_47644 get_size 1-2 47644 NULL
122755 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122756 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122757 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122758 +save_microcode_47717 save_microcode 3 47717 NULL
122759 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122760 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122761 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122762 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122763 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122764 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122765 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122766 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122767 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122768 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122769 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122770 +lov_packmd_47810 lov_packmd 0 47810 NULL
122771 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122772 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
122773 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122774 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122775 +vhci_read_47878 vhci_read 3 47878 NULL
122776 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122777 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122778 +comedi_write_47926 comedi_write 3 47926 NULL
122779 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122780 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
122781 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122782 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122783 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122784 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122785 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122786 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122787 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122788 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122789 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122790 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122791 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122792 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122793 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122794 +disc_write_48070 disc_write 3 48070 NULL
122795 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122796 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122797 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122798 +load_firmware_48128 load_firmware 2 48128 NULL
122799 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122800 +set_discoverable_48141 set_discoverable 4 48141 NULL
122801 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122802 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122803 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122804 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122805 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122806 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122807 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122808 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122809 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122810 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122811 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122812 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122813 +read_file_recv_48232 read_file_recv 3 48232 NULL
122814 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122815 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122816 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122817 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122818 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122819 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122820 +trace_options_write_48275 trace_options_write 3 48275 NULL
122821 +send_set_info_48288 send_set_info 7 48288 NULL
122822 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122823 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122824 +hash_setkey_48310 hash_setkey 3 48310 NULL
122825 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122826 +skb_add_data_48363 skb_add_data 3 48363 NULL
122827 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122828 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122829 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122830 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122831 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122832 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122833 +print_filtered_48442 print_filtered 2-0 48442 NULL
122834 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122835 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122836 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122837 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122838 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122839 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122840 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122841 +send_control_msg_48498 send_control_msg 6 48498 NULL
122842 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122843 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122844 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122845 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122846 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122847 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122848 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122849 +llog_data_len_48607 llog_data_len 1 48607 NULL
122850 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122851 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122852 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122853 +mtd_read_48655 mtd_read 0 48655 NULL
122854 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122855 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122856 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122857 +altera_drscan_48698 altera_drscan 2 48698 NULL
122858 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122859 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122860 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122861 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122862 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122863 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122864 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122865 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122866 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122867 +azx_get_position_48841 azx_get_position 0 48841 NULL
122868 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122869 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122870 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122871 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122872 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122873 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122874 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122875 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122876 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122877 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122878 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122879 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122880 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122881 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122882 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122883 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122884 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122885 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122886 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122887 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122888 +transient_status_49027 transient_status 4 49027 NULL
122889 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122890 +scsi_register_49094 scsi_register 2 49094 NULL
122891 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122892 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122893 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122894 +pt_read_49136 pt_read 3 49136 NULL nohasharray
122895 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
122896 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122897 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122898 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122899 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122900 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122901 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122902 +print_queue_49191 print_queue 0-4 49191 NULL
122903 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122904 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122905 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122906 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122907 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122908 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122909 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122910 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122911 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122912 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122913 +uio_read_49300 uio_read 3 49300 NULL
122914 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122915 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122916 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122917 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122918 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122919 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122920 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122921 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122922 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122923 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122924 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122925 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122926 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122927 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122928 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122929 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122930 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122931 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122932 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122933 +smk_write_access_49561 smk_write_access 3 49561 NULL
122934 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122935 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122936 +readfifo_49583 readfifo 1 49583 NULL
122937 +tap_write_49595 tap_write 3 49595 NULL
122938 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122939 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122940 +heap_init_49617 heap_init 2 49617 NULL
122941 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122942 +port_fops_read_49626 port_fops_read 3 49626 NULL
122943 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122944 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122945 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122946 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122947 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122948 +write_pool_49718 write_pool 3 49718 NULL
122949 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122950 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122951 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122952 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122953 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122954 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122955 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122956 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122957 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122958 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122959 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122960 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122961 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122962 +add_uuid_49831 add_uuid 4 49831 NULL
122963 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122964 +twl4030_write_49846 twl4030_write 2 49846 NULL
122965 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122966 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122967 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122968 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122969 +osc_brw_49896 osc_brw 4 49896 NULL
122970 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122971 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122972 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122973 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122974 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122975 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122976 +isdn_read_50021 isdn_read 3 50021 NULL
122977 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122978 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
122979 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122980 +ioread8_50049 ioread8 0 50049 NULL
122981 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122982 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122983 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122984 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122985 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122986 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122987 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122988 +read_file_slot_50111 read_file_slot 3 50111 NULL
122989 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122990 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122991 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122992 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122993 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122994 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122995 +odev_update_50169 odev_update 2 50169 NULL
122996 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122997 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122998 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122999 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
123000 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
123001 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
123002 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
123003 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
123004 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
123005 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
123006 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
123007 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
123008 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
123009 +do_launder_page_50329 do_launder_page 0 50329 NULL
123010 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
123011 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
123012 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
123013 +tpm_read_50344 tpm_read 3 50344 NULL
123014 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
123015 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
123016 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
123017 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
123018 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
123019 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
123020 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
123021 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
123022 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
123023 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
123024 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
123025 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
123026 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
123027 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
123028 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
123029 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
123030 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
123031 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
123032 +fat_readpages_50582 fat_readpages 4 50582 NULL
123033 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
123034 +xillybus_write_50605 xillybus_write 3 50605 NULL
123035 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
123036 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
123037 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
123038 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
123039 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
123040 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
123041 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
123042 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
123043 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
123044 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
123045 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
123046 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
123047 +tpm_write_50798 tpm_write 3 50798 NULL
123048 +tun_do_read_50800 tun_do_read 4 50800 NULL
123049 +write_flush_50803 write_flush 3 50803 NULL
123050 +dvb_play_50814 dvb_play 3 50814 NULL
123051 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
123052 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
123053 +SetArea_50835 SetArea 4 50835 NULL
123054 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
123055 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
123056 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
123057 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
123058 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
123059 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
123060 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
123061 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
123062 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
123063 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
123064 +show_device_status_50947 show_device_status 0 50947 NULL
123065 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
123066 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
123067 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
123068 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
123069 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
123070 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
123071 +timeout_write_50991 timeout_write 3 50991 NULL
123072 +proc_write_51003 proc_write 3 51003 NULL
123073 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
123074 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
123075 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
123076 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
123077 +dump_midi_51040 dump_midi 3 51040 NULL
123078 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
123079 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
123080 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
123081 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
123082 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
123083 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
123084 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
123085 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
123086 +ti_recv_51110 ti_recv 3 51110 NULL
123087 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
123088 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
123089 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
123090 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
123091 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
123092 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
123093 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
123094 +drm_property_create_51239 drm_property_create 4 51239 NULL
123095 +st_read_51251 st_read 3 51251 NULL
123096 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
123097 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
123098 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
123099 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
123100 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
123101 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
123102 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
123103 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
123104 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
123105 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
123106 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
123107 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
123108 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
123109 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
123110 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
123111 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
123112 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
123113 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
123114 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
123115 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
123116 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
123117 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
123118 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123119 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123120 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123121 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123122 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123123 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123124 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123125 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123126 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123127 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123128 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123129 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123130 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123131 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123132 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123133 +sel_write_access_51704 sel_write_access 3 51704 NULL
123134 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123135 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123136 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123137 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123138 +str_read_51731 str_read 4 51731 NULL
123139 +cm4040_read_51732 cm4040_read 3 51732 NULL
123140 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123141 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123142 +if_write_51756 if_write 3 51756 NULL
123143 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123144 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123145 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123146 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123147 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123148 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123149 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123150 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123151 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123152 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123153 +user_read_51881 user_read 3 51881 NULL
123154 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123155 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123156 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123157 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123158 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123159 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123160 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123161 +get_clock_info_51952 get_clock_info 4 51952 NULL
123162 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123163 +get_zone_51981 get_zone 0-1 51981 NULL
123164 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123165 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123166 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123167 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123168 +rdmalt_52022 rdmalt 0 52022 NULL
123169 +override_release_52032 override_release 2 52032 NULL
123170 +end_port_52042 end_port 0 52042 NULL
123171 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123172 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123173 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123174 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123175 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123176 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123177 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123178 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123179 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123180 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123181 +retry_count_read_52129 retry_count_read 3 52129 NULL
123182 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123183 +sub_alloc_52140 sub_alloc 0 52140 NULL
123184 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123185 +htable_size_52148 htable_size 0-1 52148 NULL
123186 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123187 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123188 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123189 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123190 +print_prefix_52176 print_prefix 0 52176 NULL
123191 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123192 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123193 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123194 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123195 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123196 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123197 +shrink_slab_52261 shrink_slab 2 52261 NULL
123198 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123199 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123200 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123201 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123202 +read_file_reset_52310 read_file_reset 3 52310 NULL
123203 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123204 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123205 +hwflags_read_52318 hwflags_read 3 52318 NULL
123206 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123207 +hur_len_52339 hur_len 0 52339 NULL
123208 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123209 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123210 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123211 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123212 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123213 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123214 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123215 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123216 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123217 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123218 +delay_status_52431 delay_status 5 52431 NULL
123219 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123220 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123221 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123222 +bt_alloc_52457 bt_alloc 2 52457 NULL
123223 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123224 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123225 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123226 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123227 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123228 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123229 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123230 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123231 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123232 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123233 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123234 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123235 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123236 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123237 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123238 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123239 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123240 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123241 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123242 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123243 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123244 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123245 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123246 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123247 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123248 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123249 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123250 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123251 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123252 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123253 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123254 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123255 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123256 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123257 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123258 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123259 +twlreg_write_52880 twlreg_write 3 52880 NULL
123260 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123261 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123262 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123263 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
123264 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123265 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123266 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123267 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123268 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123269 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123270 +num_node_state_52989 num_node_state 0 52989 NULL
123271 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123272 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123273 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123274 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123275 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123276 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123277 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
123278 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123279 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123280 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123281 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123282 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
123283 +verity_status_53120 verity_status 5 53120 NULL
123284 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123285 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123286 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123287 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123288 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123289 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123290 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123291 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123292 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123293 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123294 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123295 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123296 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123297 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123298 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123299 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123300 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123301 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123302 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123303 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123304 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123305 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123306 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123307 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123308 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123309 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123310 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123311 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123312 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123313 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123314 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123315 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123316 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123317 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123318 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123319 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123320 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123321 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123322 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123323 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123324 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123325 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123326 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123327 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123328 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123329 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123330 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123331 +wdm_write_53735 wdm_write 3 53735 NULL
123332 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123333 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123334 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123335 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123336 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123337 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123338 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123339 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123340 +setup_data_read_53822 setup_data_read 3 53822 NULL
123341 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123342 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123343 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123344 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123345 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123346 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123347 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123348 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123349 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123350 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123351 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123352 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123353 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123354 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123355 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123356 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123357 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123358 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123359 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123360 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123361 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123362 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123363 +strn_len_54122 strn_len 0 54122 NULL
123364 +isku_receive_54130 isku_receive 4 54130 NULL
123365 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123366 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123367 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123368 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123369 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123370 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123371 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123372 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123373 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123374 +reada_add_block_54247 reada_add_block 2 54247 NULL
123375 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
123376 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123377 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123378 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123379 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123380 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123381 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123382 +sizeof_long_54276 sizeof_long 0 54276 NULL
123383 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123384 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123385 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123386 +sprintf_54306 sprintf 0 54306 NULL
123387 +path_setxattr_54308 path_setxattr 4 54308 NULL
123388 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123389 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123390 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123391 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123392 +readlink_copy_54366 readlink_copy 2 54366 NULL
123393 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123394 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123395 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123396 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123397 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123398 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
123399 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
123400 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123401 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123402 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123403 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123404 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123405 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123406 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123407 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123408 +viacam_read_54526 viacam_read 3 54526 NULL
123409 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123410 +setsockopt_54539 setsockopt 5 54539 NULL
123411 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123412 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123413 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123414 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123415 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123416 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123417 +port_fops_write_54627 port_fops_write 3 54627 NULL
123418 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123419 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123420 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123421 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123422 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
123423 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123424 +bus_add_device_54665 bus_add_device 0 54665 NULL
123425 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123426 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123427 +evm_read_key_54674 evm_read_key 3 54674 NULL
123428 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123429 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123430 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123431 +kzalloc_54740 kzalloc 1 54740 NULL
123432 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123433 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123434 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123435 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123436 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123437 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123438 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123439 +nfsd_write_54809 nfsd_write 6 54809 NULL
123440 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123441 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123442 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123443 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123444 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123445 +write_rio_54837 write_rio 3 54837 NULL
123446 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123447 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123448 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123449 +printer_read_54851 printer_read 3 54851 NULL
123450 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123451 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123452 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123453 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123454 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123455 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123456 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123457 +add_port_54941 add_port 2 54941 NULL
123458 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123459 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123460 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123461 +c4_add_card_54968 c4_add_card 3 54968 NULL
123462 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123463 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123464 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123465 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123466 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123467 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123468 +read_dma_55086 read_dma 3 55086 NULL
123469 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123470 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123471 +filldir_55137 filldir 3 55137 NULL
123472 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123473 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123474 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123475 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123476 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123477 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123478 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123479 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123480 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
123481 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123482 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123483 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123484 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123485 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123486 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123487 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123488 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123489 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123490 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123491 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123492 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123493 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123494 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123495 +vme_user_read_55338 vme_user_read 3 55338 NULL
123496 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123497 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123498 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123499 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123500 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123501 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123502 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123503 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123504 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123505 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123506 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123507 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123508 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123509 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123510 +ea_get_55522 ea_get 3-0 55522 NULL
123511 +buffer_size_55534 buffer_size 0 55534 NULL
123512 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123513 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123514 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123515 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123516 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123517 +add_partition_55588 add_partition 2 55588 NULL
123518 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123519 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123520 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123521 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123522 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123523 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123524 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123525 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123526 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123527 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123528 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123529 +get_info_55681 get_info 3 55681 NULL
123530 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123531 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123532 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123533 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123534 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123535 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123536 +set_local_name_55757 set_local_name 4 55757 NULL
123537 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123538 +strlen_55778 strlen 0 55778 NULL
123539 +set_spte_55783 set_spte 4-5 55783 NULL
123540 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123541 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123542 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123543 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123544 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123545 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123546 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123547 +hsc_write_55875 hsc_write 3 55875 NULL
123548 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123549 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123550 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123551 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123552 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123553 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123554 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123555 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123556 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123557 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123558 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123559 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123560 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123561 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123562 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123563 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123564 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123565 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123566 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123567 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123568 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123569 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123570 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123571 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123572 +fd_copyin_56247 fd_copyin 3 56247 NULL
123573 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123574 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123575 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123576 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123577 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123578 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123579 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123580 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123581 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123582 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123583 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123584 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123585 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123586 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123587 +dev_read_56369 dev_read 3 56369 NULL
123588 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123589 +lnet_ping_56378 lnet_ping 4 56378 NULL
123590 +write_gssp_56404 write_gssp 3 56404 NULL
123591 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123592 +store_msg_56417 store_msg 3 56417 NULL
123593 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123594 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
123595 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
123596 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123597 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123598 +fl_create_56435 fl_create 5 56435 NULL
123599 +gnttab_map_56439 gnttab_map 2 56439 NULL
123600 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123601 +set_connectable_56458 set_connectable 4 56458 NULL
123602 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123603 +putused_user_56467 putused_user 3 56467 NULL
123604 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123605 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123606 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123607 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123608 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123609 +init_map_ip_56508 init_map_ip 5 56508 NULL
123610 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123611 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123612 +ip_options_get_56538 ip_options_get 4 56538 NULL
123613 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123614 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123615 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123616 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123617 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123618 +event_filter_write_56609 event_filter_write 3 56609 NULL
123619 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123620 +gather_array_56641 gather_array 3 56641 NULL
123621 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123622 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123623 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123624 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123625 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123626 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123627 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123628 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123629 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123630 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123631 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123632 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123633 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123634 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123635 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123636 +do_syslog_56807 do_syslog 3 56807 NULL
123637 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123638 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123639 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123640 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123641 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123642 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123643 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123644 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123645 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123646 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123647 +strcspn_56913 strcspn 0 56913 NULL
123648 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123649 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123650 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123651 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123652 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123653 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123654 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123655 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123656 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123657 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123658 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123659 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123660 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123661 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123662 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123663 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123664 +altera_get_note_57099 altera_get_note 6 57099 NULL
123665 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123666 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123667 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123668 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123669 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123670 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123671 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123672 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123673 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123674 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123675 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123676 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123677 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123678 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123679 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123680 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123681 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123682 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123683 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123684 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123685 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123686 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123687 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123688 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123689 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123690 +write_file_regval_57313 write_file_regval 3 57313 NULL
123691 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123692 +usblp_read_57342 usblp_read 3 57342 NULL
123693 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123694 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123695 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123696 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123697 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123698 +read_file_blob_57406 read_file_blob 3 57406 NULL
123699 +enclosure_register_57412 enclosure_register 3 57412 NULL
123700 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
123701 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123702 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123703 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123704 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123705 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123706 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123707 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123708 +skb_headlen_57501 skb_headlen 0 57501 NULL
123709 +copy_in_user_57502 copy_in_user 3 57502 NULL
123710 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123711 +init_tag_map_57515 init_tag_map 3 57515 NULL
123712 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123713 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123714 +cmm_read_57520 cmm_read 3 57520 NULL
123715 +inode_permission_57531 inode_permission 0 57531 NULL
123716 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123717 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123718 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123719 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123720 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123721 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123722 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123723 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123724 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123725 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
123726 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123727 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123728 +mem_read_57631 mem_read 3 57631 NULL
123729 +r3964_write_57662 r3964_write 4 57662 NULL
123730 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123731 +__lgwrite_57669 __lgwrite 4 57669 NULL
123732 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123733 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123734 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123735 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123736 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123737 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123738 +ld2_57794 ld2 0 57794 NULL
123739 +ivtv_read_57796 ivtv_read 3 57796 NULL
123740 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123741 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123742 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123743 +flash_read_57843 flash_read 3 57843 NULL
123744 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123745 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123746 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123747 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123748 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123749 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123750 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123751 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123752 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123753 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123754 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123755 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123756 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123757 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123758 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123759 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123760 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123761 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123762 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123763 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123764 +mce_async_out_58056 mce_async_out 3 58056 NULL
123765 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123766 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123767 +cm4040_write_58079 cm4040_write 3 58079 NULL
123768 +savemem_58129 savemem 3 58129 NULL
123769 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123770 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123771 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123772 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123773 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123774 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123775 +read_file_debug_58256 read_file_debug 3 58256 NULL
123776 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123777 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123778 +profile_load_58267 profile_load 3 58267 NULL
123779 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123780 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123781 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123782 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123783 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123784 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123785 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123786 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123787 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123788 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123789 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123790 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123791 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123792 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123793 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123794 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123795 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123796 +capabilities_read_58457 capabilities_read 3 58457 NULL
123797 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123798 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123799 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123800 +nv_rd08_58472 nv_rd08 0 58472 NULL
123801 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123802 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123803 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
123804 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123805 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123806 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123807 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123808 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123809 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123810 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123811 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123812 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123813 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123814 +xip_file_read_58592 xip_file_read 3 58592 NULL
123815 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123816 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123817 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123818 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123819 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123820 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123821 +find_zero_58685 find_zero 0-1 58685 NULL
123822 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123823 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123824 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123825 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123826 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123827 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123828 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123829 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123830 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123831 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123832 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123833 +ep_read_58813 ep_read 3 58813 NULL
123834 +command_write_58841 command_write 3 58841 NULL
123835 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123836 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123837 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123838 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123839 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123840 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123841 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123842 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123843 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123844 +init_list_set_59005 init_list_set 3 59005 NULL
123845 +ep_write_59008 ep_write 3 59008 NULL
123846 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123847 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123848 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123849 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123850 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123851 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123852 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123853 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123854 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123855 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123856 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123857 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123858 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123859 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123860 +ksize_59176 ksize 0 59176 NULL
123861 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123862 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123863 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123864 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123865 +dt3155_read_59226 dt3155_read 3 59226 NULL
123866 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123867 +nla_len_59258 nla_len 0 59258 NULL
123868 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123869 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123870 +fd_copyout_59323 fd_copyout 3 59323 NULL
123871 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123872 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123873 +__map_request_59350 __map_request 0 59350 NULL
123874 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123875 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123876 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123877 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123878 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123879 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123880 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123881 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123882 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123883 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123884 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123885 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123886 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123887 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123888 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
123889 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123890 +tunables_write_59563 tunables_write 3 59563 NULL
123891 +bio_split_59564 bio_split 2 59564 NULL
123892 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123893 +write_pbl_59583 write_pbl 4 59583 NULL
123894 +memdup_user_59590 memdup_user 2 59590 NULL
123895 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123896 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123897 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123898 +mtrr_write_59622 mtrr_write 3 59622 NULL
123899 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123900 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123901 +hidraw_read_59650 hidraw_read 3 59650 NULL
123902 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123903 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123904 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123905 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123906 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123907 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123908 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123909 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123910 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123911 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123912 +strnlen_59746 strnlen 0 59746 NULL
123913 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123914 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123915 +venus_remove_59781 venus_remove 4 59781 NULL
123916 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123917 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123918 +ipw_write_59807 ipw_write 3 59807 NULL
123919 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123920 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123921 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123922 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123923 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123924 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123925 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123926 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123927 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123928 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123929 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123930 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123931 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123932 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123933 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123934 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123935 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123936 +copy_items_60009 copy_items 7 60009 NULL
123937 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123938 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123939 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123940 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123941 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123942 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123943 +vcs_size_60050 vcs_size 0 60050 NULL
123944 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123945 +compat_writev_60063 compat_writev 3 60063 NULL
123946 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123947 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123948 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123949 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123950 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123951 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123952 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123953 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
123954 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123955 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123956 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123957 +init_state_60165 init_state 2 60165 NULL
123958 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123959 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123960 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123961 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
123962 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
123963 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123964 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123965 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123966 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123967 +printer_write_60276 printer_write 3 60276 NULL
123968 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123969 +getDataLength_60301 getDataLength 0 60301 NULL
123970 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123971 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123972 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123973 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123974 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123975 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123976 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123977 +driver_names_read_60399 driver_names_read 3 60399 NULL
123978 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123979 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123980 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123981 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123982 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123983 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123984 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123985 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123986 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123987 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123988 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123989 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123990 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123991 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123992 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123993 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123994 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123995 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123996 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123997 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123998 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123999 +raid_status_60755 raid_status 5 60755 NULL
124000 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
124001 +opticon_write_60775 opticon_write 4 60775 NULL
124002 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
124003 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
124004 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
124005 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
124006 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
124007 +generic_writepages_60871 generic_writepages 0 60871 NULL
124008 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
124009 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
124010 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
124011 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
124012 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
124013 +pti_char_write_60960 pti_char_write 3 60960 NULL
124014 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
124015 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
124016 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
124017 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
124018 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
124019 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
124020 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
124021 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
124022 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
124023 +symtab_init_61050 symtab_init 2 61050 NULL
124024 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
124025 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
124026 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
124027 +get_derived_key_61100 get_derived_key 4 61100 NULL
124028 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
124029 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
124030 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
124031 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
124032 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
124033 +pair_device_61175 pair_device 4 61175 NULL nohasharray
124034 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
124035 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
124036 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
124037 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
124038 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
124039 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
124040 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
124041 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
124042 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
124043 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
124044 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
124045 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
124046 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
124047 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
124048 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
124049 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
124050 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
124051 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
124052 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
124053 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
124054 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
124055 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
124056 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
124057 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
124058 +system_enable_write_61396 system_enable_write 3 61396 NULL
124059 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
124060 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
124061 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
124062 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
124063 +erst_errno_61526 erst_errno 0 61526 NULL
124064 +proc_write_device_61541 proc_write_device 3 61541 NULL
124065 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
124066 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
124067 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
124068 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
124069 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
124070 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
124071 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
124072 +seq_open_private_61589 seq_open_private 3 61589 NULL
124073 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
124074 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
124075 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
124076 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
124077 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
124078 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
124079 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
124080 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
124081 +resize_stripes_61650 resize_stripes 2 61650 NULL
124082 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
124083 +insert_one_name_61668 insert_one_name 7 61668 NULL
124084 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
124085 +lock_loop_61681 lock_loop 1 61681 NULL
124086 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
124087 +filter_read_61692 filter_read 3 61692 NULL
124088 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
124089 +iov_length_61716 iov_length 0 61716 NULL
124090 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
124091 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
124092 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
124093 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
124094 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
124095 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
124096 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
124097 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
124098 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
124099 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
124100 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
124101 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
124102 +get_fw_name_61874 get_fw_name 3 61874 NULL
124103 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
124104 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
124105 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
124106 +kernfs_name_61910 kernfs_name 3 61910 NULL
124107 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
124108 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
124109 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
124110 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
124111 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
124112 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
124113 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
124114 +fix_read_error_61965 fix_read_error 4 61965 NULL
124115 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
124116 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
124117 +cow_file_range_61979 cow_file_range 3 61979 NULL
124118 +dequeue_event_62000 dequeue_event 3 62000 NULL
124119 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124120 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124121 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124122 +SYSC_select_62024 SYSC_select 1 62024 NULL
124123 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
124124 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124125 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124126 +do_pselect_62061 do_pselect 1 62061 NULL
124127 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124128 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124129 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124130 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124131 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124132 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124133 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124134 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124135 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124136 +video_usercopy_62151 video_usercopy 2 62151 NULL
124137 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124138 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124139 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124140 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124141 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124142 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124143 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124144 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124145 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124146 +get_random_int_62279 get_random_int 0 62279 NULL
124147 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124148 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124149 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124150 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124151 +subseq_list_62332 subseq_list 3-0 62332 NULL
124152 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124153 +flash_write_62354 flash_write 3 62354 NULL
124154 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124155 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124156 +altera_irscan_62396 altera_irscan 2 62396 NULL
124157 +set_ssp_62411 set_ssp 4 62411 NULL
124158 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124159 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124160 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124161 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124162 +debugfs_read_62535 debugfs_read 3 62535 NULL
124163 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124164 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124165 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124166 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124167 +get_subdir_62581 get_subdir 3 62581 NULL
124168 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124169 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124170 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124171 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124172 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124173 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124174 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124175 +rdm_62719 rdm 0 62719 NULL
124176 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124177 +key_replays_read_62746 key_replays_read 3 62746 NULL
124178 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124179 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124180 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124181 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124182 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124183 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124184 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124185 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124186 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124187 +__add_action_62798 __add_action 4 62798 NULL
124188 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124189 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124190 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124191 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124192 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124193 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124194 +aoechr_write_62883 aoechr_write 3 62883 NULL
124195 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124196 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124197 +getdqbuf_62908 getdqbuf 1 62908 NULL
124198 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124199 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124200 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124201 +hwdep_read_62992 hwdep_read 3 62992 NULL
124202 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124203 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124204 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124205 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124206 +unlink1_63059 unlink1 3 63059 NULL
124207 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124208 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124209 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124210 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124211 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124212 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124213 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124214 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124215 +vme_master_read_63221 vme_master_read 0 63221 NULL
124216 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124217 +ptp_read_63251 ptp_read 4 63251 NULL
124218 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124219 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124220 +raid5_resize_63306 raid5_resize 2 63306 NULL
124221 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124222 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124223 +proc_info_read_63344 proc_info_read 3 63344 NULL
124224 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124225 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124226 +idmouse_read_63374 idmouse_read 3 63374 NULL
124227 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124228 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124229 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124230 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124231 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124232 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124233 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124234 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124235 +read_kcore_63488 read_kcore 3 63488 NULL
124236 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124237 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124238 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124239 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124240 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124241 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124242 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124243 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124244 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124245 +write_debug_level_63613 write_debug_level 3 63613 NULL
124246 +__spi_validate_63618 __spi_validate 0 63618 NULL
124247 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124248 +hid_report_len_63637 hid_report_len 0 63637 NULL
124249 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124250 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124251 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124252 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124253 +vbi_read_63673 vbi_read 3 63673 NULL
124254 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124255 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124256 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124257 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
124258 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124259 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124260 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124261 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124262 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124263 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124264 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124265 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124266 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124267 +sel_write_load_63830 sel_write_load 3 63830 NULL
124268 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124269 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124270 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124271 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124272 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124273 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124274 +__team_options_register_63941 __team_options_register 3 63941 NULL
124275 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124276 +set_bredr_63975 set_bredr 4 63975 NULL
124277 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124278 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124279 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124280 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124281 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124282 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124283 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
124284 +__sock_create_64069 __sock_create 0 64069 NULL
124285 +get_u8_64076 get_u8 0 64076 NULL
124286 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124287 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124288 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124289 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124290 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124291 +to_bytes_64103 to_bytes 0-1 64103 NULL
124292 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124293 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124294 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124295 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124296 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124297 +init_bch_64130 init_bch 1-2 64130 NULL
124298 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124299 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124300 +number_of_tds_64156 number_of_tds 0 64156 NULL
124301 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124302 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124303 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124304 +read_pulse_64227 read_pulse 0-3 64227 NULL
124305 +ea_len_64229 ea_len 0 64229 NULL
124306 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124307 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124308 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124309 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124310 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124311 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124312 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124313 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124314 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124315 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124316 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124317 +ts_write_64336 ts_write 3 64336 NULL
124318 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124319 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
124320 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124321 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124322 +reg_create_64372 reg_create 5 64372 NULL nohasharray
124323 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
124324 +ilo_write_64378 ilo_write 3 64378 NULL
124325 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124326 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124327 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124328 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124329 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124330 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124331 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124332 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124333 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124334 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124335 +single_open_size_64483 single_open_size 4 64483 NULL
124336 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124337 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124338 +remove_uuid_64505 remove_uuid 4 64505 NULL
124339 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124340 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124341 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124342 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124343 +SyS_bind_64544 SyS_bind 3 64544 NULL
124344 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124345 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124346 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124347 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124348 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124349 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124350 +do_erase_64574 do_erase 4 64574 NULL
124351 +fanotify_write_64623 fanotify_write 3 64623 NULL
124352 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124353 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124354 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124355 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124356 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124357 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124358 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124359 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124360 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124361 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124362 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124363 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124364 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124365 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124366 +hwdep_write_64776 hwdep_write 3 64776 NULL
124367 +message_for_md_64777 message_for_md 5 64777 NULL
124368 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124369 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124370 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124371 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124372 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124373 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124374 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124375 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124376 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124377 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124378 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124379 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124380 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124381 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124382 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124383 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124384 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124385 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124386 +insert_dent_65034 insert_dent 7 65034 NULL
124387 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124388 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124389 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124390 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124391 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124392 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124393 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124394 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
124395 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124396 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124397 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124398 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124399 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124400 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124401 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124402 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124403 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124404 +get_var_len_65304 get_var_len 0 65304 NULL
124405 +unpack_array_65318 unpack_array 0 65318 NULL
124406 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124407 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124408 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124409 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124410 +SyS_writev_65372 SyS_writev 3 65372 NULL
124411 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124412 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124413 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124414 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124415 +device_add_groups_65423 device_add_groups 0 65423 NULL
124416 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124417 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124418 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124419 +clear_user_65470 clear_user 2 65470 NULL
124420 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124421 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124422 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124423 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124424 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124425 new file mode 100644
124426 index 0000000..560cd7b
124427 --- /dev/null
124428 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124429 @@ -0,0 +1,92 @@
124430 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124431 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124432 +mappedread_2627 mappedread 2 2627 NULL
124433 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124434 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124435 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124436 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124437 +dmu_write_6048 dmu_write 4-3 6048 NULL
124438 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124439 +update_pages_6225 update_pages 2-3 6225 NULL
124440 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124441 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124442 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124443 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124444 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124445 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124446 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124447 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124448 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124449 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124450 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124451 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124452 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124453 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124454 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124455 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124456 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124457 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124458 +uiocopy_18680 uiocopy 2 18680 NULL
124459 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124460 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124461 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124462 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124463 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124464 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124465 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124466 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124467 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124468 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124469 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124470 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124471 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124472 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124473 +splat_write_30943 splat_write 3 30943 NULL
124474 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124475 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124476 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124477 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124478 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124479 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124480 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124481 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124482 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124483 +copyinstr_36980 copyinstr 3 36980 NULL
124484 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124485 +splat_read_38116 splat_read 3 38116 NULL
124486 +sa_setup_38756 sa_setup 4 38756 NULL
124487 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124488 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124489 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124490 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124491 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124492 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124493 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124494 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124495 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124496 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124497 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124498 +kcopy_write_43683 kcopy_write 3 43683 NULL
124499 +uiomove_44355 uiomove 2 44355 NULL
124500 +dmu_read_44418 dmu_read 4-3 44418 NULL
124501 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124502 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124503 +copyin_45945 copyin 3 45945 NULL
124504 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124505 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124506 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124507 +spa_history_write_49650 spa_history_write 3 49650 NULL
124508 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124509 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124510 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124511 +copyout_51409 copyout 3 51409 NULL
124512 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124513 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124514 +get_nvlist_56685 get_nvlist 2 56685 NULL
124515 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124516 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124517 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124518 +zpios_write_61823 zpios_write 3 61823 NULL
124519 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124520 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124521 +zpios_read_64734 zpios_read 3 64734 NULL
124522 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124523 new file mode 100644
124524 index 0000000..95f7abd
124525 --- /dev/null
124526 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124527 @@ -0,0 +1,259 @@
124528 +/*
124529 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124530 + * Licensed under the GPL v2, or (at your option) v3
124531 + *
124532 + * Homepage:
124533 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124534 + *
124535 + * Documentation:
124536 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124537 + *
124538 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124539 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124540 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124541 + *
124542 + * Usage:
124543 + * $ make
124544 + * $ make run
124545 + */
124546 +
124547 +#include "gcc-common.h"
124548 +#include "size_overflow.h"
124549 +
124550 +int plugin_is_GPL_compatible;
124551 +
124552 +tree report_size_overflow_decl;
124553 +
124554 +tree size_overflow_type_HI;
124555 +tree size_overflow_type_SI;
124556 +tree size_overflow_type_DI;
124557 +tree size_overflow_type_TI;
124558 +
124559 +static struct plugin_info size_overflow_plugin_info = {
124560 + .version = "20140725",
124561 + .help = "no-size-overflow\tturn off size overflow checking\n",
124562 +};
124563 +
124564 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124565 +{
124566 + unsigned int arg_count;
124567 + enum tree_code code = TREE_CODE(*node);
124568 +
124569 + switch (code) {
124570 + case FUNCTION_DECL:
124571 + arg_count = type_num_arguments(TREE_TYPE(*node));
124572 + break;
124573 + case FUNCTION_TYPE:
124574 + case METHOD_TYPE:
124575 + arg_count = type_num_arguments(*node);
124576 + break;
124577 + default:
124578 + *no_add_attrs = true;
124579 + error("%s: %qE attribute only applies to functions", __func__, name);
124580 + return NULL_TREE;
124581 + }
124582 +
124583 + for (; args; args = TREE_CHAIN(args)) {
124584 + tree position = TREE_VALUE(args);
124585 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124586 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124587 + *no_add_attrs = true;
124588 + }
124589 + }
124590 + return NULL_TREE;
124591 +}
124592 +
124593 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124594 +{
124595 + unsigned int arg_count;
124596 + enum tree_code code = TREE_CODE(*node);
124597 +
124598 + switch (code) {
124599 + case FUNCTION_DECL:
124600 + arg_count = type_num_arguments(TREE_TYPE(*node));
124601 + break;
124602 + case FUNCTION_TYPE:
124603 + case METHOD_TYPE:
124604 + arg_count = type_num_arguments(*node);
124605 + break;
124606 + case FIELD_DECL:
124607 + return NULL_TREE;
124608 + default:
124609 + *no_add_attrs = true;
124610 + error("%qE attribute only applies to functions", name);
124611 + return NULL_TREE;
124612 + }
124613 +
124614 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124615 + return NULL_TREE;
124616 +
124617 + for (; args; args = TREE_CHAIN(args)) {
124618 + tree position = TREE_VALUE(args);
124619 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124620 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124621 + *no_add_attrs = true;
124622 + }
124623 + }
124624 + return NULL_TREE;
124625 +}
124626 +
124627 +static struct attribute_spec size_overflow_attr = {
124628 + .name = "size_overflow",
124629 + .min_length = 1,
124630 + .max_length = -1,
124631 + .decl_required = true,
124632 + .type_required = false,
124633 + .function_type_required = false,
124634 + .handler = handle_size_overflow_attribute,
124635 +#if BUILDING_GCC_VERSION >= 4007
124636 + .affects_type_identity = false
124637 +#endif
124638 +};
124639 +
124640 +static struct attribute_spec intentional_overflow_attr = {
124641 + .name = "intentional_overflow",
124642 + .min_length = 1,
124643 + .max_length = -1,
124644 + .decl_required = true,
124645 + .type_required = false,
124646 + .function_type_required = false,
124647 + .handler = handle_intentional_overflow_attribute,
124648 +#if BUILDING_GCC_VERSION >= 4007
124649 + .affects_type_identity = false
124650 +#endif
124651 +};
124652 +
124653 +static void register_attributes(void __unused *event_data, void __unused *data)
124654 +{
124655 + register_attribute(&size_overflow_attr);
124656 + register_attribute(&intentional_overflow_attr);
124657 +}
124658 +
124659 +static tree create_typedef(tree type, const char* ident)
124660 +{
124661 + tree new_type, decl;
124662 +
124663 + new_type = build_variant_type_copy(type);
124664 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124665 + DECL_ORIGINAL_TYPE(decl) = type;
124666 + TYPE_NAME(new_type) = decl;
124667 + return new_type;
124668 +}
124669 +
124670 +// Create the noreturn report_size_overflow() function decl.
124671 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124672 +{
124673 + tree const_char_ptr_type_node;
124674 + tree fntype;
124675 +
124676 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124677 +
124678 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124679 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124680 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124681 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124682 +
124683 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124684 + fntype = build_function_type_list(void_type_node,
124685 + const_char_ptr_type_node,
124686 + unsigned_type_node,
124687 + const_char_ptr_type_node,
124688 + const_char_ptr_type_node,
124689 + NULL_TREE);
124690 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124691 +
124692 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124693 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124694 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124695 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124696 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124697 +}
124698 +
124699 +
124700 +extern struct gimple_opt_pass pass_dce;
124701 +
124702 +static struct opt_pass *make_dce_pass(void)
124703 +{
124704 +#if BUILDING_GCC_VERSION >= 4009
124705 + return make_pass_dce(g);
124706 +#else
124707 + return &pass_dce.pass;
124708 +#endif
124709 +}
124710 +
124711 +
124712 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124713 +{
124714 + int i;
124715 + const char * const plugin_name = plugin_info->base_name;
124716 + const int argc = plugin_info->argc;
124717 + const struct plugin_argument * const argv = plugin_info->argv;
124718 + bool enable = true;
124719 + struct register_pass_info insert_size_overflow_asm_pass_info;
124720 + struct register_pass_info __unused dump_before_pass_info;
124721 + struct register_pass_info __unused dump_after_pass_info;
124722 + struct register_pass_info insert_size_overflow_check_info;
124723 + struct register_pass_info dce_pass_info;
124724 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124725 + {
124726 + .base = &report_size_overflow_decl,
124727 + .nelt = 1,
124728 + .stride = sizeof(report_size_overflow_decl),
124729 + .cb = &gt_ggc_mx_tree_node,
124730 + .pchw = &gt_pch_nx_tree_node
124731 + },
124732 + LAST_GGC_ROOT_TAB
124733 + };
124734 +
124735 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124736 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124737 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124738 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124739 +
124740 + dump_before_pass_info.pass = make_dump_pass();
124741 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124742 + dump_before_pass_info.ref_pass_instance_number = 1;
124743 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124744 +
124745 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124746 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124747 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124748 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124749 +
124750 + dump_after_pass_info.pass = make_dump_pass();
124751 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124752 + dump_after_pass_info.ref_pass_instance_number = 1;
124753 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124754 +
124755 + dce_pass_info.pass = make_dce_pass();
124756 + dce_pass_info.reference_pass_name = "vrp";
124757 + dce_pass_info.ref_pass_instance_number = 1;
124758 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124759 +
124760 + if (!plugin_default_version_check(version, &gcc_version)) {
124761 + error(G_("incompatible gcc/plugin versions"));
124762 + return 1;
124763 + }
124764 +
124765 + for (i = 0; i < argc; ++i) {
124766 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124767 + enable = false;
124768 + continue;
124769 + }
124770 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124771 + }
124772 +
124773 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124774 + if (enable) {
124775 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124776 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124777 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124778 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124779 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124780 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124781 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124782 + }
124783 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124784 +
124785 + return 0;
124786 +}
124787 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124788 new file mode 100644
124789 index 0000000..0888f6c
124790 --- /dev/null
124791 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124792 @@ -0,0 +1,364 @@
124793 +/*
124794 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124795 + * Licensed under the GPL v2, or (at your option) v3
124796 + *
124797 + * Homepage:
124798 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124799 + *
124800 + * Documentation:
124801 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124802 + *
124803 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124804 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124805 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124806 + *
124807 + * Usage:
124808 + * $ make
124809 + * $ make run
124810 + */
124811 +
124812 +#include "gcc-common.h"
124813 +#include "size_overflow.h"
124814 +
124815 +#include "size_overflow_hash.h"
124816 +#include "size_overflow_hash_aux.h"
124817 +
124818 +#define CODES_LIMIT 32
124819 +
124820 +static unsigned char get_tree_code(const_tree type)
124821 +{
124822 + switch (TREE_CODE(type)) {
124823 + case ARRAY_TYPE:
124824 + return 0;
124825 + case BOOLEAN_TYPE:
124826 + return 1;
124827 + case ENUMERAL_TYPE:
124828 + return 2;
124829 + case FUNCTION_TYPE:
124830 + return 3;
124831 + case INTEGER_TYPE:
124832 + return 4;
124833 + case POINTER_TYPE:
124834 + return 5;
124835 + case RECORD_TYPE:
124836 + return 6;
124837 + case UNION_TYPE:
124838 + return 7;
124839 + case VOID_TYPE:
124840 + return 8;
124841 + case REAL_TYPE:
124842 + return 9;
124843 + case VECTOR_TYPE:
124844 + return 10;
124845 + case REFERENCE_TYPE:
124846 + return 11;
124847 + case OFFSET_TYPE:
124848 + return 12;
124849 + case COMPLEX_TYPE:
124850 + return 13;
124851 + default:
124852 + debug_tree((tree)type);
124853 + gcc_unreachable();
124854 + }
124855 +}
124856 +
124857 +struct function_hash {
124858 + size_t tree_codes_len;
124859 + unsigned char tree_codes[CODES_LIMIT];
124860 + const_tree fndecl;
124861 + unsigned int hash;
124862 +};
124863 +
124864 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124865 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124866 +{
124867 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124868 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124869 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124870 +
124871 + unsigned int m = 0x57559429;
124872 + unsigned int n = 0x5052acdb;
124873 + const unsigned int *key4 = (const unsigned int *)key;
124874 + unsigned int h = len;
124875 + unsigned int k = len + seed + n;
124876 + unsigned long long p;
124877 +
124878 + while (len >= 8) {
124879 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124880 + len -= 8;
124881 + }
124882 + if (len >= 4) {
124883 + cwmixb(key4[0]) key4 += 1;
124884 + len -= 4;
124885 + }
124886 + if (len)
124887 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124888 + cwmixb(h ^ (k + n));
124889 + return k ^ h;
124890 +
124891 +#undef cwfold
124892 +#undef cwmixa
124893 +#undef cwmixb
124894 +}
124895 +
124896 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124897 +{
124898 + unsigned int fn, codes, seed = 0;
124899 +
124900 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124901 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124902 +
124903 + fn_hash_data->hash = fn ^ codes;
124904 +}
124905 +
124906 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124907 +{
124908 + gcc_assert(type != NULL_TREE);
124909 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124910 +
124911 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124912 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124913 + fn_hash_data->tree_codes_len++;
124914 + type = TREE_TYPE(type);
124915 + }
124916 +}
124917 +
124918 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124919 +{
124920 + const_tree result;
124921 +
124922 + gcc_assert(node != NULL_TREE);
124923 +
124924 + if (DECL_P(node)) {
124925 + result = DECL_RESULT(node);
124926 + if (result != NULL_TREE)
124927 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124928 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124929 + }
124930 +
124931 + gcc_assert(TYPE_P(node));
124932 +
124933 + if (TREE_CODE(node) == FUNCTION_TYPE)
124934 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124935 +
124936 + return set_node_codes(node, fn_hash_data);
124937 +}
124938 +
124939 +static void set_function_codes(struct function_hash *fn_hash_data)
124940 +{
124941 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124942 + enum tree_code code = TREE_CODE(type);
124943 +
124944 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124945 +
124946 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124947 +
124948 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124949 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124950 +}
124951 +
124952 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124953 +{
124954 + while (entry) {
124955 + if (!strcmp(entry->name, func_name))
124956 + return entry;
124957 + entry = entry->next;
124958 + }
124959 + return NULL;
124960 +}
124961 +
124962 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124963 +{
124964 + const struct size_overflow_hash *entry;
124965 + struct function_hash fn_hash_data;
124966 + const char *func_name;
124967 +
124968 + // skip builtins __builtin_constant_p
124969 + if (DECL_BUILT_IN(fndecl))
124970 + return NULL;
124971 +
124972 + fn_hash_data.fndecl = fndecl;
124973 + fn_hash_data.tree_codes_len = 0;
124974 +
124975 + set_function_codes(&fn_hash_data);
124976 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124977 +
124978 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124979 + set_hash(func_name, &fn_hash_data);
124980 +
124981 + entry = size_overflow_hash[fn_hash_data.hash];
124982 + entry = get_proper_hash_chain(entry, func_name);
124983 + if (entry)
124984 + return entry;
124985 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124986 + return get_proper_hash_chain(entry, func_name);
124987 +}
124988 +
124989 +static void print_missing_msg(const_tree func, unsigned int argnum)
124990 +{
124991 + location_t loc;
124992 + const char *curfunc;
124993 + struct function_hash fn_hash_data;
124994 +
124995 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124996 + fn_hash_data.tree_codes_len = 0;
124997 +
124998 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124999 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
125000 +
125001 + set_function_codes(&fn_hash_data);
125002 + set_hash(curfunc, &fn_hash_data);
125003 +
125004 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
125005 +}
125006 +
125007 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
125008 +{
125009 + tree var;
125010 + unsigned int argnum = 1;
125011 +
125012 + if (TREE_CODE(arg) == SSA_NAME)
125013 + arg = SSA_NAME_VAR(arg);
125014 +
125015 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
125016 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
125017 + continue;
125018 + if (!skip_types(var))
125019 + return argnum;
125020 + }
125021 +
125022 + return CANNOT_FIND_ARG;
125023 +}
125024 +
125025 +static const char *get_asm_string(const_gimple stmt)
125026 +{
125027 + if (!stmt)
125028 + return NULL;
125029 + if (gimple_code(stmt) != GIMPLE_ASM)
125030 + return NULL;
125031 +
125032 + return gimple_asm_string(stmt);
125033 +}
125034 +
125035 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
125036 +{
125037 + const char *str;
125038 +
125039 + str = get_asm_string(stmt);
125040 + if (!str)
125041 + return false;
125042 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
125043 +}
125044 +
125045 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
125046 +{
125047 + const char *str;
125048 +
125049 + str = get_asm_string(stmt);
125050 + if (!str)
125051 + return false;
125052 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
125053 +}
125054 +
125055 +bool is_size_overflow_asm(const_gimple stmt)
125056 +{
125057 + const char *str;
125058 +
125059 + str = get_asm_string(stmt);
125060 + if (!str)
125061 + return false;
125062 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
125063 +}
125064 +
125065 +bool is_a_return_check(const_tree node)
125066 +{
125067 + if (TREE_CODE(node) == FUNCTION_DECL)
125068 + return true;
125069 +
125070 + gcc_assert(TREE_CODE(node) == PARM_DECL);
125071 + return false;
125072 +}
125073 +
125074 +// Get the argnum of a function decl, if node is a return then the argnum is 0
125075 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
125076 +{
125077 + if (is_a_return_check(node))
125078 + return 0;
125079 + else
125080 + return find_arg_number_tree(node, orig_fndecl);
125081 +}
125082 +
125083 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
125084 +{
125085 + const struct size_overflow_hash *hash;
125086 + unsigned int new_argnum;
125087 + tree arg;
125088 + const_tree origarg;
125089 +
125090 + if (argnum == 0)
125091 + return argnum;
125092 +
125093 + hash = get_function_hash(fndecl);
125094 + if (hash && hash->param & (1U << argnum))
125095 + return argnum;
125096 +
125097 + if (DECL_EXTERNAL(fndecl))
125098 + return argnum;
125099 +
125100 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
125101 + argnum--;
125102 + while (origarg && argnum) {
125103 + origarg = TREE_CHAIN(origarg);
125104 + argnum--;
125105 + }
125106 + gcc_assert(argnum == 0);
125107 + gcc_assert(origarg != NULL_TREE);
125108 +
125109 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
125110 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
125111 + return new_argnum;
125112 +
125113 + return CANNOT_FIND_ARG;
125114 +}
125115 +
125116 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
125117 +{
125118 + const struct size_overflow_hash *hash;
125119 +
125120 + hash = get_function_hash(fndecl);
125121 + if (hash && (hash->param & (1U << num)))
125122 + return true;
125123 + return false;
125124 +}
125125 +
125126 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125127 + * If the function is missing everywhere then print the missing message into stderr.
125128 + */
125129 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125130 +{
125131 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125132 +#if BUILDING_GCC_VERSION >= 4008
125133 + case BUILT_IN_BSWAP16:
125134 +#endif
125135 + case BUILT_IN_BSWAP32:
125136 + case BUILT_IN_BSWAP64:
125137 + case BUILT_IN_EXPECT:
125138 + case BUILT_IN_MEMCMP:
125139 + return false;
125140 + default:
125141 + break;
125142 + }
125143 +
125144 + // skip test.c
125145 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125146 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125147 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125148 + }
125149 +
125150 + if (is_in_hash_table(orig_fndecl, num))
125151 + return false;
125152 +
125153 + print_missing_msg(orig_fndecl, num);
125154 + return true;
125155 +}
125156 +
125157 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125158 new file mode 100644
125159 index 0000000..924652b
125160 --- /dev/null
125161 +++ b/tools/gcc/stackleak_plugin.c
125162 @@ -0,0 +1,395 @@
125163 +/*
125164 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125165 + * Licensed under the GPL v2
125166 + *
125167 + * Note: the choice of the license means that the compilation process is
125168 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125169 + * but for the kernel it doesn't matter since it doesn't link against
125170 + * any of the gcc libraries
125171 + *
125172 + * gcc plugin to help implement various PaX features
125173 + *
125174 + * - track lowest stack pointer
125175 + *
125176 + * TODO:
125177 + * - initialize all local variables
125178 + *
125179 + * BUGS:
125180 + * - none known
125181 + */
125182 +
125183 +#include "gcc-common.h"
125184 +
125185 +int plugin_is_GPL_compatible;
125186 +
125187 +static int track_frame_size = -1;
125188 +static const char track_function[] = "pax_track_stack";
125189 +static const char check_function[] = "pax_check_alloca";
125190 +static tree track_function_decl, check_function_decl;
125191 +static bool init_locals;
125192 +
125193 +static struct plugin_info stackleak_plugin_info = {
125194 + .version = "201408011900",
125195 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125196 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125197 +};
125198 +
125199 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125200 +{
125201 + gimple check_alloca;
125202 + tree alloca_size;
125203 +
125204 + // insert call to void pax_check_alloca(unsigned long size)
125205 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125206 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125207 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125208 +}
125209 +
125210 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125211 +{
125212 + gimple track_stack;
125213 +
125214 + // insert call to void pax_track_stack(void)
125215 + track_stack = gimple_build_call(track_function_decl, 0);
125216 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125217 +}
125218 +
125219 +static bool is_alloca(gimple stmt)
125220 +{
125221 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125222 + return true;
125223 +
125224 +#if BUILDING_GCC_VERSION >= 4007
125225 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125226 + return true;
125227 +#endif
125228 +
125229 + return false;
125230 +}
125231 +
125232 +static unsigned int execute_stackleak_tree_instrument(void)
125233 +{
125234 + basic_block bb, entry_bb;
125235 + bool prologue_instrumented = false, is_leaf = true;
125236 +
125237 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125238 +
125239 + // 1. loop through BBs and GIMPLE statements
125240 + FOR_EACH_BB_FN(bb, cfun) {
125241 + gimple_stmt_iterator gsi;
125242 +
125243 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125244 + gimple stmt;
125245 +
125246 + stmt = gsi_stmt(gsi);
125247 +
125248 + if (is_gimple_call(stmt))
125249 + is_leaf = false;
125250 +
125251 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125252 + if (!is_alloca(stmt))
125253 + continue;
125254 +
125255 + // 2. insert stack overflow check before each __builtin_alloca call
125256 + stackleak_check_alloca(&gsi);
125257 +
125258 + // 3. insert track call after each __builtin_alloca call
125259 + stackleak_add_instrumentation(&gsi);
125260 + if (bb == entry_bb)
125261 + prologue_instrumented = true;
125262 + }
125263 + }
125264 +
125265 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125266 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125267 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125268 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125269 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125270 + return 0;
125271 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125272 + return 0;
125273 +
125274 + // 4. insert track call at the beginning
125275 + if (!prologue_instrumented) {
125276 + gimple_stmt_iterator gsi;
125277 +
125278 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125279 + if (dom_info_available_p(CDI_DOMINATORS))
125280 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125281 + gsi = gsi_start_bb(bb);
125282 + stackleak_add_instrumentation(&gsi);
125283 + }
125284 +
125285 + return 0;
125286 +}
125287 +
125288 +static unsigned int execute_stackleak_final(void)
125289 +{
125290 + rtx insn, next;
125291 +
125292 + if (cfun->calls_alloca)
125293 + return 0;
125294 +
125295 + // keep calls only if function frame is big enough
125296 + if (get_frame_size() >= track_frame_size)
125297 + return 0;
125298 +
125299 + // 1. find pax_track_stack calls
125300 + for (insn = get_insns(); insn; insn = next) {
125301 + // 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))
125302 + rtx body;
125303 +
125304 + next = NEXT_INSN(insn);
125305 + if (!CALL_P(insn))
125306 + continue;
125307 + body = PATTERN(insn);
125308 + if (GET_CODE(body) != CALL)
125309 + continue;
125310 + body = XEXP(body, 0);
125311 + if (GET_CODE(body) != MEM)
125312 + continue;
125313 + body = XEXP(body, 0);
125314 + if (GET_CODE(body) != SYMBOL_REF)
125315 + continue;
125316 +// if (strcmp(XSTR(body, 0), track_function))
125317 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125318 + continue;
125319 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125320 + // 2. delete call
125321 + delete_insn_and_edges(insn);
125322 +#if BUILDING_GCC_VERSION >= 4007
125323 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125324 + insn = next;
125325 + next = NEXT_INSN(insn);
125326 + delete_insn_and_edges(insn);
125327 + }
125328 +#endif
125329 + }
125330 +
125331 +// print_simple_rtl(stderr, get_insns());
125332 +// print_rtl(stderr, get_insns());
125333 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125334 +
125335 + return 0;
125336 +}
125337 +
125338 +static bool gate_stackleak_track_stack(void)
125339 +{
125340 + tree section;
125341 +
125342 + if (ix86_cmodel != CM_KERNEL)
125343 + return false;
125344 +
125345 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125346 + if (section && TREE_VALUE(section)) {
125347 + section = TREE_VALUE(TREE_VALUE(section));
125348 +
125349 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125350 + return false;
125351 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125352 + return false;
125353 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125354 + return false;
125355 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125356 + return false;
125357 + }
125358 +
125359 + return track_frame_size >= 0;
125360 +}
125361 +
125362 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125363 +{
125364 + tree fntype;
125365 +
125366 + // void pax_track_stack(void)
125367 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125368 + track_function_decl = build_fn_decl(track_function, fntype);
125369 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125370 + TREE_PUBLIC(track_function_decl) = 1;
125371 + DECL_EXTERNAL(track_function_decl) = 1;
125372 + DECL_ARTIFICIAL(track_function_decl) = 1;
125373 +
125374 + // void pax_check_alloca(unsigned long)
125375 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125376 + check_function_decl = build_fn_decl(check_function, fntype);
125377 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125378 + TREE_PUBLIC(check_function_decl) = 1;
125379 + DECL_EXTERNAL(check_function_decl) = 1;
125380 + DECL_ARTIFICIAL(check_function_decl) = 1;
125381 +}
125382 +
125383 +#if BUILDING_GCC_VERSION >= 4009
125384 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125385 +#else
125386 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125387 + .pass = {
125388 +#endif
125389 + .type = GIMPLE_PASS,
125390 + .name = "stackleak_tree_instrument",
125391 +#if BUILDING_GCC_VERSION >= 4008
125392 + .optinfo_flags = OPTGROUP_NONE,
125393 +#endif
125394 +#if BUILDING_GCC_VERSION >= 4009
125395 + .has_gate = true,
125396 + .has_execute = true,
125397 +#else
125398 + .gate = gate_stackleak_track_stack,
125399 + .execute = execute_stackleak_tree_instrument,
125400 + .sub = NULL,
125401 + .next = NULL,
125402 + .static_pass_number = 0,
125403 +#endif
125404 + .tv_id = TV_NONE,
125405 + .properties_required = PROP_gimple_leh | PROP_cfg,
125406 + .properties_provided = 0,
125407 + .properties_destroyed = 0,
125408 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125409 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125410 +#if BUILDING_GCC_VERSION < 4009
125411 + }
125412 +#endif
125413 +};
125414 +
125415 +#if BUILDING_GCC_VERSION >= 4009
125416 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125417 +#else
125418 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125419 + .pass = {
125420 +#endif
125421 + .type = RTL_PASS,
125422 + .name = "stackleak_final",
125423 +#if BUILDING_GCC_VERSION >= 4008
125424 + .optinfo_flags = OPTGROUP_NONE,
125425 +#endif
125426 +#if BUILDING_GCC_VERSION >= 4009
125427 + .has_gate = true,
125428 + .has_execute = true,
125429 +#else
125430 + .gate = gate_stackleak_track_stack,
125431 + .execute = execute_stackleak_final,
125432 + .sub = NULL,
125433 + .next = NULL,
125434 + .static_pass_number = 0,
125435 +#endif
125436 + .tv_id = TV_NONE,
125437 + .properties_required = 0,
125438 + .properties_provided = 0,
125439 + .properties_destroyed = 0,
125440 + .todo_flags_start = 0,
125441 + .todo_flags_finish = TODO_dump_func
125442 +#if BUILDING_GCC_VERSION < 4009
125443 + }
125444 +#endif
125445 +};
125446 +
125447 +#if BUILDING_GCC_VERSION >= 4009
125448 +namespace {
125449 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125450 +public:
125451 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125452 + bool gate() { return gate_stackleak_track_stack(); }
125453 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125454 +};
125455 +
125456 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125457 +public:
125458 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125459 + bool gate() { return gate_stackleak_track_stack(); }
125460 + unsigned int execute() { return execute_stackleak_final(); }
125461 +};
125462 +}
125463 +
125464 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125465 +{
125466 + return new stackleak_tree_instrument_pass();
125467 +}
125468 +
125469 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125470 +{
125471 + return new stackleak_final_rtl_opt_pass();
125472 +}
125473 +#else
125474 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125475 +{
125476 + return &stackleak_tree_instrument_pass.pass;
125477 +}
125478 +
125479 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125480 +{
125481 + return &stackleak_final_rtl_opt_pass.pass;
125482 +}
125483 +#endif
125484 +
125485 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125486 +{
125487 + const char * const plugin_name = plugin_info->base_name;
125488 + const int argc = plugin_info->argc;
125489 + const struct plugin_argument * const argv = plugin_info->argv;
125490 + int i;
125491 + struct register_pass_info stackleak_tree_instrument_pass_info;
125492 + struct register_pass_info stackleak_final_pass_info;
125493 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125494 + {
125495 + .base = &track_function_decl,
125496 + .nelt = 1,
125497 + .stride = sizeof(track_function_decl),
125498 + .cb = &gt_ggc_mx_tree_node,
125499 + .pchw = &gt_pch_nx_tree_node
125500 + },
125501 + {
125502 + .base = &check_function_decl,
125503 + .nelt = 1,
125504 + .stride = sizeof(check_function_decl),
125505 + .cb = &gt_ggc_mx_tree_node,
125506 + .pchw = &gt_pch_nx_tree_node
125507 + },
125508 + LAST_GGC_ROOT_TAB
125509 + };
125510 +
125511 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125512 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125513 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125514 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125515 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125516 +
125517 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125518 + stackleak_final_pass_info.reference_pass_name = "final";
125519 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125520 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125521 +
125522 + if (!plugin_default_version_check(version, &gcc_version)) {
125523 + error(G_("incompatible gcc/plugin versions"));
125524 + return 1;
125525 + }
125526 +
125527 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125528 +
125529 + for (i = 0; i < argc; ++i) {
125530 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125531 + if (!argv[i].value) {
125532 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125533 + continue;
125534 + }
125535 + track_frame_size = atoi(argv[i].value);
125536 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125537 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125538 + continue;
125539 + }
125540 + if (!strcmp(argv[i].key, "initialize-locals")) {
125541 + if (argv[i].value) {
125542 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125543 + continue;
125544 + }
125545 + init_locals = true;
125546 + continue;
125547 + }
125548 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125549 + }
125550 +
125551 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125552 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125553 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125554 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125555 +
125556 + return 0;
125557 +}
125558 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125559 new file mode 100644
125560 index 0000000..4ee2231
125561 --- /dev/null
125562 +++ b/tools/gcc/structleak_plugin.c
125563 @@ -0,0 +1,274 @@
125564 +/*
125565 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125566 + * Licensed under the GPL v2
125567 + *
125568 + * Note: the choice of the license means that the compilation process is
125569 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125570 + * but for the kernel it doesn't matter since it doesn't link against
125571 + * any of the gcc libraries
125572 + *
125573 + * gcc plugin to forcibly initialize certain local variables that could
125574 + * otherwise leak kernel stack to userland if they aren't properly initialized
125575 + * by later code
125576 + *
125577 + * Homepage: http://pax.grsecurity.net/
125578 + *
125579 + * Usage:
125580 + * $ # for 4.5/4.6/C based 4.7
125581 + * $ 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
125582 + * $ # for C++ based 4.7/4.8+
125583 + * $ 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
125584 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125585 + *
125586 + * TODO: eliminate redundant initializers
125587 + * increase type coverage
125588 + */
125589 +
125590 +#include "gcc-common.h"
125591 +
125592 +// unused C type flag in all versions 4.5-4.9
125593 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125594 +
125595 +int plugin_is_GPL_compatible;
125596 +
125597 +static struct plugin_info structleak_plugin_info = {
125598 + .version = "201401260140",
125599 + .help = "disable\tdo not activate plugin\n",
125600 +};
125601 +
125602 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125603 +{
125604 + *no_add_attrs = true;
125605 +
125606 + // check for types? for now accept everything linux has to offer
125607 + if (TREE_CODE(*node) != FIELD_DECL)
125608 + return NULL_TREE;
125609 +
125610 + *no_add_attrs = false;
125611 + return NULL_TREE;
125612 +}
125613 +
125614 +static struct attribute_spec user_attr = {
125615 + .name = "user",
125616 + .min_length = 0,
125617 + .max_length = 0,
125618 + .decl_required = false,
125619 + .type_required = false,
125620 + .function_type_required = false,
125621 + .handler = handle_user_attribute,
125622 +#if BUILDING_GCC_VERSION >= 4007
125623 + .affects_type_identity = true
125624 +#endif
125625 +};
125626 +
125627 +static void register_attributes(void *event_data, void *data)
125628 +{
125629 + register_attribute(&user_attr);
125630 +// register_attribute(&force_attr);
125631 +}
125632 +
125633 +static tree get_field_type(tree field)
125634 +{
125635 + return strip_array_types(TREE_TYPE(field));
125636 +}
125637 +
125638 +static bool is_userspace_type(tree type)
125639 +{
125640 + tree field;
125641 +
125642 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125643 + tree fieldtype = get_field_type(field);
125644 + enum tree_code code = TREE_CODE(fieldtype);
125645 +
125646 + if (code == RECORD_TYPE || code == UNION_TYPE)
125647 + if (is_userspace_type(fieldtype))
125648 + return true;
125649 +
125650 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125651 + return true;
125652 + }
125653 + return false;
125654 +}
125655 +
125656 +static void finish_type(void *event_data, void *data)
125657 +{
125658 + tree type = (tree)event_data;
125659 +
125660 + if (TYPE_USERSPACE(type))
125661 + return;
125662 +
125663 + if (is_userspace_type(type))
125664 + TYPE_USERSPACE(type) = 1;
125665 +}
125666 +
125667 +static void initialize(tree var)
125668 +{
125669 + basic_block bb;
125670 + gimple_stmt_iterator gsi;
125671 + tree initializer;
125672 + gimple init_stmt;
125673 +
125674 + // this is the original entry bb before the forced split
125675 + // TODO: check further BBs in case more splits occured before us
125676 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125677 +
125678 + // first check if the variable is already initialized, warn otherwise
125679 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125680 + gimple stmt = gsi_stmt(gsi);
125681 + tree rhs1;
125682 +
125683 + // we're looking for an assignment of a single rhs...
125684 + if (!gimple_assign_single_p(stmt))
125685 + continue;
125686 + rhs1 = gimple_assign_rhs1(stmt);
125687 +#if BUILDING_GCC_VERSION >= 4007
125688 + // ... of a non-clobbering expression...
125689 + if (TREE_CLOBBER_P(rhs1))
125690 + continue;
125691 +#endif
125692 + // ... to our variable...
125693 + if (gimple_get_lhs(stmt) != var)
125694 + continue;
125695 + // if it's an initializer then we're good
125696 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125697 + return;
125698 + }
125699 +
125700 + // these aren't the 0days you're looking for
125701 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125702 +
125703 + // build the initializer expression
125704 + initializer = build_constructor(TREE_TYPE(var), NULL);
125705 +
125706 + // build the initializer stmt
125707 + init_stmt = gimple_build_assign(var, initializer);
125708 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125709 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125710 + update_stmt(init_stmt);
125711 +}
125712 +
125713 +static unsigned int handle_function(void)
125714 +{
125715 + basic_block bb;
125716 + unsigned int ret = 0;
125717 + tree var;
125718 + unsigned int i;
125719 +
125720 + // split the first bb where we can put the forced initializers
125721 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125722 + if (dom_info_available_p(CDI_DOMINATORS))
125723 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125724 +
125725 + // enumarate all local variables and forcibly initialize our targets
125726 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125727 + tree type = TREE_TYPE(var);
125728 +
125729 + gcc_assert(DECL_P(var));
125730 + if (!auto_var_in_fn_p(var, current_function_decl))
125731 + continue;
125732 +
125733 + // only care about structure types
125734 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125735 + continue;
125736 +
125737 + // if the type is of interest, examine the variable
125738 + if (TYPE_USERSPACE(type))
125739 + initialize(var);
125740 + }
125741 +
125742 + return ret;
125743 +}
125744 +
125745 +#if BUILDING_GCC_VERSION >= 4009
125746 +static const struct pass_data structleak_pass_data = {
125747 +#else
125748 +static struct gimple_opt_pass structleak_pass = {
125749 + .pass = {
125750 +#endif
125751 + .type = GIMPLE_PASS,
125752 + .name = "structleak",
125753 +#if BUILDING_GCC_VERSION >= 4008
125754 + .optinfo_flags = OPTGROUP_NONE,
125755 +#endif
125756 +#if BUILDING_GCC_VERSION >= 4009
125757 + .has_gate = false,
125758 + .has_execute = true,
125759 +#else
125760 + .gate = NULL,
125761 + .execute = handle_function,
125762 + .sub = NULL,
125763 + .next = NULL,
125764 + .static_pass_number = 0,
125765 +#endif
125766 + .tv_id = TV_NONE,
125767 + .properties_required = PROP_cfg,
125768 + .properties_provided = 0,
125769 + .properties_destroyed = 0,
125770 + .todo_flags_start = 0,
125771 + .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
125772 +#if BUILDING_GCC_VERSION < 4009
125773 + }
125774 +#endif
125775 +};
125776 +
125777 +#if BUILDING_GCC_VERSION >= 4009
125778 +namespace {
125779 +class structleak_pass : public gimple_opt_pass {
125780 +public:
125781 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125782 + unsigned int execute() { return handle_function(); }
125783 +};
125784 +}
125785 +
125786 +static opt_pass *make_structleak_pass(void)
125787 +{
125788 + return new structleak_pass();
125789 +}
125790 +#else
125791 +static struct opt_pass *make_structleak_pass(void)
125792 +{
125793 + return &structleak_pass.pass;
125794 +}
125795 +#endif
125796 +
125797 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125798 +{
125799 + int i;
125800 + const char * const plugin_name = plugin_info->base_name;
125801 + const int argc = plugin_info->argc;
125802 + const struct plugin_argument * const argv = plugin_info->argv;
125803 + bool enable = true;
125804 + struct register_pass_info structleak_pass_info;
125805 +
125806 + structleak_pass_info.pass = make_structleak_pass();
125807 + structleak_pass_info.reference_pass_name = "ssa";
125808 + structleak_pass_info.ref_pass_instance_number = 1;
125809 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125810 +
125811 + if (!plugin_default_version_check(version, &gcc_version)) {
125812 + error(G_("incompatible gcc/plugin versions"));
125813 + return 1;
125814 + }
125815 +
125816 + if (strcmp(lang_hooks.name, "GNU C")) {
125817 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125818 + enable = false;
125819 + }
125820 +
125821 + for (i = 0; i < argc; ++i) {
125822 + if (!strcmp(argv[i].key, "disable")) {
125823 + enable = false;
125824 + continue;
125825 + }
125826 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125827 + }
125828 +
125829 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125830 + if (enable) {
125831 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125832 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125833 + }
125834 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125835 +
125836 + return 0;
125837 +}
125838 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125839 index 88461f0..6fb70a0 100644
125840 --- a/tools/include/linux/compiler.h
125841 +++ b/tools/include/linux/compiler.h
125842 @@ -35,6 +35,14 @@
125843 # define unlikely(x) __builtin_expect(!!(x), 0)
125844 #endif
125845
125846 +#ifndef __size_overflow
125847 +# define __size_overflow(...)
125848 +#endif
125849 +
125850 +#ifndef __intentional_overflow
125851 +# define __intentional_overflow(...)
125852 +#endif
125853 +
125854 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125855
125856 #endif /* _TOOLS_LINUX_COMPILER_H */
125857 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125858 index 36c08b1..87c72d1 100644
125859 --- a/tools/lib/api/Makefile
125860 +++ b/tools/lib/api/Makefile
125861 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
125862
125863 LIBFILE = libapikfs.a
125864
125865 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125866 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125867 EXTLIBS = -lelf -lpthread -lrt -lm
125868 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125869 ALL_LDFLAGS = $(LDFLAGS)
125870 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125871 index 6789d788..4afd019e 100644
125872 --- a/tools/perf/util/include/asm/alternative-asm.h
125873 +++ b/tools/perf/util/include/asm/alternative-asm.h
125874 @@ -5,4 +5,7 @@
125875
125876 #define altinstruction_entry #
125877
125878 + .macro pax_force_retaddr rip=0, reload=0
125879 + .endm
125880 +
125881 #endif
125882 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125883 index 0a578fe..b81f62d 100644
125884 --- a/tools/virtio/linux/uaccess.h
125885 +++ b/tools/virtio/linux/uaccess.h
125886 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125887 ({ \
125888 typeof(ptr) __pu_ptr = (ptr); \
125889 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125890 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125891 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125892 0; \
125893 })
125894
125895 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125896 index 3cee7b1..29cb7d8 100644
125897 --- a/virt/kvm/kvm_main.c
125898 +++ b/virt/kvm/kvm_main.c
125899 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
125900
125901 static cpumask_var_t cpus_hardware_enabled;
125902 static int kvm_usage_count = 0;
125903 -static atomic_t hardware_enable_failed;
125904 +static atomic_unchecked_t hardware_enable_failed;
125905
125906 struct kmem_cache *kvm_vcpu_cache;
125907 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125908
125909 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125910 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125911 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125912 +static struct preempt_ops kvm_preempt_ops = {
125913 + .sched_in = kvm_sched_in,
125914 + .sched_out = kvm_sched_out,
125915 +};
125916
125917 struct dentry *kvm_debugfs_dir;
125918
125919 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125920 /* We can read the guest memory with __xxx_user() later on. */
125921 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125922 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125923 - !access_ok(VERIFY_WRITE,
125924 + !access_ok_noprefault(VERIFY_WRITE,
125925 (void __user *)(unsigned long)mem->userspace_addr,
125926 mem->memory_size)))
125927 goto out;
125928 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125929
125930 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125931 {
125932 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125933 + int r;
125934 + unsigned long addr;
125935
125936 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125937 + addr = gfn_to_hva(kvm, gfn);
125938 + if (kvm_is_error_hva(addr))
125939 + return -EFAULT;
125940 + r = __clear_user((void __user *)addr + offset, len);
125941 + if (r)
125942 + return -EFAULT;
125943 + mark_page_dirty(kvm, gfn);
125944 + return 0;
125945 }
125946 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125947
125948 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125949 return 0;
125950 }
125951
125952 -static struct file_operations kvm_vcpu_fops = {
125953 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125954 .release = kvm_vcpu_release,
125955 .unlocked_ioctl = kvm_vcpu_ioctl,
125956 #ifdef CONFIG_COMPAT
125957 @@ -2650,7 +2663,7 @@ out:
125958 }
125959 #endif
125960
125961 -static struct file_operations kvm_vm_fops = {
125962 +static file_operations_no_const kvm_vm_fops __read_only = {
125963 .release = kvm_vm_release,
125964 .unlocked_ioctl = kvm_vm_ioctl,
125965 #ifdef CONFIG_COMPAT
125966 @@ -2721,7 +2734,7 @@ out:
125967 return r;
125968 }
125969
125970 -static struct file_operations kvm_chardev_ops = {
125971 +static file_operations_no_const kvm_chardev_ops __read_only = {
125972 .unlocked_ioctl = kvm_dev_ioctl,
125973 .compat_ioctl = kvm_dev_ioctl,
125974 .llseek = noop_llseek,
125975 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
125976
125977 if (r) {
125978 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125979 - atomic_inc(&hardware_enable_failed);
125980 + atomic_inc_unchecked(&hardware_enable_failed);
125981 printk(KERN_INFO "kvm: enabling virtualization on "
125982 "CPU%d failed\n", cpu);
125983 }
125984 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
125985
125986 kvm_usage_count++;
125987 if (kvm_usage_count == 1) {
125988 - atomic_set(&hardware_enable_failed, 0);
125989 + atomic_set_unchecked(&hardware_enable_failed, 0);
125990 on_each_cpu(hardware_enable_nolock, NULL, 1);
125991
125992 - if (atomic_read(&hardware_enable_failed)) {
125993 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125994 hardware_disable_all_nolock();
125995 r = -EBUSY;
125996 }
125997 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125998 kvm_arch_vcpu_put(vcpu);
125999 }
126000
126001 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126002 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126003 struct module *module)
126004 {
126005 int r;
126006 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126007 if (!vcpu_align)
126008 vcpu_align = __alignof__(struct kvm_vcpu);
126009 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
126010 - 0, NULL);
126011 + SLAB_USERCOPY, NULL);
126012 if (!kvm_vcpu_cache) {
126013 r = -ENOMEM;
126014 goto out_free_3;
126015 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126016 if (r)
126017 goto out_free;
126018
126019 + pax_open_kernel();
126020 kvm_chardev_ops.owner = module;
126021 kvm_vm_fops.owner = module;
126022 kvm_vcpu_fops.owner = module;
126023 + pax_close_kernel();
126024
126025 r = misc_register(&kvm_dev);
126026 if (r) {
126027 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126028
126029 register_syscore_ops(&kvm_syscore_ops);
126030
126031 - kvm_preempt_ops.sched_in = kvm_sched_in;
126032 - kvm_preempt_ops.sched_out = kvm_sched_out;
126033 -
126034 r = kvm_init_debug();
126035 if (r) {
126036 printk(KERN_ERR "kvm: create debugfs files failed\n");