]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.18.4-201501272307.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.4-201501272307.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 4e93284..ba06195 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380 -HOSTCXXFLAGS = -O2
381 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387 @@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391 -PHONY += scripts_basic
392 -scripts_basic:
393 +PHONY += scripts_basic gcc-plugins
394 +scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398 @@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402 +ifndef DISABLE_PAX_PLUGINS
403 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405 +else
406 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407 +endif
408 +ifneq ($(PLUGINCC),)
409 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411 +endif
412 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
413 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415 +endif
416 +ifdef CONFIG_KALLOCSTAT_PLUGIN
417 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418 +endif
419 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423 +endif
424 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428 +endif
429 +endif
430 +ifdef CONFIG_CHECKER_PLUGIN
431 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433 +endif
434 +endif
435 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436 +ifdef CONFIG_PAX_SIZE_OVERFLOW
437 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438 +endif
439 +ifdef CONFIG_PAX_LATENT_ENTROPY
440 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441 +endif
442 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444 +endif
445 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451 +ifeq ($(KBUILD_EXTMOD),)
452 +gcc-plugins:
453 + $(Q)$(MAKE) $(build)=tools/gcc
454 +else
455 +gcc-plugins: ;
456 +endif
457 +else
458 +gcc-plugins:
459 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
461 +else
462 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463 +endif
464 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465 +endif
466 +endif
467 +
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471 @@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475 -KBUILD_AFLAGS += -Wa,-gdwarf-2
476 +KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480 @@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489 @@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498 @@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502 -$(vmlinux-dirs): prepare scripts
503 +$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507 @@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521 @@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530 @@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534 -modules_prepare: prepare scripts
535 +modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539 @@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543 - signing_key.x509.signer include/linux/version.h
544 + signing_key.x509.signer include/linux/version.h \
545 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547 + tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551 @@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560 @@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569 @@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573 -%.s: %.c prepare scripts FORCE
574 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576 +%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580 -%.o: %.c prepare scripts FORCE
581 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583 +%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587 -%.s: %.S prepare scripts FORCE
588 +%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590 -%.o: %.S prepare scripts FORCE
591 +%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595 @@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599 -%/: prepare scripts FORCE
600 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602 +%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606 -%.ko: prepare scripts FORCE
607 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609 +%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614 index 8f8eafb..3405f46 100644
615 --- a/arch/alpha/include/asm/atomic.h
616 +++ b/arch/alpha/include/asm/atomic.h
617 @@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621 +#define atomic64_read_unchecked(v) atomic64_read(v)
622 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
627 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
629 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630 +
631 #endif /* _ALPHA_ATOMIC_H */
632 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633 index ad368a9..fbe0f25 100644
634 --- a/arch/alpha/include/asm/cache.h
635 +++ b/arch/alpha/include/asm/cache.h
636 @@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640 +#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644 -# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650 -# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659 index 968d999..d36b2df 100644
660 --- a/arch/alpha/include/asm/elf.h
661 +++ b/arch/alpha/include/asm/elf.h
662 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666 +#ifdef CONFIG_PAX_ASLR
667 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668 +
669 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671 +#endif
672 +
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677 index aab14a0..b4fa3e7 100644
678 --- a/arch/alpha/include/asm/pgalloc.h
679 +++ b/arch/alpha/include/asm/pgalloc.h
680 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684 +static inline void
685 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686 +{
687 + pgd_populate(mm, pgd, pmd);
688 +}
689 +
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694 index d8f9b7e..f6222fa 100644
695 --- a/arch/alpha/include/asm/pgtable.h
696 +++ b/arch/alpha/include/asm/pgtable.h
697 @@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 +
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +#else
707 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
708 +# define PAGE_COPY_NOEXEC PAGE_COPY
709 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
710 +#endif
711 +
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716 index 2fd00b7..cfd5069 100644
717 --- a/arch/alpha/kernel/module.c
718 +++ b/arch/alpha/kernel/module.c
719 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723 - gp = (u64)me->module_core + me->core_size - 0x8000;
724 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729 index f9c732e..78fbb0f 100644
730 --- a/arch/alpha/kernel/osf_sys.c
731 +++ b/arch/alpha/kernel/osf_sys.c
732 @@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737 - unsigned long limit)
738 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739 + unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746 @@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750 + info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754 @@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758 +#ifdef CONFIG_PAX_RANDMMAP
759 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760 +#endif
761 +
762 if (addr) {
763 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771 - len, limit);
772 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773 +
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784 index 98838a0..b304fb4 100644
785 --- a/arch/alpha/mm/fault.c
786 +++ b/arch/alpha/mm/fault.c
787 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791 +#ifdef CONFIG_PAX_PAGEEXEC
792 +/*
793 + * PaX: decide what to do with offenders (regs->pc = fault address)
794 + *
795 + * returns 1 when task should be killed
796 + * 2 when patched PLT trampoline was detected
797 + * 3 when unpatched PLT trampoline was detected
798 + */
799 +static int pax_handle_fetch_fault(struct pt_regs *regs)
800 +{
801 +
802 +#ifdef CONFIG_PAX_EMUPLT
803 + int err;
804 +
805 + do { /* PaX: patched PLT emulation #1 */
806 + unsigned int ldah, ldq, jmp;
807 +
808 + err = get_user(ldah, (unsigned int *)regs->pc);
809 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811 +
812 + if (err)
813 + break;
814 +
815 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817 + jmp == 0x6BFB0000U)
818 + {
819 + unsigned long r27, addr;
820 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822 +
823 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824 + err = get_user(r27, (unsigned long *)addr);
825 + if (err)
826 + break;
827 +
828 + regs->r27 = r27;
829 + regs->pc = r27;
830 + return 2;
831 + }
832 + } while (0);
833 +
834 + do { /* PaX: patched PLT emulation #2 */
835 + unsigned int ldah, lda, br;
836 +
837 + err = get_user(ldah, (unsigned int *)regs->pc);
838 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
839 + err |= get_user(br, (unsigned int *)(regs->pc+8));
840 +
841 + if (err)
842 + break;
843 +
844 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
846 + (br & 0xFFE00000U) == 0xC3E00000U)
847 + {
848 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851 +
852 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854 + return 2;
855 + }
856 + } while (0);
857 +
858 + do { /* PaX: unpatched PLT emulation */
859 + unsigned int br;
860 +
861 + err = get_user(br, (unsigned int *)regs->pc);
862 +
863 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864 + unsigned int br2, ldq, nop, jmp;
865 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866 +
867 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868 + err = get_user(br2, (unsigned int *)addr);
869 + err |= get_user(ldq, (unsigned int *)(addr+4));
870 + err |= get_user(nop, (unsigned int *)(addr+8));
871 + err |= get_user(jmp, (unsigned int *)(addr+12));
872 + err |= get_user(resolver, (unsigned long *)(addr+16));
873 +
874 + if (err)
875 + break;
876 +
877 + if (br2 == 0xC3600000U &&
878 + ldq == 0xA77B000CU &&
879 + nop == 0x47FF041FU &&
880 + jmp == 0x6B7B0000U)
881 + {
882 + regs->r28 = regs->pc+4;
883 + regs->r27 = addr+16;
884 + regs->pc = resolver;
885 + return 3;
886 + }
887 + }
888 + } while (0);
889 +#endif
890 +
891 + return 1;
892 +}
893 +
894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895 +{
896 + unsigned long i;
897 +
898 + printk(KERN_ERR "PAX: bytes at PC: ");
899 + for (i = 0; i < 5; i++) {
900 + unsigned int c;
901 + if (get_user(c, (unsigned int *)pc+i))
902 + printk(KERN_CONT "???????? ");
903 + else
904 + printk(KERN_CONT "%08x ", c);
905 + }
906 + printk("\n");
907 +}
908 +#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912 @@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916 - if (!(vma->vm_flags & VM_EXEC))
917 + if (!(vma->vm_flags & VM_EXEC)) {
918 +
919 +#ifdef CONFIG_PAX_PAGEEXEC
920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921 + goto bad_area;
922 +
923 + up_read(&mm->mmap_sem);
924 + switch (pax_handle_fetch_fault(regs)) {
925 +
926 +#ifdef CONFIG_PAX_EMUPLT
927 + case 2:
928 + case 3:
929 + return;
930 +#endif
931 +
932 + }
933 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934 + do_group_exit(SIGKILL);
935 +#else
936 goto bad_area;
937 +#endif
938 +
939 + }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944 index 89c4b5c..847a7be 100644
945 --- a/arch/arm/Kconfig
946 +++ b/arch/arm/Kconfig
947 @@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951 - depends on MMU
952 + depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956 @@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960 + depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965 index e22c119..eaa807d 100644
966 --- a/arch/arm/include/asm/atomic.h
967 +++ b/arch/arm/include/asm/atomic.h
968 @@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972 +#ifdef CONFIG_GENERIC_ATOMIC64
973 +#include <asm-generic/atomic64.h>
974 +#endif
975 +
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980 +#ifdef CONFIG_THUMB2_KERNEL
981 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982 +#else
983 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984 +#endif
985 +
986 +#define _ASM_EXTABLE(from, to) \
987 +" .pushsection __ex_table,\"a\"\n"\
988 +" .align 3\n" \
989 +" .long " #from ", " #to"\n" \
990 +" .popsection"
991 +
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999 +{
1000 + return ACCESS_ONCE(v->counter);
1001 +}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004 +{
1005 + v->counter = i;
1006 +}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010 @@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014 -#define ATOMIC_OP(op, c_op, asm_op) \
1015 -static inline void atomic_##op(int i, atomic_t *v) \
1016 +#ifdef CONFIG_PAX_REFCOUNT
1017 +#define __OVERFLOW_POST \
1018 + " bvc 3f\n" \
1019 + "2: " REFCOUNT_TRAP_INSN "\n"\
1020 + "3:\n"
1021 +#define __OVERFLOW_POST_RETURN \
1022 + " bvc 3f\n" \
1023 +" mov %0, %1\n" \
1024 + "2: " REFCOUNT_TRAP_INSN "\n"\
1025 + "3:\n"
1026 +#define __OVERFLOW_EXTABLE \
1027 + "4:\n" \
1028 + _ASM_EXTABLE(2b, 4b)
1029 +#else
1030 +#define __OVERFLOW_POST
1031 +#define __OVERFLOW_POST_RETURN
1032 +#define __OVERFLOW_EXTABLE
1033 +#endif
1034 +
1035 +#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042 - __asm__ __volatile__("@ atomic_" #op "\n" \
1043 + __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046 + post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049 -" bne 1b" \
1050 +" bne 1b\n" \
1051 + extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1059 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060 + __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061 +
1062 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067 @@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071 - __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072 + __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075 + post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078 -" bne 1b" \
1079 +" bne 1b\n" \
1080 + extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084 @@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090 +
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094 @@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098 -" beq 2f\n"
1099 -" add %1, %0, %6\n"
1100 +" beq 4f\n"
1101 +" adds %1, %0, %6\n"
1102 +
1103 +#ifdef CONFIG_PAX_REFCOUNT
1104 +" bvc 3f\n"
1105 +"2: " REFCOUNT_TRAP_INSN "\n"
1106 +"3:\n"
1107 +#endif
1108 +
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112 -"2:"
1113 +"4:"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122 @@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127 +{
1128 + unsigned long oldval, res;
1129 +
1130 + smp_mb();
1131 +
1132 + do {
1133 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134 + "ldrex %1, [%3]\n"
1135 + "mov %0, #0\n"
1136 + "teq %1, %4\n"
1137 + "strexeq %0, %5, [%3]\n"
1138 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140 + : "cc");
1141 + } while (res);
1142 +
1143 + smp_mb();
1144 +
1145 + return oldval;
1146 +}
1147 +
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154 -#define ATOMIC_OP(op, c_op, asm_op) \
1155 -static inline void atomic_##op(int i, atomic_t *v) \
1156 +#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161 @@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166 -static inline int atomic_##op##_return(int i, atomic_t *v) \
1167 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168 + __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169 +
1170 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175 @@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181 +
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185 @@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190 +{
1191 + return atomic_cmpxchg((atomic_t *)v, old, new);
1192 +}
1193 +
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197 @@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201 +#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203 +#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207 +{
1208 + return xchg(&v->counter, new);
1209 +}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213 +{
1214 + atomic_add_unchecked(1, v);
1215 +}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218 +{
1219 + atomic_sub_unchecked(1, v);
1220 +}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224 +{
1225 + return atomic_add_return_unchecked(1, v) == 0;
1226 +}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230 +{
1231 + return atomic_add_return_unchecked(1, v);
1232 +}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236 @@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +typedef struct {
1242 + long long counter;
1243 +} atomic64_unchecked_t;
1244 +#else
1245 +typedef atomic64_t atomic64_unchecked_t;
1246 +#endif
1247 +
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251 @@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256 +{
1257 + long long result;
1258 +
1259 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260 +" ldrd %0, %H0, [%1]"
1261 + : "=&r" (result)
1262 + : "r" (&v->counter), "Qo" (v->counter)
1263 + );
1264 +
1265 + return result;
1266 +}
1267 +
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271 @@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275 +
1276 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277 +{
1278 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279 +" strd %2, %H2, [%1]"
1280 + : "=Qo" (v->counter)
1281 + : "r" (&v->counter), "r" (i)
1282 + );
1283 +}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287 @@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292 +{
1293 + long long result;
1294 +
1295 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296 +" ldrexd %0, %H0, [%1]"
1297 + : "=&r" (result)
1298 + : "r" (&v->counter), "Qo" (v->counter)
1299 + );
1300 +
1301 + return result;
1302 +}
1303 +
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307 @@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311 +
1312 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313 +{
1314 + long long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%2]\n"
1319 +" strexd %0, %3, %H3, [%2]\n"
1320 +" teq %0, #0\n"
1321 +" bne 1b"
1322 + : "=&r" (tmp), "=Qo" (v->counter)
1323 + : "r" (&v->counter), "r" (i)
1324 + : "cc");
1325 +}
1326 #endif
1327
1328 -#define ATOMIC64_OP(op, op1, op2) \
1329 -static inline void atomic64_##op(long long i, atomic64_t *v) \
1330 +#undef __OVERFLOW_POST_RETURN
1331 +#define __OVERFLOW_POST_RETURN \
1332 + " bvc 3f\n" \
1333 +" mov %0, %1\n" \
1334 +" mov %H0, %H1\n" \
1335 + "2: " REFCOUNT_TRAP_INSN "\n"\
1336 + "3:\n"
1337 +
1338 +#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339 +static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345 - __asm__ __volatile__("@ atomic64_" #op "\n" \
1346 + __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350 + post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353 -" bne 1b" \
1354 +" bne 1b\n" \
1355 + extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361 -#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362 -static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363 +#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364 + __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365 +
1366 +#define __ATOMIC64_OP_RETURN(op, suffix, op1, op2, post_op, extable) \
1367 +static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371 @@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375 - __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376 + __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380 + post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383 -" bne 1b" \
1384 +" bne 1b\n" \
1385 + extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389 @@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393 +#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394 + __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395 +
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399 @@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403 +#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405 +#undef __ATOMIC64_OP
1406 +#undef __OVERFLOW_EXTABLE
1407 +#undef __OVERFLOW_POST_RETURN
1408 +#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412 @@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417 + long long new)
1418 +{
1419 + long long oldval;
1420 + unsigned long res;
1421 +
1422 + smp_mb();
1423 +
1424 + do {
1425 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426 + "ldrexd %1, %H1, [%3]\n"
1427 + "mov %0, #0\n"
1428 + "teq %1, %4\n"
1429 + "teqeq %H1, %H4\n"
1430 + "strexdeq %0, %5, %H5, [%3]"
1431 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432 + : "r" (&ptr->counter), "r" (old), "r" (new)
1433 + : "cc");
1434 + } while (res);
1435 +
1436 + smp_mb();
1437 +
1438 + return oldval;
1439 +}
1440 +
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444 @@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448 - unsigned long tmp;
1449 + u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455 -"1: ldrexd %0, %H0, [%3]\n"
1456 -" subs %Q0, %Q0, #1\n"
1457 -" sbc %R0, %R0, #0\n"
1458 +"1: ldrexd %1, %H1, [%3]\n"
1459 +" subs %Q0, %Q1, #1\n"
1460 +" sbcs %R0, %R1, #0\n"
1461 +
1462 +#ifdef CONFIG_PAX_REFCOUNT
1463 +" bvc 3f\n"
1464 +" mov %Q0, %Q1\n"
1465 +" mov %R0, %R1\n"
1466 +"2: " REFCOUNT_TRAP_INSN "\n"
1467 +"3:\n"
1468 +#endif
1469 +
1470 " teq %R0, #0\n"
1471 -" bmi 2f\n"
1472 +" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476 -"2:"
1477 +"4:\n"
1478 +
1479 +#ifdef CONFIG_PAX_REFCOUNT
1480 + _ASM_EXTABLE(2b, 4b)
1481 +#endif
1482 +
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486 @@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490 -" beq 2f\n"
1491 +" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493 -" adc %R0, %R0, %R6\n"
1494 +" adcs %R0, %R0, %R6\n"
1495 +
1496 +#ifdef CONFIG_PAX_REFCOUNT
1497 +" bvc 3f\n"
1498 +"2: " REFCOUNT_TRAP_INSN "\n"
1499 +"3:\n"
1500 +#endif
1501 +
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505 -"2:"
1506 +"4:\n"
1507 +
1508 +#ifdef CONFIG_PAX_REFCOUNT
1509 + _ASM_EXTABLE(2b, 4b)
1510 +#endif
1511 +
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515 @@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530 index c6a3e73..35cca85 100644
1531 --- a/arch/arm/include/asm/barrier.h
1532 +++ b/arch/arm/include/asm/barrier.h
1533 @@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537 - ACCESS_ONCE(*p) = (v); \
1538 + ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543 index 75fe66b..ba3dee4 100644
1544 --- a/arch/arm/include/asm/cache.h
1545 +++ b/arch/arm/include/asm/cache.h
1546 @@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550 +#include <linux/const.h>
1551 +
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558 @@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566 index 10e78d0..dc8505d 100644
1567 --- a/arch/arm/include/asm/cacheflush.h
1568 +++ b/arch/arm/include/asm/cacheflush.h
1569 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573 -};
1574 +} __no_const;
1575
1576 /*
1577 * Select the calling method
1578 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579 index 5233151..87a71fa 100644
1580 --- a/arch/arm/include/asm/checksum.h
1581 +++ b/arch/arm/include/asm/checksum.h
1582 @@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588 +
1589 +static inline __wsum
1590 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591 +{
1592 + __wsum ret;
1593 + pax_open_userland();
1594 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595 + pax_close_userland();
1596 + return ret;
1597 +}
1598 +
1599 +
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604 index abb2c37..96db950 100644
1605 --- a/arch/arm/include/asm/cmpxchg.h
1606 +++ b/arch/arm/include/asm/cmpxchg.h
1607 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611 +#define xchg_unchecked(ptr,x) \
1612 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617 index 6ddbe44..b5e38b1 100644
1618 --- a/arch/arm/include/asm/domain.h
1619 +++ b/arch/arm/include/asm/domain.h
1620 @@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624 -#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626 +#define DOMAIN_USERCLIENT 1
1627 +#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629 +#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631 +
1632 +#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634 +#define DOMAIN_KERNEXEC 3
1635 +#else
1636 +#define DOMAIN_MANAGER 1
1637 +#endif
1638 +
1639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1640 +#define DOMAIN_USERCLIENT 0
1641 +#define DOMAIN_UDEREF 1
1642 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1643 +#else
1644 +#define DOMAIN_USERCLIENT 1
1645 +#define DOMAIN_VECTORS DOMAIN_USER
1646 +#endif
1647 +#define DOMAIN_KERNELCLIENT 1
1648 +
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655 -#ifdef CONFIG_CPU_USE_DOMAINS
1656 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664 -#define modify_domain(dom,type) \
1665 - do { \
1666 - struct thread_info *thread = current_thread_info(); \
1667 - unsigned int domain = thread->cpu_domain; \
1668 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669 - thread->cpu_domain = domain | domain_val(dom, type); \
1670 - set_domain(thread->cpu_domain); \
1671 - } while (0)
1672 -
1673 +extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678 index afb9caf..9a0bac0 100644
1679 --- a/arch/arm/include/asm/elf.h
1680 +++ b/arch/arm/include/asm/elf.h
1681 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687 +
1688 +#ifdef CONFIG_PAX_ASLR
1689 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690 +
1691 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693 +#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701 -struct mm_struct;
1702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703 -#define arch_randomize_brk arch_randomize_brk
1704 -
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709 index de53547..52b9a28 100644
1710 --- a/arch/arm/include/asm/fncpy.h
1711 +++ b/arch/arm/include/asm/fncpy.h
1712 @@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716 + pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718 + pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723 index 53e69da..3fdc896 100644
1724 --- a/arch/arm/include/asm/futex.h
1725 +++ b/arch/arm/include/asm/futex.h
1726 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730 + pax_open_userland();
1731 +
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739 + pax_close_userland();
1740 +
1741 *uval = val;
1742 return ret;
1743 }
1744 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748 + pax_open_userland();
1749 +
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757 + pax_close_userland();
1758 +
1759 *uval = val;
1760 return ret;
1761 }
1762 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766 + pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774 + pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779 index 83eb2f7..ed77159 100644
1780 --- a/arch/arm/include/asm/kmap_types.h
1781 +++ b/arch/arm/include/asm/kmap_types.h
1782 @@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786 -#define KM_TYPE_NR 16
1787 +#define KM_TYPE_NR 17
1788
1789 #endif
1790 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791 index 9e614a1..3302cca 100644
1792 --- a/arch/arm/include/asm/mach/dma.h
1793 +++ b/arch/arm/include/asm/mach/dma.h
1794 @@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798 -};
1799 +} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804 index f98c7f3..e5c626d 100644
1805 --- a/arch/arm/include/asm/mach/map.h
1806 +++ b/arch/arm/include/asm/mach/map.h
1807 @@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811 - MT_UNCACHED = 4,
1812 - MT_CACHECLEAN,
1813 - MT_MINICLEAN,
1814 + MT_UNCACHED_RW = 4,
1815 + MT_CACHECLEAN_RO,
1816 + MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819 - MT_MEMORY_RWX,
1820 + __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822 - MT_ROM,
1823 - MT_MEMORY_RWX_NONCACHED,
1824 + MT_MEMORY_RX,
1825 + MT_ROM_RX,
1826 + MT_MEMORY_RW_NONCACHED,
1827 + MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829 - MT_MEMORY_RWX_ITCM,
1830 + MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835 index 891a56b..48f337e 100644
1836 --- a/arch/arm/include/asm/outercache.h
1837 +++ b/arch/arm/include/asm/outercache.h
1838 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842 -};
1843 +} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848 index 4355f0e..cd9168e 100644
1849 --- a/arch/arm/include/asm/page.h
1850 +++ b/arch/arm/include/asm/page.h
1851 @@ -23,6 +23,7 @@
1852
1853 #else
1854
1855 +#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863 -};
1864 +} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869 index 78a7793..e3dc06c 100644
1870 --- a/arch/arm/include/asm/pgalloc.h
1871 +++ b/arch/arm/include/asm/pgalloc.h
1872 @@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876 +#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885 +{
1886 + pud_populate(mm, pud, pmd);
1887 +}
1888 +
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905 +{
1906 +#ifdef CONFIG_ARM_LPAE
1907 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908 +#else
1909 + if (addr & SECTION_SIZE)
1910 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911 + else
1912 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913 +#endif
1914 + flush_pmd_entry(pmdp);
1915 +}
1916 +
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930 index 5cfba15..f415e1a 100644
1931 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933 @@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941 +
1942 /*
1943 * - section
1944 */
1945 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949 @@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957 @@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966 index f027941..f36ce30 100644
1967 --- a/arch/arm/include/asm/pgtable-2level.h
1968 +++ b/arch/arm/include/asm/pgtable-2level.h
1969 @@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974 +#define L_PTE_PXN (_AT(pteval_t, 0))
1975 +
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980 index 9fd61c7..f8f1cff 100644
1981 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983 @@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992 index a31ecdad..95e98d4 100644
1993 --- a/arch/arm/include/asm/pgtable-3level.h
1994 +++ b/arch/arm/include/asm/pgtable-3level.h
1995 @@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003 @@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017 index 3b30062..01a5f9d 100644
2018 --- a/arch/arm/include/asm/pgtable.h
2019 +++ b/arch/arm/include/asm/pgtable.h
2020 @@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024 +#define ktla_ktva(addr) (addr)
2025 +#define ktva_ktla(addr) (addr)
2026 +
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030 @@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034 +extern pteval_t __supported_pte_mask;
2035 +extern pmdval_t __supported_pmd_mask;
2036 +
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046 +
2047 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048 +#include <asm/domain.h>
2049 +#include <linux/thread_info.h>
2050 +#include <linux/preempt.h>
2051 +
2052 +static inline int test_domain(int domain, int domaintype)
2053 +{
2054 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055 +}
2056 +#endif
2057 +
2058 +#ifdef CONFIG_PAX_KERNEXEC
2059 +static inline unsigned long pax_open_kernel(void) {
2060 +#ifdef CONFIG_ARM_LPAE
2061 + /* TODO */
2062 +#else
2063 + preempt_disable();
2064 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066 +#endif
2067 + return 0;
2068 +}
2069 +
2070 +static inline unsigned long pax_close_kernel(void) {
2071 +#ifdef CONFIG_ARM_LPAE
2072 + /* TODO */
2073 +#else
2074 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077 + preempt_enable_no_resched();
2078 +#endif
2079 + return 0;
2080 +}
2081 +#else
2082 +static inline unsigned long pax_open_kernel(void) { return 0; }
2083 +static inline unsigned long pax_close_kernel(void) { return 0; }
2084 +#endif
2085 +
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093 - * as well as any architecture dependent bits like global/ASID and SMP
2094 - * shared mapping bits.
2095 + * as well as any architecture dependent bits like global/ASID, PXN,
2096 + * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100 @@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104 - L_PTE_NONE | L_PTE_VALID;
2105 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110 index c25ef3e..735f14b 100644
2111 --- a/arch/arm/include/asm/psci.h
2112 +++ b/arch/arm/include/asm/psci.h
2113 @@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117 -};
2118 +} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123 index 18f5a55..5072a40 100644
2124 --- a/arch/arm/include/asm/smp.h
2125 +++ b/arch/arm/include/asm/smp.h
2126 @@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130 -};
2131 +} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136 index ce73ab6..7310f8a 100644
2137 --- a/arch/arm/include/asm/thread_info.h
2138 +++ b/arch/arm/include/asm/thread_info.h
2139 @@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157 +/* within 8 bits of TIF_SYSCALL_TRACE
2158 + * to meet flexible second operand requirements
2159 + */
2160 +#define TIF_GRSEC_SETXID 12
2161 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179 index 5f833f7..76e6644 100644
2180 --- a/arch/arm/include/asm/tls.h
2181 +++ b/arch/arm/include/asm/tls.h
2182 @@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186 +#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194 + pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196 + pax_close_kernel();
2197 #endif
2198 }
2199
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 4767eb9..bf00668 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index a88671c..1cc895e 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 2f5555d..d493c91 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: str r4, [sp, #S_PC] @ retry current instruction
2605 +4: pax_close_userland
2606 + str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610 @@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index 6bb09d4..113e875 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index 4176df7..a901f8d 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770 @@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index b37752a..ff5cb72 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 664eee8..f470938 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 6a4dffe..4a86a70 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index fe972a2..a772d83 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932 -/* If possible, provide a placement hint at a random offset from the
2933 - * stack for the signal page.
2934 - */
2935 -static unsigned long sigpage_addr(const struct mm_struct *mm,
2936 - unsigned int npages)
2937 -{
2938 - unsigned long offset;
2939 - unsigned long first;
2940 - unsigned long last;
2941 - unsigned long addr;
2942 - unsigned int slots;
2943 -
2944 - first = PAGE_ALIGN(mm->start_stack);
2945 -
2946 - last = TASK_SIZE - (npages << PAGE_SHIFT);
2947 -
2948 - /* No room after stack? */
2949 - if (first > last)
2950 - return 0;
2951 -
2952 - /* Just enough room? */
2953 - if (first == last)
2954 - return first;
2955 -
2956 - slots = ((last - first) >> PAGE_SHIFT) + 1;
2957 -
2958 - offset = get_random_int() % slots;
2959 -
2960 - addr = first + (offset << PAGE_SHIFT);
2961 -
2962 - return addr;
2963 -}
2964 -
2965 -static struct page *signal_page;
2966 -extern struct page *get_signal_page(void);
2967 -
2968 -static const struct vm_special_mapping sigpage_mapping = {
2969 - .name = "[sigpage]",
2970 - .pages = &signal_page,
2971 -};
2972 -
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976 - struct vm_area_struct *vma;
2977 - unsigned long addr;
2978 - unsigned long hint;
2979 - int ret = 0;
2980 -
2981 - if (!signal_page)
2982 - signal_page = get_signal_page();
2983 - if (!signal_page)
2984 - return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987 - hint = sigpage_addr(mm, 1);
2988 - addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989 - if (IS_ERR_VALUE(addr)) {
2990 - ret = addr;
2991 - goto up_fail;
2992 - }
2993 -
2994 - vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996 - &sigpage_mapping);
2997 -
2998 - if (IS_ERR(vma)) {
2999 - ret = PTR_ERR(vma);
3000 - goto up_fail;
3001 - }
3002 -
3003 - mm->context.sigpage = addr;
3004 -
3005 - up_fail:
3006 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008 - return ret;
3009 + return 0;
3010 }
3011 #endif
3012 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013 index f73891b..cf3004e 100644
3014 --- a/arch/arm/kernel/psci.c
3015 +++ b/arch/arm/kernel/psci.c
3016 @@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020 -struct psci_operations psci_ops;
3021 +struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026 index ef9119f..31995a3 100644
3027 --- a/arch/arm/kernel/ptrace.c
3028 +++ b/arch/arm/kernel/ptrace.c
3029 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033 +#ifdef CONFIG_GRKERNSEC_SETXID
3034 +extern void gr_delayed_cred_worker(void);
3035 +#endif
3036 +
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041 +#ifdef CONFIG_GRKERNSEC_SETXID
3042 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043 + gr_delayed_cred_worker();
3044 +#endif
3045 +
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050 index 306e1ac..1b477ed 100644
3051 --- a/arch/arm/kernel/setup.c
3052 +++ b/arch/arm/kernel/setup.c
3053 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057 +pteval_t __supported_pte_mask __read_only;
3058 +pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061 -struct processor processor __read_mostly;
3062 +struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3066 +struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069 -struct cpu_user_fns cpu_user __read_mostly;
3070 +struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073 -struct cpu_cache_fns cpu_cache __read_mostly;
3074 +struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077 -struct outer_cache_fns outer_cache __read_mostly;
3078 +struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082 @@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086 - (mmfr0 & 0x000000f0) >= 0x00000030)
3087 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091 + __supported_pte_mask |= L_PTE_PXN;
3092 + __supported_pmd_mask |= PMD_PXNTABLE;
3093 + }
3094 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099 index bd19834..e4d8c66 100644
3100 --- a/arch/arm/kernel/signal.c
3101 +++ b/arch/arm/kernel/signal.c
3102 @@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106 -static unsigned long signal_return_offset;
3107 -
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115 - retcode = mm->context.sigpage + signal_return_offset +
3116 - (idx << 2) + thumb;
3117 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125 -
3126 -struct page *get_signal_page(void)
3127 -{
3128 - unsigned long ptr;
3129 - unsigned offset;
3130 - struct page *page;
3131 - void *addr;
3132 -
3133 - page = alloc_pages(GFP_KERNEL, 0);
3134 -
3135 - if (!page)
3136 - return NULL;
3137 -
3138 - addr = page_address(page);
3139 -
3140 - /* Give the signal return code some randomness */
3141 - offset = 0x200 + (get_random_int() & 0x7fc);
3142 - signal_return_offset = offset;
3143 -
3144 - /*
3145 - * Copy signal return handlers into the vector page, and
3146 - * set sigreturn to be a pointer to these.
3147 - */
3148 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149 -
3150 - ptr = (unsigned long)addr + offset;
3151 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152 -
3153 - return page;
3154 -}
3155 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156 index a8e32aa..b2f7198 100644
3157 --- a/arch/arm/kernel/smp.c
3158 +++ b/arch/arm/kernel/smp.c
3159 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163 -static struct smp_operations smp_ops;
3164 +static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169 index 7a3be1d..b00c7de 100644
3170 --- a/arch/arm/kernel/tcm.c
3171 +++ b/arch/arm/kernel/tcm.c
3172 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176 - .type = MT_MEMORY_RWX_ITCM,
3177 + .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181 @@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185 + pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187 + pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192 index 9f5d818..e013427 100644
3193 --- a/arch/arm/kernel/traps.c
3194 +++ b/arch/arm/kernel/traps.c
3195 @@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204 @@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208 +extern void gr_handle_kernel_exploit(void);
3209 +
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213 @@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217 +
3218 + gr_handle_kernel_exploit();
3219 +
3220 if (signr)
3221 do_exit(signr);
3222 }
3223 @@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228 +
3229 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3230 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231 +#endif
3232 +
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237 index 8e95aa4..595dfc8 100644
3238 --- a/arch/arm/kernel/vmlinux.lds.S
3239 +++ b/arch/arm/kernel/vmlinux.lds.S
3240 @@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244 -
3245 +
3246 +#ifdef CONFIG_PAX_KERNEXEC
3247 +#include <asm/pgtable.h>
3248 +#endif
3249 +
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253 @@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257 - defined(CONFIG_GENERIC_BUG)
3258 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262 @@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266 +
3267 +#ifdef CONFIG_PAX_KERNEXEC
3268 + . = ALIGN(1<<SECTION_SHIFT);
3269 +#endif
3270 +
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274 @@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278 + _etext = .; /* End of text section */
3279 +
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283 @@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287 - _etext = .; /* End of text and rodata section */
3288 +#ifdef CONFIG_PAX_KERNEXEC
3289 + . = ALIGN(1<<SECTION_SHIFT);
3290 +#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294 @@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298 +
3299 +#ifdef CONFIG_PAX_KERNEXEC
3300 + . = ALIGN(1<<SECTION_SHIFT);
3301 +#endif
3302 +
3303 __data_loc = .;
3304 #endif
3305
3306 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307 index 9e193c8..3560fe6 100644
3308 --- a/arch/arm/kvm/arm.c
3309 +++ b/arch/arm/kvm/arm.c
3310 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319 @@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328 @@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332 - atomic64_inc(&kvm_vmid_gen);
3333 + atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337 @@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346 @@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350 -int kvm_arch_init(void *opaque)
3351 +int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356 index 14a0d98..7771a7d 100644
3357 --- a/arch/arm/lib/clear_user.S
3358 +++ b/arch/arm/lib/clear_user.S
3359 @@ -12,14 +12,14 @@
3360
3361 .text
3362
3363 -/* Prototype: int __clear_user(void *addr, size_t sz)
3364 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371 -WEAK(__clear_user)
3372 +WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380 -ENDPROC(__clear_user)
3381 +ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386 index 66a477a..bee61d3 100644
3387 --- a/arch/arm/lib/copy_from_user.S
3388 +++ b/arch/arm/lib/copy_from_user.S
3389 @@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3394 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398 @@ -84,11 +84,11 @@
3399
3400 .text
3401
3402 -ENTRY(__copy_from_user)
3403 +ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407 -ENDPROC(__copy_from_user)
3408 +ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413 index 6ee2f67..d1cce76 100644
3414 --- a/arch/arm/lib/copy_page.S
3415 +++ b/arch/arm/lib/copy_page.S
3416 @@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420 +#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425 index d066df6..df28194 100644
3426 --- a/arch/arm/lib/copy_to_user.S
3427 +++ b/arch/arm/lib/copy_to_user.S
3428 @@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3433 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437 @@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441 -WEAK(__copy_to_user)
3442 +WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446 -ENDPROC(__copy_to_user)
3447 +ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452 index 7d08b43..f7ca7ea 100644
3453 --- a/arch/arm/lib/csumpartialcopyuser.S
3454 +++ b/arch/arm/lib/csumpartialcopyuser.S
3455 @@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467 index 312d43e..21d2322 100644
3468 --- a/arch/arm/lib/delay.c
3469 +++ b/arch/arm/lib/delay.c
3470 @@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474 -struct arm_delay_ops arm_delay_ops = {
3475 +struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480 index 3e58d71..029817c 100644
3481 --- a/arch/arm/lib/uaccess_with_memcpy.c
3482 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3483 @@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3488 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492 @@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496 -unsigned long __clear_user(void __user *addr, unsigned long n)
3497 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502 index 9610792..4dfb851 100644
3503 --- a/arch/arm/mach-at91/setup.c
3504 +++ b/arch/arm/mach-at91/setup.c
3505 @@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509 - desc->type = MT_MEMORY_RWX_NONCACHED;
3510 + desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515 index 7f352de..6dc0929 100644
3516 --- a/arch/arm/mach-keystone/keystone.c
3517 +++ b/arch/arm/mach-keystone/keystone.c
3518 @@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522 -static struct notifier_block platform_nb;
3523 +static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528 index c31f4c0..c86224d 100644
3529 --- a/arch/arm/mach-mvebu/coherency.c
3530 +++ b/arch/arm/mach-mvebu/coherency.c
3531 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544 - mtype = MT_UNCACHED;
3545 + mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550 index 97767a2..9233746 100644
3551 --- a/arch/arm/mach-omap2/board-n8x0.c
3552 +++ b/arch/arm/mach-omap2/board-n8x0.c
3553 @@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557 -struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558 +struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563 index 5fa3755..1e8c247 100644
3564 --- a/arch/arm/mach-omap2/gpmc.c
3565 +++ b/arch/arm/mach-omap2/gpmc.c
3566 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570 -static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578 +static struct irq_chip gpmc_irq_chip = {
3579 + .name = "gpmc",
3580 + .irq_startup = gpmc_irq_noop_ret,
3581 + .irq_enable = gpmc_irq_enable,
3582 + .irq_disable = gpmc_irq_disable,
3583 + .irq_shutdown = gpmc_irq_noop,
3584 + .irq_ack = gpmc_irq_noop,
3585 + .irq_mask = gpmc_irq_noop,
3586 + .irq_unmask = gpmc_irq_noop,
3587 +
3588 +};
3589 +
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597 - gpmc_irq_chip.name = "gpmc";
3598 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605 -
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610 index 6944ae3..bc587ca 100644
3611 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613 @@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617 -};
3618 +} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622 @@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626 -struct cpu_pm_ops omap_pm_ops = {
3627 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632 index f961c46..4a453dc 100644
3633 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635 @@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639 -static struct notifier_block __refdata irq_hotplug_notifier = {
3640 +static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645 index 8c58b71..95b655f 100644
3646 --- a/arch/arm/mach-omap2/omap_device.c
3647 +++ b/arch/arm/mach-omap2/omap_device.c
3648 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652 - void *pdata, int pdata_len)
3653 + const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661 - int oh_cnt, void *pdata,
3662 + int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667 index 78c02b3..c94109a 100644
3668 --- a/arch/arm/mach-omap2/omap_device.h
3669 +++ b/arch/arm/mach-omap2/omap_device.h
3670 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674 - struct omap_hwmod *oh, void *pdata,
3675 + struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680 - void *pdata, int pdata_len);
3681 + const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686 index 716247e..8df346d 100644
3687 --- a/arch/arm/mach-omap2/omap_hwmod.c
3688 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3689 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693 -};
3694 +} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697 -static struct omap_hwmod_soc_ops soc_ops;
3698 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703 index 95fee54..cfa9cf1 100644
3704 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706 @@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710 +#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719 + pax_open_kernel();
3720 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721 + pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726 index ff0a68c..b312aa0 100644
3727 --- a/arch/arm/mach-omap2/wd_timer.c
3728 +++ b/arch/arm/mach-omap2/wd_timer.c
3729 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733 - struct omap_wd_timer_platform_data pdata;
3734 + static struct omap_wd_timer_platform_data pdata = {
3735 + .read_reset_sources = prm_read_reset_sources
3736 + };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744 - pdata.read_reset_sources = prm_read_reset_sources;
3745 -
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750 index b30bf5c..d0825bf 100644
3751 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757 - ACCESS_ONCE(abort_flag) = true;
3758 + ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763 index 2dea8b5..6499da2 100644
3764 --- a/arch/arm/mach-ux500/setup.h
3765 +++ b/arch/arm/mach-ux500/setup.h
3766 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770 -#define __MEM_DEV_DESC(x, sz) { \
3771 - .virtual = IO_ADDRESS(x), \
3772 - .pfn = __phys_to_pfn(x), \
3773 - .length = sz, \
3774 - .type = MT_MEMORY_RWX, \
3775 -}
3776 -
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781 index 7eb94e6..799ad3e 100644
3782 --- a/arch/arm/mm/Kconfig
3783 +++ b/arch/arm/mm/Kconfig
3784 @@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804 - depends on MMU
3805 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813 - by ROP (return orientated programming) authors when creating
3814 + by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819 index 83792f4..c25d36b 100644
3820 --- a/arch/arm/mm/alignment.c
3821 +++ b/arch/arm/mm/alignment.c
3822 @@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826 + pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839 + pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 @@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 @@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871 + pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875 @@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879 + pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884 index 5e65ca8..879e7b3 100644
3885 --- a/arch/arm/mm/cache-l2x0.c
3886 +++ b/arch/arm/mm/cache-l2x0.c
3887 @@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891 -};
3892 +} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897 index 6eb97b3..ac509f6 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 @@ -182,7 +182,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 @@ -203,7 +203,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 @@ -234,14 +234,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 0eca933..eb78c7b 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 @@ -176,6 +193,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 7225dad..2a7c8256 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 22b19c2..c5cc8c4 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 becc42b..9e43d4b 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 @@ -199,6 +216,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 3ca9c11..d163ef7 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 08d659a..ab329f4 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 @@ -495,6 +526,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 908e8c1..1524793 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 18fcd71..e4fe821 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 41a503c..cf98b04 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 @@ -973,6 +974,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 @@ -1128,6 +1130,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 @@ -1164,6 +1167,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 @@ -1216,7 +1220,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 @@ -1631,6 +1635,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 @@ -1816,7 +1821,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 @@ -1899,6 +1906,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 45abc36..97bea2d 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 30dd59a..cd9edc3 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 @@ -402,7 +405,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 50d033a..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,11 +258,14 @@ 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 -#define _LDT_empty(info) \
16656 +/* This intentionally ignores lm, since 32-bit apps don't have that field. */
16657 +#define LDT_empty(info) \
16658 ((info)->base_addr == 0 && \
16659 (info)->limit == 0 && \
16660 (info)->contents == 0 && \
16661 @@ -261,11 +275,18 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16662 (info)->seg_not_present == 1 && \
16663 (info)->useable == 0)
16664
16665 -#ifdef CONFIG_X86_64
16666 -#define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
16667 -#else
16668 -#define LDT_empty(info) (_LDT_empty(info))
16669 -#endif
16670 +/* Lots of programs expect an all-zero user_desc to mean "no segment at all". */
16671 +static inline bool LDT_zero(const struct user_desc *info)
16672 +{
16673 + return (info->base_addr == 0 &&
16674 + info->limit == 0 &&
16675 + info->contents == 0 &&
16676 + info->read_exec_only == 0 &&
16677 + info->seg_32bit == 0 &&
16678 + info->limit_in_pages == 0 &&
16679 + info->seg_not_present == 0 &&
16680 + info->useable == 0);
16681 +}
16682
16683 static inline void clear_LDT(void)
16684 {
16685 @@ -287,7 +308,7 @@ static inline void load_LDT(mm_context_t *pc)
16686 preempt_enable();
16687 }
16688
16689 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16690 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16691 {
16692 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16693 }
16694 @@ -311,7 +332,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16695 }
16696
16697 #ifdef CONFIG_X86_64
16698 -static inline void set_nmi_gate(int gate, void *addr)
16699 +static inline void set_nmi_gate(int gate, const void *addr)
16700 {
16701 gate_desc s;
16702
16703 @@ -321,14 +342,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16704 #endif
16705
16706 #ifdef CONFIG_TRACING
16707 -extern struct desc_ptr trace_idt_descr;
16708 -extern gate_desc trace_idt_table[];
16709 +extern const struct desc_ptr trace_idt_descr;
16710 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16711 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16712 {
16713 write_idt_entry(trace_idt_table, entry, gate);
16714 }
16715
16716 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16717 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16718 unsigned dpl, unsigned ist, unsigned seg)
16719 {
16720 gate_desc s;
16721 @@ -348,7 +369,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16722 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16723 #endif
16724
16725 -static inline void _set_gate(int gate, unsigned type, void *addr,
16726 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16727 unsigned dpl, unsigned ist, unsigned seg)
16728 {
16729 gate_desc s;
16730 @@ -371,9 +392,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16731 #define set_intr_gate(n, addr) \
16732 do { \
16733 BUG_ON((unsigned)n > 0xFF); \
16734 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16735 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16736 __KERNEL_CS); \
16737 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16738 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16739 0, 0, __KERNEL_CS); \
16740 } while (0)
16741
16742 @@ -401,19 +422,19 @@ static inline void alloc_system_vector(int vector)
16743 /*
16744 * This routine sets up an interrupt gate at directory privilege level 3.
16745 */
16746 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16747 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16748 {
16749 BUG_ON((unsigned)n > 0xFF);
16750 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16751 }
16752
16753 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16754 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16755 {
16756 BUG_ON((unsigned)n > 0xFF);
16757 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16758 }
16759
16760 -static inline void set_trap_gate(unsigned int n, void *addr)
16761 +static inline void set_trap_gate(unsigned int n, const void *addr)
16762 {
16763 BUG_ON((unsigned)n > 0xFF);
16764 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16765 @@ -422,16 +443,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16766 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16767 {
16768 BUG_ON((unsigned)n > 0xFF);
16769 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16770 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16771 }
16772
16773 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16774 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16775 {
16776 BUG_ON((unsigned)n > 0xFF);
16777 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16778 }
16779
16780 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16781 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16782 {
16783 BUG_ON((unsigned)n > 0xFF);
16784 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16785 @@ -503,4 +524,17 @@ static inline void load_current_idt(void)
16786 else
16787 load_idt((const struct desc_ptr *)&idt_descr);
16788 }
16789 +
16790 +#ifdef CONFIG_X86_32
16791 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16792 +{
16793 + struct desc_struct d;
16794 +
16795 + if (likely(limit))
16796 + limit = (limit - 1UL) >> PAGE_SHIFT;
16797 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16798 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16799 +}
16800 +#endif
16801 +
16802 #endif /* _ASM_X86_DESC_H */
16803 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16804 index 278441f..b95a174 100644
16805 --- a/arch/x86/include/asm/desc_defs.h
16806 +++ b/arch/x86/include/asm/desc_defs.h
16807 @@ -31,6 +31,12 @@ struct desc_struct {
16808 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16809 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16810 };
16811 + struct {
16812 + u16 offset_low;
16813 + u16 seg;
16814 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16815 + unsigned offset_high: 16;
16816 + } gate;
16817 };
16818 } __attribute__((packed));
16819
16820 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16821 index ced283a..ffe04cc 100644
16822 --- a/arch/x86/include/asm/div64.h
16823 +++ b/arch/x86/include/asm/div64.h
16824 @@ -39,7 +39,7 @@
16825 __mod; \
16826 })
16827
16828 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16829 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16830 {
16831 union {
16832 u64 v64;
16833 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16834 index ca3347a..1a5082a 100644
16835 --- a/arch/x86/include/asm/elf.h
16836 +++ b/arch/x86/include/asm/elf.h
16837 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16838
16839 #include <asm/vdso.h>
16840
16841 -#ifdef CONFIG_X86_64
16842 -extern unsigned int vdso64_enabled;
16843 -#endif
16844 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16845 extern unsigned int vdso32_enabled;
16846 #endif
16847 @@ -249,7 +246,25 @@ extern int force_personality32;
16848 the loader. We need to make sure that it is out of the way of the program
16849 that it will "exec", and that there is sufficient room for the brk. */
16850
16851 +#ifdef CONFIG_PAX_SEGMEXEC
16852 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16853 +#else
16854 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16855 +#endif
16856 +
16857 +#ifdef CONFIG_PAX_ASLR
16858 +#ifdef CONFIG_X86_32
16859 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16860 +
16861 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16862 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16863 +#else
16864 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16865 +
16866 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16867 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16868 +#endif
16869 +#endif
16870
16871 /* This yields a mask that user programs can use to figure out what
16872 instruction set this CPU supports. This could be done in user space,
16873 @@ -298,17 +313,13 @@ do { \
16874
16875 #define ARCH_DLINFO \
16876 do { \
16877 - if (vdso64_enabled) \
16878 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16879 - (unsigned long __force)current->mm->context.vdso); \
16880 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16881 } while (0)
16882
16883 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16884 #define ARCH_DLINFO_X32 \
16885 do { \
16886 - if (vdso64_enabled) \
16887 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16888 - (unsigned long __force)current->mm->context.vdso); \
16889 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16890 } while (0)
16891
16892 #define AT_SYSINFO 32
16893 @@ -323,10 +334,10 @@ else \
16894
16895 #endif /* !CONFIG_X86_32 */
16896
16897 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16898 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16899
16900 #define VDSO_ENTRY \
16901 - ((unsigned long)current->mm->context.vdso + \
16902 + (current->mm->context.vdso + \
16903 selected_vdso32->sym___kernel_vsyscall)
16904
16905 struct linux_binprm;
16906 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16907 int uses_interp);
16908 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16909
16910 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16911 -#define arch_randomize_brk arch_randomize_brk
16912 -
16913 /*
16914 * True on X86_32 or when emulating IA32 on X86_64
16915 */
16916 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16917 index 77a99ac..39ff7f5 100644
16918 --- a/arch/x86/include/asm/emergency-restart.h
16919 +++ b/arch/x86/include/asm/emergency-restart.h
16920 @@ -1,6 +1,6 @@
16921 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16922 #define _ASM_X86_EMERGENCY_RESTART_H
16923
16924 -extern void machine_emergency_restart(void);
16925 +extern void machine_emergency_restart(void) __noreturn;
16926
16927 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16928 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16929 index 1c7eefe..d0e4702 100644
16930 --- a/arch/x86/include/asm/floppy.h
16931 +++ b/arch/x86/include/asm/floppy.h
16932 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16933 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16934 } fd_routine[] = {
16935 {
16936 - request_dma,
16937 - free_dma,
16938 - get_dma_residue,
16939 - dma_mem_alloc,
16940 - hard_dma_setup
16941 + ._request_dma = request_dma,
16942 + ._free_dma = free_dma,
16943 + ._get_dma_residue = get_dma_residue,
16944 + ._dma_mem_alloc = dma_mem_alloc,
16945 + ._dma_setup = hard_dma_setup
16946 },
16947 {
16948 - vdma_request_dma,
16949 - vdma_nop,
16950 - vdma_get_dma_residue,
16951 - vdma_mem_alloc,
16952 - vdma_dma_setup
16953 + ._request_dma = vdma_request_dma,
16954 + ._free_dma = vdma_nop,
16955 + ._get_dma_residue = vdma_get_dma_residue,
16956 + ._dma_mem_alloc = vdma_mem_alloc,
16957 + ._dma_setup = vdma_dma_setup
16958 }
16959 };
16960
16961 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16962 index e97622f..d0ba77a 100644
16963 --- a/arch/x86/include/asm/fpu-internal.h
16964 +++ b/arch/x86/include/asm/fpu-internal.h
16965 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16966 #define user_insn(insn, output, input...) \
16967 ({ \
16968 int err; \
16969 + pax_open_userland(); \
16970 asm volatile(ASM_STAC "\n" \
16971 - "1:" #insn "\n\t" \
16972 + "1:" \
16973 + __copyuser_seg \
16974 + #insn "\n\t" \
16975 "2: " ASM_CLAC "\n" \
16976 ".section .fixup,\"ax\"\n" \
16977 "3: movl $-1,%[err]\n" \
16978 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16979 _ASM_EXTABLE(1b, 3b) \
16980 : [err] "=r" (err), output \
16981 : "0"(0), input); \
16982 + pax_close_userland(); \
16983 err; \
16984 })
16985
16986 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16987 "fnclex\n\t"
16988 "emms\n\t"
16989 "fildl %P[addr]" /* set F?P to defined value */
16990 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16991 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16992 }
16993
16994 return fpu_restore_checking(&tsk->thread.fpu);
16995 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16996 index b4c1f54..e290c08 100644
16997 --- a/arch/x86/include/asm/futex.h
16998 +++ b/arch/x86/include/asm/futex.h
16999 @@ -12,6 +12,7 @@
17000 #include <asm/smap.h>
17001
17002 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17003 + typecheck(u32 __user *, uaddr); \
17004 asm volatile("\t" ASM_STAC "\n" \
17005 "1:\t" insn "\n" \
17006 "2:\t" ASM_CLAC "\n" \
17007 @@ -20,15 +21,16 @@
17008 "\tjmp\t2b\n" \
17009 "\t.previous\n" \
17010 _ASM_EXTABLE(1b, 3b) \
17011 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17012 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17013 : "i" (-EFAULT), "0" (oparg), "1" (0))
17014
17015 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17016 + typecheck(u32 __user *, uaddr); \
17017 asm volatile("\t" ASM_STAC "\n" \
17018 "1:\tmovl %2, %0\n" \
17019 "\tmovl\t%0, %3\n" \
17020 "\t" insn "\n" \
17021 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17022 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17023 "\tjnz\t1b\n" \
17024 "3:\t" ASM_CLAC "\n" \
17025 "\t.section .fixup,\"ax\"\n" \
17026 @@ -38,7 +40,7 @@
17027 _ASM_EXTABLE(1b, 4b) \
17028 _ASM_EXTABLE(2b, 4b) \
17029 : "=&a" (oldval), "=&r" (ret), \
17030 - "+m" (*uaddr), "=&r" (tem) \
17031 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17032 : "r" (oparg), "i" (-EFAULT), "1" (0))
17033
17034 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17035 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17036
17037 pagefault_disable();
17038
17039 + pax_open_userland();
17040 switch (op) {
17041 case FUTEX_OP_SET:
17042 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17043 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17044 break;
17045 case FUTEX_OP_ADD:
17046 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17047 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17048 uaddr, oparg);
17049 break;
17050 case FUTEX_OP_OR:
17051 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17052 default:
17053 ret = -ENOSYS;
17054 }
17055 + pax_close_userland();
17056
17057 pagefault_enable();
17058
17059 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17060 index 4615906..788c817 100644
17061 --- a/arch/x86/include/asm/hw_irq.h
17062 +++ b/arch/x86/include/asm/hw_irq.h
17063 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17064 extern void enable_IO_APIC(void);
17065
17066 /* Statistics */
17067 -extern atomic_t irq_err_count;
17068 -extern atomic_t irq_mis_count;
17069 +extern atomic_unchecked_t irq_err_count;
17070 +extern atomic_unchecked_t irq_mis_count;
17071
17072 /* EISA */
17073 extern void eisa_set_level_irq(unsigned int irq);
17074 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17075 index ccffa53..3c90c87 100644
17076 --- a/arch/x86/include/asm/i8259.h
17077 +++ b/arch/x86/include/asm/i8259.h
17078 @@ -62,7 +62,7 @@ struct legacy_pic {
17079 void (*init)(int auto_eoi);
17080 int (*irq_pending)(unsigned int irq);
17081 void (*make_irq)(unsigned int irq);
17082 -};
17083 +} __do_const;
17084
17085 extern struct legacy_pic *legacy_pic;
17086 extern struct legacy_pic null_legacy_pic;
17087 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17088 index b8237d8..3e8864e 100644
17089 --- a/arch/x86/include/asm/io.h
17090 +++ b/arch/x86/include/asm/io.h
17091 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17092 "m" (*(volatile type __force *)addr) barrier); }
17093
17094 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17095 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17096 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17097 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17098 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17099
17100 build_mmio_read(__readb, "b", unsigned char, "=q", )
17101 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17102 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17103 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17104 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17105
17106 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17107 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17108 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17109 * this function
17110 */
17111
17112 -static inline phys_addr_t virt_to_phys(volatile void *address)
17113 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17114 {
17115 return __pa(address);
17116 }
17117 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17118 return ioremap_nocache(offset, size);
17119 }
17120
17121 -extern void iounmap(volatile void __iomem *addr);
17122 +extern void iounmap(const volatile void __iomem *addr);
17123
17124 extern void set_iounmap_nonlazy(void);
17125
17126 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17127
17128 #include <linux/vmalloc.h>
17129
17130 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17131 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17132 +{
17133 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17134 +}
17135 +
17136 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17137 +{
17138 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17139 +}
17140 +
17141 /*
17142 * Convert a virtual cached pointer to an uncached pointer
17143 */
17144 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17145 index 0a8b519..80e7d5b 100644
17146 --- a/arch/x86/include/asm/irqflags.h
17147 +++ b/arch/x86/include/asm/irqflags.h
17148 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17149 sti; \
17150 sysexit
17151
17152 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17153 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17154 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17155 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17156 +
17157 #else
17158 #define INTERRUPT_RETURN iret
17159 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17160 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17161 index 4421b5d..8543006 100644
17162 --- a/arch/x86/include/asm/kprobes.h
17163 +++ b/arch/x86/include/asm/kprobes.h
17164 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17165 #define RELATIVEJUMP_SIZE 5
17166 #define RELATIVECALL_OPCODE 0xe8
17167 #define RELATIVE_ADDR_SIZE 4
17168 -#define MAX_STACK_SIZE 64
17169 -#define MIN_STACK_SIZE(ADDR) \
17170 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17171 - THREAD_SIZE - (unsigned long)(ADDR))) \
17172 - ? (MAX_STACK_SIZE) \
17173 - : (((unsigned long)current_thread_info()) + \
17174 - THREAD_SIZE - (unsigned long)(ADDR)))
17175 +#define MAX_STACK_SIZE 64UL
17176 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17177
17178 #define flush_insn_slot(p) do { } while (0)
17179
17180 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17181 index 6ed0c30..74fb6c3 100644
17182 --- a/arch/x86/include/asm/kvm_host.h
17183 +++ b/arch/x86/include/asm/kvm_host.h
17184 @@ -51,6 +51,7 @@
17185 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17186
17187 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17188 +#define CR3_PCID_INVD (1UL << 63)
17189 #define CR4_RESERVED_BITS \
17190 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17191 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17192 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17193 index 4ad6560..75c7bdd 100644
17194 --- a/arch/x86/include/asm/local.h
17195 +++ b/arch/x86/include/asm/local.h
17196 @@ -10,33 +10,97 @@ typedef struct {
17197 atomic_long_t a;
17198 } local_t;
17199
17200 +typedef struct {
17201 + atomic_long_unchecked_t a;
17202 +} local_unchecked_t;
17203 +
17204 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17205
17206 #define local_read(l) atomic_long_read(&(l)->a)
17207 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17208 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17209 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17210
17211 static inline void local_inc(local_t *l)
17212 {
17213 - asm volatile(_ASM_INC "%0"
17214 + asm volatile(_ASM_INC "%0\n"
17215 +
17216 +#ifdef CONFIG_PAX_REFCOUNT
17217 + "jno 0f\n"
17218 + _ASM_DEC "%0\n"
17219 + "int $4\n0:\n"
17220 + _ASM_EXTABLE(0b, 0b)
17221 +#endif
17222 +
17223 + : "+m" (l->a.counter));
17224 +}
17225 +
17226 +static inline void local_inc_unchecked(local_unchecked_t *l)
17227 +{
17228 + asm volatile(_ASM_INC "%0\n"
17229 : "+m" (l->a.counter));
17230 }
17231
17232 static inline void local_dec(local_t *l)
17233 {
17234 - asm volatile(_ASM_DEC "%0"
17235 + asm volatile(_ASM_DEC "%0\n"
17236 +
17237 +#ifdef CONFIG_PAX_REFCOUNT
17238 + "jno 0f\n"
17239 + _ASM_INC "%0\n"
17240 + "int $4\n0:\n"
17241 + _ASM_EXTABLE(0b, 0b)
17242 +#endif
17243 +
17244 + : "+m" (l->a.counter));
17245 +}
17246 +
17247 +static inline void local_dec_unchecked(local_unchecked_t *l)
17248 +{
17249 + asm volatile(_ASM_DEC "%0\n"
17250 : "+m" (l->a.counter));
17251 }
17252
17253 static inline void local_add(long i, local_t *l)
17254 {
17255 - asm volatile(_ASM_ADD "%1,%0"
17256 + asm volatile(_ASM_ADD "%1,%0\n"
17257 +
17258 +#ifdef CONFIG_PAX_REFCOUNT
17259 + "jno 0f\n"
17260 + _ASM_SUB "%1,%0\n"
17261 + "int $4\n0:\n"
17262 + _ASM_EXTABLE(0b, 0b)
17263 +#endif
17264 +
17265 + : "+m" (l->a.counter)
17266 + : "ir" (i));
17267 +}
17268 +
17269 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17270 +{
17271 + asm volatile(_ASM_ADD "%1,%0\n"
17272 : "+m" (l->a.counter)
17273 : "ir" (i));
17274 }
17275
17276 static inline void local_sub(long i, local_t *l)
17277 {
17278 - asm volatile(_ASM_SUB "%1,%0"
17279 + asm volatile(_ASM_SUB "%1,%0\n"
17280 +
17281 +#ifdef CONFIG_PAX_REFCOUNT
17282 + "jno 0f\n"
17283 + _ASM_ADD "%1,%0\n"
17284 + "int $4\n0:\n"
17285 + _ASM_EXTABLE(0b, 0b)
17286 +#endif
17287 +
17288 + : "+m" (l->a.counter)
17289 + : "ir" (i));
17290 +}
17291 +
17292 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17293 +{
17294 + asm volatile(_ASM_SUB "%1,%0\n"
17295 : "+m" (l->a.counter)
17296 : "ir" (i));
17297 }
17298 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17299 */
17300 static inline int local_sub_and_test(long i, local_t *l)
17301 {
17302 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17303 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17304 }
17305
17306 /**
17307 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17308 */
17309 static inline int local_dec_and_test(local_t *l)
17310 {
17311 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17312 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17313 }
17314
17315 /**
17316 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17317 */
17318 static inline int local_inc_and_test(local_t *l)
17319 {
17320 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17321 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17322 }
17323
17324 /**
17325 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17326 */
17327 static inline int local_add_negative(long i, local_t *l)
17328 {
17329 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17330 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17331 }
17332
17333 /**
17334 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17335 static inline long local_add_return(long i, local_t *l)
17336 {
17337 long __i = i;
17338 + asm volatile(_ASM_XADD "%0, %1\n"
17339 +
17340 +#ifdef CONFIG_PAX_REFCOUNT
17341 + "jno 0f\n"
17342 + _ASM_MOV "%0,%1\n"
17343 + "int $4\n0:\n"
17344 + _ASM_EXTABLE(0b, 0b)
17345 +#endif
17346 +
17347 + : "+r" (i), "+m" (l->a.counter)
17348 + : : "memory");
17349 + return i + __i;
17350 +}
17351 +
17352 +/**
17353 + * local_add_return_unchecked - add and return
17354 + * @i: integer value to add
17355 + * @l: pointer to type local_unchecked_t
17356 + *
17357 + * Atomically adds @i to @l and returns @i + @l
17358 + */
17359 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17360 +{
17361 + long __i = i;
17362 asm volatile(_ASM_XADD "%0, %1;"
17363 : "+r" (i), "+m" (l->a.counter)
17364 : : "memory");
17365 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17366
17367 #define local_cmpxchg(l, o, n) \
17368 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17369 +#define local_cmpxchg_unchecked(l, o, n) \
17370 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17371 /* Always has a lock prefix */
17372 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17373
17374 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17375 new file mode 100644
17376 index 0000000..2bfd3ba
17377 --- /dev/null
17378 +++ b/arch/x86/include/asm/mman.h
17379 @@ -0,0 +1,15 @@
17380 +#ifndef _X86_MMAN_H
17381 +#define _X86_MMAN_H
17382 +
17383 +#include <uapi/asm/mman.h>
17384 +
17385 +#ifdef __KERNEL__
17386 +#ifndef __ASSEMBLY__
17387 +#ifdef CONFIG_X86_32
17388 +#define arch_mmap_check i386_mmap_check
17389 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17390 +#endif
17391 +#endif
17392 +#endif
17393 +
17394 +#endif /* X86_MMAN_H */
17395 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17396 index 876e74e..e20bfb1 100644
17397 --- a/arch/x86/include/asm/mmu.h
17398 +++ b/arch/x86/include/asm/mmu.h
17399 @@ -9,7 +9,7 @@
17400 * we put the segment information here.
17401 */
17402 typedef struct {
17403 - void *ldt;
17404 + struct desc_struct *ldt;
17405 int size;
17406
17407 #ifdef CONFIG_X86_64
17408 @@ -18,7 +18,19 @@ typedef struct {
17409 #endif
17410
17411 struct mutex lock;
17412 - void __user *vdso;
17413 + unsigned long vdso;
17414 +
17415 +#ifdef CONFIG_X86_32
17416 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17417 + unsigned long user_cs_base;
17418 + unsigned long user_cs_limit;
17419 +
17420 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17421 + cpumask_t cpu_user_cs_mask;
17422 +#endif
17423 +
17424 +#endif
17425 +#endif
17426 } mm_context_t;
17427
17428 #ifdef CONFIG_SMP
17429 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17430 index 166af2a..648c200 100644
17431 --- a/arch/x86/include/asm/mmu_context.h
17432 +++ b/arch/x86/include/asm/mmu_context.h
17433 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17434
17435 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17436 {
17437 +
17438 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17439 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17440 + unsigned int i;
17441 + pgd_t *pgd;
17442 +
17443 + pax_open_kernel();
17444 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17445 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17446 + set_pgd_batched(pgd+i, native_make_pgd(0));
17447 + pax_close_kernel();
17448 + }
17449 +#endif
17450 +
17451 #ifdef CONFIG_SMP
17452 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17453 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17454 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17455 struct task_struct *tsk)
17456 {
17457 unsigned cpu = smp_processor_id();
17458 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17459 + int tlbstate = TLBSTATE_OK;
17460 +#endif
17461
17462 if (likely(prev != next)) {
17463 #ifdef CONFIG_SMP
17464 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17465 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17466 +#endif
17467 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17468 this_cpu_write(cpu_tlbstate.active_mm, next);
17469 #endif
17470 cpumask_set_cpu(cpu, mm_cpumask(next));
17471
17472 /* Re-load page tables */
17473 +#ifdef CONFIG_PAX_PER_CPU_PGD
17474 + pax_open_kernel();
17475 +
17476 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17477 + if (static_cpu_has(X86_FEATURE_PCID))
17478 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17479 + else
17480 +#endif
17481 +
17482 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17483 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17484 + pax_close_kernel();
17485 + 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));
17486 +
17487 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17488 + if (static_cpu_has(X86_FEATURE_PCID)) {
17489 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17490 + u64 descriptor[2];
17491 + descriptor[0] = PCID_USER;
17492 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17493 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17494 + descriptor[0] = PCID_KERNEL;
17495 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17496 + }
17497 + } else {
17498 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17499 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17500 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17501 + else
17502 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17503 + }
17504 + } else
17505 +#endif
17506 +
17507 + load_cr3(get_cpu_pgd(cpu, kernel));
17508 +#else
17509 load_cr3(next->pgd);
17510 +#endif
17511 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17512
17513 /* Stop flush ipis for the previous mm */
17514 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17515 /* Load the LDT, if the LDT is different: */
17516 if (unlikely(prev->context.ldt != next->context.ldt))
17517 load_LDT_nolock(&next->context);
17518 +
17519 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17520 + if (!(__supported_pte_mask & _PAGE_NX)) {
17521 + smp_mb__before_atomic();
17522 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17523 + smp_mb__after_atomic();
17524 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17525 + }
17526 +#endif
17527 +
17528 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17529 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17530 + prev->context.user_cs_limit != next->context.user_cs_limit))
17531 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17532 +#ifdef CONFIG_SMP
17533 + else if (unlikely(tlbstate != TLBSTATE_OK))
17534 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17535 +#endif
17536 +#endif
17537 +
17538 }
17539 + else {
17540 +
17541 +#ifdef CONFIG_PAX_PER_CPU_PGD
17542 + pax_open_kernel();
17543 +
17544 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17545 + if (static_cpu_has(X86_FEATURE_PCID))
17546 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17547 + else
17548 +#endif
17549 +
17550 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17551 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17552 + pax_close_kernel();
17553 + 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));
17554 +
17555 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17556 + if (static_cpu_has(X86_FEATURE_PCID)) {
17557 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17558 + u64 descriptor[2];
17559 + descriptor[0] = PCID_USER;
17560 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17561 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17562 + descriptor[0] = PCID_KERNEL;
17563 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17564 + }
17565 + } else {
17566 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17567 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17568 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17569 + else
17570 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17571 + }
17572 + } else
17573 +#endif
17574 +
17575 + load_cr3(get_cpu_pgd(cpu, kernel));
17576 +#endif
17577 +
17578 #ifdef CONFIG_SMP
17579 - else {
17580 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17581 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17582
17583 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17584 * tlb flush IPI delivery. We must reload CR3
17585 * to make sure to use no freed page tables.
17586 */
17587 +
17588 +#ifndef CONFIG_PAX_PER_CPU_PGD
17589 load_cr3(next->pgd);
17590 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17591 +#endif
17592 +
17593 load_LDT_nolock(&next->context);
17594 +
17595 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17596 + if (!(__supported_pte_mask & _PAGE_NX))
17597 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17598 +#endif
17599 +
17600 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17601 +#ifdef CONFIG_PAX_PAGEEXEC
17602 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17603 +#endif
17604 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17605 +#endif
17606 +
17607 }
17608 +#endif
17609 }
17610 -#endif
17611 }
17612
17613 #define activate_mm(prev, next) \
17614 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17615 index e3b7819..b257c64 100644
17616 --- a/arch/x86/include/asm/module.h
17617 +++ b/arch/x86/include/asm/module.h
17618 @@ -5,6 +5,7 @@
17619
17620 #ifdef CONFIG_X86_64
17621 /* X86_64 does not define MODULE_PROC_FAMILY */
17622 +#define MODULE_PROC_FAMILY ""
17623 #elif defined CONFIG_M486
17624 #define MODULE_PROC_FAMILY "486 "
17625 #elif defined CONFIG_M586
17626 @@ -57,8 +58,20 @@
17627 #error unknown processor family
17628 #endif
17629
17630 -#ifdef CONFIG_X86_32
17631 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17632 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17633 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17634 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17635 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17636 +#else
17637 +#define MODULE_PAX_KERNEXEC ""
17638 #endif
17639
17640 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17641 +#define MODULE_PAX_UDEREF "UDEREF "
17642 +#else
17643 +#define MODULE_PAX_UDEREF ""
17644 +#endif
17645 +
17646 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17647 +
17648 #endif /* _ASM_X86_MODULE_H */
17649 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17650 index 5f2fc44..106caa6 100644
17651 --- a/arch/x86/include/asm/nmi.h
17652 +++ b/arch/x86/include/asm/nmi.h
17653 @@ -36,26 +36,35 @@ enum {
17654
17655 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17656
17657 +struct nmiaction;
17658 +
17659 +struct nmiwork {
17660 + const struct nmiaction *action;
17661 + u64 max_duration;
17662 + struct irq_work irq_work;
17663 +};
17664 +
17665 struct nmiaction {
17666 struct list_head list;
17667 nmi_handler_t handler;
17668 - u64 max_duration;
17669 - struct irq_work irq_work;
17670 unsigned long flags;
17671 const char *name;
17672 -};
17673 + struct nmiwork *work;
17674 +} __do_const;
17675
17676 #define register_nmi_handler(t, fn, fg, n, init...) \
17677 ({ \
17678 - static struct nmiaction init fn##_na = { \
17679 + static struct nmiwork fn##_nw; \
17680 + static const struct nmiaction init fn##_na = { \
17681 .handler = (fn), \
17682 .name = (n), \
17683 .flags = (fg), \
17684 + .work = &fn##_nw, \
17685 }; \
17686 __register_nmi_handler((t), &fn##_na); \
17687 })
17688
17689 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17690 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17691
17692 void unregister_nmi_handler(unsigned int, const char *);
17693
17694 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17695 index 802dde3..9183e68 100644
17696 --- a/arch/x86/include/asm/page.h
17697 +++ b/arch/x86/include/asm/page.h
17698 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17699 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17700
17701 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17702 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17703
17704 #define __boot_va(x) __va(x)
17705 #define __boot_pa(x) __pa(x)
17706 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17707 * virt_to_page(kaddr) returns a valid pointer if and only if
17708 * virt_addr_valid(kaddr) returns true.
17709 */
17710 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17711 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17712 extern bool __virt_addr_valid(unsigned long kaddr);
17713 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17714
17715 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17716 +#define virt_to_page(kaddr) \
17717 + ({ \
17718 + const void *__kaddr = (const void *)(kaddr); \
17719 + BUG_ON(!virt_addr_valid(__kaddr)); \
17720 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17721 + })
17722 +#else
17723 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17724 +#endif
17725 +
17726 #endif /* __ASSEMBLY__ */
17727
17728 #include <asm-generic/memory_model.h>
17729 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17730 index f408caf..4a0455e 100644
17731 --- a/arch/x86/include/asm/page_64.h
17732 +++ b/arch/x86/include/asm/page_64.h
17733 @@ -7,9 +7,9 @@
17734
17735 /* duplicated to the one in bootmem.h */
17736 extern unsigned long max_pfn;
17737 -extern unsigned long phys_base;
17738 +extern const unsigned long phys_base;
17739
17740 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17741 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17742 {
17743 unsigned long y = x - __START_KERNEL_map;
17744
17745 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17746 index cd6e1610..70f4418 100644
17747 --- a/arch/x86/include/asm/paravirt.h
17748 +++ b/arch/x86/include/asm/paravirt.h
17749 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17750 return (pmd_t) { ret };
17751 }
17752
17753 -static inline pmdval_t pmd_val(pmd_t pmd)
17754 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17755 {
17756 pmdval_t ret;
17757
17758 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17759 val);
17760 }
17761
17762 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17763 +{
17764 + pgdval_t val = native_pgd_val(pgd);
17765 +
17766 + if (sizeof(pgdval_t) > sizeof(long))
17767 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17768 + val, (u64)val >> 32);
17769 + else
17770 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17771 + val);
17772 +}
17773 +
17774 static inline void pgd_clear(pgd_t *pgdp)
17775 {
17776 set_pgd(pgdp, __pgd(0));
17777 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17778 pv_mmu_ops.set_fixmap(idx, phys, flags);
17779 }
17780
17781 +#ifdef CONFIG_PAX_KERNEXEC
17782 +static inline unsigned long pax_open_kernel(void)
17783 +{
17784 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17785 +}
17786 +
17787 +static inline unsigned long pax_close_kernel(void)
17788 +{
17789 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17790 +}
17791 +#else
17792 +static inline unsigned long pax_open_kernel(void) { return 0; }
17793 +static inline unsigned long pax_close_kernel(void) { return 0; }
17794 +#endif
17795 +
17796 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17797
17798 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17799 @@ -906,7 +933,7 @@ extern void default_banner(void);
17800
17801 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17802 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17803 -#define PARA_INDIRECT(addr) *%cs:addr
17804 +#define PARA_INDIRECT(addr) *%ss:addr
17805 #endif
17806
17807 #define INTERRUPT_RETURN \
17808 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17809 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17810 CLBR_NONE, \
17811 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17812 +
17813 +#define GET_CR0_INTO_RDI \
17814 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17815 + mov %rax,%rdi
17816 +
17817 +#define SET_RDI_INTO_CR0 \
17818 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17819 +
17820 +#define GET_CR3_INTO_RDI \
17821 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17822 + mov %rax,%rdi
17823 +
17824 +#define SET_RDI_INTO_CR3 \
17825 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17826 +
17827 #endif /* CONFIG_X86_32 */
17828
17829 #endif /* __ASSEMBLY__ */
17830 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17831 index 7549b8b..f0edfda 100644
17832 --- a/arch/x86/include/asm/paravirt_types.h
17833 +++ b/arch/x86/include/asm/paravirt_types.h
17834 @@ -84,7 +84,7 @@ struct pv_init_ops {
17835 */
17836 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17837 unsigned long addr, unsigned len);
17838 -};
17839 +} __no_const __no_randomize_layout;
17840
17841
17842 struct pv_lazy_ops {
17843 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17844 void (*enter)(void);
17845 void (*leave)(void);
17846 void (*flush)(void);
17847 -};
17848 +} __no_randomize_layout;
17849
17850 struct pv_time_ops {
17851 unsigned long long (*sched_clock)(void);
17852 unsigned long long (*steal_clock)(int cpu);
17853 unsigned long (*get_tsc_khz)(void);
17854 -};
17855 +} __no_const __no_randomize_layout;
17856
17857 struct pv_cpu_ops {
17858 /* hooks for various privileged instructions */
17859 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17860
17861 void (*start_context_switch)(struct task_struct *prev);
17862 void (*end_context_switch)(struct task_struct *next);
17863 -};
17864 +} __no_const __no_randomize_layout;
17865
17866 struct pv_irq_ops {
17867 /*
17868 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17869 #ifdef CONFIG_X86_64
17870 void (*adjust_exception_frame)(void);
17871 #endif
17872 -};
17873 +} __no_randomize_layout;
17874
17875 struct pv_apic_ops {
17876 #ifdef CONFIG_X86_LOCAL_APIC
17877 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17878 unsigned long start_eip,
17879 unsigned long start_esp);
17880 #endif
17881 -};
17882 +} __no_const __no_randomize_layout;
17883
17884 struct pv_mmu_ops {
17885 unsigned long (*read_cr2)(void);
17886 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17887 struct paravirt_callee_save make_pud;
17888
17889 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17890 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17891 #endif /* PAGETABLE_LEVELS == 4 */
17892 #endif /* PAGETABLE_LEVELS >= 3 */
17893
17894 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17895 an mfn. We can tell which is which from the index. */
17896 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17897 phys_addr_t phys, pgprot_t flags);
17898 -};
17899 +
17900 +#ifdef CONFIG_PAX_KERNEXEC
17901 + unsigned long (*pax_open_kernel)(void);
17902 + unsigned long (*pax_close_kernel)(void);
17903 +#endif
17904 +
17905 +} __no_randomize_layout;
17906
17907 struct arch_spinlock;
17908 #ifdef CONFIG_SMP
17909 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17910 struct pv_lock_ops {
17911 struct paravirt_callee_save lock_spinning;
17912 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17913 -};
17914 +} __no_randomize_layout;
17915
17916 /* This contains all the paravirt structures: we get a convenient
17917 * number for each function using the offset which we use to indicate
17918 - * what to patch. */
17919 + * what to patch.
17920 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17921 + */
17922 +
17923 struct paravirt_patch_template {
17924 struct pv_init_ops pv_init_ops;
17925 struct pv_time_ops pv_time_ops;
17926 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17927 struct pv_apic_ops pv_apic_ops;
17928 struct pv_mmu_ops pv_mmu_ops;
17929 struct pv_lock_ops pv_lock_ops;
17930 -};
17931 +} __no_randomize_layout;
17932
17933 extern struct pv_info pv_info;
17934 extern struct pv_init_ops pv_init_ops;
17935 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17936 index c4412e9..90e88c5 100644
17937 --- a/arch/x86/include/asm/pgalloc.h
17938 +++ b/arch/x86/include/asm/pgalloc.h
17939 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17940 pmd_t *pmd, pte_t *pte)
17941 {
17942 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17943 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17944 +}
17945 +
17946 +static inline void pmd_populate_user(struct mm_struct *mm,
17947 + pmd_t *pmd, pte_t *pte)
17948 +{
17949 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17950 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17951 }
17952
17953 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17954
17955 #ifdef CONFIG_X86_PAE
17956 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17957 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17958 +{
17959 + pud_populate(mm, pudp, pmd);
17960 +}
17961 #else /* !CONFIG_X86_PAE */
17962 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17963 {
17964 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17965 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17966 }
17967 +
17968 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17969 +{
17970 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17971 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17972 +}
17973 #endif /* CONFIG_X86_PAE */
17974
17975 #if PAGETABLE_LEVELS > 3
17976 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17977 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17978 }
17979
17980 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17981 +{
17982 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17983 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17984 +}
17985 +
17986 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17987 {
17988 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17989 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17990 index 206a87f..1623b06 100644
17991 --- a/arch/x86/include/asm/pgtable-2level.h
17992 +++ b/arch/x86/include/asm/pgtable-2level.h
17993 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17994
17995 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17996 {
17997 + pax_open_kernel();
17998 *pmdp = pmd;
17999 + pax_close_kernel();
18000 }
18001
18002 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18003 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18004 index 81bb91b..9392125 100644
18005 --- a/arch/x86/include/asm/pgtable-3level.h
18006 +++ b/arch/x86/include/asm/pgtable-3level.h
18007 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18008
18009 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18010 {
18011 + pax_open_kernel();
18012 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18013 + pax_close_kernel();
18014 }
18015
18016 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18017 {
18018 + pax_open_kernel();
18019 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18020 + pax_close_kernel();
18021 }
18022
18023 /*
18024 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18025 index aa97a07..5c53c32 100644
18026 --- a/arch/x86/include/asm/pgtable.h
18027 +++ b/arch/x86/include/asm/pgtable.h
18028 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18029
18030 #ifndef __PAGETABLE_PUD_FOLDED
18031 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18032 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18033 #define pgd_clear(pgd) native_pgd_clear(pgd)
18034 #endif
18035
18036 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18037
18038 #define arch_end_context_switch(prev) do {} while(0)
18039
18040 +#define pax_open_kernel() native_pax_open_kernel()
18041 +#define pax_close_kernel() native_pax_close_kernel()
18042 #endif /* CONFIG_PARAVIRT */
18043
18044 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18045 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18046 +
18047 +#ifdef CONFIG_PAX_KERNEXEC
18048 +static inline unsigned long native_pax_open_kernel(void)
18049 +{
18050 + unsigned long cr0;
18051 +
18052 + preempt_disable();
18053 + barrier();
18054 + cr0 = read_cr0() ^ X86_CR0_WP;
18055 + BUG_ON(cr0 & X86_CR0_WP);
18056 + write_cr0(cr0);
18057 + barrier();
18058 + return cr0 ^ X86_CR0_WP;
18059 +}
18060 +
18061 +static inline unsigned long native_pax_close_kernel(void)
18062 +{
18063 + unsigned long cr0;
18064 +
18065 + barrier();
18066 + cr0 = read_cr0() ^ X86_CR0_WP;
18067 + BUG_ON(!(cr0 & X86_CR0_WP));
18068 + write_cr0(cr0);
18069 + barrier();
18070 + preempt_enable_no_resched();
18071 + return cr0 ^ X86_CR0_WP;
18072 +}
18073 +#else
18074 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18075 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18076 +#endif
18077 +
18078 /*
18079 * The following only work if pte_present() is true.
18080 * Undefined behaviour if not..
18081 */
18082 +static inline int pte_user(pte_t pte)
18083 +{
18084 + return pte_val(pte) & _PAGE_USER;
18085 +}
18086 +
18087 static inline int pte_dirty(pte_t pte)
18088 {
18089 return pte_flags(pte) & _PAGE_DIRTY;
18090 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18091 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18092 }
18093
18094 +static inline unsigned long pgd_pfn(pgd_t pgd)
18095 +{
18096 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18097 +}
18098 +
18099 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18100
18101 static inline int pmd_large(pmd_t pte)
18102 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18103 return pte_clear_flags(pte, _PAGE_RW);
18104 }
18105
18106 +static inline pte_t pte_mkread(pte_t pte)
18107 +{
18108 + return __pte(pte_val(pte) | _PAGE_USER);
18109 +}
18110 +
18111 static inline pte_t pte_mkexec(pte_t pte)
18112 {
18113 - return pte_clear_flags(pte, _PAGE_NX);
18114 +#ifdef CONFIG_X86_PAE
18115 + if (__supported_pte_mask & _PAGE_NX)
18116 + return pte_clear_flags(pte, _PAGE_NX);
18117 + else
18118 +#endif
18119 + return pte_set_flags(pte, _PAGE_USER);
18120 +}
18121 +
18122 +static inline pte_t pte_exprotect(pte_t pte)
18123 +{
18124 +#ifdef CONFIG_X86_PAE
18125 + if (__supported_pte_mask & _PAGE_NX)
18126 + return pte_set_flags(pte, _PAGE_NX);
18127 + else
18128 +#endif
18129 + return pte_clear_flags(pte, _PAGE_USER);
18130 }
18131
18132 static inline pte_t pte_mkdirty(pte_t pte)
18133 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18134 #endif
18135
18136 #ifndef __ASSEMBLY__
18137 +
18138 +#ifdef CONFIG_PAX_PER_CPU_PGD
18139 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18140 +enum cpu_pgd_type {kernel = 0, user = 1};
18141 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18142 +{
18143 + return cpu_pgd[cpu][type];
18144 +}
18145 +#endif
18146 +
18147 #include <linux/mm_types.h>
18148 #include <linux/mmdebug.h>
18149 #include <linux/log2.h>
18150 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18151 * Currently stuck as a macro due to indirect forward reference to
18152 * linux/mmzone.h's __section_mem_map_addr() definition:
18153 */
18154 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18155 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18156
18157 /* Find an entry in the second-level page table.. */
18158 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18159 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18160 * Currently stuck as a macro due to indirect forward reference to
18161 * linux/mmzone.h's __section_mem_map_addr() definition:
18162 */
18163 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18164 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18165
18166 /* to find an entry in a page-table-directory. */
18167 static inline unsigned long pud_index(unsigned long address)
18168 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18169
18170 static inline int pgd_bad(pgd_t pgd)
18171 {
18172 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18173 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18174 }
18175
18176 static inline int pgd_none(pgd_t pgd)
18177 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18178 * pgd_offset() returns a (pgd_t *)
18179 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18180 */
18181 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18182 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18183 +
18184 +#ifdef CONFIG_PAX_PER_CPU_PGD
18185 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18186 +#endif
18187 +
18188 /*
18189 * a shortcut which implies the use of the kernel's pgd, instead
18190 * of a process's
18191 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18192 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18193 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18194
18195 +#ifdef CONFIG_X86_32
18196 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18197 +#else
18198 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18199 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18200 +
18201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18202 +#ifdef __ASSEMBLY__
18203 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18204 +#else
18205 +extern unsigned long pax_user_shadow_base;
18206 +extern pgdval_t clone_pgd_mask;
18207 +#endif
18208 +#endif
18209 +
18210 +#endif
18211 +
18212 #ifndef __ASSEMBLY__
18213
18214 extern int direct_gbpages;
18215 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18216 * dst and src can be on the same page, but the range must not overlap,
18217 * and must not cross a page boundary.
18218 */
18219 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18220 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18221 {
18222 - memcpy(dst, src, count * sizeof(pgd_t));
18223 + pax_open_kernel();
18224 + while (count--)
18225 + *dst++ = *src++;
18226 + pax_close_kernel();
18227 }
18228
18229 +#ifdef CONFIG_PAX_PER_CPU_PGD
18230 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18231 +#endif
18232 +
18233 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18234 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18235 +#else
18236 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18237 +#endif
18238 +
18239 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18240 static inline int page_level_shift(enum pg_level level)
18241 {
18242 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18243 index b6c0b40..3535d47 100644
18244 --- a/arch/x86/include/asm/pgtable_32.h
18245 +++ b/arch/x86/include/asm/pgtable_32.h
18246 @@ -25,9 +25,6 @@
18247 struct mm_struct;
18248 struct vm_area_struct;
18249
18250 -extern pgd_t swapper_pg_dir[1024];
18251 -extern pgd_t initial_page_table[1024];
18252 -
18253 static inline void pgtable_cache_init(void) { }
18254 static inline void check_pgt_cache(void) { }
18255 void paging_init(void);
18256 @@ -45,6 +42,12 @@ void paging_init(void);
18257 # include <asm/pgtable-2level.h>
18258 #endif
18259
18260 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18261 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18262 +#ifdef CONFIG_X86_PAE
18263 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18264 +#endif
18265 +
18266 #if defined(CONFIG_HIGHPTE)
18267 #define pte_offset_map(dir, address) \
18268 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18269 @@ -59,12 +62,17 @@ void paging_init(void);
18270 /* Clear a kernel PTE and flush it from the TLB */
18271 #define kpte_clear_flush(ptep, vaddr) \
18272 do { \
18273 + pax_open_kernel(); \
18274 pte_clear(&init_mm, (vaddr), (ptep)); \
18275 + pax_close_kernel(); \
18276 __flush_tlb_one((vaddr)); \
18277 } while (0)
18278
18279 #endif /* !__ASSEMBLY__ */
18280
18281 +#define HAVE_ARCH_UNMAPPED_AREA
18282 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18283 +
18284 /*
18285 * kern_addr_valid() is (1) for FLATMEM and (0) for
18286 * SPARSEMEM and DISCONTIGMEM
18287 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18288 index ed5903b..c7fe163 100644
18289 --- a/arch/x86/include/asm/pgtable_32_types.h
18290 +++ b/arch/x86/include/asm/pgtable_32_types.h
18291 @@ -8,7 +8,7 @@
18292 */
18293 #ifdef CONFIG_X86_PAE
18294 # include <asm/pgtable-3level_types.h>
18295 -# define PMD_SIZE (1UL << PMD_SHIFT)
18296 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18297 # define PMD_MASK (~(PMD_SIZE - 1))
18298 #else
18299 # include <asm/pgtable-2level_types.h>
18300 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18301 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18302 #endif
18303
18304 +#ifdef CONFIG_PAX_KERNEXEC
18305 +#ifndef __ASSEMBLY__
18306 +extern unsigned char MODULES_EXEC_VADDR[];
18307 +extern unsigned char MODULES_EXEC_END[];
18308 +#endif
18309 +#include <asm/boot.h>
18310 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18311 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18312 +#else
18313 +#define ktla_ktva(addr) (addr)
18314 +#define ktva_ktla(addr) (addr)
18315 +#endif
18316 +
18317 #define MODULES_VADDR VMALLOC_START
18318 #define MODULES_END VMALLOC_END
18319 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18320 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18321 index 4572b2f..4430113 100644
18322 --- a/arch/x86/include/asm/pgtable_64.h
18323 +++ b/arch/x86/include/asm/pgtable_64.h
18324 @@ -16,11 +16,16 @@
18325
18326 extern pud_t level3_kernel_pgt[512];
18327 extern pud_t level3_ident_pgt[512];
18328 +extern pud_t level3_vmalloc_start_pgt[512];
18329 +extern pud_t level3_vmalloc_end_pgt[512];
18330 +extern pud_t level3_vmemmap_pgt[512];
18331 +extern pud_t level2_vmemmap_pgt[512];
18332 extern pmd_t level2_kernel_pgt[512];
18333 extern pmd_t level2_fixmap_pgt[512];
18334 -extern pmd_t level2_ident_pgt[512];
18335 +extern pmd_t level2_ident_pgt[512*2];
18336 extern pte_t level1_fixmap_pgt[512];
18337 -extern pgd_t init_level4_pgt[];
18338 +extern pte_t level1_vsyscall_pgt[512];
18339 +extern pgd_t init_level4_pgt[512];
18340
18341 #define swapper_pg_dir init_level4_pgt
18342
18343 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18344
18345 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18346 {
18347 + pax_open_kernel();
18348 *pmdp = pmd;
18349 + pax_close_kernel();
18350 }
18351
18352 static inline void native_pmd_clear(pmd_t *pmd)
18353 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18354
18355 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18356 {
18357 + pax_open_kernel();
18358 *pudp = pud;
18359 + pax_close_kernel();
18360 }
18361
18362 static inline void native_pud_clear(pud_t *pud)
18363 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18364
18365 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18366 {
18367 + pax_open_kernel();
18368 + *pgdp = pgd;
18369 + pax_close_kernel();
18370 +}
18371 +
18372 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18373 +{
18374 *pgdp = pgd;
18375 }
18376
18377 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18378 index 7166e25..baaa6fe 100644
18379 --- a/arch/x86/include/asm/pgtable_64_types.h
18380 +++ b/arch/x86/include/asm/pgtable_64_types.h
18381 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18382 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18383 #define MODULES_END _AC(0xffffffffff000000, UL)
18384 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18385 +#define MODULES_EXEC_VADDR MODULES_VADDR
18386 +#define MODULES_EXEC_END MODULES_END
18387 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18388 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18389
18390 +#define ktla_ktva(addr) (addr)
18391 +#define ktva_ktla(addr) (addr)
18392 +
18393 #define EARLY_DYNAMIC_PAGE_TABLES 64
18394
18395 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18396 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18397 index 0778964..0e94758 100644
18398 --- a/arch/x86/include/asm/pgtable_types.h
18399 +++ b/arch/x86/include/asm/pgtable_types.h
18400 @@ -110,8 +110,10 @@
18401
18402 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18403 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18404 -#else
18405 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18406 #define _PAGE_NX (_AT(pteval_t, 0))
18407 +#else
18408 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18409 #endif
18410
18411 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18412 @@ -150,6 +152,9 @@
18413 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18414 _PAGE_ACCESSED)
18415
18416 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18417 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18418 +
18419 #define __PAGE_KERNEL_EXEC \
18420 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18421 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18422 @@ -160,7 +165,7 @@
18423 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18424 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18425 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18426 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18427 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18428 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18429 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18430 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18431 @@ -217,7 +222,7 @@
18432 #ifdef CONFIG_X86_64
18433 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18434 #else
18435 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18436 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18437 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18438 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18439 #endif
18440 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18441 {
18442 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18443 }
18444 +#endif
18445
18446 +#if PAGETABLE_LEVELS == 3
18447 +#include <asm-generic/pgtable-nopud.h>
18448 +#endif
18449 +
18450 +#if PAGETABLE_LEVELS == 2
18451 +#include <asm-generic/pgtable-nopmd.h>
18452 +#endif
18453 +
18454 +#ifndef __ASSEMBLY__
18455 #if PAGETABLE_LEVELS > 3
18456 typedef struct { pudval_t pud; } pud_t;
18457
18458 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18459 return pud.pud;
18460 }
18461 #else
18462 -#include <asm-generic/pgtable-nopud.h>
18463 -
18464 static inline pudval_t native_pud_val(pud_t pud)
18465 {
18466 return native_pgd_val(pud.pgd);
18467 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18468 return pmd.pmd;
18469 }
18470 #else
18471 -#include <asm-generic/pgtable-nopmd.h>
18472 -
18473 static inline pmdval_t native_pmd_val(pmd_t pmd)
18474 {
18475 return native_pgd_val(pmd.pud.pgd);
18476 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18477
18478 extern pteval_t __supported_pte_mask;
18479 extern void set_nx(void);
18480 -extern int nx_enabled;
18481
18482 #define pgprot_writecombine pgprot_writecombine
18483 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18484 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18485 index 4008734..48f0d81 100644
18486 --- a/arch/x86/include/asm/preempt.h
18487 +++ b/arch/x86/include/asm/preempt.h
18488 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18489 */
18490 static __always_inline bool __preempt_count_dec_and_test(void)
18491 {
18492 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18493 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18494 }
18495
18496 /*
18497 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18498 index eb71ec7..f06532a 100644
18499 --- a/arch/x86/include/asm/processor.h
18500 +++ b/arch/x86/include/asm/processor.h
18501 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18502 /* Index into per_cpu list: */
18503 u16 cpu_index;
18504 u32 microcode;
18505 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18506 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18507
18508 #define X86_VENDOR_INTEL 0
18509 #define X86_VENDOR_CYRIX 1
18510 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18511 : "memory");
18512 }
18513
18514 +/* invpcid (%rdx),%rax */
18515 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18516 +
18517 +#define INVPCID_SINGLE_ADDRESS 0UL
18518 +#define INVPCID_SINGLE_CONTEXT 1UL
18519 +#define INVPCID_ALL_GLOBAL 2UL
18520 +#define INVPCID_ALL_NONGLOBAL 3UL
18521 +
18522 +#define PCID_KERNEL 0UL
18523 +#define PCID_USER 1UL
18524 +#define PCID_NOFLUSH (1UL << 63)
18525 +
18526 static inline void load_cr3(pgd_t *pgdir)
18527 {
18528 - write_cr3(__pa(pgdir));
18529 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18530 }
18531
18532 #ifdef CONFIG_X86_32
18533 @@ -282,7 +294,7 @@ struct tss_struct {
18534
18535 } ____cacheline_aligned;
18536
18537 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18538 +extern struct tss_struct init_tss[NR_CPUS];
18539
18540 /*
18541 * Save the original ist values for checking stack pointers during debugging
18542 @@ -478,6 +490,7 @@ struct thread_struct {
18543 unsigned short ds;
18544 unsigned short fsindex;
18545 unsigned short gsindex;
18546 + unsigned short ss;
18547 #endif
18548 #ifdef CONFIG_X86_32
18549 unsigned long ip;
18550 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18551 extern unsigned long mmu_cr4_features;
18552 extern u32 *trampoline_cr4_features;
18553
18554 -static inline void set_in_cr4(unsigned long mask)
18555 -{
18556 - unsigned long cr4;
18557 -
18558 - mmu_cr4_features |= mask;
18559 - if (trampoline_cr4_features)
18560 - *trampoline_cr4_features = mmu_cr4_features;
18561 - cr4 = read_cr4();
18562 - cr4 |= mask;
18563 - write_cr4(cr4);
18564 -}
18565 -
18566 -static inline void clear_in_cr4(unsigned long mask)
18567 -{
18568 - unsigned long cr4;
18569 -
18570 - mmu_cr4_features &= ~mask;
18571 - if (trampoline_cr4_features)
18572 - *trampoline_cr4_features = mmu_cr4_features;
18573 - cr4 = read_cr4();
18574 - cr4 &= ~mask;
18575 - write_cr4(cr4);
18576 -}
18577 +extern void set_in_cr4(unsigned long mask);
18578 +extern void clear_in_cr4(unsigned long mask);
18579
18580 typedef struct {
18581 unsigned long seg;
18582 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18583 */
18584 #define TASK_SIZE PAGE_OFFSET
18585 #define TASK_SIZE_MAX TASK_SIZE
18586 +
18587 +#ifdef CONFIG_PAX_SEGMEXEC
18588 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18589 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18590 +#else
18591 #define STACK_TOP TASK_SIZE
18592 -#define STACK_TOP_MAX STACK_TOP
18593 +#endif
18594 +
18595 +#define STACK_TOP_MAX TASK_SIZE
18596
18597 #define INIT_THREAD { \
18598 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18599 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18600 .vm86_info = NULL, \
18601 .sysenter_cs = __KERNEL_CS, \
18602 .io_bitmap_ptr = NULL, \
18603 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18604 */
18605 #define INIT_TSS { \
18606 .x86_tss = { \
18607 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18608 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18609 .ss0 = __KERNEL_DS, \
18610 .ss1 = __KERNEL_CS, \
18611 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18612 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18613 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18614
18615 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18616 -#define KSTK_TOP(info) \
18617 -({ \
18618 - unsigned long *__ptr = (unsigned long *)(info); \
18619 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18620 -})
18621 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18622
18623 /*
18624 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18625 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18626 #define task_pt_regs(task) \
18627 ({ \
18628 struct pt_regs *__regs__; \
18629 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18630 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18631 __regs__ - 1; \
18632 })
18633
18634 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18635 /*
18636 * User space process size. 47bits minus one guard page.
18637 */
18638 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18639 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18640
18641 /* This decides where the kernel will search for a free chunk of vm
18642 * space during mmap's.
18643 */
18644 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18645 - 0xc0000000 : 0xFFFFe000)
18646 + 0xc0000000 : 0xFFFFf000)
18647
18648 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18649 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18650 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18651 #define STACK_TOP_MAX TASK_SIZE_MAX
18652
18653 #define INIT_THREAD { \
18654 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18655 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18656 }
18657
18658 #define INIT_TSS { \
18659 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18660 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18661 }
18662
18663 /*
18664 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18665 */
18666 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18667
18668 +#ifdef CONFIG_PAX_SEGMEXEC
18669 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18670 +#endif
18671 +
18672 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18673
18674 /* Get/set a process' ability to use the timestamp counter instruction */
18675 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18676 return 0;
18677 }
18678
18679 -extern unsigned long arch_align_stack(unsigned long sp);
18680 +#define arch_align_stack(x) ((x) & ~0xfUL)
18681 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18682
18683 void default_idle(void);
18684 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18685 #define xen_set_default_idle 0
18686 #endif
18687
18688 -void stop_this_cpu(void *dummy);
18689 +void stop_this_cpu(void *dummy) __noreturn;
18690 void df_debug(struct pt_regs *regs, long error_code);
18691 #endif /* _ASM_X86_PROCESSOR_H */
18692 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18693 index 86fc2bb..bd5049a 100644
18694 --- a/arch/x86/include/asm/ptrace.h
18695 +++ b/arch/x86/include/asm/ptrace.h
18696 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18697 }
18698
18699 /*
18700 - * user_mode_vm(regs) determines whether a register set came from user mode.
18701 + * user_mode(regs) determines whether a register set came from user mode.
18702 * This is true if V8086 mode was enabled OR if the register set was from
18703 * protected mode with RPL-3 CS value. This tricky test checks that with
18704 * one comparison. Many places in the kernel can bypass this full check
18705 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18706 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18707 + * be used.
18708 */
18709 -static inline int user_mode(struct pt_regs *regs)
18710 +static inline int user_mode_novm(struct pt_regs *regs)
18711 {
18712 #ifdef CONFIG_X86_32
18713 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18714 #else
18715 - return !!(regs->cs & 3);
18716 + return !!(regs->cs & SEGMENT_RPL_MASK);
18717 #endif
18718 }
18719
18720 -static inline int user_mode_vm(struct pt_regs *regs)
18721 +static inline int user_mode(struct pt_regs *regs)
18722 {
18723 #ifdef CONFIG_X86_32
18724 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18725 USER_RPL;
18726 #else
18727 - return user_mode(regs);
18728 + return user_mode_novm(regs);
18729 #endif
18730 }
18731
18732 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18733 #ifdef CONFIG_X86_64
18734 static inline bool user_64bit_mode(struct pt_regs *regs)
18735 {
18736 + unsigned long cs = regs->cs & 0xffff;
18737 #ifndef CONFIG_PARAVIRT
18738 /*
18739 * On non-paravirt systems, this is the only long mode CPL 3
18740 * selector. We do not allow long mode selectors in the LDT.
18741 */
18742 - return regs->cs == __USER_CS;
18743 + return cs == __USER_CS;
18744 #else
18745 /* Headers are too twisted for this to go in paravirt.h. */
18746 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18747 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18748 #endif
18749 }
18750
18751 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18752 * Traps from the kernel do not save sp and ss.
18753 * Use the helper function to retrieve sp.
18754 */
18755 - if (offset == offsetof(struct pt_regs, sp) &&
18756 - regs->cs == __KERNEL_CS)
18757 - return kernel_stack_pointer(regs);
18758 + if (offset == offsetof(struct pt_regs, sp)) {
18759 + unsigned long cs = regs->cs & 0xffff;
18760 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18761 + return kernel_stack_pointer(regs);
18762 + }
18763 #endif
18764 return *(unsigned long *)((unsigned long)regs + offset);
18765 }
18766 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18767 index ae0e241..e80b10b 100644
18768 --- a/arch/x86/include/asm/qrwlock.h
18769 +++ b/arch/x86/include/asm/qrwlock.h
18770 @@ -7,8 +7,8 @@
18771 #define queue_write_unlock queue_write_unlock
18772 static inline void queue_write_unlock(struct qrwlock *lock)
18773 {
18774 - barrier();
18775 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18776 + barrier();
18777 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18778 }
18779 #endif
18780
18781 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18782 index 9c6b890..5305f53 100644
18783 --- a/arch/x86/include/asm/realmode.h
18784 +++ b/arch/x86/include/asm/realmode.h
18785 @@ -22,16 +22,14 @@ struct real_mode_header {
18786 #endif
18787 /* APM/BIOS reboot */
18788 u32 machine_real_restart_asm;
18789 -#ifdef CONFIG_X86_64
18790 u32 machine_real_restart_seg;
18791 -#endif
18792 };
18793
18794 /* This must match data at trampoline_32/64.S */
18795 struct trampoline_header {
18796 #ifdef CONFIG_X86_32
18797 u32 start;
18798 - u16 gdt_pad;
18799 + u16 boot_cs;
18800 u16 gdt_limit;
18801 u32 gdt_base;
18802 #else
18803 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18804 index a82c4f1..ac45053 100644
18805 --- a/arch/x86/include/asm/reboot.h
18806 +++ b/arch/x86/include/asm/reboot.h
18807 @@ -6,13 +6,13 @@
18808 struct pt_regs;
18809
18810 struct machine_ops {
18811 - void (*restart)(char *cmd);
18812 - void (*halt)(void);
18813 - void (*power_off)(void);
18814 + void (* __noreturn restart)(char *cmd);
18815 + void (* __noreturn halt)(void);
18816 + void (* __noreturn power_off)(void);
18817 void (*shutdown)(void);
18818 void (*crash_shutdown)(struct pt_regs *);
18819 - void (*emergency_restart)(void);
18820 -};
18821 + void (* __noreturn emergency_restart)(void);
18822 +} __no_const;
18823
18824 extern struct machine_ops machine_ops;
18825
18826 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18827 index 8f7866a..e442f20 100644
18828 --- a/arch/x86/include/asm/rmwcc.h
18829 +++ b/arch/x86/include/asm/rmwcc.h
18830 @@ -3,7 +3,34 @@
18831
18832 #ifdef CC_HAVE_ASM_GOTO
18833
18834 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18835 +#ifdef CONFIG_PAX_REFCOUNT
18836 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18837 +do { \
18838 + asm_volatile_goto (fullop \
18839 + ";jno 0f\n" \
18840 + fullantiop \
18841 + ";int $4\n0:\n" \
18842 + _ASM_EXTABLE(0b, 0b) \
18843 + ";j" cc " %l[cc_label]" \
18844 + : : "m" (var), ## __VA_ARGS__ \
18845 + : "memory" : cc_label); \
18846 + return 0; \
18847 +cc_label: \
18848 + return 1; \
18849 +} while (0)
18850 +#else
18851 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18852 +do { \
18853 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18854 + : : "m" (var), ## __VA_ARGS__ \
18855 + : "memory" : cc_label); \
18856 + return 0; \
18857 +cc_label: \
18858 + return 1; \
18859 +} while (0)
18860 +#endif
18861 +
18862 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18863 do { \
18864 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18865 : : "m" (var), ## __VA_ARGS__ \
18866 @@ -13,15 +40,46 @@ cc_label: \
18867 return 1; \
18868 } while (0)
18869
18870 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18871 - __GEN_RMWcc(op " " arg0, var, cc)
18872 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18873 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18874
18875 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18876 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18877 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18878 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18879 +
18880 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18881 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18882 +
18883 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18884 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18885
18886 #else /* !CC_HAVE_ASM_GOTO */
18887
18888 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18889 +#ifdef CONFIG_PAX_REFCOUNT
18890 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18891 +do { \
18892 + char c; \
18893 + asm volatile (fullop \
18894 + ";jno 0f\n" \
18895 + fullantiop \
18896 + ";int $4\n0:\n" \
18897 + _ASM_EXTABLE(0b, 0b) \
18898 + "; set" cc " %1" \
18899 + : "+m" (var), "=qm" (c) \
18900 + : __VA_ARGS__ : "memory"); \
18901 + return c != 0; \
18902 +} while (0)
18903 +#else
18904 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18905 +do { \
18906 + char c; \
18907 + asm volatile (fullop "; set" cc " %1" \
18908 + : "+m" (var), "=qm" (c) \
18909 + : __VA_ARGS__ : "memory"); \
18910 + return c != 0; \
18911 +} while (0)
18912 +#endif
18913 +
18914 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18915 do { \
18916 char c; \
18917 asm volatile (fullop "; set" cc " %1" \
18918 @@ -30,11 +88,17 @@ do { \
18919 return c != 0; \
18920 } while (0)
18921
18922 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18923 - __GEN_RMWcc(op " " arg0, var, cc)
18924 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18925 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18926 +
18927 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18928 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18929 +
18930 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18931 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18932
18933 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18934 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18935 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18936 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18937
18938 #endif /* CC_HAVE_ASM_GOTO */
18939
18940 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18941 index cad82c9..2e5c5c1 100644
18942 --- a/arch/x86/include/asm/rwsem.h
18943 +++ b/arch/x86/include/asm/rwsem.h
18944 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18945 {
18946 asm volatile("# beginning down_read\n\t"
18947 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18948 +
18949 +#ifdef CONFIG_PAX_REFCOUNT
18950 + "jno 0f\n"
18951 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18952 + "int $4\n0:\n"
18953 + _ASM_EXTABLE(0b, 0b)
18954 +#endif
18955 +
18956 /* adds 0x00000001 */
18957 " jns 1f\n"
18958 " call call_rwsem_down_read_failed\n"
18959 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18960 "1:\n\t"
18961 " mov %1,%2\n\t"
18962 " add %3,%2\n\t"
18963 +
18964 +#ifdef CONFIG_PAX_REFCOUNT
18965 + "jno 0f\n"
18966 + "sub %3,%2\n"
18967 + "int $4\n0:\n"
18968 + _ASM_EXTABLE(0b, 0b)
18969 +#endif
18970 +
18971 " jle 2f\n\t"
18972 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18973 " jnz 1b\n\t"
18974 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18975 long tmp;
18976 asm volatile("# beginning down_write\n\t"
18977 LOCK_PREFIX " xadd %1,(%2)\n\t"
18978 +
18979 +#ifdef CONFIG_PAX_REFCOUNT
18980 + "jno 0f\n"
18981 + "mov %1,(%2)\n"
18982 + "int $4\n0:\n"
18983 + _ASM_EXTABLE(0b, 0b)
18984 +#endif
18985 +
18986 /* adds 0xffff0001, returns the old value */
18987 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18988 /* was the active mask 0 before? */
18989 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18990 long tmp;
18991 asm volatile("# beginning __up_read\n\t"
18992 LOCK_PREFIX " xadd %1,(%2)\n\t"
18993 +
18994 +#ifdef CONFIG_PAX_REFCOUNT
18995 + "jno 0f\n"
18996 + "mov %1,(%2)\n"
18997 + "int $4\n0:\n"
18998 + _ASM_EXTABLE(0b, 0b)
18999 +#endif
19000 +
19001 /* subtracts 1, returns the old value */
19002 " jns 1f\n\t"
19003 " call call_rwsem_wake\n" /* expects old value in %edx */
19004 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19005 long tmp;
19006 asm volatile("# beginning __up_write\n\t"
19007 LOCK_PREFIX " xadd %1,(%2)\n\t"
19008 +
19009 +#ifdef CONFIG_PAX_REFCOUNT
19010 + "jno 0f\n"
19011 + "mov %1,(%2)\n"
19012 + "int $4\n0:\n"
19013 + _ASM_EXTABLE(0b, 0b)
19014 +#endif
19015 +
19016 /* subtracts 0xffff0001, returns the old value */
19017 " jns 1f\n\t"
19018 " call call_rwsem_wake\n" /* expects old value in %edx */
19019 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19020 {
19021 asm volatile("# beginning __downgrade_write\n\t"
19022 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19023 +
19024 +#ifdef CONFIG_PAX_REFCOUNT
19025 + "jno 0f\n"
19026 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19027 + "int $4\n0:\n"
19028 + _ASM_EXTABLE(0b, 0b)
19029 +#endif
19030 +
19031 /*
19032 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19033 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19034 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19035 */
19036 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19037 {
19038 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19039 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19040 +
19041 +#ifdef CONFIG_PAX_REFCOUNT
19042 + "jno 0f\n"
19043 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19044 + "int $4\n0:\n"
19045 + _ASM_EXTABLE(0b, 0b)
19046 +#endif
19047 +
19048 : "+m" (sem->count)
19049 : "er" (delta));
19050 }
19051 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19052 */
19053 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19054 {
19055 - return delta + xadd(&sem->count, delta);
19056 + return delta + xadd_check_overflow(&sem->count, delta);
19057 }
19058
19059 #endif /* __KERNEL__ */
19060 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19061 index 6f1c3a8..7744f19 100644
19062 --- a/arch/x86/include/asm/segment.h
19063 +++ b/arch/x86/include/asm/segment.h
19064 @@ -64,10 +64,15 @@
19065 * 26 - ESPFIX small SS
19066 * 27 - per-cpu [ offset to per-cpu data area ]
19067 * 28 - stack_canary-20 [ for stack protector ]
19068 - * 29 - unused
19069 - * 30 - unused
19070 + * 29 - PCI BIOS CS
19071 + * 30 - PCI BIOS DS
19072 * 31 - TSS for double fault handler
19073 */
19074 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19075 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19076 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19077 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19078 +
19079 #define GDT_ENTRY_TLS_MIN 6
19080 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19081
19082 @@ -79,6 +84,8 @@
19083
19084 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19085
19086 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19087 +
19088 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19089
19090 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19091 @@ -104,6 +111,12 @@
19092 #define __KERNEL_STACK_CANARY 0
19093 #endif
19094
19095 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19096 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19097 +
19098 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19099 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19100 +
19101 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19102
19103 /*
19104 @@ -141,7 +154,7 @@
19105 */
19106
19107 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19108 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19109 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19110
19111
19112 #else
19113 @@ -165,6 +178,8 @@
19114 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19115 #define __USER32_DS __USER_DS
19116
19117 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19118 +
19119 #define GDT_ENTRY_TSS 8 /* needs two entries */
19120 #define GDT_ENTRY_LDT 10 /* needs two entries */
19121 #define GDT_ENTRY_TLS_MIN 12
19122 @@ -173,6 +188,8 @@
19123 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19124 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19125
19126 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19127 +
19128 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19129 #define FS_TLS 0
19130 #define GS_TLS 1
19131 @@ -180,12 +197,14 @@
19132 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19133 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19134
19135 -#define GDT_ENTRIES 16
19136 +#define GDT_ENTRIES 17
19137
19138 #endif
19139
19140 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19141 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19142 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19143 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19144 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19145 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19146 #ifndef CONFIG_PARAVIRT
19147 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19148 {
19149 unsigned long __limit;
19150 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19151 - return __limit + 1;
19152 + return __limit;
19153 }
19154
19155 #endif /* !__ASSEMBLY__ */
19156 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19157 index 8d3120f..352b440 100644
19158 --- a/arch/x86/include/asm/smap.h
19159 +++ b/arch/x86/include/asm/smap.h
19160 @@ -25,11 +25,40 @@
19161
19162 #include <asm/alternative-asm.h>
19163
19164 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19165 +#define ASM_PAX_OPEN_USERLAND \
19166 + 661: jmp 663f; \
19167 + .pushsection .altinstr_replacement, "a" ; \
19168 + 662: pushq %rax; nop; \
19169 + .popsection ; \
19170 + .pushsection .altinstructions, "a" ; \
19171 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19172 + .popsection ; \
19173 + call __pax_open_userland; \
19174 + popq %rax; \
19175 + 663:
19176 +
19177 +#define ASM_PAX_CLOSE_USERLAND \
19178 + 661: jmp 663f; \
19179 + .pushsection .altinstr_replacement, "a" ; \
19180 + 662: pushq %rax; nop; \
19181 + .popsection; \
19182 + .pushsection .altinstructions, "a" ; \
19183 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19184 + .popsection; \
19185 + call __pax_close_userland; \
19186 + popq %rax; \
19187 + 663:
19188 +#else
19189 +#define ASM_PAX_OPEN_USERLAND
19190 +#define ASM_PAX_CLOSE_USERLAND
19191 +#endif
19192 +
19193 #ifdef CONFIG_X86_SMAP
19194
19195 #define ASM_CLAC \
19196 661: ASM_NOP3 ; \
19197 - .pushsection .altinstr_replacement, "ax" ; \
19198 + .pushsection .altinstr_replacement, "a" ; \
19199 662: __ASM_CLAC ; \
19200 .popsection ; \
19201 .pushsection .altinstructions, "a" ; \
19202 @@ -38,7 +67,7 @@
19203
19204 #define ASM_STAC \
19205 661: ASM_NOP3 ; \
19206 - .pushsection .altinstr_replacement, "ax" ; \
19207 + .pushsection .altinstr_replacement, "a" ; \
19208 662: __ASM_STAC ; \
19209 .popsection ; \
19210 .pushsection .altinstructions, "a" ; \
19211 @@ -56,6 +85,37 @@
19212
19213 #include <asm/alternative.h>
19214
19215 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19216 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19217 +
19218 +extern void __pax_open_userland(void);
19219 +static __always_inline unsigned long pax_open_userland(void)
19220 +{
19221 +
19222 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19223 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19224 + :
19225 + : [open] "i" (__pax_open_userland)
19226 + : "memory", "rax");
19227 +#endif
19228 +
19229 + return 0;
19230 +}
19231 +
19232 +extern void __pax_close_userland(void);
19233 +static __always_inline unsigned long pax_close_userland(void)
19234 +{
19235 +
19236 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19237 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19238 + :
19239 + : [close] "i" (__pax_close_userland)
19240 + : "memory", "rax");
19241 +#endif
19242 +
19243 + return 0;
19244 +}
19245 +
19246 #ifdef CONFIG_X86_SMAP
19247
19248 static __always_inline void clac(void)
19249 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19250 index 8cd1cc3..827e09e 100644
19251 --- a/arch/x86/include/asm/smp.h
19252 +++ b/arch/x86/include/asm/smp.h
19253 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19254 /* cpus sharing the last level cache: */
19255 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19256 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19257 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19258 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19259
19260 static inline struct cpumask *cpu_sibling_mask(int cpu)
19261 {
19262 @@ -78,7 +78,7 @@ struct smp_ops {
19263
19264 void (*send_call_func_ipi)(const struct cpumask *mask);
19265 void (*send_call_func_single_ipi)(int cpu);
19266 -};
19267 +} __no_const;
19268
19269 /* Globals due to paravirt */
19270 extern void set_cpu_sibling_map(int cpu);
19271 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19272 extern int safe_smp_processor_id(void);
19273
19274 #elif defined(CONFIG_X86_64_SMP)
19275 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19276 -
19277 -#define stack_smp_processor_id() \
19278 -({ \
19279 - struct thread_info *ti; \
19280 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19281 - ti->cpu; \
19282 -})
19283 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19284 +#define stack_smp_processor_id() raw_smp_processor_id()
19285 #define safe_smp_processor_id() smp_processor_id()
19286
19287 #endif
19288 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19289 index 6a99859..03cb807 100644
19290 --- a/arch/x86/include/asm/stackprotector.h
19291 +++ b/arch/x86/include/asm/stackprotector.h
19292 @@ -47,7 +47,7 @@
19293 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19294 */
19295 #define GDT_STACK_CANARY_INIT \
19296 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19297 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19298
19299 /*
19300 * Initialize the stackprotector canary value.
19301 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19302
19303 static inline void load_stack_canary_segment(void)
19304 {
19305 -#ifdef CONFIG_X86_32
19306 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19307 asm volatile ("mov %0, %%gs" : : "r" (0));
19308 #endif
19309 }
19310 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19311 index 70bbe39..4ae2bd4 100644
19312 --- a/arch/x86/include/asm/stacktrace.h
19313 +++ b/arch/x86/include/asm/stacktrace.h
19314 @@ -11,28 +11,20 @@
19315
19316 extern int kstack_depth_to_print;
19317
19318 -struct thread_info;
19319 +struct task_struct;
19320 struct stacktrace_ops;
19321
19322 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19323 - unsigned long *stack,
19324 - unsigned long bp,
19325 - const struct stacktrace_ops *ops,
19326 - void *data,
19327 - unsigned long *end,
19328 - int *graph);
19329 +typedef unsigned long walk_stack_t(struct task_struct *task,
19330 + void *stack_start,
19331 + unsigned long *stack,
19332 + unsigned long bp,
19333 + const struct stacktrace_ops *ops,
19334 + void *data,
19335 + unsigned long *end,
19336 + int *graph);
19337
19338 -extern unsigned long
19339 -print_context_stack(struct thread_info *tinfo,
19340 - unsigned long *stack, unsigned long bp,
19341 - const struct stacktrace_ops *ops, void *data,
19342 - unsigned long *end, int *graph);
19343 -
19344 -extern unsigned long
19345 -print_context_stack_bp(struct thread_info *tinfo,
19346 - unsigned long *stack, unsigned long bp,
19347 - const struct stacktrace_ops *ops, void *data,
19348 - unsigned long *end, int *graph);
19349 +extern walk_stack_t print_context_stack;
19350 +extern walk_stack_t print_context_stack_bp;
19351
19352 /* Generic stack tracer with callbacks */
19353
19354 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19355 void (*address)(void *data, unsigned long address, int reliable);
19356 /* On negative return stop dumping */
19357 int (*stack)(void *data, char *name);
19358 - walk_stack_t walk_stack;
19359 + walk_stack_t *walk_stack;
19360 };
19361
19362 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19363 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19364 index d7f3b3b..3cc39f1 100644
19365 --- a/arch/x86/include/asm/switch_to.h
19366 +++ b/arch/x86/include/asm/switch_to.h
19367 @@ -108,7 +108,7 @@ do { \
19368 "call __switch_to\n\t" \
19369 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19370 __switch_canary \
19371 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19372 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19373 "movq %%rax,%%rdi\n\t" \
19374 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19375 "jnz ret_from_fork\n\t" \
19376 @@ -119,7 +119,7 @@ do { \
19377 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19378 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19379 [_tif_fork] "i" (_TIF_FORK), \
19380 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19381 + [thread_info] "m" (current_tinfo), \
19382 [current_task] "m" (current_task) \
19383 __switch_canary_iparam \
19384 : "memory", "cc" __EXTRA_CLOBBER)
19385 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19386 index 547e344..6be1175 100644
19387 --- a/arch/x86/include/asm/thread_info.h
19388 +++ b/arch/x86/include/asm/thread_info.h
19389 @@ -24,7 +24,6 @@ struct exec_domain;
19390 #include <linux/atomic.h>
19391
19392 struct thread_info {
19393 - struct task_struct *task; /* main task structure */
19394 struct exec_domain *exec_domain; /* execution domain */
19395 __u32 flags; /* low level flags */
19396 __u32 status; /* thread synchronous flags */
19397 @@ -33,13 +32,13 @@ struct thread_info {
19398 mm_segment_t addr_limit;
19399 struct restart_block restart_block;
19400 void __user *sysenter_return;
19401 + unsigned long lowest_stack;
19402 unsigned int sig_on_uaccess_error:1;
19403 unsigned int uaccess_err:1; /* uaccess failed */
19404 };
19405
19406 -#define INIT_THREAD_INFO(tsk) \
19407 +#define INIT_THREAD_INFO \
19408 { \
19409 - .task = &tsk, \
19410 .exec_domain = &default_exec_domain, \
19411 .flags = 0, \
19412 .cpu = 0, \
19413 @@ -50,7 +49,7 @@ struct thread_info {
19414 }, \
19415 }
19416
19417 -#define init_thread_info (init_thread_union.thread_info)
19418 +#define init_thread_info (init_thread_union.stack)
19419 #define init_stack (init_thread_union.stack)
19420
19421 #else /* !__ASSEMBLY__ */
19422 @@ -91,6 +90,7 @@ struct thread_info {
19423 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19424 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19425 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19426 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19427
19428 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19429 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19430 @@ -115,17 +115,18 @@ struct thread_info {
19431 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19432 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19433 #define _TIF_X32 (1 << TIF_X32)
19434 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19435
19436 /* work to do in syscall_trace_enter() */
19437 #define _TIF_WORK_SYSCALL_ENTRY \
19438 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19439 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19440 - _TIF_NOHZ)
19441 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19442
19443 /* work to do in syscall_trace_leave() */
19444 #define _TIF_WORK_SYSCALL_EXIT \
19445 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19446 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19447 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19448
19449 /* work to do on interrupt/exception return */
19450 #define _TIF_WORK_MASK \
19451 @@ -136,7 +137,7 @@ struct thread_info {
19452 /* work to do on any return to user space */
19453 #define _TIF_ALLWORK_MASK \
19454 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19455 - _TIF_NOHZ)
19456 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19457
19458 /* Only used for 64 bit */
19459 #define _TIF_DO_NOTIFY_MASK \
19460 @@ -151,7 +152,6 @@ struct thread_info {
19461 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19462
19463 #define STACK_WARN (THREAD_SIZE/8)
19464 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19465
19466 /*
19467 * macros/functions for gaining access to the thread information structure
19468 @@ -162,26 +162,18 @@ struct thread_info {
19469
19470 DECLARE_PER_CPU(unsigned long, kernel_stack);
19471
19472 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19473 +
19474 static inline struct thread_info *current_thread_info(void)
19475 {
19476 - struct thread_info *ti;
19477 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19478 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19479 - return ti;
19480 + return this_cpu_read_stable(current_tinfo);
19481 }
19482
19483 #else /* !__ASSEMBLY__ */
19484
19485 /* how to get the thread information struct from ASM */
19486 #define GET_THREAD_INFO(reg) \
19487 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19488 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19489 -
19490 -/*
19491 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19492 - * a certain register (to be used in assembler memory operands).
19493 - */
19494 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19495 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19496
19497 #endif
19498
19499 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19500 extern void arch_task_cache_init(void);
19501 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19502 extern void arch_release_task_struct(struct task_struct *tsk);
19503 +
19504 +#define __HAVE_THREAD_FUNCTIONS
19505 +#define task_thread_info(task) (&(task)->tinfo)
19506 +#define task_stack_page(task) ((task)->stack)
19507 +#define setup_thread_stack(p, org) do {} while (0)
19508 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19509 +
19510 #endif
19511 #endif /* _ASM_X86_THREAD_INFO_H */
19512 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19513 index 04905bf..1178cdf 100644
19514 --- a/arch/x86/include/asm/tlbflush.h
19515 +++ b/arch/x86/include/asm/tlbflush.h
19516 @@ -17,18 +17,44 @@
19517
19518 static inline void __native_flush_tlb(void)
19519 {
19520 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19521 + u64 descriptor[2];
19522 +
19523 + descriptor[0] = PCID_KERNEL;
19524 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19525 + return;
19526 + }
19527 +
19528 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19529 + if (static_cpu_has(X86_FEATURE_PCID)) {
19530 + unsigned int cpu = raw_get_cpu();
19531 +
19532 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19533 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19534 + raw_put_cpu_no_resched();
19535 + return;
19536 + }
19537 +#endif
19538 +
19539 native_write_cr3(native_read_cr3());
19540 }
19541
19542 static inline void __native_flush_tlb_global_irq_disabled(void)
19543 {
19544 - unsigned long cr4;
19545 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19546 + u64 descriptor[2];
19547
19548 - cr4 = native_read_cr4();
19549 - /* clear PGE */
19550 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19551 - /* write old PGE again and flush TLBs */
19552 - native_write_cr4(cr4);
19553 + descriptor[0] = PCID_KERNEL;
19554 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19555 + } else {
19556 + unsigned long cr4;
19557 +
19558 + cr4 = native_read_cr4();
19559 + /* clear PGE */
19560 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19561 + /* write old PGE again and flush TLBs */
19562 + native_write_cr4(cr4);
19563 + }
19564 }
19565
19566 static inline void __native_flush_tlb_global(void)
19567 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19568
19569 static inline void __native_flush_tlb_single(unsigned long addr)
19570 {
19571 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19572 + u64 descriptor[2];
19573 +
19574 + descriptor[0] = PCID_KERNEL;
19575 + descriptor[1] = addr;
19576 +
19577 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19578 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19579 + if (addr < TASK_SIZE_MAX)
19580 + descriptor[1] += pax_user_shadow_base;
19581 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19582 + }
19583 +
19584 + descriptor[0] = PCID_USER;
19585 + descriptor[1] = addr;
19586 +#endif
19587 +
19588 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19589 + return;
19590 + }
19591 +
19592 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19593 + if (static_cpu_has(X86_FEATURE_PCID)) {
19594 + unsigned int cpu = raw_get_cpu();
19595 +
19596 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19597 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19598 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19599 + raw_put_cpu_no_resched();
19600 +
19601 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19602 + addr += pax_user_shadow_base;
19603 + }
19604 +#endif
19605 +
19606 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19607 }
19608
19609 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19610 index 0d592e0..526f797 100644
19611 --- a/arch/x86/include/asm/uaccess.h
19612 +++ b/arch/x86/include/asm/uaccess.h
19613 @@ -7,6 +7,7 @@
19614 #include <linux/compiler.h>
19615 #include <linux/thread_info.h>
19616 #include <linux/string.h>
19617 +#include <linux/spinlock.h>
19618 #include <asm/asm.h>
19619 #include <asm/page.h>
19620 #include <asm/smap.h>
19621 @@ -29,7 +30,12 @@
19622
19623 #define get_ds() (KERNEL_DS)
19624 #define get_fs() (current_thread_info()->addr_limit)
19625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19626 +void __set_fs(mm_segment_t x);
19627 +void set_fs(mm_segment_t x);
19628 +#else
19629 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19630 +#endif
19631
19632 #define segment_eq(a, b) ((a).seg == (b).seg)
19633
19634 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19635 * checks that the pointer is in the user space range - after calling
19636 * this function, memory access functions may still return -EFAULT.
19637 */
19638 -#define access_ok(type, addr, size) \
19639 - likely(!__range_not_ok(addr, size, user_addr_max()))
19640 +extern int _cond_resched(void);
19641 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19642 +#define access_ok(type, addr, size) \
19643 +({ \
19644 + unsigned long __size = size; \
19645 + unsigned long __addr = (unsigned long)addr; \
19646 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19647 + if (__ret_ao && __size) { \
19648 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19649 + unsigned long __end_ao = __addr + __size - 1; \
19650 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19651 + while (__addr_ao <= __end_ao) { \
19652 + char __c_ao; \
19653 + __addr_ao += PAGE_SIZE; \
19654 + if (__size > PAGE_SIZE) \
19655 + _cond_resched(); \
19656 + if (__get_user(__c_ao, (char __user *)__addr)) \
19657 + break; \
19658 + if (type != VERIFY_WRITE) { \
19659 + __addr = __addr_ao; \
19660 + continue; \
19661 + } \
19662 + if (__put_user(__c_ao, (char __user *)__addr)) \
19663 + break; \
19664 + __addr = __addr_ao; \
19665 + } \
19666 + } \
19667 + } \
19668 + __ret_ao; \
19669 +})
19670
19671 /*
19672 * The exception table consists of pairs of addresses relative to the
19673 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19674 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19675 __chk_user_ptr(ptr); \
19676 might_fault(); \
19677 + pax_open_userland(); \
19678 asm volatile("call __get_user_%P3" \
19679 : "=a" (__ret_gu), "=r" (__val_gu) \
19680 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19681 (x) = (__typeof__(*(ptr))) __val_gu; \
19682 + pax_close_userland(); \
19683 __ret_gu; \
19684 })
19685
19686 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19687 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19688 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19689
19690 -
19691 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19692 +#define __copyuser_seg "gs;"
19693 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19694 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19695 +#else
19696 +#define __copyuser_seg
19697 +#define __COPYUSER_SET_ES
19698 +#define __COPYUSER_RESTORE_ES
19699 +#endif
19700
19701 #ifdef CONFIG_X86_32
19702 #define __put_user_asm_u64(x, addr, err, errret) \
19703 asm volatile(ASM_STAC "\n" \
19704 - "1: movl %%eax,0(%2)\n" \
19705 - "2: movl %%edx,4(%2)\n" \
19706 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19707 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19708 "3: " ASM_CLAC "\n" \
19709 ".section .fixup,\"ax\"\n" \
19710 "4: movl %3,%0\n" \
19711 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19712
19713 #define __put_user_asm_ex_u64(x, addr) \
19714 asm volatile(ASM_STAC "\n" \
19715 - "1: movl %%eax,0(%1)\n" \
19716 - "2: movl %%edx,4(%1)\n" \
19717 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19718 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19719 "3: " ASM_CLAC "\n" \
19720 _ASM_EXTABLE_EX(1b, 2b) \
19721 _ASM_EXTABLE_EX(2b, 3b) \
19722 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19723 __typeof__(*(ptr)) __pu_val; \
19724 __chk_user_ptr(ptr); \
19725 might_fault(); \
19726 - __pu_val = x; \
19727 + __pu_val = (x); \
19728 + pax_open_userland(); \
19729 switch (sizeof(*(ptr))) { \
19730 case 1: \
19731 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19732 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19733 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19734 break; \
19735 } \
19736 + pax_close_userland(); \
19737 __ret_pu; \
19738 })
19739
19740 @@ -355,8 +401,10 @@ do { \
19741 } while (0)
19742
19743 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19744 +do { \
19745 + pax_open_userland(); \
19746 asm volatile(ASM_STAC "\n" \
19747 - "1: mov"itype" %2,%"rtype"1\n" \
19748 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19749 "2: " ASM_CLAC "\n" \
19750 ".section .fixup,\"ax\"\n" \
19751 "3: mov %3,%0\n" \
19752 @@ -364,8 +412,10 @@ do { \
19753 " jmp 2b\n" \
19754 ".previous\n" \
19755 _ASM_EXTABLE(1b, 3b) \
19756 - : "=r" (err), ltype(x) \
19757 - : "m" (__m(addr)), "i" (errret), "0" (err))
19758 + : "=r" (err), ltype (x) \
19759 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19760 + pax_close_userland(); \
19761 +} while (0)
19762
19763 #define __get_user_size_ex(x, ptr, size) \
19764 do { \
19765 @@ -389,7 +439,7 @@ do { \
19766 } while (0)
19767
19768 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19769 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19770 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19771 "2:\n" \
19772 _ASM_EXTABLE_EX(1b, 2b) \
19773 : ltype(x) : "m" (__m(addr)))
19774 @@ -406,13 +456,24 @@ do { \
19775 int __gu_err; \
19776 unsigned long __gu_val; \
19777 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19778 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19779 + (x) = (__typeof__(*(ptr)))__gu_val; \
19780 __gu_err; \
19781 })
19782
19783 /* FIXME: this hack is definitely wrong -AK */
19784 struct __large_struct { unsigned long buf[100]; };
19785 -#define __m(x) (*(struct __large_struct __user *)(x))
19786 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19787 +#define ____m(x) \
19788 +({ \
19789 + unsigned long ____x = (unsigned long)(x); \
19790 + if (____x < pax_user_shadow_base) \
19791 + ____x += pax_user_shadow_base; \
19792 + (typeof(x))____x; \
19793 +})
19794 +#else
19795 +#define ____m(x) (x)
19796 +#endif
19797 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19798
19799 /*
19800 * Tell gcc we read from memory instead of writing: this is because
19801 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19802 * aliasing issues.
19803 */
19804 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19805 +do { \
19806 + pax_open_userland(); \
19807 asm volatile(ASM_STAC "\n" \
19808 - "1: mov"itype" %"rtype"1,%2\n" \
19809 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19810 "2: " ASM_CLAC "\n" \
19811 ".section .fixup,\"ax\"\n" \
19812 "3: mov %3,%0\n" \
19813 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19814 ".previous\n" \
19815 _ASM_EXTABLE(1b, 3b) \
19816 : "=r"(err) \
19817 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19818 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19819 + pax_close_userland(); \
19820 +} while (0)
19821
19822 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19823 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19824 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19825 "2:\n" \
19826 _ASM_EXTABLE_EX(1b, 2b) \
19827 : : ltype(x), "m" (__m(addr)))
19828 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19829 */
19830 #define uaccess_try do { \
19831 current_thread_info()->uaccess_err = 0; \
19832 + pax_open_userland(); \
19833 stac(); \
19834 barrier();
19835
19836 #define uaccess_catch(err) \
19837 clac(); \
19838 + pax_close_userland(); \
19839 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19840 } while (0)
19841
19842 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19843 * On error, the variable @x is set to zero.
19844 */
19845
19846 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19847 +#define __get_user(x, ptr) get_user((x), (ptr))
19848 +#else
19849 #define __get_user(x, ptr) \
19850 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19851 +#endif
19852
19853 /**
19854 * __put_user: - Write a simple value into user space, with less checking.
19855 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19856 * Returns zero on success, or -EFAULT on error.
19857 */
19858
19859 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19860 +#define __put_user(x, ptr) put_user((x), (ptr))
19861 +#else
19862 #define __put_user(x, ptr) \
19863 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19864 +#endif
19865
19866 #define __get_user_unaligned __get_user
19867 #define __put_user_unaligned __put_user
19868 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19869 #define get_user_ex(x, ptr) do { \
19870 unsigned long __gue_val; \
19871 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19872 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19873 + (x) = (__typeof__(*(ptr)))__gue_val; \
19874 } while (0)
19875
19876 #define put_user_try uaccess_try
19877 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19878 __typeof__(ptr) __uval = (uval); \
19879 __typeof__(*(ptr)) __old = (old); \
19880 __typeof__(*(ptr)) __new = (new); \
19881 + pax_open_userland(); \
19882 switch (size) { \
19883 case 1: \
19884 { \
19885 asm volatile("\t" ASM_STAC "\n" \
19886 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19887 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19888 "2:\t" ASM_CLAC "\n" \
19889 "\t.section .fixup, \"ax\"\n" \
19890 "3:\tmov %3, %0\n" \
19891 "\tjmp 2b\n" \
19892 "\t.previous\n" \
19893 _ASM_EXTABLE(1b, 3b) \
19894 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19895 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19896 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19897 : "memory" \
19898 ); \
19899 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19900 case 2: \
19901 { \
19902 asm volatile("\t" ASM_STAC "\n" \
19903 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19904 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19905 "2:\t" ASM_CLAC "\n" \
19906 "\t.section .fixup, \"ax\"\n" \
19907 "3:\tmov %3, %0\n" \
19908 "\tjmp 2b\n" \
19909 "\t.previous\n" \
19910 _ASM_EXTABLE(1b, 3b) \
19911 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19912 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19913 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19914 : "memory" \
19915 ); \
19916 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19917 case 4: \
19918 { \
19919 asm volatile("\t" ASM_STAC "\n" \
19920 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19921 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19922 "2:\t" ASM_CLAC "\n" \
19923 "\t.section .fixup, \"ax\"\n" \
19924 "3:\tmov %3, %0\n" \
19925 "\tjmp 2b\n" \
19926 "\t.previous\n" \
19927 _ASM_EXTABLE(1b, 3b) \
19928 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19929 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19930 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19931 : "memory" \
19932 ); \
19933 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19934 __cmpxchg_wrong_size(); \
19935 \
19936 asm volatile("\t" ASM_STAC "\n" \
19937 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19938 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19939 "2:\t" ASM_CLAC "\n" \
19940 "\t.section .fixup, \"ax\"\n" \
19941 "3:\tmov %3, %0\n" \
19942 "\tjmp 2b\n" \
19943 "\t.previous\n" \
19944 _ASM_EXTABLE(1b, 3b) \
19945 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19946 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19947 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19948 : "memory" \
19949 ); \
19950 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19951 default: \
19952 __cmpxchg_wrong_size(); \
19953 } \
19954 + pax_close_userland(); \
19955 *__uval = __old; \
19956 __ret; \
19957 })
19958 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19959
19960 #define ARCH_HAS_NOCACHE_UACCESS 1
19961
19962 -#ifdef CONFIG_X86_32
19963 -# include <asm/uaccess_32.h>
19964 -#else
19965 -# include <asm/uaccess_64.h>
19966 -#endif
19967 -
19968 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19969 - unsigned n);
19970 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19971 - unsigned n);
19972 -
19973 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19974 # define copy_user_diag __compiletime_error
19975 #else
19976 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19977 extern void copy_user_diag("copy_from_user() buffer size is too small")
19978 copy_from_user_overflow(void);
19979 extern void copy_user_diag("copy_to_user() buffer size is too small")
19980 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19981 +copy_to_user_overflow(void);
19982
19983 #undef copy_user_diag
19984
19985 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19986
19987 extern void
19988 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19989 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19990 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19991 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19992
19993 #else
19994 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19995
19996 #endif
19997
19998 +#ifdef CONFIG_X86_32
19999 +# include <asm/uaccess_32.h>
20000 +#else
20001 +# include <asm/uaccess_64.h>
20002 +#endif
20003 +
20004 static inline unsigned long __must_check
20005 copy_from_user(void *to, const void __user *from, unsigned long n)
20006 {
20007 - int sz = __compiletime_object_size(to);
20008 + size_t sz = __compiletime_object_size(to);
20009
20010 might_fault();
20011
20012 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20013 * case, and do only runtime checking for non-constant sizes.
20014 */
20015
20016 - if (likely(sz < 0 || sz >= n))
20017 - n = _copy_from_user(to, from, n);
20018 - else if(__builtin_constant_p(n))
20019 - copy_from_user_overflow();
20020 - else
20021 - __copy_from_user_overflow(sz, n);
20022 + if (likely(sz != (size_t)-1 && sz < n)) {
20023 + if(__builtin_constant_p(n))
20024 + copy_from_user_overflow();
20025 + else
20026 + __copy_from_user_overflow(sz, n);
20027 + } else if (access_ok(VERIFY_READ, from, n))
20028 + n = __copy_from_user(to, from, n);
20029 + else if ((long)n > 0)
20030 + memset(to, 0, n);
20031
20032 return n;
20033 }
20034 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20035 static inline unsigned long __must_check
20036 copy_to_user(void __user *to, const void *from, unsigned long n)
20037 {
20038 - int sz = __compiletime_object_size(from);
20039 + size_t sz = __compiletime_object_size(from);
20040
20041 might_fault();
20042
20043 /* See the comment in copy_from_user() above. */
20044 - if (likely(sz < 0 || sz >= n))
20045 - n = _copy_to_user(to, from, n);
20046 - else if(__builtin_constant_p(n))
20047 - copy_to_user_overflow();
20048 - else
20049 - __copy_to_user_overflow(sz, n);
20050 + if (likely(sz != (size_t)-1 && sz < n)) {
20051 + if(__builtin_constant_p(n))
20052 + copy_to_user_overflow();
20053 + else
20054 + __copy_to_user_overflow(sz, n);
20055 + } else if (access_ok(VERIFY_WRITE, to, n))
20056 + n = __copy_to_user(to, from, n);
20057
20058 return n;
20059 }
20060 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20061 index 3c03a5d..1071638 100644
20062 --- a/arch/x86/include/asm/uaccess_32.h
20063 +++ b/arch/x86/include/asm/uaccess_32.h
20064 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20065 static __always_inline unsigned long __must_check
20066 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20067 {
20068 + if ((long)n < 0)
20069 + return n;
20070 +
20071 + check_object_size(from, n, true);
20072 +
20073 if (__builtin_constant_p(n)) {
20074 unsigned long ret;
20075
20076 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20077 __copy_to_user(void __user *to, const void *from, unsigned long n)
20078 {
20079 might_fault();
20080 +
20081 return __copy_to_user_inatomic(to, from, n);
20082 }
20083
20084 static __always_inline unsigned long
20085 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20086 {
20087 + if ((long)n < 0)
20088 + return n;
20089 +
20090 /* Avoid zeroing the tail if the copy fails..
20091 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20092 * but as the zeroing behaviour is only significant when n is not
20093 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20094 __copy_from_user(void *to, const void __user *from, unsigned long n)
20095 {
20096 might_fault();
20097 +
20098 + if ((long)n < 0)
20099 + return n;
20100 +
20101 + check_object_size(to, n, false);
20102 +
20103 if (__builtin_constant_p(n)) {
20104 unsigned long ret;
20105
20106 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20107 const void __user *from, unsigned long n)
20108 {
20109 might_fault();
20110 +
20111 + if ((long)n < 0)
20112 + return n;
20113 +
20114 if (__builtin_constant_p(n)) {
20115 unsigned long ret;
20116
20117 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20118 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20119 unsigned long n)
20120 {
20121 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20122 + if ((long)n < 0)
20123 + return n;
20124 +
20125 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20126 }
20127
20128 #endif /* _ASM_X86_UACCESS_32_H */
20129 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20130 index 12a26b9..206c200 100644
20131 --- a/arch/x86/include/asm/uaccess_64.h
20132 +++ b/arch/x86/include/asm/uaccess_64.h
20133 @@ -10,6 +10,9 @@
20134 #include <asm/alternative.h>
20135 #include <asm/cpufeature.h>
20136 #include <asm/page.h>
20137 +#include <asm/pgtable.h>
20138 +
20139 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20140
20141 /*
20142 * Copy To/From Userspace
20143 @@ -17,14 +20,14 @@
20144
20145 /* Handles exceptions in both to and from, but doesn't do access_ok */
20146 __must_check unsigned long
20147 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20148 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20149 __must_check unsigned long
20150 -copy_user_generic_string(void *to, const void *from, unsigned len);
20151 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20152 __must_check unsigned long
20153 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20154 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20155
20156 static __always_inline __must_check unsigned long
20157 -copy_user_generic(void *to, const void *from, unsigned len)
20158 +copy_user_generic(void *to, const void *from, unsigned long len)
20159 {
20160 unsigned ret;
20161
20162 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20163 }
20164
20165 __must_check unsigned long
20166 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20167 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20168
20169 static __always_inline __must_check
20170 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20171 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20172 {
20173 - int ret = 0;
20174 + size_t sz = __compiletime_object_size(dst);
20175 + unsigned ret = 0;
20176 +
20177 + if (size > INT_MAX)
20178 + return size;
20179 +
20180 + check_object_size(dst, size, false);
20181 +
20182 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20183 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20184 + return size;
20185 +#endif
20186 +
20187 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20188 + if(__builtin_constant_p(size))
20189 + copy_from_user_overflow();
20190 + else
20191 + __copy_from_user_overflow(sz, size);
20192 + return size;
20193 + }
20194
20195 if (!__builtin_constant_p(size))
20196 - return copy_user_generic(dst, (__force void *)src, size);
20197 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20198 switch (size) {
20199 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20200 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20201 ret, "b", "b", "=q", 1);
20202 return ret;
20203 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20204 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20205 ret, "w", "w", "=r", 2);
20206 return ret;
20207 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20208 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20209 ret, "l", "k", "=r", 4);
20210 return ret;
20211 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20212 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20213 ret, "q", "", "=r", 8);
20214 return ret;
20215 case 10:
20216 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20217 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20218 ret, "q", "", "=r", 10);
20219 if (unlikely(ret))
20220 return ret;
20221 __get_user_asm(*(u16 *)(8 + (char *)dst),
20222 - (u16 __user *)(8 + (char __user *)src),
20223 + (const u16 __user *)(8 + (const char __user *)src),
20224 ret, "w", "w", "=r", 2);
20225 return ret;
20226 case 16:
20227 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20228 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20229 ret, "q", "", "=r", 16);
20230 if (unlikely(ret))
20231 return ret;
20232 __get_user_asm(*(u64 *)(8 + (char *)dst),
20233 - (u64 __user *)(8 + (char __user *)src),
20234 + (const u64 __user *)(8 + (const char __user *)src),
20235 ret, "q", "", "=r", 8);
20236 return ret;
20237 default:
20238 - return copy_user_generic(dst, (__force void *)src, size);
20239 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20240 }
20241 }
20242
20243 static __always_inline __must_check
20244 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20245 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20246 {
20247 might_fault();
20248 return __copy_from_user_nocheck(dst, src, size);
20249 }
20250
20251 static __always_inline __must_check
20252 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20253 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20254 {
20255 - int ret = 0;
20256 + size_t sz = __compiletime_object_size(src);
20257 + unsigned ret = 0;
20258 +
20259 + if (size > INT_MAX)
20260 + return size;
20261 +
20262 + check_object_size(src, size, true);
20263 +
20264 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20265 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20266 + return size;
20267 +#endif
20268 +
20269 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20270 + if(__builtin_constant_p(size))
20271 + copy_to_user_overflow();
20272 + else
20273 + __copy_to_user_overflow(sz, size);
20274 + return size;
20275 + }
20276
20277 if (!__builtin_constant_p(size))
20278 - return copy_user_generic((__force void *)dst, src, size);
20279 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20280 switch (size) {
20281 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20282 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20283 ret, "b", "b", "iq", 1);
20284 return ret;
20285 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20286 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20287 ret, "w", "w", "ir", 2);
20288 return ret;
20289 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20290 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20291 ret, "l", "k", "ir", 4);
20292 return ret;
20293 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20294 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20295 ret, "q", "", "er", 8);
20296 return ret;
20297 case 10:
20298 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20299 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20300 ret, "q", "", "er", 10);
20301 if (unlikely(ret))
20302 return ret;
20303 asm("":::"memory");
20304 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20305 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20306 ret, "w", "w", "ir", 2);
20307 return ret;
20308 case 16:
20309 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20310 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20311 ret, "q", "", "er", 16);
20312 if (unlikely(ret))
20313 return ret;
20314 asm("":::"memory");
20315 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20316 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20317 ret, "q", "", "er", 8);
20318 return ret;
20319 default:
20320 - return copy_user_generic((__force void *)dst, src, size);
20321 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20322 }
20323 }
20324
20325 static __always_inline __must_check
20326 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20327 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20328 {
20329 might_fault();
20330 return __copy_to_user_nocheck(dst, src, size);
20331 }
20332
20333 static __always_inline __must_check
20334 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20335 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20336 {
20337 - int ret = 0;
20338 + unsigned ret = 0;
20339
20340 might_fault();
20341 +
20342 + if (size > INT_MAX)
20343 + return size;
20344 +
20345 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20346 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20347 + return size;
20348 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20349 + return size;
20350 +#endif
20351 +
20352 if (!__builtin_constant_p(size))
20353 - return copy_user_generic((__force void *)dst,
20354 - (__force void *)src, size);
20355 + return copy_user_generic((__force_kernel void *)____m(dst),
20356 + (__force_kernel const void *)____m(src), size);
20357 switch (size) {
20358 case 1: {
20359 u8 tmp;
20360 - __get_user_asm(tmp, (u8 __user *)src,
20361 + __get_user_asm(tmp, (const u8 __user *)src,
20362 ret, "b", "b", "=q", 1);
20363 if (likely(!ret))
20364 __put_user_asm(tmp, (u8 __user *)dst,
20365 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20366 }
20367 case 2: {
20368 u16 tmp;
20369 - __get_user_asm(tmp, (u16 __user *)src,
20370 + __get_user_asm(tmp, (const u16 __user *)src,
20371 ret, "w", "w", "=r", 2);
20372 if (likely(!ret))
20373 __put_user_asm(tmp, (u16 __user *)dst,
20374 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20375
20376 case 4: {
20377 u32 tmp;
20378 - __get_user_asm(tmp, (u32 __user *)src,
20379 + __get_user_asm(tmp, (const u32 __user *)src,
20380 ret, "l", "k", "=r", 4);
20381 if (likely(!ret))
20382 __put_user_asm(tmp, (u32 __user *)dst,
20383 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20384 }
20385 case 8: {
20386 u64 tmp;
20387 - __get_user_asm(tmp, (u64 __user *)src,
20388 + __get_user_asm(tmp, (const u64 __user *)src,
20389 ret, "q", "", "=r", 8);
20390 if (likely(!ret))
20391 __put_user_asm(tmp, (u64 __user *)dst,
20392 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20393 return ret;
20394 }
20395 default:
20396 - return copy_user_generic((__force void *)dst,
20397 - (__force void *)src, size);
20398 + return copy_user_generic((__force_kernel void *)____m(dst),
20399 + (__force_kernel const void *)____m(src), size);
20400 }
20401 }
20402
20403 -static __must_check __always_inline int
20404 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20405 +static __must_check __always_inline unsigned long
20406 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20407 {
20408 return __copy_from_user_nocheck(dst, src, size);
20409 }
20410
20411 -static __must_check __always_inline int
20412 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20413 +static __must_check __always_inline unsigned long
20414 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20415 {
20416 return __copy_to_user_nocheck(dst, src, size);
20417 }
20418
20419 -extern long __copy_user_nocache(void *dst, const void __user *src,
20420 - unsigned size, int zerorest);
20421 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20422 + unsigned long size, int zerorest);
20423
20424 -static inline int
20425 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20426 +static inline unsigned long
20427 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20428 {
20429 might_fault();
20430 +
20431 + if (size > INT_MAX)
20432 + return size;
20433 +
20434 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20435 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20436 + return size;
20437 +#endif
20438 +
20439 return __copy_user_nocache(dst, src, size, 1);
20440 }
20441
20442 -static inline int
20443 +static inline unsigned long
20444 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20445 - unsigned size)
20446 + unsigned long size)
20447 {
20448 + if (size > INT_MAX)
20449 + return size;
20450 +
20451 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20452 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20453 + return size;
20454 +#endif
20455 +
20456 return __copy_user_nocache(dst, src, size, 0);
20457 }
20458
20459 unsigned long
20460 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20461 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20462
20463 #endif /* _ASM_X86_UACCESS_64_H */
20464 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20465 index 5b238981..77fdd78 100644
20466 --- a/arch/x86/include/asm/word-at-a-time.h
20467 +++ b/arch/x86/include/asm/word-at-a-time.h
20468 @@ -11,7 +11,7 @@
20469 * and shift, for example.
20470 */
20471 struct word_at_a_time {
20472 - const unsigned long one_bits, high_bits;
20473 + unsigned long one_bits, high_bits;
20474 };
20475
20476 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20477 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20478 index e45e4da..44e8572 100644
20479 --- a/arch/x86/include/asm/x86_init.h
20480 +++ b/arch/x86/include/asm/x86_init.h
20481 @@ -129,7 +129,7 @@ struct x86_init_ops {
20482 struct x86_init_timers timers;
20483 struct x86_init_iommu iommu;
20484 struct x86_init_pci pci;
20485 -};
20486 +} __no_const;
20487
20488 /**
20489 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20490 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20491 void (*setup_percpu_clockev)(void);
20492 void (*early_percpu_clock_init)(void);
20493 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20494 -};
20495 +} __no_const;
20496
20497 struct timespec;
20498
20499 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20500 void (*save_sched_clock_state)(void);
20501 void (*restore_sched_clock_state)(void);
20502 void (*apic_post_init)(void);
20503 -};
20504 +} __no_const;
20505
20506 struct pci_dev;
20507 struct msi_msg;
20508 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20509 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20510 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20511 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20512 -};
20513 +} __no_const;
20514
20515 struct IO_APIC_route_entry;
20516 struct io_apic_irq_attr;
20517 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20518 unsigned int destination, int vector,
20519 struct io_apic_irq_attr *attr);
20520 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20521 -};
20522 +} __no_const;
20523
20524 extern struct x86_init_ops x86_init;
20525 extern struct x86_cpuinit_ops x86_cpuinit;
20526 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20527 index c949923..c22bfa4 100644
20528 --- a/arch/x86/include/asm/xen/page.h
20529 +++ b/arch/x86/include/asm/xen/page.h
20530 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20531 extern struct page *m2p_find_override(unsigned long mfn);
20532 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20533
20534 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20535 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20536 {
20537 unsigned long mfn;
20538
20539 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20540 index 7e7a79a..0824666 100644
20541 --- a/arch/x86/include/asm/xsave.h
20542 +++ b/arch/x86/include/asm/xsave.h
20543 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20544 if (unlikely(err))
20545 return -EFAULT;
20546
20547 + pax_open_userland();
20548 __asm__ __volatile__(ASM_STAC "\n"
20549 - "1:"XSAVE"\n"
20550 + "1:"
20551 + __copyuser_seg
20552 + XSAVE"\n"
20553 "2: " ASM_CLAC "\n"
20554 xstate_fault
20555 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20556 : "memory");
20557 + pax_close_userland();
20558 return err;
20559 }
20560
20561 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20562 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20563 {
20564 int err = 0;
20565 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20566 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20567 u32 lmask = mask;
20568 u32 hmask = mask >> 32;
20569
20570 + pax_open_userland();
20571 __asm__ __volatile__(ASM_STAC "\n"
20572 - "1:"XRSTOR"\n"
20573 + "1:"
20574 + __copyuser_seg
20575 + XRSTOR"\n"
20576 "2: " ASM_CLAC "\n"
20577 xstate_fault
20578 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20579 : "memory"); /* memory required? */
20580 + pax_close_userland();
20581 return err;
20582 }
20583
20584 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20585 index d993e33..8db1b18 100644
20586 --- a/arch/x86/include/uapi/asm/e820.h
20587 +++ b/arch/x86/include/uapi/asm/e820.h
20588 @@ -58,7 +58,7 @@ struct e820map {
20589 #define ISA_START_ADDRESS 0xa0000
20590 #define ISA_END_ADDRESS 0x100000
20591
20592 -#define BIOS_BEGIN 0x000a0000
20593 +#define BIOS_BEGIN 0x000c0000
20594 #define BIOS_END 0x00100000
20595
20596 #define BIOS_ROM_BASE 0xffe00000
20597 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20598 index 7b0a55a..ad115bf 100644
20599 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20600 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20601 @@ -49,7 +49,6 @@
20602 #define EFLAGS 144
20603 #define RSP 152
20604 #define SS 160
20605 -#define ARGOFFSET R11
20606 #endif /* __ASSEMBLY__ */
20607
20608 /* top of stack page */
20609 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20610 index 8f1e774..9b4c381 100644
20611 --- a/arch/x86/kernel/Makefile
20612 +++ b/arch/x86/kernel/Makefile
20613 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20614 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20615 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20616 obj-y += probe_roms.o
20617 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20618 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20619 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20620 obj-$(CONFIG_X86_64) += mcount_64.o
20621 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20622 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20623 index a142e77..6222cdd 100644
20624 --- a/arch/x86/kernel/acpi/boot.c
20625 +++ b/arch/x86/kernel/acpi/boot.c
20626 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20627 * If your system is blacklisted here, but you find that acpi=force
20628 * works for you, please contact linux-acpi@vger.kernel.org
20629 */
20630 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20631 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20632 /*
20633 * Boxes that need ACPI disabled
20634 */
20635 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20636 };
20637
20638 /* second table for DMI checks that should run after early-quirks */
20639 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20640 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20641 /*
20642 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20643 * which includes some code which overrides all temperature
20644 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20645 index 3136820..e2c6577 100644
20646 --- a/arch/x86/kernel/acpi/sleep.c
20647 +++ b/arch/x86/kernel/acpi/sleep.c
20648 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20649 #else /* CONFIG_64BIT */
20650 #ifdef CONFIG_SMP
20651 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20652 +
20653 + pax_open_kernel();
20654 early_gdt_descr.address =
20655 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20656 + pax_close_kernel();
20657 +
20658 initial_gs = per_cpu_offset(smp_processor_id());
20659 #endif
20660 initial_code = (unsigned long)wakeup_long64;
20661 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20662 index 665c6b7..eae4d56 100644
20663 --- a/arch/x86/kernel/acpi/wakeup_32.S
20664 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20665 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20666 # and restore the stack ... but you need gdt for this to work
20667 movl saved_context_esp, %esp
20668
20669 - movl %cs:saved_magic, %eax
20670 - cmpl $0x12345678, %eax
20671 + cmpl $0x12345678, saved_magic
20672 jne bogus_magic
20673
20674 # jump to place where we left off
20675 - movl saved_eip, %eax
20676 - jmp *%eax
20677 + jmp *(saved_eip)
20678
20679 bogus_magic:
20680 jmp bogus_magic
20681 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20682 index 703130f..27a155d 100644
20683 --- a/arch/x86/kernel/alternative.c
20684 +++ b/arch/x86/kernel/alternative.c
20685 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20686 */
20687 for (a = start; a < end; a++) {
20688 instr = (u8 *)&a->instr_offset + a->instr_offset;
20689 +
20690 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20691 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20692 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20693 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20694 +#endif
20695 +
20696 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20697 BUG_ON(a->replacementlen > a->instrlen);
20698 BUG_ON(a->instrlen > sizeof(insnbuf));
20699 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20700 add_nops(insnbuf + a->replacementlen,
20701 a->instrlen - a->replacementlen);
20702
20703 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20704 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20705 + instr = ktva_ktla(instr);
20706 +#endif
20707 +
20708 text_poke_early(instr, insnbuf, a->instrlen);
20709 }
20710 }
20711 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20712 for (poff = start; poff < end; poff++) {
20713 u8 *ptr = (u8 *)poff + *poff;
20714
20715 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20716 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20717 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20718 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20719 +#endif
20720 +
20721 if (!*poff || ptr < text || ptr >= text_end)
20722 continue;
20723 /* turn DS segment override prefix into lock prefix */
20724 - if (*ptr == 0x3e)
20725 + if (*ktla_ktva(ptr) == 0x3e)
20726 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20727 }
20728 mutex_unlock(&text_mutex);
20729 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20730 for (poff = start; poff < end; poff++) {
20731 u8 *ptr = (u8 *)poff + *poff;
20732
20733 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20734 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20735 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20736 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20737 +#endif
20738 +
20739 if (!*poff || ptr < text || ptr >= text_end)
20740 continue;
20741 /* turn lock prefix into DS segment override prefix */
20742 - if (*ptr == 0xf0)
20743 + if (*ktla_ktva(ptr) == 0xf0)
20744 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20745 }
20746 mutex_unlock(&text_mutex);
20747 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20748
20749 BUG_ON(p->len > MAX_PATCH_LEN);
20750 /* prep the buffer with the original instructions */
20751 - memcpy(insnbuf, p->instr, p->len);
20752 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20753 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20754 (unsigned long)p->instr, p->len);
20755
20756 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20757 if (!uniproc_patched || num_possible_cpus() == 1)
20758 free_init_pages("SMP alternatives",
20759 (unsigned long)__smp_locks,
20760 - (unsigned long)__smp_locks_end);
20761 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20762 #endif
20763
20764 apply_paravirt(__parainstructions, __parainstructions_end);
20765 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20766 * instructions. And on the local CPU you need to be protected again NMI or MCE
20767 * handlers seeing an inconsistent instruction while you patch.
20768 */
20769 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20770 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20771 size_t len)
20772 {
20773 unsigned long flags;
20774 local_irq_save(flags);
20775 - memcpy(addr, opcode, len);
20776 +
20777 + pax_open_kernel();
20778 + memcpy(ktla_ktva(addr), opcode, len);
20779 sync_core();
20780 + pax_close_kernel();
20781 +
20782 local_irq_restore(flags);
20783 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20784 that causes hangs on some VIA CPUs. */
20785 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20786 */
20787 void *text_poke(void *addr, const void *opcode, size_t len)
20788 {
20789 - unsigned long flags;
20790 - char *vaddr;
20791 + unsigned char *vaddr = ktla_ktva(addr);
20792 struct page *pages[2];
20793 - int i;
20794 + size_t i;
20795
20796 if (!core_kernel_text((unsigned long)addr)) {
20797 - pages[0] = vmalloc_to_page(addr);
20798 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20799 + pages[0] = vmalloc_to_page(vaddr);
20800 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20801 } else {
20802 - pages[0] = virt_to_page(addr);
20803 + pages[0] = virt_to_page(vaddr);
20804 WARN_ON(!PageReserved(pages[0]));
20805 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20806 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20807 }
20808 BUG_ON(!pages[0]);
20809 - local_irq_save(flags);
20810 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20811 - if (pages[1])
20812 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20813 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20814 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20815 - clear_fixmap(FIX_TEXT_POKE0);
20816 - if (pages[1])
20817 - clear_fixmap(FIX_TEXT_POKE1);
20818 - local_flush_tlb();
20819 - sync_core();
20820 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20821 - that causes hangs on some VIA CPUs. */
20822 + text_poke_early(addr, opcode, len);
20823 for (i = 0; i < len; i++)
20824 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20825 - local_irq_restore(flags);
20826 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20827 return addr;
20828 }
20829
20830 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20831 if (likely(!bp_patching_in_progress))
20832 return 0;
20833
20834 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20835 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20836 return 0;
20837
20838 /* set up the specified breakpoint handler */
20839 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20840 */
20841 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20842 {
20843 - unsigned char int3 = 0xcc;
20844 + const unsigned char int3 = 0xcc;
20845
20846 bp_int3_handler = handler;
20847 bp_int3_addr = (u8 *)addr + sizeof(int3);
20848 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20849 index ba6cc04..06fd971 100644
20850 --- a/arch/x86/kernel/apic/apic.c
20851 +++ b/arch/x86/kernel/apic/apic.c
20852 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20853 /*
20854 * Debug level, exported for io_apic.c
20855 */
20856 -unsigned int apic_verbosity;
20857 +int apic_verbosity;
20858
20859 int pic_mode;
20860
20861 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20862 apic_write(APIC_ESR, 0);
20863 v = apic_read(APIC_ESR);
20864 ack_APIC_irq();
20865 - atomic_inc(&irq_err_count);
20866 + atomic_inc_unchecked(&irq_err_count);
20867
20868 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20869 smp_processor_id(), v);
20870 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20871 index de918c4..32eed23 100644
20872 --- a/arch/x86/kernel/apic/apic_flat_64.c
20873 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20874 @@ -154,7 +154,7 @@ static int flat_probe(void)
20875 return 1;
20876 }
20877
20878 -static struct apic apic_flat = {
20879 +static struct apic apic_flat __read_only = {
20880 .name = "flat",
20881 .probe = flat_probe,
20882 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20883 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20884 return 0;
20885 }
20886
20887 -static struct apic apic_physflat = {
20888 +static struct apic apic_physflat __read_only = {
20889
20890 .name = "physical flat",
20891 .probe = physflat_probe,
20892 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20893 index b205cdb..d8503ff 100644
20894 --- a/arch/x86/kernel/apic/apic_noop.c
20895 +++ b/arch/x86/kernel/apic/apic_noop.c
20896 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20897 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20898 }
20899
20900 -struct apic apic_noop = {
20901 +struct apic apic_noop __read_only = {
20902 .name = "noop",
20903 .probe = noop_probe,
20904 .acpi_madt_oem_check = NULL,
20905 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20906 index c4a8d63..fe893ac 100644
20907 --- a/arch/x86/kernel/apic/bigsmp_32.c
20908 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20909 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20910 return dmi_bigsmp;
20911 }
20912
20913 -static struct apic apic_bigsmp = {
20914 +static struct apic apic_bigsmp __read_only = {
20915
20916 .name = "bigsmp",
20917 .probe = probe_bigsmp,
20918 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20919 index 1183d54..6158e47 100644
20920 --- a/arch/x86/kernel/apic/io_apic.c
20921 +++ b/arch/x86/kernel/apic/io_apic.c
20922 @@ -1230,7 +1230,7 @@ out:
20923 }
20924 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20925
20926 -void lock_vector_lock(void)
20927 +void lock_vector_lock(void) __acquires(vector_lock)
20928 {
20929 /* Used to the online set of cpus does not change
20930 * during assign_irq_vector.
20931 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20932 raw_spin_lock(&vector_lock);
20933 }
20934
20935 -void unlock_vector_lock(void)
20936 +void unlock_vector_lock(void) __releases(vector_lock)
20937 {
20938 raw_spin_unlock(&vector_lock);
20939 }
20940 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20941 ack_APIC_irq();
20942 }
20943
20944 -atomic_t irq_mis_count;
20945 +atomic_unchecked_t irq_mis_count;
20946
20947 #ifdef CONFIG_GENERIC_PENDING_IRQ
20948 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20949 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20950 * at the cpu.
20951 */
20952 if (!(v & (1 << (i & 0x1f)))) {
20953 - atomic_inc(&irq_mis_count);
20954 + atomic_inc_unchecked(&irq_mis_count);
20955
20956 eoi_ioapic_irq(irq, cfg);
20957 }
20958 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20959 index bda4886..f9c7195 100644
20960 --- a/arch/x86/kernel/apic/probe_32.c
20961 +++ b/arch/x86/kernel/apic/probe_32.c
20962 @@ -72,7 +72,7 @@ static int probe_default(void)
20963 return 1;
20964 }
20965
20966 -static struct apic apic_default = {
20967 +static struct apic apic_default __read_only = {
20968
20969 .name = "default",
20970 .probe = probe_default,
20971 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20972 index e658f21..b695a1a 100644
20973 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20974 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20975 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20976 return notifier_from_errno(err);
20977 }
20978
20979 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20980 +static struct notifier_block x2apic_cpu_notifier = {
20981 .notifier_call = update_clusterinfo,
20982 };
20983
20984 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20985 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20986 }
20987
20988 -static struct apic apic_x2apic_cluster = {
20989 +static struct apic apic_x2apic_cluster __read_only = {
20990
20991 .name = "cluster x2apic",
20992 .probe = x2apic_cluster_probe,
20993 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20994 index 6fae733..5ca17af 100644
20995 --- a/arch/x86/kernel/apic/x2apic_phys.c
20996 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20997 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20998 return apic == &apic_x2apic_phys;
20999 }
21000
21001 -static struct apic apic_x2apic_phys = {
21002 +static struct apic apic_x2apic_phys __read_only = {
21003
21004 .name = "physical x2apic",
21005 .probe = x2apic_phys_probe,
21006 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21007 index 8e9dcfd..c61b3e4 100644
21008 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21009 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21010 @@ -348,7 +348,7 @@ static int uv_probe(void)
21011 return apic == &apic_x2apic_uv_x;
21012 }
21013
21014 -static struct apic __refdata apic_x2apic_uv_x = {
21015 +static struct apic apic_x2apic_uv_x __read_only = {
21016
21017 .name = "UV large system",
21018 .probe = uv_probe,
21019 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21020 index 5848744..56cb598 100644
21021 --- a/arch/x86/kernel/apm_32.c
21022 +++ b/arch/x86/kernel/apm_32.c
21023 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21024 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21025 * even though they are called in protected mode.
21026 */
21027 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21028 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21029 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21030
21031 static const char driver_version[] = "1.16ac"; /* no spaces */
21032 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21033 BUG_ON(cpu != 0);
21034 gdt = get_cpu_gdt_table(cpu);
21035 save_desc_40 = gdt[0x40 / 8];
21036 +
21037 + pax_open_kernel();
21038 gdt[0x40 / 8] = bad_bios_desc;
21039 + pax_close_kernel();
21040
21041 apm_irq_save(flags);
21042 APM_DO_SAVE_SEGS;
21043 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21044 &call->esi);
21045 APM_DO_RESTORE_SEGS;
21046 apm_irq_restore(flags);
21047 +
21048 + pax_open_kernel();
21049 gdt[0x40 / 8] = save_desc_40;
21050 + pax_close_kernel();
21051 +
21052 put_cpu();
21053
21054 return call->eax & 0xff;
21055 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21056 BUG_ON(cpu != 0);
21057 gdt = get_cpu_gdt_table(cpu);
21058 save_desc_40 = gdt[0x40 / 8];
21059 +
21060 + pax_open_kernel();
21061 gdt[0x40 / 8] = bad_bios_desc;
21062 + pax_close_kernel();
21063
21064 apm_irq_save(flags);
21065 APM_DO_SAVE_SEGS;
21066 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21067 &call->eax);
21068 APM_DO_RESTORE_SEGS;
21069 apm_irq_restore(flags);
21070 +
21071 + pax_open_kernel();
21072 gdt[0x40 / 8] = save_desc_40;
21073 + pax_close_kernel();
21074 +
21075 put_cpu();
21076 return error;
21077 }
21078 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21079 * code to that CPU.
21080 */
21081 gdt = get_cpu_gdt_table(0);
21082 +
21083 + pax_open_kernel();
21084 set_desc_base(&gdt[APM_CS >> 3],
21085 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21086 set_desc_base(&gdt[APM_CS_16 >> 3],
21087 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21088 set_desc_base(&gdt[APM_DS >> 3],
21089 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21090 + pax_close_kernel();
21091
21092 proc_create("apm", 0, NULL, &apm_file_ops);
21093
21094 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21095 index 9f6b934..cf5ffb3 100644
21096 --- a/arch/x86/kernel/asm-offsets.c
21097 +++ b/arch/x86/kernel/asm-offsets.c
21098 @@ -32,6 +32,8 @@ void common(void) {
21099 OFFSET(TI_flags, thread_info, flags);
21100 OFFSET(TI_status, thread_info, status);
21101 OFFSET(TI_addr_limit, thread_info, addr_limit);
21102 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21103 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21104
21105 BLANK();
21106 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21107 @@ -52,8 +54,26 @@ void common(void) {
21108 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21109 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21110 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21111 +
21112 +#ifdef CONFIG_PAX_KERNEXEC
21113 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21114 #endif
21115
21116 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21117 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21118 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21119 +#ifdef CONFIG_X86_64
21120 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21121 +#endif
21122 +#endif
21123 +
21124 +#endif
21125 +
21126 + BLANK();
21127 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21128 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21129 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21130 +
21131 #ifdef CONFIG_XEN
21132 BLANK();
21133 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21134 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21135 index e7c798b..2b2019b 100644
21136 --- a/arch/x86/kernel/asm-offsets_64.c
21137 +++ b/arch/x86/kernel/asm-offsets_64.c
21138 @@ -77,6 +77,7 @@ int main(void)
21139 BLANK();
21140 #undef ENTRY
21141
21142 + DEFINE(TSS_size, sizeof(struct tss_struct));
21143 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21144 BLANK();
21145
21146 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21147 index 80091ae..0c5184f 100644
21148 --- a/arch/x86/kernel/cpu/Makefile
21149 +++ b/arch/x86/kernel/cpu/Makefile
21150 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21151 CFLAGS_REMOVE_perf_event.o = -pg
21152 endif
21153
21154 -# Make sure load_percpu_segment has no stackprotector
21155 -nostackp := $(call cc-option, -fno-stack-protector)
21156 -CFLAGS_common.o := $(nostackp)
21157 -
21158 obj-y := intel_cacheinfo.o scattered.o topology.o
21159 obj-y += common.o
21160 obj-y += rdrand.o
21161 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21162 index 813d29d..6e542d4 100644
21163 --- a/arch/x86/kernel/cpu/amd.c
21164 +++ b/arch/x86/kernel/cpu/amd.c
21165 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21166 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21167 {
21168 /* AMD errata T13 (order #21922) */
21169 - if ((c->x86 == 6)) {
21170 + if (c->x86 == 6) {
21171 /* Duron Rev A0 */
21172 if (c->x86_model == 3 && c->x86_mask == 0)
21173 size = 64;
21174 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21175 index cfa9b5b..19b5084 100644
21176 --- a/arch/x86/kernel/cpu/common.c
21177 +++ b/arch/x86/kernel/cpu/common.c
21178 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21179
21180 static const struct cpu_dev *this_cpu = &default_cpu;
21181
21182 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21183 -#ifdef CONFIG_X86_64
21184 - /*
21185 - * We need valid kernel segments for data and code in long mode too
21186 - * IRET will check the segment types kkeil 2000/10/28
21187 - * Also sysret mandates a special GDT layout
21188 - *
21189 - * TLS descriptors are currently at a different place compared to i386.
21190 - * Hopefully nobody expects them at a fixed place (Wine?)
21191 - */
21192 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21193 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21194 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21195 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21196 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21197 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21198 -#else
21199 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21200 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21201 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21202 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21203 - /*
21204 - * Segments used for calling PnP BIOS have byte granularity.
21205 - * They code segments and data segments have fixed 64k limits,
21206 - * the transfer segment sizes are set at run time.
21207 - */
21208 - /* 32-bit code */
21209 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21210 - /* 16-bit code */
21211 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21212 - /* 16-bit data */
21213 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21214 - /* 16-bit data */
21215 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21216 - /* 16-bit data */
21217 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21218 - /*
21219 - * The APM segments have byte granularity and their bases
21220 - * are set at run time. All have 64k limits.
21221 - */
21222 - /* 32-bit code */
21223 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21224 - /* 16-bit code */
21225 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21226 - /* data */
21227 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21228 -
21229 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21230 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21231 - GDT_STACK_CANARY_INIT
21232 -#endif
21233 -} };
21234 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21235 -
21236 static int __init x86_xsave_setup(char *s)
21237 {
21238 if (strlen(s))
21239 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21240 }
21241 }
21242
21243 +#ifdef CONFIG_X86_64
21244 +static __init int setup_disable_pcid(char *arg)
21245 +{
21246 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21247 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21248 +
21249 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21250 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21251 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21252 +#endif
21253 +
21254 + return 1;
21255 +}
21256 +__setup("nopcid", setup_disable_pcid);
21257 +
21258 +static void setup_pcid(struct cpuinfo_x86 *c)
21259 +{
21260 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21261 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21262 +
21263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21264 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21265 + pax_open_kernel();
21266 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21267 + pax_close_kernel();
21268 + printk("PAX: slow and weak UDEREF enabled\n");
21269 + } else
21270 + printk("PAX: UDEREF disabled\n");
21271 +#endif
21272 +
21273 + return;
21274 + }
21275 +
21276 + printk("PAX: PCID detected\n");
21277 + set_in_cr4(X86_CR4_PCIDE);
21278 +
21279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21280 + pax_open_kernel();
21281 + clone_pgd_mask = ~(pgdval_t)0UL;
21282 + pax_close_kernel();
21283 + if (pax_user_shadow_base)
21284 + printk("PAX: weak UDEREF enabled\n");
21285 + else {
21286 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21287 + printk("PAX: strong UDEREF enabled\n");
21288 + }
21289 +#endif
21290 +
21291 + if (cpu_has(c, X86_FEATURE_INVPCID))
21292 + printk("PAX: INVPCID detected\n");
21293 +}
21294 +#endif
21295 +
21296 /*
21297 * Some CPU features depend on higher CPUID levels, which may not always
21298 * be available due to CPUID level capping or broken virtualization
21299 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21300 {
21301 struct desc_ptr gdt_descr;
21302
21303 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21304 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21305 gdt_descr.size = GDT_SIZE - 1;
21306 load_gdt(&gdt_descr);
21307 /* Reload the per-cpu base */
21308 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21309 setup_smep(c);
21310 setup_smap(c);
21311
21312 +#ifdef CONFIG_X86_64
21313 + setup_pcid(c);
21314 +#endif
21315 +
21316 /*
21317 * The vendor-specific functions might have changed features.
21318 * Now we do "generic changes."
21319 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21320 /* Filter out anything that depends on CPUID levels we don't have */
21321 filter_cpuid_features(c, true);
21322
21323 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21324 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21325 +#endif
21326 +
21327 /* If the model name is still unset, do table lookup. */
21328 if (!c->x86_model_id[0]) {
21329 const char *p;
21330 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21331 void enable_sep_cpu(void)
21332 {
21333 int cpu = get_cpu();
21334 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21335 + struct tss_struct *tss = init_tss + cpu;
21336
21337 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21338 put_cpu();
21339 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21340 }
21341 __setup("clearcpuid=", setup_disablecpuid);
21342
21343 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21344 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21345 +
21346 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21347 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21348 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21349 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21350
21351 #ifdef CONFIG_X86_64
21352 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21353 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21354 - (unsigned long) debug_idt_table };
21355 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21356 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21357
21358 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21359 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21360 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21361 */
21362 load_ucode_ap();
21363
21364 - t = &per_cpu(init_tss, cpu);
21365 + t = init_tss + cpu;
21366 oist = &per_cpu(orig_ist, cpu);
21367
21368 #ifdef CONFIG_NUMA
21369 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21370 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21371 barrier();
21372
21373 - x86_configure_nx();
21374 enable_x2apic();
21375
21376 /*
21377 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21378 {
21379 int cpu = smp_processor_id();
21380 struct task_struct *curr = current;
21381 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21382 + struct tss_struct *t = init_tss + cpu;
21383 struct thread_struct *thread = &curr->thread;
21384
21385 wait_for_master_cpu(cpu);
21386 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21387 index c703507..28535e3 100644
21388 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21389 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21390 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21391 };
21392
21393 #ifdef CONFIG_AMD_NB
21394 +static struct attribute *default_attrs_amd_nb[] = {
21395 + &type.attr,
21396 + &level.attr,
21397 + &coherency_line_size.attr,
21398 + &physical_line_partition.attr,
21399 + &ways_of_associativity.attr,
21400 + &number_of_sets.attr,
21401 + &size.attr,
21402 + &shared_cpu_map.attr,
21403 + &shared_cpu_list.attr,
21404 + NULL,
21405 + NULL,
21406 + NULL,
21407 + NULL
21408 +};
21409 +
21410 static struct attribute **amd_l3_attrs(void)
21411 {
21412 static struct attribute **attrs;
21413 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21414
21415 n = ARRAY_SIZE(default_attrs);
21416
21417 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21418 - n += 2;
21419 -
21420 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21421 - n += 1;
21422 -
21423 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21424 - if (attrs == NULL)
21425 - return attrs = default_attrs;
21426 -
21427 - for (n = 0; default_attrs[n]; n++)
21428 - attrs[n] = default_attrs[n];
21429 + attrs = default_attrs_amd_nb;
21430
21431 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21432 attrs[n++] = &cache_disable_0.attr;
21433 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21434 .default_attrs = default_attrs,
21435 };
21436
21437 +#ifdef CONFIG_AMD_NB
21438 +static struct kobj_type ktype_cache_amd_nb = {
21439 + .sysfs_ops = &sysfs_ops,
21440 + .default_attrs = default_attrs_amd_nb,
21441 +};
21442 +#endif
21443 +
21444 static struct kobj_type ktype_percpu_entry = {
21445 .sysfs_ops = &sysfs_ops,
21446 };
21447 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21448 return retval;
21449 }
21450
21451 +#ifdef CONFIG_AMD_NB
21452 + amd_l3_attrs();
21453 +#endif
21454 +
21455 for (i = 0; i < num_cache_leaves; i++) {
21456 + struct kobj_type *ktype;
21457 +
21458 this_object = INDEX_KOBJECT_PTR(cpu, i);
21459 this_object->cpu = cpu;
21460 this_object->index = i;
21461
21462 this_leaf = CPUID4_INFO_IDX(cpu, i);
21463
21464 - ktype_cache.default_attrs = default_attrs;
21465 + ktype = &ktype_cache;
21466 #ifdef CONFIG_AMD_NB
21467 if (this_leaf->base.nb)
21468 - ktype_cache.default_attrs = amd_l3_attrs();
21469 + ktype = &ktype_cache_amd_nb;
21470 #endif
21471 retval = kobject_init_and_add(&(this_object->kobj),
21472 - &ktype_cache,
21473 + ktype,
21474 per_cpu(ici_cache_kobject, cpu),
21475 "index%1lu", i);
21476 if (unlikely(retval)) {
21477 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21478 index 61a9668ce..b446a37 100644
21479 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21480 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21481 @@ -45,6 +45,7 @@
21482 #include <asm/processor.h>
21483 #include <asm/mce.h>
21484 #include <asm/msr.h>
21485 +#include <asm/local.h>
21486
21487 #include "mce-internal.h"
21488
21489 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21490 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21491 m->cs, m->ip);
21492
21493 - if (m->cs == __KERNEL_CS)
21494 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21495 print_symbol("{%s}", m->ip);
21496 pr_cont("\n");
21497 }
21498 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21499
21500 #define PANIC_TIMEOUT 5 /* 5 seconds */
21501
21502 -static atomic_t mce_paniced;
21503 +static atomic_unchecked_t mce_paniced;
21504
21505 static int fake_panic;
21506 -static atomic_t mce_fake_paniced;
21507 +static atomic_unchecked_t mce_fake_paniced;
21508
21509 /* Panic in progress. Enable interrupts and wait for final IPI */
21510 static void wait_for_panic(void)
21511 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21512 /*
21513 * Make sure only one CPU runs in machine check panic
21514 */
21515 - if (atomic_inc_return(&mce_paniced) > 1)
21516 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21517 wait_for_panic();
21518 barrier();
21519
21520 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21521 console_verbose();
21522 } else {
21523 /* Don't log too much for fake panic */
21524 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21525 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21526 return;
21527 }
21528 /* First print corrected ones that are still unlogged */
21529 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21530 if (!fake_panic) {
21531 if (panic_timeout == 0)
21532 panic_timeout = mca_cfg.panic_timeout;
21533 - panic(msg);
21534 + panic("%s", msg);
21535 } else
21536 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21537 }
21538 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21539 * might have been modified by someone else.
21540 */
21541 rmb();
21542 - if (atomic_read(&mce_paniced))
21543 + if (atomic_read_unchecked(&mce_paniced))
21544 wait_for_panic();
21545 if (!mca_cfg.monarch_timeout)
21546 goto out;
21547 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21548 }
21549
21550 /* Call the installed machine check handler for this CPU setup. */
21551 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21552 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21553 unexpected_machine_check;
21554
21555 /*
21556 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21557 return;
21558 }
21559
21560 + pax_open_kernel();
21561 machine_check_vector = do_machine_check;
21562 + pax_close_kernel();
21563
21564 __mcheck_cpu_init_generic();
21565 __mcheck_cpu_init_vendor(c);
21566 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21567 */
21568
21569 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21570 -static int mce_chrdev_open_count; /* #times opened */
21571 +static local_t mce_chrdev_open_count; /* #times opened */
21572 static int mce_chrdev_open_exclu; /* already open exclusive? */
21573
21574 static int mce_chrdev_open(struct inode *inode, struct file *file)
21575 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21576 spin_lock(&mce_chrdev_state_lock);
21577
21578 if (mce_chrdev_open_exclu ||
21579 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21580 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21581 spin_unlock(&mce_chrdev_state_lock);
21582
21583 return -EBUSY;
21584 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21585
21586 if (file->f_flags & O_EXCL)
21587 mce_chrdev_open_exclu = 1;
21588 - mce_chrdev_open_count++;
21589 + local_inc(&mce_chrdev_open_count);
21590
21591 spin_unlock(&mce_chrdev_state_lock);
21592
21593 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21594 {
21595 spin_lock(&mce_chrdev_state_lock);
21596
21597 - mce_chrdev_open_count--;
21598 + local_dec(&mce_chrdev_open_count);
21599 mce_chrdev_open_exclu = 0;
21600
21601 spin_unlock(&mce_chrdev_state_lock);
21602 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21603
21604 for (i = 0; i < mca_cfg.banks; i++) {
21605 struct mce_bank *b = &mce_banks[i];
21606 - struct device_attribute *a = &b->attr;
21607 + device_attribute_no_const *a = &b->attr;
21608
21609 sysfs_attr_init(&a->attr);
21610 a->attr.name = b->attrname;
21611 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21612 static void mce_reset(void)
21613 {
21614 cpu_missing = 0;
21615 - atomic_set(&mce_fake_paniced, 0);
21616 + atomic_set_unchecked(&mce_fake_paniced, 0);
21617 atomic_set(&mce_executing, 0);
21618 atomic_set(&mce_callin, 0);
21619 atomic_set(&global_nwo, 0);
21620 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21621 index a304298..49b6d06 100644
21622 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21623 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21624 @@ -10,6 +10,7 @@
21625 #include <asm/processor.h>
21626 #include <asm/mce.h>
21627 #include <asm/msr.h>
21628 +#include <asm/pgtable.h>
21629
21630 /* By default disabled */
21631 int mce_p5_enabled __read_mostly;
21632 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21633 if (!cpu_has(c, X86_FEATURE_MCE))
21634 return;
21635
21636 + pax_open_kernel();
21637 machine_check_vector = pentium_machine_check;
21638 + pax_close_kernel();
21639 /* Make sure the vector pointer is visible before we enable MCEs: */
21640 wmb();
21641
21642 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21643 index 7dc5564..1273569 100644
21644 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21645 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21646 @@ -9,6 +9,7 @@
21647 #include <asm/processor.h>
21648 #include <asm/mce.h>
21649 #include <asm/msr.h>
21650 +#include <asm/pgtable.h>
21651
21652 /* Machine check handler for WinChip C6: */
21653 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21654 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21655 {
21656 u32 lo, hi;
21657
21658 + pax_open_kernel();
21659 machine_check_vector = winchip_machine_check;
21660 + pax_close_kernel();
21661 /* Make sure the vector pointer is visible before we enable MCEs: */
21662 wmb();
21663
21664 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21665 index 15c2909..2cef20c 100644
21666 --- a/arch/x86/kernel/cpu/microcode/core.c
21667 +++ b/arch/x86/kernel/cpu/microcode/core.c
21668 @@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21669 return NOTIFY_OK;
21670 }
21671
21672 -static struct notifier_block __refdata mc_cpu_notifier = {
21673 +static struct notifier_block mc_cpu_notifier = {
21674 .notifier_call = mc_cpu_callback,
21675 };
21676
21677 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21678 index c6826d1..ad18e14a 100644
21679 --- a/arch/x86/kernel/cpu/microcode/intel.c
21680 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21681 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21682
21683 static int get_ucode_user(void *to, const void *from, size_t n)
21684 {
21685 - return copy_from_user(to, from, n);
21686 + return copy_from_user(to, (const void __force_user *)from, n);
21687 }
21688
21689 static enum ucode_state
21690 request_microcode_user(int cpu, const void __user *buf, size_t size)
21691 {
21692 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21693 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21694 }
21695
21696 static void microcode_fini_cpu(int cpu)
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 944bf01..4a4392f 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 d64f275..26522ff 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..a20c62c 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 @@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
22222
22223 return ud2 == 0x0b0f;
22224 }
22225 +
22226 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22227 +void pax_check_alloca(unsigned long size)
22228 +{
22229 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22230 + unsigned cpu, used;
22231 + char *id;
22232 +
22233 + /* check the process stack first */
22234 + stack_start = (unsigned long)task_stack_page(current);
22235 + stack_end = stack_start + THREAD_SIZE;
22236 + if (likely(stack_start <= sp && sp < stack_end)) {
22237 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22238 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22239 + return;
22240 + }
22241 +
22242 + cpu = get_cpu();
22243 +
22244 + /* check the irq stacks */
22245 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22246 + stack_start = stack_end - IRQ_STACK_SIZE;
22247 + if (stack_start <= sp && sp < stack_end) {
22248 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22249 + put_cpu();
22250 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22251 + return;
22252 + }
22253 +
22254 + /* check the exception stacks */
22255 + used = 0;
22256 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22257 + stack_start = stack_end - EXCEPTION_STKSZ;
22258 + if (stack_end && stack_start <= sp && sp < stack_end) {
22259 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22260 + put_cpu();
22261 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22262 + return;
22263 + }
22264 +
22265 + put_cpu();
22266 +
22267 + /* unknown stack */
22268 + BUG();
22269 +}
22270 +EXPORT_SYMBOL(pax_check_alloca);
22271 +#endif
22272 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22273 index 49f8864..1cc6d07 100644
22274 --- a/arch/x86/kernel/e820.c
22275 +++ b/arch/x86/kernel/e820.c
22276 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22277
22278 static void early_panic(char *msg)
22279 {
22280 - early_printk(msg);
22281 - panic(msg);
22282 + early_printk("%s", msg);
22283 + panic("%s", msg);
22284 }
22285
22286 static int userdef __initdata;
22287 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22288 index 01d1c18..8073693 100644
22289 --- a/arch/x86/kernel/early_printk.c
22290 +++ b/arch/x86/kernel/early_printk.c
22291 @@ -7,6 +7,7 @@
22292 #include <linux/pci_regs.h>
22293 #include <linux/pci_ids.h>
22294 #include <linux/errno.h>
22295 +#include <linux/sched.h>
22296 #include <asm/io.h>
22297 #include <asm/processor.h>
22298 #include <asm/fcntl.h>
22299 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22300 index 344b63f..55adf14 100644
22301 --- a/arch/x86/kernel/entry_32.S
22302 +++ b/arch/x86/kernel/entry_32.S
22303 @@ -177,13 +177,154 @@
22304 /*CFI_REL_OFFSET gs, PT_GS*/
22305 .endm
22306 .macro SET_KERNEL_GS reg
22307 +
22308 +#ifdef CONFIG_CC_STACKPROTECTOR
22309 movl $(__KERNEL_STACK_CANARY), \reg
22310 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22311 + movl $(__USER_DS), \reg
22312 +#else
22313 + xorl \reg, \reg
22314 +#endif
22315 +
22316 movl \reg, %gs
22317 .endm
22318
22319 #endif /* CONFIG_X86_32_LAZY_GS */
22320
22321 -.macro SAVE_ALL
22322 +.macro pax_enter_kernel
22323 +#ifdef CONFIG_PAX_KERNEXEC
22324 + call pax_enter_kernel
22325 +#endif
22326 +.endm
22327 +
22328 +.macro pax_exit_kernel
22329 +#ifdef CONFIG_PAX_KERNEXEC
22330 + call pax_exit_kernel
22331 +#endif
22332 +.endm
22333 +
22334 +#ifdef CONFIG_PAX_KERNEXEC
22335 +ENTRY(pax_enter_kernel)
22336 +#ifdef CONFIG_PARAVIRT
22337 + pushl %eax
22338 + pushl %ecx
22339 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22340 + mov %eax, %esi
22341 +#else
22342 + mov %cr0, %esi
22343 +#endif
22344 + bts $16, %esi
22345 + jnc 1f
22346 + mov %cs, %esi
22347 + cmp $__KERNEL_CS, %esi
22348 + jz 3f
22349 + ljmp $__KERNEL_CS, $3f
22350 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22351 +2:
22352 +#ifdef CONFIG_PARAVIRT
22353 + mov %esi, %eax
22354 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22355 +#else
22356 + mov %esi, %cr0
22357 +#endif
22358 +3:
22359 +#ifdef CONFIG_PARAVIRT
22360 + popl %ecx
22361 + popl %eax
22362 +#endif
22363 + ret
22364 +ENDPROC(pax_enter_kernel)
22365 +
22366 +ENTRY(pax_exit_kernel)
22367 +#ifdef CONFIG_PARAVIRT
22368 + pushl %eax
22369 + pushl %ecx
22370 +#endif
22371 + mov %cs, %esi
22372 + cmp $__KERNEXEC_KERNEL_CS, %esi
22373 + jnz 2f
22374 +#ifdef CONFIG_PARAVIRT
22375 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22376 + mov %eax, %esi
22377 +#else
22378 + mov %cr0, %esi
22379 +#endif
22380 + btr $16, %esi
22381 + ljmp $__KERNEL_CS, $1f
22382 +1:
22383 +#ifdef CONFIG_PARAVIRT
22384 + mov %esi, %eax
22385 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22386 +#else
22387 + mov %esi, %cr0
22388 +#endif
22389 +2:
22390 +#ifdef CONFIG_PARAVIRT
22391 + popl %ecx
22392 + popl %eax
22393 +#endif
22394 + ret
22395 +ENDPROC(pax_exit_kernel)
22396 +#endif
22397 +
22398 + .macro pax_erase_kstack
22399 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22400 + call pax_erase_kstack
22401 +#endif
22402 + .endm
22403 +
22404 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22405 +/*
22406 + * ebp: thread_info
22407 + */
22408 +ENTRY(pax_erase_kstack)
22409 + pushl %edi
22410 + pushl %ecx
22411 + pushl %eax
22412 +
22413 + mov TI_lowest_stack(%ebp), %edi
22414 + mov $-0xBEEF, %eax
22415 + std
22416 +
22417 +1: mov %edi, %ecx
22418 + and $THREAD_SIZE_asm - 1, %ecx
22419 + shr $2, %ecx
22420 + repne scasl
22421 + jecxz 2f
22422 +
22423 + cmp $2*16, %ecx
22424 + jc 2f
22425 +
22426 + mov $2*16, %ecx
22427 + repe scasl
22428 + jecxz 2f
22429 + jne 1b
22430 +
22431 +2: cld
22432 + or $2*4, %edi
22433 + mov %esp, %ecx
22434 + sub %edi, %ecx
22435 +
22436 + cmp $THREAD_SIZE_asm, %ecx
22437 + jb 3f
22438 + ud2
22439 +3:
22440 +
22441 + shr $2, %ecx
22442 + rep stosl
22443 +
22444 + mov TI_task_thread_sp0(%ebp), %edi
22445 + sub $128, %edi
22446 + mov %edi, TI_lowest_stack(%ebp)
22447 +
22448 + popl %eax
22449 + popl %ecx
22450 + popl %edi
22451 + ret
22452 +ENDPROC(pax_erase_kstack)
22453 +#endif
22454 +
22455 +.macro __SAVE_ALL _DS
22456 cld
22457 PUSH_GS
22458 pushl_cfi %fs
22459 @@ -206,7 +347,7 @@
22460 CFI_REL_OFFSET ecx, 0
22461 pushl_cfi %ebx
22462 CFI_REL_OFFSET ebx, 0
22463 - movl $(__USER_DS), %edx
22464 + movl $\_DS, %edx
22465 movl %edx, %ds
22466 movl %edx, %es
22467 movl $(__KERNEL_PERCPU), %edx
22468 @@ -214,6 +355,15 @@
22469 SET_KERNEL_GS %edx
22470 .endm
22471
22472 +.macro SAVE_ALL
22473 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22474 + __SAVE_ALL __KERNEL_DS
22475 + pax_enter_kernel
22476 +#else
22477 + __SAVE_ALL __USER_DS
22478 +#endif
22479 +.endm
22480 +
22481 .macro RESTORE_INT_REGS
22482 popl_cfi %ebx
22483 CFI_RESTORE ebx
22484 @@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22485 popfl_cfi
22486 jmp syscall_exit
22487 CFI_ENDPROC
22488 -END(ret_from_fork)
22489 +ENDPROC(ret_from_fork)
22490
22491 ENTRY(ret_from_kernel_thread)
22492 CFI_STARTPROC
22493 @@ -340,7 +490,15 @@ ret_from_intr:
22494 andl $SEGMENT_RPL_MASK, %eax
22495 #endif
22496 cmpl $USER_RPL, %eax
22497 +
22498 +#ifdef CONFIG_PAX_KERNEXEC
22499 + jae resume_userspace
22500 +
22501 + pax_exit_kernel
22502 + jmp resume_kernel
22503 +#else
22504 jb resume_kernel # not returning to v8086 or userspace
22505 +#endif
22506
22507 ENTRY(resume_userspace)
22508 LOCKDEP_SYS_EXIT
22509 @@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22510 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22511 # int/exception return?
22512 jne work_pending
22513 - jmp restore_all
22514 -END(ret_from_exception)
22515 + jmp restore_all_pax
22516 +ENDPROC(ret_from_exception)
22517
22518 #ifdef CONFIG_PREEMPT
22519 ENTRY(resume_kernel)
22520 @@ -365,7 +523,7 @@ need_resched:
22521 jz restore_all
22522 call preempt_schedule_irq
22523 jmp need_resched
22524 -END(resume_kernel)
22525 +ENDPROC(resume_kernel)
22526 #endif
22527 CFI_ENDPROC
22528
22529 @@ -395,30 +553,45 @@ sysenter_past_esp:
22530 /*CFI_REL_OFFSET cs, 0*/
22531 /*
22532 * Push current_thread_info()->sysenter_return to the stack.
22533 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22534 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22535 */
22536 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22537 + pushl_cfi $0
22538 CFI_REL_OFFSET eip, 0
22539
22540 pushl_cfi %eax
22541 SAVE_ALL
22542 + GET_THREAD_INFO(%ebp)
22543 + movl TI_sysenter_return(%ebp),%ebp
22544 + movl %ebp,PT_EIP(%esp)
22545 ENABLE_INTERRUPTS(CLBR_NONE)
22546
22547 /*
22548 * Load the potential sixth argument from user stack.
22549 * Careful about security.
22550 */
22551 + movl PT_OLDESP(%esp),%ebp
22552 +
22553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22554 + mov PT_OLDSS(%esp),%ds
22555 +1: movl %ds:(%ebp),%ebp
22556 + push %ss
22557 + pop %ds
22558 +#else
22559 cmpl $__PAGE_OFFSET-3,%ebp
22560 jae syscall_fault
22561 ASM_STAC
22562 1: movl (%ebp),%ebp
22563 ASM_CLAC
22564 +#endif
22565 +
22566 movl %ebp,PT_EBP(%esp)
22567 _ASM_EXTABLE(1b,syscall_fault)
22568
22569 GET_THREAD_INFO(%ebp)
22570
22571 +#ifdef CONFIG_PAX_RANDKSTACK
22572 + pax_erase_kstack
22573 +#endif
22574 +
22575 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22576 jnz sysenter_audit
22577 sysenter_do_call:
22578 @@ -434,12 +607,24 @@ sysenter_after_call:
22579 testl $_TIF_ALLWORK_MASK, %ecx
22580 jne sysexit_audit
22581 sysenter_exit:
22582 +
22583 +#ifdef CONFIG_PAX_RANDKSTACK
22584 + pushl_cfi %eax
22585 + movl %esp, %eax
22586 + call pax_randomize_kstack
22587 + popl_cfi %eax
22588 +#endif
22589 +
22590 + pax_erase_kstack
22591 +
22592 /* if something modifies registers it must also disable sysexit */
22593 movl PT_EIP(%esp), %edx
22594 movl PT_OLDESP(%esp), %ecx
22595 xorl %ebp,%ebp
22596 TRACE_IRQS_ON
22597 1: mov PT_FS(%esp), %fs
22598 +2: mov PT_DS(%esp), %ds
22599 +3: mov PT_ES(%esp), %es
22600 PTGS_TO_GS
22601 ENABLE_INTERRUPTS_SYSEXIT
22602
22603 @@ -453,6 +638,9 @@ sysenter_audit:
22604 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22605 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22606 call __audit_syscall_entry
22607 +
22608 + pax_erase_kstack
22609 +
22610 popl_cfi %ecx /* get that remapped edx off the stack */
22611 popl_cfi %ecx /* get that remapped esi off the stack */
22612 movl PT_EAX(%esp),%eax /* reload syscall number */
22613 @@ -479,10 +667,16 @@ sysexit_audit:
22614
22615 CFI_ENDPROC
22616 .pushsection .fixup,"ax"
22617 -2: movl $0,PT_FS(%esp)
22618 +4: movl $0,PT_FS(%esp)
22619 + jmp 1b
22620 +5: movl $0,PT_DS(%esp)
22621 + jmp 1b
22622 +6: movl $0,PT_ES(%esp)
22623 jmp 1b
22624 .popsection
22625 - _ASM_EXTABLE(1b,2b)
22626 + _ASM_EXTABLE(1b,4b)
22627 + _ASM_EXTABLE(2b,5b)
22628 + _ASM_EXTABLE(3b,6b)
22629 PTGS_TO_GS_EX
22630 ENDPROC(ia32_sysenter_target)
22631
22632 @@ -493,6 +687,11 @@ ENTRY(system_call)
22633 pushl_cfi %eax # save orig_eax
22634 SAVE_ALL
22635 GET_THREAD_INFO(%ebp)
22636 +
22637 +#ifdef CONFIG_PAX_RANDKSTACK
22638 + pax_erase_kstack
22639 +#endif
22640 +
22641 # system call tracing in operation / emulation
22642 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22643 jnz syscall_trace_entry
22644 @@ -512,6 +711,15 @@ syscall_exit:
22645 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22646 jne syscall_exit_work
22647
22648 +restore_all_pax:
22649 +
22650 +#ifdef CONFIG_PAX_RANDKSTACK
22651 + movl %esp, %eax
22652 + call pax_randomize_kstack
22653 +#endif
22654 +
22655 + pax_erase_kstack
22656 +
22657 restore_all:
22658 TRACE_IRQS_IRET
22659 restore_all_notrace:
22660 @@ -566,14 +774,34 @@ ldt_ss:
22661 * compensating for the offset by changing to the ESPFIX segment with
22662 * a base address that matches for the difference.
22663 */
22664 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22665 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22666 mov %esp, %edx /* load kernel esp */
22667 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22668 mov %dx, %ax /* eax: new kernel esp */
22669 sub %eax, %edx /* offset (low word is 0) */
22670 +#ifdef CONFIG_SMP
22671 + movl PER_CPU_VAR(cpu_number), %ebx
22672 + shll $PAGE_SHIFT_asm, %ebx
22673 + addl $cpu_gdt_table, %ebx
22674 +#else
22675 + movl $cpu_gdt_table, %ebx
22676 +#endif
22677 shr $16, %edx
22678 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22679 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22680 +
22681 +#ifdef CONFIG_PAX_KERNEXEC
22682 + mov %cr0, %esi
22683 + btr $16, %esi
22684 + mov %esi, %cr0
22685 +#endif
22686 +
22687 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22688 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22689 +
22690 +#ifdef CONFIG_PAX_KERNEXEC
22691 + bts $16, %esi
22692 + mov %esi, %cr0
22693 +#endif
22694 +
22695 pushl_cfi $__ESPFIX_SS
22696 pushl_cfi %eax /* new kernel esp */
22697 /* Disable interrupts, but do not irqtrace this section: we
22698 @@ -603,20 +831,18 @@ work_resched:
22699 movl TI_flags(%ebp), %ecx
22700 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22701 # than syscall tracing?
22702 - jz restore_all
22703 + jz restore_all_pax
22704 testb $_TIF_NEED_RESCHED, %cl
22705 jnz work_resched
22706
22707 work_notifysig: # deal with pending signals and
22708 # notify-resume requests
22709 + movl %esp, %eax
22710 #ifdef CONFIG_VM86
22711 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22712 - movl %esp, %eax
22713 jne work_notifysig_v86 # returning to kernel-space or
22714 # vm86-space
22715 1:
22716 -#else
22717 - movl %esp, %eax
22718 #endif
22719 TRACE_IRQS_ON
22720 ENABLE_INTERRUPTS(CLBR_NONE)
22721 @@ -637,7 +863,7 @@ work_notifysig_v86:
22722 movl %eax, %esp
22723 jmp 1b
22724 #endif
22725 -END(work_pending)
22726 +ENDPROC(work_pending)
22727
22728 # perform syscall exit tracing
22729 ALIGN
22730 @@ -645,11 +871,14 @@ syscall_trace_entry:
22731 movl $-ENOSYS,PT_EAX(%esp)
22732 movl %esp, %eax
22733 call syscall_trace_enter
22734 +
22735 + pax_erase_kstack
22736 +
22737 /* What it returned is what we'll actually use. */
22738 cmpl $(NR_syscalls), %eax
22739 jnae syscall_call
22740 jmp syscall_exit
22741 -END(syscall_trace_entry)
22742 +ENDPROC(syscall_trace_entry)
22743
22744 # perform syscall exit tracing
22745 ALIGN
22746 @@ -662,26 +891,30 @@ syscall_exit_work:
22747 movl %esp, %eax
22748 call syscall_trace_leave
22749 jmp resume_userspace
22750 -END(syscall_exit_work)
22751 +ENDPROC(syscall_exit_work)
22752 CFI_ENDPROC
22753
22754 RING0_INT_FRAME # can't unwind into user space anyway
22755 syscall_fault:
22756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22757 + push %ss
22758 + pop %ds
22759 +#endif
22760 ASM_CLAC
22761 GET_THREAD_INFO(%ebp)
22762 movl $-EFAULT,PT_EAX(%esp)
22763 jmp resume_userspace
22764 -END(syscall_fault)
22765 +ENDPROC(syscall_fault)
22766
22767 syscall_badsys:
22768 movl $-ENOSYS,%eax
22769 jmp syscall_after_call
22770 -END(syscall_badsys)
22771 +ENDPROC(syscall_badsys)
22772
22773 sysenter_badsys:
22774 movl $-ENOSYS,%eax
22775 jmp sysenter_after_call
22776 -END(sysenter_badsys)
22777 +ENDPROC(sysenter_badsys)
22778 CFI_ENDPROC
22779
22780 .macro FIXUP_ESPFIX_STACK
22781 @@ -694,8 +927,15 @@ END(sysenter_badsys)
22782 */
22783 #ifdef CONFIG_X86_ESPFIX32
22784 /* fixup the stack */
22785 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22786 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22787 +#ifdef CONFIG_SMP
22788 + movl PER_CPU_VAR(cpu_number), %ebx
22789 + shll $PAGE_SHIFT_asm, %ebx
22790 + addl $cpu_gdt_table, %ebx
22791 +#else
22792 + movl $cpu_gdt_table, %ebx
22793 +#endif
22794 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22795 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22796 shl $16, %eax
22797 addl %esp, %eax /* the adjusted stack pointer */
22798 pushl_cfi $__KERNEL_DS
22799 @@ -751,7 +991,7 @@ vector=vector+1
22800 .endr
22801 2: jmp common_interrupt
22802 .endr
22803 -END(irq_entries_start)
22804 +ENDPROC(irq_entries_start)
22805
22806 .previous
22807 END(interrupt)
22808 @@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22809 pushl_cfi $do_coprocessor_error
22810 jmp error_code
22811 CFI_ENDPROC
22812 -END(coprocessor_error)
22813 +ENDPROC(coprocessor_error)
22814
22815 ENTRY(simd_coprocessor_error)
22816 RING0_INT_FRAME
22817 @@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22818 .section .altinstructions,"a"
22819 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22820 .previous
22821 -.section .altinstr_replacement,"ax"
22822 +.section .altinstr_replacement,"a"
22823 663: pushl $do_simd_coprocessor_error
22824 664:
22825 .previous
22826 @@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22827 #endif
22828 jmp error_code
22829 CFI_ENDPROC
22830 -END(simd_coprocessor_error)
22831 +ENDPROC(simd_coprocessor_error)
22832
22833 ENTRY(device_not_available)
22834 RING0_INT_FRAME
22835 @@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22836 pushl_cfi $do_device_not_available
22837 jmp error_code
22838 CFI_ENDPROC
22839 -END(device_not_available)
22840 +ENDPROC(device_not_available)
22841
22842 #ifdef CONFIG_PARAVIRT
22843 ENTRY(native_iret)
22844 iret
22845 _ASM_EXTABLE(native_iret, iret_exc)
22846 -END(native_iret)
22847 +ENDPROC(native_iret)
22848
22849 ENTRY(native_irq_enable_sysexit)
22850 sti
22851 sysexit
22852 -END(native_irq_enable_sysexit)
22853 +ENDPROC(native_irq_enable_sysexit)
22854 #endif
22855
22856 ENTRY(overflow)
22857 @@ -860,7 +1100,7 @@ ENTRY(overflow)
22858 pushl_cfi $do_overflow
22859 jmp error_code
22860 CFI_ENDPROC
22861 -END(overflow)
22862 +ENDPROC(overflow)
22863
22864 ENTRY(bounds)
22865 RING0_INT_FRAME
22866 @@ -869,7 +1109,7 @@ ENTRY(bounds)
22867 pushl_cfi $do_bounds
22868 jmp error_code
22869 CFI_ENDPROC
22870 -END(bounds)
22871 +ENDPROC(bounds)
22872
22873 ENTRY(invalid_op)
22874 RING0_INT_FRAME
22875 @@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22876 pushl_cfi $do_invalid_op
22877 jmp error_code
22878 CFI_ENDPROC
22879 -END(invalid_op)
22880 +ENDPROC(invalid_op)
22881
22882 ENTRY(coprocessor_segment_overrun)
22883 RING0_INT_FRAME
22884 @@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22885 pushl_cfi $do_coprocessor_segment_overrun
22886 jmp error_code
22887 CFI_ENDPROC
22888 -END(coprocessor_segment_overrun)
22889 +ENDPROC(coprocessor_segment_overrun)
22890
22891 ENTRY(invalid_TSS)
22892 RING0_EC_FRAME
22893 @@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22894 pushl_cfi $do_invalid_TSS
22895 jmp error_code
22896 CFI_ENDPROC
22897 -END(invalid_TSS)
22898 +ENDPROC(invalid_TSS)
22899
22900 ENTRY(segment_not_present)
22901 RING0_EC_FRAME
22902 @@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22903 pushl_cfi $do_segment_not_present
22904 jmp error_code
22905 CFI_ENDPROC
22906 -END(segment_not_present)
22907 +ENDPROC(segment_not_present)
22908
22909 ENTRY(stack_segment)
22910 RING0_EC_FRAME
22911 @@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22912 pushl_cfi $do_stack_segment
22913 jmp error_code
22914 CFI_ENDPROC
22915 -END(stack_segment)
22916 +ENDPROC(stack_segment)
22917
22918 ENTRY(alignment_check)
22919 RING0_EC_FRAME
22920 @@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22921 pushl_cfi $do_alignment_check
22922 jmp error_code
22923 CFI_ENDPROC
22924 -END(alignment_check)
22925 +ENDPROC(alignment_check)
22926
22927 ENTRY(divide_error)
22928 RING0_INT_FRAME
22929 @@ -928,7 +1168,7 @@ ENTRY(divide_error)
22930 pushl_cfi $do_divide_error
22931 jmp error_code
22932 CFI_ENDPROC
22933 -END(divide_error)
22934 +ENDPROC(divide_error)
22935
22936 #ifdef CONFIG_X86_MCE
22937 ENTRY(machine_check)
22938 @@ -938,7 +1178,7 @@ ENTRY(machine_check)
22939 pushl_cfi machine_check_vector
22940 jmp error_code
22941 CFI_ENDPROC
22942 -END(machine_check)
22943 +ENDPROC(machine_check)
22944 #endif
22945
22946 ENTRY(spurious_interrupt_bug)
22947 @@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22948 pushl_cfi $do_spurious_interrupt_bug
22949 jmp error_code
22950 CFI_ENDPROC
22951 -END(spurious_interrupt_bug)
22952 +ENDPROC(spurious_interrupt_bug)
22953
22954 #ifdef CONFIG_XEN
22955 /* Xen doesn't set %esp to be precisely what the normal sysenter
22956 @@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22957
22958 ENTRY(mcount)
22959 ret
22960 -END(mcount)
22961 +ENDPROC(mcount)
22962
22963 ENTRY(ftrace_caller)
22964 pushl %eax
22965 @@ -1084,7 +1324,7 @@ ftrace_graph_call:
22966 .globl ftrace_stub
22967 ftrace_stub:
22968 ret
22969 -END(ftrace_caller)
22970 +ENDPROC(ftrace_caller)
22971
22972 ENTRY(ftrace_regs_caller)
22973 pushf /* push flags before compare (in cs location) */
22974 @@ -1182,7 +1422,7 @@ trace:
22975 popl %ecx
22976 popl %eax
22977 jmp ftrace_stub
22978 -END(mcount)
22979 +ENDPROC(mcount)
22980 #endif /* CONFIG_DYNAMIC_FTRACE */
22981 #endif /* CONFIG_FUNCTION_TRACER */
22982
22983 @@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
22984 popl %ecx
22985 popl %eax
22986 ret
22987 -END(ftrace_graph_caller)
22988 +ENDPROC(ftrace_graph_caller)
22989
22990 .globl return_to_handler
22991 return_to_handler:
22992 @@ -1261,15 +1501,18 @@ error_code:
22993 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22994 REG_TO_PTGS %ecx
22995 SET_KERNEL_GS %ecx
22996 - movl $(__USER_DS), %ecx
22997 + movl $(__KERNEL_DS), %ecx
22998 movl %ecx, %ds
22999 movl %ecx, %es
23000 +
23001 + pax_enter_kernel
23002 +
23003 TRACE_IRQS_OFF
23004 movl %esp,%eax # pt_regs pointer
23005 call *%edi
23006 jmp ret_from_exception
23007 CFI_ENDPROC
23008 -END(page_fault)
23009 +ENDPROC(page_fault)
23010
23011 /*
23012 * Debug traps and NMI can happen at the one SYSENTER instruction
23013 @@ -1312,7 +1555,7 @@ debug_stack_correct:
23014 call do_debug
23015 jmp ret_from_exception
23016 CFI_ENDPROC
23017 -END(debug)
23018 +ENDPROC(debug)
23019
23020 /*
23021 * NMI is doubly nasty. It can happen _while_ we're handling
23022 @@ -1352,6 +1595,9 @@ nmi_stack_correct:
23023 xorl %edx,%edx # zero error code
23024 movl %esp,%eax # pt_regs pointer
23025 call do_nmi
23026 +
23027 + pax_exit_kernel
23028 +
23029 jmp restore_all_notrace
23030 CFI_ENDPROC
23031
23032 @@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23033 FIXUP_ESPFIX_STACK # %eax == %esp
23034 xorl %edx,%edx # zero error code
23035 call do_nmi
23036 +
23037 + pax_exit_kernel
23038 +
23039 RESTORE_REGS
23040 lss 12+4(%esp), %esp # back to espfix stack
23041 CFI_ADJUST_CFA_OFFSET -24
23042 jmp irq_return
23043 #endif
23044 CFI_ENDPROC
23045 -END(nmi)
23046 +ENDPROC(nmi)
23047
23048 ENTRY(int3)
23049 RING0_INT_FRAME
23050 @@ -1408,14 +1657,14 @@ ENTRY(int3)
23051 call do_int3
23052 jmp ret_from_exception
23053 CFI_ENDPROC
23054 -END(int3)
23055 +ENDPROC(int3)
23056
23057 ENTRY(general_protection)
23058 RING0_EC_FRAME
23059 pushl_cfi $do_general_protection
23060 jmp error_code
23061 CFI_ENDPROC
23062 -END(general_protection)
23063 +ENDPROC(general_protection)
23064
23065 #ifdef CONFIG_KVM_GUEST
23066 ENTRY(async_page_fault)
23067 @@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23068 pushl_cfi $do_async_page_fault
23069 jmp error_code
23070 CFI_ENDPROC
23071 -END(async_page_fault)
23072 +ENDPROC(async_page_fault)
23073 #endif
23074
23075 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23076 index c0226ab..0d1dc48 100644
23077 --- a/arch/x86/kernel/entry_64.S
23078 +++ b/arch/x86/kernel/entry_64.S
23079 @@ -59,6 +59,8 @@
23080 #include <asm/smap.h>
23081 #include <asm/pgtable_types.h>
23082 #include <linux/err.h>
23083 +#include <asm/pgtable.h>
23084 +#include <asm/alternative-asm.h>
23085
23086 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23087 #include <linux/elf-em.h>
23088 @@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23089 ENDPROC(native_usergs_sysret64)
23090 #endif /* CONFIG_PARAVIRT */
23091
23092 + .macro ljmpq sel, off
23093 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23094 + .byte 0x48; ljmp *1234f(%rip)
23095 + .pushsection .rodata
23096 + .align 16
23097 + 1234: .quad \off; .word \sel
23098 + .popsection
23099 +#else
23100 + pushq $\sel
23101 + pushq $\off
23102 + lretq
23103 +#endif
23104 + .endm
23105 +
23106 + .macro pax_enter_kernel
23107 + pax_set_fptr_mask
23108 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23109 + call pax_enter_kernel
23110 +#endif
23111 + .endm
23112 +
23113 + .macro pax_exit_kernel
23114 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23115 + call pax_exit_kernel
23116 +#endif
23117 +
23118 + .endm
23119 +
23120 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23121 +ENTRY(pax_enter_kernel)
23122 + pushq %rdi
23123 +
23124 +#ifdef CONFIG_PARAVIRT
23125 + PV_SAVE_REGS(CLBR_RDI)
23126 +#endif
23127 +
23128 +#ifdef CONFIG_PAX_KERNEXEC
23129 + GET_CR0_INTO_RDI
23130 + bts $16,%rdi
23131 + jnc 3f
23132 + mov %cs,%edi
23133 + cmp $__KERNEL_CS,%edi
23134 + jnz 2f
23135 +1:
23136 +#endif
23137 +
23138 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23139 + 661: jmp 111f
23140 + .pushsection .altinstr_replacement, "a"
23141 + 662: ASM_NOP2
23142 + .popsection
23143 + .pushsection .altinstructions, "a"
23144 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23145 + .popsection
23146 + GET_CR3_INTO_RDI
23147 + cmp $0,%dil
23148 + jnz 112f
23149 + mov $__KERNEL_DS,%edi
23150 + mov %edi,%ss
23151 + jmp 111f
23152 +112: cmp $1,%dil
23153 + jz 113f
23154 + ud2
23155 +113: sub $4097,%rdi
23156 + bts $63,%rdi
23157 + SET_RDI_INTO_CR3
23158 + mov $__UDEREF_KERNEL_DS,%edi
23159 + mov %edi,%ss
23160 +111:
23161 +#endif
23162 +
23163 +#ifdef CONFIG_PARAVIRT
23164 + PV_RESTORE_REGS(CLBR_RDI)
23165 +#endif
23166 +
23167 + popq %rdi
23168 + pax_force_retaddr
23169 + retq
23170 +
23171 +#ifdef CONFIG_PAX_KERNEXEC
23172 +2: ljmpq __KERNEL_CS,1b
23173 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23174 +4: SET_RDI_INTO_CR0
23175 + jmp 1b
23176 +#endif
23177 +ENDPROC(pax_enter_kernel)
23178 +
23179 +ENTRY(pax_exit_kernel)
23180 + pushq %rdi
23181 +
23182 +#ifdef CONFIG_PARAVIRT
23183 + PV_SAVE_REGS(CLBR_RDI)
23184 +#endif
23185 +
23186 +#ifdef CONFIG_PAX_KERNEXEC
23187 + mov %cs,%rdi
23188 + cmp $__KERNEXEC_KERNEL_CS,%edi
23189 + jz 2f
23190 + GET_CR0_INTO_RDI
23191 + bts $16,%rdi
23192 + jnc 4f
23193 +1:
23194 +#endif
23195 +
23196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23197 + 661: jmp 111f
23198 + .pushsection .altinstr_replacement, "a"
23199 + 662: ASM_NOP2
23200 + .popsection
23201 + .pushsection .altinstructions, "a"
23202 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23203 + .popsection
23204 + mov %ss,%edi
23205 + cmp $__UDEREF_KERNEL_DS,%edi
23206 + jnz 111f
23207 + GET_CR3_INTO_RDI
23208 + cmp $0,%dil
23209 + jz 112f
23210 + ud2
23211 +112: add $4097,%rdi
23212 + bts $63,%rdi
23213 + SET_RDI_INTO_CR3
23214 + mov $__KERNEL_DS,%edi
23215 + mov %edi,%ss
23216 +111:
23217 +#endif
23218 +
23219 +#ifdef CONFIG_PARAVIRT
23220 + PV_RESTORE_REGS(CLBR_RDI);
23221 +#endif
23222 +
23223 + popq %rdi
23224 + pax_force_retaddr
23225 + retq
23226 +
23227 +#ifdef CONFIG_PAX_KERNEXEC
23228 +2: GET_CR0_INTO_RDI
23229 + btr $16,%rdi
23230 + jnc 4f
23231 + ljmpq __KERNEL_CS,3f
23232 +3: SET_RDI_INTO_CR0
23233 + jmp 1b
23234 +4: ud2
23235 + jmp 4b
23236 +#endif
23237 +ENDPROC(pax_exit_kernel)
23238 +#endif
23239 +
23240 + .macro pax_enter_kernel_user
23241 + pax_set_fptr_mask
23242 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23243 + call pax_enter_kernel_user
23244 +#endif
23245 + .endm
23246 +
23247 + .macro pax_exit_kernel_user
23248 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23249 + call pax_exit_kernel_user
23250 +#endif
23251 +#ifdef CONFIG_PAX_RANDKSTACK
23252 + pushq %rax
23253 + pushq %r11
23254 + call pax_randomize_kstack
23255 + popq %r11
23256 + popq %rax
23257 +#endif
23258 + .endm
23259 +
23260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23261 +ENTRY(pax_enter_kernel_user)
23262 + pushq %rdi
23263 + pushq %rbx
23264 +
23265 +#ifdef CONFIG_PARAVIRT
23266 + PV_SAVE_REGS(CLBR_RDI)
23267 +#endif
23268 +
23269 + 661: jmp 111f
23270 + .pushsection .altinstr_replacement, "a"
23271 + 662: ASM_NOP2
23272 + .popsection
23273 + .pushsection .altinstructions, "a"
23274 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23275 + .popsection
23276 + GET_CR3_INTO_RDI
23277 + cmp $1,%dil
23278 + jnz 4f
23279 + sub $4097,%rdi
23280 + bts $63,%rdi
23281 + SET_RDI_INTO_CR3
23282 + jmp 3f
23283 +111:
23284 +
23285 + GET_CR3_INTO_RDI
23286 + mov %rdi,%rbx
23287 + add $__START_KERNEL_map,%rbx
23288 + sub phys_base(%rip),%rbx
23289 +
23290 +#ifdef CONFIG_PARAVIRT
23291 + cmpl $0, pv_info+PARAVIRT_enabled
23292 + jz 1f
23293 + pushq %rdi
23294 + i = 0
23295 + .rept USER_PGD_PTRS
23296 + mov i*8(%rbx),%rsi
23297 + mov $0,%sil
23298 + lea i*8(%rbx),%rdi
23299 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23300 + i = i + 1
23301 + .endr
23302 + popq %rdi
23303 + jmp 2f
23304 +1:
23305 +#endif
23306 +
23307 + i = 0
23308 + .rept USER_PGD_PTRS
23309 + movb $0,i*8(%rbx)
23310 + i = i + 1
23311 + .endr
23312 +
23313 +2: SET_RDI_INTO_CR3
23314 +
23315 +#ifdef CONFIG_PAX_KERNEXEC
23316 + GET_CR0_INTO_RDI
23317 + bts $16,%rdi
23318 + SET_RDI_INTO_CR0
23319 +#endif
23320 +
23321 +3:
23322 +
23323 +#ifdef CONFIG_PARAVIRT
23324 + PV_RESTORE_REGS(CLBR_RDI)
23325 +#endif
23326 +
23327 + popq %rbx
23328 + popq %rdi
23329 + pax_force_retaddr
23330 + retq
23331 +4: ud2
23332 +ENDPROC(pax_enter_kernel_user)
23333 +
23334 +ENTRY(pax_exit_kernel_user)
23335 + pushq %rdi
23336 + pushq %rbx
23337 +
23338 +#ifdef CONFIG_PARAVIRT
23339 + PV_SAVE_REGS(CLBR_RDI)
23340 +#endif
23341 +
23342 + GET_CR3_INTO_RDI
23343 + 661: jmp 1f
23344 + .pushsection .altinstr_replacement, "a"
23345 + 662: ASM_NOP2
23346 + .popsection
23347 + .pushsection .altinstructions, "a"
23348 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23349 + .popsection
23350 + cmp $0,%dil
23351 + jnz 3f
23352 + add $4097,%rdi
23353 + bts $63,%rdi
23354 + SET_RDI_INTO_CR3
23355 + jmp 2f
23356 +1:
23357 +
23358 + mov %rdi,%rbx
23359 +
23360 +#ifdef CONFIG_PAX_KERNEXEC
23361 + GET_CR0_INTO_RDI
23362 + btr $16,%rdi
23363 + jnc 3f
23364 + SET_RDI_INTO_CR0
23365 +#endif
23366 +
23367 + add $__START_KERNEL_map,%rbx
23368 + sub phys_base(%rip),%rbx
23369 +
23370 +#ifdef CONFIG_PARAVIRT
23371 + cmpl $0, pv_info+PARAVIRT_enabled
23372 + jz 1f
23373 + i = 0
23374 + .rept USER_PGD_PTRS
23375 + mov i*8(%rbx),%rsi
23376 + mov $0x67,%sil
23377 + lea i*8(%rbx),%rdi
23378 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23379 + i = i + 1
23380 + .endr
23381 + jmp 2f
23382 +1:
23383 +#endif
23384 +
23385 + i = 0
23386 + .rept USER_PGD_PTRS
23387 + movb $0x67,i*8(%rbx)
23388 + i = i + 1
23389 + .endr
23390 +2:
23391 +
23392 +#ifdef CONFIG_PARAVIRT
23393 + PV_RESTORE_REGS(CLBR_RDI)
23394 +#endif
23395 +
23396 + popq %rbx
23397 + popq %rdi
23398 + pax_force_retaddr
23399 + retq
23400 +3: ud2
23401 +ENDPROC(pax_exit_kernel_user)
23402 +#endif
23403 +
23404 + .macro pax_enter_kernel_nmi
23405 + pax_set_fptr_mask
23406 +
23407 +#ifdef CONFIG_PAX_KERNEXEC
23408 + GET_CR0_INTO_RDI
23409 + bts $16,%rdi
23410 + jc 110f
23411 + SET_RDI_INTO_CR0
23412 + or $2,%ebx
23413 +110:
23414 +#endif
23415 +
23416 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23417 + 661: jmp 111f
23418 + .pushsection .altinstr_replacement, "a"
23419 + 662: ASM_NOP2
23420 + .popsection
23421 + .pushsection .altinstructions, "a"
23422 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23423 + .popsection
23424 + GET_CR3_INTO_RDI
23425 + cmp $0,%dil
23426 + jz 111f
23427 + sub $4097,%rdi
23428 + or $4,%ebx
23429 + bts $63,%rdi
23430 + SET_RDI_INTO_CR3
23431 + mov $__UDEREF_KERNEL_DS,%edi
23432 + mov %edi,%ss
23433 +111:
23434 +#endif
23435 + .endm
23436 +
23437 + .macro pax_exit_kernel_nmi
23438 +#ifdef CONFIG_PAX_KERNEXEC
23439 + btr $1,%ebx
23440 + jnc 110f
23441 + GET_CR0_INTO_RDI
23442 + btr $16,%rdi
23443 + SET_RDI_INTO_CR0
23444 +110:
23445 +#endif
23446 +
23447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23448 + btr $2,%ebx
23449 + jnc 111f
23450 + GET_CR3_INTO_RDI
23451 + add $4097,%rdi
23452 + bts $63,%rdi
23453 + SET_RDI_INTO_CR3
23454 + mov $__KERNEL_DS,%edi
23455 + mov %edi,%ss
23456 +111:
23457 +#endif
23458 + .endm
23459 +
23460 + .macro pax_erase_kstack
23461 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23462 + call pax_erase_kstack
23463 +#endif
23464 + .endm
23465 +
23466 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23467 +ENTRY(pax_erase_kstack)
23468 + pushq %rdi
23469 + pushq %rcx
23470 + pushq %rax
23471 + pushq %r11
23472 +
23473 + GET_THREAD_INFO(%r11)
23474 + mov TI_lowest_stack(%r11), %rdi
23475 + mov $-0xBEEF, %rax
23476 + std
23477 +
23478 +1: mov %edi, %ecx
23479 + and $THREAD_SIZE_asm - 1, %ecx
23480 + shr $3, %ecx
23481 + repne scasq
23482 + jecxz 2f
23483 +
23484 + cmp $2*8, %ecx
23485 + jc 2f
23486 +
23487 + mov $2*8, %ecx
23488 + repe scasq
23489 + jecxz 2f
23490 + jne 1b
23491 +
23492 +2: cld
23493 + or $2*8, %rdi
23494 + mov %esp, %ecx
23495 + sub %edi, %ecx
23496 +
23497 + cmp $THREAD_SIZE_asm, %rcx
23498 + jb 3f
23499 + ud2
23500 +3:
23501 +
23502 + shr $3, %ecx
23503 + rep stosq
23504 +
23505 + mov TI_task_thread_sp0(%r11), %rdi
23506 + sub $256, %rdi
23507 + mov %rdi, TI_lowest_stack(%r11)
23508 +
23509 + popq %r11
23510 + popq %rax
23511 + popq %rcx
23512 + popq %rdi
23513 + pax_force_retaddr
23514 + ret
23515 +ENDPROC(pax_erase_kstack)
23516 +#endif
23517
23518 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23519 #ifdef CONFIG_TRACE_IRQFLAGS
23520 @@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23521 .endm
23522
23523 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23524 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23525 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23526 jnc 1f
23527 TRACE_IRQS_ON_DEBUG
23528 1:
23529 @@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23530 movq \tmp,R11+\offset(%rsp)
23531 .endm
23532
23533 - .macro FAKE_STACK_FRAME child_rip
23534 - /* push in order ss, rsp, eflags, cs, rip */
23535 - xorl %eax, %eax
23536 - pushq_cfi $__KERNEL_DS /* ss */
23537 - /*CFI_REL_OFFSET ss,0*/
23538 - pushq_cfi %rax /* rsp */
23539 - CFI_REL_OFFSET rsp,0
23540 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23541 - /*CFI_REL_OFFSET rflags,0*/
23542 - pushq_cfi $__KERNEL_CS /* cs */
23543 - /*CFI_REL_OFFSET cs,0*/
23544 - pushq_cfi \child_rip /* rip */
23545 - CFI_REL_OFFSET rip,0
23546 - pushq_cfi %rax /* orig rax */
23547 - .endm
23548 -
23549 - .macro UNFAKE_STACK_FRAME
23550 - addq $8*6, %rsp
23551 - CFI_ADJUST_CFA_OFFSET -(6*8)
23552 - .endm
23553 -
23554 /*
23555 * initial frame state for interrupts (and exceptions without error code)
23556 */
23557 @@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23558 /* save partial stack frame */
23559 .macro SAVE_ARGS_IRQ
23560 cld
23561 - /* start from rbp in pt_regs and jump over */
23562 - movq_cfi rdi, (RDI-RBP)
23563 - movq_cfi rsi, (RSI-RBP)
23564 - movq_cfi rdx, (RDX-RBP)
23565 - movq_cfi rcx, (RCX-RBP)
23566 - movq_cfi rax, (RAX-RBP)
23567 - movq_cfi r8, (R8-RBP)
23568 - movq_cfi r9, (R9-RBP)
23569 - movq_cfi r10, (R10-RBP)
23570 - movq_cfi r11, (R11-RBP)
23571 + /* start from r15 in pt_regs and jump over */
23572 + movq_cfi rdi, RDI
23573 + movq_cfi rsi, RSI
23574 + movq_cfi rdx, RDX
23575 + movq_cfi rcx, RCX
23576 + movq_cfi rax, RAX
23577 + movq_cfi r8, R8
23578 + movq_cfi r9, R9
23579 + movq_cfi r10, R10
23580 + movq_cfi r11, R11
23581 + movq_cfi r12, R12
23582
23583 /* Save rbp so that we can unwind from get_irq_regs() */
23584 - movq_cfi rbp, 0
23585 + movq_cfi rbp, RBP
23586
23587 /* Save previous stack value */
23588 movq %rsp, %rsi
23589
23590 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23591 - testl $3, CS-RBP(%rsi)
23592 + movq %rsp,%rdi /* arg1 for handler */
23593 + testb $3, CS(%rsi)
23594 je 1f
23595 SWAPGS
23596 /*
23597 @@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23598 0x06 /* DW_OP_deref */, \
23599 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23600 0x22 /* DW_OP_plus */
23601 +
23602 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23603 + testb $3, CS(%rdi)
23604 + jnz 1f
23605 + pax_enter_kernel
23606 + jmp 2f
23607 +1: pax_enter_kernel_user
23608 +2:
23609 +#else
23610 + pax_enter_kernel
23611 +#endif
23612 +
23613 /* We entered an interrupt context - irqs are off: */
23614 TRACE_IRQS_OFF
23615 .endm
23616 @@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23617 js 1f /* negative -> in kernel */
23618 SWAPGS
23619 xorl %ebx,%ebx
23620 -1: ret
23621 +1:
23622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23623 + testb $3, CS+8(%rsp)
23624 + jnz 1f
23625 + pax_enter_kernel
23626 + jmp 2f
23627 +1: pax_enter_kernel_user
23628 +2:
23629 +#else
23630 + pax_enter_kernel
23631 +#endif
23632 + pax_force_retaddr
23633 + ret
23634 CFI_ENDPROC
23635 -END(save_paranoid)
23636 +ENDPROC(save_paranoid)
23637 +
23638 +ENTRY(save_paranoid_nmi)
23639 + XCPT_FRAME 1 RDI+8
23640 + cld
23641 + movq_cfi rdi, RDI+8
23642 + movq_cfi rsi, RSI+8
23643 + movq_cfi rdx, RDX+8
23644 + movq_cfi rcx, RCX+8
23645 + movq_cfi rax, RAX+8
23646 + movq_cfi r8, R8+8
23647 + movq_cfi r9, R9+8
23648 + movq_cfi r10, R10+8
23649 + movq_cfi r11, R11+8
23650 + movq_cfi rbx, RBX+8
23651 + movq_cfi rbp, RBP+8
23652 + movq_cfi r12, R12+8
23653 + movq_cfi r13, R13+8
23654 + movq_cfi r14, R14+8
23655 + movq_cfi r15, R15+8
23656 + movl $1,%ebx
23657 + movl $MSR_GS_BASE,%ecx
23658 + rdmsr
23659 + testl %edx,%edx
23660 + js 1f /* negative -> in kernel */
23661 + SWAPGS
23662 + xorl %ebx,%ebx
23663 +1: pax_enter_kernel_nmi
23664 + pax_force_retaddr
23665 + ret
23666 + CFI_ENDPROC
23667 +ENDPROC(save_paranoid_nmi)
23668
23669 /*
23670 * A newly forked process directly context switches into this address.
23671 @@ -331,7 +793,7 @@ ENTRY(ret_from_fork)
23672
23673 RESTORE_REST
23674
23675 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23676 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23677 jz 1f
23678
23679 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23680 @@ -341,15 +803,13 @@ ENTRY(ret_from_fork)
23681 jmp ret_from_sys_call # go to the SYSRET fastpath
23682
23683 1:
23684 - subq $REST_SKIP, %rsp # leave space for volatiles
23685 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23686 movq %rbp, %rdi
23687 call *%rbx
23688 movl $0, RAX(%rsp)
23689 RESTORE_REST
23690 jmp int_ret_from_sys_call
23691 CFI_ENDPROC
23692 -END(ret_from_fork)
23693 +ENDPROC(ret_from_fork)
23694
23695 /*
23696 * System call entry. Up to 6 arguments in registers are supported.
23697 @@ -386,7 +846,7 @@ END(ret_from_fork)
23698 ENTRY(system_call)
23699 CFI_STARTPROC simple
23700 CFI_SIGNAL_FRAME
23701 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23702 + CFI_DEF_CFA rsp,0
23703 CFI_REGISTER rip,rcx
23704 /*CFI_REGISTER rflags,r11*/
23705 SWAPGS_UNSAFE_STACK
23706 @@ -399,16 +859,23 @@ GLOBAL(system_call_after_swapgs)
23707
23708 movq %rsp,PER_CPU_VAR(old_rsp)
23709 movq PER_CPU_VAR(kernel_stack),%rsp
23710 + SAVE_ARGS 8*6, 0, rax_enosys=1
23711 + pax_enter_kernel_user
23712 +
23713 +#ifdef CONFIG_PAX_RANDKSTACK
23714 + pax_erase_kstack
23715 +#endif
23716 +
23717 /*
23718 * No need to follow this irqs off/on section - it's straight
23719 * and short:
23720 */
23721 ENABLE_INTERRUPTS(CLBR_NONE)
23722 - SAVE_ARGS 8, 0, rax_enosys=1
23723 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23724 movq %rcx,RIP-ARGOFFSET(%rsp)
23725 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23726 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23727 + GET_THREAD_INFO(%rcx)
23728 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23729 jnz tracesys
23730 system_call_fastpath:
23731 #if __SYSCALL_MASK == ~0
23732 @@ -432,10 +899,13 @@ sysret_check:
23733 LOCKDEP_SYS_EXIT
23734 DISABLE_INTERRUPTS(CLBR_NONE)
23735 TRACE_IRQS_OFF
23736 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23737 + GET_THREAD_INFO(%rcx)
23738 + movl TI_flags(%rcx),%edx
23739 andl %edi,%edx
23740 jnz sysret_careful
23741 CFI_REMEMBER_STATE
23742 + pax_exit_kernel_user
23743 + pax_erase_kstack
23744 /*
23745 * sysretq will re-enable interrupts:
23746 */
23747 @@ -494,12 +964,15 @@ sysret_audit:
23748
23749 /* Do syscall tracing */
23750 tracesys:
23751 - leaq -REST_SKIP(%rsp), %rdi
23752 + movq %rsp, %rdi
23753 movq $AUDIT_ARCH_X86_64, %rsi
23754 call syscall_trace_enter_phase1
23755 test %rax, %rax
23756 jnz tracesys_phase2 /* if needed, run the slow path */
23757 - LOAD_ARGS 0 /* else restore clobbered regs */
23758 +
23759 + pax_erase_kstack
23760 +
23761 + LOAD_ARGS /* else restore clobbered regs */
23762 jmp system_call_fastpath /* and return to the fast path */
23763
23764 tracesys_phase2:
23765 @@ -510,12 +983,14 @@ tracesys_phase2:
23766 movq %rax,%rdx
23767 call syscall_trace_enter_phase2
23768
23769 + pax_erase_kstack
23770 +
23771 /*
23772 * Reload arg registers from stack in case ptrace changed them.
23773 * We don't reload %rax because syscall_trace_entry_phase2() returned
23774 * the value it wants us to use in the table lookup.
23775 */
23776 - LOAD_ARGS ARGOFFSET, 1
23777 + LOAD_ARGS 1
23778 RESTORE_REST
23779 #if __SYSCALL_MASK == ~0
23780 cmpq $__NR_syscall_max,%rax
23781 @@ -545,7 +1020,9 @@ GLOBAL(int_with_check)
23782 andl %edi,%edx
23783 jnz int_careful
23784 andl $~TS_COMPAT,TI_status(%rcx)
23785 - jmp retint_swapgs
23786 + pax_exit_kernel_user
23787 + pax_erase_kstack
23788 + jmp retint_swapgs_pax
23789
23790 /* Either reschedule or signal or syscall exit tracking needed. */
23791 /* First do a reschedule test. */
23792 @@ -591,7 +1068,7 @@ int_restore_rest:
23793 TRACE_IRQS_OFF
23794 jmp int_with_check
23795 CFI_ENDPROC
23796 -END(system_call)
23797 +ENDPROC(system_call)
23798
23799 .macro FORK_LIKE func
23800 ENTRY(stub_\func)
23801 @@ -604,9 +1081,10 @@ ENTRY(stub_\func)
23802 DEFAULT_FRAME 0 8 /* offset 8: return address */
23803 call sys_\func
23804 RESTORE_TOP_OF_STACK %r11, 8
23805 - ret $REST_SKIP /* pop extended registers */
23806 + pax_force_retaddr
23807 + ret
23808 CFI_ENDPROC
23809 -END(stub_\func)
23810 +ENDPROC(stub_\func)
23811 .endm
23812
23813 .macro FIXED_FRAME label,func
23814 @@ -616,9 +1094,10 @@ ENTRY(\label)
23815 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23816 call \func
23817 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23818 + pax_force_retaddr
23819 ret
23820 CFI_ENDPROC
23821 -END(\label)
23822 +ENDPROC(\label)
23823 .endm
23824
23825 FORK_LIKE clone
23826 @@ -626,19 +1105,6 @@ END(\label)
23827 FORK_LIKE vfork
23828 FIXED_FRAME stub_iopl, sys_iopl
23829
23830 -ENTRY(ptregscall_common)
23831 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23832 - RESTORE_TOP_OF_STACK %r11, 8
23833 - movq_cfi_restore R15+8, r15
23834 - movq_cfi_restore R14+8, r14
23835 - movq_cfi_restore R13+8, r13
23836 - movq_cfi_restore R12+8, r12
23837 - movq_cfi_restore RBP+8, rbp
23838 - movq_cfi_restore RBX+8, rbx
23839 - ret $REST_SKIP /* pop extended registers */
23840 - CFI_ENDPROC
23841 -END(ptregscall_common)
23842 -
23843 ENTRY(stub_execve)
23844 CFI_STARTPROC
23845 addq $8, %rsp
23846 @@ -650,7 +1116,7 @@ ENTRY(stub_execve)
23847 RESTORE_REST
23848 jmp int_ret_from_sys_call
23849 CFI_ENDPROC
23850 -END(stub_execve)
23851 +ENDPROC(stub_execve)
23852
23853 /*
23854 * sigreturn is special because it needs to restore all registers on return.
23855 @@ -667,7 +1133,7 @@ ENTRY(stub_rt_sigreturn)
23856 RESTORE_REST
23857 jmp int_ret_from_sys_call
23858 CFI_ENDPROC
23859 -END(stub_rt_sigreturn)
23860 +ENDPROC(stub_rt_sigreturn)
23861
23862 #ifdef CONFIG_X86_X32_ABI
23863 ENTRY(stub_x32_rt_sigreturn)
23864 @@ -681,7 +1147,7 @@ ENTRY(stub_x32_rt_sigreturn)
23865 RESTORE_REST
23866 jmp int_ret_from_sys_call
23867 CFI_ENDPROC
23868 -END(stub_x32_rt_sigreturn)
23869 +ENDPROC(stub_x32_rt_sigreturn)
23870
23871 ENTRY(stub_x32_execve)
23872 CFI_STARTPROC
23873 @@ -695,7 +1161,7 @@ ENTRY(stub_x32_execve)
23874 RESTORE_REST
23875 jmp int_ret_from_sys_call
23876 CFI_ENDPROC
23877 -END(stub_x32_execve)
23878 +ENDPROC(stub_x32_execve)
23879
23880 #endif
23881
23882 @@ -732,7 +1198,7 @@ vector=vector+1
23883 2: jmp common_interrupt
23884 .endr
23885 CFI_ENDPROC
23886 -END(irq_entries_start)
23887 +ENDPROC(irq_entries_start)
23888
23889 .previous
23890 END(interrupt)
23891 @@ -749,8 +1215,8 @@ END(interrupt)
23892 /* 0(%rsp): ~(interrupt number) */
23893 .macro interrupt func
23894 /* reserve pt_regs for scratch regs and rbp */
23895 - subq $ORIG_RAX-RBP, %rsp
23896 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23897 + subq $ORIG_RAX, %rsp
23898 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23899 SAVE_ARGS_IRQ
23900 call \func
23901 .endm
23902 @@ -773,14 +1239,14 @@ ret_from_intr:
23903
23904 /* Restore saved previous stack */
23905 popq %rsi
23906 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23907 - leaq ARGOFFSET-RBP(%rsi), %rsp
23908 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23909 + movq %rsi, %rsp
23910 CFI_DEF_CFA_REGISTER rsp
23911 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23912 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23913
23914 exit_intr:
23915 GET_THREAD_INFO(%rcx)
23916 - testl $3,CS-ARGOFFSET(%rsp)
23917 + testb $3,CS-ARGOFFSET(%rsp)
23918 je retint_kernel
23919
23920 /* Interrupt came from user space */
23921 @@ -802,12 +1268,35 @@ retint_swapgs: /* return to user-space */
23922 * The iretq could re-enable interrupts:
23923 */
23924 DISABLE_INTERRUPTS(CLBR_ANY)
23925 + pax_exit_kernel_user
23926 +retint_swapgs_pax:
23927 TRACE_IRQS_IRETQ
23928 SWAPGS
23929 jmp restore_args
23930
23931 retint_restore_args: /* return to kernel space */
23932 DISABLE_INTERRUPTS(CLBR_ANY)
23933 + pax_exit_kernel
23934 +
23935 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23936 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23937 + * namely calling EFI runtime services with a phys mapping. We're
23938 + * starting off with NOPs and patch in the real instrumentation
23939 + * (BTS/OR) before starting any userland process; even before starting
23940 + * up the APs.
23941 + */
23942 + .pushsection .altinstr_replacement, "a"
23943 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23944 + 602:
23945 + .popsection
23946 + 603: .fill 602b-601b, 1, 0x90
23947 + .pushsection .altinstructions, "a"
23948 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23949 + .popsection
23950 +#else
23951 + pax_force_retaddr (RIP-ARGOFFSET)
23952 +#endif
23953 +
23954 /*
23955 * The iretq could re-enable interrupts:
23956 */
23957 @@ -845,15 +1334,15 @@ native_irq_return_ldt:
23958 SWAPGS
23959 movq PER_CPU_VAR(espfix_waddr),%rdi
23960 movq %rax,(0*8)(%rdi) /* RAX */
23961 - movq (2*8)(%rsp),%rax /* RIP */
23962 + movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23963 movq %rax,(1*8)(%rdi)
23964 - movq (3*8)(%rsp),%rax /* CS */
23965 + movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23966 movq %rax,(2*8)(%rdi)
23967 - movq (4*8)(%rsp),%rax /* RFLAGS */
23968 + movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23969 movq %rax,(3*8)(%rdi)
23970 - movq (6*8)(%rsp),%rax /* SS */
23971 + movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23972 movq %rax,(5*8)(%rdi)
23973 - movq (5*8)(%rsp),%rax /* RSP */
23974 + movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23975 movq %rax,(4*8)(%rdi)
23976 andl $0xffff0000,%eax
23977 popq_cfi %rdi
23978 @@ -907,7 +1396,7 @@ ENTRY(retint_kernel)
23979 jmp exit_intr
23980 #endif
23981 CFI_ENDPROC
23982 -END(common_interrupt)
23983 +ENDPROC(common_interrupt)
23984
23985 /*
23986 * APIC interrupts.
23987 @@ -921,7 +1410,7 @@ ENTRY(\sym)
23988 interrupt \do_sym
23989 jmp ret_from_intr
23990 CFI_ENDPROC
23991 -END(\sym)
23992 +ENDPROC(\sym)
23993 .endm
23994
23995 #ifdef CONFIG_TRACING
23996 @@ -994,7 +1483,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23997 /*
23998 * Exception entry points.
23999 */
24000 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24001 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24002
24003 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24004 ENTRY(\sym)
24005 @@ -1045,6 +1534,12 @@ ENTRY(\sym)
24006 .endif
24007
24008 .if \shift_ist != -1
24009 +#ifdef CONFIG_SMP
24010 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24011 + lea init_tss(%r13), %r13
24012 +#else
24013 + lea init_tss(%rip), %r13
24014 +#endif
24015 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24016 .endif
24017
24018 @@ -1061,7 +1556,7 @@ ENTRY(\sym)
24019 .endif
24020
24021 CFI_ENDPROC
24022 -END(\sym)
24023 +ENDPROC(\sym)
24024 .endm
24025
24026 #ifdef CONFIG_TRACING
24027 @@ -1102,9 +1597,10 @@ gs_change:
24028 2: mfence /* workaround */
24029 SWAPGS
24030 popfq_cfi
24031 + pax_force_retaddr
24032 ret
24033 CFI_ENDPROC
24034 -END(native_load_gs_index)
24035 +ENDPROC(native_load_gs_index)
24036
24037 _ASM_EXTABLE(gs_change,bad_gs)
24038 .section .fixup,"ax"
24039 @@ -1132,9 +1628,10 @@ ENTRY(do_softirq_own_stack)
24040 CFI_DEF_CFA_REGISTER rsp
24041 CFI_ADJUST_CFA_OFFSET -8
24042 decl PER_CPU_VAR(irq_count)
24043 + pax_force_retaddr
24044 ret
24045 CFI_ENDPROC
24046 -END(do_softirq_own_stack)
24047 +ENDPROC(do_softirq_own_stack)
24048
24049 #ifdef CONFIG_XEN
24050 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24051 @@ -1172,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24052 decl PER_CPU_VAR(irq_count)
24053 jmp error_exit
24054 CFI_ENDPROC
24055 -END(xen_do_hypervisor_callback)
24056 +ENDPROC(xen_do_hypervisor_callback)
24057
24058 /*
24059 * Hypervisor uses this for application faults while it executes.
24060 @@ -1231,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
24061 SAVE_ALL
24062 jmp error_exit
24063 CFI_ENDPROC
24064 -END(xen_failsafe_callback)
24065 +ENDPROC(xen_failsafe_callback)
24066
24067 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24068 xen_hvm_callback_vector xen_evtchn_do_upcall
24069 @@ -1278,18 +1775,33 @@ ENTRY(paranoid_exit)
24070 DEFAULT_FRAME
24071 DISABLE_INTERRUPTS(CLBR_NONE)
24072 TRACE_IRQS_OFF_DEBUG
24073 - testl %ebx,%ebx /* swapgs needed? */
24074 + testl $1,%ebx /* swapgs needed? */
24075 jnz paranoid_restore
24076 - testl $3,CS(%rsp)
24077 + testb $3,CS(%rsp)
24078 jnz paranoid_userspace
24079 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24080 + pax_exit_kernel
24081 + TRACE_IRQS_IRETQ 0
24082 + SWAPGS_UNSAFE_STACK
24083 + RESTORE_ALL 8
24084 + pax_force_retaddr_bts
24085 + jmp irq_return
24086 +#endif
24087 paranoid_swapgs:
24088 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24089 + pax_exit_kernel_user
24090 +#else
24091 + pax_exit_kernel
24092 +#endif
24093 TRACE_IRQS_IRETQ 0
24094 SWAPGS_UNSAFE_STACK
24095 RESTORE_ALL 8
24096 jmp irq_return
24097 paranoid_restore:
24098 + pax_exit_kernel
24099 TRACE_IRQS_IRETQ_DEBUG 0
24100 RESTORE_ALL 8
24101 + pax_force_retaddr_bts
24102 jmp irq_return
24103 paranoid_userspace:
24104 GET_THREAD_INFO(%rcx)
24105 @@ -1318,7 +1830,7 @@ paranoid_schedule:
24106 TRACE_IRQS_OFF
24107 jmp paranoid_userspace
24108 CFI_ENDPROC
24109 -END(paranoid_exit)
24110 +ENDPROC(paranoid_exit)
24111
24112 /*
24113 * Exception entry point. This expects an error code/orig_rax on the stack.
24114 @@ -1345,12 +1857,23 @@ ENTRY(error_entry)
24115 movq %r14, R14+8(%rsp)
24116 movq %r15, R15+8(%rsp)
24117 xorl %ebx,%ebx
24118 - testl $3,CS+8(%rsp)
24119 + testb $3,CS+8(%rsp)
24120 je error_kernelspace
24121 error_swapgs:
24122 SWAPGS
24123 error_sti:
24124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24125 + testb $3, CS+8(%rsp)
24126 + jnz 1f
24127 + pax_enter_kernel
24128 + jmp 2f
24129 +1: pax_enter_kernel_user
24130 +2:
24131 +#else
24132 + pax_enter_kernel
24133 +#endif
24134 TRACE_IRQS_OFF
24135 + pax_force_retaddr
24136 ret
24137
24138 /*
24139 @@ -1385,7 +1908,7 @@ error_bad_iret:
24140 decl %ebx /* Return to usergs */
24141 jmp error_sti
24142 CFI_ENDPROC
24143 -END(error_entry)
24144 +ENDPROC(error_entry)
24145
24146
24147 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24148 @@ -1396,7 +1919,7 @@ ENTRY(error_exit)
24149 DISABLE_INTERRUPTS(CLBR_NONE)
24150 TRACE_IRQS_OFF
24151 GET_THREAD_INFO(%rcx)
24152 - testl %eax,%eax
24153 + testl $1,%eax
24154 jne retint_kernel
24155 LOCKDEP_SYS_EXIT_IRQ
24156 movl TI_flags(%rcx),%edx
24157 @@ -1405,7 +1928,7 @@ ENTRY(error_exit)
24158 jnz retint_careful
24159 jmp retint_swapgs
24160 CFI_ENDPROC
24161 -END(error_exit)
24162 +ENDPROC(error_exit)
24163
24164 /*
24165 * Test if a given stack is an NMI stack or not.
24166 @@ -1463,9 +1986,11 @@ ENTRY(nmi)
24167 * If %cs was not the kernel segment, then the NMI triggered in user
24168 * space, which means it is definitely not nested.
24169 */
24170 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24171 + je 1f
24172 cmpl $__KERNEL_CS, 16(%rsp)
24173 jne first_nmi
24174 -
24175 +1:
24176 /*
24177 * Check the special variable on the stack to see if NMIs are
24178 * executing.
24179 @@ -1499,8 +2024,7 @@ nested_nmi:
24180
24181 1:
24182 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24183 - leaq -1*8(%rsp), %rdx
24184 - movq %rdx, %rsp
24185 + subq $8, %rsp
24186 CFI_ADJUST_CFA_OFFSET 1*8
24187 leaq -10*8(%rsp), %rdx
24188 pushq_cfi $__KERNEL_DS
24189 @@ -1518,6 +2042,7 @@ nested_nmi_out:
24190 CFI_RESTORE rdx
24191
24192 /* No need to check faults here */
24193 +# pax_force_retaddr_bts
24194 INTERRUPT_RETURN
24195
24196 CFI_RESTORE_STATE
24197 @@ -1614,13 +2139,13 @@ end_repeat_nmi:
24198 subq $ORIG_RAX-R15, %rsp
24199 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24200 /*
24201 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24202 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24203 * as we should not be calling schedule in NMI context.
24204 * Even with normal interrupts enabled. An NMI should not be
24205 * setting NEED_RESCHED or anything that normal interrupts and
24206 * exceptions might do.
24207 */
24208 - call save_paranoid
24209 + call save_paranoid_nmi
24210 DEFAULT_FRAME 0
24211
24212 /*
24213 @@ -1630,9 +2155,9 @@ end_repeat_nmi:
24214 * NMI itself takes a page fault, the page fault that was preempted
24215 * will read the information from the NMI page fault and not the
24216 * origin fault. Save it off and restore it if it changes.
24217 - * Use the r12 callee-saved register.
24218 + * Use the r13 callee-saved register.
24219 */
24220 - movq %cr2, %r12
24221 + movq %cr2, %r13
24222
24223 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24224 movq %rsp,%rdi
24225 @@ -1641,29 +2166,34 @@ end_repeat_nmi:
24226
24227 /* Did the NMI take a page fault? Restore cr2 if it did */
24228 movq %cr2, %rcx
24229 - cmpq %rcx, %r12
24230 + cmpq %rcx, %r13
24231 je 1f
24232 - movq %r12, %cr2
24233 + movq %r13, %cr2
24234 1:
24235
24236 - testl %ebx,%ebx /* swapgs needed? */
24237 + testl $1,%ebx /* swapgs needed? */
24238 jnz nmi_restore
24239 nmi_swapgs:
24240 SWAPGS_UNSAFE_STACK
24241 nmi_restore:
24242 + pax_exit_kernel_nmi
24243 /* Pop the extra iret frame at once */
24244 RESTORE_ALL 6*8
24245 + testb $3, 8(%rsp)
24246 + jnz 1f
24247 + pax_force_retaddr_bts
24248 +1:
24249
24250 /* Clear the NMI executing stack variable */
24251 movq $0, 5*8(%rsp)
24252 jmp irq_return
24253 CFI_ENDPROC
24254 -END(nmi)
24255 +ENDPROC(nmi)
24256
24257 ENTRY(ignore_sysret)
24258 CFI_STARTPROC
24259 mov $-ENOSYS,%eax
24260 sysret
24261 CFI_ENDPROC
24262 -END(ignore_sysret)
24263 +ENDPROC(ignore_sysret)
24264
24265 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24266 index 94d857f..5bce89c 100644
24267 --- a/arch/x86/kernel/espfix_64.c
24268 +++ b/arch/x86/kernel/espfix_64.c
24269 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24270 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24271 static void *espfix_pages[ESPFIX_MAX_PAGES];
24272
24273 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24274 - __aligned(PAGE_SIZE);
24275 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24276
24277 static unsigned int page_random, slot_random;
24278
24279 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24280 void __init init_espfix_bsp(void)
24281 {
24282 pgd_t *pgd_p;
24283 - pteval_t ptemask;
24284 -
24285 - ptemask = __supported_pte_mask;
24286 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24287
24288 /* Install the espfix pud into the kernel page directory */
24289 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24290 + pgd_p = &init_level4_pgt[index];
24291 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24292
24293 +#ifdef CONFIG_PAX_PER_CPU_PGD
24294 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24295 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24296 +#endif
24297 +
24298 /* Randomize the locations */
24299 init_espfix_random();
24300
24301 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24302 set_pte(&pte_p[n*PTE_STRIDE], pte);
24303
24304 /* Job is done for this CPU and any CPU which shares this page */
24305 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24306 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24307
24308 unlock_done:
24309 mutex_unlock(&espfix_init_mutex);
24310 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24311 index 3386dc9..28bdf81 100644
24312 --- a/arch/x86/kernel/ftrace.c
24313 +++ b/arch/x86/kernel/ftrace.c
24314 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24315 * kernel identity mapping to modify code.
24316 */
24317 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24318 - ip = (unsigned long)__va(__pa_symbol(ip));
24319 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24320
24321 return ip;
24322 }
24323 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24324 {
24325 unsigned char replaced[MCOUNT_INSN_SIZE];
24326
24327 + ip = ktla_ktva(ip);
24328 +
24329 /*
24330 * Note: Due to modules and __init, code can
24331 * disappear and change, we need to protect against faulting
24332 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24333 unsigned char old[MCOUNT_INSN_SIZE];
24334 int ret;
24335
24336 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24337 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24338
24339 ftrace_update_func = ip;
24340 /* Make sure the breakpoints see the ftrace_update_func update */
24341 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24342 unsigned char replaced[MCOUNT_INSN_SIZE];
24343 unsigned char brk = BREAKPOINT_INSTRUCTION;
24344
24345 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24346 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24347 return -EFAULT;
24348
24349 /* Make sure it is what we expect it to be */
24350 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24351 index eda1a86..8f6df48 100644
24352 --- a/arch/x86/kernel/head64.c
24353 +++ b/arch/x86/kernel/head64.c
24354 @@ -67,12 +67,12 @@ again:
24355 pgd = *pgd_p;
24356
24357 /*
24358 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24359 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24360 + * The use of __early_va rather than __va here is critical:
24361 + * __va would point us back into the dynamic
24362 * range and we might end up looping forever...
24363 */
24364 if (pgd)
24365 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24366 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24367 else {
24368 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24369 reset_early_page_tables();
24370 @@ -82,13 +82,13 @@ again:
24371 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24372 for (i = 0; i < PTRS_PER_PUD; i++)
24373 pud_p[i] = 0;
24374 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24375 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24376 }
24377 pud_p += pud_index(address);
24378 pud = *pud_p;
24379
24380 if (pud)
24381 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24382 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24383 else {
24384 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24385 reset_early_page_tables();
24386 @@ -98,7 +98,7 @@ again:
24387 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24388 for (i = 0; i < PTRS_PER_PMD; i++)
24389 pmd_p[i] = 0;
24390 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24391 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24392 }
24393 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24394 pmd_p[pmd_index(address)] = pmd;
24395 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24396 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24397 early_printk("Kernel alive\n");
24398
24399 - clear_page(init_level4_pgt);
24400 /* set init_level4_pgt kernel high mapping*/
24401 init_level4_pgt[511] = early_level4_pgt[511];
24402
24403 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24404 index f36bd42..0ab4474 100644
24405 --- a/arch/x86/kernel/head_32.S
24406 +++ b/arch/x86/kernel/head_32.S
24407 @@ -26,6 +26,12 @@
24408 /* Physical address */
24409 #define pa(X) ((X) - __PAGE_OFFSET)
24410
24411 +#ifdef CONFIG_PAX_KERNEXEC
24412 +#define ta(X) (X)
24413 +#else
24414 +#define ta(X) ((X) - __PAGE_OFFSET)
24415 +#endif
24416 +
24417 /*
24418 * References to members of the new_cpu_data structure.
24419 */
24420 @@ -55,11 +61,7 @@
24421 * and small than max_low_pfn, otherwise will waste some page table entries
24422 */
24423
24424 -#if PTRS_PER_PMD > 1
24425 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24426 -#else
24427 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24428 -#endif
24429 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24430
24431 /* Number of possible pages in the lowmem region */
24432 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24433 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24434 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24435
24436 /*
24437 + * Real beginning of normal "text" segment
24438 + */
24439 +ENTRY(stext)
24440 +ENTRY(_stext)
24441 +
24442 +/*
24443 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24444 * %esi points to the real-mode code as a 32-bit pointer.
24445 * CS and DS must be 4 GB flat segments, but we don't depend on
24446 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24447 * can.
24448 */
24449 __HEAD
24450 +
24451 +#ifdef CONFIG_PAX_KERNEXEC
24452 + jmp startup_32
24453 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24454 +.fill PAGE_SIZE-5,1,0xcc
24455 +#endif
24456 +
24457 ENTRY(startup_32)
24458 movl pa(stack_start),%ecx
24459
24460 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24461 2:
24462 leal -__PAGE_OFFSET(%ecx),%esp
24463
24464 +#ifdef CONFIG_SMP
24465 + movl $pa(cpu_gdt_table),%edi
24466 + movl $__per_cpu_load,%eax
24467 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24468 + rorl $16,%eax
24469 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24470 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24471 + movl $__per_cpu_end - 1,%eax
24472 + subl $__per_cpu_start,%eax
24473 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24474 +#endif
24475 +
24476 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24477 + movl $NR_CPUS,%ecx
24478 + movl $pa(cpu_gdt_table),%edi
24479 +1:
24480 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24481 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24482 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24483 + addl $PAGE_SIZE_asm,%edi
24484 + loop 1b
24485 +#endif
24486 +
24487 +#ifdef CONFIG_PAX_KERNEXEC
24488 + movl $pa(boot_gdt),%edi
24489 + movl $__LOAD_PHYSICAL_ADDR,%eax
24490 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24491 + rorl $16,%eax
24492 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24493 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24494 + rorl $16,%eax
24495 +
24496 + ljmp $(__BOOT_CS),$1f
24497 +1:
24498 +
24499 + movl $NR_CPUS,%ecx
24500 + movl $pa(cpu_gdt_table),%edi
24501 + addl $__PAGE_OFFSET,%eax
24502 +1:
24503 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24504 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24505 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24506 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24507 + rorl $16,%eax
24508 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24509 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24510 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24511 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24512 + rorl $16,%eax
24513 + addl $PAGE_SIZE_asm,%edi
24514 + loop 1b
24515 +#endif
24516 +
24517 /*
24518 * Clear BSS first so that there are no surprises...
24519 */
24520 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24521 movl %eax, pa(max_pfn_mapped)
24522
24523 /* Do early initialization of the fixmap area */
24524 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24525 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24526 +#ifdef CONFIG_COMPAT_VDSO
24527 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24528 +#else
24529 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24530 +#endif
24531 #else /* Not PAE */
24532
24533 page_pde_offset = (__PAGE_OFFSET >> 20);
24534 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24535 movl %eax, pa(max_pfn_mapped)
24536
24537 /* Do early initialization of the fixmap area */
24538 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24539 - movl %eax,pa(initial_page_table+0xffc)
24540 +#ifdef CONFIG_COMPAT_VDSO
24541 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24542 +#else
24543 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24544 +#endif
24545 #endif
24546
24547 #ifdef CONFIG_PARAVIRT
24548 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24549 cmpl $num_subarch_entries, %eax
24550 jae bad_subarch
24551
24552 - movl pa(subarch_entries)(,%eax,4), %eax
24553 - subl $__PAGE_OFFSET, %eax
24554 - jmp *%eax
24555 + jmp *pa(subarch_entries)(,%eax,4)
24556
24557 bad_subarch:
24558 WEAK(lguest_entry)
24559 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24560 __INITDATA
24561
24562 subarch_entries:
24563 - .long default_entry /* normal x86/PC */
24564 - .long lguest_entry /* lguest hypervisor */
24565 - .long xen_entry /* Xen hypervisor */
24566 - .long default_entry /* Moorestown MID */
24567 + .long ta(default_entry) /* normal x86/PC */
24568 + .long ta(lguest_entry) /* lguest hypervisor */
24569 + .long ta(xen_entry) /* Xen hypervisor */
24570 + .long ta(default_entry) /* Moorestown MID */
24571 num_subarch_entries = (. - subarch_entries) / 4
24572 .previous
24573 #else
24574 @@ -354,6 +426,7 @@ default_entry:
24575 movl pa(mmu_cr4_features),%eax
24576 movl %eax,%cr4
24577
24578 +#ifdef CONFIG_X86_PAE
24579 testb $X86_CR4_PAE, %al # check if PAE is enabled
24580 jz enable_paging
24581
24582 @@ -382,6 +455,9 @@ default_entry:
24583 /* Make changes effective */
24584 wrmsr
24585
24586 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24587 +#endif
24588 +
24589 enable_paging:
24590
24591 /*
24592 @@ -449,14 +525,20 @@ is486:
24593 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24594 movl %eax,%ss # after changing gdt.
24595
24596 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24597 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24598 movl %eax,%ds
24599 movl %eax,%es
24600
24601 movl $(__KERNEL_PERCPU), %eax
24602 movl %eax,%fs # set this cpu's percpu
24603
24604 +#ifdef CONFIG_CC_STACKPROTECTOR
24605 movl $(__KERNEL_STACK_CANARY),%eax
24606 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24607 + movl $(__USER_DS),%eax
24608 +#else
24609 + xorl %eax,%eax
24610 +#endif
24611 movl %eax,%gs
24612
24613 xorl %eax,%eax # Clear LDT
24614 @@ -512,8 +594,11 @@ setup_once:
24615 * relocation. Manually set base address in stack canary
24616 * segment descriptor.
24617 */
24618 - movl $gdt_page,%eax
24619 + movl $cpu_gdt_table,%eax
24620 movl $stack_canary,%ecx
24621 +#ifdef CONFIG_SMP
24622 + addl $__per_cpu_load,%ecx
24623 +#endif
24624 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24625 shrl $16, %ecx
24626 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24627 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24628 cmpl $2,(%esp) # X86_TRAP_NMI
24629 je is_nmi # Ignore NMI
24630
24631 - cmpl $2,%ss:early_recursion_flag
24632 + cmpl $1,%ss:early_recursion_flag
24633 je hlt_loop
24634 incl %ss:early_recursion_flag
24635
24636 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24637 pushl (20+6*4)(%esp) /* trapno */
24638 pushl $fault_msg
24639 call printk
24640 -#endif
24641 call dump_stack
24642 +#endif
24643 hlt_loop:
24644 hlt
24645 jmp hlt_loop
24646 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24647 /* This is the default interrupt "handler" :-) */
24648 ALIGN
24649 ignore_int:
24650 - cld
24651 #ifdef CONFIG_PRINTK
24652 + cmpl $2,%ss:early_recursion_flag
24653 + je hlt_loop
24654 + incl %ss:early_recursion_flag
24655 + cld
24656 pushl %eax
24657 pushl %ecx
24658 pushl %edx
24659 @@ -617,9 +705,6 @@ ignore_int:
24660 movl $(__KERNEL_DS),%eax
24661 movl %eax,%ds
24662 movl %eax,%es
24663 - cmpl $2,early_recursion_flag
24664 - je hlt_loop
24665 - incl early_recursion_flag
24666 pushl 16(%esp)
24667 pushl 24(%esp)
24668 pushl 32(%esp)
24669 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24670 /*
24671 * BSS section
24672 */
24673 -__PAGE_ALIGNED_BSS
24674 - .align PAGE_SIZE
24675 #ifdef CONFIG_X86_PAE
24676 +.section .initial_pg_pmd,"a",@progbits
24677 initial_pg_pmd:
24678 .fill 1024*KPMDS,4,0
24679 #else
24680 +.section .initial_page_table,"a",@progbits
24681 ENTRY(initial_page_table)
24682 .fill 1024,4,0
24683 #endif
24684 +.section .initial_pg_fixmap,"a",@progbits
24685 initial_pg_fixmap:
24686 .fill 1024,4,0
24687 +.section .empty_zero_page,"a",@progbits
24688 ENTRY(empty_zero_page)
24689 .fill 4096,1,0
24690 +.section .swapper_pg_dir,"a",@progbits
24691 ENTRY(swapper_pg_dir)
24692 +#ifdef CONFIG_X86_PAE
24693 + .fill 4,8,0
24694 +#else
24695 .fill 1024,4,0
24696 +#endif
24697
24698 /*
24699 * This starts the data section.
24700 */
24701 #ifdef CONFIG_X86_PAE
24702 -__PAGE_ALIGNED_DATA
24703 - /* Page-aligned for the benefit of paravirt? */
24704 - .align PAGE_SIZE
24705 +.section .initial_page_table,"a",@progbits
24706 ENTRY(initial_page_table)
24707 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24708 # if KPMDS == 3
24709 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24710 # error "Kernel PMDs should be 1, 2 or 3"
24711 # endif
24712 .align PAGE_SIZE /* needs to be page-sized too */
24713 +
24714 +#ifdef CONFIG_PAX_PER_CPU_PGD
24715 +ENTRY(cpu_pgd)
24716 + .rept 2*NR_CPUS
24717 + .fill 4,8,0
24718 + .endr
24719 +#endif
24720 +
24721 #endif
24722
24723 .data
24724 .balign 4
24725 ENTRY(stack_start)
24726 - .long init_thread_union+THREAD_SIZE
24727 + .long init_thread_union+THREAD_SIZE-8
24728
24729 __INITRODATA
24730 int_msg:
24731 @@ -727,7 +825,7 @@ fault_msg:
24732 * segment size, and 32-bit linear address value:
24733 */
24734
24735 - .data
24736 +.section .rodata,"a",@progbits
24737 .globl boot_gdt_descr
24738 .globl idt_descr
24739
24740 @@ -736,7 +834,7 @@ fault_msg:
24741 .word 0 # 32 bit align gdt_desc.address
24742 boot_gdt_descr:
24743 .word __BOOT_DS+7
24744 - .long boot_gdt - __PAGE_OFFSET
24745 + .long pa(boot_gdt)
24746
24747 .word 0 # 32-bit align idt_desc.address
24748 idt_descr:
24749 @@ -747,7 +845,7 @@ idt_descr:
24750 .word 0 # 32 bit align gdt_desc.address
24751 ENTRY(early_gdt_descr)
24752 .word GDT_ENTRIES*8-1
24753 - .long gdt_page /* Overwritten for secondary CPUs */
24754 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24755
24756 /*
24757 * The boot_gdt must mirror the equivalent in setup.S and is
24758 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24759 .align L1_CACHE_BYTES
24760 ENTRY(boot_gdt)
24761 .fill GDT_ENTRY_BOOT_CS,8,0
24762 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24763 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24764 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24765 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24766 +
24767 + .align PAGE_SIZE_asm
24768 +ENTRY(cpu_gdt_table)
24769 + .rept NR_CPUS
24770 + .quad 0x0000000000000000 /* NULL descriptor */
24771 + .quad 0x0000000000000000 /* 0x0b reserved */
24772 + .quad 0x0000000000000000 /* 0x13 reserved */
24773 + .quad 0x0000000000000000 /* 0x1b reserved */
24774 +
24775 +#ifdef CONFIG_PAX_KERNEXEC
24776 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24777 +#else
24778 + .quad 0x0000000000000000 /* 0x20 unused */
24779 +#endif
24780 +
24781 + .quad 0x0000000000000000 /* 0x28 unused */
24782 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24783 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24784 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24785 + .quad 0x0000000000000000 /* 0x4b reserved */
24786 + .quad 0x0000000000000000 /* 0x53 reserved */
24787 + .quad 0x0000000000000000 /* 0x5b reserved */
24788 +
24789 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24790 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24791 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24792 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24793 +
24794 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24795 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24796 +
24797 + /*
24798 + * Segments used for calling PnP BIOS have byte granularity.
24799 + * The code segments and data segments have fixed 64k limits,
24800 + * the transfer segment sizes are set at run time.
24801 + */
24802 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24803 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24804 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24805 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24806 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24807 +
24808 + /*
24809 + * The APM segments have byte granularity and their bases
24810 + * are set at run time. All have 64k limits.
24811 + */
24812 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24813 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24814 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24815 +
24816 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24817 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24818 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24819 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24820 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24821 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24822 +
24823 + /* Be sure this is zeroed to avoid false validations in Xen */
24824 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24825 + .endr
24826 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24827 index a468c0a..8b5a879 100644
24828 --- a/arch/x86/kernel/head_64.S
24829 +++ b/arch/x86/kernel/head_64.S
24830 @@ -20,6 +20,8 @@
24831 #include <asm/processor-flags.h>
24832 #include <asm/percpu.h>
24833 #include <asm/nops.h>
24834 +#include <asm/cpufeature.h>
24835 +#include <asm/alternative-asm.h>
24836
24837 #ifdef CONFIG_PARAVIRT
24838 #include <asm/asm-offsets.h>
24839 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24840 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24841 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24842 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24843 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24844 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24845 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24846 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24847 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24848 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24849
24850 .text
24851 __HEAD
24852 @@ -89,11 +97,24 @@ startup_64:
24853 * Fixup the physical addresses in the page table
24854 */
24855 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24856 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24857 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24858 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24859 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24860 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24861
24862 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24863 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24864 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24865 +#ifndef CONFIG_XEN
24866 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24867 +#endif
24868 +
24869 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24870 +
24871 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24872 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24873
24874 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24875 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24876
24877 /*
24878 * Set up the identity mapping for the switchover. These
24879 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24880 * after the boot processor executes this code.
24881 */
24882
24883 + orq $-1, %rbp
24884 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24885 1:
24886
24887 - /* Enable PAE mode and PGE */
24888 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24889 + /* Enable PAE mode and PSE/PGE */
24890 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24891 movq %rcx, %cr4
24892
24893 /* Setup early boot stage 4 level pagetables. */
24894 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24895 movl $MSR_EFER, %ecx
24896 rdmsr
24897 btsl $_EFER_SCE, %eax /* Enable System Call */
24898 - btl $20,%edi /* No Execute supported? */
24899 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24900 jnc 1f
24901 btsl $_EFER_NX, %eax
24902 + cmpq $-1, %rbp
24903 + je 1f
24904 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24905 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24906 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24907 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24908 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24909 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24910 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24911 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24912 1: wrmsr /* Make changes effective */
24913
24914 /* Setup cr0 */
24915 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24916 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24917 * address given in m16:64.
24918 */
24919 + pax_set_fptr_mask
24920 movq initial_code(%rip),%rax
24921 pushq $0 # fake return address to stop unwinder
24922 pushq $__KERNEL_CS # set correct cs
24923 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24924 .quad INIT_PER_CPU_VAR(irq_stack_union)
24925
24926 GLOBAL(stack_start)
24927 - .quad init_thread_union+THREAD_SIZE-8
24928 + .quad init_thread_union+THREAD_SIZE-16
24929 .word 0
24930 __FINITDATA
24931
24932 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24933 call dump_stack
24934 #ifdef CONFIG_KALLSYMS
24935 leaq early_idt_ripmsg(%rip),%rdi
24936 - movq 40(%rsp),%rsi # %rip again
24937 + movq 88(%rsp),%rsi # %rip again
24938 call __print_symbol
24939 #endif
24940 #endif /* EARLY_PRINTK */
24941 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24942 early_recursion_flag:
24943 .long 0
24944
24945 + .section .rodata,"a",@progbits
24946 #ifdef CONFIG_EARLY_PRINTK
24947 early_idt_msg:
24948 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24949 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24950 NEXT_PAGE(early_dynamic_pgts)
24951 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24952
24953 - .data
24954 + .section .rodata,"a",@progbits
24955
24956 -#ifndef CONFIG_XEN
24957 NEXT_PAGE(init_level4_pgt)
24958 - .fill 512,8,0
24959 -#else
24960 -NEXT_PAGE(init_level4_pgt)
24961 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24962 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24963 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24964 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24965 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24966 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24967 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24968 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24969 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24970 .org init_level4_pgt + L4_START_KERNEL*8, 0
24971 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24972 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24973
24974 +#ifdef CONFIG_PAX_PER_CPU_PGD
24975 +NEXT_PAGE(cpu_pgd)
24976 + .rept 2*NR_CPUS
24977 + .fill 512,8,0
24978 + .endr
24979 +#endif
24980 +
24981 NEXT_PAGE(level3_ident_pgt)
24982 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24983 +#ifdef CONFIG_XEN
24984 .fill 511, 8, 0
24985 +#else
24986 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24987 + .fill 510,8,0
24988 +#endif
24989 +
24990 +NEXT_PAGE(level3_vmalloc_start_pgt)
24991 + .fill 512,8,0
24992 +
24993 +NEXT_PAGE(level3_vmalloc_end_pgt)
24994 + .fill 512,8,0
24995 +
24996 +NEXT_PAGE(level3_vmemmap_pgt)
24997 + .fill L3_VMEMMAP_START,8,0
24998 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24999 +
25000 NEXT_PAGE(level2_ident_pgt)
25001 - /* Since I easily can, map the first 1G.
25002 + /* Since I easily can, map the first 2G.
25003 * Don't set NX because code runs from these pages.
25004 */
25005 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25006 -#endif
25007 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25008
25009 NEXT_PAGE(level3_kernel_pgt)
25010 .fill L3_START_KERNEL,8,0
25011 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25012 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25013 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25014
25015 +NEXT_PAGE(level2_vmemmap_pgt)
25016 + .fill 512,8,0
25017 +
25018 NEXT_PAGE(level2_kernel_pgt)
25019 /*
25020 * 512 MB kernel mapping. We spend a full page on this pagetable
25021 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25022 NEXT_PAGE(level2_fixmap_pgt)
25023 .fill 506,8,0
25024 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25025 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25026 - .fill 5,8,0
25027 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25028 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25029 + .fill 4,8,0
25030
25031 NEXT_PAGE(level1_fixmap_pgt)
25032 .fill 512,8,0
25033
25034 +NEXT_PAGE(level1_vsyscall_pgt)
25035 + .fill 512,8,0
25036 +
25037 #undef PMDS
25038
25039 - .data
25040 + .align PAGE_SIZE
25041 +ENTRY(cpu_gdt_table)
25042 + .rept NR_CPUS
25043 + .quad 0x0000000000000000 /* NULL descriptor */
25044 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25045 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25046 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25047 + .quad 0x00cffb000000ffff /* __USER32_CS */
25048 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25049 + .quad 0x00affb000000ffff /* __USER_CS */
25050 +
25051 +#ifdef CONFIG_PAX_KERNEXEC
25052 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25053 +#else
25054 + .quad 0x0 /* unused */
25055 +#endif
25056 +
25057 + .quad 0,0 /* TSS */
25058 + .quad 0,0 /* LDT */
25059 + .quad 0,0,0 /* three TLS descriptors */
25060 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25061 + /* asm/segment.h:GDT_ENTRIES must match this */
25062 +
25063 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25064 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25065 +#else
25066 + .quad 0x0 /* unused */
25067 +#endif
25068 +
25069 + /* zero the remaining page */
25070 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25071 + .endr
25072 +
25073 .align 16
25074 .globl early_gdt_descr
25075 early_gdt_descr:
25076 .word GDT_ENTRIES*8-1
25077 early_gdt_descr_base:
25078 - .quad INIT_PER_CPU_VAR(gdt_page)
25079 + .quad cpu_gdt_table
25080
25081 ENTRY(phys_base)
25082 /* This must match the first entry in level2_kernel_pgt */
25083 .quad 0x0000000000000000
25084
25085 #include "../../x86/xen/xen-head.S"
25086 -
25087 - __PAGE_ALIGNED_BSS
25088 +
25089 + .section .rodata,"a",@progbits
25090 NEXT_PAGE(empty_zero_page)
25091 .skip PAGE_SIZE
25092 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25093 index 05fd74f..c3548b1 100644
25094 --- a/arch/x86/kernel/i386_ksyms_32.c
25095 +++ b/arch/x86/kernel/i386_ksyms_32.c
25096 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25097 EXPORT_SYMBOL(cmpxchg8b_emu);
25098 #endif
25099
25100 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25101 +
25102 /* Networking helper routines. */
25103 EXPORT_SYMBOL(csum_partial_copy_generic);
25104 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25105 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25106
25107 EXPORT_SYMBOL(__get_user_1);
25108 EXPORT_SYMBOL(__get_user_2);
25109 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25110 EXPORT_SYMBOL(___preempt_schedule_context);
25111 #endif
25112 #endif
25113 +
25114 +#ifdef CONFIG_PAX_KERNEXEC
25115 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25116 +#endif
25117 +
25118 +#ifdef CONFIG_PAX_PER_CPU_PGD
25119 +EXPORT_SYMBOL(cpu_pgd);
25120 +#endif
25121 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25122 index a9a4229..6f4d476 100644
25123 --- a/arch/x86/kernel/i387.c
25124 +++ b/arch/x86/kernel/i387.c
25125 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25126 static inline bool interrupted_user_mode(void)
25127 {
25128 struct pt_regs *regs = get_irq_regs();
25129 - return regs && user_mode_vm(regs);
25130 + return regs && user_mode(regs);
25131 }
25132
25133 /*
25134 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25135 index e7cc537..67d7372 100644
25136 --- a/arch/x86/kernel/i8259.c
25137 +++ b/arch/x86/kernel/i8259.c
25138 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25139 static void make_8259A_irq(unsigned int irq)
25140 {
25141 disable_irq_nosync(irq);
25142 - io_apic_irqs &= ~(1<<irq);
25143 + io_apic_irqs &= ~(1UL<<irq);
25144 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25145 enable_irq(irq);
25146 }
25147 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25148 "spurious 8259A interrupt: IRQ%d.\n", irq);
25149 spurious_irq_mask |= irqmask;
25150 }
25151 - atomic_inc(&irq_err_count);
25152 + atomic_inc_unchecked(&irq_err_count);
25153 /*
25154 * Theoretically we do not have to handle this IRQ,
25155 * but in Linux this does not cause problems and is
25156 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25157 /* (slave's support for AEOI in flat mode is to be investigated) */
25158 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25159
25160 + pax_open_kernel();
25161 if (auto_eoi)
25162 /*
25163 * In AEOI mode we just have to mask the interrupt
25164 * when acking.
25165 */
25166 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25167 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25168 else
25169 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25170 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25171 + pax_close_kernel();
25172
25173 udelay(100); /* wait for 8259A to initialize */
25174
25175 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25176 index a979b5b..1d6db75 100644
25177 --- a/arch/x86/kernel/io_delay.c
25178 +++ b/arch/x86/kernel/io_delay.c
25179 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25180 * Quirk table for systems that misbehave (lock up, etc.) if port
25181 * 0x80 is used:
25182 */
25183 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25184 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25185 {
25186 .callback = dmi_io_delay_0xed_port,
25187 .ident = "Compaq Presario V6000",
25188 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25189 index 4ddaf66..49d5c18 100644
25190 --- a/arch/x86/kernel/ioport.c
25191 +++ b/arch/x86/kernel/ioport.c
25192 @@ -6,6 +6,7 @@
25193 #include <linux/sched.h>
25194 #include <linux/kernel.h>
25195 #include <linux/capability.h>
25196 +#include <linux/security.h>
25197 #include <linux/errno.h>
25198 #include <linux/types.h>
25199 #include <linux/ioport.h>
25200 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25201 return -EINVAL;
25202 if (turn_on && !capable(CAP_SYS_RAWIO))
25203 return -EPERM;
25204 +#ifdef CONFIG_GRKERNSEC_IO
25205 + if (turn_on && grsec_disable_privio) {
25206 + gr_handle_ioperm();
25207 + return -ENODEV;
25208 + }
25209 +#endif
25210
25211 /*
25212 * If it's the first ioperm() call in this thread's lifetime, set the
25213 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25214 * because the ->io_bitmap_max value must match the bitmap
25215 * contents:
25216 */
25217 - tss = &per_cpu(init_tss, get_cpu());
25218 + tss = init_tss + get_cpu();
25219
25220 if (turn_on)
25221 bitmap_clear(t->io_bitmap_ptr, from, num);
25222 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25223 if (level > old) {
25224 if (!capable(CAP_SYS_RAWIO))
25225 return -EPERM;
25226 +#ifdef CONFIG_GRKERNSEC_IO
25227 + if (grsec_disable_privio) {
25228 + gr_handle_iopl();
25229 + return -ENODEV;
25230 + }
25231 +#endif
25232 }
25233 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25234 t->iopl = level << 12;
25235 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25236 index 922d285..6d20692 100644
25237 --- a/arch/x86/kernel/irq.c
25238 +++ b/arch/x86/kernel/irq.c
25239 @@ -22,7 +22,7 @@
25240 #define CREATE_TRACE_POINTS
25241 #include <asm/trace/irq_vectors.h>
25242
25243 -atomic_t irq_err_count;
25244 +atomic_unchecked_t irq_err_count;
25245
25246 /* Function pointer for generic interrupt vector handling */
25247 void (*x86_platform_ipi_callback)(void) = NULL;
25248 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25249 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25250 seq_printf(p, " Hypervisor callback interrupts\n");
25251 #endif
25252 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25253 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25254 #if defined(CONFIG_X86_IO_APIC)
25255 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25256 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25257 #endif
25258 return 0;
25259 }
25260 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25261
25262 u64 arch_irq_stat(void)
25263 {
25264 - u64 sum = atomic_read(&irq_err_count);
25265 + u64 sum = atomic_read_unchecked(&irq_err_count);
25266 return sum;
25267 }
25268
25269 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25270 index 63ce838..2ea3e06 100644
25271 --- a/arch/x86/kernel/irq_32.c
25272 +++ b/arch/x86/kernel/irq_32.c
25273 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25274
25275 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25276
25277 +extern void gr_handle_kernel_exploit(void);
25278 +
25279 int sysctl_panic_on_stackoverflow __read_mostly;
25280
25281 /* Debugging check for stack overflow: is there less than 1KB free? */
25282 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25283 __asm__ __volatile__("andl %%esp,%0" :
25284 "=r" (sp) : "0" (THREAD_SIZE - 1));
25285
25286 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25287 + return sp < STACK_WARN;
25288 }
25289
25290 static void print_stack_overflow(void)
25291 {
25292 printk(KERN_WARNING "low stack detected by irq handler\n");
25293 dump_stack();
25294 + gr_handle_kernel_exploit();
25295 if (sysctl_panic_on_stackoverflow)
25296 panic("low stack detected by irq handler - check messages\n");
25297 }
25298 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25299 static inline int
25300 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25301 {
25302 - struct irq_stack *curstk, *irqstk;
25303 + struct irq_stack *irqstk;
25304 u32 *isp, *prev_esp, arg1, arg2;
25305
25306 - curstk = (struct irq_stack *) current_stack();
25307 irqstk = __this_cpu_read(hardirq_stack);
25308
25309 /*
25310 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25311 * handler) we can't do that and just have to keep using the
25312 * current stack (which is the irq stack already after all)
25313 */
25314 - if (unlikely(curstk == irqstk))
25315 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25316 return 0;
25317
25318 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25319 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25320
25321 /* Save the next esp at the bottom of the stack */
25322 prev_esp = (u32 *)irqstk;
25323 *prev_esp = current_stack_pointer;
25324
25325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25326 + __set_fs(MAKE_MM_SEG(0));
25327 +#endif
25328 +
25329 if (unlikely(overflow))
25330 call_on_stack(print_stack_overflow, isp);
25331
25332 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25333 : "0" (irq), "1" (desc), "2" (isp),
25334 "D" (desc->handle_irq)
25335 : "memory", "cc", "ecx");
25336 +
25337 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25338 + __set_fs(current_thread_info()->addr_limit);
25339 +#endif
25340 +
25341 return 1;
25342 }
25343
25344 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25345 */
25346 void irq_ctx_init(int cpu)
25347 {
25348 - struct irq_stack *irqstk;
25349 -
25350 if (per_cpu(hardirq_stack, cpu))
25351 return;
25352
25353 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25354 - THREADINFO_GFP,
25355 - THREAD_SIZE_ORDER));
25356 - per_cpu(hardirq_stack, cpu) = irqstk;
25357 -
25358 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25359 - THREADINFO_GFP,
25360 - THREAD_SIZE_ORDER));
25361 - per_cpu(softirq_stack, cpu) = irqstk;
25362 -
25363 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25364 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25365 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25366 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25367 }
25368
25369 void do_softirq_own_stack(void)
25370 {
25371 - struct thread_info *curstk;
25372 struct irq_stack *irqstk;
25373 u32 *isp, *prev_esp;
25374
25375 - curstk = current_stack();
25376 irqstk = __this_cpu_read(softirq_stack);
25377
25378 /* build the stack frame on the softirq stack */
25379 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25380 prev_esp = (u32 *)irqstk;
25381 *prev_esp = current_stack_pointer;
25382
25383 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25384 + __set_fs(MAKE_MM_SEG(0));
25385 +#endif
25386 +
25387 call_on_stack(__do_softirq, isp);
25388 +
25389 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25390 + __set_fs(current_thread_info()->addr_limit);
25391 +#endif
25392 +
25393 }
25394
25395 bool handle_irq(unsigned irq, struct pt_regs *regs)
25396 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25397 if (unlikely(!desc))
25398 return false;
25399
25400 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25401 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25402 if (unlikely(overflow))
25403 print_stack_overflow();
25404 desc->handle_irq(irq, desc);
25405 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25406 index e4b503d..824fce8 100644
25407 --- a/arch/x86/kernel/irq_64.c
25408 +++ b/arch/x86/kernel/irq_64.c
25409 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25410 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25411 EXPORT_PER_CPU_SYMBOL(irq_regs);
25412
25413 +extern void gr_handle_kernel_exploit(void);
25414 +
25415 int sysctl_panic_on_stackoverflow;
25416
25417 /*
25418 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25419 u64 estack_top, estack_bottom;
25420 u64 curbase = (u64)task_stack_page(current);
25421
25422 - if (user_mode_vm(regs))
25423 + if (user_mode(regs))
25424 return;
25425
25426 if (regs->sp >= curbase + sizeof(struct thread_info) +
25427 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25428 irq_stack_top, irq_stack_bottom,
25429 estack_top, estack_bottom);
25430
25431 + gr_handle_kernel_exploit();
25432 +
25433 if (sysctl_panic_on_stackoverflow)
25434 panic("low stack detected by irq handler - check messages\n");
25435 #endif
25436 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25437 index 26d5a55..a01160a 100644
25438 --- a/arch/x86/kernel/jump_label.c
25439 +++ b/arch/x86/kernel/jump_label.c
25440 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25441 * Jump label is enabled for the first time.
25442 * So we expect a default_nop...
25443 */
25444 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25445 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25446 != 0))
25447 bug_at((void *)entry->code, __LINE__);
25448 } else {
25449 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25450 * ...otherwise expect an ideal_nop. Otherwise
25451 * something went horribly wrong.
25452 */
25453 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25454 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25455 != 0))
25456 bug_at((void *)entry->code, __LINE__);
25457 }
25458 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25459 * are converting the default nop to the ideal nop.
25460 */
25461 if (init) {
25462 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25463 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25464 bug_at((void *)entry->code, __LINE__);
25465 } else {
25466 code.jump = 0xe9;
25467 code.offset = entry->target -
25468 (entry->code + JUMP_LABEL_NOP_SIZE);
25469 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25470 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25471 bug_at((void *)entry->code, __LINE__);
25472 }
25473 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25474 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25475 index 7ec1d5f..5a7d130 100644
25476 --- a/arch/x86/kernel/kgdb.c
25477 +++ b/arch/x86/kernel/kgdb.c
25478 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25479 #ifdef CONFIG_X86_32
25480 switch (regno) {
25481 case GDB_SS:
25482 - if (!user_mode_vm(regs))
25483 + if (!user_mode(regs))
25484 *(unsigned long *)mem = __KERNEL_DS;
25485 break;
25486 case GDB_SP:
25487 - if (!user_mode_vm(regs))
25488 + if (!user_mode(regs))
25489 *(unsigned long *)mem = kernel_stack_pointer(regs);
25490 break;
25491 case GDB_GS:
25492 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25493 bp->attr.bp_addr = breakinfo[breakno].addr;
25494 bp->attr.bp_len = breakinfo[breakno].len;
25495 bp->attr.bp_type = breakinfo[breakno].type;
25496 - info->address = breakinfo[breakno].addr;
25497 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25498 + info->address = ktla_ktva(breakinfo[breakno].addr);
25499 + else
25500 + info->address = breakinfo[breakno].addr;
25501 info->len = breakinfo[breakno].len;
25502 info->type = breakinfo[breakno].type;
25503 val = arch_install_hw_breakpoint(bp);
25504 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25505 case 'k':
25506 /* clear the trace bit */
25507 linux_regs->flags &= ~X86_EFLAGS_TF;
25508 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25509 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25510
25511 /* set the trace bit if we're stepping */
25512 if (remcomInBuffer[0] == 's') {
25513 linux_regs->flags |= X86_EFLAGS_TF;
25514 - atomic_set(&kgdb_cpu_doing_single_step,
25515 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25516 raw_smp_processor_id());
25517 }
25518
25519 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25520
25521 switch (cmd) {
25522 case DIE_DEBUG:
25523 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25524 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25525 if (user_mode(regs))
25526 return single_step_cont(regs, args);
25527 break;
25528 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25529 #endif /* CONFIG_DEBUG_RODATA */
25530
25531 bpt->type = BP_BREAKPOINT;
25532 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25533 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25534 BREAK_INSTR_SIZE);
25535 if (err)
25536 return err;
25537 - err = probe_kernel_write((char *)bpt->bpt_addr,
25538 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25539 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25540 #ifdef CONFIG_DEBUG_RODATA
25541 if (!err)
25542 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25543 return -EBUSY;
25544 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25545 BREAK_INSTR_SIZE);
25546 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25547 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25548 if (err)
25549 return err;
25550 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25551 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25552 if (mutex_is_locked(&text_mutex))
25553 goto knl_write;
25554 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25555 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25556 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25557 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25558 goto knl_write;
25559 return err;
25560 knl_write:
25561 #endif /* CONFIG_DEBUG_RODATA */
25562 - return probe_kernel_write((char *)bpt->bpt_addr,
25563 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25564 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25565 }
25566
25567 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25568 index 93d2c04..36d0e94 100644
25569 --- a/arch/x86/kernel/kprobes/core.c
25570 +++ b/arch/x86/kernel/kprobes/core.c
25571 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25572 s32 raddr;
25573 } __packed *insn;
25574
25575 - insn = (struct __arch_relative_insn *)from;
25576 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25577 +
25578 + pax_open_kernel();
25579 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25580 insn->op = op;
25581 + pax_close_kernel();
25582 }
25583
25584 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25585 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25586 kprobe_opcode_t opcode;
25587 kprobe_opcode_t *orig_opcodes = opcodes;
25588
25589 - if (search_exception_tables((unsigned long)opcodes))
25590 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25591 return 0; /* Page fault may occur on this address. */
25592
25593 retry:
25594 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25595 * for the first byte, we can recover the original instruction
25596 * from it and kp->opcode.
25597 */
25598 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25599 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25600 buf[0] = kp->opcode;
25601 - return (unsigned long)buf;
25602 + return ktva_ktla((unsigned long)buf);
25603 }
25604
25605 /*
25606 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25607 /* Another subsystem puts a breakpoint, failed to recover */
25608 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25609 return 0;
25610 + pax_open_kernel();
25611 memcpy(dest, insn.kaddr, insn.length);
25612 + pax_close_kernel();
25613
25614 #ifdef CONFIG_X86_64
25615 if (insn_rip_relative(&insn)) {
25616 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25617 return 0;
25618 }
25619 disp = (u8 *) dest + insn_offset_displacement(&insn);
25620 + pax_open_kernel();
25621 *(s32 *) disp = (s32) newdisp;
25622 + pax_close_kernel();
25623 }
25624 #endif
25625 return insn.length;
25626 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25627 * nor set current_kprobe, because it doesn't use single
25628 * stepping.
25629 */
25630 - regs->ip = (unsigned long)p->ainsn.insn;
25631 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25632 preempt_enable_no_resched();
25633 return;
25634 }
25635 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25636 regs->flags &= ~X86_EFLAGS_IF;
25637 /* single step inline if the instruction is an int3 */
25638 if (p->opcode == BREAKPOINT_INSTRUCTION)
25639 - regs->ip = (unsigned long)p->addr;
25640 + regs->ip = ktla_ktva((unsigned long)p->addr);
25641 else
25642 - regs->ip = (unsigned long)p->ainsn.insn;
25643 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25644 }
25645 NOKPROBE_SYMBOL(setup_singlestep);
25646
25647 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25648 struct kprobe *p;
25649 struct kprobe_ctlblk *kcb;
25650
25651 - if (user_mode_vm(regs))
25652 + if (user_mode(regs))
25653 return 0;
25654
25655 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25656 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25657 setup_singlestep(p, regs, kcb, 0);
25658 return 1;
25659 }
25660 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25661 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25662 /*
25663 * The breakpoint instruction was removed right
25664 * after we hit it. Another cpu has removed
25665 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25666 " movq %rax, 152(%rsp)\n"
25667 RESTORE_REGS_STRING
25668 " popfq\n"
25669 +#ifdef KERNEXEC_PLUGIN
25670 + " btsq $63,(%rsp)\n"
25671 +#endif
25672 #else
25673 " pushf\n"
25674 SAVE_REGS_STRING
25675 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25676 struct kprobe_ctlblk *kcb)
25677 {
25678 unsigned long *tos = stack_addr(regs);
25679 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25680 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25681 unsigned long orig_ip = (unsigned long)p->addr;
25682 kprobe_opcode_t *insn = p->ainsn.insn;
25683
25684 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25685 struct die_args *args = data;
25686 int ret = NOTIFY_DONE;
25687
25688 - if (args->regs && user_mode_vm(args->regs))
25689 + if (args->regs && user_mode(args->regs))
25690 return ret;
25691
25692 if (val == DIE_GPF) {
25693 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25694 index f1314d0..15f3154 100644
25695 --- a/arch/x86/kernel/kprobes/opt.c
25696 +++ b/arch/x86/kernel/kprobes/opt.c
25697 @@ -79,6 +79,7 @@ found:
25698 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25699 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25700 {
25701 + pax_open_kernel();
25702 #ifdef CONFIG_X86_64
25703 *addr++ = 0x48;
25704 *addr++ = 0xbf;
25705 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25706 *addr++ = 0xb8;
25707 #endif
25708 *(unsigned long *)addr = val;
25709 + pax_close_kernel();
25710 }
25711
25712 asm (
25713 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25714 * Verify if the address gap is in 2GB range, because this uses
25715 * a relative jump.
25716 */
25717 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25718 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25719 if (abs(rel) > 0x7fffffff) {
25720 __arch_remove_optimized_kprobe(op, 0);
25721 return -ERANGE;
25722 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25723 op->optinsn.size = ret;
25724
25725 /* Copy arch-dep-instance from template */
25726 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25727 + pax_open_kernel();
25728 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25729 + pax_close_kernel();
25730
25731 /* Set probe information */
25732 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25733
25734 /* Set probe function call */
25735 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25736 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25737
25738 /* Set returning jmp instruction at the tail of out-of-line buffer */
25739 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25740 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25741 (u8 *)op->kp.addr + op->optinsn.size);
25742
25743 flush_icache_range((unsigned long) buf,
25744 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25745 WARN_ON(kprobe_disabled(&op->kp));
25746
25747 /* Backup instructions which will be replaced by jump address */
25748 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25749 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25750 RELATIVE_ADDR_SIZE);
25751
25752 insn_buf[0] = RELATIVEJUMP_OPCODE;
25753 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25754 /* This kprobe is really able to run optimized path. */
25755 op = container_of(p, struct optimized_kprobe, kp);
25756 /* Detour through copied instructions */
25757 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25758 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25759 if (!reenter)
25760 reset_current_kprobe();
25761 preempt_enable_no_resched();
25762 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25763 index c2bedae..25e7ab60 100644
25764 --- a/arch/x86/kernel/ksysfs.c
25765 +++ b/arch/x86/kernel/ksysfs.c
25766 @@ -184,7 +184,7 @@ out:
25767
25768 static struct kobj_attribute type_attr = __ATTR_RO(type);
25769
25770 -static struct bin_attribute data_attr = {
25771 +static bin_attribute_no_const data_attr __read_only = {
25772 .attr = {
25773 .name = "data",
25774 .mode = S_IRUGO,
25775 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25776 index c37886d..d851d32 100644
25777 --- a/arch/x86/kernel/ldt.c
25778 +++ b/arch/x86/kernel/ldt.c
25779 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25780 if (reload) {
25781 #ifdef CONFIG_SMP
25782 preempt_disable();
25783 - load_LDT(pc);
25784 + load_LDT_nolock(pc);
25785 if (!cpumask_equal(mm_cpumask(current->mm),
25786 cpumask_of(smp_processor_id())))
25787 smp_call_function(flush_ldt, current->mm, 1);
25788 preempt_enable();
25789 #else
25790 - load_LDT(pc);
25791 + load_LDT_nolock(pc);
25792 #endif
25793 }
25794 if (oldsize) {
25795 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25796 return err;
25797
25798 for (i = 0; i < old->size; i++)
25799 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25800 + write_ldt_entry(new->ldt, i, old->ldt + i);
25801 return 0;
25802 }
25803
25804 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25805 retval = copy_ldt(&mm->context, &old_mm->context);
25806 mutex_unlock(&old_mm->context.lock);
25807 }
25808 +
25809 + if (tsk == current) {
25810 + mm->context.vdso = 0;
25811 +
25812 +#ifdef CONFIG_X86_32
25813 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25814 + mm->context.user_cs_base = 0UL;
25815 + mm->context.user_cs_limit = ~0UL;
25816 +
25817 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25818 + cpus_clear(mm->context.cpu_user_cs_mask);
25819 +#endif
25820 +
25821 +#endif
25822 +#endif
25823 +
25824 + }
25825 +
25826 return retval;
25827 }
25828
25829 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25830 }
25831 }
25832
25833 +#ifdef CONFIG_PAX_SEGMEXEC
25834 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25835 + error = -EINVAL;
25836 + goto out_unlock;
25837 + }
25838 +#endif
25839 +
25840 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25841 error = -EINVAL;
25842 goto out_unlock;
25843 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25844 index 72e8e31..f2f1605 100644
25845 --- a/arch/x86/kernel/machine_kexec_32.c
25846 +++ b/arch/x86/kernel/machine_kexec_32.c
25847 @@ -25,7 +25,7 @@
25848 #include <asm/cacheflush.h>
25849 #include <asm/debugreg.h>
25850
25851 -static void set_idt(void *newidt, __u16 limit)
25852 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25853 {
25854 struct desc_ptr curidt;
25855
25856 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25857 }
25858
25859
25860 -static void set_gdt(void *newgdt, __u16 limit)
25861 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25862 {
25863 struct desc_ptr curgdt;
25864
25865 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25866 }
25867
25868 control_page = page_address(image->control_code_page);
25869 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25870 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25871
25872 relocate_kernel_ptr = control_page;
25873 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25874 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25875 index c73aecf..4c63630 100644
25876 --- a/arch/x86/kernel/mcount_64.S
25877 +++ b/arch/x86/kernel/mcount_64.S
25878 @@ -7,7 +7,7 @@
25879 #include <linux/linkage.h>
25880 #include <asm/ptrace.h>
25881 #include <asm/ftrace.h>
25882 -
25883 +#include <asm/alternative-asm.h>
25884
25885 .code64
25886 .section .entry.text, "ax"
25887 @@ -24,8 +24,9 @@
25888 #ifdef CONFIG_DYNAMIC_FTRACE
25889
25890 ENTRY(function_hook)
25891 + pax_force_retaddr
25892 retq
25893 -END(function_hook)
25894 +ENDPROC(function_hook)
25895
25896 /* skip is set if stack has been adjusted */
25897 .macro ftrace_caller_setup skip=0
25898 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25899 #endif
25900
25901 GLOBAL(ftrace_stub)
25902 + pax_force_retaddr
25903 retq
25904 -END(ftrace_caller)
25905 +ENDPROC(ftrace_caller)
25906
25907 ENTRY(ftrace_regs_caller)
25908 /* Save the current flags before compare (in SS location)*/
25909 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25910 popfq
25911 jmp ftrace_stub
25912
25913 -END(ftrace_regs_caller)
25914 +ENDPROC(ftrace_regs_caller)
25915
25916
25917 #else /* ! CONFIG_DYNAMIC_FTRACE */
25918 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25919 #endif
25920
25921 GLOBAL(ftrace_stub)
25922 + pax_force_retaddr
25923 retq
25924
25925 trace:
25926 @@ -158,12 +161,13 @@ trace:
25927 #endif
25928 subq $MCOUNT_INSN_SIZE, %rdi
25929
25930 + pax_force_fptr ftrace_trace_function
25931 call *ftrace_trace_function
25932
25933 MCOUNT_RESTORE_FRAME
25934
25935 jmp ftrace_stub
25936 -END(function_hook)
25937 +ENDPROC(function_hook)
25938 #endif /* CONFIG_DYNAMIC_FTRACE */
25939 #endif /* CONFIG_FUNCTION_TRACER */
25940
25941 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25942
25943 MCOUNT_RESTORE_FRAME
25944
25945 + pax_force_retaddr
25946 retq
25947 -END(ftrace_graph_caller)
25948 +ENDPROC(ftrace_graph_caller)
25949
25950 GLOBAL(return_to_handler)
25951 subq $24, %rsp
25952 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25953 movq 8(%rsp), %rdx
25954 movq (%rsp), %rax
25955 addq $24, %rsp
25956 + pax_force_fptr %rdi
25957 jmp *%rdi
25958 +ENDPROC(return_to_handler)
25959 #endif
25960 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25961 index e69f988..da078ea 100644
25962 --- a/arch/x86/kernel/module.c
25963 +++ b/arch/x86/kernel/module.c
25964 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25965 }
25966 #endif
25967
25968 -void *module_alloc(unsigned long size)
25969 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25970 {
25971 - if (PAGE_ALIGN(size) > MODULES_LEN)
25972 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25973 return NULL;
25974 return __vmalloc_node_range(size, 1,
25975 MODULES_VADDR + get_module_load_offset(),
25976 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25977 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25978 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25979 + prot, NUMA_NO_NODE,
25980 __builtin_return_address(0));
25981 }
25982
25983 +void *module_alloc(unsigned long size)
25984 +{
25985 +
25986 +#ifdef CONFIG_PAX_KERNEXEC
25987 + return __module_alloc(size, PAGE_KERNEL);
25988 +#else
25989 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25990 +#endif
25991 +
25992 +}
25993 +
25994 +#ifdef CONFIG_PAX_KERNEXEC
25995 +#ifdef CONFIG_X86_32
25996 +void *module_alloc_exec(unsigned long size)
25997 +{
25998 + struct vm_struct *area;
25999 +
26000 + if (size == 0)
26001 + return NULL;
26002 +
26003 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26004 +return area ? area->addr : NULL;
26005 +}
26006 +EXPORT_SYMBOL(module_alloc_exec);
26007 +
26008 +void module_free_exec(struct module *mod, void *module_region)
26009 +{
26010 + vunmap(module_region);
26011 +}
26012 +EXPORT_SYMBOL(module_free_exec);
26013 +#else
26014 +void module_free_exec(struct module *mod, void *module_region)
26015 +{
26016 + module_free(mod, module_region);
26017 +}
26018 +EXPORT_SYMBOL(module_free_exec);
26019 +
26020 +void *module_alloc_exec(unsigned long size)
26021 +{
26022 + return __module_alloc(size, PAGE_KERNEL_RX);
26023 +}
26024 +EXPORT_SYMBOL(module_alloc_exec);
26025 +#endif
26026 +#endif
26027 +
26028 #ifdef CONFIG_X86_32
26029 int apply_relocate(Elf32_Shdr *sechdrs,
26030 const char *strtab,
26031 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26032 unsigned int i;
26033 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26034 Elf32_Sym *sym;
26035 - uint32_t *location;
26036 + uint32_t *plocation, location;
26037
26038 DEBUGP("Applying relocate section %u to %u\n",
26039 relsec, sechdrs[relsec].sh_info);
26040 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26041 /* This is where to make the change */
26042 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26043 - + rel[i].r_offset;
26044 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26045 + location = (uint32_t)plocation;
26046 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26047 + plocation = ktla_ktva((void *)plocation);
26048 /* This is the symbol it is referring to. Note that all
26049 undefined symbols have been resolved. */
26050 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26051 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26052 switch (ELF32_R_TYPE(rel[i].r_info)) {
26053 case R_386_32:
26054 /* We add the value into the location given */
26055 - *location += sym->st_value;
26056 + pax_open_kernel();
26057 + *plocation += sym->st_value;
26058 + pax_close_kernel();
26059 break;
26060 case R_386_PC32:
26061 /* Add the value, subtract its position */
26062 - *location += sym->st_value - (uint32_t)location;
26063 + pax_open_kernel();
26064 + *plocation += sym->st_value - location;
26065 + pax_close_kernel();
26066 break;
26067 default:
26068 pr_err("%s: Unknown relocation: %u\n",
26069 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26070 case R_X86_64_NONE:
26071 break;
26072 case R_X86_64_64:
26073 + pax_open_kernel();
26074 *(u64 *)loc = val;
26075 + pax_close_kernel();
26076 break;
26077 case R_X86_64_32:
26078 + pax_open_kernel();
26079 *(u32 *)loc = val;
26080 + pax_close_kernel();
26081 if (val != *(u32 *)loc)
26082 goto overflow;
26083 break;
26084 case R_X86_64_32S:
26085 + pax_open_kernel();
26086 *(s32 *)loc = val;
26087 + pax_close_kernel();
26088 if ((s64)val != *(s32 *)loc)
26089 goto overflow;
26090 break;
26091 case R_X86_64_PC32:
26092 val -= (u64)loc;
26093 + pax_open_kernel();
26094 *(u32 *)loc = val;
26095 + pax_close_kernel();
26096 +
26097 #if 0
26098 if ((s64)val != *(s32 *)loc)
26099 goto overflow;
26100 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26101 index c9603ac..9f88728 100644
26102 --- a/arch/x86/kernel/msr.c
26103 +++ b/arch/x86/kernel/msr.c
26104 @@ -37,6 +37,7 @@
26105 #include <linux/notifier.h>
26106 #include <linux/uaccess.h>
26107 #include <linux/gfp.h>
26108 +#include <linux/grsecurity.h>
26109
26110 #include <asm/processor.h>
26111 #include <asm/msr.h>
26112 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26113 int err = 0;
26114 ssize_t bytes = 0;
26115
26116 +#ifdef CONFIG_GRKERNSEC_KMEM
26117 + gr_handle_msr_write();
26118 + return -EPERM;
26119 +#endif
26120 +
26121 if (count % 8)
26122 return -EINVAL; /* Invalid chunk size */
26123
26124 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26125 err = -EBADF;
26126 break;
26127 }
26128 +#ifdef CONFIG_GRKERNSEC_KMEM
26129 + gr_handle_msr_write();
26130 + return -EPERM;
26131 +#endif
26132 if (copy_from_user(&regs, uregs, sizeof regs)) {
26133 err = -EFAULT;
26134 break;
26135 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26136 return notifier_from_errno(err);
26137 }
26138
26139 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26140 +static struct notifier_block msr_class_cpu_notifier = {
26141 .notifier_call = msr_class_cpu_callback,
26142 };
26143
26144 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26145 index c3e985d..110a36a 100644
26146 --- a/arch/x86/kernel/nmi.c
26147 +++ b/arch/x86/kernel/nmi.c
26148 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26149
26150 static void nmi_max_handler(struct irq_work *w)
26151 {
26152 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26153 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26154 int remainder_ns, decimal_msecs;
26155 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26156 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26157
26158 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26159 decimal_msecs = remainder_ns / 1000;
26160
26161 printk_ratelimited(KERN_INFO
26162 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26163 - a->handler, whole_msecs, decimal_msecs);
26164 + n->action->handler, whole_msecs, decimal_msecs);
26165 }
26166
26167 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26168 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26169 delta = sched_clock() - delta;
26170 trace_nmi_handler(a->handler, (int)delta, thishandled);
26171
26172 - if (delta < nmi_longest_ns || delta < a->max_duration)
26173 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26174 continue;
26175
26176 - a->max_duration = delta;
26177 - irq_work_queue(&a->irq_work);
26178 + a->work->max_duration = delta;
26179 + irq_work_queue(&a->work->irq_work);
26180 }
26181
26182 rcu_read_unlock();
26183 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26184 }
26185 NOKPROBE_SYMBOL(nmi_handle);
26186
26187 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26188 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26189 {
26190 struct nmi_desc *desc = nmi_to_desc(type);
26191 unsigned long flags;
26192 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26193 if (!action->handler)
26194 return -EINVAL;
26195
26196 - init_irq_work(&action->irq_work, nmi_max_handler);
26197 + action->work->action = action;
26198 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26199
26200 spin_lock_irqsave(&desc->lock, flags);
26201
26202 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26203 * event confuses some handlers (kdump uses this flag)
26204 */
26205 if (action->flags & NMI_FLAG_FIRST)
26206 - list_add_rcu(&action->list, &desc->head);
26207 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26208 else
26209 - list_add_tail_rcu(&action->list, &desc->head);
26210 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26211
26212 spin_unlock_irqrestore(&desc->lock, flags);
26213 return 0;
26214 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26215 if (!strcmp(n->name, name)) {
26216 WARN(in_nmi(),
26217 "Trying to free NMI (%s) from NMI context!\n", n->name);
26218 - list_del_rcu(&n->list);
26219 + pax_list_del_rcu((struct list_head *)&n->list);
26220 break;
26221 }
26222 }
26223 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26224 dotraplinkage notrace void
26225 do_nmi(struct pt_regs *regs, long error_code)
26226 {
26227 +
26228 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26229 + if (!user_mode(regs)) {
26230 + unsigned long cs = regs->cs & 0xFFFF;
26231 + unsigned long ip = ktva_ktla(regs->ip);
26232 +
26233 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26234 + regs->ip = ip;
26235 + }
26236 +#endif
26237 +
26238 nmi_nesting_preprocess(regs);
26239
26240 nmi_enter();
26241 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26242 index 6d9582e..f746287 100644
26243 --- a/arch/x86/kernel/nmi_selftest.c
26244 +++ b/arch/x86/kernel/nmi_selftest.c
26245 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26246 {
26247 /* trap all the unknown NMIs we may generate */
26248 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26249 - __initdata);
26250 + __initconst);
26251 }
26252
26253 static void __init cleanup_nmi_testsuite(void)
26254 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26255 unsigned long timeout;
26256
26257 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26258 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26259 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26260 nmi_fail = FAILURE;
26261 return;
26262 }
26263 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26264 index bbb6c73..24a58ef 100644
26265 --- a/arch/x86/kernel/paravirt-spinlocks.c
26266 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26267 @@ -8,7 +8,7 @@
26268
26269 #include <asm/paravirt.h>
26270
26271 -struct pv_lock_ops pv_lock_ops = {
26272 +struct pv_lock_ops pv_lock_ops __read_only = {
26273 #ifdef CONFIG_SMP
26274 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26275 .unlock_kick = paravirt_nop,
26276 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26277 index 548d25f..f8fb99c 100644
26278 --- a/arch/x86/kernel/paravirt.c
26279 +++ b/arch/x86/kernel/paravirt.c
26280 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26281 {
26282 return x;
26283 }
26284 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26285 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26286 +#endif
26287
26288 void __init default_banner(void)
26289 {
26290 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26291
26292 if (opfunc == NULL)
26293 /* If there's no function, patch it with a ud2a (BUG) */
26294 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26295 - else if (opfunc == _paravirt_nop)
26296 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26297 + else if (opfunc == (void *)_paravirt_nop)
26298 /* If the operation is a nop, then nop the callsite */
26299 ret = paravirt_patch_nop();
26300
26301 /* identity functions just return their single argument */
26302 - else if (opfunc == _paravirt_ident_32)
26303 + else if (opfunc == (void *)_paravirt_ident_32)
26304 ret = paravirt_patch_ident_32(insnbuf, len);
26305 - else if (opfunc == _paravirt_ident_64)
26306 + else if (opfunc == (void *)_paravirt_ident_64)
26307 ret = paravirt_patch_ident_64(insnbuf, len);
26308 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26309 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26310 + ret = paravirt_patch_ident_64(insnbuf, len);
26311 +#endif
26312
26313 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26314 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26315 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26316 if (insn_len > len || start == NULL)
26317 insn_len = len;
26318 else
26319 - memcpy(insnbuf, start, insn_len);
26320 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26321
26322 return insn_len;
26323 }
26324 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26325 return this_cpu_read(paravirt_lazy_mode);
26326 }
26327
26328 -struct pv_info pv_info = {
26329 +struct pv_info pv_info __read_only = {
26330 .name = "bare hardware",
26331 .paravirt_enabled = 0,
26332 .kernel_rpl = 0,
26333 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26334 #endif
26335 };
26336
26337 -struct pv_init_ops pv_init_ops = {
26338 +struct pv_init_ops pv_init_ops __read_only = {
26339 .patch = native_patch,
26340 };
26341
26342 -struct pv_time_ops pv_time_ops = {
26343 +struct pv_time_ops pv_time_ops __read_only = {
26344 .sched_clock = native_sched_clock,
26345 .steal_clock = native_steal_clock,
26346 };
26347
26348 -__visible struct pv_irq_ops pv_irq_ops = {
26349 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26350 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26351 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26352 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26353 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26354 #endif
26355 };
26356
26357 -__visible struct pv_cpu_ops pv_cpu_ops = {
26358 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26359 .cpuid = native_cpuid,
26360 .get_debugreg = native_get_debugreg,
26361 .set_debugreg = native_set_debugreg,
26362 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26363 NOKPROBE_SYMBOL(native_set_debugreg);
26364 NOKPROBE_SYMBOL(native_load_idt);
26365
26366 -struct pv_apic_ops pv_apic_ops = {
26367 +struct pv_apic_ops pv_apic_ops __read_only= {
26368 #ifdef CONFIG_X86_LOCAL_APIC
26369 .startup_ipi_hook = paravirt_nop,
26370 #endif
26371 };
26372
26373 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26374 +#ifdef CONFIG_X86_32
26375 +#ifdef CONFIG_X86_PAE
26376 +/* 64-bit pagetable entries */
26377 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26378 +#else
26379 /* 32-bit pagetable entries */
26380 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26381 +#endif
26382 #else
26383 /* 64-bit pagetable entries */
26384 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26385 #endif
26386
26387 -struct pv_mmu_ops pv_mmu_ops = {
26388 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26389
26390 .read_cr2 = native_read_cr2,
26391 .write_cr2 = native_write_cr2,
26392 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26393 .make_pud = PTE_IDENT,
26394
26395 .set_pgd = native_set_pgd,
26396 + .set_pgd_batched = native_set_pgd_batched,
26397 #endif
26398 #endif /* PAGETABLE_LEVELS >= 3 */
26399
26400 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26401 },
26402
26403 .set_fixmap = native_set_fixmap,
26404 +
26405 +#ifdef CONFIG_PAX_KERNEXEC
26406 + .pax_open_kernel = native_pax_open_kernel,
26407 + .pax_close_kernel = native_pax_close_kernel,
26408 +#endif
26409 +
26410 };
26411
26412 EXPORT_SYMBOL_GPL(pv_time_ops);
26413 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26414 index a1da673..b6f5831 100644
26415 --- a/arch/x86/kernel/paravirt_patch_64.c
26416 +++ b/arch/x86/kernel/paravirt_patch_64.c
26417 @@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26418 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26419 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26420 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26421 +
26422 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26423 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26424 +#endif
26425 +
26426 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26427 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26428
26429 @@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26430 PATCH_SITE(pv_mmu_ops, read_cr3);
26431 PATCH_SITE(pv_mmu_ops, write_cr3);
26432 PATCH_SITE(pv_cpu_ops, clts);
26433 +
26434 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26435 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26436 +#endif
26437 +
26438 PATCH_SITE(pv_cpu_ops, wbinvd);
26439
26440 patch_site:
26441 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26442 index 0497f71..7186c0d 100644
26443 --- a/arch/x86/kernel/pci-calgary_64.c
26444 +++ b/arch/x86/kernel/pci-calgary_64.c
26445 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26446 tce_space = be64_to_cpu(readq(target));
26447 tce_space = tce_space & TAR_SW_BITS;
26448
26449 - tce_space = tce_space & (~specified_table_size);
26450 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26451 info->tce_space = (u64 *)__va(tce_space);
26452 }
26453 }
26454 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26455 index 35ccf75..7a15747 100644
26456 --- a/arch/x86/kernel/pci-iommu_table.c
26457 +++ b/arch/x86/kernel/pci-iommu_table.c
26458 @@ -2,7 +2,7 @@
26459 #include <asm/iommu_table.h>
26460 #include <linux/string.h>
26461 #include <linux/kallsyms.h>
26462 -
26463 +#include <linux/sched.h>
26464
26465 #define DEBUG 1
26466
26467 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26468 index 77dd0ad..9ec4723 100644
26469 --- a/arch/x86/kernel/pci-swiotlb.c
26470 +++ b/arch/x86/kernel/pci-swiotlb.c
26471 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26472 struct dma_attrs *attrs)
26473 {
26474 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26475 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26476 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26477 else
26478 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26479 }
26480 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26481 index e127dda..94e384d 100644
26482 --- a/arch/x86/kernel/process.c
26483 +++ b/arch/x86/kernel/process.c
26484 @@ -36,7 +36,8 @@
26485 * section. Since TSS's are completely CPU-local, we want them
26486 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26487 */
26488 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26489 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26490 +EXPORT_SYMBOL(init_tss);
26491
26492 #ifdef CONFIG_X86_64
26493 static DEFINE_PER_CPU(unsigned char, is_idle);
26494 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26495 task_xstate_cachep =
26496 kmem_cache_create("task_xstate", xstate_size,
26497 __alignof__(union thread_xstate),
26498 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26499 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26500 setup_xstate_comp();
26501 }
26502
26503 @@ -108,7 +109,7 @@ void exit_thread(void)
26504 unsigned long *bp = t->io_bitmap_ptr;
26505
26506 if (bp) {
26507 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26508 + struct tss_struct *tss = init_tss + get_cpu();
26509
26510 t->io_bitmap_ptr = NULL;
26511 clear_thread_flag(TIF_IO_BITMAP);
26512 @@ -128,6 +129,9 @@ void flush_thread(void)
26513 {
26514 struct task_struct *tsk = current;
26515
26516 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26517 + loadsegment(gs, 0);
26518 +#endif
26519 flush_ptrace_hw_breakpoint(tsk);
26520 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26521 drop_init_fpu(tsk);
26522 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26523 void exit_idle(void)
26524 {
26525 /* idle loop has pid 0 */
26526 - if (current->pid)
26527 + if (task_pid_nr(current))
26528 return;
26529 __exit_idle();
26530 }
26531 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26532 return ret;
26533 }
26534 #endif
26535 -void stop_this_cpu(void *dummy)
26536 +__noreturn void stop_this_cpu(void *dummy)
26537 {
26538 local_irq_disable();
26539 /*
26540 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26541 }
26542 early_param("idle", idle_setup);
26543
26544 -unsigned long arch_align_stack(unsigned long sp)
26545 +#ifdef CONFIG_PAX_RANDKSTACK
26546 +void pax_randomize_kstack(struct pt_regs *regs)
26547 {
26548 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26549 - sp -= get_random_int() % 8192;
26550 - return sp & ~0xf;
26551 -}
26552 + struct thread_struct *thread = &current->thread;
26553 + unsigned long time;
26554
26555 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26556 -{
26557 - unsigned long range_end = mm->brk + 0x02000000;
26558 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26559 -}
26560 + if (!randomize_va_space)
26561 + return;
26562 +
26563 + if (v8086_mode(regs))
26564 + return;
26565
26566 + rdtscl(time);
26567 +
26568 + /* P4 seems to return a 0 LSB, ignore it */
26569 +#ifdef CONFIG_MPENTIUM4
26570 + time &= 0x3EUL;
26571 + time <<= 2;
26572 +#elif defined(CONFIG_X86_64)
26573 + time &= 0xFUL;
26574 + time <<= 4;
26575 +#else
26576 + time &= 0x1FUL;
26577 + time <<= 3;
26578 +#endif
26579 +
26580 + thread->sp0 ^= time;
26581 + load_sp0(init_tss + smp_processor_id(), thread);
26582 +
26583 +#ifdef CONFIG_X86_64
26584 + this_cpu_write(kernel_stack, thread->sp0);
26585 +#endif
26586 +}
26587 +#endif
26588 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26589 index 8f3ebfe..cbc731b 100644
26590 --- a/arch/x86/kernel/process_32.c
26591 +++ b/arch/x86/kernel/process_32.c
26592 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26593 unsigned long thread_saved_pc(struct task_struct *tsk)
26594 {
26595 return ((unsigned long *)tsk->thread.sp)[3];
26596 +//XXX return tsk->thread.eip;
26597 }
26598
26599 void __show_regs(struct pt_regs *regs, int all)
26600 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26601 unsigned long sp;
26602 unsigned short ss, gs;
26603
26604 - if (user_mode_vm(regs)) {
26605 + if (user_mode(regs)) {
26606 sp = regs->sp;
26607 ss = regs->ss & 0xffff;
26608 - gs = get_user_gs(regs);
26609 } else {
26610 sp = kernel_stack_pointer(regs);
26611 savesegment(ss, ss);
26612 - savesegment(gs, gs);
26613 }
26614 + gs = get_user_gs(regs);
26615
26616 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26617 (u16)regs->cs, regs->ip, regs->flags,
26618 - smp_processor_id());
26619 + raw_smp_processor_id());
26620 print_symbol("EIP is at %s\n", regs->ip);
26621
26622 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26623 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26624 int copy_thread(unsigned long clone_flags, unsigned long sp,
26625 unsigned long arg, struct task_struct *p)
26626 {
26627 - struct pt_regs *childregs = task_pt_regs(p);
26628 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26629 struct task_struct *tsk;
26630 int err;
26631
26632 p->thread.sp = (unsigned long) childregs;
26633 p->thread.sp0 = (unsigned long) (childregs+1);
26634 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26635 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26636
26637 if (unlikely(p->flags & PF_KTHREAD)) {
26638 /* kernel thread */
26639 memset(childregs, 0, sizeof(struct pt_regs));
26640 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26641 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26642 - childregs->ds = __USER_DS;
26643 - childregs->es = __USER_DS;
26644 + savesegment(gs, childregs->gs);
26645 + childregs->ds = __KERNEL_DS;
26646 + childregs->es = __KERNEL_DS;
26647 childregs->fs = __KERNEL_PERCPU;
26648 childregs->bx = sp; /* function */
26649 childregs->bp = arg;
26650 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26651 struct thread_struct *prev = &prev_p->thread,
26652 *next = &next_p->thread;
26653 int cpu = smp_processor_id();
26654 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26655 + struct tss_struct *tss = init_tss + cpu;
26656 fpu_switch_t fpu;
26657
26658 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26659 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26660 */
26661 lazy_save_gs(prev->gs);
26662
26663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26664 + __set_fs(task_thread_info(next_p)->addr_limit);
26665 +#endif
26666 +
26667 /*
26668 * Load the per-thread Thread-Local Storage descriptor.
26669 */
26670 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26671 */
26672 arch_end_context_switch(next_p);
26673
26674 - this_cpu_write(kernel_stack,
26675 - (unsigned long)task_stack_page(next_p) +
26676 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26677 + this_cpu_write(current_task, next_p);
26678 + this_cpu_write(current_tinfo, &next_p->tinfo);
26679 + this_cpu_write(kernel_stack, next->sp0);
26680
26681 /*
26682 * Restore %gs if needed (which is common)
26683 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26684
26685 switch_fpu_finish(next_p, fpu);
26686
26687 - this_cpu_write(current_task, next_p);
26688 -
26689 return prev_p;
26690 }
26691
26692 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26693 } while (count++ < 16);
26694 return 0;
26695 }
26696 -
26697 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26698 index 5a2c029..ec8611d 100644
26699 --- a/arch/x86/kernel/process_64.c
26700 +++ b/arch/x86/kernel/process_64.c
26701 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26702 struct pt_regs *childregs;
26703 struct task_struct *me = current;
26704
26705 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26706 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26707 childregs = task_pt_regs(p);
26708 p->thread.sp = (unsigned long) childregs;
26709 p->thread.usersp = me->thread.usersp;
26710 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26711 set_tsk_thread_flag(p, TIF_FORK);
26712 p->thread.io_bitmap_ptr = NULL;
26713
26714 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26715 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26716 savesegment(es, p->thread.es);
26717 savesegment(ds, p->thread.ds);
26718 + savesegment(ss, p->thread.ss);
26719 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26720 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26721
26722 if (unlikely(p->flags & PF_KTHREAD)) {
26723 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26724 struct thread_struct *prev = &prev_p->thread;
26725 struct thread_struct *next = &next_p->thread;
26726 int cpu = smp_processor_id();
26727 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26728 + struct tss_struct *tss = init_tss + cpu;
26729 unsigned fsindex, gsindex;
26730 fpu_switch_t fpu;
26731
26732 @@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26733 if (unlikely(next->ds | prev->ds))
26734 loadsegment(ds, next->ds);
26735
26736 + savesegment(ss, prev->ss);
26737 + if (unlikely(next->ss != prev->ss))
26738 + loadsegment(ss, next->ss);
26739 +
26740 /*
26741 * Switch FS and GS.
26742 *
26743 @@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26744 prev->usersp = this_cpu_read(old_rsp);
26745 this_cpu_write(old_rsp, next->usersp);
26746 this_cpu_write(current_task, next_p);
26747 + this_cpu_write(current_tinfo, &next_p->tinfo);
26748
26749 /*
26750 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26751 @@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26752 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26753 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26754
26755 - this_cpu_write(kernel_stack,
26756 - (unsigned long)task_stack_page(next_p) +
26757 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26758 + this_cpu_write(kernel_stack, next->sp0);
26759
26760 /*
26761 * Now maybe reload the debug registers and handle I/O bitmaps
26762 @@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26763 if (!p || p == current || p->state == TASK_RUNNING)
26764 return 0;
26765 stack = (unsigned long)task_stack_page(p);
26766 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26767 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26768 return 0;
26769 fp = *(u64 *)(p->thread.sp);
26770 do {
26771 - if (fp < (unsigned long)stack ||
26772 - fp >= (unsigned long)stack+THREAD_SIZE)
26773 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26774 return 0;
26775 ip = *(u64 *)(fp+8);
26776 if (!in_sched_functions(ip))
26777 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26778 index e510618..5165ac0 100644
26779 --- a/arch/x86/kernel/ptrace.c
26780 +++ b/arch/x86/kernel/ptrace.c
26781 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26782 unsigned long sp = (unsigned long)&regs->sp;
26783 u32 *prev_esp;
26784
26785 - if (context == (sp & ~(THREAD_SIZE - 1)))
26786 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26787 return sp;
26788
26789 - prev_esp = (u32 *)(context);
26790 + prev_esp = *(u32 **)(context);
26791 if (prev_esp)
26792 return (unsigned long)prev_esp;
26793
26794 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26795 if (child->thread.gs != value)
26796 return do_arch_prctl(child, ARCH_SET_GS, value);
26797 return 0;
26798 +
26799 + case offsetof(struct user_regs_struct,ip):
26800 + /*
26801 + * Protect against any attempt to set ip to an
26802 + * impossible address. There are dragons lurking if the
26803 + * address is noncanonical. (This explicitly allows
26804 + * setting ip to TASK_SIZE_MAX, because user code can do
26805 + * that all by itself by running off the end of its
26806 + * address space.
26807 + */
26808 + if (value > TASK_SIZE_MAX)
26809 + return -EIO;
26810 + break;
26811 +
26812 #endif
26813 }
26814
26815 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26816 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26817 {
26818 int i;
26819 - int dr7 = 0;
26820 + unsigned long dr7 = 0;
26821 struct arch_hw_breakpoint *info;
26822
26823 for (i = 0; i < HBP_NUM; i++) {
26824 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26825 unsigned long addr, unsigned long data)
26826 {
26827 int ret;
26828 - unsigned long __user *datap = (unsigned long __user *)data;
26829 + unsigned long __user *datap = (__force unsigned long __user *)data;
26830
26831 switch (request) {
26832 /* read the word at location addr in the USER area. */
26833 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26834 if ((int) addr < 0)
26835 return -EIO;
26836 ret = do_get_thread_area(child, addr,
26837 - (struct user_desc __user *)data);
26838 + (__force struct user_desc __user *) data);
26839 break;
26840
26841 case PTRACE_SET_THREAD_AREA:
26842 if ((int) addr < 0)
26843 return -EIO;
26844 ret = do_set_thread_area(child, addr,
26845 - (struct user_desc __user *)data, 0);
26846 + (__force struct user_desc __user *) data, 0);
26847 break;
26848 #endif
26849
26850 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26851
26852 #ifdef CONFIG_X86_64
26853
26854 -static struct user_regset x86_64_regsets[] __read_mostly = {
26855 +static user_regset_no_const x86_64_regsets[] __read_only = {
26856 [REGSET_GENERAL] = {
26857 .core_note_type = NT_PRSTATUS,
26858 .n = sizeof(struct user_regs_struct) / sizeof(long),
26859 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26860 #endif /* CONFIG_X86_64 */
26861
26862 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26863 -static struct user_regset x86_32_regsets[] __read_mostly = {
26864 +static user_regset_no_const x86_32_regsets[] __read_only = {
26865 [REGSET_GENERAL] = {
26866 .core_note_type = NT_PRSTATUS,
26867 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26868 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26869 */
26870 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26871
26872 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26873 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26874 {
26875 #ifdef CONFIG_X86_64
26876 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26877 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26878 memset(info, 0, sizeof(*info));
26879 info->si_signo = SIGTRAP;
26880 info->si_code = si_code;
26881 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26882 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26883 }
26884
26885 void user_single_step_siginfo(struct task_struct *tsk,
26886 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26887 }
26888 }
26889
26890 +#ifdef CONFIG_GRKERNSEC_SETXID
26891 +extern void gr_delayed_cred_worker(void);
26892 +#endif
26893 +
26894 /*
26895 * We can return 0 to resume the syscall or anything else to go to phase
26896 * 2. If we resume the syscall, we need to put something appropriate in
26897 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26898
26899 BUG_ON(regs != task_pt_regs(current));
26900
26901 +#ifdef CONFIG_GRKERNSEC_SETXID
26902 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26903 + gr_delayed_cred_worker();
26904 +#endif
26905 +
26906 /*
26907 * If we stepped into a sysenter/syscall insn, it trapped in
26908 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26909 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26910 */
26911 user_exit();
26912
26913 +#ifdef CONFIG_GRKERNSEC_SETXID
26914 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26915 + gr_delayed_cred_worker();
26916 +#endif
26917 +
26918 audit_syscall_exit(regs);
26919
26920 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26921 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26922 index 2f355d2..e75ed0a 100644
26923 --- a/arch/x86/kernel/pvclock.c
26924 +++ b/arch/x86/kernel/pvclock.c
26925 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26926 reset_hung_task_detector();
26927 }
26928
26929 -static atomic64_t last_value = ATOMIC64_INIT(0);
26930 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26931
26932 void pvclock_resume(void)
26933 {
26934 - atomic64_set(&last_value, 0);
26935 + atomic64_set_unchecked(&last_value, 0);
26936 }
26937
26938 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26939 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26940 * updating at the same time, and one of them could be slightly behind,
26941 * making the assumption that last_value always go forward fail to hold.
26942 */
26943 - last = atomic64_read(&last_value);
26944 + last = atomic64_read_unchecked(&last_value);
26945 do {
26946 if (ret < last)
26947 return last;
26948 - last = atomic64_cmpxchg(&last_value, last, ret);
26949 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26950 } while (unlikely(last != ret));
26951
26952 return ret;
26953 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26954 index 17962e6..47f55db 100644
26955 --- a/arch/x86/kernel/reboot.c
26956 +++ b/arch/x86/kernel/reboot.c
26957 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26958
26959 void __noreturn machine_real_restart(unsigned int type)
26960 {
26961 +
26962 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26963 + struct desc_struct *gdt;
26964 +#endif
26965 +
26966 local_irq_disable();
26967
26968 /*
26969 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26970
26971 /* Jump to the identity-mapped low memory code */
26972 #ifdef CONFIG_X86_32
26973 - asm volatile("jmpl *%0" : :
26974 +
26975 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26976 + gdt = get_cpu_gdt_table(smp_processor_id());
26977 + pax_open_kernel();
26978 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26979 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26980 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26981 + loadsegment(ds, __KERNEL_DS);
26982 + loadsegment(es, __KERNEL_DS);
26983 + loadsegment(ss, __KERNEL_DS);
26984 +#endif
26985 +#ifdef CONFIG_PAX_KERNEXEC
26986 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26987 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26988 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26989 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26990 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26991 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26992 +#endif
26993 + pax_close_kernel();
26994 +#endif
26995 +
26996 + asm volatile("ljmpl *%0" : :
26997 "rm" (real_mode_header->machine_real_restart_asm),
26998 "a" (type));
26999 #else
27000 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27001 * This means that this function can never return, it can misbehave
27002 * by not rebooting properly and hanging.
27003 */
27004 -static void native_machine_emergency_restart(void)
27005 +static void __noreturn native_machine_emergency_restart(void)
27006 {
27007 int i;
27008 int attempt = 0;
27009 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27010 #endif
27011 }
27012
27013 -static void __machine_emergency_restart(int emergency)
27014 +static void __noreturn __machine_emergency_restart(int emergency)
27015 {
27016 reboot_emergency = emergency;
27017 machine_ops.emergency_restart();
27018 }
27019
27020 -static void native_machine_restart(char *__unused)
27021 +static void __noreturn native_machine_restart(char *__unused)
27022 {
27023 pr_notice("machine restart\n");
27024
27025 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27026 __machine_emergency_restart(0);
27027 }
27028
27029 -static void native_machine_halt(void)
27030 +static void __noreturn native_machine_halt(void)
27031 {
27032 /* Stop other cpus and apics */
27033 machine_shutdown();
27034 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27035 stop_this_cpu(NULL);
27036 }
27037
27038 -static void native_machine_power_off(void)
27039 +static void __noreturn native_machine_power_off(void)
27040 {
27041 if (pm_power_off) {
27042 if (!reboot_force)
27043 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27044 }
27045 /* A fallback in case there is no PM info available */
27046 tboot_shutdown(TB_SHUTDOWN_HALT);
27047 + unreachable();
27048 }
27049
27050 -struct machine_ops machine_ops = {
27051 +struct machine_ops machine_ops __read_only = {
27052 .power_off = native_machine_power_off,
27053 .shutdown = native_machine_shutdown,
27054 .emergency_restart = native_machine_emergency_restart,
27055 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27056 index c8e41e9..64049ef 100644
27057 --- a/arch/x86/kernel/reboot_fixups_32.c
27058 +++ b/arch/x86/kernel/reboot_fixups_32.c
27059 @@ -57,7 +57,7 @@ struct device_fixup {
27060 unsigned int vendor;
27061 unsigned int device;
27062 void (*reboot_fixup)(struct pci_dev *);
27063 -};
27064 +} __do_const;
27065
27066 /*
27067 * PCI ids solely used for fixups_table go here
27068 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27069 index 3fd2c69..a444264 100644
27070 --- a/arch/x86/kernel/relocate_kernel_64.S
27071 +++ b/arch/x86/kernel/relocate_kernel_64.S
27072 @@ -96,8 +96,7 @@ relocate_kernel:
27073
27074 /* jump to identity mapped page */
27075 addq $(identity_mapped - relocate_kernel), %r8
27076 - pushq %r8
27077 - ret
27078 + jmp *%r8
27079
27080 identity_mapped:
27081 /* set return address to 0 if not preserving context */
27082 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27083 index ab08aa2..6d74a3a 100644
27084 --- a/arch/x86/kernel/setup.c
27085 +++ b/arch/x86/kernel/setup.c
27086 @@ -110,6 +110,7 @@
27087 #include <asm/mce.h>
27088 #include <asm/alternative.h>
27089 #include <asm/prom.h>
27090 +#include <asm/boot.h>
27091
27092 /*
27093 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27094 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27095 #endif
27096
27097
27098 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27099 -__visible unsigned long mmu_cr4_features;
27100 +#ifdef CONFIG_X86_64
27101 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27102 +#elif defined(CONFIG_X86_PAE)
27103 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27104 #else
27105 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27106 +__visible unsigned long mmu_cr4_features __read_only;
27107 #endif
27108
27109 +void set_in_cr4(unsigned long mask)
27110 +{
27111 + unsigned long cr4 = read_cr4();
27112 +
27113 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27114 + return;
27115 +
27116 + pax_open_kernel();
27117 + mmu_cr4_features |= mask;
27118 + pax_close_kernel();
27119 +
27120 + if (trampoline_cr4_features)
27121 + *trampoline_cr4_features = mmu_cr4_features;
27122 + cr4 |= mask;
27123 + write_cr4(cr4);
27124 +}
27125 +EXPORT_SYMBOL(set_in_cr4);
27126 +
27127 +void clear_in_cr4(unsigned long mask)
27128 +{
27129 + unsigned long cr4 = read_cr4();
27130 +
27131 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27132 + return;
27133 +
27134 + pax_open_kernel();
27135 + mmu_cr4_features &= ~mask;
27136 + pax_close_kernel();
27137 +
27138 + if (trampoline_cr4_features)
27139 + *trampoline_cr4_features = mmu_cr4_features;
27140 + cr4 &= ~mask;
27141 + write_cr4(cr4);
27142 +}
27143 +EXPORT_SYMBOL(clear_in_cr4);
27144 +
27145 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27146 int bootloader_type, bootloader_version;
27147
27148 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27149 * area (640->1Mb) as ram even though it is not.
27150 * take them out.
27151 */
27152 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27153 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27154
27155 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27156 }
27157 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27158 /* called before trim_bios_range() to spare extra sanitize */
27159 static void __init e820_add_kernel_range(void)
27160 {
27161 - u64 start = __pa_symbol(_text);
27162 + u64 start = __pa_symbol(ktla_ktva(_text));
27163 u64 size = __pa_symbol(_end) - start;
27164
27165 /*
27166 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27167
27168 void __init setup_arch(char **cmdline_p)
27169 {
27170 +#ifdef CONFIG_X86_32
27171 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27172 +#else
27173 memblock_reserve(__pa_symbol(_text),
27174 (unsigned long)__bss_stop - (unsigned long)_text);
27175 +#endif
27176
27177 early_reserve_initrd();
27178
27179 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27180
27181 if (!boot_params.hdr.root_flags)
27182 root_mountflags &= ~MS_RDONLY;
27183 - init_mm.start_code = (unsigned long) _text;
27184 - init_mm.end_code = (unsigned long) _etext;
27185 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27186 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27187 init_mm.end_data = (unsigned long) _edata;
27188 init_mm.brk = _brk_end;
27189
27190 - code_resource.start = __pa_symbol(_text);
27191 - code_resource.end = __pa_symbol(_etext)-1;
27192 - data_resource.start = __pa_symbol(_etext);
27193 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27194 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27195 + data_resource.start = __pa_symbol(_sdata);
27196 data_resource.end = __pa_symbol(_edata)-1;
27197 bss_resource.start = __pa_symbol(__bss_start);
27198 bss_resource.end = __pa_symbol(__bss_stop)-1;
27199 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27200 index 5cdff03..80fa283 100644
27201 --- a/arch/x86/kernel/setup_percpu.c
27202 +++ b/arch/x86/kernel/setup_percpu.c
27203 @@ -21,19 +21,17 @@
27204 #include <asm/cpu.h>
27205 #include <asm/stackprotector.h>
27206
27207 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27208 +#ifdef CONFIG_SMP
27209 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27210 EXPORT_PER_CPU_SYMBOL(cpu_number);
27211 +#endif
27212
27213 -#ifdef CONFIG_X86_64
27214 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27215 -#else
27216 -#define BOOT_PERCPU_OFFSET 0
27217 -#endif
27218
27219 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27220 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27221
27222 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27223 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27224 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27225 };
27226 EXPORT_SYMBOL(__per_cpu_offset);
27227 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27228 {
27229 #ifdef CONFIG_NEED_MULTIPLE_NODES
27230 pg_data_t *last = NULL;
27231 - unsigned int cpu;
27232 + int cpu;
27233
27234 for_each_possible_cpu(cpu) {
27235 int node = early_cpu_to_node(cpu);
27236 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27237 {
27238 #ifdef CONFIG_X86_32
27239 struct desc_struct gdt;
27240 + unsigned long base = per_cpu_offset(cpu);
27241
27242 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27243 - 0x2 | DESCTYPE_S, 0x8);
27244 - gdt.s = 1;
27245 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27246 + 0x83 | DESCTYPE_S, 0xC);
27247 write_gdt_entry(get_cpu_gdt_table(cpu),
27248 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27249 #endif
27250 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27251 /* alrighty, percpu areas up and running */
27252 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27253 for_each_possible_cpu(cpu) {
27254 +#ifdef CONFIG_CC_STACKPROTECTOR
27255 +#ifdef CONFIG_X86_32
27256 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27257 +#endif
27258 +#endif
27259 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27260 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27261 per_cpu(cpu_number, cpu) = cpu;
27262 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27263 */
27264 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27265 #endif
27266 +#ifdef CONFIG_CC_STACKPROTECTOR
27267 +#ifdef CONFIG_X86_32
27268 + if (!cpu)
27269 + per_cpu(stack_canary.canary, cpu) = canary;
27270 +#endif
27271 +#endif
27272 /*
27273 * Up to this point, the boot CPU has been using .init.data
27274 * area. Reload any changed state for the boot CPU.
27275 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27276 index ed37a76..39f936e 100644
27277 --- a/arch/x86/kernel/signal.c
27278 +++ b/arch/x86/kernel/signal.c
27279 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27280 * Align the stack pointer according to the i386 ABI,
27281 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27282 */
27283 - sp = ((sp + 4) & -16ul) - 4;
27284 + sp = ((sp - 12) & -16ul) - 4;
27285 #else /* !CONFIG_X86_32 */
27286 sp = round_down(sp, 16) - 8;
27287 #endif
27288 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27289 }
27290
27291 if (current->mm->context.vdso)
27292 - restorer = current->mm->context.vdso +
27293 - selected_vdso32->sym___kernel_sigreturn;
27294 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27295 else
27296 - restorer = &frame->retcode;
27297 + restorer = (void __user *)&frame->retcode;
27298 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27299 restorer = ksig->ka.sa.sa_restorer;
27300
27301 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27302 * reasons and because gdb uses it as a signature to notice
27303 * signal handler stack frames.
27304 */
27305 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27306 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27307
27308 if (err)
27309 return -EFAULT;
27310 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27311 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27312
27313 /* Set up to return from userspace. */
27314 - restorer = current->mm->context.vdso +
27315 - selected_vdso32->sym___kernel_rt_sigreturn;
27316 + if (current->mm->context.vdso)
27317 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27318 + else
27319 + restorer = (void __user *)&frame->retcode;
27320 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27321 restorer = ksig->ka.sa.sa_restorer;
27322 put_user_ex(restorer, &frame->pretcode);
27323 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27324 * reasons and because gdb uses it as a signature to notice
27325 * signal handler stack frames.
27326 */
27327 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27328 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27329 } put_user_catch(err);
27330
27331 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27332 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27333 {
27334 int usig = signr_convert(ksig->sig);
27335 sigset_t *set = sigmask_to_save();
27336 - compat_sigset_t *cset = (compat_sigset_t *) set;
27337 + sigset_t sigcopy;
27338 + compat_sigset_t *cset;
27339 +
27340 + sigcopy = *set;
27341 +
27342 + cset = (compat_sigset_t *) &sigcopy;
27343
27344 /* Set up the stack frame */
27345 if (is_ia32_frame()) {
27346 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27347 } else if (is_x32_frame()) {
27348 return x32_setup_rt_frame(ksig, cset, regs);
27349 } else {
27350 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27351 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27352 }
27353 }
27354
27355 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27356 index be8e1bd..a3d93fa 100644
27357 --- a/arch/x86/kernel/smp.c
27358 +++ b/arch/x86/kernel/smp.c
27359 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27360
27361 __setup("nonmi_ipi", nonmi_ipi_setup);
27362
27363 -struct smp_ops smp_ops = {
27364 +struct smp_ops smp_ops __read_only = {
27365 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27366 .smp_prepare_cpus = native_smp_prepare_cpus,
27367 .smp_cpus_done = native_smp_cpus_done,
27368 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27369 index 668d8f2..84a9d54 100644
27370 --- a/arch/x86/kernel/smpboot.c
27371 +++ b/arch/x86/kernel/smpboot.c
27372 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27373
27374 enable_start_cpu0 = 0;
27375
27376 -#ifdef CONFIG_X86_32
27377 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27378 + barrier();
27379 +
27380 /* switch away from the initial page table */
27381 +#ifdef CONFIG_PAX_PER_CPU_PGD
27382 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27383 +#else
27384 load_cr3(swapper_pg_dir);
27385 +#endif
27386 __flush_tlb_all();
27387 -#endif
27388
27389 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27390 - barrier();
27391 /*
27392 * Check TSC synchronization with the BP:
27393 */
27394 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27395 alternatives_enable_smp();
27396
27397 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27398 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27399 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27400 per_cpu(current_task, cpu) = idle;
27401 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27402
27403 #ifdef CONFIG_X86_32
27404 /* Stack for startup_32 can be just as for start_secondary onwards */
27405 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27406 clear_tsk_thread_flag(idle, TIF_FORK);
27407 initial_gs = per_cpu_offset(cpu);
27408 #endif
27409 - per_cpu(kernel_stack, cpu) =
27410 - (unsigned long)task_stack_page(idle) -
27411 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27412 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27413 + pax_open_kernel();
27414 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27415 + pax_close_kernel();
27416 initial_code = (unsigned long)start_secondary;
27417 stack_start = idle->thread.sp;
27418
27419 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27420 /* the FPU context is blank, nobody can own it */
27421 __cpu_disable_lazy_restore(cpu);
27422
27423 +#ifdef CONFIG_PAX_PER_CPU_PGD
27424 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27425 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27426 + KERNEL_PGD_PTRS);
27427 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27428 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27429 + KERNEL_PGD_PTRS);
27430 +#endif
27431 +
27432 err = do_boot_cpu(apicid, cpu, tidle);
27433 if (err) {
27434 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27435 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27436 index 9b4d51d..5d28b58 100644
27437 --- a/arch/x86/kernel/step.c
27438 +++ b/arch/x86/kernel/step.c
27439 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27440 struct desc_struct *desc;
27441 unsigned long base;
27442
27443 - seg &= ~7UL;
27444 + seg >>= 3;
27445
27446 mutex_lock(&child->mm->context.lock);
27447 - if (unlikely((seg >> 3) >= child->mm->context.size))
27448 + if (unlikely(seg >= child->mm->context.size))
27449 addr = -1L; /* bogus selector, access would fault */
27450 else {
27451 desc = child->mm->context.ldt + seg;
27452 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27453 addr += base;
27454 }
27455 mutex_unlock(&child->mm->context.lock);
27456 - }
27457 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27458 + addr = ktla_ktva(addr);
27459
27460 return addr;
27461 }
27462 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27463 unsigned char opcode[15];
27464 unsigned long addr = convert_ip_to_linear(child, regs);
27465
27466 + if (addr == -EINVAL)
27467 + return 0;
27468 +
27469 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27470 for (i = 0; i < copied; i++) {
27471 switch (opcode[i]) {
27472 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27473 new file mode 100644
27474 index 0000000..5877189
27475 --- /dev/null
27476 +++ b/arch/x86/kernel/sys_i386_32.c
27477 @@ -0,0 +1,189 @@
27478 +/*
27479 + * This file contains various random system calls that
27480 + * have a non-standard calling sequence on the Linux/i386
27481 + * platform.
27482 + */
27483 +
27484 +#include <linux/errno.h>
27485 +#include <linux/sched.h>
27486 +#include <linux/mm.h>
27487 +#include <linux/fs.h>
27488 +#include <linux/smp.h>
27489 +#include <linux/sem.h>
27490 +#include <linux/msg.h>
27491 +#include <linux/shm.h>
27492 +#include <linux/stat.h>
27493 +#include <linux/syscalls.h>
27494 +#include <linux/mman.h>
27495 +#include <linux/file.h>
27496 +#include <linux/utsname.h>
27497 +#include <linux/ipc.h>
27498 +#include <linux/elf.h>
27499 +
27500 +#include <linux/uaccess.h>
27501 +#include <linux/unistd.h>
27502 +
27503 +#include <asm/syscalls.h>
27504 +
27505 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27506 +{
27507 + unsigned long pax_task_size = TASK_SIZE;
27508 +
27509 +#ifdef CONFIG_PAX_SEGMEXEC
27510 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27511 + pax_task_size = SEGMEXEC_TASK_SIZE;
27512 +#endif
27513 +
27514 + if (flags & MAP_FIXED)
27515 + if (len > pax_task_size || addr > pax_task_size - len)
27516 + return -EINVAL;
27517 +
27518 + return 0;
27519 +}
27520 +
27521 +/*
27522 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27523 + */
27524 +static unsigned long get_align_mask(void)
27525 +{
27526 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27527 + return 0;
27528 +
27529 + if (!(current->flags & PF_RANDOMIZE))
27530 + return 0;
27531 +
27532 + return va_align.mask;
27533 +}
27534 +
27535 +unsigned long
27536 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27537 + unsigned long len, unsigned long pgoff, unsigned long flags)
27538 +{
27539 + struct mm_struct *mm = current->mm;
27540 + struct vm_area_struct *vma;
27541 + unsigned long pax_task_size = TASK_SIZE;
27542 + struct vm_unmapped_area_info info;
27543 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27544 +
27545 +#ifdef CONFIG_PAX_SEGMEXEC
27546 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27547 + pax_task_size = SEGMEXEC_TASK_SIZE;
27548 +#endif
27549 +
27550 + pax_task_size -= PAGE_SIZE;
27551 +
27552 + if (len > pax_task_size)
27553 + return -ENOMEM;
27554 +
27555 + if (flags & MAP_FIXED)
27556 + return addr;
27557 +
27558 +#ifdef CONFIG_PAX_RANDMMAP
27559 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27560 +#endif
27561 +
27562 + if (addr) {
27563 + addr = PAGE_ALIGN(addr);
27564 + if (pax_task_size - len >= addr) {
27565 + vma = find_vma(mm, addr);
27566 + if (check_heap_stack_gap(vma, addr, len, offset))
27567 + return addr;
27568 + }
27569 + }
27570 +
27571 + info.flags = 0;
27572 + info.length = len;
27573 + info.align_mask = filp ? get_align_mask() : 0;
27574 + info.align_offset = pgoff << PAGE_SHIFT;
27575 + info.threadstack_offset = offset;
27576 +
27577 +#ifdef CONFIG_PAX_PAGEEXEC
27578 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27579 + info.low_limit = 0x00110000UL;
27580 + info.high_limit = mm->start_code;
27581 +
27582 +#ifdef CONFIG_PAX_RANDMMAP
27583 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27584 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27585 +#endif
27586 +
27587 + if (info.low_limit < info.high_limit) {
27588 + addr = vm_unmapped_area(&info);
27589 + if (!IS_ERR_VALUE(addr))
27590 + return addr;
27591 + }
27592 + } else
27593 +#endif
27594 +
27595 + info.low_limit = mm->mmap_base;
27596 + info.high_limit = pax_task_size;
27597 +
27598 + return vm_unmapped_area(&info);
27599 +}
27600 +
27601 +unsigned long
27602 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27603 + const unsigned long len, const unsigned long pgoff,
27604 + const unsigned long flags)
27605 +{
27606 + struct vm_area_struct *vma;
27607 + struct mm_struct *mm = current->mm;
27608 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27609 + struct vm_unmapped_area_info info;
27610 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27611 +
27612 +#ifdef CONFIG_PAX_SEGMEXEC
27613 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27614 + pax_task_size = SEGMEXEC_TASK_SIZE;
27615 +#endif
27616 +
27617 + pax_task_size -= PAGE_SIZE;
27618 +
27619 + /* requested length too big for entire address space */
27620 + if (len > pax_task_size)
27621 + return -ENOMEM;
27622 +
27623 + if (flags & MAP_FIXED)
27624 + return addr;
27625 +
27626 +#ifdef CONFIG_PAX_PAGEEXEC
27627 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27628 + goto bottomup;
27629 +#endif
27630 +
27631 +#ifdef CONFIG_PAX_RANDMMAP
27632 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27633 +#endif
27634 +
27635 + /* requesting a specific address */
27636 + if (addr) {
27637 + addr = PAGE_ALIGN(addr);
27638 + if (pax_task_size - len >= addr) {
27639 + vma = find_vma(mm, addr);
27640 + if (check_heap_stack_gap(vma, addr, len, offset))
27641 + return addr;
27642 + }
27643 + }
27644 +
27645 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27646 + info.length = len;
27647 + info.low_limit = PAGE_SIZE;
27648 + info.high_limit = mm->mmap_base;
27649 + info.align_mask = filp ? get_align_mask() : 0;
27650 + info.align_offset = pgoff << PAGE_SHIFT;
27651 + info.threadstack_offset = offset;
27652 +
27653 + addr = vm_unmapped_area(&info);
27654 + if (!(addr & ~PAGE_MASK))
27655 + return addr;
27656 + VM_BUG_ON(addr != -ENOMEM);
27657 +
27658 +bottomup:
27659 + /*
27660 + * A failed mmap() very likely causes application failure,
27661 + * so fall back to the bottom-up function here. This scenario
27662 + * can happen with large stack limits and large mmap()
27663 + * allocations.
27664 + */
27665 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27666 +}
27667 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27668 index 30277e2..5664a29 100644
27669 --- a/arch/x86/kernel/sys_x86_64.c
27670 +++ b/arch/x86/kernel/sys_x86_64.c
27671 @@ -81,8 +81,8 @@ out:
27672 return error;
27673 }
27674
27675 -static void find_start_end(unsigned long flags, unsigned long *begin,
27676 - unsigned long *end)
27677 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27678 + unsigned long *begin, unsigned long *end)
27679 {
27680 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27681 unsigned long new_begin;
27682 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27683 *begin = new_begin;
27684 }
27685 } else {
27686 - *begin = current->mm->mmap_legacy_base;
27687 + *begin = mm->mmap_legacy_base;
27688 *end = TASK_SIZE;
27689 }
27690 }
27691 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27692 struct vm_area_struct *vma;
27693 struct vm_unmapped_area_info info;
27694 unsigned long begin, end;
27695 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27696
27697 if (flags & MAP_FIXED)
27698 return addr;
27699
27700 - find_start_end(flags, &begin, &end);
27701 + find_start_end(mm, flags, &begin, &end);
27702
27703 if (len > end)
27704 return -ENOMEM;
27705
27706 +#ifdef CONFIG_PAX_RANDMMAP
27707 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27708 +#endif
27709 +
27710 if (addr) {
27711 addr = PAGE_ALIGN(addr);
27712 vma = find_vma(mm, addr);
27713 - if (end - len >= addr &&
27714 - (!vma || addr + len <= vma->vm_start))
27715 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27716 return addr;
27717 }
27718
27719 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27720 info.high_limit = end;
27721 info.align_mask = filp ? get_align_mask() : 0;
27722 info.align_offset = pgoff << PAGE_SHIFT;
27723 + info.threadstack_offset = offset;
27724 return vm_unmapped_area(&info);
27725 }
27726
27727 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27728 struct mm_struct *mm = current->mm;
27729 unsigned long addr = addr0;
27730 struct vm_unmapped_area_info info;
27731 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27732
27733 /* requested length too big for entire address space */
27734 if (len > TASK_SIZE)
27735 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27736 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27737 goto bottomup;
27738
27739 +#ifdef CONFIG_PAX_RANDMMAP
27740 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27741 +#endif
27742 +
27743 /* requesting a specific address */
27744 if (addr) {
27745 addr = PAGE_ALIGN(addr);
27746 vma = find_vma(mm, addr);
27747 - if (TASK_SIZE - len >= addr &&
27748 - (!vma || addr + len <= vma->vm_start))
27749 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27750 return addr;
27751 }
27752
27753 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27754 info.high_limit = mm->mmap_base;
27755 info.align_mask = filp ? get_align_mask() : 0;
27756 info.align_offset = pgoff << PAGE_SHIFT;
27757 + info.threadstack_offset = offset;
27758 addr = vm_unmapped_area(&info);
27759 if (!(addr & ~PAGE_MASK))
27760 return addr;
27761 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27762 index 91a4496..bb87552 100644
27763 --- a/arch/x86/kernel/tboot.c
27764 +++ b/arch/x86/kernel/tboot.c
27765 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27766
27767 void tboot_shutdown(u32 shutdown_type)
27768 {
27769 - void (*shutdown)(void);
27770 + void (* __noreturn shutdown)(void);
27771
27772 if (!tboot_enabled())
27773 return;
27774 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27775
27776 switch_to_tboot_pt();
27777
27778 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27779 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27780 shutdown();
27781
27782 /* should not reach here */
27783 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27784 return -ENODEV;
27785 }
27786
27787 -static atomic_t ap_wfs_count;
27788 +static atomic_unchecked_t ap_wfs_count;
27789
27790 static int tboot_wait_for_aps(int num_aps)
27791 {
27792 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27793 {
27794 switch (action) {
27795 case CPU_DYING:
27796 - atomic_inc(&ap_wfs_count);
27797 + atomic_inc_unchecked(&ap_wfs_count);
27798 if (num_online_cpus() == 1)
27799 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27800 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27801 return NOTIFY_BAD;
27802 break;
27803 }
27804 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27805
27806 tboot_create_trampoline();
27807
27808 - atomic_set(&ap_wfs_count, 0);
27809 + atomic_set_unchecked(&ap_wfs_count, 0);
27810 register_hotcpu_notifier(&tboot_cpu_notifier);
27811
27812 #ifdef CONFIG_DEBUG_FS
27813 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27814 index 0fa2960..91eabbe 100644
27815 --- a/arch/x86/kernel/time.c
27816 +++ b/arch/x86/kernel/time.c
27817 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27818 {
27819 unsigned long pc = instruction_pointer(regs);
27820
27821 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27822 + if (!user_mode(regs) && in_lock_functions(pc)) {
27823 #ifdef CONFIG_FRAME_POINTER
27824 - return *(unsigned long *)(regs->bp + sizeof(long));
27825 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27826 #else
27827 unsigned long *sp =
27828 (unsigned long *)kernel_stack_pointer(regs);
27829 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27830 * or above a saved flags. Eflags has bits 22-31 zero,
27831 * kernel addresses don't.
27832 */
27833 +
27834 +#ifdef CONFIG_PAX_KERNEXEC
27835 + return ktla_ktva(sp[0]);
27836 +#else
27837 if (sp[0] >> 22)
27838 return sp[0];
27839 if (sp[1] >> 22)
27840 return sp[1];
27841 #endif
27842 +
27843 +#endif
27844 }
27845 return pc;
27846 }
27847 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27848 index 4e942f3..c6e445a 100644
27849 --- a/arch/x86/kernel/tls.c
27850 +++ b/arch/x86/kernel/tls.c
27851 @@ -29,7 +29,28 @@ static int get_free_idx(void)
27852
27853 static bool tls_desc_okay(const struct user_desc *info)
27854 {
27855 - if (LDT_empty(info))
27856 + /*
27857 + * For historical reasons (i.e. no one ever documented how any
27858 + * of the segmentation APIs work), user programs can and do
27859 + * assume that a struct user_desc that's all zeros except for
27860 + * entry_number means "no segment at all". This never actually
27861 + * worked. In fact, up to Linux 3.19, a struct user_desc like
27862 + * this would create a 16-bit read-write segment with base and
27863 + * limit both equal to zero.
27864 + *
27865 + * That was close enough to "no segment at all" until we
27866 + * hardened this function to disallow 16-bit TLS segments. Fix
27867 + * it up by interpreting these zeroed segments the way that they
27868 + * were almost certainly intended to be interpreted.
27869 + *
27870 + * The correct way to ask for "no segment at all" is to specify
27871 + * a user_desc that satisfies LDT_empty. To keep everything
27872 + * working, we accept both.
27873 + *
27874 + * Note that there's a similar kludge in modify_ldt -- look at
27875 + * the distinction between modes 1 and 0x11.
27876 + */
27877 + if (LDT_empty(info) || LDT_zero(info))
27878 return true;
27879
27880 /*
27881 @@ -71,7 +92,7 @@ static void set_tls_desc(struct task_struct *p, int idx,
27882 cpu = get_cpu();
27883
27884 while (n-- > 0) {
27885 - if (LDT_empty(info))
27886 + if (LDT_empty(info) || LDT_zero(info))
27887 desc->a = desc->b = 0;
27888 else
27889 fill_ldt(desc, info);
27890 @@ -118,6 +139,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27891 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27892 return -EINVAL;
27893
27894 +#ifdef CONFIG_PAX_SEGMEXEC
27895 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27896 + return -EINVAL;
27897 +#endif
27898 +
27899 set_tls_desc(p, idx, &info, 1);
27900
27901 return 0;
27902 @@ -235,7 +261,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27903
27904 if (kbuf)
27905 info = kbuf;
27906 - else if (__copy_from_user(infobuf, ubuf, count))
27907 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27908 return -EFAULT;
27909 else
27910 info = infobuf;
27911 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27912 index 1c113db..287b42e 100644
27913 --- a/arch/x86/kernel/tracepoint.c
27914 +++ b/arch/x86/kernel/tracepoint.c
27915 @@ -9,11 +9,11 @@
27916 #include <linux/atomic.h>
27917
27918 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27919 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27920 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27921 (unsigned long) trace_idt_table };
27922
27923 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27924 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27925 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27926
27927 static int trace_irq_vector_refcount;
27928 static DEFINE_MUTEX(irq_vector_mutex);
27929 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27930 index 07ab8e9..99c8456 100644
27931 --- a/arch/x86/kernel/traps.c
27932 +++ b/arch/x86/kernel/traps.c
27933 @@ -67,7 +67,7 @@
27934 #include <asm/proto.h>
27935
27936 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27937 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27938 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27939 #else
27940 #include <asm/processor-flags.h>
27941 #include <asm/setup.h>
27942 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27943 #endif
27944
27945 /* Must be page-aligned because the real IDT is used in a fixmap. */
27946 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27947 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27948
27949 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27950 EXPORT_SYMBOL_GPL(used_vectors);
27951 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27952 }
27953
27954 static nokprobe_inline int
27955 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27956 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27957 struct pt_regs *regs, long error_code)
27958 {
27959 #ifdef CONFIG_X86_32
27960 - if (regs->flags & X86_VM_MASK) {
27961 + if (v8086_mode(regs)) {
27962 /*
27963 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27964 * On nmi (interrupt 2), do_trap should not be called.
27965 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27966 return -1;
27967 }
27968 #endif
27969 - if (!user_mode(regs)) {
27970 + if (!user_mode_novm(regs)) {
27971 if (!fixup_exception(regs)) {
27972 tsk->thread.error_code = error_code;
27973 tsk->thread.trap_nr = trapnr;
27974 +
27975 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27976 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27977 + str = "PAX: suspicious stack segment fault";
27978 +#endif
27979 +
27980 die(str, regs, error_code);
27981 }
27982 +
27983 +#ifdef CONFIG_PAX_REFCOUNT
27984 + if (trapnr == X86_TRAP_OF)
27985 + pax_report_refcount_overflow(regs);
27986 +#endif
27987 +
27988 return 0;
27989 }
27990
27991 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27992 }
27993
27994 static void
27995 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27996 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27997 long error_code, siginfo_t *info)
27998 {
27999 struct task_struct *tsk = current;
28000 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28001 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28002 printk_ratelimit()) {
28003 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28004 - tsk->comm, tsk->pid, str,
28005 + tsk->comm, task_pid_nr(tsk), str,
28006 regs->ip, regs->sp, error_code);
28007 print_vma_addr(" in ", regs->ip);
28008 pr_cont("\n");
28009 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28010 tsk->thread.error_code = error_code;
28011 tsk->thread.trap_nr = X86_TRAP_DF;
28012
28013 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28014 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28015 + die("grsec: kernel stack overflow detected", regs, error_code);
28016 +#endif
28017 +
28018 #ifdef CONFIG_DOUBLEFAULT
28019 df_debug(regs, error_code);
28020 #endif
28021 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28022 conditional_sti(regs);
28023
28024 #ifdef CONFIG_X86_32
28025 - if (regs->flags & X86_VM_MASK) {
28026 + if (v8086_mode(regs)) {
28027 local_irq_enable();
28028 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28029 goto exit;
28030 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28031 #endif
28032
28033 tsk = current;
28034 - if (!user_mode(regs)) {
28035 + if (!user_mode_novm(regs)) {
28036 if (fixup_exception(regs))
28037 goto exit;
28038
28039 tsk->thread.error_code = error_code;
28040 tsk->thread.trap_nr = X86_TRAP_GP;
28041 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28042 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28043 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28044 +
28045 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28046 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28047 + die("PAX: suspicious general protection fault", regs, error_code);
28048 + else
28049 +#endif
28050 +
28051 die("general protection fault", regs, error_code);
28052 + }
28053 goto exit;
28054 }
28055
28056 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28057 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28058 + struct mm_struct *mm = tsk->mm;
28059 + unsigned long limit;
28060 +
28061 + down_write(&mm->mmap_sem);
28062 + limit = mm->context.user_cs_limit;
28063 + if (limit < TASK_SIZE) {
28064 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28065 + up_write(&mm->mmap_sem);
28066 + return;
28067 + }
28068 + up_write(&mm->mmap_sem);
28069 + }
28070 +#endif
28071 +
28072 tsk->thread.error_code = error_code;
28073 tsk->thread.trap_nr = X86_TRAP_GP;
28074
28075 @@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28076 container_of(task_pt_regs(current),
28077 struct bad_iret_stack, regs);
28078
28079 + if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28080 + new_stack = s;
28081 +
28082 /* Copy the IRET target to the new stack. */
28083 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28084
28085 /* Copy the remainder of the stack from the current stack. */
28086 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28087
28088 - BUG_ON(!user_mode_vm(&new_stack->regs));
28089 + BUG_ON(!user_mode(&new_stack->regs));
28090 return new_stack;
28091 }
28092 NOKPROBE_SYMBOL(fixup_bad_iret);
28093 @@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28094 /* It's safe to allow irq's after DR6 has been saved */
28095 preempt_conditional_sti(regs);
28096
28097 - if (regs->flags & X86_VM_MASK) {
28098 + if (v8086_mode(regs)) {
28099 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28100 X86_TRAP_DB);
28101 preempt_conditional_cli(regs);
28102 @@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28103 * We already checked v86 mode above, so we can check for kernel mode
28104 * by just checking the CPL of CS.
28105 */
28106 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28107 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28108 tsk->thread.debugreg6 &= ~DR_STEP;
28109 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28110 regs->flags &= ~X86_EFLAGS_TF;
28111 @@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28112 return;
28113 conditional_sti(regs);
28114
28115 - if (!user_mode_vm(regs))
28116 + if (!user_mode(regs))
28117 {
28118 if (!fixup_exception(regs)) {
28119 task->thread.error_code = error_code;
28120 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28121 index b7e50bb..f4a93ae 100644
28122 --- a/arch/x86/kernel/tsc.c
28123 +++ b/arch/x86/kernel/tsc.c
28124 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28125 */
28126 smp_wmb();
28127
28128 - ACCESS_ONCE(c2n->head) = data;
28129 + ACCESS_ONCE_RW(c2n->head) = data;
28130 }
28131
28132 /*
28133 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28134 index 5d1cbfe..2a21feb 100644
28135 --- a/arch/x86/kernel/uprobes.c
28136 +++ b/arch/x86/kernel/uprobes.c
28137 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28138 int ret = NOTIFY_DONE;
28139
28140 /* We are only interested in userspace traps */
28141 - if (regs && !user_mode_vm(regs))
28142 + if (regs && !user_mode(regs))
28143 return NOTIFY_DONE;
28144
28145 switch (val) {
28146 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28147
28148 if (nleft != rasize) {
28149 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28150 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28151 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28152
28153 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28154 }
28155 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28156 index b9242ba..50c5edd 100644
28157 --- a/arch/x86/kernel/verify_cpu.S
28158 +++ b/arch/x86/kernel/verify_cpu.S
28159 @@ -20,6 +20,7 @@
28160 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28161 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28162 * arch/x86/kernel/head_32.S: processor startup
28163 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28164 *
28165 * verify_cpu, returns the status of longmode and SSE in register %eax.
28166 * 0: Success 1: Failure
28167 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28168 index e8edcf5..27f9344 100644
28169 --- a/arch/x86/kernel/vm86_32.c
28170 +++ b/arch/x86/kernel/vm86_32.c
28171 @@ -44,6 +44,7 @@
28172 #include <linux/ptrace.h>
28173 #include <linux/audit.h>
28174 #include <linux/stddef.h>
28175 +#include <linux/grsecurity.h>
28176
28177 #include <asm/uaccess.h>
28178 #include <asm/io.h>
28179 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28180 do_exit(SIGSEGV);
28181 }
28182
28183 - tss = &per_cpu(init_tss, get_cpu());
28184 + tss = init_tss + get_cpu();
28185 current->thread.sp0 = current->thread.saved_sp0;
28186 current->thread.sysenter_cs = __KERNEL_CS;
28187 load_sp0(tss, &current->thread);
28188 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28189
28190 if (tsk->thread.saved_sp0)
28191 return -EPERM;
28192 +
28193 +#ifdef CONFIG_GRKERNSEC_VM86
28194 + if (!capable(CAP_SYS_RAWIO)) {
28195 + gr_handle_vm86();
28196 + return -EPERM;
28197 + }
28198 +#endif
28199 +
28200 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28201 offsetof(struct kernel_vm86_struct, vm86plus) -
28202 sizeof(info.regs));
28203 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28204 int tmp;
28205 struct vm86plus_struct __user *v86;
28206
28207 +#ifdef CONFIG_GRKERNSEC_VM86
28208 + if (!capable(CAP_SYS_RAWIO)) {
28209 + gr_handle_vm86();
28210 + return -EPERM;
28211 + }
28212 +#endif
28213 +
28214 tsk = current;
28215 switch (cmd) {
28216 case VM86_REQUEST_IRQ:
28217 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28218 tsk->thread.saved_fs = info->regs32->fs;
28219 tsk->thread.saved_gs = get_user_gs(info->regs32);
28220
28221 - tss = &per_cpu(init_tss, get_cpu());
28222 + tss = init_tss + get_cpu();
28223 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28224 if (cpu_has_sep)
28225 tsk->thread.sysenter_cs = 0;
28226 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28227 goto cannot_handle;
28228 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28229 goto cannot_handle;
28230 - intr_ptr = (unsigned long __user *) (i << 2);
28231 + intr_ptr = (__force unsigned long __user *) (i << 2);
28232 if (get_user(segoffs, intr_ptr))
28233 goto cannot_handle;
28234 if ((segoffs >> 16) == BIOSSEG)
28235 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28236 index 49edf2d..c0d1362 100644
28237 --- a/arch/x86/kernel/vmlinux.lds.S
28238 +++ b/arch/x86/kernel/vmlinux.lds.S
28239 @@ -26,6 +26,13 @@
28240 #include <asm/page_types.h>
28241 #include <asm/cache.h>
28242 #include <asm/boot.h>
28243 +#include <asm/segment.h>
28244 +
28245 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28246 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28247 +#else
28248 +#define __KERNEL_TEXT_OFFSET 0
28249 +#endif
28250
28251 #undef i386 /* in case the preprocessor is a 32bit one */
28252
28253 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28254
28255 PHDRS {
28256 text PT_LOAD FLAGS(5); /* R_E */
28257 +#ifdef CONFIG_X86_32
28258 + module PT_LOAD FLAGS(5); /* R_E */
28259 +#endif
28260 +#ifdef CONFIG_XEN
28261 + rodata PT_LOAD FLAGS(5); /* R_E */
28262 +#else
28263 + rodata PT_LOAD FLAGS(4); /* R__ */
28264 +#endif
28265 data PT_LOAD FLAGS(6); /* RW_ */
28266 -#ifdef CONFIG_X86_64
28267 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28268 #ifdef CONFIG_SMP
28269 percpu PT_LOAD FLAGS(6); /* RW_ */
28270 #endif
28271 + text.init PT_LOAD FLAGS(5); /* R_E */
28272 + text.exit PT_LOAD FLAGS(5); /* R_E */
28273 init PT_LOAD FLAGS(7); /* RWE */
28274 -#endif
28275 note PT_NOTE FLAGS(0); /* ___ */
28276 }
28277
28278 SECTIONS
28279 {
28280 #ifdef CONFIG_X86_32
28281 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28282 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28283 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28284 #else
28285 - . = __START_KERNEL;
28286 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28287 + . = __START_KERNEL;
28288 #endif
28289
28290 /* Text and read-only data */
28291 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28292 - _text = .;
28293 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28294 /* bootstrapping code */
28295 +#ifdef CONFIG_X86_32
28296 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28297 +#else
28298 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28299 +#endif
28300 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28301 + _text = .;
28302 HEAD_TEXT
28303 . = ALIGN(8);
28304 _stext = .;
28305 @@ -104,13 +124,47 @@ SECTIONS
28306 IRQENTRY_TEXT
28307 *(.fixup)
28308 *(.gnu.warning)
28309 - /* End of text section */
28310 - _etext = .;
28311 } :text = 0x9090
28312
28313 - NOTES :text :note
28314 + . += __KERNEL_TEXT_OFFSET;
28315
28316 - EXCEPTION_TABLE(16) :text = 0x9090
28317 +#ifdef CONFIG_X86_32
28318 + . = ALIGN(PAGE_SIZE);
28319 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28320 +
28321 +#ifdef CONFIG_PAX_KERNEXEC
28322 + MODULES_EXEC_VADDR = .;
28323 + BYTE(0)
28324 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28325 + . = ALIGN(HPAGE_SIZE) - 1;
28326 + MODULES_EXEC_END = .;
28327 +#endif
28328 +
28329 + } :module
28330 +#endif
28331 +
28332 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28333 + /* End of text section */
28334 + BYTE(0)
28335 + _etext = . - __KERNEL_TEXT_OFFSET;
28336 + }
28337 +
28338 +#ifdef CONFIG_X86_32
28339 + . = ALIGN(PAGE_SIZE);
28340 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28341 + . = ALIGN(PAGE_SIZE);
28342 + *(.empty_zero_page)
28343 + *(.initial_pg_fixmap)
28344 + *(.initial_pg_pmd)
28345 + *(.initial_page_table)
28346 + *(.swapper_pg_dir)
28347 + } :rodata
28348 +#endif
28349 +
28350 + . = ALIGN(PAGE_SIZE);
28351 + NOTES :rodata :note
28352 +
28353 + EXCEPTION_TABLE(16) :rodata
28354
28355 #if defined(CONFIG_DEBUG_RODATA)
28356 /* .text should occupy whole number of pages */
28357 @@ -122,16 +176,20 @@ SECTIONS
28358
28359 /* Data */
28360 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28361 +
28362 +#ifdef CONFIG_PAX_KERNEXEC
28363 + . = ALIGN(HPAGE_SIZE);
28364 +#else
28365 + . = ALIGN(PAGE_SIZE);
28366 +#endif
28367 +
28368 /* Start of data section */
28369 _sdata = .;
28370
28371 /* init_task */
28372 INIT_TASK_DATA(THREAD_SIZE)
28373
28374 -#ifdef CONFIG_X86_32
28375 - /* 32 bit has nosave before _edata */
28376 NOSAVE_DATA
28377 -#endif
28378
28379 PAGE_ALIGNED_DATA(PAGE_SIZE)
28380
28381 @@ -174,12 +232,19 @@ SECTIONS
28382 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28383
28384 /* Init code and data - will be freed after init */
28385 - . = ALIGN(PAGE_SIZE);
28386 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28387 + BYTE(0)
28388 +
28389 +#ifdef CONFIG_PAX_KERNEXEC
28390 + . = ALIGN(HPAGE_SIZE);
28391 +#else
28392 + . = ALIGN(PAGE_SIZE);
28393 +#endif
28394 +
28395 __init_begin = .; /* paired with __init_end */
28396 - }
28397 + } :init.begin
28398
28399 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28400 +#ifdef CONFIG_SMP
28401 /*
28402 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28403 * output PHDR, so the next output section - .init.text - should
28404 @@ -188,12 +253,27 @@ SECTIONS
28405 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28406 #endif
28407
28408 - INIT_TEXT_SECTION(PAGE_SIZE)
28409 -#ifdef CONFIG_X86_64
28410 - :init
28411 -#endif
28412 + . = ALIGN(PAGE_SIZE);
28413 + init_begin = .;
28414 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28415 + VMLINUX_SYMBOL(_sinittext) = .;
28416 + INIT_TEXT
28417 + VMLINUX_SYMBOL(_einittext) = .;
28418 + . = ALIGN(PAGE_SIZE);
28419 + } :text.init
28420
28421 - INIT_DATA_SECTION(16)
28422 + /*
28423 + * .exit.text is discard at runtime, not link time, to deal with
28424 + * references from .altinstructions and .eh_frame
28425 + */
28426 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28427 + EXIT_TEXT
28428 + . = ALIGN(16);
28429 + } :text.exit
28430 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28431 +
28432 + . = ALIGN(PAGE_SIZE);
28433 + INIT_DATA_SECTION(16) :init
28434
28435 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28436 __x86_cpu_dev_start = .;
28437 @@ -264,19 +344,12 @@ SECTIONS
28438 }
28439
28440 . = ALIGN(8);
28441 - /*
28442 - * .exit.text is discard at runtime, not link time, to deal with
28443 - * references from .altinstructions and .eh_frame
28444 - */
28445 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28446 - EXIT_TEXT
28447 - }
28448
28449 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28450 EXIT_DATA
28451 }
28452
28453 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28454 +#ifndef CONFIG_SMP
28455 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28456 #endif
28457
28458 @@ -295,16 +368,10 @@ SECTIONS
28459 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28460 __smp_locks = .;
28461 *(.smp_locks)
28462 - . = ALIGN(PAGE_SIZE);
28463 __smp_locks_end = .;
28464 + . = ALIGN(PAGE_SIZE);
28465 }
28466
28467 -#ifdef CONFIG_X86_64
28468 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28469 - NOSAVE_DATA
28470 - }
28471 -#endif
28472 -
28473 /* BSS */
28474 . = ALIGN(PAGE_SIZE);
28475 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28476 @@ -320,6 +387,7 @@ SECTIONS
28477 __brk_base = .;
28478 . += 64 * 1024; /* 64k alignment slop space */
28479 *(.brk_reservation) /* areas brk users have reserved */
28480 + . = ALIGN(HPAGE_SIZE);
28481 __brk_limit = .;
28482 }
28483
28484 @@ -346,13 +414,12 @@ SECTIONS
28485 * for the boot processor.
28486 */
28487 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28488 -INIT_PER_CPU(gdt_page);
28489 INIT_PER_CPU(irq_stack_union);
28490
28491 /*
28492 * Build-time check on the image size:
28493 */
28494 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28495 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28496 "kernel image bigger than KERNEL_IMAGE_SIZE");
28497
28498 #ifdef CONFIG_SMP
28499 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28500 index 957779f..74e405c 100644
28501 --- a/arch/x86/kernel/vsyscall_64.c
28502 +++ b/arch/x86/kernel/vsyscall_64.c
28503 @@ -54,15 +54,13 @@
28504
28505 DEFINE_VVAR(int, vgetcpu_mode);
28506
28507 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28508 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28509
28510 static int __init vsyscall_setup(char *str)
28511 {
28512 if (str) {
28513 if (!strcmp("emulate", str))
28514 vsyscall_mode = EMULATE;
28515 - else if (!strcmp("native", str))
28516 - vsyscall_mode = NATIVE;
28517 else if (!strcmp("none", str))
28518 vsyscall_mode = NONE;
28519 else
28520 @@ -279,8 +277,7 @@ do_ret:
28521 return true;
28522
28523 sigsegv:
28524 - force_sig(SIGSEGV, current);
28525 - return true;
28526 + do_group_exit(SIGKILL);
28527 }
28528
28529 /*
28530 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28531 extern char __vsyscall_page;
28532 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28533
28534 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28535 - vsyscall_mode == NATIVE
28536 - ? PAGE_KERNEL_VSYSCALL
28537 - : PAGE_KERNEL_VVAR);
28538 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28539 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28540 (unsigned long)VSYSCALL_ADDR);
28541 }
28542 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28543 index 04068192..4d75aa6 100644
28544 --- a/arch/x86/kernel/x8664_ksyms_64.c
28545 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28546 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28547 EXPORT_SYMBOL(copy_user_generic_unrolled);
28548 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28549 EXPORT_SYMBOL(__copy_user_nocache);
28550 -EXPORT_SYMBOL(_copy_from_user);
28551 -EXPORT_SYMBOL(_copy_to_user);
28552
28553 EXPORT_SYMBOL(copy_page);
28554 EXPORT_SYMBOL(clear_page);
28555 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28556 EXPORT_SYMBOL(___preempt_schedule_context);
28557 #endif
28558 #endif
28559 +
28560 +#ifdef CONFIG_PAX_PER_CPU_PGD
28561 +EXPORT_SYMBOL(cpu_pgd);
28562 +#endif
28563 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28564 index e48b674..a451dd9 100644
28565 --- a/arch/x86/kernel/x86_init.c
28566 +++ b/arch/x86/kernel/x86_init.c
28567 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28568 static void default_nmi_init(void) { };
28569 static int default_i8042_detect(void) { return 1; };
28570
28571 -struct x86_platform_ops x86_platform = {
28572 +struct x86_platform_ops x86_platform __read_only = {
28573 .calibrate_tsc = native_calibrate_tsc,
28574 .get_wallclock = mach_get_cmos_time,
28575 .set_wallclock = mach_set_rtc_mmss,
28576 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28577 EXPORT_SYMBOL_GPL(x86_platform);
28578
28579 #if defined(CONFIG_PCI_MSI)
28580 -struct x86_msi_ops x86_msi = {
28581 +struct x86_msi_ops x86_msi __read_only = {
28582 .setup_msi_irqs = native_setup_msi_irqs,
28583 .compose_msi_msg = native_compose_msi_msg,
28584 .teardown_msi_irq = native_teardown_msi_irq,
28585 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28586 }
28587 #endif
28588
28589 -struct x86_io_apic_ops x86_io_apic_ops = {
28590 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28591 .init = native_io_apic_init_mappings,
28592 .read = native_io_apic_read,
28593 .write = native_io_apic_write,
28594 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28595 index 0de1fae..298d037 100644
28596 --- a/arch/x86/kernel/xsave.c
28597 +++ b/arch/x86/kernel/xsave.c
28598 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28599
28600 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28601 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28602 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28603 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28604
28605 if (!use_xsave())
28606 return err;
28607
28608 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28609 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28610
28611 /*
28612 * Read the xstate_bv which we copied (directly from the cpu or
28613 * from the state in task struct) to the user buffers.
28614 */
28615 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28616 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28617
28618 /*
28619 * For legacy compatible, we always set FP/SSE bits in the bit
28620 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28621 */
28622 xstate_bv |= XSTATE_FPSSE;
28623
28624 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28625 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28626
28627 return err;
28628 }
28629 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28630 {
28631 int err;
28632
28633 + buf = (struct xsave_struct __user *)____m(buf);
28634 if (use_xsave())
28635 err = xsave_user(buf);
28636 else if (use_fxsr())
28637 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28638 */
28639 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28640 {
28641 + buf = (void __user *)____m(buf);
28642 if (use_xsave()) {
28643 if ((unsigned long)buf % 64 || fx_only) {
28644 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28645 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28646 index 88f9201..0e7f1a3 100644
28647 --- a/arch/x86/kvm/cpuid.c
28648 +++ b/arch/x86/kvm/cpuid.c
28649 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28650 struct kvm_cpuid2 *cpuid,
28651 struct kvm_cpuid_entry2 __user *entries)
28652 {
28653 - int r;
28654 + int r, i;
28655
28656 r = -E2BIG;
28657 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28658 goto out;
28659 r = -EFAULT;
28660 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28661 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28662 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28663 goto out;
28664 + for (i = 0; i < cpuid->nent; ++i) {
28665 + struct kvm_cpuid_entry2 cpuid_entry;
28666 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28667 + goto out;
28668 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28669 + }
28670 vcpu->arch.cpuid_nent = cpuid->nent;
28671 kvm_apic_set_version(vcpu);
28672 kvm_x86_ops->cpuid_update(vcpu);
28673 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28674 struct kvm_cpuid2 *cpuid,
28675 struct kvm_cpuid_entry2 __user *entries)
28676 {
28677 - int r;
28678 + int r, i;
28679
28680 r = -E2BIG;
28681 if (cpuid->nent < vcpu->arch.cpuid_nent)
28682 goto out;
28683 r = -EFAULT;
28684 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28685 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28686 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28687 goto out;
28688 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28689 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28690 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28691 + goto out;
28692 + }
28693 return 0;
28694
28695 out:
28696 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28697 index 22e7ed9..c3e2419 100644
28698 --- a/arch/x86/kvm/emulate.c
28699 +++ b/arch/x86/kvm/emulate.c
28700 @@ -2345,7 +2345,7 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt)
28701 * Not recognized on AMD in compat mode (but is recognized in legacy
28702 * mode).
28703 */
28704 - if ((ctxt->mode == X86EMUL_MODE_PROT32) && (efer & EFER_LMA)
28705 + if ((ctxt->mode != X86EMUL_MODE_PROT64) && (efer & EFER_LMA)
28706 && !vendor_intel(ctxt))
28707 return emulate_ud(ctxt);
28708
28709 @@ -2358,25 +2358,13 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt)
28710 setup_syscalls_segments(ctxt, &cs, &ss);
28711
28712 ops->get_msr(ctxt, MSR_IA32_SYSENTER_CS, &msr_data);
28713 - switch (ctxt->mode) {
28714 - case X86EMUL_MODE_PROT32:
28715 - if ((msr_data & 0xfffc) == 0x0)
28716 - return emulate_gp(ctxt, 0);
28717 - break;
28718 - case X86EMUL_MODE_PROT64:
28719 - if (msr_data == 0x0)
28720 - return emulate_gp(ctxt, 0);
28721 - break;
28722 - default:
28723 - break;
28724 - }
28725 + if ((msr_data & 0xfffc) == 0x0)
28726 + return emulate_gp(ctxt, 0);
28727
28728 ctxt->eflags &= ~(EFLG_VM | EFLG_IF);
28729 - cs_sel = (u16)msr_data;
28730 - cs_sel &= ~SELECTOR_RPL_MASK;
28731 + cs_sel = (u16)msr_data & ~SELECTOR_RPL_MASK;
28732 ss_sel = cs_sel + 8;
28733 - ss_sel &= ~SELECTOR_RPL_MASK;
28734 - if (ctxt->mode == X86EMUL_MODE_PROT64 || (efer & EFER_LMA)) {
28735 + if (efer & EFER_LMA) {
28736 cs.d = 0;
28737 cs.l = 1;
28738 }
28739 @@ -2385,10 +2373,11 @@ static int em_sysenter(struct x86_emulate_ctxt *ctxt)
28740 ops->set_segment(ctxt, ss_sel, &ss, 0, VCPU_SREG_SS);
28741
28742 ops->get_msr(ctxt, MSR_IA32_SYSENTER_EIP, &msr_data);
28743 - ctxt->_eip = msr_data;
28744 + ctxt->_eip = (efer & EFER_LMA) ? msr_data : (u32)msr_data;
28745
28746 ops->get_msr(ctxt, MSR_IA32_SYSENTER_ESP, &msr_data);
28747 - *reg_write(ctxt, VCPU_REGS_RSP) = msr_data;
28748 + *reg_write(ctxt, VCPU_REGS_RSP) = (efer & EFER_LMA) ? msr_data :
28749 + (u32)msr_data;
28750
28751 return X86EMUL_CONTINUE;
28752 }
28753 @@ -3519,7 +3508,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28754 int cr = ctxt->modrm_reg;
28755 u64 efer = 0;
28756
28757 - static u64 cr_reserved_bits[] = {
28758 + static const u64 cr_reserved_bits[] = {
28759 0xffffffff00000000ULL,
28760 0, 0, 0, /* CR3 checked later */
28761 CR4_RESERVED_BITS,
28762 @@ -3554,7 +3543,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28763
28764 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28765 if (efer & EFER_LMA)
28766 - rsvd = CR3_L_MODE_RESERVED_BITS;
28767 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28768
28769 if (new_val & rsvd)
28770 return emulate_gp(ctxt, 0);
28771 @@ -3788,8 +3777,8 @@ static const struct opcode group5[] = {
28772 };
28773
28774 static const struct opcode group6[] = {
28775 - DI(Prot, sldt),
28776 - DI(Prot, str),
28777 + DI(Prot | DstMem, sldt),
28778 + DI(Prot | DstMem, str),
28779 II(Prot | Priv | SrcMem16, em_lldt, lldt),
28780 II(Prot | Priv | SrcMem16, em_ltr, ltr),
28781 N, N, N, N,
28782 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28783 index b8345dd..f225d71 100644
28784 --- a/arch/x86/kvm/lapic.c
28785 +++ b/arch/x86/kvm/lapic.c
28786 @@ -55,7 +55,7 @@
28787 #define APIC_BUS_CYCLE_NS 1
28788
28789 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28790 -#define apic_debug(fmt, arg...)
28791 +#define apic_debug(fmt, arg...) do {} while (0)
28792
28793 #define APIC_LVT_NUM 6
28794 /* 14 is the version for Xeon and Pentium 8.4.8*/
28795 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28796 index fd49c86..77e1aa0 100644
28797 --- a/arch/x86/kvm/paging_tmpl.h
28798 +++ b/arch/x86/kvm/paging_tmpl.h
28799 @@ -343,7 +343,7 @@ retry_walk:
28800 if (unlikely(kvm_is_error_hva(host_addr)))
28801 goto error;
28802
28803 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28804 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28805 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28806 goto error;
28807 walker->ptep_user[walker->level - 1] = ptep_user;
28808 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28809 index 7527cef..c63a838e 100644
28810 --- a/arch/x86/kvm/svm.c
28811 +++ b/arch/x86/kvm/svm.c
28812 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28813 int cpu = raw_smp_processor_id();
28814
28815 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28816 +
28817 + pax_open_kernel();
28818 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28819 + pax_close_kernel();
28820 +
28821 load_TR_desc();
28822 }
28823
28824 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28825 #endif
28826 #endif
28827
28828 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28829 + __set_fs(current_thread_info()->addr_limit);
28830 +#endif
28831 +
28832 reload_tss(vcpu);
28833
28834 local_irq_disable();
28835 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28836 index ed70394..c629a68 100644
28837 --- a/arch/x86/kvm/vmx.c
28838 +++ b/arch/x86/kvm/vmx.c
28839 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28840 #endif
28841 }
28842
28843 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28844 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28845 {
28846 vmcs_writel(field, vmcs_readl(field) & ~mask);
28847 }
28848
28849 -static void vmcs_set_bits(unsigned long field, u32 mask)
28850 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28851 {
28852 vmcs_writel(field, vmcs_readl(field) | mask);
28853 }
28854 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28855 struct desc_struct *descs;
28856
28857 descs = (void *)gdt->address;
28858 +
28859 + pax_open_kernel();
28860 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28861 + pax_close_kernel();
28862 +
28863 load_TR_desc();
28864 }
28865
28866 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28867 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28868 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28869
28870 +#ifdef CONFIG_PAX_PER_CPU_PGD
28871 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28872 +#endif
28873 +
28874 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28875 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28876 vmx->loaded_vmcs->cpu = cpu;
28877 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28878 * reads and returns guest's timestamp counter "register"
28879 * guest_tsc = host_tsc + tsc_offset -- 21.3
28880 */
28881 -static u64 guest_read_tsc(void)
28882 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28883 {
28884 u64 host_tsc, tsc_offset;
28885
28886 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28887 * page upon invalidation. No need to do anything if the
28888 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28889 */
28890 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28891 + pax_open_kernel();
28892 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28893 + pax_close_kernel();
28894 }
28895
28896 - if (!cpu_has_vmx_tpr_shadow())
28897 - kvm_x86_ops->update_cr8_intercept = NULL;
28898 + if (!cpu_has_vmx_tpr_shadow()) {
28899 + pax_open_kernel();
28900 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28901 + pax_close_kernel();
28902 + }
28903
28904 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28905 kvm_disable_largepages();
28906 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28907 if (!cpu_has_vmx_apicv())
28908 enable_apicv = 0;
28909
28910 + pax_open_kernel();
28911 if (enable_apicv)
28912 - kvm_x86_ops->update_cr8_intercept = NULL;
28913 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28914 else {
28915 - kvm_x86_ops->hwapic_irr_update = NULL;
28916 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28917 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28918 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28919 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28920 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28921 }
28922 + pax_close_kernel();
28923
28924 if (nested)
28925 nested_vmx_setup_ctls_msrs();
28926 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28927 unsigned long cr4;
28928
28929 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28930 +
28931 +#ifndef CONFIG_PAX_PER_CPU_PGD
28932 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28933 +#endif
28934
28935 /* Save the most likely value for this task's CR4 in the VMCS. */
28936 cr4 = read_cr4();
28937 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28938 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28939 vmx->host_idt_base = dt.address;
28940
28941 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28942 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28943
28944 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28945 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28946 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28947 "jmp 2f \n\t"
28948 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28949 "2: "
28950 +
28951 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28952 + "ljmp %[cs],$3f\n\t"
28953 + "3: "
28954 +#endif
28955 +
28956 /* Save guest registers, load host registers, keep flags */
28957 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28958 "pop %0 \n\t"
28959 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28960 #endif
28961 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28962 [wordsize]"i"(sizeof(ulong))
28963 +
28964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28965 + ,[cs]"i"(__KERNEL_CS)
28966 +#endif
28967 +
28968 : "cc", "memory"
28969 #ifdef CONFIG_X86_64
28970 , "rax", "rbx", "rdi", "rsi"
28971 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28972 if (debugctlmsr)
28973 update_debugctlmsr(debugctlmsr);
28974
28975 -#ifndef CONFIG_X86_64
28976 +#ifdef CONFIG_X86_32
28977 /*
28978 * The sysexit path does not restore ds/es, so we must set them to
28979 * a reasonable value ourselves.
28980 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28981 * may be executed in interrupt context, which saves and restore segments
28982 * around it, nullifying its effect.
28983 */
28984 - loadsegment(ds, __USER_DS);
28985 - loadsegment(es, __USER_DS);
28986 + loadsegment(ds, __KERNEL_DS);
28987 + loadsegment(es, __KERNEL_DS);
28988 + loadsegment(ss, __KERNEL_DS);
28989 +
28990 +#ifdef CONFIG_PAX_KERNEXEC
28991 + loadsegment(fs, __KERNEL_PERCPU);
28992 +#endif
28993 +
28994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28995 + __set_fs(current_thread_info()->addr_limit);
28996 +#endif
28997 +
28998 #endif
28999
29000 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29001 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29002 index 506488c..f8df17e 100644
29003 --- a/arch/x86/kvm/x86.c
29004 +++ b/arch/x86/kvm/x86.c
29005 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
29006
29007 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
29008 {
29009 + cr3 &= ~CR3_PCID_INVD;
29010 +
29011 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
29012 kvm_mmu_sync_roots(vcpu);
29013 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
29014 @@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29015 {
29016 struct kvm *kvm = vcpu->kvm;
29017 int lm = is_long_mode(vcpu);
29018 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29019 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29020 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29021 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29022 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29023 : kvm->arch.xen_hvm_config.blob_size_32;
29024 u32 page_num = data & ~PAGE_MASK;
29025 @@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29026 if (n < msr_list.nmsrs)
29027 goto out;
29028 r = -EFAULT;
29029 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29030 + goto out;
29031 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29032 num_msrs_to_save * sizeof(u32)))
29033 goto out;
29034 @@ -5743,7 +5747,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29035 };
29036 #endif
29037
29038 -int kvm_arch_init(void *opaque)
29039 +int kvm_arch_init(const void *opaque)
29040 {
29041 int r;
29042 struct kvm_x86_ops *ops = opaque;
29043 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29044 index aae9413..d11e829 100644
29045 --- a/arch/x86/lguest/boot.c
29046 +++ b/arch/x86/lguest/boot.c
29047 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29048 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29049 * Launcher to reboot us.
29050 */
29051 -static void lguest_restart(char *reason)
29052 +static __noreturn void lguest_restart(char *reason)
29053 {
29054 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29055 + BUG();
29056 }
29057
29058 /*G:050
29059 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29060 index 00933d5..3a64af9 100644
29061 --- a/arch/x86/lib/atomic64_386_32.S
29062 +++ b/arch/x86/lib/atomic64_386_32.S
29063 @@ -48,6 +48,10 @@ BEGIN(read)
29064 movl (v), %eax
29065 movl 4(v), %edx
29066 RET_ENDP
29067 +BEGIN(read_unchecked)
29068 + movl (v), %eax
29069 + movl 4(v), %edx
29070 +RET_ENDP
29071 #undef v
29072
29073 #define v %esi
29074 @@ -55,6 +59,10 @@ BEGIN(set)
29075 movl %ebx, (v)
29076 movl %ecx, 4(v)
29077 RET_ENDP
29078 +BEGIN(set_unchecked)
29079 + movl %ebx, (v)
29080 + movl %ecx, 4(v)
29081 +RET_ENDP
29082 #undef v
29083
29084 #define v %esi
29085 @@ -70,6 +78,20 @@ RET_ENDP
29086 BEGIN(add)
29087 addl %eax, (v)
29088 adcl %edx, 4(v)
29089 +
29090 +#ifdef CONFIG_PAX_REFCOUNT
29091 + jno 0f
29092 + subl %eax, (v)
29093 + sbbl %edx, 4(v)
29094 + int $4
29095 +0:
29096 + _ASM_EXTABLE(0b, 0b)
29097 +#endif
29098 +
29099 +RET_ENDP
29100 +BEGIN(add_unchecked)
29101 + addl %eax, (v)
29102 + adcl %edx, 4(v)
29103 RET_ENDP
29104 #undef v
29105
29106 @@ -77,6 +99,24 @@ RET_ENDP
29107 BEGIN(add_return)
29108 addl (v), %eax
29109 adcl 4(v), %edx
29110 +
29111 +#ifdef CONFIG_PAX_REFCOUNT
29112 + into
29113 +1234:
29114 + _ASM_EXTABLE(1234b, 2f)
29115 +#endif
29116 +
29117 + movl %eax, (v)
29118 + movl %edx, 4(v)
29119 +
29120 +#ifdef CONFIG_PAX_REFCOUNT
29121 +2:
29122 +#endif
29123 +
29124 +RET_ENDP
29125 +BEGIN(add_return_unchecked)
29126 + addl (v), %eax
29127 + adcl 4(v), %edx
29128 movl %eax, (v)
29129 movl %edx, 4(v)
29130 RET_ENDP
29131 @@ -86,6 +126,20 @@ RET_ENDP
29132 BEGIN(sub)
29133 subl %eax, (v)
29134 sbbl %edx, 4(v)
29135 +
29136 +#ifdef CONFIG_PAX_REFCOUNT
29137 + jno 0f
29138 + addl %eax, (v)
29139 + adcl %edx, 4(v)
29140 + int $4
29141 +0:
29142 + _ASM_EXTABLE(0b, 0b)
29143 +#endif
29144 +
29145 +RET_ENDP
29146 +BEGIN(sub_unchecked)
29147 + subl %eax, (v)
29148 + sbbl %edx, 4(v)
29149 RET_ENDP
29150 #undef v
29151
29152 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29153 sbbl $0, %edx
29154 addl (v), %eax
29155 adcl 4(v), %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(sub_return_unchecked)
29172 + negl %edx
29173 + negl %eax
29174 + sbbl $0, %edx
29175 + addl (v), %eax
29176 + adcl 4(v), %edx
29177 movl %eax, (v)
29178 movl %edx, 4(v)
29179 RET_ENDP
29180 @@ -105,6 +180,20 @@ RET_ENDP
29181 BEGIN(inc)
29182 addl $1, (v)
29183 adcl $0, 4(v)
29184 +
29185 +#ifdef CONFIG_PAX_REFCOUNT
29186 + jno 0f
29187 + subl $1, (v)
29188 + sbbl $0, 4(v)
29189 + int $4
29190 +0:
29191 + _ASM_EXTABLE(0b, 0b)
29192 +#endif
29193 +
29194 +RET_ENDP
29195 +BEGIN(inc_unchecked)
29196 + addl $1, (v)
29197 + adcl $0, 4(v)
29198 RET_ENDP
29199 #undef v
29200
29201 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29202 movl 4(v), %edx
29203 addl $1, %eax
29204 adcl $0, %edx
29205 +
29206 +#ifdef CONFIG_PAX_REFCOUNT
29207 + into
29208 +1234:
29209 + _ASM_EXTABLE(1234b, 2f)
29210 +#endif
29211 +
29212 + movl %eax, (v)
29213 + movl %edx, 4(v)
29214 +
29215 +#ifdef CONFIG_PAX_REFCOUNT
29216 +2:
29217 +#endif
29218 +
29219 +RET_ENDP
29220 +BEGIN(inc_return_unchecked)
29221 + movl (v), %eax
29222 + movl 4(v), %edx
29223 + addl $1, %eax
29224 + adcl $0, %edx
29225 movl %eax, (v)
29226 movl %edx, 4(v)
29227 RET_ENDP
29228 @@ -123,6 +232,20 @@ RET_ENDP
29229 BEGIN(dec)
29230 subl $1, (v)
29231 sbbl $0, 4(v)
29232 +
29233 +#ifdef CONFIG_PAX_REFCOUNT
29234 + jno 0f
29235 + addl $1, (v)
29236 + adcl $0, 4(v)
29237 + int $4
29238 +0:
29239 + _ASM_EXTABLE(0b, 0b)
29240 +#endif
29241 +
29242 +RET_ENDP
29243 +BEGIN(dec_unchecked)
29244 + subl $1, (v)
29245 + sbbl $0, 4(v)
29246 RET_ENDP
29247 #undef v
29248
29249 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29250 movl 4(v), %edx
29251 subl $1, %eax
29252 sbbl $0, %edx
29253 +
29254 +#ifdef CONFIG_PAX_REFCOUNT
29255 + into
29256 +1234:
29257 + _ASM_EXTABLE(1234b, 2f)
29258 +#endif
29259 +
29260 + movl %eax, (v)
29261 + movl %edx, 4(v)
29262 +
29263 +#ifdef CONFIG_PAX_REFCOUNT
29264 +2:
29265 +#endif
29266 +
29267 +RET_ENDP
29268 +BEGIN(dec_return_unchecked)
29269 + movl (v), %eax
29270 + movl 4(v), %edx
29271 + subl $1, %eax
29272 + sbbl $0, %edx
29273 movl %eax, (v)
29274 movl %edx, 4(v)
29275 RET_ENDP
29276 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29277 adcl %edx, %edi
29278 addl (v), %eax
29279 adcl 4(v), %edx
29280 +
29281 +#ifdef CONFIG_PAX_REFCOUNT
29282 + into
29283 +1234:
29284 + _ASM_EXTABLE(1234b, 2f)
29285 +#endif
29286 +
29287 cmpl %eax, %ecx
29288 je 3f
29289 1:
29290 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29291 1:
29292 addl $1, %eax
29293 adcl $0, %edx
29294 +
29295 +#ifdef CONFIG_PAX_REFCOUNT
29296 + into
29297 +1234:
29298 + _ASM_EXTABLE(1234b, 2f)
29299 +#endif
29300 +
29301 movl %eax, (v)
29302 movl %edx, 4(v)
29303 movl $1, %eax
29304 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29305 movl 4(v), %edx
29306 subl $1, %eax
29307 sbbl $0, %edx
29308 +
29309 +#ifdef CONFIG_PAX_REFCOUNT
29310 + into
29311 +1234:
29312 + _ASM_EXTABLE(1234b, 1f)
29313 +#endif
29314 +
29315 js 1f
29316 movl %eax, (v)
29317 movl %edx, 4(v)
29318 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29319 index f5cc9eb..51fa319 100644
29320 --- a/arch/x86/lib/atomic64_cx8_32.S
29321 +++ b/arch/x86/lib/atomic64_cx8_32.S
29322 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29323 CFI_STARTPROC
29324
29325 read64 %ecx
29326 + pax_force_retaddr
29327 ret
29328 CFI_ENDPROC
29329 ENDPROC(atomic64_read_cx8)
29330
29331 +ENTRY(atomic64_read_unchecked_cx8)
29332 + CFI_STARTPROC
29333 +
29334 + read64 %ecx
29335 + pax_force_retaddr
29336 + ret
29337 + CFI_ENDPROC
29338 +ENDPROC(atomic64_read_unchecked_cx8)
29339 +
29340 ENTRY(atomic64_set_cx8)
29341 CFI_STARTPROC
29342
29343 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29344 cmpxchg8b (%esi)
29345 jne 1b
29346
29347 + pax_force_retaddr
29348 ret
29349 CFI_ENDPROC
29350 ENDPROC(atomic64_set_cx8)
29351
29352 +ENTRY(atomic64_set_unchecked_cx8)
29353 + CFI_STARTPROC
29354 +
29355 +1:
29356 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29357 + * are atomic on 586 and newer */
29358 + cmpxchg8b (%esi)
29359 + jne 1b
29360 +
29361 + pax_force_retaddr
29362 + ret
29363 + CFI_ENDPROC
29364 +ENDPROC(atomic64_set_unchecked_cx8)
29365 +
29366 ENTRY(atomic64_xchg_cx8)
29367 CFI_STARTPROC
29368
29369 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29370 cmpxchg8b (%esi)
29371 jne 1b
29372
29373 + pax_force_retaddr
29374 ret
29375 CFI_ENDPROC
29376 ENDPROC(atomic64_xchg_cx8)
29377
29378 -.macro addsub_return func ins insc
29379 -ENTRY(atomic64_\func\()_return_cx8)
29380 +.macro addsub_return func ins insc unchecked=""
29381 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29382 CFI_STARTPROC
29383 SAVE ebp
29384 SAVE ebx
29385 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29386 movl %edx, %ecx
29387 \ins\()l %esi, %ebx
29388 \insc\()l %edi, %ecx
29389 +
29390 +.ifb \unchecked
29391 +#ifdef CONFIG_PAX_REFCOUNT
29392 + into
29393 +2:
29394 + _ASM_EXTABLE(2b, 3f)
29395 +#endif
29396 +.endif
29397 +
29398 LOCK_PREFIX
29399 cmpxchg8b (%ebp)
29400 jne 1b
29401 -
29402 -10:
29403 movl %ebx, %eax
29404 movl %ecx, %edx
29405 +
29406 +.ifb \unchecked
29407 +#ifdef CONFIG_PAX_REFCOUNT
29408 +3:
29409 +#endif
29410 +.endif
29411 +
29412 RESTORE edi
29413 RESTORE esi
29414 RESTORE ebx
29415 RESTORE ebp
29416 + pax_force_retaddr
29417 ret
29418 CFI_ENDPROC
29419 -ENDPROC(atomic64_\func\()_return_cx8)
29420 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29421 .endm
29422
29423 addsub_return add add adc
29424 addsub_return sub sub sbb
29425 +addsub_return add add adc _unchecked
29426 +addsub_return sub sub sbb _unchecked
29427
29428 -.macro incdec_return func ins insc
29429 -ENTRY(atomic64_\func\()_return_cx8)
29430 +.macro incdec_return func ins insc unchecked=""
29431 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29432 CFI_STARTPROC
29433 SAVE ebx
29434
29435 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29436 movl %edx, %ecx
29437 \ins\()l $1, %ebx
29438 \insc\()l $0, %ecx
29439 +
29440 +.ifb \unchecked
29441 +#ifdef CONFIG_PAX_REFCOUNT
29442 + into
29443 +2:
29444 + _ASM_EXTABLE(2b, 3f)
29445 +#endif
29446 +.endif
29447 +
29448 LOCK_PREFIX
29449 cmpxchg8b (%esi)
29450 jne 1b
29451
29452 -10:
29453 movl %ebx, %eax
29454 movl %ecx, %edx
29455 +
29456 +.ifb \unchecked
29457 +#ifdef CONFIG_PAX_REFCOUNT
29458 +3:
29459 +#endif
29460 +.endif
29461 +
29462 RESTORE ebx
29463 + pax_force_retaddr
29464 ret
29465 CFI_ENDPROC
29466 -ENDPROC(atomic64_\func\()_return_cx8)
29467 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29468 .endm
29469
29470 incdec_return inc add adc
29471 incdec_return dec sub sbb
29472 +incdec_return inc add adc _unchecked
29473 +incdec_return dec sub sbb _unchecked
29474
29475 ENTRY(atomic64_dec_if_positive_cx8)
29476 CFI_STARTPROC
29477 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29478 movl %edx, %ecx
29479 subl $1, %ebx
29480 sbb $0, %ecx
29481 +
29482 +#ifdef CONFIG_PAX_REFCOUNT
29483 + into
29484 +1234:
29485 + _ASM_EXTABLE(1234b, 2f)
29486 +#endif
29487 +
29488 js 2f
29489 LOCK_PREFIX
29490 cmpxchg8b (%esi)
29491 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29492 movl %ebx, %eax
29493 movl %ecx, %edx
29494 RESTORE ebx
29495 + pax_force_retaddr
29496 ret
29497 CFI_ENDPROC
29498 ENDPROC(atomic64_dec_if_positive_cx8)
29499 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29500 movl %edx, %ecx
29501 addl %ebp, %ebx
29502 adcl %edi, %ecx
29503 +
29504 +#ifdef CONFIG_PAX_REFCOUNT
29505 + into
29506 +1234:
29507 + _ASM_EXTABLE(1234b, 3f)
29508 +#endif
29509 +
29510 LOCK_PREFIX
29511 cmpxchg8b (%esi)
29512 jne 1b
29513 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29514 CFI_ADJUST_CFA_OFFSET -8
29515 RESTORE ebx
29516 RESTORE ebp
29517 + pax_force_retaddr
29518 ret
29519 4:
29520 cmpl %edx, 4(%esp)
29521 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29522 xorl %ecx, %ecx
29523 addl $1, %ebx
29524 adcl %edx, %ecx
29525 +
29526 +#ifdef CONFIG_PAX_REFCOUNT
29527 + into
29528 +1234:
29529 + _ASM_EXTABLE(1234b, 3f)
29530 +#endif
29531 +
29532 LOCK_PREFIX
29533 cmpxchg8b (%esi)
29534 jne 1b
29535 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29536 movl $1, %eax
29537 3:
29538 RESTORE ebx
29539 + pax_force_retaddr
29540 ret
29541 CFI_ENDPROC
29542 ENDPROC(atomic64_inc_not_zero_cx8)
29543 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29544 index e78b8eee..7e173a8 100644
29545 --- a/arch/x86/lib/checksum_32.S
29546 +++ b/arch/x86/lib/checksum_32.S
29547 @@ -29,7 +29,8 @@
29548 #include <asm/dwarf2.h>
29549 #include <asm/errno.h>
29550 #include <asm/asm.h>
29551 -
29552 +#include <asm/segment.h>
29553 +
29554 /*
29555 * computes a partial checksum, e.g. for TCP/UDP fragments
29556 */
29557 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29558
29559 #define ARGBASE 16
29560 #define FP 12
29561 -
29562 -ENTRY(csum_partial_copy_generic)
29563 +
29564 +ENTRY(csum_partial_copy_generic_to_user)
29565 CFI_STARTPROC
29566 +
29567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29568 + pushl_cfi %gs
29569 + popl_cfi %es
29570 + jmp csum_partial_copy_generic
29571 +#endif
29572 +
29573 +ENTRY(csum_partial_copy_generic_from_user)
29574 +
29575 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29576 + pushl_cfi %gs
29577 + popl_cfi %ds
29578 +#endif
29579 +
29580 +ENTRY(csum_partial_copy_generic)
29581 subl $4,%esp
29582 CFI_ADJUST_CFA_OFFSET 4
29583 pushl_cfi %edi
29584 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29585 jmp 4f
29586 SRC(1: movw (%esi), %bx )
29587 addl $2, %esi
29588 -DST( movw %bx, (%edi) )
29589 +DST( movw %bx, %es:(%edi) )
29590 addl $2, %edi
29591 addw %bx, %ax
29592 adcl $0, %eax
29593 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29594 SRC(1: movl (%esi), %ebx )
29595 SRC( movl 4(%esi), %edx )
29596 adcl %ebx, %eax
29597 -DST( movl %ebx, (%edi) )
29598 +DST( movl %ebx, %es:(%edi) )
29599 adcl %edx, %eax
29600 -DST( movl %edx, 4(%edi) )
29601 +DST( movl %edx, %es:4(%edi) )
29602
29603 SRC( movl 8(%esi), %ebx )
29604 SRC( movl 12(%esi), %edx )
29605 adcl %ebx, %eax
29606 -DST( movl %ebx, 8(%edi) )
29607 +DST( movl %ebx, %es:8(%edi) )
29608 adcl %edx, %eax
29609 -DST( movl %edx, 12(%edi) )
29610 +DST( movl %edx, %es:12(%edi) )
29611
29612 SRC( movl 16(%esi), %ebx )
29613 SRC( movl 20(%esi), %edx )
29614 adcl %ebx, %eax
29615 -DST( movl %ebx, 16(%edi) )
29616 +DST( movl %ebx, %es:16(%edi) )
29617 adcl %edx, %eax
29618 -DST( movl %edx, 20(%edi) )
29619 +DST( movl %edx, %es:20(%edi) )
29620
29621 SRC( movl 24(%esi), %ebx )
29622 SRC( movl 28(%esi), %edx )
29623 adcl %ebx, %eax
29624 -DST( movl %ebx, 24(%edi) )
29625 +DST( movl %ebx, %es:24(%edi) )
29626 adcl %edx, %eax
29627 -DST( movl %edx, 28(%edi) )
29628 +DST( movl %edx, %es:28(%edi) )
29629
29630 lea 32(%esi), %esi
29631 lea 32(%edi), %edi
29632 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29633 shrl $2, %edx # This clears CF
29634 SRC(3: movl (%esi), %ebx )
29635 adcl %ebx, %eax
29636 -DST( movl %ebx, (%edi) )
29637 +DST( movl %ebx, %es:(%edi) )
29638 lea 4(%esi), %esi
29639 lea 4(%edi), %edi
29640 dec %edx
29641 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29642 jb 5f
29643 SRC( movw (%esi), %cx )
29644 leal 2(%esi), %esi
29645 -DST( movw %cx, (%edi) )
29646 +DST( movw %cx, %es:(%edi) )
29647 leal 2(%edi), %edi
29648 je 6f
29649 shll $16,%ecx
29650 SRC(5: movb (%esi), %cl )
29651 -DST( movb %cl, (%edi) )
29652 +DST( movb %cl, %es:(%edi) )
29653 6: addl %ecx, %eax
29654 adcl $0, %eax
29655 7:
29656 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29657
29658 6001:
29659 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29660 - movl $-EFAULT, (%ebx)
29661 + movl $-EFAULT, %ss:(%ebx)
29662
29663 # zero the complete destination - computing the rest
29664 # is too much work
29665 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29666
29667 6002:
29668 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29669 - movl $-EFAULT,(%ebx)
29670 + movl $-EFAULT,%ss:(%ebx)
29671 jmp 5000b
29672
29673 .previous
29674
29675 + pushl_cfi %ss
29676 + popl_cfi %ds
29677 + pushl_cfi %ss
29678 + popl_cfi %es
29679 popl_cfi %ebx
29680 CFI_RESTORE ebx
29681 popl_cfi %esi
29682 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29683 popl_cfi %ecx # equivalent to addl $4,%esp
29684 ret
29685 CFI_ENDPROC
29686 -ENDPROC(csum_partial_copy_generic)
29687 +ENDPROC(csum_partial_copy_generic_to_user)
29688
29689 #else
29690
29691 /* Version for PentiumII/PPro */
29692
29693 #define ROUND1(x) \
29694 + nop; nop; nop; \
29695 SRC(movl x(%esi), %ebx ) ; \
29696 addl %ebx, %eax ; \
29697 - DST(movl %ebx, x(%edi) ) ;
29698 + DST(movl %ebx, %es:x(%edi)) ;
29699
29700 #define ROUND(x) \
29701 + nop; nop; nop; \
29702 SRC(movl x(%esi), %ebx ) ; \
29703 adcl %ebx, %eax ; \
29704 - DST(movl %ebx, x(%edi) ) ;
29705 + DST(movl %ebx, %es:x(%edi)) ;
29706
29707 #define ARGBASE 12
29708 -
29709 -ENTRY(csum_partial_copy_generic)
29710 +
29711 +ENTRY(csum_partial_copy_generic_to_user)
29712 CFI_STARTPROC
29713 +
29714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29715 + pushl_cfi %gs
29716 + popl_cfi %es
29717 + jmp csum_partial_copy_generic
29718 +#endif
29719 +
29720 +ENTRY(csum_partial_copy_generic_from_user)
29721 +
29722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29723 + pushl_cfi %gs
29724 + popl_cfi %ds
29725 +#endif
29726 +
29727 +ENTRY(csum_partial_copy_generic)
29728 pushl_cfi %ebx
29729 CFI_REL_OFFSET ebx, 0
29730 pushl_cfi %edi
29731 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29732 subl %ebx, %edi
29733 lea -1(%esi),%edx
29734 andl $-32,%edx
29735 - lea 3f(%ebx,%ebx), %ebx
29736 + lea 3f(%ebx,%ebx,2), %ebx
29737 testl %esi, %esi
29738 jmp *%ebx
29739 1: addl $64,%esi
29740 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29741 jb 5f
29742 SRC( movw (%esi), %dx )
29743 leal 2(%esi), %esi
29744 -DST( movw %dx, (%edi) )
29745 +DST( movw %dx, %es:(%edi) )
29746 leal 2(%edi), %edi
29747 je 6f
29748 shll $16,%edx
29749 5:
29750 SRC( movb (%esi), %dl )
29751 -DST( movb %dl, (%edi) )
29752 +DST( movb %dl, %es:(%edi) )
29753 6: addl %edx, %eax
29754 adcl $0, %eax
29755 7:
29756 .section .fixup, "ax"
29757 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29758 - movl $-EFAULT, (%ebx)
29759 + movl $-EFAULT, %ss:(%ebx)
29760 # zero the complete destination (computing the rest is too much work)
29761 movl ARGBASE+8(%esp),%edi # dst
29762 movl ARGBASE+12(%esp),%ecx # len
29763 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29764 rep; stosb
29765 jmp 7b
29766 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29767 - movl $-EFAULT, (%ebx)
29768 + movl $-EFAULT, %ss:(%ebx)
29769 jmp 7b
29770 .previous
29771
29772 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29773 + pushl_cfi %ss
29774 + popl_cfi %ds
29775 + pushl_cfi %ss
29776 + popl_cfi %es
29777 +#endif
29778 +
29779 popl_cfi %esi
29780 CFI_RESTORE esi
29781 popl_cfi %edi
29782 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29783 CFI_RESTORE ebx
29784 ret
29785 CFI_ENDPROC
29786 -ENDPROC(csum_partial_copy_generic)
29787 +ENDPROC(csum_partial_copy_generic_to_user)
29788
29789 #undef ROUND
29790 #undef ROUND1
29791 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29792 index f2145cf..cea889d 100644
29793 --- a/arch/x86/lib/clear_page_64.S
29794 +++ b/arch/x86/lib/clear_page_64.S
29795 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29796 movl $4096/8,%ecx
29797 xorl %eax,%eax
29798 rep stosq
29799 + pax_force_retaddr
29800 ret
29801 CFI_ENDPROC
29802 ENDPROC(clear_page_c)
29803 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29804 movl $4096,%ecx
29805 xorl %eax,%eax
29806 rep stosb
29807 + pax_force_retaddr
29808 ret
29809 CFI_ENDPROC
29810 ENDPROC(clear_page_c_e)
29811 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29812 leaq 64(%rdi),%rdi
29813 jnz .Lloop
29814 nop
29815 + pax_force_retaddr
29816 ret
29817 CFI_ENDPROC
29818 .Lclear_page_end:
29819 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29820
29821 #include <asm/cpufeature.h>
29822
29823 - .section .altinstr_replacement,"ax"
29824 + .section .altinstr_replacement,"a"
29825 1: .byte 0xeb /* jmp <disp8> */
29826 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29827 2: .byte 0xeb /* jmp <disp8> */
29828 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29829 index 40a1725..5d12ac4 100644
29830 --- a/arch/x86/lib/cmpxchg16b_emu.S
29831 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29832 @@ -8,6 +8,7 @@
29833 #include <linux/linkage.h>
29834 #include <asm/dwarf2.h>
29835 #include <asm/percpu.h>
29836 +#include <asm/alternative-asm.h>
29837
29838 .text
29839
29840 @@ -46,12 +47,14 @@ CFI_STARTPROC
29841 CFI_REMEMBER_STATE
29842 popfq_cfi
29843 mov $1, %al
29844 + pax_force_retaddr
29845 ret
29846
29847 CFI_RESTORE_STATE
29848 .Lnot_same:
29849 popfq_cfi
29850 xor %al,%al
29851 + pax_force_retaddr
29852 ret
29853
29854 CFI_ENDPROC
29855 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29856 index 176cca6..e0d658e 100644
29857 --- a/arch/x86/lib/copy_page_64.S
29858 +++ b/arch/x86/lib/copy_page_64.S
29859 @@ -9,6 +9,7 @@ copy_page_rep:
29860 CFI_STARTPROC
29861 movl $4096/8, %ecx
29862 rep movsq
29863 + pax_force_retaddr
29864 ret
29865 CFI_ENDPROC
29866 ENDPROC(copy_page_rep)
29867 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29868 CFI_ADJUST_CFA_OFFSET 2*8
29869 movq %rbx, (%rsp)
29870 CFI_REL_OFFSET rbx, 0
29871 - movq %r12, 1*8(%rsp)
29872 - CFI_REL_OFFSET r12, 1*8
29873 + movq %r13, 1*8(%rsp)
29874 + CFI_REL_OFFSET r13, 1*8
29875
29876 movl $(4096/64)-5, %ecx
29877 .p2align 4
29878 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29879 movq 0x8*4(%rsi), %r9
29880 movq 0x8*5(%rsi), %r10
29881 movq 0x8*6(%rsi), %r11
29882 - movq 0x8*7(%rsi), %r12
29883 + movq 0x8*7(%rsi), %r13
29884
29885 prefetcht0 5*64(%rsi)
29886
29887 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29888 movq %r9, 0x8*4(%rdi)
29889 movq %r10, 0x8*5(%rdi)
29890 movq %r11, 0x8*6(%rdi)
29891 - movq %r12, 0x8*7(%rdi)
29892 + movq %r13, 0x8*7(%rdi)
29893
29894 leaq 64 (%rsi), %rsi
29895 leaq 64 (%rdi), %rdi
29896 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29897 movq 0x8*4(%rsi), %r9
29898 movq 0x8*5(%rsi), %r10
29899 movq 0x8*6(%rsi), %r11
29900 - movq 0x8*7(%rsi), %r12
29901 + movq 0x8*7(%rsi), %r13
29902
29903 movq %rax, 0x8*0(%rdi)
29904 movq %rbx, 0x8*1(%rdi)
29905 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29906 movq %r9, 0x8*4(%rdi)
29907 movq %r10, 0x8*5(%rdi)
29908 movq %r11, 0x8*6(%rdi)
29909 - movq %r12, 0x8*7(%rdi)
29910 + movq %r13, 0x8*7(%rdi)
29911
29912 leaq 64(%rdi), %rdi
29913 leaq 64(%rsi), %rsi
29914 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29915
29916 movq (%rsp), %rbx
29917 CFI_RESTORE rbx
29918 - movq 1*8(%rsp), %r12
29919 - CFI_RESTORE r12
29920 + movq 1*8(%rsp), %r13
29921 + CFI_RESTORE r13
29922 addq $2*8, %rsp
29923 CFI_ADJUST_CFA_OFFSET -2*8
29924 + pax_force_retaddr
29925 ret
29926 .Lcopy_page_end:
29927 CFI_ENDPROC
29928 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29929
29930 #include <asm/cpufeature.h>
29931
29932 - .section .altinstr_replacement,"ax"
29933 + .section .altinstr_replacement,"a"
29934 1: .byte 0xeb /* jmp <disp8> */
29935 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29936 2:
29937 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29938 index dee945d..a84067b 100644
29939 --- a/arch/x86/lib/copy_user_64.S
29940 +++ b/arch/x86/lib/copy_user_64.S
29941 @@ -18,31 +18,7 @@
29942 #include <asm/alternative-asm.h>
29943 #include <asm/asm.h>
29944 #include <asm/smap.h>
29945 -
29946 -/*
29947 - * By placing feature2 after feature1 in altinstructions section, we logically
29948 - * implement:
29949 - * If CPU has feature2, jmp to alt2 is used
29950 - * else if CPU has feature1, jmp to alt1 is used
29951 - * else jmp to orig is used.
29952 - */
29953 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29954 -0:
29955 - .byte 0xe9 /* 32bit jump */
29956 - .long \orig-1f /* by default jump to orig */
29957 -1:
29958 - .section .altinstr_replacement,"ax"
29959 -2: .byte 0xe9 /* near jump with 32bit immediate */
29960 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29961 -3: .byte 0xe9 /* near jump with 32bit immediate */
29962 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29963 - .previous
29964 -
29965 - .section .altinstructions,"a"
29966 - altinstruction_entry 0b,2b,\feature1,5,5
29967 - altinstruction_entry 0b,3b,\feature2,5,5
29968 - .previous
29969 - .endm
29970 +#include <asm/pgtable.h>
29971
29972 .macro ALIGN_DESTINATION
29973 #ifdef FIX_ALIGNMENT
29974 @@ -70,52 +46,6 @@
29975 #endif
29976 .endm
29977
29978 -/* Standard copy_to_user with segment limit checking */
29979 -ENTRY(_copy_to_user)
29980 - CFI_STARTPROC
29981 - GET_THREAD_INFO(%rax)
29982 - movq %rdi,%rcx
29983 - addq %rdx,%rcx
29984 - jc bad_to_user
29985 - cmpq TI_addr_limit(%rax),%rcx
29986 - ja bad_to_user
29987 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29988 - copy_user_generic_unrolled,copy_user_generic_string, \
29989 - copy_user_enhanced_fast_string
29990 - CFI_ENDPROC
29991 -ENDPROC(_copy_to_user)
29992 -
29993 -/* Standard copy_from_user with segment limit checking */
29994 -ENTRY(_copy_from_user)
29995 - CFI_STARTPROC
29996 - GET_THREAD_INFO(%rax)
29997 - movq %rsi,%rcx
29998 - addq %rdx,%rcx
29999 - jc bad_from_user
30000 - cmpq TI_addr_limit(%rax),%rcx
30001 - ja bad_from_user
30002 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30003 - copy_user_generic_unrolled,copy_user_generic_string, \
30004 - copy_user_enhanced_fast_string
30005 - CFI_ENDPROC
30006 -ENDPROC(_copy_from_user)
30007 -
30008 - .section .fixup,"ax"
30009 - /* must zero dest */
30010 -ENTRY(bad_from_user)
30011 -bad_from_user:
30012 - CFI_STARTPROC
30013 - movl %edx,%ecx
30014 - xorl %eax,%eax
30015 - rep
30016 - stosb
30017 -bad_to_user:
30018 - movl %edx,%eax
30019 - ret
30020 - CFI_ENDPROC
30021 -ENDPROC(bad_from_user)
30022 - .previous
30023 -
30024 /*
30025 * copy_user_generic_unrolled - memory copy with exception handling.
30026 * This version is for CPUs like P4 that don't have efficient micro
30027 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30028 */
30029 ENTRY(copy_user_generic_unrolled)
30030 CFI_STARTPROC
30031 + ASM_PAX_OPEN_USERLAND
30032 ASM_STAC
30033 cmpl $8,%edx
30034 jb 20f /* less then 8 bytes, go to byte copy loop */
30035 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30036 jnz 21b
30037 23: xor %eax,%eax
30038 ASM_CLAC
30039 + ASM_PAX_CLOSE_USERLAND
30040 + pax_force_retaddr
30041 ret
30042
30043 .section .fixup,"ax"
30044 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30045 */
30046 ENTRY(copy_user_generic_string)
30047 CFI_STARTPROC
30048 + ASM_PAX_OPEN_USERLAND
30049 ASM_STAC
30050 cmpl $8,%edx
30051 jb 2f /* less than 8 bytes, go to byte copy loop */
30052 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30053 movsb
30054 xorl %eax,%eax
30055 ASM_CLAC
30056 + ASM_PAX_CLOSE_USERLAND
30057 + pax_force_retaddr
30058 ret
30059
30060 .section .fixup,"ax"
30061 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30062 */
30063 ENTRY(copy_user_enhanced_fast_string)
30064 CFI_STARTPROC
30065 + ASM_PAX_OPEN_USERLAND
30066 ASM_STAC
30067 movl %edx,%ecx
30068 1: rep
30069 movsb
30070 xorl %eax,%eax
30071 ASM_CLAC
30072 + ASM_PAX_CLOSE_USERLAND
30073 + pax_force_retaddr
30074 ret
30075
30076 .section .fixup,"ax"
30077 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30078 index 6a4f43c..c70fb52 100644
30079 --- a/arch/x86/lib/copy_user_nocache_64.S
30080 +++ b/arch/x86/lib/copy_user_nocache_64.S
30081 @@ -8,6 +8,7 @@
30082
30083 #include <linux/linkage.h>
30084 #include <asm/dwarf2.h>
30085 +#include <asm/alternative-asm.h>
30086
30087 #define FIX_ALIGNMENT 1
30088
30089 @@ -16,6 +17,7 @@
30090 #include <asm/thread_info.h>
30091 #include <asm/asm.h>
30092 #include <asm/smap.h>
30093 +#include <asm/pgtable.h>
30094
30095 .macro ALIGN_DESTINATION
30096 #ifdef FIX_ALIGNMENT
30097 @@ -49,6 +51,16 @@
30098 */
30099 ENTRY(__copy_user_nocache)
30100 CFI_STARTPROC
30101 +
30102 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30103 + mov pax_user_shadow_base,%rcx
30104 + cmp %rcx,%rsi
30105 + jae 1f
30106 + add %rcx,%rsi
30107 +1:
30108 +#endif
30109 +
30110 + ASM_PAX_OPEN_USERLAND
30111 ASM_STAC
30112 cmpl $8,%edx
30113 jb 20f /* less then 8 bytes, go to byte copy loop */
30114 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30115 jnz 21b
30116 23: xorl %eax,%eax
30117 ASM_CLAC
30118 + ASM_PAX_CLOSE_USERLAND
30119 sfence
30120 + pax_force_retaddr
30121 ret
30122
30123 .section .fixup,"ax"
30124 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30125 index 2419d5f..fe52d0e 100644
30126 --- a/arch/x86/lib/csum-copy_64.S
30127 +++ b/arch/x86/lib/csum-copy_64.S
30128 @@ -9,6 +9,7 @@
30129 #include <asm/dwarf2.h>
30130 #include <asm/errno.h>
30131 #include <asm/asm.h>
30132 +#include <asm/alternative-asm.h>
30133
30134 /*
30135 * Checksum copy with exception handling.
30136 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30137 CFI_ADJUST_CFA_OFFSET 7*8
30138 movq %rbx, 2*8(%rsp)
30139 CFI_REL_OFFSET rbx, 2*8
30140 - movq %r12, 3*8(%rsp)
30141 - CFI_REL_OFFSET r12, 3*8
30142 + movq %r15, 3*8(%rsp)
30143 + CFI_REL_OFFSET r15, 3*8
30144 movq %r14, 4*8(%rsp)
30145 CFI_REL_OFFSET r14, 4*8
30146 movq %r13, 5*8(%rsp)
30147 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30148 movl %edx, %ecx
30149
30150 xorl %r9d, %r9d
30151 - movq %rcx, %r12
30152 + movq %rcx, %r15
30153
30154 - shrq $6, %r12
30155 + shrq $6, %r15
30156 jz .Lhandle_tail /* < 64 */
30157
30158 clc
30159
30160 /* main loop. clear in 64 byte blocks */
30161 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30162 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30163 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30164 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30165 .p2align 4
30166 .Lloop:
30167 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30168 adcq %r14, %rax
30169 adcq %r13, %rax
30170
30171 - decl %r12d
30172 + decl %r15d
30173
30174 dest
30175 movq %rbx, (%rsi)
30176 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30177 .Lende:
30178 movq 2*8(%rsp), %rbx
30179 CFI_RESTORE rbx
30180 - movq 3*8(%rsp), %r12
30181 - CFI_RESTORE r12
30182 + movq 3*8(%rsp), %r15
30183 + CFI_RESTORE r15
30184 movq 4*8(%rsp), %r14
30185 CFI_RESTORE r14
30186 movq 5*8(%rsp), %r13
30187 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30188 CFI_RESTORE rbp
30189 addq $7*8, %rsp
30190 CFI_ADJUST_CFA_OFFSET -7*8
30191 + pax_force_retaddr
30192 ret
30193 CFI_RESTORE_STATE
30194
30195 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30196 index 1318f75..44c30fd 100644
30197 --- a/arch/x86/lib/csum-wrappers_64.c
30198 +++ b/arch/x86/lib/csum-wrappers_64.c
30199 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30200 len -= 2;
30201 }
30202 }
30203 + pax_open_userland();
30204 stac();
30205 - isum = csum_partial_copy_generic((__force const void *)src,
30206 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30207 dst, len, isum, errp, NULL);
30208 clac();
30209 + pax_close_userland();
30210 if (unlikely(*errp))
30211 goto out_err;
30212
30213 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30214 }
30215
30216 *errp = 0;
30217 + pax_open_userland();
30218 stac();
30219 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30220 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30221 len, isum, NULL, errp);
30222 clac();
30223 + pax_close_userland();
30224 return ret;
30225 }
30226 EXPORT_SYMBOL(csum_partial_copy_to_user);
30227 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30228 index a451235..1daa956 100644
30229 --- a/arch/x86/lib/getuser.S
30230 +++ b/arch/x86/lib/getuser.S
30231 @@ -33,17 +33,40 @@
30232 #include <asm/thread_info.h>
30233 #include <asm/asm.h>
30234 #include <asm/smap.h>
30235 +#include <asm/segment.h>
30236 +#include <asm/pgtable.h>
30237 +#include <asm/alternative-asm.h>
30238 +
30239 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30240 +#define __copyuser_seg gs;
30241 +#else
30242 +#define __copyuser_seg
30243 +#endif
30244
30245 .text
30246 ENTRY(__get_user_1)
30247 CFI_STARTPROC
30248 +
30249 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30250 GET_THREAD_INFO(%_ASM_DX)
30251 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30252 jae bad_get_user
30253 ASM_STAC
30254 -1: movzbl (%_ASM_AX),%edx
30255 +
30256 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30257 + mov pax_user_shadow_base,%_ASM_DX
30258 + cmp %_ASM_DX,%_ASM_AX
30259 + jae 1234f
30260 + add %_ASM_DX,%_ASM_AX
30261 +1234:
30262 +#endif
30263 +
30264 +#endif
30265 +
30266 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30267 xor %eax,%eax
30268 ASM_CLAC
30269 + pax_force_retaddr
30270 ret
30271 CFI_ENDPROC
30272 ENDPROC(__get_user_1)
30273 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30274 ENTRY(__get_user_2)
30275 CFI_STARTPROC
30276 add $1,%_ASM_AX
30277 +
30278 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30279 jc bad_get_user
30280 GET_THREAD_INFO(%_ASM_DX)
30281 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30282 jae bad_get_user
30283 ASM_STAC
30284 -2: movzwl -1(%_ASM_AX),%edx
30285 +
30286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30287 + mov pax_user_shadow_base,%_ASM_DX
30288 + cmp %_ASM_DX,%_ASM_AX
30289 + jae 1234f
30290 + add %_ASM_DX,%_ASM_AX
30291 +1234:
30292 +#endif
30293 +
30294 +#endif
30295 +
30296 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30297 xor %eax,%eax
30298 ASM_CLAC
30299 + pax_force_retaddr
30300 ret
30301 CFI_ENDPROC
30302 ENDPROC(__get_user_2)
30303 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30304 ENTRY(__get_user_4)
30305 CFI_STARTPROC
30306 add $3,%_ASM_AX
30307 +
30308 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30309 jc bad_get_user
30310 GET_THREAD_INFO(%_ASM_DX)
30311 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30312 jae bad_get_user
30313 ASM_STAC
30314 -3: movl -3(%_ASM_AX),%edx
30315 +
30316 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30317 + mov pax_user_shadow_base,%_ASM_DX
30318 + cmp %_ASM_DX,%_ASM_AX
30319 + jae 1234f
30320 + add %_ASM_DX,%_ASM_AX
30321 +1234:
30322 +#endif
30323 +
30324 +#endif
30325 +
30326 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30327 xor %eax,%eax
30328 ASM_CLAC
30329 + pax_force_retaddr
30330 ret
30331 CFI_ENDPROC
30332 ENDPROC(__get_user_4)
30333 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30334 GET_THREAD_INFO(%_ASM_DX)
30335 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30336 jae bad_get_user
30337 +
30338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30339 + mov pax_user_shadow_base,%_ASM_DX
30340 + cmp %_ASM_DX,%_ASM_AX
30341 + jae 1234f
30342 + add %_ASM_DX,%_ASM_AX
30343 +1234:
30344 +#endif
30345 +
30346 ASM_STAC
30347 4: movq -7(%_ASM_AX),%rdx
30348 xor %eax,%eax
30349 ASM_CLAC
30350 + pax_force_retaddr
30351 ret
30352 #else
30353 add $7,%_ASM_AX
30354 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30355 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30356 jae bad_get_user_8
30357 ASM_STAC
30358 -4: movl -7(%_ASM_AX),%edx
30359 -5: movl -3(%_ASM_AX),%ecx
30360 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30361 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30362 xor %eax,%eax
30363 ASM_CLAC
30364 + pax_force_retaddr
30365 ret
30366 #endif
30367 CFI_ENDPROC
30368 @@ -113,6 +175,7 @@ bad_get_user:
30369 xor %edx,%edx
30370 mov $(-EFAULT),%_ASM_AX
30371 ASM_CLAC
30372 + pax_force_retaddr
30373 ret
30374 CFI_ENDPROC
30375 END(bad_get_user)
30376 @@ -124,6 +187,7 @@ bad_get_user_8:
30377 xor %ecx,%ecx
30378 mov $(-EFAULT),%_ASM_AX
30379 ASM_CLAC
30380 + pax_force_retaddr
30381 ret
30382 CFI_ENDPROC
30383 END(bad_get_user_8)
30384 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30385 index 54fcffe..7be149e 100644
30386 --- a/arch/x86/lib/insn.c
30387 +++ b/arch/x86/lib/insn.c
30388 @@ -20,8 +20,10 @@
30389
30390 #ifdef __KERNEL__
30391 #include <linux/string.h>
30392 +#include <asm/pgtable_types.h>
30393 #else
30394 #include <string.h>
30395 +#define ktla_ktva(addr) addr
30396 #endif
30397 #include <asm/inat.h>
30398 #include <asm/insn.h>
30399 @@ -53,8 +55,8 @@
30400 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30401 {
30402 memset(insn, 0, sizeof(*insn));
30403 - insn->kaddr = kaddr;
30404 - insn->next_byte = kaddr;
30405 + insn->kaddr = ktla_ktva(kaddr);
30406 + insn->next_byte = ktla_ktva(kaddr);
30407 insn->x86_64 = x86_64 ? 1 : 0;
30408 insn->opnd_bytes = 4;
30409 if (x86_64)
30410 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30411 index 05a95e7..326f2fa 100644
30412 --- a/arch/x86/lib/iomap_copy_64.S
30413 +++ b/arch/x86/lib/iomap_copy_64.S
30414 @@ -17,6 +17,7 @@
30415
30416 #include <linux/linkage.h>
30417 #include <asm/dwarf2.h>
30418 +#include <asm/alternative-asm.h>
30419
30420 /*
30421 * override generic version in lib/iomap_copy.c
30422 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30423 CFI_STARTPROC
30424 movl %edx,%ecx
30425 rep movsd
30426 + pax_force_retaddr
30427 ret
30428 CFI_ENDPROC
30429 ENDPROC(__iowrite32_copy)
30430 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30431 index 56313a3..0db417e 100644
30432 --- a/arch/x86/lib/memcpy_64.S
30433 +++ b/arch/x86/lib/memcpy_64.S
30434 @@ -24,7 +24,7 @@
30435 * This gets patched over the unrolled variant (below) via the
30436 * alternative instructions framework:
30437 */
30438 - .section .altinstr_replacement, "ax", @progbits
30439 + .section .altinstr_replacement, "a", @progbits
30440 .Lmemcpy_c:
30441 movq %rdi, %rax
30442 movq %rdx, %rcx
30443 @@ -33,6 +33,7 @@
30444 rep movsq
30445 movl %edx, %ecx
30446 rep movsb
30447 + pax_force_retaddr
30448 ret
30449 .Lmemcpy_e:
30450 .previous
30451 @@ -44,11 +45,12 @@
30452 * This gets patched over the unrolled variant (below) via the
30453 * alternative instructions framework:
30454 */
30455 - .section .altinstr_replacement, "ax", @progbits
30456 + .section .altinstr_replacement, "a", @progbits
30457 .Lmemcpy_c_e:
30458 movq %rdi, %rax
30459 movq %rdx, %rcx
30460 rep movsb
30461 + pax_force_retaddr
30462 ret
30463 .Lmemcpy_e_e:
30464 .previous
30465 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30466 movq %r9, 1*8(%rdi)
30467 movq %r10, -2*8(%rdi, %rdx)
30468 movq %r11, -1*8(%rdi, %rdx)
30469 + pax_force_retaddr
30470 retq
30471 .p2align 4
30472 .Lless_16bytes:
30473 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30474 movq -1*8(%rsi, %rdx), %r9
30475 movq %r8, 0*8(%rdi)
30476 movq %r9, -1*8(%rdi, %rdx)
30477 + pax_force_retaddr
30478 retq
30479 .p2align 4
30480 .Lless_8bytes:
30481 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30482 movl -4(%rsi, %rdx), %r8d
30483 movl %ecx, (%rdi)
30484 movl %r8d, -4(%rdi, %rdx)
30485 + pax_force_retaddr
30486 retq
30487 .p2align 4
30488 .Lless_3bytes:
30489 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30490 movb %cl, (%rdi)
30491
30492 .Lend:
30493 + pax_force_retaddr
30494 retq
30495 CFI_ENDPROC
30496 ENDPROC(memcpy)
30497 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30498 index 65268a6..dd1de11 100644
30499 --- a/arch/x86/lib/memmove_64.S
30500 +++ b/arch/x86/lib/memmove_64.S
30501 @@ -202,14 +202,16 @@ ENTRY(memmove)
30502 movb (%rsi), %r11b
30503 movb %r11b, (%rdi)
30504 13:
30505 + pax_force_retaddr
30506 retq
30507 CFI_ENDPROC
30508
30509 - .section .altinstr_replacement,"ax"
30510 + .section .altinstr_replacement,"a"
30511 .Lmemmove_begin_forward_efs:
30512 /* Forward moving data. */
30513 movq %rdx, %rcx
30514 rep movsb
30515 + pax_force_retaddr
30516 retq
30517 .Lmemmove_end_forward_efs:
30518 .previous
30519 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30520 index 2dcb380..2eb79fe 100644
30521 --- a/arch/x86/lib/memset_64.S
30522 +++ b/arch/x86/lib/memset_64.S
30523 @@ -16,7 +16,7 @@
30524 *
30525 * rax original destination
30526 */
30527 - .section .altinstr_replacement, "ax", @progbits
30528 + .section .altinstr_replacement, "a", @progbits
30529 .Lmemset_c:
30530 movq %rdi,%r9
30531 movq %rdx,%rcx
30532 @@ -30,6 +30,7 @@
30533 movl %edx,%ecx
30534 rep stosb
30535 movq %r9,%rax
30536 + pax_force_retaddr
30537 ret
30538 .Lmemset_e:
30539 .previous
30540 @@ -45,13 +46,14 @@
30541 *
30542 * rax original destination
30543 */
30544 - .section .altinstr_replacement, "ax", @progbits
30545 + .section .altinstr_replacement, "a", @progbits
30546 .Lmemset_c_e:
30547 movq %rdi,%r9
30548 movb %sil,%al
30549 movq %rdx,%rcx
30550 rep stosb
30551 movq %r9,%rax
30552 + pax_force_retaddr
30553 ret
30554 .Lmemset_e_e:
30555 .previous
30556 @@ -118,6 +120,7 @@ ENTRY(__memset)
30557
30558 .Lende:
30559 movq %r10,%rax
30560 + pax_force_retaddr
30561 ret
30562
30563 CFI_RESTORE_STATE
30564 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30565 index c9f2d9b..e7fd2c0 100644
30566 --- a/arch/x86/lib/mmx_32.c
30567 +++ b/arch/x86/lib/mmx_32.c
30568 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30569 {
30570 void *p;
30571 int i;
30572 + unsigned long cr0;
30573
30574 if (unlikely(in_interrupt()))
30575 return __memcpy(to, from, len);
30576 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30577 kernel_fpu_begin();
30578
30579 __asm__ __volatile__ (
30580 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30581 - " prefetch 64(%0)\n"
30582 - " prefetch 128(%0)\n"
30583 - " prefetch 192(%0)\n"
30584 - " prefetch 256(%0)\n"
30585 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30586 + " prefetch 64(%1)\n"
30587 + " prefetch 128(%1)\n"
30588 + " prefetch 192(%1)\n"
30589 + " prefetch 256(%1)\n"
30590 "2: \n"
30591 ".section .fixup, \"ax\"\n"
30592 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30593 + "3: \n"
30594 +
30595 +#ifdef CONFIG_PAX_KERNEXEC
30596 + " movl %%cr0, %0\n"
30597 + " movl %0, %%eax\n"
30598 + " andl $0xFFFEFFFF, %%eax\n"
30599 + " movl %%eax, %%cr0\n"
30600 +#endif
30601 +
30602 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30603 +
30604 +#ifdef CONFIG_PAX_KERNEXEC
30605 + " movl %0, %%cr0\n"
30606 +#endif
30607 +
30608 " jmp 2b\n"
30609 ".previous\n"
30610 _ASM_EXTABLE(1b, 3b)
30611 - : : "r" (from));
30612 + : "=&r" (cr0) : "r" (from) : "ax");
30613
30614 for ( ; i > 5; i--) {
30615 __asm__ __volatile__ (
30616 - "1: prefetch 320(%0)\n"
30617 - "2: movq (%0), %%mm0\n"
30618 - " movq 8(%0), %%mm1\n"
30619 - " movq 16(%0), %%mm2\n"
30620 - " movq 24(%0), %%mm3\n"
30621 - " movq %%mm0, (%1)\n"
30622 - " movq %%mm1, 8(%1)\n"
30623 - " movq %%mm2, 16(%1)\n"
30624 - " movq %%mm3, 24(%1)\n"
30625 - " movq 32(%0), %%mm0\n"
30626 - " movq 40(%0), %%mm1\n"
30627 - " movq 48(%0), %%mm2\n"
30628 - " movq 56(%0), %%mm3\n"
30629 - " movq %%mm0, 32(%1)\n"
30630 - " movq %%mm1, 40(%1)\n"
30631 - " movq %%mm2, 48(%1)\n"
30632 - " movq %%mm3, 56(%1)\n"
30633 + "1: prefetch 320(%1)\n"
30634 + "2: movq (%1), %%mm0\n"
30635 + " movq 8(%1), %%mm1\n"
30636 + " movq 16(%1), %%mm2\n"
30637 + " movq 24(%1), %%mm3\n"
30638 + " movq %%mm0, (%2)\n"
30639 + " movq %%mm1, 8(%2)\n"
30640 + " movq %%mm2, 16(%2)\n"
30641 + " movq %%mm3, 24(%2)\n"
30642 + " movq 32(%1), %%mm0\n"
30643 + " movq 40(%1), %%mm1\n"
30644 + " movq 48(%1), %%mm2\n"
30645 + " movq 56(%1), %%mm3\n"
30646 + " movq %%mm0, 32(%2)\n"
30647 + " movq %%mm1, 40(%2)\n"
30648 + " movq %%mm2, 48(%2)\n"
30649 + " movq %%mm3, 56(%2)\n"
30650 ".section .fixup, \"ax\"\n"
30651 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30652 + "3:\n"
30653 +
30654 +#ifdef CONFIG_PAX_KERNEXEC
30655 + " movl %%cr0, %0\n"
30656 + " movl %0, %%eax\n"
30657 + " andl $0xFFFEFFFF, %%eax\n"
30658 + " movl %%eax, %%cr0\n"
30659 +#endif
30660 +
30661 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30662 +
30663 +#ifdef CONFIG_PAX_KERNEXEC
30664 + " movl %0, %%cr0\n"
30665 +#endif
30666 +
30667 " jmp 2b\n"
30668 ".previous\n"
30669 _ASM_EXTABLE(1b, 3b)
30670 - : : "r" (from), "r" (to) : "memory");
30671 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30672
30673 from += 64;
30674 to += 64;
30675 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30676 static void fast_copy_page(void *to, void *from)
30677 {
30678 int i;
30679 + unsigned long cr0;
30680
30681 kernel_fpu_begin();
30682
30683 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30684 * but that is for later. -AV
30685 */
30686 __asm__ __volatile__(
30687 - "1: prefetch (%0)\n"
30688 - " prefetch 64(%0)\n"
30689 - " prefetch 128(%0)\n"
30690 - " prefetch 192(%0)\n"
30691 - " prefetch 256(%0)\n"
30692 + "1: prefetch (%1)\n"
30693 + " prefetch 64(%1)\n"
30694 + " prefetch 128(%1)\n"
30695 + " prefetch 192(%1)\n"
30696 + " prefetch 256(%1)\n"
30697 "2: \n"
30698 ".section .fixup, \"ax\"\n"
30699 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30700 + "3: \n"
30701 +
30702 +#ifdef CONFIG_PAX_KERNEXEC
30703 + " movl %%cr0, %0\n"
30704 + " movl %0, %%eax\n"
30705 + " andl $0xFFFEFFFF, %%eax\n"
30706 + " movl %%eax, %%cr0\n"
30707 +#endif
30708 +
30709 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30710 +
30711 +#ifdef CONFIG_PAX_KERNEXEC
30712 + " movl %0, %%cr0\n"
30713 +#endif
30714 +
30715 " jmp 2b\n"
30716 ".previous\n"
30717 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30718 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30719
30720 for (i = 0; i < (4096-320)/64; i++) {
30721 __asm__ __volatile__ (
30722 - "1: prefetch 320(%0)\n"
30723 - "2: movq (%0), %%mm0\n"
30724 - " movntq %%mm0, (%1)\n"
30725 - " movq 8(%0), %%mm1\n"
30726 - " movntq %%mm1, 8(%1)\n"
30727 - " movq 16(%0), %%mm2\n"
30728 - " movntq %%mm2, 16(%1)\n"
30729 - " movq 24(%0), %%mm3\n"
30730 - " movntq %%mm3, 24(%1)\n"
30731 - " movq 32(%0), %%mm4\n"
30732 - " movntq %%mm4, 32(%1)\n"
30733 - " movq 40(%0), %%mm5\n"
30734 - " movntq %%mm5, 40(%1)\n"
30735 - " movq 48(%0), %%mm6\n"
30736 - " movntq %%mm6, 48(%1)\n"
30737 - " movq 56(%0), %%mm7\n"
30738 - " movntq %%mm7, 56(%1)\n"
30739 + "1: prefetch 320(%1)\n"
30740 + "2: movq (%1), %%mm0\n"
30741 + " movntq %%mm0, (%2)\n"
30742 + " movq 8(%1), %%mm1\n"
30743 + " movntq %%mm1, 8(%2)\n"
30744 + " movq 16(%1), %%mm2\n"
30745 + " movntq %%mm2, 16(%2)\n"
30746 + " movq 24(%1), %%mm3\n"
30747 + " movntq %%mm3, 24(%2)\n"
30748 + " movq 32(%1), %%mm4\n"
30749 + " movntq %%mm4, 32(%2)\n"
30750 + " movq 40(%1), %%mm5\n"
30751 + " movntq %%mm5, 40(%2)\n"
30752 + " movq 48(%1), %%mm6\n"
30753 + " movntq %%mm6, 48(%2)\n"
30754 + " movq 56(%1), %%mm7\n"
30755 + " movntq %%mm7, 56(%2)\n"
30756 ".section .fixup, \"ax\"\n"
30757 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30758 + "3:\n"
30759 +
30760 +#ifdef CONFIG_PAX_KERNEXEC
30761 + " movl %%cr0, %0\n"
30762 + " movl %0, %%eax\n"
30763 + " andl $0xFFFEFFFF, %%eax\n"
30764 + " movl %%eax, %%cr0\n"
30765 +#endif
30766 +
30767 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30768 +
30769 +#ifdef CONFIG_PAX_KERNEXEC
30770 + " movl %0, %%cr0\n"
30771 +#endif
30772 +
30773 " jmp 2b\n"
30774 ".previous\n"
30775 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30776 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30777
30778 from += 64;
30779 to += 64;
30780 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30781 static void fast_copy_page(void *to, void *from)
30782 {
30783 int i;
30784 + unsigned long cr0;
30785
30786 kernel_fpu_begin();
30787
30788 __asm__ __volatile__ (
30789 - "1: prefetch (%0)\n"
30790 - " prefetch 64(%0)\n"
30791 - " prefetch 128(%0)\n"
30792 - " prefetch 192(%0)\n"
30793 - " prefetch 256(%0)\n"
30794 + "1: prefetch (%1)\n"
30795 + " prefetch 64(%1)\n"
30796 + " prefetch 128(%1)\n"
30797 + " prefetch 192(%1)\n"
30798 + " prefetch 256(%1)\n"
30799 "2: \n"
30800 ".section .fixup, \"ax\"\n"
30801 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30802 + "3: \n"
30803 +
30804 +#ifdef CONFIG_PAX_KERNEXEC
30805 + " movl %%cr0, %0\n"
30806 + " movl %0, %%eax\n"
30807 + " andl $0xFFFEFFFF, %%eax\n"
30808 + " movl %%eax, %%cr0\n"
30809 +#endif
30810 +
30811 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30812 +
30813 +#ifdef CONFIG_PAX_KERNEXEC
30814 + " movl %0, %%cr0\n"
30815 +#endif
30816 +
30817 " jmp 2b\n"
30818 ".previous\n"
30819 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30820 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30821
30822 for (i = 0; i < 4096/64; i++) {
30823 __asm__ __volatile__ (
30824 - "1: prefetch 320(%0)\n"
30825 - "2: movq (%0), %%mm0\n"
30826 - " movq 8(%0), %%mm1\n"
30827 - " movq 16(%0), %%mm2\n"
30828 - " movq 24(%0), %%mm3\n"
30829 - " movq %%mm0, (%1)\n"
30830 - " movq %%mm1, 8(%1)\n"
30831 - " movq %%mm2, 16(%1)\n"
30832 - " movq %%mm3, 24(%1)\n"
30833 - " movq 32(%0), %%mm0\n"
30834 - " movq 40(%0), %%mm1\n"
30835 - " movq 48(%0), %%mm2\n"
30836 - " movq 56(%0), %%mm3\n"
30837 - " movq %%mm0, 32(%1)\n"
30838 - " movq %%mm1, 40(%1)\n"
30839 - " movq %%mm2, 48(%1)\n"
30840 - " movq %%mm3, 56(%1)\n"
30841 + "1: prefetch 320(%1)\n"
30842 + "2: movq (%1), %%mm0\n"
30843 + " movq 8(%1), %%mm1\n"
30844 + " movq 16(%1), %%mm2\n"
30845 + " movq 24(%1), %%mm3\n"
30846 + " movq %%mm0, (%2)\n"
30847 + " movq %%mm1, 8(%2)\n"
30848 + " movq %%mm2, 16(%2)\n"
30849 + " movq %%mm3, 24(%2)\n"
30850 + " movq 32(%1), %%mm0\n"
30851 + " movq 40(%1), %%mm1\n"
30852 + " movq 48(%1), %%mm2\n"
30853 + " movq 56(%1), %%mm3\n"
30854 + " movq %%mm0, 32(%2)\n"
30855 + " movq %%mm1, 40(%2)\n"
30856 + " movq %%mm2, 48(%2)\n"
30857 + " movq %%mm3, 56(%2)\n"
30858 ".section .fixup, \"ax\"\n"
30859 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30860 + "3:\n"
30861 +
30862 +#ifdef CONFIG_PAX_KERNEXEC
30863 + " movl %%cr0, %0\n"
30864 + " movl %0, %%eax\n"
30865 + " andl $0xFFFEFFFF, %%eax\n"
30866 + " movl %%eax, %%cr0\n"
30867 +#endif
30868 +
30869 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30870 +
30871 +#ifdef CONFIG_PAX_KERNEXEC
30872 + " movl %0, %%cr0\n"
30873 +#endif
30874 +
30875 " jmp 2b\n"
30876 ".previous\n"
30877 _ASM_EXTABLE(1b, 3b)
30878 - : : "r" (from), "r" (to) : "memory");
30879 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30880
30881 from += 64;
30882 to += 64;
30883 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30884 index f6d13ee..d789440 100644
30885 --- a/arch/x86/lib/msr-reg.S
30886 +++ b/arch/x86/lib/msr-reg.S
30887 @@ -3,6 +3,7 @@
30888 #include <asm/dwarf2.h>
30889 #include <asm/asm.h>
30890 #include <asm/msr.h>
30891 +#include <asm/alternative-asm.h>
30892
30893 #ifdef CONFIG_X86_64
30894 /*
30895 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30896 movl %edi, 28(%r10)
30897 popq_cfi %rbp
30898 popq_cfi %rbx
30899 + pax_force_retaddr
30900 ret
30901 3:
30902 CFI_RESTORE_STATE
30903 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30904 index fc6ba17..d4d989d 100644
30905 --- a/arch/x86/lib/putuser.S
30906 +++ b/arch/x86/lib/putuser.S
30907 @@ -16,7 +16,9 @@
30908 #include <asm/errno.h>
30909 #include <asm/asm.h>
30910 #include <asm/smap.h>
30911 -
30912 +#include <asm/segment.h>
30913 +#include <asm/pgtable.h>
30914 +#include <asm/alternative-asm.h>
30915
30916 /*
30917 * __put_user_X
30918 @@ -30,57 +32,125 @@
30919 * as they get called from within inline assembly.
30920 */
30921
30922 -#define ENTER CFI_STARTPROC ; \
30923 - GET_THREAD_INFO(%_ASM_BX)
30924 -#define EXIT ASM_CLAC ; \
30925 - ret ; \
30926 +#define ENTER CFI_STARTPROC
30927 +#define EXIT ASM_CLAC ; \
30928 + pax_force_retaddr ; \
30929 + ret ; \
30930 CFI_ENDPROC
30931
30932 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30933 +#define _DEST %_ASM_CX,%_ASM_BX
30934 +#else
30935 +#define _DEST %_ASM_CX
30936 +#endif
30937 +
30938 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30939 +#define __copyuser_seg gs;
30940 +#else
30941 +#define __copyuser_seg
30942 +#endif
30943 +
30944 .text
30945 ENTRY(__put_user_1)
30946 ENTER
30947 +
30948 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30949 + GET_THREAD_INFO(%_ASM_BX)
30950 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30951 jae bad_put_user
30952 ASM_STAC
30953 -1: movb %al,(%_ASM_CX)
30954 +
30955 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30956 + mov pax_user_shadow_base,%_ASM_BX
30957 + cmp %_ASM_BX,%_ASM_CX
30958 + jb 1234f
30959 + xor %ebx,%ebx
30960 +1234:
30961 +#endif
30962 +
30963 +#endif
30964 +
30965 +1: __copyuser_seg movb %al,(_DEST)
30966 xor %eax,%eax
30967 EXIT
30968 ENDPROC(__put_user_1)
30969
30970 ENTRY(__put_user_2)
30971 ENTER
30972 +
30973 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30974 + GET_THREAD_INFO(%_ASM_BX)
30975 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30976 sub $1,%_ASM_BX
30977 cmp %_ASM_BX,%_ASM_CX
30978 jae bad_put_user
30979 ASM_STAC
30980 -2: movw %ax,(%_ASM_CX)
30981 +
30982 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30983 + mov pax_user_shadow_base,%_ASM_BX
30984 + cmp %_ASM_BX,%_ASM_CX
30985 + jb 1234f
30986 + xor %ebx,%ebx
30987 +1234:
30988 +#endif
30989 +
30990 +#endif
30991 +
30992 +2: __copyuser_seg movw %ax,(_DEST)
30993 xor %eax,%eax
30994 EXIT
30995 ENDPROC(__put_user_2)
30996
30997 ENTRY(__put_user_4)
30998 ENTER
30999 +
31000 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31001 + GET_THREAD_INFO(%_ASM_BX)
31002 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31003 sub $3,%_ASM_BX
31004 cmp %_ASM_BX,%_ASM_CX
31005 jae bad_put_user
31006 ASM_STAC
31007 -3: movl %eax,(%_ASM_CX)
31008 +
31009 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31010 + mov pax_user_shadow_base,%_ASM_BX
31011 + cmp %_ASM_BX,%_ASM_CX
31012 + jb 1234f
31013 + xor %ebx,%ebx
31014 +1234:
31015 +#endif
31016 +
31017 +#endif
31018 +
31019 +3: __copyuser_seg movl %eax,(_DEST)
31020 xor %eax,%eax
31021 EXIT
31022 ENDPROC(__put_user_4)
31023
31024 ENTRY(__put_user_8)
31025 ENTER
31026 +
31027 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31028 + GET_THREAD_INFO(%_ASM_BX)
31029 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31030 sub $7,%_ASM_BX
31031 cmp %_ASM_BX,%_ASM_CX
31032 jae bad_put_user
31033 ASM_STAC
31034 -4: mov %_ASM_AX,(%_ASM_CX)
31035 +
31036 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31037 + mov pax_user_shadow_base,%_ASM_BX
31038 + cmp %_ASM_BX,%_ASM_CX
31039 + jb 1234f
31040 + xor %ebx,%ebx
31041 +1234:
31042 +#endif
31043 +
31044 +#endif
31045 +
31046 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31047 #ifdef CONFIG_X86_32
31048 -5: movl %edx,4(%_ASM_CX)
31049 +5: __copyuser_seg movl %edx,4(_DEST)
31050 #endif
31051 xor %eax,%eax
31052 EXIT
31053 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31054 index 5dff5f0..cadebf4 100644
31055 --- a/arch/x86/lib/rwsem.S
31056 +++ b/arch/x86/lib/rwsem.S
31057 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31058 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31059 CFI_RESTORE __ASM_REG(dx)
31060 restore_common_regs
31061 + pax_force_retaddr
31062 ret
31063 CFI_ENDPROC
31064 ENDPROC(call_rwsem_down_read_failed)
31065 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31066 movq %rax,%rdi
31067 call rwsem_down_write_failed
31068 restore_common_regs
31069 + pax_force_retaddr
31070 ret
31071 CFI_ENDPROC
31072 ENDPROC(call_rwsem_down_write_failed)
31073 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31074 movq %rax,%rdi
31075 call rwsem_wake
31076 restore_common_regs
31077 -1: ret
31078 +1: pax_force_retaddr
31079 + ret
31080 CFI_ENDPROC
31081 ENDPROC(call_rwsem_wake)
31082
31083 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31084 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31085 CFI_RESTORE __ASM_REG(dx)
31086 restore_common_regs
31087 + pax_force_retaddr
31088 ret
31089 CFI_ENDPROC
31090 ENDPROC(call_rwsem_downgrade_wake)
31091 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31092 index b30b5eb..2b57052 100644
31093 --- a/arch/x86/lib/thunk_64.S
31094 +++ b/arch/x86/lib/thunk_64.S
31095 @@ -9,6 +9,7 @@
31096 #include <asm/dwarf2.h>
31097 #include <asm/calling.h>
31098 #include <asm/asm.h>
31099 +#include <asm/alternative-asm.h>
31100
31101 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31102 .macro THUNK name, func, put_ret_addr_in_rdi=0
31103 @@ -16,11 +17,11 @@
31104 \name:
31105 CFI_STARTPROC
31106
31107 - /* this one pushes 9 elems, the next one would be %rIP */
31108 - SAVE_ARGS
31109 + /* this one pushes 15+1 elems, the next one would be %rIP */
31110 + SAVE_ARGS 8
31111
31112 .if \put_ret_addr_in_rdi
31113 - movq_cfi_restore 9*8, rdi
31114 + movq_cfi_restore RIP, rdi
31115 .endif
31116
31117 call \func
31118 @@ -47,9 +48,10 @@
31119
31120 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31121 CFI_STARTPROC
31122 - SAVE_ARGS
31123 + SAVE_ARGS 8
31124 restore:
31125 - RESTORE_ARGS
31126 + RESTORE_ARGS 1,8
31127 + pax_force_retaddr
31128 ret
31129 CFI_ENDPROC
31130 _ASM_NOKPROBE(restore)
31131 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31132 index e2f5e21..4b22130 100644
31133 --- a/arch/x86/lib/usercopy_32.c
31134 +++ b/arch/x86/lib/usercopy_32.c
31135 @@ -42,11 +42,13 @@ do { \
31136 int __d0; \
31137 might_fault(); \
31138 __asm__ __volatile__( \
31139 + __COPYUSER_SET_ES \
31140 ASM_STAC "\n" \
31141 "0: rep; stosl\n" \
31142 " movl %2,%0\n" \
31143 "1: rep; stosb\n" \
31144 "2: " ASM_CLAC "\n" \
31145 + __COPYUSER_RESTORE_ES \
31146 ".section .fixup,\"ax\"\n" \
31147 "3: lea 0(%2,%0,4),%0\n" \
31148 " jmp 2b\n" \
31149 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31150
31151 #ifdef CONFIG_X86_INTEL_USERCOPY
31152 static unsigned long
31153 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31154 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31155 {
31156 int d0, d1;
31157 __asm__ __volatile__(
31158 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31159 " .align 2,0x90\n"
31160 "3: movl 0(%4), %%eax\n"
31161 "4: movl 4(%4), %%edx\n"
31162 - "5: movl %%eax, 0(%3)\n"
31163 - "6: movl %%edx, 4(%3)\n"
31164 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31165 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31166 "7: movl 8(%4), %%eax\n"
31167 "8: movl 12(%4),%%edx\n"
31168 - "9: movl %%eax, 8(%3)\n"
31169 - "10: movl %%edx, 12(%3)\n"
31170 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31171 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31172 "11: movl 16(%4), %%eax\n"
31173 "12: movl 20(%4), %%edx\n"
31174 - "13: movl %%eax, 16(%3)\n"
31175 - "14: movl %%edx, 20(%3)\n"
31176 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31177 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31178 "15: movl 24(%4), %%eax\n"
31179 "16: movl 28(%4), %%edx\n"
31180 - "17: movl %%eax, 24(%3)\n"
31181 - "18: movl %%edx, 28(%3)\n"
31182 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31183 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31184 "19: movl 32(%4), %%eax\n"
31185 "20: movl 36(%4), %%edx\n"
31186 - "21: movl %%eax, 32(%3)\n"
31187 - "22: movl %%edx, 36(%3)\n"
31188 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31189 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31190 "23: movl 40(%4), %%eax\n"
31191 "24: movl 44(%4), %%edx\n"
31192 - "25: movl %%eax, 40(%3)\n"
31193 - "26: movl %%edx, 44(%3)\n"
31194 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31195 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31196 "27: movl 48(%4), %%eax\n"
31197 "28: movl 52(%4), %%edx\n"
31198 - "29: movl %%eax, 48(%3)\n"
31199 - "30: movl %%edx, 52(%3)\n"
31200 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31201 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31202 "31: movl 56(%4), %%eax\n"
31203 "32: movl 60(%4), %%edx\n"
31204 - "33: movl %%eax, 56(%3)\n"
31205 - "34: movl %%edx, 60(%3)\n"
31206 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31207 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31208 " addl $-64, %0\n"
31209 " addl $64, %4\n"
31210 " addl $64, %3\n"
31211 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31212 " shrl $2, %0\n"
31213 " andl $3, %%eax\n"
31214 " cld\n"
31215 + __COPYUSER_SET_ES
31216 "99: rep; movsl\n"
31217 "36: movl %%eax, %0\n"
31218 "37: rep; movsb\n"
31219 "100:\n"
31220 + __COPYUSER_RESTORE_ES
31221 + ".section .fixup,\"ax\"\n"
31222 + "101: lea 0(%%eax,%0,4),%0\n"
31223 + " jmp 100b\n"
31224 + ".previous\n"
31225 + _ASM_EXTABLE(1b,100b)
31226 + _ASM_EXTABLE(2b,100b)
31227 + _ASM_EXTABLE(3b,100b)
31228 + _ASM_EXTABLE(4b,100b)
31229 + _ASM_EXTABLE(5b,100b)
31230 + _ASM_EXTABLE(6b,100b)
31231 + _ASM_EXTABLE(7b,100b)
31232 + _ASM_EXTABLE(8b,100b)
31233 + _ASM_EXTABLE(9b,100b)
31234 + _ASM_EXTABLE(10b,100b)
31235 + _ASM_EXTABLE(11b,100b)
31236 + _ASM_EXTABLE(12b,100b)
31237 + _ASM_EXTABLE(13b,100b)
31238 + _ASM_EXTABLE(14b,100b)
31239 + _ASM_EXTABLE(15b,100b)
31240 + _ASM_EXTABLE(16b,100b)
31241 + _ASM_EXTABLE(17b,100b)
31242 + _ASM_EXTABLE(18b,100b)
31243 + _ASM_EXTABLE(19b,100b)
31244 + _ASM_EXTABLE(20b,100b)
31245 + _ASM_EXTABLE(21b,100b)
31246 + _ASM_EXTABLE(22b,100b)
31247 + _ASM_EXTABLE(23b,100b)
31248 + _ASM_EXTABLE(24b,100b)
31249 + _ASM_EXTABLE(25b,100b)
31250 + _ASM_EXTABLE(26b,100b)
31251 + _ASM_EXTABLE(27b,100b)
31252 + _ASM_EXTABLE(28b,100b)
31253 + _ASM_EXTABLE(29b,100b)
31254 + _ASM_EXTABLE(30b,100b)
31255 + _ASM_EXTABLE(31b,100b)
31256 + _ASM_EXTABLE(32b,100b)
31257 + _ASM_EXTABLE(33b,100b)
31258 + _ASM_EXTABLE(34b,100b)
31259 + _ASM_EXTABLE(35b,100b)
31260 + _ASM_EXTABLE(36b,100b)
31261 + _ASM_EXTABLE(37b,100b)
31262 + _ASM_EXTABLE(99b,101b)
31263 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31264 + : "1"(to), "2"(from), "0"(size)
31265 + : "eax", "edx", "memory");
31266 + return size;
31267 +}
31268 +
31269 +static unsigned long
31270 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31271 +{
31272 + int d0, d1;
31273 + __asm__ __volatile__(
31274 + " .align 2,0x90\n"
31275 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31276 + " cmpl $67, %0\n"
31277 + " jbe 3f\n"
31278 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31279 + " .align 2,0x90\n"
31280 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31281 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31282 + "5: movl %%eax, 0(%3)\n"
31283 + "6: movl %%edx, 4(%3)\n"
31284 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31285 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31286 + "9: movl %%eax, 8(%3)\n"
31287 + "10: movl %%edx, 12(%3)\n"
31288 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31289 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31290 + "13: movl %%eax, 16(%3)\n"
31291 + "14: movl %%edx, 20(%3)\n"
31292 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31293 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31294 + "17: movl %%eax, 24(%3)\n"
31295 + "18: movl %%edx, 28(%3)\n"
31296 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31297 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31298 + "21: movl %%eax, 32(%3)\n"
31299 + "22: movl %%edx, 36(%3)\n"
31300 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31301 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31302 + "25: movl %%eax, 40(%3)\n"
31303 + "26: movl %%edx, 44(%3)\n"
31304 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31305 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31306 + "29: movl %%eax, 48(%3)\n"
31307 + "30: movl %%edx, 52(%3)\n"
31308 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31309 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31310 + "33: movl %%eax, 56(%3)\n"
31311 + "34: movl %%edx, 60(%3)\n"
31312 + " addl $-64, %0\n"
31313 + " addl $64, %4\n"
31314 + " addl $64, %3\n"
31315 + " cmpl $63, %0\n"
31316 + " ja 1b\n"
31317 + "35: movl %0, %%eax\n"
31318 + " shrl $2, %0\n"
31319 + " andl $3, %%eax\n"
31320 + " cld\n"
31321 + "99: rep; "__copyuser_seg" movsl\n"
31322 + "36: movl %%eax, %0\n"
31323 + "37: rep; "__copyuser_seg" movsb\n"
31324 + "100:\n"
31325 ".section .fixup,\"ax\"\n"
31326 "101: lea 0(%%eax,%0,4),%0\n"
31327 " jmp 100b\n"
31328 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31329 int d0, d1;
31330 __asm__ __volatile__(
31331 " .align 2,0x90\n"
31332 - "0: movl 32(%4), %%eax\n"
31333 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31334 " cmpl $67, %0\n"
31335 " jbe 2f\n"
31336 - "1: movl 64(%4), %%eax\n"
31337 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31338 " .align 2,0x90\n"
31339 - "2: movl 0(%4), %%eax\n"
31340 - "21: movl 4(%4), %%edx\n"
31341 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31342 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31343 " movl %%eax, 0(%3)\n"
31344 " movl %%edx, 4(%3)\n"
31345 - "3: movl 8(%4), %%eax\n"
31346 - "31: movl 12(%4),%%edx\n"
31347 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31348 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31349 " movl %%eax, 8(%3)\n"
31350 " movl %%edx, 12(%3)\n"
31351 - "4: movl 16(%4), %%eax\n"
31352 - "41: movl 20(%4), %%edx\n"
31353 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31354 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31355 " movl %%eax, 16(%3)\n"
31356 " movl %%edx, 20(%3)\n"
31357 - "10: movl 24(%4), %%eax\n"
31358 - "51: movl 28(%4), %%edx\n"
31359 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31360 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31361 " movl %%eax, 24(%3)\n"
31362 " movl %%edx, 28(%3)\n"
31363 - "11: movl 32(%4), %%eax\n"
31364 - "61: movl 36(%4), %%edx\n"
31365 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31366 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31367 " movl %%eax, 32(%3)\n"
31368 " movl %%edx, 36(%3)\n"
31369 - "12: movl 40(%4), %%eax\n"
31370 - "71: movl 44(%4), %%edx\n"
31371 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31372 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31373 " movl %%eax, 40(%3)\n"
31374 " movl %%edx, 44(%3)\n"
31375 - "13: movl 48(%4), %%eax\n"
31376 - "81: movl 52(%4), %%edx\n"
31377 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31378 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31379 " movl %%eax, 48(%3)\n"
31380 " movl %%edx, 52(%3)\n"
31381 - "14: movl 56(%4), %%eax\n"
31382 - "91: movl 60(%4), %%edx\n"
31383 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31384 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31385 " movl %%eax, 56(%3)\n"
31386 " movl %%edx, 60(%3)\n"
31387 " addl $-64, %0\n"
31388 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31389 " shrl $2, %0\n"
31390 " andl $3, %%eax\n"
31391 " cld\n"
31392 - "6: rep; movsl\n"
31393 + "6: rep; "__copyuser_seg" movsl\n"
31394 " movl %%eax,%0\n"
31395 - "7: rep; movsb\n"
31396 + "7: rep; "__copyuser_seg" movsb\n"
31397 "8:\n"
31398 ".section .fixup,\"ax\"\n"
31399 "9: lea 0(%%eax,%0,4),%0\n"
31400 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31401
31402 __asm__ __volatile__(
31403 " .align 2,0x90\n"
31404 - "0: movl 32(%4), %%eax\n"
31405 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31406 " cmpl $67, %0\n"
31407 " jbe 2f\n"
31408 - "1: movl 64(%4), %%eax\n"
31409 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31410 " .align 2,0x90\n"
31411 - "2: movl 0(%4), %%eax\n"
31412 - "21: movl 4(%4), %%edx\n"
31413 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31414 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31415 " movnti %%eax, 0(%3)\n"
31416 " movnti %%edx, 4(%3)\n"
31417 - "3: movl 8(%4), %%eax\n"
31418 - "31: movl 12(%4),%%edx\n"
31419 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31420 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31421 " movnti %%eax, 8(%3)\n"
31422 " movnti %%edx, 12(%3)\n"
31423 - "4: movl 16(%4), %%eax\n"
31424 - "41: movl 20(%4), %%edx\n"
31425 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31426 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31427 " movnti %%eax, 16(%3)\n"
31428 " movnti %%edx, 20(%3)\n"
31429 - "10: movl 24(%4), %%eax\n"
31430 - "51: movl 28(%4), %%edx\n"
31431 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31432 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31433 " movnti %%eax, 24(%3)\n"
31434 " movnti %%edx, 28(%3)\n"
31435 - "11: movl 32(%4), %%eax\n"
31436 - "61: movl 36(%4), %%edx\n"
31437 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31438 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31439 " movnti %%eax, 32(%3)\n"
31440 " movnti %%edx, 36(%3)\n"
31441 - "12: movl 40(%4), %%eax\n"
31442 - "71: movl 44(%4), %%edx\n"
31443 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31444 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31445 " movnti %%eax, 40(%3)\n"
31446 " movnti %%edx, 44(%3)\n"
31447 - "13: movl 48(%4), %%eax\n"
31448 - "81: movl 52(%4), %%edx\n"
31449 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31450 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31451 " movnti %%eax, 48(%3)\n"
31452 " movnti %%edx, 52(%3)\n"
31453 - "14: movl 56(%4), %%eax\n"
31454 - "91: movl 60(%4), %%edx\n"
31455 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31456 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31457 " movnti %%eax, 56(%3)\n"
31458 " movnti %%edx, 60(%3)\n"
31459 " addl $-64, %0\n"
31460 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31461 " shrl $2, %0\n"
31462 " andl $3, %%eax\n"
31463 " cld\n"
31464 - "6: rep; movsl\n"
31465 + "6: rep; "__copyuser_seg" movsl\n"
31466 " movl %%eax,%0\n"
31467 - "7: rep; movsb\n"
31468 + "7: rep; "__copyuser_seg" movsb\n"
31469 "8:\n"
31470 ".section .fixup,\"ax\"\n"
31471 "9: lea 0(%%eax,%0,4),%0\n"
31472 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31473
31474 __asm__ __volatile__(
31475 " .align 2,0x90\n"
31476 - "0: movl 32(%4), %%eax\n"
31477 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31478 " cmpl $67, %0\n"
31479 " jbe 2f\n"
31480 - "1: movl 64(%4), %%eax\n"
31481 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31482 " .align 2,0x90\n"
31483 - "2: movl 0(%4), %%eax\n"
31484 - "21: movl 4(%4), %%edx\n"
31485 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31486 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31487 " movnti %%eax, 0(%3)\n"
31488 " movnti %%edx, 4(%3)\n"
31489 - "3: movl 8(%4), %%eax\n"
31490 - "31: movl 12(%4),%%edx\n"
31491 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31492 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31493 " movnti %%eax, 8(%3)\n"
31494 " movnti %%edx, 12(%3)\n"
31495 - "4: movl 16(%4), %%eax\n"
31496 - "41: movl 20(%4), %%edx\n"
31497 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31498 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31499 " movnti %%eax, 16(%3)\n"
31500 " movnti %%edx, 20(%3)\n"
31501 - "10: movl 24(%4), %%eax\n"
31502 - "51: movl 28(%4), %%edx\n"
31503 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31504 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31505 " movnti %%eax, 24(%3)\n"
31506 " movnti %%edx, 28(%3)\n"
31507 - "11: movl 32(%4), %%eax\n"
31508 - "61: movl 36(%4), %%edx\n"
31509 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31510 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31511 " movnti %%eax, 32(%3)\n"
31512 " movnti %%edx, 36(%3)\n"
31513 - "12: movl 40(%4), %%eax\n"
31514 - "71: movl 44(%4), %%edx\n"
31515 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31516 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31517 " movnti %%eax, 40(%3)\n"
31518 " movnti %%edx, 44(%3)\n"
31519 - "13: movl 48(%4), %%eax\n"
31520 - "81: movl 52(%4), %%edx\n"
31521 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31522 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31523 " movnti %%eax, 48(%3)\n"
31524 " movnti %%edx, 52(%3)\n"
31525 - "14: movl 56(%4), %%eax\n"
31526 - "91: movl 60(%4), %%edx\n"
31527 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31528 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31529 " movnti %%eax, 56(%3)\n"
31530 " movnti %%edx, 60(%3)\n"
31531 " addl $-64, %0\n"
31532 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31533 " shrl $2, %0\n"
31534 " andl $3, %%eax\n"
31535 " cld\n"
31536 - "6: rep; movsl\n"
31537 + "6: rep; "__copyuser_seg" movsl\n"
31538 " movl %%eax,%0\n"
31539 - "7: rep; movsb\n"
31540 + "7: rep; "__copyuser_seg" movsb\n"
31541 "8:\n"
31542 ".section .fixup,\"ax\"\n"
31543 "9: lea 0(%%eax,%0,4),%0\n"
31544 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31545 */
31546 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31547 unsigned long size);
31548 -unsigned long __copy_user_intel(void __user *to, const void *from,
31549 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31550 + unsigned long size);
31551 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31552 unsigned long size);
31553 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31554 const void __user *from, unsigned long size);
31555 #endif /* CONFIG_X86_INTEL_USERCOPY */
31556
31557 /* Generic arbitrary sized copy. */
31558 -#define __copy_user(to, from, size) \
31559 +#define __copy_user(to, from, size, prefix, set, restore) \
31560 do { \
31561 int __d0, __d1, __d2; \
31562 __asm__ __volatile__( \
31563 + set \
31564 " cmp $7,%0\n" \
31565 " jbe 1f\n" \
31566 " movl %1,%0\n" \
31567 " negl %0\n" \
31568 " andl $7,%0\n" \
31569 " subl %0,%3\n" \
31570 - "4: rep; movsb\n" \
31571 + "4: rep; "prefix"movsb\n" \
31572 " movl %3,%0\n" \
31573 " shrl $2,%0\n" \
31574 " andl $3,%3\n" \
31575 " .align 2,0x90\n" \
31576 - "0: rep; movsl\n" \
31577 + "0: rep; "prefix"movsl\n" \
31578 " movl %3,%0\n" \
31579 - "1: rep; movsb\n" \
31580 + "1: rep; "prefix"movsb\n" \
31581 "2:\n" \
31582 + restore \
31583 ".section .fixup,\"ax\"\n" \
31584 "5: addl %3,%0\n" \
31585 " jmp 2b\n" \
31586 @@ -538,14 +650,14 @@ do { \
31587 " negl %0\n" \
31588 " andl $7,%0\n" \
31589 " subl %0,%3\n" \
31590 - "4: rep; movsb\n" \
31591 + "4: rep; "__copyuser_seg"movsb\n" \
31592 " movl %3,%0\n" \
31593 " shrl $2,%0\n" \
31594 " andl $3,%3\n" \
31595 " .align 2,0x90\n" \
31596 - "0: rep; movsl\n" \
31597 + "0: rep; "__copyuser_seg"movsl\n" \
31598 " movl %3,%0\n" \
31599 - "1: rep; movsb\n" \
31600 + "1: rep; "__copyuser_seg"movsb\n" \
31601 "2:\n" \
31602 ".section .fixup,\"ax\"\n" \
31603 "5: addl %3,%0\n" \
31604 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31605 {
31606 stac();
31607 if (movsl_is_ok(to, from, n))
31608 - __copy_user(to, from, n);
31609 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31610 else
31611 - n = __copy_user_intel(to, from, n);
31612 + n = __generic_copy_to_user_intel(to, from, n);
31613 clac();
31614 return n;
31615 }
31616 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31617 {
31618 stac();
31619 if (movsl_is_ok(to, from, n))
31620 - __copy_user(to, from, n);
31621 + __copy_user(to, from, n, __copyuser_seg, "", "");
31622 else
31623 - n = __copy_user_intel((void __user *)to,
31624 - (const void *)from, n);
31625 + n = __generic_copy_from_user_intel(to, from, n);
31626 clac();
31627 return n;
31628 }
31629 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31630 if (n > 64 && cpu_has_xmm2)
31631 n = __copy_user_intel_nocache(to, from, n);
31632 else
31633 - __copy_user(to, from, n);
31634 + __copy_user(to, from, n, __copyuser_seg, "", "");
31635 #else
31636 - __copy_user(to, from, n);
31637 + __copy_user(to, from, n, __copyuser_seg, "", "");
31638 #endif
31639 clac();
31640 return n;
31641 }
31642 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31643
31644 -/**
31645 - * copy_to_user: - Copy a block of data into user space.
31646 - * @to: Destination address, in user space.
31647 - * @from: Source address, in kernel space.
31648 - * @n: Number of bytes to copy.
31649 - *
31650 - * Context: User context only. This function may sleep.
31651 - *
31652 - * Copy data from kernel space to user space.
31653 - *
31654 - * Returns number of bytes that could not be copied.
31655 - * On success, this will be zero.
31656 - */
31657 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31659 +void __set_fs(mm_segment_t x)
31660 {
31661 - if (access_ok(VERIFY_WRITE, to, n))
31662 - n = __copy_to_user(to, from, n);
31663 - return n;
31664 + switch (x.seg) {
31665 + case 0:
31666 + loadsegment(gs, 0);
31667 + break;
31668 + case TASK_SIZE_MAX:
31669 + loadsegment(gs, __USER_DS);
31670 + break;
31671 + case -1UL:
31672 + loadsegment(gs, __KERNEL_DS);
31673 + break;
31674 + default:
31675 + BUG();
31676 + }
31677 }
31678 -EXPORT_SYMBOL(_copy_to_user);
31679 +EXPORT_SYMBOL(__set_fs);
31680
31681 -/**
31682 - * copy_from_user: - Copy a block of data from user space.
31683 - * @to: Destination address, in kernel space.
31684 - * @from: Source address, in user space.
31685 - * @n: Number of bytes to copy.
31686 - *
31687 - * Context: User context only. This function may sleep.
31688 - *
31689 - * Copy data from user space to kernel space.
31690 - *
31691 - * Returns number of bytes that could not be copied.
31692 - * On success, this will be zero.
31693 - *
31694 - * If some data could not be copied, this function will pad the copied
31695 - * data to the requested size using zero bytes.
31696 - */
31697 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31698 +void set_fs(mm_segment_t x)
31699 {
31700 - if (access_ok(VERIFY_READ, from, n))
31701 - n = __copy_from_user(to, from, n);
31702 - else
31703 - memset(to, 0, n);
31704 - return n;
31705 + current_thread_info()->addr_limit = x;
31706 + __set_fs(x);
31707 }
31708 -EXPORT_SYMBOL(_copy_from_user);
31709 +EXPORT_SYMBOL(set_fs);
31710 +#endif
31711 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31712 index c905e89..01ab928 100644
31713 --- a/arch/x86/lib/usercopy_64.c
31714 +++ b/arch/x86/lib/usercopy_64.c
31715 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31716 might_fault();
31717 /* no memory constraint because it doesn't change any memory gcc knows
31718 about */
31719 + pax_open_userland();
31720 stac();
31721 asm volatile(
31722 " testq %[size8],%[size8]\n"
31723 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31724 _ASM_EXTABLE(0b,3b)
31725 _ASM_EXTABLE(1b,2b)
31726 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31727 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31728 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31729 [zero] "r" (0UL), [eight] "r" (8UL));
31730 clac();
31731 + pax_close_userland();
31732 return size;
31733 }
31734 EXPORT_SYMBOL(__clear_user);
31735 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31736 }
31737 EXPORT_SYMBOL(clear_user);
31738
31739 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31740 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31741 {
31742 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31743 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31744 - }
31745 - return len;
31746 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31747 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31748 + return len;
31749 }
31750 EXPORT_SYMBOL(copy_in_user);
31751
31752 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31753 * it is not necessary to optimize tail handling.
31754 */
31755 __visible unsigned long
31756 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31757 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31758 {
31759 char c;
31760 unsigned zero_len;
31761
31762 + clac();
31763 + pax_close_userland();
31764 for (; len; --len, to++) {
31765 if (__get_user_nocheck(c, from++, sizeof(char)))
31766 break;
31767 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31768 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31769 if (__put_user_nocheck(c, to++, sizeof(char)))
31770 break;
31771 - clac();
31772 return len;
31773 }
31774 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31775 index 6a19ad9..1c48f9a 100644
31776 --- a/arch/x86/mm/Makefile
31777 +++ b/arch/x86/mm/Makefile
31778 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31779 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31780
31781 obj-$(CONFIG_MEMTEST) += memtest.o
31782 +
31783 +quote:="
31784 +obj-$(CONFIG_X86_64) += uderef_64.o
31785 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31786 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31787 index 903ec1e..c4166b2 100644
31788 --- a/arch/x86/mm/extable.c
31789 +++ b/arch/x86/mm/extable.c
31790 @@ -6,12 +6,24 @@
31791 static inline unsigned long
31792 ex_insn_addr(const struct exception_table_entry *x)
31793 {
31794 - return (unsigned long)&x->insn + x->insn;
31795 + unsigned long reloc = 0;
31796 +
31797 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31798 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31799 +#endif
31800 +
31801 + return (unsigned long)&x->insn + x->insn + reloc;
31802 }
31803 static inline unsigned long
31804 ex_fixup_addr(const struct exception_table_entry *x)
31805 {
31806 - return (unsigned long)&x->fixup + x->fixup;
31807 + unsigned long reloc = 0;
31808 +
31809 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31810 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31811 +#endif
31812 +
31813 + return (unsigned long)&x->fixup + x->fixup + reloc;
31814 }
31815
31816 int fixup_exception(struct pt_regs *regs)
31817 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31818 unsigned long new_ip;
31819
31820 #ifdef CONFIG_PNPBIOS
31821 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31822 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31823 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31824 extern u32 pnp_bios_is_utter_crap;
31825 pnp_bios_is_utter_crap = 1;
31826 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31827 i += 4;
31828 p->fixup -= i;
31829 i += 4;
31830 +
31831 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31832 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31833 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31834 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31835 +#endif
31836 +
31837 }
31838 }
31839
31840 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31841 index d973e61..fb868e9 100644
31842 --- a/arch/x86/mm/fault.c
31843 +++ b/arch/x86/mm/fault.c
31844 @@ -13,12 +13,19 @@
31845 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31846 #include <linux/prefetch.h> /* prefetchw */
31847 #include <linux/context_tracking.h> /* exception_enter(), ... */
31848 +#include <linux/unistd.h>
31849 +#include <linux/compiler.h>
31850
31851 #include <asm/traps.h> /* dotraplinkage, ... */
31852 #include <asm/pgalloc.h> /* pgd_*(), ... */
31853 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31854 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31855 #include <asm/vsyscall.h> /* emulate_vsyscall */
31856 +#include <asm/tlbflush.h>
31857 +
31858 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31859 +#include <asm/stacktrace.h>
31860 +#endif
31861
31862 #define CREATE_TRACE_POINTS
31863 #include <asm/trace/exceptions.h>
31864 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31865 int ret = 0;
31866
31867 /* kprobe_running() needs smp_processor_id() */
31868 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31869 + if (kprobes_built_in() && !user_mode(regs)) {
31870 preempt_disable();
31871 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31872 ret = 1;
31873 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31874 return !instr_lo || (instr_lo>>1) == 1;
31875 case 0x00:
31876 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31877 - if (probe_kernel_address(instr, opcode))
31878 + if (user_mode(regs)) {
31879 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31880 + return 0;
31881 + } else if (probe_kernel_address(instr, opcode))
31882 return 0;
31883
31884 *prefetch = (instr_lo == 0xF) &&
31885 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31886 while (instr < max_instr) {
31887 unsigned char opcode;
31888
31889 - if (probe_kernel_address(instr, opcode))
31890 + if (user_mode(regs)) {
31891 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31892 + break;
31893 + } else if (probe_kernel_address(instr, opcode))
31894 break;
31895
31896 instr++;
31897 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31898 force_sig_info(si_signo, &info, tsk);
31899 }
31900
31901 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31902 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31903 +#endif
31904 +
31905 +#ifdef CONFIG_PAX_EMUTRAMP
31906 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31907 +#endif
31908 +
31909 +#ifdef CONFIG_PAX_PAGEEXEC
31910 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31911 +{
31912 + pgd_t *pgd;
31913 + pud_t *pud;
31914 + pmd_t *pmd;
31915 +
31916 + pgd = pgd_offset(mm, address);
31917 + if (!pgd_present(*pgd))
31918 + return NULL;
31919 + pud = pud_offset(pgd, address);
31920 + if (!pud_present(*pud))
31921 + return NULL;
31922 + pmd = pmd_offset(pud, address);
31923 + if (!pmd_present(*pmd))
31924 + return NULL;
31925 + return pmd;
31926 +}
31927 +#endif
31928 +
31929 DEFINE_SPINLOCK(pgd_lock);
31930 LIST_HEAD(pgd_list);
31931
31932 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31933 for (address = VMALLOC_START & PMD_MASK;
31934 address >= TASK_SIZE && address < FIXADDR_TOP;
31935 address += PMD_SIZE) {
31936 +
31937 +#ifdef CONFIG_PAX_PER_CPU_PGD
31938 + unsigned long cpu;
31939 +#else
31940 struct page *page;
31941 +#endif
31942
31943 spin_lock(&pgd_lock);
31944 +
31945 +#ifdef CONFIG_PAX_PER_CPU_PGD
31946 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31947 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31948 + pmd_t *ret;
31949 +
31950 + ret = vmalloc_sync_one(pgd, address);
31951 + if (!ret)
31952 + break;
31953 + pgd = get_cpu_pgd(cpu, kernel);
31954 +#else
31955 list_for_each_entry(page, &pgd_list, lru) {
31956 + pgd_t *pgd;
31957 spinlock_t *pgt_lock;
31958 pmd_t *ret;
31959
31960 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31961 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31962
31963 spin_lock(pgt_lock);
31964 - ret = vmalloc_sync_one(page_address(page), address);
31965 + pgd = page_address(page);
31966 +#endif
31967 +
31968 + ret = vmalloc_sync_one(pgd, address);
31969 +
31970 +#ifndef CONFIG_PAX_PER_CPU_PGD
31971 spin_unlock(pgt_lock);
31972 +#endif
31973
31974 if (!ret)
31975 break;
31976 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31977 * an interrupt in the middle of a task switch..
31978 */
31979 pgd_paddr = read_cr3();
31980 +
31981 +#ifdef CONFIG_PAX_PER_CPU_PGD
31982 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31983 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31984 +#endif
31985 +
31986 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31987 if (!pmd_k)
31988 return -1;
31989 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31990 * happen within a race in page table update. In the later
31991 * case just flush:
31992 */
31993 - pgd = pgd_offset(current->active_mm, address);
31994 +
31995 pgd_ref = pgd_offset_k(address);
31996 if (pgd_none(*pgd_ref))
31997 return -1;
31998
31999 +#ifdef CONFIG_PAX_PER_CPU_PGD
32000 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32001 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32002 + if (pgd_none(*pgd)) {
32003 + set_pgd(pgd, *pgd_ref);
32004 + arch_flush_lazy_mmu_mode();
32005 + } else {
32006 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32007 + }
32008 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32009 +#else
32010 + pgd = pgd_offset(current->active_mm, address);
32011 +#endif
32012 +
32013 if (pgd_none(*pgd)) {
32014 set_pgd(pgd, *pgd_ref);
32015 arch_flush_lazy_mmu_mode();
32016 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32017 static int is_errata100(struct pt_regs *regs, unsigned long address)
32018 {
32019 #ifdef CONFIG_X86_64
32020 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32021 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32022 return 1;
32023 #endif
32024 return 0;
32025 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32026 }
32027
32028 static const char nx_warning[] = KERN_CRIT
32029 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32030 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32031 static const char smep_warning[] = KERN_CRIT
32032 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32033 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32034
32035 static void
32036 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32037 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32038 if (!oops_may_print())
32039 return;
32040
32041 - if (error_code & PF_INSTR) {
32042 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32043 unsigned int level;
32044 pgd_t *pgd;
32045 pte_t *pte;
32046 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32047 pte = lookup_address_in_pgd(pgd, address, &level);
32048
32049 if (pte && pte_present(*pte) && !pte_exec(*pte))
32050 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32051 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32052 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32053 (pgd_flags(*pgd) & _PAGE_USER) &&
32054 (read_cr4() & X86_CR4_SMEP))
32055 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32056 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32057 }
32058
32059 +#ifdef CONFIG_PAX_KERNEXEC
32060 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32061 + if (current->signal->curr_ip)
32062 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32063 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32064 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32065 + else
32066 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32067 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32068 + }
32069 +#endif
32070 +
32071 printk(KERN_ALERT "BUG: unable to handle kernel ");
32072 if (address < PAGE_SIZE)
32073 printk(KERN_CONT "NULL pointer dereference");
32074 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32075 return;
32076 }
32077 #endif
32078 +
32079 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32080 + if (pax_is_fetch_fault(regs, error_code, address)) {
32081 +
32082 +#ifdef CONFIG_PAX_EMUTRAMP
32083 + switch (pax_handle_fetch_fault(regs)) {
32084 + case 2:
32085 + return;
32086 + }
32087 +#endif
32088 +
32089 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32090 + do_group_exit(SIGKILL);
32091 + }
32092 +#endif
32093 +
32094 /* Kernel addresses are always protection faults: */
32095 if (address >= TASK_SIZE)
32096 error_code |= PF_PROT;
32097 @@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32098 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32099 printk(KERN_ERR
32100 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32101 - tsk->comm, tsk->pid, address);
32102 + tsk->comm, task_pid_nr(tsk), address);
32103 code = BUS_MCEERR_AR;
32104 }
32105 #endif
32106 @@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32107 return 1;
32108 }
32109
32110 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32111 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32112 +{
32113 + pte_t *pte;
32114 + pmd_t *pmd;
32115 + spinlock_t *ptl;
32116 + unsigned char pte_mask;
32117 +
32118 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32119 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32120 + return 0;
32121 +
32122 + /* PaX: it's our fault, let's handle it if we can */
32123 +
32124 + /* PaX: take a look at read faults before acquiring any locks */
32125 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32126 + /* instruction fetch attempt from a protected page in user mode */
32127 + up_read(&mm->mmap_sem);
32128 +
32129 +#ifdef CONFIG_PAX_EMUTRAMP
32130 + switch (pax_handle_fetch_fault(regs)) {
32131 + case 2:
32132 + return 1;
32133 + }
32134 +#endif
32135 +
32136 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32137 + do_group_exit(SIGKILL);
32138 + }
32139 +
32140 + pmd = pax_get_pmd(mm, address);
32141 + if (unlikely(!pmd))
32142 + return 0;
32143 +
32144 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32145 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32146 + pte_unmap_unlock(pte, ptl);
32147 + return 0;
32148 + }
32149 +
32150 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32151 + /* write attempt to a protected page in user mode */
32152 + pte_unmap_unlock(pte, ptl);
32153 + return 0;
32154 + }
32155 +
32156 +#ifdef CONFIG_SMP
32157 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32158 +#else
32159 + if (likely(address > get_limit(regs->cs)))
32160 +#endif
32161 + {
32162 + set_pte(pte, pte_mkread(*pte));
32163 + __flush_tlb_one(address);
32164 + pte_unmap_unlock(pte, ptl);
32165 + up_read(&mm->mmap_sem);
32166 + return 1;
32167 + }
32168 +
32169 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32170 +
32171 + /*
32172 + * PaX: fill DTLB with user rights and retry
32173 + */
32174 + __asm__ __volatile__ (
32175 + "orb %2,(%1)\n"
32176 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32177 +/*
32178 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32179 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32180 + * page fault when examined during a TLB load attempt. this is true not only
32181 + * for PTEs holding a non-present entry but also present entries that will
32182 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32183 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32184 + * for our target pages since their PTEs are simply not in the TLBs at all.
32185 +
32186 + * the best thing in omitting it is that we gain around 15-20% speed in the
32187 + * fast path of the page fault handler and can get rid of tracing since we
32188 + * can no longer flush unintended entries.
32189 + */
32190 + "invlpg (%0)\n"
32191 +#endif
32192 + __copyuser_seg"testb $0,(%0)\n"
32193 + "xorb %3,(%1)\n"
32194 + :
32195 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32196 + : "memory", "cc");
32197 + pte_unmap_unlock(pte, ptl);
32198 + up_read(&mm->mmap_sem);
32199 + return 1;
32200 +}
32201 +#endif
32202 +
32203 /*
32204 * Handle a spurious fault caused by a stale TLB entry.
32205 *
32206 @@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32207 static inline int
32208 access_error(unsigned long error_code, struct vm_area_struct *vma)
32209 {
32210 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32211 + return 1;
32212 +
32213 if (error_code & PF_WRITE) {
32214 /* write, present and write, not present: */
32215 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32216 @@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32217 if (error_code & PF_USER)
32218 return false;
32219
32220 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32221 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32222 return false;
32223
32224 return true;
32225 @@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32226 tsk = current;
32227 mm = tsk->mm;
32228
32229 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32230 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32231 + if (!search_exception_tables(regs->ip)) {
32232 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32233 + bad_area_nosemaphore(regs, error_code, address);
32234 + return;
32235 + }
32236 + if (address < pax_user_shadow_base) {
32237 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32238 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32239 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32240 + } else
32241 + address -= pax_user_shadow_base;
32242 + }
32243 +#endif
32244 +
32245 /*
32246 * Detect and handle instructions that would cause a page fault for
32247 * both a tracked kernel page and a userspace page.
32248 @@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32249 * User-mode registers count as a user access even for any
32250 * potential system fault or CPU buglet:
32251 */
32252 - if (user_mode_vm(regs)) {
32253 + if (user_mode(regs)) {
32254 local_irq_enable();
32255 error_code |= PF_USER;
32256 flags |= FAULT_FLAG_USER;
32257 @@ -1192,6 +1416,11 @@ retry:
32258 might_sleep();
32259 }
32260
32261 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32262 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32263 + return;
32264 +#endif
32265 +
32266 vma = find_vma(mm, address);
32267 if (unlikely(!vma)) {
32268 bad_area(regs, error_code, address);
32269 @@ -1203,18 +1432,24 @@ retry:
32270 bad_area(regs, error_code, address);
32271 return;
32272 }
32273 - if (error_code & PF_USER) {
32274 - /*
32275 - * Accessing the stack below %sp is always a bug.
32276 - * The large cushion allows instructions like enter
32277 - * and pusha to work. ("enter $65535, $31" pushes
32278 - * 32 pointers and then decrements %sp by 65535.)
32279 - */
32280 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32281 - bad_area(regs, error_code, address);
32282 - return;
32283 - }
32284 + /*
32285 + * Accessing the stack below %sp is always a bug.
32286 + * The large cushion allows instructions like enter
32287 + * and pusha to work. ("enter $65535, $31" pushes
32288 + * 32 pointers and then decrements %sp by 65535.)
32289 + */
32290 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32291 + bad_area(regs, error_code, address);
32292 + return;
32293 }
32294 +
32295 +#ifdef CONFIG_PAX_SEGMEXEC
32296 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32297 + bad_area(regs, error_code, address);
32298 + return;
32299 + }
32300 +#endif
32301 +
32302 if (unlikely(expand_stack(vma, address))) {
32303 bad_area(regs, error_code, address);
32304 return;
32305 @@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32306 }
32307 NOKPROBE_SYMBOL(trace_do_page_fault);
32308 #endif /* CONFIG_TRACING */
32309 +
32310 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32311 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32312 +{
32313 + struct mm_struct *mm = current->mm;
32314 + unsigned long ip = regs->ip;
32315 +
32316 + if (v8086_mode(regs))
32317 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32318 +
32319 +#ifdef CONFIG_PAX_PAGEEXEC
32320 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32321 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32322 + return true;
32323 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32324 + return true;
32325 + return false;
32326 + }
32327 +#endif
32328 +
32329 +#ifdef CONFIG_PAX_SEGMEXEC
32330 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32331 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32332 + return true;
32333 + return false;
32334 + }
32335 +#endif
32336 +
32337 + return false;
32338 +}
32339 +#endif
32340 +
32341 +#ifdef CONFIG_PAX_EMUTRAMP
32342 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32343 +{
32344 + int err;
32345 +
32346 + do { /* PaX: libffi trampoline emulation */
32347 + unsigned char mov, jmp;
32348 + unsigned int addr1, addr2;
32349 +
32350 +#ifdef CONFIG_X86_64
32351 + if ((regs->ip + 9) >> 32)
32352 + break;
32353 +#endif
32354 +
32355 + err = get_user(mov, (unsigned char __user *)regs->ip);
32356 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32357 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32358 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32359 +
32360 + if (err)
32361 + break;
32362 +
32363 + if (mov == 0xB8 && jmp == 0xE9) {
32364 + regs->ax = addr1;
32365 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32366 + return 2;
32367 + }
32368 + } while (0);
32369 +
32370 + do { /* PaX: gcc trampoline emulation #1 */
32371 + unsigned char mov1, mov2;
32372 + unsigned short jmp;
32373 + unsigned int addr1, addr2;
32374 +
32375 +#ifdef CONFIG_X86_64
32376 + if ((regs->ip + 11) >> 32)
32377 + break;
32378 +#endif
32379 +
32380 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32381 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32382 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32383 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32384 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32385 +
32386 + if (err)
32387 + break;
32388 +
32389 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32390 + regs->cx = addr1;
32391 + regs->ax = addr2;
32392 + regs->ip = addr2;
32393 + return 2;
32394 + }
32395 + } while (0);
32396 +
32397 + do { /* PaX: gcc trampoline emulation #2 */
32398 + unsigned char mov, jmp;
32399 + unsigned int addr1, addr2;
32400 +
32401 +#ifdef CONFIG_X86_64
32402 + if ((regs->ip + 9) >> 32)
32403 + break;
32404 +#endif
32405 +
32406 + err = get_user(mov, (unsigned char __user *)regs->ip);
32407 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32408 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32409 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32410 +
32411 + if (err)
32412 + break;
32413 +
32414 + if (mov == 0xB9 && jmp == 0xE9) {
32415 + regs->cx = addr1;
32416 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32417 + return 2;
32418 + }
32419 + } while (0);
32420 +
32421 + return 1; /* PaX in action */
32422 +}
32423 +
32424 +#ifdef CONFIG_X86_64
32425 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32426 +{
32427 + int err;
32428 +
32429 + do { /* PaX: libffi trampoline emulation */
32430 + unsigned short mov1, mov2, jmp1;
32431 + unsigned char stcclc, jmp2;
32432 + unsigned long addr1, addr2;
32433 +
32434 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32435 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32436 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32437 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32438 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32439 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32440 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32441 +
32442 + if (err)
32443 + break;
32444 +
32445 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32446 + regs->r11 = addr1;
32447 + regs->r10 = addr2;
32448 + if (stcclc == 0xF8)
32449 + regs->flags &= ~X86_EFLAGS_CF;
32450 + else
32451 + regs->flags |= X86_EFLAGS_CF;
32452 + regs->ip = addr1;
32453 + return 2;
32454 + }
32455 + } while (0);
32456 +
32457 + do { /* PaX: gcc trampoline emulation #1 */
32458 + unsigned short mov1, mov2, jmp1;
32459 + unsigned char jmp2;
32460 + unsigned int addr1;
32461 + unsigned long addr2;
32462 +
32463 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32464 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32465 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32466 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32467 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32468 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32469 +
32470 + if (err)
32471 + break;
32472 +
32473 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32474 + regs->r11 = addr1;
32475 + regs->r10 = addr2;
32476 + regs->ip = addr1;
32477 + return 2;
32478 + }
32479 + } while (0);
32480 +
32481 + do { /* PaX: gcc trampoline emulation #2 */
32482 + unsigned short mov1, mov2, jmp1;
32483 + unsigned char jmp2;
32484 + unsigned long addr1, addr2;
32485 +
32486 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32487 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32488 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32489 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32490 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32491 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32492 +
32493 + if (err)
32494 + break;
32495 +
32496 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32497 + regs->r11 = addr1;
32498 + regs->r10 = addr2;
32499 + regs->ip = addr1;
32500 + return 2;
32501 + }
32502 + } while (0);
32503 +
32504 + return 1; /* PaX in action */
32505 +}
32506 +#endif
32507 +
32508 +/*
32509 + * PaX: decide what to do with offenders (regs->ip = fault address)
32510 + *
32511 + * returns 1 when task should be killed
32512 + * 2 when gcc trampoline was detected
32513 + */
32514 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32515 +{
32516 + if (v8086_mode(regs))
32517 + return 1;
32518 +
32519 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32520 + return 1;
32521 +
32522 +#ifdef CONFIG_X86_32
32523 + return pax_handle_fetch_fault_32(regs);
32524 +#else
32525 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32526 + return pax_handle_fetch_fault_32(regs);
32527 + else
32528 + return pax_handle_fetch_fault_64(regs);
32529 +#endif
32530 +}
32531 +#endif
32532 +
32533 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32534 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32535 +{
32536 + long i;
32537 +
32538 + printk(KERN_ERR "PAX: bytes at PC: ");
32539 + for (i = 0; i < 20; i++) {
32540 + unsigned char c;
32541 + if (get_user(c, (unsigned char __force_user *)pc+i))
32542 + printk(KERN_CONT "?? ");
32543 + else
32544 + printk(KERN_CONT "%02x ", c);
32545 + }
32546 + printk("\n");
32547 +
32548 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32549 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32550 + unsigned long c;
32551 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32552 +#ifdef CONFIG_X86_32
32553 + printk(KERN_CONT "???????? ");
32554 +#else
32555 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32556 + printk(KERN_CONT "???????? ???????? ");
32557 + else
32558 + printk(KERN_CONT "???????????????? ");
32559 +#endif
32560 + } else {
32561 +#ifdef CONFIG_X86_64
32562 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32563 + printk(KERN_CONT "%08x ", (unsigned int)c);
32564 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32565 + } else
32566 +#endif
32567 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32568 + }
32569 + }
32570 + printk("\n");
32571 +}
32572 +#endif
32573 +
32574 +/**
32575 + * probe_kernel_write(): safely attempt to write to a location
32576 + * @dst: address to write to
32577 + * @src: pointer to the data that shall be written
32578 + * @size: size of the data chunk
32579 + *
32580 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32581 + * happens, handle that and return -EFAULT.
32582 + */
32583 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32584 +{
32585 + long ret;
32586 + mm_segment_t old_fs = get_fs();
32587 +
32588 + set_fs(KERNEL_DS);
32589 + pagefault_disable();
32590 + pax_open_kernel();
32591 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32592 + pax_close_kernel();
32593 + pagefault_enable();
32594 + set_fs(old_fs);
32595 +
32596 + return ret ? -EFAULT : 0;
32597 +}
32598 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32599 index 207d9aef..69030980 100644
32600 --- a/arch/x86/mm/gup.c
32601 +++ b/arch/x86/mm/gup.c
32602 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32603 addr = start;
32604 len = (unsigned long) nr_pages << PAGE_SHIFT;
32605 end = start + len;
32606 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32607 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32608 (void __user *)start, len)))
32609 return 0;
32610
32611 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32612 goto slow_irqon;
32613 #endif
32614
32615 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32616 + (void __user *)start, len)))
32617 + return 0;
32618 +
32619 /*
32620 * XXX: batch / limit 'nr', to avoid large irq off latency
32621 * needs some instrumenting to determine the common sizes used by
32622 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32623 index 4500142..53a363c 100644
32624 --- a/arch/x86/mm/highmem_32.c
32625 +++ b/arch/x86/mm/highmem_32.c
32626 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32627 idx = type + KM_TYPE_NR*smp_processor_id();
32628 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32629 BUG_ON(!pte_none(*(kmap_pte-idx)));
32630 +
32631 + pax_open_kernel();
32632 set_pte(kmap_pte-idx, mk_pte(page, prot));
32633 + pax_close_kernel();
32634 +
32635 arch_flush_lazy_mmu_mode();
32636
32637 return (void *)vaddr;
32638 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32639 index 8b977eb..4732c33 100644
32640 --- a/arch/x86/mm/hugetlbpage.c
32641 +++ b/arch/x86/mm/hugetlbpage.c
32642 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32643 #ifdef CONFIG_HUGETLB_PAGE
32644 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32645 unsigned long addr, unsigned long len,
32646 - unsigned long pgoff, unsigned long flags)
32647 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32648 {
32649 struct hstate *h = hstate_file(file);
32650 struct vm_unmapped_area_info info;
32651 -
32652 +
32653 info.flags = 0;
32654 info.length = len;
32655 info.low_limit = current->mm->mmap_legacy_base;
32656 info.high_limit = TASK_SIZE;
32657 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32658 info.align_offset = 0;
32659 + info.threadstack_offset = offset;
32660 return vm_unmapped_area(&info);
32661 }
32662
32663 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32664 unsigned long addr0, unsigned long len,
32665 - unsigned long pgoff, unsigned long flags)
32666 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32667 {
32668 struct hstate *h = hstate_file(file);
32669 struct vm_unmapped_area_info info;
32670 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32671 info.high_limit = current->mm->mmap_base;
32672 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32673 info.align_offset = 0;
32674 + info.threadstack_offset = offset;
32675 addr = vm_unmapped_area(&info);
32676
32677 /*
32678 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32679 VM_BUG_ON(addr != -ENOMEM);
32680 info.flags = 0;
32681 info.low_limit = TASK_UNMAPPED_BASE;
32682 +
32683 +#ifdef CONFIG_PAX_RANDMMAP
32684 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32685 + info.low_limit += current->mm->delta_mmap;
32686 +#endif
32687 +
32688 info.high_limit = TASK_SIZE;
32689 addr = vm_unmapped_area(&info);
32690 }
32691 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32692 struct hstate *h = hstate_file(file);
32693 struct mm_struct *mm = current->mm;
32694 struct vm_area_struct *vma;
32695 + unsigned long pax_task_size = TASK_SIZE;
32696 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32697
32698 if (len & ~huge_page_mask(h))
32699 return -EINVAL;
32700 - if (len > TASK_SIZE)
32701 +
32702 +#ifdef CONFIG_PAX_SEGMEXEC
32703 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32704 + pax_task_size = SEGMEXEC_TASK_SIZE;
32705 +#endif
32706 +
32707 + pax_task_size -= PAGE_SIZE;
32708 +
32709 + if (len > pax_task_size)
32710 return -ENOMEM;
32711
32712 if (flags & MAP_FIXED) {
32713 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32714 return addr;
32715 }
32716
32717 +#ifdef CONFIG_PAX_RANDMMAP
32718 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32719 +#endif
32720 +
32721 if (addr) {
32722 addr = ALIGN(addr, huge_page_size(h));
32723 vma = find_vma(mm, addr);
32724 - if (TASK_SIZE - len >= addr &&
32725 - (!vma || addr + len <= vma->vm_start))
32726 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32727 return addr;
32728 }
32729 if (mm->get_unmapped_area == arch_get_unmapped_area)
32730 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32731 - pgoff, flags);
32732 + pgoff, flags, offset);
32733 else
32734 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32735 - pgoff, flags);
32736 + pgoff, flags, offset);
32737 }
32738 #endif /* CONFIG_HUGETLB_PAGE */
32739
32740 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32741 index 66dba36..f8082ec 100644
32742 --- a/arch/x86/mm/init.c
32743 +++ b/arch/x86/mm/init.c
32744 @@ -4,6 +4,7 @@
32745 #include <linux/swap.h>
32746 #include <linux/memblock.h>
32747 #include <linux/bootmem.h> /* for max_low_pfn */
32748 +#include <linux/tboot.h>
32749
32750 #include <asm/cacheflush.h>
32751 #include <asm/e820.h>
32752 @@ -17,6 +18,8 @@
32753 #include <asm/proto.h>
32754 #include <asm/dma.h> /* for MAX_DMA_PFN */
32755 #include <asm/microcode.h>
32756 +#include <asm/desc.h>
32757 +#include <asm/bios_ebda.h>
32758
32759 /*
32760 * We need to define the tracepoints somewhere, and tlb.c
32761 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32762 early_ioremap_page_table_range_init();
32763 #endif
32764
32765 +#ifdef CONFIG_PAX_PER_CPU_PGD
32766 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32767 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32768 + KERNEL_PGD_PTRS);
32769 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32770 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32771 + KERNEL_PGD_PTRS);
32772 + load_cr3(get_cpu_pgd(0, kernel));
32773 +#else
32774 load_cr3(swapper_pg_dir);
32775 +#endif
32776 +
32777 __flush_tlb_all();
32778
32779 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32780 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32781 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32782 * mmio resources as well as potential bios/acpi data regions.
32783 */
32784 +
32785 +#ifdef CONFIG_GRKERNSEC_KMEM
32786 +static unsigned int ebda_start __read_only;
32787 +static unsigned int ebda_end __read_only;
32788 +#endif
32789 +
32790 int devmem_is_allowed(unsigned long pagenr)
32791 {
32792 - if (pagenr < 256)
32793 +#ifdef CONFIG_GRKERNSEC_KMEM
32794 + /* allow BDA */
32795 + if (!pagenr)
32796 return 1;
32797 + /* allow EBDA */
32798 + if (pagenr >= ebda_start && pagenr < ebda_end)
32799 + return 1;
32800 + /* if tboot is in use, allow access to its hardcoded serial log range */
32801 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32802 + return 1;
32803 +#else
32804 + if (!pagenr)
32805 + return 1;
32806 +#ifdef CONFIG_VM86
32807 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32808 + return 1;
32809 +#endif
32810 +#endif
32811 +
32812 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32813 + return 1;
32814 +#ifdef CONFIG_GRKERNSEC_KMEM
32815 + /* throw out everything else below 1MB */
32816 + if (pagenr <= 256)
32817 + return 0;
32818 +#endif
32819 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32820 return 0;
32821 if (!page_is_ram(pagenr))
32822 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32823 #endif
32824 }
32825
32826 +#ifdef CONFIG_GRKERNSEC_KMEM
32827 +static inline void gr_init_ebda(void)
32828 +{
32829 + unsigned int ebda_addr;
32830 + unsigned int ebda_size = 0;
32831 +
32832 + ebda_addr = get_bios_ebda();
32833 + if (ebda_addr) {
32834 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32835 + ebda_size <<= 10;
32836 + }
32837 + if (ebda_addr && ebda_size) {
32838 + ebda_start = ebda_addr >> PAGE_SHIFT;
32839 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32840 + } else {
32841 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32842 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32843 + }
32844 +}
32845 +#else
32846 +static inline void gr_init_ebda(void) { }
32847 +#endif
32848 +
32849 void free_initmem(void)
32850 {
32851 +#ifdef CONFIG_PAX_KERNEXEC
32852 +#ifdef CONFIG_X86_32
32853 + /* PaX: limit KERNEL_CS to actual size */
32854 + unsigned long addr, limit;
32855 + struct desc_struct d;
32856 + int cpu;
32857 +#else
32858 + pgd_t *pgd;
32859 + pud_t *pud;
32860 + pmd_t *pmd;
32861 + unsigned long addr, end;
32862 +#endif
32863 +#endif
32864 +
32865 + gr_init_ebda();
32866 +
32867 +#ifdef CONFIG_PAX_KERNEXEC
32868 +#ifdef CONFIG_X86_32
32869 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32870 + limit = (limit - 1UL) >> PAGE_SHIFT;
32871 +
32872 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32873 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32874 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32875 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32876 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32877 + }
32878 +
32879 + /* PaX: make KERNEL_CS read-only */
32880 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32881 + if (!paravirt_enabled())
32882 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32883 +/*
32884 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32885 + pgd = pgd_offset_k(addr);
32886 + pud = pud_offset(pgd, addr);
32887 + pmd = pmd_offset(pud, addr);
32888 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32889 + }
32890 +*/
32891 +#ifdef CONFIG_X86_PAE
32892 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32893 +/*
32894 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32895 + pgd = pgd_offset_k(addr);
32896 + pud = pud_offset(pgd, addr);
32897 + pmd = pmd_offset(pud, addr);
32898 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32899 + }
32900 +*/
32901 +#endif
32902 +
32903 +#ifdef CONFIG_MODULES
32904 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32905 +#endif
32906 +
32907 +#else
32908 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32909 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32910 + pgd = pgd_offset_k(addr);
32911 + pud = pud_offset(pgd, addr);
32912 + pmd = pmd_offset(pud, addr);
32913 + if (!pmd_present(*pmd))
32914 + continue;
32915 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32916 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32917 + else
32918 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32919 + }
32920 +
32921 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32922 + end = addr + KERNEL_IMAGE_SIZE;
32923 + for (; addr < end; addr += PMD_SIZE) {
32924 + pgd = pgd_offset_k(addr);
32925 + pud = pud_offset(pgd, addr);
32926 + pmd = pmd_offset(pud, addr);
32927 + if (!pmd_present(*pmd))
32928 + continue;
32929 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32930 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32931 + }
32932 +#endif
32933 +
32934 + flush_tlb_all();
32935 +#endif
32936 +
32937 free_init_pages("unused kernel",
32938 (unsigned long)(&__init_begin),
32939 (unsigned long)(&__init_end));
32940 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32941 index c8140e1..59257fc 100644
32942 --- a/arch/x86/mm/init_32.c
32943 +++ b/arch/x86/mm/init_32.c
32944 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32945 bool __read_mostly __vmalloc_start_set = false;
32946
32947 /*
32948 - * Creates a middle page table and puts a pointer to it in the
32949 - * given global directory entry. This only returns the gd entry
32950 - * in non-PAE compilation mode, since the middle layer is folded.
32951 - */
32952 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32953 -{
32954 - pud_t *pud;
32955 - pmd_t *pmd_table;
32956 -
32957 -#ifdef CONFIG_X86_PAE
32958 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32959 - pmd_table = (pmd_t *)alloc_low_page();
32960 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32961 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32962 - pud = pud_offset(pgd, 0);
32963 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32964 -
32965 - return pmd_table;
32966 - }
32967 -#endif
32968 - pud = pud_offset(pgd, 0);
32969 - pmd_table = pmd_offset(pud, 0);
32970 -
32971 - return pmd_table;
32972 -}
32973 -
32974 -/*
32975 * Create a page table and place a pointer to it in a middle page
32976 * directory entry:
32977 */
32978 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32979 pte_t *page_table = (pte_t *)alloc_low_page();
32980
32981 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32982 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32983 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32984 +#else
32985 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32986 +#endif
32987 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32988 }
32989
32990 return pte_offset_kernel(pmd, 0);
32991 }
32992
32993 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32994 +{
32995 + pud_t *pud;
32996 + pmd_t *pmd_table;
32997 +
32998 + pud = pud_offset(pgd, 0);
32999 + pmd_table = pmd_offset(pud, 0);
33000 +
33001 + return pmd_table;
33002 +}
33003 +
33004 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33005 {
33006 int pgd_idx = pgd_index(vaddr);
33007 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33008 int pgd_idx, pmd_idx;
33009 unsigned long vaddr;
33010 pgd_t *pgd;
33011 + pud_t *pud;
33012 pmd_t *pmd;
33013 pte_t *pte = NULL;
33014 unsigned long count = page_table_range_init_count(start, end);
33015 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33016 pgd = pgd_base + pgd_idx;
33017
33018 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33019 - pmd = one_md_table_init(pgd);
33020 - pmd = pmd + pmd_index(vaddr);
33021 + pud = pud_offset(pgd, vaddr);
33022 + pmd = pmd_offset(pud, vaddr);
33023 +
33024 +#ifdef CONFIG_X86_PAE
33025 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33026 +#endif
33027 +
33028 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33029 pmd++, pmd_idx++) {
33030 pte = page_table_kmap_check(one_page_table_init(pmd),
33031 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33032 }
33033 }
33034
33035 -static inline int is_kernel_text(unsigned long addr)
33036 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33037 {
33038 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33039 - return 1;
33040 - return 0;
33041 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33042 + end <= ktla_ktva((unsigned long)_stext)) &&
33043 + (start >= ktla_ktva((unsigned long)_einittext) ||
33044 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33045 +
33046 +#ifdef CONFIG_ACPI_SLEEP
33047 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33048 +#endif
33049 +
33050 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33051 + return 0;
33052 + return 1;
33053 }
33054
33055 /*
33056 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33057 unsigned long last_map_addr = end;
33058 unsigned long start_pfn, end_pfn;
33059 pgd_t *pgd_base = swapper_pg_dir;
33060 - int pgd_idx, pmd_idx, pte_ofs;
33061 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33062 unsigned long pfn;
33063 pgd_t *pgd;
33064 + pud_t *pud;
33065 pmd_t *pmd;
33066 pte_t *pte;
33067 unsigned pages_2m, pages_4k;
33068 @@ -291,8 +295,13 @@ repeat:
33069 pfn = start_pfn;
33070 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33071 pgd = pgd_base + pgd_idx;
33072 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33073 - pmd = one_md_table_init(pgd);
33074 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33075 + pud = pud_offset(pgd, 0);
33076 + pmd = pmd_offset(pud, 0);
33077 +
33078 +#ifdef CONFIG_X86_PAE
33079 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33080 +#endif
33081
33082 if (pfn >= end_pfn)
33083 continue;
33084 @@ -304,14 +313,13 @@ repeat:
33085 #endif
33086 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33087 pmd++, pmd_idx++) {
33088 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33089 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33090
33091 /*
33092 * Map with big pages if possible, otherwise
33093 * create normal page tables:
33094 */
33095 if (use_pse) {
33096 - unsigned int addr2;
33097 pgprot_t prot = PAGE_KERNEL_LARGE;
33098 /*
33099 * first pass will use the same initial
33100 @@ -322,11 +330,7 @@ repeat:
33101 _PAGE_PSE);
33102
33103 pfn &= PMD_MASK >> PAGE_SHIFT;
33104 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33105 - PAGE_OFFSET + PAGE_SIZE-1;
33106 -
33107 - if (is_kernel_text(addr) ||
33108 - is_kernel_text(addr2))
33109 + if (is_kernel_text(address, address + PMD_SIZE))
33110 prot = PAGE_KERNEL_LARGE_EXEC;
33111
33112 pages_2m++;
33113 @@ -343,7 +347,7 @@ repeat:
33114 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33115 pte += pte_ofs;
33116 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33117 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33118 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33119 pgprot_t prot = PAGE_KERNEL;
33120 /*
33121 * first pass will use the same initial
33122 @@ -351,7 +355,7 @@ repeat:
33123 */
33124 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33125
33126 - if (is_kernel_text(addr))
33127 + if (is_kernel_text(address, address + PAGE_SIZE))
33128 prot = PAGE_KERNEL_EXEC;
33129
33130 pages_4k++;
33131 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33132
33133 pud = pud_offset(pgd, va);
33134 pmd = pmd_offset(pud, va);
33135 - if (!pmd_present(*pmd))
33136 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33137 break;
33138
33139 /* should not be large page here */
33140 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33141
33142 static void __init pagetable_init(void)
33143 {
33144 - pgd_t *pgd_base = swapper_pg_dir;
33145 -
33146 - permanent_kmaps_init(pgd_base);
33147 + permanent_kmaps_init(swapper_pg_dir);
33148 }
33149
33150 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33151 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33152 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33153
33154 /* user-defined highmem size */
33155 @@ -787,10 +789,10 @@ void __init mem_init(void)
33156 ((unsigned long)&__init_end -
33157 (unsigned long)&__init_begin) >> 10,
33158
33159 - (unsigned long)&_etext, (unsigned long)&_edata,
33160 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33161 + (unsigned long)&_sdata, (unsigned long)&_edata,
33162 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33163
33164 - (unsigned long)&_text, (unsigned long)&_etext,
33165 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33166 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33167
33168 /*
33169 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33170 if (!kernel_set_to_readonly)
33171 return;
33172
33173 + start = ktla_ktva(start);
33174 pr_debug("Set kernel text: %lx - %lx for read write\n",
33175 start, start+size);
33176
33177 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33178 if (!kernel_set_to_readonly)
33179 return;
33180
33181 + start = ktla_ktva(start);
33182 pr_debug("Set kernel text: %lx - %lx for read only\n",
33183 start, start+size);
33184
33185 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33186 unsigned long start = PFN_ALIGN(_text);
33187 unsigned long size = PFN_ALIGN(_etext) - start;
33188
33189 + start = ktla_ktva(start);
33190 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33191 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33192 size >> 10);
33193 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33194 index 4e5dfec..6fd6dc5 100644
33195 --- a/arch/x86/mm/init_64.c
33196 +++ b/arch/x86/mm/init_64.c
33197 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33198 * around without checking the pgd every time.
33199 */
33200
33201 -pteval_t __supported_pte_mask __read_mostly = ~0;
33202 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33203 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33204
33205 int force_personality32;
33206 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33207
33208 for (address = start; address <= end; address += PGDIR_SIZE) {
33209 const pgd_t *pgd_ref = pgd_offset_k(address);
33210 +
33211 +#ifdef CONFIG_PAX_PER_CPU_PGD
33212 + unsigned long cpu;
33213 +#else
33214 struct page *page;
33215 +#endif
33216
33217 /*
33218 * When it is called after memory hot remove, pgd_none()
33219 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33220 continue;
33221
33222 spin_lock(&pgd_lock);
33223 +
33224 +#ifdef CONFIG_PAX_PER_CPU_PGD
33225 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33226 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33227 +
33228 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33229 + BUG_ON(pgd_page_vaddr(*pgd)
33230 + != pgd_page_vaddr(*pgd_ref));
33231 +
33232 + if (removed) {
33233 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33234 + pgd_clear(pgd);
33235 + } else {
33236 + if (pgd_none(*pgd))
33237 + set_pgd(pgd, *pgd_ref);
33238 + }
33239 +
33240 + pgd = pgd_offset_cpu(cpu, kernel, address);
33241 +#else
33242 list_for_each_entry(page, &pgd_list, lru) {
33243 pgd_t *pgd;
33244 spinlock_t *pgt_lock;
33245 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33246 /* the pgt_lock only for Xen */
33247 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33248 spin_lock(pgt_lock);
33249 +#endif
33250
33251 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33252 BUG_ON(pgd_page_vaddr(*pgd)
33253 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33254 set_pgd(pgd, *pgd_ref);
33255 }
33256
33257 +#ifndef CONFIG_PAX_PER_CPU_PGD
33258 spin_unlock(pgt_lock);
33259 +#endif
33260 +
33261 }
33262 spin_unlock(&pgd_lock);
33263 }
33264 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33265 {
33266 if (pgd_none(*pgd)) {
33267 pud_t *pud = (pud_t *)spp_getpage();
33268 - pgd_populate(&init_mm, pgd, pud);
33269 + pgd_populate_kernel(&init_mm, pgd, pud);
33270 if (pud != pud_offset(pgd, 0))
33271 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33272 pud, pud_offset(pgd, 0));
33273 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33274 {
33275 if (pud_none(*pud)) {
33276 pmd_t *pmd = (pmd_t *) spp_getpage();
33277 - pud_populate(&init_mm, pud, pmd);
33278 + pud_populate_kernel(&init_mm, pud, pmd);
33279 if (pmd != pmd_offset(pud, 0))
33280 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33281 pmd, pmd_offset(pud, 0));
33282 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33283 pmd = fill_pmd(pud, vaddr);
33284 pte = fill_pte(pmd, vaddr);
33285
33286 + pax_open_kernel();
33287 set_pte(pte, new_pte);
33288 + pax_close_kernel();
33289
33290 /*
33291 * It's enough to flush this one mapping.
33292 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33293 pgd = pgd_offset_k((unsigned long)__va(phys));
33294 if (pgd_none(*pgd)) {
33295 pud = (pud_t *) spp_getpage();
33296 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33297 - _PAGE_USER));
33298 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33299 }
33300 pud = pud_offset(pgd, (unsigned long)__va(phys));
33301 if (pud_none(*pud)) {
33302 pmd = (pmd_t *) spp_getpage();
33303 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33304 - _PAGE_USER));
33305 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33306 }
33307 pmd = pmd_offset(pud, phys);
33308 BUG_ON(!pmd_none(*pmd));
33309 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33310 prot);
33311
33312 spin_lock(&init_mm.page_table_lock);
33313 - pud_populate(&init_mm, pud, pmd);
33314 + pud_populate_kernel(&init_mm, pud, pmd);
33315 spin_unlock(&init_mm.page_table_lock);
33316 }
33317 __flush_tlb_all();
33318 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33319 page_size_mask);
33320
33321 spin_lock(&init_mm.page_table_lock);
33322 - pgd_populate(&init_mm, pgd, pud);
33323 + pgd_populate_kernel(&init_mm, pgd, pud);
33324 spin_unlock(&init_mm.page_table_lock);
33325 pgd_changed = true;
33326 }
33327 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33328 static struct vm_area_struct gate_vma = {
33329 .vm_start = VSYSCALL_ADDR,
33330 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33331 - .vm_page_prot = PAGE_READONLY_EXEC,
33332 - .vm_flags = VM_READ | VM_EXEC,
33333 + .vm_page_prot = PAGE_READONLY,
33334 + .vm_flags = VM_READ,
33335 .vm_ops = &gate_vma_ops,
33336 };
33337
33338 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33339 index 7b179b49..6bd17777 100644
33340 --- a/arch/x86/mm/iomap_32.c
33341 +++ b/arch/x86/mm/iomap_32.c
33342 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33343 type = kmap_atomic_idx_push();
33344 idx = type + KM_TYPE_NR * smp_processor_id();
33345 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33346 +
33347 + pax_open_kernel();
33348 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33349 + pax_close_kernel();
33350 +
33351 arch_flush_lazy_mmu_mode();
33352
33353 return (void *)vaddr;
33354 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33355 index af78e50..0790b03 100644
33356 --- a/arch/x86/mm/ioremap.c
33357 +++ b/arch/x86/mm/ioremap.c
33358 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33359 unsigned long i;
33360
33361 for (i = 0; i < nr_pages; ++i)
33362 - if (pfn_valid(start_pfn + i) &&
33363 - !PageReserved(pfn_to_page(start_pfn + i)))
33364 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33365 + !PageReserved(pfn_to_page(start_pfn + i))))
33366 return 1;
33367
33368 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33369 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33370 *
33371 * Caller must ensure there is only one unmapping for the same pointer.
33372 */
33373 -void iounmap(volatile void __iomem *addr)
33374 +void iounmap(const volatile void __iomem *addr)
33375 {
33376 struct vm_struct *p, *o;
33377
33378 @@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33379
33380 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33381 if (page_is_ram(start >> PAGE_SHIFT))
33382 +#ifdef CONFIG_HIGHMEM
33383 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33384 +#endif
33385 return __va(phys);
33386
33387 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33388 @@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33389 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33390 {
33391 if (page_is_ram(phys >> PAGE_SHIFT))
33392 +#ifdef CONFIG_HIGHMEM
33393 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33394 +#endif
33395 return;
33396
33397 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33398 return;
33399 }
33400
33401 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33402 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33403
33404 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33405 {
33406 @@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33407 early_ioremap_setup();
33408
33409 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33410 - memset(bm_pte, 0, sizeof(bm_pte));
33411 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33412 + pmd_populate_user(&init_mm, pmd, bm_pte);
33413
33414 /*
33415 * The boot-ioremap range spans multiple pmds, for which
33416 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33417 index b4f2e7e..96c9c3e 100644
33418 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33419 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33420 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33421 * memory (e.g. tracked pages)? For now, we need this to avoid
33422 * invoking kmemcheck for PnP BIOS calls.
33423 */
33424 - if (regs->flags & X86_VM_MASK)
33425 + if (v8086_mode(regs))
33426 return false;
33427 - if (regs->cs != __KERNEL_CS)
33428 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33429 return false;
33430
33431 pte = kmemcheck_pte_lookup(address);
33432 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33433 index 919b912..9267313 100644
33434 --- a/arch/x86/mm/mmap.c
33435 +++ b/arch/x86/mm/mmap.c
33436 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33437 * Leave an at least ~128 MB hole with possible stack randomization.
33438 */
33439 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33440 -#define MAX_GAP (TASK_SIZE/6*5)
33441 +#define MAX_GAP (pax_task_size/6*5)
33442
33443 static int mmap_is_legacy(void)
33444 {
33445 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33446 return rnd << PAGE_SHIFT;
33447 }
33448
33449 -static unsigned long mmap_base(void)
33450 +static unsigned long mmap_base(struct mm_struct *mm)
33451 {
33452 unsigned long gap = rlimit(RLIMIT_STACK);
33453 + unsigned long pax_task_size = TASK_SIZE;
33454 +
33455 +#ifdef CONFIG_PAX_SEGMEXEC
33456 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33457 + pax_task_size = SEGMEXEC_TASK_SIZE;
33458 +#endif
33459
33460 if (gap < MIN_GAP)
33461 gap = MIN_GAP;
33462 else if (gap > MAX_GAP)
33463 gap = MAX_GAP;
33464
33465 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33466 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33467 }
33468
33469 /*
33470 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33471 * does, but not when emulating X86_32
33472 */
33473 -static unsigned long mmap_legacy_base(void)
33474 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33475 {
33476 - if (mmap_is_ia32())
33477 + if (mmap_is_ia32()) {
33478 +
33479 +#ifdef CONFIG_PAX_SEGMEXEC
33480 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33481 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33482 + else
33483 +#endif
33484 +
33485 return TASK_UNMAPPED_BASE;
33486 - else
33487 + } else
33488 return TASK_UNMAPPED_BASE + mmap_rnd();
33489 }
33490
33491 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33492 */
33493 void arch_pick_mmap_layout(struct mm_struct *mm)
33494 {
33495 - mm->mmap_legacy_base = mmap_legacy_base();
33496 - mm->mmap_base = mmap_base();
33497 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33498 + mm->mmap_base = mmap_base(mm);
33499 +
33500 +#ifdef CONFIG_PAX_RANDMMAP
33501 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33502 + mm->mmap_legacy_base += mm->delta_mmap;
33503 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33504 + }
33505 +#endif
33506
33507 if (mmap_is_legacy()) {
33508 mm->mmap_base = mm->mmap_legacy_base;
33509 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33510 index 0057a7a..95c7edd 100644
33511 --- a/arch/x86/mm/mmio-mod.c
33512 +++ b/arch/x86/mm/mmio-mod.c
33513 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33514 break;
33515 default:
33516 {
33517 - unsigned char *ip = (unsigned char *)instptr;
33518 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33519 my_trace->opcode = MMIO_UNKNOWN_OP;
33520 my_trace->width = 0;
33521 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33522 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33523 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33524 void __iomem *addr)
33525 {
33526 - static atomic_t next_id;
33527 + static atomic_unchecked_t next_id;
33528 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33529 /* These are page-unaligned. */
33530 struct mmiotrace_map map = {
33531 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33532 .private = trace
33533 },
33534 .phys = offset,
33535 - .id = atomic_inc_return(&next_id)
33536 + .id = atomic_inc_return_unchecked(&next_id)
33537 };
33538 map.map_id = trace->id;
33539
33540 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33541 ioremap_trace_core(offset, size, addr);
33542 }
33543
33544 -static void iounmap_trace_core(volatile void __iomem *addr)
33545 +static void iounmap_trace_core(const volatile void __iomem *addr)
33546 {
33547 struct mmiotrace_map map = {
33548 .phys = 0,
33549 @@ -328,7 +328,7 @@ not_enabled:
33550 }
33551 }
33552
33553 -void mmiotrace_iounmap(volatile void __iomem *addr)
33554 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33555 {
33556 might_sleep();
33557 if (is_enabled()) /* recheck and proper locking in *_core() */
33558 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33559 index 1a88370..3f598b5 100644
33560 --- a/arch/x86/mm/numa.c
33561 +++ b/arch/x86/mm/numa.c
33562 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33563 }
33564 }
33565
33566 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33567 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33568 {
33569 unsigned long uninitialized_var(pfn_align);
33570 int i, nid;
33571 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33572 index 36de293..b820ddc 100644
33573 --- a/arch/x86/mm/pageattr.c
33574 +++ b/arch/x86/mm/pageattr.c
33575 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33576 */
33577 #ifdef CONFIG_PCI_BIOS
33578 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33579 - pgprot_val(forbidden) |= _PAGE_NX;
33580 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33581 #endif
33582
33583 /*
33584 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33585 * Does not cover __inittext since that is gone later on. On
33586 * 64bit we do not enforce !NX on the low mapping
33587 */
33588 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33589 - pgprot_val(forbidden) |= _PAGE_NX;
33590 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33591 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33592
33593 +#ifdef CONFIG_DEBUG_RODATA
33594 /*
33595 * The .rodata section needs to be read-only. Using the pfn
33596 * catches all aliases.
33597 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33598 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33599 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33600 pgprot_val(forbidden) |= _PAGE_RW;
33601 +#endif
33602
33603 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33604 /*
33605 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33606 }
33607 #endif
33608
33609 +#ifdef CONFIG_PAX_KERNEXEC
33610 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33611 + pgprot_val(forbidden) |= _PAGE_RW;
33612 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33613 + }
33614 +#endif
33615 +
33616 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33617
33618 return prot;
33619 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33620 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33621 {
33622 /* change init_mm */
33623 + pax_open_kernel();
33624 set_pte_atomic(kpte, pte);
33625 +
33626 #ifdef CONFIG_X86_32
33627 if (!SHARED_KERNEL_PMD) {
33628 +
33629 +#ifdef CONFIG_PAX_PER_CPU_PGD
33630 + unsigned long cpu;
33631 +#else
33632 struct page *page;
33633 +#endif
33634
33635 +#ifdef CONFIG_PAX_PER_CPU_PGD
33636 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33637 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33638 +#else
33639 list_for_each_entry(page, &pgd_list, lru) {
33640 - pgd_t *pgd;
33641 + pgd_t *pgd = (pgd_t *)page_address(page);
33642 +#endif
33643 +
33644 pud_t *pud;
33645 pmd_t *pmd;
33646
33647 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33648 + pgd += pgd_index(address);
33649 pud = pud_offset(pgd, address);
33650 pmd = pmd_offset(pud, address);
33651 set_pte_atomic((pte_t *)pmd, pte);
33652 }
33653 }
33654 #endif
33655 + pax_close_kernel();
33656 }
33657
33658 static int
33659 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33660 index 6574388..87e9bef 100644
33661 --- a/arch/x86/mm/pat.c
33662 +++ b/arch/x86/mm/pat.c
33663 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33664
33665 if (!entry) {
33666 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33667 - current->comm, current->pid, start, end - 1);
33668 + current->comm, task_pid_nr(current), start, end - 1);
33669 return -EINVAL;
33670 }
33671
33672 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33673
33674 while (cursor < to) {
33675 if (!devmem_is_allowed(pfn)) {
33676 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33677 - current->comm, from, to - 1);
33678 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33679 + current->comm, from, to - 1, cursor);
33680 return 0;
33681 }
33682 cursor += PAGE_SIZE;
33683 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33684 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33685 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33686 "for [mem %#010Lx-%#010Lx]\n",
33687 - current->comm, current->pid,
33688 + current->comm, task_pid_nr(current),
33689 cattr_name(flags),
33690 base, (unsigned long long)(base + size-1));
33691 return -EINVAL;
33692 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33693 flags = lookup_memtype(paddr);
33694 if (want_flags != flags) {
33695 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33696 - current->comm, current->pid,
33697 + current->comm, task_pid_nr(current),
33698 cattr_name(want_flags),
33699 (unsigned long long)paddr,
33700 (unsigned long long)(paddr + size - 1),
33701 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33702 free_memtype(paddr, paddr + size);
33703 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33704 " for [mem %#010Lx-%#010Lx], got %s\n",
33705 - current->comm, current->pid,
33706 + current->comm, task_pid_nr(current),
33707 cattr_name(want_flags),
33708 (unsigned long long)paddr,
33709 (unsigned long long)(paddr + size - 1),
33710 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33711 index 415f6c4..d319983 100644
33712 --- a/arch/x86/mm/pat_rbtree.c
33713 +++ b/arch/x86/mm/pat_rbtree.c
33714 @@ -160,7 +160,7 @@ success:
33715
33716 failure:
33717 printk(KERN_INFO "%s:%d conflicting memory types "
33718 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33719 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33720 end, cattr_name(found_type), cattr_name(match->type));
33721 return -EBUSY;
33722 }
33723 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33724 index 9f0614d..92ae64a 100644
33725 --- a/arch/x86/mm/pf_in.c
33726 +++ b/arch/x86/mm/pf_in.c
33727 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33728 int i;
33729 enum reason_type rv = OTHERS;
33730
33731 - p = (unsigned char *)ins_addr;
33732 + p = (unsigned char *)ktla_ktva(ins_addr);
33733 p += skip_prefix(p, &prf);
33734 p += get_opcode(p, &opcode);
33735
33736 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33737 struct prefix_bits prf;
33738 int i;
33739
33740 - p = (unsigned char *)ins_addr;
33741 + p = (unsigned char *)ktla_ktva(ins_addr);
33742 p += skip_prefix(p, &prf);
33743 p += get_opcode(p, &opcode);
33744
33745 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33746 struct prefix_bits prf;
33747 int i;
33748
33749 - p = (unsigned char *)ins_addr;
33750 + p = (unsigned char *)ktla_ktva(ins_addr);
33751 p += skip_prefix(p, &prf);
33752 p += get_opcode(p, &opcode);
33753
33754 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33755 struct prefix_bits prf;
33756 int i;
33757
33758 - p = (unsigned char *)ins_addr;
33759 + p = (unsigned char *)ktla_ktva(ins_addr);
33760 p += skip_prefix(p, &prf);
33761 p += get_opcode(p, &opcode);
33762 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33763 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33764 struct prefix_bits prf;
33765 int i;
33766
33767 - p = (unsigned char *)ins_addr;
33768 + p = (unsigned char *)ktla_ktva(ins_addr);
33769 p += skip_prefix(p, &prf);
33770 p += get_opcode(p, &opcode);
33771 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33772 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33773 index 6fb6927..4fc13c0 100644
33774 --- a/arch/x86/mm/pgtable.c
33775 +++ b/arch/x86/mm/pgtable.c
33776 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33777 list_del(&page->lru);
33778 }
33779
33780 -#define UNSHARED_PTRS_PER_PGD \
33781 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33782 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33783 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33784
33785 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33786 +{
33787 + unsigned int count = USER_PGD_PTRS;
33788
33789 + if (!pax_user_shadow_base)
33790 + return;
33791 +
33792 + while (count--)
33793 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33794 +}
33795 +#endif
33796 +
33797 +#ifdef CONFIG_PAX_PER_CPU_PGD
33798 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33799 +{
33800 + unsigned int count = USER_PGD_PTRS;
33801 +
33802 + while (count--) {
33803 + pgd_t pgd;
33804 +
33805 +#ifdef CONFIG_X86_64
33806 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33807 +#else
33808 + pgd = *src++;
33809 +#endif
33810 +
33811 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33812 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33813 +#endif
33814 +
33815 + *dst++ = pgd;
33816 + }
33817 +
33818 +}
33819 +#endif
33820 +
33821 +#ifdef CONFIG_X86_64
33822 +#define pxd_t pud_t
33823 +#define pyd_t pgd_t
33824 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33825 +#define pgtable_pxd_page_ctor(page) true
33826 +#define pgtable_pxd_page_dtor(page)
33827 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33828 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33829 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33830 +#define PYD_SIZE PGDIR_SIZE
33831 +#else
33832 +#define pxd_t pmd_t
33833 +#define pyd_t pud_t
33834 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33835 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33836 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33837 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33838 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33839 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33840 +#define PYD_SIZE PUD_SIZE
33841 +#endif
33842 +
33843 +#ifdef CONFIG_PAX_PER_CPU_PGD
33844 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33845 +static inline void pgd_dtor(pgd_t *pgd) {}
33846 +#else
33847 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33848 {
33849 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33850 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33851 pgd_list_del(pgd);
33852 spin_unlock(&pgd_lock);
33853 }
33854 +#endif
33855
33856 /*
33857 * List of all pgd's needed for non-PAE so it can invalidate entries
33858 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33859 * -- nyc
33860 */
33861
33862 -#ifdef CONFIG_X86_PAE
33863 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33864 /*
33865 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33866 * updating the top-level pagetable entries to guarantee the
33867 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33868 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33869 * and initialize the kernel pmds here.
33870 */
33871 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33872 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33873
33874 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33875 {
33876 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33877 */
33878 flush_tlb_mm(mm);
33879 }
33880 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33881 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33882 #else /* !CONFIG_X86_PAE */
33883
33884 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33885 -#define PREALLOCATED_PMDS 0
33886 +#define PREALLOCATED_PXDS 0
33887
33888 #endif /* CONFIG_X86_PAE */
33889
33890 -static void free_pmds(pmd_t *pmds[])
33891 +static void free_pxds(pxd_t *pxds[])
33892 {
33893 int i;
33894
33895 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33896 - if (pmds[i]) {
33897 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33898 - free_page((unsigned long)pmds[i]);
33899 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33900 + if (pxds[i]) {
33901 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33902 + free_page((unsigned long)pxds[i]);
33903 }
33904 }
33905
33906 -static int preallocate_pmds(pmd_t *pmds[])
33907 +static int preallocate_pxds(pxd_t *pxds[])
33908 {
33909 int i;
33910 bool failed = false;
33911
33912 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33913 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33914 - if (!pmd)
33915 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33916 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33917 + if (!pxd)
33918 failed = true;
33919 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33920 - free_page((unsigned long)pmd);
33921 - pmd = NULL;
33922 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33923 + free_page((unsigned long)pxd);
33924 + pxd = NULL;
33925 failed = true;
33926 }
33927 - pmds[i] = pmd;
33928 + pxds[i] = pxd;
33929 }
33930
33931 if (failed) {
33932 - free_pmds(pmds);
33933 + free_pxds(pxds);
33934 return -ENOMEM;
33935 }
33936
33937 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33938 * preallocate which never got a corresponding vma will need to be
33939 * freed manually.
33940 */
33941 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33942 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33943 {
33944 int i;
33945
33946 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33947 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33948 pgd_t pgd = pgdp[i];
33949
33950 if (pgd_val(pgd) != 0) {
33951 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33952 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33953
33954 - pgdp[i] = native_make_pgd(0);
33955 + set_pgd(pgdp + i, native_make_pgd(0));
33956
33957 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33958 - pmd_free(mm, pmd);
33959 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33960 + pxd_free(mm, pxd);
33961 }
33962 }
33963 }
33964
33965 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33966 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33967 {
33968 - pud_t *pud;
33969 + pyd_t *pyd;
33970 int i;
33971
33972 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33973 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33974 return;
33975
33976 - pud = pud_offset(pgd, 0);
33977 -
33978 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33979 - pmd_t *pmd = pmds[i];
33980 +#ifdef CONFIG_X86_64
33981 + pyd = pyd_offset(mm, 0L);
33982 +#else
33983 + pyd = pyd_offset(pgd, 0L);
33984 +#endif
33985
33986 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33987 + pxd_t *pxd = pxds[i];
33988 if (i >= KERNEL_PGD_BOUNDARY)
33989 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33990 - sizeof(pmd_t) * PTRS_PER_PMD);
33991 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33992 + sizeof(pxd_t) * PTRS_PER_PMD);
33993
33994 - pud_populate(mm, pud, pmd);
33995 + pyd_populate(mm, pyd, pxd);
33996 }
33997 }
33998
33999 pgd_t *pgd_alloc(struct mm_struct *mm)
34000 {
34001 pgd_t *pgd;
34002 - pmd_t *pmds[PREALLOCATED_PMDS];
34003 + pxd_t *pxds[PREALLOCATED_PXDS];
34004
34005 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34006
34007 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34008
34009 mm->pgd = pgd;
34010
34011 - if (preallocate_pmds(pmds) != 0)
34012 + if (preallocate_pxds(pxds) != 0)
34013 goto out_free_pgd;
34014
34015 if (paravirt_pgd_alloc(mm) != 0)
34016 - goto out_free_pmds;
34017 + goto out_free_pxds;
34018
34019 /*
34020 * Make sure that pre-populating the pmds is atomic with
34021 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34022 spin_lock(&pgd_lock);
34023
34024 pgd_ctor(mm, pgd);
34025 - pgd_prepopulate_pmd(mm, pgd, pmds);
34026 + pgd_prepopulate_pxd(mm, pgd, pxds);
34027
34028 spin_unlock(&pgd_lock);
34029
34030 return pgd;
34031
34032 -out_free_pmds:
34033 - free_pmds(pmds);
34034 +out_free_pxds:
34035 + free_pxds(pxds);
34036 out_free_pgd:
34037 free_page((unsigned long)pgd);
34038 out:
34039 @@ -313,7 +380,7 @@ out:
34040
34041 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34042 {
34043 - pgd_mop_up_pmds(mm, pgd);
34044 + pgd_mop_up_pxds(mm, pgd);
34045 pgd_dtor(pgd);
34046 paravirt_pgd_free(mm, pgd);
34047 free_page((unsigned long)pgd);
34048 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34049 index 75cc097..79a097f 100644
34050 --- a/arch/x86/mm/pgtable_32.c
34051 +++ b/arch/x86/mm/pgtable_32.c
34052 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34053 return;
34054 }
34055 pte = pte_offset_kernel(pmd, vaddr);
34056 +
34057 + pax_open_kernel();
34058 if (pte_val(pteval))
34059 set_pte_at(&init_mm, vaddr, pte, pteval);
34060 else
34061 pte_clear(&init_mm, vaddr, pte);
34062 + pax_close_kernel();
34063
34064 /*
34065 * It's enough to flush this one mapping.
34066 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34067 index e666cbb..61788c45 100644
34068 --- a/arch/x86/mm/physaddr.c
34069 +++ b/arch/x86/mm/physaddr.c
34070 @@ -10,7 +10,7 @@
34071 #ifdef CONFIG_X86_64
34072
34073 #ifdef CONFIG_DEBUG_VIRTUAL
34074 -unsigned long __phys_addr(unsigned long x)
34075 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34076 {
34077 unsigned long y = x - __START_KERNEL_map;
34078
34079 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34080 #else
34081
34082 #ifdef CONFIG_DEBUG_VIRTUAL
34083 -unsigned long __phys_addr(unsigned long x)
34084 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34085 {
34086 unsigned long phys_addr = x - PAGE_OFFSET;
34087 /* VMALLOC_* aren't constants */
34088 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34089 index 90555bf..f5f1828 100644
34090 --- a/arch/x86/mm/setup_nx.c
34091 +++ b/arch/x86/mm/setup_nx.c
34092 @@ -5,8 +5,10 @@
34093 #include <asm/pgtable.h>
34094 #include <asm/proto.h>
34095
34096 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34097 static int disable_nx;
34098
34099 +#ifndef CONFIG_PAX_PAGEEXEC
34100 /*
34101 * noexec = on|off
34102 *
34103 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34104 return 0;
34105 }
34106 early_param("noexec", noexec_setup);
34107 +#endif
34108 +
34109 +#endif
34110
34111 void x86_configure_nx(void)
34112 {
34113 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34114 if (cpu_has_nx && !disable_nx)
34115 __supported_pte_mask |= _PAGE_NX;
34116 else
34117 +#endif
34118 __supported_pte_mask &= ~_PAGE_NX;
34119 }
34120
34121 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34122 index ee61c36..e6fedeb 100644
34123 --- a/arch/x86/mm/tlb.c
34124 +++ b/arch/x86/mm/tlb.c
34125 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34126 BUG();
34127 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34128 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34129 +
34130 +#ifndef CONFIG_PAX_PER_CPU_PGD
34131 load_cr3(swapper_pg_dir);
34132 +#endif
34133 +
34134 /*
34135 * This gets called in the idle path where RCU
34136 * functions differently. Tracing normally
34137 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34138 new file mode 100644
34139 index 0000000..dace51c
34140 --- /dev/null
34141 +++ b/arch/x86/mm/uderef_64.c
34142 @@ -0,0 +1,37 @@
34143 +#include <linux/mm.h>
34144 +#include <asm/pgtable.h>
34145 +#include <asm/uaccess.h>
34146 +
34147 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34148 +/* PaX: due to the special call convention these functions must
34149 + * - remain leaf functions under all configurations,
34150 + * - never be called directly, only dereferenced from the wrappers.
34151 + */
34152 +void __pax_open_userland(void)
34153 +{
34154 + unsigned int cpu;
34155 +
34156 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34157 + return;
34158 +
34159 + cpu = raw_get_cpu();
34160 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34161 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34162 + raw_put_cpu_no_resched();
34163 +}
34164 +EXPORT_SYMBOL(__pax_open_userland);
34165 +
34166 +void __pax_close_userland(void)
34167 +{
34168 + unsigned int cpu;
34169 +
34170 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34171 + return;
34172 +
34173 + cpu = raw_get_cpu();
34174 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34175 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34176 + raw_put_cpu_no_resched();
34177 +}
34178 +EXPORT_SYMBOL(__pax_close_userland);
34179 +#endif
34180 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34181 index 6440221..f84b5c7 100644
34182 --- a/arch/x86/net/bpf_jit.S
34183 +++ b/arch/x86/net/bpf_jit.S
34184 @@ -9,6 +9,7 @@
34185 */
34186 #include <linux/linkage.h>
34187 #include <asm/dwarf2.h>
34188 +#include <asm/alternative-asm.h>
34189
34190 /*
34191 * Calling convention :
34192 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34193 jle bpf_slow_path_word
34194 mov (SKBDATA,%rsi),%eax
34195 bswap %eax /* ntohl() */
34196 + pax_force_retaddr
34197 ret
34198
34199 sk_load_half:
34200 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34201 jle bpf_slow_path_half
34202 movzwl (SKBDATA,%rsi),%eax
34203 rol $8,%ax # ntohs()
34204 + pax_force_retaddr
34205 ret
34206
34207 sk_load_byte:
34208 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34209 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34210 jle bpf_slow_path_byte
34211 movzbl (SKBDATA,%rsi),%eax
34212 + pax_force_retaddr
34213 ret
34214
34215 /* rsi contains offset and can be scratched */
34216 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34217 js bpf_error
34218 mov - MAX_BPF_STACK + 32(%rbp),%eax
34219 bswap %eax
34220 + pax_force_retaddr
34221 ret
34222
34223 bpf_slow_path_half:
34224 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34225 mov - MAX_BPF_STACK + 32(%rbp),%ax
34226 rol $8,%ax
34227 movzwl %ax,%eax
34228 + pax_force_retaddr
34229 ret
34230
34231 bpf_slow_path_byte:
34232 bpf_slow_path_common(1)
34233 js bpf_error
34234 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34235 + pax_force_retaddr
34236 ret
34237
34238 #define sk_negative_common(SIZE) \
34239 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34240 sk_negative_common(4)
34241 mov (%rax), %eax
34242 bswap %eax
34243 + pax_force_retaddr
34244 ret
34245
34246 bpf_slow_path_half_neg:
34247 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34248 mov (%rax),%ax
34249 rol $8,%ax
34250 movzwl %ax,%eax
34251 + pax_force_retaddr
34252 ret
34253
34254 bpf_slow_path_byte_neg:
34255 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34256 .globl sk_load_byte_negative_offset
34257 sk_negative_common(1)
34258 movzbl (%rax), %eax
34259 + pax_force_retaddr
34260 ret
34261
34262 bpf_error:
34263 @@ -156,4 +166,5 @@ bpf_error:
34264 mov - MAX_BPF_STACK + 16(%rbp),%r14
34265 mov - MAX_BPF_STACK + 24(%rbp),%r15
34266 leaveq
34267 + pax_force_retaddr
34268 ret
34269 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34270 index 3f62734..a57894f 100644
34271 --- a/arch/x86/net/bpf_jit_comp.c
34272 +++ b/arch/x86/net/bpf_jit_comp.c
34273 @@ -13,7 +13,11 @@
34274 #include <linux/if_vlan.h>
34275 #include <asm/cacheflush.h>
34276
34277 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34278 +int bpf_jit_enable __read_only;
34279 +#else
34280 int bpf_jit_enable __read_mostly;
34281 +#endif
34282
34283 /*
34284 * assembly code in arch/x86/net/bpf_jit.S
34285 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34286 static void jit_fill_hole(void *area, unsigned int size)
34287 {
34288 /* fill whole space with int3 instructions */
34289 + pax_open_kernel();
34290 memset(area, 0xcc, size);
34291 + pax_close_kernel();
34292 }
34293
34294 struct jit_context {
34295 @@ -894,7 +900,9 @@ common_load:
34296 pr_err("bpf_jit_compile fatal error\n");
34297 return -EFAULT;
34298 }
34299 + pax_open_kernel();
34300 memcpy(image + proglen, temp, ilen);
34301 + pax_close_kernel();
34302 }
34303 proglen += ilen;
34304 addrs[i] = proglen;
34305 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34306
34307 if (image) {
34308 bpf_flush_icache(header, image + proglen);
34309 - set_memory_ro((unsigned long)header, header->pages);
34310 prog->bpf_func = (void *)image;
34311 prog->jited = true;
34312 }
34313 @@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34314 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34315 struct bpf_binary_header *header = (void *)addr;
34316
34317 - if (!fp->jited)
34318 - goto free_filter;
34319 + if (fp->jited)
34320 + bpf_jit_binary_free(header);
34321
34322 - set_memory_rw(addr, header->pages);
34323 - bpf_jit_binary_free(header);
34324 -
34325 -free_filter:
34326 bpf_prog_unlock_free(fp);
34327 }
34328 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34329 index 5d04be5..2beeaa2 100644
34330 --- a/arch/x86/oprofile/backtrace.c
34331 +++ b/arch/x86/oprofile/backtrace.c
34332 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34333 struct stack_frame_ia32 *fp;
34334 unsigned long bytes;
34335
34336 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34337 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34338 if (bytes != 0)
34339 return NULL;
34340
34341 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34342 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34343
34344 oprofile_add_trace(bufhead[0].return_address);
34345
34346 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34347 struct stack_frame bufhead[2];
34348 unsigned long bytes;
34349
34350 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34351 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34352 if (bytes != 0)
34353 return NULL;
34354
34355 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34356 {
34357 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34358
34359 - if (!user_mode_vm(regs)) {
34360 + if (!user_mode(regs)) {
34361 unsigned long stack = kernel_stack_pointer(regs);
34362 if (depth)
34363 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34364 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34365 index 1d2e639..f6ef82a 100644
34366 --- a/arch/x86/oprofile/nmi_int.c
34367 +++ b/arch/x86/oprofile/nmi_int.c
34368 @@ -23,6 +23,7 @@
34369 #include <asm/nmi.h>
34370 #include <asm/msr.h>
34371 #include <asm/apic.h>
34372 +#include <asm/pgtable.h>
34373
34374 #include "op_counter.h"
34375 #include "op_x86_model.h"
34376 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34377 if (ret)
34378 return ret;
34379
34380 - if (!model->num_virt_counters)
34381 - model->num_virt_counters = model->num_counters;
34382 + if (!model->num_virt_counters) {
34383 + pax_open_kernel();
34384 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34385 + pax_close_kernel();
34386 + }
34387
34388 mux_init(ops);
34389
34390 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34391 index 50d86c0..7985318 100644
34392 --- a/arch/x86/oprofile/op_model_amd.c
34393 +++ b/arch/x86/oprofile/op_model_amd.c
34394 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34395 num_counters = AMD64_NUM_COUNTERS;
34396 }
34397
34398 - op_amd_spec.num_counters = num_counters;
34399 - op_amd_spec.num_controls = num_counters;
34400 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34401 + pax_open_kernel();
34402 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34403 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34404 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34405 + pax_close_kernel();
34406
34407 return 0;
34408 }
34409 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34410 index d90528e..0127e2b 100644
34411 --- a/arch/x86/oprofile/op_model_ppro.c
34412 +++ b/arch/x86/oprofile/op_model_ppro.c
34413 @@ -19,6 +19,7 @@
34414 #include <asm/msr.h>
34415 #include <asm/apic.h>
34416 #include <asm/nmi.h>
34417 +#include <asm/pgtable.h>
34418
34419 #include "op_x86_model.h"
34420 #include "op_counter.h"
34421 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34422
34423 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34424
34425 - op_arch_perfmon_spec.num_counters = num_counters;
34426 - op_arch_perfmon_spec.num_controls = num_counters;
34427 + pax_open_kernel();
34428 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34429 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34430 + pax_close_kernel();
34431 }
34432
34433 static int arch_perfmon_init(struct oprofile_operations *ignore)
34434 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34435 index 71e8a67..6a313bb 100644
34436 --- a/arch/x86/oprofile/op_x86_model.h
34437 +++ b/arch/x86/oprofile/op_x86_model.h
34438 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34439 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34440 struct op_msrs const * const msrs);
34441 #endif
34442 -};
34443 +} __do_const;
34444
34445 struct op_counter_config;
34446
34447 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34448 index b9958c3..24229ab 100644
34449 --- a/arch/x86/pci/intel_mid_pci.c
34450 +++ b/arch/x86/pci/intel_mid_pci.c
34451 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34452 pci_mmcfg_late_init();
34453 pcibios_enable_irq = intel_mid_pci_irq_enable;
34454 pcibios_disable_irq = intel_mid_pci_irq_disable;
34455 - pci_root_ops = intel_mid_pci_ops;
34456 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34457 pci_soc_mode = 1;
34458 /* Continue with standard init */
34459 return 1;
34460 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34461 index eb500c2..eab9e70 100644
34462 --- a/arch/x86/pci/irq.c
34463 +++ b/arch/x86/pci/irq.c
34464 @@ -51,7 +51,7 @@ struct irq_router {
34465 struct irq_router_handler {
34466 u16 vendor;
34467 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34468 -};
34469 +} __do_const;
34470
34471 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34472 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34473 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34474 return 0;
34475 }
34476
34477 -static __initdata struct irq_router_handler pirq_routers[] = {
34478 +static __initconst const struct irq_router_handler pirq_routers[] = {
34479 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34480 { PCI_VENDOR_ID_AL, ali_router_probe },
34481 { PCI_VENDOR_ID_ITE, ite_router_probe },
34482 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34483 static void __init pirq_find_router(struct irq_router *r)
34484 {
34485 struct irq_routing_table *rt = pirq_table;
34486 - struct irq_router_handler *h;
34487 + const struct irq_router_handler *h;
34488
34489 #ifdef CONFIG_PCI_BIOS
34490 if (!rt->signature) {
34491 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34492 return 0;
34493 }
34494
34495 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34496 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34497 {
34498 .callback = fix_broken_hp_bios_irq9,
34499 .ident = "HP Pavilion N5400 Series Laptop",
34500 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34501 index 9b83b90..4112152 100644
34502 --- a/arch/x86/pci/pcbios.c
34503 +++ b/arch/x86/pci/pcbios.c
34504 @@ -79,7 +79,7 @@ union bios32 {
34505 static struct {
34506 unsigned long address;
34507 unsigned short segment;
34508 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34509 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34510
34511 /*
34512 * Returns the entry point for the given service, NULL on error
34513 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34514 unsigned long length; /* %ecx */
34515 unsigned long entry; /* %edx */
34516 unsigned long flags;
34517 + struct desc_struct d, *gdt;
34518
34519 local_irq_save(flags);
34520 - __asm__("lcall *(%%edi); cld"
34521 +
34522 + gdt = get_cpu_gdt_table(smp_processor_id());
34523 +
34524 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34525 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34526 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34527 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34528 +
34529 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34530 : "=a" (return_code),
34531 "=b" (address),
34532 "=c" (length),
34533 "=d" (entry)
34534 : "0" (service),
34535 "1" (0),
34536 - "D" (&bios32_indirect));
34537 + "D" (&bios32_indirect),
34538 + "r"(__PCIBIOS_DS)
34539 + : "memory");
34540 +
34541 + pax_open_kernel();
34542 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34543 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34544 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34545 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34546 + pax_close_kernel();
34547 +
34548 local_irq_restore(flags);
34549
34550 switch (return_code) {
34551 - case 0:
34552 - return address + entry;
34553 - case 0x80: /* Not present */
34554 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34555 - return 0;
34556 - default: /* Shouldn't happen */
34557 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34558 - service, return_code);
34559 + case 0: {
34560 + int cpu;
34561 + unsigned char flags;
34562 +
34563 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34564 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34565 + printk(KERN_WARNING "bios32_service: not valid\n");
34566 return 0;
34567 + }
34568 + address = address + PAGE_OFFSET;
34569 + length += 16UL; /* some BIOSs underreport this... */
34570 + flags = 4;
34571 + if (length >= 64*1024*1024) {
34572 + length >>= PAGE_SHIFT;
34573 + flags |= 8;
34574 + }
34575 +
34576 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34577 + gdt = get_cpu_gdt_table(cpu);
34578 + pack_descriptor(&d, address, length, 0x9b, flags);
34579 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34580 + pack_descriptor(&d, address, length, 0x93, flags);
34581 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34582 + }
34583 + return entry;
34584 + }
34585 + case 0x80: /* Not present */
34586 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34587 + return 0;
34588 + default: /* Shouldn't happen */
34589 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34590 + service, return_code);
34591 + return 0;
34592 }
34593 }
34594
34595 static struct {
34596 unsigned long address;
34597 unsigned short segment;
34598 -} pci_indirect = { 0, __KERNEL_CS };
34599 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34600
34601 -static int pci_bios_present;
34602 +static int pci_bios_present __read_only;
34603
34604 static int __init check_pcibios(void)
34605 {
34606 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34607 unsigned long flags, pcibios_entry;
34608
34609 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34610 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34611 + pci_indirect.address = pcibios_entry;
34612
34613 local_irq_save(flags);
34614 - __asm__(
34615 - "lcall *(%%edi); cld\n\t"
34616 + __asm__("movw %w6, %%ds\n\t"
34617 + "lcall *%%ss:(%%edi); cld\n\t"
34618 + "push %%ss\n\t"
34619 + "pop %%ds\n\t"
34620 "jc 1f\n\t"
34621 "xor %%ah, %%ah\n"
34622 "1:"
34623 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34624 "=b" (ebx),
34625 "=c" (ecx)
34626 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34627 - "D" (&pci_indirect)
34628 + "D" (&pci_indirect),
34629 + "r" (__PCIBIOS_DS)
34630 : "memory");
34631 local_irq_restore(flags);
34632
34633 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34634
34635 switch (len) {
34636 case 1:
34637 - __asm__("lcall *(%%esi); cld\n\t"
34638 + __asm__("movw %w6, %%ds\n\t"
34639 + "lcall *%%ss:(%%esi); cld\n\t"
34640 + "push %%ss\n\t"
34641 + "pop %%ds\n\t"
34642 "jc 1f\n\t"
34643 "xor %%ah, %%ah\n"
34644 "1:"
34645 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34646 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34647 "b" (bx),
34648 "D" ((long)reg),
34649 - "S" (&pci_indirect));
34650 + "S" (&pci_indirect),
34651 + "r" (__PCIBIOS_DS));
34652 /*
34653 * Zero-extend the result beyond 8 bits, do not trust the
34654 * BIOS having done it:
34655 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34656 *value &= 0xff;
34657 break;
34658 case 2:
34659 - __asm__("lcall *(%%esi); cld\n\t"
34660 + __asm__("movw %w6, %%ds\n\t"
34661 + "lcall *%%ss:(%%esi); cld\n\t"
34662 + "push %%ss\n\t"
34663 + "pop %%ds\n\t"
34664 "jc 1f\n\t"
34665 "xor %%ah, %%ah\n"
34666 "1:"
34667 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34668 : "1" (PCIBIOS_READ_CONFIG_WORD),
34669 "b" (bx),
34670 "D" ((long)reg),
34671 - "S" (&pci_indirect));
34672 + "S" (&pci_indirect),
34673 + "r" (__PCIBIOS_DS));
34674 /*
34675 * Zero-extend the result beyond 16 bits, do not trust the
34676 * BIOS having done it:
34677 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34678 *value &= 0xffff;
34679 break;
34680 case 4:
34681 - __asm__("lcall *(%%esi); cld\n\t"
34682 + __asm__("movw %w6, %%ds\n\t"
34683 + "lcall *%%ss:(%%esi); cld\n\t"
34684 + "push %%ss\n\t"
34685 + "pop %%ds\n\t"
34686 "jc 1f\n\t"
34687 "xor %%ah, %%ah\n"
34688 "1:"
34689 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34690 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34691 "b" (bx),
34692 "D" ((long)reg),
34693 - "S" (&pci_indirect));
34694 + "S" (&pci_indirect),
34695 + "r" (__PCIBIOS_DS));
34696 break;
34697 }
34698
34699 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34700
34701 switch (len) {
34702 case 1:
34703 - __asm__("lcall *(%%esi); cld\n\t"
34704 + __asm__("movw %w6, %%ds\n\t"
34705 + "lcall *%%ss:(%%esi); cld\n\t"
34706 + "push %%ss\n\t"
34707 + "pop %%ds\n\t"
34708 "jc 1f\n\t"
34709 "xor %%ah, %%ah\n"
34710 "1:"
34711 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34712 "c" (value),
34713 "b" (bx),
34714 "D" ((long)reg),
34715 - "S" (&pci_indirect));
34716 + "S" (&pci_indirect),
34717 + "r" (__PCIBIOS_DS));
34718 break;
34719 case 2:
34720 - __asm__("lcall *(%%esi); cld\n\t"
34721 + __asm__("movw %w6, %%ds\n\t"
34722 + "lcall *%%ss:(%%esi); cld\n\t"
34723 + "push %%ss\n\t"
34724 + "pop %%ds\n\t"
34725 "jc 1f\n\t"
34726 "xor %%ah, %%ah\n"
34727 "1:"
34728 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34729 "c" (value),
34730 "b" (bx),
34731 "D" ((long)reg),
34732 - "S" (&pci_indirect));
34733 + "S" (&pci_indirect),
34734 + "r" (__PCIBIOS_DS));
34735 break;
34736 case 4:
34737 - __asm__("lcall *(%%esi); cld\n\t"
34738 + __asm__("movw %w6, %%ds\n\t"
34739 + "lcall *%%ss:(%%esi); cld\n\t"
34740 + "push %%ss\n\t"
34741 + "pop %%ds\n\t"
34742 "jc 1f\n\t"
34743 "xor %%ah, %%ah\n"
34744 "1:"
34745 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34746 "c" (value),
34747 "b" (bx),
34748 "D" ((long)reg),
34749 - "S" (&pci_indirect));
34750 + "S" (&pci_indirect),
34751 + "r" (__PCIBIOS_DS));
34752 break;
34753 }
34754
34755 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34756
34757 DBG("PCI: Fetching IRQ routing table... ");
34758 __asm__("push %%es\n\t"
34759 + "movw %w8, %%ds\n\t"
34760 "push %%ds\n\t"
34761 "pop %%es\n\t"
34762 - "lcall *(%%esi); cld\n\t"
34763 + "lcall *%%ss:(%%esi); cld\n\t"
34764 "pop %%es\n\t"
34765 + "push %%ss\n\t"
34766 + "pop %%ds\n"
34767 "jc 1f\n\t"
34768 "xor %%ah, %%ah\n"
34769 "1:"
34770 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34771 "1" (0),
34772 "D" ((long) &opt),
34773 "S" (&pci_indirect),
34774 - "m" (opt)
34775 + "m" (opt),
34776 + "r" (__PCIBIOS_DS)
34777 : "memory");
34778 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34779 if (ret & 0xff00)
34780 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34781 {
34782 int ret;
34783
34784 - __asm__("lcall *(%%esi); cld\n\t"
34785 + __asm__("movw %w5, %%ds\n\t"
34786 + "lcall *%%ss:(%%esi); cld\n\t"
34787 + "push %%ss\n\t"
34788 + "pop %%ds\n"
34789 "jc 1f\n\t"
34790 "xor %%ah, %%ah\n"
34791 "1:"
34792 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34793 : "0" (PCIBIOS_SET_PCI_HW_INT),
34794 "b" ((dev->bus->number << 8) | dev->devfn),
34795 "c" ((irq << 8) | (pin + 10)),
34796 - "S" (&pci_indirect));
34797 + "S" (&pci_indirect),
34798 + "r" (__PCIBIOS_DS));
34799 return !(ret & 0xff00);
34800 }
34801 EXPORT_SYMBOL(pcibios_set_irq_routing);
34802 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34803 index 40e7cda..c7e6672 100644
34804 --- a/arch/x86/platform/efi/efi_32.c
34805 +++ b/arch/x86/platform/efi/efi_32.c
34806 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34807 {
34808 struct desc_ptr gdt_descr;
34809
34810 +#ifdef CONFIG_PAX_KERNEXEC
34811 + struct desc_struct d;
34812 +#endif
34813 +
34814 local_irq_save(efi_rt_eflags);
34815
34816 load_cr3(initial_page_table);
34817 __flush_tlb_all();
34818
34819 +#ifdef CONFIG_PAX_KERNEXEC
34820 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34821 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34822 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34823 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34824 +#endif
34825 +
34826 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34827 gdt_descr.size = GDT_SIZE - 1;
34828 load_gdt(&gdt_descr);
34829 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34830 {
34831 struct desc_ptr gdt_descr;
34832
34833 +#ifdef CONFIG_PAX_KERNEXEC
34834 + struct desc_struct d;
34835 +
34836 + memset(&d, 0, sizeof d);
34837 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34838 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34839 +#endif
34840 +
34841 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34842 gdt_descr.size = GDT_SIZE - 1;
34843 load_gdt(&gdt_descr);
34844
34845 +#ifdef CONFIG_PAX_PER_CPU_PGD
34846 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34847 +#else
34848 load_cr3(swapper_pg_dir);
34849 +#endif
34850 +
34851 __flush_tlb_all();
34852
34853 local_irq_restore(efi_rt_eflags);
34854 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34855 index 35aecb6..46177db 100644
34856 --- a/arch/x86/platform/efi/efi_64.c
34857 +++ b/arch/x86/platform/efi/efi_64.c
34858 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34859 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34860 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34861 }
34862 +
34863 +#ifdef CONFIG_PAX_PER_CPU_PGD
34864 + load_cr3(swapper_pg_dir);
34865 +#endif
34866 +
34867 __flush_tlb_all();
34868 }
34869
34870 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34871 for (pgd = 0; pgd < n_pgds; pgd++)
34872 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34873 kfree(save_pgd);
34874 +
34875 +#ifdef CONFIG_PAX_PER_CPU_PGD
34876 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34877 +#endif
34878 +
34879 __flush_tlb_all();
34880 local_irq_restore(efi_flags);
34881 early_code_mapping_set_exec(0);
34882 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34883 unsigned npages;
34884 pgd_t *pgd;
34885
34886 - if (efi_enabled(EFI_OLD_MEMMAP))
34887 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34888 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34889 + * able to execute the EFI services.
34890 + */
34891 + if (__supported_pte_mask & _PAGE_NX) {
34892 + unsigned long addr = (unsigned long) __va(0);
34893 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34894 +
34895 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34896 +#ifdef CONFIG_PAX_PER_CPU_PGD
34897 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34898 +#endif
34899 + set_pgd(pgd_offset_k(addr), pe);
34900 + }
34901 +
34902 return 0;
34903 + }
34904
34905 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34906 pgd = __va(efi_scratch.efi_pgt);
34907 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34908 index 040192b..7d3300f 100644
34909 --- a/arch/x86/platform/efi/efi_stub_32.S
34910 +++ b/arch/x86/platform/efi/efi_stub_32.S
34911 @@ -6,7 +6,9 @@
34912 */
34913
34914 #include <linux/linkage.h>
34915 +#include <linux/init.h>
34916 #include <asm/page_types.h>
34917 +#include <asm/segment.h>
34918
34919 /*
34920 * efi_call_phys(void *, ...) is a function with variable parameters.
34921 @@ -20,7 +22,7 @@
34922 * service functions will comply with gcc calling convention, too.
34923 */
34924
34925 -.text
34926 +__INIT
34927 ENTRY(efi_call_phys)
34928 /*
34929 * 0. The function can only be called in Linux kernel. So CS has been
34930 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34931 * The mapping of lower virtual memory has been created in prolog and
34932 * epilog.
34933 */
34934 - movl $1f, %edx
34935 - subl $__PAGE_OFFSET, %edx
34936 - jmp *%edx
34937 +#ifdef CONFIG_PAX_KERNEXEC
34938 + movl $(__KERNEXEC_EFI_DS), %edx
34939 + mov %edx, %ds
34940 + mov %edx, %es
34941 + mov %edx, %ss
34942 + addl $2f,(1f)
34943 + ljmp *(1f)
34944 +
34945 +__INITDATA
34946 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34947 +.previous
34948 +
34949 +2:
34950 + subl $2b,(1b)
34951 +#else
34952 + jmp 1f-__PAGE_OFFSET
34953 1:
34954 +#endif
34955
34956 /*
34957 * 2. Now on the top of stack is the return
34958 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34959 * parameter 2, ..., param n. To make things easy, we save the return
34960 * address of efi_call_phys in a global variable.
34961 */
34962 - popl %edx
34963 - movl %edx, saved_return_addr
34964 - /* get the function pointer into ECX*/
34965 - popl %ecx
34966 - movl %ecx, efi_rt_function_ptr
34967 - movl $2f, %edx
34968 - subl $__PAGE_OFFSET, %edx
34969 - pushl %edx
34970 + popl (saved_return_addr)
34971 + popl (efi_rt_function_ptr)
34972
34973 /*
34974 * 3. Clear PG bit in %CR0.
34975 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34976 /*
34977 * 5. Call the physical function.
34978 */
34979 - jmp *%ecx
34980 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34981
34982 -2:
34983 /*
34984 * 6. After EFI runtime service returns, control will return to
34985 * following instruction. We'd better readjust stack pointer first.
34986 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34987 movl %cr0, %edx
34988 orl $0x80000000, %edx
34989 movl %edx, %cr0
34990 - jmp 1f
34991 -1:
34992 +
34993 /*
34994 * 8. Now restore the virtual mode from flat mode by
34995 * adding EIP with PAGE_OFFSET.
34996 */
34997 - movl $1f, %edx
34998 - jmp *%edx
34999 +#ifdef CONFIG_PAX_KERNEXEC
35000 + movl $(__KERNEL_DS), %edx
35001 + mov %edx, %ds
35002 + mov %edx, %es
35003 + mov %edx, %ss
35004 + ljmp $(__KERNEL_CS),$1f
35005 +#else
35006 + jmp 1f+__PAGE_OFFSET
35007 +#endif
35008 1:
35009
35010 /*
35011 * 9. Balance the stack. And because EAX contain the return value,
35012 * we'd better not clobber it.
35013 */
35014 - leal efi_rt_function_ptr, %edx
35015 - movl (%edx), %ecx
35016 - pushl %ecx
35017 + pushl (efi_rt_function_ptr)
35018
35019 /*
35020 - * 10. Push the saved return address onto the stack and return.
35021 + * 10. Return to the saved return address.
35022 */
35023 - leal saved_return_addr, %edx
35024 - movl (%edx), %ecx
35025 - pushl %ecx
35026 - ret
35027 + jmpl *(saved_return_addr)
35028 ENDPROC(efi_call_phys)
35029 .previous
35030
35031 -.data
35032 +__INITDATA
35033 saved_return_addr:
35034 .long 0
35035 efi_rt_function_ptr:
35036 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35037 index 5fcda72..cd4dc41 100644
35038 --- a/arch/x86/platform/efi/efi_stub_64.S
35039 +++ b/arch/x86/platform/efi/efi_stub_64.S
35040 @@ -11,6 +11,7 @@
35041 #include <asm/msr.h>
35042 #include <asm/processor-flags.h>
35043 #include <asm/page_types.h>
35044 +#include <asm/alternative-asm.h>
35045
35046 #define SAVE_XMM \
35047 mov %rsp, %rax; \
35048 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35049 RESTORE_PGT
35050 addq $48, %rsp
35051 RESTORE_XMM
35052 + pax_force_retaddr 0, 1
35053 ret
35054 ENDPROC(efi_call)
35055
35056 @@ -245,8 +247,8 @@ efi_gdt64:
35057 .long 0 /* Filled out by user */
35058 .word 0
35059 .quad 0x0000000000000000 /* NULL descriptor */
35060 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
35061 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
35062 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
35063 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
35064 .quad 0x0080890000000000 /* TS descriptor */
35065 .quad 0x0000000000000000 /* TS continued */
35066 efi_gdt64_end:
35067 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35068 index 1bbedc4..eb795b5 100644
35069 --- a/arch/x86/platform/intel-mid/intel-mid.c
35070 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35071 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35072 {
35073 };
35074
35075 -static void intel_mid_reboot(void)
35076 +static void __noreturn intel_mid_reboot(void)
35077 {
35078 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35079 + BUG();
35080 }
35081
35082 static unsigned long __init intel_mid_calibrate_tsc(void)
35083 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35084 index 3c1c386..59a68ed 100644
35085 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35086 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35087 @@ -13,6 +13,6 @@
35088 /* For every CPU addition a new get_<cpuname>_ops interface needs
35089 * to be added.
35090 */
35091 -extern void *get_penwell_ops(void);
35092 -extern void *get_cloverview_ops(void);
35093 -extern void *get_tangier_ops(void);
35094 +extern const void *get_penwell_ops(void);
35095 +extern const void *get_cloverview_ops(void);
35096 +extern const void *get_tangier_ops(void);
35097 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35098 index 23381d2..8ddc10e 100644
35099 --- a/arch/x86/platform/intel-mid/mfld.c
35100 +++ b/arch/x86/platform/intel-mid/mfld.c
35101 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35102 pm_power_off = mfld_power_off;
35103 }
35104
35105 -void *get_penwell_ops(void)
35106 +const void *get_penwell_ops(void)
35107 {
35108 return &penwell_ops;
35109 }
35110
35111 -void *get_cloverview_ops(void)
35112 +const void *get_cloverview_ops(void)
35113 {
35114 return &penwell_ops;
35115 }
35116 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35117 index aaca917..66eadbc 100644
35118 --- a/arch/x86/platform/intel-mid/mrfl.c
35119 +++ b/arch/x86/platform/intel-mid/mrfl.c
35120 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35121 .arch_setup = tangier_arch_setup,
35122 };
35123
35124 -void *get_tangier_ops(void)
35125 +const void *get_tangier_ops(void)
35126 {
35127 return &tangier_ops;
35128 }
35129 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35130 index d6ee929..3637cb5 100644
35131 --- a/arch/x86/platform/olpc/olpc_dt.c
35132 +++ b/arch/x86/platform/olpc/olpc_dt.c
35133 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35134 return res;
35135 }
35136
35137 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35138 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35139 .nextprop = olpc_dt_nextprop,
35140 .getproplen = olpc_dt_getproplen,
35141 .getproperty = olpc_dt_getproperty,
35142 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35143 index 6ec7910..ecdbb11 100644
35144 --- a/arch/x86/power/cpu.c
35145 +++ b/arch/x86/power/cpu.c
35146 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35147 static void fix_processor_context(void)
35148 {
35149 int cpu = smp_processor_id();
35150 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35151 -#ifdef CONFIG_X86_64
35152 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35153 - tss_desc tss;
35154 -#endif
35155 + struct tss_struct *t = init_tss + cpu;
35156 +
35157 set_tss_desc(cpu, t); /*
35158 * This just modifies memory; should not be
35159 * necessary. But... This is necessary, because
35160 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35161 */
35162
35163 #ifdef CONFIG_X86_64
35164 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35165 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35166 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35167 -
35168 syscall_init(); /* This sets MSR_*STAR and related */
35169 #endif
35170 load_TR_desc(); /* This does ltr */
35171 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35172 index bad628a..a102610 100644
35173 --- a/arch/x86/realmode/init.c
35174 +++ b/arch/x86/realmode/init.c
35175 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35176 __va(real_mode_header->trampoline_header);
35177
35178 #ifdef CONFIG_X86_32
35179 - trampoline_header->start = __pa_symbol(startup_32_smp);
35180 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35181 +
35182 +#ifdef CONFIG_PAX_KERNEXEC
35183 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35184 +#endif
35185 +
35186 + trampoline_header->boot_cs = __BOOT_CS;
35187 trampoline_header->gdt_limit = __BOOT_DS + 7;
35188 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35189 #else
35190 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35191 *trampoline_cr4_features = read_cr4();
35192
35193 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35194 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35195 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35196 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35197 #endif
35198 }
35199 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35200 index 7c0d7be..d24dc88 100644
35201 --- a/arch/x86/realmode/rm/Makefile
35202 +++ b/arch/x86/realmode/rm/Makefile
35203 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35204
35205 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35206 -I$(srctree)/arch/x86/boot
35207 +ifdef CONSTIFY_PLUGIN
35208 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35209 +endif
35210 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35211 GCOV_PROFILE := n
35212 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35213 index a28221d..93c40f1 100644
35214 --- a/arch/x86/realmode/rm/header.S
35215 +++ b/arch/x86/realmode/rm/header.S
35216 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35217 #endif
35218 /* APM/BIOS reboot */
35219 .long pa_machine_real_restart_asm
35220 -#ifdef CONFIG_X86_64
35221 +#ifdef CONFIG_X86_32
35222 + .long __KERNEL_CS
35223 +#else
35224 .long __KERNEL32_CS
35225 #endif
35226 END(real_mode_header)
35227 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35228 index 48ddd76..c26749f 100644
35229 --- a/arch/x86/realmode/rm/trampoline_32.S
35230 +++ b/arch/x86/realmode/rm/trampoline_32.S
35231 @@ -24,6 +24,12 @@
35232 #include <asm/page_types.h>
35233 #include "realmode.h"
35234
35235 +#ifdef CONFIG_PAX_KERNEXEC
35236 +#define ta(X) (X)
35237 +#else
35238 +#define ta(X) (pa_ ## X)
35239 +#endif
35240 +
35241 .text
35242 .code16
35243
35244 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35245
35246 cli # We should be safe anyway
35247
35248 - movl tr_start, %eax # where we need to go
35249 -
35250 movl $0xA5A5A5A5, trampoline_status
35251 # write marker for master knows we're running
35252
35253 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35254 movw $1, %dx # protected mode (PE) bit
35255 lmsw %dx # into protected mode
35256
35257 - ljmpl $__BOOT_CS, $pa_startup_32
35258 + ljmpl *(trampoline_header)
35259
35260 .section ".text32","ax"
35261 .code32
35262 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35263 .balign 8
35264 GLOBAL(trampoline_header)
35265 tr_start: .space 4
35266 - tr_gdt_pad: .space 2
35267 + tr_boot_cs: .space 2
35268 tr_gdt: .space 6
35269 END(trampoline_header)
35270
35271 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35272 index dac7b20..72dbaca 100644
35273 --- a/arch/x86/realmode/rm/trampoline_64.S
35274 +++ b/arch/x86/realmode/rm/trampoline_64.S
35275 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35276 movl %edx, %gs
35277
35278 movl pa_tr_cr4, %eax
35279 + andl $~X86_CR4_PCIDE, %eax
35280 movl %eax, %cr4 # Enable PAE mode
35281
35282 # Setup trampoline 4 level pagetables
35283 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35284 wrmsr
35285
35286 # Enable paging and in turn activate Long Mode
35287 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35288 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35289 movl %eax, %cr0
35290
35291 /*
35292 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35293 index 9e7e147..25a4158 100644
35294 --- a/arch/x86/realmode/rm/wakeup_asm.S
35295 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35296 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35297 lgdtl pmode_gdt
35298
35299 /* This really couldn't... */
35300 - movl pmode_entry, %eax
35301 movl pmode_cr0, %ecx
35302 movl %ecx, %cr0
35303 - ljmpl $__KERNEL_CS, $pa_startup_32
35304 - /* -> jmp *%eax in trampoline_32.S */
35305 +
35306 + ljmpl *pmode_entry
35307 #else
35308 jmp trampoline_start
35309 #endif
35310 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35311 index 604a37e..e49702a 100644
35312 --- a/arch/x86/tools/Makefile
35313 +++ b/arch/x86/tools/Makefile
35314 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35315
35316 $(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
35317
35318 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35319 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35320 hostprogs-y += relocs
35321 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35322 PHONY += relocs
35323 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35324 index a5efb21..97490e9 100644
35325 --- a/arch/x86/tools/relocs.c
35326 +++ b/arch/x86/tools/relocs.c
35327 @@ -1,5 +1,7 @@
35328 /* This is included from relocs_32/64.c */
35329
35330 +#include "../../../include/generated/autoconf.h"
35331 +
35332 #define ElfW(type) _ElfW(ELF_BITS, type)
35333 #define _ElfW(bits, type) __ElfW(bits, type)
35334 #define __ElfW(bits, type) Elf##bits##_##type
35335 @@ -11,6 +13,7 @@
35336 #define Elf_Sym ElfW(Sym)
35337
35338 static Elf_Ehdr ehdr;
35339 +static Elf_Phdr *phdr;
35340
35341 struct relocs {
35342 uint32_t *offset;
35343 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35344 }
35345 }
35346
35347 +static void read_phdrs(FILE *fp)
35348 +{
35349 + unsigned int i;
35350 +
35351 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35352 + if (!phdr) {
35353 + die("Unable to allocate %d program headers\n",
35354 + ehdr.e_phnum);
35355 + }
35356 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35357 + die("Seek to %d failed: %s\n",
35358 + ehdr.e_phoff, strerror(errno));
35359 + }
35360 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35361 + die("Cannot read ELF program headers: %s\n",
35362 + strerror(errno));
35363 + }
35364 + for(i = 0; i < ehdr.e_phnum; i++) {
35365 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35366 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35367 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35368 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35369 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35370 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35371 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35372 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35373 + }
35374 +
35375 +}
35376 +
35377 static void read_shdrs(FILE *fp)
35378 {
35379 - int i;
35380 + unsigned int i;
35381 Elf_Shdr shdr;
35382
35383 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35384 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35385
35386 static void read_strtabs(FILE *fp)
35387 {
35388 - int i;
35389 + unsigned int i;
35390 for (i = 0; i < ehdr.e_shnum; i++) {
35391 struct section *sec = &secs[i];
35392 if (sec->shdr.sh_type != SHT_STRTAB) {
35393 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35394
35395 static void read_symtabs(FILE *fp)
35396 {
35397 - int i,j;
35398 + unsigned int i,j;
35399 for (i = 0; i < ehdr.e_shnum; i++) {
35400 struct section *sec = &secs[i];
35401 if (sec->shdr.sh_type != SHT_SYMTAB) {
35402 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35403 }
35404
35405
35406 -static void read_relocs(FILE *fp)
35407 +static void read_relocs(FILE *fp, int use_real_mode)
35408 {
35409 - int i,j;
35410 + unsigned int i,j;
35411 + uint32_t base;
35412 +
35413 for (i = 0; i < ehdr.e_shnum; i++) {
35414 struct section *sec = &secs[i];
35415 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35416 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35417 die("Cannot read symbol table: %s\n",
35418 strerror(errno));
35419 }
35420 + base = 0;
35421 +
35422 +#ifdef CONFIG_X86_32
35423 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35424 + if (phdr[j].p_type != PT_LOAD )
35425 + continue;
35426 + 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)
35427 + continue;
35428 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35429 + break;
35430 + }
35431 +#endif
35432 +
35433 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35434 Elf_Rel *rel = &sec->reltab[j];
35435 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35436 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35437 rel->r_info = elf_xword_to_cpu(rel->r_info);
35438 #if (SHT_REL_TYPE == SHT_RELA)
35439 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35440 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35441
35442 static void print_absolute_symbols(void)
35443 {
35444 - int i;
35445 + unsigned int i;
35446 const char *format;
35447
35448 if (ELF_BITS == 64)
35449 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35450 for (i = 0; i < ehdr.e_shnum; i++) {
35451 struct section *sec = &secs[i];
35452 char *sym_strtab;
35453 - int j;
35454 + unsigned int j;
35455
35456 if (sec->shdr.sh_type != SHT_SYMTAB) {
35457 continue;
35458 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35459
35460 static void print_absolute_relocs(void)
35461 {
35462 - int i, printed = 0;
35463 + unsigned int i, printed = 0;
35464 const char *format;
35465
35466 if (ELF_BITS == 64)
35467 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35468 struct section *sec_applies, *sec_symtab;
35469 char *sym_strtab;
35470 Elf_Sym *sh_symtab;
35471 - int j;
35472 + unsigned int j;
35473 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35474 continue;
35475 }
35476 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35477 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35478 Elf_Sym *sym, const char *symname))
35479 {
35480 - int i;
35481 + unsigned int i;
35482 /* Walk through the relocations */
35483 for (i = 0; i < ehdr.e_shnum; i++) {
35484 char *sym_strtab;
35485 Elf_Sym *sh_symtab;
35486 struct section *sec_applies, *sec_symtab;
35487 - int j;
35488 + unsigned int j;
35489 struct section *sec = &secs[i];
35490
35491 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35492 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35493 {
35494 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35495 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35496 + char *sym_strtab = sec->link->link->strtab;
35497 +
35498 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35499 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35500 + return 0;
35501 +
35502 +#ifdef CONFIG_PAX_KERNEXEC
35503 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35504 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35505 + return 0;
35506 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35507 + return 0;
35508 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35509 + return 0;
35510 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35511 + return 0;
35512 +#endif
35513
35514 switch (r_type) {
35515 case R_386_NONE:
35516 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35517
35518 static void emit_relocs(int as_text, int use_real_mode)
35519 {
35520 - int i;
35521 + unsigned int i;
35522 int (*write_reloc)(uint32_t, FILE *) = write32;
35523 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35524 const char *symname);
35525 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35526 {
35527 regex_init(use_real_mode);
35528 read_ehdr(fp);
35529 + read_phdrs(fp);
35530 read_shdrs(fp);
35531 read_strtabs(fp);
35532 read_symtabs(fp);
35533 - read_relocs(fp);
35534 + read_relocs(fp, use_real_mode);
35535 if (ELF_BITS == 64)
35536 percpu_init();
35537 if (show_absolute_syms) {
35538 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35539 index f40281e..92728c9 100644
35540 --- a/arch/x86/um/mem_32.c
35541 +++ b/arch/x86/um/mem_32.c
35542 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35543 gate_vma.vm_start = FIXADDR_USER_START;
35544 gate_vma.vm_end = FIXADDR_USER_END;
35545 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35546 - gate_vma.vm_page_prot = __P101;
35547 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35548
35549 return 0;
35550 }
35551 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35552 index 80ffa5b..a33bd15 100644
35553 --- a/arch/x86/um/tls_32.c
35554 +++ b/arch/x86/um/tls_32.c
35555 @@ -260,7 +260,7 @@ out:
35556 if (unlikely(task == current &&
35557 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35558 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35559 - "without flushed TLS.", current->pid);
35560 + "without flushed TLS.", task_pid_nr(current));
35561 }
35562
35563 return 0;
35564 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35565 index 5a4affe..9e2d522 100644
35566 --- a/arch/x86/vdso/Makefile
35567 +++ b/arch/x86/vdso/Makefile
35568 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35569 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35570 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35571
35572 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35573 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35574 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35575 GCOV_PROFILE := n
35576
35577 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35578 index 0224987..c7d65a5 100644
35579 --- a/arch/x86/vdso/vdso2c.h
35580 +++ b/arch/x86/vdso/vdso2c.h
35581 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35582 unsigned long load_size = -1; /* Work around bogus warning */
35583 unsigned long mapping_size;
35584 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35585 - int i;
35586 + unsigned int i;
35587 unsigned long j;
35588 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35589 *alt_sec = NULL;
35590 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35591 index e904c27..b9eaa03 100644
35592 --- a/arch/x86/vdso/vdso32-setup.c
35593 +++ b/arch/x86/vdso/vdso32-setup.c
35594 @@ -14,6 +14,7 @@
35595 #include <asm/cpufeature.h>
35596 #include <asm/processor.h>
35597 #include <asm/vdso.h>
35598 +#include <asm/mman.h>
35599
35600 #ifdef CONFIG_COMPAT_VDSO
35601 #define VDSO_DEFAULT 0
35602 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35603 index 208c220..54f1447 100644
35604 --- a/arch/x86/vdso/vma.c
35605 +++ b/arch/x86/vdso/vma.c
35606 @@ -16,10 +16,9 @@
35607 #include <asm/vdso.h>
35608 #include <asm/page.h>
35609 #include <asm/hpet.h>
35610 +#include <asm/mman.h>
35611
35612 #if defined(CONFIG_X86_64)
35613 -unsigned int __read_mostly vdso64_enabled = 1;
35614 -
35615 extern unsigned short vdso_sync_cpuid;
35616 #endif
35617
35618 @@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35619 .pages = no_pages,
35620 };
35621
35622 +#ifdef CONFIG_PAX_RANDMMAP
35623 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35624 + calculate_addr = false;
35625 +#endif
35626 +
35627 if (calculate_addr) {
35628 addr = vdso_addr(current->mm->start_stack,
35629 image->size - image->sym_vvar_start);
35630 @@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35631 down_write(&mm->mmap_sem);
35632
35633 addr = get_unmapped_area(NULL, addr,
35634 - image->size - image->sym_vvar_start, 0, 0);
35635 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35636 if (IS_ERR_VALUE(addr)) {
35637 ret = addr;
35638 goto up_fail;
35639 }
35640
35641 text_start = addr - image->sym_vvar_start;
35642 - current->mm->context.vdso = (void __user *)text_start;
35643 + mm->context.vdso = text_start;
35644
35645 /*
35646 * MAYWRITE to allow gdb to COW and set breakpoints
35647 @@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35648 hpet_address >> PAGE_SHIFT,
35649 PAGE_SIZE,
35650 pgprot_noncached(PAGE_READONLY));
35651 -
35652 - if (ret)
35653 - goto up_fail;
35654 }
35655 #endif
35656
35657 up_fail:
35658 if (ret)
35659 - current->mm->context.vdso = NULL;
35660 + current->mm->context.vdso = 0;
35661
35662 up_write(&mm->mmap_sem);
35663 return ret;
35664 @@ -204,8 +205,8 @@ static int load_vdso32(void)
35665
35666 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35667 current_thread_info()->sysenter_return =
35668 - current->mm->context.vdso +
35669 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35670 + (void __force_user *)(current->mm->context.vdso +
35671 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35672
35673 return 0;
35674 }
35675 @@ -214,9 +215,6 @@ static int load_vdso32(void)
35676 #ifdef CONFIG_X86_64
35677 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35678 {
35679 - if (!vdso64_enabled)
35680 - return 0;
35681 -
35682 return map_vdso(&vdso_image_64, true);
35683 }
35684
35685 @@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35686 int uses_interp)
35687 {
35688 #ifdef CONFIG_X86_X32_ABI
35689 - if (test_thread_flag(TIF_X32)) {
35690 - if (!vdso64_enabled)
35691 - return 0;
35692 -
35693 + if (test_thread_flag(TIF_X32))
35694 return map_vdso(&vdso_image_x32, true);
35695 - }
35696 #endif
35697
35698 return load_vdso32();
35699 @@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35700 return load_vdso32();
35701 }
35702 #endif
35703 -
35704 -#ifdef CONFIG_X86_64
35705 -static __init int vdso_setup(char *s)
35706 -{
35707 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35708 - return 0;
35709 -}
35710 -__setup("vdso=", vdso_setup);
35711 -#endif
35712 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35713 index e88fda8..76ce7ce 100644
35714 --- a/arch/x86/xen/Kconfig
35715 +++ b/arch/x86/xen/Kconfig
35716 @@ -9,6 +9,7 @@ config XEN
35717 select XEN_HAVE_PVMMU
35718 depends on X86_64 || (X86_32 && X86_PAE)
35719 depends on X86_TSC
35720 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35721 help
35722 This is the Linux Xen port. Enabling this will allow the
35723 kernel to boot in a paravirtualized environment under the
35724 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35725 index fac5e4f..e421c18 100644
35726 --- a/arch/x86/xen/enlighten.c
35727 +++ b/arch/x86/xen/enlighten.c
35728 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35729
35730 struct shared_info xen_dummy_shared_info;
35731
35732 -void *xen_initial_gdt;
35733 -
35734 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35735 __read_mostly int xen_have_vector_callback;
35736 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35737 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35738 {
35739 unsigned long va = dtr->address;
35740 unsigned int size = dtr->size + 1;
35741 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35742 - unsigned long frames[pages];
35743 + unsigned long frames[65536 / PAGE_SIZE];
35744 int f;
35745
35746 /*
35747 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35748 {
35749 unsigned long va = dtr->address;
35750 unsigned int size = dtr->size + 1;
35751 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35752 - unsigned long frames[pages];
35753 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35754 int f;
35755
35756 /*
35757 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35758 * 8-byte entries, or 16 4k pages..
35759 */
35760
35761 - BUG_ON(size > 65536);
35762 + BUG_ON(size > GDT_SIZE);
35763 BUG_ON(va & ~PAGE_MASK);
35764
35765 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35766 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35767 return 0;
35768 }
35769
35770 -static void set_xen_basic_apic_ops(void)
35771 +static void __init set_xen_basic_apic_ops(void)
35772 {
35773 apic->read = xen_apic_read;
35774 apic->write = xen_apic_write;
35775 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35776 #endif
35777 };
35778
35779 -static void xen_reboot(int reason)
35780 +static __noreturn void xen_reboot(int reason)
35781 {
35782 struct sched_shutdown r = { .reason = reason };
35783
35784 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35785 - BUG();
35786 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35787 + BUG();
35788 }
35789
35790 -static void xen_restart(char *msg)
35791 +static __noreturn void xen_restart(char *msg)
35792 {
35793 xen_reboot(SHUTDOWN_reboot);
35794 }
35795
35796 -static void xen_emergency_restart(void)
35797 +static __noreturn void xen_emergency_restart(void)
35798 {
35799 xen_reboot(SHUTDOWN_reboot);
35800 }
35801
35802 -static void xen_machine_halt(void)
35803 +static __noreturn void xen_machine_halt(void)
35804 {
35805 xen_reboot(SHUTDOWN_poweroff);
35806 }
35807
35808 -static void xen_machine_power_off(void)
35809 +static __noreturn void xen_machine_power_off(void)
35810 {
35811 if (pm_power_off)
35812 pm_power_off();
35813 @@ -1456,8 +1452,9 @@ static void __ref xen_setup_gdt(int cpu)
35814 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35815 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35816
35817 - setup_stack_canary_segment(0);
35818 - switch_to_new_gdt(0);
35819 + setup_stack_canary_segment(cpu);
35820 + load_percpu_segment(cpu);
35821 + switch_to_new_gdt(cpu);
35822
35823 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35824 pv_cpu_ops.load_gdt = xen_load_gdt;
35825 @@ -1573,7 +1570,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35826 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35827
35828 /* Work out if we support NX */
35829 - x86_configure_nx();
35830 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35831 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35832 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35833 + unsigned l, h;
35834 +
35835 + __supported_pte_mask |= _PAGE_NX;
35836 + rdmsr(MSR_EFER, l, h);
35837 + l |= EFER_NX;
35838 + wrmsr(MSR_EFER, l, h);
35839 + }
35840 +#endif
35841
35842 /* Get mfn list */
35843 xen_build_dynamic_phys_to_machine();
35844 @@ -1601,13 +1608,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35845
35846 machine_ops = xen_machine_ops;
35847
35848 - /*
35849 - * The only reliable way to retain the initial address of the
35850 - * percpu gdt_page is to remember it here, so we can go and
35851 - * mark it RW later, when the initial percpu area is freed.
35852 - */
35853 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35854 -
35855 xen_smp_init();
35856
35857 #ifdef CONFIG_ACPI_NUMA
35858 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35859 index a8a1a3d..8216142 100644
35860 --- a/arch/x86/xen/mmu.c
35861 +++ b/arch/x86/xen/mmu.c
35862 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35863 return val;
35864 }
35865
35866 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35867 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35868 {
35869 if (val & _PAGE_PRESENT) {
35870 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35871 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35872 * L3_k[511] -> level2_fixmap_pgt */
35873 convert_pfn_mfn(level3_kernel_pgt);
35874
35875 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35876 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35877 + convert_pfn_mfn(level3_vmemmap_pgt);
35878 /* L3_k[511][506] -> level1_fixmap_pgt */
35879 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35880 convert_pfn_mfn(level2_fixmap_pgt);
35881 }
35882 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35883 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35884 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35885 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35886 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35887 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35888 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35889 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35890 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35891 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35892 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35893 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35894 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35895 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35896 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35897
35898 /* Pin down new L4 */
35899 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35900 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35901 pv_mmu_ops.set_pud = xen_set_pud;
35902 #if PAGETABLE_LEVELS == 4
35903 pv_mmu_ops.set_pgd = xen_set_pgd;
35904 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35905 #endif
35906
35907 /* This will work as long as patching hasn't happened yet
35908 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35909 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35910 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35911 .set_pgd = xen_set_pgd_hyper,
35912 + .set_pgd_batched = xen_set_pgd_hyper,
35913
35914 .alloc_pud = xen_alloc_pmd_init,
35915 .release_pud = xen_release_pmd_init,
35916 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35917 index 4c071ae..00e7049 100644
35918 --- a/arch/x86/xen/smp.c
35919 +++ b/arch/x86/xen/smp.c
35920 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35921
35922 if (xen_pv_domain()) {
35923 if (!xen_feature(XENFEAT_writable_page_tables))
35924 - /* We've switched to the "real" per-cpu gdt, so make
35925 - * sure the old memory can be recycled. */
35926 - make_lowmem_page_readwrite(xen_initial_gdt);
35927 -
35928 #ifdef CONFIG_X86_32
35929 /*
35930 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35931 * expects __USER_DS
35932 */
35933 - loadsegment(ds, __USER_DS);
35934 - loadsegment(es, __USER_DS);
35935 + loadsegment(ds, __KERNEL_DS);
35936 + loadsegment(es, __KERNEL_DS);
35937 #endif
35938
35939 xen_filter_cpu_maps();
35940 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35941 #ifdef CONFIG_X86_32
35942 /* Note: PVH is not yet supported on x86_32. */
35943 ctxt->user_regs.fs = __KERNEL_PERCPU;
35944 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35945 + savesegment(gs, ctxt->user_regs.gs);
35946 #endif
35947 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35948
35949 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35950 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35951 ctxt->flags = VGCF_IN_KERNEL;
35952 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35953 - ctxt->user_regs.ds = __USER_DS;
35954 - ctxt->user_regs.es = __USER_DS;
35955 + ctxt->user_regs.ds = __KERNEL_DS;
35956 + ctxt->user_regs.es = __KERNEL_DS;
35957 ctxt->user_regs.ss = __KERNEL_DS;
35958
35959 xen_copy_trap_info(ctxt->trap_ctxt);
35960 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35961 int rc;
35962
35963 per_cpu(current_task, cpu) = idle;
35964 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35965 #ifdef CONFIG_X86_32
35966 irq_ctx_init(cpu);
35967 #else
35968 clear_tsk_thread_flag(idle, TIF_FORK);
35969 #endif
35970 - per_cpu(kernel_stack, cpu) =
35971 - (unsigned long)task_stack_page(idle) -
35972 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35973 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35974
35975 xen_setup_runstate_info(cpu);
35976 xen_setup_timer(cpu);
35977 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35978
35979 void __init xen_smp_init(void)
35980 {
35981 - smp_ops = xen_smp_ops;
35982 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35983 xen_fill_possible_map();
35984 }
35985
35986 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35987 index fd92a64..1f72641 100644
35988 --- a/arch/x86/xen/xen-asm_32.S
35989 +++ b/arch/x86/xen/xen-asm_32.S
35990 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35991 pushw %fs
35992 movl $(__KERNEL_PERCPU), %eax
35993 movl %eax, %fs
35994 - movl %fs:xen_vcpu, %eax
35995 + mov PER_CPU_VAR(xen_vcpu), %eax
35996 POP_FS
35997 #else
35998 movl %ss:xen_vcpu, %eax
35999 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36000 index 674b2225..f1f5dc1 100644
36001 --- a/arch/x86/xen/xen-head.S
36002 +++ b/arch/x86/xen/xen-head.S
36003 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36004 #ifdef CONFIG_X86_32
36005 mov %esi,xen_start_info
36006 mov $init_thread_union+THREAD_SIZE,%esp
36007 +#ifdef CONFIG_SMP
36008 + movl $cpu_gdt_table,%edi
36009 + movl $__per_cpu_load,%eax
36010 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36011 + rorl $16,%eax
36012 + movb %al,__KERNEL_PERCPU + 4(%edi)
36013 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36014 + movl $__per_cpu_end - 1,%eax
36015 + subl $__per_cpu_start,%eax
36016 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36017 +#endif
36018 #else
36019 mov %rsi,xen_start_info
36020 mov $init_thread_union+THREAD_SIZE,%rsp
36021 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36022 index 28c7e0b..2acfec7 100644
36023 --- a/arch/x86/xen/xen-ops.h
36024 +++ b/arch/x86/xen/xen-ops.h
36025 @@ -10,8 +10,6 @@
36026 extern const char xen_hypervisor_callback[];
36027 extern const char xen_failsafe_callback[];
36028
36029 -extern void *xen_initial_gdt;
36030 -
36031 struct trap_info;
36032 void xen_copy_trap_info(struct trap_info *traps);
36033
36034 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36035 index 525bd3d..ef888b1 100644
36036 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36037 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36038 @@ -119,9 +119,9 @@
36039 ----------------------------------------------------------------------*/
36040
36041 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36042 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36043 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36044 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36045 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36046
36047 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36048 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36049 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36050 index 2f33760..835e50a 100644
36051 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36052 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36053 @@ -11,6 +11,7 @@
36054 #ifndef _XTENSA_CORE_H
36055 #define _XTENSA_CORE_H
36056
36057 +#include <linux/const.h>
36058
36059 /****************************************************************************
36060 Parameters Useful for Any Code, USER or PRIVILEGED
36061 @@ -112,9 +113,9 @@
36062 ----------------------------------------------------------------------*/
36063
36064 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36065 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36066 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36067 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36068 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36069
36070 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36071 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36072 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36073 index af00795..2bb8105 100644
36074 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36075 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36076 @@ -11,6 +11,7 @@
36077 #ifndef _XTENSA_CORE_CONFIGURATION_H
36078 #define _XTENSA_CORE_CONFIGURATION_H
36079
36080 +#include <linux/const.h>
36081
36082 /****************************************************************************
36083 Parameters Useful for Any Code, USER or PRIVILEGED
36084 @@ -118,9 +119,9 @@
36085 ----------------------------------------------------------------------*/
36086
36087 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36088 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36089 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36090 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36091 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36092
36093 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36094 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36095 diff --git a/block/bio.c b/block/bio.c
36096 index 3e6e198..5c65199 100644
36097 --- a/block/bio.c
36098 +++ b/block/bio.c
36099 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36100 /*
36101 * Overflow, abort
36102 */
36103 - if (end < start)
36104 + if (end < start || end - start > INT_MAX - nr_pages)
36105 return ERR_PTR(-EINVAL);
36106
36107 nr_pages += end - start;
36108 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36109 /*
36110 * Overflow, abort
36111 */
36112 - if (end < start)
36113 + if (end < start || end - start > INT_MAX - nr_pages)
36114 return ERR_PTR(-EINVAL);
36115
36116 nr_pages += end - start;
36117 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36118 const int read = bio_data_dir(bio) == READ;
36119 struct bio_map_data *bmd = bio->bi_private;
36120 int i;
36121 - char *p = bmd->sgvecs[0].iov_base;
36122 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36123
36124 bio_for_each_segment_all(bvec, bio, i) {
36125 char *addr = page_address(bvec->bv_page);
36126 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36127 index 0736729..2ec3b48 100644
36128 --- a/block/blk-iopoll.c
36129 +++ b/block/blk-iopoll.c
36130 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36131 }
36132 EXPORT_SYMBOL(blk_iopoll_complete);
36133
36134 -static void blk_iopoll_softirq(struct softirq_action *h)
36135 +static __latent_entropy void blk_iopoll_softirq(void)
36136 {
36137 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36138 int rearm = 0, budget = blk_iopoll_budget;
36139 diff --git a/block/blk-map.c b/block/blk-map.c
36140 index f890d43..97b0482 100644
36141 --- a/block/blk-map.c
36142 +++ b/block/blk-map.c
36143 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36144 if (!len || !kbuf)
36145 return -EINVAL;
36146
36147 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36148 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36149 if (do_copy)
36150 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36151 else
36152 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36153 index 53b1737..08177d2e 100644
36154 --- a/block/blk-softirq.c
36155 +++ b/block/blk-softirq.c
36156 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36157 * Softirq action handler - move entries to local list and loop over them
36158 * while passing them to the queue registered handler.
36159 */
36160 -static void blk_done_softirq(struct softirq_action *h)
36161 +static __latent_entropy void blk_done_softirq(void)
36162 {
36163 struct list_head *cpu_list, local_list;
36164
36165 diff --git a/block/bsg.c b/block/bsg.c
36166 index 276e869..6fe4c61 100644
36167 --- a/block/bsg.c
36168 +++ b/block/bsg.c
36169 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36170 struct sg_io_v4 *hdr, struct bsg_device *bd,
36171 fmode_t has_write_perm)
36172 {
36173 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36174 + unsigned char *cmdptr;
36175 +
36176 if (hdr->request_len > BLK_MAX_CDB) {
36177 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36178 if (!rq->cmd)
36179 return -ENOMEM;
36180 - }
36181 + cmdptr = rq->cmd;
36182 + } else
36183 + cmdptr = tmpcmd;
36184
36185 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36186 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36187 hdr->request_len))
36188 return -EFAULT;
36189
36190 + if (cmdptr != rq->cmd)
36191 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36192 +
36193 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36194 if (blk_verify_command(rq->cmd, has_write_perm))
36195 return -EPERM;
36196 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36197 index f678c73..f35aa18 100644
36198 --- a/block/compat_ioctl.c
36199 +++ b/block/compat_ioctl.c
36200 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36201 cgc = compat_alloc_user_space(sizeof(*cgc));
36202 cgc32 = compat_ptr(arg);
36203
36204 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36205 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36206 get_user(data, &cgc32->buffer) ||
36207 put_user(compat_ptr(data), &cgc->buffer) ||
36208 copy_in_user(&cgc->buflen, &cgc32->buflen,
36209 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36210 err |= __get_user(f->spec1, &uf->spec1);
36211 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36212 err |= __get_user(name, &uf->name);
36213 - f->name = compat_ptr(name);
36214 + f->name = (void __force_kernel *)compat_ptr(name);
36215 if (err) {
36216 err = -EFAULT;
36217 goto out;
36218 diff --git a/block/genhd.c b/block/genhd.c
36219 index 0a536dc..b8f7aca 100644
36220 --- a/block/genhd.c
36221 +++ b/block/genhd.c
36222 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36223
36224 /*
36225 * Register device numbers dev..(dev+range-1)
36226 - * range must be nonzero
36227 + * Noop if @range is zero.
36228 * The hash chain is sorted on range, so that subranges can override.
36229 */
36230 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36231 struct kobject *(*probe)(dev_t, int *, void *),
36232 int (*lock)(dev_t, void *), void *data)
36233 {
36234 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36235 + if (range)
36236 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36237 }
36238
36239 EXPORT_SYMBOL(blk_register_region);
36240
36241 +/* undo blk_register_region(), noop if @range is zero */
36242 void blk_unregister_region(dev_t devt, unsigned long range)
36243 {
36244 - kobj_unmap(bdev_map, devt, range);
36245 + if (range)
36246 + kobj_unmap(bdev_map, devt, range);
36247 }
36248
36249 EXPORT_SYMBOL(blk_unregister_region);
36250 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36251 index 56d08fd..2e07090 100644
36252 --- a/block/partitions/efi.c
36253 +++ b/block/partitions/efi.c
36254 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36255 if (!gpt)
36256 return NULL;
36257
36258 + if (!le32_to_cpu(gpt->num_partition_entries))
36259 + return NULL;
36260 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36261 + if (!pte)
36262 + return NULL;
36263 +
36264 count = le32_to_cpu(gpt->num_partition_entries) *
36265 le32_to_cpu(gpt->sizeof_partition_entry);
36266 - if (!count)
36267 - return NULL;
36268 - pte = kmalloc(count, GFP_KERNEL);
36269 - if (!pte)
36270 - return NULL;
36271 -
36272 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36273 (u8 *) pte, count) < count) {
36274 kfree(pte);
36275 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36276 index b0c2a61..10bb6ec 100644
36277 --- a/block/scsi_ioctl.c
36278 +++ b/block/scsi_ioctl.c
36279 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36280 return put_user(0, p);
36281 }
36282
36283 -static int sg_get_timeout(struct request_queue *q)
36284 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36285 {
36286 return jiffies_to_clock_t(q->sg_timeout);
36287 }
36288 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36289 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36290 struct sg_io_hdr *hdr, fmode_t mode)
36291 {
36292 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36293 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36294 + unsigned char *cmdptr;
36295 +
36296 + if (rq->cmd != rq->__cmd)
36297 + cmdptr = rq->cmd;
36298 + else
36299 + cmdptr = tmpcmd;
36300 +
36301 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36302 return -EFAULT;
36303 +
36304 + if (cmdptr != rq->cmd)
36305 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36306 +
36307 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36308 return -EPERM;
36309
36310 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36311 int err;
36312 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36313 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36314 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36315 + unsigned char *cmdptr;
36316
36317 if (!sic)
36318 return -EINVAL;
36319 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36320 */
36321 err = -EFAULT;
36322 rq->cmd_len = cmdlen;
36323 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36324 +
36325 + if (rq->cmd != rq->__cmd)
36326 + cmdptr = rq->cmd;
36327 + else
36328 + cmdptr = tmpcmd;
36329 +
36330 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36331 goto error;
36332
36333 + if (rq->cmd != cmdptr)
36334 + memcpy(rq->cmd, cmdptr, cmdlen);
36335 +
36336 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36337 goto error;
36338
36339 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36340 index e592c90..c566114 100644
36341 --- a/crypto/cryptd.c
36342 +++ b/crypto/cryptd.c
36343 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36344
36345 struct cryptd_blkcipher_request_ctx {
36346 crypto_completion_t complete;
36347 -};
36348 +} __no_const;
36349
36350 struct cryptd_hash_ctx {
36351 struct crypto_shash *child;
36352 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36353
36354 struct cryptd_aead_request_ctx {
36355 crypto_completion_t complete;
36356 -};
36357 +} __no_const;
36358
36359 static void cryptd_queue_worker(struct work_struct *work);
36360
36361 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36362 index 309d345..1632720 100644
36363 --- a/crypto/pcrypt.c
36364 +++ b/crypto/pcrypt.c
36365 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36366 int ret;
36367
36368 pinst->kobj.kset = pcrypt_kset;
36369 - ret = kobject_add(&pinst->kobj, NULL, name);
36370 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36371 if (!ret)
36372 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36373
36374 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36375 index 6921c7f..78e1af7 100644
36376 --- a/drivers/acpi/acpica/hwxfsleep.c
36377 +++ b/drivers/acpi/acpica/hwxfsleep.c
36378 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36379 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36380
36381 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36382 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36383 - acpi_hw_extended_sleep},
36384 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36385 - acpi_hw_extended_wake_prep},
36386 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36387 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36388 + .extended_function = acpi_hw_extended_sleep},
36389 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36390 + .extended_function = acpi_hw_extended_wake_prep},
36391 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36392 + .extended_function = acpi_hw_extended_wake}
36393 };
36394
36395 /*
36396 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36397 index 16129c7..8b675cd 100644
36398 --- a/drivers/acpi/apei/apei-internal.h
36399 +++ b/drivers/acpi/apei/apei-internal.h
36400 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36401 struct apei_exec_ins_type {
36402 u32 flags;
36403 apei_exec_ins_func_t run;
36404 -};
36405 +} __do_const;
36406
36407 struct apei_exec_context {
36408 u32 ip;
36409 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36410 index fc5f780..e5ac91a 100644
36411 --- a/drivers/acpi/apei/ghes.c
36412 +++ b/drivers/acpi/apei/ghes.c
36413 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36414 const struct acpi_hest_generic *generic,
36415 const struct acpi_hest_generic_status *estatus)
36416 {
36417 - static atomic_t seqno;
36418 + static atomic_unchecked_t seqno;
36419 unsigned int curr_seqno;
36420 char pfx_seq[64];
36421
36422 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36423 else
36424 pfx = KERN_ERR;
36425 }
36426 - curr_seqno = atomic_inc_return(&seqno);
36427 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36428 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36429 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36430 pfx_seq, generic->header.source_id);
36431 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36432 index a83e3c6..c3d617f 100644
36433 --- a/drivers/acpi/bgrt.c
36434 +++ b/drivers/acpi/bgrt.c
36435 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36436 if (!bgrt_image)
36437 return -ENODEV;
36438
36439 - bin_attr_image.private = bgrt_image;
36440 - bin_attr_image.size = bgrt_image_size;
36441 + pax_open_kernel();
36442 + *(void **)&bin_attr_image.private = bgrt_image;
36443 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36444 + pax_close_kernel();
36445
36446 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36447 if (!bgrt_kobj)
36448 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36449 index 7556e7c..89a96bd 100644
36450 --- a/drivers/acpi/blacklist.c
36451 +++ b/drivers/acpi/blacklist.c
36452 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36453 u32 is_critical_error;
36454 };
36455
36456 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36457 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36458
36459 /*
36460 * POLICY: If *anything* doesn't work, put it on the blacklist.
36461 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36462 return 0;
36463 }
36464
36465 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36466 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36467 {
36468 .callback = dmi_disable_osi_vista,
36469 .ident = "Fujitsu Siemens",
36470 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36471 index c68e724..e863008 100644
36472 --- a/drivers/acpi/custom_method.c
36473 +++ b/drivers/acpi/custom_method.c
36474 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36475 struct acpi_table_header table;
36476 acpi_status status;
36477
36478 +#ifdef CONFIG_GRKERNSEC_KMEM
36479 + return -EPERM;
36480 +#endif
36481 +
36482 if (!(*ppos)) {
36483 /* parse the table header to get the table length */
36484 if (count <= sizeof(struct acpi_table_header))
36485 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36486 index 93b7142..5676c75 100644
36487 --- a/drivers/acpi/device_pm.c
36488 +++ b/drivers/acpi/device_pm.c
36489 @@ -1021,6 +1021,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36490
36491 #endif /* CONFIG_PM_SLEEP */
36492
36493 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36494 +
36495 static struct dev_pm_domain acpi_general_pm_domain = {
36496 .ops = {
36497 #ifdef CONFIG_PM_RUNTIME
36498 @@ -1039,6 +1041,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36499 .restore_early = acpi_subsys_resume_early,
36500 #endif
36501 },
36502 + .detach = acpi_dev_pm_detach
36503 };
36504
36505 /**
36506 @@ -1108,7 +1111,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36507 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36508 }
36509
36510 - dev->pm_domain->detach = acpi_dev_pm_detach;
36511 return 0;
36512 }
36513 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36514 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36515 index 17f9ec5..d9a455e 100644
36516 --- a/drivers/acpi/processor_idle.c
36517 +++ b/drivers/acpi/processor_idle.c
36518 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36519 {
36520 int i, count = CPUIDLE_DRIVER_STATE_START;
36521 struct acpi_processor_cx *cx;
36522 - struct cpuidle_state *state;
36523 + cpuidle_state_no_const *state;
36524 struct cpuidle_driver *drv = &acpi_idle_driver;
36525
36526 if (!pr->flags.power_setup_done)
36527 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36528 index 13e577c..cef11ee 100644
36529 --- a/drivers/acpi/sysfs.c
36530 +++ b/drivers/acpi/sysfs.c
36531 @@ -423,11 +423,11 @@ static u32 num_counters;
36532 static struct attribute **all_attrs;
36533 static u32 acpi_gpe_count;
36534
36535 -static struct attribute_group interrupt_stats_attr_group = {
36536 +static attribute_group_no_const interrupt_stats_attr_group = {
36537 .name = "interrupts",
36538 };
36539
36540 -static struct kobj_attribute *counter_attrs;
36541 +static kobj_attribute_no_const *counter_attrs;
36542
36543 static void delete_gpe_attr_array(void)
36544 {
36545 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36546 index 97683e4..655f6ba 100644
36547 --- a/drivers/ata/libahci.c
36548 +++ b/drivers/ata/libahci.c
36549 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36550 }
36551 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36552
36553 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36554 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36555 struct ata_taskfile *tf, int is_cmd, u16 flags,
36556 unsigned long timeout_msec)
36557 {
36558 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36559 index c5ba15a..75ec7a8 100644
36560 --- a/drivers/ata/libata-core.c
36561 +++ b/drivers/ata/libata-core.c
36562 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36563 static void ata_dev_xfermask(struct ata_device *dev);
36564 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36565
36566 -atomic_t ata_print_id = ATOMIC_INIT(0);
36567 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36568
36569 struct ata_force_param {
36570 const char *name;
36571 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36572 struct ata_port *ap;
36573 unsigned int tag;
36574
36575 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36576 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36577 ap = qc->ap;
36578
36579 qc->flags = 0;
36580 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36581 struct ata_port *ap;
36582 struct ata_link *link;
36583
36584 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36585 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36586 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36587 ap = qc->ap;
36588 link = qc->dev->link;
36589 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36590 return;
36591
36592 spin_lock(&lock);
36593 + pax_open_kernel();
36594
36595 for (cur = ops->inherits; cur; cur = cur->inherits) {
36596 void **inherit = (void **)cur;
36597 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36598 if (IS_ERR(*pp))
36599 *pp = NULL;
36600
36601 - ops->inherits = NULL;
36602 + *(struct ata_port_operations **)&ops->inherits = NULL;
36603
36604 + pax_close_kernel();
36605 spin_unlock(&lock);
36606 }
36607
36608 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36609
36610 /* give ports names and add SCSI hosts */
36611 for (i = 0; i < host->n_ports; i++) {
36612 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36613 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36614 host->ports[i]->local_port_no = i + 1;
36615 }
36616
36617 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36618 index 0586f66..1a8f74a 100644
36619 --- a/drivers/ata/libata-scsi.c
36620 +++ b/drivers/ata/libata-scsi.c
36621 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36622
36623 if (rc)
36624 return rc;
36625 - ap->print_id = atomic_inc_return(&ata_print_id);
36626 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36627 return 0;
36628 }
36629 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36630 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36631 index 5f4e0cc..ff2c347 100644
36632 --- a/drivers/ata/libata.h
36633 +++ b/drivers/ata/libata.h
36634 @@ -53,7 +53,7 @@ enum {
36635 ATA_DNXFER_QUIET = (1 << 31),
36636 };
36637
36638 -extern atomic_t ata_print_id;
36639 +extern atomic_unchecked_t ata_print_id;
36640 extern int atapi_passthru16;
36641 extern int libata_fua;
36642 extern int libata_noacpi;
36643 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36644 index 38216b9..4ec6aeb 100644
36645 --- a/drivers/ata/pata_arasan_cf.c
36646 +++ b/drivers/ata/pata_arasan_cf.c
36647 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36648 /* Handle platform specific quirks */
36649 if (quirk) {
36650 if (quirk & CF_BROKEN_PIO) {
36651 - ap->ops->set_piomode = NULL;
36652 + pax_open_kernel();
36653 + *(void **)&ap->ops->set_piomode = NULL;
36654 + pax_close_kernel();
36655 ap->pio_mask = 0;
36656 }
36657 if (quirk & CF_BROKEN_MWDMA)
36658 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36659 index f9b983a..887b9d8 100644
36660 --- a/drivers/atm/adummy.c
36661 +++ b/drivers/atm/adummy.c
36662 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36663 vcc->pop(vcc, skb);
36664 else
36665 dev_kfree_skb_any(skb);
36666 - atomic_inc(&vcc->stats->tx);
36667 + atomic_inc_unchecked(&vcc->stats->tx);
36668
36669 return 0;
36670 }
36671 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36672 index f1a9198..f466a4a 100644
36673 --- a/drivers/atm/ambassador.c
36674 +++ b/drivers/atm/ambassador.c
36675 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36676 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36677
36678 // VC layer stats
36679 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36680 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36681
36682 // free the descriptor
36683 kfree (tx_descr);
36684 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36685 dump_skb ("<<<", vc, skb);
36686
36687 // VC layer stats
36688 - atomic_inc(&atm_vcc->stats->rx);
36689 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36690 __net_timestamp(skb);
36691 // end of our responsibility
36692 atm_vcc->push (atm_vcc, skb);
36693 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36694 } else {
36695 PRINTK (KERN_INFO, "dropped over-size frame");
36696 // should we count this?
36697 - atomic_inc(&atm_vcc->stats->rx_drop);
36698 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36699 }
36700
36701 } else {
36702 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36703 }
36704
36705 if (check_area (skb->data, skb->len)) {
36706 - atomic_inc(&atm_vcc->stats->tx_err);
36707 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36708 return -ENOMEM; // ?
36709 }
36710
36711 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36712 index 480fa6f..947067c 100644
36713 --- a/drivers/atm/atmtcp.c
36714 +++ b/drivers/atm/atmtcp.c
36715 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36716 if (vcc->pop) vcc->pop(vcc,skb);
36717 else dev_kfree_skb(skb);
36718 if (dev_data) return 0;
36719 - atomic_inc(&vcc->stats->tx_err);
36720 + atomic_inc_unchecked(&vcc->stats->tx_err);
36721 return -ENOLINK;
36722 }
36723 size = skb->len+sizeof(struct atmtcp_hdr);
36724 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36725 if (!new_skb) {
36726 if (vcc->pop) vcc->pop(vcc,skb);
36727 else dev_kfree_skb(skb);
36728 - atomic_inc(&vcc->stats->tx_err);
36729 + atomic_inc_unchecked(&vcc->stats->tx_err);
36730 return -ENOBUFS;
36731 }
36732 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36733 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36734 if (vcc->pop) vcc->pop(vcc,skb);
36735 else dev_kfree_skb(skb);
36736 out_vcc->push(out_vcc,new_skb);
36737 - atomic_inc(&vcc->stats->tx);
36738 - atomic_inc(&out_vcc->stats->rx);
36739 + atomic_inc_unchecked(&vcc->stats->tx);
36740 + atomic_inc_unchecked(&out_vcc->stats->rx);
36741 return 0;
36742 }
36743
36744 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36745 read_unlock(&vcc_sklist_lock);
36746 if (!out_vcc) {
36747 result = -EUNATCH;
36748 - atomic_inc(&vcc->stats->tx_err);
36749 + atomic_inc_unchecked(&vcc->stats->tx_err);
36750 goto done;
36751 }
36752 skb_pull(skb,sizeof(struct atmtcp_hdr));
36753 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36754 __net_timestamp(new_skb);
36755 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36756 out_vcc->push(out_vcc,new_skb);
36757 - atomic_inc(&vcc->stats->tx);
36758 - atomic_inc(&out_vcc->stats->rx);
36759 + atomic_inc_unchecked(&vcc->stats->tx);
36760 + atomic_inc_unchecked(&out_vcc->stats->rx);
36761 done:
36762 if (vcc->pop) vcc->pop(vcc,skb);
36763 else dev_kfree_skb(skb);
36764 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36765 index d65975a..0b87e20 100644
36766 --- a/drivers/atm/eni.c
36767 +++ b/drivers/atm/eni.c
36768 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36769 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36770 vcc->dev->number);
36771 length = 0;
36772 - atomic_inc(&vcc->stats->rx_err);
36773 + atomic_inc_unchecked(&vcc->stats->rx_err);
36774 }
36775 else {
36776 length = ATM_CELL_SIZE-1; /* no HEC */
36777 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36778 size);
36779 }
36780 eff = length = 0;
36781 - atomic_inc(&vcc->stats->rx_err);
36782 + atomic_inc_unchecked(&vcc->stats->rx_err);
36783 }
36784 else {
36785 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36786 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36787 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36788 vcc->dev->number,vcc->vci,length,size << 2,descr);
36789 length = eff = 0;
36790 - atomic_inc(&vcc->stats->rx_err);
36791 + atomic_inc_unchecked(&vcc->stats->rx_err);
36792 }
36793 }
36794 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36795 @@ -767,7 +767,7 @@ rx_dequeued++;
36796 vcc->push(vcc,skb);
36797 pushed++;
36798 }
36799 - atomic_inc(&vcc->stats->rx);
36800 + atomic_inc_unchecked(&vcc->stats->rx);
36801 }
36802 wake_up(&eni_dev->rx_wait);
36803 }
36804 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36805 PCI_DMA_TODEVICE);
36806 if (vcc->pop) vcc->pop(vcc,skb);
36807 else dev_kfree_skb_irq(skb);
36808 - atomic_inc(&vcc->stats->tx);
36809 + atomic_inc_unchecked(&vcc->stats->tx);
36810 wake_up(&eni_dev->tx_wait);
36811 dma_complete++;
36812 }
36813 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36814 index 82f2ae0..f205c02 100644
36815 --- a/drivers/atm/firestream.c
36816 +++ b/drivers/atm/firestream.c
36817 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36818 }
36819 }
36820
36821 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36822 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36823
36824 fs_dprintk (FS_DEBUG_TXMEM, "i");
36825 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36826 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36827 #endif
36828 skb_put (skb, qe->p1 & 0xffff);
36829 ATM_SKB(skb)->vcc = atm_vcc;
36830 - atomic_inc(&atm_vcc->stats->rx);
36831 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36832 __net_timestamp(skb);
36833 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36834 atm_vcc->push (atm_vcc, skb);
36835 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36836 kfree (pe);
36837 }
36838 if (atm_vcc)
36839 - atomic_inc(&atm_vcc->stats->rx_drop);
36840 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36841 break;
36842 case 0x1f: /* Reassembly abort: no buffers. */
36843 /* Silently increment error counter. */
36844 if (atm_vcc)
36845 - atomic_inc(&atm_vcc->stats->rx_drop);
36846 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36847 break;
36848 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36849 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36850 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36851 index d4725fc..2d4ea65 100644
36852 --- a/drivers/atm/fore200e.c
36853 +++ b/drivers/atm/fore200e.c
36854 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36855 #endif
36856 /* check error condition */
36857 if (*entry->status & STATUS_ERROR)
36858 - atomic_inc(&vcc->stats->tx_err);
36859 + atomic_inc_unchecked(&vcc->stats->tx_err);
36860 else
36861 - atomic_inc(&vcc->stats->tx);
36862 + atomic_inc_unchecked(&vcc->stats->tx);
36863 }
36864 }
36865
36866 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36867 if (skb == NULL) {
36868 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36869
36870 - atomic_inc(&vcc->stats->rx_drop);
36871 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36872 return -ENOMEM;
36873 }
36874
36875 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36876
36877 dev_kfree_skb_any(skb);
36878
36879 - atomic_inc(&vcc->stats->rx_drop);
36880 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36881 return -ENOMEM;
36882 }
36883
36884 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36885
36886 vcc->push(vcc, skb);
36887 - atomic_inc(&vcc->stats->rx);
36888 + atomic_inc_unchecked(&vcc->stats->rx);
36889
36890 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36891
36892 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36893 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36894 fore200e->atm_dev->number,
36895 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36896 - atomic_inc(&vcc->stats->rx_err);
36897 + atomic_inc_unchecked(&vcc->stats->rx_err);
36898 }
36899 }
36900
36901 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36902 goto retry_here;
36903 }
36904
36905 - atomic_inc(&vcc->stats->tx_err);
36906 + atomic_inc_unchecked(&vcc->stats->tx_err);
36907
36908 fore200e->tx_sat++;
36909 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36910 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36911 index c39702b..785b73b 100644
36912 --- a/drivers/atm/he.c
36913 +++ b/drivers/atm/he.c
36914 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36915
36916 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36917 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36918 - atomic_inc(&vcc->stats->rx_drop);
36919 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36920 goto return_host_buffers;
36921 }
36922
36923 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36924 RBRQ_LEN_ERR(he_dev->rbrq_head)
36925 ? "LEN_ERR" : "",
36926 vcc->vpi, vcc->vci);
36927 - atomic_inc(&vcc->stats->rx_err);
36928 + atomic_inc_unchecked(&vcc->stats->rx_err);
36929 goto return_host_buffers;
36930 }
36931
36932 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36933 vcc->push(vcc, skb);
36934 spin_lock(&he_dev->global_lock);
36935
36936 - atomic_inc(&vcc->stats->rx);
36937 + atomic_inc_unchecked(&vcc->stats->rx);
36938
36939 return_host_buffers:
36940 ++pdus_assembled;
36941 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36942 tpd->vcc->pop(tpd->vcc, tpd->skb);
36943 else
36944 dev_kfree_skb_any(tpd->skb);
36945 - atomic_inc(&tpd->vcc->stats->tx_err);
36946 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36947 }
36948 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36949 return;
36950 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36951 vcc->pop(vcc, skb);
36952 else
36953 dev_kfree_skb_any(skb);
36954 - atomic_inc(&vcc->stats->tx_err);
36955 + atomic_inc_unchecked(&vcc->stats->tx_err);
36956 return -EINVAL;
36957 }
36958
36959 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36960 vcc->pop(vcc, skb);
36961 else
36962 dev_kfree_skb_any(skb);
36963 - atomic_inc(&vcc->stats->tx_err);
36964 + atomic_inc_unchecked(&vcc->stats->tx_err);
36965 return -EINVAL;
36966 }
36967 #endif
36968 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36969 vcc->pop(vcc, skb);
36970 else
36971 dev_kfree_skb_any(skb);
36972 - atomic_inc(&vcc->stats->tx_err);
36973 + atomic_inc_unchecked(&vcc->stats->tx_err);
36974 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36975 return -ENOMEM;
36976 }
36977 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36978 vcc->pop(vcc, skb);
36979 else
36980 dev_kfree_skb_any(skb);
36981 - atomic_inc(&vcc->stats->tx_err);
36982 + atomic_inc_unchecked(&vcc->stats->tx_err);
36983 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36984 return -ENOMEM;
36985 }
36986 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36987 __enqueue_tpd(he_dev, tpd, cid);
36988 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36989
36990 - atomic_inc(&vcc->stats->tx);
36991 + atomic_inc_unchecked(&vcc->stats->tx);
36992
36993 return 0;
36994 }
36995 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36996 index 1dc0519..1aadaf7 100644
36997 --- a/drivers/atm/horizon.c
36998 +++ b/drivers/atm/horizon.c
36999 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37000 {
37001 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37002 // VC layer stats
37003 - atomic_inc(&vcc->stats->rx);
37004 + atomic_inc_unchecked(&vcc->stats->rx);
37005 __net_timestamp(skb);
37006 // end of our responsibility
37007 vcc->push (vcc, skb);
37008 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37009 dev->tx_iovec = NULL;
37010
37011 // VC layer stats
37012 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37013 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37014
37015 // free the skb
37016 hrz_kfree_skb (skb);
37017 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37018 index 2b24ed0..b3d6acc 100644
37019 --- a/drivers/atm/idt77252.c
37020 +++ b/drivers/atm/idt77252.c
37021 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37022 else
37023 dev_kfree_skb(skb);
37024
37025 - atomic_inc(&vcc->stats->tx);
37026 + atomic_inc_unchecked(&vcc->stats->tx);
37027 }
37028
37029 atomic_dec(&scq->used);
37030 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37031 if ((sb = dev_alloc_skb(64)) == NULL) {
37032 printk("%s: Can't allocate buffers for aal0.\n",
37033 card->name);
37034 - atomic_add(i, &vcc->stats->rx_drop);
37035 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37036 break;
37037 }
37038 if (!atm_charge(vcc, sb->truesize)) {
37039 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37040 card->name);
37041 - atomic_add(i - 1, &vcc->stats->rx_drop);
37042 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37043 dev_kfree_skb(sb);
37044 break;
37045 }
37046 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37047 ATM_SKB(sb)->vcc = vcc;
37048 __net_timestamp(sb);
37049 vcc->push(vcc, sb);
37050 - atomic_inc(&vcc->stats->rx);
37051 + atomic_inc_unchecked(&vcc->stats->rx);
37052
37053 cell += ATM_CELL_PAYLOAD;
37054 }
37055 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37056 "(CDC: %08x)\n",
37057 card->name, len, rpp->len, readl(SAR_REG_CDC));
37058 recycle_rx_pool_skb(card, rpp);
37059 - atomic_inc(&vcc->stats->rx_err);
37060 + atomic_inc_unchecked(&vcc->stats->rx_err);
37061 return;
37062 }
37063 if (stat & SAR_RSQE_CRC) {
37064 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37065 recycle_rx_pool_skb(card, rpp);
37066 - atomic_inc(&vcc->stats->rx_err);
37067 + atomic_inc_unchecked(&vcc->stats->rx_err);
37068 return;
37069 }
37070 if (skb_queue_len(&rpp->queue) > 1) {
37071 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37072 RXPRINTK("%s: Can't alloc RX skb.\n",
37073 card->name);
37074 recycle_rx_pool_skb(card, rpp);
37075 - atomic_inc(&vcc->stats->rx_err);
37076 + atomic_inc_unchecked(&vcc->stats->rx_err);
37077 return;
37078 }
37079 if (!atm_charge(vcc, skb->truesize)) {
37080 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37081 __net_timestamp(skb);
37082
37083 vcc->push(vcc, skb);
37084 - atomic_inc(&vcc->stats->rx);
37085 + atomic_inc_unchecked(&vcc->stats->rx);
37086
37087 return;
37088 }
37089 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37090 __net_timestamp(skb);
37091
37092 vcc->push(vcc, skb);
37093 - atomic_inc(&vcc->stats->rx);
37094 + atomic_inc_unchecked(&vcc->stats->rx);
37095
37096 if (skb->truesize > SAR_FB_SIZE_3)
37097 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37098 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37099 if (vcc->qos.aal != ATM_AAL0) {
37100 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37101 card->name, vpi, vci);
37102 - atomic_inc(&vcc->stats->rx_drop);
37103 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37104 goto drop;
37105 }
37106
37107 if ((sb = dev_alloc_skb(64)) == NULL) {
37108 printk("%s: Can't allocate buffers for AAL0.\n",
37109 card->name);
37110 - atomic_inc(&vcc->stats->rx_err);
37111 + atomic_inc_unchecked(&vcc->stats->rx_err);
37112 goto drop;
37113 }
37114
37115 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37116 ATM_SKB(sb)->vcc = vcc;
37117 __net_timestamp(sb);
37118 vcc->push(vcc, sb);
37119 - atomic_inc(&vcc->stats->rx);
37120 + atomic_inc_unchecked(&vcc->stats->rx);
37121
37122 drop:
37123 skb_pull(queue, 64);
37124 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37125
37126 if (vc == NULL) {
37127 printk("%s: NULL connection in send().\n", card->name);
37128 - atomic_inc(&vcc->stats->tx_err);
37129 + atomic_inc_unchecked(&vcc->stats->tx_err);
37130 dev_kfree_skb(skb);
37131 return -EINVAL;
37132 }
37133 if (!test_bit(VCF_TX, &vc->flags)) {
37134 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37135 - atomic_inc(&vcc->stats->tx_err);
37136 + atomic_inc_unchecked(&vcc->stats->tx_err);
37137 dev_kfree_skb(skb);
37138 return -EINVAL;
37139 }
37140 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37141 break;
37142 default:
37143 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37144 - atomic_inc(&vcc->stats->tx_err);
37145 + atomic_inc_unchecked(&vcc->stats->tx_err);
37146 dev_kfree_skb(skb);
37147 return -EINVAL;
37148 }
37149
37150 if (skb_shinfo(skb)->nr_frags != 0) {
37151 printk("%s: No scatter-gather yet.\n", card->name);
37152 - atomic_inc(&vcc->stats->tx_err);
37153 + atomic_inc_unchecked(&vcc->stats->tx_err);
37154 dev_kfree_skb(skb);
37155 return -EINVAL;
37156 }
37157 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37158
37159 err = queue_skb(card, vc, skb, oam);
37160 if (err) {
37161 - atomic_inc(&vcc->stats->tx_err);
37162 + atomic_inc_unchecked(&vcc->stats->tx_err);
37163 dev_kfree_skb(skb);
37164 return err;
37165 }
37166 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37167 skb = dev_alloc_skb(64);
37168 if (!skb) {
37169 printk("%s: Out of memory in send_oam().\n", card->name);
37170 - atomic_inc(&vcc->stats->tx_err);
37171 + atomic_inc_unchecked(&vcc->stats->tx_err);
37172 return -ENOMEM;
37173 }
37174 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37175 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37176 index 4217f29..88f547a 100644
37177 --- a/drivers/atm/iphase.c
37178 +++ b/drivers/atm/iphase.c
37179 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37180 status = (u_short) (buf_desc_ptr->desc_mode);
37181 if (status & (RX_CER | RX_PTE | RX_OFL))
37182 {
37183 - atomic_inc(&vcc->stats->rx_err);
37184 + atomic_inc_unchecked(&vcc->stats->rx_err);
37185 IF_ERR(printk("IA: bad packet, dropping it");)
37186 if (status & RX_CER) {
37187 IF_ERR(printk(" cause: packet CRC error\n");)
37188 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37189 len = dma_addr - buf_addr;
37190 if (len > iadev->rx_buf_sz) {
37191 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37192 - atomic_inc(&vcc->stats->rx_err);
37193 + atomic_inc_unchecked(&vcc->stats->rx_err);
37194 goto out_free_desc;
37195 }
37196
37197 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37198 ia_vcc = INPH_IA_VCC(vcc);
37199 if (ia_vcc == NULL)
37200 {
37201 - atomic_inc(&vcc->stats->rx_err);
37202 + atomic_inc_unchecked(&vcc->stats->rx_err);
37203 atm_return(vcc, skb->truesize);
37204 dev_kfree_skb_any(skb);
37205 goto INCR_DLE;
37206 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37207 if ((length > iadev->rx_buf_sz) || (length >
37208 (skb->len - sizeof(struct cpcs_trailer))))
37209 {
37210 - atomic_inc(&vcc->stats->rx_err);
37211 + atomic_inc_unchecked(&vcc->stats->rx_err);
37212 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37213 length, skb->len);)
37214 atm_return(vcc, skb->truesize);
37215 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37216
37217 IF_RX(printk("rx_dle_intr: skb push");)
37218 vcc->push(vcc,skb);
37219 - atomic_inc(&vcc->stats->rx);
37220 + atomic_inc_unchecked(&vcc->stats->rx);
37221 iadev->rx_pkt_cnt++;
37222 }
37223 INCR_DLE:
37224 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37225 {
37226 struct k_sonet_stats *stats;
37227 stats = &PRIV(_ia_dev[board])->sonet_stats;
37228 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37229 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37230 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37231 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37232 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37233 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37234 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37235 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37236 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37237 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37238 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37239 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37240 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37241 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37242 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37243 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37244 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37245 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37246 }
37247 ia_cmds.status = 0;
37248 break;
37249 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37250 if ((desc == 0) || (desc > iadev->num_tx_desc))
37251 {
37252 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37253 - atomic_inc(&vcc->stats->tx);
37254 + atomic_inc_unchecked(&vcc->stats->tx);
37255 if (vcc->pop)
37256 vcc->pop(vcc, skb);
37257 else
37258 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37259 ATM_DESC(skb) = vcc->vci;
37260 skb_queue_tail(&iadev->tx_dma_q, skb);
37261
37262 - atomic_inc(&vcc->stats->tx);
37263 + atomic_inc_unchecked(&vcc->stats->tx);
37264 iadev->tx_pkt_cnt++;
37265 /* Increment transaction counter */
37266 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37267
37268 #if 0
37269 /* add flow control logic */
37270 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37271 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37272 if (iavcc->vc_desc_cnt > 10) {
37273 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37274 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37275 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37276 index 93eaf8d..b4ca7da 100644
37277 --- a/drivers/atm/lanai.c
37278 +++ b/drivers/atm/lanai.c
37279 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37280 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37281 lanai_endtx(lanai, lvcc);
37282 lanai_free_skb(lvcc->tx.atmvcc, skb);
37283 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37284 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37285 }
37286
37287 /* Try to fill the buffer - don't call unless there is backlog */
37288 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37289 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37290 __net_timestamp(skb);
37291 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37292 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37293 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37294 out:
37295 lvcc->rx.buf.ptr = end;
37296 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37297 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37298 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37299 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37300 lanai->stats.service_rxnotaal5++;
37301 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37302 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37303 return 0;
37304 }
37305 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37306 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37307 int bytes;
37308 read_unlock(&vcc_sklist_lock);
37309 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37310 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37311 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37312 lvcc->stats.x.aal5.service_trash++;
37313 bytes = (SERVICE_GET_END(s) * 16) -
37314 (((unsigned long) lvcc->rx.buf.ptr) -
37315 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37316 }
37317 if (s & SERVICE_STREAM) {
37318 read_unlock(&vcc_sklist_lock);
37319 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37320 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37321 lvcc->stats.x.aal5.service_stream++;
37322 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37323 "PDU on VCI %d!\n", lanai->number, vci);
37324 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37325 return 0;
37326 }
37327 DPRINTK("got rx crc error on vci %d\n", vci);
37328 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37329 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37330 lvcc->stats.x.aal5.service_rxcrc++;
37331 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37332 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37333 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37334 index 9988ac9..7c52585 100644
37335 --- a/drivers/atm/nicstar.c
37336 +++ b/drivers/atm/nicstar.c
37337 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37338 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37339 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37340 card->index);
37341 - atomic_inc(&vcc->stats->tx_err);
37342 + atomic_inc_unchecked(&vcc->stats->tx_err);
37343 dev_kfree_skb_any(skb);
37344 return -EINVAL;
37345 }
37346 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37347 if (!vc->tx) {
37348 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37349 card->index);
37350 - atomic_inc(&vcc->stats->tx_err);
37351 + atomic_inc_unchecked(&vcc->stats->tx_err);
37352 dev_kfree_skb_any(skb);
37353 return -EINVAL;
37354 }
37355 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37356 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37357 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37358 card->index);
37359 - atomic_inc(&vcc->stats->tx_err);
37360 + atomic_inc_unchecked(&vcc->stats->tx_err);
37361 dev_kfree_skb_any(skb);
37362 return -EINVAL;
37363 }
37364
37365 if (skb_shinfo(skb)->nr_frags != 0) {
37366 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37367 - atomic_inc(&vcc->stats->tx_err);
37368 + atomic_inc_unchecked(&vcc->stats->tx_err);
37369 dev_kfree_skb_any(skb);
37370 return -EINVAL;
37371 }
37372 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37373 }
37374
37375 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37376 - atomic_inc(&vcc->stats->tx_err);
37377 + atomic_inc_unchecked(&vcc->stats->tx_err);
37378 dev_kfree_skb_any(skb);
37379 return -EIO;
37380 }
37381 - atomic_inc(&vcc->stats->tx);
37382 + atomic_inc_unchecked(&vcc->stats->tx);
37383
37384 return 0;
37385 }
37386 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37387 printk
37388 ("nicstar%d: Can't allocate buffers for aal0.\n",
37389 card->index);
37390 - atomic_add(i, &vcc->stats->rx_drop);
37391 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37392 break;
37393 }
37394 if (!atm_charge(vcc, sb->truesize)) {
37395 RXPRINTK
37396 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37397 card->index);
37398 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37399 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37400 dev_kfree_skb_any(sb);
37401 break;
37402 }
37403 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37404 ATM_SKB(sb)->vcc = vcc;
37405 __net_timestamp(sb);
37406 vcc->push(vcc, sb);
37407 - atomic_inc(&vcc->stats->rx);
37408 + atomic_inc_unchecked(&vcc->stats->rx);
37409 cell += ATM_CELL_PAYLOAD;
37410 }
37411
37412 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37413 if (iovb == NULL) {
37414 printk("nicstar%d: Out of iovec buffers.\n",
37415 card->index);
37416 - atomic_inc(&vcc->stats->rx_drop);
37417 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37418 recycle_rx_buf(card, skb);
37419 return;
37420 }
37421 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37422 small or large buffer itself. */
37423 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37424 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37425 - atomic_inc(&vcc->stats->rx_err);
37426 + atomic_inc_unchecked(&vcc->stats->rx_err);
37427 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37428 NS_MAX_IOVECS);
37429 NS_PRV_IOVCNT(iovb) = 0;
37430 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37431 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37432 card->index);
37433 which_list(card, skb);
37434 - atomic_inc(&vcc->stats->rx_err);
37435 + atomic_inc_unchecked(&vcc->stats->rx_err);
37436 recycle_rx_buf(card, skb);
37437 vc->rx_iov = NULL;
37438 recycle_iov_buf(card, iovb);
37439 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37440 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37441 card->index);
37442 which_list(card, skb);
37443 - atomic_inc(&vcc->stats->rx_err);
37444 + atomic_inc_unchecked(&vcc->stats->rx_err);
37445 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37446 NS_PRV_IOVCNT(iovb));
37447 vc->rx_iov = NULL;
37448 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37449 printk(" - PDU size mismatch.\n");
37450 else
37451 printk(".\n");
37452 - atomic_inc(&vcc->stats->rx_err);
37453 + atomic_inc_unchecked(&vcc->stats->rx_err);
37454 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37455 NS_PRV_IOVCNT(iovb));
37456 vc->rx_iov = NULL;
37457 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37458 /* skb points to a small buffer */
37459 if (!atm_charge(vcc, skb->truesize)) {
37460 push_rxbufs(card, skb);
37461 - atomic_inc(&vcc->stats->rx_drop);
37462 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37463 } else {
37464 skb_put(skb, len);
37465 dequeue_sm_buf(card, skb);
37466 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37467 ATM_SKB(skb)->vcc = vcc;
37468 __net_timestamp(skb);
37469 vcc->push(vcc, skb);
37470 - atomic_inc(&vcc->stats->rx);
37471 + atomic_inc_unchecked(&vcc->stats->rx);
37472 }
37473 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37474 struct sk_buff *sb;
37475 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37476 if (len <= NS_SMBUFSIZE) {
37477 if (!atm_charge(vcc, sb->truesize)) {
37478 push_rxbufs(card, sb);
37479 - atomic_inc(&vcc->stats->rx_drop);
37480 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37481 } else {
37482 skb_put(sb, len);
37483 dequeue_sm_buf(card, sb);
37484 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37485 ATM_SKB(sb)->vcc = vcc;
37486 __net_timestamp(sb);
37487 vcc->push(vcc, sb);
37488 - atomic_inc(&vcc->stats->rx);
37489 + atomic_inc_unchecked(&vcc->stats->rx);
37490 }
37491
37492 push_rxbufs(card, skb);
37493 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37494
37495 if (!atm_charge(vcc, skb->truesize)) {
37496 push_rxbufs(card, skb);
37497 - atomic_inc(&vcc->stats->rx_drop);
37498 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37499 } else {
37500 dequeue_lg_buf(card, skb);
37501 #ifdef NS_USE_DESTRUCTORS
37502 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37503 ATM_SKB(skb)->vcc = vcc;
37504 __net_timestamp(skb);
37505 vcc->push(vcc, skb);
37506 - atomic_inc(&vcc->stats->rx);
37507 + atomic_inc_unchecked(&vcc->stats->rx);
37508 }
37509
37510 push_rxbufs(card, sb);
37511 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37512 printk
37513 ("nicstar%d: Out of huge buffers.\n",
37514 card->index);
37515 - atomic_inc(&vcc->stats->rx_drop);
37516 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37517 recycle_iovec_rx_bufs(card,
37518 (struct iovec *)
37519 iovb->data,
37520 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37521 card->hbpool.count++;
37522 } else
37523 dev_kfree_skb_any(hb);
37524 - atomic_inc(&vcc->stats->rx_drop);
37525 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37526 } else {
37527 /* Copy the small buffer to the huge buffer */
37528 sb = (struct sk_buff *)iov->iov_base;
37529 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37530 #endif /* NS_USE_DESTRUCTORS */
37531 __net_timestamp(hb);
37532 vcc->push(vcc, hb);
37533 - atomic_inc(&vcc->stats->rx);
37534 + atomic_inc_unchecked(&vcc->stats->rx);
37535 }
37536 }
37537
37538 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37539 index 21b0bc6..b5f40ba 100644
37540 --- a/drivers/atm/solos-pci.c
37541 +++ b/drivers/atm/solos-pci.c
37542 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37543 }
37544 atm_charge(vcc, skb->truesize);
37545 vcc->push(vcc, skb);
37546 - atomic_inc(&vcc->stats->rx);
37547 + atomic_inc_unchecked(&vcc->stats->rx);
37548 break;
37549
37550 case PKT_STATUS:
37551 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37552 vcc = SKB_CB(oldskb)->vcc;
37553
37554 if (vcc) {
37555 - atomic_inc(&vcc->stats->tx);
37556 + atomic_inc_unchecked(&vcc->stats->tx);
37557 solos_pop(vcc, oldskb);
37558 } else {
37559 dev_kfree_skb_irq(oldskb);
37560 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37561 index 0215934..ce9f5b1 100644
37562 --- a/drivers/atm/suni.c
37563 +++ b/drivers/atm/suni.c
37564 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37565
37566
37567 #define ADD_LIMITED(s,v) \
37568 - atomic_add((v),&stats->s); \
37569 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37570 + atomic_add_unchecked((v),&stats->s); \
37571 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37572
37573
37574 static void suni_hz(unsigned long from_timer)
37575 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37576 index 5120a96..e2572bd 100644
37577 --- a/drivers/atm/uPD98402.c
37578 +++ b/drivers/atm/uPD98402.c
37579 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37580 struct sonet_stats tmp;
37581 int error = 0;
37582
37583 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37584 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37585 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37586 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37587 if (zero && !error) {
37588 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37589
37590
37591 #define ADD_LIMITED(s,v) \
37592 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37593 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37594 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37595 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37596 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37597 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37598
37599
37600 static void stat_event(struct atm_dev *dev)
37601 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37602 if (reason & uPD98402_INT_PFM) stat_event(dev);
37603 if (reason & uPD98402_INT_PCO) {
37604 (void) GET(PCOCR); /* clear interrupt cause */
37605 - atomic_add(GET(HECCT),
37606 + atomic_add_unchecked(GET(HECCT),
37607 &PRIV(dev)->sonet_stats.uncorr_hcs);
37608 }
37609 if ((reason & uPD98402_INT_RFO) &&
37610 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37611 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37612 uPD98402_INT_LOS),PIMR); /* enable them */
37613 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37614 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37615 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37616 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37617 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37618 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37619 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37620 return 0;
37621 }
37622
37623 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37624 index 969c3c2..9b72956 100644
37625 --- a/drivers/atm/zatm.c
37626 +++ b/drivers/atm/zatm.c
37627 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37628 }
37629 if (!size) {
37630 dev_kfree_skb_irq(skb);
37631 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37632 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37633 continue;
37634 }
37635 if (!atm_charge(vcc,skb->truesize)) {
37636 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37637 skb->len = size;
37638 ATM_SKB(skb)->vcc = vcc;
37639 vcc->push(vcc,skb);
37640 - atomic_inc(&vcc->stats->rx);
37641 + atomic_inc_unchecked(&vcc->stats->rx);
37642 }
37643 zout(pos & 0xffff,MTA(mbx));
37644 #if 0 /* probably a stupid idea */
37645 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37646 skb_queue_head(&zatm_vcc->backlog,skb);
37647 break;
37648 }
37649 - atomic_inc(&vcc->stats->tx);
37650 + atomic_inc_unchecked(&vcc->stats->tx);
37651 wake_up(&zatm_vcc->tx_wait);
37652 }
37653
37654 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37655 index 876bae5..8978785 100644
37656 --- a/drivers/base/bus.c
37657 +++ b/drivers/base/bus.c
37658 @@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37659 return -EINVAL;
37660
37661 mutex_lock(&subsys->p->mutex);
37662 - list_add_tail(&sif->node, &subsys->p->interfaces);
37663 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37664 if (sif->add_dev) {
37665 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37666 while ((dev = subsys_dev_iter_next(&iter)))
37667 @@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37668 subsys = sif->subsys;
37669
37670 mutex_lock(&subsys->p->mutex);
37671 - list_del_init(&sif->node);
37672 + pax_list_del_init((struct list_head *)&sif->node);
37673 if (sif->remove_dev) {
37674 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37675 while ((dev = subsys_dev_iter_next(&iter)))
37676 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37677 index 25798db..15f130e 100644
37678 --- a/drivers/base/devtmpfs.c
37679 +++ b/drivers/base/devtmpfs.c
37680 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37681 if (!thread)
37682 return 0;
37683
37684 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37685 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37686 if (err)
37687 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37688 else
37689 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37690 *err = sys_unshare(CLONE_NEWNS);
37691 if (*err)
37692 goto out;
37693 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37694 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37695 if (*err)
37696 goto out;
37697 - sys_chdir("/.."); /* will traverse into overmounted root */
37698 - sys_chroot(".");
37699 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37700 + sys_chroot((char __force_user *)".");
37701 complete(&setup_done);
37702 while (1) {
37703 spin_lock(&req_lock);
37704 diff --git a/drivers/base/node.c b/drivers/base/node.c
37705 index 472168c..4af587e 100644
37706 --- a/drivers/base/node.c
37707 +++ b/drivers/base/node.c
37708 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37709 struct node_attr {
37710 struct device_attribute attr;
37711 enum node_states state;
37712 -};
37713 +} __do_const;
37714
37715 static ssize_t show_node_state(struct device *dev,
37716 struct device_attribute *attr, char *buf)
37717 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37718 index fb83d4a..e1797b3 100644
37719 --- a/drivers/base/power/domain.c
37720 +++ b/drivers/base/power/domain.c
37721 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37722 {
37723 struct cpuidle_driver *cpuidle_drv;
37724 struct gpd_cpuidle_data *cpuidle_data;
37725 - struct cpuidle_state *idle_state;
37726 + cpuidle_state_no_const *idle_state;
37727 int ret = 0;
37728
37729 if (IS_ERR_OR_NULL(genpd) || state < 0)
37730 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37731 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37732 {
37733 struct gpd_cpuidle_data *cpuidle_data;
37734 - struct cpuidle_state *idle_state;
37735 + cpuidle_state_no_const *idle_state;
37736 int ret = 0;
37737
37738 if (IS_ERR_OR_NULL(genpd))
37739 @@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37740 return ret;
37741 }
37742
37743 - dev->pm_domain->detach = genpd_dev_pm_detach;
37744 + pax_open_kernel();
37745 + *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37746 + pax_close_kernel();
37747
37748 return 0;
37749 }
37750 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37751 index a9d26ed..74b8405 100644
37752 --- a/drivers/base/power/sysfs.c
37753 +++ b/drivers/base/power/sysfs.c
37754 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37755 return -EIO;
37756 }
37757 }
37758 - return sprintf(buf, p);
37759 + return sprintf(buf, "%s", p);
37760 }
37761
37762 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37763 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37764 index c2744b3..08fac19 100644
37765 --- a/drivers/base/power/wakeup.c
37766 +++ b/drivers/base/power/wakeup.c
37767 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37768 * They need to be modified together atomically, so it's better to use one
37769 * atomic variable to hold them both.
37770 */
37771 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37772 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37773
37774 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37775 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37776
37777 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37778 {
37779 - unsigned int comb = atomic_read(&combined_event_count);
37780 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37781
37782 *cnt = (comb >> IN_PROGRESS_BITS);
37783 *inpr = comb & MAX_IN_PROGRESS;
37784 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37785 ws->start_prevent_time = ws->last_time;
37786
37787 /* Increment the counter of events in progress. */
37788 - cec = atomic_inc_return(&combined_event_count);
37789 + cec = atomic_inc_return_unchecked(&combined_event_count);
37790
37791 trace_wakeup_source_activate(ws->name, cec);
37792 }
37793 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37794 * Increment the counter of registered wakeup events and decrement the
37795 * couter of wakeup events in progress simultaneously.
37796 */
37797 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37798 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37799 trace_wakeup_source_deactivate(ws->name, cec);
37800
37801 split_counters(&cnt, &inpr);
37802 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37803 index 8d98a32..61d3165 100644
37804 --- a/drivers/base/syscore.c
37805 +++ b/drivers/base/syscore.c
37806 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37807 void register_syscore_ops(struct syscore_ops *ops)
37808 {
37809 mutex_lock(&syscore_ops_lock);
37810 - list_add_tail(&ops->node, &syscore_ops_list);
37811 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37812 mutex_unlock(&syscore_ops_lock);
37813 }
37814 EXPORT_SYMBOL_GPL(register_syscore_ops);
37815 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37816 void unregister_syscore_ops(struct syscore_ops *ops)
37817 {
37818 mutex_lock(&syscore_ops_lock);
37819 - list_del(&ops->node);
37820 + pax_list_del((struct list_head *)&ops->node);
37821 mutex_unlock(&syscore_ops_lock);
37822 }
37823 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37824 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37825 index ff20f19..018f1da 100644
37826 --- a/drivers/block/cciss.c
37827 +++ b/drivers/block/cciss.c
37828 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37829 while (!list_empty(&h->reqQ)) {
37830 c = list_entry(h->reqQ.next, CommandList_struct, list);
37831 /* can't do anything if fifo is full */
37832 - if ((h->access.fifo_full(h))) {
37833 + if ((h->access->fifo_full(h))) {
37834 dev_warn(&h->pdev->dev, "fifo full\n");
37835 break;
37836 }
37837 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37838 h->Qdepth--;
37839
37840 /* Tell the controller execute command */
37841 - h->access.submit_command(h, c);
37842 + h->access->submit_command(h, c);
37843
37844 /* Put job onto the completed Q */
37845 addQ(&h->cmpQ, c);
37846 @@ -3444,17 +3444,17 @@ startio:
37847
37848 static inline unsigned long get_next_completion(ctlr_info_t *h)
37849 {
37850 - return h->access.command_completed(h);
37851 + return h->access->command_completed(h);
37852 }
37853
37854 static inline int interrupt_pending(ctlr_info_t *h)
37855 {
37856 - return h->access.intr_pending(h);
37857 + return h->access->intr_pending(h);
37858 }
37859
37860 static inline long interrupt_not_for_us(ctlr_info_t *h)
37861 {
37862 - return ((h->access.intr_pending(h) == 0) ||
37863 + return ((h->access->intr_pending(h) == 0) ||
37864 (h->interrupts_enabled == 0));
37865 }
37866
37867 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37868 u32 a;
37869
37870 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37871 - return h->access.command_completed(h);
37872 + return h->access->command_completed(h);
37873
37874 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37875 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37876 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37877 trans_support & CFGTBL_Trans_use_short_tags);
37878
37879 /* Change the access methods to the performant access methods */
37880 - h->access = SA5_performant_access;
37881 + h->access = &SA5_performant_access;
37882 h->transMethod = CFGTBL_Trans_Performant;
37883
37884 return;
37885 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37886 if (prod_index < 0)
37887 return -ENODEV;
37888 h->product_name = products[prod_index].product_name;
37889 - h->access = *(products[prod_index].access);
37890 + h->access = products[prod_index].access;
37891
37892 if (cciss_board_disabled(h)) {
37893 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37894 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37895 }
37896
37897 /* make sure the board interrupts are off */
37898 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37899 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37900 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37901 if (rc)
37902 goto clean2;
37903 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37904 * fake ones to scoop up any residual completions.
37905 */
37906 spin_lock_irqsave(&h->lock, flags);
37907 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37908 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37909 spin_unlock_irqrestore(&h->lock, flags);
37910 free_irq(h->intr[h->intr_mode], h);
37911 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37912 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37913 dev_info(&h->pdev->dev, "Board READY.\n");
37914 dev_info(&h->pdev->dev,
37915 "Waiting for stale completions to drain.\n");
37916 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37917 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37918 msleep(10000);
37919 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37920 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37921
37922 rc = controller_reset_failed(h->cfgtable);
37923 if (rc)
37924 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37925 cciss_scsi_setup(h);
37926
37927 /* Turn the interrupts on so we can service requests */
37928 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37929 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37930
37931 /* Get the firmware version */
37932 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37933 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37934 kfree(flush_buf);
37935 if (return_code != IO_OK)
37936 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37937 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37938 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37939 free_irq(h->intr[h->intr_mode], h);
37940 }
37941
37942 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37943 index 7fda30e..2f27946 100644
37944 --- a/drivers/block/cciss.h
37945 +++ b/drivers/block/cciss.h
37946 @@ -101,7 +101,7 @@ struct ctlr_info
37947 /* information about each logical volume */
37948 drive_info_struct *drv[CISS_MAX_LUN];
37949
37950 - struct access_method access;
37951 + struct access_method *access;
37952
37953 /* queue and queue Info */
37954 struct list_head reqQ;
37955 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37956 }
37957
37958 static struct access_method SA5_access = {
37959 - SA5_submit_command,
37960 - SA5_intr_mask,
37961 - SA5_fifo_full,
37962 - SA5_intr_pending,
37963 - SA5_completed,
37964 + .submit_command = SA5_submit_command,
37965 + .set_intr_mask = SA5_intr_mask,
37966 + .fifo_full = SA5_fifo_full,
37967 + .intr_pending = SA5_intr_pending,
37968 + .command_completed = SA5_completed,
37969 };
37970
37971 static struct access_method SA5B_access = {
37972 - SA5_submit_command,
37973 - SA5B_intr_mask,
37974 - SA5_fifo_full,
37975 - SA5B_intr_pending,
37976 - SA5_completed,
37977 + .submit_command = SA5_submit_command,
37978 + .set_intr_mask = SA5B_intr_mask,
37979 + .fifo_full = SA5_fifo_full,
37980 + .intr_pending = SA5B_intr_pending,
37981 + .command_completed = SA5_completed,
37982 };
37983
37984 static struct access_method SA5_performant_access = {
37985 - SA5_submit_command,
37986 - SA5_performant_intr_mask,
37987 - SA5_fifo_full,
37988 - SA5_performant_intr_pending,
37989 - SA5_performant_completed,
37990 + .submit_command = SA5_submit_command,
37991 + .set_intr_mask = SA5_performant_intr_mask,
37992 + .fifo_full = SA5_fifo_full,
37993 + .intr_pending = SA5_performant_intr_pending,
37994 + .command_completed = SA5_performant_completed,
37995 };
37996
37997 struct board_type {
37998 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37999 index 2b94403..fd6ad1f 100644
38000 --- a/drivers/block/cpqarray.c
38001 +++ b/drivers/block/cpqarray.c
38002 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38003 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38004 goto Enomem4;
38005 }
38006 - hba[i]->access.set_intr_mask(hba[i], 0);
38007 + hba[i]->access->set_intr_mask(hba[i], 0);
38008 if (request_irq(hba[i]->intr, do_ida_intr,
38009 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38010 {
38011 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38012 add_timer(&hba[i]->timer);
38013
38014 /* Enable IRQ now that spinlock and rate limit timer are set up */
38015 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38016 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38017
38018 for(j=0; j<NWD; j++) {
38019 struct gendisk *disk = ida_gendisk[i][j];
38020 @@ -694,7 +694,7 @@ DBGINFO(
38021 for(i=0; i<NR_PRODUCTS; i++) {
38022 if (board_id == products[i].board_id) {
38023 c->product_name = products[i].product_name;
38024 - c->access = *(products[i].access);
38025 + c->access = products[i].access;
38026 break;
38027 }
38028 }
38029 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38030 hba[ctlr]->intr = intr;
38031 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38032 hba[ctlr]->product_name = products[j].product_name;
38033 - hba[ctlr]->access = *(products[j].access);
38034 + hba[ctlr]->access = products[j].access;
38035 hba[ctlr]->ctlr = ctlr;
38036 hba[ctlr]->board_id = board_id;
38037 hba[ctlr]->pci_dev = NULL; /* not PCI */
38038 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38039
38040 while((c = h->reqQ) != NULL) {
38041 /* Can't do anything if we're busy */
38042 - if (h->access.fifo_full(h) == 0)
38043 + if (h->access->fifo_full(h) == 0)
38044 return;
38045
38046 /* Get the first entry from the request Q */
38047 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38048 h->Qdepth--;
38049
38050 /* Tell the controller to do our bidding */
38051 - h->access.submit_command(h, c);
38052 + h->access->submit_command(h, c);
38053
38054 /* Get onto the completion Q */
38055 addQ(&h->cmpQ, c);
38056 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38057 unsigned long flags;
38058 __u32 a,a1;
38059
38060 - istat = h->access.intr_pending(h);
38061 + istat = h->access->intr_pending(h);
38062 /* Is this interrupt for us? */
38063 if (istat == 0)
38064 return IRQ_NONE;
38065 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38066 */
38067 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38068 if (istat & FIFO_NOT_EMPTY) {
38069 - while((a = h->access.command_completed(h))) {
38070 + while((a = h->access->command_completed(h))) {
38071 a1 = a; a &= ~3;
38072 if ((c = h->cmpQ) == NULL)
38073 {
38074 @@ -1448,11 +1448,11 @@ static int sendcmd(
38075 /*
38076 * Disable interrupt
38077 */
38078 - info_p->access.set_intr_mask(info_p, 0);
38079 + info_p->access->set_intr_mask(info_p, 0);
38080 /* Make sure there is room in the command FIFO */
38081 /* Actually it should be completely empty at this time. */
38082 for (i = 200000; i > 0; i--) {
38083 - temp = info_p->access.fifo_full(info_p);
38084 + temp = info_p->access->fifo_full(info_p);
38085 if (temp != 0) {
38086 break;
38087 }
38088 @@ -1465,7 +1465,7 @@ DBG(
38089 /*
38090 * Send the cmd
38091 */
38092 - info_p->access.submit_command(info_p, c);
38093 + info_p->access->submit_command(info_p, c);
38094 complete = pollcomplete(ctlr);
38095
38096 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38097 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38098 * we check the new geometry. Then turn interrupts back on when
38099 * we're done.
38100 */
38101 - host->access.set_intr_mask(host, 0);
38102 + host->access->set_intr_mask(host, 0);
38103 getgeometry(ctlr);
38104 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38105 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38106
38107 for(i=0; i<NWD; i++) {
38108 struct gendisk *disk = ida_gendisk[ctlr][i];
38109 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38110 /* Wait (up to 2 seconds) for a command to complete */
38111
38112 for (i = 200000; i > 0; i--) {
38113 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38114 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38115 if (done == 0) {
38116 udelay(10); /* a short fixed delay */
38117 } else
38118 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38119 index be73e9d..7fbf140 100644
38120 --- a/drivers/block/cpqarray.h
38121 +++ b/drivers/block/cpqarray.h
38122 @@ -99,7 +99,7 @@ struct ctlr_info {
38123 drv_info_t drv[NWD];
38124 struct proc_dir_entry *proc;
38125
38126 - struct access_method access;
38127 + struct access_method *access;
38128
38129 cmdlist_t *reqQ;
38130 cmdlist_t *cmpQ;
38131 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38132 index 434c77d..6d3219a 100644
38133 --- a/drivers/block/drbd/drbd_bitmap.c
38134 +++ b/drivers/block/drbd/drbd_bitmap.c
38135 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38136 submit_bio(rw, bio);
38137 /* this should not count as user activity and cause the
38138 * resync to throttle -- see drbd_rs_should_slow_down(). */
38139 - atomic_add(len >> 9, &device->rs_sect_ev);
38140 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38141 }
38142 }
38143
38144 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38145 index 9b22f8f..f2932af 100644
38146 --- a/drivers/block/drbd/drbd_int.h
38147 +++ b/drivers/block/drbd/drbd_int.h
38148 @@ -385,7 +385,7 @@ struct drbd_epoch {
38149 struct drbd_connection *connection;
38150 struct list_head list;
38151 unsigned int barrier_nr;
38152 - atomic_t epoch_size; /* increased on every request added. */
38153 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38154 atomic_t active; /* increased on every req. added, and dec on every finished. */
38155 unsigned long flags;
38156 };
38157 @@ -946,7 +946,7 @@ struct drbd_device {
38158 unsigned int al_tr_number;
38159 int al_tr_cycle;
38160 wait_queue_head_t seq_wait;
38161 - atomic_t packet_seq;
38162 + atomic_unchecked_t packet_seq;
38163 unsigned int peer_seq;
38164 spinlock_t peer_seq_lock;
38165 unsigned long comm_bm_set; /* communicated number of set bits. */
38166 @@ -955,8 +955,8 @@ struct drbd_device {
38167 struct mutex own_state_mutex;
38168 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38169 char congestion_reason; /* Why we where congested... */
38170 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38171 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38172 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38173 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38174 int rs_last_sect_ev; /* counter to compare with */
38175 int rs_last_events; /* counter of read or write "events" (unit sectors)
38176 * on the lower level device when we last looked. */
38177 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38178 char __user *uoptval;
38179 int err;
38180
38181 - uoptval = (char __user __force *)optval;
38182 + uoptval = (char __force_user *)optval;
38183
38184 set_fs(KERNEL_DS);
38185 if (level == SOL_SOCKET)
38186 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38187 index 973c185..05d8b1a 100644
38188 --- a/drivers/block/drbd/drbd_main.c
38189 +++ b/drivers/block/drbd/drbd_main.c
38190 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38191 p->sector = sector;
38192 p->block_id = block_id;
38193 p->blksize = blksize;
38194 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38195 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38196 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38197 }
38198
38199 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38200 return -EIO;
38201 p->sector = cpu_to_be64(req->i.sector);
38202 p->block_id = (unsigned long)req;
38203 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38204 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38205 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38206 if (device->state.conn >= C_SYNC_SOURCE &&
38207 device->state.conn <= C_PAUSED_SYNC_T)
38208 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38209 atomic_set(&device->unacked_cnt, 0);
38210 atomic_set(&device->local_cnt, 0);
38211 atomic_set(&device->pp_in_use_by_net, 0);
38212 - atomic_set(&device->rs_sect_in, 0);
38213 - atomic_set(&device->rs_sect_ev, 0);
38214 + atomic_set_unchecked(&device->rs_sect_in, 0);
38215 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38216 atomic_set(&device->ap_in_flight, 0);
38217 atomic_set(&device->md_io.in_use, 0);
38218
38219 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38220 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38221 struct drbd_resource *resource = connection->resource;
38222
38223 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38224 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38225 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38226 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38227 kfree(connection->current_epoch);
38228
38229 idr_destroy(&connection->peer_devices);
38230 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38231 index 1cd47df..57c53c0 100644
38232 --- a/drivers/block/drbd/drbd_nl.c
38233 +++ b/drivers/block/drbd/drbd_nl.c
38234 @@ -3645,13 +3645,13 @@ finish:
38235
38236 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38237 {
38238 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38239 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38240 struct sk_buff *msg;
38241 struct drbd_genlmsghdr *d_out;
38242 unsigned seq;
38243 int err = -ENOMEM;
38244
38245 - seq = atomic_inc_return(&drbd_genl_seq);
38246 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38247 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38248 if (!msg)
38249 goto failed;
38250 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38251 index 6960fb0..215d76b 100644
38252 --- a/drivers/block/drbd/drbd_receiver.c
38253 +++ b/drivers/block/drbd/drbd_receiver.c
38254 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38255 struct drbd_device *device = peer_device->device;
38256 int err;
38257
38258 - atomic_set(&device->packet_seq, 0);
38259 + atomic_set_unchecked(&device->packet_seq, 0);
38260 device->peer_seq = 0;
38261
38262 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38263 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38264 do {
38265 next_epoch = NULL;
38266
38267 - epoch_size = atomic_read(&epoch->epoch_size);
38268 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38269
38270 switch (ev & ~EV_CLEANUP) {
38271 case EV_PUT:
38272 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38273 rv = FE_DESTROYED;
38274 } else {
38275 epoch->flags = 0;
38276 - atomic_set(&epoch->epoch_size, 0);
38277 + atomic_set_unchecked(&epoch->epoch_size, 0);
38278 /* atomic_set(&epoch->active, 0); is already zero */
38279 if (rv == FE_STILL_LIVE)
38280 rv = FE_RECYCLED;
38281 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38282 conn_wait_active_ee_empty(connection);
38283 drbd_flush(connection);
38284
38285 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38286 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38287 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38288 if (epoch)
38289 break;
38290 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38291 }
38292
38293 epoch->flags = 0;
38294 - atomic_set(&epoch->epoch_size, 0);
38295 + atomic_set_unchecked(&epoch->epoch_size, 0);
38296 atomic_set(&epoch->active, 0);
38297
38298 spin_lock(&connection->epoch_lock);
38299 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38300 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38301 list_add(&epoch->list, &connection->current_epoch->list);
38302 connection->current_epoch = epoch;
38303 connection->epochs++;
38304 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38305 list_add_tail(&peer_req->w.list, &device->sync_ee);
38306 spin_unlock_irq(&device->resource->req_lock);
38307
38308 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38309 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38310 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38311 return 0;
38312
38313 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38314 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38315 }
38316
38317 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38318 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38319
38320 return err;
38321 }
38322 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38323
38324 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38325 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38326 - atomic_inc(&connection->current_epoch->epoch_size);
38327 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38328 err2 = drbd_drain_block(peer_device, pi->size);
38329 if (!err)
38330 err = err2;
38331 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38332
38333 spin_lock(&connection->epoch_lock);
38334 peer_req->epoch = connection->current_epoch;
38335 - atomic_inc(&peer_req->epoch->epoch_size);
38336 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38337 atomic_inc(&peer_req->epoch->active);
38338 spin_unlock(&connection->epoch_lock);
38339
38340 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38341
38342 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38343 (int)part_stat_read(&disk->part0, sectors[1]) -
38344 - atomic_read(&device->rs_sect_ev);
38345 + atomic_read_unchecked(&device->rs_sect_ev);
38346
38347 if (atomic_read(&device->ap_actlog_cnt)
38348 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38349 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38350 device->use_csums = true;
38351 } else if (pi->cmd == P_OV_REPLY) {
38352 /* track progress, we may need to throttle */
38353 - atomic_add(size >> 9, &device->rs_sect_in);
38354 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38355 peer_req->w.cb = w_e_end_ov_reply;
38356 dec_rs_pending(device);
38357 /* drbd_rs_begin_io done when we sent this request,
38358 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38359 goto out_free_e;
38360
38361 submit_for_resync:
38362 - atomic_add(size >> 9, &device->rs_sect_ev);
38363 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38364
38365 submit:
38366 update_receiver_timing_details(connection, drbd_submit_peer_request);
38367 @@ -4564,7 +4564,7 @@ struct data_cmd {
38368 int expect_payload;
38369 size_t pkt_size;
38370 int (*fn)(struct drbd_connection *, struct packet_info *);
38371 -};
38372 +} __do_const;
38373
38374 static struct data_cmd drbd_cmd_handler[] = {
38375 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38376 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38377 if (!list_empty(&connection->current_epoch->list))
38378 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38379 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38380 - atomic_set(&connection->current_epoch->epoch_size, 0);
38381 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38382 connection->send.seen_any_write_yet = false;
38383
38384 drbd_info(connection, "Connection closed\n");
38385 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38386 put_ldev(device);
38387 }
38388 dec_rs_pending(device);
38389 - atomic_add(blksize >> 9, &device->rs_sect_in);
38390 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38391
38392 return 0;
38393 }
38394 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38395 struct asender_cmd {
38396 size_t pkt_size;
38397 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38398 -};
38399 +} __do_const;
38400
38401 static struct asender_cmd asender_tbl[] = {
38402 [P_PING] = { 0, got_Ping },
38403 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38404 index d2d1f97..6a1188f 100644
38405 --- a/drivers/block/drbd/drbd_worker.c
38406 +++ b/drivers/block/drbd/drbd_worker.c
38407 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38408 list_add_tail(&peer_req->w.list, &device->read_ee);
38409 spin_unlock_irq(&device->resource->req_lock);
38410
38411 - atomic_add(size >> 9, &device->rs_sect_ev);
38412 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38413 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38414 return 0;
38415
38416 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38417 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38418 int number, mxb;
38419
38420 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38421 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38422 device->rs_in_flight -= sect_in;
38423
38424 rcu_read_lock();
38425 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38426 {
38427 struct fifo_buffer *plan;
38428
38429 - atomic_set(&device->rs_sect_in, 0);
38430 - atomic_set(&device->rs_sect_ev, 0);
38431 + atomic_set_unchecked(&device->rs_sect_in, 0);
38432 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38433 device->rs_in_flight = 0;
38434
38435 /* Updating the RCU protected object in place is necessary since
38436 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38437 index 6cb1beb..bf490f7 100644
38438 --- a/drivers/block/loop.c
38439 +++ b/drivers/block/loop.c
38440 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38441
38442 file_start_write(file);
38443 set_fs(get_ds());
38444 - bw = file->f_op->write(file, buf, len, &pos);
38445 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38446 set_fs(old_fs);
38447 file_end_write(file);
38448 if (likely(bw == len))
38449 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38450 index e2bb8af..44b8aef 100644
38451 --- a/drivers/block/nvme-core.c
38452 +++ b/drivers/block/nvme-core.c
38453 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38454 static struct task_struct *nvme_thread;
38455 static struct workqueue_struct *nvme_workq;
38456 static wait_queue_head_t nvme_kthread_wait;
38457 -static struct notifier_block nvme_nb;
38458
38459 static void nvme_reset_failed_dev(struct work_struct *ws);
38460
38461 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38462 .err_handler = &nvme_err_handler,
38463 };
38464
38465 +static struct notifier_block nvme_nb = {
38466 + .notifier_call = &nvme_cpu_notify,
38467 +};
38468 +
38469 static int __init nvme_init(void)
38470 {
38471 int result;
38472 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38473 else if (result > 0)
38474 nvme_major = result;
38475
38476 - nvme_nb.notifier_call = &nvme_cpu_notify;
38477 result = register_hotcpu_notifier(&nvme_nb);
38478 if (result)
38479 goto unregister_blkdev;
38480 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38481 index 09e628da..7607aaa 100644
38482 --- a/drivers/block/pktcdvd.c
38483 +++ b/drivers/block/pktcdvd.c
38484 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38485
38486 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38487 {
38488 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38489 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38490 }
38491
38492 /*
38493 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38494 return -EROFS;
38495 }
38496 pd->settings.fp = ti.fp;
38497 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38498 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38499
38500 if (ti.nwa_v) {
38501 pd->nwa = be32_to_cpu(ti.next_writable);
38502 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38503 index e5565fb..71be10b4 100644
38504 --- a/drivers/block/smart1,2.h
38505 +++ b/drivers/block/smart1,2.h
38506 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38507 }
38508
38509 static struct access_method smart4_access = {
38510 - smart4_submit_command,
38511 - smart4_intr_mask,
38512 - smart4_fifo_full,
38513 - smart4_intr_pending,
38514 - smart4_completed,
38515 + .submit_command = smart4_submit_command,
38516 + .set_intr_mask = smart4_intr_mask,
38517 + .fifo_full = smart4_fifo_full,
38518 + .intr_pending = smart4_intr_pending,
38519 + .command_completed = smart4_completed,
38520 };
38521
38522 /*
38523 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38524 }
38525
38526 static struct access_method smart2_access = {
38527 - smart2_submit_command,
38528 - smart2_intr_mask,
38529 - smart2_fifo_full,
38530 - smart2_intr_pending,
38531 - smart2_completed,
38532 + .submit_command = smart2_submit_command,
38533 + .set_intr_mask = smart2_intr_mask,
38534 + .fifo_full = smart2_fifo_full,
38535 + .intr_pending = smart2_intr_pending,
38536 + .command_completed = smart2_completed,
38537 };
38538
38539 /*
38540 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38541 }
38542
38543 static struct access_method smart2e_access = {
38544 - smart2e_submit_command,
38545 - smart2e_intr_mask,
38546 - smart2e_fifo_full,
38547 - smart2e_intr_pending,
38548 - smart2e_completed,
38549 + .submit_command = smart2e_submit_command,
38550 + .set_intr_mask = smart2e_intr_mask,
38551 + .fifo_full = smart2e_fifo_full,
38552 + .intr_pending = smart2e_intr_pending,
38553 + .command_completed = smart2e_completed,
38554 };
38555
38556 /*
38557 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38558 }
38559
38560 static struct access_method smart1_access = {
38561 - smart1_submit_command,
38562 - smart1_intr_mask,
38563 - smart1_fifo_full,
38564 - smart1_intr_pending,
38565 - smart1_completed,
38566 + .submit_command = smart1_submit_command,
38567 + .set_intr_mask = smart1_intr_mask,
38568 + .fifo_full = smart1_fifo_full,
38569 + .intr_pending = smart1_intr_pending,
38570 + .command_completed = smart1_completed,
38571 };
38572 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38573 index f038dba..bb74c08 100644
38574 --- a/drivers/bluetooth/btwilink.c
38575 +++ b/drivers/bluetooth/btwilink.c
38576 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38577
38578 static int bt_ti_probe(struct platform_device *pdev)
38579 {
38580 - static struct ti_st *hst;
38581 + struct ti_st *hst;
38582 struct hci_dev *hdev;
38583 int err;
38584
38585 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38586 index 5d28a45..a538f90 100644
38587 --- a/drivers/cdrom/cdrom.c
38588 +++ b/drivers/cdrom/cdrom.c
38589 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38590 ENSURE(reset, CDC_RESET);
38591 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38592 cdi->mc_flags = 0;
38593 - cdo->n_minors = 0;
38594 cdi->options = CDO_USE_FFLAGS;
38595
38596 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38597 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38598 else
38599 cdi->cdda_method = CDDA_OLD;
38600
38601 - if (!cdo->generic_packet)
38602 - cdo->generic_packet = cdrom_dummy_generic_packet;
38603 + if (!cdo->generic_packet) {
38604 + pax_open_kernel();
38605 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38606 + pax_close_kernel();
38607 + }
38608
38609 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38610 mutex_lock(&cdrom_mutex);
38611 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38612 if (cdi->exit)
38613 cdi->exit(cdi);
38614
38615 - cdi->ops->n_minors--;
38616 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38617 }
38618
38619 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38620 */
38621 nr = nframes;
38622 do {
38623 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38624 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38625 if (cgc.buffer)
38626 break;
38627
38628 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38629 struct cdrom_device_info *cdi;
38630 int ret;
38631
38632 - ret = scnprintf(info + *pos, max_size - *pos, header);
38633 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38634 if (!ret)
38635 return 1;
38636
38637 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38638 index 584bc31..e64a12c 100644
38639 --- a/drivers/cdrom/gdrom.c
38640 +++ b/drivers/cdrom/gdrom.c
38641 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38642 .audio_ioctl = gdrom_audio_ioctl,
38643 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38644 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38645 - .n_minors = 1,
38646 };
38647
38648 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38649 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38650 index efefd12..4f1d494 100644
38651 --- a/drivers/char/Kconfig
38652 +++ b/drivers/char/Kconfig
38653 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38654
38655 config DEVKMEM
38656 bool "/dev/kmem virtual device support"
38657 - default y
38658 + default n
38659 + depends on !GRKERNSEC_KMEM
38660 help
38661 Say Y here if you want to support the /dev/kmem device. The
38662 /dev/kmem device is rarely used, but can be used for certain
38663 @@ -577,6 +578,7 @@ config DEVPORT
38664 bool
38665 depends on !M68K
38666 depends on ISA || PCI
38667 + depends on !GRKERNSEC_KMEM
38668 default y
38669
38670 source "drivers/s390/char/Kconfig"
38671 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38672 index a48e05b..6bac831 100644
38673 --- a/drivers/char/agp/compat_ioctl.c
38674 +++ b/drivers/char/agp/compat_ioctl.c
38675 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38676 return -ENOMEM;
38677 }
38678
38679 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38680 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38681 sizeof(*usegment) * ureserve.seg_count)) {
38682 kfree(usegment);
38683 kfree(ksegment);
38684 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38685 index 09f17eb..8531d2f 100644
38686 --- a/drivers/char/agp/frontend.c
38687 +++ b/drivers/char/agp/frontend.c
38688 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38689 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38690 return -EFAULT;
38691
38692 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38693 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38694 return -EFAULT;
38695
38696 client = agp_find_client_by_pid(reserve.pid);
38697 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38698 if (segment == NULL)
38699 return -ENOMEM;
38700
38701 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38702 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38703 sizeof(struct agp_segment) * reserve.seg_count)) {
38704 kfree(segment);
38705 return -EFAULT;
38706 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38707 index 4f94375..413694e 100644
38708 --- a/drivers/char/genrtc.c
38709 +++ b/drivers/char/genrtc.c
38710 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38711 switch (cmd) {
38712
38713 case RTC_PLL_GET:
38714 + memset(&pll, 0, sizeof(pll));
38715 if (get_rtc_pll(&pll))
38716 return -EINVAL;
38717 else
38718 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38719 index d5d4cd8..22d561d 100644
38720 --- a/drivers/char/hpet.c
38721 +++ b/drivers/char/hpet.c
38722 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38723 }
38724
38725 static int
38726 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38727 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38728 struct hpet_info *info)
38729 {
38730 struct hpet_timer __iomem *timer;
38731 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38732 index f816211..89eadea 100644
38733 --- a/drivers/char/ipmi/ipmi_msghandler.c
38734 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38735 @@ -438,7 +438,7 @@ struct ipmi_smi {
38736 struct proc_dir_entry *proc_dir;
38737 char proc_dir_name[10];
38738
38739 - atomic_t stats[IPMI_NUM_STATS];
38740 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38741
38742 /*
38743 * run_to_completion duplicate of smb_info, smi_info
38744 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38745 static DEFINE_MUTEX(smi_watchers_mutex);
38746
38747 #define ipmi_inc_stat(intf, stat) \
38748 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38749 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38750 #define ipmi_get_stat(intf, stat) \
38751 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38752 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38753
38754 static int is_lan_addr(struct ipmi_addr *addr)
38755 {
38756 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38757 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38758 init_waitqueue_head(&intf->waitq);
38759 for (i = 0; i < IPMI_NUM_STATS; i++)
38760 - atomic_set(&intf->stats[i], 0);
38761 + atomic_set_unchecked(&intf->stats[i], 0);
38762
38763 intf->proc_dir = NULL;
38764
38765 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38766 index 5c4e1f6..0ea58f9 100644
38767 --- a/drivers/char/ipmi/ipmi_si_intf.c
38768 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38769 @@ -285,7 +285,7 @@ struct smi_info {
38770 unsigned char slave_addr;
38771
38772 /* Counters and things for the proc filesystem. */
38773 - atomic_t stats[SI_NUM_STATS];
38774 + atomic_unchecked_t stats[SI_NUM_STATS];
38775
38776 struct task_struct *thread;
38777
38778 @@ -294,9 +294,9 @@ struct smi_info {
38779 };
38780
38781 #define smi_inc_stat(smi, stat) \
38782 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38783 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38784 #define smi_get_stat(smi, stat) \
38785 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38786 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38787
38788 #define SI_MAX_PARMS 4
38789
38790 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38791 atomic_set(&new_smi->req_events, 0);
38792 new_smi->run_to_completion = false;
38793 for (i = 0; i < SI_NUM_STATS; i++)
38794 - atomic_set(&new_smi->stats[i], 0);
38795 + atomic_set_unchecked(&new_smi->stats[i], 0);
38796
38797 new_smi->interrupt_disabled = true;
38798 atomic_set(&new_smi->stop_operation, 0);
38799 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38800 index 524b707..29d07c1 100644
38801 --- a/drivers/char/mem.c
38802 +++ b/drivers/char/mem.c
38803 @@ -18,6 +18,7 @@
38804 #include <linux/raw.h>
38805 #include <linux/tty.h>
38806 #include <linux/capability.h>
38807 +#include <linux/security.h>
38808 #include <linux/ptrace.h>
38809 #include <linux/device.h>
38810 #include <linux/highmem.h>
38811 @@ -36,6 +37,10 @@
38812
38813 #define DEVPORT_MINOR 4
38814
38815 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38816 +extern const struct file_operations grsec_fops;
38817 +#endif
38818 +
38819 static inline unsigned long size_inside_page(unsigned long start,
38820 unsigned long size)
38821 {
38822 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38823
38824 while (cursor < to) {
38825 if (!devmem_is_allowed(pfn)) {
38826 +#ifdef CONFIG_GRKERNSEC_KMEM
38827 + gr_handle_mem_readwrite(from, to);
38828 +#else
38829 printk(KERN_INFO
38830 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38831 current->comm, from, to);
38832 +#endif
38833 return 0;
38834 }
38835 cursor += PAGE_SIZE;
38836 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38837 }
38838 return 1;
38839 }
38840 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38841 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38842 +{
38843 + return 0;
38844 +}
38845 #else
38846 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38847 {
38848 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38849
38850 while (count > 0) {
38851 unsigned long remaining;
38852 + char *temp;
38853
38854 sz = size_inside_page(p, count);
38855
38856 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38857 if (!ptr)
38858 return -EFAULT;
38859
38860 - remaining = copy_to_user(buf, ptr, sz);
38861 +#ifdef CONFIG_PAX_USERCOPY
38862 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38863 + if (!temp) {
38864 + unxlate_dev_mem_ptr(p, ptr);
38865 + return -ENOMEM;
38866 + }
38867 + memcpy(temp, ptr, sz);
38868 +#else
38869 + temp = ptr;
38870 +#endif
38871 +
38872 + remaining = copy_to_user(buf, temp, sz);
38873 +
38874 +#ifdef CONFIG_PAX_USERCOPY
38875 + kfree(temp);
38876 +#endif
38877 +
38878 unxlate_dev_mem_ptr(p, ptr);
38879 if (remaining)
38880 return -EFAULT;
38881 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38882 size_t count, loff_t *ppos)
38883 {
38884 unsigned long p = *ppos;
38885 - ssize_t low_count, read, sz;
38886 + ssize_t low_count, read, sz, err = 0;
38887 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38888 - int err = 0;
38889
38890 read = 0;
38891 if (p < (unsigned long) high_memory) {
38892 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38893 }
38894 #endif
38895 while (low_count > 0) {
38896 + char *temp;
38897 +
38898 sz = size_inside_page(p, low_count);
38899
38900 /*
38901 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38902 */
38903 kbuf = xlate_dev_kmem_ptr((char *)p);
38904
38905 - if (copy_to_user(buf, kbuf, sz))
38906 +#ifdef CONFIG_PAX_USERCOPY
38907 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38908 + if (!temp)
38909 + return -ENOMEM;
38910 + memcpy(temp, kbuf, sz);
38911 +#else
38912 + temp = kbuf;
38913 +#endif
38914 +
38915 + err = copy_to_user(buf, temp, sz);
38916 +
38917 +#ifdef CONFIG_PAX_USERCOPY
38918 + kfree(temp);
38919 +#endif
38920 +
38921 + if (err)
38922 return -EFAULT;
38923 buf += sz;
38924 p += sz;
38925 @@ -797,6 +844,9 @@ static const struct memdev {
38926 #ifdef CONFIG_PRINTK
38927 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38928 #endif
38929 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38930 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38931 +#endif
38932 };
38933
38934 static int memory_open(struct inode *inode, struct file *filp)
38935 @@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38936 continue;
38937
38938 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38939 - NULL, devlist[minor].name);
38940 + NULL, "%s", devlist[minor].name);
38941 }
38942
38943 return tty_init();
38944 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38945 index 9df78e2..01ba9ae 100644
38946 --- a/drivers/char/nvram.c
38947 +++ b/drivers/char/nvram.c
38948 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38949
38950 spin_unlock_irq(&rtc_lock);
38951
38952 - if (copy_to_user(buf, contents, tmp - contents))
38953 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38954 return -EFAULT;
38955
38956 *ppos = i;
38957 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38958 index 0ea9986..e7b07e4 100644
38959 --- a/drivers/char/pcmcia/synclink_cs.c
38960 +++ b/drivers/char/pcmcia/synclink_cs.c
38961 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38962
38963 if (debug_level >= DEBUG_LEVEL_INFO)
38964 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38965 - __FILE__, __LINE__, info->device_name, port->count);
38966 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38967
38968 if (tty_port_close_start(port, tty, filp) == 0)
38969 goto cleanup;
38970 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38971 cleanup:
38972 if (debug_level >= DEBUG_LEVEL_INFO)
38973 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38974 - tty->driver->name, port->count);
38975 + tty->driver->name, atomic_read(&port->count));
38976 }
38977
38978 /* Wait until the transmitter is empty.
38979 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38980
38981 if (debug_level >= DEBUG_LEVEL_INFO)
38982 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38983 - __FILE__, __LINE__, tty->driver->name, port->count);
38984 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38985
38986 /* If port is closing, signal caller to try again */
38987 if (port->flags & ASYNC_CLOSING){
38988 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38989 goto cleanup;
38990 }
38991 spin_lock(&port->lock);
38992 - port->count++;
38993 + atomic_inc(&port->count);
38994 spin_unlock(&port->lock);
38995 spin_unlock_irqrestore(&info->netlock, flags);
38996
38997 - if (port->count == 1) {
38998 + if (atomic_read(&port->count) == 1) {
38999 /* 1st open on this device, init hardware */
39000 retval = startup(info, tty);
39001 if (retval < 0)
39002 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39003 unsigned short new_crctype;
39004
39005 /* return error if TTY interface open */
39006 - if (info->port.count)
39007 + if (atomic_read(&info->port.count))
39008 return -EBUSY;
39009
39010 switch (encoding)
39011 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39012
39013 /* arbitrate between network and tty opens */
39014 spin_lock_irqsave(&info->netlock, flags);
39015 - if (info->port.count != 0 || info->netcount != 0) {
39016 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39017 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39018 spin_unlock_irqrestore(&info->netlock, flags);
39019 return -EBUSY;
39020 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39021 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39022
39023 /* return error if TTY interface open */
39024 - if (info->port.count)
39025 + if (atomic_read(&info->port.count))
39026 return -EBUSY;
39027
39028 if (cmd != SIOCWANDEV)
39029 diff --git a/drivers/char/random.c b/drivers/char/random.c
39030 index 04645c0..560e350 100644
39031 --- a/drivers/char/random.c
39032 +++ b/drivers/char/random.c
39033 @@ -289,9 +289,6 @@
39034 /*
39035 * To allow fractional bits to be tracked, the entropy_count field is
39036 * denominated in units of 1/8th bits.
39037 - *
39038 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39039 - * credit_entropy_bits() needs to be 64 bits wide.
39040 */
39041 #define ENTROPY_SHIFT 3
39042 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39043 @@ -439,9 +436,9 @@ struct entropy_store {
39044 };
39045
39046 static void push_to_pool(struct work_struct *work);
39047 -static __u32 input_pool_data[INPUT_POOL_WORDS];
39048 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39049 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39050 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39051 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39052 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39053
39054 static struct entropy_store input_pool = {
39055 .poolinfo = &poolinfo_table[0],
39056 @@ -635,7 +632,7 @@ retry:
39057 /* The +2 corresponds to the /4 in the denominator */
39058
39059 do {
39060 - unsigned int anfrac = min(pnfrac, pool_size/2);
39061 + u64 anfrac = min(pnfrac, pool_size/2);
39062 unsigned int add =
39063 ((pool_size - entropy_count)*anfrac*3) >> s;
39064
39065 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39066
39067 extract_buf(r, tmp);
39068 i = min_t(int, nbytes, EXTRACT_SIZE);
39069 - if (copy_to_user(buf, tmp, i)) {
39070 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39071 ret = -EFAULT;
39072 break;
39073 }
39074 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39075 static int proc_do_uuid(struct ctl_table *table, int write,
39076 void __user *buffer, size_t *lenp, loff_t *ppos)
39077 {
39078 - struct ctl_table fake_table;
39079 + ctl_table_no_const fake_table;
39080 unsigned char buf[64], tmp_uuid[16], *uuid;
39081
39082 uuid = table->data;
39083 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39084 static int proc_do_entropy(struct ctl_table *table, int write,
39085 void __user *buffer, size_t *lenp, loff_t *ppos)
39086 {
39087 - struct ctl_table fake_table;
39088 + ctl_table_no_const fake_table;
39089 int entropy_count;
39090
39091 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39092 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39093 index 7cc1fe22..b602d6b 100644
39094 --- a/drivers/char/sonypi.c
39095 +++ b/drivers/char/sonypi.c
39096 @@ -54,6 +54,7 @@
39097
39098 #include <asm/uaccess.h>
39099 #include <asm/io.h>
39100 +#include <asm/local.h>
39101
39102 #include <linux/sonypi.h>
39103
39104 @@ -490,7 +491,7 @@ static struct sonypi_device {
39105 spinlock_t fifo_lock;
39106 wait_queue_head_t fifo_proc_list;
39107 struct fasync_struct *fifo_async;
39108 - int open_count;
39109 + local_t open_count;
39110 int model;
39111 struct input_dev *input_jog_dev;
39112 struct input_dev *input_key_dev;
39113 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39114 static int sonypi_misc_release(struct inode *inode, struct file *file)
39115 {
39116 mutex_lock(&sonypi_device.lock);
39117 - sonypi_device.open_count--;
39118 + local_dec(&sonypi_device.open_count);
39119 mutex_unlock(&sonypi_device.lock);
39120 return 0;
39121 }
39122 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39123 {
39124 mutex_lock(&sonypi_device.lock);
39125 /* Flush input queue on first open */
39126 - if (!sonypi_device.open_count)
39127 + if (!local_read(&sonypi_device.open_count))
39128 kfifo_reset(&sonypi_device.fifo);
39129 - sonypi_device.open_count++;
39130 + local_inc(&sonypi_device.open_count);
39131 mutex_unlock(&sonypi_device.lock);
39132
39133 return 0;
39134 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39135 index 565a947..dcdc06e 100644
39136 --- a/drivers/char/tpm/tpm_acpi.c
39137 +++ b/drivers/char/tpm/tpm_acpi.c
39138 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39139 virt = acpi_os_map_iomem(start, len);
39140 if (!virt) {
39141 kfree(log->bios_event_log);
39142 + log->bios_event_log = NULL;
39143 printk("%s: ERROR - Unable to map memory\n", __func__);
39144 return -EIO;
39145 }
39146
39147 - memcpy_fromio(log->bios_event_log, virt, len);
39148 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39149
39150 acpi_os_unmap_iomem(virt, len);
39151 return 0;
39152 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39153 index 3a56a13..f8cbd25 100644
39154 --- a/drivers/char/tpm/tpm_eventlog.c
39155 +++ b/drivers/char/tpm/tpm_eventlog.c
39156 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39157 event = addr;
39158
39159 if ((event->event_type == 0 && event->event_size == 0) ||
39160 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39161 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39162 return NULL;
39163
39164 return addr;
39165 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39166 return NULL;
39167
39168 if ((event->event_type == 0 && event->event_size == 0) ||
39169 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39170 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39171 return NULL;
39172
39173 (*pos)++;
39174 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39175 int i;
39176
39177 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39178 - seq_putc(m, data[i]);
39179 + if (!seq_putc(m, data[i]))
39180 + return -EFAULT;
39181
39182 return 0;
39183 }
39184 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39185 index cf7a561..c319ce0 100644
39186 --- a/drivers/char/virtio_console.c
39187 +++ b/drivers/char/virtio_console.c
39188 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39189 if (to_user) {
39190 ssize_t ret;
39191
39192 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39193 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39194 if (ret)
39195 return -EFAULT;
39196 } else {
39197 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39198 if (!port_has_data(port) && !port->host_connected)
39199 return 0;
39200
39201 - return fill_readbuf(port, ubuf, count, true);
39202 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39203 }
39204
39205 static int wait_port_writable(struct port *port, bool nonblock)
39206 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39207 index b9355da..9611f4e 100644
39208 --- a/drivers/clk/clk-composite.c
39209 +++ b/drivers/clk/clk-composite.c
39210 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39211 struct clk *clk;
39212 struct clk_init_data init;
39213 struct clk_composite *composite;
39214 - struct clk_ops *clk_composite_ops;
39215 + clk_ops_no_const *clk_composite_ops;
39216
39217 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39218 if (!composite) {
39219 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39220 index dd3a78c..386d49c 100644
39221 --- a/drivers/clk/socfpga/clk-gate.c
39222 +++ b/drivers/clk/socfpga/clk-gate.c
39223 @@ -22,6 +22,7 @@
39224 #include <linux/mfd/syscon.h>
39225 #include <linux/of.h>
39226 #include <linux/regmap.h>
39227 +#include <asm/pgtable.h>
39228
39229 #include "clk.h"
39230
39231 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39232 return 0;
39233 }
39234
39235 -static struct clk_ops gateclk_ops = {
39236 +static clk_ops_no_const gateclk_ops __read_only = {
39237 .prepare = socfpga_clk_prepare,
39238 .recalc_rate = socfpga_clk_recalc_rate,
39239 .get_parent = socfpga_clk_get_parent,
39240 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39241 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39242 socfpga_clk->hw.bit_idx = clk_gate[1];
39243
39244 - gateclk_ops.enable = clk_gate_ops.enable;
39245 - gateclk_ops.disable = clk_gate_ops.disable;
39246 + pax_open_kernel();
39247 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39248 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39249 + pax_close_kernel();
39250 }
39251
39252 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39253 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39254 index de6da95..c98278b 100644
39255 --- a/drivers/clk/socfpga/clk-pll.c
39256 +++ b/drivers/clk/socfpga/clk-pll.c
39257 @@ -21,6 +21,7 @@
39258 #include <linux/io.h>
39259 #include <linux/of.h>
39260 #include <linux/of_address.h>
39261 +#include <asm/pgtable.h>
39262
39263 #include "clk.h"
39264
39265 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39266 CLK_MGR_PLL_CLK_SRC_MASK;
39267 }
39268
39269 -static struct clk_ops clk_pll_ops = {
39270 +static clk_ops_no_const clk_pll_ops __read_only = {
39271 .recalc_rate = clk_pll_recalc_rate,
39272 .get_parent = clk_pll_get_parent,
39273 };
39274 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39275 pll_clk->hw.hw.init = &init;
39276
39277 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39278 - clk_pll_ops.enable = clk_gate_ops.enable;
39279 - clk_pll_ops.disable = clk_gate_ops.disable;
39280 + pax_open_kernel();
39281 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39282 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39283 + pax_close_kernel();
39284
39285 clk = clk_register(NULL, &pll_clk->hw.hw);
39286 if (WARN_ON(IS_ERR(clk))) {
39287 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39288 index b0c18ed..1713a80 100644
39289 --- a/drivers/cpufreq/acpi-cpufreq.c
39290 +++ b/drivers/cpufreq/acpi-cpufreq.c
39291 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39292 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39293 per_cpu(acfreq_data, cpu) = data;
39294
39295 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39296 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39297 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39298 + pax_open_kernel();
39299 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39300 + pax_close_kernel();
39301 + }
39302
39303 result = acpi_processor_register_performance(data->acpi_data, cpu);
39304 if (result)
39305 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39306 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39307 break;
39308 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39309 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39310 + pax_open_kernel();
39311 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39312 + pax_close_kernel();
39313 break;
39314 default:
39315 break;
39316 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39317 if (!msrs)
39318 return;
39319
39320 - acpi_cpufreq_driver.boost_supported = true;
39321 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39322 + pax_open_kernel();
39323 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39324 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39325 + pax_close_kernel();
39326
39327 cpu_notifier_register_begin();
39328
39329 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39330 index f657c57..31d97ae 100644
39331 --- a/drivers/cpufreq/cpufreq-dt.c
39332 +++ b/drivers/cpufreq/cpufreq-dt.c
39333 @@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39334 if (!IS_ERR(cpu_reg))
39335 regulator_put(cpu_reg);
39336
39337 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39338 + pax_open_kernel();
39339 + *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39340 + pax_close_kernel();
39341
39342 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39343 if (ret)
39344 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39345 index 4473eba..a4c9dc2 100644
39346 --- a/drivers/cpufreq/cpufreq.c
39347 +++ b/drivers/cpufreq/cpufreq.c
39348 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39349 }
39350
39351 mutex_lock(&cpufreq_governor_mutex);
39352 - list_del(&governor->governor_list);
39353 + pax_list_del(&governor->governor_list);
39354 mutex_unlock(&cpufreq_governor_mutex);
39355 return;
39356 }
39357 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39358 return NOTIFY_OK;
39359 }
39360
39361 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39362 +static struct notifier_block cpufreq_cpu_notifier = {
39363 .notifier_call = cpufreq_cpu_callback,
39364 };
39365
39366 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39367 return 0;
39368
39369 write_lock_irqsave(&cpufreq_driver_lock, flags);
39370 - cpufreq_driver->boost_enabled = state;
39371 + pax_open_kernel();
39372 + *(bool *)&cpufreq_driver->boost_enabled = state;
39373 + pax_close_kernel();
39374 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39375
39376 ret = cpufreq_driver->set_boost(state);
39377 if (ret) {
39378 write_lock_irqsave(&cpufreq_driver_lock, flags);
39379 - cpufreq_driver->boost_enabled = !state;
39380 + pax_open_kernel();
39381 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39382 + pax_close_kernel();
39383 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39384
39385 pr_err("%s: Cannot %s BOOST\n",
39386 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39387
39388 pr_debug("trying to register driver %s\n", driver_data->name);
39389
39390 - if (driver_data->setpolicy)
39391 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39392 + if (driver_data->setpolicy) {
39393 + pax_open_kernel();
39394 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39395 + pax_close_kernel();
39396 + }
39397
39398 write_lock_irqsave(&cpufreq_driver_lock, flags);
39399 if (cpufreq_driver) {
39400 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39401 * Check if driver provides function to enable boost -
39402 * if not, use cpufreq_boost_set_sw as default
39403 */
39404 - if (!cpufreq_driver->set_boost)
39405 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39406 + if (!cpufreq_driver->set_boost) {
39407 + pax_open_kernel();
39408 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39409 + pax_close_kernel();
39410 + }
39411
39412 ret = cpufreq_sysfs_create_file(&boost.attr);
39413 if (ret) {
39414 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39415 index 1b44496..b80ff5e 100644
39416 --- a/drivers/cpufreq/cpufreq_governor.c
39417 +++ b/drivers/cpufreq/cpufreq_governor.c
39418 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39419 struct dbs_data *dbs_data;
39420 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39421 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39422 - struct od_ops *od_ops = NULL;
39423 + const struct od_ops *od_ops = NULL;
39424 struct od_dbs_tuners *od_tuners = NULL;
39425 struct cs_dbs_tuners *cs_tuners = NULL;
39426 struct cpu_dbs_common_info *cpu_cdbs;
39427 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39428
39429 if ((cdata->governor == GOV_CONSERVATIVE) &&
39430 (!policy->governor->initialized)) {
39431 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39432 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39433
39434 cpufreq_register_notifier(cs_ops->notifier_block,
39435 CPUFREQ_TRANSITION_NOTIFIER);
39436 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39437
39438 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39439 (policy->governor->initialized == 1)) {
39440 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39441 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39442
39443 cpufreq_unregister_notifier(cs_ops->notifier_block,
39444 CPUFREQ_TRANSITION_NOTIFIER);
39445 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39446 index cc401d1..8197340 100644
39447 --- a/drivers/cpufreq/cpufreq_governor.h
39448 +++ b/drivers/cpufreq/cpufreq_governor.h
39449 @@ -212,7 +212,7 @@ struct common_dbs_data {
39450 void (*exit)(struct dbs_data *dbs_data);
39451
39452 /* Governor specific ops, see below */
39453 - void *gov_ops;
39454 + const void *gov_ops;
39455 };
39456
39457 /* Governor Per policy data */
39458 @@ -232,7 +232,7 @@ struct od_ops {
39459 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39460 unsigned int freq_next, unsigned int relation);
39461 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39462 -};
39463 +} __no_const;
39464
39465 struct cs_ops {
39466 struct notifier_block *notifier_block;
39467 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39468 index ad3f38f..8f086cd 100644
39469 --- a/drivers/cpufreq/cpufreq_ondemand.c
39470 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39471 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39472
39473 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39474
39475 -static struct od_ops od_ops = {
39476 +static struct od_ops od_ops __read_only = {
39477 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39478 .powersave_bias_target = generic_powersave_bias_target,
39479 .freq_increase = dbs_freq_increase,
39480 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39481 (struct cpufreq_policy *, unsigned int, unsigned int),
39482 unsigned int powersave_bias)
39483 {
39484 - od_ops.powersave_bias_target = f;
39485 + pax_open_kernel();
39486 + *(void **)&od_ops.powersave_bias_target = f;
39487 + pax_close_kernel();
39488 od_set_powersave_bias(powersave_bias);
39489 }
39490 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39491
39492 void od_unregister_powersave_bias_handler(void)
39493 {
39494 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39495 + pax_open_kernel();
39496 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39497 + pax_close_kernel();
39498 od_set_powersave_bias(0);
39499 }
39500 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39501 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39502 index 27bb6d3..4cf595c 100644
39503 --- a/drivers/cpufreq/intel_pstate.c
39504 +++ b/drivers/cpufreq/intel_pstate.c
39505 @@ -133,10 +133,10 @@ struct pstate_funcs {
39506 struct cpu_defaults {
39507 struct pstate_adjust_policy pid_policy;
39508 struct pstate_funcs funcs;
39509 -};
39510 +} __do_const;
39511
39512 static struct pstate_adjust_policy pid_params;
39513 -static struct pstate_funcs pstate_funcs;
39514 +static struct pstate_funcs *pstate_funcs;
39515
39516 struct perf_limits {
39517 int no_turbo;
39518 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39519
39520 cpu->pstate.current_pstate = pstate;
39521
39522 - pstate_funcs.set(cpu, pstate);
39523 + pstate_funcs->set(cpu, pstate);
39524 }
39525
39526 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39527 {
39528 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39529 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39530 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39531 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39532 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39533 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39534 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39535 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39536
39537 - if (pstate_funcs.get_vid)
39538 - pstate_funcs.get_vid(cpu);
39539 + if (pstate_funcs->get_vid)
39540 + pstate_funcs->get_vid(cpu);
39541 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39542 }
39543
39544 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39545 rdmsrl(MSR_IA32_APERF, aperf);
39546 rdmsrl(MSR_IA32_MPERF, mperf);
39547
39548 - if (!pstate_funcs.get_max() ||
39549 - !pstate_funcs.get_min() ||
39550 - !pstate_funcs.get_turbo())
39551 + if (!pstate_funcs->get_max() ||
39552 + !pstate_funcs->get_min() ||
39553 + !pstate_funcs->get_turbo())
39554 return -ENODEV;
39555
39556 rdmsrl(MSR_IA32_APERF, tmp);
39557 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39558 return 0;
39559 }
39560
39561 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39562 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39563 {
39564 pid_params.sample_rate_ms = policy->sample_rate_ms;
39565 pid_params.p_gain_pct = policy->p_gain_pct;
39566 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39567
39568 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39569 {
39570 - pstate_funcs.get_max = funcs->get_max;
39571 - pstate_funcs.get_min = funcs->get_min;
39572 - pstate_funcs.get_turbo = funcs->get_turbo;
39573 - pstate_funcs.get_scaling = funcs->get_scaling;
39574 - pstate_funcs.set = funcs->set;
39575 - pstate_funcs.get_vid = funcs->get_vid;
39576 + pstate_funcs = funcs;
39577 }
39578
39579 #if IS_ENABLED(CONFIG_ACPI)
39580 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39581 index 529cfd9..0e28fff 100644
39582 --- a/drivers/cpufreq/p4-clockmod.c
39583 +++ b/drivers/cpufreq/p4-clockmod.c
39584 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39585 case 0x0F: /* Core Duo */
39586 case 0x16: /* Celeron Core */
39587 case 0x1C: /* Atom */
39588 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39589 + pax_open_kernel();
39590 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39591 + pax_close_kernel();
39592 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39593 case 0x0D: /* Pentium M (Dothan) */
39594 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39595 + pax_open_kernel();
39596 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39597 + pax_close_kernel();
39598 /* fall through */
39599 case 0x09: /* Pentium M (Banias) */
39600 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39601 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39602
39603 /* on P-4s, the TSC runs with constant frequency independent whether
39604 * throttling is active or not. */
39605 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39606 + pax_open_kernel();
39607 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39608 + pax_close_kernel();
39609
39610 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39611 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39612 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39613 index 9bb42ba..b01b4a2 100644
39614 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39615 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39616 @@ -18,14 +18,12 @@
39617 #include <asm/head.h>
39618 #include <asm/timer.h>
39619
39620 -static struct cpufreq_driver *cpufreq_us3_driver;
39621 -
39622 struct us3_freq_percpu_info {
39623 struct cpufreq_frequency_table table[4];
39624 };
39625
39626 /* Indexed by cpu number. */
39627 -static struct us3_freq_percpu_info *us3_freq_table;
39628 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39629
39630 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39631 * in the Safari config register.
39632 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39633
39634 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39635 {
39636 - if (cpufreq_us3_driver)
39637 - us3_freq_target(policy, 0);
39638 + us3_freq_target(policy, 0);
39639
39640 return 0;
39641 }
39642
39643 +static int __init us3_freq_init(void);
39644 +static void __exit us3_freq_exit(void);
39645 +
39646 +static struct cpufreq_driver cpufreq_us3_driver = {
39647 + .init = us3_freq_cpu_init,
39648 + .verify = cpufreq_generic_frequency_table_verify,
39649 + .target_index = us3_freq_target,
39650 + .get = us3_freq_get,
39651 + .exit = us3_freq_cpu_exit,
39652 + .name = "UltraSPARC-III",
39653 +
39654 +};
39655 +
39656 static int __init us3_freq_init(void)
39657 {
39658 unsigned long manuf, impl, ver;
39659 - int ret;
39660
39661 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39662 return -ENODEV;
39663 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39664 (impl == CHEETAH_IMPL ||
39665 impl == CHEETAH_PLUS_IMPL ||
39666 impl == JAGUAR_IMPL ||
39667 - impl == PANTHER_IMPL)) {
39668 - struct cpufreq_driver *driver;
39669 -
39670 - ret = -ENOMEM;
39671 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39672 - if (!driver)
39673 - goto err_out;
39674 -
39675 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39676 - GFP_KERNEL);
39677 - if (!us3_freq_table)
39678 - goto err_out;
39679 -
39680 - driver->init = us3_freq_cpu_init;
39681 - driver->verify = cpufreq_generic_frequency_table_verify;
39682 - driver->target_index = us3_freq_target;
39683 - driver->get = us3_freq_get;
39684 - driver->exit = us3_freq_cpu_exit;
39685 - strcpy(driver->name, "UltraSPARC-III");
39686 -
39687 - cpufreq_us3_driver = driver;
39688 - ret = cpufreq_register_driver(driver);
39689 - if (ret)
39690 - goto err_out;
39691 -
39692 - return 0;
39693 -
39694 -err_out:
39695 - if (driver) {
39696 - kfree(driver);
39697 - cpufreq_us3_driver = NULL;
39698 - }
39699 - kfree(us3_freq_table);
39700 - us3_freq_table = NULL;
39701 - return ret;
39702 - }
39703 + impl == PANTHER_IMPL))
39704 + return cpufreq_register_driver(&cpufreq_us3_driver);
39705
39706 return -ENODEV;
39707 }
39708
39709 static void __exit us3_freq_exit(void)
39710 {
39711 - if (cpufreq_us3_driver) {
39712 - cpufreq_unregister_driver(cpufreq_us3_driver);
39713 - kfree(cpufreq_us3_driver);
39714 - cpufreq_us3_driver = NULL;
39715 - kfree(us3_freq_table);
39716 - us3_freq_table = NULL;
39717 - }
39718 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39719 }
39720
39721 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39722 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39723 index 7d4a315..21bb886 100644
39724 --- a/drivers/cpufreq/speedstep-centrino.c
39725 +++ b/drivers/cpufreq/speedstep-centrino.c
39726 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39727 !cpu_has(cpu, X86_FEATURE_EST))
39728 return -ENODEV;
39729
39730 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39731 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39732 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39733 + pax_open_kernel();
39734 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39735 + pax_close_kernel();
39736 + }
39737
39738 if (policy->cpu != 0)
39739 return -ENODEV;
39740 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39741 index e431d11..d0b997e 100644
39742 --- a/drivers/cpuidle/driver.c
39743 +++ b/drivers/cpuidle/driver.c
39744 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39745
39746 static void poll_idle_init(struct cpuidle_driver *drv)
39747 {
39748 - struct cpuidle_state *state = &drv->states[0];
39749 + cpuidle_state_no_const *state = &drv->states[0];
39750
39751 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39752 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39753 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39754 index fb9f511..213e6cc 100644
39755 --- a/drivers/cpuidle/governor.c
39756 +++ b/drivers/cpuidle/governor.c
39757 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39758 mutex_lock(&cpuidle_lock);
39759 if (__cpuidle_find_governor(gov->name) == NULL) {
39760 ret = 0;
39761 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39762 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39763 if (!cpuidle_curr_governor ||
39764 cpuidle_curr_governor->rating < gov->rating)
39765 cpuidle_switch_governor(gov);
39766 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39767 index 97c5903..023ad23 100644
39768 --- a/drivers/cpuidle/sysfs.c
39769 +++ b/drivers/cpuidle/sysfs.c
39770 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39771 NULL
39772 };
39773
39774 -static struct attribute_group cpuidle_attr_group = {
39775 +static attribute_group_no_const cpuidle_attr_group = {
39776 .attrs = cpuidle_default_attrs,
39777 .name = "cpuidle",
39778 };
39779 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39780 index 8d2a772..33826c9 100644
39781 --- a/drivers/crypto/hifn_795x.c
39782 +++ b/drivers/crypto/hifn_795x.c
39783 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39784 MODULE_PARM_DESC(hifn_pll_ref,
39785 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39786
39787 -static atomic_t hifn_dev_number;
39788 +static atomic_unchecked_t hifn_dev_number;
39789
39790 #define ACRYPTO_OP_DECRYPT 0
39791 #define ACRYPTO_OP_ENCRYPT 1
39792 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39793 goto err_out_disable_pci_device;
39794
39795 snprintf(name, sizeof(name), "hifn%d",
39796 - atomic_inc_return(&hifn_dev_number)-1);
39797 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39798
39799 err = pci_request_regions(pdev, name);
39800 if (err)
39801 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39802 index 30b538d8..1610d75 100644
39803 --- a/drivers/devfreq/devfreq.c
39804 +++ b/drivers/devfreq/devfreq.c
39805 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39806 goto err_out;
39807 }
39808
39809 - list_add(&governor->node, &devfreq_governor_list);
39810 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39811
39812 list_for_each_entry(devfreq, &devfreq_list, node) {
39813 int ret = 0;
39814 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39815 }
39816 }
39817
39818 - list_del(&governor->node);
39819 + pax_list_del((struct list_head *)&governor->node);
39820 err_out:
39821 mutex_unlock(&devfreq_list_lock);
39822
39823 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39824 index 42d4974..2714f36 100644
39825 --- a/drivers/dma/sh/shdma-base.c
39826 +++ b/drivers/dma/sh/shdma-base.c
39827 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39828 schan->slave_id = -EINVAL;
39829 }
39830
39831 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39832 - sdev->desc_size, GFP_KERNEL);
39833 + schan->desc = kcalloc(sdev->desc_size,
39834 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39835 if (!schan->desc) {
39836 ret = -ENOMEM;
39837 goto edescalloc;
39838 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39839 index 58eb857..d7e42c8 100644
39840 --- a/drivers/dma/sh/shdmac.c
39841 +++ b/drivers/dma/sh/shdmac.c
39842 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39843 return ret;
39844 }
39845
39846 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39847 +static struct notifier_block sh_dmae_nmi_notifier = {
39848 .notifier_call = sh_dmae_nmi_handler,
39849
39850 /* Run before NMI debug handler and KGDB */
39851 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39852 index 592af5f..bb1d583 100644
39853 --- a/drivers/edac/edac_device.c
39854 +++ b/drivers/edac/edac_device.c
39855 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39856 */
39857 int edac_device_alloc_index(void)
39858 {
39859 - static atomic_t device_indexes = ATOMIC_INIT(0);
39860 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39861
39862 - return atomic_inc_return(&device_indexes) - 1;
39863 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39864 }
39865 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39866
39867 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39868 index a6cd361..7bdbf53 100644
39869 --- a/drivers/edac/edac_mc_sysfs.c
39870 +++ b/drivers/edac/edac_mc_sysfs.c
39871 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39872 struct dev_ch_attribute {
39873 struct device_attribute attr;
39874 int channel;
39875 -};
39876 +} __do_const;
39877
39878 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39879 struct dev_ch_attribute dev_attr_legacy_##_name = \
39880 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39881 }
39882
39883 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39884 + pax_open_kernel();
39885 if (mci->get_sdram_scrub_rate) {
39886 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39887 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39888 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39889 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39890 }
39891 if (mci->set_sdram_scrub_rate) {
39892 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39893 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39894 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39895 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39896 }
39897 + pax_close_kernel();
39898 err = device_create_file(&mci->dev,
39899 &dev_attr_sdram_scrub_rate);
39900 if (err) {
39901 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39902 index 2cf44b4d..6dd2dc7 100644
39903 --- a/drivers/edac/edac_pci.c
39904 +++ b/drivers/edac/edac_pci.c
39905 @@ -29,7 +29,7 @@
39906
39907 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39908 static LIST_HEAD(edac_pci_list);
39909 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39910 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39911
39912 /*
39913 * edac_pci_alloc_ctl_info
39914 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39915 */
39916 int edac_pci_alloc_index(void)
39917 {
39918 - return atomic_inc_return(&pci_indexes) - 1;
39919 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39920 }
39921 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39922
39923 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39924 index e8658e4..22746d6 100644
39925 --- a/drivers/edac/edac_pci_sysfs.c
39926 +++ b/drivers/edac/edac_pci_sysfs.c
39927 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39928 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39929 static int edac_pci_poll_msec = 1000; /* one second workq period */
39930
39931 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39932 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39933 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39934 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39935
39936 static struct kobject *edac_pci_top_main_kobj;
39937 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39938 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39939 void *value;
39940 ssize_t(*show) (void *, char *);
39941 ssize_t(*store) (void *, const char *, size_t);
39942 -};
39943 +} __do_const;
39944
39945 /* Set of show/store abstract level functions for PCI Parity object */
39946 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39947 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39948 edac_printk(KERN_CRIT, EDAC_PCI,
39949 "Signaled System Error on %s\n",
39950 pci_name(dev));
39951 - atomic_inc(&pci_nonparity_count);
39952 + atomic_inc_unchecked(&pci_nonparity_count);
39953 }
39954
39955 if (status & (PCI_STATUS_PARITY)) {
39956 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39957 "Master Data Parity Error on %s\n",
39958 pci_name(dev));
39959
39960 - atomic_inc(&pci_parity_count);
39961 + atomic_inc_unchecked(&pci_parity_count);
39962 }
39963
39964 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39965 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39966 "Detected Parity Error on %s\n",
39967 pci_name(dev));
39968
39969 - atomic_inc(&pci_parity_count);
39970 + atomic_inc_unchecked(&pci_parity_count);
39971 }
39972 }
39973
39974 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39975 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39976 "Signaled System Error on %s\n",
39977 pci_name(dev));
39978 - atomic_inc(&pci_nonparity_count);
39979 + atomic_inc_unchecked(&pci_nonparity_count);
39980 }
39981
39982 if (status & (PCI_STATUS_PARITY)) {
39983 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39984 "Master Data Parity Error on "
39985 "%s\n", pci_name(dev));
39986
39987 - atomic_inc(&pci_parity_count);
39988 + atomic_inc_unchecked(&pci_parity_count);
39989 }
39990
39991 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39992 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39993 "Detected Parity Error on %s\n",
39994 pci_name(dev));
39995
39996 - atomic_inc(&pci_parity_count);
39997 + atomic_inc_unchecked(&pci_parity_count);
39998 }
39999 }
40000 }
40001 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40002 if (!check_pci_errors)
40003 return;
40004
40005 - before_count = atomic_read(&pci_parity_count);
40006 + before_count = atomic_read_unchecked(&pci_parity_count);
40007
40008 /* scan all PCI devices looking for a Parity Error on devices and
40009 * bridges.
40010 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40011 /* Only if operator has selected panic on PCI Error */
40012 if (edac_pci_get_panic_on_pe()) {
40013 /* If the count is different 'after' from 'before' */
40014 - if (before_count != atomic_read(&pci_parity_count))
40015 + if (before_count != atomic_read_unchecked(&pci_parity_count))
40016 panic("EDAC: PCI Parity Error");
40017 }
40018 }
40019 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40020 index 51b7e3a..aa8a3e8 100644
40021 --- a/drivers/edac/mce_amd.h
40022 +++ b/drivers/edac/mce_amd.h
40023 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
40024 bool (*mc0_mce)(u16, u8);
40025 bool (*mc1_mce)(u16, u8);
40026 bool (*mc2_mce)(u16, u8);
40027 -};
40028 +} __no_const;
40029
40030 void amd_report_gart_errors(bool);
40031 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40032 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40033 index 57ea7f4..af06b76 100644
40034 --- a/drivers/firewire/core-card.c
40035 +++ b/drivers/firewire/core-card.c
40036 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40037 const struct fw_card_driver *driver,
40038 struct device *device)
40039 {
40040 - static atomic_t index = ATOMIC_INIT(-1);
40041 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
40042
40043 - card->index = atomic_inc_return(&index);
40044 + card->index = atomic_inc_return_unchecked(&index);
40045 card->driver = driver;
40046 card->device = device;
40047 card->current_tlabel = 0;
40048 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40049
40050 void fw_core_remove_card(struct fw_card *card)
40051 {
40052 - struct fw_card_driver dummy_driver = dummy_driver_template;
40053 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40054
40055 card->driver->update_phy_reg(card, 4,
40056 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40057 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40058 index 2c6d5e1..a2cca6b 100644
40059 --- a/drivers/firewire/core-device.c
40060 +++ b/drivers/firewire/core-device.c
40061 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40062 struct config_rom_attribute {
40063 struct device_attribute attr;
40064 u32 key;
40065 -};
40066 +} __do_const;
40067
40068 static ssize_t show_immediate(struct device *dev,
40069 struct device_attribute *dattr, char *buf)
40070 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40071 index eb6935c..3cc2bfa 100644
40072 --- a/drivers/firewire/core-transaction.c
40073 +++ b/drivers/firewire/core-transaction.c
40074 @@ -38,6 +38,7 @@
40075 #include <linux/timer.h>
40076 #include <linux/types.h>
40077 #include <linux/workqueue.h>
40078 +#include <linux/sched.h>
40079
40080 #include <asm/byteorder.h>
40081
40082 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40083 index e1480ff6..1a429bd 100644
40084 --- a/drivers/firewire/core.h
40085 +++ b/drivers/firewire/core.h
40086 @@ -111,6 +111,7 @@ struct fw_card_driver {
40087
40088 int (*stop_iso)(struct fw_iso_context *ctx);
40089 };
40090 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40091
40092 void fw_card_initialize(struct fw_card *card,
40093 const struct fw_card_driver *driver, struct device *device);
40094 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40095 index a66a321..f6caf20 100644
40096 --- a/drivers/firewire/ohci.c
40097 +++ b/drivers/firewire/ohci.c
40098 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40099 be32_to_cpu(ohci->next_header));
40100 }
40101
40102 +#ifndef CONFIG_GRKERNSEC
40103 if (param_remote_dma) {
40104 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40105 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40106 }
40107 +#endif
40108
40109 spin_unlock_irq(&ohci->lock);
40110
40111 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40112 unsigned long flags;
40113 int n, ret = 0;
40114
40115 +#ifndef CONFIG_GRKERNSEC
40116 if (param_remote_dma)
40117 return 0;
40118 +#endif
40119
40120 /*
40121 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40122 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40123 index 94a58a0..f5eba42 100644
40124 --- a/drivers/firmware/dmi-id.c
40125 +++ b/drivers/firmware/dmi-id.c
40126 @@ -16,7 +16,7 @@
40127 struct dmi_device_attribute{
40128 struct device_attribute dev_attr;
40129 int field;
40130 -};
40131 +} __do_const;
40132 #define to_dmi_dev_attr(_dev_attr) \
40133 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40134
40135 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40136 index 17afc51..0ef90cd 100644
40137 --- a/drivers/firmware/dmi_scan.c
40138 +++ b/drivers/firmware/dmi_scan.c
40139 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40140 if (buf == NULL)
40141 return -1;
40142
40143 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40144 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40145
40146 dmi_unmap(buf);
40147 return 0;
40148 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40149 index 5b53d61..72cee96 100644
40150 --- a/drivers/firmware/efi/cper.c
40151 +++ b/drivers/firmware/efi/cper.c
40152 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40153 */
40154 u64 cper_next_record_id(void)
40155 {
40156 - static atomic64_t seq;
40157 + static atomic64_unchecked_t seq;
40158
40159 - if (!atomic64_read(&seq))
40160 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40161 + if (!atomic64_read_unchecked(&seq))
40162 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40163
40164 - return atomic64_inc_return(&seq);
40165 + return atomic64_inc_return_unchecked(&seq);
40166 }
40167 EXPORT_SYMBOL_GPL(cper_next_record_id);
40168
40169 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40170 index 8590099..d83627a 100644
40171 --- a/drivers/firmware/efi/efi.c
40172 +++ b/drivers/firmware/efi/efi.c
40173 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40174 };
40175
40176 static struct efivars generic_efivars;
40177 -static struct efivar_operations generic_ops;
40178 +static efivar_operations_no_const generic_ops __read_only;
40179
40180 static int generic_ops_register(void)
40181 {
40182 - generic_ops.get_variable = efi.get_variable;
40183 - generic_ops.set_variable = efi.set_variable;
40184 - generic_ops.get_next_variable = efi.get_next_variable;
40185 - generic_ops.query_variable_store = efi_query_variable_store;
40186 + pax_open_kernel();
40187 + *(void **)&generic_ops.get_variable = efi.get_variable;
40188 + *(void **)&generic_ops.set_variable = efi.set_variable;
40189 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40190 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40191 + pax_close_kernel();
40192
40193 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40194 }
40195 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40196 index f256ecd..387dcb1 100644
40197 --- a/drivers/firmware/efi/efivars.c
40198 +++ b/drivers/firmware/efi/efivars.c
40199 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40200 static int
40201 create_efivars_bin_attributes(void)
40202 {
40203 - struct bin_attribute *attr;
40204 + bin_attribute_no_const *attr;
40205 int error;
40206
40207 /* new_var */
40208 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40209 index 2f569aa..c95f4fb 100644
40210 --- a/drivers/firmware/google/memconsole.c
40211 +++ b/drivers/firmware/google/memconsole.c
40212 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40213 if (!found_memconsole())
40214 return -ENODEV;
40215
40216 - memconsole_bin_attr.size = memconsole_length;
40217 + pax_open_kernel();
40218 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40219 + pax_close_kernel();
40220 +
40221 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40222 }
40223
40224 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40225 index fe49ec3..1ade794 100644
40226 --- a/drivers/gpio/gpio-em.c
40227 +++ b/drivers/gpio/gpio-em.c
40228 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40229 struct em_gio_priv *p;
40230 struct resource *io[2], *irq[2];
40231 struct gpio_chip *gpio_chip;
40232 - struct irq_chip *irq_chip;
40233 + irq_chip_no_const *irq_chip;
40234 const char *name = dev_name(&pdev->dev);
40235 int ret;
40236
40237 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40238 index 3784e81..73637b5 100644
40239 --- a/drivers/gpio/gpio-ich.c
40240 +++ b/drivers/gpio/gpio-ich.c
40241 @@ -94,7 +94,7 @@ struct ichx_desc {
40242 * this option allows driver caching written output values
40243 */
40244 bool use_outlvl_cache;
40245 -};
40246 +} __do_const;
40247
40248 static struct {
40249 spinlock_t lock;
40250 diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40251 index 415682f..08438b8 100644
40252 --- a/drivers/gpio/gpio-omap.c
40253 +++ b/drivers/gpio/gpio-omap.c
40254 @@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40255 const struct omap_gpio_platform_data *pdata;
40256 struct resource *res;
40257 struct gpio_bank *bank;
40258 - struct irq_chip *irqc;
40259 + irq_chip_no_const *irqc;
40260 int ret;
40261
40262 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40263 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40264 index bf6c094..6573caf 100644
40265 --- a/drivers/gpio/gpio-rcar.c
40266 +++ b/drivers/gpio/gpio-rcar.c
40267 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40268 struct gpio_rcar_priv *p;
40269 struct resource *io, *irq;
40270 struct gpio_chip *gpio_chip;
40271 - struct irq_chip *irq_chip;
40272 + irq_chip_no_const *irq_chip;
40273 struct device *dev = &pdev->dev;
40274 const char *name = dev_name(dev);
40275 int ret;
40276 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40277 index dbf28fa..04dad4e 100644
40278 --- a/drivers/gpio/gpio-vr41xx.c
40279 +++ b/drivers/gpio/gpio-vr41xx.c
40280 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40281 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40282 maskl, pendl, maskh, pendh);
40283
40284 - atomic_inc(&irq_err_count);
40285 + atomic_inc_unchecked(&irq_err_count);
40286
40287 return -EINVAL;
40288 }
40289 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40290 index c81bda0..a8ccd9f 100644
40291 --- a/drivers/gpio/gpiolib.c
40292 +++ b/drivers/gpio/gpiolib.c
40293 @@ -539,8 +539,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40294 }
40295
40296 if (gpiochip->irqchip) {
40297 - gpiochip->irqchip->irq_request_resources = NULL;
40298 - gpiochip->irqchip->irq_release_resources = NULL;
40299 + pax_open_kernel();
40300 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40301 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40302 + pax_close_kernel();
40303 gpiochip->irqchip = NULL;
40304 }
40305 }
40306 @@ -606,8 +608,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40307 gpiochip->irqchip = NULL;
40308 return -EINVAL;
40309 }
40310 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40311 - irqchip->irq_release_resources = gpiochip_irq_relres;
40312 +
40313 + pax_open_kernel();
40314 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40315 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40316 + pax_close_kernel();
40317
40318 /*
40319 * Prepare the mapping since the irqchip shall be orthogonal to
40320 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40321 index e79c8d3..a9370bc 100644
40322 --- a/drivers/gpu/drm/drm_crtc.c
40323 +++ b/drivers/gpu/drm/drm_crtc.c
40324 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40325 goto done;
40326 }
40327
40328 - if (copy_to_user(&enum_ptr[copied].name,
40329 + if (copy_to_user(enum_ptr[copied].name,
40330 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40331 ret = -EFAULT;
40332 goto done;
40333 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40334 index bc3da32..7289357 100644
40335 --- a/drivers/gpu/drm/drm_drv.c
40336 +++ b/drivers/gpu/drm/drm_drv.c
40337 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40338
40339 drm_device_set_unplugged(dev);
40340
40341 - if (dev->open_count == 0) {
40342 + if (local_read(&dev->open_count) == 0) {
40343 drm_put_dev(dev);
40344 }
40345 mutex_unlock(&drm_global_mutex);
40346 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
40347 index ef757f7..98f720c 100644
40348 --- a/drivers/gpu/drm/drm_fb_helper.c
40349 +++ b/drivers/gpu/drm/drm_fb_helper.c
40350 @@ -741,7 +741,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
40351 int i, j, rc = 0;
40352 int start;
40353
40354 - drm_modeset_lock_all(dev);
40355 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40356 + return -EBUSY;
40357 + }
40358 if (!drm_fb_helper_is_bound(fb_helper)) {
40359 drm_modeset_unlock_all(dev);
40360 return -EBUSY;
40361 @@ -915,7 +917,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
40362 int ret = 0;
40363 int i;
40364
40365 - drm_modeset_lock_all(dev);
40366 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40367 + return -EBUSY;
40368 + }
40369 if (!drm_fb_helper_is_bound(fb_helper)) {
40370 drm_modeset_unlock_all(dev);
40371 return -EBUSY;
40372 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40373 index ed7bc68..0d536af 100644
40374 --- a/drivers/gpu/drm/drm_fops.c
40375 +++ b/drivers/gpu/drm/drm_fops.c
40376 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40377 return PTR_ERR(minor);
40378
40379 dev = minor->dev;
40380 - if (!dev->open_count++)
40381 + if (local_inc_return(&dev->open_count) == 1)
40382 need_setup = 1;
40383
40384 /* share address_space across all char-devs of a single device */
40385 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40386 return 0;
40387
40388 err_undo:
40389 - dev->open_count--;
40390 + local_dec(&dev->open_count);
40391 drm_minor_release(minor);
40392 return retcode;
40393 }
40394 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40395
40396 mutex_lock(&drm_global_mutex);
40397
40398 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40399 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40400
40401 mutex_lock(&dev->struct_mutex);
40402 list_del(&file_priv->lhead);
40403 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40404 * Begin inline drm_release
40405 */
40406
40407 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40408 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40409 task_pid_nr(current),
40410 (long)old_encode_dev(file_priv->minor->kdev->devt),
40411 - dev->open_count);
40412 + local_read(&dev->open_count));
40413
40414 /* Release any auth tokens that might point to this file_priv,
40415 (do that under the drm_global_mutex) */
40416 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40417 * End inline drm_release
40418 */
40419
40420 - if (!--dev->open_count) {
40421 + if (local_dec_and_test(&dev->open_count)) {
40422 retcode = drm_lastclose(dev);
40423 if (drm_device_is_unplugged(dev))
40424 drm_put_dev(dev);
40425 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40426 index 3d2e91c..d31c4c9 100644
40427 --- a/drivers/gpu/drm/drm_global.c
40428 +++ b/drivers/gpu/drm/drm_global.c
40429 @@ -36,7 +36,7 @@
40430 struct drm_global_item {
40431 struct mutex mutex;
40432 void *object;
40433 - int refcount;
40434 + atomic_t refcount;
40435 };
40436
40437 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40438 @@ -49,7 +49,7 @@ void drm_global_init(void)
40439 struct drm_global_item *item = &glob[i];
40440 mutex_init(&item->mutex);
40441 item->object = NULL;
40442 - item->refcount = 0;
40443 + atomic_set(&item->refcount, 0);
40444 }
40445 }
40446
40447 @@ -59,7 +59,7 @@ void drm_global_release(void)
40448 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40449 struct drm_global_item *item = &glob[i];
40450 BUG_ON(item->object != NULL);
40451 - BUG_ON(item->refcount != 0);
40452 + BUG_ON(atomic_read(&item->refcount) != 0);
40453 }
40454 }
40455
40456 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40457 struct drm_global_item *item = &glob[ref->global_type];
40458
40459 mutex_lock(&item->mutex);
40460 - if (item->refcount == 0) {
40461 + if (atomic_read(&item->refcount) == 0) {
40462 item->object = kzalloc(ref->size, GFP_KERNEL);
40463 if (unlikely(item->object == NULL)) {
40464 ret = -ENOMEM;
40465 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40466 goto out_err;
40467
40468 }
40469 - ++item->refcount;
40470 + atomic_inc(&item->refcount);
40471 ref->object = item->object;
40472 mutex_unlock(&item->mutex);
40473 return 0;
40474 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40475 struct drm_global_item *item = &glob[ref->global_type];
40476
40477 mutex_lock(&item->mutex);
40478 - BUG_ON(item->refcount == 0);
40479 + BUG_ON(atomic_read(&item->refcount) == 0);
40480 BUG_ON(ref->object != item->object);
40481 - if (--item->refcount == 0) {
40482 + if (atomic_dec_and_test(&item->refcount)) {
40483 ref->release(ref);
40484 item->object = NULL;
40485 }
40486 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40487 index 51efebd..2b70935 100644
40488 --- a/drivers/gpu/drm/drm_info.c
40489 +++ b/drivers/gpu/drm/drm_info.c
40490 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40491 struct drm_local_map *map;
40492 struct drm_map_list *r_list;
40493
40494 - /* Hardcoded from _DRM_FRAME_BUFFER,
40495 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40496 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40497 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40498 + static const char * const types[] = {
40499 + [_DRM_FRAME_BUFFER] = "FB",
40500 + [_DRM_REGISTERS] = "REG",
40501 + [_DRM_SHM] = "SHM",
40502 + [_DRM_AGP] = "AGP",
40503 + [_DRM_SCATTER_GATHER] = "SG",
40504 + [_DRM_CONSISTENT] = "PCI"};
40505 const char *type;
40506 int i;
40507
40508 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40509 map = r_list->map;
40510 if (!map)
40511 continue;
40512 - if (map->type < 0 || map->type > 5)
40513 + if (map->type >= ARRAY_SIZE(types))
40514 type = "??";
40515 else
40516 type = types[map->type];
40517 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40518 index 2f4c4343..dd12cd2 100644
40519 --- a/drivers/gpu/drm/drm_ioc32.c
40520 +++ b/drivers/gpu/drm/drm_ioc32.c
40521 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40522 request = compat_alloc_user_space(nbytes);
40523 if (!access_ok(VERIFY_WRITE, request, nbytes))
40524 return -EFAULT;
40525 - list = (struct drm_buf_desc *) (request + 1);
40526 + list = (struct drm_buf_desc __user *) (request + 1);
40527
40528 if (__put_user(count, &request->count)
40529 || __put_user(list, &request->list))
40530 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40531 request = compat_alloc_user_space(nbytes);
40532 if (!access_ok(VERIFY_WRITE, request, nbytes))
40533 return -EFAULT;
40534 - list = (struct drm_buf_pub *) (request + 1);
40535 + list = (struct drm_buf_pub __user *) (request + 1);
40536
40537 if (__put_user(count, &request->count)
40538 || __put_user(list, &request->list))
40539 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40540 return 0;
40541 }
40542
40543 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40544 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40545 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40546 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40547 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40548 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40549 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40550 {
40551 unsigned int nr = DRM_IOCTL_NR(cmd);
40552 - drm_ioctl_compat_t *fn;
40553 int ret;
40554
40555 /* Assume that ioctls without an explicit compat routine will just
40556 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40557 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40558 return drm_ioctl(filp, cmd, arg);
40559
40560 - fn = drm_compat_ioctls[nr];
40561 -
40562 - if (fn != NULL)
40563 - ret = (*fn) (filp, cmd, arg);
40564 + if (drm_compat_ioctls[nr] != NULL)
40565 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40566 else
40567 ret = drm_ioctl(filp, cmd, arg);
40568
40569 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40570 index 00587a1..57a65ca 100644
40571 --- a/drivers/gpu/drm/drm_ioctl.c
40572 +++ b/drivers/gpu/drm/drm_ioctl.c
40573 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40574 struct drm_file *file_priv = filp->private_data;
40575 struct drm_device *dev;
40576 const struct drm_ioctl_desc *ioctl = NULL;
40577 - drm_ioctl_t *func;
40578 + drm_ioctl_no_const_t func;
40579 unsigned int nr = DRM_IOCTL_NR(cmd);
40580 int retcode = -EINVAL;
40581 char stack_kdata[128];
40582 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40583 index 93ec5dc..82acbaf 100644
40584 --- a/drivers/gpu/drm/i810/i810_drv.h
40585 +++ b/drivers/gpu/drm/i810/i810_drv.h
40586 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40587 int page_flipping;
40588
40589 wait_queue_head_t irq_queue;
40590 - atomic_t irq_received;
40591 - atomic_t irq_emitted;
40592 + atomic_unchecked_t irq_received;
40593 + atomic_unchecked_t irq_emitted;
40594
40595 int front_offset;
40596 } drm_i810_private_t;
40597 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40598 index 318ade9..1f5de55 100644
40599 --- a/drivers/gpu/drm/i915/i915_dma.c
40600 +++ b/drivers/gpu/drm/i915/i915_dma.c
40601 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40602 * locking inversion with the driver load path. And the access here is
40603 * completely racy anyway. So don't bother with locking for now.
40604 */
40605 - return dev->open_count == 0;
40606 + return local_read(&dev->open_count) == 0;
40607 }
40608
40609 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40610 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40611 index 1a0611b..dd1fbfc 100644
40612 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40613 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40614 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40615 static int
40616 validate_exec_list(struct drm_device *dev,
40617 struct drm_i915_gem_exec_object2 *exec,
40618 - int count)
40619 + unsigned int count)
40620 {
40621 unsigned relocs_total = 0;
40622 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40623 unsigned invalid_flags;
40624 - int i;
40625 + unsigned int i;
40626
40627 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40628 if (USES_FULL_PPGTT(dev))
40629 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40630 index 2e0613e..a8b94d9 100644
40631 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40632 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40633 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40634 (unsigned long)request);
40635 }
40636
40637 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40638 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40639 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40640 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40641 [DRM_I915_GETPARAM] = compat_i915_getparam,
40642 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40643 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40644 {
40645 unsigned int nr = DRM_IOCTL_NR(cmd);
40646 - drm_ioctl_compat_t *fn = NULL;
40647 int ret;
40648
40649 if (nr < DRM_COMMAND_BASE)
40650 return drm_compat_ioctl(filp, cmd, arg);
40651
40652 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40653 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40654 -
40655 - if (fn != NULL)
40656 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40657 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40658 ret = (*fn) (filp, cmd, arg);
40659 - else
40660 + } else
40661 ret = drm_ioctl(filp, cmd, arg);
40662
40663 return ret;
40664 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40665 index cadc3bc..1bfccfe 100644
40666 --- a/drivers/gpu/drm/i915/intel_display.c
40667 +++ b/drivers/gpu/drm/i915/intel_display.c
40668 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40669 int subsystem_vendor;
40670 int subsystem_device;
40671 void (*hook)(struct drm_device *dev);
40672 -};
40673 +} __do_const;
40674
40675 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40676 struct intel_dmi_quirk {
40677 void (*hook)(struct drm_device *dev);
40678 const struct dmi_system_id (*dmi_id_list)[];
40679 -};
40680 +} __do_const;
40681
40682 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40683 {
40684 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40685 return 1;
40686 }
40687
40688 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40689 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40690 {
40691 - .dmi_id_list = &(const struct dmi_system_id[]) {
40692 - {
40693 - .callback = intel_dmi_reverse_brightness,
40694 - .ident = "NCR Corporation",
40695 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40696 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40697 - },
40698 - },
40699 - { } /* terminating entry */
40700 + .callback = intel_dmi_reverse_brightness,
40701 + .ident = "NCR Corporation",
40702 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40703 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40704 },
40705 + },
40706 + { } /* terminating entry */
40707 +};
40708 +
40709 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40710 + {
40711 + .dmi_id_list = &intel_dmi_quirks_table,
40712 .hook = quirk_invert_brightness,
40713 },
40714 };
40715 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40716 index b4a2014..219ab78 100644
40717 --- a/drivers/gpu/drm/mga/mga_drv.h
40718 +++ b/drivers/gpu/drm/mga/mga_drv.h
40719 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40720 u32 clear_cmd;
40721 u32 maccess;
40722
40723 - atomic_t vbl_received; /**< Number of vblanks received. */
40724 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40725 wait_queue_head_t fence_queue;
40726 - atomic_t last_fence_retired;
40727 + atomic_unchecked_t last_fence_retired;
40728 u32 next_fence_to_post;
40729
40730 unsigned int fb_cpp;
40731 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40732 index 729bfd5..ead8823 100644
40733 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40734 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40735 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40736 return 0;
40737 }
40738
40739 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40740 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40741 [DRM_MGA_INIT] = compat_mga_init,
40742 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40743 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40744 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40745 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40746 {
40747 unsigned int nr = DRM_IOCTL_NR(cmd);
40748 - drm_ioctl_compat_t *fn = NULL;
40749 int ret;
40750
40751 if (nr < DRM_COMMAND_BASE)
40752 return drm_compat_ioctl(filp, cmd, arg);
40753
40754 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40755 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40756 -
40757 - if (fn != NULL)
40758 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40759 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40760 ret = (*fn) (filp, cmd, arg);
40761 - else
40762 + } else
40763 ret = drm_ioctl(filp, cmd, arg);
40764
40765 return ret;
40766 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40767 index 1b071b8..de8601a 100644
40768 --- a/drivers/gpu/drm/mga/mga_irq.c
40769 +++ b/drivers/gpu/drm/mga/mga_irq.c
40770 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40771 if (crtc != 0)
40772 return 0;
40773
40774 - return atomic_read(&dev_priv->vbl_received);
40775 + return atomic_read_unchecked(&dev_priv->vbl_received);
40776 }
40777
40778
40779 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40780 /* VBLANK interrupt */
40781 if (status & MGA_VLINEPEN) {
40782 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40783 - atomic_inc(&dev_priv->vbl_received);
40784 + atomic_inc_unchecked(&dev_priv->vbl_received);
40785 drm_handle_vblank(dev, 0);
40786 handled = 1;
40787 }
40788 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40789 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40790 MGA_WRITE(MGA_PRIMEND, prim_end);
40791
40792 - atomic_inc(&dev_priv->last_fence_retired);
40793 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40794 wake_up(&dev_priv->fence_queue);
40795 handled = 1;
40796 }
40797 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40798 * using fences.
40799 */
40800 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40801 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40802 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40803 - *sequence) <= (1 << 23)));
40804
40805 *sequence = cur_fence;
40806 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40807 index dae2c96..324dbe4 100644
40808 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40809 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40810 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40811 struct bit_table {
40812 const char id;
40813 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40814 -};
40815 +} __no_const;
40816
40817 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40818
40819 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40820 index 8ae36f2..1147a30 100644
40821 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40822 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40823 @@ -121,7 +121,6 @@ struct nouveau_drm {
40824 struct drm_global_reference mem_global_ref;
40825 struct ttm_bo_global_ref bo_global_ref;
40826 struct ttm_bo_device bdev;
40827 - atomic_t validate_sequence;
40828 int (*move)(struct nouveau_channel *,
40829 struct ttm_buffer_object *,
40830 struct ttm_mem_reg *, struct ttm_mem_reg *);
40831 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40832 index 462679a..88e32a7 100644
40833 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40834 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40835 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40836 unsigned long arg)
40837 {
40838 unsigned int nr = DRM_IOCTL_NR(cmd);
40839 - drm_ioctl_compat_t *fn = NULL;
40840 + drm_ioctl_compat_t fn = NULL;
40841 int ret;
40842
40843 if (nr < DRM_COMMAND_BASE)
40844 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40845 index 3d1cfcb..0542700 100644
40846 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40847 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40848 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40849 }
40850
40851 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40852 - nouveau_vram_manager_init,
40853 - nouveau_vram_manager_fini,
40854 - nouveau_vram_manager_new,
40855 - nouveau_vram_manager_del,
40856 - nouveau_vram_manager_debug
40857 + .init = nouveau_vram_manager_init,
40858 + .takedown = nouveau_vram_manager_fini,
40859 + .get_node = nouveau_vram_manager_new,
40860 + .put_node = nouveau_vram_manager_del,
40861 + .debug = nouveau_vram_manager_debug
40862 };
40863
40864 static int
40865 @@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40866 }
40867
40868 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40869 - nouveau_gart_manager_init,
40870 - nouveau_gart_manager_fini,
40871 - nouveau_gart_manager_new,
40872 - nouveau_gart_manager_del,
40873 - nouveau_gart_manager_debug
40874 + .init = nouveau_gart_manager_init,
40875 + .takedown = nouveau_gart_manager_fini,
40876 + .get_node = nouveau_gart_manager_new,
40877 + .put_node = nouveau_gart_manager_del,
40878 + .debug = nouveau_gart_manager_debug
40879 };
40880
40881 /*XXX*/
40882 @@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40883 }
40884
40885 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40886 - nv04_gart_manager_init,
40887 - nv04_gart_manager_fini,
40888 - nv04_gart_manager_new,
40889 - nv04_gart_manager_del,
40890 - nv04_gart_manager_debug
40891 + .init = nv04_gart_manager_init,
40892 + .takedown = nv04_gart_manager_fini,
40893 + .get_node = nv04_gart_manager_new,
40894 + .put_node = nv04_gart_manager_del,
40895 + .debug = nv04_gart_manager_debug
40896 };
40897
40898 int
40899 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40900 index c7592ec..dd45ebc 100644
40901 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40902 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40903 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40904 * locking inversion with the driver load path. And the access here is
40905 * completely racy anyway. So don't bother with locking for now.
40906 */
40907 - return dev->open_count == 0;
40908 + return local_read(&dev->open_count) == 0;
40909 }
40910
40911 static const struct vga_switcheroo_client_ops
40912 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40913 index 9782364..89bd954 100644
40914 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40915 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40916 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40917 int ret;
40918
40919 mutex_lock(&qdev->async_io_mutex);
40920 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40921 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40922 if (qdev->last_sent_io_cmd > irq_num) {
40923 if (intr)
40924 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40925 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40926 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40927 else
40928 ret = wait_event_timeout(qdev->io_cmd_event,
40929 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40930 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40931 /* 0 is timeout, just bail the "hw" has gone away */
40932 if (ret <= 0)
40933 goto out;
40934 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40935 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40936 }
40937 outb(val, addr);
40938 qdev->last_sent_io_cmd = irq_num + 1;
40939 if (intr)
40940 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40941 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40942 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40943 else
40944 ret = wait_event_timeout(qdev->io_cmd_event,
40945 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40946 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40947 out:
40948 if (ret > 0)
40949 ret = 0;
40950 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40951 index 6911b8c..89d6867 100644
40952 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40953 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40954 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40955 struct drm_info_node *node = (struct drm_info_node *) m->private;
40956 struct qxl_device *qdev = node->minor->dev->dev_private;
40957
40958 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40959 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40960 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40961 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40962 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40963 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40964 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40965 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40966 seq_printf(m, "%d\n", qdev->irq_received_error);
40967 return 0;
40968 }
40969 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40970 index 7c6cafe..460f542 100644
40971 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40972 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40973 @@ -290,10 +290,10 @@ struct qxl_device {
40974 unsigned int last_sent_io_cmd;
40975
40976 /* interrupt handling */
40977 - atomic_t irq_received;
40978 - atomic_t irq_received_display;
40979 - atomic_t irq_received_cursor;
40980 - atomic_t irq_received_io_cmd;
40981 + atomic_unchecked_t irq_received;
40982 + atomic_unchecked_t irq_received_display;
40983 + atomic_unchecked_t irq_received_cursor;
40984 + atomic_unchecked_t irq_received_io_cmd;
40985 unsigned irq_received_error;
40986 wait_queue_head_t display_event;
40987 wait_queue_head_t cursor_event;
40988 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40989 index b110883..dd06418 100644
40990 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40991 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40992 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40993
40994 /* TODO copy slow path code from i915 */
40995 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40996 - 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);
40997 + 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);
40998
40999 {
41000 struct qxl_drawable *draw = fb_cmd;
41001 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41002 struct drm_qxl_reloc reloc;
41003
41004 if (copy_from_user(&reloc,
41005 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41006 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41007 sizeof(reloc))) {
41008 ret = -EFAULT;
41009 goto out_free_bos;
41010 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41011
41012 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41013
41014 - struct drm_qxl_command *commands =
41015 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41016 + struct drm_qxl_command __user *commands =
41017 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41018
41019 - if (copy_from_user(&user_cmd, &commands[cmd_num],
41020 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41021 sizeof(user_cmd)))
41022 return -EFAULT;
41023
41024 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41025 index 0bf1e20..42a7310 100644
41026 --- a/drivers/gpu/drm/qxl/qxl_irq.c
41027 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
41028 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41029 if (!pending)
41030 return IRQ_NONE;
41031
41032 - atomic_inc(&qdev->irq_received);
41033 + atomic_inc_unchecked(&qdev->irq_received);
41034
41035 if (pending & QXL_INTERRUPT_DISPLAY) {
41036 - atomic_inc(&qdev->irq_received_display);
41037 + atomic_inc_unchecked(&qdev->irq_received_display);
41038 wake_up_all(&qdev->display_event);
41039 qxl_queue_garbage_collect(qdev, false);
41040 }
41041 if (pending & QXL_INTERRUPT_CURSOR) {
41042 - atomic_inc(&qdev->irq_received_cursor);
41043 + atomic_inc_unchecked(&qdev->irq_received_cursor);
41044 wake_up_all(&qdev->cursor_event);
41045 }
41046 if (pending & QXL_INTERRUPT_IO_CMD) {
41047 - atomic_inc(&qdev->irq_received_io_cmd);
41048 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41049 wake_up_all(&qdev->io_cmd_event);
41050 }
41051 if (pending & QXL_INTERRUPT_ERROR) {
41052 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41053 init_waitqueue_head(&qdev->io_cmd_event);
41054 INIT_WORK(&qdev->client_monitors_config_work,
41055 qxl_client_monitors_config_work_func);
41056 - atomic_set(&qdev->irq_received, 0);
41057 - atomic_set(&qdev->irq_received_display, 0);
41058 - atomic_set(&qdev->irq_received_cursor, 0);
41059 - atomic_set(&qdev->irq_received_io_cmd, 0);
41060 + atomic_set_unchecked(&qdev->irq_received, 0);
41061 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41062 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41063 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41064 qdev->irq_received_error = 0;
41065 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41066 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41067 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41068 index 0cbc4c9..0e46686 100644
41069 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41070 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41071 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41072 }
41073 }
41074
41075 -static struct vm_operations_struct qxl_ttm_vm_ops;
41076 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41077 static const struct vm_operations_struct *ttm_vm_ops;
41078
41079 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41080 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41081 return r;
41082 if (unlikely(ttm_vm_ops == NULL)) {
41083 ttm_vm_ops = vma->vm_ops;
41084 + pax_open_kernel();
41085 qxl_ttm_vm_ops = *ttm_vm_ops;
41086 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41087 + pax_close_kernel();
41088 }
41089 vma->vm_ops = &qxl_ttm_vm_ops;
41090 return 0;
41091 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41092 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41093 {
41094 #if defined(CONFIG_DEBUG_FS)
41095 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41096 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41097 - unsigned i;
41098 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41099 + {
41100 + .name = "qxl_mem_mm",
41101 + .show = &qxl_mm_dump_table,
41102 + },
41103 + {
41104 + .name = "qxl_surf_mm",
41105 + .show = &qxl_mm_dump_table,
41106 + }
41107 + };
41108
41109 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41110 - if (i == 0)
41111 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41112 - else
41113 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41114 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41115 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41116 - qxl_mem_types_list[i].driver_features = 0;
41117 - if (i == 0)
41118 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41119 - else
41120 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41121 + pax_open_kernel();
41122 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41123 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41124 + pax_close_kernel();
41125
41126 - }
41127 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41128 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41129 #else
41130 return 0;
41131 #endif
41132 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41133 index 2c45ac9..5d740f8 100644
41134 --- a/drivers/gpu/drm/r128/r128_cce.c
41135 +++ b/drivers/gpu/drm/r128/r128_cce.c
41136 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41137
41138 /* GH: Simple idle check.
41139 */
41140 - atomic_set(&dev_priv->idle_count, 0);
41141 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41142
41143 /* We don't support anything other than bus-mastering ring mode,
41144 * but the ring can be in either AGP or PCI space for the ring
41145 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41146 index 723e5d6..102dbaf 100644
41147 --- a/drivers/gpu/drm/r128/r128_drv.h
41148 +++ b/drivers/gpu/drm/r128/r128_drv.h
41149 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41150 int is_pci;
41151 unsigned long cce_buffers_offset;
41152
41153 - atomic_t idle_count;
41154 + atomic_unchecked_t idle_count;
41155
41156 int page_flipping;
41157 int current_page;
41158 u32 crtc_offset;
41159 u32 crtc_offset_cntl;
41160
41161 - atomic_t vbl_received;
41162 + atomic_unchecked_t vbl_received;
41163
41164 u32 color_fmt;
41165 unsigned int front_offset;
41166 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41167 index 663f38c..c689495 100644
41168 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41169 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41170 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41171 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41172 }
41173
41174 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41175 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41176 [DRM_R128_INIT] = compat_r128_init,
41177 [DRM_R128_DEPTH] = compat_r128_depth,
41178 [DRM_R128_STIPPLE] = compat_r128_stipple,
41179 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41180 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41181 {
41182 unsigned int nr = DRM_IOCTL_NR(cmd);
41183 - drm_ioctl_compat_t *fn = NULL;
41184 int ret;
41185
41186 if (nr < DRM_COMMAND_BASE)
41187 return drm_compat_ioctl(filp, cmd, arg);
41188
41189 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41190 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41191 -
41192 - if (fn != NULL)
41193 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41194 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41195 ret = (*fn) (filp, cmd, arg);
41196 - else
41197 + } else
41198 ret = drm_ioctl(filp, cmd, arg);
41199
41200 return ret;
41201 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41202 index c2ae496..30b5993 100644
41203 --- a/drivers/gpu/drm/r128/r128_irq.c
41204 +++ b/drivers/gpu/drm/r128/r128_irq.c
41205 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41206 if (crtc != 0)
41207 return 0;
41208
41209 - return atomic_read(&dev_priv->vbl_received);
41210 + return atomic_read_unchecked(&dev_priv->vbl_received);
41211 }
41212
41213 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41214 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41215 /* VBLANK interrupt */
41216 if (status & R128_CRTC_VBLANK_INT) {
41217 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41218 - atomic_inc(&dev_priv->vbl_received);
41219 + atomic_inc_unchecked(&dev_priv->vbl_received);
41220 drm_handle_vblank(dev, 0);
41221 return IRQ_HANDLED;
41222 }
41223 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41224 index 575e986..66e62ca 100644
41225 --- a/drivers/gpu/drm/r128/r128_state.c
41226 +++ b/drivers/gpu/drm/r128/r128_state.c
41227 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41228
41229 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41230 {
41231 - if (atomic_read(&dev_priv->idle_count) == 0)
41232 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41233 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41234 else
41235 - atomic_set(&dev_priv->idle_count, 0);
41236 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41237 }
41238
41239 #endif
41240 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41241 index 4a85bb6..aaea819 100644
41242 --- a/drivers/gpu/drm/radeon/mkregtable.c
41243 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41244 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41245 regex_t mask_rex;
41246 regmatch_t match[4];
41247 char buf[1024];
41248 - size_t end;
41249 + long end;
41250 int len;
41251 int done = 0;
41252 int r;
41253 unsigned o;
41254 struct offset *offset;
41255 char last_reg_s[10];
41256 - int last_reg;
41257 + unsigned long last_reg;
41258
41259 if (regcomp
41260 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41261 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41262 index 995a8b1..b7cb898 100644
41263 --- a/drivers/gpu/drm/radeon/radeon_device.c
41264 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41265 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41266 * locking inversion with the driver load path. And the access here is
41267 * completely racy anyway. So don't bother with locking for now.
41268 */
41269 - return dev->open_count == 0;
41270 + return local_read(&dev->open_count) == 0;
41271 }
41272
41273 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41274 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41275 index 46bd393..6ae4719 100644
41276 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41277 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41278 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41279
41280 /* SW interrupt */
41281 wait_queue_head_t swi_queue;
41282 - atomic_t swi_emitted;
41283 + atomic_unchecked_t swi_emitted;
41284 int vblank_crtc;
41285 uint32_t irq_enable_reg;
41286 uint32_t r500_disp_irq_reg;
41287 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41288 index 0b98ea1..0881827 100644
41289 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41290 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41291 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41292 request = compat_alloc_user_space(sizeof(*request));
41293 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41294 || __put_user(req32.param, &request->param)
41295 - || __put_user((void __user *)(unsigned long)req32.value,
41296 + || __put_user((unsigned long)req32.value,
41297 &request->value))
41298 return -EFAULT;
41299
41300 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41301 #define compat_radeon_cp_setparam NULL
41302 #endif /* X86_64 || IA64 */
41303
41304 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41305 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41306 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41307 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41308 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41309 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41310 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41311 {
41312 unsigned int nr = DRM_IOCTL_NR(cmd);
41313 - drm_ioctl_compat_t *fn = NULL;
41314 int ret;
41315
41316 if (nr < DRM_COMMAND_BASE)
41317 return drm_compat_ioctl(filp, cmd, arg);
41318
41319 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41320 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41321 -
41322 - if (fn != NULL)
41323 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41324 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41325 ret = (*fn) (filp, cmd, arg);
41326 - else
41327 + } else
41328 ret = drm_ioctl(filp, cmd, arg);
41329
41330 return ret;
41331 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41332 index 244b19b..c19226d 100644
41333 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41334 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41335 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41336 unsigned int ret;
41337 RING_LOCALS;
41338
41339 - atomic_inc(&dev_priv->swi_emitted);
41340 - ret = atomic_read(&dev_priv->swi_emitted);
41341 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41342 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41343
41344 BEGIN_RING(4);
41345 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41346 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41347 drm_radeon_private_t *dev_priv =
41348 (drm_radeon_private_t *) dev->dev_private;
41349
41350 - atomic_set(&dev_priv->swi_emitted, 0);
41351 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41352 init_waitqueue_head(&dev_priv->swi_queue);
41353
41354 dev->max_vblank_count = 0x001fffff;
41355 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41356 index 535403e..5dd655b 100644
41357 --- a/drivers/gpu/drm/radeon/radeon_state.c
41358 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41359 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41360 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41361 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41362
41363 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41364 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41365 sarea_priv->nbox * sizeof(depth_boxes[0])))
41366 return -EFAULT;
41367
41368 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41369 {
41370 drm_radeon_private_t *dev_priv = dev->dev_private;
41371 drm_radeon_getparam_t *param = data;
41372 - int value;
41373 + int value = 0;
41374
41375 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41376
41377 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41378 index d2510cf..63bd4ed 100644
41379 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41380 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41381 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41382 man->size = size >> PAGE_SHIFT;
41383 }
41384
41385 -static struct vm_operations_struct radeon_ttm_vm_ops;
41386 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41387 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41388
41389 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41390 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41391 }
41392 if (unlikely(ttm_vm_ops == NULL)) {
41393 ttm_vm_ops = vma->vm_ops;
41394 + pax_open_kernel();
41395 radeon_ttm_vm_ops = *ttm_vm_ops;
41396 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41397 + pax_close_kernel();
41398 }
41399 vma->vm_ops = &radeon_ttm_vm_ops;
41400 return 0;
41401 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41402 index 054a79f..30d9ac4 100644
41403 --- a/drivers/gpu/drm/tegra/dc.c
41404 +++ b/drivers/gpu/drm/tegra/dc.c
41405 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41406 }
41407
41408 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41409 - dc->debugfs_files[i].data = dc;
41410 + *(void **)&dc->debugfs_files[i].data = dc;
41411
41412 err = drm_debugfs_create_files(dc->debugfs_files,
41413 ARRAY_SIZE(debugfs_files),
41414 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41415 index f787445..2df2c65 100644
41416 --- a/drivers/gpu/drm/tegra/dsi.c
41417 +++ b/drivers/gpu/drm/tegra/dsi.c
41418 @@ -41,7 +41,7 @@ struct tegra_dsi {
41419 struct clk *clk_lp;
41420 struct clk *clk;
41421
41422 - struct drm_info_list *debugfs_files;
41423 + drm_info_list_no_const *debugfs_files;
41424 struct drm_minor *minor;
41425 struct dentry *debugfs;
41426
41427 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41428 index ffe2654..03c7b1c 100644
41429 --- a/drivers/gpu/drm/tegra/hdmi.c
41430 +++ b/drivers/gpu/drm/tegra/hdmi.c
41431 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41432 bool stereo;
41433 bool dvi;
41434
41435 - struct drm_info_list *debugfs_files;
41436 + drm_info_list_no_const *debugfs_files;
41437 struct drm_minor *minor;
41438 struct dentry *debugfs;
41439 };
41440 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41441 index 964387f..4eafc00 100644
41442 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41443 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41444 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41445 }
41446
41447 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41448 - ttm_bo_man_init,
41449 - ttm_bo_man_takedown,
41450 - ttm_bo_man_get_node,
41451 - ttm_bo_man_put_node,
41452 - ttm_bo_man_debug
41453 + .init = ttm_bo_man_init,
41454 + .takedown = ttm_bo_man_takedown,
41455 + .get_node = ttm_bo_man_get_node,
41456 + .put_node = ttm_bo_man_put_node,
41457 + .debug = ttm_bo_man_debug
41458 };
41459 EXPORT_SYMBOL(ttm_bo_manager_func);
41460 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41461 index a1803fb..c53f6b0 100644
41462 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41463 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41464 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41465 zone->glob = glob;
41466 glob->zone_kernel = zone;
41467 ret = kobject_init_and_add(
41468 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41469 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41470 if (unlikely(ret != 0)) {
41471 kobject_put(&zone->kobj);
41472 return ret;
41473 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41474 zone->glob = glob;
41475 glob->zone_dma32 = zone;
41476 ret = kobject_init_and_add(
41477 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41478 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41479 if (unlikely(ret != 0)) {
41480 kobject_put(&zone->kobj);
41481 return ret;
41482 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41483 index 025c429..314062f 100644
41484 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41485 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41486 @@ -54,7 +54,7 @@
41487
41488 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41489 #define SMALL_ALLOCATION 16
41490 -#define FREE_ALL_PAGES (~0U)
41491 +#define FREE_ALL_PAGES (~0UL)
41492 /* times are in msecs */
41493 #define PAGE_FREE_INTERVAL 1000
41494
41495 @@ -299,15 +299,14 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41496 * @free_all: If set to true will free all pages in pool
41497 * @use_static: Safe to use static buffer
41498 **/
41499 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41500 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41501 bool use_static)
41502 {
41503 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41504 unsigned long irq_flags;
41505 struct page *p;
41506 struct page **pages_to_free;
41507 - unsigned freed_pages = 0,
41508 - npages_to_free = nr_free;
41509 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41510
41511 if (NUM_PAGES_TO_ALLOC < nr_free)
41512 npages_to_free = NUM_PAGES_TO_ALLOC;
41513 @@ -371,7 +370,8 @@ restart:
41514 __list_del(&p->lru, &pool->list);
41515
41516 ttm_pool_update_free_locked(pool, freed_pages);
41517 - nr_free -= freed_pages;
41518 + if (likely(nr_free != FREE_ALL_PAGES))
41519 + nr_free -= freed_pages;
41520 }
41521
41522 spin_unlock_irqrestore(&pool->lock, irq_flags);
41523 @@ -399,7 +399,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41524 unsigned i;
41525 unsigned pool_offset;
41526 struct ttm_page_pool *pool;
41527 - int shrink_pages = sc->nr_to_scan;
41528 + unsigned long shrink_pages = sc->nr_to_scan;
41529 unsigned long freed = 0;
41530
41531 if (!mutex_trylock(&lock))
41532 @@ -407,7 +407,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41533 pool_offset = ++start_pool % NUM_POOLS;
41534 /* select start pool in round robin fashion */
41535 for (i = 0; i < NUM_POOLS; ++i) {
41536 - unsigned nr_free = shrink_pages;
41537 + unsigned long nr_free = shrink_pages;
41538 if (shrink_pages == 0)
41539 break;
41540 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41541 @@ -673,7 +673,7 @@ out:
41542 }
41543
41544 /* Put all pages in pages list to correct pool to wait for reuse */
41545 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41546 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41547 enum ttm_caching_state cstate)
41548 {
41549 unsigned long irq_flags;
41550 @@ -728,7 +728,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41551 struct list_head plist;
41552 struct page *p = NULL;
41553 gfp_t gfp_flags = GFP_USER;
41554 - unsigned count;
41555 + unsigned long count;
41556 int r;
41557
41558 /* set zero flag for page allocation if required */
41559 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41560 index 01e1d27..aaa018a 100644
41561 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41562 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41563 @@ -56,7 +56,7 @@
41564
41565 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41566 #define SMALL_ALLOCATION 4
41567 -#define FREE_ALL_PAGES (~0U)
41568 +#define FREE_ALL_PAGES (~0UL)
41569 /* times are in msecs */
41570 #define IS_UNDEFINED (0)
41571 #define IS_WC (1<<1)
41572 @@ -413,7 +413,7 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41573 * @nr_free: If set to true will free all pages in pool
41574 * @use_static: Safe to use static buffer
41575 **/
41576 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41577 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41578 bool use_static)
41579 {
41580 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41581 @@ -421,8 +421,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41582 struct dma_page *dma_p, *tmp;
41583 struct page **pages_to_free;
41584 struct list_head d_pages;
41585 - unsigned freed_pages = 0,
41586 - npages_to_free = nr_free;
41587 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41588
41589 if (NUM_PAGES_TO_ALLOC < nr_free)
41590 npages_to_free = NUM_PAGES_TO_ALLOC;
41591 @@ -499,7 +498,8 @@ restart:
41592 /* remove range of pages from the pool */
41593 if (freed_pages) {
41594 ttm_pool_update_free_locked(pool, freed_pages);
41595 - nr_free -= freed_pages;
41596 + if (likely(nr_free != FREE_ALL_PAGES))
41597 + nr_free -= freed_pages;
41598 }
41599
41600 spin_unlock_irqrestore(&pool->lock, irq_flags);
41601 @@ -936,7 +936,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41602 struct dma_page *d_page, *next;
41603 enum pool_type type;
41604 bool is_cached = false;
41605 - unsigned count = 0, i, npages = 0;
41606 + unsigned long count = 0, i, npages = 0;
41607 unsigned long irq_flags;
41608
41609 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41610 @@ -1012,7 +1012,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41611 static unsigned start_pool;
41612 unsigned idx = 0;
41613 unsigned pool_offset;
41614 - unsigned shrink_pages = sc->nr_to_scan;
41615 + unsigned long shrink_pages = sc->nr_to_scan;
41616 struct device_pools *p;
41617 unsigned long freed = 0;
41618
41619 @@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41620 goto out;
41621 pool_offset = ++start_pool % _manager->npools;
41622 list_for_each_entry(p, &_manager->pools, pools) {
41623 - unsigned nr_free;
41624 + unsigned long nr_free;
41625
41626 if (!p->dev)
41627 continue;
41628 @@ -1039,7 +1039,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41629 shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
41630 freed += nr_free - shrink_pages;
41631
41632 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41633 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41634 p->pool->dev_name, p->pool->name, current->pid,
41635 nr_free, shrink_pages);
41636 }
41637 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41638 index 8cbcb45..a4d9cf7 100644
41639 --- a/drivers/gpu/drm/udl/udl_fb.c
41640 +++ b/drivers/gpu/drm/udl/udl_fb.c
41641 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41642 fb_deferred_io_cleanup(info);
41643 kfree(info->fbdefio);
41644 info->fbdefio = NULL;
41645 - info->fbops->fb_mmap = udl_fb_mmap;
41646 }
41647
41648 pr_warn("released /dev/fb%d user=%d count=%d\n",
41649 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41650 index ef8c500..01030c8 100644
41651 --- a/drivers/gpu/drm/via/via_drv.h
41652 +++ b/drivers/gpu/drm/via/via_drv.h
41653 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41654 typedef uint32_t maskarray_t[5];
41655
41656 typedef struct drm_via_irq {
41657 - atomic_t irq_received;
41658 + atomic_unchecked_t irq_received;
41659 uint32_t pending_mask;
41660 uint32_t enable_mask;
41661 wait_queue_head_t irq_queue;
41662 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41663 struct timeval last_vblank;
41664 int last_vblank_valid;
41665 unsigned usec_per_vblank;
41666 - atomic_t vbl_received;
41667 + atomic_unchecked_t vbl_received;
41668 drm_via_state_t hc_state;
41669 char pci_buf[VIA_PCI_BUF_SIZE];
41670 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41671 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41672 index 1319433..a993b0c 100644
41673 --- a/drivers/gpu/drm/via/via_irq.c
41674 +++ b/drivers/gpu/drm/via/via_irq.c
41675 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41676 if (crtc != 0)
41677 return 0;
41678
41679 - return atomic_read(&dev_priv->vbl_received);
41680 + return atomic_read_unchecked(&dev_priv->vbl_received);
41681 }
41682
41683 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41684 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41685
41686 status = VIA_READ(VIA_REG_INTERRUPT);
41687 if (status & VIA_IRQ_VBLANK_PENDING) {
41688 - atomic_inc(&dev_priv->vbl_received);
41689 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41690 + atomic_inc_unchecked(&dev_priv->vbl_received);
41691 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41692 do_gettimeofday(&cur_vblank);
41693 if (dev_priv->last_vblank_valid) {
41694 dev_priv->usec_per_vblank =
41695 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41696 dev_priv->last_vblank = cur_vblank;
41697 dev_priv->last_vblank_valid = 1;
41698 }
41699 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41700 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41701 DRM_DEBUG("US per vblank is: %u\n",
41702 dev_priv->usec_per_vblank);
41703 }
41704 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41705
41706 for (i = 0; i < dev_priv->num_irqs; ++i) {
41707 if (status & cur_irq->pending_mask) {
41708 - atomic_inc(&cur_irq->irq_received);
41709 + atomic_inc_unchecked(&cur_irq->irq_received);
41710 wake_up(&cur_irq->irq_queue);
41711 handled = 1;
41712 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41713 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41714 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41715 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41716 masks[irq][4]));
41717 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41718 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41719 } else {
41720 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41721 (((cur_irq_sequence =
41722 - atomic_read(&cur_irq->irq_received)) -
41723 + atomic_read_unchecked(&cur_irq->irq_received)) -
41724 *sequence) <= (1 << 23)));
41725 }
41726 *sequence = cur_irq_sequence;
41727 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41728 }
41729
41730 for (i = 0; i < dev_priv->num_irqs; ++i) {
41731 - atomic_set(&cur_irq->irq_received, 0);
41732 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41733 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41734 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41735 init_waitqueue_head(&cur_irq->irq_queue);
41736 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41737 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41738 case VIA_IRQ_RELATIVE:
41739 irqwait->request.sequence +=
41740 - atomic_read(&cur_irq->irq_received);
41741 + atomic_read_unchecked(&cur_irq->irq_received);
41742 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41743 case VIA_IRQ_ABSOLUTE:
41744 break;
41745 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41746 index 4ee799b..69fc0d1 100644
41747 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41748 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41749 @@ -446,7 +446,7 @@ struct vmw_private {
41750 * Fencing and IRQs.
41751 */
41752
41753 - atomic_t marker_seq;
41754 + atomic_unchecked_t marker_seq;
41755 wait_queue_head_t fence_queue;
41756 wait_queue_head_t fifo_queue;
41757 int fence_queue_waiters; /* Protected by hw_mutex */
41758 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41759 index 09e10ae..cb76c60 100644
41760 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41761 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41762 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41763 (unsigned int) min,
41764 (unsigned int) fifo->capabilities);
41765
41766 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41767 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41768 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41769 vmw_marker_queue_init(&fifo->marker_queue);
41770 return vmw_fifo_send_fence(dev_priv, &dummy);
41771 @@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41772 if (reserveable)
41773 iowrite32(bytes, fifo_mem +
41774 SVGA_FIFO_RESERVED);
41775 - return fifo_mem + (next_cmd >> 2);
41776 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41777 } else {
41778 need_bounce = true;
41779 }
41780 @@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41781
41782 fm = vmw_fifo_reserve(dev_priv, bytes);
41783 if (unlikely(fm == NULL)) {
41784 - *seqno = atomic_read(&dev_priv->marker_seq);
41785 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41786 ret = -ENOMEM;
41787 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41788 false, 3*HZ);
41789 @@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41790 }
41791
41792 do {
41793 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41794 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41795 } while (*seqno == 0);
41796
41797 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41798 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41799 index 170b61b..fec7348 100644
41800 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41801 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41802 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41803 }
41804
41805 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41806 - vmw_gmrid_man_init,
41807 - vmw_gmrid_man_takedown,
41808 - vmw_gmrid_man_get_node,
41809 - vmw_gmrid_man_put_node,
41810 - vmw_gmrid_man_debug
41811 + .init = vmw_gmrid_man_init,
41812 + .takedown = vmw_gmrid_man_takedown,
41813 + .get_node = vmw_gmrid_man_get_node,
41814 + .put_node = vmw_gmrid_man_put_node,
41815 + .debug = vmw_gmrid_man_debug
41816 };
41817 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41818 index 37881ec..319065d 100644
41819 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41820 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41821 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41822 int ret;
41823
41824 num_clips = arg->num_clips;
41825 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41826 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41827
41828 if (unlikely(num_clips == 0))
41829 return 0;
41830 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41831 int ret;
41832
41833 num_clips = arg->num_clips;
41834 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41835 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41836
41837 if (unlikely(num_clips == 0))
41838 return 0;
41839 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41840 index 0c42376..6febe77 100644
41841 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41842 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41843 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41844 * emitted. Then the fence is stale and signaled.
41845 */
41846
41847 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41848 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41849 > VMW_FENCE_WRAP);
41850
41851 return ret;
41852 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41853
41854 if (fifo_idle)
41855 down_read(&fifo_state->rwsem);
41856 - signal_seq = atomic_read(&dev_priv->marker_seq);
41857 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41858 ret = 0;
41859
41860 for (;;) {
41861 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41862 index efd1ffd..0ae13ca 100644
41863 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41864 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41865 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41866 while (!vmw_lag_lt(queue, us)) {
41867 spin_lock(&queue->lock);
41868 if (list_empty(&queue->head))
41869 - seqno = atomic_read(&dev_priv->marker_seq);
41870 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41871 else {
41872 marker = list_first_entry(&queue->head,
41873 struct vmw_marker, head);
41874 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41875 index 37ac7b5..d52a5c9 100644
41876 --- a/drivers/gpu/vga/vga_switcheroo.c
41877 +++ b/drivers/gpu/vga/vga_switcheroo.c
41878 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41879
41880 /* this version is for the case where the power switch is separate
41881 to the device being powered down. */
41882 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41883 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41884 {
41885 /* copy over all the bus versions */
41886 if (dev->bus && dev->bus->pm) {
41887 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41888 return ret;
41889 }
41890
41891 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41892 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41893 {
41894 /* copy over all the bus versions */
41895 if (dev->bus && dev->bus->pm) {
41896 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41897 index dfaccfc..bfea740 100644
41898 --- a/drivers/hid/hid-core.c
41899 +++ b/drivers/hid/hid-core.c
41900 @@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41901
41902 int hid_add_device(struct hid_device *hdev)
41903 {
41904 - static atomic_t id = ATOMIC_INIT(0);
41905 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41906 int ret;
41907
41908 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41909 @@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41910 /* XXX hack, any other cleaner solution after the driver core
41911 * is converted to allow more than 20 bytes as the device name? */
41912 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41913 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41914 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41915
41916 hid_debug_register(hdev, dev_name(&hdev->dev));
41917 ret = device_add(&hdev->dev);
41918 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41919 index 71f5692..147d3da 100644
41920 --- a/drivers/hid/hid-logitech-dj.c
41921 +++ b/drivers/hid/hid-logitech-dj.c
41922 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41923 * device (via hid_input_report() ) and return 1 so hid-core does not do
41924 * anything else with it.
41925 */
41926 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41927 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41928 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41929 + __func__, dj_report->device_index);
41930 + return false;
41931 + }
41932
41933 /* case 1) */
41934 if (data[0] != REPORT_ID_DJ_SHORT)
41935 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41936 index bc4269e..b6e6102 100644
41937 --- a/drivers/hid/hid-sony.c
41938 +++ b/drivers/hid/hid-sony.c
41939 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41940 __u8 buf[36];
41941 };
41942
41943 +#define DS4_REPORT_0x02_SIZE 37
41944 +#define DS4_REPORT_0x05_SIZE 32
41945 +#define DS4_REPORT_0x11_SIZE 78
41946 +#define DS4_REPORT_0x81_SIZE 7
41947 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41948 +
41949 static spinlock_t sony_dev_list_lock;
41950 static LIST_HEAD(sony_device_list);
41951 static DEFINE_IDA(sony_device_id_allocator);
41952 @@ -811,6 +817,7 @@ struct sony_sc {
41953 struct work_struct state_worker;
41954 struct power_supply battery;
41955 int device_id;
41956 + __u8 *output_report_dmabuf;
41957
41958 #ifdef CONFIG_SONY_FF
41959 __u8 left;
41960 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41961
41962 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41963 {
41964 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41965 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41966 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41967 + __u8 *buf;
41968 + int ret;
41969 +
41970 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41971 + if (!buf)
41972 + return -ENOMEM;
41973 +
41974 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41975 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41976 +
41977 + kfree(buf);
41978 +
41979 + return ret;
41980 }
41981
41982 /*
41983 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41984 */
41985 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41986 {
41987 - __u8 buf[37] = { 0 };
41988 + __u8 *buf;
41989 + int ret;
41990
41991 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41992 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41993 + if (!buf)
41994 + return -ENOMEM;
41995 +
41996 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41997 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41998 +
41999 + kfree(buf);
42000 +
42001 + return ret;
42002 }
42003
42004 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
42005 @@ -1471,9 +1498,7 @@ error_leds:
42006
42007 static void sixaxis_state_worker(struct work_struct *work)
42008 {
42009 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
42010 - int n;
42011 - union sixaxis_output_report_01 report = {
42012 + static const union sixaxis_output_report_01 default_report = {
42013 .buf = {
42014 0x01,
42015 0x00, 0xff, 0x00, 0xff, 0x00,
42016 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
42017 0x00, 0x00, 0x00, 0x00, 0x00
42018 }
42019 };
42020 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
42021 + struct sixaxis_output_report *report =
42022 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
42023 + int n;
42024 +
42025 + /* Initialize the report with default values */
42026 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
42027
42028 #ifdef CONFIG_SONY_FF
42029 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
42030 - report.data.rumble.left_motor_force = sc->left;
42031 + report->rumble.right_motor_on = sc->right ? 1 : 0;
42032 + report->rumble.left_motor_force = sc->left;
42033 #endif
42034
42035 - report.data.leds_bitmap |= sc->led_state[0] << 1;
42036 - report.data.leds_bitmap |= sc->led_state[1] << 2;
42037 - report.data.leds_bitmap |= sc->led_state[2] << 3;
42038 - report.data.leds_bitmap |= sc->led_state[3] << 4;
42039 + report->leds_bitmap |= sc->led_state[0] << 1;
42040 + report->leds_bitmap |= sc->led_state[1] << 2;
42041 + report->leds_bitmap |= sc->led_state[2] << 3;
42042 + report->leds_bitmap |= sc->led_state[3] << 4;
42043
42044 /* Set flag for all leds off, required for 3rd party INTEC controller */
42045 - if ((report.data.leds_bitmap & 0x1E) == 0)
42046 - report.data.leds_bitmap |= 0x20;
42047 + if ((report->leds_bitmap & 0x1E) == 0)
42048 + report->leds_bitmap |= 0x20;
42049
42050 /*
42051 * The LEDs in the report are indexed in reverse order to their
42052 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
42053 */
42054 for (n = 0; n < 4; n++) {
42055 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
42056 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
42057 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
42058 + report->led[3 - n].duty_off = sc->led_delay_off[n];
42059 + report->led[3 - n].duty_on = sc->led_delay_on[n];
42060 }
42061 }
42062
42063 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
42064 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42065 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
42066 + sizeof(struct sixaxis_output_report),
42067 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42068 }
42069
42070 static void dualshock4_state_worker(struct work_struct *work)
42071 {
42072 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
42073 struct hid_device *hdev = sc->hdev;
42074 + __u8 *buf = sc->output_report_dmabuf;
42075 int offset;
42076
42077 - __u8 buf[78] = { 0 };
42078 -
42079 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42080 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
42081 buf[0] = 0x05;
42082 buf[1] = 0xFF;
42083 offset = 4;
42084 } else {
42085 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
42086 buf[0] = 0x11;
42087 buf[1] = 0xB0;
42088 buf[3] = 0x0F;
42089 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
42090 buf[offset++] = sc->led_delay_off[3];
42091
42092 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42093 - hid_hw_output_report(hdev, buf, 32);
42094 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42095 else
42096 - hid_hw_raw_request(hdev, 0x11, buf, 78,
42097 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42098 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42099 }
42100
42101 +static int sony_allocate_output_report(struct sony_sc *sc)
42102 +{
42103 + if (sc->quirks & SIXAXIS_CONTROLLER)
42104 + sc->output_report_dmabuf =
42105 + kmalloc(sizeof(union sixaxis_output_report_01),
42106 + GFP_KERNEL);
42107 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42108 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42109 + GFP_KERNEL);
42110 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42111 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42112 + GFP_KERNEL);
42113 + else
42114 + return 0;
42115 +
42116 + if (!sc->output_report_dmabuf)
42117 + return -ENOMEM;
42118 +
42119 + return 0;
42120 +}
42121 +
42122 #ifdef CONFIG_SONY_FF
42123 static int sony_play_effect(struct input_dev *dev, void *data,
42124 struct ff_effect *effect)
42125 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42126
42127 static int sony_check_add(struct sony_sc *sc)
42128 {
42129 + __u8 *buf = NULL;
42130 int n, ret;
42131
42132 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42133 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42134 return 0;
42135 }
42136 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42137 - __u8 buf[7];
42138 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42139 + if (!buf)
42140 + return -ENOMEM;
42141
42142 /*
42143 * The MAC address of a DS4 controller connected via USB can be
42144 * retrieved with feature report 0x81. The address begins at
42145 * offset 1.
42146 */
42147 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42148 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42149 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42150 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42151 + HID_REQ_GET_REPORT);
42152
42153 - if (ret != 7) {
42154 + if (ret != DS4_REPORT_0x81_SIZE) {
42155 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42156 - return ret < 0 ? ret : -EINVAL;
42157 + ret = ret < 0 ? ret : -EINVAL;
42158 + goto out_free;
42159 }
42160
42161 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42162 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42163 - __u8 buf[18];
42164 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42165 + if (!buf)
42166 + return -ENOMEM;
42167
42168 /*
42169 * The MAC address of a Sixaxis controller connected via USB can
42170 * be retrieved with feature report 0xf2. The address begins at
42171 * offset 4.
42172 */
42173 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42174 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42175 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42176 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42177 + HID_REQ_GET_REPORT);
42178
42179 - if (ret != 18) {
42180 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42181 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42182 - return ret < 0 ? ret : -EINVAL;
42183 + ret = ret < 0 ? ret : -EINVAL;
42184 + goto out_free;
42185 }
42186
42187 /*
42188 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42189 return 0;
42190 }
42191
42192 - return sony_check_add_dev_list(sc);
42193 + ret = sony_check_add_dev_list(sc);
42194 +
42195 +out_free:
42196 +
42197 + kfree(buf);
42198 +
42199 + return ret;
42200 }
42201
42202 static int sony_set_device_id(struct sony_sc *sc)
42203 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42204 return ret;
42205 }
42206
42207 + ret = sony_allocate_output_report(sc);
42208 + if (ret < 0) {
42209 + hid_err(hdev, "failed to allocate the output report buffer\n");
42210 + goto err_stop;
42211 + }
42212 +
42213 ret = sony_set_device_id(sc);
42214 if (ret < 0) {
42215 hid_err(hdev, "failed to allocate the device id\n");
42216 @@ -1984,6 +2060,7 @@ err_stop:
42217 if (sc->quirks & SONY_BATTERY_SUPPORT)
42218 sony_battery_remove(sc);
42219 sony_cancel_work_sync(sc);
42220 + kfree(sc->output_report_dmabuf);
42221 sony_remove_dev_list(sc);
42222 sony_release_device_id(sc);
42223 hid_hw_stop(hdev);
42224 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42225
42226 sony_cancel_work_sync(sc);
42227
42228 + kfree(sc->output_report_dmabuf);
42229 +
42230 sony_remove_dev_list(sc);
42231
42232 sony_release_device_id(sc);
42233 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42234 index c13fb5b..55a3802 100644
42235 --- a/drivers/hid/hid-wiimote-debug.c
42236 +++ b/drivers/hid/hid-wiimote-debug.c
42237 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42238 else if (size == 0)
42239 return -EIO;
42240
42241 - if (copy_to_user(u, buf, size))
42242 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42243 return -EFAULT;
42244
42245 *off += size;
42246 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42247 index 433f72a..2926005 100644
42248 --- a/drivers/hv/channel.c
42249 +++ b/drivers/hv/channel.c
42250 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42251 unsigned long flags;
42252 int ret = 0;
42253
42254 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42255 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42256 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42257 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42258
42259 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42260 if (ret)
42261 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42262 index 3e4235c..877d0e5 100644
42263 --- a/drivers/hv/hv.c
42264 +++ b/drivers/hv/hv.c
42265 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42266 u64 output_address = (output) ? virt_to_phys(output) : 0;
42267 u32 output_address_hi = output_address >> 32;
42268 u32 output_address_lo = output_address & 0xFFFFFFFF;
42269 - void *hypercall_page = hv_context.hypercall_page;
42270 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42271
42272 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42273 "=a"(hv_status_lo) : "d" (control_hi),
42274 @@ -156,7 +156,7 @@ int hv_init(void)
42275 /* See if the hypercall page is already set */
42276 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42277
42278 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42279 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42280
42281 if (!virtaddr)
42282 goto cleanup;
42283 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42284 index 5e90c5d..d8fcefb 100644
42285 --- a/drivers/hv/hv_balloon.c
42286 +++ b/drivers/hv/hv_balloon.c
42287 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42288
42289 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42290 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42291 -static atomic_t trans_id = ATOMIC_INIT(0);
42292 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42293
42294 static int dm_ring_size = (5 * PAGE_SIZE);
42295
42296 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42297 pr_info("Memory hot add failed\n");
42298
42299 dm->state = DM_INITIALIZED;
42300 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42301 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42302 vmbus_sendpacket(dm->dev->channel, &resp,
42303 sizeof(struct dm_hot_add_response),
42304 (unsigned long)NULL,
42305 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42306 memset(&status, 0, sizeof(struct dm_status));
42307 status.hdr.type = DM_STATUS_REPORT;
42308 status.hdr.size = sizeof(struct dm_status);
42309 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42310 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42311
42312 /*
42313 * The host expects the guest to report free memory.
42314 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42315 * send the status. This can happen if we were interrupted
42316 * after we picked our transaction ID.
42317 */
42318 - if (status.hdr.trans_id != atomic_read(&trans_id))
42319 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42320 return;
42321
42322 /*
42323 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42324 */
42325
42326 do {
42327 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42328 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42329 ret = vmbus_sendpacket(dm_device.dev->channel,
42330 bl_resp,
42331 bl_resp->hdr.size,
42332 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42333
42334 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42335 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42336 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42337 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42338 resp.hdr.size = sizeof(struct dm_unballoon_response);
42339
42340 vmbus_sendpacket(dm_device.dev->channel, &resp,
42341 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42342 memset(&version_req, 0, sizeof(struct dm_version_request));
42343 version_req.hdr.type = DM_VERSION_REQUEST;
42344 version_req.hdr.size = sizeof(struct dm_version_request);
42345 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42346 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42347 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42348 version_req.is_last_attempt = 1;
42349
42350 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42351 memset(&version_req, 0, sizeof(struct dm_version_request));
42352 version_req.hdr.type = DM_VERSION_REQUEST;
42353 version_req.hdr.size = sizeof(struct dm_version_request);
42354 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42355 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42356 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42357 version_req.is_last_attempt = 0;
42358
42359 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42360 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42361 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42362 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42363 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42364 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42365
42366 cap_msg.caps.cap_bits.balloon = 1;
42367 cap_msg.caps.cap_bits.hot_add = 1;
42368 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42369 index c386d8d..d6004c4 100644
42370 --- a/drivers/hv/hyperv_vmbus.h
42371 +++ b/drivers/hv/hyperv_vmbus.h
42372 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42373 struct vmbus_connection {
42374 enum vmbus_connect_state conn_state;
42375
42376 - atomic_t next_gpadl_handle;
42377 + atomic_unchecked_t next_gpadl_handle;
42378
42379 /*
42380 * Represents channel interrupts. Each bit position represents a
42381 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42382 index 4d6b269..2e23b86 100644
42383 --- a/drivers/hv/vmbus_drv.c
42384 +++ b/drivers/hv/vmbus_drv.c
42385 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42386 {
42387 int ret = 0;
42388
42389 - static atomic_t device_num = ATOMIC_INIT(0);
42390 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42391
42392 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42393 - atomic_inc_return(&device_num));
42394 + atomic_inc_return_unchecked(&device_num));
42395
42396 child_device_obj->device.bus = &hv_bus;
42397 child_device_obj->device.parent = &hv_acpi_dev->dev;
42398 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42399 index 579bdf9..75118b5 100644
42400 --- a/drivers/hwmon/acpi_power_meter.c
42401 +++ b/drivers/hwmon/acpi_power_meter.c
42402 @@ -116,7 +116,7 @@ struct sensor_template {
42403 struct device_attribute *devattr,
42404 const char *buf, size_t count);
42405 int index;
42406 -};
42407 +} __do_const;
42408
42409 /* Averaging interval */
42410 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42411 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42412 struct sensor_template *attrs)
42413 {
42414 struct device *dev = &resource->acpi_dev->dev;
42415 - struct sensor_device_attribute *sensors =
42416 + sensor_device_attribute_no_const *sensors =
42417 &resource->sensors[resource->num_sensors];
42418 int res = 0;
42419
42420 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42421 index 3288f13..71cfb4e 100644
42422 --- a/drivers/hwmon/applesmc.c
42423 +++ b/drivers/hwmon/applesmc.c
42424 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42425 {
42426 struct applesmc_node_group *grp;
42427 struct applesmc_dev_attr *node;
42428 - struct attribute *attr;
42429 + attribute_no_const *attr;
42430 int ret, i;
42431
42432 for (grp = groups; grp->format; grp++) {
42433 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42434 index cccef87..06ce8ec 100644
42435 --- a/drivers/hwmon/asus_atk0110.c
42436 +++ b/drivers/hwmon/asus_atk0110.c
42437 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42438 struct atk_sensor_data {
42439 struct list_head list;
42440 struct atk_data *data;
42441 - struct device_attribute label_attr;
42442 - struct device_attribute input_attr;
42443 - struct device_attribute limit1_attr;
42444 - struct device_attribute limit2_attr;
42445 + device_attribute_no_const label_attr;
42446 + device_attribute_no_const input_attr;
42447 + device_attribute_no_const limit1_attr;
42448 + device_attribute_no_const limit2_attr;
42449 char label_attr_name[ATTR_NAME_SIZE];
42450 char input_attr_name[ATTR_NAME_SIZE];
42451 char limit1_attr_name[ATTR_NAME_SIZE];
42452 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42453 static struct device_attribute atk_name_attr =
42454 __ATTR(name, 0444, atk_name_show, NULL);
42455
42456 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42457 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42458 sysfs_show_func show)
42459 {
42460 sysfs_attr_init(&attr->attr);
42461 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42462 index d76f0b7..55ae976 100644
42463 --- a/drivers/hwmon/coretemp.c
42464 +++ b/drivers/hwmon/coretemp.c
42465 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42466 return NOTIFY_OK;
42467 }
42468
42469 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42470 +static struct notifier_block coretemp_cpu_notifier = {
42471 .notifier_call = coretemp_cpu_callback,
42472 };
42473
42474 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42475 index 7a8a6fb..015c1fd 100644
42476 --- a/drivers/hwmon/ibmaem.c
42477 +++ b/drivers/hwmon/ibmaem.c
42478 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42479 struct aem_rw_sensor_template *rw)
42480 {
42481 struct device *dev = &data->pdev->dev;
42482 - struct sensor_device_attribute *sensors = data->sensors;
42483 + sensor_device_attribute_no_const *sensors = data->sensors;
42484 int err;
42485
42486 /* Set up read-only sensors */
42487 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42488 index 14c82da..09b25d7 100644
42489 --- a/drivers/hwmon/iio_hwmon.c
42490 +++ b/drivers/hwmon/iio_hwmon.c
42491 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42492 {
42493 struct device *dev = &pdev->dev;
42494 struct iio_hwmon_state *st;
42495 - struct sensor_device_attribute *a;
42496 + sensor_device_attribute_no_const *a;
42497 int ret, i;
42498 int in_i = 1, temp_i = 1, curr_i = 1;
42499 enum iio_chan_type type;
42500 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42501 index 7710f46..427a28d 100644
42502 --- a/drivers/hwmon/nct6683.c
42503 +++ b/drivers/hwmon/nct6683.c
42504 @@ -397,11 +397,11 @@ static struct attribute_group *
42505 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42506 int repeat)
42507 {
42508 - struct sensor_device_attribute_2 *a2;
42509 - struct sensor_device_attribute *a;
42510 + sensor_device_attribute_2_no_const *a2;
42511 + sensor_device_attribute_no_const *a;
42512 struct sensor_device_template **t;
42513 struct sensor_device_attr_u *su;
42514 - struct attribute_group *group;
42515 + attribute_group_no_const *group;
42516 struct attribute **attrs;
42517 int i, j, count;
42518
42519 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42520 index 504cbdd..35d6f25 100644
42521 --- a/drivers/hwmon/nct6775.c
42522 +++ b/drivers/hwmon/nct6775.c
42523 @@ -943,10 +943,10 @@ static struct attribute_group *
42524 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42525 int repeat)
42526 {
42527 - struct attribute_group *group;
42528 + attribute_group_no_const *group;
42529 struct sensor_device_attr_u *su;
42530 - struct sensor_device_attribute *a;
42531 - struct sensor_device_attribute_2 *a2;
42532 + sensor_device_attribute_no_const *a;
42533 + sensor_device_attribute_2_no_const *a2;
42534 struct attribute **attrs;
42535 struct sensor_device_template **t;
42536 int i, count;
42537 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42538 index 291d11f..3f0dbbd 100644
42539 --- a/drivers/hwmon/pmbus/pmbus_core.c
42540 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42541 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42542 return 0;
42543 }
42544
42545 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42546 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42547 const char *name,
42548 umode_t mode,
42549 ssize_t (*show)(struct device *dev,
42550 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42551 dev_attr->store = store;
42552 }
42553
42554 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42555 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42556 const char *name,
42557 umode_t mode,
42558 ssize_t (*show)(struct device *dev,
42559 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42560 u16 reg, u8 mask)
42561 {
42562 struct pmbus_boolean *boolean;
42563 - struct sensor_device_attribute *a;
42564 + sensor_device_attribute_no_const *a;
42565
42566 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42567 if (!boolean)
42568 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42569 bool update, bool readonly)
42570 {
42571 struct pmbus_sensor *sensor;
42572 - struct device_attribute *a;
42573 + device_attribute_no_const *a;
42574
42575 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42576 if (!sensor)
42577 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42578 const char *lstring, int index)
42579 {
42580 struct pmbus_label *label;
42581 - struct device_attribute *a;
42582 + device_attribute_no_const *a;
42583
42584 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42585 if (!label)
42586 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42587 index 97cd45a..ac54d8b 100644
42588 --- a/drivers/hwmon/sht15.c
42589 +++ b/drivers/hwmon/sht15.c
42590 @@ -169,7 +169,7 @@ struct sht15_data {
42591 int supply_uv;
42592 bool supply_uv_valid;
42593 struct work_struct update_supply_work;
42594 - atomic_t interrupt_handled;
42595 + atomic_unchecked_t interrupt_handled;
42596 };
42597
42598 /**
42599 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42600 ret = gpio_direction_input(data->pdata->gpio_data);
42601 if (ret)
42602 return ret;
42603 - atomic_set(&data->interrupt_handled, 0);
42604 + atomic_set_unchecked(&data->interrupt_handled, 0);
42605
42606 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42607 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42608 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42609 /* Only relevant if the interrupt hasn't occurred. */
42610 - if (!atomic_read(&data->interrupt_handled))
42611 + if (!atomic_read_unchecked(&data->interrupt_handled))
42612 schedule_work(&data->read_work);
42613 }
42614 ret = wait_event_timeout(data->wait_queue,
42615 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42616
42617 /* First disable the interrupt */
42618 disable_irq_nosync(irq);
42619 - atomic_inc(&data->interrupt_handled);
42620 + atomic_inc_unchecked(&data->interrupt_handled);
42621 /* Then schedule a reading work struct */
42622 if (data->state != SHT15_READING_NOTHING)
42623 schedule_work(&data->read_work);
42624 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42625 * If not, then start the interrupt again - care here as could
42626 * have gone low in meantime so verify it hasn't!
42627 */
42628 - atomic_set(&data->interrupt_handled, 0);
42629 + atomic_set_unchecked(&data->interrupt_handled, 0);
42630 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42631 /* If still not occurred or another handler was scheduled */
42632 if (gpio_get_value(data->pdata->gpio_data)
42633 - || atomic_read(&data->interrupt_handled))
42634 + || atomic_read_unchecked(&data->interrupt_handled))
42635 return;
42636 }
42637
42638 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42639 index 8df43c5..b07b91d 100644
42640 --- a/drivers/hwmon/via-cputemp.c
42641 +++ b/drivers/hwmon/via-cputemp.c
42642 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42643 return NOTIFY_OK;
42644 }
42645
42646 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42647 +static struct notifier_block via_cputemp_cpu_notifier = {
42648 .notifier_call = via_cputemp_cpu_callback,
42649 };
42650
42651 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42652 index 65e3240..e6c511d 100644
42653 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42654 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42655 @@ -39,7 +39,7 @@
42656 extern struct i2c_adapter amd756_smbus;
42657
42658 static struct i2c_adapter *s4882_adapter;
42659 -static struct i2c_algorithm *s4882_algo;
42660 +static i2c_algorithm_no_const *s4882_algo;
42661
42662 /* Wrapper access functions for multiplexed SMBus */
42663 static DEFINE_MUTEX(amd756_lock);
42664 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42665 index b19a310..d6eece0 100644
42666 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42667 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42668 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42669 /* usb layer */
42670
42671 /* Send command to device, and get response. */
42672 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42673 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42674 {
42675 int ret = 0;
42676 int actual;
42677 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42678 index 88eda09..cf40434 100644
42679 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42680 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42681 @@ -37,7 +37,7 @@
42682 extern struct i2c_adapter *nforce2_smbus;
42683
42684 static struct i2c_adapter *s4985_adapter;
42685 -static struct i2c_algorithm *s4985_algo;
42686 +static i2c_algorithm_no_const *s4985_algo;
42687
42688 /* Wrapper access functions for multiplexed SMBus */
42689 static DEFINE_MUTEX(nforce2_lock);
42690 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42691 index 71c7a39..71dd3e0 100644
42692 --- a/drivers/i2c/i2c-dev.c
42693 +++ b/drivers/i2c/i2c-dev.c
42694 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42695 break;
42696 }
42697
42698 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42699 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42700 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42701 if (IS_ERR(rdwr_pa[i].buf)) {
42702 res = PTR_ERR(rdwr_pa[i].buf);
42703 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42704 index 0b510ba..4fbb5085 100644
42705 --- a/drivers/ide/ide-cd.c
42706 +++ b/drivers/ide/ide-cd.c
42707 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42708 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42709 if ((unsigned long)buf & alignment
42710 || blk_rq_bytes(rq) & q->dma_pad_mask
42711 - || object_is_on_stack(buf))
42712 + || object_starts_on_stack(buf))
42713 drive->dma = 0;
42714 }
42715 }
42716 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42717 index af3e76d..96dfe5e 100644
42718 --- a/drivers/iio/industrialio-core.c
42719 +++ b/drivers/iio/industrialio-core.c
42720 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42721 }
42722
42723 static
42724 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42725 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42726 const char *postfix,
42727 struct iio_chan_spec const *chan,
42728 ssize_t (*readfunc)(struct device *dev,
42729 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42730 index e28a494..f7c2671 100644
42731 --- a/drivers/infiniband/core/cm.c
42732 +++ b/drivers/infiniband/core/cm.c
42733 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42734
42735 struct cm_counter_group {
42736 struct kobject obj;
42737 - atomic_long_t counter[CM_ATTR_COUNT];
42738 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42739 };
42740
42741 struct cm_counter_attribute {
42742 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42743 struct ib_mad_send_buf *msg = NULL;
42744 int ret;
42745
42746 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42747 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42748 counter[CM_REQ_COUNTER]);
42749
42750 /* Quick state check to discard duplicate REQs. */
42751 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42752 if (!cm_id_priv)
42753 return;
42754
42755 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42756 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42757 counter[CM_REP_COUNTER]);
42758 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42759 if (ret)
42760 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42761 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42762 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42763 spin_unlock_irq(&cm_id_priv->lock);
42764 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42765 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42766 counter[CM_RTU_COUNTER]);
42767 goto out;
42768 }
42769 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42770 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42771 dreq_msg->local_comm_id);
42772 if (!cm_id_priv) {
42773 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42774 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42775 counter[CM_DREQ_COUNTER]);
42776 cm_issue_drep(work->port, work->mad_recv_wc);
42777 return -EINVAL;
42778 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42779 case IB_CM_MRA_REP_RCVD:
42780 break;
42781 case IB_CM_TIMEWAIT:
42782 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42783 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42784 counter[CM_DREQ_COUNTER]);
42785 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42786 goto unlock;
42787 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42788 cm_free_msg(msg);
42789 goto deref;
42790 case IB_CM_DREQ_RCVD:
42791 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42792 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42793 counter[CM_DREQ_COUNTER]);
42794 goto unlock;
42795 default:
42796 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42797 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42798 cm_id_priv->msg, timeout)) {
42799 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42800 - atomic_long_inc(&work->port->
42801 + atomic_long_inc_unchecked(&work->port->
42802 counter_group[CM_RECV_DUPLICATES].
42803 counter[CM_MRA_COUNTER]);
42804 goto out;
42805 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42806 break;
42807 case IB_CM_MRA_REQ_RCVD:
42808 case IB_CM_MRA_REP_RCVD:
42809 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42810 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42811 counter[CM_MRA_COUNTER]);
42812 /* fall through */
42813 default:
42814 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42815 case IB_CM_LAP_IDLE:
42816 break;
42817 case IB_CM_MRA_LAP_SENT:
42818 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42819 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42820 counter[CM_LAP_COUNTER]);
42821 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42822 goto unlock;
42823 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42824 cm_free_msg(msg);
42825 goto deref;
42826 case IB_CM_LAP_RCVD:
42827 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42828 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42829 counter[CM_LAP_COUNTER]);
42830 goto unlock;
42831 default:
42832 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42833 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42834 if (cur_cm_id_priv) {
42835 spin_unlock_irq(&cm.lock);
42836 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42837 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42838 counter[CM_SIDR_REQ_COUNTER]);
42839 goto out; /* Duplicate message. */
42840 }
42841 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42842 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42843 msg->retries = 1;
42844
42845 - atomic_long_add(1 + msg->retries,
42846 + atomic_long_add_unchecked(1 + msg->retries,
42847 &port->counter_group[CM_XMIT].counter[attr_index]);
42848 if (msg->retries)
42849 - atomic_long_add(msg->retries,
42850 + atomic_long_add_unchecked(msg->retries,
42851 &port->counter_group[CM_XMIT_RETRIES].
42852 counter[attr_index]);
42853
42854 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42855 }
42856
42857 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42858 - atomic_long_inc(&port->counter_group[CM_RECV].
42859 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42860 counter[attr_id - CM_ATTR_ID_OFFSET]);
42861
42862 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42863 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42864 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42865
42866 return sprintf(buf, "%ld\n",
42867 - atomic_long_read(&group->counter[cm_attr->index]));
42868 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42869 }
42870
42871 static const struct sysfs_ops cm_counter_ops = {
42872 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42873 index 9f5ad7c..588cd84 100644
42874 --- a/drivers/infiniband/core/fmr_pool.c
42875 +++ b/drivers/infiniband/core/fmr_pool.c
42876 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42877
42878 struct task_struct *thread;
42879
42880 - atomic_t req_ser;
42881 - atomic_t flush_ser;
42882 + atomic_unchecked_t req_ser;
42883 + atomic_unchecked_t flush_ser;
42884
42885 wait_queue_head_t force_wait;
42886 };
42887 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42888 struct ib_fmr_pool *pool = pool_ptr;
42889
42890 do {
42891 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42892 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42893 ib_fmr_batch_release(pool);
42894
42895 - atomic_inc(&pool->flush_ser);
42896 + atomic_inc_unchecked(&pool->flush_ser);
42897 wake_up_interruptible(&pool->force_wait);
42898
42899 if (pool->flush_function)
42900 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42901 }
42902
42903 set_current_state(TASK_INTERRUPTIBLE);
42904 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42905 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42906 !kthread_should_stop())
42907 schedule();
42908 __set_current_state(TASK_RUNNING);
42909 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42910 pool->dirty_watermark = params->dirty_watermark;
42911 pool->dirty_len = 0;
42912 spin_lock_init(&pool->pool_lock);
42913 - atomic_set(&pool->req_ser, 0);
42914 - atomic_set(&pool->flush_ser, 0);
42915 + atomic_set_unchecked(&pool->req_ser, 0);
42916 + atomic_set_unchecked(&pool->flush_ser, 0);
42917 init_waitqueue_head(&pool->force_wait);
42918
42919 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42920 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42921 }
42922 spin_unlock_irq(&pool->pool_lock);
42923
42924 - serial = atomic_inc_return(&pool->req_ser);
42925 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42926 wake_up_process(pool->thread);
42927
42928 if (wait_event_interruptible(pool->force_wait,
42929 - atomic_read(&pool->flush_ser) - serial >= 0))
42930 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42931 return -EINTR;
42932
42933 return 0;
42934 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42935 } else {
42936 list_add_tail(&fmr->list, &pool->dirty_list);
42937 if (++pool->dirty_len >= pool->dirty_watermark) {
42938 - atomic_inc(&pool->req_ser);
42939 + atomic_inc_unchecked(&pool->req_ser);
42940 wake_up_process(pool->thread);
42941 }
42942 }
42943 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42944 index ec7a298..8742e59 100644
42945 --- a/drivers/infiniband/hw/cxgb4/mem.c
42946 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42947 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42948 int err;
42949 struct fw_ri_tpte tpt;
42950 u32 stag_idx;
42951 - static atomic_t key;
42952 + static atomic_unchecked_t key;
42953
42954 if (c4iw_fatal_error(rdev))
42955 return -EIO;
42956 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42957 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42958 rdev->stats.stag.max = rdev->stats.stag.cur;
42959 mutex_unlock(&rdev->stats.lock);
42960 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42961 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42962 }
42963 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42964 __func__, stag_state, type, pdid, stag_idx);
42965 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42966 index 79b3dbc..96e5fcc 100644
42967 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42968 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42969 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42970 struct ib_atomic_eth *ateth;
42971 struct ipath_ack_entry *e;
42972 u64 vaddr;
42973 - atomic64_t *maddr;
42974 + atomic64_unchecked_t *maddr;
42975 u64 sdata;
42976 u32 rkey;
42977 u8 next;
42978 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42979 IB_ACCESS_REMOTE_ATOMIC)))
42980 goto nack_acc_unlck;
42981 /* Perform atomic OP and save result. */
42982 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42983 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42984 sdata = be64_to_cpu(ateth->swap_data);
42985 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42986 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42987 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42988 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42989 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42990 be64_to_cpu(ateth->compare_data),
42991 sdata);
42992 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42993 index 1f95bba..9530f87 100644
42994 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42995 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42996 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42997 unsigned long flags;
42998 struct ib_wc wc;
42999 u64 sdata;
43000 - atomic64_t *maddr;
43001 + atomic64_unchecked_t *maddr;
43002 enum ib_wc_status send_status;
43003
43004 /*
43005 @@ -382,11 +382,11 @@ again:
43006 IB_ACCESS_REMOTE_ATOMIC)))
43007 goto acc_err;
43008 /* Perform atomic OP and save result. */
43009 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43010 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43011 sdata = wqe->wr.wr.atomic.compare_add;
43012 *(u64 *) sqp->s_sge.sge.vaddr =
43013 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43014 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43015 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43016 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43017 sdata, wqe->wr.wr.atomic.swap);
43018 goto send_comp;
43019 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43020 index 82a7dd8..8fb6ba6 100644
43021 --- a/drivers/infiniband/hw/mlx4/mad.c
43022 +++ b/drivers/infiniband/hw/mlx4/mad.c
43023 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43024
43025 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43026 {
43027 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43028 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43029 cpu_to_be64(0xff00000000000000LL);
43030 }
43031
43032 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43033 index ed327e6..ca1739e0 100644
43034 --- a/drivers/infiniband/hw/mlx4/mcg.c
43035 +++ b/drivers/infiniband/hw/mlx4/mcg.c
43036 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43037 {
43038 char name[20];
43039
43040 - atomic_set(&ctx->tid, 0);
43041 + atomic_set_unchecked(&ctx->tid, 0);
43042 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43043 ctx->mcg_wq = create_singlethread_workqueue(name);
43044 if (!ctx->mcg_wq)
43045 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43046 index 6eb743f..a7b0f6d 100644
43047 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43048 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43049 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43050 struct list_head mcg_mgid0_list;
43051 struct workqueue_struct *mcg_wq;
43052 struct mlx4_ib_demux_pv_ctx **tun;
43053 - atomic_t tid;
43054 + atomic_unchecked_t tid;
43055 int flushing; /* flushing the work queue */
43056 };
43057
43058 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43059 index 9d3e5c1..6f166df 100644
43060 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43061 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43062 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43063 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43064 }
43065
43066 -int mthca_QUERY_FW(struct mthca_dev *dev)
43067 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43068 {
43069 struct mthca_mailbox *mailbox;
43070 u32 *outbox;
43071 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43072 CMD_TIME_CLASS_B);
43073 }
43074
43075 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43076 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43077 int num_mtt)
43078 {
43079 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43080 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43081 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43082 }
43083
43084 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43085 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43086 int eq_num)
43087 {
43088 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43089 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43090 CMD_TIME_CLASS_B);
43091 }
43092
43093 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43094 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43095 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43096 void *in_mad, void *response_mad)
43097 {
43098 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43099 index ded76c1..0cf0a08 100644
43100 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43101 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43102 @@ -692,7 +692,7 @@ err_close:
43103 return err;
43104 }
43105
43106 -static int mthca_setup_hca(struct mthca_dev *dev)
43107 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43108 {
43109 int err;
43110
43111 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43112 index ed9a989..6aa5dc2 100644
43113 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43114 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43115 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43116 * through the bitmaps)
43117 */
43118
43119 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43120 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43121 {
43122 int o;
43123 int m;
43124 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43125 return key;
43126 }
43127
43128 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43129 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43130 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43131 {
43132 struct mthca_mailbox *mailbox;
43133 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43134 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43135 }
43136
43137 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43138 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43139 u64 *buffer_list, int buffer_size_shift,
43140 int list_len, u64 iova, u64 total_size,
43141 u32 access, struct mthca_mr *mr)
43142 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43143 index 415f8e1..e34214e 100644
43144 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43145 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43146 @@ -764,7 +764,7 @@ unlock:
43147 return 0;
43148 }
43149
43150 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43151 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43152 {
43153 struct mthca_dev *dev = to_mdev(ibcq->device);
43154 struct mthca_cq *cq = to_mcq(ibcq);
43155 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43156 index 3b2a6dc..bce26ff 100644
43157 --- a/drivers/infiniband/hw/nes/nes.c
43158 +++ b/drivers/infiniband/hw/nes/nes.c
43159 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43160 LIST_HEAD(nes_adapter_list);
43161 static LIST_HEAD(nes_dev_list);
43162
43163 -atomic_t qps_destroyed;
43164 +atomic_unchecked_t qps_destroyed;
43165
43166 static unsigned int ee_flsh_adapter;
43167 static unsigned int sysfs_nonidx_addr;
43168 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43169 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43170 struct nes_adapter *nesadapter = nesdev->nesadapter;
43171
43172 - atomic_inc(&qps_destroyed);
43173 + atomic_inc_unchecked(&qps_destroyed);
43174
43175 /* Free the control structures */
43176
43177 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43178 index bd9d132..70d84f4 100644
43179 --- a/drivers/infiniband/hw/nes/nes.h
43180 +++ b/drivers/infiniband/hw/nes/nes.h
43181 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43182 extern unsigned int wqm_quanta;
43183 extern struct list_head nes_adapter_list;
43184
43185 -extern atomic_t cm_connects;
43186 -extern atomic_t cm_accepts;
43187 -extern atomic_t cm_disconnects;
43188 -extern atomic_t cm_closes;
43189 -extern atomic_t cm_connecteds;
43190 -extern atomic_t cm_connect_reqs;
43191 -extern atomic_t cm_rejects;
43192 -extern atomic_t mod_qp_timouts;
43193 -extern atomic_t qps_created;
43194 -extern atomic_t qps_destroyed;
43195 -extern atomic_t sw_qps_destroyed;
43196 +extern atomic_unchecked_t cm_connects;
43197 +extern atomic_unchecked_t cm_accepts;
43198 +extern atomic_unchecked_t cm_disconnects;
43199 +extern atomic_unchecked_t cm_closes;
43200 +extern atomic_unchecked_t cm_connecteds;
43201 +extern atomic_unchecked_t cm_connect_reqs;
43202 +extern atomic_unchecked_t cm_rejects;
43203 +extern atomic_unchecked_t mod_qp_timouts;
43204 +extern atomic_unchecked_t qps_created;
43205 +extern atomic_unchecked_t qps_destroyed;
43206 +extern atomic_unchecked_t sw_qps_destroyed;
43207 extern u32 mh_detected;
43208 extern u32 mh_pauses_sent;
43209 extern u32 cm_packets_sent;
43210 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43211 extern u32 cm_packets_received;
43212 extern u32 cm_packets_dropped;
43213 extern u32 cm_packets_retrans;
43214 -extern atomic_t cm_listens_created;
43215 -extern atomic_t cm_listens_destroyed;
43216 +extern atomic_unchecked_t cm_listens_created;
43217 +extern atomic_unchecked_t cm_listens_destroyed;
43218 extern u32 cm_backlog_drops;
43219 -extern atomic_t cm_loopbacks;
43220 -extern atomic_t cm_nodes_created;
43221 -extern atomic_t cm_nodes_destroyed;
43222 -extern atomic_t cm_accel_dropped_pkts;
43223 -extern atomic_t cm_resets_recvd;
43224 -extern atomic_t pau_qps_created;
43225 -extern atomic_t pau_qps_destroyed;
43226 +extern atomic_unchecked_t cm_loopbacks;
43227 +extern atomic_unchecked_t cm_nodes_created;
43228 +extern atomic_unchecked_t cm_nodes_destroyed;
43229 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43230 +extern atomic_unchecked_t cm_resets_recvd;
43231 +extern atomic_unchecked_t pau_qps_created;
43232 +extern atomic_unchecked_t pau_qps_destroyed;
43233
43234 extern u32 int_mod_timer_init;
43235 extern u32 int_mod_cq_depth_256;
43236 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43237 index 6f09a72..cf4399d 100644
43238 --- a/drivers/infiniband/hw/nes/nes_cm.c
43239 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43240 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43241 u32 cm_packets_retrans;
43242 u32 cm_packets_created;
43243 u32 cm_packets_received;
43244 -atomic_t cm_listens_created;
43245 -atomic_t cm_listens_destroyed;
43246 +atomic_unchecked_t cm_listens_created;
43247 +atomic_unchecked_t cm_listens_destroyed;
43248 u32 cm_backlog_drops;
43249 -atomic_t cm_loopbacks;
43250 -atomic_t cm_nodes_created;
43251 -atomic_t cm_nodes_destroyed;
43252 -atomic_t cm_accel_dropped_pkts;
43253 -atomic_t cm_resets_recvd;
43254 +atomic_unchecked_t cm_loopbacks;
43255 +atomic_unchecked_t cm_nodes_created;
43256 +atomic_unchecked_t cm_nodes_destroyed;
43257 +atomic_unchecked_t cm_accel_dropped_pkts;
43258 +atomic_unchecked_t cm_resets_recvd;
43259
43260 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43261 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43262 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43263 /* instance of function pointers for client API */
43264 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43265 static struct nes_cm_ops nes_cm_api = {
43266 - mini_cm_accelerated,
43267 - mini_cm_listen,
43268 - mini_cm_del_listen,
43269 - mini_cm_connect,
43270 - mini_cm_close,
43271 - mini_cm_accept,
43272 - mini_cm_reject,
43273 - mini_cm_recv_pkt,
43274 - mini_cm_dealloc_core,
43275 - mini_cm_get,
43276 - mini_cm_set
43277 + .accelerated = mini_cm_accelerated,
43278 + .listen = mini_cm_listen,
43279 + .stop_listener = mini_cm_del_listen,
43280 + .connect = mini_cm_connect,
43281 + .close = mini_cm_close,
43282 + .accept = mini_cm_accept,
43283 + .reject = mini_cm_reject,
43284 + .recv_pkt = mini_cm_recv_pkt,
43285 + .destroy_cm_core = mini_cm_dealloc_core,
43286 + .get = mini_cm_get,
43287 + .set = mini_cm_set
43288 };
43289
43290 static struct nes_cm_core *g_cm_core;
43291
43292 -atomic_t cm_connects;
43293 -atomic_t cm_accepts;
43294 -atomic_t cm_disconnects;
43295 -atomic_t cm_closes;
43296 -atomic_t cm_connecteds;
43297 -atomic_t cm_connect_reqs;
43298 -atomic_t cm_rejects;
43299 +atomic_unchecked_t cm_connects;
43300 +atomic_unchecked_t cm_accepts;
43301 +atomic_unchecked_t cm_disconnects;
43302 +atomic_unchecked_t cm_closes;
43303 +atomic_unchecked_t cm_connecteds;
43304 +atomic_unchecked_t cm_connect_reqs;
43305 +atomic_unchecked_t cm_rejects;
43306
43307 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43308 {
43309 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43310 kfree(listener);
43311 listener = NULL;
43312 ret = 0;
43313 - atomic_inc(&cm_listens_destroyed);
43314 + atomic_inc_unchecked(&cm_listens_destroyed);
43315 } else {
43316 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43317 }
43318 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43319 cm_node->rem_mac);
43320
43321 add_hte_node(cm_core, cm_node);
43322 - atomic_inc(&cm_nodes_created);
43323 + atomic_inc_unchecked(&cm_nodes_created);
43324
43325 return cm_node;
43326 }
43327 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43328 }
43329
43330 atomic_dec(&cm_core->node_cnt);
43331 - atomic_inc(&cm_nodes_destroyed);
43332 + atomic_inc_unchecked(&cm_nodes_destroyed);
43333 nesqp = cm_node->nesqp;
43334 if (nesqp) {
43335 nesqp->cm_node = NULL;
43336 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43337
43338 static void drop_packet(struct sk_buff *skb)
43339 {
43340 - atomic_inc(&cm_accel_dropped_pkts);
43341 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43342 dev_kfree_skb_any(skb);
43343 }
43344
43345 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43346 {
43347
43348 int reset = 0; /* whether to send reset in case of err.. */
43349 - atomic_inc(&cm_resets_recvd);
43350 + atomic_inc_unchecked(&cm_resets_recvd);
43351 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43352 " refcnt=%d\n", cm_node, cm_node->state,
43353 atomic_read(&cm_node->ref_count));
43354 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43355 rem_ref_cm_node(cm_node->cm_core, cm_node);
43356 return NULL;
43357 }
43358 - atomic_inc(&cm_loopbacks);
43359 + atomic_inc_unchecked(&cm_loopbacks);
43360 loopbackremotenode->loopbackpartner = cm_node;
43361 loopbackremotenode->tcp_cntxt.rcv_wscale =
43362 NES_CM_DEFAULT_RCV_WND_SCALE;
43363 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43364 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43365 else {
43366 rem_ref_cm_node(cm_core, cm_node);
43367 - atomic_inc(&cm_accel_dropped_pkts);
43368 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43369 dev_kfree_skb_any(skb);
43370 }
43371 break;
43372 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43373
43374 if ((cm_id) && (cm_id->event_handler)) {
43375 if (issue_disconn) {
43376 - atomic_inc(&cm_disconnects);
43377 + atomic_inc_unchecked(&cm_disconnects);
43378 cm_event.event = IW_CM_EVENT_DISCONNECT;
43379 cm_event.status = disconn_status;
43380 cm_event.local_addr = cm_id->local_addr;
43381 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43382 }
43383
43384 if (issue_close) {
43385 - atomic_inc(&cm_closes);
43386 + atomic_inc_unchecked(&cm_closes);
43387 nes_disconnect(nesqp, 1);
43388
43389 cm_id->provider_data = nesqp;
43390 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43391
43392 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43393 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43394 - atomic_inc(&cm_accepts);
43395 + atomic_inc_unchecked(&cm_accepts);
43396
43397 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43398 netdev_refcnt_read(nesvnic->netdev));
43399 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43400 struct nes_cm_core *cm_core;
43401 u8 *start_buff;
43402
43403 - atomic_inc(&cm_rejects);
43404 + atomic_inc_unchecked(&cm_rejects);
43405 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43406 loopback = cm_node->loopbackpartner;
43407 cm_core = cm_node->cm_core;
43408 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43409 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43410 ntohs(laddr->sin_port));
43411
43412 - atomic_inc(&cm_connects);
43413 + atomic_inc_unchecked(&cm_connects);
43414 nesqp->active_conn = 1;
43415
43416 /* cache the cm_id in the qp */
43417 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43418 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43419 return err;
43420 }
43421 - atomic_inc(&cm_listens_created);
43422 + atomic_inc_unchecked(&cm_listens_created);
43423 }
43424
43425 cm_id->add_ref(cm_id);
43426 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43427
43428 if (nesqp->destroyed)
43429 return;
43430 - atomic_inc(&cm_connecteds);
43431 + atomic_inc_unchecked(&cm_connecteds);
43432 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43433 " local port 0x%04X. jiffies = %lu.\n",
43434 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43435 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43436
43437 cm_id->add_ref(cm_id);
43438 ret = cm_id->event_handler(cm_id, &cm_event);
43439 - atomic_inc(&cm_closes);
43440 + atomic_inc_unchecked(&cm_closes);
43441 cm_event.event = IW_CM_EVENT_CLOSE;
43442 cm_event.status = 0;
43443 cm_event.provider_data = cm_id->provider_data;
43444 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43445 return;
43446 cm_id = cm_node->cm_id;
43447
43448 - atomic_inc(&cm_connect_reqs);
43449 + atomic_inc_unchecked(&cm_connect_reqs);
43450 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43451 cm_node, cm_id, jiffies);
43452
43453 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43454 return;
43455 cm_id = cm_node->cm_id;
43456
43457 - atomic_inc(&cm_connect_reqs);
43458 + atomic_inc_unchecked(&cm_connect_reqs);
43459 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43460 cm_node, cm_id, jiffies);
43461
43462 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43463 index 4166452..fc952c3 100644
43464 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43465 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43466 @@ -40,8 +40,8 @@
43467 #include "nes.h"
43468 #include "nes_mgt.h"
43469
43470 -atomic_t pau_qps_created;
43471 -atomic_t pau_qps_destroyed;
43472 +atomic_unchecked_t pau_qps_created;
43473 +atomic_unchecked_t pau_qps_destroyed;
43474
43475 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43476 {
43477 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43478 {
43479 struct sk_buff *skb;
43480 unsigned long flags;
43481 - atomic_inc(&pau_qps_destroyed);
43482 + atomic_inc_unchecked(&pau_qps_destroyed);
43483
43484 /* Free packets that have not yet been forwarded */
43485 /* Lock is acquired by skb_dequeue when removing the skb */
43486 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43487 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43488 skb_queue_head_init(&nesqp->pau_list);
43489 spin_lock_init(&nesqp->pau_lock);
43490 - atomic_inc(&pau_qps_created);
43491 + atomic_inc_unchecked(&pau_qps_created);
43492 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43493 }
43494
43495 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43496 index 49eb511..a774366 100644
43497 --- a/drivers/infiniband/hw/nes/nes_nic.c
43498 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43499 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43500 target_stat_values[++index] = mh_detected;
43501 target_stat_values[++index] = mh_pauses_sent;
43502 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43503 - target_stat_values[++index] = atomic_read(&cm_connects);
43504 - target_stat_values[++index] = atomic_read(&cm_accepts);
43505 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43506 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43507 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43508 - target_stat_values[++index] = atomic_read(&cm_rejects);
43509 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43510 - target_stat_values[++index] = atomic_read(&qps_created);
43511 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43512 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43513 - target_stat_values[++index] = atomic_read(&cm_closes);
43514 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43515 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43516 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43517 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43518 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43519 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43520 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43521 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43522 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43523 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43524 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43525 target_stat_values[++index] = cm_packets_sent;
43526 target_stat_values[++index] = cm_packets_bounced;
43527 target_stat_values[++index] = cm_packets_created;
43528 target_stat_values[++index] = cm_packets_received;
43529 target_stat_values[++index] = cm_packets_dropped;
43530 target_stat_values[++index] = cm_packets_retrans;
43531 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43532 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43533 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43534 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43535 target_stat_values[++index] = cm_backlog_drops;
43536 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43537 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43538 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43539 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43540 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43541 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43542 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43543 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43544 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43545 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43546 target_stat_values[++index] = nesadapter->free_4kpbl;
43547 target_stat_values[++index] = nesadapter->free_256pbl;
43548 target_stat_values[++index] = int_mod_timer_init;
43549 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43550 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43551 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43552 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43553 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43554 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43555 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43556 }
43557
43558 /**
43559 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43560 index fef067c..6a25ccd 100644
43561 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43562 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43563 @@ -46,9 +46,9 @@
43564
43565 #include <rdma/ib_umem.h>
43566
43567 -atomic_t mod_qp_timouts;
43568 -atomic_t qps_created;
43569 -atomic_t sw_qps_destroyed;
43570 +atomic_unchecked_t mod_qp_timouts;
43571 +atomic_unchecked_t qps_created;
43572 +atomic_unchecked_t sw_qps_destroyed;
43573
43574 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43575
43576 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43577 if (init_attr->create_flags)
43578 return ERR_PTR(-EINVAL);
43579
43580 - atomic_inc(&qps_created);
43581 + atomic_inc_unchecked(&qps_created);
43582 switch (init_attr->qp_type) {
43583 case IB_QPT_RC:
43584 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43585 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43586 struct iw_cm_event cm_event;
43587 int ret = 0;
43588
43589 - atomic_inc(&sw_qps_destroyed);
43590 + atomic_inc_unchecked(&sw_qps_destroyed);
43591 nesqp->destroyed = 1;
43592
43593 /* Blow away the connection if it exists. */
43594 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43595 index c00ae09..04e91be 100644
43596 --- a/drivers/infiniband/hw/qib/qib.h
43597 +++ b/drivers/infiniband/hw/qib/qib.h
43598 @@ -52,6 +52,7 @@
43599 #include <linux/kref.h>
43600 #include <linux/sched.h>
43601 #include <linux/kthread.h>
43602 +#include <linux/slab.h>
43603
43604 #include "qib_common.h"
43605 #include "qib_verbs.h"
43606 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43607 index cdc7df4..a2fdfdb 100644
43608 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43609 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43610 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43611 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43612 }
43613
43614 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43615 +static struct rtnl_link_ops ipoib_link_ops = {
43616 .kind = "ipoib",
43617 .maxtype = IFLA_IPOIB_MAX,
43618 .policy = ipoib_policy,
43619 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43620 index e29c04e..adbf68c 100644
43621 --- a/drivers/input/gameport/gameport.c
43622 +++ b/drivers/input/gameport/gameport.c
43623 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43624 */
43625 static void gameport_init_port(struct gameport *gameport)
43626 {
43627 - static atomic_t gameport_no = ATOMIC_INIT(0);
43628 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43629
43630 __module_get(THIS_MODULE);
43631
43632 mutex_init(&gameport->drv_mutex);
43633 device_initialize(&gameport->dev);
43634 dev_set_name(&gameport->dev, "gameport%lu",
43635 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43636 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43637 gameport->dev.bus = &gameport_bus;
43638 gameport->dev.release = gameport_release_port;
43639 if (gameport->parent)
43640 diff --git a/drivers/input/input.c b/drivers/input/input.c
43641 index 0f175f5..4c481c0 100644
43642 --- a/drivers/input/input.c
43643 +++ b/drivers/input/input.c
43644 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43645 */
43646 struct input_dev *input_allocate_device(void)
43647 {
43648 - static atomic_t input_no = ATOMIC_INIT(0);
43649 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43650 struct input_dev *dev;
43651
43652 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43653 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43654 INIT_LIST_HEAD(&dev->node);
43655
43656 dev_set_name(&dev->dev, "input%lu",
43657 - (unsigned long) atomic_inc_return(&input_no) - 1);
43658 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43659
43660 __module_get(THIS_MODULE);
43661 }
43662 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43663 index 4a95b22..874c182 100644
43664 --- a/drivers/input/joystick/sidewinder.c
43665 +++ b/drivers/input/joystick/sidewinder.c
43666 @@ -30,6 +30,7 @@
43667 #include <linux/kernel.h>
43668 #include <linux/module.h>
43669 #include <linux/slab.h>
43670 +#include <linux/sched.h>
43671 #include <linux/input.h>
43672 #include <linux/gameport.h>
43673 #include <linux/jiffies.h>
43674 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43675 index fc55f0d..11e2aa6 100644
43676 --- a/drivers/input/joystick/xpad.c
43677 +++ b/drivers/input/joystick/xpad.c
43678 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43679
43680 static int xpad_led_probe(struct usb_xpad *xpad)
43681 {
43682 - static atomic_t led_seq = ATOMIC_INIT(0);
43683 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43684 long led_no;
43685 struct xpad_led *led;
43686 struct led_classdev *led_cdev;
43687 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43688 if (!led)
43689 return -ENOMEM;
43690
43691 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43692 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43693
43694 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43695 led->xpad = xpad;
43696 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43697 index afed8e2..3aa8a18 100644
43698 --- a/drivers/input/misc/ims-pcu.c
43699 +++ b/drivers/input/misc/ims-pcu.c
43700 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43701
43702 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43703 {
43704 - static atomic_t device_no = ATOMIC_INIT(0);
43705 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43706
43707 const struct ims_pcu_device_info *info;
43708 int error;
43709 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43710 }
43711
43712 /* Device appears to be operable, complete initialization */
43713 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43714 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43715
43716 /*
43717 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43718 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43719 index f4cf664..3204fda 100644
43720 --- a/drivers/input/mouse/psmouse.h
43721 +++ b/drivers/input/mouse/psmouse.h
43722 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43723 ssize_t (*set)(struct psmouse *psmouse, void *data,
43724 const char *buf, size_t count);
43725 bool protect;
43726 -};
43727 +} __do_const;
43728 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43729
43730 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43731 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43732 index b604564..3f14ae4 100644
43733 --- a/drivers/input/mousedev.c
43734 +++ b/drivers/input/mousedev.c
43735 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43736
43737 spin_unlock_irq(&client->packet_lock);
43738
43739 - if (copy_to_user(buffer, data, count))
43740 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43741 return -EFAULT;
43742
43743 return count;
43744 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43745 index d399b8b..4913ede 100644
43746 --- a/drivers/input/serio/serio.c
43747 +++ b/drivers/input/serio/serio.c
43748 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43749 */
43750 static void serio_init_port(struct serio *serio)
43751 {
43752 - static atomic_t serio_no = ATOMIC_INIT(0);
43753 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43754
43755 __module_get(THIS_MODULE);
43756
43757 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43758 mutex_init(&serio->drv_mutex);
43759 device_initialize(&serio->dev);
43760 dev_set_name(&serio->dev, "serio%lu",
43761 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43762 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43763 serio->dev.bus = &serio_bus;
43764 serio->dev.release = serio_release_port;
43765 serio->dev.groups = serio_device_attr_groups;
43766 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43767 index c9a02fe..0debc75 100644
43768 --- a/drivers/input/serio/serio_raw.c
43769 +++ b/drivers/input/serio/serio_raw.c
43770 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43771
43772 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43773 {
43774 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43775 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43776 struct serio_raw *serio_raw;
43777 int err;
43778
43779 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43780 }
43781
43782 snprintf(serio_raw->name, sizeof(serio_raw->name),
43783 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43784 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43785 kref_init(&serio_raw->kref);
43786 INIT_LIST_HEAD(&serio_raw->client_list);
43787 init_waitqueue_head(&serio_raw->wait);
43788 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43789 index 505a9ad..356734c 100644
43790 --- a/drivers/iommu/amd_iommu.c
43791 +++ b/drivers/iommu/amd_iommu.c
43792 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43793
43794 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43795 {
43796 + phys_addr_t physaddr;
43797 WARN_ON(address & 0x7ULL);
43798
43799 memset(cmd, 0, sizeof(*cmd));
43800 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43801 - cmd->data[1] = upper_32_bits(__pa(address));
43802 +
43803 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43804 + if (object_starts_on_stack((void *)address)) {
43805 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43806 + physaddr = __pa((u64)adjbuf);
43807 + } else
43808 +#endif
43809 + physaddr = __pa(address);
43810 +
43811 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43812 + cmd->data[1] = upper_32_bits(physaddr);
43813 cmd->data[2] = 1;
43814 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43815 }
43816 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43817 index 60558f7..5a02369 100644
43818 --- a/drivers/iommu/arm-smmu.c
43819 +++ b/drivers/iommu/arm-smmu.c
43820 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43821 cfg->irptndx = cfg->cbndx;
43822 }
43823
43824 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43825 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43826 arm_smmu_init_context_bank(smmu_domain);
43827 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43828
43829 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43830 index ed8b048..7fbcc01 100644
43831 --- a/drivers/iommu/iommu.c
43832 +++ b/drivers/iommu/iommu.c
43833 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43834 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43835 {
43836 int err;
43837 - struct notifier_block *nb;
43838 + notifier_block_no_const *nb;
43839 struct iommu_callback_data cb = {
43840 .ops = ops,
43841 };
43842 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43843 index 74a1767..5a359e8 100644
43844 --- a/drivers/iommu/irq_remapping.c
43845 +++ b/drivers/iommu/irq_remapping.c
43846 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43847 void panic_if_irq_remap(const char *msg)
43848 {
43849 if (irq_remapping_enabled)
43850 - panic(msg);
43851 + panic("%s", msg);
43852 }
43853
43854 static void ir_ack_apic_edge(struct irq_data *data)
43855 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43856
43857 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43858 {
43859 - chip->irq_print_chip = ir_print_prefix;
43860 - chip->irq_ack = ir_ack_apic_edge;
43861 - chip->irq_eoi = ir_ack_apic_level;
43862 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43863 + pax_open_kernel();
43864 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43865 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43866 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43867 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43868 + pax_close_kernel();
43869 }
43870
43871 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43872 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43873 index 38493ff..001538b 100644
43874 --- a/drivers/irqchip/irq-gic.c
43875 +++ b/drivers/irqchip/irq-gic.c
43876 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43877 * Supported arch specific GIC irq extension.
43878 * Default make them NULL.
43879 */
43880 -struct irq_chip gic_arch_extn = {
43881 +irq_chip_no_const gic_arch_extn = {
43882 .irq_eoi = NULL,
43883 .irq_mask = NULL,
43884 .irq_unmask = NULL,
43885 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43886 chained_irq_exit(chip, desc);
43887 }
43888
43889 -static struct irq_chip gic_chip = {
43890 +static irq_chip_no_const gic_chip __read_only = {
43891 .name = "GIC",
43892 .irq_mask = gic_mask_irq,
43893 .irq_unmask = gic_unmask_irq,
43894 diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43895 index 542e850..1bb094c 100644
43896 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43897 +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43898 @@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43899 struct intc_irqpin_iomem *i;
43900 struct resource *io[INTC_IRQPIN_REG_NR];
43901 struct resource *irq;
43902 - struct irq_chip *irq_chip;
43903 + irq_chip_no_const *irq_chip;
43904 void (*enable_fn)(struct irq_data *d);
43905 void (*disable_fn)(struct irq_data *d);
43906 const char *name = dev_name(dev);
43907 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43908 index 8777065..a4a9967 100644
43909 --- a/drivers/irqchip/irq-renesas-irqc.c
43910 +++ b/drivers/irqchip/irq-renesas-irqc.c
43911 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43912 struct irqc_priv *p;
43913 struct resource *io;
43914 struct resource *irq;
43915 - struct irq_chip *irq_chip;
43916 + irq_chip_no_const *irq_chip;
43917 const char *name = dev_name(&pdev->dev);
43918 int ret;
43919 int k;
43920 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43921 index 6a2df32..dc962f1 100644
43922 --- a/drivers/isdn/capi/capi.c
43923 +++ b/drivers/isdn/capi/capi.c
43924 @@ -81,8 +81,8 @@ struct capiminor {
43925
43926 struct capi20_appl *ap;
43927 u32 ncci;
43928 - atomic_t datahandle;
43929 - atomic_t msgid;
43930 + atomic_unchecked_t datahandle;
43931 + atomic_unchecked_t msgid;
43932
43933 struct tty_port port;
43934 int ttyinstop;
43935 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43936 capimsg_setu16(s, 2, mp->ap->applid);
43937 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43938 capimsg_setu8 (s, 5, CAPI_RESP);
43939 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43940 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43941 capimsg_setu32(s, 8, mp->ncci);
43942 capimsg_setu16(s, 12, datahandle);
43943 }
43944 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43945 mp->outbytes -= len;
43946 spin_unlock_bh(&mp->outlock);
43947
43948 - datahandle = atomic_inc_return(&mp->datahandle);
43949 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43950 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43951 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43952 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43953 capimsg_setu16(skb->data, 2, mp->ap->applid);
43954 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43955 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43956 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43957 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43958 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43959 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43960 capimsg_setu16(skb->data, 16, len); /* Data length */
43961 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43962 index aecec6d..11e13c5 100644
43963 --- a/drivers/isdn/gigaset/bas-gigaset.c
43964 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43965 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43966
43967
43968 static const struct gigaset_ops gigops = {
43969 - gigaset_write_cmd,
43970 - gigaset_write_room,
43971 - gigaset_chars_in_buffer,
43972 - gigaset_brkchars,
43973 - gigaset_init_bchannel,
43974 - gigaset_close_bchannel,
43975 - gigaset_initbcshw,
43976 - gigaset_freebcshw,
43977 - gigaset_reinitbcshw,
43978 - gigaset_initcshw,
43979 - gigaset_freecshw,
43980 - gigaset_set_modem_ctrl,
43981 - gigaset_baud_rate,
43982 - gigaset_set_line_ctrl,
43983 - gigaset_isoc_send_skb,
43984 - gigaset_isoc_input,
43985 + .write_cmd = gigaset_write_cmd,
43986 + .write_room = gigaset_write_room,
43987 + .chars_in_buffer = gigaset_chars_in_buffer,
43988 + .brkchars = gigaset_brkchars,
43989 + .init_bchannel = gigaset_init_bchannel,
43990 + .close_bchannel = gigaset_close_bchannel,
43991 + .initbcshw = gigaset_initbcshw,
43992 + .freebcshw = gigaset_freebcshw,
43993 + .reinitbcshw = gigaset_reinitbcshw,
43994 + .initcshw = gigaset_initcshw,
43995 + .freecshw = gigaset_freecshw,
43996 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43997 + .baud_rate = gigaset_baud_rate,
43998 + .set_line_ctrl = gigaset_set_line_ctrl,
43999 + .send_skb = gigaset_isoc_send_skb,
44000 + .handle_input = gigaset_isoc_input,
44001 };
44002
44003 /* bas_gigaset_init
44004 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44005 index 600c79b..3752bab 100644
44006 --- a/drivers/isdn/gigaset/interface.c
44007 +++ b/drivers/isdn/gigaset/interface.c
44008 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44009 }
44010 tty->driver_data = cs;
44011
44012 - ++cs->port.count;
44013 + atomic_inc(&cs->port.count);
44014
44015 - if (cs->port.count == 1) {
44016 + if (atomic_read(&cs->port.count) == 1) {
44017 tty_port_tty_set(&cs->port, tty);
44018 cs->port.low_latency = 1;
44019 }
44020 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44021
44022 if (!cs->connected)
44023 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44024 - else if (!cs->port.count)
44025 + else if (!atomic_read(&cs->port.count))
44026 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44027 - else if (!--cs->port.count)
44028 + else if (!atomic_dec_return(&cs->port.count))
44029 tty_port_tty_set(&cs->port, NULL);
44030
44031 mutex_unlock(&cs->mutex);
44032 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44033 index 8c91fd5..14f13ce 100644
44034 --- a/drivers/isdn/gigaset/ser-gigaset.c
44035 +++ b/drivers/isdn/gigaset/ser-gigaset.c
44036 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44037 }
44038
44039 static const struct gigaset_ops ops = {
44040 - gigaset_write_cmd,
44041 - gigaset_write_room,
44042 - gigaset_chars_in_buffer,
44043 - gigaset_brkchars,
44044 - gigaset_init_bchannel,
44045 - gigaset_close_bchannel,
44046 - gigaset_initbcshw,
44047 - gigaset_freebcshw,
44048 - gigaset_reinitbcshw,
44049 - gigaset_initcshw,
44050 - gigaset_freecshw,
44051 - gigaset_set_modem_ctrl,
44052 - gigaset_baud_rate,
44053 - gigaset_set_line_ctrl,
44054 - gigaset_m10x_send_skb, /* asyncdata.c */
44055 - gigaset_m10x_input, /* asyncdata.c */
44056 + .write_cmd = gigaset_write_cmd,
44057 + .write_room = gigaset_write_room,
44058 + .chars_in_buffer = gigaset_chars_in_buffer,
44059 + .brkchars = gigaset_brkchars,
44060 + .init_bchannel = gigaset_init_bchannel,
44061 + .close_bchannel = gigaset_close_bchannel,
44062 + .initbcshw = gigaset_initbcshw,
44063 + .freebcshw = gigaset_freebcshw,
44064 + .reinitbcshw = gigaset_reinitbcshw,
44065 + .initcshw = gigaset_initcshw,
44066 + .freecshw = gigaset_freecshw,
44067 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44068 + .baud_rate = gigaset_baud_rate,
44069 + .set_line_ctrl = gigaset_set_line_ctrl,
44070 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44071 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44072 };
44073
44074
44075 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44076 index a8e652d..edadaa4 100644
44077 --- a/drivers/isdn/gigaset/usb-gigaset.c
44078 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44079 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44080 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44081 memcpy(cs->hw.usb->bchars, buf, 6);
44082 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44083 - 0, 0, &buf, 6, 2000);
44084 + 0, 0, buf, 6, 2000);
44085 }
44086
44087 static void gigaset_freebcshw(struct bc_state *bcs)
44088 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44089 }
44090
44091 static const struct gigaset_ops ops = {
44092 - gigaset_write_cmd,
44093 - gigaset_write_room,
44094 - gigaset_chars_in_buffer,
44095 - gigaset_brkchars,
44096 - gigaset_init_bchannel,
44097 - gigaset_close_bchannel,
44098 - gigaset_initbcshw,
44099 - gigaset_freebcshw,
44100 - gigaset_reinitbcshw,
44101 - gigaset_initcshw,
44102 - gigaset_freecshw,
44103 - gigaset_set_modem_ctrl,
44104 - gigaset_baud_rate,
44105 - gigaset_set_line_ctrl,
44106 - gigaset_m10x_send_skb,
44107 - gigaset_m10x_input,
44108 + .write_cmd = gigaset_write_cmd,
44109 + .write_room = gigaset_write_room,
44110 + .chars_in_buffer = gigaset_chars_in_buffer,
44111 + .brkchars = gigaset_brkchars,
44112 + .init_bchannel = gigaset_init_bchannel,
44113 + .close_bchannel = gigaset_close_bchannel,
44114 + .initbcshw = gigaset_initbcshw,
44115 + .freebcshw = gigaset_freebcshw,
44116 + .reinitbcshw = gigaset_reinitbcshw,
44117 + .initcshw = gigaset_initcshw,
44118 + .freecshw = gigaset_freecshw,
44119 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44120 + .baud_rate = gigaset_baud_rate,
44121 + .set_line_ctrl = gigaset_set_line_ctrl,
44122 + .send_skb = gigaset_m10x_send_skb,
44123 + .handle_input = gigaset_m10x_input,
44124 };
44125
44126 /*
44127 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44128 index 4d9b195..455075c 100644
44129 --- a/drivers/isdn/hardware/avm/b1.c
44130 +++ b/drivers/isdn/hardware/avm/b1.c
44131 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44132 }
44133 if (left) {
44134 if (t4file->user) {
44135 - if (copy_from_user(buf, dp, left))
44136 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44137 return -EFAULT;
44138 } else {
44139 memcpy(buf, dp, left);
44140 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44141 }
44142 if (left) {
44143 if (config->user) {
44144 - if (copy_from_user(buf, dp, left))
44145 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44146 return -EFAULT;
44147 } else {
44148 memcpy(buf, dp, left);
44149 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44150 index 9b856e1..fa03c92 100644
44151 --- a/drivers/isdn/i4l/isdn_common.c
44152 +++ b/drivers/isdn/i4l/isdn_common.c
44153 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44154 } else
44155 return -EINVAL;
44156 case IIOCDBGVAR:
44157 + if (!capable(CAP_SYS_RAWIO))
44158 + return -EPERM;
44159 if (arg) {
44160 if (copy_to_user(argp, &dev, sizeof(ulong)))
44161 return -EFAULT;
44162 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44163 index 91d5730..336523e 100644
44164 --- a/drivers/isdn/i4l/isdn_concap.c
44165 +++ b/drivers/isdn/i4l/isdn_concap.c
44166 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44167 }
44168
44169 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44170 - &isdn_concap_dl_data_req,
44171 - &isdn_concap_dl_connect_req,
44172 - &isdn_concap_dl_disconn_req
44173 + .data_req = &isdn_concap_dl_data_req,
44174 + .connect_req = &isdn_concap_dl_connect_req,
44175 + .disconn_req = &isdn_concap_dl_disconn_req
44176 };
44177
44178 /* The following should better go into a dedicated source file such that
44179 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44180 index bc91261..2ef7e36 100644
44181 --- a/drivers/isdn/i4l/isdn_tty.c
44182 +++ b/drivers/isdn/i4l/isdn_tty.c
44183 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44184
44185 #ifdef ISDN_DEBUG_MODEM_OPEN
44186 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44187 - port->count);
44188 + atomic_read(&port->count));
44189 #endif
44190 - port->count++;
44191 + atomic_inc(&port->count);
44192 port->tty = tty;
44193 /*
44194 * Start up serial port
44195 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44196 #endif
44197 return;
44198 }
44199 - if ((tty->count == 1) && (port->count != 1)) {
44200 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44201 /*
44202 * Uh, oh. tty->count is 1, which means that the tty
44203 * structure will be freed. Info->count should always
44204 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44205 * serial port won't be shutdown.
44206 */
44207 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44208 - "info->count is %d\n", port->count);
44209 - port->count = 1;
44210 + "info->count is %d\n", atomic_read(&port->count));
44211 + atomic_set(&port->count, 1);
44212 }
44213 - if (--port->count < 0) {
44214 + if (atomic_dec_return(&port->count) < 0) {
44215 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44216 - info->line, port->count);
44217 - port->count = 0;
44218 + info->line, atomic_read(&port->count));
44219 + atomic_set(&port->count, 0);
44220 }
44221 - if (port->count) {
44222 + if (atomic_read(&port->count)) {
44223 #ifdef ISDN_DEBUG_MODEM_OPEN
44224 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44225 #endif
44226 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44227 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44228 return;
44229 isdn_tty_shutdown(info);
44230 - port->count = 0;
44231 + atomic_set(&port->count, 0);
44232 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44233 port->tty = NULL;
44234 wake_up_interruptible(&port->open_wait);
44235 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44236 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44237 modem_info *info = &dev->mdm.info[i];
44238
44239 - if (info->port.count == 0)
44240 + if (atomic_read(&info->port.count) == 0)
44241 continue;
44242 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44243 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44244 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44245 index e2d4e58..40cd045 100644
44246 --- a/drivers/isdn/i4l/isdn_x25iface.c
44247 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44248 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44249
44250
44251 static struct concap_proto_ops ix25_pops = {
44252 - &isdn_x25iface_proto_new,
44253 - &isdn_x25iface_proto_del,
44254 - &isdn_x25iface_proto_restart,
44255 - &isdn_x25iface_proto_close,
44256 - &isdn_x25iface_xmit,
44257 - &isdn_x25iface_receive,
44258 - &isdn_x25iface_connect_ind,
44259 - &isdn_x25iface_disconn_ind
44260 + .proto_new = &isdn_x25iface_proto_new,
44261 + .proto_del = &isdn_x25iface_proto_del,
44262 + .restart = &isdn_x25iface_proto_restart,
44263 + .close = &isdn_x25iface_proto_close,
44264 + .encap_and_xmit = &isdn_x25iface_xmit,
44265 + .data_ind = &isdn_x25iface_receive,
44266 + .connect_ind = &isdn_x25iface_connect_ind,
44267 + .disconn_ind = &isdn_x25iface_disconn_ind
44268 };
44269
44270 /* error message helper function */
44271 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44272 index 6a7447c..cae33fe 100644
44273 --- a/drivers/isdn/icn/icn.c
44274 +++ b/drivers/isdn/icn/icn.c
44275 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44276 if (count > len)
44277 count = len;
44278 if (user) {
44279 - if (copy_from_user(msg, buf, count))
44280 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44281 return -EFAULT;
44282 } else
44283 memcpy(msg, buf, count);
44284 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44285 index 87f7dff..7300125 100644
44286 --- a/drivers/isdn/mISDN/dsp_cmx.c
44287 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44288 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44289 static u16 dsp_count; /* last sample count */
44290 static int dsp_count_valid; /* if we have last sample count */
44291
44292 -void
44293 +void __intentional_overflow(-1)
44294 dsp_cmx_send(void *arg)
44295 {
44296 struct dsp_conf *conf;
44297 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44298 index f58a354..fbae176 100644
44299 --- a/drivers/leds/leds-clevo-mail.c
44300 +++ b/drivers/leds/leds-clevo-mail.c
44301 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44302 * detected as working, but in reality it is not) as low as
44303 * possible.
44304 */
44305 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44306 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44307 {
44308 .callback = clevo_mail_led_dmi_callback,
44309 .ident = "Clevo D410J",
44310 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44311 index 046cb70..6b20d39 100644
44312 --- a/drivers/leds/leds-ss4200.c
44313 +++ b/drivers/leds/leds-ss4200.c
44314 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44315 * detected as working, but in reality it is not) as low as
44316 * possible.
44317 */
44318 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44319 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44320 {
44321 .callback = ss4200_led_dmi_callback,
44322 .ident = "Intel SS4200-E",
44323 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44324 index 6590558..a74c5dd 100644
44325 --- a/drivers/lguest/core.c
44326 +++ b/drivers/lguest/core.c
44327 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44328 * The end address needs +1 because __get_vm_area allocates an
44329 * extra guard page, so we need space for that.
44330 */
44331 +
44332 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44333 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44334 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44335 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44336 +#else
44337 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44338 VM_ALLOC, switcher_addr, switcher_addr
44339 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44340 +#endif
44341 +
44342 if (!switcher_vma) {
44343 err = -ENOMEM;
44344 printk("lguest: could not map switcher pages high\n");
44345 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44346 * Now the Switcher is mapped at the right address, we can't fail!
44347 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44348 */
44349 - memcpy(switcher_vma->addr, start_switcher_text,
44350 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44351 end_switcher_text - start_switcher_text);
44352
44353 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44354 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44355 index e8b55c3..3514c37 100644
44356 --- a/drivers/lguest/page_tables.c
44357 +++ b/drivers/lguest/page_tables.c
44358 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44359 /*:*/
44360
44361 #ifdef CONFIG_X86_PAE
44362 -static void release_pmd(pmd_t *spmd)
44363 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44364 {
44365 /* If the entry's not present, there's nothing to release. */
44366 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44367 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44368 index 922a1ac..9dd0c2a 100644
44369 --- a/drivers/lguest/x86/core.c
44370 +++ b/drivers/lguest/x86/core.c
44371 @@ -59,7 +59,7 @@ static struct {
44372 /* Offset from where switcher.S was compiled to where we've copied it */
44373 static unsigned long switcher_offset(void)
44374 {
44375 - return switcher_addr - (unsigned long)start_switcher_text;
44376 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44377 }
44378
44379 /* This cpu's struct lguest_pages (after the Switcher text page) */
44380 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44381 * These copies are pretty cheap, so we do them unconditionally: */
44382 /* Save the current Host top-level page directory.
44383 */
44384 +
44385 +#ifdef CONFIG_PAX_PER_CPU_PGD
44386 + pages->state.host_cr3 = read_cr3();
44387 +#else
44388 pages->state.host_cr3 = __pa(current->mm->pgd);
44389 +#endif
44390 +
44391 /*
44392 * Set up the Guest's page tables to see this CPU's pages (and no
44393 * other CPU's pages).
44394 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44395 * compiled-in switcher code and the high-mapped copy we just made.
44396 */
44397 for (i = 0; i < IDT_ENTRIES; i++)
44398 - default_idt_entries[i] += switcher_offset();
44399 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44400
44401 /*
44402 * Set up the Switcher's per-cpu areas.
44403 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44404 * it will be undisturbed when we switch. To change %cs and jump we
44405 * need this structure to feed to Intel's "lcall" instruction.
44406 */
44407 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44408 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44409 lguest_entry.segment = LGUEST_CS;
44410
44411 /*
44412 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44413 index 40634b0..4f5855e 100644
44414 --- a/drivers/lguest/x86/switcher_32.S
44415 +++ b/drivers/lguest/x86/switcher_32.S
44416 @@ -87,6 +87,7 @@
44417 #include <asm/page.h>
44418 #include <asm/segment.h>
44419 #include <asm/lguest.h>
44420 +#include <asm/processor-flags.h>
44421
44422 // We mark the start of the code to copy
44423 // It's placed in .text tho it's never run here
44424 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44425 // Changes type when we load it: damn Intel!
44426 // For after we switch over our page tables
44427 // That entry will be read-only: we'd crash.
44428 +
44429 +#ifdef CONFIG_PAX_KERNEXEC
44430 + mov %cr0, %edx
44431 + xor $X86_CR0_WP, %edx
44432 + mov %edx, %cr0
44433 +#endif
44434 +
44435 movl $(GDT_ENTRY_TSS*8), %edx
44436 ltr %dx
44437
44438 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44439 // Let's clear it again for our return.
44440 // The GDT descriptor of the Host
44441 // Points to the table after two "size" bytes
44442 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44443 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44444 // Clear "used" from type field (byte 5, bit 2)
44445 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44446 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44447 +
44448 +#ifdef CONFIG_PAX_KERNEXEC
44449 + mov %cr0, %eax
44450 + xor $X86_CR0_WP, %eax
44451 + mov %eax, %cr0
44452 +#endif
44453
44454 // Once our page table's switched, the Guest is live!
44455 // The Host fades as we run this final step.
44456 @@ -295,13 +309,12 @@ deliver_to_host:
44457 // I consulted gcc, and it gave
44458 // These instructions, which I gladly credit:
44459 leal (%edx,%ebx,8), %eax
44460 - movzwl (%eax),%edx
44461 - movl 4(%eax), %eax
44462 - xorw %ax, %ax
44463 - orl %eax, %edx
44464 + movl 4(%eax), %edx
44465 + movw (%eax), %dx
44466 // Now the address of the handler's in %edx
44467 // We call it now: its "iret" drops us home.
44468 - jmp *%edx
44469 + ljmp $__KERNEL_CS, $1f
44470 +1: jmp *%edx
44471
44472 // Every interrupt can come to us here
44473 // But we must truly tell each apart.
44474 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44475 index a08e3ee..df8ade2 100644
44476 --- a/drivers/md/bcache/closure.h
44477 +++ b/drivers/md/bcache/closure.h
44478 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44479 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44480 struct workqueue_struct *wq)
44481 {
44482 - BUG_ON(object_is_on_stack(cl));
44483 + BUG_ON(object_starts_on_stack(cl));
44484 closure_set_ip(cl);
44485 cl->fn = fn;
44486 cl->wq = wq;
44487 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44488 index da3604e..7789cb4c 100644
44489 --- a/drivers/md/bitmap.c
44490 +++ b/drivers/md/bitmap.c
44491 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44492 chunk_kb ? "KB" : "B");
44493 if (bitmap->storage.file) {
44494 seq_printf(seq, ", file: ");
44495 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44496 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44497 }
44498
44499 seq_printf(seq, "\n");
44500 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44501 index 0be9381..114262b 100644
44502 --- a/drivers/md/dm-ioctl.c
44503 +++ b/drivers/md/dm-ioctl.c
44504 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44505 cmd == DM_LIST_VERSIONS_CMD)
44506 return 0;
44507
44508 - if ((cmd == DM_DEV_CREATE_CMD)) {
44509 + if (cmd == DM_DEV_CREATE_CMD) {
44510 if (!*param->name) {
44511 DMWARN("name not supplied when creating device");
44512 return -EINVAL;
44513 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44514 index 7dfdb5c..4caada6 100644
44515 --- a/drivers/md/dm-raid1.c
44516 +++ b/drivers/md/dm-raid1.c
44517 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44518
44519 struct mirror {
44520 struct mirror_set *ms;
44521 - atomic_t error_count;
44522 + atomic_unchecked_t error_count;
44523 unsigned long error_type;
44524 struct dm_dev *dev;
44525 sector_t offset;
44526 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44527 struct mirror *m;
44528
44529 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44530 - if (!atomic_read(&m->error_count))
44531 + if (!atomic_read_unchecked(&m->error_count))
44532 return m;
44533
44534 return NULL;
44535 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44536 * simple way to tell if a device has encountered
44537 * errors.
44538 */
44539 - atomic_inc(&m->error_count);
44540 + atomic_inc_unchecked(&m->error_count);
44541
44542 if (test_and_set_bit(error_type, &m->error_type))
44543 return;
44544 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44545 struct mirror *m = get_default_mirror(ms);
44546
44547 do {
44548 - if (likely(!atomic_read(&m->error_count)))
44549 + if (likely(!atomic_read_unchecked(&m->error_count)))
44550 return m;
44551
44552 if (m-- == ms->mirror)
44553 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44554 {
44555 struct mirror *default_mirror = get_default_mirror(m->ms);
44556
44557 - return !atomic_read(&default_mirror->error_count);
44558 + return !atomic_read_unchecked(&default_mirror->error_count);
44559 }
44560
44561 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44562 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44563 */
44564 if (likely(region_in_sync(ms, region, 1)))
44565 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44566 - else if (m && atomic_read(&m->error_count))
44567 + else if (m && atomic_read_unchecked(&m->error_count))
44568 m = NULL;
44569
44570 if (likely(m))
44571 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44572 }
44573
44574 ms->mirror[mirror].ms = ms;
44575 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44576 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44577 ms->mirror[mirror].error_type = 0;
44578 ms->mirror[mirror].offset = offset;
44579
44580 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44581 */
44582 static char device_status_char(struct mirror *m)
44583 {
44584 - if (!atomic_read(&(m->error_count)))
44585 + if (!atomic_read_unchecked(&(m->error_count)))
44586 return 'A';
44587
44588 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44589 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44590 index 87f86c7..a1a4100 100644
44591 --- a/drivers/md/dm-stats.c
44592 +++ b/drivers/md/dm-stats.c
44593 @@ -382,7 +382,7 @@ do_sync_free:
44594 synchronize_rcu_expedited();
44595 dm_stat_free(&s->rcu_head);
44596 } else {
44597 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44598 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44599 call_rcu(&s->rcu_head, dm_stat_free);
44600 }
44601 return 0;
44602 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44603 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44604 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44605 ));
44606 - ACCESS_ONCE(last->last_sector) = end_sector;
44607 - ACCESS_ONCE(last->last_rw) = bi_rw;
44608 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44609 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44610 }
44611
44612 rcu_read_lock();
44613 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44614 index f8b37d4..5c5cafd 100644
44615 --- a/drivers/md/dm-stripe.c
44616 +++ b/drivers/md/dm-stripe.c
44617 @@ -21,7 +21,7 @@ struct stripe {
44618 struct dm_dev *dev;
44619 sector_t physical_start;
44620
44621 - atomic_t error_count;
44622 + atomic_unchecked_t error_count;
44623 };
44624
44625 struct stripe_c {
44626 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44627 kfree(sc);
44628 return r;
44629 }
44630 - atomic_set(&(sc->stripe[i].error_count), 0);
44631 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44632 }
44633
44634 ti->private = sc;
44635 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44636 DMEMIT("%d ", sc->stripes);
44637 for (i = 0; i < sc->stripes; i++) {
44638 DMEMIT("%s ", sc->stripe[i].dev->name);
44639 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44640 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44641 'D' : 'A';
44642 }
44643 buffer[i] = '\0';
44644 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44645 */
44646 for (i = 0; i < sc->stripes; i++)
44647 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44648 - atomic_inc(&(sc->stripe[i].error_count));
44649 - if (atomic_read(&(sc->stripe[i].error_count)) <
44650 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44651 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44652 DM_IO_ERROR_THRESHOLD)
44653 schedule_work(&sc->trigger_event);
44654 }
44655 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44656 index b2bd1eb..38f7a44 100644
44657 --- a/drivers/md/dm-table.c
44658 +++ b/drivers/md/dm-table.c
44659 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44660 if (!dev_size)
44661 return 0;
44662
44663 - if ((start >= dev_size) || (start + len > dev_size)) {
44664 + if ((start >= dev_size) || (len > dev_size - start)) {
44665 DMWARN("%s: %s too small for target: "
44666 "start=%llu, len=%llu, dev_size=%llu",
44667 dm_device_name(ti->table->md), bdevname(bdev, b),
44668 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44669 index e9d33ad..dae9880d 100644
44670 --- a/drivers/md/dm-thin-metadata.c
44671 +++ b/drivers/md/dm-thin-metadata.c
44672 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44673 {
44674 pmd->info.tm = pmd->tm;
44675 pmd->info.levels = 2;
44676 - pmd->info.value_type.context = pmd->data_sm;
44677 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44678 pmd->info.value_type.size = sizeof(__le64);
44679 pmd->info.value_type.inc = data_block_inc;
44680 pmd->info.value_type.dec = data_block_dec;
44681 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44682
44683 pmd->bl_info.tm = pmd->tm;
44684 pmd->bl_info.levels = 1;
44685 - pmd->bl_info.value_type.context = pmd->data_sm;
44686 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44687 pmd->bl_info.value_type.size = sizeof(__le64);
44688 pmd->bl_info.value_type.inc = data_block_inc;
44689 pmd->bl_info.value_type.dec = data_block_dec;
44690 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44691 index 62c5136..aede7f1 100644
44692 --- a/drivers/md/dm.c
44693 +++ b/drivers/md/dm.c
44694 @@ -183,9 +183,9 @@ struct mapped_device {
44695 /*
44696 * Event handling.
44697 */
44698 - atomic_t event_nr;
44699 + atomic_unchecked_t event_nr;
44700 wait_queue_head_t eventq;
44701 - atomic_t uevent_seq;
44702 + atomic_unchecked_t uevent_seq;
44703 struct list_head uevent_list;
44704 spinlock_t uevent_lock; /* Protect access to uevent_list */
44705
44706 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44707 spin_lock_init(&md->deferred_lock);
44708 atomic_set(&md->holders, 1);
44709 atomic_set(&md->open_count, 0);
44710 - atomic_set(&md->event_nr, 0);
44711 - atomic_set(&md->uevent_seq, 0);
44712 + atomic_set_unchecked(&md->event_nr, 0);
44713 + atomic_set_unchecked(&md->uevent_seq, 0);
44714 INIT_LIST_HEAD(&md->uevent_list);
44715 INIT_LIST_HEAD(&md->table_devices);
44716 spin_lock_init(&md->uevent_lock);
44717 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44718
44719 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44720
44721 - atomic_inc(&md->event_nr);
44722 + atomic_inc_unchecked(&md->event_nr);
44723 wake_up(&md->eventq);
44724 }
44725
44726 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44727
44728 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44729 {
44730 - return atomic_add_return(1, &md->uevent_seq);
44731 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44732 }
44733
44734 uint32_t dm_get_event_nr(struct mapped_device *md)
44735 {
44736 - return atomic_read(&md->event_nr);
44737 + return atomic_read_unchecked(&md->event_nr);
44738 }
44739
44740 int dm_wait_event(struct mapped_device *md, int event_nr)
44741 {
44742 return wait_event_interruptible(md->eventq,
44743 - (event_nr != atomic_read(&md->event_nr)));
44744 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44745 }
44746
44747 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44748 diff --git a/drivers/md/md.c b/drivers/md/md.c
44749 index 9233c71..ed5243a 100644
44750 --- a/drivers/md/md.c
44751 +++ b/drivers/md/md.c
44752 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44753 * start build, activate spare
44754 */
44755 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44756 -static atomic_t md_event_count;
44757 +static atomic_unchecked_t md_event_count;
44758 void md_new_event(struct mddev *mddev)
44759 {
44760 - atomic_inc(&md_event_count);
44761 + atomic_inc_unchecked(&md_event_count);
44762 wake_up(&md_event_waiters);
44763 }
44764 EXPORT_SYMBOL_GPL(md_new_event);
44765 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44766 */
44767 static void md_new_event_inintr(struct mddev *mddev)
44768 {
44769 - atomic_inc(&md_event_count);
44770 + atomic_inc_unchecked(&md_event_count);
44771 wake_up(&md_event_waiters);
44772 }
44773
44774 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44775 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44776 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44777 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44778 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44779 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44780
44781 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44782 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44783 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44784 else
44785 sb->resync_offset = cpu_to_le64(0);
44786
44787 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44788 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44789
44790 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44791 sb->size = cpu_to_le64(mddev->dev_sectors);
44792 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44793 static ssize_t
44794 errors_show(struct md_rdev *rdev, char *page)
44795 {
44796 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44797 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44798 }
44799
44800 static ssize_t
44801 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44802 char *e;
44803 unsigned long n = simple_strtoul(buf, &e, 10);
44804 if (*buf && (*e == 0 || *e == '\n')) {
44805 - atomic_set(&rdev->corrected_errors, n);
44806 + atomic_set_unchecked(&rdev->corrected_errors, n);
44807 return len;
44808 }
44809 return -EINVAL;
44810 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44811 rdev->sb_loaded = 0;
44812 rdev->bb_page = NULL;
44813 atomic_set(&rdev->nr_pending, 0);
44814 - atomic_set(&rdev->read_errors, 0);
44815 - atomic_set(&rdev->corrected_errors, 0);
44816 + atomic_set_unchecked(&rdev->read_errors, 0);
44817 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44818
44819 INIT_LIST_HEAD(&rdev->same_set);
44820 init_waitqueue_head(&rdev->blocked_wait);
44821 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44822
44823 spin_unlock(&pers_lock);
44824 seq_printf(seq, "\n");
44825 - seq->poll_event = atomic_read(&md_event_count);
44826 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44827 return 0;
44828 }
44829 if (v == (void*)2) {
44830 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44831 return error;
44832
44833 seq = file->private_data;
44834 - seq->poll_event = atomic_read(&md_event_count);
44835 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44836 return error;
44837 }
44838
44839 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44840 /* always allow read */
44841 mask = POLLIN | POLLRDNORM;
44842
44843 - if (seq->poll_event != atomic_read(&md_event_count))
44844 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44845 mask |= POLLERR | POLLPRI;
44846 return mask;
44847 }
44848 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44849 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44850 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44851 (int)part_stat_read(&disk->part0, sectors[1]) -
44852 - atomic_read(&disk->sync_io);
44853 + atomic_read_unchecked(&disk->sync_io);
44854 /* sync IO will cause sync_io to increase before the disk_stats
44855 * as sync_io is counted when a request starts, and
44856 * disk_stats is counted when it completes.
44857 diff --git a/drivers/md/md.h b/drivers/md/md.h
44858 index 03cec5b..0a658c1 100644
44859 --- a/drivers/md/md.h
44860 +++ b/drivers/md/md.h
44861 @@ -94,13 +94,13 @@ struct md_rdev {
44862 * only maintained for arrays that
44863 * support hot removal
44864 */
44865 - atomic_t read_errors; /* number of consecutive read errors that
44866 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44867 * we have tried to ignore.
44868 */
44869 struct timespec last_read_error; /* monotonic time since our
44870 * last read error
44871 */
44872 - atomic_t corrected_errors; /* number of corrected read errors,
44873 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44874 * for reporting to userspace and storing
44875 * in superblock.
44876 */
44877 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44878
44879 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44880 {
44881 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44882 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44883 }
44884
44885 struct md_personality
44886 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44887 index f4e22bc..8f83114 100644
44888 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44889 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44890 @@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44891 * Flick into a mode where all blocks get allocated in the new area.
44892 */
44893 smm->begin = old_len;
44894 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44895 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44896
44897 /*
44898 * Extend.
44899 @@ -712,7 +712,7 @@ out:
44900 /*
44901 * Switch back to normal behaviour.
44902 */
44903 - memcpy(sm, &ops, sizeof(*sm));
44904 + memcpy((void *)sm, &ops, sizeof(*sm));
44905 return r;
44906 }
44907
44908 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44909 index 3e6d115..ffecdeb 100644
44910 --- a/drivers/md/persistent-data/dm-space-map.h
44911 +++ b/drivers/md/persistent-data/dm-space-map.h
44912 @@ -71,6 +71,7 @@ struct dm_space_map {
44913 dm_sm_threshold_fn fn,
44914 void *context);
44915 };
44916 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44917
44918 /*----------------------------------------------------------------*/
44919
44920 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44921 index 40b35be..a327e11 100644
44922 --- a/drivers/md/raid1.c
44923 +++ b/drivers/md/raid1.c
44924 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44925 if (r1_sync_page_io(rdev, sect, s,
44926 bio->bi_io_vec[idx].bv_page,
44927 READ) != 0)
44928 - atomic_add(s, &rdev->corrected_errors);
44929 + atomic_add_unchecked(s, &rdev->corrected_errors);
44930 }
44931 sectors -= s;
44932 sect += s;
44933 @@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44934 !test_bit(Faulty, &rdev->flags)) {
44935 if (r1_sync_page_io(rdev, sect, s,
44936 conf->tmppage, READ)) {
44937 - atomic_add(s, &rdev->corrected_errors);
44938 + atomic_add_unchecked(s, &rdev->corrected_errors);
44939 printk(KERN_INFO
44940 "md/raid1:%s: read error corrected "
44941 "(%d sectors at %llu on %s)\n",
44942 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44943 index 32e282f..5cec803 100644
44944 --- a/drivers/md/raid10.c
44945 +++ b/drivers/md/raid10.c
44946 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44947 /* The write handler will notice the lack of
44948 * R10BIO_Uptodate and record any errors etc
44949 */
44950 - atomic_add(r10_bio->sectors,
44951 + atomic_add_unchecked(r10_bio->sectors,
44952 &conf->mirrors[d].rdev->corrected_errors);
44953
44954 /* for reconstruct, we always reschedule after a read.
44955 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44956 {
44957 struct timespec cur_time_mon;
44958 unsigned long hours_since_last;
44959 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44960 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44961
44962 ktime_get_ts(&cur_time_mon);
44963
44964 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44965 * overflowing the shift of read_errors by hours_since_last.
44966 */
44967 if (hours_since_last >= 8 * sizeof(read_errors))
44968 - atomic_set(&rdev->read_errors, 0);
44969 + atomic_set_unchecked(&rdev->read_errors, 0);
44970 else
44971 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44972 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44973 }
44974
44975 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44976 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44977 return;
44978
44979 check_decay_read_errors(mddev, rdev);
44980 - atomic_inc(&rdev->read_errors);
44981 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44982 + atomic_inc_unchecked(&rdev->read_errors);
44983 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44984 char b[BDEVNAME_SIZE];
44985 bdevname(rdev->bdev, b);
44986
44987 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44988 "md/raid10:%s: %s: Raid device exceeded "
44989 "read_error threshold [cur %d:max %d]\n",
44990 mdname(mddev), b,
44991 - atomic_read(&rdev->read_errors), max_read_errors);
44992 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44993 printk(KERN_NOTICE
44994 "md/raid10:%s: %s: Failing raid device\n",
44995 mdname(mddev), b);
44996 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44997 sect +
44998 choose_data_offset(r10_bio, rdev)),
44999 bdevname(rdev->bdev, b));
45000 - atomic_add(s, &rdev->corrected_errors);
45001 + atomic_add_unchecked(s, &rdev->corrected_errors);
45002 }
45003
45004 rdev_dec_pending(rdev, mddev);
45005 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45006 index c1b0d52..07a0a5d 100644
45007 --- a/drivers/md/raid5.c
45008 +++ b/drivers/md/raid5.c
45009 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45010 return 1;
45011 }
45012
45013 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45014 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45015 +#endif
45016 +
45017 static int grow_stripes(struct r5conf *conf, int num)
45018 {
45019 struct kmem_cache *sc;
45020 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45021 "raid%d-%s", conf->level, mdname(conf->mddev));
45022 else
45023 sprintf(conf->cache_name[0],
45024 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45025 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45026 +#else
45027 "raid%d-%p", conf->level, conf->mddev);
45028 +#endif
45029 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45030
45031 conf->active_name = 0;
45032 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45033 mdname(conf->mddev), STRIPE_SECTORS,
45034 (unsigned long long)s,
45035 bdevname(rdev->bdev, b));
45036 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45037 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45038 clear_bit(R5_ReadError, &sh->dev[i].flags);
45039 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45040 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45041 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45042
45043 - if (atomic_read(&rdev->read_errors))
45044 - atomic_set(&rdev->read_errors, 0);
45045 + if (atomic_read_unchecked(&rdev->read_errors))
45046 + atomic_set_unchecked(&rdev->read_errors, 0);
45047 } else {
45048 const char *bdn = bdevname(rdev->bdev, b);
45049 int retry = 0;
45050 int set_bad = 0;
45051
45052 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45053 - atomic_inc(&rdev->read_errors);
45054 + atomic_inc_unchecked(&rdev->read_errors);
45055 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45056 printk_ratelimited(
45057 KERN_WARNING
45058 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45059 mdname(conf->mddev),
45060 (unsigned long long)s,
45061 bdn);
45062 - } else if (atomic_read(&rdev->read_errors)
45063 + } else if (atomic_read_unchecked(&rdev->read_errors)
45064 > conf->max_nr_stripes)
45065 printk(KERN_WARNING
45066 "md/raid:%s: Too many read errors, failing device %s.\n",
45067 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45068 index 983db75..ef9248c 100644
45069 --- a/drivers/media/dvb-core/dvbdev.c
45070 +++ b/drivers/media/dvb-core/dvbdev.c
45071 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45072 const struct dvb_device *template, void *priv, int type)
45073 {
45074 struct dvb_device *dvbdev;
45075 - struct file_operations *dvbdevfops;
45076 + file_operations_no_const *dvbdevfops;
45077 struct device *clsdev;
45078 int minor;
45079 int id;
45080 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45081 index 6ad22b6..6e90e2a 100644
45082 --- a/drivers/media/dvb-frontends/af9033.h
45083 +++ b/drivers/media/dvb-frontends/af9033.h
45084 @@ -96,6 +96,6 @@ struct af9033_ops {
45085 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45086 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45087 int onoff);
45088 -};
45089 +} __no_const;
45090
45091 #endif /* AF9033_H */
45092 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45093 index 9b6c3bb..baeb5c7 100644
45094 --- a/drivers/media/dvb-frontends/dib3000.h
45095 +++ b/drivers/media/dvb-frontends/dib3000.h
45096 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45097 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45098 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45099 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45100 -};
45101 +} __no_const;
45102
45103 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45104 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45105 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45106 index 1fea0e9..321ce8f 100644
45107 --- a/drivers/media/dvb-frontends/dib7000p.h
45108 +++ b/drivers/media/dvb-frontends/dib7000p.h
45109 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45110 int (*get_adc_power)(struct dvb_frontend *fe);
45111 int (*slave_reset)(struct dvb_frontend *fe);
45112 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45113 -};
45114 +} __no_const;
45115
45116 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45117 void *dib7000p_attach(struct dib7000p_ops *ops);
45118 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45119 index 84cc103..5780c54 100644
45120 --- a/drivers/media/dvb-frontends/dib8000.h
45121 +++ b/drivers/media/dvb-frontends/dib8000.h
45122 @@ -61,7 +61,7 @@ struct dib8000_ops {
45123 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45124 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45125 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45126 -};
45127 +} __no_const;
45128
45129 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45130 void *dib8000_attach(struct dib8000_ops *ops);
45131 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45132 index ce27e6d..b70435a 100644
45133 --- a/drivers/media/pci/cx88/cx88-video.c
45134 +++ b/drivers/media/pci/cx88/cx88-video.c
45135 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45136
45137 /* ------------------------------------------------------------------ */
45138
45139 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45140 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45141 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45142 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45143 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45144 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45145
45146 module_param_array(video_nr, int, NULL, 0444);
45147 module_param_array(vbi_nr, int, NULL, 0444);
45148 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45149 index 802642d..5534900 100644
45150 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45151 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45152 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45153 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45154
45155 /* ivtv instance counter */
45156 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45157 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45158
45159 /* Parameter declarations */
45160 static int cardtype[IVTV_MAX_CARDS];
45161 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45162 index 8cbe6b4..ea3601c 100644
45163 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45164 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45165 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45166
45167 static int solo_sysfs_init(struct solo_dev *solo_dev)
45168 {
45169 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45170 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45171 struct device *dev = &solo_dev->dev;
45172 const char *driver;
45173 int i;
45174 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45175 index c7141f2..5301fec 100644
45176 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45177 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45178 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45179
45180 int solo_g723_init(struct solo_dev *solo_dev)
45181 {
45182 - static struct snd_device_ops ops = { NULL };
45183 + static struct snd_device_ops ops = { };
45184 struct snd_card *card;
45185 struct snd_kcontrol_new kctl;
45186 char name[32];
45187 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45188 index 8c84846..27b4f83 100644
45189 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45190 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45191 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45192
45193 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45194 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45195 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45196 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45197 if (p2m_id < 0)
45198 p2m_id = -p2m_id;
45199 }
45200 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45201 index 72017b7..dd37ae6 100644
45202 --- a/drivers/media/pci/solo6x10/solo6x10.h
45203 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45204 @@ -219,7 +219,7 @@ struct solo_dev {
45205
45206 /* P2M DMA Engine */
45207 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45208 - atomic_t p2m_count;
45209 + atomic_unchecked_t p2m_count;
45210 int p2m_jiffies;
45211 unsigned int p2m_timeouts;
45212
45213 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45214 index 63f0b64..a017c1c 100644
45215 --- a/drivers/media/pci/tw68/tw68-core.c
45216 +++ b/drivers/media/pci/tw68/tw68-core.c
45217 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45218 module_param_array(card, int, NULL, 0444);
45219 MODULE_PARM_DESC(card, "card type");
45220
45221 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45222 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45223
45224 /* ------------------------------------------------------------------ */
45225
45226 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45227 index 64ab6fb..ef4a8b9 100644
45228 --- a/drivers/media/platform/omap/omap_vout.c
45229 +++ b/drivers/media/platform/omap/omap_vout.c
45230 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45231 OMAP_VIDEO2,
45232 };
45233
45234 -static struct videobuf_queue_ops video_vbq_ops;
45235 /* Variables configurable through module params*/
45236 static u32 video1_numbuffers = 3;
45237 static u32 video2_numbuffers = 3;
45238 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45239 {
45240 struct videobuf_queue *q;
45241 struct omap_vout_device *vout = NULL;
45242 + static struct videobuf_queue_ops video_vbq_ops = {
45243 + .buf_setup = omap_vout_buffer_setup,
45244 + .buf_prepare = omap_vout_buffer_prepare,
45245 + .buf_release = omap_vout_buffer_release,
45246 + .buf_queue = omap_vout_buffer_queue,
45247 + };
45248
45249 vout = video_drvdata(file);
45250 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45251 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45252 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45253
45254 q = &vout->vbq;
45255 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45256 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45257 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45258 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45259 spin_lock_init(&vout->vbq_lock);
45260
45261 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45262 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45263 index fb2acc5..a2fcbdc4 100644
45264 --- a/drivers/media/platform/s5p-tv/mixer.h
45265 +++ b/drivers/media/platform/s5p-tv/mixer.h
45266 @@ -156,7 +156,7 @@ struct mxr_layer {
45267 /** layer index (unique identifier) */
45268 int idx;
45269 /** callbacks for layer methods */
45270 - struct mxr_layer_ops ops;
45271 + struct mxr_layer_ops *ops;
45272 /** format array */
45273 const struct mxr_format **fmt_array;
45274 /** size of format array */
45275 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45276 index 74344c7..a39e70e 100644
45277 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45278 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45279 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45280 {
45281 struct mxr_layer *layer;
45282 int ret;
45283 - struct mxr_layer_ops ops = {
45284 + static struct mxr_layer_ops ops = {
45285 .release = mxr_graph_layer_release,
45286 .buffer_set = mxr_graph_buffer_set,
45287 .stream_set = mxr_graph_stream_set,
45288 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45289 index b713403..53cb5ad 100644
45290 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45291 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45292 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45293 layer->update_buf = next;
45294 }
45295
45296 - layer->ops.buffer_set(layer, layer->update_buf);
45297 + layer->ops->buffer_set(layer, layer->update_buf);
45298
45299 if (done && done != layer->shadow_buf)
45300 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45301 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45302 index b4d2696..91df48e 100644
45303 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45304 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45305 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45306 layer->geo.src.height = layer->geo.src.full_height;
45307
45308 mxr_geometry_dump(mdev, &layer->geo);
45309 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45310 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45311 mxr_geometry_dump(mdev, &layer->geo);
45312 }
45313
45314 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45315 layer->geo.dst.full_width = mbus_fmt.width;
45316 layer->geo.dst.full_height = mbus_fmt.height;
45317 layer->geo.dst.field = mbus_fmt.field;
45318 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45319 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45320
45321 mxr_geometry_dump(mdev, &layer->geo);
45322 }
45323 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45324 /* set source size to highest accepted value */
45325 geo->src.full_width = max(geo->dst.full_width, pix->width);
45326 geo->src.full_height = max(geo->dst.full_height, pix->height);
45327 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45328 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45329 mxr_geometry_dump(mdev, &layer->geo);
45330 /* set cropping to total visible screen */
45331 geo->src.width = pix->width;
45332 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45333 geo->src.x_offset = 0;
45334 geo->src.y_offset = 0;
45335 /* assure consistency of geometry */
45336 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45337 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45338 mxr_geometry_dump(mdev, &layer->geo);
45339 /* set full size to lowest possible value */
45340 geo->src.full_width = 0;
45341 geo->src.full_height = 0;
45342 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45343 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45344 mxr_geometry_dump(mdev, &layer->geo);
45345
45346 /* returning results */
45347 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45348 target->width = s->r.width;
45349 target->height = s->r.height;
45350
45351 - layer->ops.fix_geometry(layer, stage, s->flags);
45352 + layer->ops->fix_geometry(layer, stage, s->flags);
45353
45354 /* retrieve update selection rectangle */
45355 res.left = target->x_offset;
45356 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45357 mxr_output_get(mdev);
45358
45359 mxr_layer_update_output(layer);
45360 - layer->ops.format_set(layer);
45361 + layer->ops->format_set(layer);
45362 /* enabling layer in hardware */
45363 spin_lock_irqsave(&layer->enq_slock, flags);
45364 layer->state = MXR_LAYER_STREAMING;
45365 spin_unlock_irqrestore(&layer->enq_slock, flags);
45366
45367 - layer->ops.stream_set(layer, MXR_ENABLE);
45368 + layer->ops->stream_set(layer, MXR_ENABLE);
45369 mxr_streamer_get(mdev);
45370
45371 return 0;
45372 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45373 spin_unlock_irqrestore(&layer->enq_slock, flags);
45374
45375 /* disabling layer in hardware */
45376 - layer->ops.stream_set(layer, MXR_DISABLE);
45377 + layer->ops->stream_set(layer, MXR_DISABLE);
45378 /* remove one streamer */
45379 mxr_streamer_put(mdev);
45380 /* allow changes in output configuration */
45381 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45382
45383 void mxr_layer_release(struct mxr_layer *layer)
45384 {
45385 - if (layer->ops.release)
45386 - layer->ops.release(layer);
45387 + if (layer->ops->release)
45388 + layer->ops->release(layer);
45389 }
45390
45391 void mxr_base_layer_release(struct mxr_layer *layer)
45392 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45393
45394 layer->mdev = mdev;
45395 layer->idx = idx;
45396 - layer->ops = *ops;
45397 + layer->ops = ops;
45398
45399 spin_lock_init(&layer->enq_slock);
45400 INIT_LIST_HEAD(&layer->enq_list);
45401 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45402 index c9388c4..ce71ece 100644
45403 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45404 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45405 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45406 {
45407 struct mxr_layer *layer;
45408 int ret;
45409 - struct mxr_layer_ops ops = {
45410 + static struct mxr_layer_ops ops = {
45411 .release = mxr_vp_layer_release,
45412 .buffer_set = mxr_vp_buffer_set,
45413 .stream_set = mxr_vp_stream_set,
45414 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45415 index 82affae..42833ec 100644
45416 --- a/drivers/media/radio/radio-cadet.c
45417 +++ b/drivers/media/radio/radio-cadet.c
45418 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45419 unsigned char readbuf[RDS_BUFFER];
45420 int i = 0;
45421
45422 + if (count > RDS_BUFFER)
45423 + return -EFAULT;
45424 mutex_lock(&dev->lock);
45425 if (dev->rdsstat == 0)
45426 cadet_start_rds(dev);
45427 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45428 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45429 mutex_unlock(&dev->lock);
45430
45431 - if (i && copy_to_user(data, readbuf, i))
45432 - return -EFAULT;
45433 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45434 + i = -EFAULT;
45435 +
45436 return i;
45437 }
45438
45439 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45440 index 5236035..c622c74 100644
45441 --- a/drivers/media/radio/radio-maxiradio.c
45442 +++ b/drivers/media/radio/radio-maxiradio.c
45443 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45444 /* TEA5757 pin mappings */
45445 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45446
45447 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45448 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45449
45450 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45451 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45452 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45453 index 050b3bb..79f62b9 100644
45454 --- a/drivers/media/radio/radio-shark.c
45455 +++ b/drivers/media/radio/radio-shark.c
45456 @@ -79,7 +79,7 @@ struct shark_device {
45457 u32 last_val;
45458 };
45459
45460 -static atomic_t shark_instance = ATOMIC_INIT(0);
45461 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45462
45463 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45464 {
45465 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45466 index 8654e0d..0608a64 100644
45467 --- a/drivers/media/radio/radio-shark2.c
45468 +++ b/drivers/media/radio/radio-shark2.c
45469 @@ -74,7 +74,7 @@ struct shark_device {
45470 u8 *transfer_buffer;
45471 };
45472
45473 -static atomic_t shark_instance = ATOMIC_INIT(0);
45474 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45475
45476 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45477 {
45478 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45479 index 633022b..7f10754 100644
45480 --- a/drivers/media/radio/radio-si476x.c
45481 +++ b/drivers/media/radio/radio-si476x.c
45482 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45483 struct si476x_radio *radio;
45484 struct v4l2_ctrl *ctrl;
45485
45486 - static atomic_t instance = ATOMIC_INIT(0);
45487 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45488
45489 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45490 if (!radio)
45491 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45492 index 9fd1527..8927230 100644
45493 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45494 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45495 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45496
45497 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45498 {
45499 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45500 - char result[64];
45501 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45502 - sizeof(result), 0);
45503 + char *buf;
45504 + char *result;
45505 + int retval;
45506 +
45507 + buf = kmalloc(2, GFP_KERNEL);
45508 + if (buf == NULL)
45509 + return -ENOMEM;
45510 + result = kmalloc(64, GFP_KERNEL);
45511 + if (result == NULL) {
45512 + kfree(buf);
45513 + return -ENOMEM;
45514 + }
45515 +
45516 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45517 + buf[1] = enable ? 1 : 0;
45518 +
45519 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45520 +
45521 + kfree(buf);
45522 + kfree(result);
45523 + return retval;
45524 }
45525
45526 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45527 {
45528 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45529 - char state[3];
45530 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45531 + char *buf;
45532 + char *state;
45533 + int retval;
45534 +
45535 + buf = kmalloc(2, GFP_KERNEL);
45536 + if (buf == NULL)
45537 + return -ENOMEM;
45538 + state = kmalloc(3, GFP_KERNEL);
45539 + if (state == NULL) {
45540 + kfree(buf);
45541 + return -ENOMEM;
45542 + }
45543 +
45544 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45545 + buf[1] = enable ? 1 : 0;
45546 +
45547 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45548 +
45549 + kfree(buf);
45550 + kfree(state);
45551 + return retval;
45552 }
45553
45554 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45555 {
45556 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45557 - char state[3];
45558 + char *query;
45559 + char *state;
45560 int ret;
45561 + query = kmalloc(1, GFP_KERNEL);
45562 + if (query == NULL)
45563 + return -ENOMEM;
45564 + state = kmalloc(3, GFP_KERNEL);
45565 + if (state == NULL) {
45566 + kfree(query);
45567 + return -ENOMEM;
45568 + }
45569 +
45570 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45571
45572 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45573
45574 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45575 - sizeof(state), 0);
45576 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45577 if (ret < 0) {
45578 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45579 "state info\n");
45580 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45581
45582 /* Copy this pointer as we are gonna need it in the release phase */
45583 cinergyt2_usb_device = adap->dev;
45584 -
45585 + kfree(query);
45586 + kfree(state);
45587 return 0;
45588 }
45589
45590 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45591 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45592 {
45593 struct cinergyt2_state *st = d->priv;
45594 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45595 + u8 *key, *cmd;
45596 int i;
45597
45598 + cmd = kmalloc(1, GFP_KERNEL);
45599 + if (cmd == NULL)
45600 + return -EINVAL;
45601 + key = kzalloc(5, GFP_KERNEL);
45602 + if (key == NULL) {
45603 + kfree(cmd);
45604 + return -EINVAL;
45605 + }
45606 +
45607 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45608 +
45609 *state = REMOTE_NO_KEY_PRESSED;
45610
45611 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45612 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45613 if (key[4] == 0xff) {
45614 /* key repeat */
45615 st->rc_counter++;
45616 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45617 *event = d->last_event;
45618 deb_rc("repeat key, event %x\n",
45619 *event);
45620 - return 0;
45621 + goto out;
45622 }
45623 }
45624 deb_rc("repeated key (non repeatable)\n");
45625 }
45626 - return 0;
45627 + goto out;
45628 }
45629
45630 /* hack to pass checksum on the custom field */
45631 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45632
45633 deb_rc("key: %*ph\n", 5, key);
45634 }
45635 +out:
45636 + kfree(cmd);
45637 + kfree(key);
45638 return 0;
45639 }
45640
45641 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45642 index c890fe4..f9b2ae6 100644
45643 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45644 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45645 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45646 fe_status_t *status)
45647 {
45648 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45649 - struct dvbt_get_status_msg result;
45650 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45651 + struct dvbt_get_status_msg *result;
45652 + u8 *cmd;
45653 int ret;
45654
45655 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45656 - sizeof(result), 0);
45657 + cmd = kmalloc(1, GFP_KERNEL);
45658 + if (cmd == NULL)
45659 + return -ENOMEM;
45660 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45661 + if (result == NULL) {
45662 + kfree(cmd);
45663 + return -ENOMEM;
45664 + }
45665 +
45666 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45667 +
45668 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45669 + sizeof(*result), 0);
45670 if (ret < 0)
45671 - return ret;
45672 + goto out;
45673
45674 *status = 0;
45675
45676 - if (0xffff - le16_to_cpu(result.gain) > 30)
45677 + if (0xffff - le16_to_cpu(result->gain) > 30)
45678 *status |= FE_HAS_SIGNAL;
45679 - if (result.lock_bits & (1 << 6))
45680 + if (result->lock_bits & (1 << 6))
45681 *status |= FE_HAS_LOCK;
45682 - if (result.lock_bits & (1 << 5))
45683 + if (result->lock_bits & (1 << 5))
45684 *status |= FE_HAS_SYNC;
45685 - if (result.lock_bits & (1 << 4))
45686 + if (result->lock_bits & (1 << 4))
45687 *status |= FE_HAS_CARRIER;
45688 - if (result.lock_bits & (1 << 1))
45689 + if (result->lock_bits & (1 << 1))
45690 *status |= FE_HAS_VITERBI;
45691
45692 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45693 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45694 *status &= ~FE_HAS_LOCK;
45695
45696 - return 0;
45697 +out:
45698 + kfree(cmd);
45699 + kfree(result);
45700 + return ret;
45701 }
45702
45703 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45704 {
45705 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45706 - struct dvbt_get_status_msg status;
45707 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45708 + struct dvbt_get_status_msg *status;
45709 + char *cmd;
45710 int ret;
45711
45712 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45713 - sizeof(status), 0);
45714 + cmd = kmalloc(1, GFP_KERNEL);
45715 + if (cmd == NULL)
45716 + return -ENOMEM;
45717 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45718 + if (status == NULL) {
45719 + kfree(cmd);
45720 + return -ENOMEM;
45721 + }
45722 +
45723 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45724 +
45725 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45726 + sizeof(*status), 0);
45727 if (ret < 0)
45728 - return ret;
45729 + goto out;
45730
45731 - *ber = le32_to_cpu(status.viterbi_error_rate);
45732 + *ber = le32_to_cpu(status->viterbi_error_rate);
45733 +out:
45734 + kfree(cmd);
45735 + kfree(status);
45736 return 0;
45737 }
45738
45739 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45740 {
45741 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45742 - struct dvbt_get_status_msg status;
45743 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45744 + struct dvbt_get_status_msg *status;
45745 + u8 *cmd;
45746 int ret;
45747
45748 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45749 - sizeof(status), 0);
45750 + cmd = kmalloc(1, GFP_KERNEL);
45751 + if (cmd == NULL)
45752 + return -ENOMEM;
45753 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45754 + if (status == NULL) {
45755 + kfree(cmd);
45756 + return -ENOMEM;
45757 + }
45758 +
45759 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45760 +
45761 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45762 + sizeof(*status), 0);
45763 if (ret < 0) {
45764 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45765 ret);
45766 - return ret;
45767 + goto out;
45768 }
45769 - *unc = le32_to_cpu(status.uncorrected_block_count);
45770 - return 0;
45771 + *unc = le32_to_cpu(status->uncorrected_block_count);
45772 +
45773 +out:
45774 + kfree(cmd);
45775 + kfree(status);
45776 + return ret;
45777 }
45778
45779 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45780 u16 *strength)
45781 {
45782 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45783 - struct dvbt_get_status_msg status;
45784 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45785 + struct dvbt_get_status_msg *status;
45786 + char *cmd;
45787 int ret;
45788
45789 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45790 - sizeof(status), 0);
45791 + cmd = kmalloc(1, GFP_KERNEL);
45792 + if (cmd == NULL)
45793 + return -ENOMEM;
45794 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45795 + if (status == NULL) {
45796 + kfree(cmd);
45797 + return -ENOMEM;
45798 + }
45799 +
45800 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45801 +
45802 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45803 + sizeof(*status), 0);
45804 if (ret < 0) {
45805 err("cinergyt2_fe_read_signal_strength() Failed!"
45806 " (Error=%d)\n", ret);
45807 - return ret;
45808 + goto out;
45809 }
45810 - *strength = (0xffff - le16_to_cpu(status.gain));
45811 + *strength = (0xffff - le16_to_cpu(status->gain));
45812 +
45813 +out:
45814 + kfree(cmd);
45815 + kfree(status);
45816 return 0;
45817 }
45818
45819 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45820 {
45821 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45822 - struct dvbt_get_status_msg status;
45823 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45824 + struct dvbt_get_status_msg *status;
45825 + char *cmd;
45826 int ret;
45827
45828 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45829 - sizeof(status), 0);
45830 + cmd = kmalloc(1, GFP_KERNEL);
45831 + if (cmd == NULL)
45832 + return -ENOMEM;
45833 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45834 + if (status == NULL) {
45835 + kfree(cmd);
45836 + return -ENOMEM;
45837 + }
45838 +
45839 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45840 +
45841 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45842 + sizeof(*status), 0);
45843 if (ret < 0) {
45844 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45845 - return ret;
45846 + goto out;
45847 }
45848 - *snr = (status.snr << 8) | status.snr;
45849 - return 0;
45850 + *snr = (status->snr << 8) | status->snr;
45851 +
45852 +out:
45853 + kfree(cmd);
45854 + kfree(status);
45855 + return ret;
45856 }
45857
45858 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45859 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45860 {
45861 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45862 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45863 - struct dvbt_set_parameters_msg param;
45864 - char result[2];
45865 + struct dvbt_set_parameters_msg *param;
45866 + char *result;
45867 int err;
45868
45869 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45870 - param.tps = cpu_to_le16(compute_tps(fep));
45871 - param.freq = cpu_to_le32(fep->frequency / 1000);
45872 - param.flags = 0;
45873 + result = kmalloc(2, GFP_KERNEL);
45874 + if (result == NULL)
45875 + return -ENOMEM;
45876 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45877 + if (param == NULL) {
45878 + kfree(result);
45879 + return -ENOMEM;
45880 + }
45881 +
45882 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45883 + param->tps = cpu_to_le16(compute_tps(fep));
45884 + param->freq = cpu_to_le32(fep->frequency / 1000);
45885 + param->flags = 0;
45886
45887 switch (fep->bandwidth_hz) {
45888 default:
45889 case 8000000:
45890 - param.bandwidth = 8;
45891 + param->bandwidth = 8;
45892 break;
45893 case 7000000:
45894 - param.bandwidth = 7;
45895 + param->bandwidth = 7;
45896 break;
45897 case 6000000:
45898 - param.bandwidth = 6;
45899 + param->bandwidth = 6;
45900 break;
45901 }
45902
45903 err = dvb_usb_generic_rw(state->d,
45904 - (char *)&param, sizeof(param),
45905 - result, sizeof(result), 0);
45906 + (char *)param, sizeof(*param),
45907 + result, 2, 0);
45908 if (err < 0)
45909 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45910
45911 - return (err < 0) ? err : 0;
45912 + kfree(result);
45913 + kfree(param);
45914 + return err;
45915 }
45916
45917 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45918 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45919 index 733a7ff..f8b52e3 100644
45920 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45921 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45922 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45923
45924 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45925 {
45926 - struct hexline hx;
45927 - u8 reset;
45928 + struct hexline *hx;
45929 + u8 *reset;
45930 int ret,pos=0;
45931
45932 + reset = kmalloc(1, GFP_KERNEL);
45933 + if (reset == NULL)
45934 + return -ENOMEM;
45935 +
45936 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45937 + if (hx == NULL) {
45938 + kfree(reset);
45939 + return -ENOMEM;
45940 + }
45941 +
45942 /* stop the CPU */
45943 - reset = 1;
45944 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45945 + reset[0] = 1;
45946 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45947 err("could not stop the USB controller CPU.");
45948
45949 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45950 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45951 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45952 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45953 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45954 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45955
45956 - if (ret != hx.len) {
45957 + if (ret != hx->len) {
45958 err("error while transferring firmware "
45959 "(transferred size: %d, block size: %d)",
45960 - ret,hx.len);
45961 + ret,hx->len);
45962 ret = -EINVAL;
45963 break;
45964 }
45965 }
45966 if (ret < 0) {
45967 err("firmware download failed at %d with %d",pos,ret);
45968 + kfree(reset);
45969 + kfree(hx);
45970 return ret;
45971 }
45972
45973 if (ret == 0) {
45974 /* restart the CPU */
45975 - reset = 0;
45976 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45977 + reset[0] = 0;
45978 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45979 err("could not restart the USB controller CPU.");
45980 ret = -EINVAL;
45981 }
45982 } else
45983 ret = -EIO;
45984
45985 + kfree(reset);
45986 + kfree(hx);
45987 +
45988 return ret;
45989 }
45990 EXPORT_SYMBOL(usb_cypress_load_firmware);
45991 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45992 index 1a3df10..57997a5 100644
45993 --- a/drivers/media/usb/dvb-usb/dw2102.c
45994 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45995 @@ -118,7 +118,7 @@ struct su3000_state {
45996
45997 struct s6x0_state {
45998 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45999 -};
46000 +} __no_const;
46001
46002 /* debug */
46003 static int dvb_usb_dw2102_debug;
46004 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46005 index 6b0b8b6b..4038398 100644
46006 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46007 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46008 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46009 static int technisat_usb2_i2c_access(struct usb_device *udev,
46010 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46011 {
46012 - u8 b[64];
46013 - int ret, actual_length;
46014 + u8 *b = kmalloc(64, GFP_KERNEL);
46015 + int ret, actual_length, error = 0;
46016 +
46017 + if (b == NULL)
46018 + return -ENOMEM;
46019
46020 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46021 debug_dump(tx, txlen, deb_i2c);
46022 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46023
46024 if (ret < 0) {
46025 err("i2c-error: out failed %02x = %d", device_addr, ret);
46026 - return -ENODEV;
46027 + error = -ENODEV;
46028 + goto out;
46029 }
46030
46031 ret = usb_bulk_msg(udev,
46032 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46033 b, 64, &actual_length, 1000);
46034 if (ret < 0) {
46035 err("i2c-error: in failed %02x = %d", device_addr, ret);
46036 - return -ENODEV;
46037 + error = -ENODEV;
46038 + goto out;
46039 }
46040
46041 if (b[0] != I2C_STATUS_OK) {
46042 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46043 /* handle tuner-i2c-nak */
46044 if (!(b[0] == I2C_STATUS_NAK &&
46045 device_addr == 0x60
46046 - /* && device_is_technisat_usb2 */))
46047 - return -ENODEV;
46048 + /* && device_is_technisat_usb2 */)) {
46049 + error = -ENODEV;
46050 + goto out;
46051 + }
46052 }
46053
46054 deb_i2c("status: %d, ", b[0]);
46055 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46056
46057 deb_i2c("\n");
46058
46059 - return 0;
46060 +out:
46061 + kfree(b);
46062 + return error;
46063 }
46064
46065 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46066 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46067 {
46068 int ret;
46069
46070 - u8 led[8] = {
46071 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46072 - 0
46073 - };
46074 + u8 *led = kzalloc(8, GFP_KERNEL);
46075 +
46076 + if (led == NULL)
46077 + return -ENOMEM;
46078
46079 if (disable_led_control && state != TECH_LED_OFF)
46080 return 0;
46081
46082 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46083 +
46084 switch (state) {
46085 case TECH_LED_ON:
46086 led[1] = 0x82;
46087 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46088 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46089 USB_TYPE_VENDOR | USB_DIR_OUT,
46090 0, 0,
46091 - led, sizeof(led), 500);
46092 + led, 8, 500);
46093
46094 mutex_unlock(&d->i2c_mutex);
46095 +
46096 + kfree(led);
46097 +
46098 return ret;
46099 }
46100
46101 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46102 {
46103 int ret;
46104 - u8 b = 0;
46105 + u8 *b = kzalloc(1, GFP_KERNEL);
46106 +
46107 + if (b == NULL)
46108 + return -ENOMEM;
46109
46110 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46111 return -EAGAIN;
46112 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46113 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46114 USB_TYPE_VENDOR | USB_DIR_OUT,
46115 (red << 8) | green, 0,
46116 - &b, 1, 500);
46117 + b, 1, 500);
46118
46119 mutex_unlock(&d->i2c_mutex);
46120
46121 + kfree(b);
46122 +
46123 return ret;
46124 }
46125
46126 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46127 struct dvb_usb_device_description **desc, int *cold)
46128 {
46129 int ret;
46130 - u8 version[3];
46131 + u8 *version = kmalloc(3, GFP_KERNEL);
46132
46133 /* first select the interface */
46134 if (usb_set_interface(udev, 0, 1) != 0)
46135 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46136
46137 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46138
46139 + if (version == NULL)
46140 + return 0;
46141 +
46142 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46143 GET_VERSION_INFO_VENDOR_REQUEST,
46144 USB_TYPE_VENDOR | USB_DIR_IN,
46145 0, 0,
46146 - version, sizeof(version), 500);
46147 + version, 3, 500);
46148
46149 if (ret < 0)
46150 *cold = 1;
46151 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46152 *cold = 0;
46153 }
46154
46155 + kfree(version);
46156 +
46157 return 0;
46158 }
46159
46160 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46161
46162 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46163 {
46164 - u8 buf[62], *b;
46165 + u8 *buf, *b;
46166 int ret;
46167 struct ir_raw_event ev;
46168
46169 + buf = kmalloc(62, GFP_KERNEL);
46170 +
46171 + if (buf == NULL)
46172 + return -ENOMEM;
46173 +
46174 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46175 buf[1] = 0x08;
46176 buf[2] = 0x8f;
46177 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46178 GET_IR_DATA_VENDOR_REQUEST,
46179 USB_TYPE_VENDOR | USB_DIR_IN,
46180 0x8080, 0,
46181 - buf, sizeof(buf), 500);
46182 + buf, 62, 500);
46183
46184 unlock:
46185 mutex_unlock(&d->i2c_mutex);
46186
46187 - if (ret < 0)
46188 + if (ret < 0) {
46189 + kfree(buf);
46190 return ret;
46191 + }
46192
46193 - if (ret == 1)
46194 + if (ret == 1) {
46195 + kfree(buf);
46196 return 0; /* no key pressed */
46197 + }
46198
46199 /* decoding */
46200 b = buf+1;
46201 @@ -653,6 +686,8 @@ unlock:
46202
46203 ir_raw_event_handle(d->rc_dev);
46204
46205 + kfree(buf);
46206 +
46207 return 1;
46208 }
46209
46210 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46211 index e502a5f..2a27f40 100644
46212 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46213 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46214 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46215 * by passing a very big num_planes value */
46216 uplane = compat_alloc_user_space(num_planes *
46217 sizeof(struct v4l2_plane));
46218 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46219 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46220
46221 while (--num_planes >= 0) {
46222 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46223 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46224 if (num_planes == 0)
46225 return 0;
46226
46227 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46228 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46229 if (get_user(p, &up->m.planes))
46230 return -EFAULT;
46231 uplane32 = compat_ptr(p);
46232 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46233 get_user(kp->flags, &up->flags) ||
46234 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46235 return -EFAULT;
46236 - kp->base = (__force void *)compat_ptr(tmp);
46237 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46238 return 0;
46239 }
46240
46241 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46242 n * sizeof(struct v4l2_ext_control32)))
46243 return -EFAULT;
46244 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46245 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46246 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46247 while (--n >= 0) {
46248 u32 id;
46249
46250 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46251 {
46252 struct v4l2_ext_control32 __user *ucontrols;
46253 struct v4l2_ext_control __user *kcontrols =
46254 - (__force struct v4l2_ext_control __user *)kp->controls;
46255 + (struct v4l2_ext_control __force_user *)kp->controls;
46256 int n = kp->count;
46257 compat_caddr_t p;
46258
46259 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46260 get_user(tmp, &up->edid) ||
46261 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46262 return -EFAULT;
46263 - kp->edid = (__force u8 *)compat_ptr(tmp);
46264 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46265 return 0;
46266 }
46267
46268 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46269 index 015f92a..59e311e 100644
46270 --- a/drivers/media/v4l2-core/v4l2-device.c
46271 +++ b/drivers/media/v4l2-core/v4l2-device.c
46272 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46273 EXPORT_SYMBOL_GPL(v4l2_device_put);
46274
46275 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46276 - atomic_t *instance)
46277 + atomic_unchecked_t *instance)
46278 {
46279 - int num = atomic_inc_return(instance) - 1;
46280 + int num = atomic_inc_return_unchecked(instance) - 1;
46281 int len = strlen(basename);
46282
46283 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46284 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46285 index 9ccb19a..d131468 100644
46286 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46287 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46288 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46289 struct file *file, void *fh, void *p);
46290 } u;
46291 void (*debug)(const void *arg, bool write_only);
46292 -};
46293 +} __do_const;
46294 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46295
46296 /* This control needs a priority check */
46297 #define INFO_FL_PRIO (1 << 0)
46298 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46299 struct video_device *vfd = video_devdata(file);
46300 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46301 bool write_only = false;
46302 - struct v4l2_ioctl_info default_info;
46303 + v4l2_ioctl_info_no_const default_info;
46304 const struct v4l2_ioctl_info *info;
46305 void *fh = file->private_data;
46306 struct v4l2_fh *vfh = NULL;
46307 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46308 ret = -EINVAL;
46309 break;
46310 }
46311 - *user_ptr = (void __user *)buf->m.planes;
46312 + *user_ptr = (void __force_user *)buf->m.planes;
46313 *kernel_ptr = (void **)&buf->m.planes;
46314 *array_size = sizeof(struct v4l2_plane) * buf->length;
46315 ret = 1;
46316 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46317 ret = -EINVAL;
46318 break;
46319 }
46320 - *user_ptr = (void __user *)edid->edid;
46321 + *user_ptr = (void __force_user *)edid->edid;
46322 *kernel_ptr = (void **)&edid->edid;
46323 *array_size = edid->blocks * 128;
46324 ret = 1;
46325 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46326 ret = -EINVAL;
46327 break;
46328 }
46329 - *user_ptr = (void __user *)ctrls->controls;
46330 + *user_ptr = (void __force_user *)ctrls->controls;
46331 *kernel_ptr = (void **)&ctrls->controls;
46332 *array_size = sizeof(struct v4l2_ext_control)
46333 * ctrls->count;
46334 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46335 }
46336
46337 if (has_array_args) {
46338 - *kernel_ptr = (void __force *)user_ptr;
46339 + *kernel_ptr = (void __force_kernel *)user_ptr;
46340 if (copy_to_user(user_ptr, mbuf, array_size))
46341 err = -EFAULT;
46342 goto out_array_args;
46343 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46344 index 187f836..679544b 100644
46345 --- a/drivers/message/fusion/mptbase.c
46346 +++ b/drivers/message/fusion/mptbase.c
46347 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46348 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46349 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46350
46351 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46352 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46353 +#else
46354 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46355 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46356 +#endif
46357 +
46358 /*
46359 * Rounding UP to nearest 4-kB boundary here...
46360 */
46361 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46362 ioc->facts.GlobalCredits);
46363
46364 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46365 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46366 + NULL, NULL);
46367 +#else
46368 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46369 +#endif
46370 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46371 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46372 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46373 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46374 index 0707fa2..70ca794 100644
46375 --- a/drivers/message/fusion/mptsas.c
46376 +++ b/drivers/message/fusion/mptsas.c
46377 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46378 return 0;
46379 }
46380
46381 +static inline void
46382 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46383 +{
46384 + if (phy_info->port_details) {
46385 + phy_info->port_details->rphy = rphy;
46386 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46387 + ioc->name, rphy));
46388 + }
46389 +
46390 + if (rphy) {
46391 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46392 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46393 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46394 + ioc->name, rphy, rphy->dev.release));
46395 + }
46396 +}
46397 +
46398 /* no mutex */
46399 static void
46400 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46401 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46402 return NULL;
46403 }
46404
46405 -static inline void
46406 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46407 -{
46408 - if (phy_info->port_details) {
46409 - phy_info->port_details->rphy = rphy;
46410 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46411 - ioc->name, rphy));
46412 - }
46413 -
46414 - if (rphy) {
46415 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46416 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46417 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46418 - ioc->name, rphy, rphy->dev.release));
46419 - }
46420 -}
46421 -
46422 static inline struct sas_port *
46423 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46424 {
46425 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46426 index b7d87cd..3fb36da 100644
46427 --- a/drivers/message/i2o/i2o_proc.c
46428 +++ b/drivers/message/i2o/i2o_proc.c
46429 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46430 "Array Controller Device"
46431 };
46432
46433 -static char *chtostr(char *tmp, u8 *chars, int n)
46434 -{
46435 - tmp[0] = 0;
46436 - return strncat(tmp, (char *)chars, n);
46437 -}
46438 -
46439 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46440 char *group)
46441 {
46442 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46443 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46444 {
46445 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46446 - static u32 work32[5];
46447 - static u8 *work8 = (u8 *) work32;
46448 - static u16 *work16 = (u16 *) work32;
46449 + u32 work32[5];
46450 + u8 *work8 = (u8 *) work32;
46451 + u16 *work16 = (u16 *) work32;
46452 int token;
46453 u32 hwcap;
46454
46455 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46456 } *result;
46457
46458 i2o_exec_execute_ddm_table ddm_table;
46459 - char tmp[28 + 1];
46460
46461 result = kmalloc(sizeof(*result), GFP_KERNEL);
46462 if (!result)
46463 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46464
46465 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46466 seq_printf(seq, "%-#8x", ddm_table.module_id);
46467 - seq_printf(seq, "%-29s",
46468 - chtostr(tmp, ddm_table.module_name_version, 28));
46469 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46470 seq_printf(seq, "%9d ", ddm_table.data_size);
46471 seq_printf(seq, "%8d", ddm_table.code_size);
46472
46473 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46474
46475 i2o_driver_result_table *result;
46476 i2o_driver_store_table *dst;
46477 - char tmp[28 + 1];
46478
46479 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46480 if (result == NULL)
46481 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46482
46483 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46484 seq_printf(seq, "%-#8x", dst->module_id);
46485 - seq_printf(seq, "%-29s",
46486 - chtostr(tmp, dst->module_name_version, 28));
46487 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46488 + seq_printf(seq, "%-.28s", dst->module_name_version);
46489 + seq_printf(seq, "%-.8s", dst->date);
46490 seq_printf(seq, "%8d ", dst->module_size);
46491 seq_printf(seq, "%8d ", dst->mpb_size);
46492 seq_printf(seq, "0x%04x", dst->module_flags);
46493 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46494 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46495 {
46496 struct i2o_device *d = (struct i2o_device *)seq->private;
46497 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46498 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46499 // == (allow) 512d bytes (max)
46500 - static u16 *work16 = (u16 *) work32;
46501 + u16 *work16 = (u16 *) work32;
46502 int token;
46503 - char tmp[16 + 1];
46504
46505 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46506
46507 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46508 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46509 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46510 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46511 - seq_printf(seq, "Vendor info : %s\n",
46512 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46513 - seq_printf(seq, "Product info : %s\n",
46514 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46515 - seq_printf(seq, "Description : %s\n",
46516 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46517 - seq_printf(seq, "Product rev. : %s\n",
46518 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46519 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46520 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46521 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46522 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46523
46524 seq_printf(seq, "Serial number : ");
46525 print_serial_number(seq, (u8 *) (work32 + 16),
46526 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46527 u8 pad[256]; // allow up to 256 byte (max) serial number
46528 } result;
46529
46530 - char tmp[24 + 1];
46531 -
46532 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46533
46534 if (token < 0) {
46535 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46536 }
46537
46538 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46539 - seq_printf(seq, "Module name : %s\n",
46540 - chtostr(tmp, result.module_name, 24));
46541 - seq_printf(seq, "Module revision : %s\n",
46542 - chtostr(tmp, result.module_rev, 8));
46543 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46544 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46545
46546 seq_printf(seq, "Serial number : ");
46547 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46548 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46549 u8 instance_number[4];
46550 } result;
46551
46552 - char tmp[64 + 1];
46553 -
46554 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46555
46556 if (token < 0) {
46557 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46558 return 0;
46559 }
46560
46561 - seq_printf(seq, "Device name : %s\n",
46562 - chtostr(tmp, result.device_name, 64));
46563 - seq_printf(seq, "Service name : %s\n",
46564 - chtostr(tmp, result.service_name, 64));
46565 - seq_printf(seq, "Physical name : %s\n",
46566 - chtostr(tmp, result.physical_location, 64));
46567 - seq_printf(seq, "Instance number : %s\n",
46568 - chtostr(tmp, result.instance_number, 4));
46569 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46570 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46571 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46572 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46573
46574 return 0;
46575 }
46576 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46577 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46578 {
46579 struct i2o_device *d = (struct i2o_device *)seq->private;
46580 - static u32 work32[12];
46581 - static u16 *work16 = (u16 *) work32;
46582 - static u8 *work8 = (u8 *) work32;
46583 + u32 work32[12];
46584 + u16 *work16 = (u16 *) work32;
46585 + u8 *work8 = (u8 *) work32;
46586 int token;
46587
46588 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46589 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46590 index 92752fb..a7494f6 100644
46591 --- a/drivers/message/i2o/iop.c
46592 +++ b/drivers/message/i2o/iop.c
46593 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46594
46595 spin_lock_irqsave(&c->context_list_lock, flags);
46596
46597 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46598 - atomic_inc(&c->context_list_counter);
46599 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46600 + atomic_inc_unchecked(&c->context_list_counter);
46601
46602 - entry->context = atomic_read(&c->context_list_counter);
46603 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46604
46605 list_add(&entry->list, &c->context_list);
46606
46607 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46608
46609 #if BITS_PER_LONG == 64
46610 spin_lock_init(&c->context_list_lock);
46611 - atomic_set(&c->context_list_counter, 0);
46612 + atomic_set_unchecked(&c->context_list_counter, 0);
46613 INIT_LIST_HEAD(&c->context_list);
46614 #endif
46615
46616 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46617 index b2c7e3b..85aa4764 100644
46618 --- a/drivers/mfd/ab8500-debugfs.c
46619 +++ b/drivers/mfd/ab8500-debugfs.c
46620 @@ -100,7 +100,7 @@ static int irq_last;
46621 static u32 *irq_count;
46622 static int num_irqs;
46623
46624 -static struct device_attribute **dev_attr;
46625 +static device_attribute_no_const **dev_attr;
46626 static char **event_name;
46627
46628 static u8 avg_sample = SAMPLE_16;
46629 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46630 index c880c89..45a7c68 100644
46631 --- a/drivers/mfd/max8925-i2c.c
46632 +++ b/drivers/mfd/max8925-i2c.c
46633 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46634 const struct i2c_device_id *id)
46635 {
46636 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46637 - static struct max8925_chip *chip;
46638 + struct max8925_chip *chip;
46639 struct device_node *node = client->dev.of_node;
46640
46641 if (node && !pdata) {
46642 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46643 index 7612d89..70549c2 100644
46644 --- a/drivers/mfd/tps65910.c
46645 +++ b/drivers/mfd/tps65910.c
46646 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46647 struct tps65910_platform_data *pdata)
46648 {
46649 int ret = 0;
46650 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46651 + struct regmap_irq_chip *tps6591x_irqs_chip;
46652
46653 if (!irq) {
46654 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46655 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46656 index 1b772ef..01e77d33 100644
46657 --- a/drivers/mfd/twl4030-irq.c
46658 +++ b/drivers/mfd/twl4030-irq.c
46659 @@ -34,6 +34,7 @@
46660 #include <linux/of.h>
46661 #include <linux/irqdomain.h>
46662 #include <linux/i2c/twl.h>
46663 +#include <asm/pgtable.h>
46664
46665 #include "twl-core.h"
46666
46667 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46668 * Install an irq handler for each of the SIH modules;
46669 * clone dummy irq_chip since PIH can't *do* anything
46670 */
46671 - twl4030_irq_chip = dummy_irq_chip;
46672 - twl4030_irq_chip.name = "twl4030";
46673 + pax_open_kernel();
46674 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46675 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46676
46677 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46678 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46679 + pax_close_kernel();
46680
46681 for (i = irq_base; i < irq_end; i++) {
46682 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46683 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46684 index 464419b..64bae8d 100644
46685 --- a/drivers/misc/c2port/core.c
46686 +++ b/drivers/misc/c2port/core.c
46687 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46688 goto error_idr_alloc;
46689 c2dev->id = ret;
46690
46691 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46692 + pax_open_kernel();
46693 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46694 + pax_close_kernel();
46695
46696 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46697 "c2port%d", c2dev->id);
46698 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46699 index 3f2b625..945e179 100644
46700 --- a/drivers/misc/eeprom/sunxi_sid.c
46701 +++ b/drivers/misc/eeprom/sunxi_sid.c
46702 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46703
46704 platform_set_drvdata(pdev, sid_data);
46705
46706 - sid_bin_attr.size = sid_data->keysize;
46707 + pax_open_kernel();
46708 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46709 + pax_close_kernel();
46710 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46711 return -ENODEV;
46712
46713 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46714 index 36f5d52..32311c3 100644
46715 --- a/drivers/misc/kgdbts.c
46716 +++ b/drivers/misc/kgdbts.c
46717 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46718 char before[BREAK_INSTR_SIZE];
46719 char after[BREAK_INSTR_SIZE];
46720
46721 - probe_kernel_read(before, (char *)kgdbts_break_test,
46722 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46723 BREAK_INSTR_SIZE);
46724 init_simple_test();
46725 ts.tst = plant_and_detach_test;
46726 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46727 /* Activate test with initial breakpoint */
46728 if (!is_early)
46729 kgdb_breakpoint();
46730 - probe_kernel_read(after, (char *)kgdbts_break_test,
46731 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46732 BREAK_INSTR_SIZE);
46733 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46734 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46735 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46736 index 3ef4627..8d00486 100644
46737 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46738 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46739 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46740 * the lid is closed. This leads to interrupts as soon as a little move
46741 * is done.
46742 */
46743 - atomic_inc(&lis3->count);
46744 + atomic_inc_unchecked(&lis3->count);
46745
46746 wake_up_interruptible(&lis3->misc_wait);
46747 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46748 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46749 if (lis3->pm_dev)
46750 pm_runtime_get_sync(lis3->pm_dev);
46751
46752 - atomic_set(&lis3->count, 0);
46753 + atomic_set_unchecked(&lis3->count, 0);
46754 return 0;
46755 }
46756
46757 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46758 add_wait_queue(&lis3->misc_wait, &wait);
46759 while (true) {
46760 set_current_state(TASK_INTERRUPTIBLE);
46761 - data = atomic_xchg(&lis3->count, 0);
46762 + data = atomic_xchg_unchecked(&lis3->count, 0);
46763 if (data)
46764 break;
46765
46766 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46767 struct lis3lv02d, miscdev);
46768
46769 poll_wait(file, &lis3->misc_wait, wait);
46770 - if (atomic_read(&lis3->count))
46771 + if (atomic_read_unchecked(&lis3->count))
46772 return POLLIN | POLLRDNORM;
46773 return 0;
46774 }
46775 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46776 index c439c82..1f20f57 100644
46777 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46778 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46779 @@ -297,7 +297,7 @@ struct lis3lv02d {
46780 struct input_polled_dev *idev; /* input device */
46781 struct platform_device *pdev; /* platform device */
46782 struct regulator_bulk_data regulators[2];
46783 - atomic_t count; /* interrupt count after last read */
46784 + atomic_unchecked_t count; /* interrupt count after last read */
46785 union axis_conversion ac; /* hw -> logical axis */
46786 int mapped_btns[3];
46787
46788 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46789 index 2f30bad..c4c13d0 100644
46790 --- a/drivers/misc/sgi-gru/gruhandles.c
46791 +++ b/drivers/misc/sgi-gru/gruhandles.c
46792 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46793 unsigned long nsec;
46794
46795 nsec = CLKS2NSEC(clks);
46796 - atomic_long_inc(&mcs_op_statistics[op].count);
46797 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46798 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46799 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46800 if (mcs_op_statistics[op].max < nsec)
46801 mcs_op_statistics[op].max = nsec;
46802 }
46803 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46804 index 4f76359..cdfcb2e 100644
46805 --- a/drivers/misc/sgi-gru/gruprocfs.c
46806 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46807 @@ -32,9 +32,9 @@
46808
46809 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46810
46811 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46812 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46813 {
46814 - unsigned long val = atomic_long_read(v);
46815 + unsigned long val = atomic_long_read_unchecked(v);
46816
46817 seq_printf(s, "%16lu %s\n", val, id);
46818 }
46819 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46820
46821 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46822 for (op = 0; op < mcsop_last; op++) {
46823 - count = atomic_long_read(&mcs_op_statistics[op].count);
46824 - total = atomic_long_read(&mcs_op_statistics[op].total);
46825 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46826 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46827 max = mcs_op_statistics[op].max;
46828 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46829 count ? total / count : 0, max);
46830 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46831 index 5c3ce24..4915ccb 100644
46832 --- a/drivers/misc/sgi-gru/grutables.h
46833 +++ b/drivers/misc/sgi-gru/grutables.h
46834 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46835 * GRU statistics.
46836 */
46837 struct gru_stats_s {
46838 - atomic_long_t vdata_alloc;
46839 - atomic_long_t vdata_free;
46840 - atomic_long_t gts_alloc;
46841 - atomic_long_t gts_free;
46842 - atomic_long_t gms_alloc;
46843 - atomic_long_t gms_free;
46844 - atomic_long_t gts_double_allocate;
46845 - atomic_long_t assign_context;
46846 - atomic_long_t assign_context_failed;
46847 - atomic_long_t free_context;
46848 - atomic_long_t load_user_context;
46849 - atomic_long_t load_kernel_context;
46850 - atomic_long_t lock_kernel_context;
46851 - atomic_long_t unlock_kernel_context;
46852 - atomic_long_t steal_user_context;
46853 - atomic_long_t steal_kernel_context;
46854 - atomic_long_t steal_context_failed;
46855 - atomic_long_t nopfn;
46856 - atomic_long_t asid_new;
46857 - atomic_long_t asid_next;
46858 - atomic_long_t asid_wrap;
46859 - atomic_long_t asid_reuse;
46860 - atomic_long_t intr;
46861 - atomic_long_t intr_cbr;
46862 - atomic_long_t intr_tfh;
46863 - atomic_long_t intr_spurious;
46864 - atomic_long_t intr_mm_lock_failed;
46865 - atomic_long_t call_os;
46866 - atomic_long_t call_os_wait_queue;
46867 - atomic_long_t user_flush_tlb;
46868 - atomic_long_t user_unload_context;
46869 - atomic_long_t user_exception;
46870 - atomic_long_t set_context_option;
46871 - atomic_long_t check_context_retarget_intr;
46872 - atomic_long_t check_context_unload;
46873 - atomic_long_t tlb_dropin;
46874 - atomic_long_t tlb_preload_page;
46875 - atomic_long_t tlb_dropin_fail_no_asid;
46876 - atomic_long_t tlb_dropin_fail_upm;
46877 - atomic_long_t tlb_dropin_fail_invalid;
46878 - atomic_long_t tlb_dropin_fail_range_active;
46879 - atomic_long_t tlb_dropin_fail_idle;
46880 - atomic_long_t tlb_dropin_fail_fmm;
46881 - atomic_long_t tlb_dropin_fail_no_exception;
46882 - atomic_long_t tfh_stale_on_fault;
46883 - atomic_long_t mmu_invalidate_range;
46884 - atomic_long_t mmu_invalidate_page;
46885 - atomic_long_t flush_tlb;
46886 - atomic_long_t flush_tlb_gru;
46887 - atomic_long_t flush_tlb_gru_tgh;
46888 - atomic_long_t flush_tlb_gru_zero_asid;
46889 + atomic_long_unchecked_t vdata_alloc;
46890 + atomic_long_unchecked_t vdata_free;
46891 + atomic_long_unchecked_t gts_alloc;
46892 + atomic_long_unchecked_t gts_free;
46893 + atomic_long_unchecked_t gms_alloc;
46894 + atomic_long_unchecked_t gms_free;
46895 + atomic_long_unchecked_t gts_double_allocate;
46896 + atomic_long_unchecked_t assign_context;
46897 + atomic_long_unchecked_t assign_context_failed;
46898 + atomic_long_unchecked_t free_context;
46899 + atomic_long_unchecked_t load_user_context;
46900 + atomic_long_unchecked_t load_kernel_context;
46901 + atomic_long_unchecked_t lock_kernel_context;
46902 + atomic_long_unchecked_t unlock_kernel_context;
46903 + atomic_long_unchecked_t steal_user_context;
46904 + atomic_long_unchecked_t steal_kernel_context;
46905 + atomic_long_unchecked_t steal_context_failed;
46906 + atomic_long_unchecked_t nopfn;
46907 + atomic_long_unchecked_t asid_new;
46908 + atomic_long_unchecked_t asid_next;
46909 + atomic_long_unchecked_t asid_wrap;
46910 + atomic_long_unchecked_t asid_reuse;
46911 + atomic_long_unchecked_t intr;
46912 + atomic_long_unchecked_t intr_cbr;
46913 + atomic_long_unchecked_t intr_tfh;
46914 + atomic_long_unchecked_t intr_spurious;
46915 + atomic_long_unchecked_t intr_mm_lock_failed;
46916 + atomic_long_unchecked_t call_os;
46917 + atomic_long_unchecked_t call_os_wait_queue;
46918 + atomic_long_unchecked_t user_flush_tlb;
46919 + atomic_long_unchecked_t user_unload_context;
46920 + atomic_long_unchecked_t user_exception;
46921 + atomic_long_unchecked_t set_context_option;
46922 + atomic_long_unchecked_t check_context_retarget_intr;
46923 + atomic_long_unchecked_t check_context_unload;
46924 + atomic_long_unchecked_t tlb_dropin;
46925 + atomic_long_unchecked_t tlb_preload_page;
46926 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46927 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46928 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46929 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46930 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46931 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46932 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46933 + atomic_long_unchecked_t tfh_stale_on_fault;
46934 + atomic_long_unchecked_t mmu_invalidate_range;
46935 + atomic_long_unchecked_t mmu_invalidate_page;
46936 + atomic_long_unchecked_t flush_tlb;
46937 + atomic_long_unchecked_t flush_tlb_gru;
46938 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46939 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46940
46941 - atomic_long_t copy_gpa;
46942 - atomic_long_t read_gpa;
46943 + atomic_long_unchecked_t copy_gpa;
46944 + atomic_long_unchecked_t read_gpa;
46945
46946 - atomic_long_t mesq_receive;
46947 - atomic_long_t mesq_receive_none;
46948 - atomic_long_t mesq_send;
46949 - atomic_long_t mesq_send_failed;
46950 - atomic_long_t mesq_noop;
46951 - atomic_long_t mesq_send_unexpected_error;
46952 - atomic_long_t mesq_send_lb_overflow;
46953 - atomic_long_t mesq_send_qlimit_reached;
46954 - atomic_long_t mesq_send_amo_nacked;
46955 - atomic_long_t mesq_send_put_nacked;
46956 - atomic_long_t mesq_page_overflow;
46957 - atomic_long_t mesq_qf_locked;
46958 - atomic_long_t mesq_qf_noop_not_full;
46959 - atomic_long_t mesq_qf_switch_head_failed;
46960 - atomic_long_t mesq_qf_unexpected_error;
46961 - atomic_long_t mesq_noop_unexpected_error;
46962 - atomic_long_t mesq_noop_lb_overflow;
46963 - atomic_long_t mesq_noop_qlimit_reached;
46964 - atomic_long_t mesq_noop_amo_nacked;
46965 - atomic_long_t mesq_noop_put_nacked;
46966 - atomic_long_t mesq_noop_page_overflow;
46967 + atomic_long_unchecked_t mesq_receive;
46968 + atomic_long_unchecked_t mesq_receive_none;
46969 + atomic_long_unchecked_t mesq_send;
46970 + atomic_long_unchecked_t mesq_send_failed;
46971 + atomic_long_unchecked_t mesq_noop;
46972 + atomic_long_unchecked_t mesq_send_unexpected_error;
46973 + atomic_long_unchecked_t mesq_send_lb_overflow;
46974 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46975 + atomic_long_unchecked_t mesq_send_amo_nacked;
46976 + atomic_long_unchecked_t mesq_send_put_nacked;
46977 + atomic_long_unchecked_t mesq_page_overflow;
46978 + atomic_long_unchecked_t mesq_qf_locked;
46979 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46980 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46981 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46982 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46983 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46984 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46985 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46986 + atomic_long_unchecked_t mesq_noop_put_nacked;
46987 + atomic_long_unchecked_t mesq_noop_page_overflow;
46988
46989 };
46990
46991 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46992 tghop_invalidate, mcsop_last};
46993
46994 struct mcs_op_statistic {
46995 - atomic_long_t count;
46996 - atomic_long_t total;
46997 + atomic_long_unchecked_t count;
46998 + atomic_long_unchecked_t total;
46999 unsigned long max;
47000 };
47001
47002 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47003
47004 #define STAT(id) do { \
47005 if (gru_options & OPT_STATS) \
47006 - atomic_long_inc(&gru_stats.id); \
47007 + atomic_long_inc_unchecked(&gru_stats.id); \
47008 } while (0)
47009
47010 #ifdef CONFIG_SGI_GRU_DEBUG
47011 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47012 index c862cd4..0d176fe 100644
47013 --- a/drivers/misc/sgi-xp/xp.h
47014 +++ b/drivers/misc/sgi-xp/xp.h
47015 @@ -288,7 +288,7 @@ struct xpc_interface {
47016 xpc_notify_func, void *);
47017 void (*received) (short, int, void *);
47018 enum xp_retval (*partid_to_nasids) (short, void *);
47019 -};
47020 +} __no_const;
47021
47022 extern struct xpc_interface xpc_interface;
47023
47024 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47025 index 01be66d..e3a0c7e 100644
47026 --- a/drivers/misc/sgi-xp/xp_main.c
47027 +++ b/drivers/misc/sgi-xp/xp_main.c
47028 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47029 }
47030
47031 struct xpc_interface xpc_interface = {
47032 - (void (*)(int))xpc_notloaded,
47033 - (void (*)(int))xpc_notloaded,
47034 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47035 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47036 + .connect = (void (*)(int))xpc_notloaded,
47037 + .disconnect = (void (*)(int))xpc_notloaded,
47038 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47039 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47040 void *))xpc_notloaded,
47041 - (void (*)(short, int, void *))xpc_notloaded,
47042 - (enum xp_retval(*)(short, void *))xpc_notloaded
47043 + .received = (void (*)(short, int, void *))xpc_notloaded,
47044 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47045 };
47046 EXPORT_SYMBOL_GPL(xpc_interface);
47047
47048 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47049 index b94d5f7..7f494c5 100644
47050 --- a/drivers/misc/sgi-xp/xpc.h
47051 +++ b/drivers/misc/sgi-xp/xpc.h
47052 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47053 void (*received_payload) (struct xpc_channel *, void *);
47054 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47055 };
47056 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47057
47058 /* struct xpc_partition act_state values (for XPC HB) */
47059
47060 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47061 /* found in xpc_main.c */
47062 extern struct device *xpc_part;
47063 extern struct device *xpc_chan;
47064 -extern struct xpc_arch_operations xpc_arch_ops;
47065 +extern xpc_arch_operations_no_const xpc_arch_ops;
47066 extern int xpc_disengage_timelimit;
47067 extern int xpc_disengage_timedout;
47068 extern int xpc_activate_IRQ_rcvd;
47069 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47070 index 82dc574..8539ab2 100644
47071 --- a/drivers/misc/sgi-xp/xpc_main.c
47072 +++ b/drivers/misc/sgi-xp/xpc_main.c
47073 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47074 .notifier_call = xpc_system_die,
47075 };
47076
47077 -struct xpc_arch_operations xpc_arch_ops;
47078 +xpc_arch_operations_no_const xpc_arch_ops;
47079
47080 /*
47081 * Timer function to enforce the timelimit on the partition disengage.
47082 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47083
47084 if (((die_args->trapnr == X86_TRAP_MF) ||
47085 (die_args->trapnr == X86_TRAP_XF)) &&
47086 - !user_mode_vm(die_args->regs))
47087 + !user_mode(die_args->regs))
47088 xpc_die_deactivate();
47089
47090 break;
47091 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47092 index a11451f..9e1bbad 100644
47093 --- a/drivers/mmc/card/block.c
47094 +++ b/drivers/mmc/card/block.c
47095 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47096 if (idata->ic.postsleep_min_us)
47097 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47098
47099 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47100 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47101 err = -EFAULT;
47102 goto cmd_rel_host;
47103 }
47104 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47105 index 7911e05..d0f9dda 100644
47106 --- a/drivers/mmc/core/mmc_ops.c
47107 +++ b/drivers/mmc/core/mmc_ops.c
47108 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47109 void *data_buf;
47110 int is_on_stack;
47111
47112 - is_on_stack = object_is_on_stack(buf);
47113 + is_on_stack = object_starts_on_stack(buf);
47114 if (is_on_stack) {
47115 /*
47116 * dma onto stack is unsafe/nonportable, but callers to this
47117 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47118 index 01b99e8..5c325e3 100644
47119 --- a/drivers/mmc/host/dw_mmc.h
47120 +++ b/drivers/mmc/host/dw_mmc.h
47121 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47122 int (*parse_dt)(struct dw_mci *host);
47123 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47124 struct dw_mci_tuning_data *tuning_data);
47125 -};
47126 +} __do_const;
47127 #endif /* _DW_MMC_H_ */
47128 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47129 index 43af791..86f4c48 100644
47130 --- a/drivers/mmc/host/mmci.c
47131 +++ b/drivers/mmc/host/mmci.c
47132 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47133 mmc->caps |= MMC_CAP_CMD23;
47134
47135 if (variant->busy_detect) {
47136 - mmci_ops.card_busy = mmci_card_busy;
47137 + pax_open_kernel();
47138 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47139 + pax_close_kernel();
47140 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47141 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47142 mmc->max_busy_timeout = 0;
47143 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47144 index 9c2b9cb..cebb09a 100644
47145 --- a/drivers/mmc/host/omap_hsmmc.c
47146 +++ b/drivers/mmc/host/omap_hsmmc.c
47147 @@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47148
47149 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47150 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47151 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47152 + pax_open_kernel();
47153 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47154 + pax_close_kernel();
47155 }
47156
47157 pm_runtime_enable(host->dev);
47158 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47159 index 587ee0e..b3bbcab 100644
47160 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47161 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47162 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47163 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47164 }
47165
47166 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47167 - sdhci_esdhc_ops.platform_execute_tuning =
47168 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47169 + pax_open_kernel();
47170 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47171 esdhc_executing_tuning;
47172 + pax_close_kernel();
47173 + }
47174
47175 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47176 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47177 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47178 index 0ce6eb1..8dcce1b 100644
47179 --- a/drivers/mmc/host/sdhci-s3c.c
47180 +++ b/drivers/mmc/host/sdhci-s3c.c
47181 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47182 * we can use overriding functions instead of default.
47183 */
47184 if (sc->no_divider) {
47185 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47186 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47187 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47188 + pax_open_kernel();
47189 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47190 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47191 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47192 + pax_close_kernel();
47193 }
47194
47195 /* It supports additional host capabilities if needed */
47196 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47197 index 423666b..81ff5eb 100644
47198 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47199 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47200 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47201 size_t totlen = 0, thislen;
47202 int ret = 0;
47203 size_t buflen = 0;
47204 - static char *buffer;
47205 + char *buffer;
47206
47207 if (!ECCBUF_SIZE) {
47208 /* We should fall back to a general writev implementation.
47209 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47210 index b3b7ca1..5dd4634 100644
47211 --- a/drivers/mtd/nand/denali.c
47212 +++ b/drivers/mtd/nand/denali.c
47213 @@ -24,6 +24,7 @@
47214 #include <linux/slab.h>
47215 #include <linux/mtd/mtd.h>
47216 #include <linux/module.h>
47217 +#include <linux/slab.h>
47218
47219 #include "denali.h"
47220
47221 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47222 index 959cb9b..8520fe5 100644
47223 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47224 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47225 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47226
47227 /* first try to map the upper buffer directly */
47228 if (virt_addr_valid(this->upper_buf) &&
47229 - !object_is_on_stack(this->upper_buf)) {
47230 + !object_starts_on_stack(this->upper_buf)) {
47231 sg_init_one(sgl, this->upper_buf, this->upper_len);
47232 ret = dma_map_sg(this->dev, sgl, 1, dr);
47233 if (ret == 0)
47234 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47235 index 51b9d6a..52af9a7 100644
47236 --- a/drivers/mtd/nftlmount.c
47237 +++ b/drivers/mtd/nftlmount.c
47238 @@ -24,6 +24,7 @@
47239 #include <asm/errno.h>
47240 #include <linux/delay.h>
47241 #include <linux/slab.h>
47242 +#include <linux/sched.h>
47243 #include <linux/mtd/mtd.h>
47244 #include <linux/mtd/nand.h>
47245 #include <linux/mtd/nftl.h>
47246 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47247 index c23184a..4115c41 100644
47248 --- a/drivers/mtd/sm_ftl.c
47249 +++ b/drivers/mtd/sm_ftl.c
47250 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47251 #define SM_CIS_VENDOR_OFFSET 0x59
47252 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47253 {
47254 - struct attribute_group *attr_group;
47255 + attribute_group_no_const *attr_group;
47256 struct attribute **attributes;
47257 struct sm_sysfs_attribute *vendor_attribute;
47258 char *vendor;
47259 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47260 index a5115fb..81b03f6 100644
47261 --- a/drivers/net/bonding/bond_main.c
47262 +++ b/drivers/net/bonding/bond_main.c
47263 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47264 bond_dev_queue_xmit(bond, skb, slave->dev);
47265 } else {
47266 dev_kfree_skb_any(skb);
47267 - atomic_long_inc(&dev->tx_dropped);
47268 + atomic_long_inc_unchecked(&dev->tx_dropped);
47269 }
47270
47271 return NETDEV_TX_OK;
47272 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47273 index 45f09a6..f154f8d 100644
47274 --- a/drivers/net/bonding/bond_netlink.c
47275 +++ b/drivers/net/bonding/bond_netlink.c
47276 @@ -585,7 +585,7 @@ nla_put_failure:
47277 return -EMSGSIZE;
47278 }
47279
47280 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47281 +struct rtnl_link_ops bond_link_ops = {
47282 .kind = "bond",
47283 .priv_size = sizeof(struct bonding),
47284 .setup = bond_setup,
47285 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47286 index 5e40a8b..126bfda 100644
47287 --- a/drivers/net/caif/caif_hsi.c
47288 +++ b/drivers/net/caif/caif_hsi.c
47289 @@ -1445,7 +1445,7 @@ err:
47290 return -ENODEV;
47291 }
47292
47293 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47294 +static struct rtnl_link_ops caif_hsi_link_ops = {
47295 .kind = "cfhsi",
47296 .priv_size = sizeof(struct cfhsi),
47297 .setup = cfhsi_setup,
47298 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47299 index 98d73aa..63ef9da 100644
47300 --- a/drivers/net/can/Kconfig
47301 +++ b/drivers/net/can/Kconfig
47302 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47303
47304 config CAN_FLEXCAN
47305 tristate "Support for Freescale FLEXCAN based chips"
47306 - depends on ARM || PPC
47307 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47308 ---help---
47309 Say Y here if you want to support for Freescale FlexCAN.
47310
47311 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47312 index 2cfe501..477d4b5 100644
47313 --- a/drivers/net/can/dev.c
47314 +++ b/drivers/net/can/dev.c
47315 @@ -868,7 +868,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47316 return -EOPNOTSUPP;
47317 }
47318
47319 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47320 +static struct rtnl_link_ops can_link_ops = {
47321 .kind = "can",
47322 .maxtype = IFLA_CAN_MAX,
47323 .policy = can_policy,
47324 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47325 index 4e94057..32032ff 100644
47326 --- a/drivers/net/can/vcan.c
47327 +++ b/drivers/net/can/vcan.c
47328 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47329 dev->destructor = free_netdev;
47330 }
47331
47332 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47333 +static struct rtnl_link_ops vcan_link_ops = {
47334 .kind = "vcan",
47335 .setup = vcan_setup,
47336 };
47337 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47338 index ff435fb..d408b1f 100644
47339 --- a/drivers/net/dummy.c
47340 +++ b/drivers/net/dummy.c
47341 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47342 return 0;
47343 }
47344
47345 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47346 +static struct rtnl_link_ops dummy_link_ops = {
47347 .kind = "dummy",
47348 .setup = dummy_setup,
47349 .validate = dummy_validate,
47350 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47351 index 1d162cc..b546a75 100644
47352 --- a/drivers/net/ethernet/8390/ax88796.c
47353 +++ b/drivers/net/ethernet/8390/ax88796.c
47354 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47355 if (ax->plat->reg_offsets)
47356 ei_local->reg_offset = ax->plat->reg_offsets;
47357 else {
47358 + resource_size_t _mem_size = mem_size;
47359 + do_div(_mem_size, 0x18);
47360 ei_local->reg_offset = ax->reg_offsets;
47361 for (ret = 0; ret < 0x18; ret++)
47362 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47363 + ax->reg_offsets[ret] = _mem_size * ret;
47364 }
47365
47366 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47367 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47368 index 4efc435..4ab9e14 100644
47369 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47370 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47371 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47372 return 0;
47373 }
47374
47375 -static struct net_device_ops altera_tse_netdev_ops = {
47376 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47377 .ndo_open = tse_open,
47378 .ndo_stop = tse_shutdown,
47379 .ndo_start_xmit = tse_start_xmit,
47380 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47381 ndev->netdev_ops = &altera_tse_netdev_ops;
47382 altera_tse_set_ethtool_ops(ndev);
47383
47384 + pax_open_kernel();
47385 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47386
47387 if (priv->hash_filter)
47388 altera_tse_netdev_ops.ndo_set_rx_mode =
47389 tse_set_rx_mode_hashfilter;
47390 + pax_close_kernel();
47391
47392 /* Scatter/gather IO is not supported,
47393 * so it is turned off
47394 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47395 index caade30..3e257d9 100644
47396 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47397 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47398 @@ -1072,14 +1072,14 @@ do { \
47399 * operations, everything works on mask values.
47400 */
47401 #define XMDIO_READ(_pdata, _mmd, _reg) \
47402 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47403 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47404 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47405
47406 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47407 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47408
47409 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47410 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47411 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47412 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47413
47414 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47415 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47416 index 8a50b01..39c1ad0 100644
47417 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47418 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47419 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47420
47421 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47422
47423 - pdata->hw_if.config_dcb_tc(pdata);
47424 + pdata->hw_if->config_dcb_tc(pdata);
47425
47426 return 0;
47427 }
47428 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47429
47430 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47431
47432 - pdata->hw_if.config_dcb_pfc(pdata);
47433 + pdata->hw_if->config_dcb_pfc(pdata);
47434
47435 return 0;
47436 }
47437 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47438 index 6fc5da0..61ac2cb 100644
47439 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47440 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47441 @@ -235,7 +235,7 @@ err_ring:
47442
47443 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47444 {
47445 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47446 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47447 struct xgbe_channel *channel;
47448 struct xgbe_ring *ring;
47449 struct xgbe_ring_data *rdata;
47450 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47451
47452 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47453 {
47454 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47455 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47456 struct xgbe_channel *channel;
47457 struct xgbe_ring *ring;
47458 struct xgbe_ring_desc *rdesc;
47459 @@ -505,7 +505,7 @@ err_out:
47460 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47461 {
47462 struct xgbe_prv_data *pdata = channel->pdata;
47463 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47464 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47465 struct xgbe_ring *ring = channel->rx_ring;
47466 struct xgbe_ring_data *rdata;
47467 struct sk_buff *skb = NULL;
47468 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47469 DBGPR("<--xgbe_realloc_skb\n");
47470 }
47471
47472 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47473 -{
47474 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47475 -
47476 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47477 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47478 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47479 - desc_if->realloc_skb = xgbe_realloc_skb;
47480 - desc_if->unmap_skb = xgbe_unmap_skb;
47481 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47482 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47483 -
47484 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47485 -}
47486 +const struct xgbe_desc_if default_xgbe_desc_if = {
47487 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47488 + .free_ring_resources = xgbe_free_ring_resources,
47489 + .map_tx_skb = xgbe_map_tx_skb,
47490 + .realloc_skb = xgbe_realloc_skb,
47491 + .unmap_skb = xgbe_unmap_skb,
47492 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47493 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47494 +};
47495 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47496 index 9da3a03..022f15c 100644
47497 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47498 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47499 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47500
47501 static int xgbe_init(struct xgbe_prv_data *pdata)
47502 {
47503 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47504 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47505 int ret;
47506
47507 DBGPR("-->xgbe_init\n");
47508 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47509 return 0;
47510 }
47511
47512 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47513 -{
47514 - DBGPR("-->xgbe_init_function_ptrs\n");
47515 -
47516 - hw_if->tx_complete = xgbe_tx_complete;
47517 -
47518 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47519 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47520 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47521 - hw_if->set_mac_address = xgbe_set_mac_address;
47522 -
47523 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47524 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47525 -
47526 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47527 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47528 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47529 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47530 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47531 -
47532 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47533 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47534 -
47535 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47536 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47537 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47538 -
47539 - hw_if->enable_tx = xgbe_enable_tx;
47540 - hw_if->disable_tx = xgbe_disable_tx;
47541 - hw_if->enable_rx = xgbe_enable_rx;
47542 - hw_if->disable_rx = xgbe_disable_rx;
47543 -
47544 - hw_if->powerup_tx = xgbe_powerup_tx;
47545 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47546 - hw_if->powerup_rx = xgbe_powerup_rx;
47547 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47548 -
47549 - hw_if->pre_xmit = xgbe_pre_xmit;
47550 - hw_if->dev_read = xgbe_dev_read;
47551 - hw_if->enable_int = xgbe_enable_int;
47552 - hw_if->disable_int = xgbe_disable_int;
47553 - hw_if->init = xgbe_init;
47554 - hw_if->exit = xgbe_exit;
47555 +const struct xgbe_hw_if default_xgbe_hw_if = {
47556 + .tx_complete = xgbe_tx_complete,
47557 +
47558 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47559 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47560 + .add_mac_addresses = xgbe_add_mac_addresses,
47561 + .set_mac_address = xgbe_set_mac_address,
47562 +
47563 + .enable_rx_csum = xgbe_enable_rx_csum,
47564 + .disable_rx_csum = xgbe_disable_rx_csum,
47565 +
47566 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47567 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47568 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47569 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47570 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47571 +
47572 + .read_mmd_regs = xgbe_read_mmd_regs,
47573 + .write_mmd_regs = xgbe_write_mmd_regs,
47574 +
47575 + .set_gmii_speed = xgbe_set_gmii_speed,
47576 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47577 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47578 +
47579 + .enable_tx = xgbe_enable_tx,
47580 + .disable_tx = xgbe_disable_tx,
47581 + .enable_rx = xgbe_enable_rx,
47582 + .disable_rx = xgbe_disable_rx,
47583 +
47584 + .powerup_tx = xgbe_powerup_tx,
47585 + .powerdown_tx = xgbe_powerdown_tx,
47586 + .powerup_rx = xgbe_powerup_rx,
47587 + .powerdown_rx = xgbe_powerdown_rx,
47588 +
47589 + .pre_xmit = xgbe_pre_xmit,
47590 + .dev_read = xgbe_dev_read,
47591 + .enable_int = xgbe_enable_int,
47592 + .disable_int = xgbe_disable_int,
47593 + .init = xgbe_init,
47594 + .exit = xgbe_exit,
47595
47596 /* Descriptor related Sequences have to be initialized here */
47597 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47598 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47599 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47600 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47601 - hw_if->is_last_desc = xgbe_is_last_desc;
47602 - hw_if->is_context_desc = xgbe_is_context_desc;
47603 + .tx_desc_init = xgbe_tx_desc_init,
47604 + .rx_desc_init = xgbe_rx_desc_init,
47605 + .tx_desc_reset = xgbe_tx_desc_reset,
47606 + .rx_desc_reset = xgbe_rx_desc_reset,
47607 + .is_last_desc = xgbe_is_last_desc,
47608 + .is_context_desc = xgbe_is_context_desc,
47609
47610 /* For FLOW ctrl */
47611 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47612 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47613 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47614 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47615
47616 /* For RX coalescing */
47617 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47618 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47619 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47620 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47621 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47622 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47623 + .usec_to_riwt = xgbe_usec_to_riwt,
47624 + .riwt_to_usec = xgbe_riwt_to_usec,
47625
47626 /* For RX and TX threshold config */
47627 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47628 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47629 + .config_rx_threshold = xgbe_config_rx_threshold,
47630 + .config_tx_threshold = xgbe_config_tx_threshold,
47631
47632 /* For RX and TX Store and Forward Mode config */
47633 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47634 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47635 + .config_rsf_mode = xgbe_config_rsf_mode,
47636 + .config_tsf_mode = xgbe_config_tsf_mode,
47637
47638 /* For TX DMA Operating on Second Frame config */
47639 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47640 + .config_osp_mode = xgbe_config_osp_mode,
47641
47642 /* For RX and TX PBL config */
47643 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47644 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47645 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47646 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47647 - hw_if->config_pblx8 = xgbe_config_pblx8;
47648 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47649 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47650 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47651 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47652 + .config_pblx8 = xgbe_config_pblx8,
47653
47654 /* For MMC statistics support */
47655 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47656 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47657 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47658 + .tx_mmc_int = xgbe_tx_mmc_int,
47659 + .rx_mmc_int = xgbe_rx_mmc_int,
47660 + .read_mmc_stats = xgbe_read_mmc_stats,
47661
47662 /* For PTP config */
47663 - hw_if->config_tstamp = xgbe_config_tstamp;
47664 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47665 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47666 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47667 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47668 + .config_tstamp = xgbe_config_tstamp,
47669 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47670 + .set_tstamp_time = xgbe_set_tstamp_time,
47671 + .get_tstamp_time = xgbe_get_tstamp_time,
47672 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47673
47674 /* For Data Center Bridging config */
47675 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47676 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47677 -
47678 - DBGPR("<--xgbe_init_function_ptrs\n");
47679 -}
47680 + .config_dcb_tc = xgbe_config_dcb_tc,
47681 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47682 +};
47683 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47684 index 2349ea9..a83a677 100644
47685 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47686 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47687 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47688
47689 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47690 {
47691 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47692 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47693 struct xgbe_channel *channel;
47694 enum xgbe_int int_id;
47695 unsigned int i;
47696 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47697
47698 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47699 {
47700 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47701 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47702 struct xgbe_channel *channel;
47703 enum xgbe_int int_id;
47704 unsigned int i;
47705 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47706 static irqreturn_t xgbe_isr(int irq, void *data)
47707 {
47708 struct xgbe_prv_data *pdata = data;
47709 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47710 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47711 struct xgbe_channel *channel;
47712 unsigned int dma_isr, dma_ch_isr;
47713 unsigned int mac_isr, mac_tssr;
47714 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47715
47716 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47717 {
47718 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47719 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47720
47721 DBGPR("-->xgbe_init_tx_coalesce\n");
47722
47723 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47724
47725 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47726 {
47727 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47728 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47729
47730 DBGPR("-->xgbe_init_rx_coalesce\n");
47731
47732 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47733
47734 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47735 {
47736 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47737 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47738 struct xgbe_channel *channel;
47739 struct xgbe_ring *ring;
47740 struct xgbe_ring_data *rdata;
47741 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47742
47743 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47744 {
47745 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47746 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47747 struct xgbe_channel *channel;
47748 struct xgbe_ring *ring;
47749 struct xgbe_ring_data *rdata;
47750 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47751 static void xgbe_adjust_link(struct net_device *netdev)
47752 {
47753 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47754 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47755 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47756 struct phy_device *phydev = pdata->phydev;
47757 int new_state = 0;
47758
47759 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47760 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47761 {
47762 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47763 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47764 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47765 unsigned long flags;
47766
47767 DBGPR("-->xgbe_powerdown\n");
47768 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47769 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47770 {
47771 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47772 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47773 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47774 unsigned long flags;
47775
47776 DBGPR("-->xgbe_powerup\n");
47777 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47778
47779 static int xgbe_start(struct xgbe_prv_data *pdata)
47780 {
47781 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47782 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47783 struct net_device *netdev = pdata->netdev;
47784
47785 DBGPR("-->xgbe_start\n");
47786 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47787
47788 static void xgbe_stop(struct xgbe_prv_data *pdata)
47789 {
47790 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47791 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47792 struct net_device *netdev = pdata->netdev;
47793
47794 DBGPR("-->xgbe_stop\n");
47795 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47796
47797 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47798 {
47799 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47800 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47801
47802 DBGPR("-->xgbe_restart_dev\n");
47803
47804 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47805 return -ERANGE;
47806 }
47807
47808 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47809 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47810
47811 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47812
47813 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47814 static int xgbe_open(struct net_device *netdev)
47815 {
47816 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47817 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47818 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47819 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47820 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47821 int ret;
47822
47823 DBGPR("-->xgbe_open\n");
47824 @@ -1170,8 +1170,8 @@ err_phy_init:
47825 static int xgbe_close(struct net_device *netdev)
47826 {
47827 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47828 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47829 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47830 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47831 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47832
47833 DBGPR("-->xgbe_close\n");
47834
47835 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47836 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47837 {
47838 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47839 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47840 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47841 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47842 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47843 struct xgbe_channel *channel;
47844 struct xgbe_ring *ring;
47845 struct xgbe_packet_data *packet;
47846 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47847 static void xgbe_set_rx_mode(struct net_device *netdev)
47848 {
47849 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47850 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47851 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47852 unsigned int pr_mode, am_mode;
47853
47854 DBGPR("-->xgbe_set_rx_mode\n");
47855 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47856 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47857 {
47858 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47859 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47860 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47861 struct sockaddr *saddr = addr;
47862
47863 DBGPR("-->xgbe_set_mac_address\n");
47864 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47865
47866 DBGPR("-->%s\n", __func__);
47867
47868 - pdata->hw_if.read_mmc_stats(pdata);
47869 + pdata->hw_if->read_mmc_stats(pdata);
47870
47871 s->rx_packets = pstats->rxframecount_gb;
47872 s->rx_bytes = pstats->rxoctetcount_gb;
47873 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47874 u16 vid)
47875 {
47876 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47877 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47878 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47879
47880 DBGPR("-->%s\n", __func__);
47881
47882 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47883 u16 vid)
47884 {
47885 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47886 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47887 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47888
47889 DBGPR("-->%s\n", __func__);
47890
47891 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47892 netdev_features_t features)
47893 {
47894 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47895 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47896 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47897 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47898
47899 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47900 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47901 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47902 {
47903 struct xgbe_prv_data *pdata = channel->pdata;
47904 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47905 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47906 struct xgbe_ring *ring = channel->rx_ring;
47907 struct xgbe_ring_data *rdata;
47908
47909 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47910 static int xgbe_tx_poll(struct xgbe_channel *channel)
47911 {
47912 struct xgbe_prv_data *pdata = channel->pdata;
47913 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47914 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47915 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47916 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47917 struct xgbe_ring *ring = channel->tx_ring;
47918 struct xgbe_ring_data *rdata;
47919 struct xgbe_ring_desc *rdesc;
47920 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47921 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47922 {
47923 struct xgbe_prv_data *pdata = channel->pdata;
47924 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47925 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47926 struct xgbe_ring *ring = channel->rx_ring;
47927 struct xgbe_ring_data *rdata;
47928 struct xgbe_packet_data *packet;
47929 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47930 index 49508ec..2617cca 100644
47931 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47932 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47933 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47934
47935 DBGPR("-->%s\n", __func__);
47936
47937 - pdata->hw_if.read_mmc_stats(pdata);
47938 + pdata->hw_if->read_mmc_stats(pdata);
47939 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47940 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47941 *data++ = *(u64 *)stat;
47942 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47943 struct ethtool_coalesce *ec)
47944 {
47945 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47946 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47947 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47948 unsigned int riwt;
47949
47950 DBGPR("-->xgbe_get_coalesce\n");
47951 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47952 struct ethtool_coalesce *ec)
47953 {
47954 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47955 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47956 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47957 unsigned int rx_frames, rx_riwt, rx_usecs;
47958 unsigned int tx_frames, tx_usecs;
47959
47960 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47961 index f5a8fa0..0bb58ff 100644
47962 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47963 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47964 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47965 DBGPR("<--xgbe_default_config\n");
47966 }
47967
47968 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47969 -{
47970 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47971 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47972 -}
47973 -
47974 static int xgbe_probe(struct platform_device *pdev)
47975 {
47976 struct xgbe_prv_data *pdata;
47977 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47978 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47979
47980 /* Set all the function pointers */
47981 - xgbe_init_all_fptrs(pdata);
47982 - hw_if = &pdata->hw_if;
47983 - desc_if = &pdata->desc_if;
47984 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47985 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47986
47987 /* Issue software reset to device */
47988 hw_if->exit(pdata);
47989 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47990 index 363b210..b241389 100644
47991 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47992 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47993 @@ -126,7 +126,7 @@
47994 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47995 {
47996 struct xgbe_prv_data *pdata = mii->priv;
47997 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47998 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47999 int mmd_data;
48000
48001 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48002 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48003 u16 mmd_val)
48004 {
48005 struct xgbe_prv_data *pdata = mii->priv;
48006 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48007 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48008 int mmd_data = mmd_val;
48009
48010 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48011 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48012 index a1bf9d1c..84adcab 100644
48013 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48014 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48015 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48016 tstamp_cc);
48017 u64 nsec;
48018
48019 - nsec = pdata->hw_if.get_tstamp_time(pdata);
48020 + nsec = pdata->hw_if->get_tstamp_time(pdata);
48021
48022 return nsec;
48023 }
48024 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48025
48026 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48027
48028 - pdata->hw_if.update_tstamp_addend(pdata, addend);
48029 + pdata->hw_if->update_tstamp_addend(pdata, addend);
48030
48031 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48032
48033 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48034 index 789957d..d7d0245 100644
48035 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48036 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48037 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
48038
48039 int irq_number;
48040
48041 - struct xgbe_hw_if hw_if;
48042 - struct xgbe_desc_if desc_if;
48043 + const struct xgbe_hw_if *hw_if;
48044 + const struct xgbe_desc_if *desc_if;
48045
48046 /* AXI DMA settings */
48047 unsigned int axdomain;
48048 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
48049 #endif
48050 };
48051
48052 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48053 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48054 +
48055 /* Function prototypes*/
48056
48057 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48058 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48059 index adcacda..fa6e0ae 100644
48060 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48061 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48062 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48063 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48064 {
48065 /* RX_MODE controlling object */
48066 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48067 + bnx2x_init_rx_mode_obj(bp);
48068
48069 /* multicast configuration controlling object */
48070 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48071 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48072 index 7bc2924..2112002 100644
48073 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48074 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48075 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48076 return rc;
48077 }
48078
48079 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48080 - struct bnx2x_rx_mode_obj *o)
48081 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48082 {
48083 if (CHIP_IS_E1x(bp)) {
48084 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48085 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48086 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48087 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48088 } else {
48089 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48090 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48091 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48092 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48093 }
48094 }
48095
48096 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48097 index e97275f..52e28bc 100644
48098 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48099 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48100 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48101
48102 /********************* RX MODE ****************/
48103
48104 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48105 - struct bnx2x_rx_mode_obj *o);
48106 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48107
48108 /**
48109 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48110 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48111 index 31c9f82..e65e986 100644
48112 --- a/drivers/net/ethernet/broadcom/tg3.h
48113 +++ b/drivers/net/ethernet/broadcom/tg3.h
48114 @@ -150,6 +150,7 @@
48115 #define CHIPREV_ID_5750_A0 0x4000
48116 #define CHIPREV_ID_5750_A1 0x4001
48117 #define CHIPREV_ID_5750_A3 0x4003
48118 +#define CHIPREV_ID_5750_C1 0x4201
48119 #define CHIPREV_ID_5750_C2 0x4202
48120 #define CHIPREV_ID_5752_A0_HW 0x5000
48121 #define CHIPREV_ID_5752_A0 0x6000
48122 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48123 index 903466e..b285864 100644
48124 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48125 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48126 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48127 }
48128
48129 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48130 - bna_cb_ioceth_enable,
48131 - bna_cb_ioceth_disable,
48132 - bna_cb_ioceth_hbfail,
48133 - bna_cb_ioceth_reset
48134 + .enable_cbfn = bna_cb_ioceth_enable,
48135 + .disable_cbfn = bna_cb_ioceth_disable,
48136 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48137 + .reset_cbfn = bna_cb_ioceth_reset
48138 };
48139
48140 static void bna_attr_init(struct bna_ioceth *ioceth)
48141 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48142 index 8cffcdf..aadf043 100644
48143 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48144 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48145 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48146 */
48147 struct l2t_skb_cb {
48148 arp_failure_handler_func arp_failure_handler;
48149 -};
48150 +} __no_const;
48151
48152 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48153
48154 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48155 index 279873c..11e1921 100644
48156 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48157 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48158 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48159
48160 int i;
48161 struct adapter *ap = netdev2adap(dev);
48162 - static const unsigned int *reg_ranges;
48163 + const unsigned int *reg_ranges;
48164 int arr_size = 0, buf_size = 0;
48165
48166 if (is_t4(ap->params.chip)) {
48167 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48168 index cf8b6ff..274271e 100644
48169 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48170 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48171 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48172 for (i=0; i<ETH_ALEN; i++) {
48173 tmp.addr[i] = dev->dev_addr[i];
48174 }
48175 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48176 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48177 break;
48178
48179 case DE4X5_SET_HWADDR: /* Set the hardware address */
48180 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48181 spin_lock_irqsave(&lp->lock, flags);
48182 memcpy(&statbuf, &lp->pktStats, ioc->len);
48183 spin_unlock_irqrestore(&lp->lock, flags);
48184 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48185 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48186 return -EFAULT;
48187 break;
48188 }
48189 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48190 index d2975fa..8aaec07 100644
48191 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48192 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48193 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48194
48195 if (wrapped)
48196 newacc += 65536;
48197 - ACCESS_ONCE(*acc) = newacc;
48198 + ACCESS_ONCE_RW(*acc) = newacc;
48199 }
48200
48201 static void populate_erx_stats(struct be_adapter *adapter,
48202 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48203 index c77fa4a..7fd42fc 100644
48204 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48205 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48206 @@ -30,6 +30,8 @@
48207 #include <linux/netdevice.h>
48208 #include <linux/phy.h>
48209 #include <linux/platform_device.h>
48210 +#include <linux/interrupt.h>
48211 +#include <linux/irqreturn.h>
48212 #include <net/ip.h>
48213
48214 #include "ftgmac100.h"
48215 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48216 index 4ff1adc..0ea6bf4 100644
48217 --- a/drivers/net/ethernet/faraday/ftmac100.c
48218 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48219 @@ -31,6 +31,8 @@
48220 #include <linux/module.h>
48221 #include <linux/netdevice.h>
48222 #include <linux/platform_device.h>
48223 +#include <linux/interrupt.h>
48224 +#include <linux/irqreturn.h>
48225
48226 #include "ftmac100.h"
48227
48228 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48229 index 537b621..07f87ce 100644
48230 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48231 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48232 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48233 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48234
48235 /* Update the base adjustement value. */
48236 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48237 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48238 smp_mb(); /* Force the above update. */
48239 }
48240
48241 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48242 index 5fd4b52..87aa34b 100644
48243 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48244 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48245 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48246 }
48247
48248 /* update the base incval used to calculate frequency adjustment */
48249 - ACCESS_ONCE(adapter->base_incval) = incval;
48250 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48251 smp_mb();
48252
48253 /* need lock to prevent incorrect read while modifying cyclecounter */
48254 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48255 index 11ff28b..375d659 100644
48256 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48257 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48258 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48259 wmb();
48260
48261 /* we want to dirty this cache line once */
48262 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48263 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48264 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48265 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48266
48267 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48268
48269 diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
48270 index f5e4b82..db0c7a9 100644
48271 --- a/drivers/net/ethernet/neterion/s2io.c
48272 +++ b/drivers/net/ethernet/neterion/s2io.c
48273 @@ -6987,7 +6987,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48274 if (sp->s2io_entries[i].in_use == MSIX_FLG) {
48275 if (sp->s2io_entries[i].type ==
48276 MSIX_RING_TYPE) {
48277 - sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
48278 + snprintf(sp->desc[i],
48279 + sizeof(sp->desc[i]),
48280 + "%s:MSI-X-%d-RX",
48281 dev->name, i);
48282 err = request_irq(sp->entries[i].vector,
48283 s2io_msix_ring_handle,
48284 @@ -6996,7 +6998,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48285 sp->s2io_entries[i].arg);
48286 } else if (sp->s2io_entries[i].type ==
48287 MSIX_ALARM_TYPE) {
48288 - sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
48289 + snprintf(sp->desc[i],
48290 + sizeof(sp->desc[i]),
48291 + "%s:MSI-X-%d-TX",
48292 dev->name, i);
48293 err = request_irq(sp->entries[i].vector,
48294 s2io_msix_fifo_handle,
48295 @@ -8154,7 +8158,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
48296 "%s: UDP Fragmentation Offload(UFO) enabled\n",
48297 dev->name);
48298 /* Initialize device name */
48299 - sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
48300 + snprintf(sp->name, sizeof(sp->name), "%s Neterion %s", dev->name,
48301 + sp->product_name);
48302
48303 if (vlan_tag_strip)
48304 sp->vlan_strip_flag = 1;
48305 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48306 index 2bbd01f..e8baa64 100644
48307 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48308 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48309 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48310 struct __vxge_hw_fifo *fifo;
48311 struct vxge_hw_fifo_config *config;
48312 u32 txdl_size, txdl_per_memblock;
48313 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48314 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48315 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48316 + };
48317 +
48318 struct __vxge_hw_virtualpath *vpath;
48319
48320 if ((vp == NULL) || (attr == NULL)) {
48321 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48322 goto exit;
48323 }
48324
48325 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48326 -
48327 fifo->mempool =
48328 __vxge_hw_mempool_create(vpath->hldev,
48329 fifo->config->memblock_size,
48330 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48331 index 2bb48d5..d1a865d 100644
48332 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48333 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48334 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48335 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48336 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48337 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48338 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48339 + pax_open_kernel();
48340 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48341 + pax_close_kernel();
48342 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48343 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48344 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48345 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48346 index be7d7a6..a8983f8 100644
48347 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48348 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48349 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48350 case QLCNIC_NON_PRIV_FUNC:
48351 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48352 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48353 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48354 + pax_open_kernel();
48355 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48356 + pax_close_kernel();
48357 break;
48358 case QLCNIC_PRIV_FUNC:
48359 ahw->op_mode = QLCNIC_PRIV_FUNC;
48360 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48361 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48362 + pax_open_kernel();
48363 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48364 + pax_close_kernel();
48365 break;
48366 case QLCNIC_MGMT_FUNC:
48367 ahw->op_mode = QLCNIC_MGMT_FUNC;
48368 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48369 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48370 + pax_open_kernel();
48371 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48372 + pax_close_kernel();
48373 break;
48374 default:
48375 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48376 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48377 index c9f57fb..208bdc1 100644
48378 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48379 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48380 @@ -1285,7 +1285,7 @@ flash_temp:
48381 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48382 {
48383 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48384 - static const struct qlcnic_dump_operations *fw_dump_ops;
48385 + const struct qlcnic_dump_operations *fw_dump_ops;
48386 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48387 u32 entry_offset, dump, no_entries, buf_offset = 0;
48388 int i, k, ops_cnt, ops_index, dump_size = 0;
48389 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48390 index cf154f7..c948d1b 100644
48391 --- a/drivers/net/ethernet/realtek/r8169.c
48392 +++ b/drivers/net/ethernet/realtek/r8169.c
48393 @@ -788,22 +788,22 @@ struct rtl8169_private {
48394 struct mdio_ops {
48395 void (*write)(struct rtl8169_private *, int, int);
48396 int (*read)(struct rtl8169_private *, int);
48397 - } mdio_ops;
48398 + } __no_const mdio_ops;
48399
48400 struct pll_power_ops {
48401 void (*down)(struct rtl8169_private *);
48402 void (*up)(struct rtl8169_private *);
48403 - } pll_power_ops;
48404 + } __no_const pll_power_ops;
48405
48406 struct jumbo_ops {
48407 void (*enable)(struct rtl8169_private *);
48408 void (*disable)(struct rtl8169_private *);
48409 - } jumbo_ops;
48410 + } __no_const jumbo_ops;
48411
48412 struct csi_ops {
48413 void (*write)(struct rtl8169_private *, int, int);
48414 u32 (*read)(struct rtl8169_private *, int);
48415 - } csi_ops;
48416 + } __no_const csi_ops;
48417
48418 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48419 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48420 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48421 index 6b861e3..204ac86 100644
48422 --- a/drivers/net/ethernet/sfc/ptp.c
48423 +++ b/drivers/net/ethernet/sfc/ptp.c
48424 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48425 ptp->start.dma_addr);
48426
48427 /* Clear flag that signals MC ready */
48428 - ACCESS_ONCE(*start) = 0;
48429 + ACCESS_ONCE_RW(*start) = 0;
48430 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48431 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48432 EFX_BUG_ON_PARANOID(rc);
48433 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48434 index 08c483b..2c4a553 100644
48435 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48436 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48437 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48438
48439 writel(value, ioaddr + MMC_CNTRL);
48440
48441 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48442 - MMC_CNTRL, value);
48443 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48444 +// MMC_CNTRL, value);
48445 }
48446
48447 /* To mask all all interrupts.*/
48448 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48449 index 2f48f79..8ae1a1a 100644
48450 --- a/drivers/net/hyperv/hyperv_net.h
48451 +++ b/drivers/net/hyperv/hyperv_net.h
48452 @@ -171,7 +171,7 @@ struct rndis_device {
48453 enum rndis_device_state state;
48454 bool link_state;
48455 bool link_change;
48456 - atomic_t new_req_id;
48457 + atomic_unchecked_t new_req_id;
48458
48459 spinlock_t request_lock;
48460 struct list_head req_list;
48461 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48462 index 2b86f0b..ecc996f 100644
48463 --- a/drivers/net/hyperv/rndis_filter.c
48464 +++ b/drivers/net/hyperv/rndis_filter.c
48465 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48466 * template
48467 */
48468 set = &rndis_msg->msg.set_req;
48469 - set->req_id = atomic_inc_return(&dev->new_req_id);
48470 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48471
48472 /* Add to the request list */
48473 spin_lock_irqsave(&dev->request_lock, flags);
48474 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48475
48476 /* Setup the rndis set */
48477 halt = &request->request_msg.msg.halt_req;
48478 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48479 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48480
48481 /* Ignore return since this msg is optional. */
48482 rndis_filter_send_request(dev, request);
48483 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48484 index 6cbc56a..5f7e6c8 100644
48485 --- a/drivers/net/ieee802154/fakehard.c
48486 +++ b/drivers/net/ieee802154/fakehard.c
48487 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48488 phy->transmit_power = 0xbf;
48489
48490 dev->netdev_ops = &fake_ops;
48491 - dev->ml_priv = &fake_mlme;
48492 + dev->ml_priv = (void *)&fake_mlme;
48493
48494 priv = netdev_priv(dev);
48495 priv->phy = phy;
48496 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48497 index 34f846b..4a0d5b1 100644
48498 --- a/drivers/net/ifb.c
48499 +++ b/drivers/net/ifb.c
48500 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48501 return 0;
48502 }
48503
48504 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48505 +static struct rtnl_link_ops ifb_link_ops = {
48506 .kind = "ifb",
48507 .priv_size = sizeof(struct ifb_private),
48508 .setup = ifb_setup,
48509 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48510 index bfb0b6e..5c396ce 100644
48511 --- a/drivers/net/macvlan.c
48512 +++ b/drivers/net/macvlan.c
48513 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48514 free_nskb:
48515 kfree_skb(nskb);
48516 err:
48517 - atomic_long_inc(&skb->dev->rx_dropped);
48518 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48519 }
48520
48521 static void macvlan_flush_sources(struct macvlan_port *port,
48522 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48523 int macvlan_link_register(struct rtnl_link_ops *ops)
48524 {
48525 /* common fields */
48526 - ops->priv_size = sizeof(struct macvlan_dev);
48527 - ops->validate = macvlan_validate;
48528 - ops->maxtype = IFLA_MACVLAN_MAX;
48529 - ops->policy = macvlan_policy;
48530 - ops->changelink = macvlan_changelink;
48531 - ops->get_size = macvlan_get_size;
48532 - ops->fill_info = macvlan_fill_info;
48533 + pax_open_kernel();
48534 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48535 + *(void **)&ops->validate = macvlan_validate;
48536 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48537 + *(const void **)&ops->policy = macvlan_policy;
48538 + *(void **)&ops->changelink = macvlan_changelink;
48539 + *(void **)&ops->get_size = macvlan_get_size;
48540 + *(void **)&ops->fill_info = macvlan_fill_info;
48541 + pax_close_kernel();
48542
48543 return rtnl_link_register(ops);
48544 };
48545 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48546 return NOTIFY_DONE;
48547 }
48548
48549 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48550 +static struct notifier_block macvlan_notifier_block = {
48551 .notifier_call = macvlan_device_event,
48552 };
48553
48554 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48555 index 880cc09..6a68ba6 100644
48556 --- a/drivers/net/macvtap.c
48557 +++ b/drivers/net/macvtap.c
48558 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48559 dev->tx_queue_len = TUN_READQ_SIZE;
48560 }
48561
48562 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48563 +static struct rtnl_link_ops macvtap_link_ops = {
48564 .kind = "macvtap",
48565 .setup = macvtap_setup,
48566 .newlink = macvtap_newlink,
48567 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48568 }
48569
48570 ret = 0;
48571 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48572 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48573 put_user(q->flags, &ifr->ifr_flags))
48574 ret = -EFAULT;
48575 macvtap_put_vlan(vlan);
48576 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48577 return NOTIFY_DONE;
48578 }
48579
48580 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48581 +static struct notifier_block macvtap_notifier_block = {
48582 .notifier_call = macvtap_device_event,
48583 };
48584
48585 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48586 index 34924df..a747360 100644
48587 --- a/drivers/net/nlmon.c
48588 +++ b/drivers/net/nlmon.c
48589 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48590 return 0;
48591 }
48592
48593 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48594 +static struct rtnl_link_ops nlmon_link_ops = {
48595 .kind = "nlmon",
48596 .priv_size = sizeof(struct nlmon),
48597 .setup = nlmon_setup,
48598 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48599 index 794a473..9fd437b 100644
48600 --- a/drivers/net/ppp/ppp_generic.c
48601 +++ b/drivers/net/ppp/ppp_generic.c
48602 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48603 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48604 struct ppp_stats stats;
48605 struct ppp_comp_stats cstats;
48606 - char *vers;
48607
48608 switch (cmd) {
48609 case SIOCGPPPSTATS:
48610 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48611 break;
48612
48613 case SIOCGPPPVER:
48614 - vers = PPP_VERSION;
48615 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48616 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48617 break;
48618 err = 0;
48619 break;
48620 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48621 index 079f7ad..b2a2bfa7 100644
48622 --- a/drivers/net/slip/slhc.c
48623 +++ b/drivers/net/slip/slhc.c
48624 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48625 register struct tcphdr *thp;
48626 register struct iphdr *ip;
48627 register struct cstate *cs;
48628 - int len, hdrlen;
48629 + long len, hdrlen;
48630 unsigned char *cp = icp;
48631
48632 /* We've got a compressed packet; read the change byte */
48633 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48634 index 9c505c4..5d0c879 100644
48635 --- a/drivers/net/team/team.c
48636 +++ b/drivers/net/team/team.c
48637 @@ -2102,7 +2102,7 @@ static unsigned int team_get_num_rx_queues(void)
48638 return TEAM_DEFAULT_NUM_RX_QUEUES;
48639 }
48640
48641 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48642 +static struct rtnl_link_ops team_link_ops = {
48643 .kind = DRV_NAME,
48644 .priv_size = sizeof(struct team),
48645 .setup = team_setup,
48646 @@ -2892,7 +2892,7 @@ static int team_device_event(struct notifier_block *unused,
48647 return NOTIFY_DONE;
48648 }
48649
48650 -static struct notifier_block team_notifier_block __read_mostly = {
48651 +static struct notifier_block team_notifier_block = {
48652 .notifier_call = team_device_event,
48653 };
48654
48655 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48656 index 9dd3746..74f191e 100644
48657 --- a/drivers/net/tun.c
48658 +++ b/drivers/net/tun.c
48659 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48660 return -EINVAL;
48661 }
48662
48663 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48664 +static struct rtnl_link_ops tun_link_ops = {
48665 .kind = DRV_NAME,
48666 .priv_size = sizeof(struct tun_struct),
48667 .setup = tun_setup,
48668 @@ -1868,7 +1868,7 @@ unlock:
48669 }
48670
48671 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48672 - unsigned long arg, int ifreq_len)
48673 + unsigned long arg, size_t ifreq_len)
48674 {
48675 struct tun_file *tfile = file->private_data;
48676 struct tun_struct *tun;
48677 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48678 unsigned int ifindex;
48679 int ret;
48680
48681 + if (ifreq_len > sizeof ifr)
48682 + return -EFAULT;
48683 +
48684 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48685 if (copy_from_user(&ifr, argp, ifreq_len))
48686 return -EFAULT;
48687 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48688 index babda7d..e40c90a 100644
48689 --- a/drivers/net/usb/hso.c
48690 +++ b/drivers/net/usb/hso.c
48691 @@ -71,7 +71,7 @@
48692 #include <asm/byteorder.h>
48693 #include <linux/serial_core.h>
48694 #include <linux/serial.h>
48695 -
48696 +#include <asm/local.h>
48697
48698 #define MOD_AUTHOR "Option Wireless"
48699 #define MOD_DESCRIPTION "USB High Speed Option driver"
48700 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48701 struct urb *urb;
48702
48703 urb = serial->rx_urb[0];
48704 - if (serial->port.count > 0) {
48705 + if (atomic_read(&serial->port.count) > 0) {
48706 count = put_rxbuf_data(urb, serial);
48707 if (count == -1)
48708 return;
48709 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48710 DUMP1(urb->transfer_buffer, urb->actual_length);
48711
48712 /* Anyone listening? */
48713 - if (serial->port.count == 0)
48714 + if (atomic_read(&serial->port.count) == 0)
48715 return;
48716
48717 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48718 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48719 tty_port_tty_set(&serial->port, tty);
48720
48721 /* check for port already opened, if not set the termios */
48722 - serial->port.count++;
48723 - if (serial->port.count == 1) {
48724 + if (atomic_inc_return(&serial->port.count) == 1) {
48725 serial->rx_state = RX_IDLE;
48726 /* Force default termio settings */
48727 _hso_serial_set_termios(tty, NULL);
48728 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48729 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48730 if (result) {
48731 hso_stop_serial_device(serial->parent);
48732 - serial->port.count--;
48733 + atomic_dec(&serial->port.count);
48734 kref_put(&serial->parent->ref, hso_serial_ref_free);
48735 }
48736 } else {
48737 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48738
48739 /* reset the rts and dtr */
48740 /* do the actual close */
48741 - serial->port.count--;
48742 + atomic_dec(&serial->port.count);
48743
48744 - if (serial->port.count <= 0) {
48745 - serial->port.count = 0;
48746 + if (atomic_read(&serial->port.count) <= 0) {
48747 + atomic_set(&serial->port.count, 0);
48748 tty_port_tty_set(&serial->port, NULL);
48749 if (!usb_gone)
48750 hso_stop_serial_device(serial->parent);
48751 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48752
48753 /* the actual setup */
48754 spin_lock_irqsave(&serial->serial_lock, flags);
48755 - if (serial->port.count)
48756 + if (atomic_read(&serial->port.count))
48757 _hso_serial_set_termios(tty, old);
48758 else
48759 tty->termios = *old;
48760 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48761 D1("Pending read interrupt on port %d\n", i);
48762 spin_lock(&serial->serial_lock);
48763 if (serial->rx_state == RX_IDLE &&
48764 - serial->port.count > 0) {
48765 + atomic_read(&serial->port.count) > 0) {
48766 /* Setup and send a ctrl req read on
48767 * port i */
48768 if (!serial->rx_urb_filled[0]) {
48769 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48770 /* Start all serial ports */
48771 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48772 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48773 - if (dev2ser(serial_table[i])->port.count) {
48774 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48775 result =
48776 hso_start_serial_device(serial_table[i], GFP_NOIO);
48777 hso_kick_transmit(dev2ser(serial_table[i]));
48778 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48779 index c6554c7..7e2ebd7 100644
48780 --- a/drivers/net/usb/r8152.c
48781 +++ b/drivers/net/usb/r8152.c
48782 @@ -577,7 +577,7 @@ struct r8152 {
48783 void (*unload)(struct r8152 *);
48784 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48785 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48786 - } rtl_ops;
48787 + } __no_const rtl_ops;
48788
48789 int intr_interval;
48790 u32 saved_wolopts;
48791 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48792 index a2515887..6d13233 100644
48793 --- a/drivers/net/usb/sierra_net.c
48794 +++ b/drivers/net/usb/sierra_net.c
48795 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48796 /* atomic counter partially included in MAC address to make sure 2 devices
48797 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48798 */
48799 -static atomic_t iface_counter = ATOMIC_INIT(0);
48800 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48801
48802 /*
48803 * SYNC Timer Delay definition used to set the expiry time
48804 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48805 dev->net->netdev_ops = &sierra_net_device_ops;
48806
48807 /* change MAC addr to include, ifacenum, and to be unique */
48808 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48809 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48810 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48811
48812 /* we will have to manufacture ethernet headers, prepare template */
48813 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48814 index b0bc8ea..3af931b5 100644
48815 --- a/drivers/net/virtio_net.c
48816 +++ b/drivers/net/virtio_net.c
48817 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48818 #define RECEIVE_AVG_WEIGHT 64
48819
48820 /* Minimum alignment for mergeable packet buffers. */
48821 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48822 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48823
48824 #define VIRTNET_DRIVER_VERSION "1.0.0"
48825
48826 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48827 index 42b2d6a5..2a2cb41 100644
48828 --- a/drivers/net/vxlan.c
48829 +++ b/drivers/net/vxlan.c
48830 @@ -2695,7 +2695,7 @@ nla_put_failure:
48831 return -EMSGSIZE;
48832 }
48833
48834 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48835 +static struct rtnl_link_ops vxlan_link_ops = {
48836 .kind = "vxlan",
48837 .maxtype = IFLA_VXLAN_MAX,
48838 .policy = vxlan_policy,
48839 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48840 return NOTIFY_DONE;
48841 }
48842
48843 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48844 +static struct notifier_block vxlan_notifier_block = {
48845 .notifier_call = vxlan_lowerdev_event,
48846 };
48847
48848 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48849 index 5920c99..ff2e4a5 100644
48850 --- a/drivers/net/wan/lmc/lmc_media.c
48851 +++ b/drivers/net/wan/lmc/lmc_media.c
48852 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48853 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48854
48855 lmc_media_t lmc_ds3_media = {
48856 - lmc_ds3_init, /* special media init stuff */
48857 - lmc_ds3_default, /* reset to default state */
48858 - lmc_ds3_set_status, /* reset status to state provided */
48859 - lmc_dummy_set_1, /* set clock source */
48860 - lmc_dummy_set2_1, /* set line speed */
48861 - lmc_ds3_set_100ft, /* set cable length */
48862 - lmc_ds3_set_scram, /* set scrambler */
48863 - lmc_ds3_get_link_status, /* get link status */
48864 - lmc_dummy_set_1, /* set link status */
48865 - lmc_ds3_set_crc_length, /* set CRC length */
48866 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48867 - lmc_ds3_watchdog
48868 + .init = lmc_ds3_init, /* special media init stuff */
48869 + .defaults = lmc_ds3_default, /* reset to default state */
48870 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48871 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48872 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48873 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48874 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48875 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48876 + .set_link_status = lmc_dummy_set_1, /* set link status */
48877 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48878 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48879 + .watchdog = lmc_ds3_watchdog
48880 };
48881
48882 lmc_media_t lmc_hssi_media = {
48883 - lmc_hssi_init, /* special media init stuff */
48884 - lmc_hssi_default, /* reset to default state */
48885 - lmc_hssi_set_status, /* reset status to state provided */
48886 - lmc_hssi_set_clock, /* set clock source */
48887 - lmc_dummy_set2_1, /* set line speed */
48888 - lmc_dummy_set_1, /* set cable length */
48889 - lmc_dummy_set_1, /* set scrambler */
48890 - lmc_hssi_get_link_status, /* get link status */
48891 - lmc_hssi_set_link_status, /* set link status */
48892 - lmc_hssi_set_crc_length, /* set CRC length */
48893 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48894 - lmc_hssi_watchdog
48895 + .init = lmc_hssi_init, /* special media init stuff */
48896 + .defaults = lmc_hssi_default, /* reset to default state */
48897 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48898 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48899 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48900 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48901 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48902 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48903 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48904 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48905 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48906 + .watchdog = lmc_hssi_watchdog
48907 };
48908
48909 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48910 - lmc_ssi_default, /* reset to default state */
48911 - lmc_ssi_set_status, /* reset status to state provided */
48912 - lmc_ssi_set_clock, /* set clock source */
48913 - lmc_ssi_set_speed, /* set line speed */
48914 - lmc_dummy_set_1, /* set cable length */
48915 - lmc_dummy_set_1, /* set scrambler */
48916 - lmc_ssi_get_link_status, /* get link status */
48917 - lmc_ssi_set_link_status, /* set link status */
48918 - lmc_ssi_set_crc_length, /* set CRC length */
48919 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48920 - lmc_ssi_watchdog
48921 +lmc_media_t lmc_ssi_media = {
48922 + .init = lmc_ssi_init, /* special media init stuff */
48923 + .defaults = lmc_ssi_default, /* reset to default state */
48924 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48925 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48926 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48927 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48928 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48929 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48930 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48931 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48932 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48933 + .watchdog = lmc_ssi_watchdog
48934 };
48935
48936 lmc_media_t lmc_t1_media = {
48937 - lmc_t1_init, /* special media init stuff */
48938 - lmc_t1_default, /* reset to default state */
48939 - lmc_t1_set_status, /* reset status to state provided */
48940 - lmc_t1_set_clock, /* set clock source */
48941 - lmc_dummy_set2_1, /* set line speed */
48942 - lmc_dummy_set_1, /* set cable length */
48943 - lmc_dummy_set_1, /* set scrambler */
48944 - lmc_t1_get_link_status, /* get link status */
48945 - lmc_dummy_set_1, /* set link status */
48946 - lmc_t1_set_crc_length, /* set CRC length */
48947 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48948 - lmc_t1_watchdog
48949 + .init = lmc_t1_init, /* special media init stuff */
48950 + .defaults = lmc_t1_default, /* reset to default state */
48951 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48952 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48953 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48954 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48955 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48956 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48957 + .set_link_status = lmc_dummy_set_1, /* set link status */
48958 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48959 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48960 + .watchdog = lmc_t1_watchdog
48961 };
48962
48963 static void
48964 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48965 index feacc3b..5bac0de 100644
48966 --- a/drivers/net/wan/z85230.c
48967 +++ b/drivers/net/wan/z85230.c
48968 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48969
48970 struct z8530_irqhandler z8530_sync =
48971 {
48972 - z8530_rx,
48973 - z8530_tx,
48974 - z8530_status
48975 + .rx = z8530_rx,
48976 + .tx = z8530_tx,
48977 + .status = z8530_status
48978 };
48979
48980 EXPORT_SYMBOL(z8530_sync);
48981 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48982 }
48983
48984 static struct z8530_irqhandler z8530_dma_sync = {
48985 - z8530_dma_rx,
48986 - z8530_dma_tx,
48987 - z8530_dma_status
48988 + .rx = z8530_dma_rx,
48989 + .tx = z8530_dma_tx,
48990 + .status = z8530_dma_status
48991 };
48992
48993 static struct z8530_irqhandler z8530_txdma_sync = {
48994 - z8530_rx,
48995 - z8530_dma_tx,
48996 - z8530_dma_status
48997 + .rx = z8530_rx,
48998 + .tx = z8530_dma_tx,
48999 + .status = z8530_dma_status
49000 };
49001
49002 /**
49003 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49004
49005 struct z8530_irqhandler z8530_nop=
49006 {
49007 - z8530_rx_clear,
49008 - z8530_tx_clear,
49009 - z8530_status_clear
49010 + .rx = z8530_rx_clear,
49011 + .tx = z8530_tx_clear,
49012 + .status = z8530_status_clear
49013 };
49014
49015
49016 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49017 index 0b60295..b8bfa5b 100644
49018 --- a/drivers/net/wimax/i2400m/rx.c
49019 +++ b/drivers/net/wimax/i2400m/rx.c
49020 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49021 if (i2400m->rx_roq == NULL)
49022 goto error_roq_alloc;
49023
49024 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49025 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49026 GFP_KERNEL);
49027 if (rd == NULL) {
49028 result = -ENOMEM;
49029 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49030 index e71a2ce..2268d61 100644
49031 --- a/drivers/net/wireless/airo.c
49032 +++ b/drivers/net/wireless/airo.c
49033 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49034 struct airo_info *ai = dev->ml_priv;
49035 int ridcode;
49036 int enabled;
49037 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49038 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49039 unsigned char *iobuf;
49040
49041 /* Only super-user can write RIDs */
49042 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49043 index da92bfa..5a9001a 100644
49044 --- a/drivers/net/wireless/at76c50x-usb.c
49045 +++ b/drivers/net/wireless/at76c50x-usb.c
49046 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49047 }
49048
49049 /* Convert timeout from the DFU status to jiffies */
49050 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49051 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49052 {
49053 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49054 | (s->poll_timeout[1] << 8)
49055 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49056 index 676bd4e..0b807a3 100644
49057 --- a/drivers/net/wireless/ath/ath10k/htc.c
49058 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49059 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
49060 /* registered target arrival callback from the HIF layer */
49061 int ath10k_htc_init(struct ath10k *ar)
49062 {
49063 - struct ath10k_hif_cb htc_callbacks;
49064 + static struct ath10k_hif_cb htc_callbacks = {
49065 + .rx_completion = ath10k_htc_rx_completion_handler,
49066 + .tx_completion = ath10k_htc_tx_completion_handler,
49067 + };
49068 struct ath10k_htc_ep *ep = NULL;
49069 struct ath10k_htc *htc = &ar->htc;
49070
49071 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
49072 ath10k_htc_reset_endpoint_states(htc);
49073
49074 /* setup HIF layer callbacks */
49075 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49076 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49077 htc->ar = ar;
49078
49079 /* Get HIF default pipe for HTC message exchange */
49080 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49081 index 527179c..a890150 100644
49082 --- a/drivers/net/wireless/ath/ath10k/htc.h
49083 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49084 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
49085
49086 struct ath10k_htc_ops {
49087 void (*target_send_suspend_complete)(struct ath10k *ar);
49088 -};
49089 +} __no_const;
49090
49091 struct ath10k_htc_ep_ops {
49092 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49093 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49094 void (*ep_tx_credits)(struct ath10k *);
49095 -};
49096 +} __no_const;
49097
49098 /* service connection information */
49099 struct ath10k_htc_svc_conn_req {
49100 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49101 index 2a93519..7052786 100644
49102 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49103 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49104 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49105 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49106 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49107
49108 - ACCESS_ONCE(ads->ds_link) = i->link;
49109 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49110 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49111 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49112
49113 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49114 ctl6 = SM(i->keytype, AR_EncrType);
49115 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49116
49117 if ((i->is_first || i->is_last) &&
49118 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49119 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49120 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49121 | set11nTries(i->rates, 1)
49122 | set11nTries(i->rates, 2)
49123 | set11nTries(i->rates, 3)
49124 | (i->dur_update ? AR_DurUpdateEna : 0)
49125 | SM(0, AR_BurstDur);
49126
49127 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49128 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49129 | set11nRate(i->rates, 1)
49130 | set11nRate(i->rates, 2)
49131 | set11nRate(i->rates, 3);
49132 } else {
49133 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49134 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49135 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49136 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49137 }
49138
49139 if (!i->is_first) {
49140 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49141 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49142 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49143 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49144 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49145 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49146 return;
49147 }
49148
49149 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49150 break;
49151 }
49152
49153 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49154 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49155 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49156 | SM(i->txpower, AR_XmitPower0)
49157 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49158 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49159 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49160 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49161
49162 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49163 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49164 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49165 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49166
49167 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49168 return;
49169
49170 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49171 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49172 | set11nPktDurRTSCTS(i->rates, 1);
49173
49174 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49175 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49176 | set11nPktDurRTSCTS(i->rates, 3);
49177
49178 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49179 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49180 | set11nRateFlags(i->rates, 1)
49181 | set11nRateFlags(i->rates, 2)
49182 | set11nRateFlags(i->rates, 3)
49183 | SM(i->rtscts_rate, AR_RTSCTSRate);
49184
49185 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49186 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49187 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49188 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49189 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49190 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49191 }
49192
49193 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49194 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49195 index 057b165..98ae88f 100644
49196 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49197 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49198 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49199 (i->qcu << AR_TxQcuNum_S) | desc_len;
49200
49201 checksum += val;
49202 - ACCESS_ONCE(ads->info) = val;
49203 + ACCESS_ONCE_RW(ads->info) = val;
49204
49205 checksum += i->link;
49206 - ACCESS_ONCE(ads->link) = i->link;
49207 + ACCESS_ONCE_RW(ads->link) = i->link;
49208
49209 checksum += i->buf_addr[0];
49210 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49211 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49212 checksum += i->buf_addr[1];
49213 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49214 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49215 checksum += i->buf_addr[2];
49216 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49217 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49218 checksum += i->buf_addr[3];
49219 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49220 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49221
49222 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49223 - ACCESS_ONCE(ads->ctl3) = val;
49224 + ACCESS_ONCE_RW(ads->ctl3) = val;
49225 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49226 - ACCESS_ONCE(ads->ctl5) = val;
49227 + ACCESS_ONCE_RW(ads->ctl5) = val;
49228 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49229 - ACCESS_ONCE(ads->ctl7) = val;
49230 + ACCESS_ONCE_RW(ads->ctl7) = val;
49231 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49232 - ACCESS_ONCE(ads->ctl9) = val;
49233 + ACCESS_ONCE_RW(ads->ctl9) = val;
49234
49235 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49236 - ACCESS_ONCE(ads->ctl10) = checksum;
49237 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49238
49239 if (i->is_first || i->is_last) {
49240 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49241 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49242 | set11nTries(i->rates, 1)
49243 | set11nTries(i->rates, 2)
49244 | set11nTries(i->rates, 3)
49245 | (i->dur_update ? AR_DurUpdateEna : 0)
49246 | SM(0, AR_BurstDur);
49247
49248 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49249 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49250 | set11nRate(i->rates, 1)
49251 | set11nRate(i->rates, 2)
49252 | set11nRate(i->rates, 3);
49253 } else {
49254 - ACCESS_ONCE(ads->ctl13) = 0;
49255 - ACCESS_ONCE(ads->ctl14) = 0;
49256 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49257 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49258 }
49259
49260 ads->ctl20 = 0;
49261 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49262
49263 ctl17 = SM(i->keytype, AR_EncrType);
49264 if (!i->is_first) {
49265 - ACCESS_ONCE(ads->ctl11) = 0;
49266 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49267 - ACCESS_ONCE(ads->ctl15) = 0;
49268 - ACCESS_ONCE(ads->ctl16) = 0;
49269 - ACCESS_ONCE(ads->ctl17) = ctl17;
49270 - ACCESS_ONCE(ads->ctl18) = 0;
49271 - ACCESS_ONCE(ads->ctl19) = 0;
49272 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49273 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49274 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49275 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49276 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49277 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49278 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49279 return;
49280 }
49281
49282 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49283 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49284 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49285 | SM(i->txpower, AR_XmitPower0)
49286 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49287 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49288 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49289 ctl12 |= SM(val, AR_PAPRDChainMask);
49290
49291 - ACCESS_ONCE(ads->ctl12) = ctl12;
49292 - ACCESS_ONCE(ads->ctl17) = ctl17;
49293 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49294 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49295
49296 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49297 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49298 | set11nPktDurRTSCTS(i->rates, 1);
49299
49300 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49301 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49302 | set11nPktDurRTSCTS(i->rates, 3);
49303
49304 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49305 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49306 | set11nRateFlags(i->rates, 1)
49307 | set11nRateFlags(i->rates, 2)
49308 | set11nRateFlags(i->rates, 3)
49309 | SM(i->rtscts_rate, AR_RTSCTSRate);
49310
49311 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49312 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49313
49314 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49315 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49316 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49317 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49318 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49319 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49320 }
49321
49322 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49323 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49324 index e8e8dd2..030f80e 100644
49325 --- a/drivers/net/wireless/ath/ath9k/hw.h
49326 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49327 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49328
49329 /* ANI */
49330 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49331 -};
49332 +} __no_const;
49333
49334 /**
49335 * struct ath_spec_scan - parameters for Atheros spectral scan
49336 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49337 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49338 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49339 #endif
49340 -};
49341 +} __no_const;
49342
49343 struct ath_nf_limits {
49344 s16 max;
49345 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49346 index 4f18a6b..b07d92f 100644
49347 --- a/drivers/net/wireless/ath/ath9k/main.c
49348 +++ b/drivers/net/wireless/ath/ath9k/main.c
49349 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49350 if (!ath9k_is_chanctx_enabled())
49351 return;
49352
49353 - ath9k_ops.hw_scan = ath9k_hw_scan;
49354 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49355 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49356 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49357 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49358 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49359 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49360 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49361 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49362 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49363 + pax_open_kernel();
49364 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49365 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49366 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49367 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49368 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49369 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49370 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49371 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49372 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49373 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49374 + pax_close_kernel();
49375 }
49376
49377 #endif
49378 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49379 index 058a9f2..d5cb1ba 100644
49380 --- a/drivers/net/wireless/b43/phy_lp.c
49381 +++ b/drivers/net/wireless/b43/phy_lp.c
49382 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49383 {
49384 struct ssb_bus *bus = dev->dev->sdev->bus;
49385
49386 - static const struct b206x_channel *chandata = NULL;
49387 + const struct b206x_channel *chandata = NULL;
49388 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49389 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49390 u16 old_comm15, scale;
49391 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49392 index dc1d20c..f7a4f06 100644
49393 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49394 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49395 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49396 */
49397 if (il3945_mod_params.disable_hw_scan) {
49398 D_INFO("Disabling hw_scan\n");
49399 - il3945_mac_ops.hw_scan = NULL;
49400 + pax_open_kernel();
49401 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49402 + pax_close_kernel();
49403 }
49404
49405 D_INFO("*** LOAD DRIVER ***\n");
49406 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49407 index 0ffb6ff..c0b7f0e 100644
49408 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49409 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49410 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49411 {
49412 struct iwl_priv *priv = file->private_data;
49413 char buf[64];
49414 - int buf_size;
49415 + size_t buf_size;
49416 u32 offset, len;
49417
49418 memset(buf, 0, sizeof(buf));
49419 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49420 struct iwl_priv *priv = file->private_data;
49421
49422 char buf[8];
49423 - int buf_size;
49424 + size_t buf_size;
49425 u32 reset_flag;
49426
49427 memset(buf, 0, sizeof(buf));
49428 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49429 {
49430 struct iwl_priv *priv = file->private_data;
49431 char buf[8];
49432 - int buf_size;
49433 + size_t buf_size;
49434 int ht40;
49435
49436 memset(buf, 0, sizeof(buf));
49437 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49438 {
49439 struct iwl_priv *priv = file->private_data;
49440 char buf[8];
49441 - int buf_size;
49442 + size_t buf_size;
49443 int value;
49444
49445 memset(buf, 0, sizeof(buf));
49446 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49447 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49448 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49449
49450 -static const char *fmt_value = " %-30s %10u\n";
49451 -static const char *fmt_hex = " %-30s 0x%02X\n";
49452 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49453 -static const char *fmt_header =
49454 +static const char fmt_value[] = " %-30s %10u\n";
49455 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49456 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49457 +static const char fmt_header[] =
49458 "%-32s current cumulative delta max\n";
49459
49460 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49461 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49462 {
49463 struct iwl_priv *priv = file->private_data;
49464 char buf[8];
49465 - int buf_size;
49466 + size_t buf_size;
49467 int clear;
49468
49469 memset(buf, 0, sizeof(buf));
49470 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49471 {
49472 struct iwl_priv *priv = file->private_data;
49473 char buf[8];
49474 - int buf_size;
49475 + size_t buf_size;
49476 int trace;
49477
49478 memset(buf, 0, sizeof(buf));
49479 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49480 {
49481 struct iwl_priv *priv = file->private_data;
49482 char buf[8];
49483 - int buf_size;
49484 + size_t buf_size;
49485 int missed;
49486
49487 memset(buf, 0, sizeof(buf));
49488 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49489
49490 struct iwl_priv *priv = file->private_data;
49491 char buf[8];
49492 - int buf_size;
49493 + size_t buf_size;
49494 int plcp;
49495
49496 memset(buf, 0, sizeof(buf));
49497 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49498
49499 struct iwl_priv *priv = file->private_data;
49500 char buf[8];
49501 - int buf_size;
49502 + size_t buf_size;
49503 int flush;
49504
49505 memset(buf, 0, sizeof(buf));
49506 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49507
49508 struct iwl_priv *priv = file->private_data;
49509 char buf[8];
49510 - int buf_size;
49511 + size_t buf_size;
49512 int rts;
49513
49514 if (!priv->cfg->ht_params)
49515 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49516 {
49517 struct iwl_priv *priv = file->private_data;
49518 char buf[8];
49519 - int buf_size;
49520 + size_t buf_size;
49521
49522 memset(buf, 0, sizeof(buf));
49523 buf_size = min(count, sizeof(buf) - 1);
49524 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49525 struct iwl_priv *priv = file->private_data;
49526 u32 event_log_flag;
49527 char buf[8];
49528 - int buf_size;
49529 + size_t buf_size;
49530
49531 /* check that the interface is up */
49532 if (!iwl_is_ready(priv))
49533 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49534 struct iwl_priv *priv = file->private_data;
49535 char buf[8];
49536 u32 calib_disabled;
49537 - int buf_size;
49538 + size_t buf_size;
49539
49540 memset(buf, 0, sizeof(buf));
49541 buf_size = min(count, sizeof(buf) - 1);
49542 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49543 index dd2f3f8..fb1ae88 100644
49544 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49545 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49546 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49547 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49548
49549 char buf[8];
49550 - int buf_size;
49551 + size_t buf_size;
49552 u32 reset_flag;
49553
49554 memset(buf, 0, sizeof(buf));
49555 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49556 {
49557 struct iwl_trans *trans = file->private_data;
49558 char buf[8];
49559 - int buf_size;
49560 + size_t buf_size;
49561 int csr;
49562
49563 memset(buf, 0, sizeof(buf));
49564 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49565 index c9ad4cf..49a2fa0 100644
49566 --- a/drivers/net/wireless/mac80211_hwsim.c
49567 +++ b/drivers/net/wireless/mac80211_hwsim.c
49568 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49569 if (channels < 1)
49570 return -EINVAL;
49571
49572 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49573 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49574 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49575 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49576 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49577 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49578 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49579 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49580 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49581 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49582 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49583 - mac80211_hwsim_assign_vif_chanctx;
49584 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49585 - mac80211_hwsim_unassign_vif_chanctx;
49586 + pax_open_kernel();
49587 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49588 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49589 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49590 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49591 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49592 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49593 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49594 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49595 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49596 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49597 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49598 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49599 + pax_close_kernel();
49600
49601 spin_lock_init(&hwsim_radio_lock);
49602 INIT_LIST_HEAD(&hwsim_radios);
49603 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49604 index 1a4facd..a2ecbbd 100644
49605 --- a/drivers/net/wireless/rndis_wlan.c
49606 +++ b/drivers/net/wireless/rndis_wlan.c
49607 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49608
49609 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49610
49611 - if (rts_threshold < 0 || rts_threshold > 2347)
49612 + if (rts_threshold > 2347)
49613 rts_threshold = 2347;
49614
49615 tmp = cpu_to_le32(rts_threshold);
49616 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49617 index d13f25c..2573994 100644
49618 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49619 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49620 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49621 * for hardware which doesn't support hardware
49622 * sequence counting.
49623 */
49624 - atomic_t seqno;
49625 + atomic_unchecked_t seqno;
49626 };
49627
49628 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49629 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49630 index 66ff364..3ce34f7 100644
49631 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49632 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49633 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49634 * sequence counter given by mac80211.
49635 */
49636 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49637 - seqno = atomic_add_return(0x10, &intf->seqno);
49638 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49639 else
49640 - seqno = atomic_read(&intf->seqno);
49641 + seqno = atomic_read_unchecked(&intf->seqno);
49642
49643 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49644 hdr->seq_ctrl |= cpu_to_le16(seqno);
49645 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49646 index b661f896..ddf7d2b 100644
49647 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49648 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49649 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49650
49651 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49652
49653 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49654 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49655 + pax_open_kernel();
49656 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49657 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49658 + pax_close_kernel();
49659
49660 wl1251_info("using dedicated interrupt line");
49661 } else {
49662 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49663 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49664 + pax_open_kernel();
49665 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49666 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49667 + pax_close_kernel();
49668
49669 wl1251_info("using SDIO interrupt");
49670 }
49671 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49672 index 0bccf12..3d95068 100644
49673 --- a/drivers/net/wireless/ti/wl12xx/main.c
49674 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49675 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49676 sizeof(wl->conf.mem));
49677
49678 /* read data preparation is only needed by wl127x */
49679 - wl->ops->prepare_read = wl127x_prepare_read;
49680 + pax_open_kernel();
49681 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49682 + pax_close_kernel();
49683
49684 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49685 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49686 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49687 sizeof(wl->conf.mem));
49688
49689 /* read data preparation is only needed by wl127x */
49690 - wl->ops->prepare_read = wl127x_prepare_read;
49691 + pax_open_kernel();
49692 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49693 + pax_close_kernel();
49694
49695 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49696 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49697 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49698 index 7af1936..128bb35 100644
49699 --- a/drivers/net/wireless/ti/wl18xx/main.c
49700 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49701 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49702 }
49703
49704 if (!checksum_param) {
49705 - wl18xx_ops.set_rx_csum = NULL;
49706 - wl18xx_ops.init_vif = NULL;
49707 + pax_open_kernel();
49708 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49709 + *(void **)&wl18xx_ops.init_vif = NULL;
49710 + pax_close_kernel();
49711 }
49712
49713 /* Enable 11a Band only if we have 5G antennas */
49714 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49715 index a912dc0..a8225ba 100644
49716 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49717 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49718 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49719 {
49720 struct zd_usb *usb = urb->context;
49721 struct zd_usb_interrupt *intr = &usb->intr;
49722 - int len;
49723 + unsigned int len;
49724 u16 int_num;
49725
49726 ZD_ASSERT(in_interrupt());
49727 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49728 index 683671a..4519fc2 100644
49729 --- a/drivers/nfc/nfcwilink.c
49730 +++ b/drivers/nfc/nfcwilink.c
49731 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49732
49733 static int nfcwilink_probe(struct platform_device *pdev)
49734 {
49735 - static struct nfcwilink *drv;
49736 + struct nfcwilink *drv;
49737 int rc;
49738 __u32 protocols;
49739
49740 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49741 index d93b2b6..ae50401 100644
49742 --- a/drivers/oprofile/buffer_sync.c
49743 +++ b/drivers/oprofile/buffer_sync.c
49744 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49745 if (cookie == NO_COOKIE)
49746 offset = pc;
49747 if (cookie == INVALID_COOKIE) {
49748 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49749 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49750 offset = pc;
49751 }
49752 if (cookie != last_cookie) {
49753 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49754 /* add userspace sample */
49755
49756 if (!mm) {
49757 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49758 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49759 return 0;
49760 }
49761
49762 cookie = lookup_dcookie(mm, s->eip, &offset);
49763
49764 if (cookie == INVALID_COOKIE) {
49765 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49766 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49767 return 0;
49768 }
49769
49770 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49771 /* ignore backtraces if failed to add a sample */
49772 if (state == sb_bt_start) {
49773 state = sb_bt_ignore;
49774 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49775 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49776 }
49777 }
49778 release_mm(mm);
49779 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49780 index c0cc4e7..44d4e54 100644
49781 --- a/drivers/oprofile/event_buffer.c
49782 +++ b/drivers/oprofile/event_buffer.c
49783 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49784 }
49785
49786 if (buffer_pos == buffer_size) {
49787 - atomic_inc(&oprofile_stats.event_lost_overflow);
49788 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49789 return;
49790 }
49791
49792 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49793 index ed2c3ec..deda85a 100644
49794 --- a/drivers/oprofile/oprof.c
49795 +++ b/drivers/oprofile/oprof.c
49796 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49797 if (oprofile_ops.switch_events())
49798 return;
49799
49800 - atomic_inc(&oprofile_stats.multiplex_counter);
49801 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49802 start_switch_worker();
49803 }
49804
49805 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49806 index ee2cfce..7f8f699 100644
49807 --- a/drivers/oprofile/oprofile_files.c
49808 +++ b/drivers/oprofile/oprofile_files.c
49809 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49810
49811 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49812
49813 -static ssize_t timeout_read(struct file *file, char __user *buf,
49814 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49815 size_t count, loff_t *offset)
49816 {
49817 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49818 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49819 index 59659ce..6c860a0 100644
49820 --- a/drivers/oprofile/oprofile_stats.c
49821 +++ b/drivers/oprofile/oprofile_stats.c
49822 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49823 cpu_buf->sample_invalid_eip = 0;
49824 }
49825
49826 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49827 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49828 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49829 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49830 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49831 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49832 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49833 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49834 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49835 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49836 }
49837
49838
49839 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49840 index 1fc622b..8c48fc3 100644
49841 --- a/drivers/oprofile/oprofile_stats.h
49842 +++ b/drivers/oprofile/oprofile_stats.h
49843 @@ -13,11 +13,11 @@
49844 #include <linux/atomic.h>
49845
49846 struct oprofile_stat_struct {
49847 - atomic_t sample_lost_no_mm;
49848 - atomic_t sample_lost_no_mapping;
49849 - atomic_t bt_lost_no_mapping;
49850 - atomic_t event_lost_overflow;
49851 - atomic_t multiplex_counter;
49852 + atomic_unchecked_t sample_lost_no_mm;
49853 + atomic_unchecked_t sample_lost_no_mapping;
49854 + atomic_unchecked_t bt_lost_no_mapping;
49855 + atomic_unchecked_t event_lost_overflow;
49856 + atomic_unchecked_t multiplex_counter;
49857 };
49858
49859 extern struct oprofile_stat_struct oprofile_stats;
49860 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49861 index 3f49345..c750d0b 100644
49862 --- a/drivers/oprofile/oprofilefs.c
49863 +++ b/drivers/oprofile/oprofilefs.c
49864 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49865
49866 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49867 {
49868 - atomic_t *val = file->private_data;
49869 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49870 + atomic_unchecked_t *val = file->private_data;
49871 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49872 }
49873
49874
49875 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49876
49877
49878 int oprofilefs_create_ro_atomic(struct dentry *root,
49879 - char const *name, atomic_t *val)
49880 + char const *name, atomic_unchecked_t *val)
49881 {
49882 return __oprofilefs_create_file(root, name,
49883 &atomic_ro_fops, 0444, val);
49884 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49885 index bdef916..88c7dee 100644
49886 --- a/drivers/oprofile/timer_int.c
49887 +++ b/drivers/oprofile/timer_int.c
49888 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49889 return NOTIFY_OK;
49890 }
49891
49892 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49893 +static struct notifier_block oprofile_cpu_notifier = {
49894 .notifier_call = oprofile_cpu_notify,
49895 };
49896
49897 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49898 index 3b47080..6cd05dd 100644
49899 --- a/drivers/parport/procfs.c
49900 +++ b/drivers/parport/procfs.c
49901 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49902
49903 *ppos += len;
49904
49905 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49906 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49907 }
49908
49909 #ifdef CONFIG_PARPORT_1284
49910 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49911
49912 *ppos += len;
49913
49914 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49915 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49916 }
49917 #endif /* IEEE1284.3 support. */
49918
49919 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49920 index 6ca2399..68d866b 100644
49921 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49922 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49923 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49924 goto init_cleanup;
49925 }
49926
49927 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49928 + pax_open_kernel();
49929 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49930 + pax_close_kernel();
49931 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49932
49933 return retval;
49934 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49935 index 66b7bbe..26bee78 100644
49936 --- a/drivers/pci/hotplug/cpcihp_generic.c
49937 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49938 @@ -73,7 +73,6 @@ static u16 port;
49939 static unsigned int enum_bit;
49940 static u8 enum_mask;
49941
49942 -static struct cpci_hp_controller_ops generic_hpc_ops;
49943 static struct cpci_hp_controller generic_hpc;
49944
49945 static int __init validate_parameters(void)
49946 @@ -139,6 +138,10 @@ static int query_enum(void)
49947 return ((value & enum_mask) == enum_mask);
49948 }
49949
49950 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49951 + .query_enum = query_enum,
49952 +};
49953 +
49954 static int __init cpcihp_generic_init(void)
49955 {
49956 int status;
49957 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49958 pci_dev_put(dev);
49959
49960 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49961 - generic_hpc_ops.query_enum = query_enum;
49962 generic_hpc.ops = &generic_hpc_ops;
49963
49964 status = cpci_hp_register_controller(&generic_hpc);
49965 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49966 index 7ecf34e..effed62 100644
49967 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
49968 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49969 @@ -59,7 +59,6 @@
49970 /* local variables */
49971 static bool debug;
49972 static bool poll;
49973 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
49974 static struct cpci_hp_controller zt5550_hpc;
49975
49976 /* Primary cPCI bus bridge device */
49977 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49978 return 0;
49979 }
49980
49981 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
49982 + .query_enum = zt5550_hc_query_enum,
49983 +};
49984 +
49985 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
49986 {
49987 int status;
49988 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
49989 dbg("returned from zt5550_hc_config");
49990
49991 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
49992 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
49993 zt5550_hpc.ops = &zt5550_hpc_ops;
49994 if (!poll) {
49995 zt5550_hpc.irq = hc_dev->irq;
49996 zt5550_hpc.irq_flags = IRQF_SHARED;
49997 zt5550_hpc.dev_id = hc_dev;
49998
49999 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50000 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50001 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50002 + pax_open_kernel();
50003 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50004 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50005 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50006 + pax_open_kernel();
50007 } else {
50008 info("using ENUM# polling mode");
50009 }
50010 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50011 index 1e08ff8c..3cd145f 100644
50012 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50013 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50014 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
50015
50016 void compaq_nvram_init (void __iomem *rom_start)
50017 {
50018 +#ifndef CONFIG_PAX_KERNEXEC
50019 if (rom_start)
50020 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50021 +#endif
50022
50023 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50024
50025 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50026 index 56d8486..f26113f 100644
50027 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50028 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50029 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50030 return -EINVAL;
50031 }
50032
50033 - slot->ops->owner = owner;
50034 - slot->ops->mod_name = mod_name;
50035 + pax_open_kernel();
50036 + *(struct module **)&slot->ops->owner = owner;
50037 + *(const char **)&slot->ops->mod_name = mod_name;
50038 + pax_close_kernel();
50039
50040 mutex_lock(&pci_hp_mutex);
50041 /*
50042 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50043 index 07aa722..84514b4 100644
50044 --- a/drivers/pci/hotplug/pciehp_core.c
50045 +++ b/drivers/pci/hotplug/pciehp_core.c
50046 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50047 struct slot *slot = ctrl->slot;
50048 struct hotplug_slot *hotplug = NULL;
50049 struct hotplug_slot_info *info = NULL;
50050 - struct hotplug_slot_ops *ops = NULL;
50051 + hotplug_slot_ops_no_const *ops = NULL;
50052 char name[SLOT_NAME_SIZE];
50053 int retval = -ENOMEM;
50054
50055 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50056 index 084587d..4a8f9df 100644
50057 --- a/drivers/pci/msi.c
50058 +++ b/drivers/pci/msi.c
50059 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50060 {
50061 struct attribute **msi_attrs;
50062 struct attribute *msi_attr;
50063 - struct device_attribute *msi_dev_attr;
50064 - struct attribute_group *msi_irq_group;
50065 + device_attribute_no_const *msi_dev_attr;
50066 + attribute_group_no_const *msi_irq_group;
50067 const struct attribute_group **msi_irq_groups;
50068 struct msi_desc *entry;
50069 int ret = -ENOMEM;
50070 @@ -549,7 +549,7 @@ error_attrs:
50071 count = 0;
50072 msi_attr = msi_attrs[count];
50073 while (msi_attr) {
50074 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50075 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50076 kfree(msi_attr->name);
50077 kfree(msi_dev_attr);
50078 ++count;
50079 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50080 index 2c6643f..3a6d8e0 100644
50081 --- a/drivers/pci/pci-sysfs.c
50082 +++ b/drivers/pci/pci-sysfs.c
50083 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50084 {
50085 /* allocate attribute structure, piggyback attribute name */
50086 int name_len = write_combine ? 13 : 10;
50087 - struct bin_attribute *res_attr;
50088 + bin_attribute_no_const *res_attr;
50089 int retval;
50090
50091 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50092 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50093 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50094 {
50095 int retval;
50096 - struct bin_attribute *attr;
50097 + bin_attribute_no_const *attr;
50098
50099 /* If the device has VPD, try to expose it in sysfs. */
50100 if (dev->vpd) {
50101 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50102 {
50103 int retval;
50104 int rom_size = 0;
50105 - struct bin_attribute *attr;
50106 + bin_attribute_no_const *attr;
50107
50108 if (!sysfs_initialized)
50109 return -EACCES;
50110 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50111 index 4a3902d..7f1fc42 100644
50112 --- a/drivers/pci/pci.h
50113 +++ b/drivers/pci/pci.h
50114 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
50115 struct pci_vpd {
50116 unsigned int len;
50117 const struct pci_vpd_ops *ops;
50118 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50119 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50120 };
50121
50122 int pci_vpd_pci22_init(struct pci_dev *dev);
50123 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50124 index e1e7026..d28dd33 100644
50125 --- a/drivers/pci/pcie/aspm.c
50126 +++ b/drivers/pci/pcie/aspm.c
50127 @@ -27,9 +27,9 @@
50128 #define MODULE_PARAM_PREFIX "pcie_aspm."
50129
50130 /* Note: those are not register definitions */
50131 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50132 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50133 -#define ASPM_STATE_L1 (4) /* L1 state */
50134 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50135 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50136 +#define ASPM_STATE_L1 (4U) /* L1 state */
50137 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50138 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50139
50140 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50141 index 3010ffc..5e2e133 100644
50142 --- a/drivers/pci/probe.c
50143 +++ b/drivers/pci/probe.c
50144 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50145 struct pci_bus_region region, inverted_region;
50146 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50147
50148 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50149 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50150
50151 /* No printks while decoding is disabled! */
50152 if (!dev->mmio_always_on) {
50153 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50154 index 3f155e7..0f4b1f0 100644
50155 --- a/drivers/pci/proc.c
50156 +++ b/drivers/pci/proc.c
50157 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50158 static int __init pci_proc_init(void)
50159 {
50160 struct pci_dev *dev = NULL;
50161 +
50162 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50163 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50164 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50165 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50166 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50167 +#endif
50168 +#else
50169 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50170 +#endif
50171 proc_create("devices", 0, proc_bus_pci_dir,
50172 &proc_bus_pci_dev_operations);
50173 proc_initialized = 1;
50174 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50175 index d866db8..c827d1f 100644
50176 --- a/drivers/platform/chrome/chromeos_laptop.c
50177 +++ b/drivers/platform/chrome/chromeos_laptop.c
50178 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50179 .callback = chromeos_laptop_dmi_matched, \
50180 .driver_data = (void *)&board_
50181
50182 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50183 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50184 {
50185 .ident = "Samsung Series 5 550",
50186 .matches = {
50187 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50188 index c5af23b..3d62d5e 100644
50189 --- a/drivers/platform/x86/alienware-wmi.c
50190 +++ b/drivers/platform/x86/alienware-wmi.c
50191 @@ -150,7 +150,7 @@ struct wmax_led_args {
50192 } __packed;
50193
50194 static struct platform_device *platform_device;
50195 -static struct device_attribute *zone_dev_attrs;
50196 +static device_attribute_no_const *zone_dev_attrs;
50197 static struct attribute **zone_attrs;
50198 static struct platform_zone *zone_data;
50199
50200 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50201 }
50202 };
50203
50204 -static struct attribute_group zone_attribute_group = {
50205 +static attribute_group_no_const zone_attribute_group = {
50206 .name = "rgb_zones",
50207 };
50208
50209 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50210 index 21fc932..ee9394a 100644
50211 --- a/drivers/platform/x86/asus-wmi.c
50212 +++ b/drivers/platform/x86/asus-wmi.c
50213 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50214 int err;
50215 u32 retval = -1;
50216
50217 +#ifdef CONFIG_GRKERNSEC_KMEM
50218 + return -EPERM;
50219 +#endif
50220 +
50221 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50222
50223 if (err < 0)
50224 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50225 int err;
50226 u32 retval = -1;
50227
50228 +#ifdef CONFIG_GRKERNSEC_KMEM
50229 + return -EPERM;
50230 +#endif
50231 +
50232 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50233 &retval);
50234
50235 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50236 union acpi_object *obj;
50237 acpi_status status;
50238
50239 +#ifdef CONFIG_GRKERNSEC_KMEM
50240 + return -EPERM;
50241 +#endif
50242 +
50243 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50244 1, asus->debug.method_id,
50245 &input, &output);
50246 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50247 index 62f8030..c7f2a45 100644
50248 --- a/drivers/platform/x86/msi-laptop.c
50249 +++ b/drivers/platform/x86/msi-laptop.c
50250 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50251
50252 if (!quirks->ec_read_only) {
50253 /* allow userland write sysfs file */
50254 - dev_attr_bluetooth.store = store_bluetooth;
50255 - dev_attr_wlan.store = store_wlan;
50256 - dev_attr_threeg.store = store_threeg;
50257 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50258 - dev_attr_wlan.attr.mode |= S_IWUSR;
50259 - dev_attr_threeg.attr.mode |= S_IWUSR;
50260 + pax_open_kernel();
50261 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50262 + *(void **)&dev_attr_wlan.store = store_wlan;
50263 + *(void **)&dev_attr_threeg.store = store_threeg;
50264 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50265 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50266 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50267 + pax_close_kernel();
50268 }
50269
50270 /* disable hardware control by fn key */
50271 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50272 index 70222f2..8c8ce66 100644
50273 --- a/drivers/platform/x86/msi-wmi.c
50274 +++ b/drivers/platform/x86/msi-wmi.c
50275 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50276 static void msi_wmi_notify(u32 value, void *context)
50277 {
50278 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50279 - static struct key_entry *key;
50280 + struct key_entry *key;
50281 union acpi_object *obj;
50282 acpi_status status;
50283
50284 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50285 index 26ad9ff..7c52909 100644
50286 --- a/drivers/platform/x86/sony-laptop.c
50287 +++ b/drivers/platform/x86/sony-laptop.c
50288 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50289 }
50290
50291 /* High speed charging function */
50292 -static struct device_attribute *hsc_handle;
50293 +static device_attribute_no_const *hsc_handle;
50294
50295 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50296 struct device_attribute *attr,
50297 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50298 }
50299
50300 /* low battery function */
50301 -static struct device_attribute *lowbatt_handle;
50302 +static device_attribute_no_const *lowbatt_handle;
50303
50304 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50305 struct device_attribute *attr,
50306 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50307 }
50308
50309 /* fan speed function */
50310 -static struct device_attribute *fan_handle, *hsf_handle;
50311 +static device_attribute_no_const *fan_handle, *hsf_handle;
50312
50313 static ssize_t sony_nc_hsfan_store(struct device *dev,
50314 struct device_attribute *attr,
50315 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50316 }
50317
50318 /* USB charge function */
50319 -static struct device_attribute *uc_handle;
50320 +static device_attribute_no_const *uc_handle;
50321
50322 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50323 struct device_attribute *attr,
50324 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50325 }
50326
50327 /* Panel ID function */
50328 -static struct device_attribute *panel_handle;
50329 +static device_attribute_no_const *panel_handle;
50330
50331 static ssize_t sony_nc_panelid_show(struct device *dev,
50332 struct device_attribute *attr, char *buffer)
50333 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50334 }
50335
50336 /* smart connect function */
50337 -static struct device_attribute *sc_handle;
50338 +static device_attribute_no_const *sc_handle;
50339
50340 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50341 struct device_attribute *attr,
50342 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50343 index cf0f893..5955997 100644
50344 --- a/drivers/platform/x86/thinkpad_acpi.c
50345 +++ b/drivers/platform/x86/thinkpad_acpi.c
50346 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50347 return 0;
50348 }
50349
50350 -void static hotkey_mask_warn_incomplete_mask(void)
50351 +static void hotkey_mask_warn_incomplete_mask(void)
50352 {
50353 /* log only what the user can fix... */
50354 const u32 wantedmask = hotkey_driver_mask &
50355 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50356 && !tp_features.bright_unkfw)
50357 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50358 }
50359 +}
50360
50361 #undef TPACPI_COMPARE_KEY
50362 #undef TPACPI_MAY_SEND_KEY
50363 -}
50364
50365 /*
50366 * Polling driver
50367 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50368 index 438d4c7..ca8a2fb 100644
50369 --- a/drivers/pnp/pnpbios/bioscalls.c
50370 +++ b/drivers/pnp/pnpbios/bioscalls.c
50371 @@ -59,7 +59,7 @@ do { \
50372 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50373 } while(0)
50374
50375 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50376 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50377 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50378
50379 /*
50380 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50381
50382 cpu = get_cpu();
50383 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50384 +
50385 + pax_open_kernel();
50386 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50387 + pax_close_kernel();
50388
50389 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50390 spin_lock_irqsave(&pnp_bios_lock, flags);
50391 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50392 :"memory");
50393 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50394
50395 + pax_open_kernel();
50396 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50397 + pax_close_kernel();
50398 +
50399 put_cpu();
50400
50401 /* If we get here and this is set then the PnP BIOS faulted on us. */
50402 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50403 return status;
50404 }
50405
50406 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50407 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50408 {
50409 int i;
50410
50411 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50412 pnp_bios_callpoint.offset = header->fields.pm16offset;
50413 pnp_bios_callpoint.segment = PNP_CS16;
50414
50415 + pax_open_kernel();
50416 +
50417 for_each_possible_cpu(i) {
50418 struct desc_struct *gdt = get_cpu_gdt_table(i);
50419 if (!gdt)
50420 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50421 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50422 (unsigned long)__va(header->fields.pm16dseg));
50423 }
50424 +
50425 + pax_close_kernel();
50426 }
50427 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50428 index 0c52e2a..3421ab7 100644
50429 --- a/drivers/power/pda_power.c
50430 +++ b/drivers/power/pda_power.c
50431 @@ -37,7 +37,11 @@ static int polling;
50432
50433 #if IS_ENABLED(CONFIG_USB_PHY)
50434 static struct usb_phy *transceiver;
50435 -static struct notifier_block otg_nb;
50436 +static int otg_handle_notification(struct notifier_block *nb,
50437 + unsigned long event, void *unused);
50438 +static struct notifier_block otg_nb = {
50439 + .notifier_call = otg_handle_notification
50440 +};
50441 #endif
50442
50443 static struct regulator *ac_draw;
50444 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50445
50446 #if IS_ENABLED(CONFIG_USB_PHY)
50447 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50448 - otg_nb.notifier_call = otg_handle_notification;
50449 ret = usb_register_notifier(transceiver, &otg_nb);
50450 if (ret) {
50451 dev_err(dev, "failure to register otg notifier\n");
50452 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50453 index cc439fd..8fa30df 100644
50454 --- a/drivers/power/power_supply.h
50455 +++ b/drivers/power/power_supply.h
50456 @@ -16,12 +16,12 @@ struct power_supply;
50457
50458 #ifdef CONFIG_SYSFS
50459
50460 -extern void power_supply_init_attrs(struct device_type *dev_type);
50461 +extern void power_supply_init_attrs(void);
50462 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50463
50464 #else
50465
50466 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50467 +static inline void power_supply_init_attrs(void) {}
50468 #define power_supply_uevent NULL
50469
50470 #endif /* CONFIG_SYSFS */
50471 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50472 index 694e8cd..9f03483 100644
50473 --- a/drivers/power/power_supply_core.c
50474 +++ b/drivers/power/power_supply_core.c
50475 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50476 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50477 EXPORT_SYMBOL_GPL(power_supply_notifier);
50478
50479 -static struct device_type power_supply_dev_type;
50480 +extern const struct attribute_group *power_supply_attr_groups[];
50481 +static struct device_type power_supply_dev_type = {
50482 + .groups = power_supply_attr_groups,
50483 +};
50484
50485 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50486 struct power_supply *supply)
50487 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50488 return PTR_ERR(power_supply_class);
50489
50490 power_supply_class->dev_uevent = power_supply_uevent;
50491 - power_supply_init_attrs(&power_supply_dev_type);
50492 + power_supply_init_attrs();
50493
50494 return 0;
50495 }
50496 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50497 index 62653f5..d0bb485 100644
50498 --- a/drivers/power/power_supply_sysfs.c
50499 +++ b/drivers/power/power_supply_sysfs.c
50500 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50501 .is_visible = power_supply_attr_is_visible,
50502 };
50503
50504 -static const struct attribute_group *power_supply_attr_groups[] = {
50505 +const struct attribute_group *power_supply_attr_groups[] = {
50506 &power_supply_attr_group,
50507 NULL,
50508 };
50509
50510 -void power_supply_init_attrs(struct device_type *dev_type)
50511 +void power_supply_init_attrs(void)
50512 {
50513 int i;
50514
50515 - dev_type->groups = power_supply_attr_groups;
50516 -
50517 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50518 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50519 }
50520 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50521 index 84419af..268ede8 100644
50522 --- a/drivers/powercap/powercap_sys.c
50523 +++ b/drivers/powercap/powercap_sys.c
50524 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50525 struct device_attribute name_attr;
50526 };
50527
50528 +static ssize_t show_constraint_name(struct device *dev,
50529 + struct device_attribute *dev_attr,
50530 + char *buf);
50531 +
50532 static struct powercap_constraint_attr
50533 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50534 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50535 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50536 + .power_limit_attr = {
50537 + .attr = {
50538 + .name = NULL,
50539 + .mode = S_IWUSR | S_IRUGO
50540 + },
50541 + .show = show_constraint_power_limit_uw,
50542 + .store = store_constraint_power_limit_uw
50543 + },
50544 +
50545 + .time_window_attr = {
50546 + .attr = {
50547 + .name = NULL,
50548 + .mode = S_IWUSR | S_IRUGO
50549 + },
50550 + .show = show_constraint_time_window_us,
50551 + .store = store_constraint_time_window_us
50552 + },
50553 +
50554 + .max_power_attr = {
50555 + .attr = {
50556 + .name = NULL,
50557 + .mode = S_IRUGO
50558 + },
50559 + .show = show_constraint_max_power_uw,
50560 + .store = NULL
50561 + },
50562 +
50563 + .min_power_attr = {
50564 + .attr = {
50565 + .name = NULL,
50566 + .mode = S_IRUGO
50567 + },
50568 + .show = show_constraint_min_power_uw,
50569 + .store = NULL
50570 + },
50571 +
50572 + .max_time_window_attr = {
50573 + .attr = {
50574 + .name = NULL,
50575 + .mode = S_IRUGO
50576 + },
50577 + .show = show_constraint_max_time_window_us,
50578 + .store = NULL
50579 + },
50580 +
50581 + .min_time_window_attr = {
50582 + .attr = {
50583 + .name = NULL,
50584 + .mode = S_IRUGO
50585 + },
50586 + .show = show_constraint_min_time_window_us,
50587 + .store = NULL
50588 + },
50589 +
50590 + .name_attr = {
50591 + .attr = {
50592 + .name = NULL,
50593 + .mode = S_IRUGO
50594 + },
50595 + .show = show_constraint_name,
50596 + .store = NULL
50597 + }
50598 + }
50599 +};
50600
50601 /* A list of powercap control_types */
50602 static LIST_HEAD(powercap_cntrl_list);
50603 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50604 }
50605
50606 static int create_constraint_attribute(int id, const char *name,
50607 - int mode,
50608 - struct device_attribute *dev_attr,
50609 - ssize_t (*show)(struct device *,
50610 - struct device_attribute *, char *),
50611 - ssize_t (*store)(struct device *,
50612 - struct device_attribute *,
50613 - const char *, size_t)
50614 - )
50615 + struct device_attribute *dev_attr)
50616 {
50617 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50618
50619 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50620 - id, name);
50621 - if (!dev_attr->attr.name)
50622 + if (!name)
50623 return -ENOMEM;
50624 - dev_attr->attr.mode = mode;
50625 - dev_attr->show = show;
50626 - dev_attr->store = store;
50627 +
50628 + pax_open_kernel();
50629 + *(const char **)&dev_attr->attr.name = name;
50630 + pax_close_kernel();
50631
50632 return 0;
50633 }
50634 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50635
50636 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50637 ret = create_constraint_attribute(i, "power_limit_uw",
50638 - S_IWUSR | S_IRUGO,
50639 - &constraint_attrs[i].power_limit_attr,
50640 - show_constraint_power_limit_uw,
50641 - store_constraint_power_limit_uw);
50642 + &constraint_attrs[i].power_limit_attr);
50643 if (ret)
50644 goto err_alloc;
50645 ret = create_constraint_attribute(i, "time_window_us",
50646 - S_IWUSR | S_IRUGO,
50647 - &constraint_attrs[i].time_window_attr,
50648 - show_constraint_time_window_us,
50649 - store_constraint_time_window_us);
50650 + &constraint_attrs[i].time_window_attr);
50651 if (ret)
50652 goto err_alloc;
50653 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50654 - &constraint_attrs[i].name_attr,
50655 - show_constraint_name,
50656 - NULL);
50657 + ret = create_constraint_attribute(i, "name",
50658 + &constraint_attrs[i].name_attr);
50659 if (ret)
50660 goto err_alloc;
50661 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50662 - &constraint_attrs[i].max_power_attr,
50663 - show_constraint_max_power_uw,
50664 - NULL);
50665 + ret = create_constraint_attribute(i, "max_power_uw",
50666 + &constraint_attrs[i].max_power_attr);
50667 if (ret)
50668 goto err_alloc;
50669 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50670 - &constraint_attrs[i].min_power_attr,
50671 - show_constraint_min_power_uw,
50672 - NULL);
50673 + ret = create_constraint_attribute(i, "min_power_uw",
50674 + &constraint_attrs[i].min_power_attr);
50675 if (ret)
50676 goto err_alloc;
50677 ret = create_constraint_attribute(i, "max_time_window_us",
50678 - S_IRUGO,
50679 - &constraint_attrs[i].max_time_window_attr,
50680 - show_constraint_max_time_window_us,
50681 - NULL);
50682 + &constraint_attrs[i].max_time_window_attr);
50683 if (ret)
50684 goto err_alloc;
50685 ret = create_constraint_attribute(i, "min_time_window_us",
50686 - S_IRUGO,
50687 - &constraint_attrs[i].min_time_window_attr,
50688 - show_constraint_min_time_window_us,
50689 - NULL);
50690 + &constraint_attrs[i].min_time_window_attr);
50691 if (ret)
50692 goto err_alloc;
50693
50694 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50695 power_zone->zone_dev_attrs[count++] =
50696 &dev_attr_max_energy_range_uj.attr;
50697 if (power_zone->ops->get_energy_uj) {
50698 + pax_open_kernel();
50699 if (power_zone->ops->reset_energy_uj)
50700 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50701 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50702 else
50703 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50704 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50705 + pax_close_kernel();
50706 power_zone->zone_dev_attrs[count++] =
50707 &dev_attr_energy_uj.attr;
50708 }
50709 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50710 index 9c5d414..c7900ce 100644
50711 --- a/drivers/ptp/ptp_private.h
50712 +++ b/drivers/ptp/ptp_private.h
50713 @@ -51,7 +51,7 @@ struct ptp_clock {
50714 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50715 wait_queue_head_t tsev_wq;
50716 int defunct; /* tells readers to go away when clock is being removed */
50717 - struct device_attribute *pin_dev_attr;
50718 + device_attribute_no_const *pin_dev_attr;
50719 struct attribute **pin_attr;
50720 struct attribute_group pin_attr_group;
50721 };
50722 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50723 index 302e626..12579af 100644
50724 --- a/drivers/ptp/ptp_sysfs.c
50725 +++ b/drivers/ptp/ptp_sysfs.c
50726 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50727 goto no_pin_attr;
50728
50729 for (i = 0; i < n_pins; i++) {
50730 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50731 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50732 sysfs_attr_init(&da->attr);
50733 da->attr.name = info->pin_config[i].name;
50734 da->attr.mode = 0644;
50735 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50736 index cd87c0c..715ecbe 100644
50737 --- a/drivers/regulator/core.c
50738 +++ b/drivers/regulator/core.c
50739 @@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50740 {
50741 const struct regulation_constraints *constraints = NULL;
50742 const struct regulator_init_data *init_data;
50743 - static atomic_t regulator_no = ATOMIC_INIT(0);
50744 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50745 struct regulator_dev *rdev;
50746 struct device *dev;
50747 int ret, i;
50748 @@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50749 rdev->dev.class = &regulator_class;
50750 rdev->dev.parent = dev;
50751 dev_set_name(&rdev->dev, "regulator.%d",
50752 - atomic_inc_return(&regulator_no) - 1);
50753 + atomic_inc_return_unchecked(&regulator_no) - 1);
50754 ret = device_register(&rdev->dev);
50755 if (ret != 0) {
50756 put_device(&rdev->dev);
50757 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50758 index 7eee2ca..4024513 100644
50759 --- a/drivers/regulator/max8660.c
50760 +++ b/drivers/regulator/max8660.c
50761 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50762 max8660->shadow_regs[MAX8660_OVER1] = 5;
50763 } else {
50764 /* Otherwise devices can be toggled via software */
50765 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50766 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50767 + pax_open_kernel();
50768 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50769 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50770 + pax_close_kernel();
50771 }
50772
50773 /*
50774 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50775 index dbedf17..18ff6b7 100644
50776 --- a/drivers/regulator/max8973-regulator.c
50777 +++ b/drivers/regulator/max8973-regulator.c
50778 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50779 if (!pdata || !pdata->enable_ext_control) {
50780 max->desc.enable_reg = MAX8973_VOUT;
50781 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50782 - max->ops.enable = regulator_enable_regmap;
50783 - max->ops.disable = regulator_disable_regmap;
50784 - max->ops.is_enabled = regulator_is_enabled_regmap;
50785 + pax_open_kernel();
50786 + *(void **)&max->ops.enable = regulator_enable_regmap;
50787 + *(void **)&max->ops.disable = regulator_disable_regmap;
50788 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50789 + pax_close_kernel();
50790 }
50791
50792 if (pdata) {
50793 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50794 index 793b662..85f74cd 100644
50795 --- a/drivers/regulator/mc13892-regulator.c
50796 +++ b/drivers/regulator/mc13892-regulator.c
50797 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50798 mc13xxx_unlock(mc13892);
50799
50800 /* update mc13892_vcam ops */
50801 + pax_open_kernel();
50802 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50803 sizeof(struct regulator_ops));
50804 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50805 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50806 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50807 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50808 + pax_close_kernel();
50809 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50810
50811 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50812 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50813 index 5b2e761..c8c8a4a 100644
50814 --- a/drivers/rtc/rtc-cmos.c
50815 +++ b/drivers/rtc/rtc-cmos.c
50816 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50817 hpet_rtc_timer_init();
50818
50819 /* export at least the first block of NVRAM */
50820 - nvram.size = address_space - NVRAM_OFFSET;
50821 + pax_open_kernel();
50822 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50823 + pax_close_kernel();
50824 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50825 if (retval < 0) {
50826 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50827 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50828 index d049393..bb20be0 100644
50829 --- a/drivers/rtc/rtc-dev.c
50830 +++ b/drivers/rtc/rtc-dev.c
50831 @@ -16,6 +16,7 @@
50832 #include <linux/module.h>
50833 #include <linux/rtc.h>
50834 #include <linux/sched.h>
50835 +#include <linux/grsecurity.h>
50836 #include "rtc-core.h"
50837
50838 static dev_t rtc_devt;
50839 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50840 if (copy_from_user(&tm, uarg, sizeof(tm)))
50841 return -EFAULT;
50842
50843 + gr_log_timechange();
50844 +
50845 return rtc_set_time(rtc, &tm);
50846
50847 case RTC_PIE_ON:
50848 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50849 index bb43cf7..ee4d274 100644
50850 --- a/drivers/rtc/rtc-ds1307.c
50851 +++ b/drivers/rtc/rtc-ds1307.c
50852 @@ -107,7 +107,7 @@ struct ds1307 {
50853 u8 offset; /* register's offset */
50854 u8 regs[11];
50855 u16 nvram_offset;
50856 - struct bin_attribute *nvram;
50857 + bin_attribute_no_const *nvram;
50858 enum ds_type type;
50859 unsigned long flags;
50860 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50861 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50862 index 11880c1..b823aa4 100644
50863 --- a/drivers/rtc/rtc-m48t59.c
50864 +++ b/drivers/rtc/rtc-m48t59.c
50865 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50866 if (IS_ERR(m48t59->rtc))
50867 return PTR_ERR(m48t59->rtc);
50868
50869 - m48t59_nvram_attr.size = pdata->offset;
50870 + pax_open_kernel();
50871 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50872 + pax_close_kernel();
50873
50874 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50875 if (ret)
50876 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50877 index e693af6..2e525b6 100644
50878 --- a/drivers/scsi/bfa/bfa_fcpim.h
50879 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50880 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50881
50882 struct bfa_itn_s {
50883 bfa_isr_func_t isr;
50884 -};
50885 +} __no_const;
50886
50887 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50888 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50889 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50890 index 0f19455..ef7adb5 100644
50891 --- a/drivers/scsi/bfa/bfa_fcs.c
50892 +++ b/drivers/scsi/bfa/bfa_fcs.c
50893 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50894 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50895
50896 static struct bfa_fcs_mod_s fcs_modules[] = {
50897 - { bfa_fcs_port_attach, NULL, NULL },
50898 - { bfa_fcs_uf_attach, NULL, NULL },
50899 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50900 - bfa_fcs_fabric_modexit },
50901 + {
50902 + .attach = bfa_fcs_port_attach,
50903 + .modinit = NULL,
50904 + .modexit = NULL
50905 + },
50906 + {
50907 + .attach = bfa_fcs_uf_attach,
50908 + .modinit = NULL,
50909 + .modexit = NULL
50910 + },
50911 + {
50912 + .attach = bfa_fcs_fabric_attach,
50913 + .modinit = bfa_fcs_fabric_modinit,
50914 + .modexit = bfa_fcs_fabric_modexit
50915 + },
50916 };
50917
50918 /*
50919 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50920 index ff75ef8..2dfe00a 100644
50921 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50922 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50923 @@ -89,15 +89,26 @@ static struct {
50924 void (*offline) (struct bfa_fcs_lport_s *port);
50925 } __port_action[] = {
50926 {
50927 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50928 - bfa_fcs_lport_unknown_offline}, {
50929 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50930 - bfa_fcs_lport_fab_offline}, {
50931 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50932 - bfa_fcs_lport_n2n_offline}, {
50933 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50934 - bfa_fcs_lport_loop_offline},
50935 - };
50936 + .init = bfa_fcs_lport_unknown_init,
50937 + .online = bfa_fcs_lport_unknown_online,
50938 + .offline = bfa_fcs_lport_unknown_offline
50939 + },
50940 + {
50941 + .init = bfa_fcs_lport_fab_init,
50942 + .online = bfa_fcs_lport_fab_online,
50943 + .offline = bfa_fcs_lport_fab_offline
50944 + },
50945 + {
50946 + .init = bfa_fcs_lport_n2n_init,
50947 + .online = bfa_fcs_lport_n2n_online,
50948 + .offline = bfa_fcs_lport_n2n_offline
50949 + },
50950 + {
50951 + .init = bfa_fcs_lport_loop_init,
50952 + .online = bfa_fcs_lport_loop_online,
50953 + .offline = bfa_fcs_lport_loop_offline
50954 + },
50955 +};
50956
50957 /*
50958 * fcs_port_sm FCS logical port state machine
50959 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50960 index a38aafa0..fe8f03b 100644
50961 --- a/drivers/scsi/bfa/bfa_ioc.h
50962 +++ b/drivers/scsi/bfa/bfa_ioc.h
50963 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50964 bfa_ioc_disable_cbfn_t disable_cbfn;
50965 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50966 bfa_ioc_reset_cbfn_t reset_cbfn;
50967 -};
50968 +} __no_const;
50969
50970 /*
50971 * IOC event notification mechanism.
50972 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50973 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50974 enum bfi_ioc_state fwstate);
50975 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50976 -};
50977 +} __no_const;
50978
50979 /*
50980 * Queue element to wait for room in request queue. FIFO order is
50981 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
50982 index a14c784..6de6790 100644
50983 --- a/drivers/scsi/bfa/bfa_modules.h
50984 +++ b/drivers/scsi/bfa/bfa_modules.h
50985 @@ -78,12 +78,12 @@ enum {
50986 \
50987 extern struct bfa_module_s hal_mod_ ## __mod; \
50988 struct bfa_module_s hal_mod_ ## __mod = { \
50989 - bfa_ ## __mod ## _meminfo, \
50990 - bfa_ ## __mod ## _attach, \
50991 - bfa_ ## __mod ## _detach, \
50992 - bfa_ ## __mod ## _start, \
50993 - bfa_ ## __mod ## _stop, \
50994 - bfa_ ## __mod ## _iocdisable, \
50995 + .meminfo = bfa_ ## __mod ## _meminfo, \
50996 + .attach = bfa_ ## __mod ## _attach, \
50997 + .detach = bfa_ ## __mod ## _detach, \
50998 + .start = bfa_ ## __mod ## _start, \
50999 + .stop = bfa_ ## __mod ## _stop, \
51000 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51001 }
51002
51003 #define BFA_CACHELINE_SZ (256)
51004 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51005 index 045c4e1..13de803 100644
51006 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51007 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51008 @@ -33,8 +33,8 @@
51009 */
51010 #include "libfcoe.h"
51011
51012 -static atomic_t ctlr_num;
51013 -static atomic_t fcf_num;
51014 +static atomic_unchecked_t ctlr_num;
51015 +static atomic_unchecked_t fcf_num;
51016
51017 /*
51018 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51019 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51020 if (!ctlr)
51021 goto out;
51022
51023 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51024 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51025 ctlr->f = f;
51026 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51027 INIT_LIST_HEAD(&ctlr->fcfs);
51028 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51029 fcf->dev.parent = &ctlr->dev;
51030 fcf->dev.bus = &fcoe_bus_type;
51031 fcf->dev.type = &fcoe_fcf_device_type;
51032 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51033 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51034 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51035
51036 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51037 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51038 {
51039 int error;
51040
51041 - atomic_set(&ctlr_num, 0);
51042 - atomic_set(&fcf_num, 0);
51043 + atomic_set_unchecked(&ctlr_num, 0);
51044 + atomic_set_unchecked(&fcf_num, 0);
51045
51046 error = bus_register(&fcoe_bus_type);
51047 if (error)
51048 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51049 index 6de80e3..a11e0ac 100644
51050 --- a/drivers/scsi/hosts.c
51051 +++ b/drivers/scsi/hosts.c
51052 @@ -42,7 +42,7 @@
51053 #include "scsi_logging.h"
51054
51055
51056 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51057 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51058
51059
51060 static void scsi_host_cls_release(struct device *dev)
51061 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51062 * subtract one because we increment first then return, but we need to
51063 * know what the next host number was before increment
51064 */
51065 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51066 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51067 shost->dma_channel = 0xff;
51068
51069 /* These three are default values which can be overridden */
51070 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51071 index cef5d49..01e280e 100644
51072 --- a/drivers/scsi/hpsa.c
51073 +++ b/drivers/scsi/hpsa.c
51074 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51075 unsigned long flags;
51076
51077 if (h->transMethod & CFGTBL_Trans_io_accel1)
51078 - return h->access.command_completed(h, q);
51079 + return h->access->command_completed(h, q);
51080
51081 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51082 - return h->access.command_completed(h, q);
51083 + return h->access->command_completed(h, q);
51084
51085 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51086 a = rq->head[rq->current_entry];
51087 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51088 while (!list_empty(&h->reqQ)) {
51089 c = list_entry(h->reqQ.next, struct CommandList, list);
51090 /* can't do anything if fifo is full */
51091 - if ((h->access.fifo_full(h))) {
51092 + if ((h->access->fifo_full(h))) {
51093 h->fifo_recently_full = 1;
51094 dev_warn(&h->pdev->dev, "fifo full\n");
51095 break;
51096 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51097
51098 /* Tell the controller execute command */
51099 spin_unlock_irqrestore(&h->lock, *flags);
51100 - h->access.submit_command(h, c);
51101 + h->access->submit_command(h, c);
51102 spin_lock_irqsave(&h->lock, *flags);
51103 }
51104 }
51105 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51106
51107 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51108 {
51109 - return h->access.command_completed(h, q);
51110 + return h->access->command_completed(h, q);
51111 }
51112
51113 static inline bool interrupt_pending(struct ctlr_info *h)
51114 {
51115 - return h->access.intr_pending(h);
51116 + return h->access->intr_pending(h);
51117 }
51118
51119 static inline long interrupt_not_for_us(struct ctlr_info *h)
51120 {
51121 - return (h->access.intr_pending(h) == 0) ||
51122 + return (h->access->intr_pending(h) == 0) ||
51123 (h->interrupts_enabled == 0);
51124 }
51125
51126 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51127 if (prod_index < 0)
51128 return -ENODEV;
51129 h->product_name = products[prod_index].product_name;
51130 - h->access = *(products[prod_index].access);
51131 + h->access = products[prod_index].access;
51132
51133 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51134 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51135 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51136 unsigned long flags;
51137 u32 lockup_detected;
51138
51139 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51140 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51141 spin_lock_irqsave(&h->lock, flags);
51142 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51143 if (!lockup_detected) {
51144 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51145 }
51146
51147 /* make sure the board interrupts are off */
51148 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51149 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51150
51151 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51152 goto clean2;
51153 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51154 * fake ones to scoop up any residual completions.
51155 */
51156 spin_lock_irqsave(&h->lock, flags);
51157 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51158 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51159 spin_unlock_irqrestore(&h->lock, flags);
51160 free_irqs(h);
51161 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51162 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51163 dev_info(&h->pdev->dev, "Board READY.\n");
51164 dev_info(&h->pdev->dev,
51165 "Waiting for stale completions to drain.\n");
51166 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51167 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51168 msleep(10000);
51169 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51170 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51171
51172 rc = controller_reset_failed(h->cfgtable);
51173 if (rc)
51174 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51175 h->drv_req_rescan = 0;
51176
51177 /* Turn the interrupts on so we can service requests */
51178 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51179 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51180
51181 hpsa_hba_inquiry(h);
51182 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51183 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51184 * To write all data in the battery backed cache to disks
51185 */
51186 hpsa_flush_cache(h);
51187 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51188 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51189 hpsa_free_irqs_and_disable_msix(h);
51190 }
51191
51192 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51193 CFGTBL_Trans_enable_directed_msix |
51194 (trans_support & (CFGTBL_Trans_io_accel1 |
51195 CFGTBL_Trans_io_accel2));
51196 - struct access_method access = SA5_performant_access;
51197 + struct access_method *access = &SA5_performant_access;
51198
51199 /* This is a bit complicated. There are 8 registers on
51200 * the controller which we write to to tell it 8 different
51201 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51202 * perform the superfluous readl() after each command submission.
51203 */
51204 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51205 - access = SA5_performant_access_no_read;
51206 + access = &SA5_performant_access_no_read;
51207
51208 /* Controller spec: zero out this buffer. */
51209 for (i = 0; i < h->nreply_queues; i++)
51210 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51211 * enable outbound interrupt coalescing in accelerator mode;
51212 */
51213 if (trans_support & CFGTBL_Trans_io_accel1) {
51214 - access = SA5_ioaccel_mode1_access;
51215 + access = &SA5_ioaccel_mode1_access;
51216 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51217 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51218 } else {
51219 if (trans_support & CFGTBL_Trans_io_accel2) {
51220 - access = SA5_ioaccel_mode2_access;
51221 + access = &SA5_ioaccel_mode2_access;
51222 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51223 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51224 }
51225 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51226 index 24472ce..8782caf 100644
51227 --- a/drivers/scsi/hpsa.h
51228 +++ b/drivers/scsi/hpsa.h
51229 @@ -127,7 +127,7 @@ struct ctlr_info {
51230 unsigned int msix_vector;
51231 unsigned int msi_vector;
51232 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51233 - struct access_method access;
51234 + struct access_method *access;
51235 char hba_mode_enabled;
51236
51237 /* queue and queue Info */
51238 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51239 }
51240
51241 static struct access_method SA5_access = {
51242 - SA5_submit_command,
51243 - SA5_intr_mask,
51244 - SA5_fifo_full,
51245 - SA5_intr_pending,
51246 - SA5_completed,
51247 + .submit_command = SA5_submit_command,
51248 + .set_intr_mask = SA5_intr_mask,
51249 + .fifo_full = SA5_fifo_full,
51250 + .intr_pending = SA5_intr_pending,
51251 + .command_completed = SA5_completed,
51252 };
51253
51254 static struct access_method SA5_ioaccel_mode1_access = {
51255 - SA5_submit_command,
51256 - SA5_performant_intr_mask,
51257 - SA5_fifo_full,
51258 - SA5_ioaccel_mode1_intr_pending,
51259 - SA5_ioaccel_mode1_completed,
51260 + .submit_command = SA5_submit_command,
51261 + .set_intr_mask = SA5_performant_intr_mask,
51262 + .fifo_full = SA5_fifo_full,
51263 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51264 + .command_completed = SA5_ioaccel_mode1_completed,
51265 };
51266
51267 static struct access_method SA5_ioaccel_mode2_access = {
51268 - SA5_submit_command_ioaccel2,
51269 - SA5_performant_intr_mask,
51270 - SA5_fifo_full,
51271 - SA5_performant_intr_pending,
51272 - SA5_performant_completed,
51273 + .submit_command = SA5_submit_command_ioaccel2,
51274 + .set_intr_mask = SA5_performant_intr_mask,
51275 + .fifo_full = SA5_fifo_full,
51276 + .intr_pending = SA5_performant_intr_pending,
51277 + .command_completed = SA5_performant_completed,
51278 };
51279
51280 static struct access_method SA5_performant_access = {
51281 - SA5_submit_command,
51282 - SA5_performant_intr_mask,
51283 - SA5_fifo_full,
51284 - SA5_performant_intr_pending,
51285 - SA5_performant_completed,
51286 + .submit_command = SA5_submit_command,
51287 + .set_intr_mask = SA5_performant_intr_mask,
51288 + .fifo_full = SA5_fifo_full,
51289 + .intr_pending = SA5_performant_intr_pending,
51290 + .command_completed = SA5_performant_completed,
51291 };
51292
51293 static struct access_method SA5_performant_access_no_read = {
51294 - SA5_submit_command_no_read,
51295 - SA5_performant_intr_mask,
51296 - SA5_fifo_full,
51297 - SA5_performant_intr_pending,
51298 - SA5_performant_completed,
51299 + .submit_command = SA5_submit_command_no_read,
51300 + .set_intr_mask = SA5_performant_intr_mask,
51301 + .fifo_full = SA5_fifo_full,
51302 + .intr_pending = SA5_performant_intr_pending,
51303 + .command_completed = SA5_performant_completed,
51304 };
51305
51306 struct board_type {
51307 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51308 index 1b3a094..068e683 100644
51309 --- a/drivers/scsi/libfc/fc_exch.c
51310 +++ b/drivers/scsi/libfc/fc_exch.c
51311 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51312 u16 pool_max_index;
51313
51314 struct {
51315 - atomic_t no_free_exch;
51316 - atomic_t no_free_exch_xid;
51317 - atomic_t xid_not_found;
51318 - atomic_t xid_busy;
51319 - atomic_t seq_not_found;
51320 - atomic_t non_bls_resp;
51321 + atomic_unchecked_t no_free_exch;
51322 + atomic_unchecked_t no_free_exch_xid;
51323 + atomic_unchecked_t xid_not_found;
51324 + atomic_unchecked_t xid_busy;
51325 + atomic_unchecked_t seq_not_found;
51326 + atomic_unchecked_t non_bls_resp;
51327 } stats;
51328 };
51329
51330 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51331 /* allocate memory for exchange */
51332 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51333 if (!ep) {
51334 - atomic_inc(&mp->stats.no_free_exch);
51335 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51336 goto out;
51337 }
51338 memset(ep, 0, sizeof(*ep));
51339 @@ -874,7 +874,7 @@ out:
51340 return ep;
51341 err:
51342 spin_unlock_bh(&pool->lock);
51343 - atomic_inc(&mp->stats.no_free_exch_xid);
51344 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51345 mempool_free(ep, mp->ep_pool);
51346 return NULL;
51347 }
51348 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51349 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51350 ep = fc_exch_find(mp, xid);
51351 if (!ep) {
51352 - atomic_inc(&mp->stats.xid_not_found);
51353 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51354 reject = FC_RJT_OX_ID;
51355 goto out;
51356 }
51357 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51358 ep = fc_exch_find(mp, xid);
51359 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51360 if (ep) {
51361 - atomic_inc(&mp->stats.xid_busy);
51362 + atomic_inc_unchecked(&mp->stats.xid_busy);
51363 reject = FC_RJT_RX_ID;
51364 goto rel;
51365 }
51366 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51367 }
51368 xid = ep->xid; /* get our XID */
51369 } else if (!ep) {
51370 - atomic_inc(&mp->stats.xid_not_found);
51371 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51372 reject = FC_RJT_RX_ID; /* XID not found */
51373 goto out;
51374 }
51375 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51376 } else {
51377 sp = &ep->seq;
51378 if (sp->id != fh->fh_seq_id) {
51379 - atomic_inc(&mp->stats.seq_not_found);
51380 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51381 if (f_ctl & FC_FC_END_SEQ) {
51382 /*
51383 * Update sequence_id based on incoming last
51384 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51385
51386 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51387 if (!ep) {
51388 - atomic_inc(&mp->stats.xid_not_found);
51389 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51390 goto out;
51391 }
51392 if (ep->esb_stat & ESB_ST_COMPLETE) {
51393 - atomic_inc(&mp->stats.xid_not_found);
51394 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51395 goto rel;
51396 }
51397 if (ep->rxid == FC_XID_UNKNOWN)
51398 ep->rxid = ntohs(fh->fh_rx_id);
51399 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51400 - atomic_inc(&mp->stats.xid_not_found);
51401 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51402 goto rel;
51403 }
51404 if (ep->did != ntoh24(fh->fh_s_id) &&
51405 ep->did != FC_FID_FLOGI) {
51406 - atomic_inc(&mp->stats.xid_not_found);
51407 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51408 goto rel;
51409 }
51410 sof = fr_sof(fp);
51411 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51412 sp->ssb_stat |= SSB_ST_RESP;
51413 sp->id = fh->fh_seq_id;
51414 } else if (sp->id != fh->fh_seq_id) {
51415 - atomic_inc(&mp->stats.seq_not_found);
51416 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51417 goto rel;
51418 }
51419
51420 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51421 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51422
51423 if (!sp)
51424 - atomic_inc(&mp->stats.xid_not_found);
51425 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51426 else
51427 - atomic_inc(&mp->stats.non_bls_resp);
51428 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51429
51430 fc_frame_free(fp);
51431 }
51432 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51433
51434 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51435 mp = ema->mp;
51436 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51437 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51438 st->fc_no_free_exch_xid +=
51439 - atomic_read(&mp->stats.no_free_exch_xid);
51440 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51441 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51442 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51443 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51444 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51445 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51446 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51447 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51448 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51449 }
51450 }
51451 EXPORT_SYMBOL(fc_exch_update_stats);
51452 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51453 index 766098a..1c6c971 100644
51454 --- a/drivers/scsi/libsas/sas_ata.c
51455 +++ b/drivers/scsi/libsas/sas_ata.c
51456 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51457 .postreset = ata_std_postreset,
51458 .error_handler = ata_std_error_handler,
51459 .post_internal_cmd = sas_ata_post_internal,
51460 - .qc_defer = ata_std_qc_defer,
51461 + .qc_defer = ata_std_qc_defer,
51462 .qc_prep = ata_noop_qc_prep,
51463 .qc_issue = sas_ata_qc_issue,
51464 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51465 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51466 index 434e903..5a4a79b 100644
51467 --- a/drivers/scsi/lpfc/lpfc.h
51468 +++ b/drivers/scsi/lpfc/lpfc.h
51469 @@ -430,7 +430,7 @@ struct lpfc_vport {
51470 struct dentry *debug_nodelist;
51471 struct dentry *vport_debugfs_root;
51472 struct lpfc_debugfs_trc *disc_trc;
51473 - atomic_t disc_trc_cnt;
51474 + atomic_unchecked_t disc_trc_cnt;
51475 #endif
51476 uint8_t stat_data_enabled;
51477 uint8_t stat_data_blocked;
51478 @@ -880,8 +880,8 @@ struct lpfc_hba {
51479 struct timer_list fabric_block_timer;
51480 unsigned long bit_flags;
51481 #define FABRIC_COMANDS_BLOCKED 0
51482 - atomic_t num_rsrc_err;
51483 - atomic_t num_cmd_success;
51484 + atomic_unchecked_t num_rsrc_err;
51485 + atomic_unchecked_t num_cmd_success;
51486 unsigned long last_rsrc_error_time;
51487 unsigned long last_ramp_down_time;
51488 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51489 @@ -916,7 +916,7 @@ struct lpfc_hba {
51490
51491 struct dentry *debug_slow_ring_trc;
51492 struct lpfc_debugfs_trc *slow_ring_trc;
51493 - atomic_t slow_ring_trc_cnt;
51494 + atomic_unchecked_t slow_ring_trc_cnt;
51495 /* iDiag debugfs sub-directory */
51496 struct dentry *idiag_root;
51497 struct dentry *idiag_pci_cfg;
51498 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51499 index 786a2af..562c6a2 100644
51500 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51501 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51502 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51503
51504 #include <linux/debugfs.h>
51505
51506 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51507 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51508 static unsigned long lpfc_debugfs_start_time = 0L;
51509
51510 /* iDiag */
51511 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51512 lpfc_debugfs_enable = 0;
51513
51514 len = 0;
51515 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51516 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51517 (lpfc_debugfs_max_disc_trc - 1);
51518 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51519 dtp = vport->disc_trc + i;
51520 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51521 lpfc_debugfs_enable = 0;
51522
51523 len = 0;
51524 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51525 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51526 (lpfc_debugfs_max_slow_ring_trc - 1);
51527 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51528 dtp = phba->slow_ring_trc + i;
51529 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51530 !vport || !vport->disc_trc)
51531 return;
51532
51533 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51534 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51535 (lpfc_debugfs_max_disc_trc - 1);
51536 dtp = vport->disc_trc + index;
51537 dtp->fmt = fmt;
51538 dtp->data1 = data1;
51539 dtp->data2 = data2;
51540 dtp->data3 = data3;
51541 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51542 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51543 dtp->jif = jiffies;
51544 #endif
51545 return;
51546 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51547 !phba || !phba->slow_ring_trc)
51548 return;
51549
51550 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51551 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51552 (lpfc_debugfs_max_slow_ring_trc - 1);
51553 dtp = phba->slow_ring_trc + index;
51554 dtp->fmt = fmt;
51555 dtp->data1 = data1;
51556 dtp->data2 = data2;
51557 dtp->data3 = data3;
51558 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51559 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51560 dtp->jif = jiffies;
51561 #endif
51562 return;
51563 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51564 "slow_ring buffer\n");
51565 goto debug_failed;
51566 }
51567 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51568 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51569 memset(phba->slow_ring_trc, 0,
51570 (sizeof(struct lpfc_debugfs_trc) *
51571 lpfc_debugfs_max_slow_ring_trc));
51572 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51573 "buffer\n");
51574 goto debug_failed;
51575 }
51576 - atomic_set(&vport->disc_trc_cnt, 0);
51577 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51578
51579 snprintf(name, sizeof(name), "discovery_trace");
51580 vport->debug_disc_trc =
51581 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51582 index 0b2c53a..aec2b45 100644
51583 --- a/drivers/scsi/lpfc/lpfc_init.c
51584 +++ b/drivers/scsi/lpfc/lpfc_init.c
51585 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51586 "misc_register returned with status %d", error);
51587
51588 if (lpfc_enable_npiv) {
51589 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51590 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51591 + pax_open_kernel();
51592 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51593 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51594 + pax_close_kernel();
51595 }
51596 lpfc_transport_template =
51597 fc_attach_transport(&lpfc_transport_functions);
51598 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51599 index b99399f..d29dc75 100644
51600 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51601 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51602 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51603 unsigned long expires;
51604
51605 spin_lock_irqsave(&phba->hbalock, flags);
51606 - atomic_inc(&phba->num_rsrc_err);
51607 + atomic_inc_unchecked(&phba->num_rsrc_err);
51608 phba->last_rsrc_error_time = jiffies;
51609
51610 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51611 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51612 unsigned long num_rsrc_err, num_cmd_success;
51613 int i;
51614
51615 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51616 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51617 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51618 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51619
51620 /*
51621 * The error and success command counters are global per
51622 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51623 }
51624 }
51625 lpfc_destroy_vport_work_array(phba, vports);
51626 - atomic_set(&phba->num_rsrc_err, 0);
51627 - atomic_set(&phba->num_cmd_success, 0);
51628 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51629 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51630 }
51631
51632 /**
51633 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51634 index c80ed04..e674f01 100644
51635 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51636 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51637 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51638 {
51639 struct scsi_device *sdev = to_scsi_device(dev);
51640 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51641 - static struct _raid_device *raid_device;
51642 + struct _raid_device *raid_device;
51643 unsigned long flags;
51644 Mpi2RaidVolPage0_t vol_pg0;
51645 Mpi2ConfigReply_t mpi_reply;
51646 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51647 {
51648 struct scsi_device *sdev = to_scsi_device(dev);
51649 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51650 - static struct _raid_device *raid_device;
51651 + struct _raid_device *raid_device;
51652 unsigned long flags;
51653 Mpi2RaidVolPage0_t vol_pg0;
51654 Mpi2ConfigReply_t mpi_reply;
51655 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51656 Mpi2EventDataIrOperationStatus_t *event_data =
51657 (Mpi2EventDataIrOperationStatus_t *)
51658 fw_event->event_data;
51659 - static struct _raid_device *raid_device;
51660 + struct _raid_device *raid_device;
51661 unsigned long flags;
51662 u16 handle;
51663
51664 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51665 u64 sas_address;
51666 struct _sas_device *sas_device;
51667 struct _sas_node *expander_device;
51668 - static struct _raid_device *raid_device;
51669 + struct _raid_device *raid_device;
51670 u8 retry_count;
51671 unsigned long flags;
51672
51673 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51674 index bcb64eb..f08cf71 100644
51675 --- a/drivers/scsi/pmcraid.c
51676 +++ b/drivers/scsi/pmcraid.c
51677 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51678 res->scsi_dev = scsi_dev;
51679 scsi_dev->hostdata = res;
51680 res->change_detected = 0;
51681 - atomic_set(&res->read_failures, 0);
51682 - atomic_set(&res->write_failures, 0);
51683 + atomic_set_unchecked(&res->read_failures, 0);
51684 + atomic_set_unchecked(&res->write_failures, 0);
51685 rc = 0;
51686 }
51687 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51688 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51689
51690 /* If this was a SCSI read/write command keep count of errors */
51691 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51692 - atomic_inc(&res->read_failures);
51693 + atomic_inc_unchecked(&res->read_failures);
51694 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51695 - atomic_inc(&res->write_failures);
51696 + atomic_inc_unchecked(&res->write_failures);
51697
51698 if (!RES_IS_GSCSI(res->cfg_entry) &&
51699 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51700 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51701 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51702 * hrrq_id assigned here in queuecommand
51703 */
51704 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51705 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51706 pinstance->num_hrrq;
51707 cmd->cmd_done = pmcraid_io_done;
51708
51709 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51710 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51711 * hrrq_id assigned here in queuecommand
51712 */
51713 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51714 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51715 pinstance->num_hrrq;
51716
51717 if (request_size) {
51718 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51719
51720 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51721 /* add resources only after host is added into system */
51722 - if (!atomic_read(&pinstance->expose_resources))
51723 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51724 return;
51725
51726 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51727 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51728 init_waitqueue_head(&pinstance->reset_wait_q);
51729
51730 atomic_set(&pinstance->outstanding_cmds, 0);
51731 - atomic_set(&pinstance->last_message_id, 0);
51732 - atomic_set(&pinstance->expose_resources, 0);
51733 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51734 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51735
51736 INIT_LIST_HEAD(&pinstance->free_res_q);
51737 INIT_LIST_HEAD(&pinstance->used_res_q);
51738 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51739 /* Schedule worker thread to handle CCN and take care of adding and
51740 * removing devices to OS
51741 */
51742 - atomic_set(&pinstance->expose_resources, 1);
51743 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51744 schedule_work(&pinstance->worker_q);
51745 return rc;
51746
51747 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51748 index e1d150f..6c6df44 100644
51749 --- a/drivers/scsi/pmcraid.h
51750 +++ b/drivers/scsi/pmcraid.h
51751 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51752 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51753
51754 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51755 - atomic_t last_message_id;
51756 + atomic_unchecked_t last_message_id;
51757
51758 /* configuration table */
51759 struct pmcraid_config_table *cfg_table;
51760 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51761 atomic_t outstanding_cmds;
51762
51763 /* should add/delete resources to mid-layer now ?*/
51764 - atomic_t expose_resources;
51765 + atomic_unchecked_t expose_resources;
51766
51767
51768
51769 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51770 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51771 };
51772 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51773 - atomic_t read_failures; /* count of failed READ commands */
51774 - atomic_t write_failures; /* count of failed WRITE commands */
51775 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51776 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51777
51778 /* To indicate add/delete/modify during CCN */
51779 u8 change_detected;
51780 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51781 index 82b92c4..3178171 100644
51782 --- a/drivers/scsi/qla2xxx/qla_attr.c
51783 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51784 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51785 return 0;
51786 }
51787
51788 -struct fc_function_template qla2xxx_transport_functions = {
51789 +fc_function_template_no_const qla2xxx_transport_functions = {
51790
51791 .show_host_node_name = 1,
51792 .show_host_port_name = 1,
51793 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51794 .bsg_timeout = qla24xx_bsg_timeout,
51795 };
51796
51797 -struct fc_function_template qla2xxx_transport_vport_functions = {
51798 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51799
51800 .show_host_node_name = 1,
51801 .show_host_port_name = 1,
51802 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51803 index b1865a7..a7723d3 100644
51804 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51805 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51806 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51807 struct device_attribute;
51808 extern struct device_attribute *qla2x00_host_attrs[];
51809 struct fc_function_template;
51810 -extern struct fc_function_template qla2xxx_transport_functions;
51811 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51812 +extern fc_function_template_no_const qla2xxx_transport_functions;
51813 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51814 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51815 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51816 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51817 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51818 index db3dbd9..2492392 100644
51819 --- a/drivers/scsi/qla2xxx/qla_os.c
51820 +++ b/drivers/scsi/qla2xxx/qla_os.c
51821 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51822 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51823 /* Ok, a 64bit DMA mask is applicable. */
51824 ha->flags.enable_64bit_addressing = 1;
51825 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51826 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51827 + pax_open_kernel();
51828 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51829 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51830 + pax_close_kernel();
51831 return;
51832 }
51833 }
51834 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51835 index 8f6d0fb..1b21097 100644
51836 --- a/drivers/scsi/qla4xxx/ql4_def.h
51837 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51838 @@ -305,7 +305,7 @@ struct ddb_entry {
51839 * (4000 only) */
51840 atomic_t relogin_timer; /* Max Time to wait for
51841 * relogin to complete */
51842 - atomic_t relogin_retry_count; /* Num of times relogin has been
51843 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51844 * retried */
51845 uint32_t default_time2wait; /* Default Min time between
51846 * relogins (+aens) */
51847 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51848 index 199fcf7..3c3a918 100644
51849 --- a/drivers/scsi/qla4xxx/ql4_os.c
51850 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51851 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51852 */
51853 if (!iscsi_is_session_online(cls_sess)) {
51854 /* Reset retry relogin timer */
51855 - atomic_inc(&ddb_entry->relogin_retry_count);
51856 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51857 DEBUG2(ql4_printk(KERN_INFO, ha,
51858 "%s: index[%d] relogin timed out-retrying"
51859 " relogin (%d), retry (%d)\n", __func__,
51860 ddb_entry->fw_ddb_index,
51861 - atomic_read(&ddb_entry->relogin_retry_count),
51862 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51863 ddb_entry->default_time2wait + 4));
51864 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51865 atomic_set(&ddb_entry->retry_relogin_timer,
51866 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51867
51868 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51869 atomic_set(&ddb_entry->relogin_timer, 0);
51870 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51871 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51872 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51873 ddb_entry->default_relogin_timeout =
51874 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51875 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51876 index 79c77b4..ef6ec0b 100644
51877 --- a/drivers/scsi/scsi.c
51878 +++ b/drivers/scsi/scsi.c
51879 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51880 struct Scsi_Host *host = cmd->device->host;
51881 int rtn = 0;
51882
51883 - atomic_inc(&cmd->device->iorequest_cnt);
51884 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51885
51886 /* check if the device is still usable */
51887 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51888 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51889 index 17fb051..937fbbd 100644
51890 --- a/drivers/scsi/scsi_lib.c
51891 +++ b/drivers/scsi/scsi_lib.c
51892 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51893 shost = sdev->host;
51894 scsi_init_cmd_errh(cmd);
51895 cmd->result = DID_NO_CONNECT << 16;
51896 - atomic_inc(&cmd->device->iorequest_cnt);
51897 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51898
51899 /*
51900 * SCSI request completion path will do scsi_device_unbusy(),
51901 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51902
51903 INIT_LIST_HEAD(&cmd->eh_entry);
51904
51905 - atomic_inc(&cmd->device->iodone_cnt);
51906 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51907 if (cmd->result)
51908 - atomic_inc(&cmd->device->ioerr_cnt);
51909 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51910
51911 disposition = scsi_decide_disposition(cmd);
51912 if (disposition != SUCCESS &&
51913 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51914 index f4cb7b3..dfa79c4 100644
51915 --- a/drivers/scsi/scsi_sysfs.c
51916 +++ b/drivers/scsi/scsi_sysfs.c
51917 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51918 char *buf) \
51919 { \
51920 struct scsi_device *sdev = to_scsi_device(dev); \
51921 - unsigned long long count = atomic_read(&sdev->field); \
51922 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51923 return snprintf(buf, 20, "0x%llx\n", count); \
51924 } \
51925 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51926 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51927 index 5d6f348..18778a6b 100644
51928 --- a/drivers/scsi/scsi_transport_fc.c
51929 +++ b/drivers/scsi/scsi_transport_fc.c
51930 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51931 * Netlink Infrastructure
51932 */
51933
51934 -static atomic_t fc_event_seq;
51935 +static atomic_unchecked_t fc_event_seq;
51936
51937 /**
51938 * fc_get_event_number - Obtain the next sequential FC event number
51939 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51940 u32
51941 fc_get_event_number(void)
51942 {
51943 - return atomic_add_return(1, &fc_event_seq);
51944 + return atomic_add_return_unchecked(1, &fc_event_seq);
51945 }
51946 EXPORT_SYMBOL(fc_get_event_number);
51947
51948 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51949 {
51950 int error;
51951
51952 - atomic_set(&fc_event_seq, 0);
51953 + atomic_set_unchecked(&fc_event_seq, 0);
51954
51955 error = transport_class_register(&fc_host_class);
51956 if (error)
51957 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51958 char *cp;
51959
51960 *val = simple_strtoul(buf, &cp, 0);
51961 - if ((*cp && (*cp != '\n')) || (*val < 0))
51962 + if (*cp && (*cp != '\n'))
51963 return -EINVAL;
51964 /*
51965 * Check for overflow; dev_loss_tmo is u32
51966 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51967 index 67d43e3..8cee73c 100644
51968 --- a/drivers/scsi/scsi_transport_iscsi.c
51969 +++ b/drivers/scsi/scsi_transport_iscsi.c
51970 @@ -79,7 +79,7 @@ struct iscsi_internal {
51971 struct transport_container session_cont;
51972 };
51973
51974 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51975 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51976 static struct workqueue_struct *iscsi_eh_timer_workq;
51977
51978 static DEFINE_IDA(iscsi_sess_ida);
51979 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
51980 int err;
51981
51982 ihost = shost->shost_data;
51983 - session->sid = atomic_add_return(1, &iscsi_session_nr);
51984 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
51985
51986 if (target_id == ISCSI_MAX_TARGET) {
51987 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
51988 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
51989 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
51990 ISCSI_TRANSPORT_VERSION);
51991
51992 - atomic_set(&iscsi_session_nr, 0);
51993 + atomic_set_unchecked(&iscsi_session_nr, 0);
51994
51995 err = class_register(&iscsi_transport_class);
51996 if (err)
51997 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
51998 index ae45bd9..c32a586 100644
51999 --- a/drivers/scsi/scsi_transport_srp.c
52000 +++ b/drivers/scsi/scsi_transport_srp.c
52001 @@ -35,7 +35,7 @@
52002 #include "scsi_priv.h"
52003
52004 struct srp_host_attrs {
52005 - atomic_t next_port_id;
52006 + atomic_unchecked_t next_port_id;
52007 };
52008 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52009
52010 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52011 struct Scsi_Host *shost = dev_to_shost(dev);
52012 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52013
52014 - atomic_set(&srp_host->next_port_id, 0);
52015 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52016 return 0;
52017 }
52018
52019 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52020 rport_fast_io_fail_timedout);
52021 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52022
52023 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52024 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52025 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52026
52027 transport_setup_device(&rport->dev);
52028 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52029 index cfba74c..415f09b 100644
52030 --- a/drivers/scsi/sd.c
52031 +++ b/drivers/scsi/sd.c
52032 @@ -3022,7 +3022,7 @@ static int sd_probe(struct device *dev)
52033 sdkp->disk = gd;
52034 sdkp->index = index;
52035 atomic_set(&sdkp->openers, 0);
52036 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52037 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52038
52039 if (!sdp->request_queue->rq_timeout) {
52040 if (sdp->type != TYPE_MOD)
52041 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52042 index 6035444..c82edd4 100644
52043 --- a/drivers/scsi/sg.c
52044 +++ b/drivers/scsi/sg.c
52045 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52046 sdp->disk->disk_name,
52047 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52048 NULL,
52049 - (char *)arg);
52050 + (char __user *)arg);
52051 case BLKTRACESTART:
52052 return blk_trace_startstop(sdp->device->request_queue, 1);
52053 case BLKTRACESTOP:
52054 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52055 index 11a5043..e36f04c 100644
52056 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52057 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52058 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52059 return i;
52060 }
52061
52062 -static struct bin_attribute fuse_bin_attr = {
52063 +static bin_attribute_no_const fuse_bin_attr = {
52064 .attr = { .name = "fuse", .mode = S_IRUGO, },
52065 .read = fuse_read,
52066 };
52067 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52068 index 50f20f2..6bd81e0 100644
52069 --- a/drivers/spi/spi.c
52070 +++ b/drivers/spi/spi.c
52071 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
52072 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52073
52074 /* portable code must never pass more than 32 bytes */
52075 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52076 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52077
52078 static u8 *buf;
52079
52080 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52081 index b41429f..2de5373 100644
52082 --- a/drivers/staging/android/timed_output.c
52083 +++ b/drivers/staging/android/timed_output.c
52084 @@ -25,7 +25,7 @@
52085 #include "timed_output.h"
52086
52087 static struct class *timed_output_class;
52088 -static atomic_t device_count;
52089 +static atomic_unchecked_t device_count;
52090
52091 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52092 char *buf)
52093 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52094 timed_output_class = class_create(THIS_MODULE, "timed_output");
52095 if (IS_ERR(timed_output_class))
52096 return PTR_ERR(timed_output_class);
52097 - atomic_set(&device_count, 0);
52098 + atomic_set_unchecked(&device_count, 0);
52099 timed_output_class->dev_groups = timed_output_groups;
52100 }
52101
52102 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52103 if (ret < 0)
52104 return ret;
52105
52106 - tdev->index = atomic_inc_return(&device_count);
52107 + tdev->index = atomic_inc_return_unchecked(&device_count);
52108 tdev->dev = device_create(timed_output_class, NULL,
52109 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52110 if (IS_ERR(tdev->dev))
52111 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52112 index 001348c..cfaac8a 100644
52113 --- a/drivers/staging/gdm724x/gdm_tty.c
52114 +++ b/drivers/staging/gdm724x/gdm_tty.c
52115 @@ -44,7 +44,7 @@
52116 #define gdm_tty_send_control(n, r, v, d, l) (\
52117 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52118
52119 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52120 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52121
52122 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52123 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52124 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52125 index 9cb222e..8766f26 100644
52126 --- a/drivers/staging/imx-drm/imx-drm-core.c
52127 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52128 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52129 if (imxdrm->pipes >= MAX_CRTC)
52130 return -EINVAL;
52131
52132 - if (imxdrm->drm->open_count)
52133 + if (local_read(&imxdrm->drm->open_count))
52134 return -EBUSY;
52135
52136 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52137 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52138 index 503b2d7..c904931 100644
52139 --- a/drivers/staging/line6/driver.c
52140 +++ b/drivers/staging/line6/driver.c
52141 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52142 {
52143 struct usb_device *usbdev = line6->usbdev;
52144 int ret;
52145 - unsigned char len;
52146 + unsigned char *plen;
52147
52148 /* query the serial number: */
52149 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52150 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52151 return ret;
52152 }
52153
52154 + plen = kmalloc(1, GFP_KERNEL);
52155 + if (plen == NULL)
52156 + return -ENOMEM;
52157 +
52158 /* Wait for data length. We'll get 0xff until length arrives. */
52159 do {
52160 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52161 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52162 USB_DIR_IN,
52163 - 0x0012, 0x0000, &len, 1,
52164 + 0x0012, 0x0000, plen, 1,
52165 LINE6_TIMEOUT * HZ);
52166 if (ret < 0) {
52167 dev_err(line6->ifcdev,
52168 "receive length failed (error %d)\n", ret);
52169 + kfree(plen);
52170 return ret;
52171 }
52172 - } while (len == 0xff);
52173 + } while (*plen == 0xff);
52174
52175 - if (len != datalen) {
52176 + if (*plen != datalen) {
52177 /* should be equal or something went wrong */
52178 dev_err(line6->ifcdev,
52179 "length mismatch (expected %d, got %d)\n",
52180 - (int)datalen, (int)len);
52181 + (int)datalen, (int)*plen);
52182 + kfree(plen);
52183 return -EINVAL;
52184 }
52185 + kfree(plen);
52186
52187 /* receive the result: */
52188 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52189 @@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52190 {
52191 struct usb_device *usbdev = line6->usbdev;
52192 int ret;
52193 - unsigned char status;
52194 + unsigned char *status;
52195
52196 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52197 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52198 @@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52199 return ret;
52200 }
52201
52202 + status = kmalloc(1, GFP_KERNEL);
52203 + if (status == NULL)
52204 + return -ENOMEM;
52205 +
52206 do {
52207 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52208 0x67,
52209 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52210 USB_DIR_IN,
52211 0x0012, 0x0000,
52212 - &status, 1, LINE6_TIMEOUT * HZ);
52213 + status, 1, LINE6_TIMEOUT * HZ);
52214
52215 if (ret < 0) {
52216 dev_err(line6->ifcdev,
52217 "receiving status failed (error %d)\n", ret);
52218 + kfree(status);
52219 return ret;
52220 }
52221 - } while (status == 0xff);
52222 + } while (*status == 0xff);
52223
52224 - if (status != 0) {
52225 + if (*status != 0) {
52226 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52227 + kfree(status);
52228 return -EINVAL;
52229 }
52230
52231 + kfree(status);
52232 +
52233 return 0;
52234 }
52235
52236 diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52237 index 6943715..0a93632 100644
52238 --- a/drivers/staging/line6/toneport.c
52239 +++ b/drivers/staging/line6/toneport.c
52240 @@ -11,6 +11,7 @@
52241 */
52242
52243 #include <linux/wait.h>
52244 +#include <linux/slab.h>
52245 #include <sound/control.h>
52246
52247 #include "audio.h"
52248 @@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52249 */
52250 static void toneport_setup(struct usb_line6_toneport *toneport)
52251 {
52252 - int ticks;
52253 + int *ticks;
52254 struct usb_line6 *line6 = &toneport->line6;
52255 struct usb_device *usbdev = line6->usbdev;
52256 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52257
52258 + ticks = kmalloc(sizeof(int), GFP_KERNEL);
52259 + if (ticks == NULL)
52260 + return;
52261 +
52262 /* sync time on device with host: */
52263 - ticks = (int)get_seconds();
52264 - line6_write_data(line6, 0x80c6, &ticks, 4);
52265 + *ticks = (int)get_seconds();
52266 + line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52267 +
52268 + kfree(ticks);
52269
52270 /* enable device: */
52271 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52272 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52273 index a94f336..6a1924d 100644
52274 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52275 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52276 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52277 return 0;
52278 }
52279
52280 -sfw_test_client_ops_t brw_test_client;
52281 -void brw_init_test_client(void)
52282 -{
52283 - brw_test_client.tso_init = brw_client_init;
52284 - brw_test_client.tso_fini = brw_client_fini;
52285 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52286 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52287 +sfw_test_client_ops_t brw_test_client = {
52288 + .tso_init = brw_client_init,
52289 + .tso_fini = brw_client_fini,
52290 + .tso_prep_rpc = brw_client_prep_rpc,
52291 + .tso_done_rpc = brw_client_done_rpc,
52292 };
52293
52294 srpc_service_t brw_test_service;
52295 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52296 index df04ab7..1deb1ac 100644
52297 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52298 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52299 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52300
52301 extern sfw_test_client_ops_t ping_test_client;
52302 extern srpc_service_t ping_test_service;
52303 -extern void ping_init_test_client(void);
52304 extern void ping_init_test_service(void);
52305
52306 extern sfw_test_client_ops_t brw_test_client;
52307 extern srpc_service_t brw_test_service;
52308 -extern void brw_init_test_client(void);
52309 extern void brw_init_test_service(void);
52310
52311
52312 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52313 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52314 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52315
52316 - brw_init_test_client();
52317 brw_init_test_service();
52318 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52319 LASSERT (rc == 0);
52320
52321 - ping_init_test_client();
52322 ping_init_test_service();
52323 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52324 LASSERT (rc == 0);
52325 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52326 index 750cac4..e4d751f 100644
52327 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52328 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52329 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52330 return 0;
52331 }
52332
52333 -sfw_test_client_ops_t ping_test_client;
52334 -void ping_init_test_client(void)
52335 -{
52336 - ping_test_client.tso_init = ping_client_init;
52337 - ping_test_client.tso_fini = ping_client_fini;
52338 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52339 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52340 -}
52341 +sfw_test_client_ops_t ping_test_client = {
52342 + .tso_init = ping_client_init,
52343 + .tso_fini = ping_client_fini,
52344 + .tso_prep_rpc = ping_client_prep_rpc,
52345 + .tso_done_rpc = ping_client_done_rpc,
52346 +};
52347
52348 srpc_service_t ping_test_service;
52349 void ping_init_test_service(void)
52350 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52351 index 14ac46f..eca2c16 100644
52352 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52353 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52354 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52355 ldlm_completion_callback lcs_completion;
52356 ldlm_blocking_callback lcs_blocking;
52357 ldlm_glimpse_callback lcs_glimpse;
52358 -};
52359 +} __no_const;
52360
52361 /* ldlm_lockd.c */
52362 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52363 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52364 index 2a88b80..62e7e5f 100644
52365 --- a/drivers/staging/lustre/lustre/include/obd.h
52366 +++ b/drivers/staging/lustre/lustre/include/obd.h
52367 @@ -1362,7 +1362,7 @@ struct md_ops {
52368 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52369 * wrapper function in include/linux/obd_class.h.
52370 */
52371 -};
52372 +} __no_const;
52373
52374 struct lsm_operations {
52375 void (*lsm_free)(struct lov_stripe_md *);
52376 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52377 index b798daa..b28ca8f 100644
52378 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52379 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52380 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52381 int added = (mode == LCK_NL);
52382 int overlaps = 0;
52383 int splitted = 0;
52384 - const struct ldlm_callback_suite null_cbs = { NULL };
52385 + const struct ldlm_callback_suite null_cbs = { };
52386
52387 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52388 *flags, new->l_policy_data.l_flock.owner,
52389 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52390 index bbe2c68..c6b4275 100644
52391 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52392 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52393 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52394 void __user *buffer, size_t *lenp, loff_t *ppos)
52395 {
52396 int rc, max_delay_cs;
52397 - struct ctl_table dummy = *table;
52398 + ctl_table_no_const dummy = *table;
52399 long d;
52400
52401 dummy.data = &max_delay_cs;
52402 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52403 void __user *buffer, size_t *lenp, loff_t *ppos)
52404 {
52405 int rc, min_delay_cs;
52406 - struct ctl_table dummy = *table;
52407 + ctl_table_no_const dummy = *table;
52408 long d;
52409
52410 dummy.data = &min_delay_cs;
52411 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52412 void __user *buffer, size_t *lenp, loff_t *ppos)
52413 {
52414 int rc, backoff;
52415 - struct ctl_table dummy = *table;
52416 + ctl_table_no_const dummy = *table;
52417
52418 dummy.data = &backoff;
52419 dummy.proc_handler = &proc_dointvec;
52420 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52421 index 2c4fc74..b04ca79 100644
52422 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52423 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52424 @@ -315,11 +315,11 @@ out:
52425
52426
52427 struct cfs_psdev_ops libcfs_psdev_ops = {
52428 - libcfs_psdev_open,
52429 - libcfs_psdev_release,
52430 - NULL,
52431 - NULL,
52432 - libcfs_ioctl
52433 + .p_open = libcfs_psdev_open,
52434 + .p_close = libcfs_psdev_release,
52435 + .p_read = NULL,
52436 + .p_write = NULL,
52437 + .p_ioctl = libcfs_ioctl
52438 };
52439
52440 extern int insert_proc(void);
52441 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52442 index b0bb709..0117c96 100644
52443 --- a/drivers/staging/lustre/lustre/llite/dir.c
52444 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52445 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52446 int mode;
52447 int err;
52448
52449 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52450 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52451 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52452 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52453 lump);
52454 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52455 index b2b6c3c..302e4e4 100644
52456 --- a/drivers/staging/octeon/ethernet-rx.c
52457 +++ b/drivers/staging/octeon/ethernet-rx.c
52458 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52459 /* Increment RX stats for virtual ports */
52460 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52461 #ifdef CONFIG_64BIT
52462 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52463 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52464 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52465 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52466 #else
52467 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52468 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52469 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52470 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52471 #endif
52472 }
52473 netif_receive_skb(skb);
52474 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52475 dev->name);
52476 */
52477 #ifdef CONFIG_64BIT
52478 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52479 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52480 #else
52481 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52482 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52483 #endif
52484 dev_kfree_skb_irq(skb);
52485 }
52486 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52487 index 8f9e3fb..d283fb9 100644
52488 --- a/drivers/staging/octeon/ethernet.c
52489 +++ b/drivers/staging/octeon/ethernet.c
52490 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52491 * since the RX tasklet also increments it.
52492 */
52493 #ifdef CONFIG_64BIT
52494 - atomic64_add(rx_status.dropped_packets,
52495 - (atomic64_t *)&priv->stats.rx_dropped);
52496 + atomic64_add_unchecked(rx_status.dropped_packets,
52497 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52498 #else
52499 - atomic_add(rx_status.dropped_packets,
52500 - (atomic_t *)&priv->stats.rx_dropped);
52501 + atomic_add_unchecked(rx_status.dropped_packets,
52502 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52503 #endif
52504 }
52505
52506 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52507 index 9191993..30e9817 100644
52508 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52509 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52510 @@ -225,7 +225,7 @@ struct hal_ops {
52511
52512 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52513 void (*hal_reset_security_engine)(struct adapter *adapter);
52514 -};
52515 +} __no_const;
52516
52517 enum rt_eeprom_type {
52518 EEPROM_93C46,
52519 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52520 index 070cc03..6806e37 100644
52521 --- a/drivers/staging/rtl8712/rtl871x_io.h
52522 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52523 @@ -108,7 +108,7 @@ struct _io_ops {
52524 u8 *pmem);
52525 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52526 u8 *pmem);
52527 -};
52528 +} __no_const;
52529
52530 struct io_req {
52531 struct list_head list;
52532 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52533 index 2bf2e2f..84421c9 100644
52534 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52535 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52536 @@ -228,7 +228,7 @@ typedef struct {
52537 void (*device_resume)(ulong busNo, ulong devNo);
52538 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52539 ulong *maxSize);
52540 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52541 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52542
52543 /* These functions live inside visorchipset, and will be called to indicate
52544 * responses to specific events (by code outside of visorchipset).
52545 @@ -243,7 +243,7 @@ typedef struct {
52546 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52547 void (*device_pause)(ulong busNo, ulong devNo, int response);
52548 void (*device_resume)(ulong busNo, ulong devNo, int response);
52549 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52550 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52551
52552 /** Register functions (in the bus driver) to get called by visorchipset
52553 * whenever a bus or device appears for which this service partition is
52554 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52555 index ae0dade..803d53a 100644
52556 --- a/drivers/staging/vt6655/hostap.c
52557 +++ b/drivers/staging/vt6655/hostap.c
52558 @@ -65,14 +65,13 @@
52559 *
52560 */
52561
52562 +static net_device_ops_no_const apdev_netdev_ops;
52563 +
52564 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52565 {
52566 struct vnt_private *apdev_priv;
52567 struct net_device *dev = pDevice->dev;
52568 int ret;
52569 - const struct net_device_ops apdev_netdev_ops = {
52570 - .ndo_start_xmit = pDevice->tx_80211,
52571 - };
52572
52573 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52574
52575 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52576 *apdev_priv = *pDevice;
52577 eth_hw_addr_inherit(pDevice->apdev, dev);
52578
52579 + /* only half broken now */
52580 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52581 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52582
52583 pDevice->apdev->type = ARPHRD_IEEE80211;
52584 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52585 index e7e9372..161f530 100644
52586 --- a/drivers/target/sbp/sbp_target.c
52587 +++ b/drivers/target/sbp/sbp_target.c
52588 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52589
52590 #define SESSION_MAINTENANCE_INTERVAL HZ
52591
52592 -static atomic_t login_id = ATOMIC_INIT(0);
52593 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52594
52595 static void session_maintenance_work(struct work_struct *);
52596 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52597 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52598 login->lun = se_lun;
52599 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52600 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52601 - login->login_id = atomic_inc_return(&login_id);
52602 + login->login_id = atomic_inc_return_unchecked(&login_id);
52603
52604 login->tgt_agt = sbp_target_agent_register(login);
52605 if (IS_ERR(login->tgt_agt)) {
52606 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52607 index 24fa5d1..fae56f1 100644
52608 --- a/drivers/target/target_core_device.c
52609 +++ b/drivers/target/target_core_device.c
52610 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52611 spin_lock_init(&dev->se_tmr_lock);
52612 spin_lock_init(&dev->qf_cmd_lock);
52613 sema_init(&dev->caw_sem, 1);
52614 - atomic_set(&dev->dev_ordered_id, 0);
52615 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52616 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52617 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52618 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52619 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52620 index be877bf..7be9cd4 100644
52621 --- a/drivers/target/target_core_transport.c
52622 +++ b/drivers/target/target_core_transport.c
52623 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52624 * Used to determine when ORDERED commands should go from
52625 * Dormant to Active status.
52626 */
52627 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52628 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52629 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52630 cmd->se_ordered_id, cmd->sam_task_attr,
52631 dev->transport->name);
52632 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52633 index edc1cce..769e4cb 100644
52634 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52635 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52636 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52637 platform_set_drvdata(pdev, priv);
52638
52639 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52640 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52641 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52642 + pax_open_kernel();
52643 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52644 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52645 + pax_close_kernel();
52646 }
52647 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52648 priv, &int3400_thermal_ops,
52649 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52650 index 62143ba..ae21165 100644
52651 --- a/drivers/thermal/of-thermal.c
52652 +++ b/drivers/thermal/of-thermal.c
52653 @@ -30,6 +30,7 @@
52654 #include <linux/err.h>
52655 #include <linux/export.h>
52656 #include <linux/string.h>
52657 +#include <linux/mm.h>
52658
52659 #include "thermal_core.h"
52660
52661 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52662 tz->get_trend = get_trend;
52663 tz->sensor_data = data;
52664
52665 - tzd->ops->get_temp = of_thermal_get_temp;
52666 - tzd->ops->get_trend = of_thermal_get_trend;
52667 + pax_open_kernel();
52668 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52669 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52670 + pax_close_kernel();
52671 mutex_unlock(&tzd->lock);
52672
52673 return tzd;
52674 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52675 return;
52676
52677 mutex_lock(&tzd->lock);
52678 - tzd->ops->get_temp = NULL;
52679 - tzd->ops->get_trend = NULL;
52680 + pax_open_kernel();
52681 + *(void **)&tzd->ops->get_temp = NULL;
52682 + *(void **)&tzd->ops->get_trend = NULL;
52683 + pax_close_kernel();
52684
52685 tz->get_temp = NULL;
52686 tz->get_trend = NULL;
52687 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52688 index fd66f57..48e6376 100644
52689 --- a/drivers/tty/cyclades.c
52690 +++ b/drivers/tty/cyclades.c
52691 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52692 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52693 info->port.count);
52694 #endif
52695 - info->port.count++;
52696 + atomic_inc(&info->port.count);
52697 #ifdef CY_DEBUG_COUNT
52698 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52699 - current->pid, info->port.count);
52700 + current->pid, atomic_read(&info->port.count));
52701 #endif
52702
52703 /*
52704 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52705 for (j = 0; j < cy_card[i].nports; j++) {
52706 info = &cy_card[i].ports[j];
52707
52708 - if (info->port.count) {
52709 + if (atomic_read(&info->port.count)) {
52710 /* XXX is the ldisc num worth this? */
52711 struct tty_struct *tty;
52712 struct tty_ldisc *ld;
52713 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52714 index 4fcec1d..5a036f7 100644
52715 --- a/drivers/tty/hvc/hvc_console.c
52716 +++ b/drivers/tty/hvc/hvc_console.c
52717 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52718
52719 spin_lock_irqsave(&hp->port.lock, flags);
52720 /* Check and then increment for fast path open. */
52721 - if (hp->port.count++ > 0) {
52722 + if (atomic_inc_return(&hp->port.count) > 1) {
52723 spin_unlock_irqrestore(&hp->port.lock, flags);
52724 hvc_kick();
52725 return 0;
52726 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52727
52728 spin_lock_irqsave(&hp->port.lock, flags);
52729
52730 - if (--hp->port.count == 0) {
52731 + if (atomic_dec_return(&hp->port.count) == 0) {
52732 spin_unlock_irqrestore(&hp->port.lock, flags);
52733 /* We are done with the tty pointer now. */
52734 tty_port_tty_set(&hp->port, NULL);
52735 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52736 */
52737 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52738 } else {
52739 - if (hp->port.count < 0)
52740 + if (atomic_read(&hp->port.count) < 0)
52741 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52742 - hp->vtermno, hp->port.count);
52743 + hp->vtermno, atomic_read(&hp->port.count));
52744 spin_unlock_irqrestore(&hp->port.lock, flags);
52745 }
52746 }
52747 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52748 * open->hangup case this can be called after the final close so prevent
52749 * that from happening for now.
52750 */
52751 - if (hp->port.count <= 0) {
52752 + if (atomic_read(&hp->port.count) <= 0) {
52753 spin_unlock_irqrestore(&hp->port.lock, flags);
52754 return;
52755 }
52756
52757 - hp->port.count = 0;
52758 + atomic_set(&hp->port.count, 0);
52759 spin_unlock_irqrestore(&hp->port.lock, flags);
52760 tty_port_tty_set(&hp->port, NULL);
52761
52762 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52763 return -EPIPE;
52764
52765 /* FIXME what's this (unprotected) check for? */
52766 - if (hp->port.count <= 0)
52767 + if (atomic_read(&hp->port.count) <= 0)
52768 return -EIO;
52769
52770 spin_lock_irqsave(&hp->lock, flags);
52771 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52772 index 81e939e..95ead10 100644
52773 --- a/drivers/tty/hvc/hvcs.c
52774 +++ b/drivers/tty/hvc/hvcs.c
52775 @@ -83,6 +83,7 @@
52776 #include <asm/hvcserver.h>
52777 #include <asm/uaccess.h>
52778 #include <asm/vio.h>
52779 +#include <asm/local.h>
52780
52781 /*
52782 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52783 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52784
52785 spin_lock_irqsave(&hvcsd->lock, flags);
52786
52787 - if (hvcsd->port.count > 0) {
52788 + if (atomic_read(&hvcsd->port.count) > 0) {
52789 spin_unlock_irqrestore(&hvcsd->lock, flags);
52790 printk(KERN_INFO "HVCS: vterm state unchanged. "
52791 "The hvcs device node is still in use.\n");
52792 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52793 }
52794 }
52795
52796 - hvcsd->port.count = 0;
52797 + atomic_set(&hvcsd->port.count, 0);
52798 hvcsd->port.tty = tty;
52799 tty->driver_data = hvcsd;
52800
52801 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52802 unsigned long flags;
52803
52804 spin_lock_irqsave(&hvcsd->lock, flags);
52805 - hvcsd->port.count++;
52806 + atomic_inc(&hvcsd->port.count);
52807 hvcsd->todo_mask |= HVCS_SCHED_READ;
52808 spin_unlock_irqrestore(&hvcsd->lock, flags);
52809
52810 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52811 hvcsd = tty->driver_data;
52812
52813 spin_lock_irqsave(&hvcsd->lock, flags);
52814 - if (--hvcsd->port.count == 0) {
52815 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52816
52817 vio_disable_interrupts(hvcsd->vdev);
52818
52819 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52820
52821 free_irq(irq, hvcsd);
52822 return;
52823 - } else if (hvcsd->port.count < 0) {
52824 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52825 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52826 " is missmanaged.\n",
52827 - hvcsd->vdev->unit_address, hvcsd->port.count);
52828 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52829 }
52830
52831 spin_unlock_irqrestore(&hvcsd->lock, flags);
52832 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52833
52834 spin_lock_irqsave(&hvcsd->lock, flags);
52835 /* Preserve this so that we know how many kref refs to put */
52836 - temp_open_count = hvcsd->port.count;
52837 + temp_open_count = atomic_read(&hvcsd->port.count);
52838
52839 /*
52840 * Don't kref put inside the spinlock because the destruction
52841 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52842 tty->driver_data = NULL;
52843 hvcsd->port.tty = NULL;
52844
52845 - hvcsd->port.count = 0;
52846 + atomic_set(&hvcsd->port.count, 0);
52847
52848 /* This will drop any buffered data on the floor which is OK in a hangup
52849 * scenario. */
52850 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52851 * the middle of a write operation? This is a crummy place to do this
52852 * but we want to keep it all in the spinlock.
52853 */
52854 - if (hvcsd->port.count <= 0) {
52855 + if (atomic_read(&hvcsd->port.count) <= 0) {
52856 spin_unlock_irqrestore(&hvcsd->lock, flags);
52857 return -ENODEV;
52858 }
52859 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52860 {
52861 struct hvcs_struct *hvcsd = tty->driver_data;
52862
52863 - if (!hvcsd || hvcsd->port.count <= 0)
52864 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52865 return 0;
52866
52867 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52868 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52869 index 4190199..06d5bfa 100644
52870 --- a/drivers/tty/hvc/hvsi.c
52871 +++ b/drivers/tty/hvc/hvsi.c
52872 @@ -85,7 +85,7 @@ struct hvsi_struct {
52873 int n_outbuf;
52874 uint32_t vtermno;
52875 uint32_t virq;
52876 - atomic_t seqno; /* HVSI packet sequence number */
52877 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52878 uint16_t mctrl;
52879 uint8_t state; /* HVSI protocol state */
52880 uint8_t flags;
52881 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52882
52883 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52884 packet.hdr.len = sizeof(struct hvsi_query_response);
52885 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52886 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52887 packet.verb = VSV_SEND_VERSION_NUMBER;
52888 packet.u.version = HVSI_VERSION;
52889 packet.query_seqno = query_seqno+1;
52890 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52891
52892 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52893 packet.hdr.len = sizeof(struct hvsi_query);
52894 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52895 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52896 packet.verb = verb;
52897
52898 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52899 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52900 int wrote;
52901
52902 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52903 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52904 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52905 packet.hdr.len = sizeof(struct hvsi_control);
52906 packet.verb = VSV_SET_MODEM_CTL;
52907 packet.mask = HVSI_TSDTR;
52908 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52909 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52910
52911 packet.hdr.type = VS_DATA_PACKET_HEADER;
52912 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52913 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52914 packet.hdr.len = count + sizeof(struct hvsi_header);
52915 memcpy(&packet.data, buf, count);
52916
52917 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52918 struct hvsi_control packet __ALIGNED__;
52919
52920 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52921 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52922 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52923 packet.hdr.len = 6;
52924 packet.verb = VSV_CLOSE_PROTOCOL;
52925
52926 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52927
52928 tty_port_tty_set(&hp->port, tty);
52929 spin_lock_irqsave(&hp->lock, flags);
52930 - hp->port.count++;
52931 + atomic_inc(&hp->port.count);
52932 atomic_set(&hp->seqno, 0);
52933 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52934 spin_unlock_irqrestore(&hp->lock, flags);
52935 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52936
52937 spin_lock_irqsave(&hp->lock, flags);
52938
52939 - if (--hp->port.count == 0) {
52940 + if (atomic_dec_return(&hp->port.count) == 0) {
52941 tty_port_tty_set(&hp->port, NULL);
52942 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52943
52944 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52945
52946 spin_lock_irqsave(&hp->lock, flags);
52947 }
52948 - } else if (hp->port.count < 0)
52949 + } else if (atomic_read(&hp->port.count) < 0)
52950 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52951 - hp - hvsi_ports, hp->port.count);
52952 + hp - hvsi_ports, atomic_read(&hp->port.count));
52953
52954 spin_unlock_irqrestore(&hp->lock, flags);
52955 }
52956 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52957 tty_port_tty_set(&hp->port, NULL);
52958
52959 spin_lock_irqsave(&hp->lock, flags);
52960 - hp->port.count = 0;
52961 + atomic_set(&hp->port.count, 0);
52962 hp->n_outbuf = 0;
52963 spin_unlock_irqrestore(&hp->lock, flags);
52964 }
52965 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52966 index 7ae6c29..05c6dba 100644
52967 --- a/drivers/tty/hvc/hvsi_lib.c
52968 +++ b/drivers/tty/hvc/hvsi_lib.c
52969 @@ -8,7 +8,7 @@
52970
52971 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52972 {
52973 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52974 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52975
52976 /* Assumes that always succeeds, works in practice */
52977 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52978 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52979
52980 /* Reset state */
52981 pv->established = 0;
52982 - atomic_set(&pv->seqno, 0);
52983 + atomic_set_unchecked(&pv->seqno, 0);
52984
52985 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
52986
52987 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
52988 index 345cebb..d5a1e9e 100644
52989 --- a/drivers/tty/ipwireless/tty.c
52990 +++ b/drivers/tty/ipwireless/tty.c
52991 @@ -28,6 +28,7 @@
52992 #include <linux/tty_driver.h>
52993 #include <linux/tty_flip.h>
52994 #include <linux/uaccess.h>
52995 +#include <asm/local.h>
52996
52997 #include "tty.h"
52998 #include "network.h"
52999 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53000 return -ENODEV;
53001
53002 mutex_lock(&tty->ipw_tty_mutex);
53003 - if (tty->port.count == 0)
53004 + if (atomic_read(&tty->port.count) == 0)
53005 tty->tx_bytes_queued = 0;
53006
53007 - tty->port.count++;
53008 + atomic_inc(&tty->port.count);
53009
53010 tty->port.tty = linux_tty;
53011 linux_tty->driver_data = tty;
53012 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53013
53014 static void do_ipw_close(struct ipw_tty *tty)
53015 {
53016 - tty->port.count--;
53017 -
53018 - if (tty->port.count == 0) {
53019 + if (atomic_dec_return(&tty->port.count) == 0) {
53020 struct tty_struct *linux_tty = tty->port.tty;
53021
53022 if (linux_tty != NULL) {
53023 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53024 return;
53025
53026 mutex_lock(&tty->ipw_tty_mutex);
53027 - if (tty->port.count == 0) {
53028 + if (atomic_read(&tty->port.count) == 0) {
53029 mutex_unlock(&tty->ipw_tty_mutex);
53030 return;
53031 }
53032 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53033
53034 mutex_lock(&tty->ipw_tty_mutex);
53035
53036 - if (!tty->port.count) {
53037 + if (!atomic_read(&tty->port.count)) {
53038 mutex_unlock(&tty->ipw_tty_mutex);
53039 return;
53040 }
53041 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53042 return -ENODEV;
53043
53044 mutex_lock(&tty->ipw_tty_mutex);
53045 - if (!tty->port.count) {
53046 + if (!atomic_read(&tty->port.count)) {
53047 mutex_unlock(&tty->ipw_tty_mutex);
53048 return -EINVAL;
53049 }
53050 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53051 if (!tty)
53052 return -ENODEV;
53053
53054 - if (!tty->port.count)
53055 + if (!atomic_read(&tty->port.count))
53056 return -EINVAL;
53057
53058 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53059 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53060 if (!tty)
53061 return 0;
53062
53063 - if (!tty->port.count)
53064 + if (!atomic_read(&tty->port.count))
53065 return 0;
53066
53067 return tty->tx_bytes_queued;
53068 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53069 if (!tty)
53070 return -ENODEV;
53071
53072 - if (!tty->port.count)
53073 + if (!atomic_read(&tty->port.count))
53074 return -EINVAL;
53075
53076 return get_control_lines(tty);
53077 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53078 if (!tty)
53079 return -ENODEV;
53080
53081 - if (!tty->port.count)
53082 + if (!atomic_read(&tty->port.count))
53083 return -EINVAL;
53084
53085 return set_control_lines(tty, set, clear);
53086 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53087 if (!tty)
53088 return -ENODEV;
53089
53090 - if (!tty->port.count)
53091 + if (!atomic_read(&tty->port.count))
53092 return -EINVAL;
53093
53094 /* FIXME: Exactly how is the tty object locked here .. */
53095 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53096 * are gone */
53097 mutex_lock(&ttyj->ipw_tty_mutex);
53098 }
53099 - while (ttyj->port.count)
53100 + while (atomic_read(&ttyj->port.count))
53101 do_ipw_close(ttyj);
53102 ipwireless_disassociate_network_ttys(network,
53103 ttyj->channel_idx);
53104 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53105 index 14c54e0..1efd4f2 100644
53106 --- a/drivers/tty/moxa.c
53107 +++ b/drivers/tty/moxa.c
53108 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53109 }
53110
53111 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53112 - ch->port.count++;
53113 + atomic_inc(&ch->port.count);
53114 tty->driver_data = ch;
53115 tty_port_tty_set(&ch->port, tty);
53116 mutex_lock(&ch->port.mutex);
53117 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53118 index c434376..114ce13 100644
53119 --- a/drivers/tty/n_gsm.c
53120 +++ b/drivers/tty/n_gsm.c
53121 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53122 spin_lock_init(&dlci->lock);
53123 mutex_init(&dlci->mutex);
53124 dlci->fifo = &dlci->_fifo;
53125 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53126 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53127 kfree(dlci);
53128 return NULL;
53129 }
53130 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53131 struct gsm_dlci *dlci = tty->driver_data;
53132 struct tty_port *port = &dlci->port;
53133
53134 - port->count++;
53135 + atomic_inc(&port->count);
53136 tty_port_tty_set(port, tty);
53137
53138 dlci->modem_rx = 0;
53139 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53140 index 47ca0f3..3c0b803 100644
53141 --- a/drivers/tty/n_tty.c
53142 +++ b/drivers/tty/n_tty.c
53143 @@ -115,7 +115,7 @@ struct n_tty_data {
53144 int minimum_to_wake;
53145
53146 /* consumer-published */
53147 - size_t read_tail;
53148 + size_t read_tail __intentional_overflow(-1);
53149 size_t line_start;
53150
53151 /* protected by output lock */
53152 @@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53153 {
53154 *ops = tty_ldisc_N_TTY;
53155 ops->owner = NULL;
53156 - ops->refcount = ops->flags = 0;
53157 + atomic_set(&ops->refcount, 0);
53158 + ops->flags = 0;
53159 }
53160 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53161 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53162 index 7c4447a..70fbc1e 100644
53163 --- a/drivers/tty/pty.c
53164 +++ b/drivers/tty/pty.c
53165 @@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
53166 panic("Couldn't register Unix98 pts driver");
53167
53168 /* Now create the /dev/ptmx special device */
53169 + pax_open_kernel();
53170 tty_default_fops(&ptmx_fops);
53171 - ptmx_fops.open = ptmx_open;
53172 + *(void **)&ptmx_fops.open = ptmx_open;
53173 + pax_close_kernel();
53174
53175 cdev_init(&ptmx_cdev, &ptmx_fops);
53176 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53177 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53178 index 383c4c7..d408e21 100644
53179 --- a/drivers/tty/rocket.c
53180 +++ b/drivers/tty/rocket.c
53181 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53182 tty->driver_data = info;
53183 tty_port_tty_set(port, tty);
53184
53185 - if (port->count++ == 0) {
53186 + if (atomic_inc_return(&port->count) == 1) {
53187 atomic_inc(&rp_num_ports_open);
53188
53189 #ifdef ROCKET_DEBUG_OPEN
53190 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53191 #endif
53192 }
53193 #ifdef ROCKET_DEBUG_OPEN
53194 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53195 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53196 #endif
53197
53198 /*
53199 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53200 spin_unlock_irqrestore(&info->port.lock, flags);
53201 return;
53202 }
53203 - if (info->port.count)
53204 + if (atomic_read(&info->port.count))
53205 atomic_dec(&rp_num_ports_open);
53206 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53207 spin_unlock_irqrestore(&info->port.lock, flags);
53208 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53209 index aa28209..e08fb85 100644
53210 --- a/drivers/tty/serial/ioc4_serial.c
53211 +++ b/drivers/tty/serial/ioc4_serial.c
53212 @@ -437,7 +437,7 @@ struct ioc4_soft {
53213 } is_intr_info[MAX_IOC4_INTR_ENTS];
53214
53215 /* Number of entries active in the above array */
53216 - atomic_t is_num_intrs;
53217 + atomic_unchecked_t is_num_intrs;
53218 } is_intr_type[IOC4_NUM_INTR_TYPES];
53219
53220 /* is_ir_lock must be held while
53221 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53222 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53223 || (type == IOC4_OTHER_INTR_TYPE)));
53224
53225 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53226 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53227 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53228
53229 /* Save off the lower level interrupt handler */
53230 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53231
53232 soft = arg;
53233 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53234 - num_intrs = (int)atomic_read(
53235 + num_intrs = (int)atomic_read_unchecked(
53236 &soft->is_intr_type[intr_type].is_num_intrs);
53237
53238 this_mir = this_ir = pending_intrs(soft, intr_type);
53239 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53240 index 129dc5b..1da5bb8 100644
53241 --- a/drivers/tty/serial/kgdb_nmi.c
53242 +++ b/drivers/tty/serial/kgdb_nmi.c
53243 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53244 * I/O utilities that messages sent to the console will automatically
53245 * be displayed on the dbg_io.
53246 */
53247 - dbg_io_ops->is_console = true;
53248 + pax_open_kernel();
53249 + *(int *)&dbg_io_ops->is_console = true;
53250 + pax_close_kernel();
53251
53252 return 0;
53253 }
53254 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53255 index a260cde..6b2b5ce 100644
53256 --- a/drivers/tty/serial/kgdboc.c
53257 +++ b/drivers/tty/serial/kgdboc.c
53258 @@ -24,8 +24,9 @@
53259 #define MAX_CONFIG_LEN 40
53260
53261 static struct kgdb_io kgdboc_io_ops;
53262 +static struct kgdb_io kgdboc_io_ops_console;
53263
53264 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53265 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53266 static int configured = -1;
53267
53268 static char config[MAX_CONFIG_LEN];
53269 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53270 kgdboc_unregister_kbd();
53271 if (configured == 1)
53272 kgdb_unregister_io_module(&kgdboc_io_ops);
53273 + else if (configured == 2)
53274 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53275 }
53276
53277 static int configure_kgdboc(void)
53278 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53279 int err;
53280 char *cptr = config;
53281 struct console *cons;
53282 + int is_console = 0;
53283
53284 err = kgdboc_option_setup(config);
53285 if (err || !strlen(config) || isspace(config[0]))
53286 goto noconfig;
53287
53288 err = -ENODEV;
53289 - kgdboc_io_ops.is_console = 0;
53290 kgdb_tty_driver = NULL;
53291
53292 kgdboc_use_kms = 0;
53293 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53294 int idx;
53295 if (cons->device && cons->device(cons, &idx) == p &&
53296 idx == tty_line) {
53297 - kgdboc_io_ops.is_console = 1;
53298 + is_console = 1;
53299 break;
53300 }
53301 cons = cons->next;
53302 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53303 kgdb_tty_line = tty_line;
53304
53305 do_register:
53306 - err = kgdb_register_io_module(&kgdboc_io_ops);
53307 + if (is_console) {
53308 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53309 + configured = 2;
53310 + } else {
53311 + err = kgdb_register_io_module(&kgdboc_io_ops);
53312 + configured = 1;
53313 + }
53314 if (err)
53315 goto noconfig;
53316
53317 @@ -205,8 +214,6 @@ do_register:
53318 if (err)
53319 goto nmi_con_failed;
53320
53321 - configured = 1;
53322 -
53323 return 0;
53324
53325 nmi_con_failed:
53326 @@ -223,7 +230,7 @@ noconfig:
53327 static int __init init_kgdboc(void)
53328 {
53329 /* Already configured? */
53330 - if (configured == 1)
53331 + if (configured >= 1)
53332 return 0;
53333
53334 return configure_kgdboc();
53335 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53336 if (config[len - 1] == '\n')
53337 config[len - 1] = '\0';
53338
53339 - if (configured == 1)
53340 + if (configured >= 1)
53341 cleanup_kgdboc();
53342
53343 /* Go and configure with the new params. */
53344 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53345 .post_exception = kgdboc_post_exp_handler,
53346 };
53347
53348 +static struct kgdb_io kgdboc_io_ops_console = {
53349 + .name = "kgdboc",
53350 + .read_char = kgdboc_get_char,
53351 + .write_char = kgdboc_put_char,
53352 + .pre_exception = kgdboc_pre_exp_handler,
53353 + .post_exception = kgdboc_post_exp_handler,
53354 + .is_console = 1
53355 +};
53356 +
53357 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53358 /* This is only available if kgdboc is a built in for early debugging */
53359 static int __init kgdboc_early_init(char *opt)
53360 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53361 index 4b6c783..9a19db3 100644
53362 --- a/drivers/tty/serial/msm_serial.c
53363 +++ b/drivers/tty/serial/msm_serial.c
53364 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53365 .cons = MSM_CONSOLE,
53366 };
53367
53368 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53369 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53370
53371 static const struct of_device_id msm_uartdm_table[] = {
53372 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53373 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53374 int irq;
53375
53376 if (pdev->id == -1)
53377 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53378 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53379
53380 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53381 return -ENXIO;
53382 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53383 index 587d63b..48423a6 100644
53384 --- a/drivers/tty/serial/samsung.c
53385 +++ b/drivers/tty/serial/samsung.c
53386 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53387 }
53388 }
53389
53390 +static int s3c64xx_serial_startup(struct uart_port *port);
53391 static int s3c24xx_serial_startup(struct uart_port *port)
53392 {
53393 struct s3c24xx_uart_port *ourport = to_ourport(port);
53394 int ret;
53395
53396 + /* Startup sequence is different for s3c64xx and higher SoC's */
53397 + if (s3c24xx_serial_has_interrupt_mask(port))
53398 + return s3c64xx_serial_startup(port);
53399 +
53400 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53401 port, (unsigned long long)port->mapbase, port->membase);
53402
53403 @@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53404 /* setup info for port */
53405 port->dev = &platdev->dev;
53406
53407 - /* Startup sequence is different for s3c64xx and higher SoC's */
53408 - if (s3c24xx_serial_has_interrupt_mask(port))
53409 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53410 -
53411 port->uartclk = 1;
53412
53413 if (cfg->uart_flags & UPF_CONS_FLOW) {
53414 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53415 index a28dee9..168ba47 100644
53416 --- a/drivers/tty/serial/serial_core.c
53417 +++ b/drivers/tty/serial/serial_core.c
53418 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53419
53420 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53421
53422 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53423 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53424 return;
53425
53426 /*
53427 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53428 uart_flush_buffer(tty);
53429 uart_shutdown(tty, state);
53430 spin_lock_irqsave(&port->lock, flags);
53431 - port->count = 0;
53432 + atomic_set(&port->count, 0);
53433 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53434 spin_unlock_irqrestore(&port->lock, flags);
53435 tty_port_tty_set(port, NULL);
53436 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53437 goto end;
53438 }
53439
53440 - port->count++;
53441 + atomic_inc(&port->count);
53442 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53443 retval = -ENXIO;
53444 goto err_dec_count;
53445 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53446 end:
53447 return retval;
53448 err_dec_count:
53449 - port->count--;
53450 + atomic_dec(&port->count);
53451 mutex_unlock(&port->mutex);
53452 goto end;
53453 }
53454 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53455 index b799170..87dafd5 100644
53456 --- a/drivers/tty/synclink.c
53457 +++ b/drivers/tty/synclink.c
53458 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53459
53460 if (debug_level >= DEBUG_LEVEL_INFO)
53461 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53462 - __FILE__,__LINE__, info->device_name, info->port.count);
53463 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53464
53465 if (tty_port_close_start(&info->port, tty, filp) == 0)
53466 goto cleanup;
53467 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53468 cleanup:
53469 if (debug_level >= DEBUG_LEVEL_INFO)
53470 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53471 - tty->driver->name, info->port.count);
53472 + tty->driver->name, atomic_read(&info->port.count));
53473
53474 } /* end of mgsl_close() */
53475
53476 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53477
53478 mgsl_flush_buffer(tty);
53479 shutdown(info);
53480 -
53481 - info->port.count = 0;
53482 +
53483 + atomic_set(&info->port.count, 0);
53484 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53485 info->port.tty = NULL;
53486
53487 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53488
53489 if (debug_level >= DEBUG_LEVEL_INFO)
53490 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53491 - __FILE__,__LINE__, tty->driver->name, port->count );
53492 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53493
53494 spin_lock_irqsave(&info->irq_spinlock, flags);
53495 - port->count--;
53496 + atomic_dec(&port->count);
53497 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53498 port->blocked_open++;
53499
53500 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53501
53502 if (debug_level >= DEBUG_LEVEL_INFO)
53503 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53504 - __FILE__,__LINE__, tty->driver->name, port->count );
53505 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53506
53507 tty_unlock(tty);
53508 schedule();
53509 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53510
53511 /* FIXME: Racy on hangup during close wait */
53512 if (!tty_hung_up_p(filp))
53513 - port->count++;
53514 + atomic_inc(&port->count);
53515 port->blocked_open--;
53516
53517 if (debug_level >= DEBUG_LEVEL_INFO)
53518 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53519 - __FILE__,__LINE__, tty->driver->name, port->count );
53520 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53521
53522 if (!retval)
53523 port->flags |= ASYNC_NORMAL_ACTIVE;
53524 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53525
53526 if (debug_level >= DEBUG_LEVEL_INFO)
53527 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53528 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53529 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53530
53531 /* If port is closing, signal caller to try again */
53532 if (info->port.flags & ASYNC_CLOSING){
53533 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53534 spin_unlock_irqrestore(&info->netlock, flags);
53535 goto cleanup;
53536 }
53537 - info->port.count++;
53538 + atomic_inc(&info->port.count);
53539 spin_unlock_irqrestore(&info->netlock, flags);
53540
53541 - if (info->port.count == 1) {
53542 + if (atomic_read(&info->port.count) == 1) {
53543 /* 1st open on this device, init hardware */
53544 retval = startup(info);
53545 if (retval < 0)
53546 @@ -3442,8 +3442,8 @@ cleanup:
53547 if (retval) {
53548 if (tty->count == 1)
53549 info->port.tty = NULL; /* tty layer will release tty struct */
53550 - if(info->port.count)
53551 - info->port.count--;
53552 + if (atomic_read(&info->port.count))
53553 + atomic_dec(&info->port.count);
53554 }
53555
53556 return retval;
53557 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53558 unsigned short new_crctype;
53559
53560 /* return error if TTY interface open */
53561 - if (info->port.count)
53562 + if (atomic_read(&info->port.count))
53563 return -EBUSY;
53564
53565 switch (encoding)
53566 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53567
53568 /* arbitrate between network and tty opens */
53569 spin_lock_irqsave(&info->netlock, flags);
53570 - if (info->port.count != 0 || info->netcount != 0) {
53571 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53572 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53573 spin_unlock_irqrestore(&info->netlock, flags);
53574 return -EBUSY;
53575 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53576 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53577
53578 /* return error if TTY interface open */
53579 - if (info->port.count)
53580 + if (atomic_read(&info->port.count))
53581 return -EBUSY;
53582
53583 if (cmd != SIOCWANDEV)
53584 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53585 index 0e8c39b..e0cb171 100644
53586 --- a/drivers/tty/synclink_gt.c
53587 +++ b/drivers/tty/synclink_gt.c
53588 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53589 tty->driver_data = info;
53590 info->port.tty = tty;
53591
53592 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53593 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53594
53595 /* If port is closing, signal caller to try again */
53596 if (info->port.flags & ASYNC_CLOSING){
53597 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53598 mutex_unlock(&info->port.mutex);
53599 goto cleanup;
53600 }
53601 - info->port.count++;
53602 + atomic_inc(&info->port.count);
53603 spin_unlock_irqrestore(&info->netlock, flags);
53604
53605 - if (info->port.count == 1) {
53606 + if (atomic_read(&info->port.count) == 1) {
53607 /* 1st open on this device, init hardware */
53608 retval = startup(info);
53609 if (retval < 0) {
53610 @@ -715,8 +715,8 @@ cleanup:
53611 if (retval) {
53612 if (tty->count == 1)
53613 info->port.tty = NULL; /* tty layer will release tty struct */
53614 - if(info->port.count)
53615 - info->port.count--;
53616 + if(atomic_read(&info->port.count))
53617 + atomic_dec(&info->port.count);
53618 }
53619
53620 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53621 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53622
53623 if (sanity_check(info, tty->name, "close"))
53624 return;
53625 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53626 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53627
53628 if (tty_port_close_start(&info->port, tty, filp) == 0)
53629 goto cleanup;
53630 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53631 tty_port_close_end(&info->port, tty);
53632 info->port.tty = NULL;
53633 cleanup:
53634 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53635 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53636 }
53637
53638 static void hangup(struct tty_struct *tty)
53639 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53640 shutdown(info);
53641
53642 spin_lock_irqsave(&info->port.lock, flags);
53643 - info->port.count = 0;
53644 + atomic_set(&info->port.count, 0);
53645 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53646 info->port.tty = NULL;
53647 spin_unlock_irqrestore(&info->port.lock, flags);
53648 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53649 unsigned short new_crctype;
53650
53651 /* return error if TTY interface open */
53652 - if (info->port.count)
53653 + if (atomic_read(&info->port.count))
53654 return -EBUSY;
53655
53656 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53657 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53658
53659 /* arbitrate between network and tty opens */
53660 spin_lock_irqsave(&info->netlock, flags);
53661 - if (info->port.count != 0 || info->netcount != 0) {
53662 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53663 DBGINFO(("%s hdlc_open busy\n", dev->name));
53664 spin_unlock_irqrestore(&info->netlock, flags);
53665 return -EBUSY;
53666 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53667 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53668
53669 /* return error if TTY interface open */
53670 - if (info->port.count)
53671 + if (atomic_read(&info->port.count))
53672 return -EBUSY;
53673
53674 if (cmd != SIOCWANDEV)
53675 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53676 if (port == NULL)
53677 continue;
53678 spin_lock(&port->lock);
53679 - if ((port->port.count || port->netcount) &&
53680 + if ((atomic_read(&port->port.count) || port->netcount) &&
53681 port->pending_bh && !port->bh_running &&
53682 !port->bh_requested) {
53683 DBGISR(("%s bh queued\n", port->device_name));
53684 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53685 add_wait_queue(&port->open_wait, &wait);
53686
53687 spin_lock_irqsave(&info->lock, flags);
53688 - port->count--;
53689 + atomic_dec(&port->count);
53690 spin_unlock_irqrestore(&info->lock, flags);
53691 port->blocked_open++;
53692
53693 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53694 remove_wait_queue(&port->open_wait, &wait);
53695
53696 if (!tty_hung_up_p(filp))
53697 - port->count++;
53698 + atomic_inc(&port->count);
53699 port->blocked_open--;
53700
53701 if (!retval)
53702 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53703 index c3f9091..abe4601 100644
53704 --- a/drivers/tty/synclinkmp.c
53705 +++ b/drivers/tty/synclinkmp.c
53706 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53707
53708 if (debug_level >= DEBUG_LEVEL_INFO)
53709 printk("%s(%d):%s open(), old ref count = %d\n",
53710 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53711 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53712
53713 /* If port is closing, signal caller to try again */
53714 if (info->port.flags & ASYNC_CLOSING){
53715 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53716 spin_unlock_irqrestore(&info->netlock, flags);
53717 goto cleanup;
53718 }
53719 - info->port.count++;
53720 + atomic_inc(&info->port.count);
53721 spin_unlock_irqrestore(&info->netlock, flags);
53722
53723 - if (info->port.count == 1) {
53724 + if (atomic_read(&info->port.count) == 1) {
53725 /* 1st open on this device, init hardware */
53726 retval = startup(info);
53727 if (retval < 0)
53728 @@ -796,8 +796,8 @@ cleanup:
53729 if (retval) {
53730 if (tty->count == 1)
53731 info->port.tty = NULL; /* tty layer will release tty struct */
53732 - if(info->port.count)
53733 - info->port.count--;
53734 + if(atomic_read(&info->port.count))
53735 + atomic_dec(&info->port.count);
53736 }
53737
53738 return retval;
53739 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53740
53741 if (debug_level >= DEBUG_LEVEL_INFO)
53742 printk("%s(%d):%s close() entry, count=%d\n",
53743 - __FILE__,__LINE__, info->device_name, info->port.count);
53744 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53745
53746 if (tty_port_close_start(&info->port, tty, filp) == 0)
53747 goto cleanup;
53748 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53749 cleanup:
53750 if (debug_level >= DEBUG_LEVEL_INFO)
53751 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53752 - tty->driver->name, info->port.count);
53753 + tty->driver->name, atomic_read(&info->port.count));
53754 }
53755
53756 /* Called by tty_hangup() when a hangup is signaled.
53757 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53758 shutdown(info);
53759
53760 spin_lock_irqsave(&info->port.lock, flags);
53761 - info->port.count = 0;
53762 + atomic_set(&info->port.count, 0);
53763 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53764 info->port.tty = NULL;
53765 spin_unlock_irqrestore(&info->port.lock, flags);
53766 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53767 unsigned short new_crctype;
53768
53769 /* return error if TTY interface open */
53770 - if (info->port.count)
53771 + if (atomic_read(&info->port.count))
53772 return -EBUSY;
53773
53774 switch (encoding)
53775 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53776
53777 /* arbitrate between network and tty opens */
53778 spin_lock_irqsave(&info->netlock, flags);
53779 - if (info->port.count != 0 || info->netcount != 0) {
53780 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53781 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53782 spin_unlock_irqrestore(&info->netlock, flags);
53783 return -EBUSY;
53784 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53785 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53786
53787 /* return error if TTY interface open */
53788 - if (info->port.count)
53789 + if (atomic_read(&info->port.count))
53790 return -EBUSY;
53791
53792 if (cmd != SIOCWANDEV)
53793 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53794 * do not request bottom half processing if the
53795 * device is not open in a normal mode.
53796 */
53797 - if ( port && (port->port.count || port->netcount) &&
53798 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53799 port->pending_bh && !port->bh_running &&
53800 !port->bh_requested ) {
53801 if ( debug_level >= DEBUG_LEVEL_ISR )
53802 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53803
53804 if (debug_level >= DEBUG_LEVEL_INFO)
53805 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53806 - __FILE__,__LINE__, tty->driver->name, port->count );
53807 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53808
53809 spin_lock_irqsave(&info->lock, flags);
53810 - port->count--;
53811 + atomic_dec(&port->count);
53812 spin_unlock_irqrestore(&info->lock, flags);
53813 port->blocked_open++;
53814
53815 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53816
53817 if (debug_level >= DEBUG_LEVEL_INFO)
53818 printk("%s(%d):%s block_til_ready() count=%d\n",
53819 - __FILE__,__LINE__, tty->driver->name, port->count );
53820 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53821
53822 tty_unlock(tty);
53823 schedule();
53824 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53825 set_current_state(TASK_RUNNING);
53826 remove_wait_queue(&port->open_wait, &wait);
53827 if (!tty_hung_up_p(filp))
53828 - port->count++;
53829 + atomic_inc(&port->count);
53830 port->blocked_open--;
53831
53832 if (debug_level >= DEBUG_LEVEL_INFO)
53833 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53834 - __FILE__,__LINE__, tty->driver->name, port->count );
53835 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53836
53837 if (!retval)
53838 port->flags |= ASYNC_NORMAL_ACTIVE;
53839 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53840 index 42bad18..447d7a2 100644
53841 --- a/drivers/tty/sysrq.c
53842 +++ b/drivers/tty/sysrq.c
53843 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53844 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53845 size_t count, loff_t *ppos)
53846 {
53847 - if (count) {
53848 + if (count && capable(CAP_SYS_ADMIN)) {
53849 char c;
53850
53851 if (get_user(c, buf))
53852 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53853 index 0508a1d..b610592 100644
53854 --- a/drivers/tty/tty_io.c
53855 +++ b/drivers/tty/tty_io.c
53856 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53857
53858 void tty_default_fops(struct file_operations *fops)
53859 {
53860 - *fops = tty_fops;
53861 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53862 }
53863
53864 /*
53865 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53866 index 2d822aa..a566234 100644
53867 --- a/drivers/tty/tty_ldisc.c
53868 +++ b/drivers/tty/tty_ldisc.c
53869 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53870 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53871 tty_ldiscs[disc] = new_ldisc;
53872 new_ldisc->num = disc;
53873 - new_ldisc->refcount = 0;
53874 + atomic_set(&new_ldisc->refcount, 0);
53875 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53876
53877 return ret;
53878 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53879 return -EINVAL;
53880
53881 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53882 - if (tty_ldiscs[disc]->refcount)
53883 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53884 ret = -EBUSY;
53885 else
53886 tty_ldiscs[disc] = NULL;
53887 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53888 if (ldops) {
53889 ret = ERR_PTR(-EAGAIN);
53890 if (try_module_get(ldops->owner)) {
53891 - ldops->refcount++;
53892 + atomic_inc(&ldops->refcount);
53893 ret = ldops;
53894 }
53895 }
53896 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53897 unsigned long flags;
53898
53899 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53900 - ldops->refcount--;
53901 + atomic_dec(&ldops->refcount);
53902 module_put(ldops->owner);
53903 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53904 }
53905 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53906 index 1b93357..ea9f82c 100644
53907 --- a/drivers/tty/tty_port.c
53908 +++ b/drivers/tty/tty_port.c
53909 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53910 unsigned long flags;
53911
53912 spin_lock_irqsave(&port->lock, flags);
53913 - port->count = 0;
53914 + atomic_set(&port->count, 0);
53915 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53916 tty = port->tty;
53917 if (tty)
53918 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53919
53920 /* The port lock protects the port counts */
53921 spin_lock_irqsave(&port->lock, flags);
53922 - port->count--;
53923 + atomic_dec(&port->count);
53924 port->blocked_open++;
53925 spin_unlock_irqrestore(&port->lock, flags);
53926
53927 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53928 we must not mess that up further */
53929 spin_lock_irqsave(&port->lock, flags);
53930 if (!tty_hung_up_p(filp))
53931 - port->count++;
53932 + atomic_inc(&port->count);
53933 port->blocked_open--;
53934 if (retval == 0)
53935 port->flags |= ASYNC_NORMAL_ACTIVE;
53936 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53937 return 0;
53938 }
53939
53940 - if (tty->count == 1 && port->count != 1) {
53941 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53942 printk(KERN_WARNING
53943 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53944 - port->count);
53945 - port->count = 1;
53946 + atomic_read(&port->count));
53947 + atomic_set(&port->count, 1);
53948 }
53949 - if (--port->count < 0) {
53950 + if (atomic_dec_return(&port->count) < 0) {
53951 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53952 - port->count);
53953 - port->count = 0;
53954 + atomic_read(&port->count));
53955 + atomic_set(&port->count, 0);
53956 }
53957
53958 - if (port->count) {
53959 + if (atomic_read(&port->count)) {
53960 spin_unlock_irqrestore(&port->lock, flags);
53961 return 0;
53962 }
53963 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53964 struct file *filp)
53965 {
53966 spin_lock_irq(&port->lock);
53967 - ++port->count;
53968 + atomic_inc(&port->count);
53969 spin_unlock_irq(&port->lock);
53970 tty_port_tty_set(port, tty);
53971
53972 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53973 index c039cfe..0b463b0 100644
53974 --- a/drivers/tty/vt/keyboard.c
53975 +++ b/drivers/tty/vt/keyboard.c
53976 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53977 kbd->kbdmode == VC_OFF) &&
53978 value != KVAL(K_SAK))
53979 return; /* SAK is allowed even in raw mode */
53980 +
53981 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53982 + {
53983 + void *func = fn_handler[value];
53984 + if (func == fn_show_state || func == fn_show_ptregs ||
53985 + func == fn_show_mem)
53986 + return;
53987 + }
53988 +#endif
53989 +
53990 fn_handler[value](vc);
53991 }
53992
53993 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53994 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
53995 return -EFAULT;
53996
53997 - if (!capable(CAP_SYS_TTY_CONFIG))
53998 - perm = 0;
53999 -
54000 switch (cmd) {
54001 case KDGKBENT:
54002 /* Ensure another thread doesn't free it under us */
54003 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54004 spin_unlock_irqrestore(&kbd_event_lock, flags);
54005 return put_user(val, &user_kbe->kb_value);
54006 case KDSKBENT:
54007 + if (!capable(CAP_SYS_TTY_CONFIG))
54008 + perm = 0;
54009 +
54010 if (!perm)
54011 return -EPERM;
54012 if (!i && v == K_NOSUCHMAP) {
54013 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54014 int i, j, k;
54015 int ret;
54016
54017 - if (!capable(CAP_SYS_TTY_CONFIG))
54018 - perm = 0;
54019 -
54020 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54021 if (!kbs) {
54022 ret = -ENOMEM;
54023 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54024 kfree(kbs);
54025 return ((p && *p) ? -EOVERFLOW : 0);
54026 case KDSKBSENT:
54027 + if (!capable(CAP_SYS_TTY_CONFIG))
54028 + perm = 0;
54029 +
54030 if (!perm) {
54031 ret = -EPERM;
54032 goto reterr;
54033 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54034 index 60fa627..7214965 100644
54035 --- a/drivers/uio/uio.c
54036 +++ b/drivers/uio/uio.c
54037 @@ -25,6 +25,7 @@
54038 #include <linux/kobject.h>
54039 #include <linux/cdev.h>
54040 #include <linux/uio_driver.h>
54041 +#include <asm/local.h>
54042
54043 #define UIO_MAX_DEVICES (1U << MINORBITS)
54044
54045 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
54046 struct device_attribute *attr, char *buf)
54047 {
54048 struct uio_device *idev = dev_get_drvdata(dev);
54049 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54050 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54051 }
54052 static DEVICE_ATTR_RO(event);
54053
54054 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
54055 {
54056 struct uio_device *idev = info->uio_dev;
54057
54058 - atomic_inc(&idev->event);
54059 + atomic_inc_unchecked(&idev->event);
54060 wake_up_interruptible(&idev->wait);
54061 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54062 }
54063 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54064 }
54065
54066 listener->dev = idev;
54067 - listener->event_count = atomic_read(&idev->event);
54068 + listener->event_count = atomic_read_unchecked(&idev->event);
54069 filep->private_data = listener;
54070
54071 if (idev->info->open) {
54072 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54073 return -EIO;
54074
54075 poll_wait(filep, &idev->wait, wait);
54076 - if (listener->event_count != atomic_read(&idev->event))
54077 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54078 return POLLIN | POLLRDNORM;
54079 return 0;
54080 }
54081 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54082 do {
54083 set_current_state(TASK_INTERRUPTIBLE);
54084
54085 - event_count = atomic_read(&idev->event);
54086 + event_count = atomic_read_unchecked(&idev->event);
54087 if (event_count != listener->event_count) {
54088 if (copy_to_user(buf, &event_count, count))
54089 retval = -EFAULT;
54090 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54091 static int uio_find_mem_index(struct vm_area_struct *vma)
54092 {
54093 struct uio_device *idev = vma->vm_private_data;
54094 + unsigned long size;
54095
54096 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54097 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54098 + size = idev->info->mem[vma->vm_pgoff].size;
54099 + if (size == 0)
54100 + return -1;
54101 + if (vma->vm_end - vma->vm_start > size)
54102 return -1;
54103 return (int)vma->vm_pgoff;
54104 }
54105 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
54106 idev->owner = owner;
54107 idev->info = info;
54108 init_waitqueue_head(&idev->wait);
54109 - atomic_set(&idev->event, 0);
54110 + atomic_set_unchecked(&idev->event, 0);
54111
54112 ret = uio_get_minor(idev);
54113 if (ret)
54114 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54115 index 813d4d3..a71934f 100644
54116 --- a/drivers/usb/atm/cxacru.c
54117 +++ b/drivers/usb/atm/cxacru.c
54118 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54119 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54120 if (ret < 2)
54121 return -EINVAL;
54122 - if (index < 0 || index > 0x7f)
54123 + if (index > 0x7f)
54124 return -EINVAL;
54125 pos += tmp;
54126
54127 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54128 index dada014..1d0d517 100644
54129 --- a/drivers/usb/atm/usbatm.c
54130 +++ b/drivers/usb/atm/usbatm.c
54131 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54132 if (printk_ratelimit())
54133 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54134 __func__, vpi, vci);
54135 - atomic_inc(&vcc->stats->rx_err);
54136 + atomic_inc_unchecked(&vcc->stats->rx_err);
54137 return;
54138 }
54139
54140 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54141 if (length > ATM_MAX_AAL5_PDU) {
54142 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54143 __func__, length, vcc);
54144 - atomic_inc(&vcc->stats->rx_err);
54145 + atomic_inc_unchecked(&vcc->stats->rx_err);
54146 goto out;
54147 }
54148
54149 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54150 if (sarb->len < pdu_length) {
54151 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54152 __func__, pdu_length, sarb->len, vcc);
54153 - atomic_inc(&vcc->stats->rx_err);
54154 + atomic_inc_unchecked(&vcc->stats->rx_err);
54155 goto out;
54156 }
54157
54158 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54159 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54160 __func__, vcc);
54161 - atomic_inc(&vcc->stats->rx_err);
54162 + atomic_inc_unchecked(&vcc->stats->rx_err);
54163 goto out;
54164 }
54165
54166 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54167 if (printk_ratelimit())
54168 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54169 __func__, length);
54170 - atomic_inc(&vcc->stats->rx_drop);
54171 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54172 goto out;
54173 }
54174
54175 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54176
54177 vcc->push(vcc, skb);
54178
54179 - atomic_inc(&vcc->stats->rx);
54180 + atomic_inc_unchecked(&vcc->stats->rx);
54181 out:
54182 skb_trim(sarb, 0);
54183 }
54184 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54185 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54186
54187 usbatm_pop(vcc, skb);
54188 - atomic_inc(&vcc->stats->tx);
54189 + atomic_inc_unchecked(&vcc->stats->tx);
54190
54191 skb = skb_dequeue(&instance->sndqueue);
54192 }
54193 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54194 if (!left--)
54195 return sprintf(page,
54196 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54197 - atomic_read(&atm_dev->stats.aal5.tx),
54198 - atomic_read(&atm_dev->stats.aal5.tx_err),
54199 - atomic_read(&atm_dev->stats.aal5.rx),
54200 - atomic_read(&atm_dev->stats.aal5.rx_err),
54201 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54202 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54203 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54204 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54205 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54206 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54207
54208 if (!left--) {
54209 if (instance->disconnected)
54210 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54211 index 2a3bbdf..91d72cf 100644
54212 --- a/drivers/usb/core/devices.c
54213 +++ b/drivers/usb/core/devices.c
54214 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54215 * time it gets called.
54216 */
54217 static struct device_connect_event {
54218 - atomic_t count;
54219 + atomic_unchecked_t count;
54220 wait_queue_head_t wait;
54221 } device_event = {
54222 .count = ATOMIC_INIT(1),
54223 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54224
54225 void usbfs_conn_disc_event(void)
54226 {
54227 - atomic_add(2, &device_event.count);
54228 + atomic_add_unchecked(2, &device_event.count);
54229 wake_up(&device_event.wait);
54230 }
54231
54232 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54233
54234 poll_wait(file, &device_event.wait, wait);
54235
54236 - event_count = atomic_read(&device_event.count);
54237 + event_count = atomic_read_unchecked(&device_event.count);
54238 if (file->f_version != event_count) {
54239 file->f_version = event_count;
54240 return POLLIN | POLLRDNORM;
54241 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54242 index 0b59731..46ee7d1 100644
54243 --- a/drivers/usb/core/devio.c
54244 +++ b/drivers/usb/core/devio.c
54245 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54246 struct usb_dev_state *ps = file->private_data;
54247 struct usb_device *dev = ps->dev;
54248 ssize_t ret = 0;
54249 - unsigned len;
54250 + size_t len;
54251 loff_t pos;
54252 int i;
54253
54254 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54255 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54256 struct usb_config_descriptor *config =
54257 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54258 - unsigned int length = le16_to_cpu(config->wTotalLength);
54259 + size_t length = le16_to_cpu(config->wTotalLength);
54260
54261 if (*ppos < pos + length) {
54262
54263 /* The descriptor may claim to be longer than it
54264 * really is. Here is the actual allocated length. */
54265 - unsigned alloclen =
54266 + size_t alloclen =
54267 le16_to_cpu(dev->config[i].desc.wTotalLength);
54268
54269 - len = length - (*ppos - pos);
54270 + len = length + pos - *ppos;
54271 if (len > nbytes)
54272 len = nbytes;
54273
54274 /* Simply don't write (skip over) unallocated parts */
54275 if (alloclen > (*ppos - pos)) {
54276 - alloclen -= (*ppos - pos);
54277 + alloclen = alloclen + pos - *ppos;
54278 if (copy_to_user(buf,
54279 dev->rawdescriptors[i] + (*ppos - pos),
54280 min(len, alloclen))) {
54281 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54282 index a6efb41..6f72549b 100644
54283 --- a/drivers/usb/core/hcd.c
54284 +++ b/drivers/usb/core/hcd.c
54285 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54286 */
54287 usb_get_urb(urb);
54288 atomic_inc(&urb->use_count);
54289 - atomic_inc(&urb->dev->urbnum);
54290 + atomic_inc_unchecked(&urb->dev->urbnum);
54291 usbmon_urb_submit(&hcd->self, urb);
54292
54293 /* NOTE requirements on root-hub callers (usbfs and the hub
54294 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54295 urb->hcpriv = NULL;
54296 INIT_LIST_HEAD(&urb->urb_list);
54297 atomic_dec(&urb->use_count);
54298 - atomic_dec(&urb->dev->urbnum);
54299 + atomic_dec_unchecked(&urb->dev->urbnum);
54300 if (atomic_read(&urb->reject))
54301 wake_up(&usb_kill_urb_queue);
54302 usb_put_urb(urb);
54303 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54304 index b649fef..c7107a0 100644
54305 --- a/drivers/usb/core/hub.c
54306 +++ b/drivers/usb/core/hub.c
54307 @@ -26,6 +26,7 @@
54308 #include <linux/mutex.h>
54309 #include <linux/random.h>
54310 #include <linux/pm_qos.h>
54311 +#include <linux/grsecurity.h>
54312
54313 #include <asm/uaccess.h>
54314 #include <asm/byteorder.h>
54315 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54316 goto done;
54317 return;
54318 }
54319 +
54320 + if (gr_handle_new_usb())
54321 + goto done;
54322 +
54323 if (hub_is_superspeed(hub->hdev))
54324 unit_load = 150;
54325 else
54326 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54327 index f7b7713..23d07ec 100644
54328 --- a/drivers/usb/core/message.c
54329 +++ b/drivers/usb/core/message.c
54330 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54331 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54332 * error number.
54333 */
54334 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54335 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54336 __u8 requesttype, __u16 value, __u16 index, void *data,
54337 __u16 size, int timeout)
54338 {
54339 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54340 * If successful, 0. Otherwise a negative error number. The number of actual
54341 * bytes transferred will be stored in the @actual_length parameter.
54342 */
54343 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54344 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54345 void *data, int len, int *actual_length, int timeout)
54346 {
54347 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54348 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54349 * bytes transferred will be stored in the @actual_length parameter.
54350 *
54351 */
54352 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54353 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54354 void *data, int len, int *actual_length, int timeout)
54355 {
54356 struct urb *urb;
54357 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54358 index 1236c60..d47a51c 100644
54359 --- a/drivers/usb/core/sysfs.c
54360 +++ b/drivers/usb/core/sysfs.c
54361 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54362 struct usb_device *udev;
54363
54364 udev = to_usb_device(dev);
54365 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54366 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54367 }
54368 static DEVICE_ATTR_RO(urbnum);
54369
54370 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54371 index 2dd2362..1135437 100644
54372 --- a/drivers/usb/core/usb.c
54373 +++ b/drivers/usb/core/usb.c
54374 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54375 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54376 dev->state = USB_STATE_ATTACHED;
54377 dev->lpm_disable_count = 1;
54378 - atomic_set(&dev->urbnum, 0);
54379 + atomic_set_unchecked(&dev->urbnum, 0);
54380
54381 INIT_LIST_HEAD(&dev->ep0.urb_list);
54382 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54383 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54384 index 8cfc319..4868255 100644
54385 --- a/drivers/usb/early/ehci-dbgp.c
54386 +++ b/drivers/usb/early/ehci-dbgp.c
54387 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54388
54389 #ifdef CONFIG_KGDB
54390 static struct kgdb_io kgdbdbgp_io_ops;
54391 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54392 +static struct kgdb_io kgdbdbgp_io_ops_console;
54393 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54394 #else
54395 #define dbgp_kgdb_mode (0)
54396 #endif
54397 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54398 .write_char = kgdbdbgp_write_char,
54399 };
54400
54401 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54402 + .name = "kgdbdbgp",
54403 + .read_char = kgdbdbgp_read_char,
54404 + .write_char = kgdbdbgp_write_char,
54405 + .is_console = 1
54406 +};
54407 +
54408 static int kgdbdbgp_wait_time;
54409
54410 static int __init kgdbdbgp_parse_config(char *str)
54411 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54412 ptr++;
54413 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54414 }
54415 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54416 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54417 + if (early_dbgp_console.index != -1)
54418 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54419 + else
54420 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54421
54422 return 0;
54423 }
54424 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54425 index f7b2032..fbb340c 100644
54426 --- a/drivers/usb/gadget/function/f_uac1.c
54427 +++ b/drivers/usb/gadget/function/f_uac1.c
54428 @@ -14,6 +14,7 @@
54429 #include <linux/module.h>
54430 #include <linux/device.h>
54431 #include <linux/atomic.h>
54432 +#include <linux/module.h>
54433
54434 #include "u_uac1.h"
54435
54436 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54437 index 491082a..dfd7d17 100644
54438 --- a/drivers/usb/gadget/function/u_serial.c
54439 +++ b/drivers/usb/gadget/function/u_serial.c
54440 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54441 spin_lock_irq(&port->port_lock);
54442
54443 /* already open? Great. */
54444 - if (port->port.count) {
54445 + if (atomic_read(&port->port.count)) {
54446 status = 0;
54447 - port->port.count++;
54448 + atomic_inc(&port->port.count);
54449
54450 /* currently opening/closing? wait ... */
54451 } else if (port->openclose) {
54452 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54453 tty->driver_data = port;
54454 port->port.tty = tty;
54455
54456 - port->port.count = 1;
54457 + atomic_set(&port->port.count, 1);
54458 port->openclose = false;
54459
54460 /* if connected, start the I/O stream */
54461 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54462
54463 spin_lock_irq(&port->port_lock);
54464
54465 - if (port->port.count != 1) {
54466 - if (port->port.count == 0)
54467 + if (atomic_read(&port->port.count) != 1) {
54468 + if (atomic_read(&port->port.count) == 0)
54469 WARN_ON(1);
54470 else
54471 - --port->port.count;
54472 + atomic_dec(&port->port.count);
54473 goto exit;
54474 }
54475
54476 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54477 * and sleep if necessary
54478 */
54479 port->openclose = true;
54480 - port->port.count = 0;
54481 + atomic_set(&port->port.count, 0);
54482
54483 gser = port->port_usb;
54484 if (gser && gser->disconnect)
54485 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54486 int cond;
54487
54488 spin_lock_irq(&port->port_lock);
54489 - cond = (port->port.count == 0) && !port->openclose;
54490 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54491 spin_unlock_irq(&port->port_lock);
54492 return cond;
54493 }
54494 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54495 /* if it's already open, start I/O ... and notify the serial
54496 * protocol about open/close status (connect/disconnect).
54497 */
54498 - if (port->port.count) {
54499 + if (atomic_read(&port->port.count)) {
54500 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54501 gs_start_io(port);
54502 if (gser->connect)
54503 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54504
54505 port->port_usb = NULL;
54506 gser->ioport = NULL;
54507 - if (port->port.count > 0 || port->openclose) {
54508 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54509 wake_up_interruptible(&port->drain_wait);
54510 if (port->port.tty)
54511 tty_hangup(port->port.tty);
54512 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54513
54514 /* finally, free any unused/unusable I/O buffers */
54515 spin_lock_irqsave(&port->port_lock, flags);
54516 - if (port->port.count == 0 && !port->openclose)
54517 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54518 gs_buf_free(&port->port_write_buf);
54519 gs_free_requests(gser->out, &port->read_pool, NULL);
54520 gs_free_requests(gser->out, &port->read_queue, NULL);
54521 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54522 index a44a07f..ecea924 100644
54523 --- a/drivers/usb/gadget/function/u_uac1.c
54524 +++ b/drivers/usb/gadget/function/u_uac1.c
54525 @@ -17,6 +17,7 @@
54526 #include <linux/ctype.h>
54527 #include <linux/random.h>
54528 #include <linux/syscalls.h>
54529 +#include <linux/module.h>
54530
54531 #include "u_uac1.h"
54532
54533 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54534 index 5728829..fefc6bf 100644
54535 --- a/drivers/usb/host/ehci-hub.c
54536 +++ b/drivers/usb/host/ehci-hub.c
54537 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54538 urb->transfer_flags = URB_DIR_IN;
54539 usb_get_urb(urb);
54540 atomic_inc(&urb->use_count);
54541 - atomic_inc(&urb->dev->urbnum);
54542 + atomic_inc_unchecked(&urb->dev->urbnum);
54543 urb->setup_dma = dma_map_single(
54544 hcd->self.controller,
54545 urb->setup_packet,
54546 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54547 urb->status = -EINPROGRESS;
54548 usb_get_urb(urb);
54549 atomic_inc(&urb->use_count);
54550 - atomic_inc(&urb->dev->urbnum);
54551 + atomic_inc_unchecked(&urb->dev->urbnum);
54552 retval = submit_single_step_set_feature(hcd, urb, 0);
54553 if (!retval && !wait_for_completion_timeout(&done,
54554 msecs_to_jiffies(2000))) {
54555 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54556 index 1db0626..4948782 100644
54557 --- a/drivers/usb/host/hwa-hc.c
54558 +++ b/drivers/usb/host/hwa-hc.c
54559 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54560 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54561 struct wahc *wa = &hwahc->wa;
54562 struct device *dev = &wa->usb_iface->dev;
54563 - u8 mas_le[UWB_NUM_MAS/8];
54564 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54565 +
54566 + if (mas_le == NULL)
54567 + return -ENOMEM;
54568
54569 /* Set the stream index */
54570 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54571 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54572 WUSB_REQ_SET_WUSB_MAS,
54573 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54574 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54575 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54576 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54577 if (result < 0)
54578 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54579 out:
54580 + kfree(mas_le);
54581 +
54582 return result;
54583 }
54584
54585 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54586 index b3d245e..99549ed 100644
54587 --- a/drivers/usb/misc/appledisplay.c
54588 +++ b/drivers/usb/misc/appledisplay.c
54589 @@ -84,7 +84,7 @@ struct appledisplay {
54590 struct mutex sysfslock; /* concurrent read and write */
54591 };
54592
54593 -static atomic_t count_displays = ATOMIC_INIT(0);
54594 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54595 static struct workqueue_struct *wq;
54596
54597 static void appledisplay_complete(struct urb *urb)
54598 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54599
54600 /* Register backlight device */
54601 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54602 - atomic_inc_return(&count_displays) - 1);
54603 + atomic_inc_return_unchecked(&count_displays) - 1);
54604 memset(&props, 0, sizeof(struct backlight_properties));
54605 props.type = BACKLIGHT_RAW;
54606 props.max_brightness = 0xff;
54607 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54608 index 29fa1c3..a57b08e 100644
54609 --- a/drivers/usb/serial/console.c
54610 +++ b/drivers/usb/serial/console.c
54611 @@ -125,7 +125,7 @@ static int usb_console_setup(struct console *co, char *options)
54612
54613 info->port = port;
54614
54615 - ++port->port.count;
54616 + atomic_inc(&port->port.count);
54617 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54618 if (serial->type->set_termios) {
54619 /*
54620 @@ -173,7 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
54621 }
54622 /* Now that any required fake tty operations are completed restore
54623 * the tty port count */
54624 - --port->port.count;
54625 + atomic_dec(&port->port.count);
54626 /* The console is special in terms of closing the device so
54627 * indicate this port is now acting as a system console. */
54628 port->port.console = 1;
54629 @@ -186,7 +186,7 @@ static int usb_console_setup(struct console *co, char *options)
54630 put_tty:
54631 tty_kref_put(tty);
54632 reset_open_count:
54633 - port->port.count = 0;
54634 + atomic_set(&port->port.count, 0);
54635 usb_autopm_put_interface(serial->interface);
54636 error_get_interface:
54637 usb_serial_put(serial);
54638 @@ -197,7 +197,7 @@ static int usb_console_setup(struct console *co, char *options)
54639 static void usb_console_write(struct console *co,
54640 const char *buf, unsigned count)
54641 {
54642 - static struct usbcons_info *info = &usbcons_info;
54643 + struct usbcons_info *info = &usbcons_info;
54644 struct usb_serial_port *port = info->port;
54645 struct usb_serial *serial;
54646 int retval = -ENODEV;
54647 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54648 index 307e339..6aa97cb 100644
54649 --- a/drivers/usb/storage/usb.h
54650 +++ b/drivers/usb/storage/usb.h
54651 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54652 __u8 useProtocol;
54653 __u8 useTransport;
54654 int (*initFunction)(struct us_data *);
54655 -};
54656 +} __do_const;
54657
54658
54659 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54660 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54661 index a863a98..d272795 100644
54662 --- a/drivers/usb/usbip/vhci.h
54663 +++ b/drivers/usb/usbip/vhci.h
54664 @@ -83,7 +83,7 @@ struct vhci_hcd {
54665 unsigned resuming:1;
54666 unsigned long re_timeout;
54667
54668 - atomic_t seqnum;
54669 + atomic_unchecked_t seqnum;
54670
54671 /*
54672 * NOTE:
54673 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54674 index c02374b..32d47a9 100644
54675 --- a/drivers/usb/usbip/vhci_hcd.c
54676 +++ b/drivers/usb/usbip/vhci_hcd.c
54677 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54678
54679 spin_lock(&vdev->priv_lock);
54680
54681 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54682 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54683 if (priv->seqnum == 0xffff)
54684 dev_info(&urb->dev->dev, "seqnum max\n");
54685
54686 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54687 return -ENOMEM;
54688 }
54689
54690 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54691 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54692 if (unlink->seqnum == 0xffff)
54693 pr_info("seqnum max\n");
54694
54695 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54696 vdev->rhport = rhport;
54697 }
54698
54699 - atomic_set(&vhci->seqnum, 0);
54700 + atomic_set_unchecked(&vhci->seqnum, 0);
54701 spin_lock_init(&vhci->lock);
54702
54703 hcd->power_budget = 0; /* no limit */
54704 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54705 index 00e4a54..d676f85 100644
54706 --- a/drivers/usb/usbip/vhci_rx.c
54707 +++ b/drivers/usb/usbip/vhci_rx.c
54708 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54709 if (!urb) {
54710 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54711 pr_info("max seqnum %d\n",
54712 - atomic_read(&the_controller->seqnum));
54713 + atomic_read_unchecked(&the_controller->seqnum));
54714 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54715 return;
54716 }
54717 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54718 index edc7267..9f65ce2 100644
54719 --- a/drivers/usb/wusbcore/wa-hc.h
54720 +++ b/drivers/usb/wusbcore/wa-hc.h
54721 @@ -240,7 +240,7 @@ struct wahc {
54722 spinlock_t xfer_list_lock;
54723 struct work_struct xfer_enqueue_work;
54724 struct work_struct xfer_error_work;
54725 - atomic_t xfer_id_count;
54726 + atomic_unchecked_t xfer_id_count;
54727
54728 kernel_ulong_t quirks;
54729 };
54730 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54731 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54732 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54733 wa->dto_in_use = 0;
54734 - atomic_set(&wa->xfer_id_count, 1);
54735 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54736 /* init the buf in URBs */
54737 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54738 usb_init_urb(&(wa->buf_in_urbs[index]));
54739 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54740 index 69af4fd..da390d7 100644
54741 --- a/drivers/usb/wusbcore/wa-xfer.c
54742 +++ b/drivers/usb/wusbcore/wa-xfer.c
54743 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54744 */
54745 static void wa_xfer_id_init(struct wa_xfer *xfer)
54746 {
54747 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54748 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54749 }
54750
54751 /* Return the xfer's ID. */
54752 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54753 index f018d8d..ccab63f 100644
54754 --- a/drivers/vfio/vfio.c
54755 +++ b/drivers/vfio/vfio.c
54756 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54757 return 0;
54758
54759 /* TODO Prevent device auto probing */
54760 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54761 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54762 iommu_group_id(group->iommu_group));
54763
54764 return 0;
54765 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54766 index 5174eba..451e6bc 100644
54767 --- a/drivers/vhost/vringh.c
54768 +++ b/drivers/vhost/vringh.c
54769 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54770 /* Userspace access helpers: in this case, addresses are really userspace. */
54771 static inline int getu16_user(u16 *val, const u16 *p)
54772 {
54773 - return get_user(*val, (__force u16 __user *)p);
54774 + return get_user(*val, (u16 __force_user *)p);
54775 }
54776
54777 static inline int putu16_user(u16 *p, u16 val)
54778 {
54779 - return put_user(val, (__force u16 __user *)p);
54780 + return put_user(val, (u16 __force_user *)p);
54781 }
54782
54783 static inline int copydesc_user(void *dst, const void *src, size_t len)
54784 {
54785 - return copy_from_user(dst, (__force void __user *)src, len) ?
54786 + return copy_from_user(dst, (void __force_user *)src, len) ?
54787 -EFAULT : 0;
54788 }
54789
54790 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54791 const struct vring_used_elem *src,
54792 unsigned int num)
54793 {
54794 - return copy_to_user((__force void __user *)dst, src,
54795 + return copy_to_user((void __force_user *)dst, src,
54796 sizeof(*dst) * num) ? -EFAULT : 0;
54797 }
54798
54799 static inline int xfer_from_user(void *src, void *dst, size_t len)
54800 {
54801 - return copy_from_user(dst, (__force void __user *)src, len) ?
54802 + return copy_from_user(dst, (void __force_user *)src, len) ?
54803 -EFAULT : 0;
54804 }
54805
54806 static inline int xfer_to_user(void *dst, void *src, size_t len)
54807 {
54808 - return copy_to_user((__force void __user *)dst, src, len) ?
54809 + return copy_to_user((void __force_user *)dst, src, len) ?
54810 -EFAULT : 0;
54811 }
54812
54813 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54814 vrh->last_used_idx = 0;
54815 vrh->vring.num = num;
54816 /* vring expects kernel addresses, but only used via accessors. */
54817 - vrh->vring.desc = (__force struct vring_desc *)desc;
54818 - vrh->vring.avail = (__force struct vring_avail *)avail;
54819 - vrh->vring.used = (__force struct vring_used *)used;
54820 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54821 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54822 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54823 return 0;
54824 }
54825 EXPORT_SYMBOL(vringh_init_user);
54826 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54827
54828 static inline int putu16_kern(u16 *p, u16 val)
54829 {
54830 - ACCESS_ONCE(*p) = val;
54831 + ACCESS_ONCE_RW(*p) = val;
54832 return 0;
54833 }
54834
54835 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54836 index 84a110a..96312c3 100644
54837 --- a/drivers/video/backlight/kb3886_bl.c
54838 +++ b/drivers/video/backlight/kb3886_bl.c
54839 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54840 static unsigned long kb3886bl_flags;
54841 #define KB3886BL_SUSPENDED 0x01
54842
54843 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54844 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54845 {
54846 .ident = "Sahara Touch-iT",
54847 .matches = {
54848 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54849 index 1b0b233..6f34c2c 100644
54850 --- a/drivers/video/fbdev/arcfb.c
54851 +++ b/drivers/video/fbdev/arcfb.c
54852 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54853 return -ENOSPC;
54854
54855 err = 0;
54856 - if ((count + p) > fbmemlength) {
54857 + if (count > (fbmemlength - p)) {
54858 count = fbmemlength - p;
54859 err = -ENOSPC;
54860 }
54861 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54862 index aedf2fb..47c9aca 100644
54863 --- a/drivers/video/fbdev/aty/aty128fb.c
54864 +++ b/drivers/video/fbdev/aty/aty128fb.c
54865 @@ -149,7 +149,7 @@ enum {
54866 };
54867
54868 /* Must match above enum */
54869 -static char * const r128_family[] = {
54870 +static const char * const r128_family[] = {
54871 "AGP",
54872 "PCI",
54873 "PRO AGP",
54874 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54875 index 37ec09b..98f8862 100644
54876 --- a/drivers/video/fbdev/aty/atyfb_base.c
54877 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54878 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54879 par->accel_flags = var->accel_flags; /* hack */
54880
54881 if (var->accel_flags) {
54882 - info->fbops->fb_sync = atyfb_sync;
54883 + pax_open_kernel();
54884 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54885 + pax_close_kernel();
54886 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54887 } else {
54888 - info->fbops->fb_sync = NULL;
54889 + pax_open_kernel();
54890 + *(void **)&info->fbops->fb_sync = NULL;
54891 + pax_close_kernel();
54892 info->flags |= FBINFO_HWACCEL_DISABLED;
54893 }
54894
54895 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54896 index 2fa0317..4983f2a 100644
54897 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54898 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54899 @@ -8,6 +8,7 @@
54900 #include "../core/fb_draw.h"
54901
54902 #include <asm/io.h>
54903 +#include <asm/pgtable.h>
54904
54905 #ifdef __sparc__
54906 #include <asm/fbio.h>
54907 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54908 info->sprite.buf_align = 16; /* and 64 lines tall. */
54909 info->sprite.flags = FB_PIXMAP_IO;
54910
54911 - info->fbops->fb_cursor = atyfb_cursor;
54912 + pax_open_kernel();
54913 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54914 + pax_close_kernel();
54915
54916 return 0;
54917 }
54918 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54919 index d6cab1f..112f680 100644
54920 --- a/drivers/video/fbdev/core/fb_defio.c
54921 +++ b/drivers/video/fbdev/core/fb_defio.c
54922 @@ -207,7 +207,9 @@ void fb_deferred_io_init(struct fb_info *info)
54923
54924 BUG_ON(!fbdefio);
54925 mutex_init(&fbdefio->lock);
54926 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54927 + pax_open_kernel();
54928 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54929 + pax_close_kernel();
54930 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54931 INIT_LIST_HEAD(&fbdefio->pagelist);
54932 if (fbdefio->delay == 0) /* set a default of 1 s */
54933 @@ -238,7 +240,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54934 page->mapping = NULL;
54935 }
54936
54937 - info->fbops->fb_mmap = NULL;
54938 + *(void **)&info->fbops->fb_mmap = NULL;
54939 mutex_destroy(&fbdefio->lock);
54940 }
54941 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54942 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54943 index 0705d88..d9429bf 100644
54944 --- a/drivers/video/fbdev/core/fbmem.c
54945 +++ b/drivers/video/fbdev/core/fbmem.c
54946 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54947 __u32 data;
54948 int err;
54949
54950 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54951 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54952
54953 data = (__u32) (unsigned long) fix->smem_start;
54954 err |= put_user(data, &fix32->smem_start);
54955 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54956 index 4254336..282567e 100644
54957 --- a/drivers/video/fbdev/hyperv_fb.c
54958 +++ b/drivers/video/fbdev/hyperv_fb.c
54959 @@ -240,7 +240,7 @@ static uint screen_fb_size;
54960 static inline int synthvid_send(struct hv_device *hdev,
54961 struct synthvid_msg *msg)
54962 {
54963 - static atomic64_t request_id = ATOMIC64_INIT(0);
54964 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54965 int ret;
54966
54967 msg->pipe_hdr.type = PIPE_MSG_DATA;
54968 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54969
54970 ret = vmbus_sendpacket(hdev->channel, msg,
54971 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54972 - atomic64_inc_return(&request_id),
54973 + atomic64_inc_return_unchecked(&request_id),
54974 VM_PKT_DATA_INBAND, 0);
54975
54976 if (ret)
54977 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54978 index 7672d2e..b56437f 100644
54979 --- a/drivers/video/fbdev/i810/i810_accel.c
54980 +++ b/drivers/video/fbdev/i810/i810_accel.c
54981 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
54982 }
54983 }
54984 printk("ringbuffer lockup!!!\n");
54985 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
54986 i810_report_error(mmio);
54987 par->dev_flags |= LOCKUP;
54988 info->pixmap.scan_align = 1;
54989 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54990 index a01147f..5d896f8 100644
54991 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54992 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54993 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54994
54995 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54996 struct matrox_switch matrox_mystique = {
54997 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54998 + .preinit = MGA1064_preinit,
54999 + .reset = MGA1064_reset,
55000 + .init = MGA1064_init,
55001 + .restore = MGA1064_restore,
55002 };
55003 EXPORT_SYMBOL(matrox_mystique);
55004 #endif
55005
55006 #ifdef CONFIG_FB_MATROX_G
55007 struct matrox_switch matrox_G100 = {
55008 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55009 + .preinit = MGAG100_preinit,
55010 + .reset = MGAG100_reset,
55011 + .init = MGAG100_init,
55012 + .restore = MGAG100_restore,
55013 };
55014 EXPORT_SYMBOL(matrox_G100);
55015 #endif
55016 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55017 index 195ad7c..09743fc 100644
55018 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55019 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55020 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55021 }
55022
55023 struct matrox_switch matrox_millennium = {
55024 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55025 + .preinit = Ti3026_preinit,
55026 + .reset = Ti3026_reset,
55027 + .init = Ti3026_init,
55028 + .restore = Ti3026_restore
55029 };
55030 EXPORT_SYMBOL(matrox_millennium);
55031 #endif
55032 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55033 index fe92eed..106e085 100644
55034 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55035 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55036 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55037 struct mb862xxfb_par *par = info->par;
55038
55039 if (info->var.bits_per_pixel == 32) {
55040 - info->fbops->fb_fillrect = cfb_fillrect;
55041 - info->fbops->fb_copyarea = cfb_copyarea;
55042 - info->fbops->fb_imageblit = cfb_imageblit;
55043 + pax_open_kernel();
55044 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55045 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55046 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55047 + pax_close_kernel();
55048 } else {
55049 outreg(disp, GC_L0EM, 3);
55050 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55051 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55052 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55053 + pax_open_kernel();
55054 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55055 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55056 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55057 + pax_close_kernel();
55058 }
55059 outreg(draw, GDC_REG_DRAW_BASE, 0);
55060 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55061 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55062 index def0412..fed6529 100644
55063 --- a/drivers/video/fbdev/nvidia/nvidia.c
55064 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55065 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55066 info->fix.line_length = (info->var.xres_virtual *
55067 info->var.bits_per_pixel) >> 3;
55068 if (info->var.accel_flags) {
55069 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55070 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55071 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55072 - info->fbops->fb_sync = nvidiafb_sync;
55073 + pax_open_kernel();
55074 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55075 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55076 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55077 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55078 + pax_close_kernel();
55079 info->pixmap.scan_align = 4;
55080 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55081 info->flags |= FBINFO_READS_FAST;
55082 NVResetGraphics(info);
55083 } else {
55084 - info->fbops->fb_imageblit = cfb_imageblit;
55085 - info->fbops->fb_fillrect = cfb_fillrect;
55086 - info->fbops->fb_copyarea = cfb_copyarea;
55087 - info->fbops->fb_sync = NULL;
55088 + pax_open_kernel();
55089 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55090 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55091 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55092 + *(void **)&info->fbops->fb_sync = NULL;
55093 + pax_close_kernel();
55094 info->pixmap.scan_align = 1;
55095 info->flags |= FBINFO_HWACCEL_DISABLED;
55096 info->flags &= ~FBINFO_READS_FAST;
55097 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55098 info->pixmap.size = 8 * 1024;
55099 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55100
55101 - if (!hwcur)
55102 - info->fbops->fb_cursor = NULL;
55103 + if (!hwcur) {
55104 + pax_open_kernel();
55105 + *(void **)&info->fbops->fb_cursor = NULL;
55106 + pax_close_kernel();
55107 + }
55108
55109 info->var.accel_flags = (!noaccel);
55110
55111 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55112 index 2412a0d..294215b 100644
55113 --- a/drivers/video/fbdev/omap2/dss/display.c
55114 +++ b/drivers/video/fbdev/omap2/dss/display.c
55115 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55116 if (dssdev->name == NULL)
55117 dssdev->name = dssdev->alias;
55118
55119 + pax_open_kernel();
55120 if (drv && drv->get_resolution == NULL)
55121 - drv->get_resolution = omapdss_default_get_resolution;
55122 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55123 if (drv && drv->get_recommended_bpp == NULL)
55124 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55125 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55126 if (drv && drv->get_timings == NULL)
55127 - drv->get_timings = omapdss_default_get_timings;
55128 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55129 + pax_close_kernel();
55130
55131 mutex_lock(&panel_list_mutex);
55132 list_add_tail(&dssdev->panel_list, &panel_list);
55133 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55134 index 83433cb..71e9b98 100644
55135 --- a/drivers/video/fbdev/s1d13xxxfb.c
55136 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55137 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55138
55139 switch(prod_id) {
55140 case S1D13506_PROD_ID: /* activate acceleration */
55141 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55142 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55143 + pax_open_kernel();
55144 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55145 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55146 + pax_close_kernel();
55147 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55148 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55149 break;
55150 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55151 index 2bcc84a..29dd1ea 100644
55152 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55153 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55154 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55155 }
55156
55157 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55158 - lcdc_sys_write_index,
55159 - lcdc_sys_write_data,
55160 - lcdc_sys_read_data,
55161 + .write_index = lcdc_sys_write_index,
55162 + .write_data = lcdc_sys_write_data,
55163 + .read_data = lcdc_sys_read_data,
55164 };
55165
55166 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55167 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55168 index d513ed6..90b0de9 100644
55169 --- a/drivers/video/fbdev/smscufx.c
55170 +++ b/drivers/video/fbdev/smscufx.c
55171 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55172 fb_deferred_io_cleanup(info);
55173 kfree(info->fbdefio);
55174 info->fbdefio = NULL;
55175 - info->fbops->fb_mmap = ufx_ops_mmap;
55176 + pax_open_kernel();
55177 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55178 + pax_close_kernel();
55179 }
55180
55181 pr_debug("released /dev/fb%d user=%d count=%d",
55182 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55183 index 046d51d..be564da 100644
55184 --- a/drivers/video/fbdev/udlfb.c
55185 +++ b/drivers/video/fbdev/udlfb.c
55186 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55187 dlfb_urb_completion(urb);
55188
55189 error:
55190 - atomic_add(bytes_sent, &dev->bytes_sent);
55191 - atomic_add(bytes_identical, &dev->bytes_identical);
55192 - atomic_add(width*height*2, &dev->bytes_rendered);
55193 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55194 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55195 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55196 end_cycles = get_cycles();
55197 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55198 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55199 >> 10)), /* Kcycles */
55200 &dev->cpu_kcycles_used);
55201
55202 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55203 dlfb_urb_completion(urb);
55204
55205 error:
55206 - atomic_add(bytes_sent, &dev->bytes_sent);
55207 - atomic_add(bytes_identical, &dev->bytes_identical);
55208 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55209 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55210 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55211 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55212 end_cycles = get_cycles();
55213 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55214 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55215 >> 10)), /* Kcycles */
55216 &dev->cpu_kcycles_used);
55217 }
55218 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55219 fb_deferred_io_cleanup(info);
55220 kfree(info->fbdefio);
55221 info->fbdefio = NULL;
55222 - info->fbops->fb_mmap = dlfb_ops_mmap;
55223 + pax_open_kernel();
55224 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55225 + pax_close_kernel();
55226 }
55227
55228 pr_warn("released /dev/fb%d user=%d count=%d\n",
55229 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55230 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55231 struct dlfb_data *dev = fb_info->par;
55232 return snprintf(buf, PAGE_SIZE, "%u\n",
55233 - atomic_read(&dev->bytes_rendered));
55234 + atomic_read_unchecked(&dev->bytes_rendered));
55235 }
55236
55237 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55238 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55239 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55240 struct dlfb_data *dev = fb_info->par;
55241 return snprintf(buf, PAGE_SIZE, "%u\n",
55242 - atomic_read(&dev->bytes_identical));
55243 + atomic_read_unchecked(&dev->bytes_identical));
55244 }
55245
55246 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55247 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55248 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55249 struct dlfb_data *dev = fb_info->par;
55250 return snprintf(buf, PAGE_SIZE, "%u\n",
55251 - atomic_read(&dev->bytes_sent));
55252 + atomic_read_unchecked(&dev->bytes_sent));
55253 }
55254
55255 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55256 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55257 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55258 struct dlfb_data *dev = fb_info->par;
55259 return snprintf(buf, PAGE_SIZE, "%u\n",
55260 - atomic_read(&dev->cpu_kcycles_used));
55261 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55262 }
55263
55264 static ssize_t edid_show(
55265 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55266 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55267 struct dlfb_data *dev = fb_info->par;
55268
55269 - atomic_set(&dev->bytes_rendered, 0);
55270 - atomic_set(&dev->bytes_identical, 0);
55271 - atomic_set(&dev->bytes_sent, 0);
55272 - atomic_set(&dev->cpu_kcycles_used, 0);
55273 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55274 + atomic_set_unchecked(&dev->bytes_identical, 0);
55275 + atomic_set_unchecked(&dev->bytes_sent, 0);
55276 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55277
55278 return count;
55279 }
55280 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55281 index 509d452..7c9d2de 100644
55282 --- a/drivers/video/fbdev/uvesafb.c
55283 +++ b/drivers/video/fbdev/uvesafb.c
55284 @@ -19,6 +19,7 @@
55285 #include <linux/io.h>
55286 #include <linux/mutex.h>
55287 #include <linux/slab.h>
55288 +#include <linux/moduleloader.h>
55289 #include <video/edid.h>
55290 #include <video/uvesafb.h>
55291 #ifdef CONFIG_X86
55292 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55293 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55294 par->pmi_setpal = par->ypan = 0;
55295 } else {
55296 +
55297 +#ifdef CONFIG_PAX_KERNEXEC
55298 +#ifdef CONFIG_MODULES
55299 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55300 +#endif
55301 + if (!par->pmi_code) {
55302 + par->pmi_setpal = par->ypan = 0;
55303 + return 0;
55304 + }
55305 +#endif
55306 +
55307 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55308 + task->t.regs.edi);
55309 +
55310 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55311 + pax_open_kernel();
55312 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55313 + pax_close_kernel();
55314 +
55315 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55316 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55317 +#else
55318 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55319 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55320 +#endif
55321 +
55322 printk(KERN_INFO "uvesafb: protected mode interface info at "
55323 "%04x:%04x\n",
55324 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55325 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55326 par->ypan = ypan;
55327
55328 if (par->pmi_setpal || par->ypan) {
55329 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55330 if (__supported_pte_mask & _PAGE_NX) {
55331 par->pmi_setpal = par->ypan = 0;
55332 printk(KERN_WARNING "uvesafb: NX protection is active, "
55333 "better not use the PMI.\n");
55334 - } else {
55335 + } else
55336 +#endif
55337 uvesafb_vbe_getpmi(task, par);
55338 - }
55339 }
55340 #else
55341 /* The protected mode interface is not available on non-x86. */
55342 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55343 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55344
55345 /* Disable blanking if the user requested so. */
55346 - if (!blank)
55347 - info->fbops->fb_blank = NULL;
55348 + if (!blank) {
55349 + pax_open_kernel();
55350 + *(void **)&info->fbops->fb_blank = NULL;
55351 + pax_close_kernel();
55352 + }
55353
55354 /*
55355 * Find out how much IO memory is required for the mode with
55356 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55357 info->flags = FBINFO_FLAG_DEFAULT |
55358 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55359
55360 - if (!par->ypan)
55361 - info->fbops->fb_pan_display = NULL;
55362 + if (!par->ypan) {
55363 + pax_open_kernel();
55364 + *(void **)&info->fbops->fb_pan_display = NULL;
55365 + pax_close_kernel();
55366 + }
55367 }
55368
55369 static void uvesafb_init_mtrr(struct fb_info *info)
55370 @@ -1787,6 +1817,11 @@ out_mode:
55371 out:
55372 kfree(par->vbe_modes);
55373
55374 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55375 + if (par->pmi_code)
55376 + module_free_exec(NULL, par->pmi_code);
55377 +#endif
55378 +
55379 framebuffer_release(info);
55380 return err;
55381 }
55382 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55383 kfree(par->vbe_state_orig);
55384 kfree(par->vbe_state_saved);
55385
55386 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55387 + if (par->pmi_code)
55388 + module_free_exec(NULL, par->pmi_code);
55389 +#endif
55390 +
55391 framebuffer_release(info);
55392 }
55393 return 0;
55394 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55395 index 6170e7f..dd63031 100644
55396 --- a/drivers/video/fbdev/vesafb.c
55397 +++ b/drivers/video/fbdev/vesafb.c
55398 @@ -9,6 +9,7 @@
55399 */
55400
55401 #include <linux/module.h>
55402 +#include <linux/moduleloader.h>
55403 #include <linux/kernel.h>
55404 #include <linux/errno.h>
55405 #include <linux/string.h>
55406 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55407 static int vram_total; /* Set total amount of memory */
55408 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55409 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55410 -static void (*pmi_start)(void) __read_mostly;
55411 -static void (*pmi_pal) (void) __read_mostly;
55412 +static void (*pmi_start)(void) __read_only;
55413 +static void (*pmi_pal) (void) __read_only;
55414 static int depth __read_mostly;
55415 static int vga_compat __read_mostly;
55416 /* --------------------------------------------------------------------- */
55417 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55418 unsigned int size_remap;
55419 unsigned int size_total;
55420 char *option = NULL;
55421 + void *pmi_code = NULL;
55422
55423 /* ignore error return of fb_get_options */
55424 fb_get_options("vesafb", &option);
55425 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55426 size_remap = size_total;
55427 vesafb_fix.smem_len = size_remap;
55428
55429 -#ifndef __i386__
55430 - screen_info.vesapm_seg = 0;
55431 -#endif
55432 -
55433 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55434 printk(KERN_WARNING
55435 "vesafb: cannot reserve video memory at 0x%lx\n",
55436 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55437 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55438 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55439
55440 +#ifdef __i386__
55441 +
55442 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55443 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55444 + if (!pmi_code)
55445 +#elif !defined(CONFIG_PAX_KERNEXEC)
55446 + if (0)
55447 +#endif
55448 +
55449 +#endif
55450 + screen_info.vesapm_seg = 0;
55451 +
55452 if (screen_info.vesapm_seg) {
55453 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55454 - screen_info.vesapm_seg,screen_info.vesapm_off);
55455 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55456 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55457 }
55458
55459 if (screen_info.vesapm_seg < 0xc000)
55460 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55461
55462 if (ypan || pmi_setpal) {
55463 unsigned short *pmi_base;
55464 +
55465 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55466 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55467 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55468 +
55469 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55470 + pax_open_kernel();
55471 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55472 +#else
55473 + pmi_code = pmi_base;
55474 +#endif
55475 +
55476 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55477 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55478 +
55479 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55480 + pmi_start = ktva_ktla(pmi_start);
55481 + pmi_pal = ktva_ktla(pmi_pal);
55482 + pax_close_kernel();
55483 +#endif
55484 +
55485 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55486 if (pmi_base[3]) {
55487 printk(KERN_INFO "vesafb: pmi: ports = ");
55488 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55489 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55490 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55491
55492 - if (!ypan)
55493 - info->fbops->fb_pan_display = NULL;
55494 + if (!ypan) {
55495 + pax_open_kernel();
55496 + *(void **)&info->fbops->fb_pan_display = NULL;
55497 + pax_close_kernel();
55498 + }
55499
55500 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55501 err = -ENOMEM;
55502 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55503 fb_info(info, "%s frame buffer device\n", info->fix.id);
55504 return 0;
55505 err:
55506 +
55507 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55508 + module_free_exec(NULL, pmi_code);
55509 +#endif
55510 +
55511 if (info->screen_base)
55512 iounmap(info->screen_base);
55513 framebuffer_release(info);
55514 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55515 index 88714ae..16c2e11 100644
55516 --- a/drivers/video/fbdev/via/via_clock.h
55517 +++ b/drivers/video/fbdev/via/via_clock.h
55518 @@ -56,7 +56,7 @@ struct via_clock {
55519
55520 void (*set_engine_pll_state)(u8 state);
55521 void (*set_engine_pll)(struct via_pll_config config);
55522 -};
55523 +} __no_const;
55524
55525
55526 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55527 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55528 index 3c14e43..2630570 100644
55529 --- a/drivers/video/logo/logo_linux_clut224.ppm
55530 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55531 @@ -2,1603 +2,1123 @@ P3
55532 # Standard 224-color Linux logo
55533 80 80
55534 255
55535 - 0 0 0 0 0 0 0 0 0 0 0 0
55536 - 0 0 0 0 0 0 0 0 0 0 0 0
55537 - 0 0 0 0 0 0 0 0 0 0 0 0
55538 - 0 0 0 0 0 0 0 0 0 0 0 0
55539 - 0 0 0 0 0 0 0 0 0 0 0 0
55540 - 0 0 0 0 0 0 0 0 0 0 0 0
55541 - 0 0 0 0 0 0 0 0 0 0 0 0
55542 - 0 0 0 0 0 0 0 0 0 0 0 0
55543 - 0 0 0 0 0 0 0 0 0 0 0 0
55544 - 6 6 6 6 6 6 10 10 10 10 10 10
55545 - 10 10 10 6 6 6 6 6 6 6 6 6
55546 - 0 0 0 0 0 0 0 0 0 0 0 0
55547 - 0 0 0 0 0 0 0 0 0 0 0 0
55548 - 0 0 0 0 0 0 0 0 0 0 0 0
55549 - 0 0 0 0 0 0 0 0 0 0 0 0
55550 - 0 0 0 0 0 0 0 0 0 0 0 0
55551 - 0 0 0 0 0 0 0 0 0 0 0 0
55552 - 0 0 0 0 0 0 0 0 0 0 0 0
55553 - 0 0 0 0 0 0 0 0 0 0 0 0
55554 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
55564 - 22 22 22 26 26 26 30 30 30 34 34 34
55565 - 30 30 30 30 30 30 26 26 26 18 18 18
55566 - 14 14 14 10 10 10 6 6 6 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 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
55584 - 54 54 54 66 66 66 78 78 78 78 78 78
55585 - 78 78 78 74 74 74 66 66 66 54 54 54
55586 - 42 42 42 26 26 26 18 18 18 10 10 10
55587 - 6 6 6 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 1 0 0 0 0 0 0 0 0 0
55597 - 0 0 0 0 0 0 0 0 0 0 0 0
55598 - 0 0 0 0 0 0 0 0 0 0 0 0
55599 - 0 0 0 0 0 0 0 0 0 0 0 0
55600 - 0 0 0 0 0 0 0 0 0 0 0 0
55601 - 0 0 0 0 0 0 0 0 0 0 0 0
55602 - 0 0 0 0 0 0 0 0 0 10 10 10
55603 - 22 22 22 42 42 42 66 66 66 86 86 86
55604 - 66 66 66 38 38 38 38 38 38 22 22 22
55605 - 26 26 26 34 34 34 54 54 54 66 66 66
55606 - 86 86 86 70 70 70 46 46 46 26 26 26
55607 - 14 14 14 6 6 6 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 1 0 0 1 0 0 0
55617 - 0 0 0 0 0 0 0 0 0 0 0 0
55618 - 0 0 0 0 0 0 0 0 0 0 0 0
55619 - 0 0 0 0 0 0 0 0 0 0 0 0
55620 - 0 0 0 0 0 0 0 0 0 0 0 0
55621 - 0 0 0 0 0 0 0 0 0 0 0 0
55622 - 0 0 0 0 0 0 10 10 10 26 26 26
55623 - 50 50 50 82 82 82 58 58 58 6 6 6
55624 - 2 2 6 2 2 6 2 2 6 2 2 6
55625 - 2 2 6 2 2 6 2 2 6 2 2 6
55626 - 6 6 6 54 54 54 86 86 86 66 66 66
55627 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55637 - 0 0 0 0 0 0 0 0 0 0 0 0
55638 - 0 0 0 0 0 0 0 0 0 0 0 0
55639 - 0 0 0 0 0 0 0 0 0 0 0 0
55640 - 0 0 0 0 0 0 0 0 0 0 0 0
55641 - 0 0 0 0 0 0 0 0 0 0 0 0
55642 - 0 0 0 6 6 6 22 22 22 50 50 50
55643 - 78 78 78 34 34 34 2 2 6 2 2 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 - 2 2 6 2 2 6 6 6 6 70 70 70
55647 - 78 78 78 46 46 46 22 22 22 6 6 6
55648 - 0 0 0 0 0 0 0 0 0 0 0 0
55649 - 0 0 0 0 0 0 0 0 0 0 0 0
55650 - 0 0 0 0 0 0 0 0 0 0 0 0
55651 - 0 0 0 0 0 0 0 0 0 0 0 0
55652 - 0 0 0 0 0 0 0 0 0 0 0 0
55653 - 0 0 0 0 0 0 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 1 0 0 1 0 0 1 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 6 6 6 18 18 18 42 42 42 82 82 82
55663 - 26 26 26 2 2 6 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 14 14 14
55666 - 46 46 46 34 34 34 6 6 6 2 2 6
55667 - 42 42 42 78 78 78 42 42 42 18 18 18
55668 - 6 6 6 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 0 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 - 10 10 10 30 30 30 66 66 66 58 58 58
55683 - 2 2 6 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 26 26 26
55686 - 86 86 86 101 101 101 46 46 46 10 10 10
55687 - 2 2 6 58 58 58 70 70 70 34 34 34
55688 - 10 10 10 0 0 0 0 0 0 0 0 0
55689 - 0 0 0 0 0 0 0 0 0 0 0 0
55690 - 0 0 0 0 0 0 0 0 0 0 0 0
55691 - 0 0 0 0 0 0 0 0 0 0 0 0
55692 - 0 0 0 0 0 0 0 0 0 0 0 0
55693 - 0 0 0 0 0 0 0 0 0 0 0 0
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 1 0 0 1 0 0 1 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 14 14 14 42 42 42 86 86 86 10 10 10
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 30 30 30
55706 - 94 94 94 94 94 94 58 58 58 26 26 26
55707 - 2 2 6 6 6 6 78 78 78 54 54 54
55708 - 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 6 6 6
55722 - 22 22 22 62 62 62 62 62 62 2 2 6
55723 - 2 2 6 2 2 6 2 2 6 2 2 6
55724 - 2 2 6 2 2 6 2 2 6 2 2 6
55725 - 2 2 6 2 2 6 2 2 6 26 26 26
55726 - 54 54 54 38 38 38 18 18 18 10 10 10
55727 - 2 2 6 2 2 6 34 34 34 82 82 82
55728 - 38 38 38 14 14 14 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 1 0 0 1 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 6 6 6
55742 - 30 30 30 78 78 78 30 30 30 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 10 10 10
55746 - 10 10 10 2 2 6 2 2 6 2 2 6
55747 - 2 2 6 2 2 6 2 2 6 78 78 78
55748 - 50 50 50 18 18 18 6 6 6 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 1 0 0 0 0 0 0 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 10 10 10
55762 - 38 38 38 86 86 86 14 14 14 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 2 2 6
55766 - 2 2 6 2 2 6 2 2 6 2 2 6
55767 - 2 2 6 2 2 6 2 2 6 54 54 54
55768 - 66 66 66 26 26 26 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 0 0 0 1 0 0 1 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 14 14 14
55782 - 42 42 42 82 82 82 2 2 6 2 2 6
55783 - 2 2 6 6 6 6 10 10 10 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 6 6 6
55786 - 14 14 14 10 10 10 2 2 6 2 2 6
55787 - 2 2 6 2 2 6 2 2 6 18 18 18
55788 - 82 82 82 34 34 34 10 10 10 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 0 0 0
55790 - 0 0 0 0 0 0 0 0 0 0 0 0
55791 - 0 0 0 0 0 0 0 0 0 0 0 0
55792 - 0 0 0 0 0 0 0 0 0 0 0 0
55793 - 0 0 0 0 0 0 0 0 0 0 0 0
55794 - 0 0 0 0 0 0 0 0 0 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 1 0 0 0 0 0 0 0 0 0
55797 - 0 0 0 0 0 0 0 0 0 0 0 0
55798 - 0 0 0 0 0 0 0 0 0 0 0 0
55799 - 0 0 0 0 0 0 0 0 0 0 0 0
55800 - 0 0 0 0 0 0 0 0 0 0 0 0
55801 - 0 0 0 0 0 0 0 0 0 14 14 14
55802 - 46 46 46 86 86 86 2 2 6 2 2 6
55803 - 6 6 6 6 6 6 22 22 22 34 34 34
55804 - 6 6 6 2 2 6 2 2 6 2 2 6
55805 - 2 2 6 2 2 6 18 18 18 34 34 34
55806 - 10 10 10 50 50 50 22 22 22 2 2 6
55807 - 2 2 6 2 2 6 2 2 6 10 10 10
55808 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 14 14 14
55822 - 46 46 46 86 86 86 2 2 6 2 2 6
55823 - 38 38 38 116 116 116 94 94 94 22 22 22
55824 - 22 22 22 2 2 6 2 2 6 2 2 6
55825 - 14 14 14 86 86 86 138 138 138 162 162 162
55826 -154 154 154 38 38 38 26 26 26 6 6 6
55827 - 2 2 6 2 2 6 2 2 6 2 2 6
55828 - 86 86 86 46 46 46 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 0 0 0 0 0 0 0 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 14 14 14
55842 - 46 46 46 86 86 86 2 2 6 14 14 14
55843 -134 134 134 198 198 198 195 195 195 116 116 116
55844 - 10 10 10 2 2 6 2 2 6 6 6 6
55845 -101 98 89 187 187 187 210 210 210 218 218 218
55846 -214 214 214 134 134 134 14 14 14 6 6 6
55847 - 2 2 6 2 2 6 2 2 6 2 2 6
55848 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
55856 - 0 0 1 0 0 1 0 0 1 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 14 14 14
55862 - 46 46 46 86 86 86 2 2 6 54 54 54
55863 -218 218 218 195 195 195 226 226 226 246 246 246
55864 - 58 58 58 2 2 6 2 2 6 30 30 30
55865 -210 210 210 253 253 253 174 174 174 123 123 123
55866 -221 221 221 234 234 234 74 74 74 2 2 6
55867 - 2 2 6 2 2 6 2 2 6 2 2 6
55868 - 70 70 70 58 58 58 22 22 22 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 0 0 0 0
55876 - 0 0 0 0 0 0 0 0 0 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 14 14 14
55882 - 46 46 46 82 82 82 2 2 6 106 106 106
55883 -170 170 170 26 26 26 86 86 86 226 226 226
55884 -123 123 123 10 10 10 14 14 14 46 46 46
55885 -231 231 231 190 190 190 6 6 6 70 70 70
55886 - 90 90 90 238 238 238 158 158 158 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 1 0 0 0
55896 - 0 0 1 0 0 1 0 0 1 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 0 14 14 14
55902 - 42 42 42 86 86 86 6 6 6 116 116 116
55903 -106 106 106 6 6 6 70 70 70 149 149 149
55904 -128 128 128 18 18 18 38 38 38 54 54 54
55905 -221 221 221 106 106 106 2 2 6 14 14 14
55906 - 46 46 46 190 190 190 198 198 198 2 2 6
55907 - 2 2 6 2 2 6 2 2 6 2 2 6
55908 - 74 74 74 62 62 62 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 0 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 94 94 94 14 14 14 101 101 101
55923 -128 128 128 2 2 6 18 18 18 116 116 116
55924 -118 98 46 121 92 8 121 92 8 98 78 10
55925 -162 162 162 106 106 106 2 2 6 2 2 6
55926 - 2 2 6 195 195 195 195 195 195 6 6 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 1
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 10 10 10
55942 - 38 38 38 90 90 90 14 14 14 58 58 58
55943 -210 210 210 26 26 26 54 38 6 154 114 10
55944 -226 170 11 236 186 11 225 175 15 184 144 12
55945 -215 174 15 175 146 61 37 26 9 2 2 6
55946 - 70 70 70 246 246 246 138 138 138 2 2 6
55947 - 2 2 6 2 2 6 2 2 6 2 2 6
55948 - 70 70 70 66 66 66 26 26 26 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 0 0 0 0
55956 - 0 0 0 0 0 0 0 0 0 0 0 0
55957 - 0 0 0 0 0 0 0 0 0 0 0 0
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 10 10 10
55962 - 38 38 38 86 86 86 14 14 14 10 10 10
55963 -195 195 195 188 164 115 192 133 9 225 175 15
55964 -239 182 13 234 190 10 232 195 16 232 200 30
55965 -245 207 45 241 208 19 232 195 16 184 144 12
55966 -218 194 134 211 206 186 42 42 42 2 2 6
55967 - 2 2 6 2 2 6 2 2 6 2 2 6
55968 - 50 50 50 74 74 74 30 30 30 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 - 34 34 34 86 86 86 14 14 14 2 2 6
55983 -121 87 25 192 133 9 219 162 10 239 182 13
55984 -236 186 11 232 195 16 241 208 19 244 214 54
55985 -246 218 60 246 218 38 246 215 20 241 208 19
55986 -241 208 19 226 184 13 121 87 25 2 2 6
55987 - 2 2 6 2 2 6 2 2 6 2 2 6
55988 - 50 50 50 82 82 82 34 34 34 10 10 10
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 82 82 82 30 30 30 61 42 6
56003 -180 123 7 206 145 10 230 174 11 239 182 13
56004 -234 190 10 238 202 15 241 208 19 246 218 74
56005 -246 218 38 246 215 20 246 215 20 246 215 20
56006 -226 184 13 215 174 15 184 144 12 6 6 6
56007 - 2 2 6 2 2 6 2 2 6 2 2 6
56008 - 26 26 26 94 94 94 42 42 42 14 14 14
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 - 30 30 30 78 78 78 50 50 50 104 69 6
56023 -192 133 9 216 158 10 236 178 12 236 186 11
56024 -232 195 16 241 208 19 244 214 54 245 215 43
56025 -246 215 20 246 215 20 241 208 19 198 155 10
56026 -200 144 11 216 158 10 156 118 10 2 2 6
56027 - 2 2 6 2 2 6 2 2 6 2 2 6
56028 - 6 6 6 90 90 90 54 54 54 18 18 18
56029 - 6 6 6 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 46 46 46 22 22 22
56043 -137 92 6 210 162 10 239 182 13 238 190 10
56044 -238 202 15 241 208 19 246 215 20 246 215 20
56045 -241 208 19 203 166 17 185 133 11 210 150 10
56046 -216 158 10 210 150 10 102 78 10 2 2 6
56047 - 6 6 6 54 54 54 14 14 14 2 2 6
56048 - 2 2 6 62 62 62 74 74 74 30 30 30
56049 - 10 10 10 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 - 34 34 34 78 78 78 50 50 50 6 6 6
56063 - 94 70 30 139 102 15 190 146 13 226 184 13
56064 -232 200 30 232 195 16 215 174 15 190 146 13
56065 -168 122 10 192 133 9 210 150 10 213 154 11
56066 -202 150 34 182 157 106 101 98 89 2 2 6
56067 - 2 2 6 78 78 78 116 116 116 58 58 58
56068 - 2 2 6 22 22 22 90 90 90 46 46 46
56069 - 18 18 18 6 6 6 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 - 38 38 38 86 86 86 50 50 50 6 6 6
56083 -128 128 128 174 154 114 156 107 11 168 122 10
56084 -198 155 10 184 144 12 197 138 11 200 144 11
56085 -206 145 10 206 145 10 197 138 11 188 164 115
56086 -195 195 195 198 198 198 174 174 174 14 14 14
56087 - 2 2 6 22 22 22 116 116 116 116 116 116
56088 - 22 22 22 2 2 6 74 74 74 70 70 70
56089 - 30 30 30 10 10 10 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 6 6 6 18 18 18
56102 - 50 50 50 101 101 101 26 26 26 10 10 10
56103 -138 138 138 190 190 190 174 154 114 156 107 11
56104 -197 138 11 200 144 11 197 138 11 192 133 9
56105 -180 123 7 190 142 34 190 178 144 187 187 187
56106 -202 202 202 221 221 221 214 214 214 66 66 66
56107 - 2 2 6 2 2 6 50 50 50 62 62 62
56108 - 6 6 6 2 2 6 10 10 10 90 90 90
56109 - 50 50 50 18 18 18 6 6 6 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 10 10 10 34 34 34
56122 - 74 74 74 74 74 74 2 2 6 6 6 6
56123 -144 144 144 198 198 198 190 190 190 178 166 146
56124 -154 121 60 156 107 11 156 107 11 168 124 44
56125 -174 154 114 187 187 187 190 190 190 210 210 210
56126 -246 246 246 253 253 253 253 253 253 182 182 182
56127 - 6 6 6 2 2 6 2 2 6 2 2 6
56128 - 2 2 6 2 2 6 2 2 6 62 62 62
56129 - 74 74 74 34 34 34 14 14 14 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 10 10 10 22 22 22 54 54 54
56142 - 94 94 94 18 18 18 2 2 6 46 46 46
56143 -234 234 234 221 221 221 190 190 190 190 190 190
56144 -190 190 190 187 187 187 187 187 187 190 190 190
56145 -190 190 190 195 195 195 214 214 214 242 242 242
56146 -253 253 253 253 253 253 253 253 253 253 253 253
56147 - 82 82 82 2 2 6 2 2 6 2 2 6
56148 - 2 2 6 2 2 6 2 2 6 14 14 14
56149 - 86 86 86 54 54 54 22 22 22 6 6 6
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 - 6 6 6 18 18 18 46 46 46 90 90 90
56162 - 46 46 46 18 18 18 6 6 6 182 182 182
56163 -253 253 253 246 246 246 206 206 206 190 190 190
56164 -190 190 190 190 190 190 190 190 190 190 190 190
56165 -206 206 206 231 231 231 250 250 250 253 253 253
56166 -253 253 253 253 253 253 253 253 253 253 253 253
56167 -202 202 202 14 14 14 2 2 6 2 2 6
56168 - 2 2 6 2 2 6 2 2 6 2 2 6
56169 - 42 42 42 86 86 86 42 42 42 18 18 18
56170 - 6 6 6 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 6 6 6
56181 - 14 14 14 38 38 38 74 74 74 66 66 66
56182 - 2 2 6 6 6 6 90 90 90 250 250 250
56183 -253 253 253 253 253 253 238 238 238 198 198 198
56184 -190 190 190 190 190 190 195 195 195 221 221 221
56185 -246 246 246 253 253 253 253 253 253 253 253 253
56186 -253 253 253 253 253 253 253 253 253 253 253 253
56187 -253 253 253 82 82 82 2 2 6 2 2 6
56188 - 2 2 6 2 2 6 2 2 6 2 2 6
56189 - 2 2 6 78 78 78 70 70 70 34 34 34
56190 - 14 14 14 6 6 6 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 14 14 14
56201 - 34 34 34 66 66 66 78 78 78 6 6 6
56202 - 2 2 6 18 18 18 218 218 218 253 253 253
56203 -253 253 253 253 253 253 253 253 253 246 246 246
56204 -226 226 226 231 231 231 246 246 246 253 253 253
56205 -253 253 253 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 178 178 178 2 2 6 2 2 6
56208 - 2 2 6 2 2 6 2 2 6 2 2 6
56209 - 2 2 6 18 18 18 90 90 90 62 62 62
56210 - 30 30 30 10 10 10 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 10 10 10 26 26 26
56221 - 58 58 58 90 90 90 18 18 18 2 2 6
56222 - 2 2 6 110 110 110 253 253 253 253 253 253
56223 -253 253 253 253 253 253 253 253 253 253 253 253
56224 -250 250 250 253 253 253 253 253 253 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 231 231 231 18 18 18 2 2 6
56228 - 2 2 6 2 2 6 2 2 6 2 2 6
56229 - 2 2 6 2 2 6 18 18 18 94 94 94
56230 - 54 54 54 26 26 26 10 10 10 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 6 6 6 22 22 22 50 50 50
56241 - 90 90 90 26 26 26 2 2 6 2 2 6
56242 - 14 14 14 195 195 195 250 250 250 253 253 253
56243 -253 253 253 253 253 253 253 253 253 253 253 253
56244 -253 253 253 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 -250 250 250 242 242 242 54 54 54 2 2 6
56248 - 2 2 6 2 2 6 2 2 6 2 2 6
56249 - 2 2 6 2 2 6 2 2 6 38 38 38
56250 - 86 86 86 50 50 50 22 22 22 6 6 6
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 - 6 6 6 14 14 14 38 38 38 82 82 82
56261 - 34 34 34 2 2 6 2 2 6 2 2 6
56262 - 42 42 42 195 195 195 246 246 246 253 253 253
56263 -253 253 253 253 253 253 253 253 253 250 250 250
56264 -242 242 242 242 242 242 250 250 250 253 253 253
56265 -253 253 253 253 253 253 253 253 253 253 253 253
56266 -253 253 253 250 250 250 246 246 246 238 238 238
56267 -226 226 226 231 231 231 101 101 101 6 6 6
56268 - 2 2 6 2 2 6 2 2 6 2 2 6
56269 - 2 2 6 2 2 6 2 2 6 2 2 6
56270 - 38 38 38 82 82 82 42 42 42 14 14 14
56271 - 6 6 6 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 - 10 10 10 26 26 26 62 62 62 66 66 66
56281 - 2 2 6 2 2 6 2 2 6 6 6 6
56282 - 70 70 70 170 170 170 206 206 206 234 234 234
56283 -246 246 246 250 250 250 250 250 250 238 238 238
56284 -226 226 226 231 231 231 238 238 238 250 250 250
56285 -250 250 250 250 250 250 246 246 246 231 231 231
56286 -214 214 214 206 206 206 202 202 202 202 202 202
56287 -198 198 198 202 202 202 182 182 182 18 18 18
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 - 2 2 6 62 62 62 66 66 66 30 30 30
56291 - 10 10 10 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 - 14 14 14 42 42 42 82 82 82 18 18 18
56301 - 2 2 6 2 2 6 2 2 6 10 10 10
56302 - 94 94 94 182 182 182 218 218 218 242 242 242
56303 -250 250 250 253 253 253 253 253 253 250 250 250
56304 -234 234 234 253 253 253 253 253 253 253 253 253
56305 -253 253 253 253 253 253 253 253 253 246 246 246
56306 -238 238 238 226 226 226 210 210 210 202 202 202
56307 -195 195 195 195 195 195 210 210 210 158 158 158
56308 - 6 6 6 14 14 14 50 50 50 14 14 14
56309 - 2 2 6 2 2 6 2 2 6 2 2 6
56310 - 2 2 6 6 6 6 86 86 86 46 46 46
56311 - 18 18 18 6 6 6 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 6 6 6
56320 - 22 22 22 54 54 54 70 70 70 2 2 6
56321 - 2 2 6 10 10 10 2 2 6 22 22 22
56322 -166 166 166 231 231 231 250 250 250 253 253 253
56323 -253 253 253 253 253 253 253 253 253 250 250 250
56324 -242 242 242 253 253 253 253 253 253 253 253 253
56325 -253 253 253 253 253 253 253 253 253 253 253 253
56326 -253 253 253 253 253 253 253 253 253 246 246 246
56327 -231 231 231 206 206 206 198 198 198 226 226 226
56328 - 94 94 94 2 2 6 6 6 6 38 38 38
56329 - 30 30 30 2 2 6 2 2 6 2 2 6
56330 - 2 2 6 2 2 6 62 62 62 66 66 66
56331 - 26 26 26 10 10 10 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 10 10 10
56340 - 30 30 30 74 74 74 50 50 50 2 2 6
56341 - 26 26 26 26 26 26 2 2 6 106 106 106
56342 -238 238 238 253 253 253 253 253 253 253 253 253
56343 -253 253 253 253 253 253 253 253 253 253 253 253
56344 -253 253 253 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 253 253 253
56347 -253 253 253 246 246 246 218 218 218 202 202 202
56348 -210 210 210 14 14 14 2 2 6 2 2 6
56349 - 30 30 30 22 22 22 2 2 6 2 2 6
56350 - 2 2 6 2 2 6 18 18 18 86 86 86
56351 - 42 42 42 14 14 14 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 14 14 14
56360 - 42 42 42 90 90 90 22 22 22 2 2 6
56361 - 42 42 42 2 2 6 18 18 18 218 218 218
56362 -253 253 253 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 253 253 253 250 250 250 221 221 221
56368 -218 218 218 101 101 101 2 2 6 14 14 14
56369 - 18 18 18 38 38 38 10 10 10 2 2 6
56370 - 2 2 6 2 2 6 2 2 6 78 78 78
56371 - 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
56380 - 54 54 54 82 82 82 2 2 6 26 26 26
56381 - 22 22 22 2 2 6 123 123 123 253 253 253
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 253 253 253 250 250 250
56388 -238 238 238 198 198 198 6 6 6 38 38 38
56389 - 58 58 58 26 26 26 38 38 38 2 2 6
56390 - 2 2 6 2 2 6 2 2 6 46 46 46
56391 - 78 78 78 30 30 30 10 10 10 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 10 10 10 30 30 30
56400 - 74 74 74 58 58 58 2 2 6 42 42 42
56401 - 2 2 6 22 22 22 231 231 231 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 250 250 250
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 253 253 253
56408 -253 253 253 246 246 246 46 46 46 38 38 38
56409 - 42 42 42 14 14 14 38 38 38 14 14 14
56410 - 2 2 6 2 2 6 2 2 6 6 6 6
56411 - 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
56420 - 90 90 90 18 18 18 18 18 18 26 26 26
56421 - 2 2 6 116 116 116 253 253 253 253 253 253
56422 -253 253 253 253 253 253 253 253 253 253 253 253
56423 -253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 94 94 94 6 6 6
56429 - 2 2 6 2 2 6 10 10 10 34 34 34
56430 - 2 2 6 2 2 6 2 2 6 2 2 6
56431 - 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
56440 - 82 82 82 2 2 6 38 38 38 6 6 6
56441 - 14 14 14 210 210 210 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 246 246 246 242 242 242
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 144 144 144 2 2 6
56449 - 2 2 6 2 2 6 2 2 6 46 46 46
56450 - 2 2 6 2 2 6 2 2 6 2 2 6
56451 - 42 42 42 74 74 74 30 30 30 10 10 10
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 - 6 6 6 14 14 14 42 42 42 90 90 90
56460 - 26 26 26 6 6 6 42 42 42 2 2 6
56461 - 74 74 74 250 250 250 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 242 242 242 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 182 182 182 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 - 10 10 10 86 86 86 38 38 38 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 - 10 10 10 26 26 26 66 66 66 82 82 82
56480 - 2 2 6 22 22 22 18 18 18 2 2 6
56481 -149 149 149 253 253 253 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 234 234 234 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 206 206 206 2 2 6
56489 - 2 2 6 2 2 6 2 2 6 38 38 38
56490 - 2 2 6 2 2 6 2 2 6 2 2 6
56491 - 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
56499 - 18 18 18 46 46 46 86 86 86 18 18 18
56500 - 2 2 6 34 34 34 10 10 10 6 6 6
56501 -210 210 210 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 221 221 221 6 6 6
56509 - 2 2 6 2 2 6 6 6 6 30 30 30
56510 - 2 2 6 2 2 6 2 2 6 2 2 6
56511 - 2 2 6 82 82 82 54 54 54 18 18 18
56512 - 6 6 6 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 10 10 10
56519 - 26 26 26 66 66 66 62 62 62 2 2 6
56520 - 2 2 6 38 38 38 10 10 10 26 26 26
56521 -238 238 238 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 231 231 231 238 238 238
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 231 231 231 6 6 6
56529 - 2 2 6 2 2 6 10 10 10 30 30 30
56530 - 2 2 6 2 2 6 2 2 6 2 2 6
56531 - 2 2 6 66 66 66 58 58 58 22 22 22
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 - 38 38 38 78 78 78 6 6 6 2 2 6
56540 - 2 2 6 46 46 46 14 14 14 42 42 42
56541 -246 246 246 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 242 242 242
56544 -253 253 253 253 253 253 253 253 253 253 253 253
56545 -253 253 253 253 253 253 253 253 253 253 253 253
56546 -253 253 253 253 253 253 253 253 253 253 253 253
56547 -253 253 253 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 234 234 234 10 10 10
56549 - 2 2 6 2 2 6 22 22 22 14 14 14
56550 - 2 2 6 2 2 6 2 2 6 2 2 6
56551 - 2 2 6 66 66 66 62 62 62 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 6 6 6 18 18 18
56559 - 50 50 50 74 74 74 2 2 6 2 2 6
56560 - 14 14 14 70 70 70 34 34 34 62 62 62
56561 -250 250 250 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 246 246 246
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 14 14 14
56569 - 2 2 6 2 2 6 30 30 30 2 2 6
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 - 54 54 54 62 62 62 2 2 6 2 2 6
56580 - 2 2 6 30 30 30 46 46 46 70 70 70
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 226 226 226 10 10 10
56589 - 2 2 6 6 6 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 58 58 58 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 22 22 22
56599 - 58 58 58 62 62 62 2 2 6 2 2 6
56600 - 2 2 6 2 2 6 30 30 30 78 78 78
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 206 206 206 2 2 6
56609 - 22 22 22 34 34 34 18 14 6 22 22 22
56610 - 26 26 26 18 18 18 6 6 6 2 2 6
56611 - 2 2 6 82 82 82 54 54 54 18 18 18
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 26 26 26
56619 - 62 62 62 106 106 106 74 54 14 185 133 11
56620 -210 162 10 121 92 8 6 6 6 62 62 62
56621 -238 238 238 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 158 158 158 18 18 18
56629 - 14 14 14 2 2 6 2 2 6 2 2 6
56630 - 6 6 6 18 18 18 66 66 66 38 38 38
56631 - 6 6 6 94 94 94 50 50 50 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 6 6 6
56638 - 10 10 10 10 10 10 18 18 18 38 38 38
56639 - 78 78 78 142 134 106 216 158 10 242 186 14
56640 -246 190 14 246 190 14 156 118 10 10 10 10
56641 - 90 90 90 238 238 238 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 250 250 250
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 246 230 190
56648 -238 204 91 238 204 91 181 142 44 37 26 9
56649 - 2 2 6 2 2 6 2 2 6 2 2 6
56650 - 2 2 6 2 2 6 38 38 38 46 46 46
56651 - 26 26 26 106 106 106 54 54 54 18 18 18
56652 - 6 6 6 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 6 6 6 14 14 14 22 22 22
56658 - 30 30 30 38 38 38 50 50 50 70 70 70
56659 -106 106 106 190 142 34 226 170 11 242 186 14
56660 -246 190 14 246 190 14 246 190 14 154 114 10
56661 - 6 6 6 74 74 74 226 226 226 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 228 184 62
56668 -241 196 14 241 208 19 232 195 16 38 30 10
56669 - 2 2 6 2 2 6 2 2 6 2 2 6
56670 - 2 2 6 6 6 6 30 30 30 26 26 26
56671 -203 166 17 154 142 90 66 66 66 26 26 26
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 - 6 6 6 18 18 18 38 38 38 58 58 58
56678 - 78 78 78 86 86 86 101 101 101 123 123 123
56679 -175 146 61 210 150 10 234 174 13 246 186 14
56680 -246 190 14 246 190 14 246 190 14 238 190 10
56681 -102 78 10 2 2 6 46 46 46 198 198 198
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 234 234 234 242 242 242
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 224 178 62
56688 -242 186 14 241 196 14 210 166 10 22 18 6
56689 - 2 2 6 2 2 6 2 2 6 2 2 6
56690 - 2 2 6 2 2 6 6 6 6 121 92 8
56691 -238 202 15 232 195 16 82 82 82 34 34 34
56692 - 10 10 10 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 - 14 14 14 38 38 38 70 70 70 154 122 46
56698 -190 142 34 200 144 11 197 138 11 197 138 11
56699 -213 154 11 226 170 11 242 186 14 246 190 14
56700 -246 190 14 246 190 14 246 190 14 246 190 14
56701 -225 175 15 46 32 6 2 2 6 22 22 22
56702 -158 158 158 250 250 250 253 253 253 253 253 253
56703 -253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 242 242 242 224 178 62
56708 -239 182 13 236 186 11 213 154 11 46 32 6
56709 - 2 2 6 2 2 6 2 2 6 2 2 6
56710 - 2 2 6 2 2 6 61 42 6 225 175 15
56711 -238 190 10 236 186 11 112 100 78 42 42 42
56712 - 14 14 14 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 6 6 6
56717 - 22 22 22 54 54 54 154 122 46 213 154 11
56718 -226 170 11 230 174 11 226 170 11 226 170 11
56719 -236 178 12 242 186 14 246 190 14 246 190 14
56720 -246 190 14 246 190 14 246 190 14 246 190 14
56721 -241 196 14 184 144 12 10 10 10 2 2 6
56722 - 6 6 6 116 116 116 242 242 242 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 231 231 231 198 198 198 214 170 54
56728 -236 178 12 236 178 12 210 150 10 137 92 6
56729 - 18 14 6 2 2 6 2 2 6 2 2 6
56730 - 6 6 6 70 47 6 200 144 11 236 178 12
56731 -239 182 13 239 182 13 124 112 88 58 58 58
56732 - 22 22 22 6 6 6 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 10 10 10
56737 - 30 30 30 70 70 70 180 133 36 226 170 11
56738 -239 182 13 242 186 14 242 186 14 246 186 14
56739 -246 190 14 246 190 14 246 190 14 246 190 14
56740 -246 190 14 246 190 14 246 190 14 246 190 14
56741 -246 190 14 232 195 16 98 70 6 2 2 6
56742 - 2 2 6 2 2 6 66 66 66 221 221 221
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 206 206 206 198 198 198 214 166 58
56748 -230 174 11 230 174 11 216 158 10 192 133 9
56749 -163 110 8 116 81 8 102 78 10 116 81 8
56750 -167 114 7 197 138 11 226 170 11 239 182 13
56751 -242 186 14 242 186 14 162 146 94 78 78 78
56752 - 34 34 34 14 14 14 6 6 6 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 6 6 6
56757 - 30 30 30 78 78 78 190 142 34 226 170 11
56758 -239 182 13 246 190 14 246 190 14 246 190 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 241 196 14 203 166 17 22 18 6
56762 - 2 2 6 2 2 6 2 2 6 38 38 38
56763 -218 218 218 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 -250 250 250 206 206 206 198 198 198 202 162 69
56768 -226 170 11 236 178 12 224 166 10 210 150 10
56769 -200 144 11 197 138 11 192 133 9 197 138 11
56770 -210 150 10 226 170 11 242 186 14 246 190 14
56771 -246 190 14 246 186 14 225 175 15 124 112 88
56772 - 62 62 62 30 30 30 14 14 14 6 6 6
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 10 10 10
56777 - 30 30 30 78 78 78 174 135 50 224 166 10
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 246 190 14 241 196 14 139 102 15
56782 - 2 2 6 2 2 6 2 2 6 2 2 6
56783 - 78 78 78 250 250 250 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 214 214 214 198 198 198 190 150 46
56788 -219 162 10 236 178 12 234 174 13 224 166 10
56789 -216 158 10 213 154 11 213 154 11 216 158 10
56790 -226 170 11 239 182 13 246 190 14 246 190 14
56791 -246 190 14 246 190 14 242 186 14 206 162 42
56792 -101 101 101 58 58 58 30 30 30 14 14 14
56793 - 6 6 6 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 74 74 74 174 135 50 216 158 10
56798 -236 178 12 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 226 184 13
56802 - 61 42 6 2 2 6 2 2 6 2 2 6
56803 - 22 22 22 238 238 238 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 -253 253 253 226 226 226 187 187 187 180 133 36
56808 -216 158 10 236 178 12 239 182 13 236 178 12
56809 -230 174 11 226 170 11 226 170 11 230 174 11
56810 -236 178 12 242 186 14 246 190 14 246 190 14
56811 -246 190 14 246 190 14 246 186 14 239 182 13
56812 -206 162 42 106 106 106 66 66 66 34 34 34
56813 - 14 14 14 6 6 6 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 6 6 6
56817 - 26 26 26 70 70 70 163 133 67 213 154 11
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 246 190 14 241 196 14
56822 -190 146 13 18 14 6 2 2 6 2 2 6
56823 - 46 46 46 246 246 246 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 221 221 221 86 86 86 156 107 11
56828 -216 158 10 236 178 12 242 186 14 246 186 14
56829 -242 186 14 239 182 13 239 182 13 242 186 14
56830 -242 186 14 246 186 14 246 190 14 246 190 14
56831 -246 190 14 246 190 14 246 190 14 246 190 14
56832 -242 186 14 225 175 15 142 122 72 66 66 66
56833 - 30 30 30 10 10 10 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 210 150 10
56838 -236 178 12 246 190 14 246 190 14 246 190 14
56839 -246 190 14 246 190 14 246 190 14 246 190 14
56840 -246 190 14 246 190 14 246 190 14 246 190 14
56841 -246 190 14 246 190 14 246 190 14 246 190 14
56842 -232 195 16 121 92 8 34 34 34 106 106 106
56843 -221 221 221 253 253 253 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 -242 242 242 82 82 82 18 14 6 163 110 8
56848 -216 158 10 236 178 12 242 186 14 246 190 14
56849 -246 190 14 246 190 14 246 190 14 246 190 14
56850 -246 190 14 246 190 14 246 190 14 246 190 14
56851 -246 190 14 246 190 14 246 190 14 246 190 14
56852 -246 190 14 246 190 14 242 186 14 163 133 67
56853 - 46 46 46 18 18 18 6 6 6 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 10 10 10
56857 - 30 30 30 78 78 78 163 133 67 210 150 10
56858 -236 178 12 246 186 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 -241 196 14 215 174 15 190 178 144 253 253 253
56863 -253 253 253 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 218 218 218
56867 - 58 58 58 2 2 6 22 18 6 167 114 7
56868 -216 158 10 236 178 12 246 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 186 14 242 186 14 190 150 46
56873 - 54 54 54 22 22 22 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 14 14 14
56877 - 38 38 38 86 86 86 180 133 36 213 154 11
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 -246 190 14 232 195 16 190 146 13 214 214 214
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 250 250 250 170 170 170 26 26 26
56887 - 2 2 6 2 2 6 37 26 9 163 110 8
56888 -219 162 10 239 182 13 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 186 14 236 178 12 224 166 10 142 122 72
56893 - 46 46 46 18 18 18 6 6 6 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 6 6 6 18 18 18
56897 - 50 50 50 109 106 95 192 133 9 224 166 10
56898 -242 186 14 246 190 14 246 190 14 246 190 14
56899 -246 190 14 246 190 14 246 190 14 246 190 14
56900 -246 190 14 246 190 14 246 190 14 246 190 14
56901 -246 190 14 246 190 14 246 190 14 246 190 14
56902 -242 186 14 226 184 13 210 162 10 142 110 46
56903 -226 226 226 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 -198 198 198 66 66 66 2 2 6 2 2 6
56907 - 2 2 6 2 2 6 50 34 6 156 107 11
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 242 186 14
56912 -234 174 13 213 154 11 154 122 46 66 66 66
56913 - 30 30 30 10 10 10 0 0 0 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 22 22 22
56917 - 58 58 58 154 121 60 206 145 10 234 174 13
56918 -242 186 14 246 186 14 246 190 14 246 190 14
56919 -246 190 14 246 190 14 246 190 14 246 190 14
56920 -246 190 14 246 190 14 246 190 14 246 190 14
56921 -246 190 14 246 190 14 246 190 14 246 190 14
56922 -246 186 14 236 178 12 210 162 10 163 110 8
56923 - 61 42 6 138 138 138 218 218 218 250 250 250
56924 -253 253 253 253 253 253 253 253 253 250 250 250
56925 -242 242 242 210 210 210 144 144 144 66 66 66
56926 - 6 6 6 2 2 6 2 2 6 2 2 6
56927 - 2 2 6 2 2 6 61 42 6 163 110 8
56928 -216 158 10 236 178 12 246 190 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 239 182 13 230 174 11 216 158 10
56932 -190 142 34 124 112 88 70 70 70 38 38 38
56933 - 18 18 18 6 6 6 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 - 62 62 62 168 124 44 206 145 10 224 166 10
56938 -236 178 12 239 182 13 242 186 14 242 186 14
56939 -246 186 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 190 14 236 178 12 216 158 10 175 118 6
56943 - 80 54 7 2 2 6 6 6 6 30 30 30
56944 - 54 54 54 62 62 62 50 50 50 38 38 38
56945 - 14 14 14 2 2 6 2 2 6 2 2 6
56946 - 2 2 6 2 2 6 2 2 6 2 2 6
56947 - 2 2 6 6 6 6 80 54 7 167 114 7
56948 -213 154 11 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 242 186 14 239 182 13 239 182 13
56951 -230 174 11 210 150 10 174 135 50 124 112 88
56952 - 82 82 82 54 54 54 34 34 34 18 18 18
56953 - 6 6 6 0 0 0 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 18 18 18
56957 - 50 50 50 158 118 36 192 133 9 200 144 11
56958 -216 158 10 219 162 10 224 166 10 226 170 11
56959 -230 174 11 236 178 12 239 182 13 239 182 13
56960 -242 186 14 246 186 14 246 190 14 246 190 14
56961 -246 190 14 246 190 14 246 190 14 246 190 14
56962 -246 186 14 230 174 11 210 150 10 163 110 8
56963 -104 69 6 10 10 10 2 2 6 2 2 6
56964 - 2 2 6 2 2 6 2 2 6 2 2 6
56965 - 2 2 6 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 91 60 6 167 114 7
56968 -206 145 10 230 174 11 242 186 14 246 190 14
56969 -246 190 14 246 190 14 246 186 14 242 186 14
56970 -239 182 13 230 174 11 224 166 10 213 154 11
56971 -180 133 36 124 112 88 86 86 86 58 58 58
56972 - 38 38 38 22 22 22 10 10 10 6 6 6
56973 - 0 0 0 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 0 0 0 14 14 14
56977 - 34 34 34 70 70 70 138 110 50 158 118 36
56978 -167 114 7 180 123 7 192 133 9 197 138 11
56979 -200 144 11 206 145 10 213 154 11 219 162 10
56980 -224 166 10 230 174 11 239 182 13 242 186 14
56981 -246 186 14 246 186 14 246 186 14 246 186 14
56982 -239 182 13 216 158 10 185 133 11 152 99 6
56983 -104 69 6 18 14 6 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 80 54 7 152 99 6
56988 -192 133 9 219 162 10 236 178 12 239 182 13
56989 -246 186 14 242 186 14 239 182 13 236 178 12
56990 -224 166 10 206 145 10 192 133 9 154 121 60
56991 - 94 94 94 62 62 62 42 42 42 22 22 22
56992 - 14 14 14 6 6 6 0 0 0 0 0 0
56993 - 0 0 0 0 0 0 0 0 0 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 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 6 6 6
56997 - 18 18 18 34 34 34 58 58 58 78 78 78
56998 -101 98 89 124 112 88 142 110 46 156 107 11
56999 -163 110 8 167 114 7 175 118 6 180 123 7
57000 -185 133 11 197 138 11 210 150 10 219 162 10
57001 -226 170 11 236 178 12 236 178 12 234 174 13
57002 -219 162 10 197 138 11 163 110 8 130 83 6
57003 - 91 60 6 10 10 10 2 2 6 2 2 6
57004 - 18 18 18 38 38 38 38 38 38 38 38 38
57005 - 38 38 38 38 38 38 38 38 38 38 38 38
57006 - 38 38 38 38 38 38 26 26 26 2 2 6
57007 - 2 2 6 6 6 6 70 47 6 137 92 6
57008 -175 118 6 200 144 11 219 162 10 230 174 11
57009 -234 174 13 230 174 11 219 162 10 210 150 10
57010 -192 133 9 163 110 8 124 112 88 82 82 82
57011 - 50 50 50 30 30 30 14 14 14 6 6 6
57012 - 0 0 0 0 0 0 0 0 0 0 0 0
57013 - 0 0 0 0 0 0 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 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 0 0 0
57017 - 6 6 6 14 14 14 22 22 22 34 34 34
57018 - 42 42 42 58 58 58 74 74 74 86 86 86
57019 -101 98 89 122 102 70 130 98 46 121 87 25
57020 -137 92 6 152 99 6 163 110 8 180 123 7
57021 -185 133 11 197 138 11 206 145 10 200 144 11
57022 -180 123 7 156 107 11 130 83 6 104 69 6
57023 - 50 34 6 54 54 54 110 110 110 101 98 89
57024 - 86 86 86 82 82 82 78 78 78 78 78 78
57025 - 78 78 78 78 78 78 78 78 78 78 78 78
57026 - 78 78 78 82 82 82 86 86 86 94 94 94
57027 -106 106 106 101 101 101 86 66 34 124 80 6
57028 -156 107 11 180 123 7 192 133 9 200 144 11
57029 -206 145 10 200 144 11 192 133 9 175 118 6
57030 -139 102 15 109 106 95 70 70 70 42 42 42
57031 - 22 22 22 10 10 10 0 0 0 0 0 0
57032 - 0 0 0 0 0 0 0 0 0 0 0 0
57033 - 0 0 0 0 0 0 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 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 - 0 0 0 0 0 0 6 6 6 10 10 10
57038 - 14 14 14 22 22 22 30 30 30 38 38 38
57039 - 50 50 50 62 62 62 74 74 74 90 90 90
57040 -101 98 89 112 100 78 121 87 25 124 80 6
57041 -137 92 6 152 99 6 152 99 6 152 99 6
57042 -138 86 6 124 80 6 98 70 6 86 66 30
57043 -101 98 89 82 82 82 58 58 58 46 46 46
57044 - 38 38 38 34 34 34 34 34 34 34 34 34
57045 - 34 34 34 34 34 34 34 34 34 34 34 34
57046 - 34 34 34 34 34 34 38 38 38 42 42 42
57047 - 54 54 54 82 82 82 94 86 76 91 60 6
57048 -134 86 6 156 107 11 167 114 7 175 118 6
57049 -175 118 6 167 114 7 152 99 6 121 87 25
57050 -101 98 89 62 62 62 34 34 34 18 18 18
57051 - 6 6 6 0 0 0 0 0 0 0 0 0
57052 - 0 0 0 0 0 0 0 0 0 0 0 0
57053 - 0 0 0 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 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 0 0 0 0 0 0
57058 - 0 0 0 6 6 6 6 6 6 10 10 10
57059 - 18 18 18 22 22 22 30 30 30 42 42 42
57060 - 50 50 50 66 66 66 86 86 86 101 98 89
57061 -106 86 58 98 70 6 104 69 6 104 69 6
57062 -104 69 6 91 60 6 82 62 34 90 90 90
57063 - 62 62 62 38 38 38 22 22 22 14 14 14
57064 - 10 10 10 10 10 10 10 10 10 10 10 10
57065 - 10 10 10 10 10 10 6 6 6 10 10 10
57066 - 10 10 10 10 10 10 10 10 10 14 14 14
57067 - 22 22 22 42 42 42 70 70 70 89 81 66
57068 - 80 54 7 104 69 6 124 80 6 137 92 6
57069 -134 86 6 116 81 8 100 82 52 86 86 86
57070 - 58 58 58 30 30 30 14 14 14 6 6 6
57071 - 0 0 0 0 0 0 0 0 0 0 0 0
57072 - 0 0 0 0 0 0 0 0 0 0 0 0
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 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 0 0 0 0 0 0 0 0 0
57079 - 0 0 0 6 6 6 10 10 10 14 14 14
57080 - 18 18 18 26 26 26 38 38 38 54 54 54
57081 - 70 70 70 86 86 86 94 86 76 89 81 66
57082 - 89 81 66 86 86 86 74 74 74 50 50 50
57083 - 30 30 30 14 14 14 6 6 6 0 0 0
57084 - 0 0 0 0 0 0 0 0 0 0 0 0
57085 - 0 0 0 0 0 0 0 0 0 0 0 0
57086 - 0 0 0 0 0 0 0 0 0 0 0 0
57087 - 6 6 6 18 18 18 34 34 34 58 58 58
57088 - 82 82 82 89 81 66 89 81 66 89 81 66
57089 - 94 86 66 94 86 76 74 74 74 50 50 50
57090 - 26 26 26 14 14 14 6 6 6 0 0 0
57091 - 0 0 0 0 0 0 0 0 0 0 0 0
57092 - 0 0 0 0 0 0 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 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 0 0 0 0 0 0 0 0 0
57100 - 6 6 6 6 6 6 14 14 14 18 18 18
57101 - 30 30 30 38 38 38 46 46 46 54 54 54
57102 - 50 50 50 42 42 42 30 30 30 18 18 18
57103 - 10 10 10 0 0 0 0 0 0 0 0 0
57104 - 0 0 0 0 0 0 0 0 0 0 0 0
57105 - 0 0 0 0 0 0 0 0 0 0 0 0
57106 - 0 0 0 0 0 0 0 0 0 0 0 0
57107 - 0 0 0 6 6 6 14 14 14 26 26 26
57108 - 38 38 38 50 50 50 58 58 58 58 58 58
57109 - 54 54 54 42 42 42 30 30 30 18 18 18
57110 - 10 10 10 0 0 0 0 0 0 0 0 0
57111 - 0 0 0 0 0 0 0 0 0 0 0 0
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 6 6 6
57121 - 6 6 6 10 10 10 14 14 14 18 18 18
57122 - 18 18 18 14 14 14 10 10 10 6 6 6
57123 - 0 0 0 0 0 0 0 0 0 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 0 0 0 0 0 0 0 0 0 6 6 6
57128 - 14 14 14 18 18 18 22 22 22 22 22 22
57129 - 18 18 18 14 14 14 10 10 10 6 6 6
57130 - 0 0 0 0 0 0 0 0 0 0 0 0
57131 - 0 0 0 0 0 0 0 0 0 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57148 +4 4 4 4 4 4
57149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
57177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57188 +4 4 4 4 4 4 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
57191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57202 +4 4 4 4 4 4 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
57205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57216 +4 4 4 4 4 4 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
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 3 3 3 0 0 0 0 0 0
57224 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
57229 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57230 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
57238 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57239 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
57243 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57244 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57245 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57251 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57252 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57253 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
57257 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57258 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57259 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57264 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57265 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57266 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57267 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
57270 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57271 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57272 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57273 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57274 +4 4 4 4 4 4
57275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57278 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57279 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57280 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57281 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57282 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57283 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57284 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57285 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57286 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57287 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57288 +4 4 4 4 4 4
57289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57292 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57293 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57294 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57295 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57296 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57297 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57298 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57299 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57300 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57301 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57302 +4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57305 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57306 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57307 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57308 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57309 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57310 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57311 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57312 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57313 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57314 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57315 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57316 +4 4 4 4 4 4
57317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57319 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57320 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57321 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57322 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57323 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57324 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57325 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57326 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57327 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57328 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57329 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57330 +4 4 4 4 4 4
57331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57333 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57334 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57335 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57336 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57337 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57338 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57339 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57340 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57341 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57342 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57343 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57344 +4 4 4 4 4 4
57345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57347 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57348 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57349 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57350 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57351 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57352 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57353 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57354 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57355 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57356 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57357 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57358 +4 4 4 4 4 4
57359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57360 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57361 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57362 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57363 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57364 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57365 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57366 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57367 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57368 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57369 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57370 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57371 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57372 +4 4 4 4 4 4
57373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57374 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57375 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57376 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57377 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57378 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57379 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57380 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57381 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57382 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57383 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57384 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57385 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57386 +0 0 0 4 4 4
57387 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57388 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57389 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57390 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57391 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57392 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57393 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57394 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57395 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57396 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57397 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57398 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57399 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57400 +2 0 0 0 0 0
57401 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57402 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57403 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57404 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57405 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57406 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57407 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57408 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57409 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57410 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57411 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57412 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57413 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57414 +37 38 37 0 0 0
57415 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57416 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57417 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57418 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57419 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57420 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57421 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57422 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57423 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57424 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57425 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57426 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57427 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57428 +85 115 134 4 0 0
57429 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57430 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57431 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57432 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57433 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57434 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57435 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57436 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57437 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57438 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57439 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57440 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57441 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57442 +60 73 81 4 0 0
57443 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57444 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57445 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57446 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57447 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57448 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57449 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57450 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57451 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57452 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57453 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57454 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57455 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57456 +16 19 21 4 0 0
57457 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57458 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57459 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57460 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57461 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57462 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57463 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57464 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57465 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57466 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57467 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57468 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57469 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57470 +4 0 0 4 3 3
57471 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57472 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57473 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57475 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57476 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57477 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57478 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57479 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57480 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57481 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57482 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57483 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57484 +3 2 2 4 4 4
57485 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57486 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57487 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57488 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57489 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57490 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57491 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57492 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57493 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57494 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57495 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57496 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57497 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57498 +4 4 4 4 4 4
57499 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57500 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57501 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57502 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57503 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57504 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57505 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57506 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57507 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57508 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57509 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57510 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57511 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57512 +4 4 4 4 4 4
57513 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57514 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57515 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57516 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57517 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57518 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57519 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57520 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57521 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57522 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57523 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57524 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57525 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57526 +5 5 5 5 5 5
57527 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57528 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57529 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57530 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57531 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57532 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57533 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57534 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57535 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57536 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57537 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57538 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57539 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57540 +5 5 5 4 4 4
57541 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57542 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57543 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57544 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57545 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57546 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57547 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57548 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57549 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57550 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57551 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57552 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57554 +4 4 4 4 4 4
57555 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57556 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57557 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57558 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57559 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57560 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57561 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57562 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57563 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57564 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57565 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57566 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57568 +4 4 4 4 4 4
57569 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57570 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57571 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57572 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57573 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57574 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57575 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57576 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57577 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57578 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57579 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57582 +4 4 4 4 4 4
57583 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57584 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57585 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57586 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57587 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57588 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57589 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57590 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57591 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57592 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57593 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57596 +4 4 4 4 4 4
57597 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57598 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57599 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57600 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57601 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57602 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57603 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57604 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57605 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57606 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57607 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57610 +4 4 4 4 4 4
57611 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57612 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57613 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57614 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57615 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57616 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57617 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57618 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57619 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57620 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57621 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57624 +4 4 4 4 4 4
57625 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57626 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57627 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57628 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57629 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57630 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57631 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57632 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57633 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57634 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57635 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57638 +4 4 4 4 4 4
57639 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57640 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57641 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57642 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57643 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57644 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57645 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57646 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57647 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57648 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57649 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57652 +4 4 4 4 4 4
57653 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57654 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57655 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57656 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57657 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57658 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57659 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57660 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57661 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57662 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57663 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57666 +4 4 4 4 4 4
57667 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57668 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57669 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57670 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57671 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57672 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57673 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57674 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57675 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57676 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57677 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57680 +4 4 4 4 4 4
57681 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57682 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57683 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57684 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57685 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57686 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57687 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57688 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57689 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57690 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57691 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57694 +4 4 4 4 4 4
57695 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57696 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57697 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57698 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57699 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57700 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57701 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57702 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57703 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57704 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57705 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57708 +4 4 4 4 4 4
57709 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57710 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57711 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57712 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57713 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57714 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57715 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57716 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57717 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57718 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57719 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57722 +4 4 4 4 4 4
57723 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57724 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57725 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57726 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57727 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57728 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57729 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57730 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57731 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57732 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57733 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57736 +4 4 4 4 4 4
57737 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57738 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57739 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57740 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57741 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57742 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57743 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57744 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57745 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57746 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57747 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57750 +4 4 4 4 4 4
57751 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57752 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57753 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57754 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57755 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57756 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57757 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57758 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57759 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57760 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57761 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57764 +4 4 4 4 4 4
57765 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57766 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57767 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57768 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57769 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57770 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57771 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57772 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57773 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57774 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57775 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57778 +4 4 4 4 4 4
57779 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57780 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57781 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57782 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57783 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57784 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57785 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57786 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57787 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57788 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57789 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57792 +4 4 4 4 4 4
57793 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57794 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57795 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57796 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57797 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57798 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57799 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57800 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57801 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57802 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57803 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57806 +4 4 4 4 4 4
57807 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57808 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57809 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57810 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57811 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57812 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57813 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57814 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57815 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57816 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57817 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57820 +4 4 4 4 4 4
57821 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57822 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57823 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57824 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57825 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57826 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57827 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57828 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57829 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57830 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57831 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57834 +4 4 4 4 4 4
57835 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57836 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57837 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57838 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57839 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57840 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57841 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57842 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57843 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57844 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57845 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57848 +4 4 4 4 4 4
57849 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57850 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57851 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57852 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57853 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57854 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57855 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57856 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57857 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57858 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57859 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57862 +4 4 4 4 4 4
57863 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57864 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57865 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57866 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57867 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57868 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57869 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57870 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57871 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57872 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57873 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57876 +4 4 4 4 4 4
57877 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57878 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57879 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57880 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57881 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57882 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57883 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57884 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57885 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57886 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57887 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57890 +4 4 4 4 4 4
57891 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57892 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57893 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57894 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57895 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57896 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57897 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57898 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57899 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57900 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57901 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57904 +4 4 4 4 4 4
57905 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57906 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57907 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57908 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57909 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57910 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57911 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57912 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57913 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57914 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57915 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57918 +4 4 4 4 4 4
57919 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57920 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57921 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57922 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57923 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57924 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57925 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57926 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57927 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57928 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57929 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57932 +4 4 4 4 4 4
57933 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57934 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57935 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57936 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57937 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57938 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57939 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57940 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57941 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57942 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57943 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57946 +4 4 4 4 4 4
57947 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57948 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57949 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57950 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57951 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57952 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57953 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57954 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57955 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57956 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
57957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57960 +4 4 4 4 4 4
57961 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57962 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57963 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57964 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57965 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57966 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57967 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57968 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57969 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57970 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
57971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57974 +4 4 4 4 4 4
57975 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57976 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57977 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57978 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57979 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
57980 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
57981 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
57982 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
57983 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
57984 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57988 +4 4 4 4 4 4
57989 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
57990 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
57991 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
57992 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
57993 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
57994 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
57995 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
57996 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
57997 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57998 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58002 +4 4 4 4 4 4
58003 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58004 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58005 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58006 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58007 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58008 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58009 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58010 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58011 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58016 +4 4 4 4 4 4
58017 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58018 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58019 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58020 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58021 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58022 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58023 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58024 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58025 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58030 +4 4 4 4 4 4
58031 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58032 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58033 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58034 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58035 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58036 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58037 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58038 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58039 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58044 +4 4 4 4 4 4
58045 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58046 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58047 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58048 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58049 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58050 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58051 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58052 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58058 +4 4 4 4 4 4
58059 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58060 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58061 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58062 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58063 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58064 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58065 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58066 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072 +4 4 4 4 4 4
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58074 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58075 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58076 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58077 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58078 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58079 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58080 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086 +4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58089 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58090 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58091 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58092 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58093 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58094 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
58103 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58104 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58105 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58106 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58107 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58108 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58118 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58119 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58120 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58121 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58122 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4
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 5 5 5
58132 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58133 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58134 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58135 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58147 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58148 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58149 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
58161 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58162 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58163 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58170 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
58175 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58176 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58177 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58184 +4 4 4 4 4 4
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 5 5 5
58189 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58190 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58191 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58198 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58204 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58205 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58218 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58219 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
58232 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4
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 5 5 5 4 3 3
58246 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4
58255 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58256 index fef20db..d28b1ab 100644
58257 --- a/drivers/xen/xenfs/xenstored.c
58258 +++ b/drivers/xen/xenfs/xenstored.c
58259 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58260 static int xsd_kva_open(struct inode *inode, struct file *file)
58261 {
58262 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58263 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58264 + NULL);
58265 +#else
58266 xen_store_interface);
58267 +#endif
58268 +
58269 if (!file->private_data)
58270 return -ENOMEM;
58271 return 0;
58272 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58273 index eb14e05..5156de7 100644
58274 --- a/fs/9p/vfs_addr.c
58275 +++ b/fs/9p/vfs_addr.c
58276 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58277
58278 retval = v9fs_file_write_internal(inode,
58279 v9inode->writeback_fid,
58280 - (__force const char __user *)buffer,
58281 + (const char __force_user *)buffer,
58282 len, &offset, 0);
58283 if (retval > 0)
58284 retval = 0;
58285 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58286 index 296482f..183ddc3 100644
58287 --- a/fs/9p/vfs_inode.c
58288 +++ b/fs/9p/vfs_inode.c
58289 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58290 void
58291 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58292 {
58293 - char *s = nd_get_link(nd);
58294 + const char *s = nd_get_link(nd);
58295
58296 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58297 dentry, IS_ERR(s) ? "<error>" : s);
58298 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58299 index 370b24c..ff0be7b 100644
58300 --- a/fs/Kconfig.binfmt
58301 +++ b/fs/Kconfig.binfmt
58302 @@ -103,7 +103,7 @@ config HAVE_AOUT
58303
58304 config BINFMT_AOUT
58305 tristate "Kernel support for a.out and ECOFF binaries"
58306 - depends on HAVE_AOUT
58307 + depends on HAVE_AOUT && BROKEN
58308 ---help---
58309 A.out (Assembler.OUTput) is a set of formats for libraries and
58310 executables used in the earliest versions of UNIX. Linux used
58311 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58312 index 2946712..f737435 100644
58313 --- a/fs/afs/inode.c
58314 +++ b/fs/afs/inode.c
58315 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58316 struct afs_vnode *vnode;
58317 struct super_block *sb;
58318 struct inode *inode;
58319 - static atomic_t afs_autocell_ino;
58320 + static atomic_unchecked_t afs_autocell_ino;
58321
58322 _enter("{%x:%u},%*.*s,",
58323 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58324 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58325 data.fid.unique = 0;
58326 data.fid.vnode = 0;
58327
58328 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58329 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58330 afs_iget5_autocell_test, afs_iget5_set,
58331 &data);
58332 if (!inode) {
58333 diff --git a/fs/aio.c b/fs/aio.c
58334 index 14b9315..365980f 100644
58335 --- a/fs/aio.c
58336 +++ b/fs/aio.c
58337 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58338 size += sizeof(struct io_event) * nr_events;
58339
58340 nr_pages = PFN_UP(size);
58341 - if (nr_pages < 0)
58342 + if (nr_pages <= 0)
58343 return -EINVAL;
58344
58345 file = aio_private_file(ctx, nr_pages);
58346 diff --git a/fs/attr.c b/fs/attr.c
58347 index 6530ced..4a827e2 100644
58348 --- a/fs/attr.c
58349 +++ b/fs/attr.c
58350 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58351 unsigned long limit;
58352
58353 limit = rlimit(RLIMIT_FSIZE);
58354 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58355 if (limit != RLIM_INFINITY && offset > limit)
58356 goto out_sig;
58357 if (offset > inode->i_sb->s_maxbytes)
58358 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58359 index 116fd38..c04182da 100644
58360 --- a/fs/autofs4/waitq.c
58361 +++ b/fs/autofs4/waitq.c
58362 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58363 {
58364 unsigned long sigpipe, flags;
58365 mm_segment_t fs;
58366 - const char *data = (const char *)addr;
58367 + const char __user *data = (const char __force_user *)addr;
58368 ssize_t wr = 0;
58369
58370 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58371 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58372 return 1;
58373 }
58374
58375 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58376 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58377 +#endif
58378 +
58379 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58380 enum autofs_notify notify)
58381 {
58382 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58383
58384 /* If this is a direct mount request create a dummy name */
58385 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58386 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58387 + /* this name does get written to userland via autofs4_write() */
58388 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58389 +#else
58390 qstr.len = sprintf(name, "%p", dentry);
58391 +#endif
58392 else {
58393 qstr.len = autofs4_getpath(sbi, dentry, &name);
58394 if (!qstr.len) {
58395 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58396 index 2722387..56059b5 100644
58397 --- a/fs/befs/endian.h
58398 +++ b/fs/befs/endian.h
58399 @@ -11,7 +11,7 @@
58400
58401 #include <asm/byteorder.h>
58402
58403 -static inline u64
58404 +static inline u64 __intentional_overflow(-1)
58405 fs64_to_cpu(const struct super_block *sb, fs64 n)
58406 {
58407 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58408 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58409 return (__force fs64)cpu_to_be64(n);
58410 }
58411
58412 -static inline u32
58413 +static inline u32 __intentional_overflow(-1)
58414 fs32_to_cpu(const struct super_block *sb, fs32 n)
58415 {
58416 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58417 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58418 return (__force fs32)cpu_to_be32(n);
58419 }
58420
58421 -static inline u16
58422 +static inline u16 __intentional_overflow(-1)
58423 fs16_to_cpu(const struct super_block *sb, fs16 n)
58424 {
58425 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58426 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58427 index 929dec0..84bd914 100644
58428 --- a/fs/binfmt_aout.c
58429 +++ b/fs/binfmt_aout.c
58430 @@ -16,6 +16,7 @@
58431 #include <linux/string.h>
58432 #include <linux/fs.h>
58433 #include <linux/file.h>
58434 +#include <linux/security.h>
58435 #include <linux/stat.h>
58436 #include <linux/fcntl.h>
58437 #include <linux/ptrace.h>
58438 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58439 #endif
58440 # define START_STACK(u) ((void __user *)u.start_stack)
58441
58442 + memset(&dump, 0, sizeof(dump));
58443 +
58444 fs = get_fs();
58445 set_fs(KERNEL_DS);
58446 has_dumped = 1;
58447 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58448
58449 /* If the size of the dump file exceeds the rlimit, then see what would happen
58450 if we wrote the stack, but not the data area. */
58451 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58452 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58453 dump.u_dsize = 0;
58454
58455 /* Make sure we have enough room to write the stack and data areas. */
58456 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58457 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58458 dump.u_ssize = 0;
58459
58460 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58461 rlim = rlimit(RLIMIT_DATA);
58462 if (rlim >= RLIM_INFINITY)
58463 rlim = ~0;
58464 +
58465 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58466 if (ex.a_data + ex.a_bss > rlim)
58467 return -ENOMEM;
58468
58469 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58470
58471 install_exec_creds(bprm);
58472
58473 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58474 + current->mm->pax_flags = 0UL;
58475 +#endif
58476 +
58477 +#ifdef CONFIG_PAX_PAGEEXEC
58478 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58479 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58480 +
58481 +#ifdef CONFIG_PAX_EMUTRAMP
58482 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58483 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58484 +#endif
58485 +
58486 +#ifdef CONFIG_PAX_MPROTECT
58487 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58488 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58489 +#endif
58490 +
58491 + }
58492 +#endif
58493 +
58494 if (N_MAGIC(ex) == OMAGIC) {
58495 unsigned long text_addr, map_size;
58496 loff_t pos;
58497 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58498 return error;
58499
58500 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58501 - PROT_READ | PROT_WRITE | PROT_EXEC,
58502 + PROT_READ | PROT_WRITE,
58503 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58504 fd_offset + ex.a_text);
58505 if (error != N_DATADDR(ex))
58506 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58507 index d8fc060..cbd44d5 100644
58508 --- a/fs/binfmt_elf.c
58509 +++ b/fs/binfmt_elf.c
58510 @@ -34,6 +34,7 @@
58511 #include <linux/utsname.h>
58512 #include <linux/coredump.h>
58513 #include <linux/sched.h>
58514 +#include <linux/xattr.h>
58515 #include <asm/uaccess.h>
58516 #include <asm/param.h>
58517 #include <asm/page.h>
58518 @@ -47,7 +48,7 @@
58519
58520 static int load_elf_binary(struct linux_binprm *bprm);
58521 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58522 - int, int, unsigned long);
58523 + int, int, unsigned long) __intentional_overflow(-1);
58524
58525 #ifdef CONFIG_USELIB
58526 static int load_elf_library(struct file *);
58527 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58528 #define elf_core_dump NULL
58529 #endif
58530
58531 +#ifdef CONFIG_PAX_MPROTECT
58532 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58533 +#endif
58534 +
58535 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58536 +static void elf_handle_mmap(struct file *file);
58537 +#endif
58538 +
58539 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58540 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58541 #else
58542 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58543 .load_binary = load_elf_binary,
58544 .load_shlib = load_elf_library,
58545 .core_dump = elf_core_dump,
58546 +
58547 +#ifdef CONFIG_PAX_MPROTECT
58548 + .handle_mprotect= elf_handle_mprotect,
58549 +#endif
58550 +
58551 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58552 + .handle_mmap = elf_handle_mmap,
58553 +#endif
58554 +
58555 .min_coredump = ELF_EXEC_PAGESIZE,
58556 };
58557
58558 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58559
58560 static int set_brk(unsigned long start, unsigned long end)
58561 {
58562 + unsigned long e = end;
58563 +
58564 start = ELF_PAGEALIGN(start);
58565 end = ELF_PAGEALIGN(end);
58566 if (end > start) {
58567 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58568 if (BAD_ADDR(addr))
58569 return addr;
58570 }
58571 - current->mm->start_brk = current->mm->brk = end;
58572 + current->mm->start_brk = current->mm->brk = e;
58573 return 0;
58574 }
58575
58576 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58577 elf_addr_t __user *u_rand_bytes;
58578 const char *k_platform = ELF_PLATFORM;
58579 const char *k_base_platform = ELF_BASE_PLATFORM;
58580 - unsigned char k_rand_bytes[16];
58581 + u32 k_rand_bytes[4];
58582 int items;
58583 elf_addr_t *elf_info;
58584 int ei_index = 0;
58585 const struct cred *cred = current_cred();
58586 struct vm_area_struct *vma;
58587 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58588
58589 /*
58590 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58591 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58592 * Generate 16 random bytes for userspace PRNG seeding.
58593 */
58594 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58595 - u_rand_bytes = (elf_addr_t __user *)
58596 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58597 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58598 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58599 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58600 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58601 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58602 + u_rand_bytes = (elf_addr_t __user *) p;
58603 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58604 return -EFAULT;
58605
58606 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58607 return -EFAULT;
58608 current->mm->env_end = p;
58609
58610 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58611 +
58612 /* Put the elf_info on the stack in the right place. */
58613 sp = (elf_addr_t __user *)envp + 1;
58614 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58615 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58616 return -EFAULT;
58617 return 0;
58618 }
58619 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58620 an ELF header */
58621
58622 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58623 - struct file *interpreter, unsigned long *interp_map_addr,
58624 - unsigned long no_base)
58625 + struct file *interpreter, unsigned long no_base)
58626 {
58627 struct elf_phdr *elf_phdata;
58628 struct elf_phdr *eppnt;
58629 - unsigned long load_addr = 0;
58630 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58631 int load_addr_set = 0;
58632 unsigned long last_bss = 0, elf_bss = 0;
58633 - unsigned long error = ~0UL;
58634 + unsigned long error = -EINVAL;
58635 unsigned long total_size;
58636 int retval, i, size;
58637
58638 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58639 goto out_close;
58640 }
58641
58642 +#ifdef CONFIG_PAX_SEGMEXEC
58643 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58644 + pax_task_size = SEGMEXEC_TASK_SIZE;
58645 +#endif
58646 +
58647 eppnt = elf_phdata;
58648 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58649 if (eppnt->p_type == PT_LOAD) {
58650 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58651 map_addr = elf_map(interpreter, load_addr + vaddr,
58652 eppnt, elf_prot, elf_type, total_size);
58653 total_size = 0;
58654 - if (!*interp_map_addr)
58655 - *interp_map_addr = map_addr;
58656 error = map_addr;
58657 if (BAD_ADDR(map_addr))
58658 goto out_close;
58659 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58660 k = load_addr + eppnt->p_vaddr;
58661 if (BAD_ADDR(k) ||
58662 eppnt->p_filesz > eppnt->p_memsz ||
58663 - eppnt->p_memsz > TASK_SIZE ||
58664 - TASK_SIZE - eppnt->p_memsz < k) {
58665 + eppnt->p_memsz > pax_task_size ||
58666 + pax_task_size - eppnt->p_memsz < k) {
58667 error = -ENOMEM;
58668 goto out_close;
58669 }
58670 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58671 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58672
58673 /* Map the last of the bss segment */
58674 - error = vm_brk(elf_bss, last_bss - elf_bss);
58675 - if (BAD_ADDR(error))
58676 - goto out_close;
58677 + if (last_bss > elf_bss) {
58678 + error = vm_brk(elf_bss, last_bss - elf_bss);
58679 + if (BAD_ADDR(error))
58680 + goto out_close;
58681 + }
58682 }
58683
58684 error = load_addr;
58685 @@ -543,6 +574,336 @@ out:
58686 return error;
58687 }
58688
58689 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58690 +#ifdef CONFIG_PAX_SOFTMODE
58691 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58692 +{
58693 + unsigned long pax_flags = 0UL;
58694 +
58695 +#ifdef CONFIG_PAX_PAGEEXEC
58696 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58697 + pax_flags |= MF_PAX_PAGEEXEC;
58698 +#endif
58699 +
58700 +#ifdef CONFIG_PAX_SEGMEXEC
58701 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58702 + pax_flags |= MF_PAX_SEGMEXEC;
58703 +#endif
58704 +
58705 +#ifdef CONFIG_PAX_EMUTRAMP
58706 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58707 + pax_flags |= MF_PAX_EMUTRAMP;
58708 +#endif
58709 +
58710 +#ifdef CONFIG_PAX_MPROTECT
58711 + if (elf_phdata->p_flags & PF_MPROTECT)
58712 + pax_flags |= MF_PAX_MPROTECT;
58713 +#endif
58714 +
58715 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58716 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58717 + pax_flags |= MF_PAX_RANDMMAP;
58718 +#endif
58719 +
58720 + return pax_flags;
58721 +}
58722 +#endif
58723 +
58724 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58725 +{
58726 + unsigned long pax_flags = 0UL;
58727 +
58728 +#ifdef CONFIG_PAX_PAGEEXEC
58729 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58730 + pax_flags |= MF_PAX_PAGEEXEC;
58731 +#endif
58732 +
58733 +#ifdef CONFIG_PAX_SEGMEXEC
58734 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58735 + pax_flags |= MF_PAX_SEGMEXEC;
58736 +#endif
58737 +
58738 +#ifdef CONFIG_PAX_EMUTRAMP
58739 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58740 + pax_flags |= MF_PAX_EMUTRAMP;
58741 +#endif
58742 +
58743 +#ifdef CONFIG_PAX_MPROTECT
58744 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58745 + pax_flags |= MF_PAX_MPROTECT;
58746 +#endif
58747 +
58748 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58749 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58750 + pax_flags |= MF_PAX_RANDMMAP;
58751 +#endif
58752 +
58753 + return pax_flags;
58754 +}
58755 +#endif
58756 +
58757 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58758 +#ifdef CONFIG_PAX_SOFTMODE
58759 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58760 +{
58761 + unsigned long pax_flags = 0UL;
58762 +
58763 +#ifdef CONFIG_PAX_PAGEEXEC
58764 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58765 + pax_flags |= MF_PAX_PAGEEXEC;
58766 +#endif
58767 +
58768 +#ifdef CONFIG_PAX_SEGMEXEC
58769 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58770 + pax_flags |= MF_PAX_SEGMEXEC;
58771 +#endif
58772 +
58773 +#ifdef CONFIG_PAX_EMUTRAMP
58774 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58775 + pax_flags |= MF_PAX_EMUTRAMP;
58776 +#endif
58777 +
58778 +#ifdef CONFIG_PAX_MPROTECT
58779 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58780 + pax_flags |= MF_PAX_MPROTECT;
58781 +#endif
58782 +
58783 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58784 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58785 + pax_flags |= MF_PAX_RANDMMAP;
58786 +#endif
58787 +
58788 + return pax_flags;
58789 +}
58790 +#endif
58791 +
58792 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58793 +{
58794 + unsigned long pax_flags = 0UL;
58795 +
58796 +#ifdef CONFIG_PAX_PAGEEXEC
58797 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58798 + pax_flags |= MF_PAX_PAGEEXEC;
58799 +#endif
58800 +
58801 +#ifdef CONFIG_PAX_SEGMEXEC
58802 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58803 + pax_flags |= MF_PAX_SEGMEXEC;
58804 +#endif
58805 +
58806 +#ifdef CONFIG_PAX_EMUTRAMP
58807 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58808 + pax_flags |= MF_PAX_EMUTRAMP;
58809 +#endif
58810 +
58811 +#ifdef CONFIG_PAX_MPROTECT
58812 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58813 + pax_flags |= MF_PAX_MPROTECT;
58814 +#endif
58815 +
58816 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58817 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58818 + pax_flags |= MF_PAX_RANDMMAP;
58819 +#endif
58820 +
58821 + return pax_flags;
58822 +}
58823 +#endif
58824 +
58825 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58826 +static unsigned long pax_parse_defaults(void)
58827 +{
58828 + unsigned long pax_flags = 0UL;
58829 +
58830 +#ifdef CONFIG_PAX_SOFTMODE
58831 + if (pax_softmode)
58832 + return pax_flags;
58833 +#endif
58834 +
58835 +#ifdef CONFIG_PAX_PAGEEXEC
58836 + pax_flags |= MF_PAX_PAGEEXEC;
58837 +#endif
58838 +
58839 +#ifdef CONFIG_PAX_SEGMEXEC
58840 + pax_flags |= MF_PAX_SEGMEXEC;
58841 +#endif
58842 +
58843 +#ifdef CONFIG_PAX_MPROTECT
58844 + pax_flags |= MF_PAX_MPROTECT;
58845 +#endif
58846 +
58847 +#ifdef CONFIG_PAX_RANDMMAP
58848 + if (randomize_va_space)
58849 + pax_flags |= MF_PAX_RANDMMAP;
58850 +#endif
58851 +
58852 + return pax_flags;
58853 +}
58854 +
58855 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58856 +{
58857 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58858 +
58859 +#ifdef CONFIG_PAX_EI_PAX
58860 +
58861 +#ifdef CONFIG_PAX_SOFTMODE
58862 + if (pax_softmode)
58863 + return pax_flags;
58864 +#endif
58865 +
58866 + pax_flags = 0UL;
58867 +
58868 +#ifdef CONFIG_PAX_PAGEEXEC
58869 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58870 + pax_flags |= MF_PAX_PAGEEXEC;
58871 +#endif
58872 +
58873 +#ifdef CONFIG_PAX_SEGMEXEC
58874 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58875 + pax_flags |= MF_PAX_SEGMEXEC;
58876 +#endif
58877 +
58878 +#ifdef CONFIG_PAX_EMUTRAMP
58879 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58880 + pax_flags |= MF_PAX_EMUTRAMP;
58881 +#endif
58882 +
58883 +#ifdef CONFIG_PAX_MPROTECT
58884 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58885 + pax_flags |= MF_PAX_MPROTECT;
58886 +#endif
58887 +
58888 +#ifdef CONFIG_PAX_ASLR
58889 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58890 + pax_flags |= MF_PAX_RANDMMAP;
58891 +#endif
58892 +
58893 +#endif
58894 +
58895 + return pax_flags;
58896 +
58897 +}
58898 +
58899 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58900 +{
58901 +
58902 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58903 + unsigned long i;
58904 +
58905 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58906 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58907 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58908 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58909 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58910 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58911 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58912 + return PAX_PARSE_FLAGS_FALLBACK;
58913 +
58914 +#ifdef CONFIG_PAX_SOFTMODE
58915 + if (pax_softmode)
58916 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58917 + else
58918 +#endif
58919 +
58920 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58921 + break;
58922 + }
58923 +#endif
58924 +
58925 + return PAX_PARSE_FLAGS_FALLBACK;
58926 +}
58927 +
58928 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58929 +{
58930 +
58931 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58932 + ssize_t xattr_size, i;
58933 + unsigned char xattr_value[sizeof("pemrs") - 1];
58934 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58935 +
58936 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58937 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58938 + return PAX_PARSE_FLAGS_FALLBACK;
58939 +
58940 + for (i = 0; i < xattr_size; i++)
58941 + switch (xattr_value[i]) {
58942 + default:
58943 + return PAX_PARSE_FLAGS_FALLBACK;
58944 +
58945 +#define parse_flag(option1, option2, flag) \
58946 + case option1: \
58947 + if (pax_flags_hardmode & MF_PAX_##flag) \
58948 + return PAX_PARSE_FLAGS_FALLBACK;\
58949 + pax_flags_hardmode |= MF_PAX_##flag; \
58950 + break; \
58951 + case option2: \
58952 + if (pax_flags_softmode & MF_PAX_##flag) \
58953 + return PAX_PARSE_FLAGS_FALLBACK;\
58954 + pax_flags_softmode |= MF_PAX_##flag; \
58955 + break;
58956 +
58957 + parse_flag('p', 'P', PAGEEXEC);
58958 + parse_flag('e', 'E', EMUTRAMP);
58959 + parse_flag('m', 'M', MPROTECT);
58960 + parse_flag('r', 'R', RANDMMAP);
58961 + parse_flag('s', 'S', SEGMEXEC);
58962 +
58963 +#undef parse_flag
58964 + }
58965 +
58966 + if (pax_flags_hardmode & pax_flags_softmode)
58967 + return PAX_PARSE_FLAGS_FALLBACK;
58968 +
58969 +#ifdef CONFIG_PAX_SOFTMODE
58970 + if (pax_softmode)
58971 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
58972 + else
58973 +#endif
58974 +
58975 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
58976 +#else
58977 + return PAX_PARSE_FLAGS_FALLBACK;
58978 +#endif
58979 +
58980 +}
58981 +
58982 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
58983 +{
58984 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
58985 +
58986 + pax_flags = pax_parse_defaults();
58987 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
58988 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
58989 + xattr_pax_flags = pax_parse_xattr_pax(file);
58990 +
58991 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58992 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58993 + pt_pax_flags != xattr_pax_flags)
58994 + return -EINVAL;
58995 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58996 + pax_flags = xattr_pax_flags;
58997 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58998 + pax_flags = pt_pax_flags;
58999 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59000 + pax_flags = ei_pax_flags;
59001 +
59002 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59003 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59004 + if ((__supported_pte_mask & _PAGE_NX))
59005 + pax_flags &= ~MF_PAX_SEGMEXEC;
59006 + else
59007 + pax_flags &= ~MF_PAX_PAGEEXEC;
59008 + }
59009 +#endif
59010 +
59011 + if (0 > pax_check_flags(&pax_flags))
59012 + return -EINVAL;
59013 +
59014 + current->mm->pax_flags = pax_flags;
59015 + return 0;
59016 +}
59017 +#endif
59018 +
59019 /*
59020 * These are the functions used to load ELF style executables and shared
59021 * libraries. There is no binary dependent code anywhere else.
59022 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59023 {
59024 unsigned int random_variable = 0;
59025
59026 +#ifdef CONFIG_PAX_RANDUSTACK
59027 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59028 + return stack_top - current->mm->delta_stack;
59029 +#endif
59030 +
59031 if ((current->flags & PF_RANDOMIZE) &&
59032 !(current->personality & ADDR_NO_RANDOMIZE)) {
59033 random_variable = get_random_int() & STACK_RND_MASK;
59034 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59035 unsigned long load_addr = 0, load_bias = 0;
59036 int load_addr_set = 0;
59037 char * elf_interpreter = NULL;
59038 - unsigned long error;
59039 + unsigned long error = 0;
59040 struct elf_phdr *elf_ppnt, *elf_phdata;
59041 unsigned long elf_bss, elf_brk;
59042 int retval, i;
59043 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59044 struct elfhdr elf_ex;
59045 struct elfhdr interp_elf_ex;
59046 } *loc;
59047 + unsigned long pax_task_size;
59048
59049 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59050 if (!loc) {
59051 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59052 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59053 may depend on the personality. */
59054 SET_PERSONALITY(loc->elf_ex);
59055 +
59056 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59057 + current->mm->pax_flags = 0UL;
59058 +#endif
59059 +
59060 +#ifdef CONFIG_PAX_DLRESOLVE
59061 + current->mm->call_dl_resolve = 0UL;
59062 +#endif
59063 +
59064 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59065 + current->mm->call_syscall = 0UL;
59066 +#endif
59067 +
59068 +#ifdef CONFIG_PAX_ASLR
59069 + current->mm->delta_mmap = 0UL;
59070 + current->mm->delta_stack = 0UL;
59071 +#endif
59072 +
59073 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59074 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59075 + send_sig(SIGKILL, current, 0);
59076 + goto out_free_dentry;
59077 + }
59078 +#endif
59079 +
59080 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59081 + pax_set_initial_flags(bprm);
59082 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59083 + if (pax_set_initial_flags_func)
59084 + (pax_set_initial_flags_func)(bprm);
59085 +#endif
59086 +
59087 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59088 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59089 + current->mm->context.user_cs_limit = PAGE_SIZE;
59090 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59091 + }
59092 +#endif
59093 +
59094 +#ifdef CONFIG_PAX_SEGMEXEC
59095 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59096 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59097 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59098 + pax_task_size = SEGMEXEC_TASK_SIZE;
59099 + current->mm->def_flags |= VM_NOHUGEPAGE;
59100 + } else
59101 +#endif
59102 +
59103 + pax_task_size = TASK_SIZE;
59104 +
59105 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59106 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59107 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59108 + put_cpu();
59109 + }
59110 +#endif
59111 +
59112 +#ifdef CONFIG_PAX_ASLR
59113 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59114 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59115 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59116 + }
59117 +#endif
59118 +
59119 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59120 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59121 + executable_stack = EXSTACK_DISABLE_X;
59122 + current->personality &= ~READ_IMPLIES_EXEC;
59123 + } else
59124 +#endif
59125 +
59126 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59127 current->personality |= READ_IMPLIES_EXEC;
59128
59129 @@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59130 #else
59131 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59132 #endif
59133 +
59134 +#ifdef CONFIG_PAX_RANDMMAP
59135 + /* PaX: randomize base address at the default exe base if requested */
59136 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59137 +#ifdef CONFIG_SPARC64
59138 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59139 +#else
59140 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59141 +#endif
59142 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59143 + elf_flags |= MAP_FIXED;
59144 + }
59145 +#endif
59146 +
59147 }
59148
59149 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59150 @@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59151 * allowed task size. Note that p_filesz must always be
59152 * <= p_memsz so it is only necessary to check p_memsz.
59153 */
59154 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59155 - elf_ppnt->p_memsz > TASK_SIZE ||
59156 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59157 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59158 + elf_ppnt->p_memsz > pax_task_size ||
59159 + pax_task_size - elf_ppnt->p_memsz < k) {
59160 /* set_brk can never work. Avoid overflows. */
59161 retval = -EINVAL;
59162 goto out_free_dentry;
59163 @@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
59164 if (retval)
59165 goto out_free_dentry;
59166 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59167 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59168 - goto out_free_dentry;
59169 + /*
59170 + * This bss-zeroing can fail if the ELF
59171 + * file specifies odd protections. So
59172 + * we don't check the return value
59173 + */
59174 }
59175
59176 +#ifdef CONFIG_PAX_RANDMMAP
59177 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59178 + unsigned long start, size, flags;
59179 + vm_flags_t vm_flags;
59180 +
59181 + start = ELF_PAGEALIGN(elf_brk);
59182 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59183 + flags = MAP_FIXED | MAP_PRIVATE;
59184 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59185 +
59186 + down_write(&current->mm->mmap_sem);
59187 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59188 + retval = -ENOMEM;
59189 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59190 +// if (current->personality & ADDR_NO_RANDOMIZE)
59191 +// vm_flags |= VM_READ | VM_MAYREAD;
59192 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59193 + retval = IS_ERR_VALUE(start) ? start : 0;
59194 + }
59195 + up_write(&current->mm->mmap_sem);
59196 + if (retval == 0)
59197 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59198 + if (retval < 0)
59199 + goto out_free_dentry;
59200 + }
59201 +#endif
59202 +
59203 if (elf_interpreter) {
59204 - unsigned long interp_map_addr = 0;
59205 -
59206 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59207 interpreter,
59208 - &interp_map_addr,
59209 load_bias);
59210 if (!IS_ERR((void *)elf_entry)) {
59211 /*
59212 @@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59213 * Decide what to dump of a segment, part, all or none.
59214 */
59215 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59216 - unsigned long mm_flags)
59217 + unsigned long mm_flags, long signr)
59218 {
59219 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59220
59221 @@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59222 if (vma->vm_file == NULL)
59223 return 0;
59224
59225 - if (FILTER(MAPPED_PRIVATE))
59226 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59227 goto whole;
59228
59229 /*
59230 @@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59231 {
59232 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59233 int i = 0;
59234 - do
59235 + do {
59236 i += 2;
59237 - while (auxv[i - 2] != AT_NULL);
59238 + } while (auxv[i - 2] != AT_NULL);
59239 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59240 }
59241
59242 @@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59243 {
59244 mm_segment_t old_fs = get_fs();
59245 set_fs(KERNEL_DS);
59246 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59247 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59248 set_fs(old_fs);
59249 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59250 }
59251 @@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59252 }
59253
59254 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59255 - unsigned long mm_flags)
59256 + struct coredump_params *cprm)
59257 {
59258 struct vm_area_struct *vma;
59259 size_t size = 0;
59260
59261 for (vma = first_vma(current, gate_vma); vma != NULL;
59262 vma = next_vma(vma, gate_vma))
59263 - size += vma_dump_size(vma, mm_flags);
59264 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59265 return size;
59266 }
59267
59268 @@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59269
59270 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59271
59272 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59273 + offset += elf_core_vma_data_size(gate_vma, cprm);
59274 offset += elf_core_extra_data_size();
59275 e_shoff = offset;
59276
59277 @@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59278 phdr.p_offset = offset;
59279 phdr.p_vaddr = vma->vm_start;
59280 phdr.p_paddr = 0;
59281 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59282 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59283 phdr.p_memsz = vma->vm_end - vma->vm_start;
59284 offset += phdr.p_filesz;
59285 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59286 @@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59287 unsigned long addr;
59288 unsigned long end;
59289
59290 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59291 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59292
59293 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59294 struct page *page;
59295 @@ -2195,6 +2674,167 @@ out:
59296
59297 #endif /* CONFIG_ELF_CORE */
59298
59299 +#ifdef CONFIG_PAX_MPROTECT
59300 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59301 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59302 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59303 + *
59304 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59305 + * basis because we want to allow the common case and not the special ones.
59306 + */
59307 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59308 +{
59309 + struct elfhdr elf_h;
59310 + struct elf_phdr elf_p;
59311 + unsigned long i;
59312 + unsigned long oldflags;
59313 + bool is_textrel_rw, is_textrel_rx, is_relro;
59314 +
59315 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59316 + return;
59317 +
59318 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59319 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59320 +
59321 +#ifdef CONFIG_PAX_ELFRELOCS
59322 + /* possible TEXTREL */
59323 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59324 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59325 +#else
59326 + is_textrel_rw = false;
59327 + is_textrel_rx = false;
59328 +#endif
59329 +
59330 + /* possible RELRO */
59331 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59332 +
59333 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59334 + return;
59335 +
59336 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59337 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59338 +
59339 +#ifdef CONFIG_PAX_ETEXECRELOCS
59340 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59341 +#else
59342 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59343 +#endif
59344 +
59345 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59346 + !elf_check_arch(&elf_h) ||
59347 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59348 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59349 + return;
59350 +
59351 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59352 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59353 + return;
59354 + switch (elf_p.p_type) {
59355 + case PT_DYNAMIC:
59356 + if (!is_textrel_rw && !is_textrel_rx)
59357 + continue;
59358 + i = 0UL;
59359 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59360 + elf_dyn dyn;
59361 +
59362 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59363 + break;
59364 + if (dyn.d_tag == DT_NULL)
59365 + break;
59366 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59367 + gr_log_textrel(vma);
59368 + if (is_textrel_rw)
59369 + vma->vm_flags |= VM_MAYWRITE;
59370 + else
59371 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59372 + vma->vm_flags &= ~VM_MAYWRITE;
59373 + break;
59374 + }
59375 + i++;
59376 + }
59377 + is_textrel_rw = false;
59378 + is_textrel_rx = false;
59379 + continue;
59380 +
59381 + case PT_GNU_RELRO:
59382 + if (!is_relro)
59383 + continue;
59384 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59385 + vma->vm_flags &= ~VM_MAYWRITE;
59386 + is_relro = false;
59387 + continue;
59388 +
59389 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59390 + case PT_PAX_FLAGS: {
59391 + const char *msg_mprotect = "", *msg_emutramp = "";
59392 + char *buffer_lib, *buffer_exe;
59393 +
59394 + if (elf_p.p_flags & PF_NOMPROTECT)
59395 + msg_mprotect = "MPROTECT disabled";
59396 +
59397 +#ifdef CONFIG_PAX_EMUTRAMP
59398 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59399 + msg_emutramp = "EMUTRAMP enabled";
59400 +#endif
59401 +
59402 + if (!msg_mprotect[0] && !msg_emutramp[0])
59403 + continue;
59404 +
59405 + if (!printk_ratelimit())
59406 + continue;
59407 +
59408 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59409 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59410 + if (buffer_lib && buffer_exe) {
59411 + char *path_lib, *path_exe;
59412 +
59413 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59414 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59415 +
59416 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59417 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59418 +
59419 + }
59420 + free_page((unsigned long)buffer_exe);
59421 + free_page((unsigned long)buffer_lib);
59422 + continue;
59423 + }
59424 +#endif
59425 +
59426 + }
59427 + }
59428 +}
59429 +#endif
59430 +
59431 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59432 +
59433 +extern int grsec_enable_log_rwxmaps;
59434 +
59435 +static void elf_handle_mmap(struct file *file)
59436 +{
59437 + struct elfhdr elf_h;
59438 + struct elf_phdr elf_p;
59439 + unsigned long i;
59440 +
59441 + if (!grsec_enable_log_rwxmaps)
59442 + return;
59443 +
59444 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59445 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59446 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59447 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59448 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59449 + return;
59450 +
59451 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59452 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59453 + return;
59454 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59455 + gr_log_ptgnustack(file);
59456 + }
59457 +}
59458 +#endif
59459 +
59460 static int __init init_elf_binfmt(void)
59461 {
59462 register_binfmt(&elf_format);
59463 diff --git a/fs/block_dev.c b/fs/block_dev.c
59464 index 1d9c9f3..2905786 100644
59465 --- a/fs/block_dev.c
59466 +++ b/fs/block_dev.c
59467 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59468 else if (bdev->bd_contains == bdev)
59469 return true; /* is a whole device which isn't held */
59470
59471 - else if (whole->bd_holder == bd_may_claim)
59472 + else if (whole->bd_holder == (void *)bd_may_claim)
59473 return true; /* is a partition of a device that is being partitioned */
59474 else if (whole->bd_holder != NULL)
59475 return false; /* is a partition of a held device */
59476 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59477 index 150822e..75bb326 100644
59478 --- a/fs/btrfs/ctree.c
59479 +++ b/fs/btrfs/ctree.c
59480 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59481 free_extent_buffer(buf);
59482 add_root_to_dirty_list(root);
59483 } else {
59484 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59485 - parent_start = parent->start;
59486 - else
59487 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59488 + if (parent)
59489 + parent_start = parent->start;
59490 + else
59491 + parent_start = 0;
59492 + } else
59493 parent_start = 0;
59494
59495 WARN_ON(trans->transid != btrfs_header_generation(parent));
59496 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59497 index de4e70f..b41dc45 100644
59498 --- a/fs/btrfs/delayed-inode.c
59499 +++ b/fs/btrfs/delayed-inode.c
59500 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59501
59502 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59503 {
59504 - int seq = atomic_inc_return(&delayed_root->items_seq);
59505 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59506 if ((atomic_dec_return(&delayed_root->items) <
59507 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59508 waitqueue_active(&delayed_root->wait))
59509 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59510
59511 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59512 {
59513 - int val = atomic_read(&delayed_root->items_seq);
59514 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59515
59516 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59517 return 1;
59518 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59519 int seq;
59520 int ret;
59521
59522 - seq = atomic_read(&delayed_root->items_seq);
59523 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59524
59525 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59526 if (ret)
59527 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59528 index f70119f..ab5894d 100644
59529 --- a/fs/btrfs/delayed-inode.h
59530 +++ b/fs/btrfs/delayed-inode.h
59531 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59532 */
59533 struct list_head prepare_list;
59534 atomic_t items; /* for delayed items */
59535 - atomic_t items_seq; /* for delayed items */
59536 + atomic_unchecked_t items_seq; /* for delayed items */
59537 int nodes; /* for delayed nodes */
59538 wait_queue_head_t wait;
59539 };
59540 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59541 struct btrfs_delayed_root *delayed_root)
59542 {
59543 atomic_set(&delayed_root->items, 0);
59544 - atomic_set(&delayed_root->items_seq, 0);
59545 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59546 delayed_root->nodes = 0;
59547 spin_lock_init(&delayed_root->lock);
59548 init_waitqueue_head(&delayed_root->wait);
59549 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59550 index 4399f0c..a34d8b4 100644
59551 --- a/fs/btrfs/ioctl.c
59552 +++ b/fs/btrfs/ioctl.c
59553 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59554 for (i = 0; i < num_types; i++) {
59555 struct btrfs_space_info *tmp;
59556
59557 + /* Don't copy in more than we allocated */
59558 if (!slot_count)
59559 break;
59560
59561 + slot_count--;
59562 +
59563 info = NULL;
59564 rcu_read_lock();
59565 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59566 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59567 memcpy(dest, &space, sizeof(space));
59568 dest++;
59569 space_args.total_spaces++;
59570 - slot_count--;
59571 }
59572 - if (!slot_count)
59573 - break;
59574 }
59575 up_read(&info->groups_sem);
59576 }
59577 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59578 index cde9c03..ad4d4db 100644
59579 --- a/fs/btrfs/super.c
59580 +++ b/fs/btrfs/super.c
59581 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59582 function, line, errstr);
59583 return;
59584 }
59585 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59586 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59587 /* Wake up anybody who may be waiting on this transaction */
59588 wake_up(&root->fs_info->transaction_wait);
59589 wake_up(&root->fs_info->transaction_blocked_wait);
59590 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59591 index b2e7bb4..3719201 100644
59592 --- a/fs/btrfs/sysfs.c
59593 +++ b/fs/btrfs/sysfs.c
59594 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59595 for (set = 0; set < FEAT_MAX; set++) {
59596 int i;
59597 struct attribute *attrs[2];
59598 - struct attribute_group agroup = {
59599 + attribute_group_no_const agroup = {
59600 .name = "features",
59601 .attrs = attrs,
59602 };
59603 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59604 index 2299bfd..4098e72 100644
59605 --- a/fs/btrfs/tests/free-space-tests.c
59606 +++ b/fs/btrfs/tests/free-space-tests.c
59607 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59608 * extent entry.
59609 */
59610 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59611 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59612 + pax_open_kernel();
59613 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59614 + pax_close_kernel();
59615
59616 /*
59617 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59618 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59619 if (ret)
59620 return ret;
59621
59622 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59623 + pax_open_kernel();
59624 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59625 + pax_close_kernel();
59626 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59627
59628 return 0;
59629 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59630 index 154990c..d0cf699 100644
59631 --- a/fs/btrfs/tree-log.h
59632 +++ b/fs/btrfs/tree-log.h
59633 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59634 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59635 struct btrfs_trans_handle *trans)
59636 {
59637 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59638 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59639 }
59640
59641 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59642 diff --git a/fs/buffer.c b/fs/buffer.c
59643 index 20805db..2e8fc69 100644
59644 --- a/fs/buffer.c
59645 +++ b/fs/buffer.c
59646 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59647 bh_cachep = kmem_cache_create("buffer_head",
59648 sizeof(struct buffer_head), 0,
59649 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59650 - SLAB_MEM_SPREAD),
59651 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59652 NULL);
59653
59654 /*
59655 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59656 index fbb08e9..0fda764 100644
59657 --- a/fs/cachefiles/bind.c
59658 +++ b/fs/cachefiles/bind.c
59659 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59660 args);
59661
59662 /* start by checking things over */
59663 - ASSERT(cache->fstop_percent >= 0 &&
59664 - cache->fstop_percent < cache->fcull_percent &&
59665 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59666 cache->fcull_percent < cache->frun_percent &&
59667 cache->frun_percent < 100);
59668
59669 - ASSERT(cache->bstop_percent >= 0 &&
59670 - cache->bstop_percent < cache->bcull_percent &&
59671 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59672 cache->bcull_percent < cache->brun_percent &&
59673 cache->brun_percent < 100);
59674
59675 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59676 index ce1b115..4a6852c 100644
59677 --- a/fs/cachefiles/daemon.c
59678 +++ b/fs/cachefiles/daemon.c
59679 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59680 if (n > buflen)
59681 return -EMSGSIZE;
59682
59683 - if (copy_to_user(_buffer, buffer, n) != 0)
59684 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59685 return -EFAULT;
59686
59687 return n;
59688 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59689 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59690 return -EIO;
59691
59692 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59693 + if (datalen > PAGE_SIZE - 1)
59694 return -EOPNOTSUPP;
59695
59696 /* drag the command string into the kernel so we can parse it */
59697 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59698 if (args[0] != '%' || args[1] != '\0')
59699 return -EINVAL;
59700
59701 - if (fstop < 0 || fstop >= cache->fcull_percent)
59702 + if (fstop >= cache->fcull_percent)
59703 return cachefiles_daemon_range_error(cache, args);
59704
59705 cache->fstop_percent = fstop;
59706 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59707 if (args[0] != '%' || args[1] != '\0')
59708 return -EINVAL;
59709
59710 - if (bstop < 0 || bstop >= cache->bcull_percent)
59711 + if (bstop >= cache->bcull_percent)
59712 return cachefiles_daemon_range_error(cache, args);
59713
59714 cache->bstop_percent = bstop;
59715 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59716 index 8c52472..c4e3a69 100644
59717 --- a/fs/cachefiles/internal.h
59718 +++ b/fs/cachefiles/internal.h
59719 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59720 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59721 struct rb_root active_nodes; /* active nodes (can't be culled) */
59722 rwlock_t active_lock; /* lock for active_nodes */
59723 - atomic_t gravecounter; /* graveyard uniquifier */
59724 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59725 unsigned frun_percent; /* when to stop culling (% files) */
59726 unsigned fcull_percent; /* when to start culling (% files) */
59727 unsigned fstop_percent; /* when to stop allocating (% files) */
59728 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59729 * proc.c
59730 */
59731 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59732 -extern atomic_t cachefiles_lookup_histogram[HZ];
59733 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59734 -extern atomic_t cachefiles_create_histogram[HZ];
59735 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59736 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59737 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59738
59739 extern int __init cachefiles_proc_init(void);
59740 extern void cachefiles_proc_cleanup(void);
59741 static inline
59742 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59743 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59744 {
59745 unsigned long jif = jiffies - start_jif;
59746 if (jif >= HZ)
59747 jif = HZ - 1;
59748 - atomic_inc(&histogram[jif]);
59749 + atomic_inc_unchecked(&histogram[jif]);
59750 }
59751
59752 #else
59753 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59754 index e12f189..ed17244 100644
59755 --- a/fs/cachefiles/namei.c
59756 +++ b/fs/cachefiles/namei.c
59757 @@ -312,7 +312,7 @@ try_again:
59758 /* first step is to make up a grave dentry in the graveyard */
59759 sprintf(nbuffer, "%08x%08x",
59760 (uint32_t) get_seconds(),
59761 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59762 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59763
59764 /* do the multiway lock magic */
59765 trap = lock_rename(cache->graveyard, dir);
59766 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59767 index eccd339..4c1d995 100644
59768 --- a/fs/cachefiles/proc.c
59769 +++ b/fs/cachefiles/proc.c
59770 @@ -14,9 +14,9 @@
59771 #include <linux/seq_file.h>
59772 #include "internal.h"
59773
59774 -atomic_t cachefiles_lookup_histogram[HZ];
59775 -atomic_t cachefiles_mkdir_histogram[HZ];
59776 -atomic_t cachefiles_create_histogram[HZ];
59777 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59778 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59779 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59780
59781 /*
59782 * display the latency histogram
59783 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59784 return 0;
59785 default:
59786 index = (unsigned long) v - 3;
59787 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59788 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59789 - z = atomic_read(&cachefiles_create_histogram[index]);
59790 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59791 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59792 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59793 if (x == 0 && y == 0 && z == 0)
59794 return 0;
59795
59796 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59797 index 695e788..f4a9d4d 100644
59798 --- a/fs/ceph/dir.c
59799 +++ b/fs/ceph/dir.c
59800 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59801 struct dentry *dentry, *last;
59802 struct ceph_dentry_info *di;
59803 int err = 0;
59804 + char d_name[DNAME_INLINE_LEN];
59805 + const unsigned char *name;
59806
59807 /* claim ref on last dentry we returned */
59808 last = fi->dentry;
59809 @@ -192,7 +194,12 @@ more:
59810
59811 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59812 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59813 - if (!dir_emit(ctx, dentry->d_name.name,
59814 + name = dentry->d_name.name;
59815 + if (name == dentry->d_iname) {
59816 + memcpy(d_name, name, dentry->d_name.len);
59817 + name = d_name;
59818 + }
59819 + if (!dir_emit(ctx, name,
59820 dentry->d_name.len,
59821 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59822 dentry->d_inode->i_mode >> 12)) {
59823 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59824 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59825 struct ceph_mds_client *mdsc = fsc->mdsc;
59826 unsigned frag = fpos_frag(ctx->pos);
59827 - int off = fpos_off(ctx->pos);
59828 + unsigned int off = fpos_off(ctx->pos);
59829 int err;
59830 u32 ftype;
59831 struct ceph_mds_reply_info_parsed *rinfo;
59832 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59833 index f6e1237..796ffd1 100644
59834 --- a/fs/ceph/super.c
59835 +++ b/fs/ceph/super.c
59836 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59837 /*
59838 * construct our own bdi so we can control readahead, etc.
59839 */
59840 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59841 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59842
59843 static int ceph_register_bdi(struct super_block *sb,
59844 struct ceph_fs_client *fsc)
59845 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59846 default_backing_dev_info.ra_pages;
59847
59848 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59849 - atomic_long_inc_return(&bdi_seq));
59850 + atomic_long_inc_return_unchecked(&bdi_seq));
59851 if (!err)
59852 sb->s_bdi = &fsc->backing_dev_info;
59853 return err;
59854 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59855 index 44ec726..bcb06a3 100644
59856 --- a/fs/cifs/cifs_debug.c
59857 +++ b/fs/cifs/cifs_debug.c
59858 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59859
59860 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59861 #ifdef CONFIG_CIFS_STATS2
59862 - atomic_set(&totBufAllocCount, 0);
59863 - atomic_set(&totSmBufAllocCount, 0);
59864 + atomic_set_unchecked(&totBufAllocCount, 0);
59865 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59866 #endif /* CONFIG_CIFS_STATS2 */
59867 spin_lock(&cifs_tcp_ses_lock);
59868 list_for_each(tmp1, &cifs_tcp_ses_list) {
59869 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59870 tcon = list_entry(tmp3,
59871 struct cifs_tcon,
59872 tcon_list);
59873 - atomic_set(&tcon->num_smbs_sent, 0);
59874 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59875 if (server->ops->clear_stats)
59876 server->ops->clear_stats(tcon);
59877 }
59878 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59879 smBufAllocCount.counter, cifs_min_small);
59880 #ifdef CONFIG_CIFS_STATS2
59881 seq_printf(m, "Total Large %d Small %d Allocations\n",
59882 - atomic_read(&totBufAllocCount),
59883 - atomic_read(&totSmBufAllocCount));
59884 + atomic_read_unchecked(&totBufAllocCount),
59885 + atomic_read_unchecked(&totSmBufAllocCount));
59886 #endif /* CONFIG_CIFS_STATS2 */
59887
59888 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59889 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59890 if (tcon->need_reconnect)
59891 seq_puts(m, "\tDISCONNECTED ");
59892 seq_printf(m, "\nSMBs: %d",
59893 - atomic_read(&tcon->num_smbs_sent));
59894 + atomic_read_unchecked(&tcon->num_smbs_sent));
59895 if (server->ops->print_stats)
59896 server->ops->print_stats(m, tcon);
59897 }
59898 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59899 index 9d7996e..35ad5cf4 100644
59900 --- a/fs/cifs/cifsfs.c
59901 +++ b/fs/cifs/cifsfs.c
59902 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59903 */
59904 cifs_req_cachep = kmem_cache_create("cifs_request",
59905 CIFSMaxBufSize + max_hdr_size, 0,
59906 - SLAB_HWCACHE_ALIGN, NULL);
59907 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59908 if (cifs_req_cachep == NULL)
59909 return -ENOMEM;
59910
59911 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59912 efficient to alloc 1 per page off the slab compared to 17K (5page)
59913 alloc of large cifs buffers even when page debugging is on */
59914 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59915 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59916 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59917 NULL);
59918 if (cifs_sm_req_cachep == NULL) {
59919 mempool_destroy(cifs_req_poolp);
59920 @@ -1205,8 +1205,8 @@ init_cifs(void)
59921 atomic_set(&bufAllocCount, 0);
59922 atomic_set(&smBufAllocCount, 0);
59923 #ifdef CONFIG_CIFS_STATS2
59924 - atomic_set(&totBufAllocCount, 0);
59925 - atomic_set(&totSmBufAllocCount, 0);
59926 + atomic_set_unchecked(&totBufAllocCount, 0);
59927 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59928 #endif /* CONFIG_CIFS_STATS2 */
59929
59930 atomic_set(&midCount, 0);
59931 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59932 index 02a33e5..3a28b5a 100644
59933 --- a/fs/cifs/cifsglob.h
59934 +++ b/fs/cifs/cifsglob.h
59935 @@ -823,35 +823,35 @@ struct cifs_tcon {
59936 __u16 Flags; /* optional support bits */
59937 enum statusEnum tidStatus;
59938 #ifdef CONFIG_CIFS_STATS
59939 - atomic_t num_smbs_sent;
59940 + atomic_unchecked_t num_smbs_sent;
59941 union {
59942 struct {
59943 - atomic_t num_writes;
59944 - atomic_t num_reads;
59945 - atomic_t num_flushes;
59946 - atomic_t num_oplock_brks;
59947 - atomic_t num_opens;
59948 - atomic_t num_closes;
59949 - atomic_t num_deletes;
59950 - atomic_t num_mkdirs;
59951 - atomic_t num_posixopens;
59952 - atomic_t num_posixmkdirs;
59953 - atomic_t num_rmdirs;
59954 - atomic_t num_renames;
59955 - atomic_t num_t2renames;
59956 - atomic_t num_ffirst;
59957 - atomic_t num_fnext;
59958 - atomic_t num_fclose;
59959 - atomic_t num_hardlinks;
59960 - atomic_t num_symlinks;
59961 - atomic_t num_locks;
59962 - atomic_t num_acl_get;
59963 - atomic_t num_acl_set;
59964 + atomic_unchecked_t num_writes;
59965 + atomic_unchecked_t num_reads;
59966 + atomic_unchecked_t num_flushes;
59967 + atomic_unchecked_t num_oplock_brks;
59968 + atomic_unchecked_t num_opens;
59969 + atomic_unchecked_t num_closes;
59970 + atomic_unchecked_t num_deletes;
59971 + atomic_unchecked_t num_mkdirs;
59972 + atomic_unchecked_t num_posixopens;
59973 + atomic_unchecked_t num_posixmkdirs;
59974 + atomic_unchecked_t num_rmdirs;
59975 + atomic_unchecked_t num_renames;
59976 + atomic_unchecked_t num_t2renames;
59977 + atomic_unchecked_t num_ffirst;
59978 + atomic_unchecked_t num_fnext;
59979 + atomic_unchecked_t num_fclose;
59980 + atomic_unchecked_t num_hardlinks;
59981 + atomic_unchecked_t num_symlinks;
59982 + atomic_unchecked_t num_locks;
59983 + atomic_unchecked_t num_acl_get;
59984 + atomic_unchecked_t num_acl_set;
59985 } cifs_stats;
59986 #ifdef CONFIG_CIFS_SMB2
59987 struct {
59988 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59989 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59990 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59991 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59992 } smb2_stats;
59993 #endif /* CONFIG_CIFS_SMB2 */
59994 } stats;
59995 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
59996 }
59997
59998 #ifdef CONFIG_CIFS_STATS
59999 -#define cifs_stats_inc atomic_inc
60000 +#define cifs_stats_inc atomic_inc_unchecked
60001
60002 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60003 unsigned int bytes)
60004 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60005 /* Various Debug counters */
60006 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60007 #ifdef CONFIG_CIFS_STATS2
60008 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60009 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60010 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60011 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60012 #endif
60013 GLOBAL_EXTERN atomic_t smBufAllocCount;
60014 GLOBAL_EXTERN atomic_t midCount;
60015 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60016 index 3e4d00a..38a122d 100644
60017 --- a/fs/cifs/file.c
60018 +++ b/fs/cifs/file.c
60019 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60020 index = mapping->writeback_index; /* Start from prev offset */
60021 end = -1;
60022 } else {
60023 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60024 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60025 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60026 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60027 range_whole = true;
60028 + index = 0;
60029 + end = ULONG_MAX;
60030 + } else {
60031 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60032 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60033 + }
60034 scanned = true;
60035 }
60036 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60037 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60038 index b7415d5..3984ec0 100644
60039 --- a/fs/cifs/misc.c
60040 +++ b/fs/cifs/misc.c
60041 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60042 memset(ret_buf, 0, buf_size + 3);
60043 atomic_inc(&bufAllocCount);
60044 #ifdef CONFIG_CIFS_STATS2
60045 - atomic_inc(&totBufAllocCount);
60046 + atomic_inc_unchecked(&totBufAllocCount);
60047 #endif /* CONFIG_CIFS_STATS2 */
60048 }
60049
60050 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60051 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60052 atomic_inc(&smBufAllocCount);
60053 #ifdef CONFIG_CIFS_STATS2
60054 - atomic_inc(&totSmBufAllocCount);
60055 + atomic_inc_unchecked(&totSmBufAllocCount);
60056 #endif /* CONFIG_CIFS_STATS2 */
60057
60058 }
60059 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60060 index d297903..1cb7516 100644
60061 --- a/fs/cifs/smb1ops.c
60062 +++ b/fs/cifs/smb1ops.c
60063 @@ -622,27 +622,27 @@ static void
60064 cifs_clear_stats(struct cifs_tcon *tcon)
60065 {
60066 #ifdef CONFIG_CIFS_STATS
60067 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60068 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60069 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60070 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60071 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60072 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60073 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60074 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60075 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60076 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60077 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60078 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60079 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60080 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60081 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60082 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60083 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60084 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60085 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60086 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60087 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60088 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60089 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60090 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60091 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60092 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60093 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60094 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60095 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60096 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60097 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60098 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60099 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60100 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60101 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60102 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60103 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60104 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60105 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60106 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60107 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60108 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60109 #endif
60110 }
60111
60112 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60113 {
60114 #ifdef CONFIG_CIFS_STATS
60115 seq_printf(m, " Oplocks breaks: %d",
60116 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60117 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60118 seq_printf(m, "\nReads: %d Bytes: %llu",
60119 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60120 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60121 (long long)(tcon->bytes_read));
60122 seq_printf(m, "\nWrites: %d Bytes: %llu",
60123 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60124 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60125 (long long)(tcon->bytes_written));
60126 seq_printf(m, "\nFlushes: %d",
60127 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60128 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60129 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60130 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60131 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60132 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60133 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60134 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60135 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60136 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60137 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60138 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60139 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60140 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60141 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60142 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60143 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60144 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60145 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60146 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60147 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60148 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60149 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60150 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60151 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60152 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60153 seq_printf(m, "\nRenames: %d T2 Renames %d",
60154 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60155 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60156 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60157 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60158 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60159 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60160 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60161 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60162 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60163 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60164 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60165 #endif
60166 }
60167
60168 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60169 index c5f521b..1a40865 100644
60170 --- a/fs/cifs/smb2ops.c
60171 +++ b/fs/cifs/smb2ops.c
60172 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60173 #ifdef CONFIG_CIFS_STATS
60174 int i;
60175 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60176 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60177 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60178 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60179 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60180 }
60181 #endif
60182 }
60183 @@ -458,65 +458,65 @@ static void
60184 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60185 {
60186 #ifdef CONFIG_CIFS_STATS
60187 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60188 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60189 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60190 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60191 seq_printf(m, "\nNegotiates: %d sent %d failed",
60192 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60193 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60194 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60195 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60196 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60197 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60198 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60199 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60200 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60201 seq_printf(m, "\nLogoffs: %d sent %d failed",
60202 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60203 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60204 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60205 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60206 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60207 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60208 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60209 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60210 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60211 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60212 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60213 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60214 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60215 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60216 seq_printf(m, "\nCreates: %d sent %d failed",
60217 - atomic_read(&sent[SMB2_CREATE_HE]),
60218 - atomic_read(&failed[SMB2_CREATE_HE]));
60219 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60220 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60221 seq_printf(m, "\nCloses: %d sent %d failed",
60222 - atomic_read(&sent[SMB2_CLOSE_HE]),
60223 - atomic_read(&failed[SMB2_CLOSE_HE]));
60224 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60225 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60226 seq_printf(m, "\nFlushes: %d sent %d failed",
60227 - atomic_read(&sent[SMB2_FLUSH_HE]),
60228 - atomic_read(&failed[SMB2_FLUSH_HE]));
60229 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60230 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60231 seq_printf(m, "\nReads: %d sent %d failed",
60232 - atomic_read(&sent[SMB2_READ_HE]),
60233 - atomic_read(&failed[SMB2_READ_HE]));
60234 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60235 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60236 seq_printf(m, "\nWrites: %d sent %d failed",
60237 - atomic_read(&sent[SMB2_WRITE_HE]),
60238 - atomic_read(&failed[SMB2_WRITE_HE]));
60239 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60240 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60241 seq_printf(m, "\nLocks: %d sent %d failed",
60242 - atomic_read(&sent[SMB2_LOCK_HE]),
60243 - atomic_read(&failed[SMB2_LOCK_HE]));
60244 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60245 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60246 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60247 - atomic_read(&sent[SMB2_IOCTL_HE]),
60248 - atomic_read(&failed[SMB2_IOCTL_HE]));
60249 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60250 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60251 seq_printf(m, "\nCancels: %d sent %d failed",
60252 - atomic_read(&sent[SMB2_CANCEL_HE]),
60253 - atomic_read(&failed[SMB2_CANCEL_HE]));
60254 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60255 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60256 seq_printf(m, "\nEchos: %d sent %d failed",
60257 - atomic_read(&sent[SMB2_ECHO_HE]),
60258 - atomic_read(&failed[SMB2_ECHO_HE]));
60259 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60260 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60261 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60262 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60263 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60264 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60265 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60266 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60267 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60268 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60269 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60270 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60271 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60272 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60273 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60274 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60275 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60276 seq_printf(m, "\nSetInfos: %d sent %d failed",
60277 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60278 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60279 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60280 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60281 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60282 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60283 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60284 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60285 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60286 #endif
60287 }
60288
60289 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60290 index 8f1672b..af339c07 100644
60291 --- a/fs/cifs/smb2pdu.c
60292 +++ b/fs/cifs/smb2pdu.c
60293 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60294 default:
60295 cifs_dbg(VFS, "info level %u isn't supported\n",
60296 srch_inf->info_level);
60297 - rc = -EINVAL;
60298 - goto qdir_exit;
60299 + return -EINVAL;
60300 }
60301
60302 req->FileIndex = cpu_to_le32(index);
60303 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60304 index 46ee6f2..89a9e7f 100644
60305 --- a/fs/coda/cache.c
60306 +++ b/fs/coda/cache.c
60307 @@ -24,7 +24,7 @@
60308 #include "coda_linux.h"
60309 #include "coda_cache.h"
60310
60311 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60312 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60313
60314 /* replace or extend an acl cache hit */
60315 void coda_cache_enter(struct inode *inode, int mask)
60316 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60317 struct coda_inode_info *cii = ITOC(inode);
60318
60319 spin_lock(&cii->c_lock);
60320 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60321 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60322 if (!uid_eq(cii->c_uid, current_fsuid())) {
60323 cii->c_uid = current_fsuid();
60324 cii->c_cached_perm = mask;
60325 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60326 {
60327 struct coda_inode_info *cii = ITOC(inode);
60328 spin_lock(&cii->c_lock);
60329 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60330 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60331 spin_unlock(&cii->c_lock);
60332 }
60333
60334 /* remove all acl caches */
60335 void coda_cache_clear_all(struct super_block *sb)
60336 {
60337 - atomic_inc(&permission_epoch);
60338 + atomic_inc_unchecked(&permission_epoch);
60339 }
60340
60341
60342 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60343 spin_lock(&cii->c_lock);
60344 hit = (mask & cii->c_cached_perm) == mask &&
60345 uid_eq(cii->c_uid, current_fsuid()) &&
60346 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60347 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60348 spin_unlock(&cii->c_lock);
60349
60350 return hit;
60351 diff --git a/fs/compat.c b/fs/compat.c
60352 index b13df99..6f6f4a3 100644
60353 --- a/fs/compat.c
60354 +++ b/fs/compat.c
60355 @@ -54,7 +54,7 @@
60356 #include <asm/ioctls.h>
60357 #include "internal.h"
60358
60359 -int compat_log = 1;
60360 +int compat_log = 0;
60361
60362 int compat_printk(const char *fmt, ...)
60363 {
60364 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60365
60366 set_fs(KERNEL_DS);
60367 /* The __user pointer cast is valid because of the set_fs() */
60368 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60369 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60370 set_fs(oldfs);
60371 /* truncating is ok because it's a user address */
60372 if (!ret)
60373 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60374 goto out;
60375
60376 ret = -EINVAL;
60377 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60378 + if (nr_segs > UIO_MAXIOV)
60379 goto out;
60380 if (nr_segs > fast_segs) {
60381 ret = -ENOMEM;
60382 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60383 struct compat_readdir_callback {
60384 struct dir_context ctx;
60385 struct compat_old_linux_dirent __user *dirent;
60386 + struct file * file;
60387 int result;
60388 };
60389
60390 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60391 buf->result = -EOVERFLOW;
60392 return -EOVERFLOW;
60393 }
60394 +
60395 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60396 + return 0;
60397 +
60398 buf->result++;
60399 dirent = buf->dirent;
60400 if (!access_ok(VERIFY_WRITE, dirent,
60401 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60402 if (!f.file)
60403 return -EBADF;
60404
60405 + buf.file = f.file;
60406 error = iterate_dir(f.file, &buf.ctx);
60407 if (buf.result)
60408 error = buf.result;
60409 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60410 struct dir_context ctx;
60411 struct compat_linux_dirent __user *current_dir;
60412 struct compat_linux_dirent __user *previous;
60413 + struct file * file;
60414 int count;
60415 int error;
60416 };
60417 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60418 buf->error = -EOVERFLOW;
60419 return -EOVERFLOW;
60420 }
60421 +
60422 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60423 + return 0;
60424 +
60425 dirent = buf->previous;
60426 if (dirent) {
60427 if (__put_user(offset, &dirent->d_off))
60428 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60429 if (!f.file)
60430 return -EBADF;
60431
60432 + buf.file = f.file;
60433 error = iterate_dir(f.file, &buf.ctx);
60434 if (error >= 0)
60435 error = buf.error;
60436 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60437 struct dir_context ctx;
60438 struct linux_dirent64 __user *current_dir;
60439 struct linux_dirent64 __user *previous;
60440 + struct file * file;
60441 int count;
60442 int error;
60443 };
60444 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60445 buf->error = -EINVAL; /* only used if we fail.. */
60446 if (reclen > buf->count)
60447 return -EINVAL;
60448 +
60449 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60450 + return 0;
60451 +
60452 dirent = buf->previous;
60453
60454 if (dirent) {
60455 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60456 if (!f.file)
60457 return -EBADF;
60458
60459 + buf.file = f.file;
60460 error = iterate_dir(f.file, &buf.ctx);
60461 if (error >= 0)
60462 error = buf.error;
60463 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60464 index 4d24d17..4f8c09e 100644
60465 --- a/fs/compat_binfmt_elf.c
60466 +++ b/fs/compat_binfmt_elf.c
60467 @@ -30,11 +30,13 @@
60468 #undef elf_phdr
60469 #undef elf_shdr
60470 #undef elf_note
60471 +#undef elf_dyn
60472 #undef elf_addr_t
60473 #define elfhdr elf32_hdr
60474 #define elf_phdr elf32_phdr
60475 #define elf_shdr elf32_shdr
60476 #define elf_note elf32_note
60477 +#define elf_dyn Elf32_Dyn
60478 #define elf_addr_t Elf32_Addr
60479
60480 /*
60481 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60482 index afec645..9c65620 100644
60483 --- a/fs/compat_ioctl.c
60484 +++ b/fs/compat_ioctl.c
60485 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60486 return -EFAULT;
60487 if (__get_user(udata, &ss32->iomem_base))
60488 return -EFAULT;
60489 - ss.iomem_base = compat_ptr(udata);
60490 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60491 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60492 __get_user(ss.port_high, &ss32->port_high))
60493 return -EFAULT;
60494 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60495 for (i = 0; i < nmsgs; i++) {
60496 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60497 return -EFAULT;
60498 - if (get_user(datap, &umsgs[i].buf) ||
60499 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60500 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60501 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60502 return -EFAULT;
60503 }
60504 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60505 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60506 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60507 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60508 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60509 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60510 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60511 return -EFAULT;
60512
60513 return ioctl_preallocate(file, p);
60514 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60515 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60516 {
60517 unsigned int a, b;
60518 - a = *(unsigned int *)p;
60519 - b = *(unsigned int *)q;
60520 + a = *(const unsigned int *)p;
60521 + b = *(const unsigned int *)q;
60522 if (a > b)
60523 return 1;
60524 if (a < b)
60525 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60526 index 668dcab..daebcd6 100644
60527 --- a/fs/configfs/dir.c
60528 +++ b/fs/configfs/dir.c
60529 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60530 }
60531 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60532 struct configfs_dirent *next;
60533 - const char *name;
60534 + const unsigned char * name;
60535 + char d_name[sizeof(next->s_dentry->d_iname)];
60536 int len;
60537 struct inode *inode = NULL;
60538
60539 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60540 continue;
60541
60542 name = configfs_get_name(next);
60543 - len = strlen(name);
60544 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60545 + len = next->s_dentry->d_name.len;
60546 + memcpy(d_name, name, len);
60547 + name = d_name;
60548 + } else
60549 + len = strlen(name);
60550
60551 /*
60552 * We'll have a dentry and an inode for
60553 diff --git a/fs/coredump.c b/fs/coredump.c
60554 index b5c86ff..0dac262 100644
60555 --- a/fs/coredump.c
60556 +++ b/fs/coredump.c
60557 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60558 struct pipe_inode_info *pipe = file->private_data;
60559
60560 pipe_lock(pipe);
60561 - pipe->readers++;
60562 - pipe->writers--;
60563 + atomic_inc(&pipe->readers);
60564 + atomic_dec(&pipe->writers);
60565 wake_up_interruptible_sync(&pipe->wait);
60566 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60567 pipe_unlock(pipe);
60568 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60569 * We actually want wait_event_freezable() but then we need
60570 * to clear TIF_SIGPENDING and improve dump_interrupted().
60571 */
60572 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60573 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60574
60575 pipe_lock(pipe);
60576 - pipe->readers--;
60577 - pipe->writers++;
60578 + atomic_dec(&pipe->readers);
60579 + atomic_inc(&pipe->writers);
60580 pipe_unlock(pipe);
60581 }
60582
60583 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60584 struct files_struct *displaced;
60585 bool need_nonrelative = false;
60586 bool core_dumped = false;
60587 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60588 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60589 + long signr = siginfo->si_signo;
60590 + int dumpable;
60591 struct coredump_params cprm = {
60592 .siginfo = siginfo,
60593 .regs = signal_pt_regs(),
60594 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60595 .mm_flags = mm->flags,
60596 };
60597
60598 - audit_core_dumps(siginfo->si_signo);
60599 + audit_core_dumps(signr);
60600 +
60601 + dumpable = __get_dumpable(cprm.mm_flags);
60602 +
60603 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60604 + gr_handle_brute_attach(dumpable);
60605
60606 binfmt = mm->binfmt;
60607 if (!binfmt || !binfmt->core_dump)
60608 goto fail;
60609 - if (!__get_dumpable(cprm.mm_flags))
60610 + if (!dumpable)
60611 goto fail;
60612
60613 cred = prepare_creds();
60614 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60615 need_nonrelative = true;
60616 }
60617
60618 - retval = coredump_wait(siginfo->si_signo, &core_state);
60619 + retval = coredump_wait(signr, &core_state);
60620 if (retval < 0)
60621 goto fail_creds;
60622
60623 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60624 }
60625 cprm.limit = RLIM_INFINITY;
60626
60627 - dump_count = atomic_inc_return(&core_dump_count);
60628 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60629 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60630 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60631 task_tgid_vnr(current), current->comm);
60632 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60633 } else {
60634 struct inode *inode;
60635
60636 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60637 +
60638 if (cprm.limit < binfmt->min_coredump)
60639 goto fail_unlock;
60640
60641 @@ -681,7 +690,7 @@ close_fail:
60642 filp_close(cprm.file, NULL);
60643 fail_dropcount:
60644 if (ispipe)
60645 - atomic_dec(&core_dump_count);
60646 + atomic_dec_unchecked(&core_dump_count);
60647 fail_unlock:
60648 kfree(cn.corename);
60649 coredump_finish(mm, core_dumped);
60650 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60651 struct file *file = cprm->file;
60652 loff_t pos = file->f_pos;
60653 ssize_t n;
60654 +
60655 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60656 if (cprm->written + nr > cprm->limit)
60657 return 0;
60658 while (nr) {
60659 diff --git a/fs/dcache.c b/fs/dcache.c
60660 index 03dca3c..15f326d 100644
60661 --- a/fs/dcache.c
60662 +++ b/fs/dcache.c
60663 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60664 * dentry_iput drops the locks, at which point nobody (except
60665 * transient RCU lookups) can reach this dentry.
60666 */
60667 - BUG_ON((int)dentry->d_lockref.count > 0);
60668 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60669 this_cpu_dec(nr_dentry);
60670 if (dentry->d_op && dentry->d_op->d_release)
60671 dentry->d_op->d_release(dentry);
60672 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60673 struct dentry *parent = dentry->d_parent;
60674 if (IS_ROOT(dentry))
60675 return NULL;
60676 - if (unlikely((int)dentry->d_lockref.count < 0))
60677 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60678 return NULL;
60679 if (likely(spin_trylock(&parent->d_lock)))
60680 return parent;
60681 @@ -638,7 +638,7 @@ repeat:
60682 dentry->d_flags |= DCACHE_REFERENCED;
60683 dentry_lru_add(dentry);
60684
60685 - dentry->d_lockref.count--;
60686 + __lockref_dec(&dentry->d_lockref);
60687 spin_unlock(&dentry->d_lock);
60688 return;
60689
60690 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60691 /* This must be called with d_lock held */
60692 static inline void __dget_dlock(struct dentry *dentry)
60693 {
60694 - dentry->d_lockref.count++;
60695 + __lockref_inc(&dentry->d_lockref);
60696 }
60697
60698 static inline void __dget(struct dentry *dentry)
60699 @@ -694,8 +694,8 @@ repeat:
60700 goto repeat;
60701 }
60702 rcu_read_unlock();
60703 - BUG_ON(!ret->d_lockref.count);
60704 - ret->d_lockref.count++;
60705 + BUG_ON(!__lockref_read(&ret->d_lockref));
60706 + __lockref_inc(&ret->d_lockref);
60707 spin_unlock(&ret->d_lock);
60708 return ret;
60709 }
60710 @@ -773,9 +773,9 @@ restart:
60711 spin_lock(&inode->i_lock);
60712 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60713 spin_lock(&dentry->d_lock);
60714 - if (!dentry->d_lockref.count) {
60715 + if (!__lockref_read(&dentry->d_lockref)) {
60716 struct dentry *parent = lock_parent(dentry);
60717 - if (likely(!dentry->d_lockref.count)) {
60718 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60719 __dentry_kill(dentry);
60720 dput(parent);
60721 goto restart;
60722 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60723 * We found an inuse dentry which was not removed from
60724 * the LRU because of laziness during lookup. Do not free it.
60725 */
60726 - if ((int)dentry->d_lockref.count > 0) {
60727 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60728 spin_unlock(&dentry->d_lock);
60729 if (parent)
60730 spin_unlock(&parent->d_lock);
60731 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60732 dentry = parent;
60733 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60734 parent = lock_parent(dentry);
60735 - if (dentry->d_lockref.count != 1) {
60736 - dentry->d_lockref.count--;
60737 + if (__lockref_read(&dentry->d_lockref) != 1) {
60738 + __lockref_inc(&dentry->d_lockref);
60739 spin_unlock(&dentry->d_lock);
60740 if (parent)
60741 spin_unlock(&parent->d_lock);
60742 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60743 * counts, just remove them from the LRU. Otherwise give them
60744 * another pass through the LRU.
60745 */
60746 - if (dentry->d_lockref.count) {
60747 + if (__lockref_read(&dentry->d_lockref) > 0) {
60748 d_lru_isolate(dentry);
60749 spin_unlock(&dentry->d_lock);
60750 return LRU_REMOVED;
60751 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60752 } else {
60753 if (dentry->d_flags & DCACHE_LRU_LIST)
60754 d_lru_del(dentry);
60755 - if (!dentry->d_lockref.count) {
60756 + if (!__lockref_read(&dentry->d_lockref)) {
60757 d_shrink_add(dentry, &data->dispose);
60758 data->found++;
60759 }
60760 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60761 return D_WALK_CONTINUE;
60762
60763 /* root with refcount 1 is fine */
60764 - if (dentry == _data && dentry->d_lockref.count == 1)
60765 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60766 return D_WALK_CONTINUE;
60767
60768 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60769 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60770 dentry->d_inode ?
60771 dentry->d_inode->i_ino : 0UL,
60772 dentry,
60773 - dentry->d_lockref.count,
60774 + __lockref_read(&dentry->d_lockref),
60775 dentry->d_sb->s_type->name,
60776 dentry->d_sb->s_id);
60777 WARN_ON(1);
60778 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60779 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60780 if (name->len > DNAME_INLINE_LEN-1) {
60781 size_t size = offsetof(struct external_name, name[1]);
60782 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60783 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60784 if (!p) {
60785 kmem_cache_free(dentry_cache, dentry);
60786 return NULL;
60787 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60788 smp_wmb();
60789 dentry->d_name.name = dname;
60790
60791 - dentry->d_lockref.count = 1;
60792 + __lockref_set(&dentry->d_lockref, 1);
60793 dentry->d_flags = 0;
60794 spin_lock_init(&dentry->d_lock);
60795 seqcount_init(&dentry->d_seq);
60796 @@ -1452,6 +1452,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60797 dentry->d_sb = sb;
60798 dentry->d_op = NULL;
60799 dentry->d_fsdata = NULL;
60800 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
60801 + atomic_set(&dentry->chroot_refcnt, 0);
60802 +#endif
60803 INIT_HLIST_BL_NODE(&dentry->d_hash);
60804 INIT_LIST_HEAD(&dentry->d_lru);
60805 INIT_LIST_HEAD(&dentry->d_subdirs);
60806 @@ -2183,7 +2186,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60807 goto next;
60808 }
60809
60810 - dentry->d_lockref.count++;
60811 + __lockref_inc(&dentry->d_lockref);
60812 found = dentry;
60813 spin_unlock(&dentry->d_lock);
60814 break;
60815 @@ -2282,7 +2285,7 @@ again:
60816 spin_lock(&dentry->d_lock);
60817 inode = dentry->d_inode;
60818 isdir = S_ISDIR(inode->i_mode);
60819 - if (dentry->d_lockref.count == 1) {
60820 + if (__lockref_read(&dentry->d_lockref) == 1) {
60821 if (!spin_trylock(&inode->i_lock)) {
60822 spin_unlock(&dentry->d_lock);
60823 cpu_relax();
60824 @@ -3308,7 +3311,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60825
60826 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60827 dentry->d_flags |= DCACHE_GENOCIDE;
60828 - dentry->d_lockref.count--;
60829 + __lockref_dec(&dentry->d_lockref);
60830 }
60831 }
60832 return D_WALK_CONTINUE;
60833 @@ -3424,7 +3427,8 @@ void __init vfs_caches_init(unsigned long mempages)
60834 mempages -= reserve;
60835
60836 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60837 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60838 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60839 + SLAB_NO_SANITIZE, NULL);
60840
60841 dcache_init();
60842 inode_init();
60843 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60844 index 05f2960..b012481 100644
60845 --- a/fs/debugfs/inode.c
60846 +++ b/fs/debugfs/inode.c
60847 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60848 */
60849 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60850 {
60851 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60852 + return __create_file(name, S_IFDIR | S_IRWXU,
60853 +#else
60854 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60855 +#endif
60856 parent, NULL, NULL);
60857 }
60858 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60859 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60860 index 1686dc2..9611c50 100644
60861 --- a/fs/ecryptfs/inode.c
60862 +++ b/fs/ecryptfs/inode.c
60863 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60864 old_fs = get_fs();
60865 set_fs(get_ds());
60866 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60867 - (char __user *)lower_buf,
60868 + (char __force_user *)lower_buf,
60869 PATH_MAX);
60870 set_fs(old_fs);
60871 if (rc < 0)
60872 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60873 index e4141f2..d8263e8 100644
60874 --- a/fs/ecryptfs/miscdev.c
60875 +++ b/fs/ecryptfs/miscdev.c
60876 @@ -304,7 +304,7 @@ check_list:
60877 goto out_unlock_msg_ctx;
60878 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60879 if (msg_ctx->msg) {
60880 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60881 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60882 goto out_unlock_msg_ctx;
60883 i += packet_length_size;
60884 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60885 diff --git a/fs/exec.c b/fs/exec.c
60886 index 7302b75..b917171 100644
60887 --- a/fs/exec.c
60888 +++ b/fs/exec.c
60889 @@ -56,8 +56,20 @@
60890 #include <linux/pipe_fs_i.h>
60891 #include <linux/oom.h>
60892 #include <linux/compat.h>
60893 +#include <linux/random.h>
60894 +#include <linux/seq_file.h>
60895 +#include <linux/coredump.h>
60896 +#include <linux/mman.h>
60897 +
60898 +#ifdef CONFIG_PAX_REFCOUNT
60899 +#include <linux/kallsyms.h>
60900 +#include <linux/kdebug.h>
60901 +#endif
60902 +
60903 +#include <trace/events/fs.h>
60904
60905 #include <asm/uaccess.h>
60906 +#include <asm/sections.h>
60907 #include <asm/mmu_context.h>
60908 #include <asm/tlb.h>
60909
60910 @@ -66,19 +78,34 @@
60911
60912 #include <trace/events/sched.h>
60913
60914 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60915 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60916 +{
60917 + 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");
60918 +}
60919 +#endif
60920 +
60921 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60922 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60923 +EXPORT_SYMBOL(pax_set_initial_flags_func);
60924 +#endif
60925 +
60926 int suid_dumpable = 0;
60927
60928 static LIST_HEAD(formats);
60929 static DEFINE_RWLOCK(binfmt_lock);
60930
60931 +extern int gr_process_kernel_exec_ban(void);
60932 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60933 +
60934 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60935 {
60936 BUG_ON(!fmt);
60937 if (WARN_ON(!fmt->load_binary))
60938 return;
60939 write_lock(&binfmt_lock);
60940 - insert ? list_add(&fmt->lh, &formats) :
60941 - list_add_tail(&fmt->lh, &formats);
60942 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60943 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60944 write_unlock(&binfmt_lock);
60945 }
60946
60947 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60948 void unregister_binfmt(struct linux_binfmt * fmt)
60949 {
60950 write_lock(&binfmt_lock);
60951 - list_del(&fmt->lh);
60952 + pax_list_del((struct list_head *)&fmt->lh);
60953 write_unlock(&binfmt_lock);
60954 }
60955
60956 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60957 int write)
60958 {
60959 struct page *page;
60960 - int ret;
60961
60962 -#ifdef CONFIG_STACK_GROWSUP
60963 - if (write) {
60964 - ret = expand_downwards(bprm->vma, pos);
60965 - if (ret < 0)
60966 - return NULL;
60967 - }
60968 -#endif
60969 - ret = get_user_pages(current, bprm->mm, pos,
60970 - 1, write, 1, &page, NULL);
60971 - if (ret <= 0)
60972 + if (0 > expand_downwards(bprm->vma, pos))
60973 + return NULL;
60974 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
60975 return NULL;
60976
60977 if (write) {
60978 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60979 if (size <= ARG_MAX)
60980 return page;
60981
60982 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60983 + // only allow 512KB for argv+env on suid/sgid binaries
60984 + // to prevent easy ASLR exhaustion
60985 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
60986 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
60987 + (size > (512 * 1024))) {
60988 + put_page(page);
60989 + return NULL;
60990 + }
60991 +#endif
60992 +
60993 /*
60994 * Limit to 1/4-th the stack size for the argv+env strings.
60995 * This ensures that:
60996 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60997 vma->vm_end = STACK_TOP_MAX;
60998 vma->vm_start = vma->vm_end - PAGE_SIZE;
60999 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61000 +
61001 +#ifdef CONFIG_PAX_SEGMEXEC
61002 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61003 +#endif
61004 +
61005 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61006 INIT_LIST_HEAD(&vma->anon_vma_chain);
61007
61008 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61009 mm->stack_vm = mm->total_vm = 1;
61010 up_write(&mm->mmap_sem);
61011 bprm->p = vma->vm_end - sizeof(void *);
61012 +
61013 +#ifdef CONFIG_PAX_RANDUSTACK
61014 + if (randomize_va_space)
61015 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61016 +#endif
61017 +
61018 return 0;
61019 err:
61020 up_write(&mm->mmap_sem);
61021 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61022 } ptr;
61023 };
61024
61025 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61026 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61027 {
61028 const char __user *native;
61029
61030 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61031 compat_uptr_t compat;
61032
61033 if (get_user(compat, argv.ptr.compat + nr))
61034 - return ERR_PTR(-EFAULT);
61035 + return (const char __force_user *)ERR_PTR(-EFAULT);
61036
61037 return compat_ptr(compat);
61038 }
61039 #endif
61040
61041 if (get_user(native, argv.ptr.native + nr))
61042 - return ERR_PTR(-EFAULT);
61043 + return (const char __force_user *)ERR_PTR(-EFAULT);
61044
61045 return native;
61046 }
61047 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61048 if (!p)
61049 break;
61050
61051 - if (IS_ERR(p))
61052 + if (IS_ERR((const char __force_kernel *)p))
61053 return -EFAULT;
61054
61055 if (i >= max)
61056 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61057
61058 ret = -EFAULT;
61059 str = get_user_arg_ptr(argv, argc);
61060 - if (IS_ERR(str))
61061 + if (IS_ERR((const char __force_kernel *)str))
61062 goto out;
61063
61064 len = strnlen_user(str, MAX_ARG_STRLEN);
61065 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61066 int r;
61067 mm_segment_t oldfs = get_fs();
61068 struct user_arg_ptr argv = {
61069 - .ptr.native = (const char __user *const __user *)__argv,
61070 + .ptr.native = (const char __user * const __force_user *)__argv,
61071 };
61072
61073 set_fs(KERNEL_DS);
61074 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61075 unsigned long new_end = old_end - shift;
61076 struct mmu_gather tlb;
61077
61078 - BUG_ON(new_start > new_end);
61079 + if (new_start >= new_end || new_start < mmap_min_addr)
61080 + return -ENOMEM;
61081
61082 /*
61083 * ensure there are no vmas between where we want to go
61084 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61085 if (vma != find_vma(mm, new_start))
61086 return -EFAULT;
61087
61088 +#ifdef CONFIG_PAX_SEGMEXEC
61089 + BUG_ON(pax_find_mirror_vma(vma));
61090 +#endif
61091 +
61092 /*
61093 * cover the whole range: [new_start, old_end)
61094 */
61095 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61096 stack_top = arch_align_stack(stack_top);
61097 stack_top = PAGE_ALIGN(stack_top);
61098
61099 - if (unlikely(stack_top < mmap_min_addr) ||
61100 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61101 - return -ENOMEM;
61102 -
61103 stack_shift = vma->vm_end - stack_top;
61104
61105 bprm->p -= stack_shift;
61106 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61107 bprm->exec -= stack_shift;
61108
61109 down_write(&mm->mmap_sem);
61110 +
61111 + /* Move stack pages down in memory. */
61112 + if (stack_shift) {
61113 + ret = shift_arg_pages(vma, stack_shift);
61114 + if (ret)
61115 + goto out_unlock;
61116 + }
61117 +
61118 vm_flags = VM_STACK_FLAGS;
61119
61120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61121 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61122 + vm_flags &= ~VM_EXEC;
61123 +
61124 +#ifdef CONFIG_PAX_MPROTECT
61125 + if (mm->pax_flags & MF_PAX_MPROTECT)
61126 + vm_flags &= ~VM_MAYEXEC;
61127 +#endif
61128 +
61129 + }
61130 +#endif
61131 +
61132 /*
61133 * Adjust stack execute permissions; explicitly enable for
61134 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61135 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61136 goto out_unlock;
61137 BUG_ON(prev != vma);
61138
61139 - /* Move stack pages down in memory. */
61140 - if (stack_shift) {
61141 - ret = shift_arg_pages(vma, stack_shift);
61142 - if (ret)
61143 - goto out_unlock;
61144 - }
61145 -
61146 /* mprotect_fixup is overkill to remove the temporary stack flags */
61147 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61148
61149 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61150 #endif
61151 current->mm->start_stack = bprm->p;
61152 ret = expand_stack(vma, stack_base);
61153 +
61154 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61155 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61156 + unsigned long size;
61157 + vm_flags_t vm_flags;
61158 +
61159 + size = STACK_TOP - vma->vm_end;
61160 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61161 +
61162 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61163 +
61164 +#ifdef CONFIG_X86
61165 + if (!ret) {
61166 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61167 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61168 + }
61169 +#endif
61170 +
61171 + }
61172 +#endif
61173 +
61174 if (ret)
61175 ret = -EFAULT;
61176
61177 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61178
61179 fsnotify_open(file);
61180
61181 + trace_open_exec(name->name);
61182 +
61183 err = deny_write_access(file);
61184 if (err)
61185 goto exit;
61186 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61187 old_fs = get_fs();
61188 set_fs(get_ds());
61189 /* The cast to a user pointer is valid due to the set_fs() */
61190 - result = vfs_read(file, (void __user *)addr, count, &pos);
61191 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61192 set_fs(old_fs);
61193 return result;
61194 }
61195 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61196 tsk->mm = mm;
61197 tsk->active_mm = mm;
61198 activate_mm(active_mm, mm);
61199 + populate_stack();
61200 tsk->mm->vmacache_seqnum = 0;
61201 vmacache_flush(tsk);
61202 task_unlock(tsk);
61203 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61204 }
61205 rcu_read_unlock();
61206
61207 - if (p->fs->users > n_fs)
61208 + if (atomic_read(&p->fs->users) > n_fs)
61209 bprm->unsafe |= LSM_UNSAFE_SHARE;
61210 else
61211 p->fs->in_exec = 1;
61212 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61213 return ret;
61214 }
61215
61216 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61217 +static DEFINE_PER_CPU(u64, exec_counter);
61218 +static int __init init_exec_counters(void)
61219 +{
61220 + unsigned int cpu;
61221 +
61222 + for_each_possible_cpu(cpu) {
61223 + per_cpu(exec_counter, cpu) = (u64)cpu;
61224 + }
61225 +
61226 + return 0;
61227 +}
61228 +early_initcall(init_exec_counters);
61229 +static inline void increment_exec_counter(void)
61230 +{
61231 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61232 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61233 +}
61234 +#else
61235 +static inline void increment_exec_counter(void) {}
61236 +#endif
61237 +
61238 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61239 + struct user_arg_ptr argv);
61240 +
61241 /*
61242 * sys_execve() executes a new program.
61243 */
61244 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61245 struct user_arg_ptr argv,
61246 struct user_arg_ptr envp)
61247 {
61248 +#ifdef CONFIG_GRKERNSEC
61249 + struct file *old_exec_file;
61250 + struct acl_subject_label *old_acl;
61251 + struct rlimit old_rlim[RLIM_NLIMITS];
61252 +#endif
61253 struct linux_binprm *bprm;
61254 struct file *file;
61255 struct files_struct *displaced;
61256 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61257 if (IS_ERR(filename))
61258 return PTR_ERR(filename);
61259
61260 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61261 +
61262 /*
61263 * We move the actual failure in case of RLIMIT_NPROC excess from
61264 * set*uid() to execve() because too many poorly written programs
61265 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61266 if (IS_ERR(file))
61267 goto out_unmark;
61268
61269 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61270 + retval = -EPERM;
61271 + goto out_unmark;
61272 + }
61273 +
61274 sched_exec();
61275
61276 bprm->file = file;
61277 bprm->filename = bprm->interp = filename->name;
61278
61279 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61280 + retval = -EACCES;
61281 + goto out_unmark;
61282 + }
61283 +
61284 retval = bprm_mm_init(bprm);
61285 if (retval)
61286 goto out_unmark;
61287 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61288 if (retval < 0)
61289 goto out;
61290
61291 +#ifdef CONFIG_GRKERNSEC
61292 + old_acl = current->acl;
61293 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61294 + old_exec_file = current->exec_file;
61295 + get_file(file);
61296 + current->exec_file = file;
61297 +#endif
61298 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61299 + /* limit suid stack to 8MB
61300 + * we saved the old limits above and will restore them if this exec fails
61301 + */
61302 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61303 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61304 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61305 +#endif
61306 +
61307 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61308 + retval = -EPERM;
61309 + goto out_fail;
61310 + }
61311 +
61312 + if (!gr_tpe_allow(file)) {
61313 + retval = -EACCES;
61314 + goto out_fail;
61315 + }
61316 +
61317 + if (gr_check_crash_exec(file)) {
61318 + retval = -EACCES;
61319 + goto out_fail;
61320 + }
61321 +
61322 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61323 + bprm->unsafe);
61324 + if (retval < 0)
61325 + goto out_fail;
61326 +
61327 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61328 if (retval < 0)
61329 - goto out;
61330 + goto out_fail;
61331
61332 bprm->exec = bprm->p;
61333 retval = copy_strings(bprm->envc, envp, bprm);
61334 if (retval < 0)
61335 - goto out;
61336 + goto out_fail;
61337
61338 retval = copy_strings(bprm->argc, argv, bprm);
61339 if (retval < 0)
61340 - goto out;
61341 + goto out_fail;
61342 +
61343 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61344 +
61345 + gr_handle_exec_args(bprm, argv);
61346
61347 retval = exec_binprm(bprm);
61348 if (retval < 0)
61349 - goto out;
61350 + goto out_fail;
61351 +#ifdef CONFIG_GRKERNSEC
61352 + if (old_exec_file)
61353 + fput(old_exec_file);
61354 +#endif
61355
61356 /* execve succeeded */
61357 +
61358 + increment_exec_counter();
61359 current->fs->in_exec = 0;
61360 current->in_execve = 0;
61361 acct_update_integrals(current);
61362 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61363 put_files_struct(displaced);
61364 return retval;
61365
61366 +out_fail:
61367 +#ifdef CONFIG_GRKERNSEC
61368 + current->acl = old_acl;
61369 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61370 + fput(current->exec_file);
61371 + current->exec_file = old_exec_file;
61372 +#endif
61373 +
61374 out:
61375 if (bprm->mm) {
61376 acct_arg_size(bprm, 0);
61377 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61378 return compat_do_execve(getname(filename), argv, envp);
61379 }
61380 #endif
61381 +
61382 +int pax_check_flags(unsigned long *flags)
61383 +{
61384 + int retval = 0;
61385 +
61386 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61387 + if (*flags & MF_PAX_SEGMEXEC)
61388 + {
61389 + *flags &= ~MF_PAX_SEGMEXEC;
61390 + retval = -EINVAL;
61391 + }
61392 +#endif
61393 +
61394 + if ((*flags & MF_PAX_PAGEEXEC)
61395 +
61396 +#ifdef CONFIG_PAX_PAGEEXEC
61397 + && (*flags & MF_PAX_SEGMEXEC)
61398 +#endif
61399 +
61400 + )
61401 + {
61402 + *flags &= ~MF_PAX_PAGEEXEC;
61403 + retval = -EINVAL;
61404 + }
61405 +
61406 + if ((*flags & MF_PAX_MPROTECT)
61407 +
61408 +#ifdef CONFIG_PAX_MPROTECT
61409 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61410 +#endif
61411 +
61412 + )
61413 + {
61414 + *flags &= ~MF_PAX_MPROTECT;
61415 + retval = -EINVAL;
61416 + }
61417 +
61418 + if ((*flags & MF_PAX_EMUTRAMP)
61419 +
61420 +#ifdef CONFIG_PAX_EMUTRAMP
61421 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61422 +#endif
61423 +
61424 + )
61425 + {
61426 + *flags &= ~MF_PAX_EMUTRAMP;
61427 + retval = -EINVAL;
61428 + }
61429 +
61430 + return retval;
61431 +}
61432 +
61433 +EXPORT_SYMBOL(pax_check_flags);
61434 +
61435 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61436 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61437 +{
61438 + char *pathname = d_path(path, buf, buflen);
61439 +
61440 + if (IS_ERR(pathname))
61441 + goto toolong;
61442 +
61443 + pathname = mangle_path(buf, pathname, "\t\n\\");
61444 + if (!pathname)
61445 + goto toolong;
61446 +
61447 + *pathname = 0;
61448 + return buf;
61449 +
61450 +toolong:
61451 + return "<path too long>";
61452 +}
61453 +EXPORT_SYMBOL(pax_get_path);
61454 +
61455 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61456 +{
61457 + struct task_struct *tsk = current;
61458 + struct mm_struct *mm = current->mm;
61459 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61460 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61461 + char *path_exec = NULL;
61462 + char *path_fault = NULL;
61463 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61464 + siginfo_t info = { };
61465 +
61466 + if (buffer_exec && buffer_fault) {
61467 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61468 +
61469 + down_read(&mm->mmap_sem);
61470 + vma = mm->mmap;
61471 + while (vma && (!vma_exec || !vma_fault)) {
61472 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61473 + vma_exec = vma;
61474 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61475 + vma_fault = vma;
61476 + vma = vma->vm_next;
61477 + }
61478 + if (vma_exec)
61479 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61480 + if (vma_fault) {
61481 + start = vma_fault->vm_start;
61482 + end = vma_fault->vm_end;
61483 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61484 + if (vma_fault->vm_file)
61485 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61486 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61487 + path_fault = "<heap>";
61488 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61489 + path_fault = "<stack>";
61490 + else
61491 + path_fault = "<anonymous mapping>";
61492 + }
61493 + up_read(&mm->mmap_sem);
61494 + }
61495 + if (tsk->signal->curr_ip)
61496 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61497 + else
61498 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61499 + 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),
61500 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61501 + free_page((unsigned long)buffer_exec);
61502 + free_page((unsigned long)buffer_fault);
61503 + pax_report_insns(regs, pc, sp);
61504 + info.si_signo = SIGKILL;
61505 + info.si_errno = 0;
61506 + info.si_code = SI_KERNEL;
61507 + info.si_pid = 0;
61508 + info.si_uid = 0;
61509 + do_coredump(&info);
61510 +}
61511 +#endif
61512 +
61513 +#ifdef CONFIG_PAX_REFCOUNT
61514 +void pax_report_refcount_overflow(struct pt_regs *regs)
61515 +{
61516 + if (current->signal->curr_ip)
61517 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61518 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61519 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61520 + else
61521 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61522 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61523 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61524 + preempt_disable();
61525 + show_regs(regs);
61526 + preempt_enable();
61527 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61528 +}
61529 +#endif
61530 +
61531 +#ifdef CONFIG_PAX_USERCOPY
61532 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61533 +static noinline int check_stack_object(const void *obj, unsigned long len)
61534 +{
61535 + const void * const stack = task_stack_page(current);
61536 + const void * const stackend = stack + THREAD_SIZE;
61537 +
61538 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61539 + const void *frame = NULL;
61540 + const void *oldframe;
61541 +#endif
61542 +
61543 + if (obj + len < obj)
61544 + return -1;
61545 +
61546 + if (obj + len <= stack || stackend <= obj)
61547 + return 0;
61548 +
61549 + if (obj < stack || stackend < obj + len)
61550 + return -1;
61551 +
61552 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61553 + oldframe = __builtin_frame_address(1);
61554 + if (oldframe)
61555 + frame = __builtin_frame_address(2);
61556 + /*
61557 + low ----------------------------------------------> high
61558 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61559 + ^----------------^
61560 + allow copies only within here
61561 + */
61562 + while (stack <= frame && frame < stackend) {
61563 + /* if obj + len extends past the last frame, this
61564 + check won't pass and the next frame will be 0,
61565 + causing us to bail out and correctly report
61566 + the copy as invalid
61567 + */
61568 + if (obj + len <= frame)
61569 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61570 + oldframe = frame;
61571 + frame = *(const void * const *)frame;
61572 + }
61573 + return -1;
61574 +#else
61575 + return 1;
61576 +#endif
61577 +}
61578 +
61579 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61580 +{
61581 + if (current->signal->curr_ip)
61582 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61583 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61584 + else
61585 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61586 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61587 + dump_stack();
61588 + gr_handle_kernel_exploit();
61589 + do_group_exit(SIGKILL);
61590 +}
61591 +#endif
61592 +
61593 +#ifdef CONFIG_PAX_USERCOPY
61594 +
61595 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61596 +{
61597 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61598 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61599 +#ifdef CONFIG_MODULES
61600 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61601 +#else
61602 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61603 +#endif
61604 +
61605 +#else
61606 + unsigned long textlow = (unsigned long)_stext;
61607 + unsigned long texthigh = (unsigned long)_etext;
61608 +
61609 +#ifdef CONFIG_X86_64
61610 + /* check against linear mapping as well */
61611 + if (high > (unsigned long)__va(__pa(textlow)) &&
61612 + low < (unsigned long)__va(__pa(texthigh)))
61613 + return true;
61614 +#endif
61615 +
61616 +#endif
61617 +
61618 + if (high <= textlow || low >= texthigh)
61619 + return false;
61620 + else
61621 + return true;
61622 +}
61623 +#endif
61624 +
61625 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61626 +{
61627 +#ifdef CONFIG_PAX_USERCOPY
61628 + const char *type;
61629 +#endif
61630 +
61631 +#ifndef CONFIG_STACK_GROWSUP
61632 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61633 + unsigned long currentsp = (unsigned long)&stackstart;
61634 + if (unlikely((currentsp < stackstart + 512 ||
61635 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61636 + BUG();
61637 +#endif
61638 +
61639 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61640 + if (const_size)
61641 + return;
61642 +#endif
61643 +
61644 +#ifdef CONFIG_PAX_USERCOPY
61645 + if (!n)
61646 + return;
61647 +
61648 + type = check_heap_object(ptr, n);
61649 + if (!type) {
61650 + int ret = check_stack_object(ptr, n);
61651 + if (ret == 1 || ret == 2)
61652 + return;
61653 + if (ret == 0) {
61654 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61655 + type = "<kernel text>";
61656 + else
61657 + return;
61658 + } else
61659 + type = "<process stack>";
61660 + }
61661 +
61662 + pax_report_usercopy(ptr, n, to_user, type);
61663 +#endif
61664 +
61665 +}
61666 +EXPORT_SYMBOL(__check_object_size);
61667 +
61668 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61669 +void pax_track_stack(void)
61670 +{
61671 + unsigned long sp = (unsigned long)&sp;
61672 + if (sp < current_thread_info()->lowest_stack &&
61673 + sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61674 + current_thread_info()->lowest_stack = sp;
61675 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61676 + BUG();
61677 +}
61678 +EXPORT_SYMBOL(pax_track_stack);
61679 +#endif
61680 +
61681 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61682 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61683 +{
61684 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61685 + dump_stack();
61686 + do_group_exit(SIGKILL);
61687 +}
61688 +EXPORT_SYMBOL(report_size_overflow);
61689 +#endif
61690 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61691 index 9f9992b..8b59411 100644
61692 --- a/fs/ext2/balloc.c
61693 +++ b/fs/ext2/balloc.c
61694 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61695
61696 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61697 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61698 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61699 + if (free_blocks < root_blocks + 1 &&
61700 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61701 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61702 - !in_group_p (sbi->s_resgid))) {
61703 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61704 return 0;
61705 }
61706 return 1;
61707 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61708 index 170dc41..62f6b18 100644
61709 --- a/fs/ext2/super.c
61710 +++ b/fs/ext2/super.c
61711 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61712 #ifdef CONFIG_EXT2_FS_XATTR
61713 if (test_opt(sb, XATTR_USER))
61714 seq_puts(seq, ",user_xattr");
61715 - if (!test_opt(sb, XATTR_USER) &&
61716 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61717 + if (!test_opt(sb, XATTR_USER))
61718 seq_puts(seq, ",nouser_xattr");
61719 - }
61720 #endif
61721
61722 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61723 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61724 if (def_mount_opts & EXT2_DEFM_UID16)
61725 set_opt(sbi->s_mount_opt, NO_UID32);
61726 #ifdef CONFIG_EXT2_FS_XATTR
61727 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61728 - set_opt(sbi->s_mount_opt, XATTR_USER);
61729 + /* always enable user xattrs */
61730 + set_opt(sbi->s_mount_opt, XATTR_USER);
61731 #endif
61732 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61733 if (def_mount_opts & EXT2_DEFM_ACL)
61734 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61735 index 9142614..97484fa 100644
61736 --- a/fs/ext2/xattr.c
61737 +++ b/fs/ext2/xattr.c
61738 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61739 struct buffer_head *bh = NULL;
61740 struct ext2_xattr_entry *entry;
61741 char *end;
61742 - size_t rest = buffer_size;
61743 + size_t rest = buffer_size, total_size = 0;
61744 int error;
61745
61746 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61747 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61748 buffer += size;
61749 }
61750 rest -= size;
61751 + total_size += size;
61752 }
61753 }
61754 - error = buffer_size - rest; /* total size */
61755 + error = total_size;
61756
61757 cleanup:
61758 brelse(bh);
61759 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61760 index 158b5d4..2432610 100644
61761 --- a/fs/ext3/balloc.c
61762 +++ b/fs/ext3/balloc.c
61763 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61764
61765 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61766 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61767 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61768 + if (free_blocks < root_blocks + 1 &&
61769 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61770 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61771 - !in_group_p (sbi->s_resgid))) {
61772 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61773 return 0;
61774 }
61775 return 1;
61776 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61777 index eb742d0..c19f705 100644
61778 --- a/fs/ext3/super.c
61779 +++ b/fs/ext3/super.c
61780 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61781 #ifdef CONFIG_EXT3_FS_XATTR
61782 if (test_opt(sb, XATTR_USER))
61783 seq_puts(seq, ",user_xattr");
61784 - if (!test_opt(sb, XATTR_USER) &&
61785 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61786 + if (!test_opt(sb, XATTR_USER))
61787 seq_puts(seq, ",nouser_xattr");
61788 - }
61789 #endif
61790 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61791 if (test_opt(sb, POSIX_ACL))
61792 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61793 if (def_mount_opts & EXT3_DEFM_UID16)
61794 set_opt(sbi->s_mount_opt, NO_UID32);
61795 #ifdef CONFIG_EXT3_FS_XATTR
61796 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61797 - set_opt(sbi->s_mount_opt, XATTR_USER);
61798 + /* always enable user xattrs */
61799 + set_opt(sbi->s_mount_opt, XATTR_USER);
61800 #endif
61801 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61802 if (def_mount_opts & EXT3_DEFM_ACL)
61803 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61804 index c6874be..f8a6ae8 100644
61805 --- a/fs/ext3/xattr.c
61806 +++ b/fs/ext3/xattr.c
61807 @@ -330,7 +330,7 @@ static int
61808 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61809 char *buffer, size_t buffer_size)
61810 {
61811 - size_t rest = buffer_size;
61812 + size_t rest = buffer_size, total_size = 0;
61813
61814 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61815 const struct xattr_handler *handler =
61816 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61817 buffer += size;
61818 }
61819 rest -= size;
61820 + total_size += size;
61821 }
61822 }
61823 - return buffer_size - rest;
61824 + return total_size;
61825 }
61826
61827 static int
61828 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61829 index 83a6f49..d4e4d03 100644
61830 --- a/fs/ext4/balloc.c
61831 +++ b/fs/ext4/balloc.c
61832 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61833 /* Hm, nope. Are (enough) root reserved clusters available? */
61834 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61835 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61836 - capable(CAP_SYS_RESOURCE) ||
61837 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61838 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61839 + capable_nolog(CAP_SYS_RESOURCE)) {
61840
61841 if (free_clusters >= (nclusters + dirty_clusters +
61842 resv_clusters))
61843 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61844 index c55a1fa..9904ebb 100644
61845 --- a/fs/ext4/ext4.h
61846 +++ b/fs/ext4/ext4.h
61847 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61848 unsigned long s_mb_last_start;
61849
61850 /* stats for buddy allocator */
61851 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61852 - atomic_t s_bal_success; /* we found long enough chunks */
61853 - atomic_t s_bal_allocated; /* in blocks */
61854 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61855 - atomic_t s_bal_goals; /* goal hits */
61856 - atomic_t s_bal_breaks; /* too long searches */
61857 - atomic_t s_bal_2orders; /* 2^order hits */
61858 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61859 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61860 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61861 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61862 + atomic_unchecked_t s_bal_goals; /* goal hits */
61863 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61864 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61865 spinlock_t s_bal_lock;
61866 unsigned long s_mb_buddies_generated;
61867 unsigned long long s_mb_generation_time;
61868 - atomic_t s_mb_lost_chunks;
61869 - atomic_t s_mb_preallocated;
61870 - atomic_t s_mb_discarded;
61871 + atomic_unchecked_t s_mb_lost_chunks;
61872 + atomic_unchecked_t s_mb_preallocated;
61873 + atomic_unchecked_t s_mb_discarded;
61874 atomic_t s_lock_busy;
61875
61876 /* locality groups */
61877 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61878 index dbfe15c..9a6ee8d 100644
61879 --- a/fs/ext4/mballoc.c
61880 +++ b/fs/ext4/mballoc.c
61881 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61882 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61883
61884 if (EXT4_SB(sb)->s_mb_stats)
61885 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61886 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61887
61888 break;
61889 }
61890 @@ -2211,7 +2211,7 @@ repeat:
61891 ac->ac_status = AC_STATUS_CONTINUE;
61892 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61893 cr = 3;
61894 - atomic_inc(&sbi->s_mb_lost_chunks);
61895 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61896 goto repeat;
61897 }
61898 }
61899 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61900 if (sbi->s_mb_stats) {
61901 ext4_msg(sb, KERN_INFO,
61902 "mballoc: %u blocks %u reqs (%u success)",
61903 - atomic_read(&sbi->s_bal_allocated),
61904 - atomic_read(&sbi->s_bal_reqs),
61905 - atomic_read(&sbi->s_bal_success));
61906 + atomic_read_unchecked(&sbi->s_bal_allocated),
61907 + atomic_read_unchecked(&sbi->s_bal_reqs),
61908 + atomic_read_unchecked(&sbi->s_bal_success));
61909 ext4_msg(sb, KERN_INFO,
61910 "mballoc: %u extents scanned, %u goal hits, "
61911 "%u 2^N hits, %u breaks, %u lost",
61912 - atomic_read(&sbi->s_bal_ex_scanned),
61913 - atomic_read(&sbi->s_bal_goals),
61914 - atomic_read(&sbi->s_bal_2orders),
61915 - atomic_read(&sbi->s_bal_breaks),
61916 - atomic_read(&sbi->s_mb_lost_chunks));
61917 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61918 + atomic_read_unchecked(&sbi->s_bal_goals),
61919 + atomic_read_unchecked(&sbi->s_bal_2orders),
61920 + atomic_read_unchecked(&sbi->s_bal_breaks),
61921 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61922 ext4_msg(sb, KERN_INFO,
61923 "mballoc: %lu generated and it took %Lu",
61924 sbi->s_mb_buddies_generated,
61925 sbi->s_mb_generation_time);
61926 ext4_msg(sb, KERN_INFO,
61927 "mballoc: %u preallocated, %u discarded",
61928 - atomic_read(&sbi->s_mb_preallocated),
61929 - atomic_read(&sbi->s_mb_discarded));
61930 + atomic_read_unchecked(&sbi->s_mb_preallocated),
61931 + atomic_read_unchecked(&sbi->s_mb_discarded));
61932 }
61933
61934 free_percpu(sbi->s_locality_groups);
61935 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61936 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61937
61938 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61939 - atomic_inc(&sbi->s_bal_reqs);
61940 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61941 + atomic_inc_unchecked(&sbi->s_bal_reqs);
61942 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61943 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61944 - atomic_inc(&sbi->s_bal_success);
61945 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61946 + atomic_inc_unchecked(&sbi->s_bal_success);
61947 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61948 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61949 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61950 - atomic_inc(&sbi->s_bal_goals);
61951 + atomic_inc_unchecked(&sbi->s_bal_goals);
61952 if (ac->ac_found > sbi->s_mb_max_to_scan)
61953 - atomic_inc(&sbi->s_bal_breaks);
61954 + atomic_inc_unchecked(&sbi->s_bal_breaks);
61955 }
61956
61957 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61958 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61959 trace_ext4_mb_new_inode_pa(ac, pa);
61960
61961 ext4_mb_use_inode_pa(ac, pa);
61962 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61963 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61964
61965 ei = EXT4_I(ac->ac_inode);
61966 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61967 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61968 trace_ext4_mb_new_group_pa(ac, pa);
61969
61970 ext4_mb_use_group_pa(ac, pa);
61971 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61972 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61973
61974 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61975 lg = ac->ac_lg;
61976 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61977 * from the bitmap and continue.
61978 */
61979 }
61980 - atomic_add(free, &sbi->s_mb_discarded);
61981 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
61982
61983 return err;
61984 }
61985 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61986 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61987 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61988 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61989 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61990 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61991 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61992
61993 return 0;
61994 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61995 index 8313ca3..8a37d08 100644
61996 --- a/fs/ext4/mmp.c
61997 +++ b/fs/ext4/mmp.c
61998 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61999 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62000 const char *function, unsigned int line, const char *msg)
62001 {
62002 - __ext4_warning(sb, function, line, msg);
62003 + __ext4_warning(sb, function, line, "%s", msg);
62004 __ext4_warning(sb, function, line,
62005 "MMP failure info: last update time: %llu, last update "
62006 "node: %s, last update device: %s\n",
62007 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62008 index 2c9e686..6a40edc 100644
62009 --- a/fs/ext4/super.c
62010 +++ b/fs/ext4/super.c
62011 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62012 }
62013
62014 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62015 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62016 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62017 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62018
62019 #ifdef CONFIG_QUOTA
62020 @@ -2434,7 +2434,7 @@ struct ext4_attr {
62021 int offset;
62022 int deprecated_val;
62023 } u;
62024 -};
62025 +} __do_const;
62026
62027 static int parse_strtoull(const char *buf,
62028 unsigned long long max, unsigned long long *value)
62029 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62030 index 1e09fc7..0400dd4 100644
62031 --- a/fs/ext4/xattr.c
62032 +++ b/fs/ext4/xattr.c
62033 @@ -399,7 +399,7 @@ static int
62034 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62035 char *buffer, size_t buffer_size)
62036 {
62037 - size_t rest = buffer_size;
62038 + size_t rest = buffer_size, total_size = 0;
62039
62040 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62041 const struct xattr_handler *handler =
62042 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62043 buffer += size;
62044 }
62045 rest -= size;
62046 + total_size += size;
62047 }
62048 }
62049 - return buffer_size - rest;
62050 + return total_size;
62051 }
62052
62053 static int
62054 diff --git a/fs/fcntl.c b/fs/fcntl.c
62055 index 99d440a..eb979d1 100644
62056 --- a/fs/fcntl.c
62057 +++ b/fs/fcntl.c
62058 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62059 int force)
62060 {
62061 security_file_set_fowner(filp);
62062 + if (gr_handle_chroot_fowner(pid, type))
62063 + return;
62064 + if (gr_check_protected_task_fowner(pid, type))
62065 + return;
62066 f_modown(filp, pid, type, force);
62067 }
62068 EXPORT_SYMBOL(__f_setown);
62069 diff --git a/fs/fhandle.c b/fs/fhandle.c
62070 index 999ff5c..ac037c9 100644
62071 --- a/fs/fhandle.c
62072 +++ b/fs/fhandle.c
62073 @@ -8,6 +8,7 @@
62074 #include <linux/fs_struct.h>
62075 #include <linux/fsnotify.h>
62076 #include <linux/personality.h>
62077 +#include <linux/grsecurity.h>
62078 #include <asm/uaccess.h>
62079 #include "internal.h"
62080 #include "mount.h"
62081 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62082 } else
62083 retval = 0;
62084 /* copy the mount id */
62085 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62086 - sizeof(*mnt_id)) ||
62087 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62088 copy_to_user(ufh, handle,
62089 sizeof(struct file_handle) + handle_bytes))
62090 retval = -EFAULT;
62091 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62092 * the directory. Ideally we would like CAP_DAC_SEARCH.
62093 * But we don't have that
62094 */
62095 - if (!capable(CAP_DAC_READ_SEARCH)) {
62096 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62097 retval = -EPERM;
62098 goto out_err;
62099 }
62100 diff --git a/fs/file.c b/fs/file.c
62101 index ab3eb6a..8de2392 100644
62102 --- a/fs/file.c
62103 +++ b/fs/file.c
62104 @@ -16,6 +16,7 @@
62105 #include <linux/slab.h>
62106 #include <linux/vmalloc.h>
62107 #include <linux/file.h>
62108 +#include <linux/security.h>
62109 #include <linux/fdtable.h>
62110 #include <linux/bitops.h>
62111 #include <linux/interrupt.h>
62112 @@ -139,7 +140,7 @@ out:
62113 * Return <0 error code on error; 1 on successful completion.
62114 * The files->file_lock should be held on entry, and will be held on exit.
62115 */
62116 -static int expand_fdtable(struct files_struct *files, int nr)
62117 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62118 __releases(files->file_lock)
62119 __acquires(files->file_lock)
62120 {
62121 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62122 * expanded and execution may have blocked.
62123 * The files->file_lock should be held on entry, and will be held on exit.
62124 */
62125 -static int expand_files(struct files_struct *files, int nr)
62126 +static int expand_files(struct files_struct *files, unsigned int nr)
62127 {
62128 struct fdtable *fdt;
62129
62130 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62131 if (!file)
62132 return __close_fd(files, fd);
62133
62134 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62135 if (fd >= rlimit(RLIMIT_NOFILE))
62136 return -EBADF;
62137
62138 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62139 if (unlikely(oldfd == newfd))
62140 return -EINVAL;
62141
62142 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62143 if (newfd >= rlimit(RLIMIT_NOFILE))
62144 return -EBADF;
62145
62146 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62147 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62148 {
62149 int err;
62150 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62151 if (from >= rlimit(RLIMIT_NOFILE))
62152 return -EINVAL;
62153 err = alloc_fd(from, flags);
62154 diff --git a/fs/filesystems.c b/fs/filesystems.c
62155 index 5797d45..7d7d79a 100644
62156 --- a/fs/filesystems.c
62157 +++ b/fs/filesystems.c
62158 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62159 int len = dot ? dot - name : strlen(name);
62160
62161 fs = __get_fs_type(name, len);
62162 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62163 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62164 +#else
62165 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62166 +#endif
62167 fs = __get_fs_type(name, len);
62168
62169 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62170 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62171 index 7dca743..f5e007d 100644
62172 --- a/fs/fs_struct.c
62173 +++ b/fs/fs_struct.c
62174 @@ -4,6 +4,7 @@
62175 #include <linux/path.h>
62176 #include <linux/slab.h>
62177 #include <linux/fs_struct.h>
62178 +#include <linux/grsecurity.h>
62179 #include "internal.h"
62180
62181 /*
62182 @@ -15,14 +16,18 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62183 struct path old_root;
62184
62185 path_get(path);
62186 + gr_inc_chroot_refcnts(path->dentry, path->mnt);
62187 spin_lock(&fs->lock);
62188 write_seqcount_begin(&fs->seq);
62189 old_root = fs->root;
62190 fs->root = *path;
62191 + gr_set_chroot_entries(current, path);
62192 write_seqcount_end(&fs->seq);
62193 spin_unlock(&fs->lock);
62194 - if (old_root.dentry)
62195 + if (old_root.dentry) {
62196 + gr_inc_chroot_refcnts(old_root.dentry, old_root.mnt);
62197 path_put(&old_root);
62198 + }
62199 }
62200
62201 /*
62202 @@ -67,6 +72,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62203 int hits = 0;
62204 spin_lock(&fs->lock);
62205 write_seqcount_begin(&fs->seq);
62206 + /* this root replacement is only done by pivot_root,
62207 + leave grsec's chroot tagging alone for this task
62208 + so that a pivoted root isn't treated as a chroot
62209 + */
62210 hits += replace_path(&fs->root, old_root, new_root);
62211 hits += replace_path(&fs->pwd, old_root, new_root);
62212 write_seqcount_end(&fs->seq);
62213 @@ -85,6 +94,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62214
62215 void free_fs_struct(struct fs_struct *fs)
62216 {
62217 + gr_dec_chroot_refcnts(fs->root.dentry, fs->root.mnt);
62218 path_put(&fs->root);
62219 path_put(&fs->pwd);
62220 kmem_cache_free(fs_cachep, fs);
62221 @@ -99,7 +109,8 @@ void exit_fs(struct task_struct *tsk)
62222 task_lock(tsk);
62223 spin_lock(&fs->lock);
62224 tsk->fs = NULL;
62225 - kill = !--fs->users;
62226 + gr_clear_chroot_entries(tsk);
62227 + kill = !atomic_dec_return(&fs->users);
62228 spin_unlock(&fs->lock);
62229 task_unlock(tsk);
62230 if (kill)
62231 @@ -112,7 +123,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62232 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62233 /* We don't need to lock fs - think why ;-) */
62234 if (fs) {
62235 - fs->users = 1;
62236 + atomic_set(&fs->users, 1);
62237 fs->in_exec = 0;
62238 spin_lock_init(&fs->lock);
62239 seqcount_init(&fs->seq);
62240 @@ -121,6 +132,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62241 spin_lock(&old->lock);
62242 fs->root = old->root;
62243 path_get(&fs->root);
62244 + /* instead of calling gr_set_chroot_entries here,
62245 + we call it from every caller of this function
62246 + */
62247 fs->pwd = old->pwd;
62248 path_get(&fs->pwd);
62249 spin_unlock(&old->lock);
62250 @@ -139,8 +153,9 @@ int unshare_fs_struct(void)
62251
62252 task_lock(current);
62253 spin_lock(&fs->lock);
62254 - kill = !--fs->users;
62255 + kill = !atomic_dec_return(&fs->users);
62256 current->fs = new_fs;
62257 + gr_set_chroot_entries(current, &new_fs->root);
62258 spin_unlock(&fs->lock);
62259 task_unlock(current);
62260
62261 @@ -153,13 +168,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62262
62263 int current_umask(void)
62264 {
62265 - return current->fs->umask;
62266 + return current->fs->umask | gr_acl_umask();
62267 }
62268 EXPORT_SYMBOL(current_umask);
62269
62270 /* to be mentioned only in INIT_TASK */
62271 struct fs_struct init_fs = {
62272 - .users = 1,
62273 + .users = ATOMIC_INIT(1),
62274 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62275 .seq = SEQCNT_ZERO(init_fs.seq),
62276 .umask = 0022,
62277 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62278 index 89acec7..a575262 100644
62279 --- a/fs/fscache/cookie.c
62280 +++ b/fs/fscache/cookie.c
62281 @@ -19,7 +19,7 @@
62282
62283 struct kmem_cache *fscache_cookie_jar;
62284
62285 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62286 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62287
62288 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62289 static int fscache_alloc_object(struct fscache_cache *cache,
62290 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62291 parent ? (char *) parent->def->name : "<no-parent>",
62292 def->name, netfs_data, enable);
62293
62294 - fscache_stat(&fscache_n_acquires);
62295 + fscache_stat_unchecked(&fscache_n_acquires);
62296
62297 /* if there's no parent cookie, then we don't create one here either */
62298 if (!parent) {
62299 - fscache_stat(&fscache_n_acquires_null);
62300 + fscache_stat_unchecked(&fscache_n_acquires_null);
62301 _leave(" [no parent]");
62302 return NULL;
62303 }
62304 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62305 /* allocate and initialise a cookie */
62306 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62307 if (!cookie) {
62308 - fscache_stat(&fscache_n_acquires_oom);
62309 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62310 _leave(" [ENOMEM]");
62311 return NULL;
62312 }
62313 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62314
62315 switch (cookie->def->type) {
62316 case FSCACHE_COOKIE_TYPE_INDEX:
62317 - fscache_stat(&fscache_n_cookie_index);
62318 + fscache_stat_unchecked(&fscache_n_cookie_index);
62319 break;
62320 case FSCACHE_COOKIE_TYPE_DATAFILE:
62321 - fscache_stat(&fscache_n_cookie_data);
62322 + fscache_stat_unchecked(&fscache_n_cookie_data);
62323 break;
62324 default:
62325 - fscache_stat(&fscache_n_cookie_special);
62326 + fscache_stat_unchecked(&fscache_n_cookie_special);
62327 break;
62328 }
62329
62330 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62331 } else {
62332 atomic_dec(&parent->n_children);
62333 __fscache_cookie_put(cookie);
62334 - fscache_stat(&fscache_n_acquires_nobufs);
62335 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62336 _leave(" = NULL");
62337 return NULL;
62338 }
62339 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62340 }
62341 }
62342
62343 - fscache_stat(&fscache_n_acquires_ok);
62344 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62345 _leave(" = %p", cookie);
62346 return cookie;
62347 }
62348 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62349 cache = fscache_select_cache_for_object(cookie->parent);
62350 if (!cache) {
62351 up_read(&fscache_addremove_sem);
62352 - fscache_stat(&fscache_n_acquires_no_cache);
62353 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62354 _leave(" = -ENOMEDIUM [no cache]");
62355 return -ENOMEDIUM;
62356 }
62357 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62358 object = cache->ops->alloc_object(cache, cookie);
62359 fscache_stat_d(&fscache_n_cop_alloc_object);
62360 if (IS_ERR(object)) {
62361 - fscache_stat(&fscache_n_object_no_alloc);
62362 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62363 ret = PTR_ERR(object);
62364 goto error;
62365 }
62366
62367 - fscache_stat(&fscache_n_object_alloc);
62368 + fscache_stat_unchecked(&fscache_n_object_alloc);
62369
62370 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62371 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62372
62373 _debug("ALLOC OBJ%x: %s {%lx}",
62374 object->debug_id, cookie->def->name, object->events);
62375 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62376
62377 _enter("{%s}", cookie->def->name);
62378
62379 - fscache_stat(&fscache_n_invalidates);
62380 + fscache_stat_unchecked(&fscache_n_invalidates);
62381
62382 /* Only permit invalidation of data files. Invalidating an index will
62383 * require the caller to release all its attachments to the tree rooted
62384 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62385 {
62386 struct fscache_object *object;
62387
62388 - fscache_stat(&fscache_n_updates);
62389 + fscache_stat_unchecked(&fscache_n_updates);
62390
62391 if (!cookie) {
62392 - fscache_stat(&fscache_n_updates_null);
62393 + fscache_stat_unchecked(&fscache_n_updates_null);
62394 _leave(" [no cookie]");
62395 return;
62396 }
62397 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62398 */
62399 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62400 {
62401 - fscache_stat(&fscache_n_relinquishes);
62402 + fscache_stat_unchecked(&fscache_n_relinquishes);
62403 if (retire)
62404 - fscache_stat(&fscache_n_relinquishes_retire);
62405 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62406
62407 if (!cookie) {
62408 - fscache_stat(&fscache_n_relinquishes_null);
62409 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62410 _leave(" [no cookie]");
62411 return;
62412 }
62413 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62414 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62415 goto inconsistent;
62416
62417 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62418 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62419
62420 __fscache_use_cookie(cookie);
62421 if (fscache_submit_op(object, op) < 0)
62422 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62423 index 7872a62..d91b19f 100644
62424 --- a/fs/fscache/internal.h
62425 +++ b/fs/fscache/internal.h
62426 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62427 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62428 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62429 struct fscache_operation *,
62430 - atomic_t *,
62431 - atomic_t *,
62432 + atomic_unchecked_t *,
62433 + atomic_unchecked_t *,
62434 void (*)(struct fscache_operation *));
62435 extern void fscache_invalidate_writes(struct fscache_cookie *);
62436
62437 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62438 * stats.c
62439 */
62440 #ifdef CONFIG_FSCACHE_STATS
62441 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62442 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62443 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62444 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62445
62446 -extern atomic_t fscache_n_op_pend;
62447 -extern atomic_t fscache_n_op_run;
62448 -extern atomic_t fscache_n_op_enqueue;
62449 -extern atomic_t fscache_n_op_deferred_release;
62450 -extern atomic_t fscache_n_op_release;
62451 -extern atomic_t fscache_n_op_gc;
62452 -extern atomic_t fscache_n_op_cancelled;
62453 -extern atomic_t fscache_n_op_rejected;
62454 +extern atomic_unchecked_t fscache_n_op_pend;
62455 +extern atomic_unchecked_t fscache_n_op_run;
62456 +extern atomic_unchecked_t fscache_n_op_enqueue;
62457 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62458 +extern atomic_unchecked_t fscache_n_op_release;
62459 +extern atomic_unchecked_t fscache_n_op_gc;
62460 +extern atomic_unchecked_t fscache_n_op_cancelled;
62461 +extern atomic_unchecked_t fscache_n_op_rejected;
62462
62463 -extern atomic_t fscache_n_attr_changed;
62464 -extern atomic_t fscache_n_attr_changed_ok;
62465 -extern atomic_t fscache_n_attr_changed_nobufs;
62466 -extern atomic_t fscache_n_attr_changed_nomem;
62467 -extern atomic_t fscache_n_attr_changed_calls;
62468 +extern atomic_unchecked_t fscache_n_attr_changed;
62469 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62470 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62471 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62472 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62473
62474 -extern atomic_t fscache_n_allocs;
62475 -extern atomic_t fscache_n_allocs_ok;
62476 -extern atomic_t fscache_n_allocs_wait;
62477 -extern atomic_t fscache_n_allocs_nobufs;
62478 -extern atomic_t fscache_n_allocs_intr;
62479 -extern atomic_t fscache_n_allocs_object_dead;
62480 -extern atomic_t fscache_n_alloc_ops;
62481 -extern atomic_t fscache_n_alloc_op_waits;
62482 +extern atomic_unchecked_t fscache_n_allocs;
62483 +extern atomic_unchecked_t fscache_n_allocs_ok;
62484 +extern atomic_unchecked_t fscache_n_allocs_wait;
62485 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62486 +extern atomic_unchecked_t fscache_n_allocs_intr;
62487 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62488 +extern atomic_unchecked_t fscache_n_alloc_ops;
62489 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62490
62491 -extern atomic_t fscache_n_retrievals;
62492 -extern atomic_t fscache_n_retrievals_ok;
62493 -extern atomic_t fscache_n_retrievals_wait;
62494 -extern atomic_t fscache_n_retrievals_nodata;
62495 -extern atomic_t fscache_n_retrievals_nobufs;
62496 -extern atomic_t fscache_n_retrievals_intr;
62497 -extern atomic_t fscache_n_retrievals_nomem;
62498 -extern atomic_t fscache_n_retrievals_object_dead;
62499 -extern atomic_t fscache_n_retrieval_ops;
62500 -extern atomic_t fscache_n_retrieval_op_waits;
62501 +extern atomic_unchecked_t fscache_n_retrievals;
62502 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62503 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62504 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62505 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62506 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62507 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62508 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62509 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62510 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62511
62512 -extern atomic_t fscache_n_stores;
62513 -extern atomic_t fscache_n_stores_ok;
62514 -extern atomic_t fscache_n_stores_again;
62515 -extern atomic_t fscache_n_stores_nobufs;
62516 -extern atomic_t fscache_n_stores_oom;
62517 -extern atomic_t fscache_n_store_ops;
62518 -extern atomic_t fscache_n_store_calls;
62519 -extern atomic_t fscache_n_store_pages;
62520 -extern atomic_t fscache_n_store_radix_deletes;
62521 -extern atomic_t fscache_n_store_pages_over_limit;
62522 +extern atomic_unchecked_t fscache_n_stores;
62523 +extern atomic_unchecked_t fscache_n_stores_ok;
62524 +extern atomic_unchecked_t fscache_n_stores_again;
62525 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62526 +extern atomic_unchecked_t fscache_n_stores_oom;
62527 +extern atomic_unchecked_t fscache_n_store_ops;
62528 +extern atomic_unchecked_t fscache_n_store_calls;
62529 +extern atomic_unchecked_t fscache_n_store_pages;
62530 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62531 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62532
62533 -extern atomic_t fscache_n_store_vmscan_not_storing;
62534 -extern atomic_t fscache_n_store_vmscan_gone;
62535 -extern atomic_t fscache_n_store_vmscan_busy;
62536 -extern atomic_t fscache_n_store_vmscan_cancelled;
62537 -extern atomic_t fscache_n_store_vmscan_wait;
62538 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62539 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62540 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62541 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62542 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62543
62544 -extern atomic_t fscache_n_marks;
62545 -extern atomic_t fscache_n_uncaches;
62546 +extern atomic_unchecked_t fscache_n_marks;
62547 +extern atomic_unchecked_t fscache_n_uncaches;
62548
62549 -extern atomic_t fscache_n_acquires;
62550 -extern atomic_t fscache_n_acquires_null;
62551 -extern atomic_t fscache_n_acquires_no_cache;
62552 -extern atomic_t fscache_n_acquires_ok;
62553 -extern atomic_t fscache_n_acquires_nobufs;
62554 -extern atomic_t fscache_n_acquires_oom;
62555 +extern atomic_unchecked_t fscache_n_acquires;
62556 +extern atomic_unchecked_t fscache_n_acquires_null;
62557 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62558 +extern atomic_unchecked_t fscache_n_acquires_ok;
62559 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62560 +extern atomic_unchecked_t fscache_n_acquires_oom;
62561
62562 -extern atomic_t fscache_n_invalidates;
62563 -extern atomic_t fscache_n_invalidates_run;
62564 +extern atomic_unchecked_t fscache_n_invalidates;
62565 +extern atomic_unchecked_t fscache_n_invalidates_run;
62566
62567 -extern atomic_t fscache_n_updates;
62568 -extern atomic_t fscache_n_updates_null;
62569 -extern atomic_t fscache_n_updates_run;
62570 +extern atomic_unchecked_t fscache_n_updates;
62571 +extern atomic_unchecked_t fscache_n_updates_null;
62572 +extern atomic_unchecked_t fscache_n_updates_run;
62573
62574 -extern atomic_t fscache_n_relinquishes;
62575 -extern atomic_t fscache_n_relinquishes_null;
62576 -extern atomic_t fscache_n_relinquishes_waitcrt;
62577 -extern atomic_t fscache_n_relinquishes_retire;
62578 +extern atomic_unchecked_t fscache_n_relinquishes;
62579 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62580 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62581 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62582
62583 -extern atomic_t fscache_n_cookie_index;
62584 -extern atomic_t fscache_n_cookie_data;
62585 -extern atomic_t fscache_n_cookie_special;
62586 +extern atomic_unchecked_t fscache_n_cookie_index;
62587 +extern atomic_unchecked_t fscache_n_cookie_data;
62588 +extern atomic_unchecked_t fscache_n_cookie_special;
62589
62590 -extern atomic_t fscache_n_object_alloc;
62591 -extern atomic_t fscache_n_object_no_alloc;
62592 -extern atomic_t fscache_n_object_lookups;
62593 -extern atomic_t fscache_n_object_lookups_negative;
62594 -extern atomic_t fscache_n_object_lookups_positive;
62595 -extern atomic_t fscache_n_object_lookups_timed_out;
62596 -extern atomic_t fscache_n_object_created;
62597 -extern atomic_t fscache_n_object_avail;
62598 -extern atomic_t fscache_n_object_dead;
62599 +extern atomic_unchecked_t fscache_n_object_alloc;
62600 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62601 +extern atomic_unchecked_t fscache_n_object_lookups;
62602 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62603 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62604 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62605 +extern atomic_unchecked_t fscache_n_object_created;
62606 +extern atomic_unchecked_t fscache_n_object_avail;
62607 +extern atomic_unchecked_t fscache_n_object_dead;
62608
62609 -extern atomic_t fscache_n_checkaux_none;
62610 -extern atomic_t fscache_n_checkaux_okay;
62611 -extern atomic_t fscache_n_checkaux_update;
62612 -extern atomic_t fscache_n_checkaux_obsolete;
62613 +extern atomic_unchecked_t fscache_n_checkaux_none;
62614 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62615 +extern atomic_unchecked_t fscache_n_checkaux_update;
62616 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62617
62618 extern atomic_t fscache_n_cop_alloc_object;
62619 extern atomic_t fscache_n_cop_lookup_object;
62620 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62621 atomic_inc(stat);
62622 }
62623
62624 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62625 +{
62626 + atomic_inc_unchecked(stat);
62627 +}
62628 +
62629 static inline void fscache_stat_d(atomic_t *stat)
62630 {
62631 atomic_dec(stat);
62632 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62633
62634 #define __fscache_stat(stat) (NULL)
62635 #define fscache_stat(stat) do {} while (0)
62636 +#define fscache_stat_unchecked(stat) do {} while (0)
62637 #define fscache_stat_d(stat) do {} while (0)
62638 #endif
62639
62640 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62641 index da032da..0076ce7 100644
62642 --- a/fs/fscache/object.c
62643 +++ b/fs/fscache/object.c
62644 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62645 _debug("LOOKUP \"%s\" in \"%s\"",
62646 cookie->def->name, object->cache->tag->name);
62647
62648 - fscache_stat(&fscache_n_object_lookups);
62649 + fscache_stat_unchecked(&fscache_n_object_lookups);
62650 fscache_stat(&fscache_n_cop_lookup_object);
62651 ret = object->cache->ops->lookup_object(object);
62652 fscache_stat_d(&fscache_n_cop_lookup_object);
62653 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62654 if (ret == -ETIMEDOUT) {
62655 /* probably stuck behind another object, so move this one to
62656 * the back of the queue */
62657 - fscache_stat(&fscache_n_object_lookups_timed_out);
62658 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62659 _leave(" [timeout]");
62660 return NO_TRANSIT;
62661 }
62662 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62663 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62664
62665 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62666 - fscache_stat(&fscache_n_object_lookups_negative);
62667 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62668
62669 /* Allow write requests to begin stacking up and read requests to begin
62670 * returning ENODATA.
62671 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62672 /* if we were still looking up, then we must have a positive lookup
62673 * result, in which case there may be data available */
62674 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62675 - fscache_stat(&fscache_n_object_lookups_positive);
62676 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62677
62678 /* We do (presumably) have data */
62679 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62680 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62681 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62682 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62683 } else {
62684 - fscache_stat(&fscache_n_object_created);
62685 + fscache_stat_unchecked(&fscache_n_object_created);
62686 }
62687
62688 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62689 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62690 fscache_stat_d(&fscache_n_cop_lookup_complete);
62691
62692 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62693 - fscache_stat(&fscache_n_object_avail);
62694 + fscache_stat_unchecked(&fscache_n_object_avail);
62695
62696 _leave("");
62697 return transit_to(JUMPSTART_DEPS);
62698 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62699
62700 /* this just shifts the object release to the work processor */
62701 fscache_put_object(object);
62702 - fscache_stat(&fscache_n_object_dead);
62703 + fscache_stat_unchecked(&fscache_n_object_dead);
62704
62705 _leave("");
62706 return transit_to(OBJECT_DEAD);
62707 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62708 enum fscache_checkaux result;
62709
62710 if (!object->cookie->def->check_aux) {
62711 - fscache_stat(&fscache_n_checkaux_none);
62712 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62713 return FSCACHE_CHECKAUX_OKAY;
62714 }
62715
62716 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62717 switch (result) {
62718 /* entry okay as is */
62719 case FSCACHE_CHECKAUX_OKAY:
62720 - fscache_stat(&fscache_n_checkaux_okay);
62721 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62722 break;
62723
62724 /* entry requires update */
62725 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62726 - fscache_stat(&fscache_n_checkaux_update);
62727 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62728 break;
62729
62730 /* entry requires deletion */
62731 case FSCACHE_CHECKAUX_OBSOLETE:
62732 - fscache_stat(&fscache_n_checkaux_obsolete);
62733 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62734 break;
62735
62736 default:
62737 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62738 {
62739 const struct fscache_state *s;
62740
62741 - fscache_stat(&fscache_n_invalidates_run);
62742 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62743 fscache_stat(&fscache_n_cop_invalidate_object);
62744 s = _fscache_invalidate_object(object, event);
62745 fscache_stat_d(&fscache_n_cop_invalidate_object);
62746 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62747 {
62748 _enter("{OBJ%x},%d", object->debug_id, event);
62749
62750 - fscache_stat(&fscache_n_updates_run);
62751 + fscache_stat_unchecked(&fscache_n_updates_run);
62752 fscache_stat(&fscache_n_cop_update_object);
62753 object->cache->ops->update_object(object);
62754 fscache_stat_d(&fscache_n_cop_update_object);
62755 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62756 index e7b87a0..a85d47a 100644
62757 --- a/fs/fscache/operation.c
62758 +++ b/fs/fscache/operation.c
62759 @@ -17,7 +17,7 @@
62760 #include <linux/slab.h>
62761 #include "internal.h"
62762
62763 -atomic_t fscache_op_debug_id;
62764 +atomic_unchecked_t fscache_op_debug_id;
62765 EXPORT_SYMBOL(fscache_op_debug_id);
62766
62767 /**
62768 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62769 ASSERTCMP(atomic_read(&op->usage), >, 0);
62770 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62771
62772 - fscache_stat(&fscache_n_op_enqueue);
62773 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62774 switch (op->flags & FSCACHE_OP_TYPE) {
62775 case FSCACHE_OP_ASYNC:
62776 _debug("queue async");
62777 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62778 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62779 if (op->processor)
62780 fscache_enqueue_operation(op);
62781 - fscache_stat(&fscache_n_op_run);
62782 + fscache_stat_unchecked(&fscache_n_op_run);
62783 }
62784
62785 /*
62786 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62787 if (object->n_in_progress > 0) {
62788 atomic_inc(&op->usage);
62789 list_add_tail(&op->pend_link, &object->pending_ops);
62790 - fscache_stat(&fscache_n_op_pend);
62791 + fscache_stat_unchecked(&fscache_n_op_pend);
62792 } else if (!list_empty(&object->pending_ops)) {
62793 atomic_inc(&op->usage);
62794 list_add_tail(&op->pend_link, &object->pending_ops);
62795 - fscache_stat(&fscache_n_op_pend);
62796 + fscache_stat_unchecked(&fscache_n_op_pend);
62797 fscache_start_operations(object);
62798 } else {
62799 ASSERTCMP(object->n_in_progress, ==, 0);
62800 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62801 object->n_exclusive++; /* reads and writes must wait */
62802 atomic_inc(&op->usage);
62803 list_add_tail(&op->pend_link, &object->pending_ops);
62804 - fscache_stat(&fscache_n_op_pend);
62805 + fscache_stat_unchecked(&fscache_n_op_pend);
62806 ret = 0;
62807 } else {
62808 /* If we're in any other state, there must have been an I/O
62809 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62810 if (object->n_exclusive > 0) {
62811 atomic_inc(&op->usage);
62812 list_add_tail(&op->pend_link, &object->pending_ops);
62813 - fscache_stat(&fscache_n_op_pend);
62814 + fscache_stat_unchecked(&fscache_n_op_pend);
62815 } else if (!list_empty(&object->pending_ops)) {
62816 atomic_inc(&op->usage);
62817 list_add_tail(&op->pend_link, &object->pending_ops);
62818 - fscache_stat(&fscache_n_op_pend);
62819 + fscache_stat_unchecked(&fscache_n_op_pend);
62820 fscache_start_operations(object);
62821 } else {
62822 ASSERTCMP(object->n_exclusive, ==, 0);
62823 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62824 object->n_ops++;
62825 atomic_inc(&op->usage);
62826 list_add_tail(&op->pend_link, &object->pending_ops);
62827 - fscache_stat(&fscache_n_op_pend);
62828 + fscache_stat_unchecked(&fscache_n_op_pend);
62829 ret = 0;
62830 } else if (fscache_object_is_dying(object)) {
62831 - fscache_stat(&fscache_n_op_rejected);
62832 + fscache_stat_unchecked(&fscache_n_op_rejected);
62833 op->state = FSCACHE_OP_ST_CANCELLED;
62834 ret = -ENOBUFS;
62835 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62836 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62837 ret = -EBUSY;
62838 if (op->state == FSCACHE_OP_ST_PENDING) {
62839 ASSERT(!list_empty(&op->pend_link));
62840 - fscache_stat(&fscache_n_op_cancelled);
62841 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62842 list_del_init(&op->pend_link);
62843 if (do_cancel)
62844 do_cancel(op);
62845 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62846 while (!list_empty(&object->pending_ops)) {
62847 op = list_entry(object->pending_ops.next,
62848 struct fscache_operation, pend_link);
62849 - fscache_stat(&fscache_n_op_cancelled);
62850 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62851 list_del_init(&op->pend_link);
62852
62853 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62854 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62855 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62856 op->state = FSCACHE_OP_ST_DEAD;
62857
62858 - fscache_stat(&fscache_n_op_release);
62859 + fscache_stat_unchecked(&fscache_n_op_release);
62860
62861 if (op->release) {
62862 op->release(op);
62863 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62864 * lock, and defer it otherwise */
62865 if (!spin_trylock(&object->lock)) {
62866 _debug("defer put");
62867 - fscache_stat(&fscache_n_op_deferred_release);
62868 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62869
62870 cache = object->cache;
62871 spin_lock(&cache->op_gc_list_lock);
62872 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62873
62874 _debug("GC DEFERRED REL OBJ%x OP%x",
62875 object->debug_id, op->debug_id);
62876 - fscache_stat(&fscache_n_op_gc);
62877 + fscache_stat_unchecked(&fscache_n_op_gc);
62878
62879 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62880 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62881 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62882 index de33b3f..8be4d29 100644
62883 --- a/fs/fscache/page.c
62884 +++ b/fs/fscache/page.c
62885 @@ -74,7 +74,7 @@ try_again:
62886 val = radix_tree_lookup(&cookie->stores, page->index);
62887 if (!val) {
62888 rcu_read_unlock();
62889 - fscache_stat(&fscache_n_store_vmscan_not_storing);
62890 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62891 __fscache_uncache_page(cookie, page);
62892 return true;
62893 }
62894 @@ -104,11 +104,11 @@ try_again:
62895 spin_unlock(&cookie->stores_lock);
62896
62897 if (xpage) {
62898 - fscache_stat(&fscache_n_store_vmscan_cancelled);
62899 - fscache_stat(&fscache_n_store_radix_deletes);
62900 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62901 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62902 ASSERTCMP(xpage, ==, page);
62903 } else {
62904 - fscache_stat(&fscache_n_store_vmscan_gone);
62905 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62906 }
62907
62908 wake_up_bit(&cookie->flags, 0);
62909 @@ -123,11 +123,11 @@ page_busy:
62910 * sleeping on memory allocation, so we may need to impose a timeout
62911 * too. */
62912 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62913 - fscache_stat(&fscache_n_store_vmscan_busy);
62914 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62915 return false;
62916 }
62917
62918 - fscache_stat(&fscache_n_store_vmscan_wait);
62919 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62920 if (!release_page_wait_timeout(cookie, page))
62921 _debug("fscache writeout timeout page: %p{%lx}",
62922 page, page->index);
62923 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62924 FSCACHE_COOKIE_STORING_TAG);
62925 if (!radix_tree_tag_get(&cookie->stores, page->index,
62926 FSCACHE_COOKIE_PENDING_TAG)) {
62927 - fscache_stat(&fscache_n_store_radix_deletes);
62928 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62929 xpage = radix_tree_delete(&cookie->stores, page->index);
62930 }
62931 spin_unlock(&cookie->stores_lock);
62932 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62933
62934 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62935
62936 - fscache_stat(&fscache_n_attr_changed_calls);
62937 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62938
62939 if (fscache_object_is_active(object)) {
62940 fscache_stat(&fscache_n_cop_attr_changed);
62941 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62942
62943 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62944
62945 - fscache_stat(&fscache_n_attr_changed);
62946 + fscache_stat_unchecked(&fscache_n_attr_changed);
62947
62948 op = kzalloc(sizeof(*op), GFP_KERNEL);
62949 if (!op) {
62950 - fscache_stat(&fscache_n_attr_changed_nomem);
62951 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62952 _leave(" = -ENOMEM");
62953 return -ENOMEM;
62954 }
62955 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62956 if (fscache_submit_exclusive_op(object, op) < 0)
62957 goto nobufs_dec;
62958 spin_unlock(&cookie->lock);
62959 - fscache_stat(&fscache_n_attr_changed_ok);
62960 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62961 fscache_put_operation(op);
62962 _leave(" = 0");
62963 return 0;
62964 @@ -242,7 +242,7 @@ nobufs:
62965 kfree(op);
62966 if (wake_cookie)
62967 __fscache_wake_unused_cookie(cookie);
62968 - fscache_stat(&fscache_n_attr_changed_nobufs);
62969 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62970 _leave(" = %d", -ENOBUFS);
62971 return -ENOBUFS;
62972 }
62973 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62974 /* allocate a retrieval operation and attempt to submit it */
62975 op = kzalloc(sizeof(*op), GFP_NOIO);
62976 if (!op) {
62977 - fscache_stat(&fscache_n_retrievals_nomem);
62978 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62979 return NULL;
62980 }
62981
62982 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62983 return 0;
62984 }
62985
62986 - fscache_stat(&fscache_n_retrievals_wait);
62987 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
62988
62989 jif = jiffies;
62990 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62991 TASK_INTERRUPTIBLE) != 0) {
62992 - fscache_stat(&fscache_n_retrievals_intr);
62993 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
62994 _leave(" = -ERESTARTSYS");
62995 return -ERESTARTSYS;
62996 }
62997 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62998 */
62999 int fscache_wait_for_operation_activation(struct fscache_object *object,
63000 struct fscache_operation *op,
63001 - atomic_t *stat_op_waits,
63002 - atomic_t *stat_object_dead,
63003 + atomic_unchecked_t *stat_op_waits,
63004 + atomic_unchecked_t *stat_object_dead,
63005 void (*do_cancel)(struct fscache_operation *))
63006 {
63007 int ret;
63008 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63009
63010 _debug(">>> WT");
63011 if (stat_op_waits)
63012 - fscache_stat(stat_op_waits);
63013 + fscache_stat_unchecked(stat_op_waits);
63014 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63015 TASK_INTERRUPTIBLE) != 0) {
63016 ret = fscache_cancel_op(op, do_cancel);
63017 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63018 check_if_dead:
63019 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63020 if (stat_object_dead)
63021 - fscache_stat(stat_object_dead);
63022 + fscache_stat_unchecked(stat_object_dead);
63023 _leave(" = -ENOBUFS [cancelled]");
63024 return -ENOBUFS;
63025 }
63026 @@ -381,7 +381,7 @@ check_if_dead:
63027 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63028 fscache_cancel_op(op, do_cancel);
63029 if (stat_object_dead)
63030 - fscache_stat(stat_object_dead);
63031 + fscache_stat_unchecked(stat_object_dead);
63032 return -ENOBUFS;
63033 }
63034 return 0;
63035 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63036
63037 _enter("%p,%p,,,", cookie, page);
63038
63039 - fscache_stat(&fscache_n_retrievals);
63040 + fscache_stat_unchecked(&fscache_n_retrievals);
63041
63042 if (hlist_empty(&cookie->backing_objects))
63043 goto nobufs;
63044 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63045 goto nobufs_unlock_dec;
63046 spin_unlock(&cookie->lock);
63047
63048 - fscache_stat(&fscache_n_retrieval_ops);
63049 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63050
63051 /* pin the netfs read context in case we need to do the actual netfs
63052 * read because we've encountered a cache read failure */
63053 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63054
63055 error:
63056 if (ret == -ENOMEM)
63057 - fscache_stat(&fscache_n_retrievals_nomem);
63058 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63059 else if (ret == -ERESTARTSYS)
63060 - fscache_stat(&fscache_n_retrievals_intr);
63061 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63062 else if (ret == -ENODATA)
63063 - fscache_stat(&fscache_n_retrievals_nodata);
63064 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63065 else if (ret < 0)
63066 - fscache_stat(&fscache_n_retrievals_nobufs);
63067 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63068 else
63069 - fscache_stat(&fscache_n_retrievals_ok);
63070 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63071
63072 fscache_put_retrieval(op);
63073 _leave(" = %d", ret);
63074 @@ -505,7 +505,7 @@ nobufs_unlock:
63075 __fscache_wake_unused_cookie(cookie);
63076 kfree(op);
63077 nobufs:
63078 - fscache_stat(&fscache_n_retrievals_nobufs);
63079 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63080 _leave(" = -ENOBUFS");
63081 return -ENOBUFS;
63082 }
63083 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63084
63085 _enter("%p,,%d,,,", cookie, *nr_pages);
63086
63087 - fscache_stat(&fscache_n_retrievals);
63088 + fscache_stat_unchecked(&fscache_n_retrievals);
63089
63090 if (hlist_empty(&cookie->backing_objects))
63091 goto nobufs;
63092 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63093 goto nobufs_unlock_dec;
63094 spin_unlock(&cookie->lock);
63095
63096 - fscache_stat(&fscache_n_retrieval_ops);
63097 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63098
63099 /* pin the netfs read context in case we need to do the actual netfs
63100 * read because we've encountered a cache read failure */
63101 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63102
63103 error:
63104 if (ret == -ENOMEM)
63105 - fscache_stat(&fscache_n_retrievals_nomem);
63106 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63107 else if (ret == -ERESTARTSYS)
63108 - fscache_stat(&fscache_n_retrievals_intr);
63109 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63110 else if (ret == -ENODATA)
63111 - fscache_stat(&fscache_n_retrievals_nodata);
63112 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63113 else if (ret < 0)
63114 - fscache_stat(&fscache_n_retrievals_nobufs);
63115 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63116 else
63117 - fscache_stat(&fscache_n_retrievals_ok);
63118 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63119
63120 fscache_put_retrieval(op);
63121 _leave(" = %d", ret);
63122 @@ -636,7 +636,7 @@ nobufs_unlock:
63123 if (wake_cookie)
63124 __fscache_wake_unused_cookie(cookie);
63125 nobufs:
63126 - fscache_stat(&fscache_n_retrievals_nobufs);
63127 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63128 _leave(" = -ENOBUFS");
63129 return -ENOBUFS;
63130 }
63131 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63132
63133 _enter("%p,%p,,,", cookie, page);
63134
63135 - fscache_stat(&fscache_n_allocs);
63136 + fscache_stat_unchecked(&fscache_n_allocs);
63137
63138 if (hlist_empty(&cookie->backing_objects))
63139 goto nobufs;
63140 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63141 goto nobufs_unlock_dec;
63142 spin_unlock(&cookie->lock);
63143
63144 - fscache_stat(&fscache_n_alloc_ops);
63145 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63146
63147 ret = fscache_wait_for_operation_activation(
63148 object, &op->op,
63149 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63150
63151 error:
63152 if (ret == -ERESTARTSYS)
63153 - fscache_stat(&fscache_n_allocs_intr);
63154 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63155 else if (ret < 0)
63156 - fscache_stat(&fscache_n_allocs_nobufs);
63157 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63158 else
63159 - fscache_stat(&fscache_n_allocs_ok);
63160 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63161
63162 fscache_put_retrieval(op);
63163 _leave(" = %d", ret);
63164 @@ -730,7 +730,7 @@ nobufs_unlock:
63165 if (wake_cookie)
63166 __fscache_wake_unused_cookie(cookie);
63167 nobufs:
63168 - fscache_stat(&fscache_n_allocs_nobufs);
63169 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63170 _leave(" = -ENOBUFS");
63171 return -ENOBUFS;
63172 }
63173 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63174
63175 spin_lock(&cookie->stores_lock);
63176
63177 - fscache_stat(&fscache_n_store_calls);
63178 + fscache_stat_unchecked(&fscache_n_store_calls);
63179
63180 /* find a page to store */
63181 page = NULL;
63182 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63183 page = results[0];
63184 _debug("gang %d [%lx]", n, page->index);
63185 if (page->index > op->store_limit) {
63186 - fscache_stat(&fscache_n_store_pages_over_limit);
63187 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63188 goto superseded;
63189 }
63190
63191 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63192 spin_unlock(&cookie->stores_lock);
63193 spin_unlock(&object->lock);
63194
63195 - fscache_stat(&fscache_n_store_pages);
63196 + fscache_stat_unchecked(&fscache_n_store_pages);
63197 fscache_stat(&fscache_n_cop_write_page);
63198 ret = object->cache->ops->write_page(op, page);
63199 fscache_stat_d(&fscache_n_cop_write_page);
63200 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63201 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63202 ASSERT(PageFsCache(page));
63203
63204 - fscache_stat(&fscache_n_stores);
63205 + fscache_stat_unchecked(&fscache_n_stores);
63206
63207 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63208 _leave(" = -ENOBUFS [invalidating]");
63209 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63210 spin_unlock(&cookie->stores_lock);
63211 spin_unlock(&object->lock);
63212
63213 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63214 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63215 op->store_limit = object->store_limit;
63216
63217 __fscache_use_cookie(cookie);
63218 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63219
63220 spin_unlock(&cookie->lock);
63221 radix_tree_preload_end();
63222 - fscache_stat(&fscache_n_store_ops);
63223 - fscache_stat(&fscache_n_stores_ok);
63224 + fscache_stat_unchecked(&fscache_n_store_ops);
63225 + fscache_stat_unchecked(&fscache_n_stores_ok);
63226
63227 /* the work queue now carries its own ref on the object */
63228 fscache_put_operation(&op->op);
63229 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63230 return 0;
63231
63232 already_queued:
63233 - fscache_stat(&fscache_n_stores_again);
63234 + fscache_stat_unchecked(&fscache_n_stores_again);
63235 already_pending:
63236 spin_unlock(&cookie->stores_lock);
63237 spin_unlock(&object->lock);
63238 spin_unlock(&cookie->lock);
63239 radix_tree_preload_end();
63240 kfree(op);
63241 - fscache_stat(&fscache_n_stores_ok);
63242 + fscache_stat_unchecked(&fscache_n_stores_ok);
63243 _leave(" = 0");
63244 return 0;
63245
63246 @@ -1039,14 +1039,14 @@ nobufs:
63247 kfree(op);
63248 if (wake_cookie)
63249 __fscache_wake_unused_cookie(cookie);
63250 - fscache_stat(&fscache_n_stores_nobufs);
63251 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63252 _leave(" = -ENOBUFS");
63253 return -ENOBUFS;
63254
63255 nomem_free:
63256 kfree(op);
63257 nomem:
63258 - fscache_stat(&fscache_n_stores_oom);
63259 + fscache_stat_unchecked(&fscache_n_stores_oom);
63260 _leave(" = -ENOMEM");
63261 return -ENOMEM;
63262 }
63263 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63264 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63265 ASSERTCMP(page, !=, NULL);
63266
63267 - fscache_stat(&fscache_n_uncaches);
63268 + fscache_stat_unchecked(&fscache_n_uncaches);
63269
63270 /* cache withdrawal may beat us to it */
63271 if (!PageFsCache(page))
63272 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63273 struct fscache_cookie *cookie = op->op.object->cookie;
63274
63275 #ifdef CONFIG_FSCACHE_STATS
63276 - atomic_inc(&fscache_n_marks);
63277 + atomic_inc_unchecked(&fscache_n_marks);
63278 #endif
63279
63280 _debug("- mark %p{%lx}", page, page->index);
63281 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63282 index 40d13c7..ddf52b9 100644
63283 --- a/fs/fscache/stats.c
63284 +++ b/fs/fscache/stats.c
63285 @@ -18,99 +18,99 @@
63286 /*
63287 * operation counters
63288 */
63289 -atomic_t fscache_n_op_pend;
63290 -atomic_t fscache_n_op_run;
63291 -atomic_t fscache_n_op_enqueue;
63292 -atomic_t fscache_n_op_requeue;
63293 -atomic_t fscache_n_op_deferred_release;
63294 -atomic_t fscache_n_op_release;
63295 -atomic_t fscache_n_op_gc;
63296 -atomic_t fscache_n_op_cancelled;
63297 -atomic_t fscache_n_op_rejected;
63298 +atomic_unchecked_t fscache_n_op_pend;
63299 +atomic_unchecked_t fscache_n_op_run;
63300 +atomic_unchecked_t fscache_n_op_enqueue;
63301 +atomic_unchecked_t fscache_n_op_requeue;
63302 +atomic_unchecked_t fscache_n_op_deferred_release;
63303 +atomic_unchecked_t fscache_n_op_release;
63304 +atomic_unchecked_t fscache_n_op_gc;
63305 +atomic_unchecked_t fscache_n_op_cancelled;
63306 +atomic_unchecked_t fscache_n_op_rejected;
63307
63308 -atomic_t fscache_n_attr_changed;
63309 -atomic_t fscache_n_attr_changed_ok;
63310 -atomic_t fscache_n_attr_changed_nobufs;
63311 -atomic_t fscache_n_attr_changed_nomem;
63312 -atomic_t fscache_n_attr_changed_calls;
63313 +atomic_unchecked_t fscache_n_attr_changed;
63314 +atomic_unchecked_t fscache_n_attr_changed_ok;
63315 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63316 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63317 +atomic_unchecked_t fscache_n_attr_changed_calls;
63318
63319 -atomic_t fscache_n_allocs;
63320 -atomic_t fscache_n_allocs_ok;
63321 -atomic_t fscache_n_allocs_wait;
63322 -atomic_t fscache_n_allocs_nobufs;
63323 -atomic_t fscache_n_allocs_intr;
63324 -atomic_t fscache_n_allocs_object_dead;
63325 -atomic_t fscache_n_alloc_ops;
63326 -atomic_t fscache_n_alloc_op_waits;
63327 +atomic_unchecked_t fscache_n_allocs;
63328 +atomic_unchecked_t fscache_n_allocs_ok;
63329 +atomic_unchecked_t fscache_n_allocs_wait;
63330 +atomic_unchecked_t fscache_n_allocs_nobufs;
63331 +atomic_unchecked_t fscache_n_allocs_intr;
63332 +atomic_unchecked_t fscache_n_allocs_object_dead;
63333 +atomic_unchecked_t fscache_n_alloc_ops;
63334 +atomic_unchecked_t fscache_n_alloc_op_waits;
63335
63336 -atomic_t fscache_n_retrievals;
63337 -atomic_t fscache_n_retrievals_ok;
63338 -atomic_t fscache_n_retrievals_wait;
63339 -atomic_t fscache_n_retrievals_nodata;
63340 -atomic_t fscache_n_retrievals_nobufs;
63341 -atomic_t fscache_n_retrievals_intr;
63342 -atomic_t fscache_n_retrievals_nomem;
63343 -atomic_t fscache_n_retrievals_object_dead;
63344 -atomic_t fscache_n_retrieval_ops;
63345 -atomic_t fscache_n_retrieval_op_waits;
63346 +atomic_unchecked_t fscache_n_retrievals;
63347 +atomic_unchecked_t fscache_n_retrievals_ok;
63348 +atomic_unchecked_t fscache_n_retrievals_wait;
63349 +atomic_unchecked_t fscache_n_retrievals_nodata;
63350 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63351 +atomic_unchecked_t fscache_n_retrievals_intr;
63352 +atomic_unchecked_t fscache_n_retrievals_nomem;
63353 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63354 +atomic_unchecked_t fscache_n_retrieval_ops;
63355 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63356
63357 -atomic_t fscache_n_stores;
63358 -atomic_t fscache_n_stores_ok;
63359 -atomic_t fscache_n_stores_again;
63360 -atomic_t fscache_n_stores_nobufs;
63361 -atomic_t fscache_n_stores_oom;
63362 -atomic_t fscache_n_store_ops;
63363 -atomic_t fscache_n_store_calls;
63364 -atomic_t fscache_n_store_pages;
63365 -atomic_t fscache_n_store_radix_deletes;
63366 -atomic_t fscache_n_store_pages_over_limit;
63367 +atomic_unchecked_t fscache_n_stores;
63368 +atomic_unchecked_t fscache_n_stores_ok;
63369 +atomic_unchecked_t fscache_n_stores_again;
63370 +atomic_unchecked_t fscache_n_stores_nobufs;
63371 +atomic_unchecked_t fscache_n_stores_oom;
63372 +atomic_unchecked_t fscache_n_store_ops;
63373 +atomic_unchecked_t fscache_n_store_calls;
63374 +atomic_unchecked_t fscache_n_store_pages;
63375 +atomic_unchecked_t fscache_n_store_radix_deletes;
63376 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63377
63378 -atomic_t fscache_n_store_vmscan_not_storing;
63379 -atomic_t fscache_n_store_vmscan_gone;
63380 -atomic_t fscache_n_store_vmscan_busy;
63381 -atomic_t fscache_n_store_vmscan_cancelled;
63382 -atomic_t fscache_n_store_vmscan_wait;
63383 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63384 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63385 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63386 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63387 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63388
63389 -atomic_t fscache_n_marks;
63390 -atomic_t fscache_n_uncaches;
63391 +atomic_unchecked_t fscache_n_marks;
63392 +atomic_unchecked_t fscache_n_uncaches;
63393
63394 -atomic_t fscache_n_acquires;
63395 -atomic_t fscache_n_acquires_null;
63396 -atomic_t fscache_n_acquires_no_cache;
63397 -atomic_t fscache_n_acquires_ok;
63398 -atomic_t fscache_n_acquires_nobufs;
63399 -atomic_t fscache_n_acquires_oom;
63400 +atomic_unchecked_t fscache_n_acquires;
63401 +atomic_unchecked_t fscache_n_acquires_null;
63402 +atomic_unchecked_t fscache_n_acquires_no_cache;
63403 +atomic_unchecked_t fscache_n_acquires_ok;
63404 +atomic_unchecked_t fscache_n_acquires_nobufs;
63405 +atomic_unchecked_t fscache_n_acquires_oom;
63406
63407 -atomic_t fscache_n_invalidates;
63408 -atomic_t fscache_n_invalidates_run;
63409 +atomic_unchecked_t fscache_n_invalidates;
63410 +atomic_unchecked_t fscache_n_invalidates_run;
63411
63412 -atomic_t fscache_n_updates;
63413 -atomic_t fscache_n_updates_null;
63414 -atomic_t fscache_n_updates_run;
63415 +atomic_unchecked_t fscache_n_updates;
63416 +atomic_unchecked_t fscache_n_updates_null;
63417 +atomic_unchecked_t fscache_n_updates_run;
63418
63419 -atomic_t fscache_n_relinquishes;
63420 -atomic_t fscache_n_relinquishes_null;
63421 -atomic_t fscache_n_relinquishes_waitcrt;
63422 -atomic_t fscache_n_relinquishes_retire;
63423 +atomic_unchecked_t fscache_n_relinquishes;
63424 +atomic_unchecked_t fscache_n_relinquishes_null;
63425 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63426 +atomic_unchecked_t fscache_n_relinquishes_retire;
63427
63428 -atomic_t fscache_n_cookie_index;
63429 -atomic_t fscache_n_cookie_data;
63430 -atomic_t fscache_n_cookie_special;
63431 +atomic_unchecked_t fscache_n_cookie_index;
63432 +atomic_unchecked_t fscache_n_cookie_data;
63433 +atomic_unchecked_t fscache_n_cookie_special;
63434
63435 -atomic_t fscache_n_object_alloc;
63436 -atomic_t fscache_n_object_no_alloc;
63437 -atomic_t fscache_n_object_lookups;
63438 -atomic_t fscache_n_object_lookups_negative;
63439 -atomic_t fscache_n_object_lookups_positive;
63440 -atomic_t fscache_n_object_lookups_timed_out;
63441 -atomic_t fscache_n_object_created;
63442 -atomic_t fscache_n_object_avail;
63443 -atomic_t fscache_n_object_dead;
63444 +atomic_unchecked_t fscache_n_object_alloc;
63445 +atomic_unchecked_t fscache_n_object_no_alloc;
63446 +atomic_unchecked_t fscache_n_object_lookups;
63447 +atomic_unchecked_t fscache_n_object_lookups_negative;
63448 +atomic_unchecked_t fscache_n_object_lookups_positive;
63449 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63450 +atomic_unchecked_t fscache_n_object_created;
63451 +atomic_unchecked_t fscache_n_object_avail;
63452 +atomic_unchecked_t fscache_n_object_dead;
63453
63454 -atomic_t fscache_n_checkaux_none;
63455 -atomic_t fscache_n_checkaux_okay;
63456 -atomic_t fscache_n_checkaux_update;
63457 -atomic_t fscache_n_checkaux_obsolete;
63458 +atomic_unchecked_t fscache_n_checkaux_none;
63459 +atomic_unchecked_t fscache_n_checkaux_okay;
63460 +atomic_unchecked_t fscache_n_checkaux_update;
63461 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63462
63463 atomic_t fscache_n_cop_alloc_object;
63464 atomic_t fscache_n_cop_lookup_object;
63465 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63466 seq_puts(m, "FS-Cache statistics\n");
63467
63468 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63469 - atomic_read(&fscache_n_cookie_index),
63470 - atomic_read(&fscache_n_cookie_data),
63471 - atomic_read(&fscache_n_cookie_special));
63472 + atomic_read_unchecked(&fscache_n_cookie_index),
63473 + atomic_read_unchecked(&fscache_n_cookie_data),
63474 + atomic_read_unchecked(&fscache_n_cookie_special));
63475
63476 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63477 - atomic_read(&fscache_n_object_alloc),
63478 - atomic_read(&fscache_n_object_no_alloc),
63479 - atomic_read(&fscache_n_object_avail),
63480 - atomic_read(&fscache_n_object_dead));
63481 + atomic_read_unchecked(&fscache_n_object_alloc),
63482 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63483 + atomic_read_unchecked(&fscache_n_object_avail),
63484 + atomic_read_unchecked(&fscache_n_object_dead));
63485 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63486 - atomic_read(&fscache_n_checkaux_none),
63487 - atomic_read(&fscache_n_checkaux_okay),
63488 - atomic_read(&fscache_n_checkaux_update),
63489 - atomic_read(&fscache_n_checkaux_obsolete));
63490 + atomic_read_unchecked(&fscache_n_checkaux_none),
63491 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63492 + atomic_read_unchecked(&fscache_n_checkaux_update),
63493 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63494
63495 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63496 - atomic_read(&fscache_n_marks),
63497 - atomic_read(&fscache_n_uncaches));
63498 + atomic_read_unchecked(&fscache_n_marks),
63499 + atomic_read_unchecked(&fscache_n_uncaches));
63500
63501 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63502 " oom=%u\n",
63503 - atomic_read(&fscache_n_acquires),
63504 - atomic_read(&fscache_n_acquires_null),
63505 - atomic_read(&fscache_n_acquires_no_cache),
63506 - atomic_read(&fscache_n_acquires_ok),
63507 - atomic_read(&fscache_n_acquires_nobufs),
63508 - atomic_read(&fscache_n_acquires_oom));
63509 + atomic_read_unchecked(&fscache_n_acquires),
63510 + atomic_read_unchecked(&fscache_n_acquires_null),
63511 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63512 + atomic_read_unchecked(&fscache_n_acquires_ok),
63513 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63514 + atomic_read_unchecked(&fscache_n_acquires_oom));
63515
63516 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63517 - atomic_read(&fscache_n_object_lookups),
63518 - atomic_read(&fscache_n_object_lookups_negative),
63519 - atomic_read(&fscache_n_object_lookups_positive),
63520 - atomic_read(&fscache_n_object_created),
63521 - atomic_read(&fscache_n_object_lookups_timed_out));
63522 + atomic_read_unchecked(&fscache_n_object_lookups),
63523 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63524 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63525 + atomic_read_unchecked(&fscache_n_object_created),
63526 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63527
63528 seq_printf(m, "Invals : n=%u run=%u\n",
63529 - atomic_read(&fscache_n_invalidates),
63530 - atomic_read(&fscache_n_invalidates_run));
63531 + atomic_read_unchecked(&fscache_n_invalidates),
63532 + atomic_read_unchecked(&fscache_n_invalidates_run));
63533
63534 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63535 - atomic_read(&fscache_n_updates),
63536 - atomic_read(&fscache_n_updates_null),
63537 - atomic_read(&fscache_n_updates_run));
63538 + atomic_read_unchecked(&fscache_n_updates),
63539 + atomic_read_unchecked(&fscache_n_updates_null),
63540 + atomic_read_unchecked(&fscache_n_updates_run));
63541
63542 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63543 - atomic_read(&fscache_n_relinquishes),
63544 - atomic_read(&fscache_n_relinquishes_null),
63545 - atomic_read(&fscache_n_relinquishes_waitcrt),
63546 - atomic_read(&fscache_n_relinquishes_retire));
63547 + atomic_read_unchecked(&fscache_n_relinquishes),
63548 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63549 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63550 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63551
63552 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63553 - atomic_read(&fscache_n_attr_changed),
63554 - atomic_read(&fscache_n_attr_changed_ok),
63555 - atomic_read(&fscache_n_attr_changed_nobufs),
63556 - atomic_read(&fscache_n_attr_changed_nomem),
63557 - atomic_read(&fscache_n_attr_changed_calls));
63558 + atomic_read_unchecked(&fscache_n_attr_changed),
63559 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63560 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63561 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63562 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63563
63564 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63565 - atomic_read(&fscache_n_allocs),
63566 - atomic_read(&fscache_n_allocs_ok),
63567 - atomic_read(&fscache_n_allocs_wait),
63568 - atomic_read(&fscache_n_allocs_nobufs),
63569 - atomic_read(&fscache_n_allocs_intr));
63570 + atomic_read_unchecked(&fscache_n_allocs),
63571 + atomic_read_unchecked(&fscache_n_allocs_ok),
63572 + atomic_read_unchecked(&fscache_n_allocs_wait),
63573 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63574 + atomic_read_unchecked(&fscache_n_allocs_intr));
63575 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63576 - atomic_read(&fscache_n_alloc_ops),
63577 - atomic_read(&fscache_n_alloc_op_waits),
63578 - atomic_read(&fscache_n_allocs_object_dead));
63579 + atomic_read_unchecked(&fscache_n_alloc_ops),
63580 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63581 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63582
63583 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63584 " int=%u oom=%u\n",
63585 - atomic_read(&fscache_n_retrievals),
63586 - atomic_read(&fscache_n_retrievals_ok),
63587 - atomic_read(&fscache_n_retrievals_wait),
63588 - atomic_read(&fscache_n_retrievals_nodata),
63589 - atomic_read(&fscache_n_retrievals_nobufs),
63590 - atomic_read(&fscache_n_retrievals_intr),
63591 - atomic_read(&fscache_n_retrievals_nomem));
63592 + atomic_read_unchecked(&fscache_n_retrievals),
63593 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63594 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63595 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63596 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63597 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63598 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63599 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63600 - atomic_read(&fscache_n_retrieval_ops),
63601 - atomic_read(&fscache_n_retrieval_op_waits),
63602 - atomic_read(&fscache_n_retrievals_object_dead));
63603 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63604 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63605 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63606
63607 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63608 - atomic_read(&fscache_n_stores),
63609 - atomic_read(&fscache_n_stores_ok),
63610 - atomic_read(&fscache_n_stores_again),
63611 - atomic_read(&fscache_n_stores_nobufs),
63612 - atomic_read(&fscache_n_stores_oom));
63613 + atomic_read_unchecked(&fscache_n_stores),
63614 + atomic_read_unchecked(&fscache_n_stores_ok),
63615 + atomic_read_unchecked(&fscache_n_stores_again),
63616 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63617 + atomic_read_unchecked(&fscache_n_stores_oom));
63618 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63619 - atomic_read(&fscache_n_store_ops),
63620 - atomic_read(&fscache_n_store_calls),
63621 - atomic_read(&fscache_n_store_pages),
63622 - atomic_read(&fscache_n_store_radix_deletes),
63623 - atomic_read(&fscache_n_store_pages_over_limit));
63624 + atomic_read_unchecked(&fscache_n_store_ops),
63625 + atomic_read_unchecked(&fscache_n_store_calls),
63626 + atomic_read_unchecked(&fscache_n_store_pages),
63627 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63628 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63629
63630 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63631 - atomic_read(&fscache_n_store_vmscan_not_storing),
63632 - atomic_read(&fscache_n_store_vmscan_gone),
63633 - atomic_read(&fscache_n_store_vmscan_busy),
63634 - atomic_read(&fscache_n_store_vmscan_cancelled),
63635 - atomic_read(&fscache_n_store_vmscan_wait));
63636 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63637 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63638 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63639 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63640 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63641
63642 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63643 - atomic_read(&fscache_n_op_pend),
63644 - atomic_read(&fscache_n_op_run),
63645 - atomic_read(&fscache_n_op_enqueue),
63646 - atomic_read(&fscache_n_op_cancelled),
63647 - atomic_read(&fscache_n_op_rejected));
63648 + atomic_read_unchecked(&fscache_n_op_pend),
63649 + atomic_read_unchecked(&fscache_n_op_run),
63650 + atomic_read_unchecked(&fscache_n_op_enqueue),
63651 + atomic_read_unchecked(&fscache_n_op_cancelled),
63652 + atomic_read_unchecked(&fscache_n_op_rejected));
63653 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63654 - atomic_read(&fscache_n_op_deferred_release),
63655 - atomic_read(&fscache_n_op_release),
63656 - atomic_read(&fscache_n_op_gc));
63657 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63658 + atomic_read_unchecked(&fscache_n_op_release),
63659 + atomic_read_unchecked(&fscache_n_op_gc));
63660
63661 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63662 atomic_read(&fscache_n_cop_alloc_object),
63663 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63664 index 966ace8..030a03a 100644
63665 --- a/fs/fuse/cuse.c
63666 +++ b/fs/fuse/cuse.c
63667 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63668 INIT_LIST_HEAD(&cuse_conntbl[i]);
63669
63670 /* inherit and extend fuse_dev_operations */
63671 - cuse_channel_fops = fuse_dev_operations;
63672 - cuse_channel_fops.owner = THIS_MODULE;
63673 - cuse_channel_fops.open = cuse_channel_open;
63674 - cuse_channel_fops.release = cuse_channel_release;
63675 + pax_open_kernel();
63676 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63677 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63678 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63679 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63680 + pax_close_kernel();
63681
63682 cuse_class = class_create(THIS_MODULE, "cuse");
63683 if (IS_ERR(cuse_class))
63684 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63685 index ca88731..8e9c55d 100644
63686 --- a/fs/fuse/dev.c
63687 +++ b/fs/fuse/dev.c
63688 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63689 ret = 0;
63690 pipe_lock(pipe);
63691
63692 - if (!pipe->readers) {
63693 + if (!atomic_read(&pipe->readers)) {
63694 send_sig(SIGPIPE, current, 0);
63695 if (!ret)
63696 ret = -EPIPE;
63697 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63698 page_nr++;
63699 ret += buf->len;
63700
63701 - if (pipe->files)
63702 + if (atomic_read(&pipe->files))
63703 do_wakeup = 1;
63704 }
63705
63706 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63707 index dbab798..fefa22b 100644
63708 --- a/fs/fuse/dir.c
63709 +++ b/fs/fuse/dir.c
63710 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63711 return link;
63712 }
63713
63714 -static void free_link(char *link)
63715 +static void free_link(const char *link)
63716 {
63717 if (!IS_ERR(link))
63718 free_page((unsigned long) link);
63719 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63720 index fd62cae..3494dfa 100644
63721 --- a/fs/hostfs/hostfs_kern.c
63722 +++ b/fs/hostfs/hostfs_kern.c
63723 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63724
63725 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63726 {
63727 - char *s = nd_get_link(nd);
63728 + const char *s = nd_get_link(nd);
63729 if (!IS_ERR(s))
63730 __putname(s);
63731 }
63732 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63733 index 1e2872b..7aea000 100644
63734 --- a/fs/hugetlbfs/inode.c
63735 +++ b/fs/hugetlbfs/inode.c
63736 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63737 struct mm_struct *mm = current->mm;
63738 struct vm_area_struct *vma;
63739 struct hstate *h = hstate_file(file);
63740 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63741 struct vm_unmapped_area_info info;
63742
63743 if (len & ~huge_page_mask(h))
63744 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63745 return addr;
63746 }
63747
63748 +#ifdef CONFIG_PAX_RANDMMAP
63749 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63750 +#endif
63751 +
63752 if (addr) {
63753 addr = ALIGN(addr, huge_page_size(h));
63754 vma = find_vma(mm, addr);
63755 - if (TASK_SIZE - len >= addr &&
63756 - (!vma || addr + len <= vma->vm_start))
63757 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63758 return addr;
63759 }
63760
63761 info.flags = 0;
63762 info.length = len;
63763 info.low_limit = TASK_UNMAPPED_BASE;
63764 +
63765 +#ifdef CONFIG_PAX_RANDMMAP
63766 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63767 + info.low_limit += mm->delta_mmap;
63768 +#endif
63769 +
63770 info.high_limit = TASK_SIZE;
63771 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63772 info.align_offset = 0;
63773 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63774 };
63775 MODULE_ALIAS_FS("hugetlbfs");
63776
63777 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63778 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63779
63780 static int can_do_hugetlb_shm(void)
63781 {
63782 diff --git a/fs/inode.c b/fs/inode.c
63783 index 26753ba..d19eb34 100644
63784 --- a/fs/inode.c
63785 +++ b/fs/inode.c
63786 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63787 unsigned int *p = &get_cpu_var(last_ino);
63788 unsigned int res = *p;
63789
63790 +start:
63791 +
63792 #ifdef CONFIG_SMP
63793 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63794 - static atomic_t shared_last_ino;
63795 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63796 + static atomic_unchecked_t shared_last_ino;
63797 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63798
63799 res = next - LAST_INO_BATCH;
63800 }
63801 #endif
63802
63803 - *p = ++res;
63804 + if (unlikely(!++res))
63805 + goto start; /* never zero */
63806 + *p = res;
63807 put_cpu_var(last_ino);
63808 return res;
63809 }
63810 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63811 index 4a6cf28..d3a29d3 100644
63812 --- a/fs/jffs2/erase.c
63813 +++ b/fs/jffs2/erase.c
63814 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63815 struct jffs2_unknown_node marker = {
63816 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63817 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63818 - .totlen = cpu_to_je32(c->cleanmarker_size)
63819 + .totlen = cpu_to_je32(c->cleanmarker_size),
63820 + .hdr_crc = cpu_to_je32(0)
63821 };
63822
63823 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63824 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63825 index 09ed551..45684f8 100644
63826 --- a/fs/jffs2/wbuf.c
63827 +++ b/fs/jffs2/wbuf.c
63828 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63829 {
63830 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63831 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63832 - .totlen = constant_cpu_to_je32(8)
63833 + .totlen = constant_cpu_to_je32(8),
63834 + .hdr_crc = constant_cpu_to_je32(0)
63835 };
63836
63837 /*
63838 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63839 index 93e897e..a863de4 100644
63840 --- a/fs/jfs/super.c
63841 +++ b/fs/jfs/super.c
63842 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63843
63844 jfs_inode_cachep =
63845 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63846 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63847 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63848 init_once);
63849 if (jfs_inode_cachep == NULL)
63850 return -ENOMEM;
63851 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63852 index 1c77193..ba73e66 100644
63853 --- a/fs/kernfs/dir.c
63854 +++ b/fs/kernfs/dir.c
63855 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63856 *
63857 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63858 */
63859 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63860 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63861 {
63862 unsigned long hash = init_name_hash();
63863 unsigned int len = strlen(name);
63864 @@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63865 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63866
63867 kernfs_put_active(parent);
63868 +
63869 + if (!ret) {
63870 + struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
63871 + ret = PTR_ERR_OR_ZERO(dentry_ret);
63872 + }
63873 +
63874 return ret;
63875 }
63876
63877 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63878 index 4429d6d..9831f52 100644
63879 --- a/fs/kernfs/file.c
63880 +++ b/fs/kernfs/file.c
63881 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63882
63883 struct kernfs_open_node {
63884 atomic_t refcnt;
63885 - atomic_t event;
63886 + atomic_unchecked_t event;
63887 wait_queue_head_t poll;
63888 struct list_head files; /* goes through kernfs_open_file.list */
63889 };
63890 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63891 {
63892 struct kernfs_open_file *of = sf->private;
63893
63894 - of->event = atomic_read(&of->kn->attr.open->event);
63895 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63896
63897 return of->kn->attr.ops->seq_show(sf, v);
63898 }
63899 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63900 return ret;
63901 }
63902
63903 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63904 - void *buf, int len, int write)
63905 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63906 + void *buf, size_t len, int write)
63907 {
63908 struct file *file = vma->vm_file;
63909 struct kernfs_open_file *of = kernfs_of(file);
63910 - int ret;
63911 + ssize_t ret;
63912
63913 if (!of->vm_ops)
63914 return -EINVAL;
63915 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63916 return -ENOMEM;
63917
63918 atomic_set(&new_on->refcnt, 0);
63919 - atomic_set(&new_on->event, 1);
63920 + atomic_set_unchecked(&new_on->event, 1);
63921 init_waitqueue_head(&new_on->poll);
63922 INIT_LIST_HEAD(&new_on->files);
63923 goto retry;
63924 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63925
63926 kernfs_put_active(kn);
63927
63928 - if (of->event != atomic_read(&on->event))
63929 + if (of->event != atomic_read_unchecked(&on->event))
63930 goto trigger;
63931
63932 return DEFAULT_POLLMASK;
63933 @@ -818,7 +818,7 @@ repeat:
63934
63935 on = kn->attr.open;
63936 if (on) {
63937 - atomic_inc(&on->event);
63938 + atomic_inc_unchecked(&on->event);
63939 wake_up_interruptible(&on->poll);
63940 }
63941
63942 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63943 index 8a19889..4c3069a 100644
63944 --- a/fs/kernfs/symlink.c
63945 +++ b/fs/kernfs/symlink.c
63946 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63947 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63948 void *cookie)
63949 {
63950 - char *page = nd_get_link(nd);
63951 + const char *page = nd_get_link(nd);
63952 if (!IS_ERR(page))
63953 free_page((unsigned long)page);
63954 }
63955 diff --git a/fs/libfs.c b/fs/libfs.c
63956 index 005843c..06c4191 100644
63957 --- a/fs/libfs.c
63958 +++ b/fs/libfs.c
63959 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63960
63961 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63962 struct dentry *next = list_entry(p, struct dentry, d_child);
63963 + char d_name[sizeof(next->d_iname)];
63964 + const unsigned char *name;
63965 +
63966 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63967 if (!simple_positive(next)) {
63968 spin_unlock(&next->d_lock);
63969 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63970
63971 spin_unlock(&next->d_lock);
63972 spin_unlock(&dentry->d_lock);
63973 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63974 + name = next->d_name.name;
63975 + if (name == next->d_iname) {
63976 + memcpy(d_name, name, next->d_name.len);
63977 + name = d_name;
63978 + }
63979 + if (!dir_emit(ctx, name, next->d_name.len,
63980 next->d_inode->i_ino, dt_type(next->d_inode)))
63981 return 0;
63982 spin_lock(&dentry->d_lock);
63983 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63984 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63985 void *cookie)
63986 {
63987 - char *s = nd_get_link(nd);
63988 + const char *s = nd_get_link(nd);
63989 if (!IS_ERR(s))
63990 kfree(s);
63991 }
63992 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63993 index acd3947..1f896e2 100644
63994 --- a/fs/lockd/clntproc.c
63995 +++ b/fs/lockd/clntproc.c
63996 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63997 /*
63998 * Cookie counter for NLM requests
63999 */
64000 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64001 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64002
64003 void nlmclnt_next_cookie(struct nlm_cookie *c)
64004 {
64005 - u32 cookie = atomic_inc_return(&nlm_cookie);
64006 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64007
64008 memcpy(c->data, &cookie, 4);
64009 c->len=4;
64010 diff --git a/fs/locks.c b/fs/locks.c
64011 index 59e2f90..bd69071 100644
64012 --- a/fs/locks.c
64013 +++ b/fs/locks.c
64014 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
64015 locks_remove_posix(filp, filp);
64016
64017 if (filp->f_op->flock) {
64018 - struct file_lock fl = {
64019 + struct file_lock flock = {
64020 .fl_owner = filp,
64021 .fl_pid = current->tgid,
64022 .fl_file = filp,
64023 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
64024 .fl_type = F_UNLCK,
64025 .fl_end = OFFSET_MAX,
64026 };
64027 - filp->f_op->flock(filp, F_SETLKW, &fl);
64028 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64029 - fl.fl_ops->fl_release_private(&fl);
64030 + filp->f_op->flock(filp, F_SETLKW, &flock);
64031 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64032 + flock.fl_ops->fl_release_private(&flock);
64033 }
64034
64035 spin_lock(&inode->i_lock);
64036 diff --git a/fs/mount.h b/fs/mount.h
64037 index f82c628..9492b99 100644
64038 --- a/fs/mount.h
64039 +++ b/fs/mount.h
64040 @@ -11,7 +11,7 @@ struct mnt_namespace {
64041 u64 seq; /* Sequence number to prevent loops */
64042 wait_queue_head_t poll;
64043 u64 event;
64044 -};
64045 +} __randomize_layout;
64046
64047 struct mnt_pcp {
64048 int mnt_count;
64049 @@ -62,7 +62,7 @@ struct mount {
64050 int mnt_expiry_mark; /* true if marked for expiry */
64051 struct hlist_head mnt_pins;
64052 struct path mnt_ex_mountpoint;
64053 -};
64054 +} __randomize_layout;
64055
64056 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64057
64058 diff --git a/fs/namei.c b/fs/namei.c
64059 index db5fe86..ac769e4 100644
64060 --- a/fs/namei.c
64061 +++ b/fs/namei.c
64062 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64063 if (ret != -EACCES)
64064 return ret;
64065
64066 +#ifdef CONFIG_GRKERNSEC
64067 + /* we'll block if we have to log due to a denied capability use */
64068 + if (mask & MAY_NOT_BLOCK)
64069 + return -ECHILD;
64070 +#endif
64071 +
64072 if (S_ISDIR(inode->i_mode)) {
64073 /* DACs are overridable for directories */
64074 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64075 - return 0;
64076 if (!(mask & MAY_WRITE))
64077 - if (capable_wrt_inode_uidgid(inode,
64078 - CAP_DAC_READ_SEARCH))
64079 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64080 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64081 return 0;
64082 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64083 + return 0;
64084 return -EACCES;
64085 }
64086 /*
64087 + * Searching includes executable on directories, else just read.
64088 + */
64089 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64090 + if (mask == MAY_READ)
64091 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64092 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64093 + return 0;
64094 +
64095 + /*
64096 * Read/write DACs are always overridable.
64097 * Executable DACs are overridable when there is
64098 * at least one exec bit set.
64099 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64100 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64101 return 0;
64102
64103 - /*
64104 - * Searching includes executable on directories, else just read.
64105 - */
64106 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64107 - if (mask == MAY_READ)
64108 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64109 - return 0;
64110 -
64111 return -EACCES;
64112 }
64113 EXPORT_SYMBOL(generic_permission);
64114 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64115 {
64116 struct dentry *dentry = link->dentry;
64117 int error;
64118 - char *s;
64119 + const char *s;
64120
64121 BUG_ON(nd->flags & LOOKUP_RCU);
64122
64123 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64124 if (error)
64125 goto out_put_nd_path;
64126
64127 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64128 + dentry->d_inode, dentry, nd->path.mnt)) {
64129 + error = -EACCES;
64130 + goto out_put_nd_path;
64131 + }
64132 +
64133 nd->last_type = LAST_BIND;
64134 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64135 error = PTR_ERR(*p);
64136 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64137 if (res)
64138 break;
64139 res = walk_component(nd, path, LOOKUP_FOLLOW);
64140 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64141 + res = -EACCES;
64142 put_link(nd, &link, cookie);
64143 } while (res > 0);
64144
64145 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
64146 static inline u64 hash_name(const char *name)
64147 {
64148 unsigned long a, b, adata, bdata, mask, hash, len;
64149 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64150 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64151
64152 hash = a = 0;
64153 len = -sizeof(unsigned long);
64154 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
64155 if (err)
64156 break;
64157 err = lookup_last(nd, &path);
64158 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64159 + err = -EACCES;
64160 put_link(nd, &link, cookie);
64161 }
64162 }
64163 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
64164 if (!err)
64165 err = complete_walk(nd);
64166
64167 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64168 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64169 + path_put(&nd->path);
64170 + err = -ENOENT;
64171 + }
64172 + }
64173 +
64174 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64175 if (!d_can_lookup(nd->path.dentry)) {
64176 path_put(&nd->path);
64177 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
64178 retval = path_lookupat(dfd, name->name,
64179 flags | LOOKUP_REVAL, nd);
64180
64181 - if (likely(!retval))
64182 + if (likely(!retval)) {
64183 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64184 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64185 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64186 + path_put(&nd->path);
64187 + return -ENOENT;
64188 + }
64189 + }
64190 + }
64191 return retval;
64192 }
64193
64194 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64195 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64196 return -EPERM;
64197
64198 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64199 + return -EPERM;
64200 + if (gr_handle_rawio(inode))
64201 + return -EPERM;
64202 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64203 + return -EACCES;
64204 +
64205 return 0;
64206 }
64207
64208 @@ -2813,7 +2851,7 @@ looked_up:
64209 * cleared otherwise prior to returning.
64210 */
64211 static int lookup_open(struct nameidata *nd, struct path *path,
64212 - struct file *file,
64213 + struct path *link, struct file *file,
64214 const struct open_flags *op,
64215 bool got_write, int *opened)
64216 {
64217 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64218 /* Negative dentry, just create the file */
64219 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64220 umode_t mode = op->mode;
64221 +
64222 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64223 + error = -EACCES;
64224 + goto out_dput;
64225 + }
64226 +
64227 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64228 + error = -EACCES;
64229 + goto out_dput;
64230 + }
64231 +
64232 if (!IS_POSIXACL(dir->d_inode))
64233 mode &= ~current_umask();
64234 /*
64235 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64236 nd->flags & LOOKUP_EXCL);
64237 if (error)
64238 goto out_dput;
64239 + else
64240 + gr_handle_create(dentry, nd->path.mnt);
64241 }
64242 out_no_open:
64243 path->dentry = dentry;
64244 @@ -2883,7 +2934,7 @@ out_dput:
64245 /*
64246 * Handle the last step of open()
64247 */
64248 -static int do_last(struct nameidata *nd, struct path *path,
64249 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64250 struct file *file, const struct open_flags *op,
64251 int *opened, struct filename *name)
64252 {
64253 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64254 if (error)
64255 return error;
64256
64257 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64258 + error = -ENOENT;
64259 + goto out;
64260 + }
64261 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64262 + error = -EACCES;
64263 + goto out;
64264 + }
64265 +
64266 audit_inode(name, dir, LOOKUP_PARENT);
64267 error = -EISDIR;
64268 /* trailing slashes? */
64269 @@ -2952,7 +3012,7 @@ retry_lookup:
64270 */
64271 }
64272 mutex_lock(&dir->d_inode->i_mutex);
64273 - error = lookup_open(nd, path, file, op, got_write, opened);
64274 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64275 mutex_unlock(&dir->d_inode->i_mutex);
64276
64277 if (error <= 0) {
64278 @@ -2976,11 +3036,28 @@ retry_lookup:
64279 goto finish_open_created;
64280 }
64281
64282 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64283 + error = -ENOENT;
64284 + goto exit_dput;
64285 + }
64286 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64287 + error = -EACCES;
64288 + goto exit_dput;
64289 + }
64290 +
64291 /*
64292 * create/update audit record if it already exists.
64293 */
64294 - if (d_is_positive(path->dentry))
64295 + if (d_is_positive(path->dentry)) {
64296 + /* only check if O_CREAT is specified, all other checks need to go
64297 + into may_open */
64298 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64299 + error = -EACCES;
64300 + goto exit_dput;
64301 + }
64302 +
64303 audit_inode(name, path->dentry, 0);
64304 + }
64305
64306 /*
64307 * If atomic_open() acquired write access it is dropped now due to
64308 @@ -3021,6 +3098,11 @@ finish_lookup:
64309 }
64310 }
64311 BUG_ON(inode != path->dentry->d_inode);
64312 + /* if we're resolving a symlink to another symlink */
64313 + if (link && gr_handle_symlink_owner(link, inode)) {
64314 + error = -EACCES;
64315 + goto out;
64316 + }
64317 return 1;
64318 }
64319
64320 @@ -3040,7 +3122,18 @@ finish_open:
64321 path_put(&save_parent);
64322 return error;
64323 }
64324 +
64325 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64326 + error = -ENOENT;
64327 + goto out;
64328 + }
64329 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64330 + error = -EACCES;
64331 + goto out;
64332 + }
64333 +
64334 audit_inode(name, nd->path.dentry, 0);
64335 +
64336 error = -EISDIR;
64337 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64338 goto out;
64339 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64340 if (unlikely(error))
64341 goto out;
64342
64343 - error = do_last(nd, &path, file, op, &opened, pathname);
64344 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64345 while (unlikely(error > 0)) { /* trailing symlink */
64346 struct path link = path;
64347 void *cookie;
64348 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64349 error = follow_link(&link, nd, &cookie);
64350 if (unlikely(error))
64351 break;
64352 - error = do_last(nd, &path, file, op, &opened, pathname);
64353 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64354 put_link(nd, &link, cookie);
64355 }
64356 out:
64357 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64358 goto unlock;
64359
64360 error = -EEXIST;
64361 - if (d_is_positive(dentry))
64362 + if (d_is_positive(dentry)) {
64363 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64364 + error = -ENOENT;
64365 goto fail;
64366 -
64367 + }
64368 /*
64369 * Special case - lookup gave negative, but... we had foo/bar/
64370 * From the vfs_mknod() POV we just have a negative dentry -
64371 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64372 }
64373 EXPORT_SYMBOL(user_path_create);
64374
64375 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64376 +{
64377 + struct filename *tmp = getname(pathname);
64378 + struct dentry *res;
64379 + if (IS_ERR(tmp))
64380 + return ERR_CAST(tmp);
64381 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64382 + if (IS_ERR(res))
64383 + putname(tmp);
64384 + else
64385 + *to = tmp;
64386 + return res;
64387 +}
64388 +
64389 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64390 {
64391 int error = may_create(dir, dentry);
64392 @@ -3442,6 +3551,17 @@ retry:
64393
64394 if (!IS_POSIXACL(path.dentry->d_inode))
64395 mode &= ~current_umask();
64396 +
64397 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64398 + error = -EPERM;
64399 + goto out;
64400 + }
64401 +
64402 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64403 + error = -EACCES;
64404 + goto out;
64405 + }
64406 +
64407 error = security_path_mknod(&path, dentry, mode, dev);
64408 if (error)
64409 goto out;
64410 @@ -3457,6 +3577,8 @@ retry:
64411 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64412 break;
64413 }
64414 + if (!error)
64415 + gr_handle_create(dentry, path.mnt);
64416 out:
64417 done_path_create(&path, dentry);
64418 if (retry_estale(error, lookup_flags)) {
64419 @@ -3511,9 +3633,16 @@ retry:
64420
64421 if (!IS_POSIXACL(path.dentry->d_inode))
64422 mode &= ~current_umask();
64423 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64424 + error = -EACCES;
64425 + goto out;
64426 + }
64427 error = security_path_mkdir(&path, dentry, mode);
64428 if (!error)
64429 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64430 + if (!error)
64431 + gr_handle_create(dentry, path.mnt);
64432 +out:
64433 done_path_create(&path, dentry);
64434 if (retry_estale(error, lookup_flags)) {
64435 lookup_flags |= LOOKUP_REVAL;
64436 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64437 struct filename *name;
64438 struct dentry *dentry;
64439 struct nameidata nd;
64440 + ino_t saved_ino = 0;
64441 + dev_t saved_dev = 0;
64442 unsigned int lookup_flags = 0;
64443 retry:
64444 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64445 @@ -3629,10 +3760,21 @@ retry:
64446 error = -ENOENT;
64447 goto exit3;
64448 }
64449 +
64450 + saved_ino = dentry->d_inode->i_ino;
64451 + saved_dev = gr_get_dev_from_dentry(dentry);
64452 +
64453 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64454 + error = -EACCES;
64455 + goto exit3;
64456 + }
64457 +
64458 error = security_path_rmdir(&nd.path, dentry);
64459 if (error)
64460 goto exit3;
64461 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64462 + if (!error && (saved_dev || saved_ino))
64463 + gr_handle_delete(saved_ino, saved_dev);
64464 exit3:
64465 dput(dentry);
64466 exit2:
64467 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64468 struct nameidata nd;
64469 struct inode *inode = NULL;
64470 struct inode *delegated_inode = NULL;
64471 + ino_t saved_ino = 0;
64472 + dev_t saved_dev = 0;
64473 unsigned int lookup_flags = 0;
64474 retry:
64475 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64476 @@ -3751,10 +3895,22 @@ retry_deleg:
64477 if (d_is_negative(dentry))
64478 goto slashes;
64479 ihold(inode);
64480 +
64481 + if (inode->i_nlink <= 1) {
64482 + saved_ino = inode->i_ino;
64483 + saved_dev = gr_get_dev_from_dentry(dentry);
64484 + }
64485 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64486 + error = -EACCES;
64487 + goto exit2;
64488 + }
64489 +
64490 error = security_path_unlink(&nd.path, dentry);
64491 if (error)
64492 goto exit2;
64493 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64494 + if (!error && (saved_ino || saved_dev))
64495 + gr_handle_delete(saved_ino, saved_dev);
64496 exit2:
64497 dput(dentry);
64498 }
64499 @@ -3843,9 +3999,17 @@ retry:
64500 if (IS_ERR(dentry))
64501 goto out_putname;
64502
64503 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64504 + error = -EACCES;
64505 + goto out;
64506 + }
64507 +
64508 error = security_path_symlink(&path, dentry, from->name);
64509 if (!error)
64510 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64511 + if (!error)
64512 + gr_handle_create(dentry, path.mnt);
64513 +out:
64514 done_path_create(&path, dentry);
64515 if (retry_estale(error, lookup_flags)) {
64516 lookup_flags |= LOOKUP_REVAL;
64517 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64518 struct dentry *new_dentry;
64519 struct path old_path, new_path;
64520 struct inode *delegated_inode = NULL;
64521 + struct filename *to = NULL;
64522 int how = 0;
64523 int error;
64524
64525 @@ -3972,7 +4137,7 @@ retry:
64526 if (error)
64527 return error;
64528
64529 - new_dentry = user_path_create(newdfd, newname, &new_path,
64530 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64531 (how & LOOKUP_REVAL));
64532 error = PTR_ERR(new_dentry);
64533 if (IS_ERR(new_dentry))
64534 @@ -3984,11 +4149,28 @@ retry:
64535 error = may_linkat(&old_path);
64536 if (unlikely(error))
64537 goto out_dput;
64538 +
64539 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64540 + old_path.dentry->d_inode,
64541 + old_path.dentry->d_inode->i_mode, to)) {
64542 + error = -EACCES;
64543 + goto out_dput;
64544 + }
64545 +
64546 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64547 + old_path.dentry, old_path.mnt, to)) {
64548 + error = -EACCES;
64549 + goto out_dput;
64550 + }
64551 +
64552 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64553 if (error)
64554 goto out_dput;
64555 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64556 + if (!error)
64557 + gr_handle_create(new_dentry, new_path.mnt);
64558 out_dput:
64559 + putname(to);
64560 done_path_create(&new_path, new_dentry);
64561 if (delegated_inode) {
64562 error = break_deleg_wait(&delegated_inode);
64563 @@ -4304,6 +4486,20 @@ retry_deleg:
64564 if (new_dentry == trap)
64565 goto exit5;
64566
64567 + if (gr_bad_chroot_rename(old_dentry, oldnd.path.mnt, new_dentry, newnd.path.mnt)) {
64568 + /* use EXDEV error to cause 'mv' to switch to an alternative
64569 + * method for usability
64570 + */
64571 + error = -EXDEV;
64572 + goto exit5;
64573 + }
64574 +
64575 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64576 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64577 + to, flags);
64578 + if (error)
64579 + goto exit5;
64580 +
64581 error = security_path_rename(&oldnd.path, old_dentry,
64582 &newnd.path, new_dentry, flags);
64583 if (error)
64584 @@ -4311,6 +4507,9 @@ retry_deleg:
64585 error = vfs_rename(old_dir->d_inode, old_dentry,
64586 new_dir->d_inode, new_dentry,
64587 &delegated_inode, flags);
64588 + if (!error)
64589 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64590 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64591 exit5:
64592 dput(new_dentry);
64593 exit4:
64594 @@ -4367,14 +4566,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64595
64596 int readlink_copy(char __user *buffer, int buflen, const char *link)
64597 {
64598 + char tmpbuf[64];
64599 + const char *newlink;
64600 int len = PTR_ERR(link);
64601 +
64602 if (IS_ERR(link))
64603 goto out;
64604
64605 len = strlen(link);
64606 if (len > (unsigned) buflen)
64607 len = buflen;
64608 - if (copy_to_user(buffer, link, len))
64609 +
64610 + if (len < sizeof(tmpbuf)) {
64611 + memcpy(tmpbuf, link, len);
64612 + newlink = tmpbuf;
64613 + } else
64614 + newlink = link;
64615 +
64616 + if (copy_to_user(buffer, newlink, len))
64617 len = -EFAULT;
64618 out:
64619 return len;
64620 diff --git a/fs/namespace.c b/fs/namespace.c
64621 index bbde147..f4deeba 100644
64622 --- a/fs/namespace.c
64623 +++ b/fs/namespace.c
64624 @@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64625 if (!(sb->s_flags & MS_RDONLY))
64626 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64627 up_write(&sb->s_umount);
64628 +
64629 + gr_log_remount(mnt->mnt_devname, retval);
64630 +
64631 return retval;
64632 }
64633
64634 @@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64635 }
64636 unlock_mount_hash();
64637 namespace_unlock();
64638 +
64639 + gr_log_unmount(mnt->mnt_devname, retval);
64640 +
64641 return retval;
64642 }
64643
64644 @@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64645 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64646 */
64647
64648 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64649 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64650 {
64651 struct path path;
64652 struct mount *mnt;
64653 @@ -1564,7 +1570,7 @@ out:
64654 /*
64655 * The 2.0 compatible umount. No flags.
64656 */
64657 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64658 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64659 {
64660 return sys_umount(name, 0);
64661 }
64662 @@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64663 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64664 MS_STRICTATIME);
64665
64666 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64667 + retval = -EPERM;
64668 + goto dput_out;
64669 + }
64670 +
64671 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64672 + retval = -EPERM;
64673 + goto dput_out;
64674 + }
64675 +
64676 if (flags & MS_REMOUNT)
64677 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64678 data_page);
64679 @@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64680 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64681 dev_name, data_page);
64682 dput_out:
64683 + gr_log_mount(dev_name, &path, retval);
64684 +
64685 path_put(&path);
64686 +
64687 return retval;
64688 }
64689
64690 @@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64691 * number incrementing at 10Ghz will take 12,427 years to wrap which
64692 * is effectively never, so we can ignore the possibility.
64693 */
64694 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64695 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64696
64697 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64698 {
64699 @@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64700 kfree(new_ns);
64701 return ERR_PTR(ret);
64702 }
64703 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64704 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64705 atomic_set(&new_ns->count, 1);
64706 new_ns->root = NULL;
64707 INIT_LIST_HEAD(&new_ns->list);
64708 @@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64709 return new_ns;
64710 }
64711
64712 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64713 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64714 struct user_namespace *user_ns, struct fs_struct *new_fs)
64715 {
64716 struct mnt_namespace *new_ns;
64717 @@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64718 }
64719 EXPORT_SYMBOL(mount_subtree);
64720
64721 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64722 - char __user *, type, unsigned long, flags, void __user *, data)
64723 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64724 + const char __user *, type, unsigned long, flags, void __user *, data)
64725 {
64726 int ret;
64727 char *kernel_type;
64728 @@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64729 if (error)
64730 goto out2;
64731
64732 + if (gr_handle_chroot_pivot()) {
64733 + error = -EPERM;
64734 + goto out2;
64735 + }
64736 +
64737 get_fs_root(current->fs, &root);
64738 old_mp = lock_mount(&old);
64739 error = PTR_ERR(old_mp);
64740 @@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64741 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64742 return -EPERM;
64743
64744 - if (fs->users != 1)
64745 + if (atomic_read(&fs->users) != 1)
64746 return -EINVAL;
64747
64748 get_mnt_ns(mnt_ns);
64749 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64750 index f4ccfe6..a5cf064 100644
64751 --- a/fs/nfs/callback_xdr.c
64752 +++ b/fs/nfs/callback_xdr.c
64753 @@ -51,7 +51,7 @@ struct callback_op {
64754 callback_decode_arg_t decode_args;
64755 callback_encode_res_t encode_res;
64756 long res_maxsize;
64757 -};
64758 +} __do_const;
64759
64760 static struct callback_op callback_ops[];
64761
64762 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64763 index 00689a8..b162632 100644
64764 --- a/fs/nfs/inode.c
64765 +++ b/fs/nfs/inode.c
64766 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64767 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64768 }
64769
64770 -static atomic_long_t nfs_attr_generation_counter;
64771 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64772
64773 static unsigned long nfs_read_attr_generation_counter(void)
64774 {
64775 - return atomic_long_read(&nfs_attr_generation_counter);
64776 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64777 }
64778
64779 unsigned long nfs_inc_attr_generation_counter(void)
64780 {
64781 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64782 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64783 }
64784
64785 void nfs_fattr_init(struct nfs_fattr *fattr)
64786 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64787 index 0beb023..3f685ec 100644
64788 --- a/fs/nfsd/nfs4proc.c
64789 +++ b/fs/nfsd/nfs4proc.c
64790 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64791 nfsd4op_rsize op_rsize_bop;
64792 stateid_getter op_get_currentstateid;
64793 stateid_setter op_set_currentstateid;
64794 -};
64795 +} __do_const;
64796
64797 static struct nfsd4_operation nfsd4_ops[];
64798
64799 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64800 index 2a77603..68e0e37 100644
64801 --- a/fs/nfsd/nfs4xdr.c
64802 +++ b/fs/nfsd/nfs4xdr.c
64803 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64804
64805 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64806
64807 -static nfsd4_dec nfsd4_dec_ops[] = {
64808 +static const nfsd4_dec nfsd4_dec_ops[] = {
64809 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64810 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64811 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64812 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64813 index 122f691..a00e2e0 100644
64814 --- a/fs/nfsd/nfscache.c
64815 +++ b/fs/nfsd/nfscache.c
64816 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64817 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64818 u32 hash;
64819 struct nfsd_drc_bucket *b;
64820 - int len;
64821 + long len;
64822 size_t bufsize = 0;
64823
64824 if (!rp)
64825 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64826 hash = nfsd_cache_hash(rp->c_xid);
64827 b = &drc_hashtbl[hash];
64828
64829 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64830 - len >>= 2;
64831 + if (statp) {
64832 + len = (char*)statp - (char*)resv->iov_base;
64833 + len = resv->iov_len - len;
64834 + len >>= 2;
64835 + }
64836
64837 /* Don't cache excessive amounts of data and XDR failures */
64838 - if (!statp || len > (256 >> 2)) {
64839 + if (!statp || len > (256 >> 2) || len < 0) {
64840 nfsd_reply_cache_free(b, rp);
64841 return;
64842 }
64843 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64844 switch (cachetype) {
64845 case RC_REPLSTAT:
64846 if (len != 1)
64847 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64848 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64849 rp->c_replstat = *statp;
64850 break;
64851 case RC_REPLBUFF:
64852 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64853 index 989129e..42e019e 100644
64854 --- a/fs/nfsd/vfs.c
64855 +++ b/fs/nfsd/vfs.c
64856 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64857
64858 oldfs = get_fs();
64859 set_fs(KERNEL_DS);
64860 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64861 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64862 set_fs(oldfs);
64863 return nfsd_finish_read(file, count, host_err);
64864 }
64865 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64866
64867 /* Write the data. */
64868 oldfs = get_fs(); set_fs(KERNEL_DS);
64869 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64870 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64871 set_fs(oldfs);
64872 if (host_err < 0)
64873 goto out_nfserr;
64874 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64875 */
64876
64877 oldfs = get_fs(); set_fs(KERNEL_DS);
64878 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64879 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64880 set_fs(oldfs);
64881
64882 if (host_err < 0)
64883 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64884 index 52ccd34..7a6b202 100644
64885 --- a/fs/nls/nls_base.c
64886 +++ b/fs/nls/nls_base.c
64887 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64888
64889 int __register_nls(struct nls_table *nls, struct module *owner)
64890 {
64891 - struct nls_table ** tmp = &tables;
64892 + struct nls_table *tmp = tables;
64893
64894 if (nls->next)
64895 return -EBUSY;
64896
64897 - nls->owner = owner;
64898 + pax_open_kernel();
64899 + *(void **)&nls->owner = owner;
64900 + pax_close_kernel();
64901 spin_lock(&nls_lock);
64902 - while (*tmp) {
64903 - if (nls == *tmp) {
64904 + while (tmp) {
64905 + if (nls == tmp) {
64906 spin_unlock(&nls_lock);
64907 return -EBUSY;
64908 }
64909 - tmp = &(*tmp)->next;
64910 + tmp = tmp->next;
64911 }
64912 - nls->next = tables;
64913 + pax_open_kernel();
64914 + *(struct nls_table **)&nls->next = tables;
64915 + pax_close_kernel();
64916 tables = nls;
64917 spin_unlock(&nls_lock);
64918 return 0;
64919 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64920
64921 int unregister_nls(struct nls_table * nls)
64922 {
64923 - struct nls_table ** tmp = &tables;
64924 + struct nls_table * const * tmp = &tables;
64925
64926 spin_lock(&nls_lock);
64927 while (*tmp) {
64928 if (nls == *tmp) {
64929 - *tmp = nls->next;
64930 + pax_open_kernel();
64931 + *(struct nls_table **)tmp = nls->next;
64932 + pax_close_kernel();
64933 spin_unlock(&nls_lock);
64934 return 0;
64935 }
64936 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64937 return -EINVAL;
64938 }
64939
64940 -static struct nls_table *find_nls(char *charset)
64941 +static struct nls_table *find_nls(const char *charset)
64942 {
64943 struct nls_table *nls;
64944 spin_lock(&nls_lock);
64945 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64946 return nls;
64947 }
64948
64949 -struct nls_table *load_nls(char *charset)
64950 +struct nls_table *load_nls(const char *charset)
64951 {
64952 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64953 }
64954 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64955 index 162b3f1..6076a7c 100644
64956 --- a/fs/nls/nls_euc-jp.c
64957 +++ b/fs/nls/nls_euc-jp.c
64958 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64959 p_nls = load_nls("cp932");
64960
64961 if (p_nls) {
64962 - table.charset2upper = p_nls->charset2upper;
64963 - table.charset2lower = p_nls->charset2lower;
64964 + pax_open_kernel();
64965 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64966 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64967 + pax_close_kernel();
64968 return register_nls(&table);
64969 }
64970
64971 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64972 index a80a741..7b96e1b 100644
64973 --- a/fs/nls/nls_koi8-ru.c
64974 +++ b/fs/nls/nls_koi8-ru.c
64975 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64976 p_nls = load_nls("koi8-u");
64977
64978 if (p_nls) {
64979 - table.charset2upper = p_nls->charset2upper;
64980 - table.charset2lower = p_nls->charset2lower;
64981 + pax_open_kernel();
64982 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64983 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64984 + pax_close_kernel();
64985 return register_nls(&table);
64986 }
64987
64988 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64989 index c991616..5ae51af 100644
64990 --- a/fs/notify/fanotify/fanotify_user.c
64991 +++ b/fs/notify/fanotify/fanotify_user.c
64992 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64993
64994 fd = fanotify_event_metadata.fd;
64995 ret = -EFAULT;
64996 - if (copy_to_user(buf, &fanotify_event_metadata,
64997 - fanotify_event_metadata.event_len))
64998 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64999 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65000 goto out_close_fd;
65001
65002 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65003 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65004 index a95d8e0..a91a5fd 100644
65005 --- a/fs/notify/notification.c
65006 +++ b/fs/notify/notification.c
65007 @@ -48,7 +48,7 @@
65008 #include <linux/fsnotify_backend.h>
65009 #include "fsnotify.h"
65010
65011 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65012 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65013
65014 /**
65015 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65016 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65017 */
65018 u32 fsnotify_get_cookie(void)
65019 {
65020 - return atomic_inc_return(&fsnotify_sync_cookie);
65021 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65022 }
65023 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65024
65025 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65026 index 9e38daf..5727cae 100644
65027 --- a/fs/ntfs/dir.c
65028 +++ b/fs/ntfs/dir.c
65029 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65030 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65031 ~(s64)(ndir->itype.index.block_size - 1)));
65032 /* Bounds checks. */
65033 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65034 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65035 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65036 "inode 0x%lx or driver bug.", vdir->i_ino);
65037 goto err_out;
65038 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65039 index 643faa4..ef9027e 100644
65040 --- a/fs/ntfs/file.c
65041 +++ b/fs/ntfs/file.c
65042 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65043 char *addr;
65044 size_t total = 0;
65045 unsigned len;
65046 - int left;
65047 + unsigned left;
65048
65049 do {
65050 len = PAGE_CACHE_SIZE - ofs;
65051 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65052 index 9e1e112..241a52a 100644
65053 --- a/fs/ntfs/super.c
65054 +++ b/fs/ntfs/super.c
65055 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65056 if (!silent)
65057 ntfs_error(sb, "Primary boot sector is invalid.");
65058 } else if (!silent)
65059 - ntfs_error(sb, read_err_str, "primary");
65060 + ntfs_error(sb, read_err_str, "%s", "primary");
65061 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65062 if (bh_primary)
65063 brelse(bh_primary);
65064 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65065 goto hotfix_primary_boot_sector;
65066 brelse(bh_backup);
65067 } else if (!silent)
65068 - ntfs_error(sb, read_err_str, "backup");
65069 + ntfs_error(sb, read_err_str, "%s", "backup");
65070 /* Try to read NT3.51- backup boot sector. */
65071 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65072 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65073 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65074 "sector.");
65075 brelse(bh_backup);
65076 } else if (!silent)
65077 - ntfs_error(sb, read_err_str, "backup");
65078 + ntfs_error(sb, read_err_str, "%s", "backup");
65079 /* We failed. Cleanup and return. */
65080 if (bh_primary)
65081 brelse(bh_primary);
65082 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65083 index 0440134..d52c93a 100644
65084 --- a/fs/ocfs2/localalloc.c
65085 +++ b/fs/ocfs2/localalloc.c
65086 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65087 goto bail;
65088 }
65089
65090 - atomic_inc(&osb->alloc_stats.moves);
65091 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65092
65093 bail:
65094 if (handle)
65095 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65096 index bbec539..7b266d5 100644
65097 --- a/fs/ocfs2/ocfs2.h
65098 +++ b/fs/ocfs2/ocfs2.h
65099 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65100
65101 struct ocfs2_alloc_stats
65102 {
65103 - atomic_t moves;
65104 - atomic_t local_data;
65105 - atomic_t bitmap_data;
65106 - atomic_t bg_allocs;
65107 - atomic_t bg_extends;
65108 + atomic_unchecked_t moves;
65109 + atomic_unchecked_t local_data;
65110 + atomic_unchecked_t bitmap_data;
65111 + atomic_unchecked_t bg_allocs;
65112 + atomic_unchecked_t bg_extends;
65113 };
65114
65115 enum ocfs2_local_alloc_state
65116 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65117 index 0cb889a..6a26b24 100644
65118 --- a/fs/ocfs2/suballoc.c
65119 +++ b/fs/ocfs2/suballoc.c
65120 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65121 mlog_errno(status);
65122 goto bail;
65123 }
65124 - atomic_inc(&osb->alloc_stats.bg_extends);
65125 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65126
65127 /* You should never ask for this much metadata */
65128 BUG_ON(bits_wanted >
65129 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65130 mlog_errno(status);
65131 goto bail;
65132 }
65133 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65134 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65135
65136 *suballoc_loc = res.sr_bg_blkno;
65137 *suballoc_bit_start = res.sr_bit_offset;
65138 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65139 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65140 res->sr_bits);
65141
65142 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65143 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65144
65145 BUG_ON(res->sr_bits != 1);
65146
65147 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65148 mlog_errno(status);
65149 goto bail;
65150 }
65151 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65152 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65153
65154 BUG_ON(res.sr_bits != 1);
65155
65156 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65157 cluster_start,
65158 num_clusters);
65159 if (!status)
65160 - atomic_inc(&osb->alloc_stats.local_data);
65161 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65162 } else {
65163 if (min_clusters > (osb->bitmap_cpg - 1)) {
65164 /* The only paths asking for contiguousness
65165 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65166 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65167 res.sr_bg_blkno,
65168 res.sr_bit_offset);
65169 - atomic_inc(&osb->alloc_stats.bitmap_data);
65170 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65171 *num_clusters = res.sr_bits;
65172 }
65173 }
65174 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65175 index 93c85bc..02f68a4 100644
65176 --- a/fs/ocfs2/super.c
65177 +++ b/fs/ocfs2/super.c
65178 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65179 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65180 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65181 "Stats",
65182 - atomic_read(&osb->alloc_stats.bitmap_data),
65183 - atomic_read(&osb->alloc_stats.local_data),
65184 - atomic_read(&osb->alloc_stats.bg_allocs),
65185 - atomic_read(&osb->alloc_stats.moves),
65186 - atomic_read(&osb->alloc_stats.bg_extends));
65187 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65188 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65189 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65190 + atomic_read_unchecked(&osb->alloc_stats.moves),
65191 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65192
65193 out += snprintf(buf + out, len - out,
65194 "%10s => State: %u Descriptor: %llu Size: %u bits "
65195 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65196
65197 mutex_init(&osb->system_file_mutex);
65198
65199 - atomic_set(&osb->alloc_stats.moves, 0);
65200 - atomic_set(&osb->alloc_stats.local_data, 0);
65201 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65202 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65203 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65204 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65205 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65206 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65207 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65208 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65209
65210 /* Copy the blockcheck stats from the superblock probe */
65211 osb->osb_ecc_stats = *stats;
65212 diff --git a/fs/open.c b/fs/open.c
65213 index de92c13..52d2a6c 100644
65214 --- a/fs/open.c
65215 +++ b/fs/open.c
65216 @@ -32,6 +32,8 @@
65217 #include <linux/dnotify.h>
65218 #include <linux/compat.h>
65219
65220 +#define CREATE_TRACE_POINTS
65221 +#include <trace/events/fs.h>
65222 #include "internal.h"
65223
65224 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65225 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65226 error = locks_verify_truncate(inode, NULL, length);
65227 if (!error)
65228 error = security_path_truncate(path);
65229 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65230 + error = -EACCES;
65231 if (!error)
65232 error = do_truncate(path->dentry, length, 0, NULL);
65233
65234 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65235 error = locks_verify_truncate(inode, f.file, length);
65236 if (!error)
65237 error = security_path_truncate(&f.file->f_path);
65238 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65239 + error = -EACCES;
65240 if (!error)
65241 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65242 sb_end_write(inode->i_sb);
65243 @@ -380,6 +386,9 @@ retry:
65244 if (__mnt_is_readonly(path.mnt))
65245 res = -EROFS;
65246
65247 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65248 + res = -EACCES;
65249 +
65250 out_path_release:
65251 path_put(&path);
65252 if (retry_estale(res, lookup_flags)) {
65253 @@ -411,6 +420,8 @@ retry:
65254 if (error)
65255 goto dput_and_out;
65256
65257 + gr_log_chdir(path.dentry, path.mnt);
65258 +
65259 set_fs_pwd(current->fs, &path);
65260
65261 dput_and_out:
65262 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65263 goto out_putf;
65264
65265 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65266 +
65267 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65268 + error = -EPERM;
65269 +
65270 + if (!error)
65271 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65272 +
65273 if (!error)
65274 set_fs_pwd(current->fs, &f.file->f_path);
65275 out_putf:
65276 @@ -469,7 +487,13 @@ retry:
65277 if (error)
65278 goto dput_and_out;
65279
65280 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65281 + goto dput_and_out;
65282 +
65283 set_fs_root(current->fs, &path);
65284 +
65285 + gr_handle_chroot_chdir(&path);
65286 +
65287 error = 0;
65288 dput_and_out:
65289 path_put(&path);
65290 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65291 return error;
65292 retry_deleg:
65293 mutex_lock(&inode->i_mutex);
65294 +
65295 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65296 + error = -EACCES;
65297 + goto out_unlock;
65298 + }
65299 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65300 + error = -EACCES;
65301 + goto out_unlock;
65302 + }
65303 +
65304 error = security_path_chmod(path, mode);
65305 if (error)
65306 goto out_unlock;
65307 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65308 uid = make_kuid(current_user_ns(), user);
65309 gid = make_kgid(current_user_ns(), group);
65310
65311 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65312 + return -EACCES;
65313 +
65314 newattrs.ia_valid = ATTR_CTIME;
65315 if (user != (uid_t) -1) {
65316 if (!uid_valid(uid))
65317 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65318 } else {
65319 fsnotify_open(f);
65320 fd_install(fd, f);
65321 + trace_do_sys_open(tmp->name, flags, mode);
65322 }
65323 }
65324 putname(tmp);
65325 diff --git a/fs/pipe.c b/fs/pipe.c
65326 index 21981e5..3d5f55c 100644
65327 --- a/fs/pipe.c
65328 +++ b/fs/pipe.c
65329 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65330
65331 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65332 {
65333 - if (pipe->files)
65334 + if (atomic_read(&pipe->files))
65335 mutex_lock_nested(&pipe->mutex, subclass);
65336 }
65337
65338 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65339
65340 void pipe_unlock(struct pipe_inode_info *pipe)
65341 {
65342 - if (pipe->files)
65343 + if (atomic_read(&pipe->files))
65344 mutex_unlock(&pipe->mutex);
65345 }
65346 EXPORT_SYMBOL(pipe_unlock);
65347 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65348 }
65349 if (bufs) /* More to do? */
65350 continue;
65351 - if (!pipe->writers)
65352 + if (!atomic_read(&pipe->writers))
65353 break;
65354 - if (!pipe->waiting_writers) {
65355 + if (!atomic_read(&pipe->waiting_writers)) {
65356 /* syscall merging: Usually we must not sleep
65357 * if O_NONBLOCK is set, or if we got some data.
65358 * But if a writer sleeps in kernel space, then
65359 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65360
65361 __pipe_lock(pipe);
65362
65363 - if (!pipe->readers) {
65364 + if (!atomic_read(&pipe->readers)) {
65365 send_sig(SIGPIPE, current, 0);
65366 ret = -EPIPE;
65367 goto out;
65368 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65369 for (;;) {
65370 int bufs;
65371
65372 - if (!pipe->readers) {
65373 + if (!atomic_read(&pipe->readers)) {
65374 send_sig(SIGPIPE, current, 0);
65375 if (!ret)
65376 ret = -EPIPE;
65377 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65378 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65379 do_wakeup = 0;
65380 }
65381 - pipe->waiting_writers++;
65382 + atomic_inc(&pipe->waiting_writers);
65383 pipe_wait(pipe);
65384 - pipe->waiting_writers--;
65385 + atomic_dec(&pipe->waiting_writers);
65386 }
65387 out:
65388 __pipe_unlock(pipe);
65389 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65390 mask = 0;
65391 if (filp->f_mode & FMODE_READ) {
65392 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65393 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65394 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65395 mask |= POLLHUP;
65396 }
65397
65398 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65399 * Most Unices do not set POLLERR for FIFOs but on Linux they
65400 * behave exactly like pipes for poll().
65401 */
65402 - if (!pipe->readers)
65403 + if (!atomic_read(&pipe->readers))
65404 mask |= POLLERR;
65405 }
65406
65407 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65408 int kill = 0;
65409
65410 spin_lock(&inode->i_lock);
65411 - if (!--pipe->files) {
65412 + if (atomic_dec_and_test(&pipe->files)) {
65413 inode->i_pipe = NULL;
65414 kill = 1;
65415 }
65416 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65417
65418 __pipe_lock(pipe);
65419 if (file->f_mode & FMODE_READ)
65420 - pipe->readers--;
65421 + atomic_dec(&pipe->readers);
65422 if (file->f_mode & FMODE_WRITE)
65423 - pipe->writers--;
65424 + atomic_dec(&pipe->writers);
65425
65426 - if (pipe->readers || pipe->writers) {
65427 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65428 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65429 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65430 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65431 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65432 kfree(pipe);
65433 }
65434
65435 -static struct vfsmount *pipe_mnt __read_mostly;
65436 +struct vfsmount *pipe_mnt __read_mostly;
65437
65438 /*
65439 * pipefs_dname() is called from d_path().
65440 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65441 goto fail_iput;
65442
65443 inode->i_pipe = pipe;
65444 - pipe->files = 2;
65445 - pipe->readers = pipe->writers = 1;
65446 + atomic_set(&pipe->files, 2);
65447 + atomic_set(&pipe->readers, 1);
65448 + atomic_set(&pipe->writers, 1);
65449 inode->i_fop = &pipefifo_fops;
65450
65451 /*
65452 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65453 spin_lock(&inode->i_lock);
65454 if (inode->i_pipe) {
65455 pipe = inode->i_pipe;
65456 - pipe->files++;
65457 + atomic_inc(&pipe->files);
65458 spin_unlock(&inode->i_lock);
65459 } else {
65460 spin_unlock(&inode->i_lock);
65461 pipe = alloc_pipe_info();
65462 if (!pipe)
65463 return -ENOMEM;
65464 - pipe->files = 1;
65465 + atomic_set(&pipe->files, 1);
65466 spin_lock(&inode->i_lock);
65467 if (unlikely(inode->i_pipe)) {
65468 - inode->i_pipe->files++;
65469 + atomic_inc(&inode->i_pipe->files);
65470 spin_unlock(&inode->i_lock);
65471 free_pipe_info(pipe);
65472 pipe = inode->i_pipe;
65473 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65474 * opened, even when there is no process writing the FIFO.
65475 */
65476 pipe->r_counter++;
65477 - if (pipe->readers++ == 0)
65478 + if (atomic_inc_return(&pipe->readers) == 1)
65479 wake_up_partner(pipe);
65480
65481 - if (!is_pipe && !pipe->writers) {
65482 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65483 if ((filp->f_flags & O_NONBLOCK)) {
65484 /* suppress POLLHUP until we have
65485 * seen a writer */
65486 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65487 * errno=ENXIO when there is no process reading the FIFO.
65488 */
65489 ret = -ENXIO;
65490 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65491 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65492 goto err;
65493
65494 pipe->w_counter++;
65495 - if (!pipe->writers++)
65496 + if (atomic_inc_return(&pipe->writers) == 1)
65497 wake_up_partner(pipe);
65498
65499 - if (!is_pipe && !pipe->readers) {
65500 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65501 if (wait_for_partner(pipe, &pipe->r_counter))
65502 goto err_wr;
65503 }
65504 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65505 * the process can at least talk to itself.
65506 */
65507
65508 - pipe->readers++;
65509 - pipe->writers++;
65510 + atomic_inc(&pipe->readers);
65511 + atomic_inc(&pipe->writers);
65512 pipe->r_counter++;
65513 pipe->w_counter++;
65514 - if (pipe->readers == 1 || pipe->writers == 1)
65515 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65516 wake_up_partner(pipe);
65517 break;
65518
65519 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65520 return 0;
65521
65522 err_rd:
65523 - if (!--pipe->readers)
65524 + if (atomic_dec_and_test(&pipe->readers))
65525 wake_up_interruptible(&pipe->wait);
65526 ret = -ERESTARTSYS;
65527 goto err;
65528
65529 err_wr:
65530 - if (!--pipe->writers)
65531 + if (atomic_dec_and_test(&pipe->writers))
65532 wake_up_interruptible(&pipe->wait);
65533 ret = -ERESTARTSYS;
65534 goto err;
65535 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65536 index 0855f77..6787d50 100644
65537 --- a/fs/posix_acl.c
65538 +++ b/fs/posix_acl.c
65539 @@ -20,6 +20,7 @@
65540 #include <linux/xattr.h>
65541 #include <linux/export.h>
65542 #include <linux/user_namespace.h>
65543 +#include <linux/grsecurity.h>
65544
65545 struct posix_acl **acl_by_type(struct inode *inode, int type)
65546 {
65547 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65548 }
65549 }
65550 if (mode_p)
65551 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65552 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65553 return not_equiv;
65554 }
65555 EXPORT_SYMBOL(posix_acl_equiv_mode);
65556 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65557 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65558 }
65559
65560 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65561 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65562 return not_equiv;
65563 }
65564
65565 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65566 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65567 int err = -ENOMEM;
65568 if (clone) {
65569 + *mode_p &= ~gr_acl_umask();
65570 +
65571 err = posix_acl_create_masq(clone, mode_p);
65572 if (err < 0) {
65573 posix_acl_release(clone);
65574 @@ -659,11 +662,12 @@ struct posix_acl *
65575 posix_acl_from_xattr(struct user_namespace *user_ns,
65576 const void *value, size_t size)
65577 {
65578 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65579 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65580 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65581 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65582 int count;
65583 struct posix_acl *acl;
65584 struct posix_acl_entry *acl_e;
65585 + umode_t umask = gr_acl_umask();
65586
65587 if (!value)
65588 return NULL;
65589 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65590
65591 switch(acl_e->e_tag) {
65592 case ACL_USER_OBJ:
65593 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65594 + break;
65595 case ACL_GROUP_OBJ:
65596 case ACL_MASK:
65597 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65598 + break;
65599 case ACL_OTHER:
65600 + acl_e->e_perm &= ~(umask & S_IRWXO);
65601 break;
65602
65603 case ACL_USER:
65604 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65605 acl_e->e_uid =
65606 make_kuid(user_ns,
65607 le32_to_cpu(entry->e_id));
65608 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65609 goto fail;
65610 break;
65611 case ACL_GROUP:
65612 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65613 acl_e->e_gid =
65614 make_kgid(user_ns,
65615 le32_to_cpu(entry->e_id));
65616 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65617 index 2183fcf..3c32a98 100644
65618 --- a/fs/proc/Kconfig
65619 +++ b/fs/proc/Kconfig
65620 @@ -30,7 +30,7 @@ config PROC_FS
65621
65622 config PROC_KCORE
65623 bool "/proc/kcore support" if !ARM
65624 - depends on PROC_FS && MMU
65625 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65626 help
65627 Provides a virtual ELF core file of the live kernel. This can
65628 be read with gdb and other ELF tools. No modifications can be
65629 @@ -38,8 +38,8 @@ config PROC_KCORE
65630
65631 config PROC_VMCORE
65632 bool "/proc/vmcore support"
65633 - depends on PROC_FS && CRASH_DUMP
65634 - default y
65635 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65636 + default n
65637 help
65638 Exports the dump image of crashed kernel in ELF format.
65639
65640 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65641 limited in memory.
65642
65643 config PROC_PAGE_MONITOR
65644 - default y
65645 - depends on PROC_FS && MMU
65646 + default n
65647 + depends on PROC_FS && MMU && !GRKERNSEC
65648 bool "Enable /proc page monitoring" if EXPERT
65649 help
65650 Various /proc files exist to monitor process memory utilization:
65651 diff --git a/fs/proc/array.c b/fs/proc/array.c
65652 index cd3653e..9b9b79a 100644
65653 --- a/fs/proc/array.c
65654 +++ b/fs/proc/array.c
65655 @@ -60,6 +60,7 @@
65656 #include <linux/tty.h>
65657 #include <linux/string.h>
65658 #include <linux/mman.h>
65659 +#include <linux/grsecurity.h>
65660 #include <linux/proc_fs.h>
65661 #include <linux/ioport.h>
65662 #include <linux/uaccess.h>
65663 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65664 seq_putc(m, '\n');
65665 }
65666
65667 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65668 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65669 +{
65670 + if (p->mm)
65671 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65672 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65673 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65674 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65675 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65676 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65677 + else
65678 + seq_printf(m, "PaX:\t-----\n");
65679 +}
65680 +#endif
65681 +
65682 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65683 struct pid *pid, struct task_struct *task)
65684 {
65685 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65686 task_cpus_allowed(m, task);
65687 cpuset_task_status_allowed(m, task);
65688 task_context_switch_counts(m, task);
65689 +
65690 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65691 + task_pax(m, task);
65692 +#endif
65693 +
65694 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65695 + task_grsec_rbac(m, task);
65696 +#endif
65697 +
65698 return 0;
65699 }
65700
65701 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65702 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65703 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65704 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65705 +#endif
65706 +
65707 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65708 struct pid *pid, struct task_struct *task, int whole)
65709 {
65710 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65711 char tcomm[sizeof(task->comm)];
65712 unsigned long flags;
65713
65714 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65715 + if (current->exec_id != m->exec_id) {
65716 + gr_log_badprocpid("stat");
65717 + return 0;
65718 + }
65719 +#endif
65720 +
65721 state = *get_task_state(task);
65722 vsize = eip = esp = 0;
65723 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65724 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65725 gtime = task_gtime(task);
65726 }
65727
65728 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65729 + if (PAX_RAND_FLAGS(mm)) {
65730 + eip = 0;
65731 + esp = 0;
65732 + wchan = 0;
65733 + }
65734 +#endif
65735 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65736 + wchan = 0;
65737 + eip =0;
65738 + esp =0;
65739 +#endif
65740 +
65741 /* scale priority and nice values from timeslices to -20..20 */
65742 /* to make it look like a "normal" Unix priority/nice value */
65743 priority = task_prio(task);
65744 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65745 seq_put_decimal_ull(m, ' ', vsize);
65746 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65747 seq_put_decimal_ull(m, ' ', rsslim);
65748 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65749 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65750 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65751 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65752 +#else
65753 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65754 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65755 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65756 +#endif
65757 seq_put_decimal_ull(m, ' ', esp);
65758 seq_put_decimal_ull(m, ' ', eip);
65759 /* The signal information here is obsolete.
65760 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65761 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65762 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65763
65764 - if (mm && permitted) {
65765 + if (mm && permitted
65766 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65767 + && !PAX_RAND_FLAGS(mm)
65768 +#endif
65769 + ) {
65770 seq_put_decimal_ull(m, ' ', mm->start_data);
65771 seq_put_decimal_ull(m, ' ', mm->end_data);
65772 seq_put_decimal_ull(m, ' ', mm->start_brk);
65773 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65774 struct pid *pid, struct task_struct *task)
65775 {
65776 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65777 - struct mm_struct *mm = get_task_mm(task);
65778 + struct mm_struct *mm;
65779
65780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65781 + if (current->exec_id != m->exec_id) {
65782 + gr_log_badprocpid("statm");
65783 + return 0;
65784 + }
65785 +#endif
65786 + mm = get_task_mm(task);
65787 if (mm) {
65788 size = task_statm(mm, &shared, &text, &data, &resident);
65789 mmput(mm);
65790 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65791 return 0;
65792 }
65793
65794 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65795 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65796 +{
65797 + unsigned long flags;
65798 + u32 curr_ip = 0;
65799 +
65800 + if (lock_task_sighand(task, &flags)) {
65801 + curr_ip = task->signal->curr_ip;
65802 + unlock_task_sighand(task, &flags);
65803 + }
65804 + return seq_printf(m, "%pI4\n", &curr_ip);
65805 +}
65806 +#endif
65807 +
65808 #ifdef CONFIG_CHECKPOINT_RESTORE
65809 static struct pid *
65810 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65811 diff --git a/fs/proc/base.c b/fs/proc/base.c
65812 index 7dc3ea8..4cfe92f 100644
65813 --- a/fs/proc/base.c
65814 +++ b/fs/proc/base.c
65815 @@ -113,6 +113,14 @@ struct pid_entry {
65816 union proc_op op;
65817 };
65818
65819 +struct getdents_callback {
65820 + struct linux_dirent __user * current_dir;
65821 + struct linux_dirent __user * previous;
65822 + struct file * file;
65823 + int count;
65824 + int error;
65825 +};
65826 +
65827 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65828 .name = (NAME), \
65829 .len = sizeof(NAME) - 1, \
65830 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65831 return 0;
65832 }
65833
65834 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65835 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65836 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65837 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65838 +#endif
65839 +
65840 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65841 struct pid *pid, struct task_struct *task)
65842 {
65843 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65844 if (mm && !IS_ERR(mm)) {
65845 unsigned int nwords = 0;
65846 +
65847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65848 + /* allow if we're currently ptracing this task */
65849 + if (PAX_RAND_FLAGS(mm) &&
65850 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65851 + mmput(mm);
65852 + return 0;
65853 + }
65854 +#endif
65855 +
65856 do {
65857 nwords += 2;
65858 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65859 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65860 }
65861
65862
65863 -#ifdef CONFIG_KALLSYMS
65864 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65865 /*
65866 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65867 * Returns the resolved symbol. If that fails, simply return the address.
65868 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65869 mutex_unlock(&task->signal->cred_guard_mutex);
65870 }
65871
65872 -#ifdef CONFIG_STACKTRACE
65873 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65874
65875 #define MAX_STACK_TRACE_DEPTH 64
65876
65877 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65878 return 0;
65879 }
65880
65881 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65882 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65883 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65884 struct pid *pid, struct task_struct *task)
65885 {
65886 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65887 /************************************************************************/
65888
65889 /* permission checks */
65890 -static int proc_fd_access_allowed(struct inode *inode)
65891 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65892 {
65893 struct task_struct *task;
65894 int allowed = 0;
65895 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65896 */
65897 task = get_proc_task(inode);
65898 if (task) {
65899 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65900 + if (log)
65901 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65902 + else
65903 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65904 put_task_struct(task);
65905 }
65906 return allowed;
65907 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65908 struct task_struct *task,
65909 int hide_pid_min)
65910 {
65911 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65912 + return false;
65913 +
65914 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65915 + rcu_read_lock();
65916 + {
65917 + const struct cred *tmpcred = current_cred();
65918 + const struct cred *cred = __task_cred(task);
65919 +
65920 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65921 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65922 + || in_group_p(grsec_proc_gid)
65923 +#endif
65924 + ) {
65925 + rcu_read_unlock();
65926 + return true;
65927 + }
65928 + }
65929 + rcu_read_unlock();
65930 +
65931 + if (!pid->hide_pid)
65932 + return false;
65933 +#endif
65934 +
65935 if (pid->hide_pid < hide_pid_min)
65936 return true;
65937 if (in_group_p(pid->pid_gid))
65938 return true;
65939 +
65940 return ptrace_may_access(task, PTRACE_MODE_READ);
65941 }
65942
65943 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65944 put_task_struct(task);
65945
65946 if (!has_perms) {
65947 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65948 + {
65949 +#else
65950 if (pid->hide_pid == 2) {
65951 +#endif
65952 /*
65953 * Let's make getdents(), stat(), and open()
65954 * consistent with each other. If a process
65955 @@ -609,6 +665,8 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
65956
65957 if (task) {
65958 mm = mm_access(task, mode);
65959 + if (gr_acl_handle_procpidmem(task))
65960 + mm = ERR_PTR(-EPERM);
65961 put_task_struct(task);
65962
65963 if (!IS_ERR_OR_NULL(mm)) {
65964 @@ -630,6 +688,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65965 return PTR_ERR(mm);
65966
65967 file->private_data = mm;
65968 +
65969 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65970 + file->f_version = current->exec_id;
65971 +#endif
65972 +
65973 return 0;
65974 }
65975
65976 @@ -651,6 +714,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65977 ssize_t copied;
65978 char *page;
65979
65980 +#ifdef CONFIG_GRKERNSEC
65981 + if (write)
65982 + return -EPERM;
65983 +#endif
65984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65985 + if (file->f_version != current->exec_id) {
65986 + gr_log_badprocpid("mem");
65987 + return 0;
65988 + }
65989 +#endif
65990 +
65991 if (!mm)
65992 return 0;
65993
65994 @@ -663,7 +737,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65995 goto free;
65996
65997 while (count > 0) {
65998 - int this_len = min_t(int, count, PAGE_SIZE);
65999 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66000
66001 if (write && copy_from_user(page, buf, this_len)) {
66002 copied = -EFAULT;
66003 @@ -755,6 +829,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66004 if (!mm)
66005 return 0;
66006
66007 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66008 + if (file->f_version != current->exec_id) {
66009 + gr_log_badprocpid("environ");
66010 + return 0;
66011 + }
66012 +#endif
66013 +
66014 page = (char *)__get_free_page(GFP_TEMPORARY);
66015 if (!page)
66016 return -ENOMEM;
66017 @@ -764,7 +845,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66018 goto free;
66019 while (count > 0) {
66020 size_t this_len, max_len;
66021 - int retval;
66022 + ssize_t retval;
66023
66024 if (src >= (mm->env_end - mm->env_start))
66025 break;
66026 @@ -1378,7 +1459,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66027 int error = -EACCES;
66028
66029 /* Are we allowed to snoop on the tasks file descriptors? */
66030 - if (!proc_fd_access_allowed(inode))
66031 + if (!proc_fd_access_allowed(inode, 0))
66032 goto out;
66033
66034 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66035 @@ -1422,8 +1503,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66036 struct path path;
66037
66038 /* Are we allowed to snoop on the tasks file descriptors? */
66039 - if (!proc_fd_access_allowed(inode))
66040 - goto out;
66041 + /* logging this is needed for learning on chromium to work properly,
66042 + but we don't want to flood the logs from 'ps' which does a readlink
66043 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66044 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66045 + */
66046 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66047 + if (!proc_fd_access_allowed(inode,0))
66048 + goto out;
66049 + } else {
66050 + if (!proc_fd_access_allowed(inode,1))
66051 + goto out;
66052 + }
66053
66054 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66055 if (error)
66056 @@ -1473,7 +1564,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66057 rcu_read_lock();
66058 cred = __task_cred(task);
66059 inode->i_uid = cred->euid;
66060 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66061 + inode->i_gid = grsec_proc_gid;
66062 +#else
66063 inode->i_gid = cred->egid;
66064 +#endif
66065 rcu_read_unlock();
66066 }
66067 security_task_to_inode(task, inode);
66068 @@ -1509,10 +1604,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66069 return -ENOENT;
66070 }
66071 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66072 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66073 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66074 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66075 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66076 +#endif
66077 task_dumpable(task)) {
66078 cred = __task_cred(task);
66079 stat->uid = cred->euid;
66080 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66081 + stat->gid = grsec_proc_gid;
66082 +#else
66083 stat->gid = cred->egid;
66084 +#endif
66085 }
66086 }
66087 rcu_read_unlock();
66088 @@ -1550,11 +1654,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66089
66090 if (task) {
66091 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66092 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66093 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66094 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66095 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66096 +#endif
66097 task_dumpable(task)) {
66098 rcu_read_lock();
66099 cred = __task_cred(task);
66100 inode->i_uid = cred->euid;
66101 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66102 + inode->i_gid = grsec_proc_gid;
66103 +#else
66104 inode->i_gid = cred->egid;
66105 +#endif
66106 rcu_read_unlock();
66107 } else {
66108 inode->i_uid = GLOBAL_ROOT_UID;
66109 @@ -2085,6 +2198,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66110 if (!task)
66111 goto out_no_task;
66112
66113 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66114 + goto out;
66115 +
66116 /*
66117 * Yes, it does not scale. And it should not. Don't add
66118 * new entries into /proc/<tgid>/ without very good reasons.
66119 @@ -2115,6 +2231,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66120 if (!task)
66121 return -ENOENT;
66122
66123 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66124 + goto out;
66125 +
66126 if (!dir_emit_dots(file, ctx))
66127 goto out;
66128
66129 @@ -2557,7 +2676,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66130 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66131 #endif
66132 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66133 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66134 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66135 ONE("syscall", S_IRUSR, proc_pid_syscall),
66136 #endif
66137 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66138 @@ -2582,10 +2701,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66139 #ifdef CONFIG_SECURITY
66140 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66141 #endif
66142 -#ifdef CONFIG_KALLSYMS
66143 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66144 ONE("wchan", S_IRUGO, proc_pid_wchan),
66145 #endif
66146 -#ifdef CONFIG_STACKTRACE
66147 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66148 ONE("stack", S_IRUSR, proc_pid_stack),
66149 #endif
66150 #ifdef CONFIG_SCHEDSTATS
66151 @@ -2619,6 +2738,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66152 #ifdef CONFIG_HARDWALL
66153 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66154 #endif
66155 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66156 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66157 +#endif
66158 #ifdef CONFIG_USER_NS
66159 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66160 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66161 @@ -2748,7 +2870,14 @@ static int proc_pid_instantiate(struct inode *dir,
66162 if (!inode)
66163 goto out;
66164
66165 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66166 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66167 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66168 + inode->i_gid = grsec_proc_gid;
66169 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66170 +#else
66171 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66172 +#endif
66173 inode->i_op = &proc_tgid_base_inode_operations;
66174 inode->i_fop = &proc_tgid_base_operations;
66175 inode->i_flags|=S_IMMUTABLE;
66176 @@ -2786,7 +2915,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66177 if (!task)
66178 goto out;
66179
66180 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66181 + goto out_put_task;
66182 +
66183 result = proc_pid_instantiate(dir, dentry, task, NULL);
66184 +out_put_task:
66185 put_task_struct(task);
66186 out:
66187 return ERR_PTR(result);
66188 @@ -2900,7 +3033,7 @@ static const struct pid_entry tid_base_stuff[] = {
66189 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66190 #endif
66191 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66192 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66193 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66194 ONE("syscall", S_IRUSR, proc_pid_syscall),
66195 #endif
66196 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66197 @@ -2927,10 +3060,10 @@ static const struct pid_entry tid_base_stuff[] = {
66198 #ifdef CONFIG_SECURITY
66199 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66200 #endif
66201 -#ifdef CONFIG_KALLSYMS
66202 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66203 ONE("wchan", S_IRUGO, proc_pid_wchan),
66204 #endif
66205 -#ifdef CONFIG_STACKTRACE
66206 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66207 ONE("stack", S_IRUSR, proc_pid_stack),
66208 #endif
66209 #ifdef CONFIG_SCHEDSTATS
66210 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66211 index cbd82df..c0407d2 100644
66212 --- a/fs/proc/cmdline.c
66213 +++ b/fs/proc/cmdline.c
66214 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66215
66216 static int __init proc_cmdline_init(void)
66217 {
66218 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66219 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66220 +#else
66221 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66222 +#endif
66223 return 0;
66224 }
66225 fs_initcall(proc_cmdline_init);
66226 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66227 index 50493ed..248166b 100644
66228 --- a/fs/proc/devices.c
66229 +++ b/fs/proc/devices.c
66230 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66231
66232 static int __init proc_devices_init(void)
66233 {
66234 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66235 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66236 +#else
66237 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66238 +#endif
66239 return 0;
66240 }
66241 fs_initcall(proc_devices_init);
66242 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66243 index e11d7c5..9128ce06 100644
66244 --- a/fs/proc/fd.c
66245 +++ b/fs/proc/fd.c
66246 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66247 if (!task)
66248 return -ENOENT;
66249
66250 - files = get_files_struct(task);
66251 + if (!gr_acl_handle_procpidmem(task))
66252 + files = get_files_struct(task);
66253 put_task_struct(task);
66254
66255 if (files) {
66256 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66257 */
66258 int proc_fd_permission(struct inode *inode, int mask)
66259 {
66260 + struct task_struct *task;
66261 int rv = generic_permission(inode, mask);
66262 - if (rv == 0)
66263 - return 0;
66264 +
66265 if (task_tgid(current) == proc_pid(inode))
66266 rv = 0;
66267 +
66268 + task = get_proc_task(inode);
66269 + if (task == NULL)
66270 + return rv;
66271 +
66272 + if (gr_acl_handle_procpidmem(task))
66273 + rv = -EACCES;
66274 +
66275 + put_task_struct(task);
66276 +
66277 return rv;
66278 }
66279
66280 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66281 index 317b726..e329aed 100644
66282 --- a/fs/proc/generic.c
66283 +++ b/fs/proc/generic.c
66284 @@ -23,6 +23,7 @@
66285 #include <linux/bitops.h>
66286 #include <linux/spinlock.h>
66287 #include <linux/completion.h>
66288 +#include <linux/grsecurity.h>
66289 #include <asm/uaccess.h>
66290
66291 #include "internal.h"
66292 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66293 return proc_lookup_de(PDE(dir), dir, dentry);
66294 }
66295
66296 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66297 + unsigned int flags)
66298 +{
66299 + if (gr_proc_is_restricted())
66300 + return ERR_PTR(-EACCES);
66301 +
66302 + return proc_lookup_de(PDE(dir), dir, dentry);
66303 +}
66304 +
66305 /*
66306 * This returns non-zero if at EOF, so that the /proc
66307 * root directory can use this and check if it should
66308 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66309 return proc_readdir_de(PDE(inode), file, ctx);
66310 }
66311
66312 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66313 +{
66314 + struct inode *inode = file_inode(file);
66315 +
66316 + if (gr_proc_is_restricted())
66317 + return -EACCES;
66318 +
66319 + return proc_readdir_de(PDE(inode), file, ctx);
66320 +}
66321 +
66322 /*
66323 * These are the generic /proc directory operations. They
66324 * use the in-memory "struct proc_dir_entry" tree to parse
66325 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66326 .iterate = proc_readdir,
66327 };
66328
66329 +static const struct file_operations proc_dir_restricted_operations = {
66330 + .llseek = generic_file_llseek,
66331 + .read = generic_read_dir,
66332 + .iterate = proc_readdir_restrict,
66333 +};
66334 +
66335 /*
66336 * proc directories can do almost nothing..
66337 */
66338 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66339 .setattr = proc_notify_change,
66340 };
66341
66342 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66343 + .lookup = proc_lookup_restrict,
66344 + .getattr = proc_getattr,
66345 + .setattr = proc_notify_change,
66346 +};
66347 +
66348 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66349 {
66350 struct proc_dir_entry *tmp;
66351 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66352 return ret;
66353
66354 if (S_ISDIR(dp->mode)) {
66355 - dp->proc_fops = &proc_dir_operations;
66356 - dp->proc_iops = &proc_dir_inode_operations;
66357 + if (dp->restricted) {
66358 + dp->proc_fops = &proc_dir_restricted_operations;
66359 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66360 + } else {
66361 + dp->proc_fops = &proc_dir_operations;
66362 + dp->proc_iops = &proc_dir_inode_operations;
66363 + }
66364 dir->nlink++;
66365 } else if (S_ISLNK(dp->mode)) {
66366 dp->proc_iops = &proc_link_inode_operations;
66367 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66368 }
66369 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66370
66371 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66372 + struct proc_dir_entry *parent, void *data)
66373 +{
66374 + struct proc_dir_entry *ent;
66375 +
66376 + if (mode == 0)
66377 + mode = S_IRUGO | S_IXUGO;
66378 +
66379 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66380 + if (ent) {
66381 + ent->data = data;
66382 + ent->restricted = 1;
66383 + if (proc_register(parent, ent) < 0) {
66384 + kfree(ent);
66385 + ent = NULL;
66386 + }
66387 + }
66388 + return ent;
66389 +}
66390 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66391 +
66392 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66393 struct proc_dir_entry *parent)
66394 {
66395 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66396 }
66397 EXPORT_SYMBOL(proc_mkdir);
66398
66399 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66400 + struct proc_dir_entry *parent)
66401 +{
66402 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66403 +}
66404 +EXPORT_SYMBOL(proc_mkdir_restrict);
66405 +
66406 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66407 struct proc_dir_entry *parent,
66408 const struct file_operations *proc_fops,
66409 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66410 index 333080d..0a35ec4 100644
66411 --- a/fs/proc/inode.c
66412 +++ b/fs/proc/inode.c
66413 @@ -23,11 +23,17 @@
66414 #include <linux/slab.h>
66415 #include <linux/mount.h>
66416 #include <linux/magic.h>
66417 +#include <linux/grsecurity.h>
66418
66419 #include <asm/uaccess.h>
66420
66421 #include "internal.h"
66422
66423 +#ifdef CONFIG_PROC_SYSCTL
66424 +extern const struct inode_operations proc_sys_inode_operations;
66425 +extern const struct inode_operations proc_sys_dir_operations;
66426 +#endif
66427 +
66428 static void proc_evict_inode(struct inode *inode)
66429 {
66430 struct proc_dir_entry *de;
66431 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66432 ns = PROC_I(inode)->ns.ns;
66433 if (ns_ops && ns)
66434 ns_ops->put(ns);
66435 +
66436 +#ifdef CONFIG_PROC_SYSCTL
66437 + if (inode->i_op == &proc_sys_inode_operations ||
66438 + inode->i_op == &proc_sys_dir_operations)
66439 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66440 +#endif
66441 +
66442 }
66443
66444 static struct kmem_cache * proc_inode_cachep;
66445 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66446 if (de->mode) {
66447 inode->i_mode = de->mode;
66448 inode->i_uid = de->uid;
66449 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66450 + inode->i_gid = grsec_proc_gid;
66451 +#else
66452 inode->i_gid = de->gid;
66453 +#endif
66454 }
66455 if (de->size)
66456 inode->i_size = de->size;
66457 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66458 index aa7a0ee..f2318df 100644
66459 --- a/fs/proc/internal.h
66460 +++ b/fs/proc/internal.h
66461 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66462 struct completion *pde_unload_completion;
66463 struct list_head pde_openers; /* who did ->open, but not ->release */
66464 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66465 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66466 u8 namelen;
66467 char name[];
66468 -};
66469 +} __randomize_layout;
66470
66471 union proc_op {
66472 int (*proc_get_link)(struct dentry *, struct path *);
66473 @@ -66,7 +67,7 @@ struct proc_inode {
66474 struct ctl_table *sysctl_entry;
66475 struct proc_ns ns;
66476 struct inode vfs_inode;
66477 -};
66478 +} __randomize_layout;
66479
66480 /*
66481 * General functions
66482 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66483 struct pid *, struct task_struct *);
66484 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66485 struct pid *, struct task_struct *);
66486 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66487 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66488 + struct pid *, struct task_struct *);
66489 +#endif
66490
66491 /*
66492 * base.c
66493 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66494 * generic.c
66495 */
66496 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66497 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66498 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66499 struct dentry *);
66500 extern int proc_readdir(struct file *, struct dir_context *);
66501 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66502 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66503
66504 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66505 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66506 index a352d57..cb94a5c 100644
66507 --- a/fs/proc/interrupts.c
66508 +++ b/fs/proc/interrupts.c
66509 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66510
66511 static int __init proc_interrupts_init(void)
66512 {
66513 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66514 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66515 +#else
66516 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66517 +#endif
66518 return 0;
66519 }
66520 fs_initcall(proc_interrupts_init);
66521 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66522 index 91a4e64..cb007c0 100644
66523 --- a/fs/proc/kcore.c
66524 +++ b/fs/proc/kcore.c
66525 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66526 * the addresses in the elf_phdr on our list.
66527 */
66528 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66529 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66530 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66531 + if (tsz > buflen)
66532 tsz = buflen;
66533 -
66534 +
66535 while (buflen) {
66536 struct kcore_list *m;
66537
66538 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66539 kfree(elf_buf);
66540 } else {
66541 if (kern_addr_valid(start)) {
66542 - unsigned long n;
66543 + char *elf_buf;
66544 + mm_segment_t oldfs;
66545
66546 - n = copy_to_user(buffer, (char *)start, tsz);
66547 - /*
66548 - * We cannot distinguish between fault on source
66549 - * and fault on destination. When this happens
66550 - * we clear too and hope it will trigger the
66551 - * EFAULT again.
66552 - */
66553 - if (n) {
66554 - if (clear_user(buffer + tsz - n,
66555 - n))
66556 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66557 + if (!elf_buf)
66558 + return -ENOMEM;
66559 + oldfs = get_fs();
66560 + set_fs(KERNEL_DS);
66561 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66562 + set_fs(oldfs);
66563 + if (copy_to_user(buffer, elf_buf, tsz)) {
66564 + kfree(elf_buf);
66565 return -EFAULT;
66566 + }
66567 }
66568 + set_fs(oldfs);
66569 + kfree(elf_buf);
66570 } else {
66571 if (clear_user(buffer, tsz))
66572 return -EFAULT;
66573 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66574
66575 static int open_kcore(struct inode *inode, struct file *filp)
66576 {
66577 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66578 + return -EPERM;
66579 +#endif
66580 if (!capable(CAP_SYS_RAWIO))
66581 return -EPERM;
66582 if (kcore_need_update)
66583 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66584 index aa1eee0..03dda72 100644
66585 --- a/fs/proc/meminfo.c
66586 +++ b/fs/proc/meminfo.c
66587 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66588 vmi.used >> 10,
66589 vmi.largest_chunk >> 10
66590 #ifdef CONFIG_MEMORY_FAILURE
66591 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66592 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66593 #endif
66594 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66595 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66596 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66597 index d4a3574..b421ce9 100644
66598 --- a/fs/proc/nommu.c
66599 +++ b/fs/proc/nommu.c
66600 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66601
66602 if (file) {
66603 seq_pad(m, ' ');
66604 - seq_path(m, &file->f_path, "");
66605 + seq_path(m, &file->f_path, "\n\\");
66606 }
66607
66608 seq_putc(m, '\n');
66609 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66610 index a63af3e..b4f262a 100644
66611 --- a/fs/proc/proc_net.c
66612 +++ b/fs/proc/proc_net.c
66613 @@ -23,9 +23,27 @@
66614 #include <linux/nsproxy.h>
66615 #include <net/net_namespace.h>
66616 #include <linux/seq_file.h>
66617 +#include <linux/grsecurity.h>
66618
66619 #include "internal.h"
66620
66621 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66622 +static struct seq_operations *ipv6_seq_ops_addr;
66623 +
66624 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66625 +{
66626 + ipv6_seq_ops_addr = addr;
66627 +}
66628 +
66629 +void unregister_ipv6_seq_ops_addr(void)
66630 +{
66631 + ipv6_seq_ops_addr = NULL;
66632 +}
66633 +
66634 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66635 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66636 +#endif
66637 +
66638 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66639 {
66640 return pde->parent->data;
66641 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66642 return maybe_get_net(PDE_NET(PDE(inode)));
66643 }
66644
66645 +extern const struct seq_operations dev_seq_ops;
66646 +
66647 int seq_open_net(struct inode *ino, struct file *f,
66648 const struct seq_operations *ops, int size)
66649 {
66650 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66651
66652 BUG_ON(size < sizeof(*p));
66653
66654 + /* only permit access to /proc/net/dev */
66655 + if (
66656 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66657 + ops != ipv6_seq_ops_addr &&
66658 +#endif
66659 + ops != &dev_seq_ops && gr_proc_is_restricted())
66660 + return -EACCES;
66661 +
66662 net = get_proc_net(ino);
66663 if (net == NULL)
66664 return -ENXIO;
66665 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66666 int err;
66667 struct net *net;
66668
66669 + if (gr_proc_is_restricted())
66670 + return -EACCES;
66671 +
66672 err = -ENXIO;
66673 net = get_proc_net(inode);
66674 if (net == NULL)
66675 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66676 index f92d5dd..26398ac 100644
66677 --- a/fs/proc/proc_sysctl.c
66678 +++ b/fs/proc/proc_sysctl.c
66679 @@ -11,13 +11,21 @@
66680 #include <linux/namei.h>
66681 #include <linux/mm.h>
66682 #include <linux/module.h>
66683 +#include <linux/nsproxy.h>
66684 +#ifdef CONFIG_GRKERNSEC
66685 +#include <net/net_namespace.h>
66686 +#endif
66687 #include "internal.h"
66688
66689 +extern int gr_handle_chroot_sysctl(const int op);
66690 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66691 + const int op);
66692 +
66693 static const struct dentry_operations proc_sys_dentry_operations;
66694 static const struct file_operations proc_sys_file_operations;
66695 -static const struct inode_operations proc_sys_inode_operations;
66696 +const struct inode_operations proc_sys_inode_operations;
66697 static const struct file_operations proc_sys_dir_file_operations;
66698 -static const struct inode_operations proc_sys_dir_operations;
66699 +const struct inode_operations proc_sys_dir_operations;
66700
66701 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66702 {
66703 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66704
66705 err = NULL;
66706 d_set_d_op(dentry, &proc_sys_dentry_operations);
66707 +
66708 + gr_handle_proc_create(dentry, inode);
66709 +
66710 d_add(dentry, inode);
66711
66712 out:
66713 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66714 struct inode *inode = file_inode(filp);
66715 struct ctl_table_header *head = grab_header(inode);
66716 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66717 + int op = write ? MAY_WRITE : MAY_READ;
66718 ssize_t error;
66719 size_t res;
66720
66721 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66722 * and won't be until we finish.
66723 */
66724 error = -EPERM;
66725 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66726 + if (sysctl_perm(head, table, op))
66727 goto out;
66728
66729 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66730 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66731 if (!table->proc_handler)
66732 goto out;
66733
66734 +#ifdef CONFIG_GRKERNSEC
66735 + error = -EPERM;
66736 + if (gr_handle_chroot_sysctl(op))
66737 + goto out;
66738 + dget(filp->f_path.dentry);
66739 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66740 + dput(filp->f_path.dentry);
66741 + goto out;
66742 + }
66743 + dput(filp->f_path.dentry);
66744 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66745 + goto out;
66746 + if (write) {
66747 + if (current->nsproxy->net_ns != table->extra2) {
66748 + if (!capable(CAP_SYS_ADMIN))
66749 + goto out;
66750 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66751 + goto out;
66752 + }
66753 +#endif
66754 +
66755 /* careful: calling conventions are nasty here */
66756 res = count;
66757 error = table->proc_handler(table, write, buf, &res, ppos);
66758 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66759 return false;
66760 } else {
66761 d_set_d_op(child, &proc_sys_dentry_operations);
66762 +
66763 + gr_handle_proc_create(child, inode);
66764 +
66765 d_add(child, inode);
66766 }
66767 } else {
66768 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66769 if ((*pos)++ < ctx->pos)
66770 return true;
66771
66772 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66773 + return 0;
66774 +
66775 if (unlikely(S_ISLNK(table->mode)))
66776 res = proc_sys_link_fill_cache(file, ctx, head, table);
66777 else
66778 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66779 if (IS_ERR(head))
66780 return PTR_ERR(head);
66781
66782 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66783 + return -ENOENT;
66784 +
66785 generic_fillattr(inode, stat);
66786 if (table)
66787 stat->mode = (stat->mode & S_IFMT) | table->mode;
66788 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66789 .llseek = generic_file_llseek,
66790 };
66791
66792 -static const struct inode_operations proc_sys_inode_operations = {
66793 +const struct inode_operations proc_sys_inode_operations = {
66794 .permission = proc_sys_permission,
66795 .setattr = proc_sys_setattr,
66796 .getattr = proc_sys_getattr,
66797 };
66798
66799 -static const struct inode_operations proc_sys_dir_operations = {
66800 +const struct inode_operations proc_sys_dir_operations = {
66801 .lookup = proc_sys_lookup,
66802 .permission = proc_sys_permission,
66803 .setattr = proc_sys_setattr,
66804 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66805 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66806 const char *name, int namelen)
66807 {
66808 - struct ctl_table *table;
66809 + ctl_table_no_const *table;
66810 struct ctl_dir *new;
66811 struct ctl_node *node;
66812 char *new_name;
66813 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66814 return NULL;
66815
66816 node = (struct ctl_node *)(new + 1);
66817 - table = (struct ctl_table *)(node + 1);
66818 + table = (ctl_table_no_const *)(node + 1);
66819 new_name = (char *)(table + 2);
66820 memcpy(new_name, name, namelen);
66821 new_name[namelen] = '\0';
66822 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66823 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66824 struct ctl_table_root *link_root)
66825 {
66826 - struct ctl_table *link_table, *entry, *link;
66827 + ctl_table_no_const *link_table, *link;
66828 + struct ctl_table *entry;
66829 struct ctl_table_header *links;
66830 struct ctl_node *node;
66831 char *link_name;
66832 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66833 return NULL;
66834
66835 node = (struct ctl_node *)(links + 1);
66836 - link_table = (struct ctl_table *)(node + nr_entries);
66837 + link_table = (ctl_table_no_const *)(node + nr_entries);
66838 link_name = (char *)&link_table[nr_entries + 1];
66839
66840 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66841 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66842 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66843 struct ctl_table *table)
66844 {
66845 - struct ctl_table *ctl_table_arg = NULL;
66846 - struct ctl_table *entry, *files;
66847 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66848 + struct ctl_table *entry;
66849 int nr_files = 0;
66850 int nr_dirs = 0;
66851 int err = -ENOMEM;
66852 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66853 nr_files++;
66854 }
66855
66856 - files = table;
66857 /* If there are mixed files and directories we need a new table */
66858 if (nr_dirs && nr_files) {
66859 - struct ctl_table *new;
66860 + ctl_table_no_const *new;
66861 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66862 GFP_KERNEL);
66863 if (!files)
66864 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66865 /* Register everything except a directory full of subdirectories */
66866 if (nr_files || !nr_dirs) {
66867 struct ctl_table_header *header;
66868 - header = __register_sysctl_table(set, path, files);
66869 + header = __register_sysctl_table(set, path, files ? files : table);
66870 if (!header) {
66871 kfree(ctl_table_arg);
66872 goto out;
66873 diff --git a/fs/proc/root.c b/fs/proc/root.c
66874 index 094e44d..085a877 100644
66875 --- a/fs/proc/root.c
66876 +++ b/fs/proc/root.c
66877 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66878 proc_mkdir("openprom", NULL);
66879 #endif
66880 proc_tty_init();
66881 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66882 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66883 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66884 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66885 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66886 +#endif
66887 +#else
66888 proc_mkdir("bus", NULL);
66889 +#endif
66890 proc_sys_init();
66891 }
66892
66893 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66894 index 510413eb..34d9a8c 100644
66895 --- a/fs/proc/stat.c
66896 +++ b/fs/proc/stat.c
66897 @@ -11,6 +11,7 @@
66898 #include <linux/irqnr.h>
66899 #include <linux/cputime.h>
66900 #include <linux/tick.h>
66901 +#include <linux/grsecurity.h>
66902
66903 #ifndef arch_irq_stat_cpu
66904 #define arch_irq_stat_cpu(cpu) 0
66905 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66906 u64 sum_softirq = 0;
66907 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66908 struct timespec boottime;
66909 + int unrestricted = 1;
66910 +
66911 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66912 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66913 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66914 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66915 + && !in_group_p(grsec_proc_gid)
66916 +#endif
66917 + )
66918 + unrestricted = 0;
66919 +#endif
66920 +#endif
66921
66922 user = nice = system = idle = iowait =
66923 irq = softirq = steal = 0;
66924 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66925 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66926 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66927 idle += get_idle_time(i);
66928 - iowait += get_iowait_time(i);
66929 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66930 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66931 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66932 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66933 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66934 - sum += kstat_cpu_irqs_sum(i);
66935 - sum += arch_irq_stat_cpu(i);
66936 + if (unrestricted) {
66937 + iowait += get_iowait_time(i);
66938 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66939 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66940 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66941 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66942 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66943 + sum += kstat_cpu_irqs_sum(i);
66944 + sum += arch_irq_stat_cpu(i);
66945 + for (j = 0; j < NR_SOFTIRQS; j++) {
66946 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66947
66948 - for (j = 0; j < NR_SOFTIRQS; j++) {
66949 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66950 -
66951 - per_softirq_sums[j] += softirq_stat;
66952 - sum_softirq += softirq_stat;
66953 + per_softirq_sums[j] += softirq_stat;
66954 + sum_softirq += softirq_stat;
66955 + }
66956 }
66957 }
66958 - sum += arch_irq_stat();
66959 + if (unrestricted)
66960 + sum += arch_irq_stat();
66961
66962 seq_puts(p, "cpu ");
66963 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66964 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66965 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66966 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66967 idle = get_idle_time(i);
66968 - iowait = get_iowait_time(i);
66969 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66970 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66971 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66972 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66973 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66974 + if (unrestricted) {
66975 + iowait = get_iowait_time(i);
66976 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66977 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66978 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66979 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66980 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66981 + }
66982 seq_printf(p, "cpu%d", i);
66983 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66984 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66985 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66986
66987 /* sum again ? it could be updated? */
66988 for_each_irq_nr(j)
66989 - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
66990 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs_usr(j) : 0ULL);
66991
66992 seq_printf(p,
66993 "\nctxt %llu\n"
66994 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66995 "processes %lu\n"
66996 "procs_running %lu\n"
66997 "procs_blocked %lu\n",
66998 - nr_context_switches(),
66999 + unrestricted ? nr_context_switches() : 0ULL,
67000 (unsigned long)jif,
67001 - total_forks,
67002 - nr_running(),
67003 - nr_iowait());
67004 + unrestricted ? total_forks : 0UL,
67005 + unrestricted ? nr_running() : 0UL,
67006 + unrestricted ? nr_iowait() : 0UL);
67007
67008 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67009
67010 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67011 index 4e0388c..fc6a0e1 100644
67012 --- a/fs/proc/task_mmu.c
67013 +++ b/fs/proc/task_mmu.c
67014 @@ -13,12 +13,19 @@
67015 #include <linux/swap.h>
67016 #include <linux/swapops.h>
67017 #include <linux/mmu_notifier.h>
67018 +#include <linux/grsecurity.h>
67019
67020 #include <asm/elf.h>
67021 #include <asm/uaccess.h>
67022 #include <asm/tlbflush.h>
67023 #include "internal.h"
67024
67025 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67026 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67027 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67028 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67029 +#endif
67030 +
67031 void task_mem(struct seq_file *m, struct mm_struct *mm)
67032 {
67033 unsigned long data, text, lib, swap;
67034 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67035 "VmExe:\t%8lu kB\n"
67036 "VmLib:\t%8lu kB\n"
67037 "VmPTE:\t%8lu kB\n"
67038 - "VmSwap:\t%8lu kB\n",
67039 - hiwater_vm << (PAGE_SHIFT-10),
67040 + "VmSwap:\t%8lu kB\n"
67041 +
67042 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67043 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67044 +#endif
67045 +
67046 + ,hiwater_vm << (PAGE_SHIFT-10),
67047 total_vm << (PAGE_SHIFT-10),
67048 mm->locked_vm << (PAGE_SHIFT-10),
67049 mm->pinned_vm << (PAGE_SHIFT-10),
67050 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67051 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67052 (PTRS_PER_PTE * sizeof(pte_t) *
67053 atomic_long_read(&mm->nr_ptes)) >> 10,
67054 - swap << (PAGE_SHIFT-10));
67055 + swap << (PAGE_SHIFT-10)
67056 +
67057 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67058 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67059 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67060 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67061 +#else
67062 + , mm->context.user_cs_base
67063 + , mm->context.user_cs_limit
67064 +#endif
67065 +#endif
67066 +
67067 + );
67068 }
67069
67070 unsigned long task_vsize(struct mm_struct *mm)
67071 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67072 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67073 }
67074
67075 - /* We don't show the stack guard page in /proc/maps */
67076 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67077 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67078 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67079 +#else
67080 start = vma->vm_start;
67081 - if (stack_guard_page_start(vma, start))
67082 - start += PAGE_SIZE;
67083 end = vma->vm_end;
67084 - if (stack_guard_page_end(vma, end))
67085 - end -= PAGE_SIZE;
67086 +#endif
67087
67088 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67089 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67090 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67091 flags & VM_WRITE ? 'w' : '-',
67092 flags & VM_EXEC ? 'x' : '-',
67093 flags & VM_MAYSHARE ? 's' : 'p',
67094 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67095 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67096 +#else
67097 pgoff,
67098 +#endif
67099 MAJOR(dev), MINOR(dev), ino);
67100
67101 /*
67102 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67103 */
67104 if (file) {
67105 seq_pad(m, ' ');
67106 - seq_path(m, &file->f_path, "\n");
67107 + seq_path(m, &file->f_path, "\n\\");
67108 goto done;
67109 }
67110
67111 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67112 * Thread stack in /proc/PID/task/TID/maps or
67113 * the main process stack.
67114 */
67115 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67116 - vma->vm_end >= mm->start_stack)) {
67117 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67118 + (vma->vm_start <= mm->start_stack &&
67119 + vma->vm_end >= mm->start_stack)) {
67120 name = "[stack]";
67121 } else {
67122 /* Thread stack in /proc/PID/maps */
67123 @@ -359,6 +388,12 @@ done:
67124
67125 static int show_map(struct seq_file *m, void *v, int is_pid)
67126 {
67127 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67128 + if (current->exec_id != m->exec_id) {
67129 + gr_log_badprocpid("maps");
67130 + return 0;
67131 + }
67132 +#endif
67133 show_map_vma(m, v, is_pid);
67134 m_cache_vma(m, v);
67135 return 0;
67136 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67137 .private = &mss,
67138 };
67139
67140 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67141 + if (current->exec_id != m->exec_id) {
67142 + gr_log_badprocpid("smaps");
67143 + return 0;
67144 + }
67145 +#endif
67146 memset(&mss, 0, sizeof mss);
67147 - mss.vma = vma;
67148 - /* mmap_sem is held in m_start */
67149 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67150 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67151 -
67152 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67153 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67154 +#endif
67155 + mss.vma = vma;
67156 + /* mmap_sem is held in m_start */
67157 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67158 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67159 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67160 + }
67161 +#endif
67162 show_map_vma(m, vma, is_pid);
67163
67164 seq_printf(m,
67165 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67166 "KernelPageSize: %8lu kB\n"
67167 "MMUPageSize: %8lu kB\n"
67168 "Locked: %8lu kB\n",
67169 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67170 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67171 +#else
67172 (vma->vm_end - vma->vm_start) >> 10,
67173 +#endif
67174 mss.resident >> 10,
67175 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67176 mss.shared_clean >> 10,
67177 @@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67178 char buffer[64];
67179 int nid;
67180
67181 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67182 + if (current->exec_id != m->exec_id) {
67183 + gr_log_badprocpid("numa_maps");
67184 + return 0;
67185 + }
67186 +#endif
67187 +
67188 if (!mm)
67189 return 0;
67190
67191 @@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67192 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
67193 }
67194
67195 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67196 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67197 +#else
67198 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67199 +#endif
67200
67201 if (file) {
67202 seq_puts(m, " file=");
67203 - seq_path(m, &file->f_path, "\n\t= ");
67204 + seq_path(m, &file->f_path, "\n\t\\= ");
67205 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67206 seq_puts(m, " heap");
67207 } else {
67208 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67209 index 599ec2e..f1413ae 100644
67210 --- a/fs/proc/task_nommu.c
67211 +++ b/fs/proc/task_nommu.c
67212 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67213 else
67214 bytes += kobjsize(mm);
67215
67216 - if (current->fs && current->fs->users > 1)
67217 + if (current->fs && atomic_read(&current->fs->users) > 1)
67218 sbytes += kobjsize(current->fs);
67219 else
67220 bytes += kobjsize(current->fs);
67221 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67222
67223 if (file) {
67224 seq_pad(m, ' ');
67225 - seq_path(m, &file->f_path, "");
67226 + seq_path(m, &file->f_path, "\n\\");
67227 } else if (mm) {
67228 pid_t tid = pid_of_stack(priv, vma, is_pid);
67229
67230 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67231 index a90d6d35..d08047c 100644
67232 --- a/fs/proc/vmcore.c
67233 +++ b/fs/proc/vmcore.c
67234 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67235 nr_bytes = count;
67236
67237 /* If pfn is not ram, return zeros for sparse dump files */
67238 - if (pfn_is_ram(pfn) == 0)
67239 - memset(buf, 0, nr_bytes);
67240 - else {
67241 + if (pfn_is_ram(pfn) == 0) {
67242 + if (userbuf) {
67243 + if (clear_user((char __force_user *)buf, nr_bytes))
67244 + return -EFAULT;
67245 + } else
67246 + memset(buf, 0, nr_bytes);
67247 + } else {
67248 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67249 offset, userbuf);
67250 if (tmp < 0)
67251 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67252 static int copy_to(void *target, void *src, size_t size, int userbuf)
67253 {
67254 if (userbuf) {
67255 - if (copy_to_user((char __user *) target, src, size))
67256 + if (copy_to_user((char __force_user *) target, src, size))
67257 return -EFAULT;
67258 } else {
67259 memcpy(target, src, size);
67260 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67261 if (*fpos < m->offset + m->size) {
67262 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67263 start = m->paddr + *fpos - m->offset;
67264 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67265 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67266 if (tmp < 0)
67267 return tmp;
67268 buflen -= tsz;
67269 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67270 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67271 size_t buflen, loff_t *fpos)
67272 {
67273 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67274 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67275 }
67276
67277 /*
67278 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67279 index d3fb2b6..43a8140 100644
67280 --- a/fs/qnx6/qnx6.h
67281 +++ b/fs/qnx6/qnx6.h
67282 @@ -74,7 +74,7 @@ enum {
67283 BYTESEX_BE,
67284 };
67285
67286 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67287 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67288 {
67289 if (sbi->s_bytesex == BYTESEX_LE)
67290 return le64_to_cpu((__force __le64)n);
67291 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67292 return (__force __fs64)cpu_to_be64(n);
67293 }
67294
67295 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67296 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67297 {
67298 if (sbi->s_bytesex == BYTESEX_LE)
67299 return le32_to_cpu((__force __le32)n);
67300 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67301 index bb2869f..d34ada8 100644
67302 --- a/fs/quota/netlink.c
67303 +++ b/fs/quota/netlink.c
67304 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67305 void quota_send_warning(struct kqid qid, dev_t dev,
67306 const char warntype)
67307 {
67308 - static atomic_t seq;
67309 + static atomic_unchecked_t seq;
67310 struct sk_buff *skb;
67311 void *msg_head;
67312 int ret;
67313 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67314 "VFS: Not enough memory to send quota warning.\n");
67315 return;
67316 }
67317 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67318 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67319 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67320 if (!msg_head) {
67321 printk(KERN_ERR
67322 diff --git a/fs/read_write.c b/fs/read_write.c
67323 index 7d9318c..51b336f 100644
67324 --- a/fs/read_write.c
67325 +++ b/fs/read_write.c
67326 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67327
67328 old_fs = get_fs();
67329 set_fs(get_ds());
67330 - p = (__force const char __user *)buf;
67331 + p = (const char __force_user *)buf;
67332 if (count > MAX_RW_COUNT)
67333 count = MAX_RW_COUNT;
67334 if (file->f_op->write)
67335 diff --git a/fs/readdir.c b/fs/readdir.c
67336 index 33fd922..e0d6094 100644
67337 --- a/fs/readdir.c
67338 +++ b/fs/readdir.c
67339 @@ -18,6 +18,7 @@
67340 #include <linux/security.h>
67341 #include <linux/syscalls.h>
67342 #include <linux/unistd.h>
67343 +#include <linux/namei.h>
67344
67345 #include <asm/uaccess.h>
67346
67347 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67348 struct readdir_callback {
67349 struct dir_context ctx;
67350 struct old_linux_dirent __user * dirent;
67351 + struct file * file;
67352 int result;
67353 };
67354
67355 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67356 buf->result = -EOVERFLOW;
67357 return -EOVERFLOW;
67358 }
67359 +
67360 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67361 + return 0;
67362 +
67363 buf->result++;
67364 dirent = buf->dirent;
67365 if (!access_ok(VERIFY_WRITE, dirent,
67366 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67367 if (!f.file)
67368 return -EBADF;
67369
67370 + buf.file = f.file;
67371 error = iterate_dir(f.file, &buf.ctx);
67372 if (buf.result)
67373 error = buf.result;
67374 @@ -144,6 +151,7 @@ struct getdents_callback {
67375 struct dir_context ctx;
67376 struct linux_dirent __user * current_dir;
67377 struct linux_dirent __user * previous;
67378 + struct file * file;
67379 int count;
67380 int error;
67381 };
67382 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67383 buf->error = -EOVERFLOW;
67384 return -EOVERFLOW;
67385 }
67386 +
67387 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67388 + return 0;
67389 +
67390 dirent = buf->previous;
67391 if (dirent) {
67392 if (__put_user(offset, &dirent->d_off))
67393 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67394 if (!f.file)
67395 return -EBADF;
67396
67397 + buf.file = f.file;
67398 error = iterate_dir(f.file, &buf.ctx);
67399 if (error >= 0)
67400 error = buf.error;
67401 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67402 struct dir_context ctx;
67403 struct linux_dirent64 __user * current_dir;
67404 struct linux_dirent64 __user * previous;
67405 + struct file *file;
67406 int count;
67407 int error;
67408 };
67409 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67410 buf->error = -EINVAL; /* only used if we fail.. */
67411 if (reclen > buf->count)
67412 return -EINVAL;
67413 +
67414 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67415 + return 0;
67416 +
67417 dirent = buf->previous;
67418 if (dirent) {
67419 if (__put_user(offset, &dirent->d_off))
67420 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67421 if (!f.file)
67422 return -EBADF;
67423
67424 + buf.file = f.file;
67425 error = iterate_dir(f.file, &buf.ctx);
67426 if (error >= 0)
67427 error = buf.error;
67428 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67429 index 9c02d96..6562c10 100644
67430 --- a/fs/reiserfs/do_balan.c
67431 +++ b/fs/reiserfs/do_balan.c
67432 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67433 return;
67434 }
67435
67436 - atomic_inc(&fs_generation(tb->tb_sb));
67437 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67438 do_balance_starts(tb);
67439
67440 /*
67441 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67442 index aca73dd..e3c558d 100644
67443 --- a/fs/reiserfs/item_ops.c
67444 +++ b/fs/reiserfs/item_ops.c
67445 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67446 }
67447
67448 static struct item_operations errcatch_ops = {
67449 - errcatch_bytes_number,
67450 - errcatch_decrement_key,
67451 - errcatch_is_left_mergeable,
67452 - errcatch_print_item,
67453 - errcatch_check_item,
67454 + .bytes_number = errcatch_bytes_number,
67455 + .decrement_key = errcatch_decrement_key,
67456 + .is_left_mergeable = errcatch_is_left_mergeable,
67457 + .print_item = errcatch_print_item,
67458 + .check_item = errcatch_check_item,
67459
67460 - errcatch_create_vi,
67461 - errcatch_check_left,
67462 - errcatch_check_right,
67463 - errcatch_part_size,
67464 - errcatch_unit_num,
67465 - errcatch_print_vi
67466 + .create_vi = errcatch_create_vi,
67467 + .check_left = errcatch_check_left,
67468 + .check_right = errcatch_check_right,
67469 + .part_size = errcatch_part_size,
67470 + .unit_num = errcatch_unit_num,
67471 + .print_vi = errcatch_print_vi
67472 };
67473
67474 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67475 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67476 index 621b9f3..af527fd 100644
67477 --- a/fs/reiserfs/procfs.c
67478 +++ b/fs/reiserfs/procfs.c
67479 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67480 "SMALL_TAILS " : "NO_TAILS ",
67481 replay_only(sb) ? "REPLAY_ONLY " : "",
67482 convert_reiserfs(sb) ? "CONV " : "",
67483 - atomic_read(&r->s_generation_counter),
67484 + atomic_read_unchecked(&r->s_generation_counter),
67485 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67486 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67487 SF(s_good_search_by_key_reada), SF(s_bmaps),
67488 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67489 index 1894d96..1dfd1c2 100644
67490 --- a/fs/reiserfs/reiserfs.h
67491 +++ b/fs/reiserfs/reiserfs.h
67492 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67493 /* Comment? -Hans */
67494 wait_queue_head_t s_wait;
67495 /* increased by one every time the tree gets re-balanced */
67496 - atomic_t s_generation_counter;
67497 + atomic_unchecked_t s_generation_counter;
67498
67499 /* File system properties. Currently holds on-disk FS format */
67500 unsigned long s_properties;
67501 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67502 #define REISERFS_USER_MEM 1 /* user memory mode */
67503
67504 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67505 -#define get_generation(s) atomic_read (&fs_generation(s))
67506 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67507 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67508 #define __fs_changed(gen,s) (gen != get_generation (s))
67509 #define fs_changed(gen,s) \
67510 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67511 index b27ef35..d9c6c18 100644
67512 --- a/fs/reiserfs/super.c
67513 +++ b/fs/reiserfs/super.c
67514 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67515 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67516 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67517 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67518 +#ifdef CONFIG_REISERFS_FS_XATTR
67519 + /* turn on user xattrs by default */
67520 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67521 +#endif
67522 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67523 sbi->s_alloc_options.preallocmin = 0;
67524 /* Preallocate by 16 blocks (17-1) at once */
67525 diff --git a/fs/select.c b/fs/select.c
67526 index 467bb1c..cf9d65a 100644
67527 --- a/fs/select.c
67528 +++ b/fs/select.c
67529 @@ -20,6 +20,7 @@
67530 #include <linux/export.h>
67531 #include <linux/slab.h>
67532 #include <linux/poll.h>
67533 +#include <linux/security.h>
67534 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67535 #include <linux/file.h>
67536 #include <linux/fdtable.h>
67537 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67538 struct poll_list *walk = head;
67539 unsigned long todo = nfds;
67540
67541 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67542 if (nfds > rlimit(RLIMIT_NOFILE))
67543 return -EINVAL;
67544
67545 diff --git a/fs/seq_file.c b/fs/seq_file.c
67546 index 3857b72..0b7281e 100644
67547 --- a/fs/seq_file.c
67548 +++ b/fs/seq_file.c
67549 @@ -12,6 +12,8 @@
67550 #include <linux/slab.h>
67551 #include <linux/cred.h>
67552 #include <linux/mm.h>
67553 +#include <linux/sched.h>
67554 +#include <linux/grsecurity.h>
67555
67556 #include <asm/uaccess.h>
67557 #include <asm/page.h>
67558 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67559
67560 static void *seq_buf_alloc(unsigned long size)
67561 {
67562 - void *buf;
67563 -
67564 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67565 - if (!buf && size > PAGE_SIZE)
67566 - buf = vmalloc(size);
67567 - return buf;
67568 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67569 }
67570
67571 /**
67572 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67573 #ifdef CONFIG_USER_NS
67574 p->user_ns = file->f_cred->user_ns;
67575 #endif
67576 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67577 + p->exec_id = current->exec_id;
67578 +#endif
67579
67580 /*
67581 * Wrappers around seq_open(e.g. swaps_open) need to be
67582 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67583 }
67584 EXPORT_SYMBOL(seq_open);
67585
67586 +
67587 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67588 +{
67589 + if (gr_proc_is_restricted())
67590 + return -EACCES;
67591 +
67592 + return seq_open(file, op);
67593 +}
67594 +EXPORT_SYMBOL(seq_open_restrict);
67595 +
67596 static int traverse(struct seq_file *m, loff_t offset)
67597 {
67598 loff_t pos = 0, index;
67599 @@ -165,7 +175,7 @@ Eoverflow:
67600 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67601 {
67602 struct seq_file *m = file->private_data;
67603 - size_t copied = 0;
67604 + ssize_t copied = 0;
67605 loff_t pos;
67606 size_t n;
67607 void *p;
67608 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67609 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67610 void *data)
67611 {
67612 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67613 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67614 int res = -ENOMEM;
67615
67616 if (op) {
67617 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67618 }
67619 EXPORT_SYMBOL(single_open_size);
67620
67621 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67622 + void *data)
67623 +{
67624 + if (gr_proc_is_restricted())
67625 + return -EACCES;
67626 +
67627 + return single_open(file, show, data);
67628 +}
67629 +EXPORT_SYMBOL(single_open_restrict);
67630 +
67631 +
67632 int single_release(struct inode *inode, struct file *file)
67633 {
67634 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67635 diff --git a/fs/splice.c b/fs/splice.c
67636 index 75c6058..770d40c 100644
67637 --- a/fs/splice.c
67638 +++ b/fs/splice.c
67639 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67640 pipe_lock(pipe);
67641
67642 for (;;) {
67643 - if (!pipe->readers) {
67644 + if (!atomic_read(&pipe->readers)) {
67645 send_sig(SIGPIPE, current, 0);
67646 if (!ret)
67647 ret = -EPIPE;
67648 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67649 page_nr++;
67650 ret += buf->len;
67651
67652 - if (pipe->files)
67653 + if (atomic_read(&pipe->files))
67654 do_wakeup = 1;
67655
67656 if (!--spd->nr_pages)
67657 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67658 do_wakeup = 0;
67659 }
67660
67661 - pipe->waiting_writers++;
67662 + atomic_inc(&pipe->waiting_writers);
67663 pipe_wait(pipe);
67664 - pipe->waiting_writers--;
67665 + atomic_dec(&pipe->waiting_writers);
67666 }
67667
67668 pipe_unlock(pipe);
67669 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67670 old_fs = get_fs();
67671 set_fs(get_ds());
67672 /* The cast to a user pointer is valid due to the set_fs() */
67673 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67674 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67675 set_fs(old_fs);
67676
67677 return res;
67678 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67679 old_fs = get_fs();
67680 set_fs(get_ds());
67681 /* The cast to a user pointer is valid due to the set_fs() */
67682 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67683 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67684 set_fs(old_fs);
67685
67686 return res;
67687 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67688 goto err;
67689
67690 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67691 - vec[i].iov_base = (void __user *) page_address(page);
67692 + vec[i].iov_base = (void __force_user *) page_address(page);
67693 vec[i].iov_len = this_len;
67694 spd.pages[i] = page;
67695 spd.nr_pages++;
67696 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67697 ops->release(pipe, buf);
67698 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67699 pipe->nrbufs--;
67700 - if (pipe->files)
67701 + if (atomic_read(&pipe->files))
67702 sd->need_wakeup = true;
67703 }
67704
67705 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67706 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67707 {
67708 while (!pipe->nrbufs) {
67709 - if (!pipe->writers)
67710 + if (!atomic_read(&pipe->writers))
67711 return 0;
67712
67713 - if (!pipe->waiting_writers && sd->num_spliced)
67714 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67715 return 0;
67716
67717 if (sd->flags & SPLICE_F_NONBLOCK)
67718 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67719 ops->release(pipe, buf);
67720 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67721 pipe->nrbufs--;
67722 - if (pipe->files)
67723 + if (atomic_read(&pipe->files))
67724 sd.need_wakeup = true;
67725 } else {
67726 buf->offset += ret;
67727 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67728 * out of the pipe right after the splice_to_pipe(). So set
67729 * PIPE_READERS appropriately.
67730 */
67731 - pipe->readers = 1;
67732 + atomic_set(&pipe->readers, 1);
67733
67734 current->splice_pipe = pipe;
67735 }
67736 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67737
67738 partial[buffers].offset = off;
67739 partial[buffers].len = plen;
67740 + partial[buffers].private = 0;
67741
67742 off = 0;
67743 len -= plen;
67744 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67745 ret = -ERESTARTSYS;
67746 break;
67747 }
67748 - if (!pipe->writers)
67749 + if (!atomic_read(&pipe->writers))
67750 break;
67751 - if (!pipe->waiting_writers) {
67752 + if (!atomic_read(&pipe->waiting_writers)) {
67753 if (flags & SPLICE_F_NONBLOCK) {
67754 ret = -EAGAIN;
67755 break;
67756 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67757 pipe_lock(pipe);
67758
67759 while (pipe->nrbufs >= pipe->buffers) {
67760 - if (!pipe->readers) {
67761 + if (!atomic_read(&pipe->readers)) {
67762 send_sig(SIGPIPE, current, 0);
67763 ret = -EPIPE;
67764 break;
67765 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67766 ret = -ERESTARTSYS;
67767 break;
67768 }
67769 - pipe->waiting_writers++;
67770 + atomic_inc(&pipe->waiting_writers);
67771 pipe_wait(pipe);
67772 - pipe->waiting_writers--;
67773 + atomic_dec(&pipe->waiting_writers);
67774 }
67775
67776 pipe_unlock(pipe);
67777 @@ -1818,14 +1819,14 @@ retry:
67778 pipe_double_lock(ipipe, opipe);
67779
67780 do {
67781 - if (!opipe->readers) {
67782 + if (!atomic_read(&opipe->readers)) {
67783 send_sig(SIGPIPE, current, 0);
67784 if (!ret)
67785 ret = -EPIPE;
67786 break;
67787 }
67788
67789 - if (!ipipe->nrbufs && !ipipe->writers)
67790 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67791 break;
67792
67793 /*
67794 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67795 pipe_double_lock(ipipe, opipe);
67796
67797 do {
67798 - if (!opipe->readers) {
67799 + if (!atomic_read(&opipe->readers)) {
67800 send_sig(SIGPIPE, current, 0);
67801 if (!ret)
67802 ret = -EPIPE;
67803 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67804 * return EAGAIN if we have the potential of some data in the
67805 * future, otherwise just return 0
67806 */
67807 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67808 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67809 ret = -EAGAIN;
67810
67811 pipe_unlock(ipipe);
67812 diff --git a/fs/stat.c b/fs/stat.c
67813 index ae0c3ce..9ee641c 100644
67814 --- a/fs/stat.c
67815 +++ b/fs/stat.c
67816 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67817 stat->gid = inode->i_gid;
67818 stat->rdev = inode->i_rdev;
67819 stat->size = i_size_read(inode);
67820 - stat->atime = inode->i_atime;
67821 - stat->mtime = inode->i_mtime;
67822 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67823 + stat->atime = inode->i_ctime;
67824 + stat->mtime = inode->i_ctime;
67825 + } else {
67826 + stat->atime = inode->i_atime;
67827 + stat->mtime = inode->i_mtime;
67828 + }
67829 stat->ctime = inode->i_ctime;
67830 stat->blksize = (1 << inode->i_blkbits);
67831 stat->blocks = inode->i_blocks;
67832 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67833 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67834 {
67835 struct inode *inode = path->dentry->d_inode;
67836 + int retval;
67837
67838 - if (inode->i_op->getattr)
67839 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67840 + if (inode->i_op->getattr) {
67841 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67842 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67843 + stat->atime = stat->ctime;
67844 + stat->mtime = stat->ctime;
67845 + }
67846 + return retval;
67847 + }
67848
67849 generic_fillattr(inode, stat);
67850 return 0;
67851 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67852 index 0b45ff4..847de5b 100644
67853 --- a/fs/sysfs/dir.c
67854 +++ b/fs/sysfs/dir.c
67855 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67856 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67857 {
67858 struct kernfs_node *parent, *kn;
67859 + const char *name;
67860 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67861 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67862 + const char *parent_name;
67863 +#endif
67864
67865 BUG_ON(!kobj);
67866
67867 + name = kobject_name(kobj);
67868 +
67869 if (kobj->parent)
67870 parent = kobj->parent->sd;
67871 else
67872 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67873 if (!parent)
67874 return -ENOENT;
67875
67876 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67877 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67878 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67879 + parent_name = parent->name;
67880 + mode = S_IRWXU;
67881 +
67882 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67883 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67884 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67885 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67886 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
67887 +#endif
67888 +
67889 + kn = kernfs_create_dir_ns(parent, name,
67890 + mode, kobj, ns);
67891 if (IS_ERR(kn)) {
67892 if (PTR_ERR(kn) == -EEXIST)
67893 - sysfs_warn_dup(parent, kobject_name(kobj));
67894 + sysfs_warn_dup(parent, name);
67895 return PTR_ERR(kn);
67896 }
67897
67898 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67899 index 69d4889..a810bd4 100644
67900 --- a/fs/sysv/sysv.h
67901 +++ b/fs/sysv/sysv.h
67902 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67903 #endif
67904 }
67905
67906 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67907 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67908 {
67909 if (sbi->s_bytesex == BYTESEX_PDP)
67910 return PDP_swab((__force __u32)n);
67911 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67912 index fb08b0c..65fcc7e 100644
67913 --- a/fs/ubifs/io.c
67914 +++ b/fs/ubifs/io.c
67915 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67916 return err;
67917 }
67918
67919 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67920 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67921 {
67922 int err;
67923
67924 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67925 index c175b4d..8f36a16 100644
67926 --- a/fs/udf/misc.c
67927 +++ b/fs/udf/misc.c
67928 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67929
67930 u8 udf_tag_checksum(const struct tag *t)
67931 {
67932 - u8 *data = (u8 *)t;
67933 + const u8 *data = (const u8 *)t;
67934 u8 checksum = 0;
67935 int i;
67936 for (i = 0; i < sizeof(struct tag); ++i)
67937 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
67938 index 8d974c4..b82f6ec 100644
67939 --- a/fs/ufs/swab.h
67940 +++ b/fs/ufs/swab.h
67941 @@ -22,7 +22,7 @@ enum {
67942 BYTESEX_BE
67943 };
67944
67945 -static inline u64
67946 +static inline u64 __intentional_overflow(-1)
67947 fs64_to_cpu(struct super_block *sbp, __fs64 n)
67948 {
67949 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67950 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
67951 return (__force __fs64)cpu_to_be64(n);
67952 }
67953
67954 -static inline u32
67955 +static inline u32 __intentional_overflow(-1)
67956 fs32_to_cpu(struct super_block *sbp, __fs32 n)
67957 {
67958 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67959 diff --git a/fs/utimes.c b/fs/utimes.c
67960 index aa138d6..5f3a811 100644
67961 --- a/fs/utimes.c
67962 +++ b/fs/utimes.c
67963 @@ -1,6 +1,7 @@
67964 #include <linux/compiler.h>
67965 #include <linux/file.h>
67966 #include <linux/fs.h>
67967 +#include <linux/security.h>
67968 #include <linux/linkage.h>
67969 #include <linux/mount.h>
67970 #include <linux/namei.h>
67971 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
67972 }
67973 }
67974 retry_deleg:
67975 +
67976 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
67977 + error = -EACCES;
67978 + goto mnt_drop_write_and_out;
67979 + }
67980 +
67981 mutex_lock(&inode->i_mutex);
67982 error = notify_change(path->dentry, &newattrs, &delegated_inode);
67983 mutex_unlock(&inode->i_mutex);
67984 diff --git a/fs/xattr.c b/fs/xattr.c
67985 index 64e83ef..b6be154 100644
67986 --- a/fs/xattr.c
67987 +++ b/fs/xattr.c
67988 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
67989 return rc;
67990 }
67991
67992 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
67993 +ssize_t
67994 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
67995 +{
67996 + struct inode *inode = dentry->d_inode;
67997 + ssize_t error;
67998 +
67999 + error = inode_permission(inode, MAY_EXEC);
68000 + if (error)
68001 + return error;
68002 +
68003 + if (inode->i_op->getxattr)
68004 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68005 + else
68006 + error = -EOPNOTSUPP;
68007 +
68008 + return error;
68009 +}
68010 +EXPORT_SYMBOL(pax_getxattr);
68011 +#endif
68012 +
68013 ssize_t
68014 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68015 {
68016 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68017 * Extended attribute SET operations
68018 */
68019 static long
68020 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68021 +setxattr(struct path *path, const char __user *name, const void __user *value,
68022 size_t size, int flags)
68023 {
68024 int error;
68025 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68026 posix_acl_fix_xattr_from_user(kvalue, size);
68027 }
68028
68029 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68030 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68031 + error = -EACCES;
68032 + goto out;
68033 + }
68034 +
68035 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68036 out:
68037 if (vvalue)
68038 vfree(vvalue);
68039 @@ -376,7 +402,7 @@ retry:
68040 return error;
68041 error = mnt_want_write(path.mnt);
68042 if (!error) {
68043 - error = setxattr(path.dentry, name, value, size, flags);
68044 + error = setxattr(&path, name, value, size, flags);
68045 mnt_drop_write(path.mnt);
68046 }
68047 path_put(&path);
68048 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68049 const void __user *,value, size_t, size, int, flags)
68050 {
68051 struct fd f = fdget(fd);
68052 - struct dentry *dentry;
68053 int error = -EBADF;
68054
68055 if (!f.file)
68056 return error;
68057 - dentry = f.file->f_path.dentry;
68058 - audit_inode(NULL, dentry, 0);
68059 + audit_inode(NULL, f.file->f_path.dentry, 0);
68060 error = mnt_want_write_file(f.file);
68061 if (!error) {
68062 - error = setxattr(dentry, name, value, size, flags);
68063 + error = setxattr(&f.file->f_path, name, value, size, flags);
68064 mnt_drop_write_file(f.file);
68065 }
68066 fdput(f);
68067 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68068 * Extended attribute REMOVE operations
68069 */
68070 static long
68071 -removexattr(struct dentry *d, const char __user *name)
68072 +removexattr(struct path *path, const char __user *name)
68073 {
68074 int error;
68075 char kname[XATTR_NAME_MAX + 1];
68076 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68077 if (error < 0)
68078 return error;
68079
68080 - return vfs_removexattr(d, kname);
68081 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68082 + return -EACCES;
68083 +
68084 + return vfs_removexattr(path->dentry, kname);
68085 }
68086
68087 static int path_removexattr(const char __user *pathname,
68088 @@ -625,7 +652,7 @@ retry:
68089 return error;
68090 error = mnt_want_write(path.mnt);
68091 if (!error) {
68092 - error = removexattr(path.dentry, name);
68093 + error = removexattr(&path, name);
68094 mnt_drop_write(path.mnt);
68095 }
68096 path_put(&path);
68097 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68098 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68099 {
68100 struct fd f = fdget(fd);
68101 - struct dentry *dentry;
68102 + struct path *path;
68103 int error = -EBADF;
68104
68105 if (!f.file)
68106 return error;
68107 - dentry = f.file->f_path.dentry;
68108 - audit_inode(NULL, dentry, 0);
68109 + path = &f.file->f_path;
68110 + audit_inode(NULL, path->dentry, 0);
68111 error = mnt_want_write_file(f.file);
68112 if (!error) {
68113 - error = removexattr(dentry, name);
68114 + error = removexattr(path, name);
68115 mnt_drop_write_file(f.file);
68116 }
68117 fdput(f);
68118 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68119 index 79c9819..22226b4 100644
68120 --- a/fs/xfs/libxfs/xfs_bmap.c
68121 +++ b/fs/xfs/libxfs/xfs_bmap.c
68122 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68123
68124 #else
68125 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68126 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68127 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68128 #endif /* DEBUG */
68129
68130 /*
68131 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68132 index f1b69ed..3d0222f 100644
68133 --- a/fs/xfs/xfs_dir2_readdir.c
68134 +++ b/fs/xfs/xfs_dir2_readdir.c
68135 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68136 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68137 filetype = dp->d_ops->sf_get_ftype(sfep);
68138 ctx->pos = off & 0x7fffffff;
68139 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68140 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68141 + char name[sfep->namelen];
68142 + memcpy(name, sfep->name, sfep->namelen);
68143 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68144 + return 0;
68145 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68146 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68147 return 0;
68148 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68149 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68150 index 24c926b6..8726af88 100644
68151 --- a/fs/xfs/xfs_ioctl.c
68152 +++ b/fs/xfs/xfs_ioctl.c
68153 @@ -122,7 +122,7 @@ xfs_find_handle(
68154 }
68155
68156 error = -EFAULT;
68157 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68158 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68159 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68160 goto out_put;
68161
68162 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68163 index 6a51619..9592e1b 100644
68164 --- a/fs/xfs/xfs_linux.h
68165 +++ b/fs/xfs/xfs_linux.h
68166 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68167 * of the compiler which do not like us using do_div in the middle
68168 * of large functions.
68169 */
68170 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68171 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68172 {
68173 __u32 mod;
68174
68175 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68176 return 0;
68177 }
68178 #else
68179 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68180 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68181 {
68182 __u32 mod;
68183
68184 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68185 new file mode 100644
68186 index 0000000..31f8fe4
68187 --- /dev/null
68188 +++ b/grsecurity/Kconfig
68189 @@ -0,0 +1,1182 @@
68190 +#
68191 +# grecurity configuration
68192 +#
68193 +menu "Memory Protections"
68194 +depends on GRKERNSEC
68195 +
68196 +config GRKERNSEC_KMEM
68197 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68198 + default y if GRKERNSEC_CONFIG_AUTO
68199 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68200 + help
68201 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68202 + be written to or read from to modify or leak the contents of the running
68203 + kernel. /dev/port will also not be allowed to be opened, writing to
68204 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68205 + If you have module support disabled, enabling this will close up several
68206 + ways that are currently used to insert malicious code into the running
68207 + kernel.
68208 +
68209 + Even with this feature enabled, we still highly recommend that
68210 + you use the RBAC system, as it is still possible for an attacker to
68211 + modify the running kernel through other more obscure methods.
68212 +
68213 + It is highly recommended that you say Y here if you meet all the
68214 + conditions above.
68215 +
68216 +config GRKERNSEC_VM86
68217 + bool "Restrict VM86 mode"
68218 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68219 + depends on X86_32
68220 +
68221 + help
68222 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68223 + make use of a special execution mode on 32bit x86 processors called
68224 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68225 + video cards and will still work with this option enabled. The purpose
68226 + of the option is to prevent exploitation of emulation errors in
68227 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68228 + Nearly all users should be able to enable this option.
68229 +
68230 +config GRKERNSEC_IO
68231 + bool "Disable privileged I/O"
68232 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68233 + depends on X86
68234 + select RTC_CLASS
68235 + select RTC_INTF_DEV
68236 + select RTC_DRV_CMOS
68237 +
68238 + help
68239 + If you say Y here, all ioperm and iopl calls will return an error.
68240 + Ioperm and iopl can be used to modify the running kernel.
68241 + Unfortunately, some programs need this access to operate properly,
68242 + the most notable of which are XFree86 and hwclock. hwclock can be
68243 + remedied by having RTC support in the kernel, so real-time
68244 + clock support is enabled if this option is enabled, to ensure
68245 + that hwclock operates correctly. If hwclock still does not work,
68246 + either update udev or symlink /dev/rtc to /dev/rtc0.
68247 +
68248 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68249 + you may not be able to boot into a graphical environment with this
68250 + option enabled. In this case, you should use the RBAC system instead.
68251 +
68252 +config GRKERNSEC_BPF_HARDEN
68253 + bool "Harden BPF interpreter"
68254 + default y if GRKERNSEC_CONFIG_AUTO
68255 + help
68256 + Unlike previous versions of grsecurity that hardened both the BPF
68257 + interpreted code against corruption at rest as well as the JIT code
68258 + against JIT-spray attacks and attacker-controlled immediate values
68259 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68260 + and will ensure the interpreted code is read-only at rest. This feature
68261 + may be removed at a later time when eBPF stabilizes to entirely revert
68262 + back to the more secure pre-3.16 BPF interpreter/JIT.
68263 +
68264 + If you're using KERNEXEC, it's recommended that you enable this option
68265 + to supplement the hardening of the kernel.
68266 +
68267 +config GRKERNSEC_PERF_HARDEN
68268 + bool "Disable unprivileged PERF_EVENTS usage by default"
68269 + default y if GRKERNSEC_CONFIG_AUTO
68270 + depends on PERF_EVENTS
68271 + help
68272 + If you say Y here, the range of acceptable values for the
68273 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68274 + default to a new value: 3. When the sysctl is set to this value, no
68275 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68276 +
68277 + Though PERF_EVENTS can be used legitimately for performance monitoring
68278 + and low-level application profiling, it is forced on regardless of
68279 + configuration, has been at fault for several vulnerabilities, and
68280 + creates new opportunities for side channels and other information leaks.
68281 +
68282 + This feature puts PERF_EVENTS into a secure default state and permits
68283 + the administrator to change out of it temporarily if unprivileged
68284 + application profiling is needed.
68285 +
68286 +config GRKERNSEC_RAND_THREADSTACK
68287 + bool "Insert random gaps between thread stacks"
68288 + default y if GRKERNSEC_CONFIG_AUTO
68289 + depends on PAX_RANDMMAP && !PPC
68290 + help
68291 + If you say Y here, a random-sized gap will be enforced between allocated
68292 + thread stacks. Glibc's NPTL and other threading libraries that
68293 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68294 + The implementation currently provides 8 bits of entropy for the gap.
68295 +
68296 + Many distributions do not compile threaded remote services with the
68297 + -fstack-check argument to GCC, causing the variable-sized stack-based
68298 + allocator, alloca(), to not probe the stack on allocation. This
68299 + permits an unbounded alloca() to skip over any guard page and potentially
68300 + modify another thread's stack reliably. An enforced random gap
68301 + reduces the reliability of such an attack and increases the chance
68302 + that such a read/write to another thread's stack instead lands in
68303 + an unmapped area, causing a crash and triggering grsecurity's
68304 + anti-bruteforcing logic.
68305 +
68306 +config GRKERNSEC_PROC_MEMMAP
68307 + bool "Harden ASLR against information leaks and entropy reduction"
68308 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68309 + depends on PAX_NOEXEC || PAX_ASLR
68310 + help
68311 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68312 + give no information about the addresses of its mappings if
68313 + PaX features that rely on random addresses are enabled on the task.
68314 + In addition to sanitizing this information and disabling other
68315 + dangerous sources of information, this option causes reads of sensitive
68316 + /proc/<pid> entries where the file descriptor was opened in a different
68317 + task than the one performing the read. Such attempts are logged.
68318 + This option also limits argv/env strings for suid/sgid binaries
68319 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68320 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68321 + binaries to prevent alternative mmap layouts from being abused.
68322 +
68323 + If you use PaX it is essential that you say Y here as it closes up
68324 + several holes that make full ASLR useless locally.
68325 +
68326 +
68327 +config GRKERNSEC_KSTACKOVERFLOW
68328 + bool "Prevent kernel stack overflows"
68329 + default y if GRKERNSEC_CONFIG_AUTO
68330 + depends on !IA64 && 64BIT
68331 + help
68332 + If you say Y here, the kernel's process stacks will be allocated
68333 + with vmalloc instead of the kernel's default allocator. This
68334 + introduces guard pages that in combination with the alloca checking
68335 + of the STACKLEAK feature prevents all forms of kernel process stack
68336 + overflow abuse. Note that this is different from kernel stack
68337 + buffer overflows.
68338 +
68339 +config GRKERNSEC_BRUTE
68340 + bool "Deter exploit bruteforcing"
68341 + default y if GRKERNSEC_CONFIG_AUTO
68342 + help
68343 + If you say Y here, attempts to bruteforce exploits against forking
68344 + daemons such as apache or sshd, as well as against suid/sgid binaries
68345 + will be deterred. When a child of a forking daemon is killed by PaX
68346 + or crashes due to an illegal instruction or other suspicious signal,
68347 + the parent process will be delayed 30 seconds upon every subsequent
68348 + fork until the administrator is able to assess the situation and
68349 + restart the daemon.
68350 + In the suid/sgid case, the attempt is logged, the user has all their
68351 + existing instances of the suid/sgid binary terminated and will
68352 + be unable to execute any suid/sgid binaries for 15 minutes.
68353 +
68354 + It is recommended that you also enable signal logging in the auditing
68355 + section so that logs are generated when a process triggers a suspicious
68356 + signal.
68357 + If the sysctl option is enabled, a sysctl option with name
68358 + "deter_bruteforce" is created.
68359 +
68360 +config GRKERNSEC_MODHARDEN
68361 + bool "Harden module auto-loading"
68362 + default y if GRKERNSEC_CONFIG_AUTO
68363 + depends on MODULES
68364 + help
68365 + If you say Y here, module auto-loading in response to use of some
68366 + feature implemented by an unloaded module will be restricted to
68367 + root users. Enabling this option helps defend against attacks
68368 + by unprivileged users who abuse the auto-loading behavior to
68369 + cause a vulnerable module to load that is then exploited.
68370 +
68371 + If this option prevents a legitimate use of auto-loading for a
68372 + non-root user, the administrator can execute modprobe manually
68373 + with the exact name of the module mentioned in the alert log.
68374 + Alternatively, the administrator can add the module to the list
68375 + of modules loaded at boot by modifying init scripts.
68376 +
68377 + Modification of init scripts will most likely be needed on
68378 + Ubuntu servers with encrypted home directory support enabled,
68379 + as the first non-root user logging in will cause the ecb(aes),
68380 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68381 +
68382 +config GRKERNSEC_HIDESYM
68383 + bool "Hide kernel symbols"
68384 + default y if GRKERNSEC_CONFIG_AUTO
68385 + select PAX_USERCOPY_SLABS
68386 + help
68387 + If you say Y here, getting information on loaded modules, and
68388 + displaying all kernel symbols through a syscall will be restricted
68389 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68390 + /proc/kallsyms will be restricted to the root user. The RBAC
68391 + system can hide that entry even from root.
68392 +
68393 + This option also prevents leaking of kernel addresses through
68394 + several /proc entries.
68395 +
68396 + Note that this option is only effective provided the following
68397 + conditions are met:
68398 + 1) The kernel using grsecurity is not precompiled by some distribution
68399 + 2) You have also enabled GRKERNSEC_DMESG
68400 + 3) You are using the RBAC system and hiding other files such as your
68401 + kernel image and System.map. Alternatively, enabling this option
68402 + causes the permissions on /boot, /lib/modules, and the kernel
68403 + source directory to change at compile time to prevent
68404 + reading by non-root users.
68405 + If the above conditions are met, this option will aid in providing a
68406 + useful protection against local kernel exploitation of overflows
68407 + and arbitrary read/write vulnerabilities.
68408 +
68409 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68410 + in addition to this feature.
68411 +
68412 +config GRKERNSEC_RANDSTRUCT
68413 + bool "Randomize layout of sensitive kernel structures"
68414 + default y if GRKERNSEC_CONFIG_AUTO
68415 + select GRKERNSEC_HIDESYM
68416 + select MODVERSIONS if MODULES
68417 + help
68418 + If you say Y here, the layouts of a number of sensitive kernel
68419 + structures (task, fs, cred, etc) and all structures composed entirely
68420 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68421 + This can introduce the requirement of an additional infoleak
68422 + vulnerability for exploits targeting these structure types.
68423 +
68424 + Enabling this feature will introduce some performance impact, slightly
68425 + increase memory usage, and prevent the use of forensic tools like
68426 + Volatility against the system (unless the kernel source tree isn't
68427 + cleaned after kernel installation).
68428 +
68429 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68430 + It remains after a make clean to allow for external modules to be compiled
68431 + with the existing seed and will be removed by a make mrproper or
68432 + make distclean.
68433 +
68434 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68435 + to install the supporting headers explicitly in addition to the normal
68436 + gcc package.
68437 +
68438 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68439 + bool "Use cacheline-aware structure randomization"
68440 + depends on GRKERNSEC_RANDSTRUCT
68441 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68442 + help
68443 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68444 + at restricting randomization to cacheline-sized groups of elements. It
68445 + will further not randomize bitfields in structures. This reduces the
68446 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68447 +
68448 +config GRKERNSEC_KERN_LOCKOUT
68449 + bool "Active kernel exploit response"
68450 + default y if GRKERNSEC_CONFIG_AUTO
68451 + depends on X86 || ARM || PPC || SPARC
68452 + help
68453 + If you say Y here, when a PaX alert is triggered due to suspicious
68454 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68455 + or an OOPS occurs due to bad memory accesses, instead of just
68456 + terminating the offending process (and potentially allowing
68457 + a subsequent exploit from the same user), we will take one of two
68458 + actions:
68459 + If the user was root, we will panic the system
68460 + If the user was non-root, we will log the attempt, terminate
68461 + all processes owned by the user, then prevent them from creating
68462 + any new processes until the system is restarted
68463 + This deters repeated kernel exploitation/bruteforcing attempts
68464 + and is useful for later forensics.
68465 +
68466 +config GRKERNSEC_OLD_ARM_USERLAND
68467 + bool "Old ARM userland compatibility"
68468 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68469 + help
68470 + If you say Y here, stubs of executable code to perform such operations
68471 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68472 + table. This is unfortunately needed for old ARM userland meant to run
68473 + across a wide range of processors. Without this option enabled,
68474 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68475 + which is enough for Linaro userlands or other userlands designed for v6
68476 + and newer ARM CPUs. It's recommended that you try without this option enabled
68477 + first, and only enable it if your userland does not boot (it will likely fail
68478 + at init time).
68479 +
68480 +endmenu
68481 +menu "Role Based Access Control Options"
68482 +depends on GRKERNSEC
68483 +
68484 +config GRKERNSEC_RBAC_DEBUG
68485 + bool
68486 +
68487 +config GRKERNSEC_NO_RBAC
68488 + bool "Disable RBAC system"
68489 + help
68490 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68491 + preventing the RBAC system from being enabled. You should only say Y
68492 + here if you have no intention of using the RBAC system, so as to prevent
68493 + an attacker with root access from misusing the RBAC system to hide files
68494 + and processes when loadable module support and /dev/[k]mem have been
68495 + locked down.
68496 +
68497 +config GRKERNSEC_ACL_HIDEKERN
68498 + bool "Hide kernel processes"
68499 + help
68500 + If you say Y here, all kernel threads will be hidden to all
68501 + processes but those whose subject has the "view hidden processes"
68502 + flag.
68503 +
68504 +config GRKERNSEC_ACL_MAXTRIES
68505 + int "Maximum tries before password lockout"
68506 + default 3
68507 + help
68508 + This option enforces the maximum number of times a user can attempt
68509 + to authorize themselves with the grsecurity RBAC system before being
68510 + denied the ability to attempt authorization again for a specified time.
68511 + The lower the number, the harder it will be to brute-force a password.
68512 +
68513 +config GRKERNSEC_ACL_TIMEOUT
68514 + int "Time to wait after max password tries, in seconds"
68515 + default 30
68516 + help
68517 + This option specifies the time the user must wait after attempting to
68518 + authorize to the RBAC system with the maximum number of invalid
68519 + passwords. The higher the number, the harder it will be to brute-force
68520 + a password.
68521 +
68522 +endmenu
68523 +menu "Filesystem Protections"
68524 +depends on GRKERNSEC
68525 +
68526 +config GRKERNSEC_PROC
68527 + bool "Proc restrictions"
68528 + default y if GRKERNSEC_CONFIG_AUTO
68529 + help
68530 + If you say Y here, the permissions of the /proc filesystem
68531 + will be altered to enhance system security and privacy. You MUST
68532 + choose either a user only restriction or a user and group restriction.
68533 + Depending upon the option you choose, you can either restrict users to
68534 + see only the processes they themselves run, or choose a group that can
68535 + view all processes and files normally restricted to root if you choose
68536 + the "restrict to user only" option. NOTE: If you're running identd or
68537 + ntpd as a non-root user, you will have to run it as the group you
68538 + specify here.
68539 +
68540 +config GRKERNSEC_PROC_USER
68541 + bool "Restrict /proc to user only"
68542 + depends on GRKERNSEC_PROC
68543 + help
68544 + If you say Y here, non-root users will only be able to view their own
68545 + processes, and restricts them from viewing network-related information,
68546 + and viewing kernel symbol and module information.
68547 +
68548 +config GRKERNSEC_PROC_USERGROUP
68549 + bool "Allow special group"
68550 + default y if GRKERNSEC_CONFIG_AUTO
68551 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68552 + help
68553 + If you say Y here, you will be able to select a group that will be
68554 + able to view all processes and network-related information. If you've
68555 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68556 + remain hidden. This option is useful if you want to run identd as
68557 + a non-root user. The group you select may also be chosen at boot time
68558 + via "grsec_proc_gid=" on the kernel commandline.
68559 +
68560 +config GRKERNSEC_PROC_GID
68561 + int "GID for special group"
68562 + depends on GRKERNSEC_PROC_USERGROUP
68563 + default 1001
68564 +
68565 +config GRKERNSEC_PROC_ADD
68566 + bool "Additional restrictions"
68567 + default y if GRKERNSEC_CONFIG_AUTO
68568 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68569 + help
68570 + If you say Y here, additional restrictions will be placed on
68571 + /proc that keep normal users from viewing device information and
68572 + slabinfo information that could be useful for exploits.
68573 +
68574 +config GRKERNSEC_LINK
68575 + bool "Linking restrictions"
68576 + default y if GRKERNSEC_CONFIG_AUTO
68577 + help
68578 + If you say Y here, /tmp race exploits will be prevented, since users
68579 + will no longer be able to follow symlinks owned by other users in
68580 + world-writable +t directories (e.g. /tmp), unless the owner of the
68581 + symlink is the owner of the directory. users will also not be
68582 + able to hardlink to files they do not own. If the sysctl option is
68583 + enabled, a sysctl option with name "linking_restrictions" is created.
68584 +
68585 +config GRKERNSEC_SYMLINKOWN
68586 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68587 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68588 + help
68589 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68590 + that prevents it from being used as a security feature. As Apache
68591 + verifies the symlink by performing a stat() against the target of
68592 + the symlink before it is followed, an attacker can setup a symlink
68593 + to point to a same-owned file, then replace the symlink with one
68594 + that targets another user's file just after Apache "validates" the
68595 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68596 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68597 + will be in place for the group you specify. If the sysctl option
68598 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68599 + created.
68600 +
68601 +config GRKERNSEC_SYMLINKOWN_GID
68602 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68603 + depends on GRKERNSEC_SYMLINKOWN
68604 + default 1006
68605 + help
68606 + Setting this GID determines what group kernel-enforced
68607 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68608 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68609 +
68610 +config GRKERNSEC_FIFO
68611 + bool "FIFO restrictions"
68612 + default y if GRKERNSEC_CONFIG_AUTO
68613 + help
68614 + If you say Y here, users will not be able to write to FIFOs they don't
68615 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68616 + the FIFO is the same owner of the directory it's held in. If the sysctl
68617 + option is enabled, a sysctl option with name "fifo_restrictions" is
68618 + created.
68619 +
68620 +config GRKERNSEC_SYSFS_RESTRICT
68621 + bool "Sysfs/debugfs restriction"
68622 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68623 + depends on SYSFS
68624 + help
68625 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68626 + any filesystem normally mounted under it (e.g. debugfs) will be
68627 + mostly accessible only by root. These filesystems generally provide access
68628 + to hardware and debug information that isn't appropriate for unprivileged
68629 + users of the system. Sysfs and debugfs have also become a large source
68630 + of new vulnerabilities, ranging from infoleaks to local compromise.
68631 + There has been very little oversight with an eye toward security involved
68632 + in adding new exporters of information to these filesystems, so their
68633 + use is discouraged.
68634 + For reasons of compatibility, a few directories have been whitelisted
68635 + for access by non-root users:
68636 + /sys/fs/selinux
68637 + /sys/fs/fuse
68638 + /sys/devices/system/cpu
68639 +
68640 +config GRKERNSEC_ROFS
68641 + bool "Runtime read-only mount protection"
68642 + depends on SYSCTL
68643 + help
68644 + If you say Y here, a sysctl option with name "romount_protect" will
68645 + be created. By setting this option to 1 at runtime, filesystems
68646 + will be protected in the following ways:
68647 + * No new writable mounts will be allowed
68648 + * Existing read-only mounts won't be able to be remounted read/write
68649 + * Write operations will be denied on all block devices
68650 + This option acts independently of grsec_lock: once it is set to 1,
68651 + it cannot be turned off. Therefore, please be mindful of the resulting
68652 + behavior if this option is enabled in an init script on a read-only
68653 + filesystem.
68654 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68655 + and GRKERNSEC_IO should be enabled and module loading disabled via
68656 + config or at runtime.
68657 + This feature is mainly intended for secure embedded systems.
68658 +
68659 +
68660 +config GRKERNSEC_DEVICE_SIDECHANNEL
68661 + bool "Eliminate stat/notify-based device sidechannels"
68662 + default y if GRKERNSEC_CONFIG_AUTO
68663 + help
68664 + If you say Y here, timing analyses on block or character
68665 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68666 + will be thwarted for unprivileged users. If a process without
68667 + CAP_MKNOD stats such a device, the last access and last modify times
68668 + will match the device's create time. No access or modify events
68669 + will be triggered through inotify/dnotify/fanotify for such devices.
68670 + This feature will prevent attacks that may at a minimum
68671 + allow an attacker to determine the administrator's password length.
68672 +
68673 +config GRKERNSEC_CHROOT
68674 + bool "Chroot jail restrictions"
68675 + default y if GRKERNSEC_CONFIG_AUTO
68676 + help
68677 + If you say Y here, you will be able to choose several options that will
68678 + make breaking out of a chrooted jail much more difficult. If you
68679 + encounter no software incompatibilities with the following options, it
68680 + is recommended that you enable each one.
68681 +
68682 + Note that the chroot restrictions are not intended to apply to "chroots"
68683 + to directories that are simple bind mounts of the global root filesystem.
68684 + For several other reasons, a user shouldn't expect any significant
68685 + security by performing such a chroot.
68686 +
68687 +config GRKERNSEC_CHROOT_MOUNT
68688 + bool "Deny mounts"
68689 + default y if GRKERNSEC_CONFIG_AUTO
68690 + depends on GRKERNSEC_CHROOT
68691 + help
68692 + If you say Y here, processes inside a chroot will not be able to
68693 + mount or remount filesystems. If the sysctl option is enabled, a
68694 + sysctl option with name "chroot_deny_mount" is created.
68695 +
68696 +config GRKERNSEC_CHROOT_DOUBLE
68697 + bool "Deny double-chroots"
68698 + default y if GRKERNSEC_CONFIG_AUTO
68699 + depends on GRKERNSEC_CHROOT
68700 + help
68701 + If you say Y here, processes inside a chroot will not be able to chroot
68702 + again outside the chroot. This is a widely used method of breaking
68703 + out of a chroot jail and should not be allowed. If the sysctl
68704 + option is enabled, a sysctl option with name
68705 + "chroot_deny_chroot" is created.
68706 +
68707 +config GRKERNSEC_CHROOT_PIVOT
68708 + bool "Deny pivot_root in chroot"
68709 + default y if GRKERNSEC_CONFIG_AUTO
68710 + depends on GRKERNSEC_CHROOT
68711 + help
68712 + If you say Y here, processes inside a chroot will not be able to use
68713 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68714 + works similar to chroot in that it changes the root filesystem. This
68715 + function could be misused in a chrooted process to attempt to break out
68716 + of the chroot, and therefore should not be allowed. If the sysctl
68717 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68718 + created.
68719 +
68720 +config GRKERNSEC_CHROOT_CHDIR
68721 + bool "Enforce chdir(\"/\") on all chroots"
68722 + default y if GRKERNSEC_CONFIG_AUTO
68723 + depends on GRKERNSEC_CHROOT
68724 + help
68725 + If you say Y here, the current working directory of all newly-chrooted
68726 + applications will be set to the the root directory of the chroot.
68727 + The man page on chroot(2) states:
68728 + Note that this call does not change the current working
68729 + directory, so that `.' can be outside the tree rooted at
68730 + `/'. In particular, the super-user can escape from a
68731 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68732 +
68733 + It is recommended that you say Y here, since it's not known to break
68734 + any software. If the sysctl option is enabled, a sysctl option with
68735 + name "chroot_enforce_chdir" is created.
68736 +
68737 +config GRKERNSEC_CHROOT_CHMOD
68738 + bool "Deny (f)chmod +s"
68739 + default y if GRKERNSEC_CONFIG_AUTO
68740 + depends on GRKERNSEC_CHROOT
68741 + help
68742 + If you say Y here, processes inside a chroot will not be able to chmod
68743 + or fchmod files to make them have suid or sgid bits. This protects
68744 + against another published method of breaking a chroot. If the sysctl
68745 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68746 + created.
68747 +
68748 +config GRKERNSEC_CHROOT_FCHDIR
68749 + bool "Deny fchdir and fhandle out of chroot"
68750 + default y if GRKERNSEC_CONFIG_AUTO
68751 + depends on GRKERNSEC_CHROOT
68752 + help
68753 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68754 + to a file descriptor of the chrooting process that points to a directory
68755 + outside the filesystem will be stopped. Additionally, this option prevents
68756 + use of the recently-created syscall for opening files by a guessable "file
68757 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68758 + with name "chroot_deny_fchdir" is created.
68759 +
68760 +config GRKERNSEC_CHROOT_MKNOD
68761 + bool "Deny mknod"
68762 + default y if GRKERNSEC_CONFIG_AUTO
68763 + depends on GRKERNSEC_CHROOT
68764 + help
68765 + If you say Y here, processes inside a chroot will not be allowed to
68766 + mknod. The problem with using mknod inside a chroot is that it
68767 + would allow an attacker to create a device entry that is the same
68768 + as one on the physical root of your system, which could range from
68769 + anything from the console device to a device for your harddrive (which
68770 + they could then use to wipe the drive or steal data). It is recommended
68771 + that you say Y here, unless you run into software incompatibilities.
68772 + If the sysctl option is enabled, a sysctl option with name
68773 + "chroot_deny_mknod" is created.
68774 +
68775 +config GRKERNSEC_CHROOT_SHMAT
68776 + bool "Deny shmat() out of chroot"
68777 + default y if GRKERNSEC_CONFIG_AUTO
68778 + depends on GRKERNSEC_CHROOT
68779 + help
68780 + If you say Y here, processes inside a chroot will not be able to attach
68781 + to shared memory segments that were created outside of the chroot jail.
68782 + It is recommended that you say Y here. If the sysctl option is enabled,
68783 + a sysctl option with name "chroot_deny_shmat" is created.
68784 +
68785 +config GRKERNSEC_CHROOT_UNIX
68786 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68787 + default y if GRKERNSEC_CONFIG_AUTO
68788 + depends on GRKERNSEC_CHROOT
68789 + help
68790 + If you say Y here, processes inside a chroot will not be able to
68791 + connect to abstract (meaning not belonging to a filesystem) Unix
68792 + domain sockets that were bound outside of a chroot. It is recommended
68793 + that you say Y here. If the sysctl option is enabled, a sysctl option
68794 + with name "chroot_deny_unix" is created.
68795 +
68796 +config GRKERNSEC_CHROOT_FINDTASK
68797 + bool "Protect outside processes"
68798 + default y if GRKERNSEC_CONFIG_AUTO
68799 + depends on GRKERNSEC_CHROOT
68800 + help
68801 + If you say Y here, processes inside a chroot will not be able to
68802 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68803 + getsid, or view any process outside of the chroot. If the sysctl
68804 + option is enabled, a sysctl option with name "chroot_findtask" is
68805 + created.
68806 +
68807 +config GRKERNSEC_CHROOT_NICE
68808 + bool "Restrict priority changes"
68809 + default y if GRKERNSEC_CONFIG_AUTO
68810 + depends on GRKERNSEC_CHROOT
68811 + help
68812 + If you say Y here, processes inside a chroot will not be able to raise
68813 + the priority of processes in the chroot, or alter the priority of
68814 + processes outside the chroot. This provides more security than simply
68815 + removing CAP_SYS_NICE from the process' capability set. If the
68816 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68817 + is created.
68818 +
68819 +config GRKERNSEC_CHROOT_SYSCTL
68820 + bool "Deny sysctl writes"
68821 + default y if GRKERNSEC_CONFIG_AUTO
68822 + depends on GRKERNSEC_CHROOT
68823 + help
68824 + If you say Y here, an attacker in a chroot will not be able to
68825 + write to sysctl entries, either by sysctl(2) or through a /proc
68826 + interface. It is strongly recommended that you say Y here. If the
68827 + sysctl option is enabled, a sysctl option with name
68828 + "chroot_deny_sysctl" is created.
68829 +
68830 +config GRKERNSEC_CHROOT_RENAME
68831 + bool "Deny bad renames"
68832 + default y if GRKERNSEC_CONFIG_AUTO
68833 + depends on GRKERNSEC_CHROOT
68834 + help
68835 + If you say Y here, an attacker in a chroot will not be able to
68836 + abuse the ability to create double chroots to break out of the
68837 + chroot by exploiting a race condition between a rename of a directory
68838 + within a chroot against an open of a symlink with relative path
68839 + components. This feature will likewise prevent an accomplice outside
68840 + a chroot from enabling a user inside the chroot to break out and make
68841 + use of their credentials on the global filesystem. Enabling this
68842 + feature is essential to prevent root users from breaking out of a
68843 + chroot. If the sysctl option is enabled, a sysctl option with name
68844 + "chroot_deny_bad_rename" is created.
68845 +
68846 +config GRKERNSEC_CHROOT_CAPS
68847 + bool "Capability restrictions"
68848 + default y if GRKERNSEC_CONFIG_AUTO
68849 + depends on GRKERNSEC_CHROOT
68850 + help
68851 + If you say Y here, the capabilities on all processes within a
68852 + chroot jail will be lowered to stop module insertion, raw i/o,
68853 + system and net admin tasks, rebooting the system, modifying immutable
68854 + files, modifying IPC owned by another, and changing the system time.
68855 + This is left an option because it can break some apps. Disable this
68856 + if your chrooted apps are having problems performing those kinds of
68857 + tasks. If the sysctl option is enabled, a sysctl option with
68858 + name "chroot_caps" is created.
68859 +
68860 +config GRKERNSEC_CHROOT_INITRD
68861 + bool "Exempt initrd tasks from restrictions"
68862 + default y if GRKERNSEC_CONFIG_AUTO
68863 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68864 + help
68865 + If you say Y here, tasks started prior to init will be exempted from
68866 + grsecurity's chroot restrictions. This option is mainly meant to
68867 + resolve Plymouth's performing privileged operations unnecessarily
68868 + in a chroot.
68869 +
68870 +endmenu
68871 +menu "Kernel Auditing"
68872 +depends on GRKERNSEC
68873 +
68874 +config GRKERNSEC_AUDIT_GROUP
68875 + bool "Single group for auditing"
68876 + help
68877 + If you say Y here, the exec and chdir logging features will only operate
68878 + on a group you specify. This option is recommended if you only want to
68879 + watch certain users instead of having a large amount of logs from the
68880 + entire system. If the sysctl option is enabled, a sysctl option with
68881 + name "audit_group" is created.
68882 +
68883 +config GRKERNSEC_AUDIT_GID
68884 + int "GID for auditing"
68885 + depends on GRKERNSEC_AUDIT_GROUP
68886 + default 1007
68887 +
68888 +config GRKERNSEC_EXECLOG
68889 + bool "Exec logging"
68890 + help
68891 + If you say Y here, all execve() calls will be logged (since the
68892 + other exec*() calls are frontends to execve(), all execution
68893 + will be logged). Useful for shell-servers that like to keep track
68894 + of their users. If the sysctl option is enabled, a sysctl option with
68895 + name "exec_logging" is created.
68896 + WARNING: This option when enabled will produce a LOT of logs, especially
68897 + on an active system.
68898 +
68899 +config GRKERNSEC_RESLOG
68900 + bool "Resource logging"
68901 + default y if GRKERNSEC_CONFIG_AUTO
68902 + help
68903 + If you say Y here, all attempts to overstep resource limits will
68904 + be logged with the resource name, the requested size, and the current
68905 + limit. It is highly recommended that you say Y here. If the sysctl
68906 + option is enabled, a sysctl option with name "resource_logging" is
68907 + created. If the RBAC system is enabled, the sysctl value is ignored.
68908 +
68909 +config GRKERNSEC_CHROOT_EXECLOG
68910 + bool "Log execs within chroot"
68911 + help
68912 + If you say Y here, all executions inside a chroot jail will be logged
68913 + to syslog. This can cause a large amount of logs if certain
68914 + applications (eg. djb's daemontools) are installed on the system, and
68915 + is therefore left as an option. If the sysctl option is enabled, a
68916 + sysctl option with name "chroot_execlog" is created.
68917 +
68918 +config GRKERNSEC_AUDIT_PTRACE
68919 + bool "Ptrace logging"
68920 + help
68921 + If you say Y here, all attempts to attach to a process via ptrace
68922 + will be logged. If the sysctl option is enabled, a sysctl option
68923 + with name "audit_ptrace" is created.
68924 +
68925 +config GRKERNSEC_AUDIT_CHDIR
68926 + bool "Chdir logging"
68927 + help
68928 + If you say Y here, all chdir() calls will be logged. If the sysctl
68929 + option is enabled, a sysctl option with name "audit_chdir" is created.
68930 +
68931 +config GRKERNSEC_AUDIT_MOUNT
68932 + bool "(Un)Mount logging"
68933 + help
68934 + If you say Y here, all mounts and unmounts will be logged. If the
68935 + sysctl option is enabled, a sysctl option with name "audit_mount" is
68936 + created.
68937 +
68938 +config GRKERNSEC_SIGNAL
68939 + bool "Signal logging"
68940 + default y if GRKERNSEC_CONFIG_AUTO
68941 + help
68942 + If you say Y here, certain important signals will be logged, such as
68943 + SIGSEGV, which will as a result inform you of when a error in a program
68944 + occurred, which in some cases could mean a possible exploit attempt.
68945 + If the sysctl option is enabled, a sysctl option with name
68946 + "signal_logging" is created.
68947 +
68948 +config GRKERNSEC_FORKFAIL
68949 + bool "Fork failure logging"
68950 + help
68951 + If you say Y here, all failed fork() attempts will be logged.
68952 + This could suggest a fork bomb, or someone attempting to overstep
68953 + their process limit. If the sysctl option is enabled, a sysctl option
68954 + with name "forkfail_logging" is created.
68955 +
68956 +config GRKERNSEC_TIME
68957 + bool "Time change logging"
68958 + default y if GRKERNSEC_CONFIG_AUTO
68959 + help
68960 + If you say Y here, any changes of the system clock will be logged.
68961 + If the sysctl option is enabled, a sysctl option with name
68962 + "timechange_logging" is created.
68963 +
68964 +config GRKERNSEC_PROC_IPADDR
68965 + bool "/proc/<pid>/ipaddr support"
68966 + default y if GRKERNSEC_CONFIG_AUTO
68967 + help
68968 + If you say Y here, a new entry will be added to each /proc/<pid>
68969 + directory that contains the IP address of the person using the task.
68970 + The IP is carried across local TCP and AF_UNIX stream sockets.
68971 + This information can be useful for IDS/IPSes to perform remote response
68972 + to a local attack. The entry is readable by only the owner of the
68973 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
68974 + the RBAC system), and thus does not create privacy concerns.
68975 +
68976 +config GRKERNSEC_RWXMAP_LOG
68977 + bool 'Denied RWX mmap/mprotect logging'
68978 + default y if GRKERNSEC_CONFIG_AUTO
68979 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
68980 + help
68981 + If you say Y here, calls to mmap() and mprotect() with explicit
68982 + usage of PROT_WRITE and PROT_EXEC together will be logged when
68983 + denied by the PAX_MPROTECT feature. This feature will also
68984 + log other problematic scenarios that can occur when PAX_MPROTECT
68985 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
68986 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
68987 + is created.
68988 +
68989 +endmenu
68990 +
68991 +menu "Executable Protections"
68992 +depends on GRKERNSEC
68993 +
68994 +config GRKERNSEC_DMESG
68995 + bool "Dmesg(8) restriction"
68996 + default y if GRKERNSEC_CONFIG_AUTO
68997 + help
68998 + If you say Y here, non-root users will not be able to use dmesg(8)
68999 + to view the contents of the kernel's circular log buffer.
69000 + The kernel's log buffer often contains kernel addresses and other
69001 + identifying information useful to an attacker in fingerprinting a
69002 + system for a targeted exploit.
69003 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69004 + created.
69005 +
69006 +config GRKERNSEC_HARDEN_PTRACE
69007 + bool "Deter ptrace-based process snooping"
69008 + default y if GRKERNSEC_CONFIG_AUTO
69009 + help
69010 + If you say Y here, TTY sniffers and other malicious monitoring
69011 + programs implemented through ptrace will be defeated. If you
69012 + have been using the RBAC system, this option has already been
69013 + enabled for several years for all users, with the ability to make
69014 + fine-grained exceptions.
69015 +
69016 + This option only affects the ability of non-root users to ptrace
69017 + processes that are not a descendent of the ptracing process.
69018 + This means that strace ./binary and gdb ./binary will still work,
69019 + but attaching to arbitrary processes will not. If the sysctl
69020 + option is enabled, a sysctl option with name "harden_ptrace" is
69021 + created.
69022 +
69023 +config GRKERNSEC_PTRACE_READEXEC
69024 + bool "Require read access to ptrace sensitive binaries"
69025 + default y if GRKERNSEC_CONFIG_AUTO
69026 + help
69027 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69028 + binaries. This option is useful in environments that
69029 + remove the read bits (e.g. file mode 4711) from suid binaries to
69030 + prevent infoleaking of their contents. This option adds
69031 + consistency to the use of that file mode, as the binary could normally
69032 + be read out when run without privileges while ptracing.
69033 +
69034 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69035 + is created.
69036 +
69037 +config GRKERNSEC_SETXID
69038 + bool "Enforce consistent multithreaded privileges"
69039 + default y if GRKERNSEC_CONFIG_AUTO
69040 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69041 + help
69042 + If you say Y here, a change from a root uid to a non-root uid
69043 + in a multithreaded application will cause the resulting uids,
69044 + gids, supplementary groups, and capabilities in that thread
69045 + to be propagated to the other threads of the process. In most
69046 + cases this is unnecessary, as glibc will emulate this behavior
69047 + on behalf of the application. Other libcs do not act in the
69048 + same way, allowing the other threads of the process to continue
69049 + running with root privileges. If the sysctl option is enabled,
69050 + a sysctl option with name "consistent_setxid" is created.
69051 +
69052 +config GRKERNSEC_HARDEN_IPC
69053 + bool "Disallow access to overly-permissive IPC objects"
69054 + default y if GRKERNSEC_CONFIG_AUTO
69055 + depends on SYSVIPC
69056 + help
69057 + If you say Y here, access to overly-permissive IPC objects (shared
69058 + memory, message queues, and semaphores) will be denied for processes
69059 + given the following criteria beyond normal permission checks:
69060 + 1) If the IPC object is world-accessible and the euid doesn't match
69061 + that of the creator or current uid for the IPC object
69062 + 2) If the IPC object is group-accessible and the egid doesn't
69063 + match that of the creator or current gid for the IPC object
69064 + It's a common error to grant too much permission to these objects,
69065 + with impact ranging from denial of service and information leaking to
69066 + privilege escalation. This feature was developed in response to
69067 + research by Tim Brown:
69068 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69069 + who found hundreds of such insecure usages. Processes with
69070 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69071 + If the sysctl option is enabled, a sysctl option with name
69072 + "harden_ipc" is created.
69073 +
69074 +config GRKERNSEC_TPE
69075 + bool "Trusted Path Execution (TPE)"
69076 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69077 + help
69078 + If you say Y here, you will be able to choose a gid to add to the
69079 + supplementary groups of users you want to mark as "untrusted."
69080 + These users will not be able to execute any files that are not in
69081 + root-owned directories writable only by root. If the sysctl option
69082 + is enabled, a sysctl option with name "tpe" is created.
69083 +
69084 +config GRKERNSEC_TPE_ALL
69085 + bool "Partially restrict all non-root users"
69086 + depends on GRKERNSEC_TPE
69087 + help
69088 + If you say Y here, all non-root users will be covered under
69089 + a weaker TPE restriction. This is separate from, and in addition to,
69090 + the main TPE options that you have selected elsewhere. Thus, if a
69091 + "trusted" GID is chosen, this restriction applies to even that GID.
69092 + Under this restriction, all non-root users will only be allowed to
69093 + execute files in directories they own that are not group or
69094 + world-writable, or in directories owned by root and writable only by
69095 + root. If the sysctl option is enabled, a sysctl option with name
69096 + "tpe_restrict_all" is created.
69097 +
69098 +config GRKERNSEC_TPE_INVERT
69099 + bool "Invert GID option"
69100 + depends on GRKERNSEC_TPE
69101 + help
69102 + If you say Y here, the group you specify in the TPE configuration will
69103 + decide what group TPE restrictions will be *disabled* for. This
69104 + option is useful if you want TPE restrictions to be applied to most
69105 + users on the system. If the sysctl option is enabled, a sysctl option
69106 + with name "tpe_invert" is created. Unlike other sysctl options, this
69107 + entry will default to on for backward-compatibility.
69108 +
69109 +config GRKERNSEC_TPE_GID
69110 + int
69111 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69112 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69113 +
69114 +config GRKERNSEC_TPE_UNTRUSTED_GID
69115 + int "GID for TPE-untrusted users"
69116 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69117 + default 1005
69118 + help
69119 + Setting this GID determines what group TPE restrictions will be
69120 + *enabled* for. If the sysctl option is enabled, a sysctl option
69121 + with name "tpe_gid" is created.
69122 +
69123 +config GRKERNSEC_TPE_TRUSTED_GID
69124 + int "GID for TPE-trusted users"
69125 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69126 + default 1005
69127 + help
69128 + Setting this GID determines what group TPE restrictions will be
69129 + *disabled* for. If the sysctl option is enabled, a sysctl option
69130 + with name "tpe_gid" is created.
69131 +
69132 +endmenu
69133 +menu "Network Protections"
69134 +depends on GRKERNSEC
69135 +
69136 +config GRKERNSEC_BLACKHOLE
69137 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69138 + default y if GRKERNSEC_CONFIG_AUTO
69139 + depends on NET
69140 + help
69141 + If you say Y here, neither TCP resets nor ICMP
69142 + destination-unreachable packets will be sent in response to packets
69143 + sent to ports for which no associated listening process exists.
69144 + It will also prevent the sending of ICMP protocol unreachable packets
69145 + in response to packets with unknown protocols.
69146 + This feature supports both IPV4 and IPV6 and exempts the
69147 + loopback interface from blackholing. Enabling this feature
69148 + makes a host more resilient to DoS attacks and reduces network
69149 + visibility against scanners.
69150 +
69151 + The blackhole feature as-implemented is equivalent to the FreeBSD
69152 + blackhole feature, as it prevents RST responses to all packets, not
69153 + just SYNs. Under most application behavior this causes no
69154 + problems, but applications (like haproxy) may not close certain
69155 + connections in a way that cleanly terminates them on the remote
69156 + end, leaving the remote host in LAST_ACK state. Because of this
69157 + side-effect and to prevent intentional LAST_ACK DoSes, this
69158 + feature also adds automatic mitigation against such attacks.
69159 + The mitigation drastically reduces the amount of time a socket
69160 + can spend in LAST_ACK state. If you're using haproxy and not
69161 + all servers it connects to have this option enabled, consider
69162 + disabling this feature on the haproxy host.
69163 +
69164 + If the sysctl option is enabled, two sysctl options with names
69165 + "ip_blackhole" and "lastack_retries" will be created.
69166 + While "ip_blackhole" takes the standard zero/non-zero on/off
69167 + toggle, "lastack_retries" uses the same kinds of values as
69168 + "tcp_retries1" and "tcp_retries2". The default value of 4
69169 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69170 + state.
69171 +
69172 +config GRKERNSEC_NO_SIMULT_CONNECT
69173 + bool "Disable TCP Simultaneous Connect"
69174 + default y if GRKERNSEC_CONFIG_AUTO
69175 + depends on NET
69176 + help
69177 + If you say Y here, a feature by Willy Tarreau will be enabled that
69178 + removes a weakness in Linux's strict implementation of TCP that
69179 + allows two clients to connect to each other without either entering
69180 + a listening state. The weakness allows an attacker to easily prevent
69181 + a client from connecting to a known server provided the source port
69182 + for the connection is guessed correctly.
69183 +
69184 + As the weakness could be used to prevent an antivirus or IPS from
69185 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69186 + it should be eliminated by enabling this option. Though Linux is
69187 + one of few operating systems supporting simultaneous connect, it
69188 + has no legitimate use in practice and is rarely supported by firewalls.
69189 +
69190 +config GRKERNSEC_SOCKET
69191 + bool "Socket restrictions"
69192 + depends on NET
69193 + help
69194 + If you say Y here, you will be able to choose from several options.
69195 + If you assign a GID on your system and add it to the supplementary
69196 + groups of users you want to restrict socket access to, this patch
69197 + will perform up to three things, based on the option(s) you choose.
69198 +
69199 +config GRKERNSEC_SOCKET_ALL
69200 + bool "Deny any sockets to group"
69201 + depends on GRKERNSEC_SOCKET
69202 + help
69203 + If you say Y here, you will be able to choose a GID of whose users will
69204 + be unable to connect to other hosts from your machine or run server
69205 + applications from your machine. If the sysctl option is enabled, a
69206 + sysctl option with name "socket_all" is created.
69207 +
69208 +config GRKERNSEC_SOCKET_ALL_GID
69209 + int "GID to deny all sockets for"
69210 + depends on GRKERNSEC_SOCKET_ALL
69211 + default 1004
69212 + help
69213 + Here you can choose the GID to disable socket access for. Remember to
69214 + add the users you want socket access disabled for to the GID
69215 + specified here. If the sysctl option is enabled, a sysctl option
69216 + with name "socket_all_gid" is created.
69217 +
69218 +config GRKERNSEC_SOCKET_CLIENT
69219 + bool "Deny client sockets to group"
69220 + depends on GRKERNSEC_SOCKET
69221 + help
69222 + If you say Y here, you will be able to choose a GID of whose users will
69223 + be unable to connect to other hosts from your machine, but will be
69224 + able to run servers. If this option is enabled, all users in the group
69225 + you specify will have to use passive mode when initiating ftp transfers
69226 + from the shell on your machine. If the sysctl option is enabled, a
69227 + sysctl option with name "socket_client" is created.
69228 +
69229 +config GRKERNSEC_SOCKET_CLIENT_GID
69230 + int "GID to deny client sockets for"
69231 + depends on GRKERNSEC_SOCKET_CLIENT
69232 + default 1003
69233 + help
69234 + Here you can choose the GID to disable client socket access for.
69235 + Remember to add the users you want client socket access disabled for to
69236 + the GID specified here. If the sysctl option is enabled, a sysctl
69237 + option with name "socket_client_gid" is created.
69238 +
69239 +config GRKERNSEC_SOCKET_SERVER
69240 + bool "Deny server sockets to group"
69241 + depends on GRKERNSEC_SOCKET
69242 + help
69243 + If you say Y here, you will be able to choose a GID of whose users will
69244 + be unable to run server applications from your machine. If the sysctl
69245 + option is enabled, a sysctl option with name "socket_server" is created.
69246 +
69247 +config GRKERNSEC_SOCKET_SERVER_GID
69248 + int "GID to deny server sockets for"
69249 + depends on GRKERNSEC_SOCKET_SERVER
69250 + default 1002
69251 + help
69252 + Here you can choose the GID to disable server socket access for.
69253 + Remember to add the users you want server socket access disabled for to
69254 + the GID specified here. If the sysctl option is enabled, a sysctl
69255 + option with name "socket_server_gid" is created.
69256 +
69257 +endmenu
69258 +
69259 +menu "Physical Protections"
69260 +depends on GRKERNSEC
69261 +
69262 +config GRKERNSEC_DENYUSB
69263 + bool "Deny new USB connections after toggle"
69264 + default y if GRKERNSEC_CONFIG_AUTO
69265 + depends on SYSCTL && USB_SUPPORT
69266 + help
69267 + If you say Y here, a new sysctl option with name "deny_new_usb"
69268 + will be created. Setting its value to 1 will prevent any new
69269 + USB devices from being recognized by the OS. Any attempted USB
69270 + device insertion will be logged. This option is intended to be
69271 + used against custom USB devices designed to exploit vulnerabilities
69272 + in various USB device drivers.
69273 +
69274 + For greatest effectiveness, this sysctl should be set after any
69275 + relevant init scripts. This option is safe to enable in distros
69276 + as each user can choose whether or not to toggle the sysctl.
69277 +
69278 +config GRKERNSEC_DENYUSB_FORCE
69279 + bool "Reject all USB devices not connected at boot"
69280 + select USB
69281 + depends on GRKERNSEC_DENYUSB
69282 + help
69283 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69284 + that doesn't involve a sysctl entry. This option should only be
69285 + enabled if you're sure you want to deny all new USB connections
69286 + at runtime and don't want to modify init scripts. This should not
69287 + be enabled by distros. It forces the core USB code to be built
69288 + into the kernel image so that all devices connected at boot time
69289 + can be recognized and new USB device connections can be prevented
69290 + prior to init running.
69291 +
69292 +endmenu
69293 +
69294 +menu "Sysctl Support"
69295 +depends on GRKERNSEC && SYSCTL
69296 +
69297 +config GRKERNSEC_SYSCTL
69298 + bool "Sysctl support"
69299 + default y if GRKERNSEC_CONFIG_AUTO
69300 + help
69301 + If you say Y here, you will be able to change the options that
69302 + grsecurity runs with at bootup, without having to recompile your
69303 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69304 + to enable (1) or disable (0) various features. All the sysctl entries
69305 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69306 + All features enabled in the kernel configuration are disabled at boot
69307 + if you do not say Y to the "Turn on features by default" option.
69308 + All options should be set at startup, and the grsec_lock entry should
69309 + be set to a non-zero value after all the options are set.
69310 + *THIS IS EXTREMELY IMPORTANT*
69311 +
69312 +config GRKERNSEC_SYSCTL_DISTRO
69313 + bool "Extra sysctl support for distro makers (READ HELP)"
69314 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69315 + help
69316 + If you say Y here, additional sysctl options will be created
69317 + for features that affect processes running as root. Therefore,
69318 + it is critical when using this option that the grsec_lock entry be
69319 + enabled after boot. Only distros with prebuilt kernel packages
69320 + with this option enabled that can ensure grsec_lock is enabled
69321 + after boot should use this option.
69322 + *Failure to set grsec_lock after boot makes all grsec features
69323 + this option covers useless*
69324 +
69325 + Currently this option creates the following sysctl entries:
69326 + "Disable Privileged I/O": "disable_priv_io"
69327 +
69328 +config GRKERNSEC_SYSCTL_ON
69329 + bool "Turn on features by default"
69330 + default y if GRKERNSEC_CONFIG_AUTO
69331 + depends on GRKERNSEC_SYSCTL
69332 + help
69333 + If you say Y here, instead of having all features enabled in the
69334 + kernel configuration disabled at boot time, the features will be
69335 + enabled at boot time. It is recommended you say Y here unless
69336 + there is some reason you would want all sysctl-tunable features to
69337 + be disabled by default. As mentioned elsewhere, it is important
69338 + to enable the grsec_lock entry once you have finished modifying
69339 + the sysctl entries.
69340 +
69341 +endmenu
69342 +menu "Logging Options"
69343 +depends on GRKERNSEC
69344 +
69345 +config GRKERNSEC_FLOODTIME
69346 + int "Seconds in between log messages (minimum)"
69347 + default 10
69348 + help
69349 + This option allows you to enforce the number of seconds between
69350 + grsecurity log messages. The default should be suitable for most
69351 + people, however, if you choose to change it, choose a value small enough
69352 + to allow informative logs to be produced, but large enough to
69353 + prevent flooding.
69354 +
69355 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69356 + any rate limiting on grsecurity log messages.
69357 +
69358 +config GRKERNSEC_FLOODBURST
69359 + int "Number of messages in a burst (maximum)"
69360 + default 6
69361 + help
69362 + This option allows you to choose the maximum number of messages allowed
69363 + within the flood time interval you chose in a separate option. The
69364 + default should be suitable for most people, however if you find that
69365 + many of your logs are being interpreted as flooding, you may want to
69366 + raise this value.
69367 +
69368 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69369 + any rate limiting on grsecurity log messages.
69370 +
69371 +endmenu
69372 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69373 new file mode 100644
69374 index 0000000..30ababb
69375 --- /dev/null
69376 +++ b/grsecurity/Makefile
69377 @@ -0,0 +1,54 @@
69378 +# grsecurity – access control and security hardening for Linux
69379 +# All code in this directory and various hooks located throughout the Linux kernel are
69380 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69381 +# http://www.grsecurity.net spender@grsecurity.net
69382 +#
69383 +# This program is free software; you can redistribute it and/or
69384 +# modify it under the terms of the GNU General Public License version 2
69385 +# as published by the Free Software Foundation.
69386 +#
69387 +# This program is distributed in the hope that it will be useful,
69388 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69389 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69390 +# GNU General Public License for more details.
69391 +#
69392 +# You should have received a copy of the GNU General Public License
69393 +# along with this program; if not, write to the Free Software
69394 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69395 +
69396 +KBUILD_CFLAGS += -Werror
69397 +
69398 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69399 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69400 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69401 + grsec_usb.o grsec_ipc.o grsec_proc.o
69402 +
69403 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69404 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69405 + gracl_learn.o grsec_log.o gracl_policy.o
69406 +ifdef CONFIG_COMPAT
69407 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69408 +endif
69409 +
69410 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69411 +
69412 +ifdef CONFIG_NET
69413 +obj-y += grsec_sock.o
69414 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69415 +endif
69416 +
69417 +ifndef CONFIG_GRKERNSEC
69418 +obj-y += grsec_disabled.o
69419 +endif
69420 +
69421 +ifdef CONFIG_GRKERNSEC_HIDESYM
69422 +extra-y := grsec_hidesym.o
69423 +$(obj)/grsec_hidesym.o:
69424 + @-chmod -f 500 /boot
69425 + @-chmod -f 500 /lib/modules
69426 + @-chmod -f 500 /lib64/modules
69427 + @-chmod -f 500 /lib32/modules
69428 + @-chmod -f 700 .
69429 + @-chmod -f 700 $(objtree)
69430 + @echo ' grsec: protected kernel image paths'
69431 +endif
69432 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69433 new file mode 100644
69434 index 0000000..9c2d930
69435 --- /dev/null
69436 +++ b/grsecurity/gracl.c
69437 @@ -0,0 +1,2721 @@
69438 +#include <linux/kernel.h>
69439 +#include <linux/module.h>
69440 +#include <linux/sched.h>
69441 +#include <linux/mm.h>
69442 +#include <linux/file.h>
69443 +#include <linux/fs.h>
69444 +#include <linux/namei.h>
69445 +#include <linux/mount.h>
69446 +#include <linux/tty.h>
69447 +#include <linux/proc_fs.h>
69448 +#include <linux/lglock.h>
69449 +#include <linux/slab.h>
69450 +#include <linux/vmalloc.h>
69451 +#include <linux/types.h>
69452 +#include <linux/sysctl.h>
69453 +#include <linux/netdevice.h>
69454 +#include <linux/ptrace.h>
69455 +#include <linux/gracl.h>
69456 +#include <linux/gralloc.h>
69457 +#include <linux/security.h>
69458 +#include <linux/grinternal.h>
69459 +#include <linux/pid_namespace.h>
69460 +#include <linux/stop_machine.h>
69461 +#include <linux/fdtable.h>
69462 +#include <linux/percpu.h>
69463 +#include <linux/lglock.h>
69464 +#include <linux/hugetlb.h>
69465 +#include <linux/posix-timers.h>
69466 +#include <linux/prefetch.h>
69467 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69468 +#include <linux/magic.h>
69469 +#include <linux/pagemap.h>
69470 +#include "../fs/btrfs/async-thread.h"
69471 +#include "../fs/btrfs/ctree.h"
69472 +#include "../fs/btrfs/btrfs_inode.h"
69473 +#endif
69474 +#include "../fs/mount.h"
69475 +
69476 +#include <asm/uaccess.h>
69477 +#include <asm/errno.h>
69478 +#include <asm/mman.h>
69479 +
69480 +#define FOR_EACH_ROLE_START(role) \
69481 + role = running_polstate.role_list; \
69482 + while (role) {
69483 +
69484 +#define FOR_EACH_ROLE_END(role) \
69485 + role = role->prev; \
69486 + }
69487 +
69488 +extern struct path gr_real_root;
69489 +
69490 +static struct gr_policy_state running_polstate;
69491 +struct gr_policy_state *polstate = &running_polstate;
69492 +extern struct gr_alloc_state *current_alloc_state;
69493 +
69494 +extern char *gr_shared_page[4];
69495 +DEFINE_RWLOCK(gr_inode_lock);
69496 +
69497 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69498 +
69499 +#ifdef CONFIG_NET
69500 +extern struct vfsmount *sock_mnt;
69501 +#endif
69502 +
69503 +extern struct vfsmount *pipe_mnt;
69504 +extern struct vfsmount *shm_mnt;
69505 +
69506 +#ifdef CONFIG_HUGETLBFS
69507 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69508 +#endif
69509 +
69510 +extern u16 acl_sp_role_value;
69511 +extern struct acl_object_label *fakefs_obj_rw;
69512 +extern struct acl_object_label *fakefs_obj_rwx;
69513 +
69514 +int gr_acl_is_enabled(void)
69515 +{
69516 + return (gr_status & GR_READY);
69517 +}
69518 +
69519 +void gr_enable_rbac_system(void)
69520 +{
69521 + pax_open_kernel();
69522 + gr_status |= GR_READY;
69523 + pax_close_kernel();
69524 +}
69525 +
69526 +int gr_rbac_disable(void *unused)
69527 +{
69528 + pax_open_kernel();
69529 + gr_status &= ~GR_READY;
69530 + pax_close_kernel();
69531 +
69532 + return 0;
69533 +}
69534 +
69535 +static inline dev_t __get_dev(const struct dentry *dentry)
69536 +{
69537 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69538 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69539 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69540 + else
69541 +#endif
69542 + return dentry->d_sb->s_dev;
69543 +}
69544 +
69545 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69546 +{
69547 + return __get_dev(dentry);
69548 +}
69549 +
69550 +static char gr_task_roletype_to_char(struct task_struct *task)
69551 +{
69552 + switch (task->role->roletype &
69553 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69554 + GR_ROLE_SPECIAL)) {
69555 + case GR_ROLE_DEFAULT:
69556 + return 'D';
69557 + case GR_ROLE_USER:
69558 + return 'U';
69559 + case GR_ROLE_GROUP:
69560 + return 'G';
69561 + case GR_ROLE_SPECIAL:
69562 + return 'S';
69563 + }
69564 +
69565 + return 'X';
69566 +}
69567 +
69568 +char gr_roletype_to_char(void)
69569 +{
69570 + return gr_task_roletype_to_char(current);
69571 +}
69572 +
69573 +__inline__ int
69574 +gr_acl_tpe_check(void)
69575 +{
69576 + if (unlikely(!(gr_status & GR_READY)))
69577 + return 0;
69578 + if (current->role->roletype & GR_ROLE_TPE)
69579 + return 1;
69580 + else
69581 + return 0;
69582 +}
69583 +
69584 +int
69585 +gr_handle_rawio(const struct inode *inode)
69586 +{
69587 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69588 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69589 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69590 + !capable(CAP_SYS_RAWIO))
69591 + return 1;
69592 +#endif
69593 + return 0;
69594 +}
69595 +
69596 +int
69597 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69598 +{
69599 + if (likely(lena != lenb))
69600 + return 0;
69601 +
69602 + return !memcmp(a, b, lena);
69603 +}
69604 +
69605 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69606 +{
69607 + *buflen -= namelen;
69608 + if (*buflen < 0)
69609 + return -ENAMETOOLONG;
69610 + *buffer -= namelen;
69611 + memcpy(*buffer, str, namelen);
69612 + return 0;
69613 +}
69614 +
69615 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69616 +{
69617 + return prepend(buffer, buflen, name->name, name->len);
69618 +}
69619 +
69620 +static int prepend_path(const struct path *path, struct path *root,
69621 + char **buffer, int *buflen)
69622 +{
69623 + struct dentry *dentry = path->dentry;
69624 + struct vfsmount *vfsmnt = path->mnt;
69625 + struct mount *mnt = real_mount(vfsmnt);
69626 + bool slash = false;
69627 + int error = 0;
69628 +
69629 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69630 + struct dentry * parent;
69631 +
69632 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69633 + /* Global root? */
69634 + if (!mnt_has_parent(mnt)) {
69635 + goto out;
69636 + }
69637 + dentry = mnt->mnt_mountpoint;
69638 + mnt = mnt->mnt_parent;
69639 + vfsmnt = &mnt->mnt;
69640 + continue;
69641 + }
69642 + parent = dentry->d_parent;
69643 + prefetch(parent);
69644 + spin_lock(&dentry->d_lock);
69645 + error = prepend_name(buffer, buflen, &dentry->d_name);
69646 + spin_unlock(&dentry->d_lock);
69647 + if (!error)
69648 + error = prepend(buffer, buflen, "/", 1);
69649 + if (error)
69650 + break;
69651 +
69652 + slash = true;
69653 + dentry = parent;
69654 + }
69655 +
69656 +out:
69657 + if (!error && !slash)
69658 + error = prepend(buffer, buflen, "/", 1);
69659 +
69660 + return error;
69661 +}
69662 +
69663 +/* this must be called with mount_lock and rename_lock held */
69664 +
69665 +static char *__our_d_path(const struct path *path, struct path *root,
69666 + char *buf, int buflen)
69667 +{
69668 + char *res = buf + buflen;
69669 + int error;
69670 +
69671 + prepend(&res, &buflen, "\0", 1);
69672 + error = prepend_path(path, root, &res, &buflen);
69673 + if (error)
69674 + return ERR_PTR(error);
69675 +
69676 + return res;
69677 +}
69678 +
69679 +static char *
69680 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69681 +{
69682 + char *retval;
69683 +
69684 + retval = __our_d_path(path, root, buf, buflen);
69685 + if (unlikely(IS_ERR(retval)))
69686 + retval = strcpy(buf, "<path too long>");
69687 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69688 + retval[1] = '\0';
69689 +
69690 + return retval;
69691 +}
69692 +
69693 +static char *
69694 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69695 + char *buf, int buflen)
69696 +{
69697 + struct path path;
69698 + char *res;
69699 +
69700 + path.dentry = (struct dentry *)dentry;
69701 + path.mnt = (struct vfsmount *)vfsmnt;
69702 +
69703 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69704 + by the RBAC system */
69705 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69706 +
69707 + return res;
69708 +}
69709 +
69710 +static char *
69711 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69712 + char *buf, int buflen)
69713 +{
69714 + char *res;
69715 + struct path path;
69716 + struct path root;
69717 + struct task_struct *reaper = init_pid_ns.child_reaper;
69718 +
69719 + path.dentry = (struct dentry *)dentry;
69720 + path.mnt = (struct vfsmount *)vfsmnt;
69721 +
69722 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69723 + get_fs_root(reaper->fs, &root);
69724 +
69725 + read_seqlock_excl(&mount_lock);
69726 + write_seqlock(&rename_lock);
69727 + res = gen_full_path(&path, &root, buf, buflen);
69728 + write_sequnlock(&rename_lock);
69729 + read_sequnlock_excl(&mount_lock);
69730 +
69731 + path_put(&root);
69732 + return res;
69733 +}
69734 +
69735 +char *
69736 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69737 +{
69738 + char *ret;
69739 + read_seqlock_excl(&mount_lock);
69740 + write_seqlock(&rename_lock);
69741 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69742 + PAGE_SIZE);
69743 + write_sequnlock(&rename_lock);
69744 + read_sequnlock_excl(&mount_lock);
69745 + return ret;
69746 +}
69747 +
69748 +static char *
69749 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69750 +{
69751 + char *ret;
69752 + char *buf;
69753 + int buflen;
69754 +
69755 + read_seqlock_excl(&mount_lock);
69756 + write_seqlock(&rename_lock);
69757 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69758 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69759 + buflen = (int)(ret - buf);
69760 + if (buflen >= 5)
69761 + prepend(&ret, &buflen, "/proc", 5);
69762 + else
69763 + ret = strcpy(buf, "<path too long>");
69764 + write_sequnlock(&rename_lock);
69765 + read_sequnlock_excl(&mount_lock);
69766 + return ret;
69767 +}
69768 +
69769 +char *
69770 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69771 +{
69772 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69773 + PAGE_SIZE);
69774 +}
69775 +
69776 +char *
69777 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69778 +{
69779 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69780 + PAGE_SIZE);
69781 +}
69782 +
69783 +char *
69784 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69785 +{
69786 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69787 + PAGE_SIZE);
69788 +}
69789 +
69790 +char *
69791 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69792 +{
69793 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69794 + PAGE_SIZE);
69795 +}
69796 +
69797 +char *
69798 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69799 +{
69800 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69801 + PAGE_SIZE);
69802 +}
69803 +
69804 +__inline__ __u32
69805 +to_gr_audit(const __u32 reqmode)
69806 +{
69807 + /* masks off auditable permission flags, then shifts them to create
69808 + auditing flags, and adds the special case of append auditing if
69809 + we're requesting write */
69810 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69811 +}
69812 +
69813 +struct acl_role_label *
69814 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69815 + const gid_t gid)
69816 +{
69817 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69818 + struct acl_role_label *match;
69819 + struct role_allowed_ip *ipp;
69820 + unsigned int x;
69821 + u32 curr_ip = task->signal->saved_ip;
69822 +
69823 + match = state->acl_role_set.r_hash[index];
69824 +
69825 + while (match) {
69826 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69827 + for (x = 0; x < match->domain_child_num; x++) {
69828 + if (match->domain_children[x] == uid)
69829 + goto found;
69830 + }
69831 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69832 + break;
69833 + match = match->next;
69834 + }
69835 +found:
69836 + if (match == NULL) {
69837 + try_group:
69838 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69839 + match = state->acl_role_set.r_hash[index];
69840 +
69841 + while (match) {
69842 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69843 + for (x = 0; x < match->domain_child_num; x++) {
69844 + if (match->domain_children[x] == gid)
69845 + goto found2;
69846 + }
69847 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69848 + break;
69849 + match = match->next;
69850 + }
69851 +found2:
69852 + if (match == NULL)
69853 + match = state->default_role;
69854 + if (match->allowed_ips == NULL)
69855 + return match;
69856 + else {
69857 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69858 + if (likely
69859 + ((ntohl(curr_ip) & ipp->netmask) ==
69860 + (ntohl(ipp->addr) & ipp->netmask)))
69861 + return match;
69862 + }
69863 + match = state->default_role;
69864 + }
69865 + } else if (match->allowed_ips == NULL) {
69866 + return match;
69867 + } else {
69868 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69869 + if (likely
69870 + ((ntohl(curr_ip) & ipp->netmask) ==
69871 + (ntohl(ipp->addr) & ipp->netmask)))
69872 + return match;
69873 + }
69874 + goto try_group;
69875 + }
69876 +
69877 + return match;
69878 +}
69879 +
69880 +static struct acl_role_label *
69881 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69882 + const gid_t gid)
69883 +{
69884 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69885 +}
69886 +
69887 +struct acl_subject_label *
69888 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69889 + const struct acl_role_label *role)
69890 +{
69891 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69892 + struct acl_subject_label *match;
69893 +
69894 + match = role->subj_hash[index];
69895 +
69896 + while (match && (match->inode != ino || match->device != dev ||
69897 + (match->mode & GR_DELETED))) {
69898 + match = match->next;
69899 + }
69900 +
69901 + if (match && !(match->mode & GR_DELETED))
69902 + return match;
69903 + else
69904 + return NULL;
69905 +}
69906 +
69907 +struct acl_subject_label *
69908 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69909 + const struct acl_role_label *role)
69910 +{
69911 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69912 + struct acl_subject_label *match;
69913 +
69914 + match = role->subj_hash[index];
69915 +
69916 + while (match && (match->inode != ino || match->device != dev ||
69917 + !(match->mode & GR_DELETED))) {
69918 + match = match->next;
69919 + }
69920 +
69921 + if (match && (match->mode & GR_DELETED))
69922 + return match;
69923 + else
69924 + return NULL;
69925 +}
69926 +
69927 +static struct acl_object_label *
69928 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69929 + const struct acl_subject_label *subj)
69930 +{
69931 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69932 + struct acl_object_label *match;
69933 +
69934 + match = subj->obj_hash[index];
69935 +
69936 + while (match && (match->inode != ino || match->device != dev ||
69937 + (match->mode & GR_DELETED))) {
69938 + match = match->next;
69939 + }
69940 +
69941 + if (match && !(match->mode & GR_DELETED))
69942 + return match;
69943 + else
69944 + return NULL;
69945 +}
69946 +
69947 +static struct acl_object_label *
69948 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
69949 + const struct acl_subject_label *subj)
69950 +{
69951 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69952 + struct acl_object_label *match;
69953 +
69954 + match = subj->obj_hash[index];
69955 +
69956 + while (match && (match->inode != ino || match->device != dev ||
69957 + !(match->mode & GR_DELETED))) {
69958 + match = match->next;
69959 + }
69960 +
69961 + if (match && (match->mode & GR_DELETED))
69962 + return match;
69963 +
69964 + match = subj->obj_hash[index];
69965 +
69966 + while (match && (match->inode != ino || match->device != dev ||
69967 + (match->mode & GR_DELETED))) {
69968 + match = match->next;
69969 + }
69970 +
69971 + if (match && !(match->mode & GR_DELETED))
69972 + return match;
69973 + else
69974 + return NULL;
69975 +}
69976 +
69977 +struct name_entry *
69978 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
69979 +{
69980 + unsigned int len = strlen(name);
69981 + unsigned int key = full_name_hash(name, len);
69982 + unsigned int index = key % state->name_set.n_size;
69983 + struct name_entry *match;
69984 +
69985 + match = state->name_set.n_hash[index];
69986 +
69987 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
69988 + match = match->next;
69989 +
69990 + return match;
69991 +}
69992 +
69993 +static struct name_entry *
69994 +lookup_name_entry(const char *name)
69995 +{
69996 + return __lookup_name_entry(&running_polstate, name);
69997 +}
69998 +
69999 +static struct name_entry *
70000 +lookup_name_entry_create(const char *name)
70001 +{
70002 + unsigned int len = strlen(name);
70003 + unsigned int key = full_name_hash(name, len);
70004 + unsigned int index = key % running_polstate.name_set.n_size;
70005 + struct name_entry *match;
70006 +
70007 + match = running_polstate.name_set.n_hash[index];
70008 +
70009 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70010 + !match->deleted))
70011 + match = match->next;
70012 +
70013 + if (match && match->deleted)
70014 + return match;
70015 +
70016 + match = running_polstate.name_set.n_hash[index];
70017 +
70018 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70019 + match->deleted))
70020 + match = match->next;
70021 +
70022 + if (match && !match->deleted)
70023 + return match;
70024 + else
70025 + return NULL;
70026 +}
70027 +
70028 +static struct inodev_entry *
70029 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70030 +{
70031 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70032 + struct inodev_entry *match;
70033 +
70034 + match = running_polstate.inodev_set.i_hash[index];
70035 +
70036 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70037 + match = match->next;
70038 +
70039 + return match;
70040 +}
70041 +
70042 +void
70043 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70044 +{
70045 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70046 + state->inodev_set.i_size);
70047 + struct inodev_entry **curr;
70048 +
70049 + entry->prev = NULL;
70050 +
70051 + curr = &state->inodev_set.i_hash[index];
70052 + if (*curr != NULL)
70053 + (*curr)->prev = entry;
70054 +
70055 + entry->next = *curr;
70056 + *curr = entry;
70057 +
70058 + return;
70059 +}
70060 +
70061 +static void
70062 +insert_inodev_entry(struct inodev_entry *entry)
70063 +{
70064 + __insert_inodev_entry(&running_polstate, entry);
70065 +}
70066 +
70067 +void
70068 +insert_acl_obj_label(struct acl_object_label *obj,
70069 + struct acl_subject_label *subj)
70070 +{
70071 + unsigned int index =
70072 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70073 + struct acl_object_label **curr;
70074 +
70075 + obj->prev = NULL;
70076 +
70077 + curr = &subj->obj_hash[index];
70078 + if (*curr != NULL)
70079 + (*curr)->prev = obj;
70080 +
70081 + obj->next = *curr;
70082 + *curr = obj;
70083 +
70084 + return;
70085 +}
70086 +
70087 +void
70088 +insert_acl_subj_label(struct acl_subject_label *obj,
70089 + struct acl_role_label *role)
70090 +{
70091 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70092 + struct acl_subject_label **curr;
70093 +
70094 + obj->prev = NULL;
70095 +
70096 + curr = &role->subj_hash[index];
70097 + if (*curr != NULL)
70098 + (*curr)->prev = obj;
70099 +
70100 + obj->next = *curr;
70101 + *curr = obj;
70102 +
70103 + return;
70104 +}
70105 +
70106 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70107 +
70108 +static int
70109 +glob_match(const char *p, const char *n)
70110 +{
70111 + char c;
70112 +
70113 + while ((c = *p++) != '\0') {
70114 + switch (c) {
70115 + case '?':
70116 + if (*n == '\0')
70117 + return 1;
70118 + else if (*n == '/')
70119 + return 1;
70120 + break;
70121 + case '\\':
70122 + if (*n != c)
70123 + return 1;
70124 + break;
70125 + case '*':
70126 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70127 + if (*n == '/')
70128 + return 1;
70129 + else if (c == '?') {
70130 + if (*n == '\0')
70131 + return 1;
70132 + else
70133 + ++n;
70134 + }
70135 + }
70136 + if (c == '\0') {
70137 + return 0;
70138 + } else {
70139 + const char *endp;
70140 +
70141 + if ((endp = strchr(n, '/')) == NULL)
70142 + endp = n + strlen(n);
70143 +
70144 + if (c == '[') {
70145 + for (--p; n < endp; ++n)
70146 + if (!glob_match(p, n))
70147 + return 0;
70148 + } else if (c == '/') {
70149 + while (*n != '\0' && *n != '/')
70150 + ++n;
70151 + if (*n == '/' && !glob_match(p, n + 1))
70152 + return 0;
70153 + } else {
70154 + for (--p; n < endp; ++n)
70155 + if (*n == c && !glob_match(p, n))
70156 + return 0;
70157 + }
70158 +
70159 + return 1;
70160 + }
70161 + case '[':
70162 + {
70163 + int not;
70164 + char cold;
70165 +
70166 + if (*n == '\0' || *n == '/')
70167 + return 1;
70168 +
70169 + not = (*p == '!' || *p == '^');
70170 + if (not)
70171 + ++p;
70172 +
70173 + c = *p++;
70174 + for (;;) {
70175 + unsigned char fn = (unsigned char)*n;
70176 +
70177 + if (c == '\0')
70178 + return 1;
70179 + else {
70180 + if (c == fn)
70181 + goto matched;
70182 + cold = c;
70183 + c = *p++;
70184 +
70185 + if (c == '-' && *p != ']') {
70186 + unsigned char cend = *p++;
70187 +
70188 + if (cend == '\0')
70189 + return 1;
70190 +
70191 + if (cold <= fn && fn <= cend)
70192 + goto matched;
70193 +
70194 + c = *p++;
70195 + }
70196 + }
70197 +
70198 + if (c == ']')
70199 + break;
70200 + }
70201 + if (!not)
70202 + return 1;
70203 + break;
70204 + matched:
70205 + while (c != ']') {
70206 + if (c == '\0')
70207 + return 1;
70208 +
70209 + c = *p++;
70210 + }
70211 + if (not)
70212 + return 1;
70213 + }
70214 + break;
70215 + default:
70216 + if (c != *n)
70217 + return 1;
70218 + }
70219 +
70220 + ++n;
70221 + }
70222 +
70223 + if (*n == '\0')
70224 + return 0;
70225 +
70226 + if (*n == '/')
70227 + return 0;
70228 +
70229 + return 1;
70230 +}
70231 +
70232 +static struct acl_object_label *
70233 +chk_glob_label(struct acl_object_label *globbed,
70234 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70235 +{
70236 + struct acl_object_label *tmp;
70237 +
70238 + if (*path == NULL)
70239 + *path = gr_to_filename_nolock(dentry, mnt);
70240 +
70241 + tmp = globbed;
70242 +
70243 + while (tmp) {
70244 + if (!glob_match(tmp->filename, *path))
70245 + return tmp;
70246 + tmp = tmp->next;
70247 + }
70248 +
70249 + return NULL;
70250 +}
70251 +
70252 +static struct acl_object_label *
70253 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70254 + const ino_t curr_ino, const dev_t curr_dev,
70255 + const struct acl_subject_label *subj, char **path, const int checkglob)
70256 +{
70257 + struct acl_subject_label *tmpsubj;
70258 + struct acl_object_label *retval;
70259 + struct acl_object_label *retval2;
70260 +
70261 + tmpsubj = (struct acl_subject_label *) subj;
70262 + read_lock(&gr_inode_lock);
70263 + do {
70264 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70265 + if (retval) {
70266 + if (checkglob && retval->globbed) {
70267 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70268 + if (retval2)
70269 + retval = retval2;
70270 + }
70271 + break;
70272 + }
70273 + } while ((tmpsubj = tmpsubj->parent_subject));
70274 + read_unlock(&gr_inode_lock);
70275 +
70276 + return retval;
70277 +}
70278 +
70279 +static __inline__ struct acl_object_label *
70280 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70281 + struct dentry *curr_dentry,
70282 + const struct acl_subject_label *subj, char **path, const int checkglob)
70283 +{
70284 + int newglob = checkglob;
70285 + ino_t inode;
70286 + dev_t device;
70287 +
70288 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70289 + as we don't want a / * rule to match instead of the / object
70290 + don't do this for create lookups that call this function though, since they're looking up
70291 + on the parent and thus need globbing checks on all paths
70292 + */
70293 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70294 + newglob = GR_NO_GLOB;
70295 +
70296 + spin_lock(&curr_dentry->d_lock);
70297 + inode = curr_dentry->d_inode->i_ino;
70298 + device = __get_dev(curr_dentry);
70299 + spin_unlock(&curr_dentry->d_lock);
70300 +
70301 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70302 +}
70303 +
70304 +#ifdef CONFIG_HUGETLBFS
70305 +static inline bool
70306 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70307 +{
70308 + int i;
70309 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70310 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70311 + return true;
70312 + }
70313 +
70314 + return false;
70315 +}
70316 +#endif
70317 +
70318 +static struct acl_object_label *
70319 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70320 + const struct acl_subject_label *subj, char *path, const int checkglob)
70321 +{
70322 + struct dentry *dentry = (struct dentry *) l_dentry;
70323 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70324 + struct mount *real_mnt = real_mount(mnt);
70325 + struct acl_object_label *retval;
70326 + struct dentry *parent;
70327 +
70328 + read_seqlock_excl(&mount_lock);
70329 + write_seqlock(&rename_lock);
70330 +
70331 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70332 +#ifdef CONFIG_NET
70333 + mnt == sock_mnt ||
70334 +#endif
70335 +#ifdef CONFIG_HUGETLBFS
70336 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70337 +#endif
70338 + /* ignore Eric Biederman */
70339 + IS_PRIVATE(l_dentry->d_inode))) {
70340 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70341 + goto out;
70342 + }
70343 +
70344 + for (;;) {
70345 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70346 + break;
70347 +
70348 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70349 + if (!mnt_has_parent(real_mnt))
70350 + break;
70351 +
70352 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70353 + if (retval != NULL)
70354 + goto out;
70355 +
70356 + dentry = real_mnt->mnt_mountpoint;
70357 + real_mnt = real_mnt->mnt_parent;
70358 + mnt = &real_mnt->mnt;
70359 + continue;
70360 + }
70361 +
70362 + parent = dentry->d_parent;
70363 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70364 + if (retval != NULL)
70365 + goto out;
70366 +
70367 + dentry = parent;
70368 + }
70369 +
70370 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70371 +
70372 + /* gr_real_root is pinned so we don't have to hold a reference */
70373 + if (retval == NULL)
70374 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70375 +out:
70376 + write_sequnlock(&rename_lock);
70377 + read_sequnlock_excl(&mount_lock);
70378 +
70379 + BUG_ON(retval == NULL);
70380 +
70381 + return retval;
70382 +}
70383 +
70384 +static __inline__ struct acl_object_label *
70385 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70386 + const struct acl_subject_label *subj)
70387 +{
70388 + char *path = NULL;
70389 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70390 +}
70391 +
70392 +static __inline__ struct acl_object_label *
70393 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70394 + const struct acl_subject_label *subj)
70395 +{
70396 + char *path = NULL;
70397 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70398 +}
70399 +
70400 +static __inline__ struct acl_object_label *
70401 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70402 + const struct acl_subject_label *subj, char *path)
70403 +{
70404 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70405 +}
70406 +
70407 +struct acl_subject_label *
70408 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70409 + const struct acl_role_label *role)
70410 +{
70411 + struct dentry *dentry = (struct dentry *) l_dentry;
70412 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70413 + struct mount *real_mnt = real_mount(mnt);
70414 + struct acl_subject_label *retval;
70415 + struct dentry *parent;
70416 +
70417 + read_seqlock_excl(&mount_lock);
70418 + write_seqlock(&rename_lock);
70419 +
70420 + for (;;) {
70421 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70422 + break;
70423 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70424 + if (!mnt_has_parent(real_mnt))
70425 + break;
70426 +
70427 + spin_lock(&dentry->d_lock);
70428 + read_lock(&gr_inode_lock);
70429 + retval =
70430 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70431 + __get_dev(dentry), role);
70432 + read_unlock(&gr_inode_lock);
70433 + spin_unlock(&dentry->d_lock);
70434 + if (retval != NULL)
70435 + goto out;
70436 +
70437 + dentry = real_mnt->mnt_mountpoint;
70438 + real_mnt = real_mnt->mnt_parent;
70439 + mnt = &real_mnt->mnt;
70440 + continue;
70441 + }
70442 +
70443 + spin_lock(&dentry->d_lock);
70444 + read_lock(&gr_inode_lock);
70445 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70446 + __get_dev(dentry), role);
70447 + read_unlock(&gr_inode_lock);
70448 + parent = dentry->d_parent;
70449 + spin_unlock(&dentry->d_lock);
70450 +
70451 + if (retval != NULL)
70452 + goto out;
70453 +
70454 + dentry = parent;
70455 + }
70456 +
70457 + spin_lock(&dentry->d_lock);
70458 + read_lock(&gr_inode_lock);
70459 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70460 + __get_dev(dentry), role);
70461 + read_unlock(&gr_inode_lock);
70462 + spin_unlock(&dentry->d_lock);
70463 +
70464 + if (unlikely(retval == NULL)) {
70465 + /* gr_real_root is pinned, we don't need to hold a reference */
70466 + read_lock(&gr_inode_lock);
70467 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70468 + __get_dev(gr_real_root.dentry), role);
70469 + read_unlock(&gr_inode_lock);
70470 + }
70471 +out:
70472 + write_sequnlock(&rename_lock);
70473 + read_sequnlock_excl(&mount_lock);
70474 +
70475 + BUG_ON(retval == NULL);
70476 +
70477 + return retval;
70478 +}
70479 +
70480 +void
70481 +assign_special_role(const char *rolename)
70482 +{
70483 + struct acl_object_label *obj;
70484 + struct acl_role_label *r;
70485 + struct acl_role_label *assigned = NULL;
70486 + struct task_struct *tsk;
70487 + struct file *filp;
70488 +
70489 + FOR_EACH_ROLE_START(r)
70490 + if (!strcmp(rolename, r->rolename) &&
70491 + (r->roletype & GR_ROLE_SPECIAL)) {
70492 + assigned = r;
70493 + break;
70494 + }
70495 + FOR_EACH_ROLE_END(r)
70496 +
70497 + if (!assigned)
70498 + return;
70499 +
70500 + read_lock(&tasklist_lock);
70501 + read_lock(&grsec_exec_file_lock);
70502 +
70503 + tsk = current->real_parent;
70504 + if (tsk == NULL)
70505 + goto out_unlock;
70506 +
70507 + filp = tsk->exec_file;
70508 + if (filp == NULL)
70509 + goto out_unlock;
70510 +
70511 + tsk->is_writable = 0;
70512 + tsk->inherited = 0;
70513 +
70514 + tsk->acl_sp_role = 1;
70515 + tsk->acl_role_id = ++acl_sp_role_value;
70516 + tsk->role = assigned;
70517 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70518 +
70519 + /* ignore additional mmap checks for processes that are writable
70520 + by the default ACL */
70521 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70522 + if (unlikely(obj->mode & GR_WRITE))
70523 + tsk->is_writable = 1;
70524 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70525 + if (unlikely(obj->mode & GR_WRITE))
70526 + tsk->is_writable = 1;
70527 +
70528 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70529 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70530 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70531 +#endif
70532 +
70533 +out_unlock:
70534 + read_unlock(&grsec_exec_file_lock);
70535 + read_unlock(&tasklist_lock);
70536 + return;
70537 +}
70538 +
70539 +
70540 +static void
70541 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70542 +{
70543 + struct task_struct *task = current;
70544 + const struct cred *cred = current_cred();
70545 +
70546 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70547 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70548 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70549 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70550 +
70551 + return;
70552 +}
70553 +
70554 +static void
70555 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70556 +{
70557 + struct task_struct *task = current;
70558 + const struct cred *cred = current_cred();
70559 +
70560 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70561 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70562 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70563 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70564 +
70565 + return;
70566 +}
70567 +
70568 +static void
70569 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70570 +{
70571 + struct task_struct *task = current;
70572 + const struct cred *cred = current_cred();
70573 +
70574 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70575 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70576 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70577 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70578 +
70579 + return;
70580 +}
70581 +
70582 +static void
70583 +gr_set_proc_res(struct task_struct *task)
70584 +{
70585 + struct acl_subject_label *proc;
70586 + unsigned short i;
70587 +
70588 + proc = task->acl;
70589 +
70590 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70591 + return;
70592 +
70593 + for (i = 0; i < RLIM_NLIMITS; i++) {
70594 + if (!(proc->resmask & (1U << i)))
70595 + continue;
70596 +
70597 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70598 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70599 +
70600 + if (i == RLIMIT_CPU)
70601 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70602 + }
70603 +
70604 + return;
70605 +}
70606 +
70607 +/* both of the below must be called with
70608 + rcu_read_lock();
70609 + read_lock(&tasklist_lock);
70610 + read_lock(&grsec_exec_file_lock);
70611 + except in the case of gr_set_role_label() (for __gr_get_subject_for_task)
70612 +*/
70613 +
70614 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback)
70615 +{
70616 + char *tmpname;
70617 + struct acl_subject_label *tmpsubj;
70618 + struct file *filp;
70619 + struct name_entry *nmatch;
70620 +
70621 + filp = task->exec_file;
70622 + if (filp == NULL)
70623 + return NULL;
70624 +
70625 + /* the following is to apply the correct subject
70626 + on binaries running when the RBAC system
70627 + is enabled, when the binaries have been
70628 + replaced or deleted since their execution
70629 + -----
70630 + when the RBAC system starts, the inode/dev
70631 + from exec_file will be one the RBAC system
70632 + is unaware of. It only knows the inode/dev
70633 + of the present file on disk, or the absence
70634 + of it.
70635 + */
70636 +
70637 + if (filename)
70638 + nmatch = __lookup_name_entry(state, filename);
70639 + else {
70640 + preempt_disable();
70641 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70642 +
70643 + nmatch = __lookup_name_entry(state, tmpname);
70644 + preempt_enable();
70645 + }
70646 + tmpsubj = NULL;
70647 + if (nmatch) {
70648 + if (nmatch->deleted)
70649 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70650 + else
70651 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70652 + }
70653 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70654 + then we fall back to a normal lookup based on the binary's ino/dev
70655 + */
70656 + if (tmpsubj == NULL && fallback)
70657 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70658 +
70659 + return tmpsubj;
70660 +}
70661 +
70662 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename, int fallback)
70663 +{
70664 + return __gr_get_subject_for_task(&running_polstate, task, filename, fallback);
70665 +}
70666 +
70667 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70668 +{
70669 + struct acl_object_label *obj;
70670 + struct file *filp;
70671 +
70672 + filp = task->exec_file;
70673 +
70674 + task->acl = subj;
70675 + task->is_writable = 0;
70676 + /* ignore additional mmap checks for processes that are writable
70677 + by the default ACL */
70678 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70679 + if (unlikely(obj->mode & GR_WRITE))
70680 + task->is_writable = 1;
70681 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70682 + if (unlikely(obj->mode & GR_WRITE))
70683 + task->is_writable = 1;
70684 +
70685 + gr_set_proc_res(task);
70686 +
70687 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70688 + 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);
70689 +#endif
70690 +}
70691 +
70692 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70693 +{
70694 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70695 +}
70696 +
70697 +__u32
70698 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70699 + const struct vfsmount * mnt)
70700 +{
70701 + __u32 retval = mode;
70702 + struct acl_subject_label *curracl;
70703 + struct acl_object_label *currobj;
70704 +
70705 + if (unlikely(!(gr_status & GR_READY)))
70706 + return (mode & ~GR_AUDITS);
70707 +
70708 + curracl = current->acl;
70709 +
70710 + currobj = chk_obj_label(dentry, mnt, curracl);
70711 + retval = currobj->mode & mode;
70712 +
70713 + /* if we're opening a specified transfer file for writing
70714 + (e.g. /dev/initctl), then transfer our role to init
70715 + */
70716 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70717 + current->role->roletype & GR_ROLE_PERSIST)) {
70718 + struct task_struct *task = init_pid_ns.child_reaper;
70719 +
70720 + if (task->role != current->role) {
70721 + struct acl_subject_label *subj;
70722 +
70723 + task->acl_sp_role = 0;
70724 + task->acl_role_id = current->acl_role_id;
70725 + task->role = current->role;
70726 + rcu_read_lock();
70727 + read_lock(&grsec_exec_file_lock);
70728 + subj = gr_get_subject_for_task(task, NULL, 1);
70729 + gr_apply_subject_to_task(task, subj);
70730 + read_unlock(&grsec_exec_file_lock);
70731 + rcu_read_unlock();
70732 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70733 + }
70734 + }
70735 +
70736 + if (unlikely
70737 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70738 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70739 + __u32 new_mode = mode;
70740 +
70741 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70742 +
70743 + retval = new_mode;
70744 +
70745 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70746 + new_mode |= GR_INHERIT;
70747 +
70748 + if (!(mode & GR_NOLEARN))
70749 + gr_log_learn(dentry, mnt, new_mode);
70750 + }
70751 +
70752 + return retval;
70753 +}
70754 +
70755 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70756 + const struct dentry *parent,
70757 + const struct vfsmount *mnt)
70758 +{
70759 + struct name_entry *match;
70760 + struct acl_object_label *matchpo;
70761 + struct acl_subject_label *curracl;
70762 + char *path;
70763 +
70764 + if (unlikely(!(gr_status & GR_READY)))
70765 + return NULL;
70766 +
70767 + preempt_disable();
70768 + path = gr_to_filename_rbac(new_dentry, mnt);
70769 + match = lookup_name_entry_create(path);
70770 +
70771 + curracl = current->acl;
70772 +
70773 + if (match) {
70774 + read_lock(&gr_inode_lock);
70775 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70776 + read_unlock(&gr_inode_lock);
70777 +
70778 + if (matchpo) {
70779 + preempt_enable();
70780 + return matchpo;
70781 + }
70782 + }
70783 +
70784 + // lookup parent
70785 +
70786 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70787 +
70788 + preempt_enable();
70789 + return matchpo;
70790 +}
70791 +
70792 +__u32
70793 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70794 + const struct vfsmount * mnt, const __u32 mode)
70795 +{
70796 + struct acl_object_label *matchpo;
70797 + __u32 retval;
70798 +
70799 + if (unlikely(!(gr_status & GR_READY)))
70800 + return (mode & ~GR_AUDITS);
70801 +
70802 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70803 +
70804 + retval = matchpo->mode & mode;
70805 +
70806 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70807 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70808 + __u32 new_mode = mode;
70809 +
70810 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70811 +
70812 + gr_log_learn(new_dentry, mnt, new_mode);
70813 + return new_mode;
70814 + }
70815 +
70816 + return retval;
70817 +}
70818 +
70819 +__u32
70820 +gr_check_link(const struct dentry * new_dentry,
70821 + const struct dentry * parent_dentry,
70822 + const struct vfsmount * parent_mnt,
70823 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70824 +{
70825 + struct acl_object_label *obj;
70826 + __u32 oldmode, newmode;
70827 + __u32 needmode;
70828 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70829 + GR_DELETE | GR_INHERIT;
70830 +
70831 + if (unlikely(!(gr_status & GR_READY)))
70832 + return (GR_CREATE | GR_LINK);
70833 +
70834 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70835 + oldmode = obj->mode;
70836 +
70837 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70838 + newmode = obj->mode;
70839 +
70840 + needmode = newmode & checkmodes;
70841 +
70842 + // old name for hardlink must have at least the permissions of the new name
70843 + if ((oldmode & needmode) != needmode)
70844 + goto bad;
70845 +
70846 + // if old name had restrictions/auditing, make sure the new name does as well
70847 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70848 +
70849 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70850 + if (is_privileged_binary(old_dentry))
70851 + needmode |= GR_SETID;
70852 +
70853 + if ((newmode & needmode) != needmode)
70854 + goto bad;
70855 +
70856 + // enforce minimum permissions
70857 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70858 + return newmode;
70859 +bad:
70860 + needmode = oldmode;
70861 + if (is_privileged_binary(old_dentry))
70862 + needmode |= GR_SETID;
70863 +
70864 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70865 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70866 + return (GR_CREATE | GR_LINK);
70867 + } else if (newmode & GR_SUPPRESS)
70868 + return GR_SUPPRESS;
70869 + else
70870 + return 0;
70871 +}
70872 +
70873 +int
70874 +gr_check_hidden_task(const struct task_struct *task)
70875 +{
70876 + if (unlikely(!(gr_status & GR_READY)))
70877 + return 0;
70878 +
70879 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70880 + return 1;
70881 +
70882 + return 0;
70883 +}
70884 +
70885 +int
70886 +gr_check_protected_task(const struct task_struct *task)
70887 +{
70888 + if (unlikely(!(gr_status & GR_READY) || !task))
70889 + return 0;
70890 +
70891 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70892 + task->acl != current->acl)
70893 + return 1;
70894 +
70895 + return 0;
70896 +}
70897 +
70898 +int
70899 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70900 +{
70901 + struct task_struct *p;
70902 + int ret = 0;
70903 +
70904 + if (unlikely(!(gr_status & GR_READY) || !pid))
70905 + return ret;
70906 +
70907 + read_lock(&tasklist_lock);
70908 + do_each_pid_task(pid, type, p) {
70909 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70910 + p->acl != current->acl) {
70911 + ret = 1;
70912 + goto out;
70913 + }
70914 + } while_each_pid_task(pid, type, p);
70915 +out:
70916 + read_unlock(&tasklist_lock);
70917 +
70918 + return ret;
70919 +}
70920 +
70921 +void
70922 +gr_copy_label(struct task_struct *tsk)
70923 +{
70924 + struct task_struct *p = current;
70925 +
70926 + tsk->inherited = p->inherited;
70927 + tsk->acl_sp_role = 0;
70928 + tsk->acl_role_id = p->acl_role_id;
70929 + tsk->acl = p->acl;
70930 + tsk->role = p->role;
70931 + tsk->signal->used_accept = 0;
70932 + tsk->signal->curr_ip = p->signal->curr_ip;
70933 + tsk->signal->saved_ip = p->signal->saved_ip;
70934 + if (p->exec_file)
70935 + get_file(p->exec_file);
70936 + tsk->exec_file = p->exec_file;
70937 + tsk->is_writable = p->is_writable;
70938 + if (unlikely(p->signal->used_accept)) {
70939 + p->signal->curr_ip = 0;
70940 + p->signal->saved_ip = 0;
70941 + }
70942 +
70943 + return;
70944 +}
70945 +
70946 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
70947 +
70948 +int
70949 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70950 +{
70951 + unsigned int i;
70952 + __u16 num;
70953 + uid_t *uidlist;
70954 + uid_t curuid;
70955 + int realok = 0;
70956 + int effectiveok = 0;
70957 + int fsok = 0;
70958 + uid_t globalreal, globaleffective, globalfs;
70959 +
70960 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
70961 + struct user_struct *user;
70962 +
70963 + if (!uid_valid(real))
70964 + goto skipit;
70965 +
70966 + /* find user based on global namespace */
70967 +
70968 + globalreal = GR_GLOBAL_UID(real);
70969 +
70970 + user = find_user(make_kuid(&init_user_ns, globalreal));
70971 + if (user == NULL)
70972 + goto skipit;
70973 +
70974 + if (gr_process_kernel_setuid_ban(user)) {
70975 + /* for find_user */
70976 + free_uid(user);
70977 + return 1;
70978 + }
70979 +
70980 + /* for find_user */
70981 + free_uid(user);
70982 +
70983 +skipit:
70984 +#endif
70985 +
70986 + if (unlikely(!(gr_status & GR_READY)))
70987 + return 0;
70988 +
70989 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70990 + gr_log_learn_uid_change(real, effective, fs);
70991 +
70992 + num = current->acl->user_trans_num;
70993 + uidlist = current->acl->user_transitions;
70994 +
70995 + if (uidlist == NULL)
70996 + return 0;
70997 +
70998 + if (!uid_valid(real)) {
70999 + realok = 1;
71000 + globalreal = (uid_t)-1;
71001 + } else {
71002 + globalreal = GR_GLOBAL_UID(real);
71003 + }
71004 + if (!uid_valid(effective)) {
71005 + effectiveok = 1;
71006 + globaleffective = (uid_t)-1;
71007 + } else {
71008 + globaleffective = GR_GLOBAL_UID(effective);
71009 + }
71010 + if (!uid_valid(fs)) {
71011 + fsok = 1;
71012 + globalfs = (uid_t)-1;
71013 + } else {
71014 + globalfs = GR_GLOBAL_UID(fs);
71015 + }
71016 +
71017 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71018 + for (i = 0; i < num; i++) {
71019 + curuid = uidlist[i];
71020 + if (globalreal == curuid)
71021 + realok = 1;
71022 + if (globaleffective == curuid)
71023 + effectiveok = 1;
71024 + if (globalfs == curuid)
71025 + fsok = 1;
71026 + }
71027 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71028 + for (i = 0; i < num; i++) {
71029 + curuid = uidlist[i];
71030 + if (globalreal == curuid)
71031 + break;
71032 + if (globaleffective == curuid)
71033 + break;
71034 + if (globalfs == curuid)
71035 + break;
71036 + }
71037 + /* not in deny list */
71038 + if (i == num) {
71039 + realok = 1;
71040 + effectiveok = 1;
71041 + fsok = 1;
71042 + }
71043 + }
71044 +
71045 + if (realok && effectiveok && fsok)
71046 + return 0;
71047 + else {
71048 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71049 + return 1;
71050 + }
71051 +}
71052 +
71053 +int
71054 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71055 +{
71056 + unsigned int i;
71057 + __u16 num;
71058 + gid_t *gidlist;
71059 + gid_t curgid;
71060 + int realok = 0;
71061 + int effectiveok = 0;
71062 + int fsok = 0;
71063 + gid_t globalreal, globaleffective, globalfs;
71064 +
71065 + if (unlikely(!(gr_status & GR_READY)))
71066 + return 0;
71067 +
71068 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71069 + gr_log_learn_gid_change(real, effective, fs);
71070 +
71071 + num = current->acl->group_trans_num;
71072 + gidlist = current->acl->group_transitions;
71073 +
71074 + if (gidlist == NULL)
71075 + return 0;
71076 +
71077 + if (!gid_valid(real)) {
71078 + realok = 1;
71079 + globalreal = (gid_t)-1;
71080 + } else {
71081 + globalreal = GR_GLOBAL_GID(real);
71082 + }
71083 + if (!gid_valid(effective)) {
71084 + effectiveok = 1;
71085 + globaleffective = (gid_t)-1;
71086 + } else {
71087 + globaleffective = GR_GLOBAL_GID(effective);
71088 + }
71089 + if (!gid_valid(fs)) {
71090 + fsok = 1;
71091 + globalfs = (gid_t)-1;
71092 + } else {
71093 + globalfs = GR_GLOBAL_GID(fs);
71094 + }
71095 +
71096 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71097 + for (i = 0; i < num; i++) {
71098 + curgid = gidlist[i];
71099 + if (globalreal == curgid)
71100 + realok = 1;
71101 + if (globaleffective == curgid)
71102 + effectiveok = 1;
71103 + if (globalfs == curgid)
71104 + fsok = 1;
71105 + }
71106 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71107 + for (i = 0; i < num; i++) {
71108 + curgid = gidlist[i];
71109 + if (globalreal == curgid)
71110 + break;
71111 + if (globaleffective == curgid)
71112 + break;
71113 + if (globalfs == curgid)
71114 + break;
71115 + }
71116 + /* not in deny list */
71117 + if (i == num) {
71118 + realok = 1;
71119 + effectiveok = 1;
71120 + fsok = 1;
71121 + }
71122 + }
71123 +
71124 + if (realok && effectiveok && fsok)
71125 + return 0;
71126 + else {
71127 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71128 + return 1;
71129 + }
71130 +}
71131 +
71132 +extern int gr_acl_is_capable(const int cap);
71133 +
71134 +void
71135 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71136 +{
71137 + struct acl_role_label *role = task->role;
71138 + struct acl_role_label *origrole = role;
71139 + struct acl_subject_label *subj = NULL;
71140 + struct acl_object_label *obj;
71141 + struct file *filp;
71142 + uid_t uid;
71143 + gid_t gid;
71144 +
71145 + if (unlikely(!(gr_status & GR_READY)))
71146 + return;
71147 +
71148 + uid = GR_GLOBAL_UID(kuid);
71149 + gid = GR_GLOBAL_GID(kgid);
71150 +
71151 + filp = task->exec_file;
71152 +
71153 + /* kernel process, we'll give them the kernel role */
71154 + if (unlikely(!filp)) {
71155 + task->role = running_polstate.kernel_role;
71156 + task->acl = running_polstate.kernel_role->root_label;
71157 + return;
71158 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71159 + /* save the current ip at time of role lookup so that the proper
71160 + IP will be learned for role_allowed_ip */
71161 + task->signal->saved_ip = task->signal->curr_ip;
71162 + role = lookup_acl_role_label(task, uid, gid);
71163 + }
71164 +
71165 + /* don't change the role if we're not a privileged process */
71166 + if (role && task->role != role &&
71167 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71168 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71169 + return;
71170 +
71171 + task->role = role;
71172 +
71173 + if (task->inherited) {
71174 + /* if we reached our subject through inheritance, then first see
71175 + if there's a subject of the same name in the new role that has
71176 + an object that would result in the same inherited subject
71177 + */
71178 + subj = gr_get_subject_for_task(task, task->acl->filename, 0);
71179 + if (subj) {
71180 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, subj);
71181 + if (!(obj->mode & GR_INHERIT))
71182 + subj = NULL;
71183 + }
71184 +
71185 + }
71186 + if (subj == NULL) {
71187 + /* otherwise:
71188 + perform subject lookup in possibly new role
71189 + we can use this result below in the case where role == task->role
71190 + */
71191 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71192 + }
71193 +
71194 + /* if we changed uid/gid, but result in the same role
71195 + and are using inheritance, don't lose the inherited subject
71196 + if current subject is other than what normal lookup
71197 + would result in, we arrived via inheritance, don't
71198 + lose subject
71199 + */
71200 + if (role != origrole || (!(task->acl->mode & GR_INHERITLEARN) &&
71201 + (subj == task->acl)))
71202 + task->acl = subj;
71203 +
71204 + /* leave task->inherited unaffected */
71205 +
71206 + task->is_writable = 0;
71207 +
71208 + /* ignore additional mmap checks for processes that are writable
71209 + by the default ACL */
71210 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71211 + if (unlikely(obj->mode & GR_WRITE))
71212 + task->is_writable = 1;
71213 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71214 + if (unlikely(obj->mode & GR_WRITE))
71215 + task->is_writable = 1;
71216 +
71217 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71218 + 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);
71219 +#endif
71220 +
71221 + gr_set_proc_res(task);
71222 +
71223 + return;
71224 +}
71225 +
71226 +int
71227 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71228 + const int unsafe_flags)
71229 +{
71230 + struct task_struct *task = current;
71231 + struct acl_subject_label *newacl;
71232 + struct acl_object_label *obj;
71233 + __u32 retmode;
71234 +
71235 + if (unlikely(!(gr_status & GR_READY)))
71236 + return 0;
71237 +
71238 + newacl = chk_subj_label(dentry, mnt, task->role);
71239 +
71240 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71241 + did an exec
71242 + */
71243 + rcu_read_lock();
71244 + read_lock(&tasklist_lock);
71245 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71246 + (task->parent->acl->mode & GR_POVERRIDE))) {
71247 + read_unlock(&tasklist_lock);
71248 + rcu_read_unlock();
71249 + goto skip_check;
71250 + }
71251 + read_unlock(&tasklist_lock);
71252 + rcu_read_unlock();
71253 +
71254 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71255 + !(task->role->roletype & GR_ROLE_GOD) &&
71256 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71257 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71258 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71259 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71260 + else
71261 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71262 + return -EACCES;
71263 + }
71264 +
71265 +skip_check:
71266 +
71267 + obj = chk_obj_label(dentry, mnt, task->acl);
71268 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71269 +
71270 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71271 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71272 + if (obj->nested)
71273 + task->acl = obj->nested;
71274 + else
71275 + task->acl = newacl;
71276 + task->inherited = 0;
71277 + } else {
71278 + task->inherited = 1;
71279 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71280 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71281 + }
71282 +
71283 + task->is_writable = 0;
71284 +
71285 + /* ignore additional mmap checks for processes that are writable
71286 + by the default ACL */
71287 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71288 + if (unlikely(obj->mode & GR_WRITE))
71289 + task->is_writable = 1;
71290 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71291 + if (unlikely(obj->mode & GR_WRITE))
71292 + task->is_writable = 1;
71293 +
71294 + gr_set_proc_res(task);
71295 +
71296 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71297 + 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);
71298 +#endif
71299 + return 0;
71300 +}
71301 +
71302 +/* always called with valid inodev ptr */
71303 +static void
71304 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71305 +{
71306 + struct acl_object_label *matchpo;
71307 + struct acl_subject_label *matchps;
71308 + struct acl_subject_label *subj;
71309 + struct acl_role_label *role;
71310 + unsigned int x;
71311 +
71312 + FOR_EACH_ROLE_START(role)
71313 + FOR_EACH_SUBJECT_START(role, subj, x)
71314 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71315 + matchpo->mode |= GR_DELETED;
71316 + FOR_EACH_SUBJECT_END(subj,x)
71317 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71318 + /* nested subjects aren't in the role's subj_hash table */
71319 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71320 + matchpo->mode |= GR_DELETED;
71321 + FOR_EACH_NESTED_SUBJECT_END(subj)
71322 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71323 + matchps->mode |= GR_DELETED;
71324 + FOR_EACH_ROLE_END(role)
71325 +
71326 + inodev->nentry->deleted = 1;
71327 +
71328 + return;
71329 +}
71330 +
71331 +void
71332 +gr_handle_delete(const ino_t ino, const dev_t dev)
71333 +{
71334 + struct inodev_entry *inodev;
71335 +
71336 + if (unlikely(!(gr_status & GR_READY)))
71337 + return;
71338 +
71339 + write_lock(&gr_inode_lock);
71340 + inodev = lookup_inodev_entry(ino, dev);
71341 + if (inodev != NULL)
71342 + do_handle_delete(inodev, ino, dev);
71343 + write_unlock(&gr_inode_lock);
71344 +
71345 + return;
71346 +}
71347 +
71348 +static void
71349 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71350 + const ino_t newinode, const dev_t newdevice,
71351 + struct acl_subject_label *subj)
71352 +{
71353 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71354 + struct acl_object_label *match;
71355 +
71356 + match = subj->obj_hash[index];
71357 +
71358 + while (match && (match->inode != oldinode ||
71359 + match->device != olddevice ||
71360 + !(match->mode & GR_DELETED)))
71361 + match = match->next;
71362 +
71363 + if (match && (match->inode == oldinode)
71364 + && (match->device == olddevice)
71365 + && (match->mode & GR_DELETED)) {
71366 + if (match->prev == NULL) {
71367 + subj->obj_hash[index] = match->next;
71368 + if (match->next != NULL)
71369 + match->next->prev = NULL;
71370 + } else {
71371 + match->prev->next = match->next;
71372 + if (match->next != NULL)
71373 + match->next->prev = match->prev;
71374 + }
71375 + match->prev = NULL;
71376 + match->next = NULL;
71377 + match->inode = newinode;
71378 + match->device = newdevice;
71379 + match->mode &= ~GR_DELETED;
71380 +
71381 + insert_acl_obj_label(match, subj);
71382 + }
71383 +
71384 + return;
71385 +}
71386 +
71387 +static void
71388 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71389 + const ino_t newinode, const dev_t newdevice,
71390 + struct acl_role_label *role)
71391 +{
71392 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71393 + struct acl_subject_label *match;
71394 +
71395 + match = role->subj_hash[index];
71396 +
71397 + while (match && (match->inode != oldinode ||
71398 + match->device != olddevice ||
71399 + !(match->mode & GR_DELETED)))
71400 + match = match->next;
71401 +
71402 + if (match && (match->inode == oldinode)
71403 + && (match->device == olddevice)
71404 + && (match->mode & GR_DELETED)) {
71405 + if (match->prev == NULL) {
71406 + role->subj_hash[index] = match->next;
71407 + if (match->next != NULL)
71408 + match->next->prev = NULL;
71409 + } else {
71410 + match->prev->next = match->next;
71411 + if (match->next != NULL)
71412 + match->next->prev = match->prev;
71413 + }
71414 + match->prev = NULL;
71415 + match->next = NULL;
71416 + match->inode = newinode;
71417 + match->device = newdevice;
71418 + match->mode &= ~GR_DELETED;
71419 +
71420 + insert_acl_subj_label(match, role);
71421 + }
71422 +
71423 + return;
71424 +}
71425 +
71426 +static void
71427 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71428 + const ino_t newinode, const dev_t newdevice)
71429 +{
71430 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71431 + struct inodev_entry *match;
71432 +
71433 + match = running_polstate.inodev_set.i_hash[index];
71434 +
71435 + while (match && (match->nentry->inode != oldinode ||
71436 + match->nentry->device != olddevice || !match->nentry->deleted))
71437 + match = match->next;
71438 +
71439 + if (match && (match->nentry->inode == oldinode)
71440 + && (match->nentry->device == olddevice) &&
71441 + match->nentry->deleted) {
71442 + if (match->prev == NULL) {
71443 + running_polstate.inodev_set.i_hash[index] = match->next;
71444 + if (match->next != NULL)
71445 + match->next->prev = NULL;
71446 + } else {
71447 + match->prev->next = match->next;
71448 + if (match->next != NULL)
71449 + match->next->prev = match->prev;
71450 + }
71451 + match->prev = NULL;
71452 + match->next = NULL;
71453 + match->nentry->inode = newinode;
71454 + match->nentry->device = newdevice;
71455 + match->nentry->deleted = 0;
71456 +
71457 + insert_inodev_entry(match);
71458 + }
71459 +
71460 + return;
71461 +}
71462 +
71463 +static void
71464 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71465 +{
71466 + struct acl_subject_label *subj;
71467 + struct acl_role_label *role;
71468 + unsigned int x;
71469 +
71470 + FOR_EACH_ROLE_START(role)
71471 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71472 +
71473 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71474 + if ((subj->inode == ino) && (subj->device == dev)) {
71475 + subj->inode = ino;
71476 + subj->device = dev;
71477 + }
71478 + /* nested subjects aren't in the role's subj_hash table */
71479 + update_acl_obj_label(matchn->inode, matchn->device,
71480 + ino, dev, subj);
71481 + FOR_EACH_NESTED_SUBJECT_END(subj)
71482 + FOR_EACH_SUBJECT_START(role, subj, x)
71483 + update_acl_obj_label(matchn->inode, matchn->device,
71484 + ino, dev, subj);
71485 + FOR_EACH_SUBJECT_END(subj,x)
71486 + FOR_EACH_ROLE_END(role)
71487 +
71488 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71489 +
71490 + return;
71491 +}
71492 +
71493 +static void
71494 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71495 + const struct vfsmount *mnt)
71496 +{
71497 + ino_t ino = dentry->d_inode->i_ino;
71498 + dev_t dev = __get_dev(dentry);
71499 +
71500 + __do_handle_create(matchn, ino, dev);
71501 +
71502 + return;
71503 +}
71504 +
71505 +void
71506 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71507 +{
71508 + struct name_entry *matchn;
71509 +
71510 + if (unlikely(!(gr_status & GR_READY)))
71511 + return;
71512 +
71513 + preempt_disable();
71514 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71515 +
71516 + if (unlikely((unsigned long)matchn)) {
71517 + write_lock(&gr_inode_lock);
71518 + do_handle_create(matchn, dentry, mnt);
71519 + write_unlock(&gr_inode_lock);
71520 + }
71521 + preempt_enable();
71522 +
71523 + return;
71524 +}
71525 +
71526 +void
71527 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71528 +{
71529 + struct name_entry *matchn;
71530 +
71531 + if (unlikely(!(gr_status & GR_READY)))
71532 + return;
71533 +
71534 + preempt_disable();
71535 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71536 +
71537 + if (unlikely((unsigned long)matchn)) {
71538 + write_lock(&gr_inode_lock);
71539 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71540 + write_unlock(&gr_inode_lock);
71541 + }
71542 + preempt_enable();
71543 +
71544 + return;
71545 +}
71546 +
71547 +void
71548 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71549 + struct dentry *old_dentry,
71550 + struct dentry *new_dentry,
71551 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71552 +{
71553 + struct name_entry *matchn;
71554 + struct name_entry *matchn2 = NULL;
71555 + struct inodev_entry *inodev;
71556 + struct inode *inode = new_dentry->d_inode;
71557 + ino_t old_ino = old_dentry->d_inode->i_ino;
71558 + dev_t old_dev = __get_dev(old_dentry);
71559 + unsigned int exchange = flags & RENAME_EXCHANGE;
71560 +
71561 + /* vfs_rename swaps the name and parent link for old_dentry and
71562 + new_dentry
71563 + at this point, old_dentry has the new name, parent link, and inode
71564 + for the renamed file
71565 + if a file is being replaced by a rename, new_dentry has the inode
71566 + and name for the replaced file
71567 + */
71568 +
71569 + if (unlikely(!(gr_status & GR_READY)))
71570 + return;
71571 +
71572 + preempt_disable();
71573 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71574 +
71575 + /* exchange cases:
71576 + a filename exists for the source, but not dest
71577 + do a recreate on source
71578 + a filename exists for the dest, but not source
71579 + do a recreate on dest
71580 + a filename exists for both source and dest
71581 + delete source and dest, then create source and dest
71582 + a filename exists for neither source nor dest
71583 + no updates needed
71584 +
71585 + the name entry lookups get us the old inode/dev associated with
71586 + each name, so do the deletes first (if possible) so that when
71587 + we do the create, we pick up on the right entries
71588 + */
71589 +
71590 + if (exchange)
71591 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71592 +
71593 + /* we wouldn't have to check d_inode if it weren't for
71594 + NFS silly-renaming
71595 + */
71596 +
71597 + write_lock(&gr_inode_lock);
71598 + if (unlikely((replace || exchange) && inode)) {
71599 + ino_t new_ino = inode->i_ino;
71600 + dev_t new_dev = __get_dev(new_dentry);
71601 +
71602 + inodev = lookup_inodev_entry(new_ino, new_dev);
71603 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71604 + do_handle_delete(inodev, new_ino, new_dev);
71605 + }
71606 +
71607 + inodev = lookup_inodev_entry(old_ino, old_dev);
71608 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71609 + do_handle_delete(inodev, old_ino, old_dev);
71610 +
71611 + if (unlikely(matchn != NULL))
71612 + do_handle_create(matchn, old_dentry, mnt);
71613 +
71614 + if (unlikely(matchn2 != NULL))
71615 + do_handle_create(matchn2, new_dentry, mnt);
71616 +
71617 + write_unlock(&gr_inode_lock);
71618 + preempt_enable();
71619 +
71620 + return;
71621 +}
71622 +
71623 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71624 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71625 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71626 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71627 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71628 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71629 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71630 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71631 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71632 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71633 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71634 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71635 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71636 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71637 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71638 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71639 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71640 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71641 +};
71642 +
71643 +void
71644 +gr_learn_resource(const struct task_struct *task,
71645 + const int res, const unsigned long wanted, const int gt)
71646 +{
71647 + struct acl_subject_label *acl;
71648 + const struct cred *cred;
71649 +
71650 + if (unlikely((gr_status & GR_READY) &&
71651 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71652 + goto skip_reslog;
71653 +
71654 + gr_log_resource(task, res, wanted, gt);
71655 +skip_reslog:
71656 +
71657 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71658 + return;
71659 +
71660 + acl = task->acl;
71661 +
71662 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71663 + !(acl->resmask & (1U << (unsigned short) res))))
71664 + return;
71665 +
71666 + if (wanted >= acl->res[res].rlim_cur) {
71667 + unsigned long res_add;
71668 +
71669 + res_add = wanted + res_learn_bumps[res];
71670 +
71671 + acl->res[res].rlim_cur = res_add;
71672 +
71673 + if (wanted > acl->res[res].rlim_max)
71674 + acl->res[res].rlim_max = res_add;
71675 +
71676 + /* only log the subject filename, since resource logging is supported for
71677 + single-subject learning only */
71678 + rcu_read_lock();
71679 + cred = __task_cred(task);
71680 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71681 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71682 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71683 + "", (unsigned long) res, &task->signal->saved_ip);
71684 + rcu_read_unlock();
71685 + }
71686 +
71687 + return;
71688 +}
71689 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71690 +#endif
71691 +
71692 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71693 +void
71694 +pax_set_initial_flags(struct linux_binprm *bprm)
71695 +{
71696 + struct task_struct *task = current;
71697 + struct acl_subject_label *proc;
71698 + unsigned long flags;
71699 +
71700 + if (unlikely(!(gr_status & GR_READY)))
71701 + return;
71702 +
71703 + flags = pax_get_flags(task);
71704 +
71705 + proc = task->acl;
71706 +
71707 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71708 + flags &= ~MF_PAX_PAGEEXEC;
71709 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71710 + flags &= ~MF_PAX_SEGMEXEC;
71711 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71712 + flags &= ~MF_PAX_RANDMMAP;
71713 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71714 + flags &= ~MF_PAX_EMUTRAMP;
71715 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71716 + flags &= ~MF_PAX_MPROTECT;
71717 +
71718 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71719 + flags |= MF_PAX_PAGEEXEC;
71720 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71721 + flags |= MF_PAX_SEGMEXEC;
71722 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71723 + flags |= MF_PAX_RANDMMAP;
71724 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71725 + flags |= MF_PAX_EMUTRAMP;
71726 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71727 + flags |= MF_PAX_MPROTECT;
71728 +
71729 + pax_set_flags(task, flags);
71730 +
71731 + return;
71732 +}
71733 +#endif
71734 +
71735 +int
71736 +gr_handle_proc_ptrace(struct task_struct *task)
71737 +{
71738 + struct file *filp;
71739 + struct task_struct *tmp = task;
71740 + struct task_struct *curtemp = current;
71741 + __u32 retmode;
71742 +
71743 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71744 + if (unlikely(!(gr_status & GR_READY)))
71745 + return 0;
71746 +#endif
71747 +
71748 + read_lock(&tasklist_lock);
71749 + read_lock(&grsec_exec_file_lock);
71750 + filp = task->exec_file;
71751 +
71752 + while (task_pid_nr(tmp) > 0) {
71753 + if (tmp == curtemp)
71754 + break;
71755 + tmp = tmp->real_parent;
71756 + }
71757 +
71758 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71759 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71760 + read_unlock(&grsec_exec_file_lock);
71761 + read_unlock(&tasklist_lock);
71762 + return 1;
71763 + }
71764 +
71765 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71766 + if (!(gr_status & GR_READY)) {
71767 + read_unlock(&grsec_exec_file_lock);
71768 + read_unlock(&tasklist_lock);
71769 + return 0;
71770 + }
71771 +#endif
71772 +
71773 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71774 + read_unlock(&grsec_exec_file_lock);
71775 + read_unlock(&tasklist_lock);
71776 +
71777 + if (retmode & GR_NOPTRACE)
71778 + return 1;
71779 +
71780 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71781 + && (current->acl != task->acl || (current->acl != current->role->root_label
71782 + && task_pid_nr(current) != task_pid_nr(task))))
71783 + return 1;
71784 +
71785 + return 0;
71786 +}
71787 +
71788 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71789 +{
71790 + if (unlikely(!(gr_status & GR_READY)))
71791 + return;
71792 +
71793 + if (!(current->role->roletype & GR_ROLE_GOD))
71794 + return;
71795 +
71796 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71797 + p->role->rolename, gr_task_roletype_to_char(p),
71798 + p->acl->filename);
71799 +}
71800 +
71801 +int
71802 +gr_handle_ptrace(struct task_struct *task, const long request)
71803 +{
71804 + struct task_struct *tmp = task;
71805 + struct task_struct *curtemp = current;
71806 + __u32 retmode;
71807 +
71808 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71809 + if (unlikely(!(gr_status & GR_READY)))
71810 + return 0;
71811 +#endif
71812 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71813 + read_lock(&tasklist_lock);
71814 + while (task_pid_nr(tmp) > 0) {
71815 + if (tmp == curtemp)
71816 + break;
71817 + tmp = tmp->real_parent;
71818 + }
71819 +
71820 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71821 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71822 + read_unlock(&tasklist_lock);
71823 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71824 + return 1;
71825 + }
71826 + read_unlock(&tasklist_lock);
71827 + }
71828 +
71829 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71830 + if (!(gr_status & GR_READY))
71831 + return 0;
71832 +#endif
71833 +
71834 + read_lock(&grsec_exec_file_lock);
71835 + if (unlikely(!task->exec_file)) {
71836 + read_unlock(&grsec_exec_file_lock);
71837 + return 0;
71838 + }
71839 +
71840 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71841 + read_unlock(&grsec_exec_file_lock);
71842 +
71843 + if (retmode & GR_NOPTRACE) {
71844 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71845 + return 1;
71846 + }
71847 +
71848 + if (retmode & GR_PTRACERD) {
71849 + switch (request) {
71850 + case PTRACE_SEIZE:
71851 + case PTRACE_POKETEXT:
71852 + case PTRACE_POKEDATA:
71853 + case PTRACE_POKEUSR:
71854 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71855 + case PTRACE_SETREGS:
71856 + case PTRACE_SETFPREGS:
71857 +#endif
71858 +#ifdef CONFIG_X86
71859 + case PTRACE_SETFPXREGS:
71860 +#endif
71861 +#ifdef CONFIG_ALTIVEC
71862 + case PTRACE_SETVRREGS:
71863 +#endif
71864 + return 1;
71865 + default:
71866 + return 0;
71867 + }
71868 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71869 + !(current->role->roletype & GR_ROLE_GOD) &&
71870 + (current->acl != task->acl)) {
71871 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71872 + return 1;
71873 + }
71874 +
71875 + return 0;
71876 +}
71877 +
71878 +static int is_writable_mmap(const struct file *filp)
71879 +{
71880 + struct task_struct *task = current;
71881 + struct acl_object_label *obj, *obj2;
71882 +
71883 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71884 + !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))) {
71885 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71886 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71887 + task->role->root_label);
71888 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71889 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71890 + return 1;
71891 + }
71892 + }
71893 + return 0;
71894 +}
71895 +
71896 +int
71897 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71898 +{
71899 + __u32 mode;
71900 +
71901 + if (unlikely(!file || !(prot & PROT_EXEC)))
71902 + return 1;
71903 +
71904 + if (is_writable_mmap(file))
71905 + return 0;
71906 +
71907 + mode =
71908 + gr_search_file(file->f_path.dentry,
71909 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71910 + file->f_path.mnt);
71911 +
71912 + if (!gr_tpe_allow(file))
71913 + return 0;
71914 +
71915 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71916 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71917 + return 0;
71918 + } else if (unlikely(!(mode & GR_EXEC))) {
71919 + return 0;
71920 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71921 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71922 + return 1;
71923 + }
71924 +
71925 + return 1;
71926 +}
71927 +
71928 +int
71929 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71930 +{
71931 + __u32 mode;
71932 +
71933 + if (unlikely(!file || !(prot & PROT_EXEC)))
71934 + return 1;
71935 +
71936 + if (is_writable_mmap(file))
71937 + return 0;
71938 +
71939 + mode =
71940 + gr_search_file(file->f_path.dentry,
71941 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71942 + file->f_path.mnt);
71943 +
71944 + if (!gr_tpe_allow(file))
71945 + return 0;
71946 +
71947 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71948 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71949 + return 0;
71950 + } else if (unlikely(!(mode & GR_EXEC))) {
71951 + return 0;
71952 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71953 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71954 + return 1;
71955 + }
71956 +
71957 + return 1;
71958 +}
71959 +
71960 +void
71961 +gr_acl_handle_psacct(struct task_struct *task, const long code)
71962 +{
71963 + unsigned long runtime, cputime;
71964 + cputime_t utime, stime;
71965 + unsigned int wday, cday;
71966 + __u8 whr, chr;
71967 + __u8 wmin, cmin;
71968 + __u8 wsec, csec;
71969 + struct timespec curtime, starttime;
71970 +
71971 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
71972 + !(task->acl->mode & GR_PROCACCT)))
71973 + return;
71974 +
71975 + curtime = ns_to_timespec(ktime_get_ns());
71976 + starttime = ns_to_timespec(task->start_time);
71977 + runtime = curtime.tv_sec - starttime.tv_sec;
71978 + wday = runtime / (60 * 60 * 24);
71979 + runtime -= wday * (60 * 60 * 24);
71980 + whr = runtime / (60 * 60);
71981 + runtime -= whr * (60 * 60);
71982 + wmin = runtime / 60;
71983 + runtime -= wmin * 60;
71984 + wsec = runtime;
71985 +
71986 + task_cputime(task, &utime, &stime);
71987 + cputime = cputime_to_secs(utime + stime);
71988 + cday = cputime / (60 * 60 * 24);
71989 + cputime -= cday * (60 * 60 * 24);
71990 + chr = cputime / (60 * 60);
71991 + cputime -= chr * (60 * 60);
71992 + cmin = cputime / 60;
71993 + cputime -= cmin * 60;
71994 + csec = cputime;
71995 +
71996 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
71997 +
71998 + return;
71999 +}
72000 +
72001 +#ifdef CONFIG_TASKSTATS
72002 +int gr_is_taskstats_denied(int pid)
72003 +{
72004 + struct task_struct *task;
72005 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72006 + const struct cred *cred;
72007 +#endif
72008 + int ret = 0;
72009 +
72010 + /* restrict taskstats viewing to un-chrooted root users
72011 + who have the 'view' subject flag if the RBAC system is enabled
72012 + */
72013 +
72014 + rcu_read_lock();
72015 + read_lock(&tasklist_lock);
72016 + task = find_task_by_vpid(pid);
72017 + if (task) {
72018 +#ifdef CONFIG_GRKERNSEC_CHROOT
72019 + if (proc_is_chrooted(task))
72020 + ret = -EACCES;
72021 +#endif
72022 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72023 + cred = __task_cred(task);
72024 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72025 + if (gr_is_global_nonroot(cred->uid))
72026 + ret = -EACCES;
72027 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72028 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72029 + ret = -EACCES;
72030 +#endif
72031 +#endif
72032 + if (gr_status & GR_READY) {
72033 + if (!(task->acl->mode & GR_VIEW))
72034 + ret = -EACCES;
72035 + }
72036 + } else
72037 + ret = -ENOENT;
72038 +
72039 + read_unlock(&tasklist_lock);
72040 + rcu_read_unlock();
72041 +
72042 + return ret;
72043 +}
72044 +#endif
72045 +
72046 +/* AUXV entries are filled via a descendant of search_binary_handler
72047 + after we've already applied the subject for the target
72048 +*/
72049 +int gr_acl_enable_at_secure(void)
72050 +{
72051 + if (unlikely(!(gr_status & GR_READY)))
72052 + return 0;
72053 +
72054 + if (current->acl->mode & GR_ATSECURE)
72055 + return 1;
72056 +
72057 + return 0;
72058 +}
72059 +
72060 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72061 +{
72062 + struct task_struct *task = current;
72063 + struct dentry *dentry = file->f_path.dentry;
72064 + struct vfsmount *mnt = file->f_path.mnt;
72065 + struct acl_object_label *obj, *tmp;
72066 + struct acl_subject_label *subj;
72067 + unsigned int bufsize;
72068 + int is_not_root;
72069 + char *path;
72070 + dev_t dev = __get_dev(dentry);
72071 +
72072 + if (unlikely(!(gr_status & GR_READY)))
72073 + return 1;
72074 +
72075 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72076 + return 1;
72077 +
72078 + /* ignore Eric Biederman */
72079 + if (IS_PRIVATE(dentry->d_inode))
72080 + return 1;
72081 +
72082 + subj = task->acl;
72083 + read_lock(&gr_inode_lock);
72084 + do {
72085 + obj = lookup_acl_obj_label(ino, dev, subj);
72086 + if (obj != NULL) {
72087 + read_unlock(&gr_inode_lock);
72088 + return (obj->mode & GR_FIND) ? 1 : 0;
72089 + }
72090 + } while ((subj = subj->parent_subject));
72091 + read_unlock(&gr_inode_lock);
72092 +
72093 + /* this is purely an optimization since we're looking for an object
72094 + for the directory we're doing a readdir on
72095 + if it's possible for any globbed object to match the entry we're
72096 + filling into the directory, then the object we find here will be
72097 + an anchor point with attached globbed objects
72098 + */
72099 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72100 + if (obj->globbed == NULL)
72101 + return (obj->mode & GR_FIND) ? 1 : 0;
72102 +
72103 + is_not_root = ((obj->filename[0] == '/') &&
72104 + (obj->filename[1] == '\0')) ? 0 : 1;
72105 + bufsize = PAGE_SIZE - namelen - is_not_root;
72106 +
72107 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72108 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72109 + return 1;
72110 +
72111 + preempt_disable();
72112 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72113 + bufsize);
72114 +
72115 + bufsize = strlen(path);
72116 +
72117 + /* if base is "/", don't append an additional slash */
72118 + if (is_not_root)
72119 + *(path + bufsize) = '/';
72120 + memcpy(path + bufsize + is_not_root, name, namelen);
72121 + *(path + bufsize + namelen + is_not_root) = '\0';
72122 +
72123 + tmp = obj->globbed;
72124 + while (tmp) {
72125 + if (!glob_match(tmp->filename, path)) {
72126 + preempt_enable();
72127 + return (tmp->mode & GR_FIND) ? 1 : 0;
72128 + }
72129 + tmp = tmp->next;
72130 + }
72131 + preempt_enable();
72132 + return (obj->mode & GR_FIND) ? 1 : 0;
72133 +}
72134 +
72135 +void gr_put_exec_file(struct task_struct *task)
72136 +{
72137 + struct file *filp;
72138 +
72139 + write_lock(&grsec_exec_file_lock);
72140 + filp = task->exec_file;
72141 + task->exec_file = NULL;
72142 + write_unlock(&grsec_exec_file_lock);
72143 +
72144 + if (filp)
72145 + fput(filp);
72146 +
72147 + return;
72148 +}
72149 +
72150 +
72151 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72152 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72153 +#endif
72154 +#ifdef CONFIG_SECURITY
72155 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72156 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72157 +#endif
72158 +
72159 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72160 new file mode 100644
72161 index 0000000..18ffbbd
72162 --- /dev/null
72163 +++ b/grsecurity/gracl_alloc.c
72164 @@ -0,0 +1,105 @@
72165 +#include <linux/kernel.h>
72166 +#include <linux/mm.h>
72167 +#include <linux/slab.h>
72168 +#include <linux/vmalloc.h>
72169 +#include <linux/gracl.h>
72170 +#include <linux/grsecurity.h>
72171 +
72172 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72173 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72174 +
72175 +static __inline__ int
72176 +alloc_pop(void)
72177 +{
72178 + if (current_alloc_state->alloc_stack_next == 1)
72179 + return 0;
72180 +
72181 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72182 +
72183 + current_alloc_state->alloc_stack_next--;
72184 +
72185 + return 1;
72186 +}
72187 +
72188 +static __inline__ int
72189 +alloc_push(void *buf)
72190 +{
72191 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72192 + return 1;
72193 +
72194 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72195 +
72196 + current_alloc_state->alloc_stack_next++;
72197 +
72198 + return 0;
72199 +}
72200 +
72201 +void *
72202 +acl_alloc(unsigned long len)
72203 +{
72204 + void *ret = NULL;
72205 +
72206 + if (!len || len > PAGE_SIZE)
72207 + goto out;
72208 +
72209 + ret = kmalloc(len, GFP_KERNEL);
72210 +
72211 + if (ret) {
72212 + if (alloc_push(ret)) {
72213 + kfree(ret);
72214 + ret = NULL;
72215 + }
72216 + }
72217 +
72218 +out:
72219 + return ret;
72220 +}
72221 +
72222 +void *
72223 +acl_alloc_num(unsigned long num, unsigned long len)
72224 +{
72225 + if (!len || (num > (PAGE_SIZE / len)))
72226 + return NULL;
72227 +
72228 + return acl_alloc(num * len);
72229 +}
72230 +
72231 +void
72232 +acl_free_all(void)
72233 +{
72234 + if (!current_alloc_state->alloc_stack)
72235 + return;
72236 +
72237 + while (alloc_pop()) ;
72238 +
72239 + if (current_alloc_state->alloc_stack) {
72240 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72241 + kfree(current_alloc_state->alloc_stack);
72242 + else
72243 + vfree(current_alloc_state->alloc_stack);
72244 + }
72245 +
72246 + current_alloc_state->alloc_stack = NULL;
72247 + current_alloc_state->alloc_stack_size = 1;
72248 + current_alloc_state->alloc_stack_next = 1;
72249 +
72250 + return;
72251 +}
72252 +
72253 +int
72254 +acl_alloc_stack_init(unsigned long size)
72255 +{
72256 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72257 + current_alloc_state->alloc_stack =
72258 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72259 + else
72260 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72261 +
72262 + current_alloc_state->alloc_stack_size = size;
72263 + current_alloc_state->alloc_stack_next = 1;
72264 +
72265 + if (!current_alloc_state->alloc_stack)
72266 + return 0;
72267 + else
72268 + return 1;
72269 +}
72270 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72271 new file mode 100644
72272 index 0000000..1a94c11
72273 --- /dev/null
72274 +++ b/grsecurity/gracl_cap.c
72275 @@ -0,0 +1,127 @@
72276 +#include <linux/kernel.h>
72277 +#include <linux/module.h>
72278 +#include <linux/sched.h>
72279 +#include <linux/gracl.h>
72280 +#include <linux/grsecurity.h>
72281 +#include <linux/grinternal.h>
72282 +
72283 +extern const char *captab_log[];
72284 +extern int captab_log_entries;
72285 +
72286 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72287 +{
72288 + struct acl_subject_label *curracl;
72289 +
72290 + if (!gr_acl_is_enabled())
72291 + return 1;
72292 +
72293 + curracl = task->acl;
72294 +
72295 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72296 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72297 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72298 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72299 + gr_to_filename(task->exec_file->f_path.dentry,
72300 + task->exec_file->f_path.mnt) : curracl->filename,
72301 + curracl->filename, 0UL,
72302 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72303 + return 1;
72304 + }
72305 +
72306 + return 0;
72307 +}
72308 +
72309 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72310 +{
72311 + struct acl_subject_label *curracl;
72312 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72313 + kernel_cap_t cap_audit = __cap_empty_set;
72314 +
72315 + if (!gr_acl_is_enabled())
72316 + return 1;
72317 +
72318 + curracl = task->acl;
72319 +
72320 + cap_drop = curracl->cap_lower;
72321 + cap_mask = curracl->cap_mask;
72322 + cap_audit = curracl->cap_invert_audit;
72323 +
72324 + while ((curracl = curracl->parent_subject)) {
72325 + /* if the cap isn't specified in the current computed mask but is specified in the
72326 + current level subject, and is lowered in the current level subject, then add
72327 + it to the set of dropped capabilities
72328 + otherwise, add the current level subject's mask to the current computed mask
72329 + */
72330 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72331 + cap_raise(cap_mask, cap);
72332 + if (cap_raised(curracl->cap_lower, cap))
72333 + cap_raise(cap_drop, cap);
72334 + if (cap_raised(curracl->cap_invert_audit, cap))
72335 + cap_raise(cap_audit, cap);
72336 + }
72337 + }
72338 +
72339 + if (!cap_raised(cap_drop, cap)) {
72340 + if (cap_raised(cap_audit, cap))
72341 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72342 + return 1;
72343 + }
72344 +
72345 + /* only learn the capability use if the process has the capability in the
72346 + general case, the two uses in sys.c of gr_learn_cap are an exception
72347 + to this rule to ensure any role transition involves what the full-learned
72348 + policy believes in a privileged process
72349 + */
72350 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72351 + return 1;
72352 +
72353 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72354 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72355 +
72356 + return 0;
72357 +}
72358 +
72359 +int
72360 +gr_acl_is_capable(const int cap)
72361 +{
72362 + return gr_task_acl_is_capable(current, current_cred(), cap);
72363 +}
72364 +
72365 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72366 +{
72367 + struct acl_subject_label *curracl;
72368 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72369 +
72370 + if (!gr_acl_is_enabled())
72371 + return 1;
72372 +
72373 + curracl = task->acl;
72374 +
72375 + cap_drop = curracl->cap_lower;
72376 + cap_mask = curracl->cap_mask;
72377 +
72378 + while ((curracl = curracl->parent_subject)) {
72379 + /* if the cap isn't specified in the current computed mask but is specified in the
72380 + current level subject, and is lowered in the current level subject, then add
72381 + it to the set of dropped capabilities
72382 + otherwise, add the current level subject's mask to the current computed mask
72383 + */
72384 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72385 + cap_raise(cap_mask, cap);
72386 + if (cap_raised(curracl->cap_lower, cap))
72387 + cap_raise(cap_drop, cap);
72388 + }
72389 + }
72390 +
72391 + if (!cap_raised(cap_drop, cap))
72392 + return 1;
72393 +
72394 + return 0;
72395 +}
72396 +
72397 +int
72398 +gr_acl_is_capable_nolog(const int cap)
72399 +{
72400 + return gr_task_acl_is_capable_nolog(current, cap);
72401 +}
72402 +
72403 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72404 new file mode 100644
72405 index 0000000..ca25605
72406 --- /dev/null
72407 +++ b/grsecurity/gracl_compat.c
72408 @@ -0,0 +1,270 @@
72409 +#include <linux/kernel.h>
72410 +#include <linux/gracl.h>
72411 +#include <linux/compat.h>
72412 +#include <linux/gracl_compat.h>
72413 +
72414 +#include <asm/uaccess.h>
72415 +
72416 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72417 +{
72418 + struct gr_arg_wrapper_compat uwrapcompat;
72419 +
72420 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72421 + return -EFAULT;
72422 +
72423 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72424 + (uwrapcompat.version != 0x2901)) ||
72425 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72426 + return -EINVAL;
72427 +
72428 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72429 + uwrap->version = uwrapcompat.version;
72430 + uwrap->size = sizeof(struct gr_arg);
72431 +
72432 + return 0;
72433 +}
72434 +
72435 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72436 +{
72437 + struct gr_arg_compat argcompat;
72438 +
72439 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72440 + return -EFAULT;
72441 +
72442 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72443 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72444 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72445 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72446 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72447 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72448 +
72449 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72450 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72451 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72452 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72453 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72454 + arg->segv_device = argcompat.segv_device;
72455 + arg->segv_inode = argcompat.segv_inode;
72456 + arg->segv_uid = argcompat.segv_uid;
72457 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72458 + arg->mode = argcompat.mode;
72459 +
72460 + return 0;
72461 +}
72462 +
72463 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72464 +{
72465 + struct acl_object_label_compat objcompat;
72466 +
72467 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72468 + return -EFAULT;
72469 +
72470 + obj->filename = compat_ptr(objcompat.filename);
72471 + obj->inode = objcompat.inode;
72472 + obj->device = objcompat.device;
72473 + obj->mode = objcompat.mode;
72474 +
72475 + obj->nested = compat_ptr(objcompat.nested);
72476 + obj->globbed = compat_ptr(objcompat.globbed);
72477 +
72478 + obj->prev = compat_ptr(objcompat.prev);
72479 + obj->next = compat_ptr(objcompat.next);
72480 +
72481 + return 0;
72482 +}
72483 +
72484 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72485 +{
72486 + unsigned int i;
72487 + struct acl_subject_label_compat subjcompat;
72488 +
72489 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72490 + return -EFAULT;
72491 +
72492 + subj->filename = compat_ptr(subjcompat.filename);
72493 + subj->inode = subjcompat.inode;
72494 + subj->device = subjcompat.device;
72495 + subj->mode = subjcompat.mode;
72496 + subj->cap_mask = subjcompat.cap_mask;
72497 + subj->cap_lower = subjcompat.cap_lower;
72498 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72499 +
72500 + for (i = 0; i < GR_NLIMITS; i++) {
72501 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72502 + subj->res[i].rlim_cur = RLIM_INFINITY;
72503 + else
72504 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72505 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72506 + subj->res[i].rlim_max = RLIM_INFINITY;
72507 + else
72508 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72509 + }
72510 + subj->resmask = subjcompat.resmask;
72511 +
72512 + subj->user_trans_type = subjcompat.user_trans_type;
72513 + subj->group_trans_type = subjcompat.group_trans_type;
72514 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72515 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72516 + subj->user_trans_num = subjcompat.user_trans_num;
72517 + subj->group_trans_num = subjcompat.group_trans_num;
72518 +
72519 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72520 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72521 + subj->ip_type = subjcompat.ip_type;
72522 + subj->ips = compat_ptr(subjcompat.ips);
72523 + subj->ip_num = subjcompat.ip_num;
72524 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72525 +
72526 + subj->crashes = subjcompat.crashes;
72527 + subj->expires = subjcompat.expires;
72528 +
72529 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72530 + subj->hash = compat_ptr(subjcompat.hash);
72531 + subj->prev = compat_ptr(subjcompat.prev);
72532 + subj->next = compat_ptr(subjcompat.next);
72533 +
72534 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72535 + subj->obj_hash_size = subjcompat.obj_hash_size;
72536 + subj->pax_flags = subjcompat.pax_flags;
72537 +
72538 + return 0;
72539 +}
72540 +
72541 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72542 +{
72543 + struct acl_role_label_compat rolecompat;
72544 +
72545 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72546 + return -EFAULT;
72547 +
72548 + role->rolename = compat_ptr(rolecompat.rolename);
72549 + role->uidgid = rolecompat.uidgid;
72550 + role->roletype = rolecompat.roletype;
72551 +
72552 + role->auth_attempts = rolecompat.auth_attempts;
72553 + role->expires = rolecompat.expires;
72554 +
72555 + role->root_label = compat_ptr(rolecompat.root_label);
72556 + role->hash = compat_ptr(rolecompat.hash);
72557 +
72558 + role->prev = compat_ptr(rolecompat.prev);
72559 + role->next = compat_ptr(rolecompat.next);
72560 +
72561 + role->transitions = compat_ptr(rolecompat.transitions);
72562 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72563 + role->domain_children = compat_ptr(rolecompat.domain_children);
72564 + role->domain_child_num = rolecompat.domain_child_num;
72565 +
72566 + role->umask = rolecompat.umask;
72567 +
72568 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72569 + role->subj_hash_size = rolecompat.subj_hash_size;
72570 +
72571 + return 0;
72572 +}
72573 +
72574 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72575 +{
72576 + struct role_allowed_ip_compat roleip_compat;
72577 +
72578 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72579 + return -EFAULT;
72580 +
72581 + roleip->addr = roleip_compat.addr;
72582 + roleip->netmask = roleip_compat.netmask;
72583 +
72584 + roleip->prev = compat_ptr(roleip_compat.prev);
72585 + roleip->next = compat_ptr(roleip_compat.next);
72586 +
72587 + return 0;
72588 +}
72589 +
72590 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72591 +{
72592 + struct role_transition_compat trans_compat;
72593 +
72594 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72595 + return -EFAULT;
72596 +
72597 + trans->rolename = compat_ptr(trans_compat.rolename);
72598 +
72599 + trans->prev = compat_ptr(trans_compat.prev);
72600 + trans->next = compat_ptr(trans_compat.next);
72601 +
72602 + return 0;
72603 +
72604 +}
72605 +
72606 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72607 +{
72608 + struct gr_hash_struct_compat hash_compat;
72609 +
72610 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72611 + return -EFAULT;
72612 +
72613 + hash->table = compat_ptr(hash_compat.table);
72614 + hash->nametable = compat_ptr(hash_compat.nametable);
72615 + hash->first = compat_ptr(hash_compat.first);
72616 +
72617 + hash->table_size = hash_compat.table_size;
72618 + hash->used_size = hash_compat.used_size;
72619 +
72620 + hash->type = hash_compat.type;
72621 +
72622 + return 0;
72623 +}
72624 +
72625 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72626 +{
72627 + compat_uptr_t ptrcompat;
72628 +
72629 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72630 + return -EFAULT;
72631 +
72632 + *(void **)ptr = compat_ptr(ptrcompat);
72633 +
72634 + return 0;
72635 +}
72636 +
72637 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72638 +{
72639 + struct acl_ip_label_compat ip_compat;
72640 +
72641 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72642 + return -EFAULT;
72643 +
72644 + ip->iface = compat_ptr(ip_compat.iface);
72645 + ip->addr = ip_compat.addr;
72646 + ip->netmask = ip_compat.netmask;
72647 + ip->low = ip_compat.low;
72648 + ip->high = ip_compat.high;
72649 + ip->mode = ip_compat.mode;
72650 + ip->type = ip_compat.type;
72651 +
72652 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72653 +
72654 + ip->prev = compat_ptr(ip_compat.prev);
72655 + ip->next = compat_ptr(ip_compat.next);
72656 +
72657 + return 0;
72658 +}
72659 +
72660 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72661 +{
72662 + struct sprole_pw_compat pw_compat;
72663 +
72664 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72665 + return -EFAULT;
72666 +
72667 + pw->rolename = compat_ptr(pw_compat.rolename);
72668 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72669 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72670 +
72671 + return 0;
72672 +}
72673 +
72674 +size_t get_gr_arg_wrapper_size_compat(void)
72675 +{
72676 + return sizeof(struct gr_arg_wrapper_compat);
72677 +}
72678 +
72679 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72680 new file mode 100644
72681 index 0000000..8ee8e4f
72682 --- /dev/null
72683 +++ b/grsecurity/gracl_fs.c
72684 @@ -0,0 +1,447 @@
72685 +#include <linux/kernel.h>
72686 +#include <linux/sched.h>
72687 +#include <linux/types.h>
72688 +#include <linux/fs.h>
72689 +#include <linux/file.h>
72690 +#include <linux/stat.h>
72691 +#include <linux/grsecurity.h>
72692 +#include <linux/grinternal.h>
72693 +#include <linux/gracl.h>
72694 +
72695 +umode_t
72696 +gr_acl_umask(void)
72697 +{
72698 + if (unlikely(!gr_acl_is_enabled()))
72699 + return 0;
72700 +
72701 + return current->role->umask;
72702 +}
72703 +
72704 +__u32
72705 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72706 + const struct vfsmount * mnt)
72707 +{
72708 + __u32 mode;
72709 +
72710 + if (unlikely(d_is_negative(dentry)))
72711 + return GR_FIND;
72712 +
72713 + mode =
72714 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72715 +
72716 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72717 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72718 + return mode;
72719 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72720 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72721 + return 0;
72722 + } else if (unlikely(!(mode & GR_FIND)))
72723 + return 0;
72724 +
72725 + return GR_FIND;
72726 +}
72727 +
72728 +__u32
72729 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72730 + int acc_mode)
72731 +{
72732 + __u32 reqmode = GR_FIND;
72733 + __u32 mode;
72734 +
72735 + if (unlikely(d_is_negative(dentry)))
72736 + return reqmode;
72737 +
72738 + if (acc_mode & MAY_APPEND)
72739 + reqmode |= GR_APPEND;
72740 + else if (acc_mode & MAY_WRITE)
72741 + reqmode |= GR_WRITE;
72742 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72743 + reqmode |= GR_READ;
72744 +
72745 + mode =
72746 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72747 + mnt);
72748 +
72749 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72750 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72751 + reqmode & GR_READ ? " reading" : "",
72752 + reqmode & GR_WRITE ? " writing" : reqmode &
72753 + GR_APPEND ? " appending" : "");
72754 + return reqmode;
72755 + } else
72756 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72757 + {
72758 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72759 + reqmode & GR_READ ? " reading" : "",
72760 + reqmode & GR_WRITE ? " writing" : reqmode &
72761 + GR_APPEND ? " appending" : "");
72762 + return 0;
72763 + } else if (unlikely((mode & reqmode) != reqmode))
72764 + return 0;
72765 +
72766 + return reqmode;
72767 +}
72768 +
72769 +__u32
72770 +gr_acl_handle_creat(const struct dentry * dentry,
72771 + const struct dentry * p_dentry,
72772 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72773 + const int imode)
72774 +{
72775 + __u32 reqmode = GR_WRITE | GR_CREATE;
72776 + __u32 mode;
72777 +
72778 + if (acc_mode & MAY_APPEND)
72779 + reqmode |= GR_APPEND;
72780 + // if a directory was required or the directory already exists, then
72781 + // don't count this open as a read
72782 + if ((acc_mode & MAY_READ) &&
72783 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72784 + reqmode |= GR_READ;
72785 + if ((open_flags & O_CREAT) &&
72786 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72787 + reqmode |= GR_SETID;
72788 +
72789 + mode =
72790 + gr_check_create(dentry, p_dentry, p_mnt,
72791 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72792 +
72793 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72794 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72795 + reqmode & GR_READ ? " reading" : "",
72796 + reqmode & GR_WRITE ? " writing" : reqmode &
72797 + GR_APPEND ? " appending" : "");
72798 + return reqmode;
72799 + } else
72800 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72801 + {
72802 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72803 + reqmode & GR_READ ? " reading" : "",
72804 + reqmode & GR_WRITE ? " writing" : reqmode &
72805 + GR_APPEND ? " appending" : "");
72806 + return 0;
72807 + } else if (unlikely((mode & reqmode) != reqmode))
72808 + return 0;
72809 +
72810 + return reqmode;
72811 +}
72812 +
72813 +__u32
72814 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72815 + const int fmode)
72816 +{
72817 + __u32 mode, reqmode = GR_FIND;
72818 +
72819 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72820 + reqmode |= GR_EXEC;
72821 + if (fmode & S_IWOTH)
72822 + reqmode |= GR_WRITE;
72823 + if (fmode & S_IROTH)
72824 + reqmode |= GR_READ;
72825 +
72826 + mode =
72827 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72828 + mnt);
72829 +
72830 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72831 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72832 + reqmode & GR_READ ? " reading" : "",
72833 + reqmode & GR_WRITE ? " writing" : "",
72834 + reqmode & GR_EXEC ? " executing" : "");
72835 + return reqmode;
72836 + } else
72837 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72838 + {
72839 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72840 + reqmode & GR_READ ? " reading" : "",
72841 + reqmode & GR_WRITE ? " writing" : "",
72842 + reqmode & GR_EXEC ? " executing" : "");
72843 + return 0;
72844 + } else if (unlikely((mode & reqmode) != reqmode))
72845 + return 0;
72846 +
72847 + return reqmode;
72848 +}
72849 +
72850 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72851 +{
72852 + __u32 mode;
72853 +
72854 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72855 +
72856 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72857 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72858 + return mode;
72859 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72860 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72861 + return 0;
72862 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72863 + return 0;
72864 +
72865 + return (reqmode);
72866 +}
72867 +
72868 +__u32
72869 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72870 +{
72871 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72872 +}
72873 +
72874 +__u32
72875 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72876 +{
72877 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72878 +}
72879 +
72880 +__u32
72881 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72882 +{
72883 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72884 +}
72885 +
72886 +__u32
72887 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72888 +{
72889 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72890 +}
72891 +
72892 +__u32
72893 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72894 + umode_t *modeptr)
72895 +{
72896 + umode_t mode;
72897 +
72898 + *modeptr &= ~gr_acl_umask();
72899 + mode = *modeptr;
72900 +
72901 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72902 + return 1;
72903 +
72904 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72905 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72906 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72907 + GR_CHMOD_ACL_MSG);
72908 + } else {
72909 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72910 + }
72911 +}
72912 +
72913 +__u32
72914 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72915 +{
72916 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72917 +}
72918 +
72919 +__u32
72920 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72921 +{
72922 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72923 +}
72924 +
72925 +__u32
72926 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72927 +{
72928 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72929 +}
72930 +
72931 +__u32
72932 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72933 +{
72934 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72935 +}
72936 +
72937 +__u32
72938 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72939 +{
72940 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72941 + GR_UNIXCONNECT_ACL_MSG);
72942 +}
72943 +
72944 +/* hardlinks require at minimum create and link permission,
72945 + any additional privilege required is based on the
72946 + privilege of the file being linked to
72947 +*/
72948 +__u32
72949 +gr_acl_handle_link(const struct dentry * new_dentry,
72950 + const struct dentry * parent_dentry,
72951 + const struct vfsmount * parent_mnt,
72952 + const struct dentry * old_dentry,
72953 + const struct vfsmount * old_mnt, const struct filename *to)
72954 +{
72955 + __u32 mode;
72956 + __u32 needmode = GR_CREATE | GR_LINK;
72957 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
72958 +
72959 + mode =
72960 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
72961 + old_mnt);
72962 +
72963 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
72964 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72965 + return mode;
72966 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72967 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72968 + return 0;
72969 + } else if (unlikely((mode & needmode) != needmode))
72970 + return 0;
72971 +
72972 + return 1;
72973 +}
72974 +
72975 +__u32
72976 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72977 + const struct dentry * parent_dentry,
72978 + const struct vfsmount * parent_mnt, const struct filename *from)
72979 +{
72980 + __u32 needmode = GR_WRITE | GR_CREATE;
72981 + __u32 mode;
72982 +
72983 + mode =
72984 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
72985 + GR_CREATE | GR_AUDIT_CREATE |
72986 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
72987 +
72988 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
72989 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72990 + return mode;
72991 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72992 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72993 + return 0;
72994 + } else if (unlikely((mode & needmode) != needmode))
72995 + return 0;
72996 +
72997 + return (GR_WRITE | GR_CREATE);
72998 +}
72999 +
73000 +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)
73001 +{
73002 + __u32 mode;
73003 +
73004 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73005 +
73006 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73007 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73008 + return mode;
73009 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73010 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73011 + return 0;
73012 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73013 + return 0;
73014 +
73015 + return (reqmode);
73016 +}
73017 +
73018 +__u32
73019 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73020 + const struct dentry * parent_dentry,
73021 + const struct vfsmount * parent_mnt,
73022 + const int mode)
73023 +{
73024 + __u32 reqmode = GR_WRITE | GR_CREATE;
73025 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73026 + reqmode |= GR_SETID;
73027 +
73028 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73029 + reqmode, GR_MKNOD_ACL_MSG);
73030 +}
73031 +
73032 +__u32
73033 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73034 + const struct dentry *parent_dentry,
73035 + const struct vfsmount *parent_mnt)
73036 +{
73037 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73038 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73039 +}
73040 +
73041 +#define RENAME_CHECK_SUCCESS(old, new) \
73042 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73043 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73044 +
73045 +int
73046 +gr_acl_handle_rename(struct dentry *new_dentry,
73047 + struct dentry *parent_dentry,
73048 + const struct vfsmount *parent_mnt,
73049 + struct dentry *old_dentry,
73050 + struct inode *old_parent_inode,
73051 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73052 +{
73053 + __u32 comp1, comp2;
73054 + int error = 0;
73055 +
73056 + if (unlikely(!gr_acl_is_enabled()))
73057 + return 0;
73058 +
73059 + if (flags & RENAME_EXCHANGE) {
73060 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73061 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73062 + GR_SUPPRESS, parent_mnt);
73063 + comp2 =
73064 + gr_search_file(old_dentry,
73065 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73066 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73067 + } else if (d_is_negative(new_dentry)) {
73068 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73069 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73070 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73071 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73072 + GR_DELETE | GR_AUDIT_DELETE |
73073 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73074 + GR_SUPPRESS, old_mnt);
73075 + } else {
73076 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73077 + GR_CREATE | GR_DELETE |
73078 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73079 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73080 + GR_SUPPRESS, parent_mnt);
73081 + comp2 =
73082 + gr_search_file(old_dentry,
73083 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73084 + GR_DELETE | GR_AUDIT_DELETE |
73085 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73086 + }
73087 +
73088 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73089 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73090 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73091 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73092 + && !(comp2 & GR_SUPPRESS)) {
73093 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73094 + error = -EACCES;
73095 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73096 + error = -EACCES;
73097 +
73098 + return error;
73099 +}
73100 +
73101 +void
73102 +gr_acl_handle_exit(void)
73103 +{
73104 + u16 id;
73105 + char *rolename;
73106 +
73107 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73108 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73109 + id = current->acl_role_id;
73110 + rolename = current->role->rolename;
73111 + gr_set_acls(1);
73112 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73113 + }
73114 +
73115 + gr_put_exec_file(current);
73116 + return;
73117 +}
73118 +
73119 +int
73120 +gr_acl_handle_procpidmem(const struct task_struct *task)
73121 +{
73122 + if (unlikely(!gr_acl_is_enabled()))
73123 + return 0;
73124 +
73125 + if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
73126 + !(current->acl->mode & GR_POVERRIDE) &&
73127 + !(current->role->roletype & GR_ROLE_GOD))
73128 + return -EACCES;
73129 +
73130 + return 0;
73131 +}
73132 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73133 new file mode 100644
73134 index 0000000..f056b81
73135 --- /dev/null
73136 +++ b/grsecurity/gracl_ip.c
73137 @@ -0,0 +1,386 @@
73138 +#include <linux/kernel.h>
73139 +#include <asm/uaccess.h>
73140 +#include <asm/errno.h>
73141 +#include <net/sock.h>
73142 +#include <linux/file.h>
73143 +#include <linux/fs.h>
73144 +#include <linux/net.h>
73145 +#include <linux/in.h>
73146 +#include <linux/skbuff.h>
73147 +#include <linux/ip.h>
73148 +#include <linux/udp.h>
73149 +#include <linux/types.h>
73150 +#include <linux/sched.h>
73151 +#include <linux/netdevice.h>
73152 +#include <linux/inetdevice.h>
73153 +#include <linux/gracl.h>
73154 +#include <linux/grsecurity.h>
73155 +#include <linux/grinternal.h>
73156 +
73157 +#define GR_BIND 0x01
73158 +#define GR_CONNECT 0x02
73159 +#define GR_INVERT 0x04
73160 +#define GR_BINDOVERRIDE 0x08
73161 +#define GR_CONNECTOVERRIDE 0x10
73162 +#define GR_SOCK_FAMILY 0x20
73163 +
73164 +static const char * gr_protocols[IPPROTO_MAX] = {
73165 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73166 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73167 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73168 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73169 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73170 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73171 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73172 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73173 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73174 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73175 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73176 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73177 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73178 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73179 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73180 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73181 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73182 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73183 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73184 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73185 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73186 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73187 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73188 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73189 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73190 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73191 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73192 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73193 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73194 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73195 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73196 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73197 + };
73198 +
73199 +static const char * gr_socktypes[SOCK_MAX] = {
73200 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73201 + "unknown:7", "unknown:8", "unknown:9", "packet"
73202 + };
73203 +
73204 +static const char * gr_sockfamilies[AF_MAX+1] = {
73205 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73206 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73207 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73208 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73209 + };
73210 +
73211 +const char *
73212 +gr_proto_to_name(unsigned char proto)
73213 +{
73214 + return gr_protocols[proto];
73215 +}
73216 +
73217 +const char *
73218 +gr_socktype_to_name(unsigned char type)
73219 +{
73220 + return gr_socktypes[type];
73221 +}
73222 +
73223 +const char *
73224 +gr_sockfamily_to_name(unsigned char family)
73225 +{
73226 + return gr_sockfamilies[family];
73227 +}
73228 +
73229 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73230 +
73231 +int
73232 +gr_search_socket(const int domain, const int type, const int protocol)
73233 +{
73234 + struct acl_subject_label *curr;
73235 + const struct cred *cred = current_cred();
73236 +
73237 + if (unlikely(!gr_acl_is_enabled()))
73238 + goto exit;
73239 +
73240 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73241 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73242 + goto exit; // let the kernel handle it
73243 +
73244 + curr = current->acl;
73245 +
73246 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73247 + /* the family is allowed, if this is PF_INET allow it only if
73248 + the extra sock type/protocol checks pass */
73249 + if (domain == PF_INET)
73250 + goto inet_check;
73251 + goto exit;
73252 + } else {
73253 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73254 + __u32 fakeip = 0;
73255 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73256 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73257 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73258 + gr_to_filename(current->exec_file->f_path.dentry,
73259 + current->exec_file->f_path.mnt) :
73260 + curr->filename, curr->filename,
73261 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73262 + &current->signal->saved_ip);
73263 + goto exit;
73264 + }
73265 + goto exit_fail;
73266 + }
73267 +
73268 +inet_check:
73269 + /* the rest of this checking is for IPv4 only */
73270 + if (!curr->ips)
73271 + goto exit;
73272 +
73273 + if ((curr->ip_type & (1U << type)) &&
73274 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73275 + goto exit;
73276 +
73277 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73278 + /* we don't place acls on raw sockets , and sometimes
73279 + dgram/ip sockets are opened for ioctl and not
73280 + bind/connect, so we'll fake a bind learn log */
73281 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73282 + __u32 fakeip = 0;
73283 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73284 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73285 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73286 + gr_to_filename(current->exec_file->f_path.dentry,
73287 + current->exec_file->f_path.mnt) :
73288 + curr->filename, curr->filename,
73289 + &fakeip, 0, type,
73290 + protocol, GR_CONNECT, &current->signal->saved_ip);
73291 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73292 + __u32 fakeip = 0;
73293 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73294 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73295 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73296 + gr_to_filename(current->exec_file->f_path.dentry,
73297 + current->exec_file->f_path.mnt) :
73298 + curr->filename, curr->filename,
73299 + &fakeip, 0, type,
73300 + protocol, GR_BIND, &current->signal->saved_ip);
73301 + }
73302 + /* we'll log when they use connect or bind */
73303 + goto exit;
73304 + }
73305 +
73306 +exit_fail:
73307 + if (domain == PF_INET)
73308 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73309 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73310 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73311 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73312 + gr_socktype_to_name(type), protocol);
73313 +
73314 + return 0;
73315 +exit:
73316 + return 1;
73317 +}
73318 +
73319 +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)
73320 +{
73321 + if ((ip->mode & mode) &&
73322 + (ip_port >= ip->low) &&
73323 + (ip_port <= ip->high) &&
73324 + ((ntohl(ip_addr) & our_netmask) ==
73325 + (ntohl(our_addr) & our_netmask))
73326 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73327 + && (ip->type & (1U << type))) {
73328 + if (ip->mode & GR_INVERT)
73329 + return 2; // specifically denied
73330 + else
73331 + return 1; // allowed
73332 + }
73333 +
73334 + return 0; // not specifically allowed, may continue parsing
73335 +}
73336 +
73337 +static int
73338 +gr_search_connectbind(const int full_mode, struct sock *sk,
73339 + struct sockaddr_in *addr, const int type)
73340 +{
73341 + char iface[IFNAMSIZ] = {0};
73342 + struct acl_subject_label *curr;
73343 + struct acl_ip_label *ip;
73344 + struct inet_sock *isk;
73345 + struct net_device *dev;
73346 + struct in_device *idev;
73347 + unsigned long i;
73348 + int ret;
73349 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73350 + __u32 ip_addr = 0;
73351 + __u32 our_addr;
73352 + __u32 our_netmask;
73353 + char *p;
73354 + __u16 ip_port = 0;
73355 + const struct cred *cred = current_cred();
73356 +
73357 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73358 + return 0;
73359 +
73360 + curr = current->acl;
73361 + isk = inet_sk(sk);
73362 +
73363 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73364 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73365 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73366 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73367 + struct sockaddr_in saddr;
73368 + int err;
73369 +
73370 + saddr.sin_family = AF_INET;
73371 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73372 + saddr.sin_port = isk->inet_sport;
73373 +
73374 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73375 + if (err)
73376 + return err;
73377 +
73378 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73379 + if (err)
73380 + return err;
73381 + }
73382 +
73383 + if (!curr->ips)
73384 + return 0;
73385 +
73386 + ip_addr = addr->sin_addr.s_addr;
73387 + ip_port = ntohs(addr->sin_port);
73388 +
73389 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73390 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73391 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73392 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73393 + gr_to_filename(current->exec_file->f_path.dentry,
73394 + current->exec_file->f_path.mnt) :
73395 + curr->filename, curr->filename,
73396 + &ip_addr, ip_port, type,
73397 + sk->sk_protocol, mode, &current->signal->saved_ip);
73398 + return 0;
73399 + }
73400 +
73401 + for (i = 0; i < curr->ip_num; i++) {
73402 + ip = *(curr->ips + i);
73403 + if (ip->iface != NULL) {
73404 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73405 + p = strchr(iface, ':');
73406 + if (p != NULL)
73407 + *p = '\0';
73408 + dev = dev_get_by_name(sock_net(sk), iface);
73409 + if (dev == NULL)
73410 + continue;
73411 + idev = in_dev_get(dev);
73412 + if (idev == NULL) {
73413 + dev_put(dev);
73414 + continue;
73415 + }
73416 + rcu_read_lock();
73417 + for_ifa(idev) {
73418 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73419 + our_addr = ifa->ifa_address;
73420 + our_netmask = 0xffffffff;
73421 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73422 + if (ret == 1) {
73423 + rcu_read_unlock();
73424 + in_dev_put(idev);
73425 + dev_put(dev);
73426 + return 0;
73427 + } else if (ret == 2) {
73428 + rcu_read_unlock();
73429 + in_dev_put(idev);
73430 + dev_put(dev);
73431 + goto denied;
73432 + }
73433 + }
73434 + } endfor_ifa(idev);
73435 + rcu_read_unlock();
73436 + in_dev_put(idev);
73437 + dev_put(dev);
73438 + } else {
73439 + our_addr = ip->addr;
73440 + our_netmask = ip->netmask;
73441 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73442 + if (ret == 1)
73443 + return 0;
73444 + else if (ret == 2)
73445 + goto denied;
73446 + }
73447 + }
73448 +
73449 +denied:
73450 + if (mode == GR_BIND)
73451 + 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));
73452 + else if (mode == GR_CONNECT)
73453 + 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));
73454 +
73455 + return -EACCES;
73456 +}
73457 +
73458 +int
73459 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73460 +{
73461 + /* always allow disconnection of dgram sockets with connect */
73462 + if (addr->sin_family == AF_UNSPEC)
73463 + return 0;
73464 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73465 +}
73466 +
73467 +int
73468 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73469 +{
73470 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73471 +}
73472 +
73473 +int gr_search_listen(struct socket *sock)
73474 +{
73475 + struct sock *sk = sock->sk;
73476 + struct sockaddr_in addr;
73477 +
73478 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73479 + addr.sin_port = inet_sk(sk)->inet_sport;
73480 +
73481 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73482 +}
73483 +
73484 +int gr_search_accept(struct socket *sock)
73485 +{
73486 + struct sock *sk = sock->sk;
73487 + struct sockaddr_in addr;
73488 +
73489 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73490 + addr.sin_port = inet_sk(sk)->inet_sport;
73491 +
73492 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73493 +}
73494 +
73495 +int
73496 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73497 +{
73498 + if (addr)
73499 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73500 + else {
73501 + struct sockaddr_in sin;
73502 + const struct inet_sock *inet = inet_sk(sk);
73503 +
73504 + sin.sin_addr.s_addr = inet->inet_daddr;
73505 + sin.sin_port = inet->inet_dport;
73506 +
73507 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73508 + }
73509 +}
73510 +
73511 +int
73512 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73513 +{
73514 + struct sockaddr_in sin;
73515 +
73516 + if (unlikely(skb->len < sizeof (struct udphdr)))
73517 + return 0; // skip this packet
73518 +
73519 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73520 + sin.sin_port = udp_hdr(skb)->source;
73521 +
73522 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73523 +}
73524 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73525 new file mode 100644
73526 index 0000000..25f54ef
73527 --- /dev/null
73528 +++ b/grsecurity/gracl_learn.c
73529 @@ -0,0 +1,207 @@
73530 +#include <linux/kernel.h>
73531 +#include <linux/mm.h>
73532 +#include <linux/sched.h>
73533 +#include <linux/poll.h>
73534 +#include <linux/string.h>
73535 +#include <linux/file.h>
73536 +#include <linux/types.h>
73537 +#include <linux/vmalloc.h>
73538 +#include <linux/grinternal.h>
73539 +
73540 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73541 + size_t count, loff_t *ppos);
73542 +extern int gr_acl_is_enabled(void);
73543 +
73544 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73545 +static int gr_learn_attached;
73546 +
73547 +/* use a 512k buffer */
73548 +#define LEARN_BUFFER_SIZE (512 * 1024)
73549 +
73550 +static DEFINE_SPINLOCK(gr_learn_lock);
73551 +static DEFINE_MUTEX(gr_learn_user_mutex);
73552 +
73553 +/* we need to maintain two buffers, so that the kernel context of grlearn
73554 + uses a semaphore around the userspace copying, and the other kernel contexts
73555 + use a spinlock when copying into the buffer, since they cannot sleep
73556 +*/
73557 +static char *learn_buffer;
73558 +static char *learn_buffer_user;
73559 +static int learn_buffer_len;
73560 +static int learn_buffer_user_len;
73561 +
73562 +static ssize_t
73563 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73564 +{
73565 + DECLARE_WAITQUEUE(wait, current);
73566 + ssize_t retval = 0;
73567 +
73568 + add_wait_queue(&learn_wait, &wait);
73569 + set_current_state(TASK_INTERRUPTIBLE);
73570 + do {
73571 + mutex_lock(&gr_learn_user_mutex);
73572 + spin_lock(&gr_learn_lock);
73573 + if (learn_buffer_len)
73574 + break;
73575 + spin_unlock(&gr_learn_lock);
73576 + mutex_unlock(&gr_learn_user_mutex);
73577 + if (file->f_flags & O_NONBLOCK) {
73578 + retval = -EAGAIN;
73579 + goto out;
73580 + }
73581 + if (signal_pending(current)) {
73582 + retval = -ERESTARTSYS;
73583 + goto out;
73584 + }
73585 +
73586 + schedule();
73587 + } while (1);
73588 +
73589 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73590 + learn_buffer_user_len = learn_buffer_len;
73591 + retval = learn_buffer_len;
73592 + learn_buffer_len = 0;
73593 +
73594 + spin_unlock(&gr_learn_lock);
73595 +
73596 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73597 + retval = -EFAULT;
73598 +
73599 + mutex_unlock(&gr_learn_user_mutex);
73600 +out:
73601 + set_current_state(TASK_RUNNING);
73602 + remove_wait_queue(&learn_wait, &wait);
73603 + return retval;
73604 +}
73605 +
73606 +static unsigned int
73607 +poll_learn(struct file * file, poll_table * wait)
73608 +{
73609 + poll_wait(file, &learn_wait, wait);
73610 +
73611 + if (learn_buffer_len)
73612 + return (POLLIN | POLLRDNORM);
73613 +
73614 + return 0;
73615 +}
73616 +
73617 +void
73618 +gr_clear_learn_entries(void)
73619 +{
73620 + char *tmp;
73621 +
73622 + mutex_lock(&gr_learn_user_mutex);
73623 + spin_lock(&gr_learn_lock);
73624 + tmp = learn_buffer;
73625 + learn_buffer = NULL;
73626 + spin_unlock(&gr_learn_lock);
73627 + if (tmp)
73628 + vfree(tmp);
73629 + if (learn_buffer_user != NULL) {
73630 + vfree(learn_buffer_user);
73631 + learn_buffer_user = NULL;
73632 + }
73633 + learn_buffer_len = 0;
73634 + mutex_unlock(&gr_learn_user_mutex);
73635 +
73636 + return;
73637 +}
73638 +
73639 +void
73640 +gr_add_learn_entry(const char *fmt, ...)
73641 +{
73642 + va_list args;
73643 + unsigned int len;
73644 +
73645 + if (!gr_learn_attached)
73646 + return;
73647 +
73648 + spin_lock(&gr_learn_lock);
73649 +
73650 + /* leave a gap at the end so we know when it's "full" but don't have to
73651 + compute the exact length of the string we're trying to append
73652 + */
73653 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73654 + spin_unlock(&gr_learn_lock);
73655 + wake_up_interruptible(&learn_wait);
73656 + return;
73657 + }
73658 + if (learn_buffer == NULL) {
73659 + spin_unlock(&gr_learn_lock);
73660 + return;
73661 + }
73662 +
73663 + va_start(args, fmt);
73664 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73665 + va_end(args);
73666 +
73667 + learn_buffer_len += len + 1;
73668 +
73669 + spin_unlock(&gr_learn_lock);
73670 + wake_up_interruptible(&learn_wait);
73671 +
73672 + return;
73673 +}
73674 +
73675 +static int
73676 +open_learn(struct inode *inode, struct file *file)
73677 +{
73678 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73679 + return -EBUSY;
73680 + if (file->f_mode & FMODE_READ) {
73681 + int retval = 0;
73682 + mutex_lock(&gr_learn_user_mutex);
73683 + if (learn_buffer == NULL)
73684 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73685 + if (learn_buffer_user == NULL)
73686 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73687 + if (learn_buffer == NULL) {
73688 + retval = -ENOMEM;
73689 + goto out_error;
73690 + }
73691 + if (learn_buffer_user == NULL) {
73692 + retval = -ENOMEM;
73693 + goto out_error;
73694 + }
73695 + learn_buffer_len = 0;
73696 + learn_buffer_user_len = 0;
73697 + gr_learn_attached = 1;
73698 +out_error:
73699 + mutex_unlock(&gr_learn_user_mutex);
73700 + return retval;
73701 + }
73702 + return 0;
73703 +}
73704 +
73705 +static int
73706 +close_learn(struct inode *inode, struct file *file)
73707 +{
73708 + if (file->f_mode & FMODE_READ) {
73709 + char *tmp = NULL;
73710 + mutex_lock(&gr_learn_user_mutex);
73711 + spin_lock(&gr_learn_lock);
73712 + tmp = learn_buffer;
73713 + learn_buffer = NULL;
73714 + spin_unlock(&gr_learn_lock);
73715 + if (tmp)
73716 + vfree(tmp);
73717 + if (learn_buffer_user != NULL) {
73718 + vfree(learn_buffer_user);
73719 + learn_buffer_user = NULL;
73720 + }
73721 + learn_buffer_len = 0;
73722 + learn_buffer_user_len = 0;
73723 + gr_learn_attached = 0;
73724 + mutex_unlock(&gr_learn_user_mutex);
73725 + }
73726 +
73727 + return 0;
73728 +}
73729 +
73730 +const struct file_operations grsec_fops = {
73731 + .read = read_learn,
73732 + .write = write_grsec_handler,
73733 + .open = open_learn,
73734 + .release = close_learn,
73735 + .poll = poll_learn,
73736 +};
73737 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73738 new file mode 100644
73739 index 0000000..7949dcd
73740 --- /dev/null
73741 +++ b/grsecurity/gracl_policy.c
73742 @@ -0,0 +1,1782 @@
73743 +#include <linux/kernel.h>
73744 +#include <linux/module.h>
73745 +#include <linux/sched.h>
73746 +#include <linux/mm.h>
73747 +#include <linux/file.h>
73748 +#include <linux/fs.h>
73749 +#include <linux/namei.h>
73750 +#include <linux/mount.h>
73751 +#include <linux/tty.h>
73752 +#include <linux/proc_fs.h>
73753 +#include <linux/lglock.h>
73754 +#include <linux/slab.h>
73755 +#include <linux/vmalloc.h>
73756 +#include <linux/types.h>
73757 +#include <linux/sysctl.h>
73758 +#include <linux/netdevice.h>
73759 +#include <linux/ptrace.h>
73760 +#include <linux/gracl.h>
73761 +#include <linux/gralloc.h>
73762 +#include <linux/security.h>
73763 +#include <linux/grinternal.h>
73764 +#include <linux/pid_namespace.h>
73765 +#include <linux/stop_machine.h>
73766 +#include <linux/fdtable.h>
73767 +#include <linux/percpu.h>
73768 +#include <linux/lglock.h>
73769 +#include <linux/hugetlb.h>
73770 +#include <linux/posix-timers.h>
73771 +#include "../fs/mount.h"
73772 +
73773 +#include <asm/uaccess.h>
73774 +#include <asm/errno.h>
73775 +#include <asm/mman.h>
73776 +
73777 +extern struct gr_policy_state *polstate;
73778 +
73779 +#define FOR_EACH_ROLE_START(role) \
73780 + role = polstate->role_list; \
73781 + while (role) {
73782 +
73783 +#define FOR_EACH_ROLE_END(role) \
73784 + role = role->prev; \
73785 + }
73786 +
73787 +struct path gr_real_root;
73788 +
73789 +extern struct gr_alloc_state *current_alloc_state;
73790 +
73791 +u16 acl_sp_role_value;
73792 +
73793 +static DEFINE_MUTEX(gr_dev_mutex);
73794 +
73795 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73796 +extern void gr_clear_learn_entries(void);
73797 +
73798 +struct gr_arg *gr_usermode __read_only;
73799 +unsigned char *gr_system_salt __read_only;
73800 +unsigned char *gr_system_sum __read_only;
73801 +
73802 +static unsigned int gr_auth_attempts = 0;
73803 +static unsigned long gr_auth_expires = 0UL;
73804 +
73805 +struct acl_object_label *fakefs_obj_rw;
73806 +struct acl_object_label *fakefs_obj_rwx;
73807 +
73808 +extern int gr_init_uidset(void);
73809 +extern void gr_free_uidset(void);
73810 +extern void gr_remove_uid(uid_t uid);
73811 +extern int gr_find_uid(uid_t uid);
73812 +
73813 +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);
73814 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73815 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73816 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73817 +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);
73818 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73819 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73820 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73821 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73822 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73823 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73824 +extern void assign_special_role(const char *rolename);
73825 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73826 +extern int gr_rbac_disable(void *unused);
73827 +extern void gr_enable_rbac_system(void);
73828 +
73829 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73830 +{
73831 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73832 + return -EFAULT;
73833 +
73834 + return 0;
73835 +}
73836 +
73837 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73838 +{
73839 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73840 + return -EFAULT;
73841 +
73842 + return 0;
73843 +}
73844 +
73845 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73846 +{
73847 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73848 + return -EFAULT;
73849 +
73850 + return 0;
73851 +}
73852 +
73853 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73854 +{
73855 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73856 + return -EFAULT;
73857 +
73858 + return 0;
73859 +}
73860 +
73861 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73862 +{
73863 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73864 + return -EFAULT;
73865 +
73866 + return 0;
73867 +}
73868 +
73869 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73870 +{
73871 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73872 + return -EFAULT;
73873 +
73874 + return 0;
73875 +}
73876 +
73877 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73878 +{
73879 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73880 + return -EFAULT;
73881 +
73882 + return 0;
73883 +}
73884 +
73885 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73886 +{
73887 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73888 + return -EFAULT;
73889 +
73890 + return 0;
73891 +}
73892 +
73893 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73894 +{
73895 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73896 + return -EFAULT;
73897 +
73898 + return 0;
73899 +}
73900 +
73901 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73902 +{
73903 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73904 + return -EFAULT;
73905 +
73906 + if (((uwrap->version != GRSECURITY_VERSION) &&
73907 + (uwrap->version != 0x2901)) ||
73908 + (uwrap->size != sizeof(struct gr_arg)))
73909 + return -EINVAL;
73910 +
73911 + return 0;
73912 +}
73913 +
73914 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73915 +{
73916 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73917 + return -EFAULT;
73918 +
73919 + return 0;
73920 +}
73921 +
73922 +static size_t get_gr_arg_wrapper_size_normal(void)
73923 +{
73924 + return sizeof(struct gr_arg_wrapper);
73925 +}
73926 +
73927 +#ifdef CONFIG_COMPAT
73928 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73929 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73930 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73931 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73932 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73933 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73934 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73935 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73936 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73937 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73938 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73939 +extern size_t get_gr_arg_wrapper_size_compat(void);
73940 +
73941 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73942 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73943 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73944 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73945 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73946 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73947 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73948 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73949 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73950 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73951 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73952 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
73953 +
73954 +#else
73955 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
73956 +#define copy_gr_arg copy_gr_arg_normal
73957 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
73958 +#define copy_acl_object_label copy_acl_object_label_normal
73959 +#define copy_acl_subject_label copy_acl_subject_label_normal
73960 +#define copy_acl_role_label copy_acl_role_label_normal
73961 +#define copy_acl_ip_label copy_acl_ip_label_normal
73962 +#define copy_pointer_from_array copy_pointer_from_array_normal
73963 +#define copy_sprole_pw copy_sprole_pw_normal
73964 +#define copy_role_transition copy_role_transition_normal
73965 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
73966 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
73967 +#endif
73968 +
73969 +static struct acl_subject_label *
73970 +lookup_subject_map(const struct acl_subject_label *userp)
73971 +{
73972 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
73973 + struct subject_map *match;
73974 +
73975 + match = polstate->subj_map_set.s_hash[index];
73976 +
73977 + while (match && match->user != userp)
73978 + match = match->next;
73979 +
73980 + if (match != NULL)
73981 + return match->kernel;
73982 + else
73983 + return NULL;
73984 +}
73985 +
73986 +static void
73987 +insert_subj_map_entry(struct subject_map *subjmap)
73988 +{
73989 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
73990 + struct subject_map **curr;
73991 +
73992 + subjmap->prev = NULL;
73993 +
73994 + curr = &polstate->subj_map_set.s_hash[index];
73995 + if (*curr != NULL)
73996 + (*curr)->prev = subjmap;
73997 +
73998 + subjmap->next = *curr;
73999 + *curr = subjmap;
74000 +
74001 + return;
74002 +}
74003 +
74004 +static void
74005 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74006 +{
74007 + unsigned int index =
74008 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74009 + struct acl_role_label **curr;
74010 + struct acl_role_label *tmp, *tmp2;
74011 +
74012 + curr = &polstate->acl_role_set.r_hash[index];
74013 +
74014 + /* simple case, slot is empty, just set it to our role */
74015 + if (*curr == NULL) {
74016 + *curr = role;
74017 + } else {
74018 + /* example:
74019 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74020 + 2 -> 3
74021 + */
74022 + /* first check to see if we can already be reached via this slot */
74023 + tmp = *curr;
74024 + while (tmp && tmp != role)
74025 + tmp = tmp->next;
74026 + if (tmp == role) {
74027 + /* we don't need to add ourselves to this slot's chain */
74028 + return;
74029 + }
74030 + /* we need to add ourselves to this chain, two cases */
74031 + if (role->next == NULL) {
74032 + /* simple case, append the current chain to our role */
74033 + role->next = *curr;
74034 + *curr = role;
74035 + } else {
74036 + /* 1 -> 2 -> 3 -> 4
74037 + 2 -> 3 -> 4
74038 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74039 + */
74040 + /* trickier case: walk our role's chain until we find
74041 + the role for the start of the current slot's chain */
74042 + tmp = role;
74043 + tmp2 = *curr;
74044 + while (tmp->next && tmp->next != tmp2)
74045 + tmp = tmp->next;
74046 + if (tmp->next == tmp2) {
74047 + /* from example above, we found 3, so just
74048 + replace this slot's chain with ours */
74049 + *curr = role;
74050 + } else {
74051 + /* we didn't find a subset of our role's chain
74052 + in the current slot's chain, so append their
74053 + chain to ours, and set us as the first role in
74054 + the slot's chain
74055 +
74056 + we could fold this case with the case above,
74057 + but making it explicit for clarity
74058 + */
74059 + tmp->next = tmp2;
74060 + *curr = role;
74061 + }
74062 + }
74063 + }
74064 +
74065 + return;
74066 +}
74067 +
74068 +static void
74069 +insert_acl_role_label(struct acl_role_label *role)
74070 +{
74071 + int i;
74072 +
74073 + if (polstate->role_list == NULL) {
74074 + polstate->role_list = role;
74075 + role->prev = NULL;
74076 + } else {
74077 + role->prev = polstate->role_list;
74078 + polstate->role_list = role;
74079 + }
74080 +
74081 + /* used for hash chains */
74082 + role->next = NULL;
74083 +
74084 + if (role->roletype & GR_ROLE_DOMAIN) {
74085 + for (i = 0; i < role->domain_child_num; i++)
74086 + __insert_acl_role_label(role, role->domain_children[i]);
74087 + } else
74088 + __insert_acl_role_label(role, role->uidgid);
74089 +}
74090 +
74091 +static int
74092 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74093 +{
74094 + struct name_entry **curr, *nentry;
74095 + struct inodev_entry *ientry;
74096 + unsigned int len = strlen(name);
74097 + unsigned int key = full_name_hash(name, len);
74098 + unsigned int index = key % polstate->name_set.n_size;
74099 +
74100 + curr = &polstate->name_set.n_hash[index];
74101 +
74102 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74103 + curr = &((*curr)->next);
74104 +
74105 + if (*curr != NULL)
74106 + return 1;
74107 +
74108 + nentry = acl_alloc(sizeof (struct name_entry));
74109 + if (nentry == NULL)
74110 + return 0;
74111 + ientry = acl_alloc(sizeof (struct inodev_entry));
74112 + if (ientry == NULL)
74113 + return 0;
74114 + ientry->nentry = nentry;
74115 +
74116 + nentry->key = key;
74117 + nentry->name = name;
74118 + nentry->inode = inode;
74119 + nentry->device = device;
74120 + nentry->len = len;
74121 + nentry->deleted = deleted;
74122 +
74123 + nentry->prev = NULL;
74124 + curr = &polstate->name_set.n_hash[index];
74125 + if (*curr != NULL)
74126 + (*curr)->prev = nentry;
74127 + nentry->next = *curr;
74128 + *curr = nentry;
74129 +
74130 + /* insert us into the table searchable by inode/dev */
74131 + __insert_inodev_entry(polstate, ientry);
74132 +
74133 + return 1;
74134 +}
74135 +
74136 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74137 +
74138 +static void *
74139 +create_table(__u32 * len, int elementsize)
74140 +{
74141 + unsigned int table_sizes[] = {
74142 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74143 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74144 + 4194301, 8388593, 16777213, 33554393, 67108859
74145 + };
74146 + void *newtable = NULL;
74147 + unsigned int pwr = 0;
74148 +
74149 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74150 + table_sizes[pwr] <= *len)
74151 + pwr++;
74152 +
74153 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74154 + return newtable;
74155 +
74156 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74157 + newtable =
74158 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74159 + else
74160 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74161 +
74162 + *len = table_sizes[pwr];
74163 +
74164 + return newtable;
74165 +}
74166 +
74167 +static int
74168 +init_variables(const struct gr_arg *arg, bool reload)
74169 +{
74170 + struct task_struct *reaper = init_pid_ns.child_reaper;
74171 + unsigned int stacksize;
74172 +
74173 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74174 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74175 + polstate->name_set.n_size = arg->role_db.num_objects;
74176 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74177 +
74178 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74179 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74180 + return 1;
74181 +
74182 + if (!reload) {
74183 + if (!gr_init_uidset())
74184 + return 1;
74185 + }
74186 +
74187 + /* set up the stack that holds allocation info */
74188 +
74189 + stacksize = arg->role_db.num_pointers + 5;
74190 +
74191 + if (!acl_alloc_stack_init(stacksize))
74192 + return 1;
74193 +
74194 + if (!reload) {
74195 + /* grab reference for the real root dentry and vfsmount */
74196 + get_fs_root(reaper->fs, &gr_real_root);
74197 +
74198 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74199 + 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);
74200 +#endif
74201 +
74202 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74203 + if (fakefs_obj_rw == NULL)
74204 + return 1;
74205 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74206 +
74207 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74208 + if (fakefs_obj_rwx == NULL)
74209 + return 1;
74210 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74211 + }
74212 +
74213 + polstate->subj_map_set.s_hash =
74214 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74215 + polstate->acl_role_set.r_hash =
74216 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74217 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74218 + polstate->inodev_set.i_hash =
74219 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74220 +
74221 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74222 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74223 + return 1;
74224 +
74225 + memset(polstate->subj_map_set.s_hash, 0,
74226 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74227 + memset(polstate->acl_role_set.r_hash, 0,
74228 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74229 + memset(polstate->name_set.n_hash, 0,
74230 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74231 + memset(polstate->inodev_set.i_hash, 0,
74232 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74233 +
74234 + return 0;
74235 +}
74236 +
74237 +/* free information not needed after startup
74238 + currently contains user->kernel pointer mappings for subjects
74239 +*/
74240 +
74241 +static void
74242 +free_init_variables(void)
74243 +{
74244 + __u32 i;
74245 +
74246 + if (polstate->subj_map_set.s_hash) {
74247 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74248 + if (polstate->subj_map_set.s_hash[i]) {
74249 + kfree(polstate->subj_map_set.s_hash[i]);
74250 + polstate->subj_map_set.s_hash[i] = NULL;
74251 + }
74252 + }
74253 +
74254 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74255 + PAGE_SIZE)
74256 + kfree(polstate->subj_map_set.s_hash);
74257 + else
74258 + vfree(polstate->subj_map_set.s_hash);
74259 + }
74260 +
74261 + return;
74262 +}
74263 +
74264 +static void
74265 +free_variables(bool reload)
74266 +{
74267 + struct acl_subject_label *s;
74268 + struct acl_role_label *r;
74269 + struct task_struct *task, *task2;
74270 + unsigned int x;
74271 +
74272 + if (!reload) {
74273 + gr_clear_learn_entries();
74274 +
74275 + read_lock(&tasklist_lock);
74276 + do_each_thread(task2, task) {
74277 + task->acl_sp_role = 0;
74278 + task->acl_role_id = 0;
74279 + task->inherited = 0;
74280 + task->acl = NULL;
74281 + task->role = NULL;
74282 + } while_each_thread(task2, task);
74283 + read_unlock(&tasklist_lock);
74284 +
74285 + kfree(fakefs_obj_rw);
74286 + fakefs_obj_rw = NULL;
74287 + kfree(fakefs_obj_rwx);
74288 + fakefs_obj_rwx = NULL;
74289 +
74290 + /* release the reference to the real root dentry and vfsmount */
74291 + path_put(&gr_real_root);
74292 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74293 + }
74294 +
74295 + /* free all object hash tables */
74296 +
74297 + FOR_EACH_ROLE_START(r)
74298 + if (r->subj_hash == NULL)
74299 + goto next_role;
74300 + FOR_EACH_SUBJECT_START(r, s, x)
74301 + if (s->obj_hash == NULL)
74302 + break;
74303 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74304 + kfree(s->obj_hash);
74305 + else
74306 + vfree(s->obj_hash);
74307 + FOR_EACH_SUBJECT_END(s, x)
74308 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74309 + if (s->obj_hash == NULL)
74310 + break;
74311 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74312 + kfree(s->obj_hash);
74313 + else
74314 + vfree(s->obj_hash);
74315 + FOR_EACH_NESTED_SUBJECT_END(s)
74316 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74317 + kfree(r->subj_hash);
74318 + else
74319 + vfree(r->subj_hash);
74320 + r->subj_hash = NULL;
74321 +next_role:
74322 + FOR_EACH_ROLE_END(r)
74323 +
74324 + acl_free_all();
74325 +
74326 + if (polstate->acl_role_set.r_hash) {
74327 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74328 + PAGE_SIZE)
74329 + kfree(polstate->acl_role_set.r_hash);
74330 + else
74331 + vfree(polstate->acl_role_set.r_hash);
74332 + }
74333 + if (polstate->name_set.n_hash) {
74334 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74335 + PAGE_SIZE)
74336 + kfree(polstate->name_set.n_hash);
74337 + else
74338 + vfree(polstate->name_set.n_hash);
74339 + }
74340 +
74341 + if (polstate->inodev_set.i_hash) {
74342 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74343 + PAGE_SIZE)
74344 + kfree(polstate->inodev_set.i_hash);
74345 + else
74346 + vfree(polstate->inodev_set.i_hash);
74347 + }
74348 +
74349 + if (!reload)
74350 + gr_free_uidset();
74351 +
74352 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74353 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74354 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74355 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74356 +
74357 + polstate->default_role = NULL;
74358 + polstate->kernel_role = NULL;
74359 + polstate->role_list = NULL;
74360 +
74361 + return;
74362 +}
74363 +
74364 +static struct acl_subject_label *
74365 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74366 +
74367 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74368 +{
74369 + unsigned int len = strnlen_user(*name, maxlen);
74370 + char *tmp;
74371 +
74372 + if (!len || len >= maxlen)
74373 + return -EINVAL;
74374 +
74375 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74376 + return -ENOMEM;
74377 +
74378 + if (copy_from_user(tmp, *name, len))
74379 + return -EFAULT;
74380 +
74381 + tmp[len-1] = '\0';
74382 + *name = tmp;
74383 +
74384 + return 0;
74385 +}
74386 +
74387 +static int
74388 +copy_user_glob(struct acl_object_label *obj)
74389 +{
74390 + struct acl_object_label *g_tmp, **guser;
74391 + int error;
74392 +
74393 + if (obj->globbed == NULL)
74394 + return 0;
74395 +
74396 + guser = &obj->globbed;
74397 + while (*guser) {
74398 + g_tmp = (struct acl_object_label *)
74399 + acl_alloc(sizeof (struct acl_object_label));
74400 + if (g_tmp == NULL)
74401 + return -ENOMEM;
74402 +
74403 + if (copy_acl_object_label(g_tmp, *guser))
74404 + return -EFAULT;
74405 +
74406 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74407 + if (error)
74408 + return error;
74409 +
74410 + *guser = g_tmp;
74411 + guser = &(g_tmp->next);
74412 + }
74413 +
74414 + return 0;
74415 +}
74416 +
74417 +static int
74418 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74419 + struct acl_role_label *role)
74420 +{
74421 + struct acl_object_label *o_tmp;
74422 + int ret;
74423 +
74424 + while (userp) {
74425 + if ((o_tmp = (struct acl_object_label *)
74426 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74427 + return -ENOMEM;
74428 +
74429 + if (copy_acl_object_label(o_tmp, userp))
74430 + return -EFAULT;
74431 +
74432 + userp = o_tmp->prev;
74433 +
74434 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74435 + if (ret)
74436 + return ret;
74437 +
74438 + insert_acl_obj_label(o_tmp, subj);
74439 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74440 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74441 + return -ENOMEM;
74442 +
74443 + ret = copy_user_glob(o_tmp);
74444 + if (ret)
74445 + return ret;
74446 +
74447 + if (o_tmp->nested) {
74448 + int already_copied;
74449 +
74450 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74451 + if (IS_ERR(o_tmp->nested))
74452 + return PTR_ERR(o_tmp->nested);
74453 +
74454 + /* insert into nested subject list if we haven't copied this one yet
74455 + to prevent duplicate entries */
74456 + if (!already_copied) {
74457 + o_tmp->nested->next = role->hash->first;
74458 + role->hash->first = o_tmp->nested;
74459 + }
74460 + }
74461 + }
74462 +
74463 + return 0;
74464 +}
74465 +
74466 +static __u32
74467 +count_user_subjs(struct acl_subject_label *userp)
74468 +{
74469 + struct acl_subject_label s_tmp;
74470 + __u32 num = 0;
74471 +
74472 + while (userp) {
74473 + if (copy_acl_subject_label(&s_tmp, userp))
74474 + break;
74475 +
74476 + userp = s_tmp.prev;
74477 + }
74478 +
74479 + return num;
74480 +}
74481 +
74482 +static int
74483 +copy_user_allowedips(struct acl_role_label *rolep)
74484 +{
74485 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74486 +
74487 + ruserip = rolep->allowed_ips;
74488 +
74489 + while (ruserip) {
74490 + rlast = rtmp;
74491 +
74492 + if ((rtmp = (struct role_allowed_ip *)
74493 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74494 + return -ENOMEM;
74495 +
74496 + if (copy_role_allowed_ip(rtmp, ruserip))
74497 + return -EFAULT;
74498 +
74499 + ruserip = rtmp->prev;
74500 +
74501 + if (!rlast) {
74502 + rtmp->prev = NULL;
74503 + rolep->allowed_ips = rtmp;
74504 + } else {
74505 + rlast->next = rtmp;
74506 + rtmp->prev = rlast;
74507 + }
74508 +
74509 + if (!ruserip)
74510 + rtmp->next = NULL;
74511 + }
74512 +
74513 + return 0;
74514 +}
74515 +
74516 +static int
74517 +copy_user_transitions(struct acl_role_label *rolep)
74518 +{
74519 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74520 + int error;
74521 +
74522 + rusertp = rolep->transitions;
74523 +
74524 + while (rusertp) {
74525 + rlast = rtmp;
74526 +
74527 + if ((rtmp = (struct role_transition *)
74528 + acl_alloc(sizeof (struct role_transition))) == NULL)
74529 + return -ENOMEM;
74530 +
74531 + if (copy_role_transition(rtmp, rusertp))
74532 + return -EFAULT;
74533 +
74534 + rusertp = rtmp->prev;
74535 +
74536 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74537 + if (error)
74538 + return error;
74539 +
74540 + if (!rlast) {
74541 + rtmp->prev = NULL;
74542 + rolep->transitions = rtmp;
74543 + } else {
74544 + rlast->next = rtmp;
74545 + rtmp->prev = rlast;
74546 + }
74547 +
74548 + if (!rusertp)
74549 + rtmp->next = NULL;
74550 + }
74551 +
74552 + return 0;
74553 +}
74554 +
74555 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74556 +{
74557 + struct acl_object_label o_tmp;
74558 + __u32 num = 0;
74559 +
74560 + while (userp) {
74561 + if (copy_acl_object_label(&o_tmp, userp))
74562 + break;
74563 +
74564 + userp = o_tmp.prev;
74565 + num++;
74566 + }
74567 +
74568 + return num;
74569 +}
74570 +
74571 +static struct acl_subject_label *
74572 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74573 +{
74574 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74575 + __u32 num_objs;
74576 + struct acl_ip_label **i_tmp, *i_utmp2;
74577 + struct gr_hash_struct ghash;
74578 + struct subject_map *subjmap;
74579 + unsigned int i_num;
74580 + int err;
74581 +
74582 + if (already_copied != NULL)
74583 + *already_copied = 0;
74584 +
74585 + s_tmp = lookup_subject_map(userp);
74586 +
74587 + /* we've already copied this subject into the kernel, just return
74588 + the reference to it, and don't copy it over again
74589 + */
74590 + if (s_tmp) {
74591 + if (already_copied != NULL)
74592 + *already_copied = 1;
74593 + return(s_tmp);
74594 + }
74595 +
74596 + if ((s_tmp = (struct acl_subject_label *)
74597 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74598 + return ERR_PTR(-ENOMEM);
74599 +
74600 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74601 + if (subjmap == NULL)
74602 + return ERR_PTR(-ENOMEM);
74603 +
74604 + subjmap->user = userp;
74605 + subjmap->kernel = s_tmp;
74606 + insert_subj_map_entry(subjmap);
74607 +
74608 + if (copy_acl_subject_label(s_tmp, userp))
74609 + return ERR_PTR(-EFAULT);
74610 +
74611 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74612 + if (err)
74613 + return ERR_PTR(err);
74614 +
74615 + if (!strcmp(s_tmp->filename, "/"))
74616 + role->root_label = s_tmp;
74617 +
74618 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74619 + return ERR_PTR(-EFAULT);
74620 +
74621 + /* copy user and group transition tables */
74622 +
74623 + if (s_tmp->user_trans_num) {
74624 + uid_t *uidlist;
74625 +
74626 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74627 + if (uidlist == NULL)
74628 + return ERR_PTR(-ENOMEM);
74629 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74630 + return ERR_PTR(-EFAULT);
74631 +
74632 + s_tmp->user_transitions = uidlist;
74633 + }
74634 +
74635 + if (s_tmp->group_trans_num) {
74636 + gid_t *gidlist;
74637 +
74638 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74639 + if (gidlist == NULL)
74640 + return ERR_PTR(-ENOMEM);
74641 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74642 + return ERR_PTR(-EFAULT);
74643 +
74644 + s_tmp->group_transitions = gidlist;
74645 + }
74646 +
74647 + /* set up object hash table */
74648 + num_objs = count_user_objs(ghash.first);
74649 +
74650 + s_tmp->obj_hash_size = num_objs;
74651 + s_tmp->obj_hash =
74652 + (struct acl_object_label **)
74653 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74654 +
74655 + if (!s_tmp->obj_hash)
74656 + return ERR_PTR(-ENOMEM);
74657 +
74658 + memset(s_tmp->obj_hash, 0,
74659 + s_tmp->obj_hash_size *
74660 + sizeof (struct acl_object_label *));
74661 +
74662 + /* add in objects */
74663 + err = copy_user_objs(ghash.first, s_tmp, role);
74664 +
74665 + if (err)
74666 + return ERR_PTR(err);
74667 +
74668 + /* set pointer for parent subject */
74669 + if (s_tmp->parent_subject) {
74670 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74671 +
74672 + if (IS_ERR(s_tmp2))
74673 + return s_tmp2;
74674 +
74675 + s_tmp->parent_subject = s_tmp2;
74676 + }
74677 +
74678 + /* add in ip acls */
74679 +
74680 + if (!s_tmp->ip_num) {
74681 + s_tmp->ips = NULL;
74682 + goto insert;
74683 + }
74684 +
74685 + i_tmp =
74686 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74687 + sizeof (struct acl_ip_label *));
74688 +
74689 + if (!i_tmp)
74690 + return ERR_PTR(-ENOMEM);
74691 +
74692 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74693 + *(i_tmp + i_num) =
74694 + (struct acl_ip_label *)
74695 + acl_alloc(sizeof (struct acl_ip_label));
74696 + if (!*(i_tmp + i_num))
74697 + return ERR_PTR(-ENOMEM);
74698 +
74699 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74700 + return ERR_PTR(-EFAULT);
74701 +
74702 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74703 + return ERR_PTR(-EFAULT);
74704 +
74705 + if ((*(i_tmp + i_num))->iface == NULL)
74706 + continue;
74707 +
74708 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74709 + if (err)
74710 + return ERR_PTR(err);
74711 + }
74712 +
74713 + s_tmp->ips = i_tmp;
74714 +
74715 +insert:
74716 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74717 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74718 + return ERR_PTR(-ENOMEM);
74719 +
74720 + return s_tmp;
74721 +}
74722 +
74723 +static int
74724 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74725 +{
74726 + struct acl_subject_label s_pre;
74727 + struct acl_subject_label * ret;
74728 + int err;
74729 +
74730 + while (userp) {
74731 + if (copy_acl_subject_label(&s_pre, userp))
74732 + return -EFAULT;
74733 +
74734 + ret = do_copy_user_subj(userp, role, NULL);
74735 +
74736 + err = PTR_ERR(ret);
74737 + if (IS_ERR(ret))
74738 + return err;
74739 +
74740 + insert_acl_subj_label(ret, role);
74741 +
74742 + userp = s_pre.prev;
74743 + }
74744 +
74745 + return 0;
74746 +}
74747 +
74748 +static int
74749 +copy_user_acl(struct gr_arg *arg)
74750 +{
74751 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74752 + struct acl_subject_label *subj_list;
74753 + struct sprole_pw *sptmp;
74754 + struct gr_hash_struct *ghash;
74755 + uid_t *domainlist;
74756 + unsigned int r_num;
74757 + int err = 0;
74758 + __u16 i;
74759 + __u32 num_subjs;
74760 +
74761 + /* we need a default and kernel role */
74762 + if (arg->role_db.num_roles < 2)
74763 + return -EINVAL;
74764 +
74765 + /* copy special role authentication info from userspace */
74766 +
74767 + polstate->num_sprole_pws = arg->num_sprole_pws;
74768 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74769 +
74770 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74771 + return -ENOMEM;
74772 +
74773 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74774 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74775 + if (!sptmp)
74776 + return -ENOMEM;
74777 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74778 + return -EFAULT;
74779 +
74780 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74781 + if (err)
74782 + return err;
74783 +
74784 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74785 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74786 +#endif
74787 +
74788 + polstate->acl_special_roles[i] = sptmp;
74789 + }
74790 +
74791 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74792 +
74793 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74794 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74795 +
74796 + if (!r_tmp)
74797 + return -ENOMEM;
74798 +
74799 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74800 + return -EFAULT;
74801 +
74802 + if (copy_acl_role_label(r_tmp, r_utmp2))
74803 + return -EFAULT;
74804 +
74805 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74806 + if (err)
74807 + return err;
74808 +
74809 + if (!strcmp(r_tmp->rolename, "default")
74810 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74811 + polstate->default_role = r_tmp;
74812 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74813 + polstate->kernel_role = r_tmp;
74814 + }
74815 +
74816 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74817 + return -ENOMEM;
74818 +
74819 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74820 + return -EFAULT;
74821 +
74822 + r_tmp->hash = ghash;
74823 +
74824 + num_subjs = count_user_subjs(r_tmp->hash->first);
74825 +
74826 + r_tmp->subj_hash_size = num_subjs;
74827 + r_tmp->subj_hash =
74828 + (struct acl_subject_label **)
74829 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74830 +
74831 + if (!r_tmp->subj_hash)
74832 + return -ENOMEM;
74833 +
74834 + err = copy_user_allowedips(r_tmp);
74835 + if (err)
74836 + return err;
74837 +
74838 + /* copy domain info */
74839 + if (r_tmp->domain_children != NULL) {
74840 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74841 + if (domainlist == NULL)
74842 + return -ENOMEM;
74843 +
74844 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74845 + return -EFAULT;
74846 +
74847 + r_tmp->domain_children = domainlist;
74848 + }
74849 +
74850 + err = copy_user_transitions(r_tmp);
74851 + if (err)
74852 + return err;
74853 +
74854 + memset(r_tmp->subj_hash, 0,
74855 + r_tmp->subj_hash_size *
74856 + sizeof (struct acl_subject_label *));
74857 +
74858 + /* acquire the list of subjects, then NULL out
74859 + the list prior to parsing the subjects for this role,
74860 + as during this parsing the list is replaced with a list
74861 + of *nested* subjects for the role
74862 + */
74863 + subj_list = r_tmp->hash->first;
74864 +
74865 + /* set nested subject list to null */
74866 + r_tmp->hash->first = NULL;
74867 +
74868 + err = copy_user_subjs(subj_list, r_tmp);
74869 +
74870 + if (err)
74871 + return err;
74872 +
74873 + insert_acl_role_label(r_tmp);
74874 + }
74875 +
74876 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74877 + return -EINVAL;
74878 +
74879 + return err;
74880 +}
74881 +
74882 +static int gracl_reload_apply_policies(void *reload)
74883 +{
74884 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74885 + struct task_struct *task, *task2;
74886 + struct acl_role_label *role, *rtmp;
74887 + struct acl_subject_label *subj;
74888 + const struct cred *cred;
74889 + int role_applied;
74890 + int ret = 0;
74891 +
74892 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74893 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74894 +
74895 + /* first make sure we'll be able to apply the new policy cleanly */
74896 + do_each_thread(task2, task) {
74897 + if (task->exec_file == NULL)
74898 + continue;
74899 + role_applied = 0;
74900 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74901 + /* preserve special roles */
74902 + FOR_EACH_ROLE_START(role)
74903 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74904 + rtmp = task->role;
74905 + task->role = role;
74906 + role_applied = 1;
74907 + break;
74908 + }
74909 + FOR_EACH_ROLE_END(role)
74910 + }
74911 + if (!role_applied) {
74912 + cred = __task_cred(task);
74913 + rtmp = task->role;
74914 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74915 + }
74916 + /* this handles non-nested inherited subjects, nested subjects will still
74917 + be dropped currently */
74918 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
74919 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL, 1);
74920 + /* change the role back so that we've made no modifications to the policy */
74921 + task->role = rtmp;
74922 +
74923 + if (subj == NULL || task->tmpacl == NULL) {
74924 + ret = -EINVAL;
74925 + goto out;
74926 + }
74927 + } while_each_thread(task2, task);
74928 +
74929 + /* now actually apply the policy */
74930 +
74931 + do_each_thread(task2, task) {
74932 + if (task->exec_file) {
74933 + role_applied = 0;
74934 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74935 + /* preserve special roles */
74936 + FOR_EACH_ROLE_START(role)
74937 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74938 + task->role = role;
74939 + role_applied = 1;
74940 + break;
74941 + }
74942 + FOR_EACH_ROLE_END(role)
74943 + }
74944 + if (!role_applied) {
74945 + cred = __task_cred(task);
74946 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74947 + }
74948 + /* this handles non-nested inherited subjects, nested subjects will still
74949 + be dropped currently */
74950 + if (!reload_state->oldmode && task->inherited)
74951 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
74952 + else {
74953 + /* looked up and tagged to the task previously */
74954 + subj = task->tmpacl;
74955 + }
74956 + /* subj will be non-null */
74957 + __gr_apply_subject_to_task(polstate, task, subj);
74958 + if (reload_state->oldmode) {
74959 + task->acl_role_id = 0;
74960 + task->acl_sp_role = 0;
74961 + task->inherited = 0;
74962 + }
74963 + } else {
74964 + // it's a kernel process
74965 + task->role = polstate->kernel_role;
74966 + task->acl = polstate->kernel_role->root_label;
74967 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
74968 + task->acl->mode &= ~GR_PROCFIND;
74969 +#endif
74970 + }
74971 + } while_each_thread(task2, task);
74972 +
74973 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
74974 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
74975 +
74976 +out:
74977 +
74978 + return ret;
74979 +}
74980 +
74981 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
74982 +{
74983 + struct gr_reload_state new_reload_state = { };
74984 + int err;
74985 +
74986 + new_reload_state.oldpolicy_ptr = polstate;
74987 + new_reload_state.oldalloc_ptr = current_alloc_state;
74988 + new_reload_state.oldmode = oldmode;
74989 +
74990 + current_alloc_state = &new_reload_state.newalloc;
74991 + polstate = &new_reload_state.newpolicy;
74992 +
74993 + /* everything relevant is now saved off, copy in the new policy */
74994 + if (init_variables(args, true)) {
74995 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74996 + err = -ENOMEM;
74997 + goto error;
74998 + }
74999 +
75000 + err = copy_user_acl(args);
75001 + free_init_variables();
75002 + if (err)
75003 + goto error;
75004 + /* the new policy is copied in, with the old policy available via saved_state
75005 + first go through applying roles, making sure to preserve special roles
75006 + then apply new subjects, making sure to preserve inherited and nested subjects,
75007 + though currently only inherited subjects will be preserved
75008 + */
75009 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75010 + if (err)
75011 + goto error;
75012 +
75013 + /* we've now applied the new policy, so restore the old policy state to free it */
75014 + polstate = &new_reload_state.oldpolicy;
75015 + current_alloc_state = &new_reload_state.oldalloc;
75016 + free_variables(true);
75017 +
75018 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75019 + to running_polstate/current_alloc_state inside stop_machine
75020 + */
75021 + err = 0;
75022 + goto out;
75023 +error:
75024 + /* on error of loading the new policy, we'll just keep the previous
75025 + policy set around
75026 + */
75027 + free_variables(true);
75028 +
75029 + /* doesn't affect runtime, but maintains consistent state */
75030 +out:
75031 + polstate = new_reload_state.oldpolicy_ptr;
75032 + current_alloc_state = new_reload_state.oldalloc_ptr;
75033 +
75034 + return err;
75035 +}
75036 +
75037 +static int
75038 +gracl_init(struct gr_arg *args)
75039 +{
75040 + int error = 0;
75041 +
75042 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75043 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75044 +
75045 + if (init_variables(args, false)) {
75046 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75047 + error = -ENOMEM;
75048 + goto out;
75049 + }
75050 +
75051 + error = copy_user_acl(args);
75052 + free_init_variables();
75053 + if (error)
75054 + goto out;
75055 +
75056 + error = gr_set_acls(0);
75057 + if (error)
75058 + goto out;
75059 +
75060 + gr_enable_rbac_system();
75061 +
75062 + return 0;
75063 +
75064 +out:
75065 + free_variables(false);
75066 + return error;
75067 +}
75068 +
75069 +static int
75070 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75071 + unsigned char **sum)
75072 +{
75073 + struct acl_role_label *r;
75074 + struct role_allowed_ip *ipp;
75075 + struct role_transition *trans;
75076 + unsigned int i;
75077 + int found = 0;
75078 + u32 curr_ip = current->signal->curr_ip;
75079 +
75080 + current->signal->saved_ip = curr_ip;
75081 +
75082 + /* check transition table */
75083 +
75084 + for (trans = current->role->transitions; trans; trans = trans->next) {
75085 + if (!strcmp(rolename, trans->rolename)) {
75086 + found = 1;
75087 + break;
75088 + }
75089 + }
75090 +
75091 + if (!found)
75092 + return 0;
75093 +
75094 + /* handle special roles that do not require authentication
75095 + and check ip */
75096 +
75097 + FOR_EACH_ROLE_START(r)
75098 + if (!strcmp(rolename, r->rolename) &&
75099 + (r->roletype & GR_ROLE_SPECIAL)) {
75100 + found = 0;
75101 + if (r->allowed_ips != NULL) {
75102 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75103 + if ((ntohl(curr_ip) & ipp->netmask) ==
75104 + (ntohl(ipp->addr) & ipp->netmask))
75105 + found = 1;
75106 + }
75107 + } else
75108 + found = 2;
75109 + if (!found)
75110 + return 0;
75111 +
75112 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75113 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75114 + *salt = NULL;
75115 + *sum = NULL;
75116 + return 1;
75117 + }
75118 + }
75119 + FOR_EACH_ROLE_END(r)
75120 +
75121 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75122 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75123 + *salt = polstate->acl_special_roles[i]->salt;
75124 + *sum = polstate->acl_special_roles[i]->sum;
75125 + return 1;
75126 + }
75127 + }
75128 +
75129 + return 0;
75130 +}
75131 +
75132 +int gr_check_secure_terminal(struct task_struct *task)
75133 +{
75134 + struct task_struct *p, *p2, *p3;
75135 + struct files_struct *files;
75136 + struct fdtable *fdt;
75137 + struct file *our_file = NULL, *file;
75138 + int i;
75139 +
75140 + if (task->signal->tty == NULL)
75141 + return 1;
75142 +
75143 + files = get_files_struct(task);
75144 + if (files != NULL) {
75145 + rcu_read_lock();
75146 + fdt = files_fdtable(files);
75147 + for (i=0; i < fdt->max_fds; i++) {
75148 + file = fcheck_files(files, i);
75149 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75150 + get_file(file);
75151 + our_file = file;
75152 + }
75153 + }
75154 + rcu_read_unlock();
75155 + put_files_struct(files);
75156 + }
75157 +
75158 + if (our_file == NULL)
75159 + return 1;
75160 +
75161 + read_lock(&tasklist_lock);
75162 + do_each_thread(p2, p) {
75163 + files = get_files_struct(p);
75164 + if (files == NULL ||
75165 + (p->signal && p->signal->tty == task->signal->tty)) {
75166 + if (files != NULL)
75167 + put_files_struct(files);
75168 + continue;
75169 + }
75170 + rcu_read_lock();
75171 + fdt = files_fdtable(files);
75172 + for (i=0; i < fdt->max_fds; i++) {
75173 + file = fcheck_files(files, i);
75174 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75175 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75176 + p3 = task;
75177 + while (task_pid_nr(p3) > 0) {
75178 + if (p3 == p)
75179 + break;
75180 + p3 = p3->real_parent;
75181 + }
75182 + if (p3 == p)
75183 + break;
75184 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75185 + gr_handle_alertkill(p);
75186 + rcu_read_unlock();
75187 + put_files_struct(files);
75188 + read_unlock(&tasklist_lock);
75189 + fput(our_file);
75190 + return 0;
75191 + }
75192 + }
75193 + rcu_read_unlock();
75194 + put_files_struct(files);
75195 + } while_each_thread(p2, p);
75196 + read_unlock(&tasklist_lock);
75197 +
75198 + fput(our_file);
75199 + return 1;
75200 +}
75201 +
75202 +ssize_t
75203 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75204 +{
75205 + struct gr_arg_wrapper uwrap;
75206 + unsigned char *sprole_salt = NULL;
75207 + unsigned char *sprole_sum = NULL;
75208 + int error = 0;
75209 + int error2 = 0;
75210 + size_t req_count = 0;
75211 + unsigned char oldmode = 0;
75212 +
75213 + mutex_lock(&gr_dev_mutex);
75214 +
75215 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75216 + error = -EPERM;
75217 + goto out;
75218 + }
75219 +
75220 +#ifdef CONFIG_COMPAT
75221 + pax_open_kernel();
75222 + if (is_compat_task()) {
75223 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75224 + copy_gr_arg = &copy_gr_arg_compat;
75225 + copy_acl_object_label = &copy_acl_object_label_compat;
75226 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75227 + copy_acl_role_label = &copy_acl_role_label_compat;
75228 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75229 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75230 + copy_role_transition = &copy_role_transition_compat;
75231 + copy_sprole_pw = &copy_sprole_pw_compat;
75232 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75233 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75234 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75235 + } else {
75236 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75237 + copy_gr_arg = &copy_gr_arg_normal;
75238 + copy_acl_object_label = &copy_acl_object_label_normal;
75239 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75240 + copy_acl_role_label = &copy_acl_role_label_normal;
75241 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75242 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75243 + copy_role_transition = &copy_role_transition_normal;
75244 + copy_sprole_pw = &copy_sprole_pw_normal;
75245 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75246 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75247 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75248 + }
75249 + pax_close_kernel();
75250 +#endif
75251 +
75252 + req_count = get_gr_arg_wrapper_size();
75253 +
75254 + if (count != req_count) {
75255 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75256 + error = -EINVAL;
75257 + goto out;
75258 + }
75259 +
75260 +
75261 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75262 + gr_auth_expires = 0;
75263 + gr_auth_attempts = 0;
75264 + }
75265 +
75266 + error = copy_gr_arg_wrapper(buf, &uwrap);
75267 + if (error)
75268 + goto out;
75269 +
75270 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75271 + if (error)
75272 + goto out;
75273 +
75274 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75275 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75276 + time_after(gr_auth_expires, get_seconds())) {
75277 + error = -EBUSY;
75278 + goto out;
75279 + }
75280 +
75281 + /* if non-root trying to do anything other than use a special role,
75282 + do not attempt authentication, do not count towards authentication
75283 + locking
75284 + */
75285 +
75286 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75287 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75288 + gr_is_global_nonroot(current_uid())) {
75289 + error = -EPERM;
75290 + goto out;
75291 + }
75292 +
75293 + /* ensure pw and special role name are null terminated */
75294 +
75295 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75296 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75297 +
75298 + /* Okay.
75299 + * We have our enough of the argument structure..(we have yet
75300 + * to copy_from_user the tables themselves) . Copy the tables
75301 + * only if we need them, i.e. for loading operations. */
75302 +
75303 + switch (gr_usermode->mode) {
75304 + case GR_STATUS:
75305 + if (gr_acl_is_enabled()) {
75306 + error = 1;
75307 + if (!gr_check_secure_terminal(current))
75308 + error = 3;
75309 + } else
75310 + error = 2;
75311 + goto out;
75312 + case GR_SHUTDOWN:
75313 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75314 + stop_machine(gr_rbac_disable, NULL, NULL);
75315 + free_variables(false);
75316 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75317 + memset(gr_system_salt, 0, GR_SALT_LEN);
75318 + memset(gr_system_sum, 0, GR_SHA_LEN);
75319 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75320 + } else if (gr_acl_is_enabled()) {
75321 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75322 + error = -EPERM;
75323 + } else {
75324 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75325 + error = -EAGAIN;
75326 + }
75327 + break;
75328 + case GR_ENABLE:
75329 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75330 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75331 + else {
75332 + if (gr_acl_is_enabled())
75333 + error = -EAGAIN;
75334 + else
75335 + error = error2;
75336 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75337 + }
75338 + break;
75339 + case GR_OLDRELOAD:
75340 + oldmode = 1;
75341 + case GR_RELOAD:
75342 + if (!gr_acl_is_enabled()) {
75343 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75344 + error = -EAGAIN;
75345 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75346 + error2 = gracl_reload(gr_usermode, oldmode);
75347 + if (!error2)
75348 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75349 + else {
75350 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75351 + error = error2;
75352 + }
75353 + } else {
75354 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75355 + error = -EPERM;
75356 + }
75357 + break;
75358 + case GR_SEGVMOD:
75359 + if (unlikely(!gr_acl_is_enabled())) {
75360 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75361 + error = -EAGAIN;
75362 + break;
75363 + }
75364 +
75365 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75366 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75367 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75368 + struct acl_subject_label *segvacl;
75369 + segvacl =
75370 + lookup_acl_subj_label(gr_usermode->segv_inode,
75371 + gr_usermode->segv_device,
75372 + current->role);
75373 + if (segvacl) {
75374 + segvacl->crashes = 0;
75375 + segvacl->expires = 0;
75376 + }
75377 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75378 + gr_remove_uid(gr_usermode->segv_uid);
75379 + }
75380 + } else {
75381 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75382 + error = -EPERM;
75383 + }
75384 + break;
75385 + case GR_SPROLE:
75386 + case GR_SPROLEPAM:
75387 + if (unlikely(!gr_acl_is_enabled())) {
75388 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75389 + error = -EAGAIN;
75390 + break;
75391 + }
75392 +
75393 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75394 + current->role->expires = 0;
75395 + current->role->auth_attempts = 0;
75396 + }
75397 +
75398 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75399 + time_after(current->role->expires, get_seconds())) {
75400 + error = -EBUSY;
75401 + goto out;
75402 + }
75403 +
75404 + if (lookup_special_role_auth
75405 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75406 + && ((!sprole_salt && !sprole_sum)
75407 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75408 + char *p = "";
75409 + assign_special_role(gr_usermode->sp_role);
75410 + read_lock(&tasklist_lock);
75411 + if (current->real_parent)
75412 + p = current->real_parent->role->rolename;
75413 + read_unlock(&tasklist_lock);
75414 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75415 + p, acl_sp_role_value);
75416 + } else {
75417 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75418 + error = -EPERM;
75419 + if(!(current->role->auth_attempts++))
75420 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75421 +
75422 + goto out;
75423 + }
75424 + break;
75425 + case GR_UNSPROLE:
75426 + if (unlikely(!gr_acl_is_enabled())) {
75427 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75428 + error = -EAGAIN;
75429 + break;
75430 + }
75431 +
75432 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75433 + char *p = "";
75434 + int i = 0;
75435 +
75436 + read_lock(&tasklist_lock);
75437 + if (current->real_parent) {
75438 + p = current->real_parent->role->rolename;
75439 + i = current->real_parent->acl_role_id;
75440 + }
75441 + read_unlock(&tasklist_lock);
75442 +
75443 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75444 + gr_set_acls(1);
75445 + } else {
75446 + error = -EPERM;
75447 + goto out;
75448 + }
75449 + break;
75450 + default:
75451 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75452 + error = -EINVAL;
75453 + break;
75454 + }
75455 +
75456 + if (error != -EPERM)
75457 + goto out;
75458 +
75459 + if(!(gr_auth_attempts++))
75460 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75461 +
75462 + out:
75463 + mutex_unlock(&gr_dev_mutex);
75464 +
75465 + if (!error)
75466 + error = req_count;
75467 +
75468 + return error;
75469 +}
75470 +
75471 +int
75472 +gr_set_acls(const int type)
75473 +{
75474 + struct task_struct *task, *task2;
75475 + struct acl_role_label *role = current->role;
75476 + struct acl_subject_label *subj;
75477 + __u16 acl_role_id = current->acl_role_id;
75478 + const struct cred *cred;
75479 + int ret;
75480 +
75481 + rcu_read_lock();
75482 + read_lock(&tasklist_lock);
75483 + read_lock(&grsec_exec_file_lock);
75484 + do_each_thread(task2, task) {
75485 + /* check to see if we're called from the exit handler,
75486 + if so, only replace ACLs that have inherited the admin
75487 + ACL */
75488 +
75489 + if (type && (task->role != role ||
75490 + task->acl_role_id != acl_role_id))
75491 + continue;
75492 +
75493 + task->acl_role_id = 0;
75494 + task->acl_sp_role = 0;
75495 + task->inherited = 0;
75496 +
75497 + if (task->exec_file) {
75498 + cred = __task_cred(task);
75499 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75500 + subj = __gr_get_subject_for_task(polstate, task, NULL, 1);
75501 + if (subj == NULL) {
75502 + ret = -EINVAL;
75503 + read_unlock(&grsec_exec_file_lock);
75504 + read_unlock(&tasklist_lock);
75505 + rcu_read_unlock();
75506 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75507 + return ret;
75508 + }
75509 + __gr_apply_subject_to_task(polstate, task, subj);
75510 + } else {
75511 + // it's a kernel process
75512 + task->role = polstate->kernel_role;
75513 + task->acl = polstate->kernel_role->root_label;
75514 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75515 + task->acl->mode &= ~GR_PROCFIND;
75516 +#endif
75517 + }
75518 + } while_each_thread(task2, task);
75519 + read_unlock(&grsec_exec_file_lock);
75520 + read_unlock(&tasklist_lock);
75521 + rcu_read_unlock();
75522 +
75523 + return 0;
75524 +}
75525 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75526 new file mode 100644
75527 index 0000000..39645c9
75528 --- /dev/null
75529 +++ b/grsecurity/gracl_res.c
75530 @@ -0,0 +1,68 @@
75531 +#include <linux/kernel.h>
75532 +#include <linux/sched.h>
75533 +#include <linux/gracl.h>
75534 +#include <linux/grinternal.h>
75535 +
75536 +static const char *restab_log[] = {
75537 + [RLIMIT_CPU] = "RLIMIT_CPU",
75538 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75539 + [RLIMIT_DATA] = "RLIMIT_DATA",
75540 + [RLIMIT_STACK] = "RLIMIT_STACK",
75541 + [RLIMIT_CORE] = "RLIMIT_CORE",
75542 + [RLIMIT_RSS] = "RLIMIT_RSS",
75543 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75544 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75545 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75546 + [RLIMIT_AS] = "RLIMIT_AS",
75547 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75548 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75549 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75550 + [RLIMIT_NICE] = "RLIMIT_NICE",
75551 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75552 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75553 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75554 +};
75555 +
75556 +void
75557 +gr_log_resource(const struct task_struct *task,
75558 + const int res, const unsigned long wanted, const int gt)
75559 +{
75560 + const struct cred *cred;
75561 + unsigned long rlim;
75562 +
75563 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75564 + return;
75565 +
75566 + // not yet supported resource
75567 + if (unlikely(!restab_log[res]))
75568 + return;
75569 +
75570 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75571 + rlim = task_rlimit_max(task, res);
75572 + else
75573 + rlim = task_rlimit(task, res);
75574 +
75575 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75576 + return;
75577 +
75578 + rcu_read_lock();
75579 + cred = __task_cred(task);
75580 +
75581 + if (res == RLIMIT_NPROC &&
75582 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75583 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75584 + goto out_rcu_unlock;
75585 + else if (res == RLIMIT_MEMLOCK &&
75586 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75587 + goto out_rcu_unlock;
75588 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75589 + goto out_rcu_unlock;
75590 + rcu_read_unlock();
75591 +
75592 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75593 +
75594 + return;
75595 +out_rcu_unlock:
75596 + rcu_read_unlock();
75597 + return;
75598 +}
75599 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75600 new file mode 100644
75601 index 0000000..2040e61
75602 --- /dev/null
75603 +++ b/grsecurity/gracl_segv.c
75604 @@ -0,0 +1,313 @@
75605 +#include <linux/kernel.h>
75606 +#include <linux/mm.h>
75607 +#include <asm/uaccess.h>
75608 +#include <asm/errno.h>
75609 +#include <asm/mman.h>
75610 +#include <net/sock.h>
75611 +#include <linux/file.h>
75612 +#include <linux/fs.h>
75613 +#include <linux/net.h>
75614 +#include <linux/in.h>
75615 +#include <linux/slab.h>
75616 +#include <linux/types.h>
75617 +#include <linux/sched.h>
75618 +#include <linux/timer.h>
75619 +#include <linux/gracl.h>
75620 +#include <linux/grsecurity.h>
75621 +#include <linux/grinternal.h>
75622 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75623 +#include <linux/magic.h>
75624 +#include <linux/pagemap.h>
75625 +#include "../fs/btrfs/async-thread.h"
75626 +#include "../fs/btrfs/ctree.h"
75627 +#include "../fs/btrfs/btrfs_inode.h"
75628 +#endif
75629 +
75630 +static struct crash_uid *uid_set;
75631 +static unsigned short uid_used;
75632 +static DEFINE_SPINLOCK(gr_uid_lock);
75633 +extern rwlock_t gr_inode_lock;
75634 +extern struct acl_subject_label *
75635 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75636 + struct acl_role_label *role);
75637 +
75638 +static inline dev_t __get_dev(const struct dentry *dentry)
75639 +{
75640 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75641 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75642 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75643 + else
75644 +#endif
75645 + return dentry->d_sb->s_dev;
75646 +}
75647 +
75648 +int
75649 +gr_init_uidset(void)
75650 +{
75651 + uid_set =
75652 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75653 + uid_used = 0;
75654 +
75655 + return uid_set ? 1 : 0;
75656 +}
75657 +
75658 +void
75659 +gr_free_uidset(void)
75660 +{
75661 + if (uid_set) {
75662 + struct crash_uid *tmpset;
75663 + spin_lock(&gr_uid_lock);
75664 + tmpset = uid_set;
75665 + uid_set = NULL;
75666 + uid_used = 0;
75667 + spin_unlock(&gr_uid_lock);
75668 + if (tmpset)
75669 + kfree(tmpset);
75670 + }
75671 +
75672 + return;
75673 +}
75674 +
75675 +int
75676 +gr_find_uid(const uid_t uid)
75677 +{
75678 + struct crash_uid *tmp = uid_set;
75679 + uid_t buid;
75680 + int low = 0, high = uid_used - 1, mid;
75681 +
75682 + while (high >= low) {
75683 + mid = (low + high) >> 1;
75684 + buid = tmp[mid].uid;
75685 + if (buid == uid)
75686 + return mid;
75687 + if (buid > uid)
75688 + high = mid - 1;
75689 + if (buid < uid)
75690 + low = mid + 1;
75691 + }
75692 +
75693 + return -1;
75694 +}
75695 +
75696 +static __inline__ void
75697 +gr_insertsort(void)
75698 +{
75699 + unsigned short i, j;
75700 + struct crash_uid index;
75701 +
75702 + for (i = 1; i < uid_used; i++) {
75703 + index = uid_set[i];
75704 + j = i;
75705 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75706 + uid_set[j] = uid_set[j - 1];
75707 + j--;
75708 + }
75709 + uid_set[j] = index;
75710 + }
75711 +
75712 + return;
75713 +}
75714 +
75715 +static __inline__ void
75716 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75717 +{
75718 + int loc;
75719 + uid_t uid = GR_GLOBAL_UID(kuid);
75720 +
75721 + if (uid_used == GR_UIDTABLE_MAX)
75722 + return;
75723 +
75724 + loc = gr_find_uid(uid);
75725 +
75726 + if (loc >= 0) {
75727 + uid_set[loc].expires = expires;
75728 + return;
75729 + }
75730 +
75731 + uid_set[uid_used].uid = uid;
75732 + uid_set[uid_used].expires = expires;
75733 + uid_used++;
75734 +
75735 + gr_insertsort();
75736 +
75737 + return;
75738 +}
75739 +
75740 +void
75741 +gr_remove_uid(const unsigned short loc)
75742 +{
75743 + unsigned short i;
75744 +
75745 + for (i = loc + 1; i < uid_used; i++)
75746 + uid_set[i - 1] = uid_set[i];
75747 +
75748 + uid_used--;
75749 +
75750 + return;
75751 +}
75752 +
75753 +int
75754 +gr_check_crash_uid(const kuid_t kuid)
75755 +{
75756 + int loc;
75757 + int ret = 0;
75758 + uid_t uid;
75759 +
75760 + if (unlikely(!gr_acl_is_enabled()))
75761 + return 0;
75762 +
75763 + uid = GR_GLOBAL_UID(kuid);
75764 +
75765 + spin_lock(&gr_uid_lock);
75766 + loc = gr_find_uid(uid);
75767 +
75768 + if (loc < 0)
75769 + goto out_unlock;
75770 +
75771 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75772 + gr_remove_uid(loc);
75773 + else
75774 + ret = 1;
75775 +
75776 +out_unlock:
75777 + spin_unlock(&gr_uid_lock);
75778 + return ret;
75779 +}
75780 +
75781 +static __inline__ int
75782 +proc_is_setxid(const struct cred *cred)
75783 +{
75784 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75785 + !uid_eq(cred->uid, cred->fsuid))
75786 + return 1;
75787 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75788 + !gid_eq(cred->gid, cred->fsgid))
75789 + return 1;
75790 +
75791 + return 0;
75792 +}
75793 +
75794 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75795 +
75796 +void
75797 +gr_handle_crash(struct task_struct *task, const int sig)
75798 +{
75799 + struct acl_subject_label *curr;
75800 + struct task_struct *tsk, *tsk2;
75801 + const struct cred *cred;
75802 + const struct cred *cred2;
75803 +
75804 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75805 + return;
75806 +
75807 + if (unlikely(!gr_acl_is_enabled()))
75808 + return;
75809 +
75810 + curr = task->acl;
75811 +
75812 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75813 + return;
75814 +
75815 + if (time_before_eq(curr->expires, get_seconds())) {
75816 + curr->expires = 0;
75817 + curr->crashes = 0;
75818 + }
75819 +
75820 + curr->crashes++;
75821 +
75822 + if (!curr->expires)
75823 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75824 +
75825 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75826 + time_after(curr->expires, get_seconds())) {
75827 + rcu_read_lock();
75828 + cred = __task_cred(task);
75829 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75830 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75831 + spin_lock(&gr_uid_lock);
75832 + gr_insert_uid(cred->uid, curr->expires);
75833 + spin_unlock(&gr_uid_lock);
75834 + curr->expires = 0;
75835 + curr->crashes = 0;
75836 + read_lock(&tasklist_lock);
75837 + do_each_thread(tsk2, tsk) {
75838 + cred2 = __task_cred(tsk);
75839 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75840 + gr_fake_force_sig(SIGKILL, tsk);
75841 + } while_each_thread(tsk2, tsk);
75842 + read_unlock(&tasklist_lock);
75843 + } else {
75844 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75845 + read_lock(&tasklist_lock);
75846 + read_lock(&grsec_exec_file_lock);
75847 + do_each_thread(tsk2, tsk) {
75848 + if (likely(tsk != task)) {
75849 + // if this thread has the same subject as the one that triggered
75850 + // RES_CRASH and it's the same binary, kill it
75851 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75852 + gr_fake_force_sig(SIGKILL, tsk);
75853 + }
75854 + } while_each_thread(tsk2, tsk);
75855 + read_unlock(&grsec_exec_file_lock);
75856 + read_unlock(&tasklist_lock);
75857 + }
75858 + rcu_read_unlock();
75859 + }
75860 +
75861 + return;
75862 +}
75863 +
75864 +int
75865 +gr_check_crash_exec(const struct file *filp)
75866 +{
75867 + struct acl_subject_label *curr;
75868 +
75869 + if (unlikely(!gr_acl_is_enabled()))
75870 + return 0;
75871 +
75872 + read_lock(&gr_inode_lock);
75873 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75874 + __get_dev(filp->f_path.dentry),
75875 + current->role);
75876 + read_unlock(&gr_inode_lock);
75877 +
75878 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75879 + (!curr->crashes && !curr->expires))
75880 + return 0;
75881 +
75882 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75883 + time_after(curr->expires, get_seconds()))
75884 + return 1;
75885 + else if (time_before_eq(curr->expires, get_seconds())) {
75886 + curr->crashes = 0;
75887 + curr->expires = 0;
75888 + }
75889 +
75890 + return 0;
75891 +}
75892 +
75893 +void
75894 +gr_handle_alertkill(struct task_struct *task)
75895 +{
75896 + struct acl_subject_label *curracl;
75897 + __u32 curr_ip;
75898 + struct task_struct *p, *p2;
75899 +
75900 + if (unlikely(!gr_acl_is_enabled()))
75901 + return;
75902 +
75903 + curracl = task->acl;
75904 + curr_ip = task->signal->curr_ip;
75905 +
75906 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75907 + read_lock(&tasklist_lock);
75908 + do_each_thread(p2, p) {
75909 + if (p->signal->curr_ip == curr_ip)
75910 + gr_fake_force_sig(SIGKILL, p);
75911 + } while_each_thread(p2, p);
75912 + read_unlock(&tasklist_lock);
75913 + } else if (curracl->mode & GR_KILLPROC)
75914 + gr_fake_force_sig(SIGKILL, task);
75915 +
75916 + return;
75917 +}
75918 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75919 new file mode 100644
75920 index 0000000..6b0c9cc
75921 --- /dev/null
75922 +++ b/grsecurity/gracl_shm.c
75923 @@ -0,0 +1,40 @@
75924 +#include <linux/kernel.h>
75925 +#include <linux/mm.h>
75926 +#include <linux/sched.h>
75927 +#include <linux/file.h>
75928 +#include <linux/ipc.h>
75929 +#include <linux/gracl.h>
75930 +#include <linux/grsecurity.h>
75931 +#include <linux/grinternal.h>
75932 +
75933 +int
75934 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75935 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
75936 +{
75937 + struct task_struct *task;
75938 +
75939 + if (!gr_acl_is_enabled())
75940 + return 1;
75941 +
75942 + rcu_read_lock();
75943 + read_lock(&tasklist_lock);
75944 +
75945 + task = find_task_by_vpid(shm_cprid);
75946 +
75947 + if (unlikely(!task))
75948 + task = find_task_by_vpid(shm_lapid);
75949 +
75950 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75951 + (task_pid_nr(task) == shm_lapid)) &&
75952 + (task->acl->mode & GR_PROTSHM) &&
75953 + (task->acl != current->acl))) {
75954 + read_unlock(&tasklist_lock);
75955 + rcu_read_unlock();
75956 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
75957 + return 0;
75958 + }
75959 + read_unlock(&tasklist_lock);
75960 + rcu_read_unlock();
75961 +
75962 + return 1;
75963 +}
75964 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
75965 new file mode 100644
75966 index 0000000..bc0be01
75967 --- /dev/null
75968 +++ b/grsecurity/grsec_chdir.c
75969 @@ -0,0 +1,19 @@
75970 +#include <linux/kernel.h>
75971 +#include <linux/sched.h>
75972 +#include <linux/fs.h>
75973 +#include <linux/file.h>
75974 +#include <linux/grsecurity.h>
75975 +#include <linux/grinternal.h>
75976 +
75977 +void
75978 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
75979 +{
75980 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75981 + if ((grsec_enable_chdir && grsec_enable_group &&
75982 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
75983 + !grsec_enable_group)) {
75984 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
75985 + }
75986 +#endif
75987 + return;
75988 +}
75989 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
75990 new file mode 100644
75991 index 0000000..114ea4f
75992 --- /dev/null
75993 +++ b/grsecurity/grsec_chroot.c
75994 @@ -0,0 +1,467 @@
75995 +#include <linux/kernel.h>
75996 +#include <linux/module.h>
75997 +#include <linux/sched.h>
75998 +#include <linux/file.h>
75999 +#include <linux/fs.h>
76000 +#include <linux/mount.h>
76001 +#include <linux/types.h>
76002 +#include "../fs/mount.h"
76003 +#include <linux/grsecurity.h>
76004 +#include <linux/grinternal.h>
76005 +
76006 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76007 +int gr_init_ran;
76008 +#endif
76009 +
76010 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76011 +{
76012 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76013 + struct dentry *tmpd = dentry;
76014 +
76015 + read_seqlock_excl(&mount_lock);
76016 + write_seqlock(&rename_lock);
76017 +
76018 + while (tmpd != mnt->mnt_root) {
76019 + atomic_inc(&tmpd->chroot_refcnt);
76020 + tmpd = tmpd->d_parent;
76021 + }
76022 + atomic_inc(&tmpd->chroot_refcnt);
76023 +
76024 + write_sequnlock(&rename_lock);
76025 + read_sequnlock_excl(&mount_lock);
76026 +#endif
76027 +}
76028 +
76029 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76030 +{
76031 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76032 + struct dentry *tmpd = dentry;
76033 +
76034 + read_seqlock_excl(&mount_lock);
76035 + write_seqlock(&rename_lock);
76036 +
76037 + while (tmpd != mnt->mnt_root) {
76038 + atomic_dec(&tmpd->chroot_refcnt);
76039 + tmpd = tmpd->d_parent;
76040 + }
76041 + atomic_dec(&tmpd->chroot_refcnt);
76042 +
76043 + write_sequnlock(&rename_lock);
76044 + read_sequnlock_excl(&mount_lock);
76045 +#endif
76046 +}
76047 +
76048 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76049 +static struct dentry *get_closest_chroot(struct dentry *dentry)
76050 +{
76051 + write_seqlock(&rename_lock);
76052 + do {
76053 + if (atomic_read(&dentry->chroot_refcnt)) {
76054 + write_sequnlock(&rename_lock);
76055 + return dentry;
76056 + }
76057 + dentry = dentry->d_parent;
76058 + } while (!IS_ROOT(dentry));
76059 + write_sequnlock(&rename_lock);
76060 + return NULL;
76061 +}
76062 +#endif
76063 +
76064 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
76065 + struct dentry *newdentry, struct vfsmount *newmnt)
76066 +{
76067 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76068 + struct dentry *chroot;
76069 +
76070 + if (unlikely(!grsec_enable_chroot_rename))
76071 + return 0;
76072 +
76073 + if (likely(!proc_is_chrooted(current) && gr_is_global_root(current_uid())))
76074 + return 0;
76075 +
76076 + chroot = get_closest_chroot(olddentry);
76077 +
76078 + if (chroot == NULL)
76079 + return 0;
76080 +
76081 + if (is_subdir(newdentry, chroot))
76082 + return 0;
76083 +
76084 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_RENAME_MSG, olddentry, oldmnt);
76085 +
76086 + return 1;
76087 +#else
76088 + return 0;
76089 +#endif
76090 +}
76091 +
76092 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76093 +{
76094 +#ifdef CONFIG_GRKERNSEC
76095 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76096 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76097 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76098 + && gr_init_ran
76099 +#endif
76100 + )
76101 + task->gr_is_chrooted = 1;
76102 + else {
76103 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76104 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76105 + gr_init_ran = 1;
76106 +#endif
76107 + task->gr_is_chrooted = 0;
76108 + }
76109 +
76110 + task->gr_chroot_dentry = path->dentry;
76111 +#endif
76112 + return;
76113 +}
76114 +
76115 +void gr_clear_chroot_entries(struct task_struct *task)
76116 +{
76117 +#ifdef CONFIG_GRKERNSEC
76118 + task->gr_is_chrooted = 0;
76119 + task->gr_chroot_dentry = NULL;
76120 +#endif
76121 + return;
76122 +}
76123 +
76124 +int
76125 +gr_handle_chroot_unix(const pid_t pid)
76126 +{
76127 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76128 + struct task_struct *p;
76129 +
76130 + if (unlikely(!grsec_enable_chroot_unix))
76131 + return 1;
76132 +
76133 + if (likely(!proc_is_chrooted(current)))
76134 + return 1;
76135 +
76136 + rcu_read_lock();
76137 + read_lock(&tasklist_lock);
76138 + p = find_task_by_vpid_unrestricted(pid);
76139 + if (unlikely(p && !have_same_root(current, p))) {
76140 + read_unlock(&tasklist_lock);
76141 + rcu_read_unlock();
76142 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76143 + return 0;
76144 + }
76145 + read_unlock(&tasklist_lock);
76146 + rcu_read_unlock();
76147 +#endif
76148 + return 1;
76149 +}
76150 +
76151 +int
76152 +gr_handle_chroot_nice(void)
76153 +{
76154 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76155 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76156 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76157 + return -EPERM;
76158 + }
76159 +#endif
76160 + return 0;
76161 +}
76162 +
76163 +int
76164 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76165 +{
76166 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76167 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76168 + && proc_is_chrooted(current)) {
76169 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76170 + return -EACCES;
76171 + }
76172 +#endif
76173 + return 0;
76174 +}
76175 +
76176 +int
76177 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76178 +{
76179 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76180 + struct task_struct *p;
76181 + int ret = 0;
76182 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76183 + return ret;
76184 +
76185 + read_lock(&tasklist_lock);
76186 + do_each_pid_task(pid, type, p) {
76187 + if (!have_same_root(current, p)) {
76188 + ret = 1;
76189 + goto out;
76190 + }
76191 + } while_each_pid_task(pid, type, p);
76192 +out:
76193 + read_unlock(&tasklist_lock);
76194 + return ret;
76195 +#endif
76196 + return 0;
76197 +}
76198 +
76199 +int
76200 +gr_pid_is_chrooted(struct task_struct *p)
76201 +{
76202 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76203 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76204 + return 0;
76205 +
76206 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76207 + !have_same_root(current, p)) {
76208 + return 1;
76209 + }
76210 +#endif
76211 + return 0;
76212 +}
76213 +
76214 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76215 +
76216 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76217 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76218 +{
76219 + struct path path, currentroot;
76220 + int ret = 0;
76221 +
76222 + path.dentry = (struct dentry *)u_dentry;
76223 + path.mnt = (struct vfsmount *)u_mnt;
76224 + get_fs_root(current->fs, &currentroot);
76225 + if (path_is_under(&path, &currentroot))
76226 + ret = 1;
76227 + path_put(&currentroot);
76228 +
76229 + return ret;
76230 +}
76231 +#endif
76232 +
76233 +int
76234 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76235 +{
76236 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76237 + if (!grsec_enable_chroot_fchdir)
76238 + return 1;
76239 +
76240 + if (!proc_is_chrooted(current))
76241 + return 1;
76242 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76243 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76244 + return 0;
76245 + }
76246 +#endif
76247 + return 1;
76248 +}
76249 +
76250 +int
76251 +gr_chroot_fhandle(void)
76252 +{
76253 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76254 + if (!grsec_enable_chroot_fchdir)
76255 + return 1;
76256 +
76257 + if (!proc_is_chrooted(current))
76258 + return 1;
76259 + else {
76260 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76261 + return 0;
76262 + }
76263 +#endif
76264 + return 1;
76265 +}
76266 +
76267 +int
76268 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76269 + const u64 shm_createtime)
76270 +{
76271 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76272 + struct task_struct *p;
76273 +
76274 + if (unlikely(!grsec_enable_chroot_shmat))
76275 + return 1;
76276 +
76277 + if (likely(!proc_is_chrooted(current)))
76278 + return 1;
76279 +
76280 + rcu_read_lock();
76281 + read_lock(&tasklist_lock);
76282 +
76283 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76284 + if (time_before_eq64(p->start_time, shm_createtime)) {
76285 + if (have_same_root(current, p)) {
76286 + goto allow;
76287 + } else {
76288 + read_unlock(&tasklist_lock);
76289 + rcu_read_unlock();
76290 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76291 + return 0;
76292 + }
76293 + }
76294 + /* creator exited, pid reuse, fall through to next check */
76295 + }
76296 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76297 + if (unlikely(!have_same_root(current, p))) {
76298 + read_unlock(&tasklist_lock);
76299 + rcu_read_unlock();
76300 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76301 + return 0;
76302 + }
76303 + }
76304 +
76305 +allow:
76306 + read_unlock(&tasklist_lock);
76307 + rcu_read_unlock();
76308 +#endif
76309 + return 1;
76310 +}
76311 +
76312 +void
76313 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76314 +{
76315 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76316 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76317 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76318 +#endif
76319 + return;
76320 +}
76321 +
76322 +int
76323 +gr_handle_chroot_mknod(const struct dentry *dentry,
76324 + const struct vfsmount *mnt, const int mode)
76325 +{
76326 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76327 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76328 + proc_is_chrooted(current)) {
76329 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76330 + return -EPERM;
76331 + }
76332 +#endif
76333 + return 0;
76334 +}
76335 +
76336 +int
76337 +gr_handle_chroot_mount(const struct dentry *dentry,
76338 + const struct vfsmount *mnt, const char *dev_name)
76339 +{
76340 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76341 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76342 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76343 + return -EPERM;
76344 + }
76345 +#endif
76346 + return 0;
76347 +}
76348 +
76349 +int
76350 +gr_handle_chroot_pivot(void)
76351 +{
76352 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76353 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76354 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76355 + return -EPERM;
76356 + }
76357 +#endif
76358 + return 0;
76359 +}
76360 +
76361 +int
76362 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76363 +{
76364 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76365 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76366 + !gr_is_outside_chroot(dentry, mnt)) {
76367 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76368 + return -EPERM;
76369 + }
76370 +#endif
76371 + return 0;
76372 +}
76373 +
76374 +extern const char *captab_log[];
76375 +extern int captab_log_entries;
76376 +
76377 +int
76378 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76379 +{
76380 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76381 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76382 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76383 + if (cap_raised(chroot_caps, cap)) {
76384 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76385 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76386 + }
76387 + return 0;
76388 + }
76389 + }
76390 +#endif
76391 + return 1;
76392 +}
76393 +
76394 +int
76395 +gr_chroot_is_capable(const int cap)
76396 +{
76397 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76398 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76399 +#endif
76400 + return 1;
76401 +}
76402 +
76403 +int
76404 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76405 +{
76406 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76407 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76408 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76409 + if (cap_raised(chroot_caps, cap)) {
76410 + return 0;
76411 + }
76412 + }
76413 +#endif
76414 + return 1;
76415 +}
76416 +
76417 +int
76418 +gr_chroot_is_capable_nolog(const int cap)
76419 +{
76420 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76421 + return gr_task_chroot_is_capable_nolog(current, cap);
76422 +#endif
76423 + return 1;
76424 +}
76425 +
76426 +int
76427 +gr_handle_chroot_sysctl(const int op)
76428 +{
76429 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76430 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76431 + proc_is_chrooted(current))
76432 + return -EACCES;
76433 +#endif
76434 + return 0;
76435 +}
76436 +
76437 +void
76438 +gr_handle_chroot_chdir(const struct path *path)
76439 +{
76440 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76441 + if (grsec_enable_chroot_chdir)
76442 + set_fs_pwd(current->fs, path);
76443 +#endif
76444 + return;
76445 +}
76446 +
76447 +int
76448 +gr_handle_chroot_chmod(const struct dentry *dentry,
76449 + const struct vfsmount *mnt, const int mode)
76450 +{
76451 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76452 + /* allow chmod +s on directories, but not files */
76453 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76454 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76455 + proc_is_chrooted(current)) {
76456 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76457 + return -EPERM;
76458 + }
76459 +#endif
76460 + return 0;
76461 +}
76462 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76463 new file mode 100644
76464 index 0000000..0f9ac91
76465 --- /dev/null
76466 +++ b/grsecurity/grsec_disabled.c
76467 @@ -0,0 +1,440 @@
76468 +#include <linux/kernel.h>
76469 +#include <linux/module.h>
76470 +#include <linux/sched.h>
76471 +#include <linux/file.h>
76472 +#include <linux/fs.h>
76473 +#include <linux/kdev_t.h>
76474 +#include <linux/net.h>
76475 +#include <linux/in.h>
76476 +#include <linux/ip.h>
76477 +#include <linux/skbuff.h>
76478 +#include <linux/sysctl.h>
76479 +
76480 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76481 +void
76482 +pax_set_initial_flags(struct linux_binprm *bprm)
76483 +{
76484 + return;
76485 +}
76486 +#endif
76487 +
76488 +#ifdef CONFIG_SYSCTL
76489 +__u32
76490 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76491 +{
76492 + return 0;
76493 +}
76494 +#endif
76495 +
76496 +#ifdef CONFIG_TASKSTATS
76497 +int gr_is_taskstats_denied(int pid)
76498 +{
76499 + return 0;
76500 +}
76501 +#endif
76502 +
76503 +int
76504 +gr_acl_is_enabled(void)
76505 +{
76506 + return 0;
76507 +}
76508 +
76509 +int
76510 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76511 +{
76512 + return 0;
76513 +}
76514 +
76515 +void
76516 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76517 +{
76518 + return;
76519 +}
76520 +
76521 +int
76522 +gr_handle_rawio(const struct inode *inode)
76523 +{
76524 + return 0;
76525 +}
76526 +
76527 +void
76528 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76529 +{
76530 + return;
76531 +}
76532 +
76533 +int
76534 +gr_handle_ptrace(struct task_struct *task, const long request)
76535 +{
76536 + return 0;
76537 +}
76538 +
76539 +int
76540 +gr_handle_proc_ptrace(struct task_struct *task)
76541 +{
76542 + return 0;
76543 +}
76544 +
76545 +int
76546 +gr_set_acls(const int type)
76547 +{
76548 + return 0;
76549 +}
76550 +
76551 +int
76552 +gr_check_hidden_task(const struct task_struct *tsk)
76553 +{
76554 + return 0;
76555 +}
76556 +
76557 +int
76558 +gr_check_protected_task(const struct task_struct *task)
76559 +{
76560 + return 0;
76561 +}
76562 +
76563 +int
76564 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76565 +{
76566 + return 0;
76567 +}
76568 +
76569 +void
76570 +gr_copy_label(struct task_struct *tsk)
76571 +{
76572 + return;
76573 +}
76574 +
76575 +void
76576 +gr_set_pax_flags(struct task_struct *task)
76577 +{
76578 + return;
76579 +}
76580 +
76581 +int
76582 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76583 + const int unsafe_share)
76584 +{
76585 + return 0;
76586 +}
76587 +
76588 +void
76589 +gr_handle_delete(const ino_t ino, const dev_t dev)
76590 +{
76591 + return;
76592 +}
76593 +
76594 +void
76595 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76596 +{
76597 + return;
76598 +}
76599 +
76600 +void
76601 +gr_handle_crash(struct task_struct *task, const int sig)
76602 +{
76603 + return;
76604 +}
76605 +
76606 +int
76607 +gr_check_crash_exec(const struct file *filp)
76608 +{
76609 + return 0;
76610 +}
76611 +
76612 +int
76613 +gr_check_crash_uid(const kuid_t uid)
76614 +{
76615 + return 0;
76616 +}
76617 +
76618 +void
76619 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76620 + struct dentry *old_dentry,
76621 + struct dentry *new_dentry,
76622 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76623 +{
76624 + return;
76625 +}
76626 +
76627 +int
76628 +gr_search_socket(const int family, const int type, const int protocol)
76629 +{
76630 + return 1;
76631 +}
76632 +
76633 +int
76634 +gr_search_connectbind(const int mode, const struct socket *sock,
76635 + const struct sockaddr_in *addr)
76636 +{
76637 + return 0;
76638 +}
76639 +
76640 +void
76641 +gr_handle_alertkill(struct task_struct *task)
76642 +{
76643 + return;
76644 +}
76645 +
76646 +__u32
76647 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76648 +{
76649 + return 1;
76650 +}
76651 +
76652 +__u32
76653 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76654 + const struct vfsmount * mnt)
76655 +{
76656 + return 1;
76657 +}
76658 +
76659 +__u32
76660 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76661 + int acc_mode)
76662 +{
76663 + return 1;
76664 +}
76665 +
76666 +__u32
76667 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76668 +{
76669 + return 1;
76670 +}
76671 +
76672 +__u32
76673 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76674 +{
76675 + return 1;
76676 +}
76677 +
76678 +int
76679 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76680 + unsigned int *vm_flags)
76681 +{
76682 + return 1;
76683 +}
76684 +
76685 +__u32
76686 +gr_acl_handle_truncate(const struct dentry * dentry,
76687 + const struct vfsmount * mnt)
76688 +{
76689 + return 1;
76690 +}
76691 +
76692 +__u32
76693 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76694 +{
76695 + return 1;
76696 +}
76697 +
76698 +__u32
76699 +gr_acl_handle_access(const struct dentry * dentry,
76700 + const struct vfsmount * mnt, const int fmode)
76701 +{
76702 + return 1;
76703 +}
76704 +
76705 +__u32
76706 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76707 + umode_t *mode)
76708 +{
76709 + return 1;
76710 +}
76711 +
76712 +__u32
76713 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76714 +{
76715 + return 1;
76716 +}
76717 +
76718 +__u32
76719 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76720 +{
76721 + return 1;
76722 +}
76723 +
76724 +__u32
76725 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76726 +{
76727 + return 1;
76728 +}
76729 +
76730 +void
76731 +grsecurity_init(void)
76732 +{
76733 + return;
76734 +}
76735 +
76736 +umode_t gr_acl_umask(void)
76737 +{
76738 + return 0;
76739 +}
76740 +
76741 +__u32
76742 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76743 + const struct dentry * parent_dentry,
76744 + const struct vfsmount * parent_mnt,
76745 + const int mode)
76746 +{
76747 + return 1;
76748 +}
76749 +
76750 +__u32
76751 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76752 + const struct dentry * parent_dentry,
76753 + const struct vfsmount * parent_mnt)
76754 +{
76755 + return 1;
76756 +}
76757 +
76758 +__u32
76759 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76760 + const struct dentry * parent_dentry,
76761 + const struct vfsmount * parent_mnt, const struct filename *from)
76762 +{
76763 + return 1;
76764 +}
76765 +
76766 +__u32
76767 +gr_acl_handle_link(const struct dentry * new_dentry,
76768 + const struct dentry * parent_dentry,
76769 + const struct vfsmount * parent_mnt,
76770 + const struct dentry * old_dentry,
76771 + const struct vfsmount * old_mnt, const struct filename *to)
76772 +{
76773 + return 1;
76774 +}
76775 +
76776 +int
76777 +gr_acl_handle_rename(const struct dentry *new_dentry,
76778 + const struct dentry *parent_dentry,
76779 + const struct vfsmount *parent_mnt,
76780 + const struct dentry *old_dentry,
76781 + const struct inode *old_parent_inode,
76782 + const struct vfsmount *old_mnt, const struct filename *newname,
76783 + unsigned int flags)
76784 +{
76785 + return 0;
76786 +}
76787 +
76788 +int
76789 +gr_acl_handle_filldir(const struct file *file, const char *name,
76790 + const int namelen, const ino_t ino)
76791 +{
76792 + return 1;
76793 +}
76794 +
76795 +int
76796 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76797 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76798 +{
76799 + return 1;
76800 +}
76801 +
76802 +int
76803 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76804 +{
76805 + return 0;
76806 +}
76807 +
76808 +int
76809 +gr_search_accept(const struct socket *sock)
76810 +{
76811 + return 0;
76812 +}
76813 +
76814 +int
76815 +gr_search_listen(const struct socket *sock)
76816 +{
76817 + return 0;
76818 +}
76819 +
76820 +int
76821 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76822 +{
76823 + return 0;
76824 +}
76825 +
76826 +__u32
76827 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76828 +{
76829 + return 1;
76830 +}
76831 +
76832 +__u32
76833 +gr_acl_handle_creat(const struct dentry * dentry,
76834 + const struct dentry * p_dentry,
76835 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76836 + const int imode)
76837 +{
76838 + return 1;
76839 +}
76840 +
76841 +void
76842 +gr_acl_handle_exit(void)
76843 +{
76844 + return;
76845 +}
76846 +
76847 +int
76848 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76849 +{
76850 + return 1;
76851 +}
76852 +
76853 +void
76854 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76855 +{
76856 + return;
76857 +}
76858 +
76859 +int
76860 +gr_acl_handle_procpidmem(const struct task_struct *task)
76861 +{
76862 + return 0;
76863 +}
76864 +
76865 +int
76866 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76867 +{
76868 + return 0;
76869 +}
76870 +
76871 +int
76872 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76873 +{
76874 + return 0;
76875 +}
76876 +
76877 +int
76878 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76879 +{
76880 + return 0;
76881 +}
76882 +
76883 +int
76884 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76885 +{
76886 + return 0;
76887 +}
76888 +
76889 +int gr_acl_enable_at_secure(void)
76890 +{
76891 + return 0;
76892 +}
76893 +
76894 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76895 +{
76896 + return dentry->d_sb->s_dev;
76897 +}
76898 +
76899 +void gr_put_exec_file(struct task_struct *task)
76900 +{
76901 + return;
76902 +}
76903 +
76904 +#ifdef CONFIG_SECURITY
76905 +EXPORT_SYMBOL_GPL(gr_check_user_change);
76906 +EXPORT_SYMBOL_GPL(gr_check_group_change);
76907 +#endif
76908 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76909 new file mode 100644
76910 index 0000000..14638ff
76911 --- /dev/null
76912 +++ b/grsecurity/grsec_exec.c
76913 @@ -0,0 +1,188 @@
76914 +#include <linux/kernel.h>
76915 +#include <linux/sched.h>
76916 +#include <linux/file.h>
76917 +#include <linux/binfmts.h>
76918 +#include <linux/fs.h>
76919 +#include <linux/types.h>
76920 +#include <linux/grdefs.h>
76921 +#include <linux/grsecurity.h>
76922 +#include <linux/grinternal.h>
76923 +#include <linux/capability.h>
76924 +#include <linux/module.h>
76925 +#include <linux/compat.h>
76926 +
76927 +#include <asm/uaccess.h>
76928 +
76929 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76930 +static char gr_exec_arg_buf[132];
76931 +static DEFINE_MUTEX(gr_exec_arg_mutex);
76932 +#endif
76933 +
76934 +struct user_arg_ptr {
76935 +#ifdef CONFIG_COMPAT
76936 + bool is_compat;
76937 +#endif
76938 + union {
76939 + const char __user *const __user *native;
76940 +#ifdef CONFIG_COMPAT
76941 + const compat_uptr_t __user *compat;
76942 +#endif
76943 + } ptr;
76944 +};
76945 +
76946 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76947 +
76948 +void
76949 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76950 +{
76951 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76952 + char *grarg = gr_exec_arg_buf;
76953 + unsigned int i, x, execlen = 0;
76954 + char c;
76955 +
76956 + if (!((grsec_enable_execlog && grsec_enable_group &&
76957 + in_group_p(grsec_audit_gid))
76958 + || (grsec_enable_execlog && !grsec_enable_group)))
76959 + return;
76960 +
76961 + mutex_lock(&gr_exec_arg_mutex);
76962 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
76963 +
76964 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
76965 + const char __user *p;
76966 + unsigned int len;
76967 +
76968 + p = get_user_arg_ptr(argv, i);
76969 + if (IS_ERR(p))
76970 + goto log;
76971 +
76972 + len = strnlen_user(p, 128 - execlen);
76973 + if (len > 128 - execlen)
76974 + len = 128 - execlen;
76975 + else if (len > 0)
76976 + len--;
76977 + if (copy_from_user(grarg + execlen, p, len))
76978 + goto log;
76979 +
76980 + /* rewrite unprintable characters */
76981 + for (x = 0; x < len; x++) {
76982 + c = *(grarg + execlen + x);
76983 + if (c < 32 || c > 126)
76984 + *(grarg + execlen + x) = ' ';
76985 + }
76986 +
76987 + execlen += len;
76988 + *(grarg + execlen) = ' ';
76989 + *(grarg + execlen + 1) = '\0';
76990 + execlen++;
76991 + }
76992 +
76993 + log:
76994 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76995 + bprm->file->f_path.mnt, grarg);
76996 + mutex_unlock(&gr_exec_arg_mutex);
76997 +#endif
76998 + return;
76999 +}
77000 +
77001 +#ifdef CONFIG_GRKERNSEC
77002 +extern int gr_acl_is_capable(const int cap);
77003 +extern int gr_acl_is_capable_nolog(const int cap);
77004 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77005 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77006 +extern int gr_chroot_is_capable(const int cap);
77007 +extern int gr_chroot_is_capable_nolog(const int cap);
77008 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77009 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77010 +#endif
77011 +
77012 +const char *captab_log[] = {
77013 + "CAP_CHOWN",
77014 + "CAP_DAC_OVERRIDE",
77015 + "CAP_DAC_READ_SEARCH",
77016 + "CAP_FOWNER",
77017 + "CAP_FSETID",
77018 + "CAP_KILL",
77019 + "CAP_SETGID",
77020 + "CAP_SETUID",
77021 + "CAP_SETPCAP",
77022 + "CAP_LINUX_IMMUTABLE",
77023 + "CAP_NET_BIND_SERVICE",
77024 + "CAP_NET_BROADCAST",
77025 + "CAP_NET_ADMIN",
77026 + "CAP_NET_RAW",
77027 + "CAP_IPC_LOCK",
77028 + "CAP_IPC_OWNER",
77029 + "CAP_SYS_MODULE",
77030 + "CAP_SYS_RAWIO",
77031 + "CAP_SYS_CHROOT",
77032 + "CAP_SYS_PTRACE",
77033 + "CAP_SYS_PACCT",
77034 + "CAP_SYS_ADMIN",
77035 + "CAP_SYS_BOOT",
77036 + "CAP_SYS_NICE",
77037 + "CAP_SYS_RESOURCE",
77038 + "CAP_SYS_TIME",
77039 + "CAP_SYS_TTY_CONFIG",
77040 + "CAP_MKNOD",
77041 + "CAP_LEASE",
77042 + "CAP_AUDIT_WRITE",
77043 + "CAP_AUDIT_CONTROL",
77044 + "CAP_SETFCAP",
77045 + "CAP_MAC_OVERRIDE",
77046 + "CAP_MAC_ADMIN",
77047 + "CAP_SYSLOG",
77048 + "CAP_WAKE_ALARM",
77049 + "CAP_BLOCK_SUSPEND"
77050 +};
77051 +
77052 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77053 +
77054 +int gr_is_capable(const int cap)
77055 +{
77056 +#ifdef CONFIG_GRKERNSEC
77057 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77058 + return 1;
77059 + return 0;
77060 +#else
77061 + return 1;
77062 +#endif
77063 +}
77064 +
77065 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77066 +{
77067 +#ifdef CONFIG_GRKERNSEC
77068 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77069 + return 1;
77070 + return 0;
77071 +#else
77072 + return 1;
77073 +#endif
77074 +}
77075 +
77076 +int gr_is_capable_nolog(const int cap)
77077 +{
77078 +#ifdef CONFIG_GRKERNSEC
77079 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77080 + return 1;
77081 + return 0;
77082 +#else
77083 + return 1;
77084 +#endif
77085 +}
77086 +
77087 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77088 +{
77089 +#ifdef CONFIG_GRKERNSEC
77090 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77091 + return 1;
77092 + return 0;
77093 +#else
77094 + return 1;
77095 +#endif
77096 +}
77097 +
77098 +EXPORT_SYMBOL_GPL(gr_is_capable);
77099 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77100 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77101 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77102 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77103 new file mode 100644
77104 index 0000000..06cc6ea
77105 --- /dev/null
77106 +++ b/grsecurity/grsec_fifo.c
77107 @@ -0,0 +1,24 @@
77108 +#include <linux/kernel.h>
77109 +#include <linux/sched.h>
77110 +#include <linux/fs.h>
77111 +#include <linux/file.h>
77112 +#include <linux/grinternal.h>
77113 +
77114 +int
77115 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77116 + const struct dentry *dir, const int flag, const int acc_mode)
77117 +{
77118 +#ifdef CONFIG_GRKERNSEC_FIFO
77119 + const struct cred *cred = current_cred();
77120 +
77121 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77122 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77123 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77124 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77125 + if (!inode_permission(dentry->d_inode, acc_mode))
77126 + 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));
77127 + return -EACCES;
77128 + }
77129 +#endif
77130 + return 0;
77131 +}
77132 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77133 new file mode 100644
77134 index 0000000..8ca18bf
77135 --- /dev/null
77136 +++ b/grsecurity/grsec_fork.c
77137 @@ -0,0 +1,23 @@
77138 +#include <linux/kernel.h>
77139 +#include <linux/sched.h>
77140 +#include <linux/grsecurity.h>
77141 +#include <linux/grinternal.h>
77142 +#include <linux/errno.h>
77143 +
77144 +void
77145 +gr_log_forkfail(const int retval)
77146 +{
77147 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77148 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77149 + switch (retval) {
77150 + case -EAGAIN:
77151 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77152 + break;
77153 + case -ENOMEM:
77154 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77155 + break;
77156 + }
77157 + }
77158 +#endif
77159 + return;
77160 +}
77161 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77162 new file mode 100644
77163 index 0000000..4ed9e7d
77164 --- /dev/null
77165 +++ b/grsecurity/grsec_init.c
77166 @@ -0,0 +1,290 @@
77167 +#include <linux/kernel.h>
77168 +#include <linux/sched.h>
77169 +#include <linux/mm.h>
77170 +#include <linux/gracl.h>
77171 +#include <linux/slab.h>
77172 +#include <linux/vmalloc.h>
77173 +#include <linux/percpu.h>
77174 +#include <linux/module.h>
77175 +
77176 +int grsec_enable_ptrace_readexec;
77177 +int grsec_enable_setxid;
77178 +int grsec_enable_symlinkown;
77179 +kgid_t grsec_symlinkown_gid;
77180 +int grsec_enable_brute;
77181 +int grsec_enable_link;
77182 +int grsec_enable_dmesg;
77183 +int grsec_enable_harden_ptrace;
77184 +int grsec_enable_harden_ipc;
77185 +int grsec_enable_fifo;
77186 +int grsec_enable_execlog;
77187 +int grsec_enable_signal;
77188 +int grsec_enable_forkfail;
77189 +int grsec_enable_audit_ptrace;
77190 +int grsec_enable_time;
77191 +int grsec_enable_group;
77192 +kgid_t grsec_audit_gid;
77193 +int grsec_enable_chdir;
77194 +int grsec_enable_mount;
77195 +int grsec_enable_rofs;
77196 +int grsec_deny_new_usb;
77197 +int grsec_enable_chroot_findtask;
77198 +int grsec_enable_chroot_mount;
77199 +int grsec_enable_chroot_shmat;
77200 +int grsec_enable_chroot_fchdir;
77201 +int grsec_enable_chroot_double;
77202 +int grsec_enable_chroot_pivot;
77203 +int grsec_enable_chroot_chdir;
77204 +int grsec_enable_chroot_chmod;
77205 +int grsec_enable_chroot_mknod;
77206 +int grsec_enable_chroot_nice;
77207 +int grsec_enable_chroot_execlog;
77208 +int grsec_enable_chroot_caps;
77209 +int grsec_enable_chroot_rename;
77210 +int grsec_enable_chroot_sysctl;
77211 +int grsec_enable_chroot_unix;
77212 +int grsec_enable_tpe;
77213 +kgid_t grsec_tpe_gid;
77214 +int grsec_enable_blackhole;
77215 +#ifdef CONFIG_IPV6_MODULE
77216 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77217 +#endif
77218 +int grsec_lastack_retries;
77219 +int grsec_enable_tpe_all;
77220 +int grsec_enable_tpe_invert;
77221 +int grsec_enable_socket_all;
77222 +kgid_t grsec_socket_all_gid;
77223 +int grsec_enable_socket_client;
77224 +kgid_t grsec_socket_client_gid;
77225 +int grsec_enable_socket_server;
77226 +kgid_t grsec_socket_server_gid;
77227 +int grsec_resource_logging;
77228 +int grsec_disable_privio;
77229 +int grsec_enable_log_rwxmaps;
77230 +int grsec_lock;
77231 +
77232 +DEFINE_SPINLOCK(grsec_alert_lock);
77233 +unsigned long grsec_alert_wtime = 0;
77234 +unsigned long grsec_alert_fyet = 0;
77235 +
77236 +DEFINE_SPINLOCK(grsec_audit_lock);
77237 +
77238 +DEFINE_RWLOCK(grsec_exec_file_lock);
77239 +
77240 +char *gr_shared_page[4];
77241 +
77242 +char *gr_alert_log_fmt;
77243 +char *gr_audit_log_fmt;
77244 +char *gr_alert_log_buf;
77245 +char *gr_audit_log_buf;
77246 +
77247 +extern struct gr_arg *gr_usermode;
77248 +extern unsigned char *gr_system_salt;
77249 +extern unsigned char *gr_system_sum;
77250 +
77251 +void __init
77252 +grsecurity_init(void)
77253 +{
77254 + int j;
77255 + /* create the per-cpu shared pages */
77256 +
77257 +#ifdef CONFIG_X86
77258 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77259 +#endif
77260 +
77261 + for (j = 0; j < 4; j++) {
77262 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77263 + if (gr_shared_page[j] == NULL) {
77264 + panic("Unable to allocate grsecurity shared page");
77265 + return;
77266 + }
77267 + }
77268 +
77269 + /* allocate log buffers */
77270 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77271 + if (!gr_alert_log_fmt) {
77272 + panic("Unable to allocate grsecurity alert log format buffer");
77273 + return;
77274 + }
77275 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77276 + if (!gr_audit_log_fmt) {
77277 + panic("Unable to allocate grsecurity audit log format buffer");
77278 + return;
77279 + }
77280 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77281 + if (!gr_alert_log_buf) {
77282 + panic("Unable to allocate grsecurity alert log buffer");
77283 + return;
77284 + }
77285 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77286 + if (!gr_audit_log_buf) {
77287 + panic("Unable to allocate grsecurity audit log buffer");
77288 + return;
77289 + }
77290 +
77291 + /* allocate memory for authentication structure */
77292 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77293 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77294 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77295 +
77296 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77297 + panic("Unable to allocate grsecurity authentication structure");
77298 + return;
77299 + }
77300 +
77301 +#ifdef CONFIG_GRKERNSEC_IO
77302 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77303 + grsec_disable_privio = 1;
77304 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77305 + grsec_disable_privio = 1;
77306 +#else
77307 + grsec_disable_privio = 0;
77308 +#endif
77309 +#endif
77310 +
77311 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77312 + /* for backward compatibility, tpe_invert always defaults to on if
77313 + enabled in the kernel
77314 + */
77315 + grsec_enable_tpe_invert = 1;
77316 +#endif
77317 +
77318 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77319 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77320 + grsec_lock = 1;
77321 +#endif
77322 +
77323 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77324 + grsec_enable_log_rwxmaps = 1;
77325 +#endif
77326 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77327 + grsec_enable_group = 1;
77328 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77329 +#endif
77330 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77331 + grsec_enable_ptrace_readexec = 1;
77332 +#endif
77333 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77334 + grsec_enable_chdir = 1;
77335 +#endif
77336 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77337 + grsec_enable_harden_ptrace = 1;
77338 +#endif
77339 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77340 + grsec_enable_harden_ipc = 1;
77341 +#endif
77342 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77343 + grsec_enable_mount = 1;
77344 +#endif
77345 +#ifdef CONFIG_GRKERNSEC_LINK
77346 + grsec_enable_link = 1;
77347 +#endif
77348 +#ifdef CONFIG_GRKERNSEC_BRUTE
77349 + grsec_enable_brute = 1;
77350 +#endif
77351 +#ifdef CONFIG_GRKERNSEC_DMESG
77352 + grsec_enable_dmesg = 1;
77353 +#endif
77354 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77355 + grsec_enable_blackhole = 1;
77356 + grsec_lastack_retries = 4;
77357 +#endif
77358 +#ifdef CONFIG_GRKERNSEC_FIFO
77359 + grsec_enable_fifo = 1;
77360 +#endif
77361 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77362 + grsec_enable_execlog = 1;
77363 +#endif
77364 +#ifdef CONFIG_GRKERNSEC_SETXID
77365 + grsec_enable_setxid = 1;
77366 +#endif
77367 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77368 + grsec_enable_signal = 1;
77369 +#endif
77370 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77371 + grsec_enable_forkfail = 1;
77372 +#endif
77373 +#ifdef CONFIG_GRKERNSEC_TIME
77374 + grsec_enable_time = 1;
77375 +#endif
77376 +#ifdef CONFIG_GRKERNSEC_RESLOG
77377 + grsec_resource_logging = 1;
77378 +#endif
77379 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77380 + grsec_enable_chroot_findtask = 1;
77381 +#endif
77382 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77383 + grsec_enable_chroot_unix = 1;
77384 +#endif
77385 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77386 + grsec_enable_chroot_mount = 1;
77387 +#endif
77388 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77389 + grsec_enable_chroot_fchdir = 1;
77390 +#endif
77391 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77392 + grsec_enable_chroot_shmat = 1;
77393 +#endif
77394 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77395 + grsec_enable_audit_ptrace = 1;
77396 +#endif
77397 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77398 + grsec_enable_chroot_double = 1;
77399 +#endif
77400 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77401 + grsec_enable_chroot_pivot = 1;
77402 +#endif
77403 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77404 + grsec_enable_chroot_chdir = 1;
77405 +#endif
77406 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77407 + grsec_enable_chroot_chmod = 1;
77408 +#endif
77409 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77410 + grsec_enable_chroot_mknod = 1;
77411 +#endif
77412 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77413 + grsec_enable_chroot_nice = 1;
77414 +#endif
77415 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77416 + grsec_enable_chroot_execlog = 1;
77417 +#endif
77418 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77419 + grsec_enable_chroot_caps = 1;
77420 +#endif
77421 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
77422 + grsec_enable_chroot_rename = 1;
77423 +#endif
77424 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77425 + grsec_enable_chroot_sysctl = 1;
77426 +#endif
77427 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77428 + grsec_enable_symlinkown = 1;
77429 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77430 +#endif
77431 +#ifdef CONFIG_GRKERNSEC_TPE
77432 + grsec_enable_tpe = 1;
77433 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77434 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77435 + grsec_enable_tpe_all = 1;
77436 +#endif
77437 +#endif
77438 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77439 + grsec_enable_socket_all = 1;
77440 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77441 +#endif
77442 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77443 + grsec_enable_socket_client = 1;
77444 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77445 +#endif
77446 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77447 + grsec_enable_socket_server = 1;
77448 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77449 +#endif
77450 +#endif
77451 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77452 + grsec_deny_new_usb = 1;
77453 +#endif
77454 +
77455 + return;
77456 +}
77457 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77458 new file mode 100644
77459 index 0000000..1773300
77460 --- /dev/null
77461 +++ b/grsecurity/grsec_ipc.c
77462 @@ -0,0 +1,48 @@
77463 +#include <linux/kernel.h>
77464 +#include <linux/mm.h>
77465 +#include <linux/sched.h>
77466 +#include <linux/file.h>
77467 +#include <linux/ipc.h>
77468 +#include <linux/ipc_namespace.h>
77469 +#include <linux/grsecurity.h>
77470 +#include <linux/grinternal.h>
77471 +
77472 +int
77473 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77474 +{
77475 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77476 + int write;
77477 + int orig_granted_mode;
77478 + kuid_t euid;
77479 + kgid_t egid;
77480 +
77481 + if (!grsec_enable_harden_ipc)
77482 + return 1;
77483 +
77484 + euid = current_euid();
77485 + egid = current_egid();
77486 +
77487 + write = requested_mode & 00002;
77488 + orig_granted_mode = ipcp->mode;
77489 +
77490 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77491 + orig_granted_mode >>= 6;
77492 + else {
77493 + /* if likely wrong permissions, lock to user */
77494 + if (orig_granted_mode & 0007)
77495 + orig_granted_mode = 0;
77496 + /* otherwise do a egid-only check */
77497 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77498 + orig_granted_mode >>= 3;
77499 + /* otherwise, no access */
77500 + else
77501 + orig_granted_mode = 0;
77502 + }
77503 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77504 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77505 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77506 + return 0;
77507 + }
77508 +#endif
77509 + return 1;
77510 +}
77511 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77512 new file mode 100644
77513 index 0000000..5e05e20
77514 --- /dev/null
77515 +++ b/grsecurity/grsec_link.c
77516 @@ -0,0 +1,58 @@
77517 +#include <linux/kernel.h>
77518 +#include <linux/sched.h>
77519 +#include <linux/fs.h>
77520 +#include <linux/file.h>
77521 +#include <linux/grinternal.h>
77522 +
77523 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77524 +{
77525 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77526 + const struct inode *link_inode = link->dentry->d_inode;
77527 +
77528 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77529 + /* ignore root-owned links, e.g. /proc/self */
77530 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77531 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77532 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77533 + return 1;
77534 + }
77535 +#endif
77536 + return 0;
77537 +}
77538 +
77539 +int
77540 +gr_handle_follow_link(const struct inode *parent,
77541 + const struct inode *inode,
77542 + const struct dentry *dentry, const struct vfsmount *mnt)
77543 +{
77544 +#ifdef CONFIG_GRKERNSEC_LINK
77545 + const struct cred *cred = current_cred();
77546 +
77547 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77548 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77549 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77550 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77551 + return -EACCES;
77552 + }
77553 +#endif
77554 + return 0;
77555 +}
77556 +
77557 +int
77558 +gr_handle_hardlink(const struct dentry *dentry,
77559 + const struct vfsmount *mnt,
77560 + struct inode *inode, const int mode, const struct filename *to)
77561 +{
77562 +#ifdef CONFIG_GRKERNSEC_LINK
77563 + const struct cred *cred = current_cred();
77564 +
77565 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77566 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77567 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77568 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77569 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77570 + return -EPERM;
77571 + }
77572 +#endif
77573 + return 0;
77574 +}
77575 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77576 new file mode 100644
77577 index 0000000..dbe0a6b
77578 --- /dev/null
77579 +++ b/grsecurity/grsec_log.c
77580 @@ -0,0 +1,341 @@
77581 +#include <linux/kernel.h>
77582 +#include <linux/sched.h>
77583 +#include <linux/file.h>
77584 +#include <linux/tty.h>
77585 +#include <linux/fs.h>
77586 +#include <linux/mm.h>
77587 +#include <linux/grinternal.h>
77588 +
77589 +#ifdef CONFIG_TREE_PREEMPT_RCU
77590 +#define DISABLE_PREEMPT() preempt_disable()
77591 +#define ENABLE_PREEMPT() preempt_enable()
77592 +#else
77593 +#define DISABLE_PREEMPT()
77594 +#define ENABLE_PREEMPT()
77595 +#endif
77596 +
77597 +#define BEGIN_LOCKS(x) \
77598 + DISABLE_PREEMPT(); \
77599 + rcu_read_lock(); \
77600 + read_lock(&tasklist_lock); \
77601 + read_lock(&grsec_exec_file_lock); \
77602 + if (x != GR_DO_AUDIT) \
77603 + spin_lock(&grsec_alert_lock); \
77604 + else \
77605 + spin_lock(&grsec_audit_lock)
77606 +
77607 +#define END_LOCKS(x) \
77608 + if (x != GR_DO_AUDIT) \
77609 + spin_unlock(&grsec_alert_lock); \
77610 + else \
77611 + spin_unlock(&grsec_audit_lock); \
77612 + read_unlock(&grsec_exec_file_lock); \
77613 + read_unlock(&tasklist_lock); \
77614 + rcu_read_unlock(); \
77615 + ENABLE_PREEMPT(); \
77616 + if (x == GR_DONT_AUDIT) \
77617 + gr_handle_alertkill(current)
77618 +
77619 +enum {
77620 + FLOODING,
77621 + NO_FLOODING
77622 +};
77623 +
77624 +extern char *gr_alert_log_fmt;
77625 +extern char *gr_audit_log_fmt;
77626 +extern char *gr_alert_log_buf;
77627 +extern char *gr_audit_log_buf;
77628 +
77629 +static int gr_log_start(int audit)
77630 +{
77631 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77632 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77633 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77634 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77635 + unsigned long curr_secs = get_seconds();
77636 +
77637 + if (audit == GR_DO_AUDIT)
77638 + goto set_fmt;
77639 +
77640 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77641 + grsec_alert_wtime = curr_secs;
77642 + grsec_alert_fyet = 0;
77643 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77644 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77645 + grsec_alert_fyet++;
77646 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77647 + grsec_alert_wtime = curr_secs;
77648 + grsec_alert_fyet++;
77649 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77650 + return FLOODING;
77651 + }
77652 + else return FLOODING;
77653 +
77654 +set_fmt:
77655 +#endif
77656 + memset(buf, 0, PAGE_SIZE);
77657 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77658 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77659 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77660 + } else if (current->signal->curr_ip) {
77661 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77662 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77663 + } else if (gr_acl_is_enabled()) {
77664 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77665 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77666 + } else {
77667 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77668 + strcpy(buf, fmt);
77669 + }
77670 +
77671 + return NO_FLOODING;
77672 +}
77673 +
77674 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77675 + __attribute__ ((format (printf, 2, 0)));
77676 +
77677 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77678 +{
77679 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77680 + unsigned int len = strlen(buf);
77681 +
77682 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77683 +
77684 + return;
77685 +}
77686 +
77687 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77688 + __attribute__ ((format (printf, 2, 3)));
77689 +
77690 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77691 +{
77692 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77693 + unsigned int len = strlen(buf);
77694 + va_list ap;
77695 +
77696 + va_start(ap, msg);
77697 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77698 + va_end(ap);
77699 +
77700 + return;
77701 +}
77702 +
77703 +static void gr_log_end(int audit, int append_default)
77704 +{
77705 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77706 + if (append_default) {
77707 + struct task_struct *task = current;
77708 + struct task_struct *parent = task->real_parent;
77709 + const struct cred *cred = __task_cred(task);
77710 + const struct cred *pcred = __task_cred(parent);
77711 + unsigned int len = strlen(buf);
77712 +
77713 + 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));
77714 + }
77715 +
77716 + printk("%s\n", buf);
77717 +
77718 + return;
77719 +}
77720 +
77721 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77722 +{
77723 + int logtype;
77724 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77725 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77726 + void *voidptr = NULL;
77727 + int num1 = 0, num2 = 0;
77728 + unsigned long ulong1 = 0, ulong2 = 0;
77729 + struct dentry *dentry = NULL;
77730 + struct vfsmount *mnt = NULL;
77731 + struct file *file = NULL;
77732 + struct task_struct *task = NULL;
77733 + struct vm_area_struct *vma = NULL;
77734 + const struct cred *cred, *pcred;
77735 + va_list ap;
77736 +
77737 + BEGIN_LOCKS(audit);
77738 + logtype = gr_log_start(audit);
77739 + if (logtype == FLOODING) {
77740 + END_LOCKS(audit);
77741 + return;
77742 + }
77743 + va_start(ap, argtypes);
77744 + switch (argtypes) {
77745 + case GR_TTYSNIFF:
77746 + task = va_arg(ap, struct task_struct *);
77747 + 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));
77748 + break;
77749 + case GR_SYSCTL_HIDDEN:
77750 + str1 = va_arg(ap, char *);
77751 + gr_log_middle_varargs(audit, msg, result, str1);
77752 + break;
77753 + case GR_RBAC:
77754 + dentry = va_arg(ap, struct dentry *);
77755 + mnt = va_arg(ap, struct vfsmount *);
77756 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77757 + break;
77758 + case GR_RBAC_STR:
77759 + dentry = va_arg(ap, struct dentry *);
77760 + mnt = va_arg(ap, struct vfsmount *);
77761 + str1 = va_arg(ap, char *);
77762 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77763 + break;
77764 + case GR_STR_RBAC:
77765 + str1 = va_arg(ap, char *);
77766 + dentry = va_arg(ap, struct dentry *);
77767 + mnt = va_arg(ap, struct vfsmount *);
77768 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77769 + break;
77770 + case GR_RBAC_MODE2:
77771 + dentry = va_arg(ap, struct dentry *);
77772 + mnt = va_arg(ap, struct vfsmount *);
77773 + str1 = va_arg(ap, char *);
77774 + str2 = va_arg(ap, char *);
77775 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77776 + break;
77777 + case GR_RBAC_MODE3:
77778 + dentry = va_arg(ap, struct dentry *);
77779 + mnt = va_arg(ap, struct vfsmount *);
77780 + str1 = va_arg(ap, char *);
77781 + str2 = va_arg(ap, char *);
77782 + str3 = va_arg(ap, char *);
77783 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77784 + break;
77785 + case GR_FILENAME:
77786 + dentry = va_arg(ap, struct dentry *);
77787 + mnt = va_arg(ap, struct vfsmount *);
77788 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77789 + break;
77790 + case GR_STR_FILENAME:
77791 + str1 = va_arg(ap, char *);
77792 + dentry = va_arg(ap, struct dentry *);
77793 + mnt = va_arg(ap, struct vfsmount *);
77794 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77795 + break;
77796 + case GR_FILENAME_STR:
77797 + dentry = va_arg(ap, struct dentry *);
77798 + mnt = va_arg(ap, struct vfsmount *);
77799 + str1 = va_arg(ap, char *);
77800 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77801 + break;
77802 + case GR_FILENAME_TWO_INT:
77803 + dentry = va_arg(ap, struct dentry *);
77804 + mnt = va_arg(ap, struct vfsmount *);
77805 + num1 = va_arg(ap, int);
77806 + num2 = va_arg(ap, int);
77807 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77808 + break;
77809 + case GR_FILENAME_TWO_INT_STR:
77810 + dentry = va_arg(ap, struct dentry *);
77811 + mnt = va_arg(ap, struct vfsmount *);
77812 + num1 = va_arg(ap, int);
77813 + num2 = va_arg(ap, int);
77814 + str1 = va_arg(ap, char *);
77815 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77816 + break;
77817 + case GR_TEXTREL:
77818 + file = va_arg(ap, struct file *);
77819 + ulong1 = va_arg(ap, unsigned long);
77820 + ulong2 = va_arg(ap, unsigned long);
77821 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77822 + break;
77823 + case GR_PTRACE:
77824 + task = va_arg(ap, struct task_struct *);
77825 + 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));
77826 + break;
77827 + case GR_RESOURCE:
77828 + task = va_arg(ap, struct task_struct *);
77829 + cred = __task_cred(task);
77830 + pcred = __task_cred(task->real_parent);
77831 + ulong1 = va_arg(ap, unsigned long);
77832 + str1 = va_arg(ap, char *);
77833 + ulong2 = va_arg(ap, unsigned long);
77834 + 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));
77835 + break;
77836 + case GR_CAP:
77837 + task = va_arg(ap, struct task_struct *);
77838 + cred = __task_cred(task);
77839 + pcred = __task_cred(task->real_parent);
77840 + str1 = va_arg(ap, char *);
77841 + 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));
77842 + break;
77843 + case GR_SIG:
77844 + str1 = va_arg(ap, char *);
77845 + voidptr = va_arg(ap, void *);
77846 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77847 + break;
77848 + case GR_SIG2:
77849 + task = va_arg(ap, struct task_struct *);
77850 + cred = __task_cred(task);
77851 + pcred = __task_cred(task->real_parent);
77852 + num1 = va_arg(ap, int);
77853 + 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));
77854 + break;
77855 + case GR_CRASH1:
77856 + task = va_arg(ap, struct task_struct *);
77857 + cred = __task_cred(task);
77858 + pcred = __task_cred(task->real_parent);
77859 + ulong1 = va_arg(ap, unsigned long);
77860 + 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);
77861 + break;
77862 + case GR_CRASH2:
77863 + task = va_arg(ap, struct task_struct *);
77864 + cred = __task_cred(task);
77865 + pcred = __task_cred(task->real_parent);
77866 + ulong1 = va_arg(ap, unsigned long);
77867 + 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);
77868 + break;
77869 + case GR_RWXMAP:
77870 + file = va_arg(ap, struct file *);
77871 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77872 + break;
77873 + case GR_RWXMAPVMA:
77874 + vma = va_arg(ap, struct vm_area_struct *);
77875 + if (vma->vm_file)
77876 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77877 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77878 + str1 = "<stack>";
77879 + else if (vma->vm_start <= current->mm->brk &&
77880 + vma->vm_end >= current->mm->start_brk)
77881 + str1 = "<heap>";
77882 + else
77883 + str1 = "<anonymous mapping>";
77884 + gr_log_middle_varargs(audit, msg, str1);
77885 + break;
77886 + case GR_PSACCT:
77887 + {
77888 + unsigned int wday, cday;
77889 + __u8 whr, chr;
77890 + __u8 wmin, cmin;
77891 + __u8 wsec, csec;
77892 + char cur_tty[64] = { 0 };
77893 + char parent_tty[64] = { 0 };
77894 +
77895 + task = va_arg(ap, struct task_struct *);
77896 + wday = va_arg(ap, unsigned int);
77897 + cday = va_arg(ap, unsigned int);
77898 + whr = va_arg(ap, int);
77899 + chr = va_arg(ap, int);
77900 + wmin = va_arg(ap, int);
77901 + cmin = va_arg(ap, int);
77902 + wsec = va_arg(ap, int);
77903 + csec = va_arg(ap, int);
77904 + ulong1 = va_arg(ap, unsigned long);
77905 + cred = __task_cred(task);
77906 + pcred = __task_cred(task->real_parent);
77907 +
77908 + 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));
77909 + }
77910 + break;
77911 + default:
77912 + gr_log_middle(audit, msg, ap);
77913 + }
77914 + va_end(ap);
77915 + // these don't need DEFAULTSECARGS printed on the end
77916 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77917 + gr_log_end(audit, 0);
77918 + else
77919 + gr_log_end(audit, 1);
77920 + END_LOCKS(audit);
77921 +}
77922 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77923 new file mode 100644
77924 index 0000000..0e39d8c
77925 --- /dev/null
77926 +++ b/grsecurity/grsec_mem.c
77927 @@ -0,0 +1,48 @@
77928 +#include <linux/kernel.h>
77929 +#include <linux/sched.h>
77930 +#include <linux/mm.h>
77931 +#include <linux/mman.h>
77932 +#include <linux/module.h>
77933 +#include <linux/grinternal.h>
77934 +
77935 +void gr_handle_msr_write(void)
77936 +{
77937 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77938 + return;
77939 +}
77940 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77941 +
77942 +void
77943 +gr_handle_ioperm(void)
77944 +{
77945 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77946 + return;
77947 +}
77948 +
77949 +void
77950 +gr_handle_iopl(void)
77951 +{
77952 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77953 + return;
77954 +}
77955 +
77956 +void
77957 +gr_handle_mem_readwrite(u64 from, u64 to)
77958 +{
77959 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77960 + return;
77961 +}
77962 +
77963 +void
77964 +gr_handle_vm86(void)
77965 +{
77966 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77967 + return;
77968 +}
77969 +
77970 +void
77971 +gr_log_badprocpid(const char *entry)
77972 +{
77973 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77974 + return;
77975 +}
77976 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77977 new file mode 100644
77978 index 0000000..6f9eb73
77979 --- /dev/null
77980 +++ b/grsecurity/grsec_mount.c
77981 @@ -0,0 +1,65 @@
77982 +#include <linux/kernel.h>
77983 +#include <linux/sched.h>
77984 +#include <linux/mount.h>
77985 +#include <linux/major.h>
77986 +#include <linux/grsecurity.h>
77987 +#include <linux/grinternal.h>
77988 +
77989 +void
77990 +gr_log_remount(const char *devname, const int retval)
77991 +{
77992 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77993 + if (grsec_enable_mount && (retval >= 0))
77994 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77995 +#endif
77996 + return;
77997 +}
77998 +
77999 +void
78000 +gr_log_unmount(const char *devname, const int retval)
78001 +{
78002 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78003 + if (grsec_enable_mount && (retval >= 0))
78004 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78005 +#endif
78006 + return;
78007 +}
78008 +
78009 +void
78010 +gr_log_mount(const char *from, struct path *to, const int retval)
78011 +{
78012 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78013 + if (grsec_enable_mount && (retval >= 0))
78014 + gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
78015 +#endif
78016 + return;
78017 +}
78018 +
78019 +int
78020 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78021 +{
78022 +#ifdef CONFIG_GRKERNSEC_ROFS
78023 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78024 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78025 + return -EPERM;
78026 + } else
78027 + return 0;
78028 +#endif
78029 + return 0;
78030 +}
78031 +
78032 +int
78033 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78034 +{
78035 +#ifdef CONFIG_GRKERNSEC_ROFS
78036 + struct inode *inode = dentry->d_inode;
78037 +
78038 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78039 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78040 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78041 + return -EPERM;
78042 + } else
78043 + return 0;
78044 +#endif
78045 + return 0;
78046 +}
78047 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78048 new file mode 100644
78049 index 0000000..6ee9d50
78050 --- /dev/null
78051 +++ b/grsecurity/grsec_pax.c
78052 @@ -0,0 +1,45 @@
78053 +#include <linux/kernel.h>
78054 +#include <linux/sched.h>
78055 +#include <linux/mm.h>
78056 +#include <linux/file.h>
78057 +#include <linux/grinternal.h>
78058 +#include <linux/grsecurity.h>
78059 +
78060 +void
78061 +gr_log_textrel(struct vm_area_struct * vma)
78062 +{
78063 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78064 + if (grsec_enable_log_rwxmaps)
78065 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78066 +#endif
78067 + return;
78068 +}
78069 +
78070 +void gr_log_ptgnustack(struct file *file)
78071 +{
78072 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78073 + if (grsec_enable_log_rwxmaps)
78074 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78075 +#endif
78076 + return;
78077 +}
78078 +
78079 +void
78080 +gr_log_rwxmmap(struct file *file)
78081 +{
78082 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78083 + if (grsec_enable_log_rwxmaps)
78084 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78085 +#endif
78086 + return;
78087 +}
78088 +
78089 +void
78090 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78091 +{
78092 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78093 + if (grsec_enable_log_rwxmaps)
78094 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78095 +#endif
78096 + return;
78097 +}
78098 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78099 new file mode 100644
78100 index 0000000..2005a3a
78101 --- /dev/null
78102 +++ b/grsecurity/grsec_proc.c
78103 @@ -0,0 +1,20 @@
78104 +#include <linux/kernel.h>
78105 +#include <linux/sched.h>
78106 +#include <linux/grsecurity.h>
78107 +#include <linux/grinternal.h>
78108 +
78109 +int gr_proc_is_restricted(void)
78110 +{
78111 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78112 + const struct cred *cred = current_cred();
78113 +#endif
78114 +
78115 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78116 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78117 + return -EACCES;
78118 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78119 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78120 + return -EACCES;
78121 +#endif
78122 + return 0;
78123 +}
78124 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78125 new file mode 100644
78126 index 0000000..f7f29aa
78127 --- /dev/null
78128 +++ b/grsecurity/grsec_ptrace.c
78129 @@ -0,0 +1,30 @@
78130 +#include <linux/kernel.h>
78131 +#include <linux/sched.h>
78132 +#include <linux/grinternal.h>
78133 +#include <linux/security.h>
78134 +
78135 +void
78136 +gr_audit_ptrace(struct task_struct *task)
78137 +{
78138 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78139 + if (grsec_enable_audit_ptrace)
78140 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78141 +#endif
78142 + return;
78143 +}
78144 +
78145 +int
78146 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78147 +{
78148 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78149 + const struct dentry *dentry = file->f_path.dentry;
78150 + const struct vfsmount *mnt = file->f_path.mnt;
78151 +
78152 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78153 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78154 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78155 + return -EACCES;
78156 + }
78157 +#endif
78158 + return 0;
78159 +}
78160 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78161 new file mode 100644
78162 index 0000000..3860c7e
78163 --- /dev/null
78164 +++ b/grsecurity/grsec_sig.c
78165 @@ -0,0 +1,236 @@
78166 +#include <linux/kernel.h>
78167 +#include <linux/sched.h>
78168 +#include <linux/fs.h>
78169 +#include <linux/delay.h>
78170 +#include <linux/grsecurity.h>
78171 +#include <linux/grinternal.h>
78172 +#include <linux/hardirq.h>
78173 +
78174 +char *signames[] = {
78175 + [SIGSEGV] = "Segmentation fault",
78176 + [SIGILL] = "Illegal instruction",
78177 + [SIGABRT] = "Abort",
78178 + [SIGBUS] = "Invalid alignment/Bus error"
78179 +};
78180 +
78181 +void
78182 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78183 +{
78184 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78185 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78186 + (sig == SIGABRT) || (sig == SIGBUS))) {
78187 + if (task_pid_nr(t) == task_pid_nr(current)) {
78188 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78189 + } else {
78190 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78191 + }
78192 + }
78193 +#endif
78194 + return;
78195 +}
78196 +
78197 +int
78198 +gr_handle_signal(const struct task_struct *p, const int sig)
78199 +{
78200 +#ifdef CONFIG_GRKERNSEC
78201 + /* ignore the 0 signal for protected task checks */
78202 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78203 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78204 + return -EPERM;
78205 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78206 + return -EPERM;
78207 + }
78208 +#endif
78209 + return 0;
78210 +}
78211 +
78212 +#ifdef CONFIG_GRKERNSEC
78213 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78214 +
78215 +int gr_fake_force_sig(int sig, struct task_struct *t)
78216 +{
78217 + unsigned long int flags;
78218 + int ret, blocked, ignored;
78219 + struct k_sigaction *action;
78220 +
78221 + spin_lock_irqsave(&t->sighand->siglock, flags);
78222 + action = &t->sighand->action[sig-1];
78223 + ignored = action->sa.sa_handler == SIG_IGN;
78224 + blocked = sigismember(&t->blocked, sig);
78225 + if (blocked || ignored) {
78226 + action->sa.sa_handler = SIG_DFL;
78227 + if (blocked) {
78228 + sigdelset(&t->blocked, sig);
78229 + recalc_sigpending_and_wake(t);
78230 + }
78231 + }
78232 + if (action->sa.sa_handler == SIG_DFL)
78233 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78234 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78235 +
78236 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78237 +
78238 + return ret;
78239 +}
78240 +#endif
78241 +
78242 +#define GR_USER_BAN_TIME (15 * 60)
78243 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78244 +
78245 +void gr_handle_brute_attach(int dumpable)
78246 +{
78247 +#ifdef CONFIG_GRKERNSEC_BRUTE
78248 + struct task_struct *p = current;
78249 + kuid_t uid = GLOBAL_ROOT_UID;
78250 + int daemon = 0;
78251 +
78252 + if (!grsec_enable_brute)
78253 + return;
78254 +
78255 + rcu_read_lock();
78256 + read_lock(&tasklist_lock);
78257 + read_lock(&grsec_exec_file_lock);
78258 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78259 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78260 + p->real_parent->brute = 1;
78261 + daemon = 1;
78262 + } else {
78263 + const struct cred *cred = __task_cred(p), *cred2;
78264 + struct task_struct *tsk, *tsk2;
78265 +
78266 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78267 + struct user_struct *user;
78268 +
78269 + uid = cred->uid;
78270 +
78271 + /* this is put upon execution past expiration */
78272 + user = find_user(uid);
78273 + if (user == NULL)
78274 + goto unlock;
78275 + user->suid_banned = 1;
78276 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78277 + if (user->suid_ban_expires == ~0UL)
78278 + user->suid_ban_expires--;
78279 +
78280 + /* only kill other threads of the same binary, from the same user */
78281 + do_each_thread(tsk2, tsk) {
78282 + cred2 = __task_cred(tsk);
78283 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78284 + gr_fake_force_sig(SIGKILL, tsk);
78285 + } while_each_thread(tsk2, tsk);
78286 + }
78287 + }
78288 +unlock:
78289 + read_unlock(&grsec_exec_file_lock);
78290 + read_unlock(&tasklist_lock);
78291 + rcu_read_unlock();
78292 +
78293 + if (gr_is_global_nonroot(uid))
78294 + 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);
78295 + else if (daemon)
78296 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78297 +
78298 +#endif
78299 + return;
78300 +}
78301 +
78302 +void gr_handle_brute_check(void)
78303 +{
78304 +#ifdef CONFIG_GRKERNSEC_BRUTE
78305 + struct task_struct *p = current;
78306 +
78307 + if (unlikely(p->brute)) {
78308 + if (!grsec_enable_brute)
78309 + p->brute = 0;
78310 + else if (time_before(get_seconds(), p->brute_expires))
78311 + msleep(30 * 1000);
78312 + }
78313 +#endif
78314 + return;
78315 +}
78316 +
78317 +void gr_handle_kernel_exploit(void)
78318 +{
78319 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78320 + const struct cred *cred;
78321 + struct task_struct *tsk, *tsk2;
78322 + struct user_struct *user;
78323 + kuid_t uid;
78324 +
78325 + if (in_irq() || in_serving_softirq() || in_nmi())
78326 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78327 +
78328 + uid = current_uid();
78329 +
78330 + if (gr_is_global_root(uid))
78331 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78332 + else {
78333 + /* kill all the processes of this user, hold a reference
78334 + to their creds struct, and prevent them from creating
78335 + another process until system reset
78336 + */
78337 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78338 + GR_GLOBAL_UID(uid));
78339 + /* we intentionally leak this ref */
78340 + user = get_uid(current->cred->user);
78341 + if (user)
78342 + user->kernel_banned = 1;
78343 +
78344 + /* kill all processes of this user */
78345 + read_lock(&tasklist_lock);
78346 + do_each_thread(tsk2, tsk) {
78347 + cred = __task_cred(tsk);
78348 + if (uid_eq(cred->uid, uid))
78349 + gr_fake_force_sig(SIGKILL, tsk);
78350 + } while_each_thread(tsk2, tsk);
78351 + read_unlock(&tasklist_lock);
78352 + }
78353 +#endif
78354 +}
78355 +
78356 +#ifdef CONFIG_GRKERNSEC_BRUTE
78357 +static bool suid_ban_expired(struct user_struct *user)
78358 +{
78359 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78360 + user->suid_banned = 0;
78361 + user->suid_ban_expires = 0;
78362 + free_uid(user);
78363 + return true;
78364 + }
78365 +
78366 + return false;
78367 +}
78368 +#endif
78369 +
78370 +int gr_process_kernel_exec_ban(void)
78371 +{
78372 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78373 + if (unlikely(current->cred->user->kernel_banned))
78374 + return -EPERM;
78375 +#endif
78376 + return 0;
78377 +}
78378 +
78379 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78380 +{
78381 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78382 + if (unlikely(user->kernel_banned))
78383 + gr_fake_force_sig(SIGKILL, current);
78384 +#endif
78385 + return 0;
78386 +}
78387 +
78388 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78389 +{
78390 +#ifdef CONFIG_GRKERNSEC_BRUTE
78391 + struct user_struct *user = current->cred->user;
78392 + if (unlikely(user->suid_banned)) {
78393 + if (suid_ban_expired(user))
78394 + return 0;
78395 + /* disallow execution of suid binaries only */
78396 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78397 + return -EPERM;
78398 + }
78399 +#endif
78400 + return 0;
78401 +}
78402 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78403 new file mode 100644
78404 index 0000000..e3650b6
78405 --- /dev/null
78406 +++ b/grsecurity/grsec_sock.c
78407 @@ -0,0 +1,244 @@
78408 +#include <linux/kernel.h>
78409 +#include <linux/module.h>
78410 +#include <linux/sched.h>
78411 +#include <linux/file.h>
78412 +#include <linux/net.h>
78413 +#include <linux/in.h>
78414 +#include <linux/ip.h>
78415 +#include <net/sock.h>
78416 +#include <net/inet_sock.h>
78417 +#include <linux/grsecurity.h>
78418 +#include <linux/grinternal.h>
78419 +#include <linux/gracl.h>
78420 +
78421 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78422 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78423 +
78424 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78425 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78426 +
78427 +#ifdef CONFIG_UNIX_MODULE
78428 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78429 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78430 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78431 +EXPORT_SYMBOL_GPL(gr_handle_create);
78432 +#endif
78433 +
78434 +#ifdef CONFIG_GRKERNSEC
78435 +#define gr_conn_table_size 32749
78436 +struct conn_table_entry {
78437 + struct conn_table_entry *next;
78438 + struct signal_struct *sig;
78439 +};
78440 +
78441 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78442 +DEFINE_SPINLOCK(gr_conn_table_lock);
78443 +
78444 +extern const char * gr_socktype_to_name(unsigned char type);
78445 +extern const char * gr_proto_to_name(unsigned char proto);
78446 +extern const char * gr_sockfamily_to_name(unsigned char family);
78447 +
78448 +static __inline__ int
78449 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78450 +{
78451 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78452 +}
78453 +
78454 +static __inline__ int
78455 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78456 + __u16 sport, __u16 dport)
78457 +{
78458 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78459 + sig->gr_sport == sport && sig->gr_dport == dport))
78460 + return 1;
78461 + else
78462 + return 0;
78463 +}
78464 +
78465 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78466 +{
78467 + struct conn_table_entry **match;
78468 + unsigned int index;
78469 +
78470 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78471 + sig->gr_sport, sig->gr_dport,
78472 + gr_conn_table_size);
78473 +
78474 + newent->sig = sig;
78475 +
78476 + match = &gr_conn_table[index];
78477 + newent->next = *match;
78478 + *match = newent;
78479 +
78480 + return;
78481 +}
78482 +
78483 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78484 +{
78485 + struct conn_table_entry *match, *last = NULL;
78486 + unsigned int index;
78487 +
78488 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78489 + sig->gr_sport, sig->gr_dport,
78490 + gr_conn_table_size);
78491 +
78492 + match = gr_conn_table[index];
78493 + while (match && !conn_match(match->sig,
78494 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78495 + sig->gr_dport)) {
78496 + last = match;
78497 + match = match->next;
78498 + }
78499 +
78500 + if (match) {
78501 + if (last)
78502 + last->next = match->next;
78503 + else
78504 + gr_conn_table[index] = NULL;
78505 + kfree(match);
78506 + }
78507 +
78508 + return;
78509 +}
78510 +
78511 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78512 + __u16 sport, __u16 dport)
78513 +{
78514 + struct conn_table_entry *match;
78515 + unsigned int index;
78516 +
78517 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78518 +
78519 + match = gr_conn_table[index];
78520 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78521 + match = match->next;
78522 +
78523 + if (match)
78524 + return match->sig;
78525 + else
78526 + return NULL;
78527 +}
78528 +
78529 +#endif
78530 +
78531 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78532 +{
78533 +#ifdef CONFIG_GRKERNSEC
78534 + struct signal_struct *sig = current->signal;
78535 + struct conn_table_entry *newent;
78536 +
78537 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78538 + if (newent == NULL)
78539 + return;
78540 + /* no bh lock needed since we are called with bh disabled */
78541 + spin_lock(&gr_conn_table_lock);
78542 + gr_del_task_from_ip_table_nolock(sig);
78543 + sig->gr_saddr = inet->inet_rcv_saddr;
78544 + sig->gr_daddr = inet->inet_daddr;
78545 + sig->gr_sport = inet->inet_sport;
78546 + sig->gr_dport = inet->inet_dport;
78547 + gr_add_to_task_ip_table_nolock(sig, newent);
78548 + spin_unlock(&gr_conn_table_lock);
78549 +#endif
78550 + return;
78551 +}
78552 +
78553 +void gr_del_task_from_ip_table(struct task_struct *task)
78554 +{
78555 +#ifdef CONFIG_GRKERNSEC
78556 + spin_lock_bh(&gr_conn_table_lock);
78557 + gr_del_task_from_ip_table_nolock(task->signal);
78558 + spin_unlock_bh(&gr_conn_table_lock);
78559 +#endif
78560 + return;
78561 +}
78562 +
78563 +void
78564 +gr_attach_curr_ip(const struct sock *sk)
78565 +{
78566 +#ifdef CONFIG_GRKERNSEC
78567 + struct signal_struct *p, *set;
78568 + const struct inet_sock *inet = inet_sk(sk);
78569 +
78570 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78571 + return;
78572 +
78573 + set = current->signal;
78574 +
78575 + spin_lock_bh(&gr_conn_table_lock);
78576 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78577 + inet->inet_dport, inet->inet_sport);
78578 + if (unlikely(p != NULL)) {
78579 + set->curr_ip = p->curr_ip;
78580 + set->used_accept = 1;
78581 + gr_del_task_from_ip_table_nolock(p);
78582 + spin_unlock_bh(&gr_conn_table_lock);
78583 + return;
78584 + }
78585 + spin_unlock_bh(&gr_conn_table_lock);
78586 +
78587 + set->curr_ip = inet->inet_daddr;
78588 + set->used_accept = 1;
78589 +#endif
78590 + return;
78591 +}
78592 +
78593 +int
78594 +gr_handle_sock_all(const int family, const int type, const int protocol)
78595 +{
78596 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78597 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78598 + (family != AF_UNIX)) {
78599 + if (family == AF_INET)
78600 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78601 + else
78602 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78603 + return -EACCES;
78604 + }
78605 +#endif
78606 + return 0;
78607 +}
78608 +
78609 +int
78610 +gr_handle_sock_server(const struct sockaddr *sck)
78611 +{
78612 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78613 + if (grsec_enable_socket_server &&
78614 + in_group_p(grsec_socket_server_gid) &&
78615 + sck && (sck->sa_family != AF_UNIX) &&
78616 + (sck->sa_family != AF_LOCAL)) {
78617 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78618 + return -EACCES;
78619 + }
78620 +#endif
78621 + return 0;
78622 +}
78623 +
78624 +int
78625 +gr_handle_sock_server_other(const struct sock *sck)
78626 +{
78627 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78628 + if (grsec_enable_socket_server &&
78629 + in_group_p(grsec_socket_server_gid) &&
78630 + sck && (sck->sk_family != AF_UNIX) &&
78631 + (sck->sk_family != AF_LOCAL)) {
78632 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78633 + return -EACCES;
78634 + }
78635 +#endif
78636 + return 0;
78637 +}
78638 +
78639 +int
78640 +gr_handle_sock_client(const struct sockaddr *sck)
78641 +{
78642 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78643 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78644 + sck && (sck->sa_family != AF_UNIX) &&
78645 + (sck->sa_family != AF_LOCAL)) {
78646 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78647 + return -EACCES;
78648 + }
78649 +#endif
78650 + return 0;
78651 +}
78652 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78653 new file mode 100644
78654 index 0000000..cce889e
78655 --- /dev/null
78656 +++ b/grsecurity/grsec_sysctl.c
78657 @@ -0,0 +1,488 @@
78658 +#include <linux/kernel.h>
78659 +#include <linux/sched.h>
78660 +#include <linux/sysctl.h>
78661 +#include <linux/grsecurity.h>
78662 +#include <linux/grinternal.h>
78663 +
78664 +int
78665 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78666 +{
78667 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78668 + if (dirname == NULL || name == NULL)
78669 + return 0;
78670 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78671 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78672 + return -EACCES;
78673 + }
78674 +#endif
78675 + return 0;
78676 +}
78677 +
78678 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78679 +static int __maybe_unused __read_only one = 1;
78680 +#endif
78681 +
78682 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78683 + defined(CONFIG_GRKERNSEC_DENYUSB)
78684 +struct ctl_table grsecurity_table[] = {
78685 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78686 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78687 +#ifdef CONFIG_GRKERNSEC_IO
78688 + {
78689 + .procname = "disable_priv_io",
78690 + .data = &grsec_disable_privio,
78691 + .maxlen = sizeof(int),
78692 + .mode = 0600,
78693 + .proc_handler = &proc_dointvec,
78694 + },
78695 +#endif
78696 +#endif
78697 +#ifdef CONFIG_GRKERNSEC_LINK
78698 + {
78699 + .procname = "linking_restrictions",
78700 + .data = &grsec_enable_link,
78701 + .maxlen = sizeof(int),
78702 + .mode = 0600,
78703 + .proc_handler = &proc_dointvec,
78704 + },
78705 +#endif
78706 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78707 + {
78708 + .procname = "enforce_symlinksifowner",
78709 + .data = &grsec_enable_symlinkown,
78710 + .maxlen = sizeof(int),
78711 + .mode = 0600,
78712 + .proc_handler = &proc_dointvec,
78713 + },
78714 + {
78715 + .procname = "symlinkown_gid",
78716 + .data = &grsec_symlinkown_gid,
78717 + .maxlen = sizeof(int),
78718 + .mode = 0600,
78719 + .proc_handler = &proc_dointvec,
78720 + },
78721 +#endif
78722 +#ifdef CONFIG_GRKERNSEC_BRUTE
78723 + {
78724 + .procname = "deter_bruteforce",
78725 + .data = &grsec_enable_brute,
78726 + .maxlen = sizeof(int),
78727 + .mode = 0600,
78728 + .proc_handler = &proc_dointvec,
78729 + },
78730 +#endif
78731 +#ifdef CONFIG_GRKERNSEC_FIFO
78732 + {
78733 + .procname = "fifo_restrictions",
78734 + .data = &grsec_enable_fifo,
78735 + .maxlen = sizeof(int),
78736 + .mode = 0600,
78737 + .proc_handler = &proc_dointvec,
78738 + },
78739 +#endif
78740 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78741 + {
78742 + .procname = "ptrace_readexec",
78743 + .data = &grsec_enable_ptrace_readexec,
78744 + .maxlen = sizeof(int),
78745 + .mode = 0600,
78746 + .proc_handler = &proc_dointvec,
78747 + },
78748 +#endif
78749 +#ifdef CONFIG_GRKERNSEC_SETXID
78750 + {
78751 + .procname = "consistent_setxid",
78752 + .data = &grsec_enable_setxid,
78753 + .maxlen = sizeof(int),
78754 + .mode = 0600,
78755 + .proc_handler = &proc_dointvec,
78756 + },
78757 +#endif
78758 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78759 + {
78760 + .procname = "ip_blackhole",
78761 + .data = &grsec_enable_blackhole,
78762 + .maxlen = sizeof(int),
78763 + .mode = 0600,
78764 + .proc_handler = &proc_dointvec,
78765 + },
78766 + {
78767 + .procname = "lastack_retries",
78768 + .data = &grsec_lastack_retries,
78769 + .maxlen = sizeof(int),
78770 + .mode = 0600,
78771 + .proc_handler = &proc_dointvec,
78772 + },
78773 +#endif
78774 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78775 + {
78776 + .procname = "exec_logging",
78777 + .data = &grsec_enable_execlog,
78778 + .maxlen = sizeof(int),
78779 + .mode = 0600,
78780 + .proc_handler = &proc_dointvec,
78781 + },
78782 +#endif
78783 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78784 + {
78785 + .procname = "rwxmap_logging",
78786 + .data = &grsec_enable_log_rwxmaps,
78787 + .maxlen = sizeof(int),
78788 + .mode = 0600,
78789 + .proc_handler = &proc_dointvec,
78790 + },
78791 +#endif
78792 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78793 + {
78794 + .procname = "signal_logging",
78795 + .data = &grsec_enable_signal,
78796 + .maxlen = sizeof(int),
78797 + .mode = 0600,
78798 + .proc_handler = &proc_dointvec,
78799 + },
78800 +#endif
78801 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78802 + {
78803 + .procname = "forkfail_logging",
78804 + .data = &grsec_enable_forkfail,
78805 + .maxlen = sizeof(int),
78806 + .mode = 0600,
78807 + .proc_handler = &proc_dointvec,
78808 + },
78809 +#endif
78810 +#ifdef CONFIG_GRKERNSEC_TIME
78811 + {
78812 + .procname = "timechange_logging",
78813 + .data = &grsec_enable_time,
78814 + .maxlen = sizeof(int),
78815 + .mode = 0600,
78816 + .proc_handler = &proc_dointvec,
78817 + },
78818 +#endif
78819 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78820 + {
78821 + .procname = "chroot_deny_shmat",
78822 + .data = &grsec_enable_chroot_shmat,
78823 + .maxlen = sizeof(int),
78824 + .mode = 0600,
78825 + .proc_handler = &proc_dointvec,
78826 + },
78827 +#endif
78828 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78829 + {
78830 + .procname = "chroot_deny_unix",
78831 + .data = &grsec_enable_chroot_unix,
78832 + .maxlen = sizeof(int),
78833 + .mode = 0600,
78834 + .proc_handler = &proc_dointvec,
78835 + },
78836 +#endif
78837 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78838 + {
78839 + .procname = "chroot_deny_mount",
78840 + .data = &grsec_enable_chroot_mount,
78841 + .maxlen = sizeof(int),
78842 + .mode = 0600,
78843 + .proc_handler = &proc_dointvec,
78844 + },
78845 +#endif
78846 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78847 + {
78848 + .procname = "chroot_deny_fchdir",
78849 + .data = &grsec_enable_chroot_fchdir,
78850 + .maxlen = sizeof(int),
78851 + .mode = 0600,
78852 + .proc_handler = &proc_dointvec,
78853 + },
78854 +#endif
78855 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78856 + {
78857 + .procname = "chroot_deny_chroot",
78858 + .data = &grsec_enable_chroot_double,
78859 + .maxlen = sizeof(int),
78860 + .mode = 0600,
78861 + .proc_handler = &proc_dointvec,
78862 + },
78863 +#endif
78864 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78865 + {
78866 + .procname = "chroot_deny_pivot",
78867 + .data = &grsec_enable_chroot_pivot,
78868 + .maxlen = sizeof(int),
78869 + .mode = 0600,
78870 + .proc_handler = &proc_dointvec,
78871 + },
78872 +#endif
78873 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78874 + {
78875 + .procname = "chroot_enforce_chdir",
78876 + .data = &grsec_enable_chroot_chdir,
78877 + .maxlen = sizeof(int),
78878 + .mode = 0600,
78879 + .proc_handler = &proc_dointvec,
78880 + },
78881 +#endif
78882 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78883 + {
78884 + .procname = "chroot_deny_chmod",
78885 + .data = &grsec_enable_chroot_chmod,
78886 + .maxlen = sizeof(int),
78887 + .mode = 0600,
78888 + .proc_handler = &proc_dointvec,
78889 + },
78890 +#endif
78891 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78892 + {
78893 + .procname = "chroot_deny_mknod",
78894 + .data = &grsec_enable_chroot_mknod,
78895 + .maxlen = sizeof(int),
78896 + .mode = 0600,
78897 + .proc_handler = &proc_dointvec,
78898 + },
78899 +#endif
78900 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78901 + {
78902 + .procname = "chroot_restrict_nice",
78903 + .data = &grsec_enable_chroot_nice,
78904 + .maxlen = sizeof(int),
78905 + .mode = 0600,
78906 + .proc_handler = &proc_dointvec,
78907 + },
78908 +#endif
78909 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78910 + {
78911 + .procname = "chroot_execlog",
78912 + .data = &grsec_enable_chroot_execlog,
78913 + .maxlen = sizeof(int),
78914 + .mode = 0600,
78915 + .proc_handler = &proc_dointvec,
78916 + },
78917 +#endif
78918 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78919 + {
78920 + .procname = "chroot_caps",
78921 + .data = &grsec_enable_chroot_caps,
78922 + .maxlen = sizeof(int),
78923 + .mode = 0600,
78924 + .proc_handler = &proc_dointvec,
78925 + },
78926 +#endif
78927 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
78928 + {
78929 + .procname = "chroot_deny_bad_rename",
78930 + .data = &grsec_enable_chroot_rename,
78931 + .maxlen = sizeof(int),
78932 + .mode = 0600,
78933 + .proc_handler = &proc_dointvec,
78934 + },
78935 +#endif
78936 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78937 + {
78938 + .procname = "chroot_deny_sysctl",
78939 + .data = &grsec_enable_chroot_sysctl,
78940 + .maxlen = sizeof(int),
78941 + .mode = 0600,
78942 + .proc_handler = &proc_dointvec,
78943 + },
78944 +#endif
78945 +#ifdef CONFIG_GRKERNSEC_TPE
78946 + {
78947 + .procname = "tpe",
78948 + .data = &grsec_enable_tpe,
78949 + .maxlen = sizeof(int),
78950 + .mode = 0600,
78951 + .proc_handler = &proc_dointvec,
78952 + },
78953 + {
78954 + .procname = "tpe_gid",
78955 + .data = &grsec_tpe_gid,
78956 + .maxlen = sizeof(int),
78957 + .mode = 0600,
78958 + .proc_handler = &proc_dointvec,
78959 + },
78960 +#endif
78961 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78962 + {
78963 + .procname = "tpe_invert",
78964 + .data = &grsec_enable_tpe_invert,
78965 + .maxlen = sizeof(int),
78966 + .mode = 0600,
78967 + .proc_handler = &proc_dointvec,
78968 + },
78969 +#endif
78970 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78971 + {
78972 + .procname = "tpe_restrict_all",
78973 + .data = &grsec_enable_tpe_all,
78974 + .maxlen = sizeof(int),
78975 + .mode = 0600,
78976 + .proc_handler = &proc_dointvec,
78977 + },
78978 +#endif
78979 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78980 + {
78981 + .procname = "socket_all",
78982 + .data = &grsec_enable_socket_all,
78983 + .maxlen = sizeof(int),
78984 + .mode = 0600,
78985 + .proc_handler = &proc_dointvec,
78986 + },
78987 + {
78988 + .procname = "socket_all_gid",
78989 + .data = &grsec_socket_all_gid,
78990 + .maxlen = sizeof(int),
78991 + .mode = 0600,
78992 + .proc_handler = &proc_dointvec,
78993 + },
78994 +#endif
78995 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78996 + {
78997 + .procname = "socket_client",
78998 + .data = &grsec_enable_socket_client,
78999 + .maxlen = sizeof(int),
79000 + .mode = 0600,
79001 + .proc_handler = &proc_dointvec,
79002 + },
79003 + {
79004 + .procname = "socket_client_gid",
79005 + .data = &grsec_socket_client_gid,
79006 + .maxlen = sizeof(int),
79007 + .mode = 0600,
79008 + .proc_handler = &proc_dointvec,
79009 + },
79010 +#endif
79011 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79012 + {
79013 + .procname = "socket_server",
79014 + .data = &grsec_enable_socket_server,
79015 + .maxlen = sizeof(int),
79016 + .mode = 0600,
79017 + .proc_handler = &proc_dointvec,
79018 + },
79019 + {
79020 + .procname = "socket_server_gid",
79021 + .data = &grsec_socket_server_gid,
79022 + .maxlen = sizeof(int),
79023 + .mode = 0600,
79024 + .proc_handler = &proc_dointvec,
79025 + },
79026 +#endif
79027 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79028 + {
79029 + .procname = "audit_group",
79030 + .data = &grsec_enable_group,
79031 + .maxlen = sizeof(int),
79032 + .mode = 0600,
79033 + .proc_handler = &proc_dointvec,
79034 + },
79035 + {
79036 + .procname = "audit_gid",
79037 + .data = &grsec_audit_gid,
79038 + .maxlen = sizeof(int),
79039 + .mode = 0600,
79040 + .proc_handler = &proc_dointvec,
79041 + },
79042 +#endif
79043 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79044 + {
79045 + .procname = "audit_chdir",
79046 + .data = &grsec_enable_chdir,
79047 + .maxlen = sizeof(int),
79048 + .mode = 0600,
79049 + .proc_handler = &proc_dointvec,
79050 + },
79051 +#endif
79052 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79053 + {
79054 + .procname = "audit_mount",
79055 + .data = &grsec_enable_mount,
79056 + .maxlen = sizeof(int),
79057 + .mode = 0600,
79058 + .proc_handler = &proc_dointvec,
79059 + },
79060 +#endif
79061 +#ifdef CONFIG_GRKERNSEC_DMESG
79062 + {
79063 + .procname = "dmesg",
79064 + .data = &grsec_enable_dmesg,
79065 + .maxlen = sizeof(int),
79066 + .mode = 0600,
79067 + .proc_handler = &proc_dointvec,
79068 + },
79069 +#endif
79070 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79071 + {
79072 + .procname = "chroot_findtask",
79073 + .data = &grsec_enable_chroot_findtask,
79074 + .maxlen = sizeof(int),
79075 + .mode = 0600,
79076 + .proc_handler = &proc_dointvec,
79077 + },
79078 +#endif
79079 +#ifdef CONFIG_GRKERNSEC_RESLOG
79080 + {
79081 + .procname = "resource_logging",
79082 + .data = &grsec_resource_logging,
79083 + .maxlen = sizeof(int),
79084 + .mode = 0600,
79085 + .proc_handler = &proc_dointvec,
79086 + },
79087 +#endif
79088 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79089 + {
79090 + .procname = "audit_ptrace",
79091 + .data = &grsec_enable_audit_ptrace,
79092 + .maxlen = sizeof(int),
79093 + .mode = 0600,
79094 + .proc_handler = &proc_dointvec,
79095 + },
79096 +#endif
79097 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79098 + {
79099 + .procname = "harden_ptrace",
79100 + .data = &grsec_enable_harden_ptrace,
79101 + .maxlen = sizeof(int),
79102 + .mode = 0600,
79103 + .proc_handler = &proc_dointvec,
79104 + },
79105 +#endif
79106 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79107 + {
79108 + .procname = "harden_ipc",
79109 + .data = &grsec_enable_harden_ipc,
79110 + .maxlen = sizeof(int),
79111 + .mode = 0600,
79112 + .proc_handler = &proc_dointvec,
79113 + },
79114 +#endif
79115 + {
79116 + .procname = "grsec_lock",
79117 + .data = &grsec_lock,
79118 + .maxlen = sizeof(int),
79119 + .mode = 0600,
79120 + .proc_handler = &proc_dointvec,
79121 + },
79122 +#endif
79123 +#ifdef CONFIG_GRKERNSEC_ROFS
79124 + {
79125 + .procname = "romount_protect",
79126 + .data = &grsec_enable_rofs,
79127 + .maxlen = sizeof(int),
79128 + .mode = 0600,
79129 + .proc_handler = &proc_dointvec_minmax,
79130 + .extra1 = &one,
79131 + .extra2 = &one,
79132 + },
79133 +#endif
79134 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79135 + {
79136 + .procname = "deny_new_usb",
79137 + .data = &grsec_deny_new_usb,
79138 + .maxlen = sizeof(int),
79139 + .mode = 0600,
79140 + .proc_handler = &proc_dointvec,
79141 + },
79142 +#endif
79143 + { }
79144 +};
79145 +#endif
79146 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79147 new file mode 100644
79148 index 0000000..61b514e
79149 --- /dev/null
79150 +++ b/grsecurity/grsec_time.c
79151 @@ -0,0 +1,16 @@
79152 +#include <linux/kernel.h>
79153 +#include <linux/sched.h>
79154 +#include <linux/grinternal.h>
79155 +#include <linux/module.h>
79156 +
79157 +void
79158 +gr_log_timechange(void)
79159 +{
79160 +#ifdef CONFIG_GRKERNSEC_TIME
79161 + if (grsec_enable_time)
79162 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79163 +#endif
79164 + return;
79165 +}
79166 +
79167 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79168 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79169 new file mode 100644
79170 index 0000000..d1953de
79171 --- /dev/null
79172 +++ b/grsecurity/grsec_tpe.c
79173 @@ -0,0 +1,78 @@
79174 +#include <linux/kernel.h>
79175 +#include <linux/sched.h>
79176 +#include <linux/file.h>
79177 +#include <linux/fs.h>
79178 +#include <linux/grinternal.h>
79179 +
79180 +extern int gr_acl_tpe_check(void);
79181 +
79182 +int
79183 +gr_tpe_allow(const struct file *file)
79184 +{
79185 +#ifdef CONFIG_GRKERNSEC
79186 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79187 + struct inode *file_inode = file->f_path.dentry->d_inode;
79188 + const struct cred *cred = current_cred();
79189 + char *msg = NULL;
79190 + char *msg2 = NULL;
79191 +
79192 + // never restrict root
79193 + if (gr_is_global_root(cred->uid))
79194 + return 1;
79195 +
79196 + if (grsec_enable_tpe) {
79197 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79198 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79199 + msg = "not being in trusted group";
79200 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79201 + msg = "being in untrusted group";
79202 +#else
79203 + if (in_group_p(grsec_tpe_gid))
79204 + msg = "being in untrusted group";
79205 +#endif
79206 + }
79207 + if (!msg && gr_acl_tpe_check())
79208 + msg = "being in untrusted role";
79209 +
79210 + // not in any affected group/role
79211 + if (!msg)
79212 + goto next_check;
79213 +
79214 + if (gr_is_global_nonroot(inode->i_uid))
79215 + msg2 = "file in non-root-owned directory";
79216 + else if (inode->i_mode & S_IWOTH)
79217 + msg2 = "file in world-writable directory";
79218 + else if (inode->i_mode & S_IWGRP)
79219 + msg2 = "file in group-writable directory";
79220 + else if (file_inode->i_mode & S_IWOTH)
79221 + msg2 = "file is world-writable";
79222 +
79223 + if (msg && msg2) {
79224 + char fullmsg[70] = {0};
79225 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79226 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79227 + return 0;
79228 + }
79229 + msg = NULL;
79230 +next_check:
79231 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79232 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79233 + return 1;
79234 +
79235 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79236 + msg = "directory not owned by user";
79237 + else if (inode->i_mode & S_IWOTH)
79238 + msg = "file in world-writable directory";
79239 + else if (inode->i_mode & S_IWGRP)
79240 + msg = "file in group-writable directory";
79241 + else if (file_inode->i_mode & S_IWOTH)
79242 + msg = "file is world-writable";
79243 +
79244 + if (msg) {
79245 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79246 + return 0;
79247 + }
79248 +#endif
79249 +#endif
79250 + return 1;
79251 +}
79252 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79253 new file mode 100644
79254 index 0000000..ae02d8e
79255 --- /dev/null
79256 +++ b/grsecurity/grsec_usb.c
79257 @@ -0,0 +1,15 @@
79258 +#include <linux/kernel.h>
79259 +#include <linux/grinternal.h>
79260 +#include <linux/module.h>
79261 +
79262 +int gr_handle_new_usb(void)
79263 +{
79264 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79265 + if (grsec_deny_new_usb) {
79266 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79267 + return 1;
79268 + }
79269 +#endif
79270 + return 0;
79271 +}
79272 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79273 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79274 new file mode 100644
79275 index 0000000..158b330
79276 --- /dev/null
79277 +++ b/grsecurity/grsum.c
79278 @@ -0,0 +1,64 @@
79279 +#include <linux/err.h>
79280 +#include <linux/kernel.h>
79281 +#include <linux/sched.h>
79282 +#include <linux/mm.h>
79283 +#include <linux/scatterlist.h>
79284 +#include <linux/crypto.h>
79285 +#include <linux/gracl.h>
79286 +
79287 +
79288 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79289 +#error "crypto and sha256 must be built into the kernel"
79290 +#endif
79291 +
79292 +int
79293 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79294 +{
79295 + struct crypto_hash *tfm;
79296 + struct hash_desc desc;
79297 + struct scatterlist sg[2];
79298 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79299 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79300 + unsigned long *sumptr = (unsigned long *)sum;
79301 + int cryptres;
79302 + int retval = 1;
79303 + volatile int mismatched = 0;
79304 + volatile int dummy = 0;
79305 + unsigned int i;
79306 +
79307 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79308 + if (IS_ERR(tfm)) {
79309 + /* should never happen, since sha256 should be built in */
79310 + memset(entry->pw, 0, GR_PW_LEN);
79311 + return 1;
79312 + }
79313 +
79314 + sg_init_table(sg, 2);
79315 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79316 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79317 +
79318 + desc.tfm = tfm;
79319 + desc.flags = 0;
79320 +
79321 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79322 + temp_sum);
79323 +
79324 + memset(entry->pw, 0, GR_PW_LEN);
79325 +
79326 + if (cryptres)
79327 + goto out;
79328 +
79329 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79330 + if (sumptr[i] != tmpsumptr[i])
79331 + mismatched = 1;
79332 + else
79333 + dummy = 1; // waste a cycle
79334 +
79335 + if (!mismatched)
79336 + retval = dummy - 1;
79337 +
79338 +out:
79339 + crypto_free_hash(tfm);
79340 +
79341 + return retval;
79342 +}
79343 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79344 index 77ff547..181834f 100644
79345 --- a/include/asm-generic/4level-fixup.h
79346 +++ b/include/asm-generic/4level-fixup.h
79347 @@ -13,8 +13,10 @@
79348 #define pmd_alloc(mm, pud, address) \
79349 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79350 NULL: pmd_offset(pud, address))
79351 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79352
79353 #define pud_alloc(mm, pgd, address) (pgd)
79354 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79355 #define pud_offset(pgd, start) (pgd)
79356 #define pud_none(pud) 0
79357 #define pud_bad(pud) 0
79358 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79359 index b7babf0..1e4b4f1 100644
79360 --- a/include/asm-generic/atomic-long.h
79361 +++ b/include/asm-generic/atomic-long.h
79362 @@ -22,6 +22,12 @@
79363
79364 typedef atomic64_t atomic_long_t;
79365
79366 +#ifdef CONFIG_PAX_REFCOUNT
79367 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79368 +#else
79369 +typedef atomic64_t atomic_long_unchecked_t;
79370 +#endif
79371 +
79372 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79373
79374 static inline long atomic_long_read(atomic_long_t *l)
79375 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79376 return (long)atomic64_read(v);
79377 }
79378
79379 +#ifdef CONFIG_PAX_REFCOUNT
79380 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79381 +{
79382 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79383 +
79384 + return (long)atomic64_read_unchecked(v);
79385 +}
79386 +#endif
79387 +
79388 static inline void atomic_long_set(atomic_long_t *l, long i)
79389 {
79390 atomic64_t *v = (atomic64_t *)l;
79391 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79392 atomic64_set(v, i);
79393 }
79394
79395 +#ifdef CONFIG_PAX_REFCOUNT
79396 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79397 +{
79398 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79399 +
79400 + atomic64_set_unchecked(v, i);
79401 +}
79402 +#endif
79403 +
79404 static inline void atomic_long_inc(atomic_long_t *l)
79405 {
79406 atomic64_t *v = (atomic64_t *)l;
79407 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79408 atomic64_inc(v);
79409 }
79410
79411 +#ifdef CONFIG_PAX_REFCOUNT
79412 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79413 +{
79414 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79415 +
79416 + atomic64_inc_unchecked(v);
79417 +}
79418 +#endif
79419 +
79420 static inline void atomic_long_dec(atomic_long_t *l)
79421 {
79422 atomic64_t *v = (atomic64_t *)l;
79423 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79424 atomic64_dec(v);
79425 }
79426
79427 +#ifdef CONFIG_PAX_REFCOUNT
79428 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79429 +{
79430 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79431 +
79432 + atomic64_dec_unchecked(v);
79433 +}
79434 +#endif
79435 +
79436 static inline void atomic_long_add(long i, atomic_long_t *l)
79437 {
79438 atomic64_t *v = (atomic64_t *)l;
79439 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79440 atomic64_add(i, v);
79441 }
79442
79443 +#ifdef CONFIG_PAX_REFCOUNT
79444 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79445 +{
79446 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79447 +
79448 + atomic64_add_unchecked(i, v);
79449 +}
79450 +#endif
79451 +
79452 static inline void atomic_long_sub(long i, atomic_long_t *l)
79453 {
79454 atomic64_t *v = (atomic64_t *)l;
79455 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79456 atomic64_sub(i, v);
79457 }
79458
79459 +#ifdef CONFIG_PAX_REFCOUNT
79460 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79461 +{
79462 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79463 +
79464 + atomic64_sub_unchecked(i, v);
79465 +}
79466 +#endif
79467 +
79468 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79469 {
79470 atomic64_t *v = (atomic64_t *)l;
79471 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79472 return atomic64_add_negative(i, v);
79473 }
79474
79475 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79476 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79477 {
79478 atomic64_t *v = (atomic64_t *)l;
79479
79480 return (long)atomic64_add_return(i, v);
79481 }
79482
79483 +#ifdef CONFIG_PAX_REFCOUNT
79484 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79485 +{
79486 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79487 +
79488 + return (long)atomic64_add_return_unchecked(i, v);
79489 +}
79490 +#endif
79491 +
79492 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79493 {
79494 atomic64_t *v = (atomic64_t *)l;
79495 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79496 return (long)atomic64_inc_return(v);
79497 }
79498
79499 +#ifdef CONFIG_PAX_REFCOUNT
79500 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79501 +{
79502 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79503 +
79504 + return (long)atomic64_inc_return_unchecked(v);
79505 +}
79506 +#endif
79507 +
79508 static inline long atomic_long_dec_return(atomic_long_t *l)
79509 {
79510 atomic64_t *v = (atomic64_t *)l;
79511 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79512
79513 typedef atomic_t atomic_long_t;
79514
79515 +#ifdef CONFIG_PAX_REFCOUNT
79516 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79517 +#else
79518 +typedef atomic_t atomic_long_unchecked_t;
79519 +#endif
79520 +
79521 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79522 static inline long atomic_long_read(atomic_long_t *l)
79523 {
79524 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79525 return (long)atomic_read(v);
79526 }
79527
79528 +#ifdef CONFIG_PAX_REFCOUNT
79529 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79530 +{
79531 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79532 +
79533 + return (long)atomic_read_unchecked(v);
79534 +}
79535 +#endif
79536 +
79537 static inline void atomic_long_set(atomic_long_t *l, long i)
79538 {
79539 atomic_t *v = (atomic_t *)l;
79540 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79541 atomic_set(v, i);
79542 }
79543
79544 +#ifdef CONFIG_PAX_REFCOUNT
79545 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79546 +{
79547 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79548 +
79549 + atomic_set_unchecked(v, i);
79550 +}
79551 +#endif
79552 +
79553 static inline void atomic_long_inc(atomic_long_t *l)
79554 {
79555 atomic_t *v = (atomic_t *)l;
79556 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79557 atomic_inc(v);
79558 }
79559
79560 +#ifdef CONFIG_PAX_REFCOUNT
79561 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79562 +{
79563 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79564 +
79565 + atomic_inc_unchecked(v);
79566 +}
79567 +#endif
79568 +
79569 static inline void atomic_long_dec(atomic_long_t *l)
79570 {
79571 atomic_t *v = (atomic_t *)l;
79572 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79573 atomic_dec(v);
79574 }
79575
79576 +#ifdef CONFIG_PAX_REFCOUNT
79577 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79578 +{
79579 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79580 +
79581 + atomic_dec_unchecked(v);
79582 +}
79583 +#endif
79584 +
79585 static inline void atomic_long_add(long i, atomic_long_t *l)
79586 {
79587 atomic_t *v = (atomic_t *)l;
79588 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79589 atomic_add(i, v);
79590 }
79591
79592 +#ifdef CONFIG_PAX_REFCOUNT
79593 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79594 +{
79595 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79596 +
79597 + atomic_add_unchecked(i, v);
79598 +}
79599 +#endif
79600 +
79601 static inline void atomic_long_sub(long i, atomic_long_t *l)
79602 {
79603 atomic_t *v = (atomic_t *)l;
79604 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79605 atomic_sub(i, v);
79606 }
79607
79608 +#ifdef CONFIG_PAX_REFCOUNT
79609 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79610 +{
79611 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79612 +
79613 + atomic_sub_unchecked(i, v);
79614 +}
79615 +#endif
79616 +
79617 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79618 {
79619 atomic_t *v = (atomic_t *)l;
79620 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79621 return atomic_add_negative(i, v);
79622 }
79623
79624 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79625 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79626 {
79627 atomic_t *v = (atomic_t *)l;
79628
79629 return (long)atomic_add_return(i, v);
79630 }
79631
79632 +#ifdef CONFIG_PAX_REFCOUNT
79633 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79634 +{
79635 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79636 +
79637 + return (long)atomic_add_return_unchecked(i, v);
79638 +}
79639 +
79640 +#endif
79641 +
79642 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79643 {
79644 atomic_t *v = (atomic_t *)l;
79645 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79646 return (long)atomic_inc_return(v);
79647 }
79648
79649 +#ifdef CONFIG_PAX_REFCOUNT
79650 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79651 +{
79652 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79653 +
79654 + return (long)atomic_inc_return_unchecked(v);
79655 +}
79656 +#endif
79657 +
79658 static inline long atomic_long_dec_return(atomic_long_t *l)
79659 {
79660 atomic_t *v = (atomic_t *)l;
79661 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79662
79663 #endif /* BITS_PER_LONG == 64 */
79664
79665 +#ifdef CONFIG_PAX_REFCOUNT
79666 +static inline void pax_refcount_needs_these_functions(void)
79667 +{
79668 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79669 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79670 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79671 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79672 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79673 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79674 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79675 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79676 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79677 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79678 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79679 +#ifdef CONFIG_X86
79680 + atomic_clear_mask_unchecked(0, NULL);
79681 + atomic_set_mask_unchecked(0, NULL);
79682 +#endif
79683 +
79684 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79685 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79686 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79687 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79688 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79689 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79690 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79691 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79692 +}
79693 +#else
79694 +#define atomic_read_unchecked(v) atomic_read(v)
79695 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79696 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79697 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79698 +#define atomic_inc_unchecked(v) atomic_inc(v)
79699 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79700 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79701 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79702 +#define atomic_dec_unchecked(v) atomic_dec(v)
79703 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79704 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79705 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79706 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79707 +
79708 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79709 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79710 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79711 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79712 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79713 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79714 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79715 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79716 +#endif
79717 +
79718 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79719 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79720 index 30ad9c8..c70c170 100644
79721 --- a/include/asm-generic/atomic64.h
79722 +++ b/include/asm-generic/atomic64.h
79723 @@ -16,6 +16,8 @@ typedef struct {
79724 long long counter;
79725 } atomic64_t;
79726
79727 +typedef atomic64_t atomic64_unchecked_t;
79728 +
79729 #define ATOMIC64_INIT(i) { (i) }
79730
79731 extern long long atomic64_read(const atomic64_t *v);
79732 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79733 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79734 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79735
79736 +#define atomic64_read_unchecked(v) atomic64_read(v)
79737 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79738 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79739 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79740 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79741 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79742 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79743 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79744 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79745 +
79746 #endif /* _ASM_GENERIC_ATOMIC64_H */
79747 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79748 index 1402fa8..025a736 100644
79749 --- a/include/asm-generic/barrier.h
79750 +++ b/include/asm-generic/barrier.h
79751 @@ -74,7 +74,7 @@
79752 do { \
79753 compiletime_assert_atomic_type(*p); \
79754 smp_mb(); \
79755 - ACCESS_ONCE(*p) = (v); \
79756 + ACCESS_ONCE_RW(*p) = (v); \
79757 } while (0)
79758
79759 #define smp_load_acquire(p) \
79760 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79761 index a60a7cc..0fe12f2 100644
79762 --- a/include/asm-generic/bitops/__fls.h
79763 +++ b/include/asm-generic/bitops/__fls.h
79764 @@ -9,7 +9,7 @@
79765 *
79766 * Undefined if no set bit exists, so code should check against 0 first.
79767 */
79768 -static __always_inline unsigned long __fls(unsigned long word)
79769 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79770 {
79771 int num = BITS_PER_LONG - 1;
79772
79773 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79774 index 0576d1f..dad6c71 100644
79775 --- a/include/asm-generic/bitops/fls.h
79776 +++ b/include/asm-generic/bitops/fls.h
79777 @@ -9,7 +9,7 @@
79778 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79779 */
79780
79781 -static __always_inline int fls(int x)
79782 +static __always_inline int __intentional_overflow(-1) fls(int x)
79783 {
79784 int r = 32;
79785
79786 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79787 index b097cf8..3d40e14 100644
79788 --- a/include/asm-generic/bitops/fls64.h
79789 +++ b/include/asm-generic/bitops/fls64.h
79790 @@ -15,7 +15,7 @@
79791 * at position 64.
79792 */
79793 #if BITS_PER_LONG == 32
79794 -static __always_inline int fls64(__u64 x)
79795 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79796 {
79797 __u32 h = x >> 32;
79798 if (h)
79799 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79800 return fls(x);
79801 }
79802 #elif BITS_PER_LONG == 64
79803 -static __always_inline int fls64(__u64 x)
79804 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79805 {
79806 if (x == 0)
79807 return 0;
79808 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79809 index 1bfcfe5..e04c5c9 100644
79810 --- a/include/asm-generic/cache.h
79811 +++ b/include/asm-generic/cache.h
79812 @@ -6,7 +6,7 @@
79813 * cache lines need to provide their own cache.h.
79814 */
79815
79816 -#define L1_CACHE_SHIFT 5
79817 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79818 +#define L1_CACHE_SHIFT 5UL
79819 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79820
79821 #endif /* __ASM_GENERIC_CACHE_H */
79822 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79823 index 0d68a1e..b74a761 100644
79824 --- a/include/asm-generic/emergency-restart.h
79825 +++ b/include/asm-generic/emergency-restart.h
79826 @@ -1,7 +1,7 @@
79827 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79828 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79829
79830 -static inline void machine_emergency_restart(void)
79831 +static inline __noreturn void machine_emergency_restart(void)
79832 {
79833 machine_restart(NULL);
79834 }
79835 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79836 index b8fdc57..c6d5a5c 100644
79837 --- a/include/asm-generic/io.h
79838 +++ b/include/asm-generic/io.h
79839 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79840 * These are pretty trivial
79841 */
79842 #ifndef virt_to_phys
79843 -static inline unsigned long virt_to_phys(volatile void *address)
79844 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79845 {
79846 return __pa((unsigned long)address);
79847 }
79848 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79849 index 90f99c7..00ce236 100644
79850 --- a/include/asm-generic/kmap_types.h
79851 +++ b/include/asm-generic/kmap_types.h
79852 @@ -2,9 +2,9 @@
79853 #define _ASM_GENERIC_KMAP_TYPES_H
79854
79855 #ifdef __WITH_KM_FENCE
79856 -# define KM_TYPE_NR 41
79857 +# define KM_TYPE_NR 42
79858 #else
79859 -# define KM_TYPE_NR 20
79860 +# define KM_TYPE_NR 21
79861 #endif
79862
79863 #endif
79864 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79865 index 9ceb03b..62b0b8f 100644
79866 --- a/include/asm-generic/local.h
79867 +++ b/include/asm-generic/local.h
79868 @@ -23,24 +23,37 @@ typedef struct
79869 atomic_long_t a;
79870 } local_t;
79871
79872 +typedef struct {
79873 + atomic_long_unchecked_t a;
79874 +} local_unchecked_t;
79875 +
79876 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79877
79878 #define local_read(l) atomic_long_read(&(l)->a)
79879 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79880 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79881 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79882 #define local_inc(l) atomic_long_inc(&(l)->a)
79883 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79884 #define local_dec(l) atomic_long_dec(&(l)->a)
79885 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79886 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79887 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79888 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79889 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79890
79891 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79892 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79893 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79894 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79895 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79896 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79897 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79898 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79899 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79900
79901 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79902 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79903 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79904 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79905 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79906 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79907 index 725612b..9cc513a 100644
79908 --- a/include/asm-generic/pgtable-nopmd.h
79909 +++ b/include/asm-generic/pgtable-nopmd.h
79910 @@ -1,14 +1,19 @@
79911 #ifndef _PGTABLE_NOPMD_H
79912 #define _PGTABLE_NOPMD_H
79913
79914 -#ifndef __ASSEMBLY__
79915 -
79916 #include <asm-generic/pgtable-nopud.h>
79917
79918 -struct mm_struct;
79919 -
79920 #define __PAGETABLE_PMD_FOLDED
79921
79922 +#define PMD_SHIFT PUD_SHIFT
79923 +#define PTRS_PER_PMD 1
79924 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79925 +#define PMD_MASK (~(PMD_SIZE-1))
79926 +
79927 +#ifndef __ASSEMBLY__
79928 +
79929 +struct mm_struct;
79930 +
79931 /*
79932 * Having the pmd type consist of a pud gets the size right, and allows
79933 * us to conceptually access the pud entry that this pmd is folded into
79934 @@ -16,11 +21,6 @@ struct mm_struct;
79935 */
79936 typedef struct { pud_t pud; } pmd_t;
79937
79938 -#define PMD_SHIFT PUD_SHIFT
79939 -#define PTRS_PER_PMD 1
79940 -#define PMD_SIZE (1UL << PMD_SHIFT)
79941 -#define PMD_MASK (~(PMD_SIZE-1))
79942 -
79943 /*
79944 * The "pud_xxx()" functions here are trivial for a folded two-level
79945 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79946 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79947 index 810431d..0ec4804f 100644
79948 --- a/include/asm-generic/pgtable-nopud.h
79949 +++ b/include/asm-generic/pgtable-nopud.h
79950 @@ -1,10 +1,15 @@
79951 #ifndef _PGTABLE_NOPUD_H
79952 #define _PGTABLE_NOPUD_H
79953
79954 -#ifndef __ASSEMBLY__
79955 -
79956 #define __PAGETABLE_PUD_FOLDED
79957
79958 +#define PUD_SHIFT PGDIR_SHIFT
79959 +#define PTRS_PER_PUD 1
79960 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79961 +#define PUD_MASK (~(PUD_SIZE-1))
79962 +
79963 +#ifndef __ASSEMBLY__
79964 +
79965 /*
79966 * Having the pud type consist of a pgd gets the size right, and allows
79967 * us to conceptually access the pgd entry that this pud is folded into
79968 @@ -12,11 +17,6 @@
79969 */
79970 typedef struct { pgd_t pgd; } pud_t;
79971
79972 -#define PUD_SHIFT PGDIR_SHIFT
79973 -#define PTRS_PER_PUD 1
79974 -#define PUD_SIZE (1UL << PUD_SHIFT)
79975 -#define PUD_MASK (~(PUD_SIZE-1))
79976 -
79977 /*
79978 * The "pgd_xxx()" functions here are trivial for a folded two-level
79979 * setup: the pud is never bad, and a pud always exists (as it's folded
79980 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79981 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79982
79983 #define pgd_populate(mm, pgd, pud) do { } while (0)
79984 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79985 /*
79986 * (puds are folded into pgds so this doesn't get actually called,
79987 * but the define is needed for a generic inline function.)
79988 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79989 index 752e30d..87f172d 100644
79990 --- a/include/asm-generic/pgtable.h
79991 +++ b/include/asm-generic/pgtable.h
79992 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79993 }
79994 #endif /* CONFIG_NUMA_BALANCING */
79995
79996 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79997 +#ifdef CONFIG_PAX_KERNEXEC
79998 +#error KERNEXEC requires pax_open_kernel
79999 +#else
80000 +static inline unsigned long pax_open_kernel(void) { return 0; }
80001 +#endif
80002 +#endif
80003 +
80004 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80005 +#ifdef CONFIG_PAX_KERNEXEC
80006 +#error KERNEXEC requires pax_close_kernel
80007 +#else
80008 +static inline unsigned long pax_close_kernel(void) { return 0; }
80009 +#endif
80010 +#endif
80011 +
80012 #endif /* CONFIG_MMU */
80013
80014 #endif /* !__ASSEMBLY__ */
80015 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80016 index 72d8803..cb9749c 100644
80017 --- a/include/asm-generic/uaccess.h
80018 +++ b/include/asm-generic/uaccess.h
80019 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80020 return __clear_user(to, n);
80021 }
80022
80023 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80025 +#error UDEREF requires pax_open_userland
80026 +#else
80027 +static inline unsigned long pax_open_userland(void) { return 0; }
80028 +#endif
80029 +#endif
80030 +
80031 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80032 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80033 +#error UDEREF requires pax_close_userland
80034 +#else
80035 +static inline unsigned long pax_close_userland(void) { return 0; }
80036 +#endif
80037 +#endif
80038 +
80039 #endif /* __ASM_GENERIC_UACCESS_H */
80040 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80041 index aa70cbd..fd72c7a 100644
80042 --- a/include/asm-generic/vmlinux.lds.h
80043 +++ b/include/asm-generic/vmlinux.lds.h
80044 @@ -233,6 +233,7 @@
80045 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80046 VMLINUX_SYMBOL(__start_rodata) = .; \
80047 *(.rodata) *(.rodata.*) \
80048 + *(.data..read_only) \
80049 *(__vermagic) /* Kernel version magic */ \
80050 . = ALIGN(8); \
80051 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80052 @@ -724,17 +725,18 @@
80053 * section in the linker script will go there too. @phdr should have
80054 * a leading colon.
80055 *
80056 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80057 + * Note that this macros defines per_cpu_load as an absolute symbol.
80058 * If there is no need to put the percpu section at a predetermined
80059 * address, use PERCPU_SECTION.
80060 */
80061 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80062 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80063 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80064 + per_cpu_load = .; \
80065 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80066 - LOAD_OFFSET) { \
80067 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80068 PERCPU_INPUT(cacheline) \
80069 } phdr \
80070 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80071 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80072
80073 /**
80074 * PERCPU_SECTION - define output section for percpu area, simple version
80075 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80076 index 623a59c..1e79ab9 100644
80077 --- a/include/crypto/algapi.h
80078 +++ b/include/crypto/algapi.h
80079 @@ -34,7 +34,7 @@ struct crypto_type {
80080 unsigned int maskclear;
80081 unsigned int maskset;
80082 unsigned int tfmsize;
80083 -};
80084 +} __do_const;
80085
80086 struct crypto_instance {
80087 struct crypto_alg alg;
80088 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80089 index 53ed876..5bb09be 100644
80090 --- a/include/drm/drmP.h
80091 +++ b/include/drm/drmP.h
80092 @@ -59,6 +59,7 @@
80093
80094 #include <asm/mman.h>
80095 #include <asm/pgalloc.h>
80096 +#include <asm/local.h>
80097 #include <asm/uaccess.h>
80098
80099 #include <uapi/drm/drm.h>
80100 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80101 * \param cmd command.
80102 * \param arg argument.
80103 */
80104 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80105 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80106 + struct drm_file *file_priv);
80107 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80108 struct drm_file *file_priv);
80109
80110 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80111 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80112 unsigned long arg);
80113
80114 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80115 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80116 struct drm_ioctl_desc {
80117 unsigned int cmd;
80118 int flags;
80119 - drm_ioctl_t *func;
80120 + drm_ioctl_t func;
80121 unsigned int cmd_drv;
80122 const char *name;
80123 -};
80124 +} __do_const;
80125
80126 /**
80127 * Creates a driver or general drm_ioctl_desc array entry for the given
80128 @@ -629,7 +632,8 @@ struct drm_info_list {
80129 int (*show)(struct seq_file*, void*); /** show callback */
80130 u32 driver_features; /**< Required driver features for this entry */
80131 void *data;
80132 -};
80133 +} __do_const;
80134 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80135
80136 /**
80137 * debugfs node structure. This structure represents a debugfs file.
80138 @@ -713,7 +717,7 @@ struct drm_device {
80139
80140 /** \name Usage Counters */
80141 /*@{ */
80142 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80143 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80144 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80145 int buf_use; /**< Buffers in use -- cannot alloc */
80146 atomic_t buf_alloc; /**< Buffer allocation in progress */
80147 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80148 index a3d75fe..6802f9c 100644
80149 --- a/include/drm/drm_crtc_helper.h
80150 +++ b/include/drm/drm_crtc_helper.h
80151 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80152 struct drm_connector *connector);
80153 /* disable encoder when not in use - more explicit than dpms off */
80154 void (*disable)(struct drm_encoder *encoder);
80155 -};
80156 +} __no_const;
80157
80158 /**
80159 * drm_connector_helper_funcs - helper operations for connectors
80160 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80161 index a70d456..6ea07cd 100644
80162 --- a/include/drm/i915_pciids.h
80163 +++ b/include/drm/i915_pciids.h
80164 @@ -37,7 +37,7 @@
80165 */
80166 #define INTEL_VGA_DEVICE(id, info) { \
80167 0x8086, id, \
80168 - ~0, ~0, \
80169 + PCI_ANY_ID, PCI_ANY_ID, \
80170 0x030000, 0xff0000, \
80171 (unsigned long) info }
80172
80173 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80174 index 72dcbe8..8db58d7 100644
80175 --- a/include/drm/ttm/ttm_memory.h
80176 +++ b/include/drm/ttm/ttm_memory.h
80177 @@ -48,7 +48,7 @@
80178
80179 struct ttm_mem_shrink {
80180 int (*do_shrink) (struct ttm_mem_shrink *);
80181 -};
80182 +} __no_const;
80183
80184 /**
80185 * struct ttm_mem_global - Global memory accounting structure.
80186 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80187 index 49a8284..9643967 100644
80188 --- a/include/drm/ttm/ttm_page_alloc.h
80189 +++ b/include/drm/ttm/ttm_page_alloc.h
80190 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80191 */
80192 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80193
80194 +struct device;
80195 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80196 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80197
80198 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80199 index 4b840e8..155d235 100644
80200 --- a/include/keys/asymmetric-subtype.h
80201 +++ b/include/keys/asymmetric-subtype.h
80202 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80203 /* Verify the signature on a key of this subtype (optional) */
80204 int (*verify_signature)(const struct key *key,
80205 const struct public_key_signature *sig);
80206 -};
80207 +} __do_const;
80208
80209 /**
80210 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80211 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80212 index c1da539..1dcec55 100644
80213 --- a/include/linux/atmdev.h
80214 +++ b/include/linux/atmdev.h
80215 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80216 #endif
80217
80218 struct k_atm_aal_stats {
80219 -#define __HANDLE_ITEM(i) atomic_t i
80220 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80221 __AAL_STAT_ITEMS
80222 #undef __HANDLE_ITEM
80223 };
80224 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80225 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80226 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80227 struct module *owner;
80228 -};
80229 +} __do_const ;
80230
80231 struct atmphy_ops {
80232 int (*start)(struct atm_dev *dev);
80233 diff --git a/include/linux/audit.h b/include/linux/audit.h
80234 index 10f155b..6c73ffe 100644
80235 --- a/include/linux/audit.h
80236 +++ b/include/linux/audit.h
80237 @@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
80238 extern unsigned int audit_serial(void);
80239 extern int auditsc_get_stamp(struct audit_context *ctx,
80240 struct timespec *t, unsigned int *serial);
80241 -extern int audit_set_loginuid(kuid_t loginuid);
80242 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80243
80244 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80245 {
80246 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80247 index 61f29e5..e67c658 100644
80248 --- a/include/linux/binfmts.h
80249 +++ b/include/linux/binfmts.h
80250 @@ -44,7 +44,7 @@ struct linux_binprm {
80251 unsigned interp_flags;
80252 unsigned interp_data;
80253 unsigned long loader, exec;
80254 -};
80255 +} __randomize_layout;
80256
80257 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80258 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80259 @@ -73,8 +73,10 @@ struct linux_binfmt {
80260 int (*load_binary)(struct linux_binprm *);
80261 int (*load_shlib)(struct file *);
80262 int (*core_dump)(struct coredump_params *cprm);
80263 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80264 + void (*handle_mmap)(struct file *);
80265 unsigned long min_coredump; /* minimal dump size */
80266 -};
80267 +} __do_const __randomize_layout;
80268
80269 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80270
80271 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80272 index 5d858e0..336c1d9 100644
80273 --- a/include/linux/bitops.h
80274 +++ b/include/linux/bitops.h
80275 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80276 * @word: value to rotate
80277 * @shift: bits to roll
80278 */
80279 -static inline __u32 rol32(__u32 word, unsigned int shift)
80280 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80281 {
80282 return (word << shift) | (word >> (32 - shift));
80283 }
80284 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80285 * @word: value to rotate
80286 * @shift: bits to roll
80287 */
80288 -static inline __u32 ror32(__u32 word, unsigned int shift)
80289 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80290 {
80291 return (word >> shift) | (word << (32 - shift));
80292 }
80293 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80294 return (__s32)(value << shift) >> shift;
80295 }
80296
80297 -static inline unsigned fls_long(unsigned long l)
80298 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80299 {
80300 if (sizeof(l) == 4)
80301 return fls(l);
80302 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80303 index aac0f9e..73c9869 100644
80304 --- a/include/linux/blkdev.h
80305 +++ b/include/linux/blkdev.h
80306 @@ -1615,7 +1615,7 @@ struct block_device_operations {
80307 /* this callback is with swap_lock and sometimes page table lock held */
80308 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80309 struct module *owner;
80310 -};
80311 +} __do_const;
80312
80313 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80314 unsigned long);
80315 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80316 index afc1343..9735539 100644
80317 --- a/include/linux/blktrace_api.h
80318 +++ b/include/linux/blktrace_api.h
80319 @@ -25,7 +25,7 @@ struct blk_trace {
80320 struct dentry *dropped_file;
80321 struct dentry *msg_file;
80322 struct list_head running_list;
80323 - atomic_t dropped;
80324 + atomic_unchecked_t dropped;
80325 };
80326
80327 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80328 diff --git a/include/linux/cache.h b/include/linux/cache.h
80329 index 17e7e82..1d7da26 100644
80330 --- a/include/linux/cache.h
80331 +++ b/include/linux/cache.h
80332 @@ -16,6 +16,14 @@
80333 #define __read_mostly
80334 #endif
80335
80336 +#ifndef __read_only
80337 +#ifdef CONFIG_PAX_KERNEXEC
80338 +#error KERNEXEC requires __read_only
80339 +#else
80340 +#define __read_only __read_mostly
80341 +#endif
80342 +#endif
80343 +
80344 #ifndef ____cacheline_aligned
80345 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80346 #endif
80347 diff --git a/include/linux/capability.h b/include/linux/capability.h
80348 index aa93e5e..985a1b0 100644
80349 --- a/include/linux/capability.h
80350 +++ b/include/linux/capability.h
80351 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80352 extern bool capable(int cap);
80353 extern bool ns_capable(struct user_namespace *ns, int cap);
80354 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80355 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80356 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80357 +extern bool capable_nolog(int cap);
80358 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80359
80360 /* audit system wants to get cap info from files as well */
80361 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80362
80363 +extern int is_privileged_binary(const struct dentry *dentry);
80364 +
80365 #endif /* !_LINUX_CAPABILITY_H */
80366 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80367 index 8609d57..86e4d79 100644
80368 --- a/include/linux/cdrom.h
80369 +++ b/include/linux/cdrom.h
80370 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80371
80372 /* driver specifications */
80373 const int capability; /* capability flags */
80374 - int n_minors; /* number of active minor devices */
80375 /* handle uniform packets for scsi type devices (scsi,atapi) */
80376 int (*generic_packet) (struct cdrom_device_info *,
80377 struct packet_command *);
80378 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80379 index 4ce9056..86caac6 100644
80380 --- a/include/linux/cleancache.h
80381 +++ b/include/linux/cleancache.h
80382 @@ -31,7 +31,7 @@ struct cleancache_ops {
80383 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80384 void (*invalidate_inode)(int, struct cleancache_filekey);
80385 void (*invalidate_fs)(int);
80386 -};
80387 +} __no_const;
80388
80389 extern struct cleancache_ops *
80390 cleancache_register_ops(struct cleancache_ops *ops);
80391 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80392 index 2839c63..5b06b6b 100644
80393 --- a/include/linux/clk-provider.h
80394 +++ b/include/linux/clk-provider.h
80395 @@ -191,6 +191,7 @@ struct clk_ops {
80396 void (*init)(struct clk_hw *hw);
80397 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80398 };
80399 +typedef struct clk_ops __no_const clk_ops_no_const;
80400
80401 /**
80402 * struct clk_init_data - holds init data that's common to all clocks and is
80403 diff --git a/include/linux/compat.h b/include/linux/compat.h
80404 index e649426..a74047b 100644
80405 --- a/include/linux/compat.h
80406 +++ b/include/linux/compat.h
80407 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80408 compat_size_t __user *len_ptr);
80409
80410 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80411 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80412 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80413 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80414 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80415 compat_ssize_t msgsz, int msgflg);
80416 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80417 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80418 compat_ulong_t addr, compat_ulong_t data);
80419 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80420 - compat_long_t addr, compat_long_t data);
80421 + compat_ulong_t addr, compat_ulong_t data);
80422
80423 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80424 /*
80425 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80426 index d1a5582..4424efa 100644
80427 --- a/include/linux/compiler-gcc4.h
80428 +++ b/include/linux/compiler-gcc4.h
80429 @@ -39,9 +39,34 @@
80430 # define __compiletime_warning(message) __attribute__((warning(message)))
80431 # define __compiletime_error(message) __attribute__((error(message)))
80432 #endif /* __CHECKER__ */
80433 +
80434 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80435 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80436 +#define __bos0(ptr) __bos((ptr), 0)
80437 +#define __bos1(ptr) __bos((ptr), 1)
80438 #endif /* GCC_VERSION >= 40300 */
80439
80440 #if GCC_VERSION >= 40500
80441 +
80442 +#ifdef RANDSTRUCT_PLUGIN
80443 +#define __randomize_layout __attribute__((randomize_layout))
80444 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80445 +#endif
80446 +
80447 +#ifdef CONSTIFY_PLUGIN
80448 +#define __no_const __attribute__((no_const))
80449 +#define __do_const __attribute__((do_const))
80450 +#endif
80451 +
80452 +#ifdef SIZE_OVERFLOW_PLUGIN
80453 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80454 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80455 +#endif
80456 +
80457 +#ifdef LATENT_ENTROPY_PLUGIN
80458 +#define __latent_entropy __attribute__((latent_entropy))
80459 +#endif
80460 +
80461 /*
80462 * Mark a position in code as unreachable. This can be used to
80463 * suppress control flow warnings after asm blocks that transfer
80464 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80465 index d5ad7b1..3b74638 100644
80466 --- a/include/linux/compiler.h
80467 +++ b/include/linux/compiler.h
80468 @@ -5,11 +5,14 @@
80469
80470 #ifdef __CHECKER__
80471 # define __user __attribute__((noderef, address_space(1)))
80472 +# define __force_user __force __user
80473 # define __kernel __attribute__((address_space(0)))
80474 +# define __force_kernel __force __kernel
80475 # define __safe __attribute__((safe))
80476 # define __force __attribute__((force))
80477 # define __nocast __attribute__((nocast))
80478 # define __iomem __attribute__((noderef, address_space(2)))
80479 +# define __force_iomem __force __iomem
80480 # define __must_hold(x) __attribute__((context(x,1,1)))
80481 # define __acquires(x) __attribute__((context(x,0,1)))
80482 # define __releases(x) __attribute__((context(x,1,0)))
80483 @@ -17,20 +20,37 @@
80484 # define __release(x) __context__(x,-1)
80485 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80486 # define __percpu __attribute__((noderef, address_space(3)))
80487 +# define __force_percpu __force __percpu
80488 #ifdef CONFIG_SPARSE_RCU_POINTER
80489 # define __rcu __attribute__((noderef, address_space(4)))
80490 +# define __force_rcu __force __rcu
80491 #else
80492 # define __rcu
80493 +# define __force_rcu
80494 #endif
80495 extern void __chk_user_ptr(const volatile void __user *);
80496 extern void __chk_io_ptr(const volatile void __iomem *);
80497 #else
80498 -# define __user
80499 -# define __kernel
80500 +# ifdef CHECKER_PLUGIN
80501 +//# define __user
80502 +//# define __force_user
80503 +//# define __kernel
80504 +//# define __force_kernel
80505 +# else
80506 +# ifdef STRUCTLEAK_PLUGIN
80507 +# define __user __attribute__((user))
80508 +# else
80509 +# define __user
80510 +# endif
80511 +# define __force_user
80512 +# define __kernel
80513 +# define __force_kernel
80514 +# endif
80515 # define __safe
80516 # define __force
80517 # define __nocast
80518 # define __iomem
80519 +# define __force_iomem
80520 # define __chk_user_ptr(x) (void)0
80521 # define __chk_io_ptr(x) (void)0
80522 # define __builtin_warning(x, y...) (1)
80523 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80524 # define __release(x) (void)0
80525 # define __cond_lock(x,c) (c)
80526 # define __percpu
80527 +# define __force_percpu
80528 # define __rcu
80529 +# define __force_rcu
80530 #endif
80531
80532 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80533 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80534 # define __attribute_const__ /* unimplemented */
80535 #endif
80536
80537 +#ifndef __randomize_layout
80538 +# define __randomize_layout
80539 +#endif
80540 +
80541 +#ifndef __no_randomize_layout
80542 +# define __no_randomize_layout
80543 +#endif
80544 +
80545 +#ifndef __no_const
80546 +# define __no_const
80547 +#endif
80548 +
80549 +#ifndef __do_const
80550 +# define __do_const
80551 +#endif
80552 +
80553 +#ifndef __size_overflow
80554 +# define __size_overflow(...)
80555 +#endif
80556 +
80557 +#ifndef __intentional_overflow
80558 +# define __intentional_overflow(...)
80559 +#endif
80560 +
80561 +#ifndef __latent_entropy
80562 +# define __latent_entropy
80563 +#endif
80564 +
80565 /*
80566 * Tell gcc if a function is cold. The compiler will assume any path
80567 * directly leading to the call is unlikely.
80568 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80569 #define __cold
80570 #endif
80571
80572 +#ifndef __alloc_size
80573 +#define __alloc_size(...)
80574 +#endif
80575 +
80576 +#ifndef __bos
80577 +#define __bos(ptr, arg)
80578 +#endif
80579 +
80580 +#ifndef __bos0
80581 +#define __bos0(ptr)
80582 +#endif
80583 +
80584 +#ifndef __bos1
80585 +#define __bos1(ptr)
80586 +#endif
80587 +
80588 /* Simple shorthand for a section definition */
80589 #ifndef __section
80590 # define __section(S) __attribute__ ((__section__(#S)))
80591 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80592 * use is to mediate communication between process-level code and irq/NMI
80593 * handlers, all running on the same CPU.
80594 */
80595 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80596 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80597 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80598
80599 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80600 #ifdef CONFIG_KPROBES
80601 diff --git a/include/linux/completion.h b/include/linux/completion.h
80602 index 5d5aaae..0ea9b84 100644
80603 --- a/include/linux/completion.h
80604 +++ b/include/linux/completion.h
80605 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80606
80607 extern void wait_for_completion(struct completion *);
80608 extern void wait_for_completion_io(struct completion *);
80609 -extern int wait_for_completion_interruptible(struct completion *x);
80610 -extern int wait_for_completion_killable(struct completion *x);
80611 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80612 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80613 extern unsigned long wait_for_completion_timeout(struct completion *x,
80614 - unsigned long timeout);
80615 + unsigned long timeout) __intentional_overflow(-1);
80616 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80617 - unsigned long timeout);
80618 + unsigned long timeout) __intentional_overflow(-1);
80619 extern long wait_for_completion_interruptible_timeout(
80620 - struct completion *x, unsigned long timeout);
80621 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80622 extern long wait_for_completion_killable_timeout(
80623 - struct completion *x, unsigned long timeout);
80624 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80625 extern bool try_wait_for_completion(struct completion *x);
80626 extern bool completion_done(struct completion *x);
80627
80628 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80629 index 34025df..d94bbbc 100644
80630 --- a/include/linux/configfs.h
80631 +++ b/include/linux/configfs.h
80632 @@ -125,7 +125,7 @@ struct configfs_attribute {
80633 const char *ca_name;
80634 struct module *ca_owner;
80635 umode_t ca_mode;
80636 -};
80637 +} __do_const;
80638
80639 /*
80640 * Users often need to create attribute structures for their configurable
80641 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80642 index 503b085b..1638c9e 100644
80643 --- a/include/linux/cpufreq.h
80644 +++ b/include/linux/cpufreq.h
80645 @@ -206,6 +206,7 @@ struct global_attr {
80646 ssize_t (*store)(struct kobject *a, struct attribute *b,
80647 const char *c, size_t count);
80648 };
80649 +typedef struct global_attr __no_const global_attr_no_const;
80650
80651 #define define_one_global_ro(_name) \
80652 static struct global_attr _name = \
80653 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80654 bool boost_supported;
80655 bool boost_enabled;
80656 int (*set_boost) (int state);
80657 -};
80658 +} __do_const;
80659
80660 /* flags */
80661 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80662 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80663 index 25e0df6..952dffd 100644
80664 --- a/include/linux/cpuidle.h
80665 +++ b/include/linux/cpuidle.h
80666 @@ -50,7 +50,8 @@ struct cpuidle_state {
80667 int index);
80668
80669 int (*enter_dead) (struct cpuidle_device *dev, int index);
80670 -};
80671 +} __do_const;
80672 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80673
80674 /* Idle State Flags */
80675 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80676 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80677 void (*reflect) (struct cpuidle_device *dev, int index);
80678
80679 struct module *owner;
80680 -};
80681 +} __do_const;
80682
80683 #ifdef CONFIG_CPU_IDLE
80684 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80685 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80686 index 0a9a6da..ea597ca 100644
80687 --- a/include/linux/cpumask.h
80688 +++ b/include/linux/cpumask.h
80689 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80690 }
80691
80692 /* Valid inputs for n are -1 and 0. */
80693 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80694 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80695 {
80696 return n+1;
80697 }
80698
80699 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80700 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80701 {
80702 return n+1;
80703 }
80704
80705 -static inline unsigned int cpumask_next_and(int n,
80706 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80707 const struct cpumask *srcp,
80708 const struct cpumask *andp)
80709 {
80710 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80711 *
80712 * Returns >= nr_cpu_ids if no further cpus set.
80713 */
80714 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80715 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80716 {
80717 /* -1 is a legal arg here. */
80718 if (n != -1)
80719 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80720 *
80721 * Returns >= nr_cpu_ids if no further cpus unset.
80722 */
80723 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80724 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80725 {
80726 /* -1 is a legal arg here. */
80727 if (n != -1)
80728 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80729 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80730 }
80731
80732 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80733 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80734 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80735 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80736
80737 diff --git a/include/linux/cred.h b/include/linux/cred.h
80738 index 2fb2ca2..d6a3340 100644
80739 --- a/include/linux/cred.h
80740 +++ b/include/linux/cred.h
80741 @@ -35,7 +35,7 @@ struct group_info {
80742 int nblocks;
80743 kgid_t small_block[NGROUPS_SMALL];
80744 kgid_t *blocks[0];
80745 -};
80746 +} __randomize_layout;
80747
80748 /**
80749 * get_group_info - Get a reference to a group info structure
80750 @@ -137,7 +137,7 @@ struct cred {
80751 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80752 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80753 struct rcu_head rcu; /* RCU deletion hook */
80754 -};
80755 +} __randomize_layout;
80756
80757 extern void __put_cred(struct cred *);
80758 extern void exit_creds(struct task_struct *);
80759 @@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80760 static inline void validate_process_creds(void)
80761 {
80762 }
80763 +static inline void validate_task_creds(struct task_struct *task)
80764 +{
80765 +}
80766 #endif
80767
80768 /**
80769 @@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
80770
80771 #define task_uid(task) (task_cred_xxx((task), uid))
80772 #define task_euid(task) (task_cred_xxx((task), euid))
80773 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80774
80775 #define current_cred_xxx(xxx) \
80776 ({ \
80777 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80778 index d45e949..51cf5ea 100644
80779 --- a/include/linux/crypto.h
80780 +++ b/include/linux/crypto.h
80781 @@ -373,7 +373,7 @@ struct cipher_tfm {
80782 const u8 *key, unsigned int keylen);
80783 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80784 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80785 -};
80786 +} __no_const;
80787
80788 struct hash_tfm {
80789 int (*init)(struct hash_desc *desc);
80790 @@ -394,13 +394,13 @@ struct compress_tfm {
80791 int (*cot_decompress)(struct crypto_tfm *tfm,
80792 const u8 *src, unsigned int slen,
80793 u8 *dst, unsigned int *dlen);
80794 -};
80795 +} __no_const;
80796
80797 struct rng_tfm {
80798 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80799 unsigned int dlen);
80800 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80801 -};
80802 +} __no_const;
80803
80804 #define crt_ablkcipher crt_u.ablkcipher
80805 #define crt_aead crt_u.aead
80806 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80807 index 653589e..4ef254a 100644
80808 --- a/include/linux/ctype.h
80809 +++ b/include/linux/ctype.h
80810 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80811 * Fast implementation of tolower() for internal usage. Do not use in your
80812 * code.
80813 */
80814 -static inline char _tolower(const char c)
80815 +static inline unsigned char _tolower(const unsigned char c)
80816 {
80817 return c | 0x20;
80818 }
80819 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80820 index 1c2f1b8..7b9f50c 100644
80821 --- a/include/linux/dcache.h
80822 +++ b/include/linux/dcache.h
80823 @@ -123,6 +123,9 @@ struct dentry {
80824 unsigned long d_time; /* used by d_revalidate */
80825 void *d_fsdata; /* fs-specific data */
80826
80827 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
80828 + atomic_t chroot_refcnt; /* tracks use of directory in chroot */
80829 +#endif
80830 struct list_head d_lru; /* LRU list */
80831 struct list_head d_child; /* child of parent list */
80832 struct list_head d_subdirs; /* our children */
80833 @@ -133,7 +136,7 @@ struct dentry {
80834 struct hlist_node d_alias; /* inode alias list */
80835 struct rcu_head d_rcu;
80836 } d_u;
80837 -};
80838 +} __randomize_layout;
80839
80840 /*
80841 * dentry->d_lock spinlock nesting subclasses:
80842 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80843 index 7925bf0..d5143d2 100644
80844 --- a/include/linux/decompress/mm.h
80845 +++ b/include/linux/decompress/mm.h
80846 @@ -77,7 +77,7 @@ static void free(void *where)
80847 * warnings when not needed (indeed large_malloc / large_free are not
80848 * needed by inflate */
80849
80850 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80851 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80852 #define free(a) kfree(a)
80853
80854 #define large_malloc(a) vmalloc(a)
80855 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80856 index f1863dc..5c26074 100644
80857 --- a/include/linux/devfreq.h
80858 +++ b/include/linux/devfreq.h
80859 @@ -114,7 +114,7 @@ struct devfreq_governor {
80860 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80861 int (*event_handler)(struct devfreq *devfreq,
80862 unsigned int event, void *data);
80863 -};
80864 +} __do_const;
80865
80866 /**
80867 * struct devfreq - Device devfreq structure
80868 diff --git a/include/linux/device.h b/include/linux/device.h
80869 index ce1f2160..189bc33 100644
80870 --- a/include/linux/device.h
80871 +++ b/include/linux/device.h
80872 @@ -311,7 +311,7 @@ struct subsys_interface {
80873 struct list_head node;
80874 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80875 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80876 -};
80877 +} __do_const;
80878
80879 int subsys_interface_register(struct subsys_interface *sif);
80880 void subsys_interface_unregister(struct subsys_interface *sif);
80881 @@ -507,7 +507,7 @@ struct device_type {
80882 void (*release)(struct device *dev);
80883
80884 const struct dev_pm_ops *pm;
80885 -};
80886 +} __do_const;
80887
80888 /* interface for exporting device attributes */
80889 struct device_attribute {
80890 @@ -517,11 +517,12 @@ struct device_attribute {
80891 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80892 const char *buf, size_t count);
80893 };
80894 +typedef struct device_attribute __no_const device_attribute_no_const;
80895
80896 struct dev_ext_attribute {
80897 struct device_attribute attr;
80898 void *var;
80899 -};
80900 +} __do_const;
80901
80902 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80903 char *buf);
80904 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80905 index d5d3881..7ed54af 100644
80906 --- a/include/linux/dma-mapping.h
80907 +++ b/include/linux/dma-mapping.h
80908 @@ -60,7 +60,7 @@ struct dma_map_ops {
80909 u64 (*get_required_mask)(struct device *dev);
80910 #endif
80911 int is_phys;
80912 -};
80913 +} __do_const;
80914
80915 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80916
80917 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80918 index 653a1fd..9133cd1 100644
80919 --- a/include/linux/dmaengine.h
80920 +++ b/include/linux/dmaengine.h
80921 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
80922 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80923 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80924
80925 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80926 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80927 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80928 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80929 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80930 struct dma_pinned_list *pinned_list, struct page *page,
80931 unsigned int offset, size_t len);
80932
80933 diff --git a/include/linux/efi.h b/include/linux/efi.h
80934 index 0949f9c..04cb9a5 100644
80935 --- a/include/linux/efi.h
80936 +++ b/include/linux/efi.h
80937 @@ -1050,6 +1050,7 @@ struct efivar_operations {
80938 efi_set_variable_nonblocking_t *set_variable_nonblocking;
80939 efi_query_variable_store_t *query_variable_store;
80940 };
80941 +typedef struct efivar_operations __no_const efivar_operations_no_const;
80942
80943 struct efivars {
80944 /*
80945 diff --git a/include/linux/elf.h b/include/linux/elf.h
80946 index 67a5fa7..b817372 100644
80947 --- a/include/linux/elf.h
80948 +++ b/include/linux/elf.h
80949 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80950 #define elf_note elf32_note
80951 #define elf_addr_t Elf32_Off
80952 #define Elf_Half Elf32_Half
80953 +#define elf_dyn Elf32_Dyn
80954
80955 #else
80956
80957 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80958 #define elf_note elf64_note
80959 #define elf_addr_t Elf64_Off
80960 #define Elf_Half Elf64_Half
80961 +#define elf_dyn Elf64_Dyn
80962
80963 #endif
80964
80965 diff --git a/include/linux/err.h b/include/linux/err.h
80966 index a729120..6ede2c9 100644
80967 --- a/include/linux/err.h
80968 +++ b/include/linux/err.h
80969 @@ -20,12 +20,12 @@
80970
80971 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80972
80973 -static inline void * __must_check ERR_PTR(long error)
80974 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80975 {
80976 return (void *) error;
80977 }
80978
80979 -static inline long __must_check PTR_ERR(__force const void *ptr)
80980 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80981 {
80982 return (long) ptr;
80983 }
80984 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80985 index 36f49c4..a2a1f4c 100644
80986 --- a/include/linux/extcon.h
80987 +++ b/include/linux/extcon.h
80988 @@ -135,7 +135,7 @@ struct extcon_dev {
80989 /* /sys/class/extcon/.../mutually_exclusive/... */
80990 struct attribute_group attr_g_muex;
80991 struct attribute **attrs_muex;
80992 - struct device_attribute *d_attrs_muex;
80993 + device_attribute_no_const *d_attrs_muex;
80994 };
80995
80996 /**
80997 diff --git a/include/linux/fb.h b/include/linux/fb.h
80998 index 09bb7a1..d98870a 100644
80999 --- a/include/linux/fb.h
81000 +++ b/include/linux/fb.h
81001 @@ -305,7 +305,7 @@ struct fb_ops {
81002 /* called at KDB enter and leave time to prepare the console */
81003 int (*fb_debug_enter)(struct fb_info *info);
81004 int (*fb_debug_leave)(struct fb_info *info);
81005 -};
81006 +} __do_const;
81007
81008 #ifdef CONFIG_FB_TILEBLITTING
81009 #define FB_TILE_CURSOR_NONE 0
81010 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81011 index 230f87b..1fd0485 100644
81012 --- a/include/linux/fdtable.h
81013 +++ b/include/linux/fdtable.h
81014 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81015 void put_files_struct(struct files_struct *fs);
81016 void reset_files_struct(struct files_struct *);
81017 int unshare_files(struct files_struct **);
81018 -struct files_struct *dup_fd(struct files_struct *, int *);
81019 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81020 void do_close_on_exec(struct files_struct *);
81021 int iterate_fd(struct files_struct *, unsigned,
81022 int (*)(const void *, struct file *, unsigned),
81023 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81024 index 8293262..2b3b8bd 100644
81025 --- a/include/linux/frontswap.h
81026 +++ b/include/linux/frontswap.h
81027 @@ -11,7 +11,7 @@ struct frontswap_ops {
81028 int (*load)(unsigned, pgoff_t, struct page *);
81029 void (*invalidate_page)(unsigned, pgoff_t);
81030 void (*invalidate_area)(unsigned);
81031 -};
81032 +} __no_const;
81033
81034 extern bool frontswap_enabled;
81035 extern struct frontswap_ops *
81036 diff --git a/include/linux/fs.h b/include/linux/fs.h
81037 index 9ab779e..0c636f2 100644
81038 --- a/include/linux/fs.h
81039 +++ b/include/linux/fs.h
81040 @@ -412,7 +412,7 @@ struct address_space {
81041 spinlock_t private_lock; /* for use by the address_space */
81042 struct list_head private_list; /* ditto */
81043 void *private_data; /* ditto */
81044 -} __attribute__((aligned(sizeof(long))));
81045 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81046 /*
81047 * On most architectures that alignment is already the case; but
81048 * must be enforced here for CRIS, to let the least significant bit
81049 @@ -455,7 +455,7 @@ struct block_device {
81050 int bd_fsfreeze_count;
81051 /* Mutex for freeze */
81052 struct mutex bd_fsfreeze_mutex;
81053 -};
81054 +} __randomize_layout;
81055
81056 /*
81057 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81058 @@ -624,7 +624,7 @@ struct inode {
81059 #endif
81060
81061 void *i_private; /* fs or device private pointer */
81062 -};
81063 +} __randomize_layout;
81064
81065 static inline int inode_unhashed(struct inode *inode)
81066 {
81067 @@ -820,7 +820,7 @@ struct file {
81068 struct list_head f_tfile_llink;
81069 #endif /* #ifdef CONFIG_EPOLL */
81070 struct address_space *f_mapping;
81071 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81072 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81073
81074 struct file_handle {
81075 __u32 handle_bytes;
81076 @@ -945,7 +945,7 @@ struct file_lock {
81077 int state; /* state of grant or error if -ve */
81078 } afs;
81079 } fl_u;
81080 -};
81081 +} __randomize_layout;
81082
81083 /* The following constant reflects the upper bound of the file/locking space */
81084 #ifndef OFFSET_MAX
81085 @@ -1287,7 +1287,7 @@ struct super_block {
81086 * Indicates how deep in a filesystem stack this SB is
81087 */
81088 int s_stack_depth;
81089 -};
81090 +} __randomize_layout;
81091
81092 extern struct timespec current_fs_time(struct super_block *sb);
81093
81094 @@ -1514,7 +1514,8 @@ struct file_operations {
81095 long (*fallocate)(struct file *file, int mode, loff_t offset,
81096 loff_t len);
81097 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81098 -};
81099 +} __do_const __randomize_layout;
81100 +typedef struct file_operations __no_const file_operations_no_const;
81101
81102 struct inode_operations {
81103 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81104 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81105 return !IS_DEADDIR(inode);
81106 }
81107
81108 +static inline bool is_sidechannel_device(const struct inode *inode)
81109 +{
81110 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81111 + umode_t mode = inode->i_mode;
81112 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81113 +#else
81114 + return false;
81115 +#endif
81116 +}
81117 +
81118 #endif /* _LINUX_FS_H */
81119 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81120 index 0efc3e6..fd23610 100644
81121 --- a/include/linux/fs_struct.h
81122 +++ b/include/linux/fs_struct.h
81123 @@ -6,13 +6,13 @@
81124 #include <linux/seqlock.h>
81125
81126 struct fs_struct {
81127 - int users;
81128 + atomic_t users;
81129 spinlock_t lock;
81130 seqcount_t seq;
81131 int umask;
81132 int in_exec;
81133 struct path root, pwd;
81134 -};
81135 +} __randomize_layout;
81136
81137 extern struct kmem_cache *fs_cachep;
81138
81139 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81140 index 7714849..a4a5c7a 100644
81141 --- a/include/linux/fscache-cache.h
81142 +++ b/include/linux/fscache-cache.h
81143 @@ -113,7 +113,7 @@ struct fscache_operation {
81144 fscache_operation_release_t release;
81145 };
81146
81147 -extern atomic_t fscache_op_debug_id;
81148 +extern atomic_unchecked_t fscache_op_debug_id;
81149 extern void fscache_op_work_func(struct work_struct *work);
81150
81151 extern void fscache_enqueue_operation(struct fscache_operation *);
81152 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81153 INIT_WORK(&op->work, fscache_op_work_func);
81154 atomic_set(&op->usage, 1);
81155 op->state = FSCACHE_OP_ST_INITIALISED;
81156 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81157 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81158 op->processor = processor;
81159 op->release = release;
81160 INIT_LIST_HEAD(&op->pend_link);
81161 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81162 index 115bb81..e7b812b 100644
81163 --- a/include/linux/fscache.h
81164 +++ b/include/linux/fscache.h
81165 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81166 * - this is mandatory for any object that may have data
81167 */
81168 void (*now_uncached)(void *cookie_netfs_data);
81169 -};
81170 +} __do_const;
81171
81172 /*
81173 * fscache cached network filesystem type
81174 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81175 index 1c804b0..1432c2b 100644
81176 --- a/include/linux/fsnotify.h
81177 +++ b/include/linux/fsnotify.h
81178 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81179 struct inode *inode = file_inode(file);
81180 __u32 mask = FS_ACCESS;
81181
81182 + if (is_sidechannel_device(inode))
81183 + return;
81184 +
81185 if (S_ISDIR(inode->i_mode))
81186 mask |= FS_ISDIR;
81187
81188 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81189 struct inode *inode = file_inode(file);
81190 __u32 mask = FS_MODIFY;
81191
81192 + if (is_sidechannel_device(inode))
81193 + return;
81194 +
81195 if (S_ISDIR(inode->i_mode))
81196 mask |= FS_ISDIR;
81197
81198 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81199 */
81200 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81201 {
81202 - return kstrdup(name, GFP_KERNEL);
81203 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81204 }
81205
81206 /*
81207 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81208 index ec274e0..e678159 100644
81209 --- a/include/linux/genhd.h
81210 +++ b/include/linux/genhd.h
81211 @@ -194,7 +194,7 @@ struct gendisk {
81212 struct kobject *slave_dir;
81213
81214 struct timer_rand_state *random;
81215 - atomic_t sync_io; /* RAID */
81216 + atomic_unchecked_t sync_io; /* RAID */
81217 struct disk_events *ev;
81218 #ifdef CONFIG_BLK_DEV_INTEGRITY
81219 struct blk_integrity *integrity;
81220 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81221 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81222
81223 /* drivers/char/random.c */
81224 -extern void add_disk_randomness(struct gendisk *disk);
81225 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81226 extern void rand_initialize_disk(struct gendisk *disk);
81227
81228 static inline sector_t get_start_sect(struct block_device *bdev)
81229 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81230 index 667c311..abac2a7 100644
81231 --- a/include/linux/genl_magic_func.h
81232 +++ b/include/linux/genl_magic_func.h
81233 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81234 },
81235
81236 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81237 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81238 +static struct genl_ops ZZZ_genl_ops[] = {
81239 #include GENL_MAGIC_INCLUDE_FILE
81240 };
81241
81242 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81243 index 41b30fd..a3718cf 100644
81244 --- a/include/linux/gfp.h
81245 +++ b/include/linux/gfp.h
81246 @@ -34,6 +34,13 @@ struct vm_area_struct;
81247 #define ___GFP_NO_KSWAPD 0x400000u
81248 #define ___GFP_OTHER_NODE 0x800000u
81249 #define ___GFP_WRITE 0x1000000u
81250 +
81251 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81252 +#define ___GFP_USERCOPY 0x2000000u
81253 +#else
81254 +#define ___GFP_USERCOPY 0
81255 +#endif
81256 +
81257 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81258
81259 /*
81260 @@ -90,6 +97,7 @@ struct vm_area_struct;
81261 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81262 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81263 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81264 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81265
81266 /*
81267 * This may seem redundant, but it's a way of annotating false positives vs.
81268 @@ -97,7 +105,7 @@ struct vm_area_struct;
81269 */
81270 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81271
81272 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81273 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81274 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81275
81276 /* This equals 0, but use constants in case they ever change */
81277 @@ -155,6 +163,8 @@ struct vm_area_struct;
81278 /* 4GB DMA on some platforms */
81279 #define GFP_DMA32 __GFP_DMA32
81280
81281 +#define GFP_USERCOPY __GFP_USERCOPY
81282 +
81283 /* Convert GFP flags to their corresponding migrate type */
81284 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81285 {
81286 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81287 new file mode 100644
81288 index 0000000..edb2cb6
81289 --- /dev/null
81290 +++ b/include/linux/gracl.h
81291 @@ -0,0 +1,340 @@
81292 +#ifndef GR_ACL_H
81293 +#define GR_ACL_H
81294 +
81295 +#include <linux/grdefs.h>
81296 +#include <linux/resource.h>
81297 +#include <linux/capability.h>
81298 +#include <linux/dcache.h>
81299 +#include <asm/resource.h>
81300 +
81301 +/* Major status information */
81302 +
81303 +#define GR_VERSION "grsecurity 3.0"
81304 +#define GRSECURITY_VERSION 0x3000
81305 +
81306 +enum {
81307 + GR_SHUTDOWN = 0,
81308 + GR_ENABLE = 1,
81309 + GR_SPROLE = 2,
81310 + GR_OLDRELOAD = 3,
81311 + GR_SEGVMOD = 4,
81312 + GR_STATUS = 5,
81313 + GR_UNSPROLE = 6,
81314 + GR_PASSSET = 7,
81315 + GR_SPROLEPAM = 8,
81316 + GR_RELOAD = 9,
81317 +};
81318 +
81319 +/* Password setup definitions
81320 + * kernel/grhash.c */
81321 +enum {
81322 + GR_PW_LEN = 128,
81323 + GR_SALT_LEN = 16,
81324 + GR_SHA_LEN = 32,
81325 +};
81326 +
81327 +enum {
81328 + GR_SPROLE_LEN = 64,
81329 +};
81330 +
81331 +enum {
81332 + GR_NO_GLOB = 0,
81333 + GR_REG_GLOB,
81334 + GR_CREATE_GLOB
81335 +};
81336 +
81337 +#define GR_NLIMITS 32
81338 +
81339 +/* Begin Data Structures */
81340 +
81341 +struct sprole_pw {
81342 + unsigned char *rolename;
81343 + unsigned char salt[GR_SALT_LEN];
81344 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81345 +};
81346 +
81347 +struct name_entry {
81348 + __u32 key;
81349 + ino_t inode;
81350 + dev_t device;
81351 + char *name;
81352 + __u16 len;
81353 + __u8 deleted;
81354 + struct name_entry *prev;
81355 + struct name_entry *next;
81356 +};
81357 +
81358 +struct inodev_entry {
81359 + struct name_entry *nentry;
81360 + struct inodev_entry *prev;
81361 + struct inodev_entry *next;
81362 +};
81363 +
81364 +struct acl_role_db {
81365 + struct acl_role_label **r_hash;
81366 + __u32 r_size;
81367 +};
81368 +
81369 +struct inodev_db {
81370 + struct inodev_entry **i_hash;
81371 + __u32 i_size;
81372 +};
81373 +
81374 +struct name_db {
81375 + struct name_entry **n_hash;
81376 + __u32 n_size;
81377 +};
81378 +
81379 +struct crash_uid {
81380 + uid_t uid;
81381 + unsigned long expires;
81382 +};
81383 +
81384 +struct gr_hash_struct {
81385 + void **table;
81386 + void **nametable;
81387 + void *first;
81388 + __u32 table_size;
81389 + __u32 used_size;
81390 + int type;
81391 +};
81392 +
81393 +/* Userspace Grsecurity ACL data structures */
81394 +
81395 +struct acl_subject_label {
81396 + char *filename;
81397 + ino_t inode;
81398 + dev_t device;
81399 + __u32 mode;
81400 + kernel_cap_t cap_mask;
81401 + kernel_cap_t cap_lower;
81402 + kernel_cap_t cap_invert_audit;
81403 +
81404 + struct rlimit res[GR_NLIMITS];
81405 + __u32 resmask;
81406 +
81407 + __u8 user_trans_type;
81408 + __u8 group_trans_type;
81409 + uid_t *user_transitions;
81410 + gid_t *group_transitions;
81411 + __u16 user_trans_num;
81412 + __u16 group_trans_num;
81413 +
81414 + __u32 sock_families[2];
81415 + __u32 ip_proto[8];
81416 + __u32 ip_type;
81417 + struct acl_ip_label **ips;
81418 + __u32 ip_num;
81419 + __u32 inaddr_any_override;
81420 +
81421 + __u32 crashes;
81422 + unsigned long expires;
81423 +
81424 + struct acl_subject_label *parent_subject;
81425 + struct gr_hash_struct *hash;
81426 + struct acl_subject_label *prev;
81427 + struct acl_subject_label *next;
81428 +
81429 + struct acl_object_label **obj_hash;
81430 + __u32 obj_hash_size;
81431 + __u16 pax_flags;
81432 +};
81433 +
81434 +struct role_allowed_ip {
81435 + __u32 addr;
81436 + __u32 netmask;
81437 +
81438 + struct role_allowed_ip *prev;
81439 + struct role_allowed_ip *next;
81440 +};
81441 +
81442 +struct role_transition {
81443 + char *rolename;
81444 +
81445 + struct role_transition *prev;
81446 + struct role_transition *next;
81447 +};
81448 +
81449 +struct acl_role_label {
81450 + char *rolename;
81451 + uid_t uidgid;
81452 + __u16 roletype;
81453 +
81454 + __u16 auth_attempts;
81455 + unsigned long expires;
81456 +
81457 + struct acl_subject_label *root_label;
81458 + struct gr_hash_struct *hash;
81459 +
81460 + struct acl_role_label *prev;
81461 + struct acl_role_label *next;
81462 +
81463 + struct role_transition *transitions;
81464 + struct role_allowed_ip *allowed_ips;
81465 + uid_t *domain_children;
81466 + __u16 domain_child_num;
81467 +
81468 + umode_t umask;
81469 +
81470 + struct acl_subject_label **subj_hash;
81471 + __u32 subj_hash_size;
81472 +};
81473 +
81474 +struct user_acl_role_db {
81475 + struct acl_role_label **r_table;
81476 + __u32 num_pointers; /* Number of allocations to track */
81477 + __u32 num_roles; /* Number of roles */
81478 + __u32 num_domain_children; /* Number of domain children */
81479 + __u32 num_subjects; /* Number of subjects */
81480 + __u32 num_objects; /* Number of objects */
81481 +};
81482 +
81483 +struct acl_object_label {
81484 + char *filename;
81485 + ino_t inode;
81486 + dev_t device;
81487 + __u32 mode;
81488 +
81489 + struct acl_subject_label *nested;
81490 + struct acl_object_label *globbed;
81491 +
81492 + /* next two structures not used */
81493 +
81494 + struct acl_object_label *prev;
81495 + struct acl_object_label *next;
81496 +};
81497 +
81498 +struct acl_ip_label {
81499 + char *iface;
81500 + __u32 addr;
81501 + __u32 netmask;
81502 + __u16 low, high;
81503 + __u8 mode;
81504 + __u32 type;
81505 + __u32 proto[8];
81506 +
81507 + /* next two structures not used */
81508 +
81509 + struct acl_ip_label *prev;
81510 + struct acl_ip_label *next;
81511 +};
81512 +
81513 +struct gr_arg {
81514 + struct user_acl_role_db role_db;
81515 + unsigned char pw[GR_PW_LEN];
81516 + unsigned char salt[GR_SALT_LEN];
81517 + unsigned char sum[GR_SHA_LEN];
81518 + unsigned char sp_role[GR_SPROLE_LEN];
81519 + struct sprole_pw *sprole_pws;
81520 + dev_t segv_device;
81521 + ino_t segv_inode;
81522 + uid_t segv_uid;
81523 + __u16 num_sprole_pws;
81524 + __u16 mode;
81525 +};
81526 +
81527 +struct gr_arg_wrapper {
81528 + struct gr_arg *arg;
81529 + __u32 version;
81530 + __u32 size;
81531 +};
81532 +
81533 +struct subject_map {
81534 + struct acl_subject_label *user;
81535 + struct acl_subject_label *kernel;
81536 + struct subject_map *prev;
81537 + struct subject_map *next;
81538 +};
81539 +
81540 +struct acl_subj_map_db {
81541 + struct subject_map **s_hash;
81542 + __u32 s_size;
81543 +};
81544 +
81545 +struct gr_policy_state {
81546 + struct sprole_pw **acl_special_roles;
81547 + __u16 num_sprole_pws;
81548 + struct acl_role_label *kernel_role;
81549 + struct acl_role_label *role_list;
81550 + struct acl_role_label *default_role;
81551 + struct acl_role_db acl_role_set;
81552 + struct acl_subj_map_db subj_map_set;
81553 + struct name_db name_set;
81554 + struct inodev_db inodev_set;
81555 +};
81556 +
81557 +struct gr_alloc_state {
81558 + unsigned long alloc_stack_next;
81559 + unsigned long alloc_stack_size;
81560 + void **alloc_stack;
81561 +};
81562 +
81563 +struct gr_reload_state {
81564 + struct gr_policy_state oldpolicy;
81565 + struct gr_alloc_state oldalloc;
81566 + struct gr_policy_state newpolicy;
81567 + struct gr_alloc_state newalloc;
81568 + struct gr_policy_state *oldpolicy_ptr;
81569 + struct gr_alloc_state *oldalloc_ptr;
81570 + unsigned char oldmode;
81571 +};
81572 +
81573 +/* End Data Structures Section */
81574 +
81575 +/* Hash functions generated by empirical testing by Brad Spengler
81576 + Makes good use of the low bits of the inode. Generally 0-1 times
81577 + in loop for successful match. 0-3 for unsuccessful match.
81578 + Shift/add algorithm with modulus of table size and an XOR*/
81579 +
81580 +static __inline__ unsigned int
81581 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81582 +{
81583 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81584 +}
81585 +
81586 + static __inline__ unsigned int
81587 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81588 +{
81589 + return ((const unsigned long)userp % sz);
81590 +}
81591 +
81592 +static __inline__ unsigned int
81593 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81594 +{
81595 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81596 +}
81597 +
81598 +static __inline__ unsigned int
81599 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81600 +{
81601 + return full_name_hash((const unsigned char *)name, len) % sz;
81602 +}
81603 +
81604 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81605 + subj = NULL; \
81606 + iter = 0; \
81607 + while (iter < role->subj_hash_size) { \
81608 + if (subj == NULL) \
81609 + subj = role->subj_hash[iter]; \
81610 + if (subj == NULL) { \
81611 + iter++; \
81612 + continue; \
81613 + }
81614 +
81615 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81616 + subj = subj->next; \
81617 + if (subj == NULL) \
81618 + iter++; \
81619 + }
81620 +
81621 +
81622 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81623 + subj = role->hash->first; \
81624 + while (subj != NULL) {
81625 +
81626 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81627 + subj = subj->next; \
81628 + }
81629 +
81630 +#endif
81631 +
81632 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81633 new file mode 100644
81634 index 0000000..33ebd1f
81635 --- /dev/null
81636 +++ b/include/linux/gracl_compat.h
81637 @@ -0,0 +1,156 @@
81638 +#ifndef GR_ACL_COMPAT_H
81639 +#define GR_ACL_COMPAT_H
81640 +
81641 +#include <linux/resource.h>
81642 +#include <asm/resource.h>
81643 +
81644 +struct sprole_pw_compat {
81645 + compat_uptr_t rolename;
81646 + unsigned char salt[GR_SALT_LEN];
81647 + unsigned char sum[GR_SHA_LEN];
81648 +};
81649 +
81650 +struct gr_hash_struct_compat {
81651 + compat_uptr_t table;
81652 + compat_uptr_t nametable;
81653 + compat_uptr_t first;
81654 + __u32 table_size;
81655 + __u32 used_size;
81656 + int type;
81657 +};
81658 +
81659 +struct acl_subject_label_compat {
81660 + compat_uptr_t filename;
81661 + compat_ino_t inode;
81662 + __u32 device;
81663 + __u32 mode;
81664 + kernel_cap_t cap_mask;
81665 + kernel_cap_t cap_lower;
81666 + kernel_cap_t cap_invert_audit;
81667 +
81668 + struct compat_rlimit res[GR_NLIMITS];
81669 + __u32 resmask;
81670 +
81671 + __u8 user_trans_type;
81672 + __u8 group_trans_type;
81673 + compat_uptr_t user_transitions;
81674 + compat_uptr_t group_transitions;
81675 + __u16 user_trans_num;
81676 + __u16 group_trans_num;
81677 +
81678 + __u32 sock_families[2];
81679 + __u32 ip_proto[8];
81680 + __u32 ip_type;
81681 + compat_uptr_t ips;
81682 + __u32 ip_num;
81683 + __u32 inaddr_any_override;
81684 +
81685 + __u32 crashes;
81686 + compat_ulong_t expires;
81687 +
81688 + compat_uptr_t parent_subject;
81689 + compat_uptr_t hash;
81690 + compat_uptr_t prev;
81691 + compat_uptr_t next;
81692 +
81693 + compat_uptr_t obj_hash;
81694 + __u32 obj_hash_size;
81695 + __u16 pax_flags;
81696 +};
81697 +
81698 +struct role_allowed_ip_compat {
81699 + __u32 addr;
81700 + __u32 netmask;
81701 +
81702 + compat_uptr_t prev;
81703 + compat_uptr_t next;
81704 +};
81705 +
81706 +struct role_transition_compat {
81707 + compat_uptr_t rolename;
81708 +
81709 + compat_uptr_t prev;
81710 + compat_uptr_t next;
81711 +};
81712 +
81713 +struct acl_role_label_compat {
81714 + compat_uptr_t rolename;
81715 + uid_t uidgid;
81716 + __u16 roletype;
81717 +
81718 + __u16 auth_attempts;
81719 + compat_ulong_t expires;
81720 +
81721 + compat_uptr_t root_label;
81722 + compat_uptr_t hash;
81723 +
81724 + compat_uptr_t prev;
81725 + compat_uptr_t next;
81726 +
81727 + compat_uptr_t transitions;
81728 + compat_uptr_t allowed_ips;
81729 + compat_uptr_t domain_children;
81730 + __u16 domain_child_num;
81731 +
81732 + umode_t umask;
81733 +
81734 + compat_uptr_t subj_hash;
81735 + __u32 subj_hash_size;
81736 +};
81737 +
81738 +struct user_acl_role_db_compat {
81739 + compat_uptr_t r_table;
81740 + __u32 num_pointers;
81741 + __u32 num_roles;
81742 + __u32 num_domain_children;
81743 + __u32 num_subjects;
81744 + __u32 num_objects;
81745 +};
81746 +
81747 +struct acl_object_label_compat {
81748 + compat_uptr_t filename;
81749 + compat_ino_t inode;
81750 + __u32 device;
81751 + __u32 mode;
81752 +
81753 + compat_uptr_t nested;
81754 + compat_uptr_t globbed;
81755 +
81756 + compat_uptr_t prev;
81757 + compat_uptr_t next;
81758 +};
81759 +
81760 +struct acl_ip_label_compat {
81761 + compat_uptr_t iface;
81762 + __u32 addr;
81763 + __u32 netmask;
81764 + __u16 low, high;
81765 + __u8 mode;
81766 + __u32 type;
81767 + __u32 proto[8];
81768 +
81769 + compat_uptr_t prev;
81770 + compat_uptr_t next;
81771 +};
81772 +
81773 +struct gr_arg_compat {
81774 + struct user_acl_role_db_compat role_db;
81775 + unsigned char pw[GR_PW_LEN];
81776 + unsigned char salt[GR_SALT_LEN];
81777 + unsigned char sum[GR_SHA_LEN];
81778 + unsigned char sp_role[GR_SPROLE_LEN];
81779 + compat_uptr_t sprole_pws;
81780 + __u32 segv_device;
81781 + compat_ino_t segv_inode;
81782 + uid_t segv_uid;
81783 + __u16 num_sprole_pws;
81784 + __u16 mode;
81785 +};
81786 +
81787 +struct gr_arg_wrapper_compat {
81788 + compat_uptr_t arg;
81789 + __u32 version;
81790 + __u32 size;
81791 +};
81792 +
81793 +#endif
81794 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81795 new file mode 100644
81796 index 0000000..323ecf2
81797 --- /dev/null
81798 +++ b/include/linux/gralloc.h
81799 @@ -0,0 +1,9 @@
81800 +#ifndef __GRALLOC_H
81801 +#define __GRALLOC_H
81802 +
81803 +void acl_free_all(void);
81804 +int acl_alloc_stack_init(unsigned long size);
81805 +void *acl_alloc(unsigned long len);
81806 +void *acl_alloc_num(unsigned long num, unsigned long len);
81807 +
81808 +#endif
81809 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81810 new file mode 100644
81811 index 0000000..be66033
81812 --- /dev/null
81813 +++ b/include/linux/grdefs.h
81814 @@ -0,0 +1,140 @@
81815 +#ifndef GRDEFS_H
81816 +#define GRDEFS_H
81817 +
81818 +/* Begin grsecurity status declarations */
81819 +
81820 +enum {
81821 + GR_READY = 0x01,
81822 + GR_STATUS_INIT = 0x00 // disabled state
81823 +};
81824 +
81825 +/* Begin ACL declarations */
81826 +
81827 +/* Role flags */
81828 +
81829 +enum {
81830 + GR_ROLE_USER = 0x0001,
81831 + GR_ROLE_GROUP = 0x0002,
81832 + GR_ROLE_DEFAULT = 0x0004,
81833 + GR_ROLE_SPECIAL = 0x0008,
81834 + GR_ROLE_AUTH = 0x0010,
81835 + GR_ROLE_NOPW = 0x0020,
81836 + GR_ROLE_GOD = 0x0040,
81837 + GR_ROLE_LEARN = 0x0080,
81838 + GR_ROLE_TPE = 0x0100,
81839 + GR_ROLE_DOMAIN = 0x0200,
81840 + GR_ROLE_PAM = 0x0400,
81841 + GR_ROLE_PERSIST = 0x0800
81842 +};
81843 +
81844 +/* ACL Subject and Object mode flags */
81845 +enum {
81846 + GR_DELETED = 0x80000000
81847 +};
81848 +
81849 +/* ACL Object-only mode flags */
81850 +enum {
81851 + GR_READ = 0x00000001,
81852 + GR_APPEND = 0x00000002,
81853 + GR_WRITE = 0x00000004,
81854 + GR_EXEC = 0x00000008,
81855 + GR_FIND = 0x00000010,
81856 + GR_INHERIT = 0x00000020,
81857 + GR_SETID = 0x00000040,
81858 + GR_CREATE = 0x00000080,
81859 + GR_DELETE = 0x00000100,
81860 + GR_LINK = 0x00000200,
81861 + GR_AUDIT_READ = 0x00000400,
81862 + GR_AUDIT_APPEND = 0x00000800,
81863 + GR_AUDIT_WRITE = 0x00001000,
81864 + GR_AUDIT_EXEC = 0x00002000,
81865 + GR_AUDIT_FIND = 0x00004000,
81866 + GR_AUDIT_INHERIT= 0x00008000,
81867 + GR_AUDIT_SETID = 0x00010000,
81868 + GR_AUDIT_CREATE = 0x00020000,
81869 + GR_AUDIT_DELETE = 0x00040000,
81870 + GR_AUDIT_LINK = 0x00080000,
81871 + GR_PTRACERD = 0x00100000,
81872 + GR_NOPTRACE = 0x00200000,
81873 + GR_SUPPRESS = 0x00400000,
81874 + GR_NOLEARN = 0x00800000,
81875 + GR_INIT_TRANSFER= 0x01000000
81876 +};
81877 +
81878 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81879 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81880 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81881 +
81882 +/* ACL subject-only mode flags */
81883 +enum {
81884 + GR_KILL = 0x00000001,
81885 + GR_VIEW = 0x00000002,
81886 + GR_PROTECTED = 0x00000004,
81887 + GR_LEARN = 0x00000008,
81888 + GR_OVERRIDE = 0x00000010,
81889 + /* just a placeholder, this mode is only used in userspace */
81890 + GR_DUMMY = 0x00000020,
81891 + GR_PROTSHM = 0x00000040,
81892 + GR_KILLPROC = 0x00000080,
81893 + GR_KILLIPPROC = 0x00000100,
81894 + /* just a placeholder, this mode is only used in userspace */
81895 + GR_NOTROJAN = 0x00000200,
81896 + GR_PROTPROCFD = 0x00000400,
81897 + GR_PROCACCT = 0x00000800,
81898 + GR_RELAXPTRACE = 0x00001000,
81899 + //GR_NESTED = 0x00002000,
81900 + GR_INHERITLEARN = 0x00004000,
81901 + GR_PROCFIND = 0x00008000,
81902 + GR_POVERRIDE = 0x00010000,
81903 + GR_KERNELAUTH = 0x00020000,
81904 + GR_ATSECURE = 0x00040000,
81905 + GR_SHMEXEC = 0x00080000
81906 +};
81907 +
81908 +enum {
81909 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81910 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81911 + GR_PAX_ENABLE_MPROTECT = 0x0004,
81912 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
81913 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81914 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81915 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81916 + GR_PAX_DISABLE_MPROTECT = 0x0400,
81917 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
81918 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81919 +};
81920 +
81921 +enum {
81922 + GR_ID_USER = 0x01,
81923 + GR_ID_GROUP = 0x02,
81924 +};
81925 +
81926 +enum {
81927 + GR_ID_ALLOW = 0x01,
81928 + GR_ID_DENY = 0x02,
81929 +};
81930 +
81931 +#define GR_CRASH_RES 31
81932 +#define GR_UIDTABLE_MAX 500
81933 +
81934 +/* begin resource learning section */
81935 +enum {
81936 + GR_RLIM_CPU_BUMP = 60,
81937 + GR_RLIM_FSIZE_BUMP = 50000,
81938 + GR_RLIM_DATA_BUMP = 10000,
81939 + GR_RLIM_STACK_BUMP = 1000,
81940 + GR_RLIM_CORE_BUMP = 10000,
81941 + GR_RLIM_RSS_BUMP = 500000,
81942 + GR_RLIM_NPROC_BUMP = 1,
81943 + GR_RLIM_NOFILE_BUMP = 5,
81944 + GR_RLIM_MEMLOCK_BUMP = 50000,
81945 + GR_RLIM_AS_BUMP = 500000,
81946 + GR_RLIM_LOCKS_BUMP = 2,
81947 + GR_RLIM_SIGPENDING_BUMP = 5,
81948 + GR_RLIM_MSGQUEUE_BUMP = 10000,
81949 + GR_RLIM_NICE_BUMP = 1,
81950 + GR_RLIM_RTPRIO_BUMP = 1,
81951 + GR_RLIM_RTTIME_BUMP = 1000000
81952 +};
81953 +
81954 +#endif
81955 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81956 new file mode 100644
81957 index 0000000..fb1de5d
81958 --- /dev/null
81959 +++ b/include/linux/grinternal.h
81960 @@ -0,0 +1,230 @@
81961 +#ifndef __GRINTERNAL_H
81962 +#define __GRINTERNAL_H
81963 +
81964 +#ifdef CONFIG_GRKERNSEC
81965 +
81966 +#include <linux/fs.h>
81967 +#include <linux/mnt_namespace.h>
81968 +#include <linux/nsproxy.h>
81969 +#include <linux/gracl.h>
81970 +#include <linux/grdefs.h>
81971 +#include <linux/grmsg.h>
81972 +
81973 +void gr_add_learn_entry(const char *fmt, ...)
81974 + __attribute__ ((format (printf, 1, 2)));
81975 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81976 + const struct vfsmount *mnt);
81977 +__u32 gr_check_create(const struct dentry *new_dentry,
81978 + const struct dentry *parent,
81979 + const struct vfsmount *mnt, const __u32 mode);
81980 +int gr_check_protected_task(const struct task_struct *task);
81981 +__u32 to_gr_audit(const __u32 reqmode);
81982 +int gr_set_acls(const int type);
81983 +int gr_acl_is_enabled(void);
81984 +char gr_roletype_to_char(void);
81985 +
81986 +void gr_handle_alertkill(struct task_struct *task);
81987 +char *gr_to_filename(const struct dentry *dentry,
81988 + const struct vfsmount *mnt);
81989 +char *gr_to_filename1(const struct dentry *dentry,
81990 + const struct vfsmount *mnt);
81991 +char *gr_to_filename2(const struct dentry *dentry,
81992 + const struct vfsmount *mnt);
81993 +char *gr_to_filename3(const struct dentry *dentry,
81994 + const struct vfsmount *mnt);
81995 +
81996 +extern int grsec_enable_ptrace_readexec;
81997 +extern int grsec_enable_harden_ptrace;
81998 +extern int grsec_enable_link;
81999 +extern int grsec_enable_fifo;
82000 +extern int grsec_enable_execve;
82001 +extern int grsec_enable_shm;
82002 +extern int grsec_enable_execlog;
82003 +extern int grsec_enable_signal;
82004 +extern int grsec_enable_audit_ptrace;
82005 +extern int grsec_enable_forkfail;
82006 +extern int grsec_enable_time;
82007 +extern int grsec_enable_rofs;
82008 +extern int grsec_deny_new_usb;
82009 +extern int grsec_enable_chroot_shmat;
82010 +extern int grsec_enable_chroot_mount;
82011 +extern int grsec_enable_chroot_double;
82012 +extern int grsec_enable_chroot_pivot;
82013 +extern int grsec_enable_chroot_chdir;
82014 +extern int grsec_enable_chroot_chmod;
82015 +extern int grsec_enable_chroot_mknod;
82016 +extern int grsec_enable_chroot_fchdir;
82017 +extern int grsec_enable_chroot_nice;
82018 +extern int grsec_enable_chroot_execlog;
82019 +extern int grsec_enable_chroot_caps;
82020 +extern int grsec_enable_chroot_rename;
82021 +extern int grsec_enable_chroot_sysctl;
82022 +extern int grsec_enable_chroot_unix;
82023 +extern int grsec_enable_symlinkown;
82024 +extern kgid_t grsec_symlinkown_gid;
82025 +extern int grsec_enable_tpe;
82026 +extern kgid_t grsec_tpe_gid;
82027 +extern int grsec_enable_tpe_all;
82028 +extern int grsec_enable_tpe_invert;
82029 +extern int grsec_enable_socket_all;
82030 +extern kgid_t grsec_socket_all_gid;
82031 +extern int grsec_enable_socket_client;
82032 +extern kgid_t grsec_socket_client_gid;
82033 +extern int grsec_enable_socket_server;
82034 +extern kgid_t grsec_socket_server_gid;
82035 +extern kgid_t grsec_audit_gid;
82036 +extern int grsec_enable_group;
82037 +extern int grsec_enable_log_rwxmaps;
82038 +extern int grsec_enable_mount;
82039 +extern int grsec_enable_chdir;
82040 +extern int grsec_resource_logging;
82041 +extern int grsec_enable_blackhole;
82042 +extern int grsec_lastack_retries;
82043 +extern int grsec_enable_brute;
82044 +extern int grsec_enable_harden_ipc;
82045 +extern int grsec_lock;
82046 +
82047 +extern spinlock_t grsec_alert_lock;
82048 +extern unsigned long grsec_alert_wtime;
82049 +extern unsigned long grsec_alert_fyet;
82050 +
82051 +extern spinlock_t grsec_audit_lock;
82052 +
82053 +extern rwlock_t grsec_exec_file_lock;
82054 +
82055 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82056 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82057 + (tsk)->exec_file->f_path.mnt) : "/")
82058 +
82059 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82060 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82061 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82062 +
82063 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82064 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82065 + (tsk)->exec_file->f_path.mnt) : "/")
82066 +
82067 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82068 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82069 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82070 +
82071 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82072 +
82073 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82074 +
82075 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82076 +{
82077 + if (file1 && file2) {
82078 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82079 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82080 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82081 + return true;
82082 + }
82083 +
82084 + return false;
82085 +}
82086 +
82087 +#define GR_CHROOT_CAPS {{ \
82088 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82089 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82090 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82091 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82092 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82093 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82094 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82095 +
82096 +#define security_learn(normal_msg,args...) \
82097 +({ \
82098 + read_lock(&grsec_exec_file_lock); \
82099 + gr_add_learn_entry(normal_msg "\n", ## args); \
82100 + read_unlock(&grsec_exec_file_lock); \
82101 +})
82102 +
82103 +enum {
82104 + GR_DO_AUDIT,
82105 + GR_DONT_AUDIT,
82106 + /* used for non-audit messages that we shouldn't kill the task on */
82107 + GR_DONT_AUDIT_GOOD
82108 +};
82109 +
82110 +enum {
82111 + GR_TTYSNIFF,
82112 + GR_RBAC,
82113 + GR_RBAC_STR,
82114 + GR_STR_RBAC,
82115 + GR_RBAC_MODE2,
82116 + GR_RBAC_MODE3,
82117 + GR_FILENAME,
82118 + GR_SYSCTL_HIDDEN,
82119 + GR_NOARGS,
82120 + GR_ONE_INT,
82121 + GR_ONE_INT_TWO_STR,
82122 + GR_ONE_STR,
82123 + GR_STR_INT,
82124 + GR_TWO_STR_INT,
82125 + GR_TWO_INT,
82126 + GR_TWO_U64,
82127 + GR_THREE_INT,
82128 + GR_FIVE_INT_TWO_STR,
82129 + GR_TWO_STR,
82130 + GR_THREE_STR,
82131 + GR_FOUR_STR,
82132 + GR_STR_FILENAME,
82133 + GR_FILENAME_STR,
82134 + GR_FILENAME_TWO_INT,
82135 + GR_FILENAME_TWO_INT_STR,
82136 + GR_TEXTREL,
82137 + GR_PTRACE,
82138 + GR_RESOURCE,
82139 + GR_CAP,
82140 + GR_SIG,
82141 + GR_SIG2,
82142 + GR_CRASH1,
82143 + GR_CRASH2,
82144 + GR_PSACCT,
82145 + GR_RWXMAP,
82146 + GR_RWXMAPVMA
82147 +};
82148 +
82149 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82150 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82151 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82152 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82153 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82154 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82155 +#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)
82156 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82157 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82158 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82159 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82160 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82161 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82162 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82163 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82164 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82165 +#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)
82166 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82167 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82168 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82169 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82170 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82171 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82172 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82173 +#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)
82174 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82175 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82176 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82177 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82178 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82179 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82180 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82181 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82182 +#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)
82183 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82184 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82185 +
82186 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82187 +
82188 +#endif
82189 +
82190 +#endif
82191 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82192 new file mode 100644
82193 index 0000000..26ef560
82194 --- /dev/null
82195 +++ b/include/linux/grmsg.h
82196 @@ -0,0 +1,118 @@
82197 +#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"
82198 +#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"
82199 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82200 +#define GR_STOPMOD_MSG "denied modification of module state by "
82201 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82202 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82203 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82204 +#define GR_IOPL_MSG "denied use of iopl() by "
82205 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82206 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82207 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82208 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82209 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82210 +#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"
82211 +#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"
82212 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82213 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82214 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82215 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82216 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82217 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82218 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82219 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82220 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82221 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82222 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82223 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82224 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82225 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82226 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82227 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82228 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82229 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82230 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82231 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82232 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82233 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82234 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82235 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82236 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82237 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82238 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82239 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82240 +#define GR_CHROOT_RENAME_MSG "denied bad rename of %.950s out of a chroot by "
82241 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82242 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82243 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82244 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82245 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82246 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82247 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82248 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82249 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82250 +#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"
82251 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82252 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82253 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82254 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82255 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82256 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82257 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82258 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82259 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82260 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82261 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82262 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82263 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82264 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82265 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82266 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82267 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82268 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82269 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82270 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82271 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82272 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82273 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82274 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82275 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82276 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82277 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82278 +#define GR_TIME_MSG "time set by "
82279 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82280 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82281 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82282 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82283 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82284 +#define GR_BIND_MSG "denied bind() by "
82285 +#define GR_CONNECT_MSG "denied connect() by "
82286 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82287 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82288 +#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"
82289 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82290 +#define GR_CAP_ACL_MSG "use of %s denied for "
82291 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82292 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82293 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82294 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82295 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82296 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82297 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82298 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82299 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82300 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82301 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82302 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82303 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82304 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82305 +#define GR_VM86_MSG "denied use of vm86 by "
82306 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82307 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82308 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82309 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82310 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82311 +#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 "
82312 +#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 "
82313 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82314 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82315 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82316 new file mode 100644
82317 index 0000000..6c76fcb
82318 --- /dev/null
82319 +++ b/include/linux/grsecurity.h
82320 @@ -0,0 +1,249 @@
82321 +#ifndef GR_SECURITY_H
82322 +#define GR_SECURITY_H
82323 +#include <linux/fs.h>
82324 +#include <linux/fs_struct.h>
82325 +#include <linux/binfmts.h>
82326 +#include <linux/gracl.h>
82327 +
82328 +/* notify of brain-dead configs */
82329 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82330 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82331 +#endif
82332 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82333 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82334 +#endif
82335 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82336 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82337 +#endif
82338 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82339 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82340 +#endif
82341 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82342 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82343 +#endif
82344 +
82345 +int gr_handle_new_usb(void);
82346 +
82347 +void gr_handle_brute_attach(int dumpable);
82348 +void gr_handle_brute_check(void);
82349 +void gr_handle_kernel_exploit(void);
82350 +
82351 +char gr_roletype_to_char(void);
82352 +
82353 +int gr_proc_is_restricted(void);
82354 +
82355 +int gr_acl_enable_at_secure(void);
82356 +
82357 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82358 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82359 +
82360 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82361 +
82362 +void gr_del_task_from_ip_table(struct task_struct *p);
82363 +
82364 +int gr_pid_is_chrooted(struct task_struct *p);
82365 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82366 +int gr_handle_chroot_nice(void);
82367 +int gr_handle_chroot_sysctl(const int op);
82368 +int gr_handle_chroot_setpriority(struct task_struct *p,
82369 + const int niceval);
82370 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82371 +int gr_chroot_fhandle(void);
82372 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82373 + const struct vfsmount *mnt);
82374 +void gr_handle_chroot_chdir(const struct path *path);
82375 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82376 + const struct vfsmount *mnt, const int mode);
82377 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82378 + const struct vfsmount *mnt, const int mode);
82379 +int gr_handle_chroot_mount(const struct dentry *dentry,
82380 + const struct vfsmount *mnt,
82381 + const char *dev_name);
82382 +int gr_handle_chroot_pivot(void);
82383 +int gr_handle_chroot_unix(const pid_t pid);
82384 +
82385 +int gr_handle_rawio(const struct inode *inode);
82386 +
82387 +void gr_handle_ioperm(void);
82388 +void gr_handle_iopl(void);
82389 +void gr_handle_msr_write(void);
82390 +
82391 +umode_t gr_acl_umask(void);
82392 +
82393 +int gr_tpe_allow(const struct file *file);
82394 +
82395 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82396 +void gr_clear_chroot_entries(struct task_struct *task);
82397 +
82398 +void gr_log_forkfail(const int retval);
82399 +void gr_log_timechange(void);
82400 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82401 +void gr_log_chdir(const struct dentry *dentry,
82402 + const struct vfsmount *mnt);
82403 +void gr_log_chroot_exec(const struct dentry *dentry,
82404 + const struct vfsmount *mnt);
82405 +void gr_log_remount(const char *devname, const int retval);
82406 +void gr_log_unmount(const char *devname, const int retval);
82407 +void gr_log_mount(const char *from, struct path *to, const int retval);
82408 +void gr_log_textrel(struct vm_area_struct *vma);
82409 +void gr_log_ptgnustack(struct file *file);
82410 +void gr_log_rwxmmap(struct file *file);
82411 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82412 +
82413 +int gr_handle_follow_link(const struct inode *parent,
82414 + const struct inode *inode,
82415 + const struct dentry *dentry,
82416 + const struct vfsmount *mnt);
82417 +int gr_handle_fifo(const struct dentry *dentry,
82418 + const struct vfsmount *mnt,
82419 + const struct dentry *dir, const int flag,
82420 + const int acc_mode);
82421 +int gr_handle_hardlink(const struct dentry *dentry,
82422 + const struct vfsmount *mnt,
82423 + struct inode *inode,
82424 + const int mode, const struct filename *to);
82425 +
82426 +int gr_is_capable(const int cap);
82427 +int gr_is_capable_nolog(const int cap);
82428 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82429 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82430 +
82431 +void gr_copy_label(struct task_struct *tsk);
82432 +void gr_handle_crash(struct task_struct *task, const int sig);
82433 +int gr_handle_signal(const struct task_struct *p, const int sig);
82434 +int gr_check_crash_uid(const kuid_t uid);
82435 +int gr_check_protected_task(const struct task_struct *task);
82436 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82437 +int gr_acl_handle_mmap(const struct file *file,
82438 + const unsigned long prot);
82439 +int gr_acl_handle_mprotect(const struct file *file,
82440 + const unsigned long prot);
82441 +int gr_check_hidden_task(const struct task_struct *tsk);
82442 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82443 + const struct vfsmount *mnt);
82444 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82445 + const struct vfsmount *mnt);
82446 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82447 + const struct vfsmount *mnt, const int fmode);
82448 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82449 + const struct vfsmount *mnt, umode_t *mode);
82450 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82451 + const struct vfsmount *mnt);
82452 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82453 + const struct vfsmount *mnt);
82454 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82455 + const struct vfsmount *mnt);
82456 +int gr_handle_ptrace(struct task_struct *task, const long request);
82457 +int gr_handle_proc_ptrace(struct task_struct *task);
82458 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82459 + const struct vfsmount *mnt);
82460 +int gr_check_crash_exec(const struct file *filp);
82461 +int gr_acl_is_enabled(void);
82462 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82463 + const kgid_t gid);
82464 +int gr_set_proc_label(const struct dentry *dentry,
82465 + const struct vfsmount *mnt,
82466 + const int unsafe_flags);
82467 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82468 + const struct vfsmount *mnt);
82469 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82470 + const struct vfsmount *mnt, int acc_mode);
82471 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82472 + const struct dentry *p_dentry,
82473 + const struct vfsmount *p_mnt,
82474 + int open_flags, int acc_mode, const int imode);
82475 +void gr_handle_create(const struct dentry *dentry,
82476 + const struct vfsmount *mnt);
82477 +void gr_handle_proc_create(const struct dentry *dentry,
82478 + const struct inode *inode);
82479 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82480 + const struct dentry *parent_dentry,
82481 + const struct vfsmount *parent_mnt,
82482 + const int mode);
82483 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82484 + const struct dentry *parent_dentry,
82485 + const struct vfsmount *parent_mnt);
82486 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82487 + const struct vfsmount *mnt);
82488 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82489 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82490 + const struct vfsmount *mnt);
82491 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82492 + const struct dentry *parent_dentry,
82493 + const struct vfsmount *parent_mnt,
82494 + const struct filename *from);
82495 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82496 + const struct dentry *parent_dentry,
82497 + const struct vfsmount *parent_mnt,
82498 + const struct dentry *old_dentry,
82499 + const struct vfsmount *old_mnt, const struct filename *to);
82500 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82501 +int gr_acl_handle_rename(struct dentry *new_dentry,
82502 + struct dentry *parent_dentry,
82503 + const struct vfsmount *parent_mnt,
82504 + struct dentry *old_dentry,
82505 + struct inode *old_parent_inode,
82506 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82507 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82508 + struct dentry *old_dentry,
82509 + struct dentry *new_dentry,
82510 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82511 +__u32 gr_check_link(const struct dentry *new_dentry,
82512 + const struct dentry *parent_dentry,
82513 + const struct vfsmount *parent_mnt,
82514 + const struct dentry *old_dentry,
82515 + const struct vfsmount *old_mnt);
82516 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82517 + const unsigned int namelen, const ino_t ino);
82518 +
82519 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82520 + const struct vfsmount *mnt);
82521 +void gr_acl_handle_exit(void);
82522 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82523 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82524 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82525 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82526 +void gr_audit_ptrace(struct task_struct *task);
82527 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82528 +void gr_put_exec_file(struct task_struct *task);
82529 +
82530 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82531 +
82532 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82533 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82534 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
82535 + struct dentry *newdentry, struct vfsmount *newmnt);
82536 +
82537 +#ifdef CONFIG_GRKERNSEC_RESLOG
82538 +extern void gr_log_resource(const struct task_struct *task, const int res,
82539 + const unsigned long wanted, const int gt);
82540 +#else
82541 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82542 + const unsigned long wanted, const int gt)
82543 +{
82544 +}
82545 +#endif
82546 +
82547 +#ifdef CONFIG_GRKERNSEC
82548 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82549 +void gr_handle_vm86(void);
82550 +void gr_handle_mem_readwrite(u64 from, u64 to);
82551 +
82552 +void gr_log_badprocpid(const char *entry);
82553 +
82554 +extern int grsec_enable_dmesg;
82555 +extern int grsec_disable_privio;
82556 +
82557 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82558 +extern kgid_t grsec_proc_gid;
82559 +#endif
82560 +
82561 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82562 +extern int grsec_enable_chroot_findtask;
82563 +#endif
82564 +#ifdef CONFIG_GRKERNSEC_SETXID
82565 +extern int grsec_enable_setxid;
82566 +#endif
82567 +#endif
82568 +
82569 +#endif
82570 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82571 new file mode 100644
82572 index 0000000..e7ffaaf
82573 --- /dev/null
82574 +++ b/include/linux/grsock.h
82575 @@ -0,0 +1,19 @@
82576 +#ifndef __GRSOCK_H
82577 +#define __GRSOCK_H
82578 +
82579 +extern void gr_attach_curr_ip(const struct sock *sk);
82580 +extern int gr_handle_sock_all(const int family, const int type,
82581 + const int protocol);
82582 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82583 +extern int gr_handle_sock_server_other(const struct sock *sck);
82584 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82585 +extern int gr_search_connect(struct socket * sock,
82586 + struct sockaddr_in * addr);
82587 +extern int gr_search_bind(struct socket * sock,
82588 + struct sockaddr_in * addr);
82589 +extern int gr_search_listen(struct socket * sock);
82590 +extern int gr_search_accept(struct socket * sock);
82591 +extern int gr_search_socket(const int domain, const int type,
82592 + const int protocol);
82593 +
82594 +#endif
82595 diff --git a/include/linux/hash.h b/include/linux/hash.h
82596 index d0494c3..69b7715 100644
82597 --- a/include/linux/hash.h
82598 +++ b/include/linux/hash.h
82599 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82600 struct fast_hash_ops {
82601 u32 (*hash)(const void *data, u32 len, u32 seed);
82602 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82603 -};
82604 +} __no_const;
82605
82606 /**
82607 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82608 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82609 index 9286a46..373f27f 100644
82610 --- a/include/linux/highmem.h
82611 +++ b/include/linux/highmem.h
82612 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82613 kunmap_atomic(kaddr);
82614 }
82615
82616 +static inline void sanitize_highpage(struct page *page)
82617 +{
82618 + void *kaddr;
82619 + unsigned long flags;
82620 +
82621 + local_irq_save(flags);
82622 + kaddr = kmap_atomic(page);
82623 + clear_page(kaddr);
82624 + kunmap_atomic(kaddr);
82625 + local_irq_restore(flags);
82626 +}
82627 +
82628 static inline void zero_user_segments(struct page *page,
82629 unsigned start1, unsigned end1,
82630 unsigned start2, unsigned end2)
82631 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82632 index 1c7b89a..7dda400 100644
82633 --- a/include/linux/hwmon-sysfs.h
82634 +++ b/include/linux/hwmon-sysfs.h
82635 @@ -25,7 +25,8 @@
82636 struct sensor_device_attribute{
82637 struct device_attribute dev_attr;
82638 int index;
82639 -};
82640 +} __do_const;
82641 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82642 #define to_sensor_dev_attr(_dev_attr) \
82643 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82644
82645 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82646 struct device_attribute dev_attr;
82647 u8 index;
82648 u8 nr;
82649 -};
82650 +} __do_const;
82651 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82652 #define to_sensor_dev_attr_2(_dev_attr) \
82653 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82654
82655 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82656 index b556e0a..c10a515 100644
82657 --- a/include/linux/i2c.h
82658 +++ b/include/linux/i2c.h
82659 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82660 /* To determine what the adapter supports */
82661 u32 (*functionality) (struct i2c_adapter *);
82662 };
82663 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82664
82665 /**
82666 * struct i2c_bus_recovery_info - I2C bus recovery information
82667 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82668 index d23c3c2..eb63c81 100644
82669 --- a/include/linux/i2o.h
82670 +++ b/include/linux/i2o.h
82671 @@ -565,7 +565,7 @@ struct i2o_controller {
82672 struct i2o_device *exec; /* Executive */
82673 #if BITS_PER_LONG == 64
82674 spinlock_t context_list_lock; /* lock for context_list */
82675 - atomic_t context_list_counter; /* needed for unique contexts */
82676 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82677 struct list_head context_list; /* list of context id's
82678 and pointers */
82679 #endif
82680 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82681 index aff7ad8..3942bbd 100644
82682 --- a/include/linux/if_pppox.h
82683 +++ b/include/linux/if_pppox.h
82684 @@ -76,7 +76,7 @@ struct pppox_proto {
82685 int (*ioctl)(struct socket *sock, unsigned int cmd,
82686 unsigned long arg);
82687 struct module *owner;
82688 -};
82689 +} __do_const;
82690
82691 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82692 extern void unregister_pppox_proto(int proto_num);
82693 diff --git a/include/linux/init.h b/include/linux/init.h
82694 index 2df8e8d..3e1280d 100644
82695 --- a/include/linux/init.h
82696 +++ b/include/linux/init.h
82697 @@ -37,9 +37,17 @@
82698 * section.
82699 */
82700
82701 +#define add_init_latent_entropy __latent_entropy
82702 +
82703 +#ifdef CONFIG_MEMORY_HOTPLUG
82704 +#define add_meminit_latent_entropy
82705 +#else
82706 +#define add_meminit_latent_entropy __latent_entropy
82707 +#endif
82708 +
82709 /* These are for everybody (although not all archs will actually
82710 discard it in modules) */
82711 -#define __init __section(.init.text) __cold notrace
82712 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82713 #define __initdata __section(.init.data)
82714 #define __initconst __constsection(.init.rodata)
82715 #define __exitdata __section(.exit.data)
82716 @@ -100,7 +108,7 @@
82717 #define __cpuexitconst
82718
82719 /* Used for MEMORY_HOTPLUG */
82720 -#define __meminit __section(.meminit.text) __cold notrace
82721 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82722 #define __meminitdata __section(.meminit.data)
82723 #define __meminitconst __constsection(.meminit.rodata)
82724 #define __memexit __section(.memexit.text) __exitused __cold notrace
82725 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82726 index 77fc43f..73caf92 100644
82727 --- a/include/linux/init_task.h
82728 +++ b/include/linux/init_task.h
82729 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82730
82731 #define INIT_TASK_COMM "swapper"
82732
82733 +#ifdef CONFIG_X86
82734 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82735 +#else
82736 +#define INIT_TASK_THREAD_INFO
82737 +#endif
82738 +
82739 #ifdef CONFIG_RT_MUTEXES
82740 # define INIT_RT_MUTEXES(tsk) \
82741 .pi_waiters = RB_ROOT, \
82742 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82743 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82744 .comm = INIT_TASK_COMM, \
82745 .thread = INIT_THREAD, \
82746 + INIT_TASK_THREAD_INFO \
82747 .fs = &init_fs, \
82748 .files = &init_files, \
82749 .signal = &init_signals, \
82750 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82751 index 69517a2..6b12d37 100644
82752 --- a/include/linux/interrupt.h
82753 +++ b/include/linux/interrupt.h
82754 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82755
82756 struct softirq_action
82757 {
82758 - void (*action)(struct softirq_action *);
82759 -};
82760 + void (*action)(void);
82761 +} __no_const;
82762
82763 asmlinkage void do_softirq(void);
82764 asmlinkage void __do_softirq(void);
82765 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82766 }
82767 #endif
82768
82769 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82770 +extern void open_softirq(int nr, void (*action)(void));
82771 extern void softirq_init(void);
82772 extern void __raise_softirq_irqoff(unsigned int nr);
82773
82774 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82775 index e6a7c9f..5804745 100644
82776 --- a/include/linux/iommu.h
82777 +++ b/include/linux/iommu.h
82778 @@ -133,7 +133,7 @@ struct iommu_ops {
82779 u32 (*domain_get_windows)(struct iommu_domain *domain);
82780
82781 unsigned long pgsize_bitmap;
82782 -};
82783 +} __do_const;
82784
82785 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82786 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82787 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82788 index 2c525022..345b106 100644
82789 --- a/include/linux/ioport.h
82790 +++ b/include/linux/ioport.h
82791 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82792 int adjust_resource(struct resource *res, resource_size_t start,
82793 resource_size_t size);
82794 resource_size_t resource_alignment(struct resource *res);
82795 -static inline resource_size_t resource_size(const struct resource *res)
82796 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82797 {
82798 return res->end - res->start + 1;
82799 }
82800 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82801 index 35e7eca..6afb7ad 100644
82802 --- a/include/linux/ipc_namespace.h
82803 +++ b/include/linux/ipc_namespace.h
82804 @@ -69,7 +69,7 @@ struct ipc_namespace {
82805 struct user_namespace *user_ns;
82806
82807 unsigned int proc_inum;
82808 -};
82809 +} __randomize_layout;
82810
82811 extern struct ipc_namespace init_ipc_ns;
82812 extern atomic_t nr_ipc_ns;
82813 diff --git a/include/linux/irq.h b/include/linux/irq.h
82814 index 03f48d9..e86af0c 100644
82815 --- a/include/linux/irq.h
82816 +++ b/include/linux/irq.h
82817 @@ -352,7 +352,8 @@ struct irq_chip {
82818 void (*irq_release_resources)(struct irq_data *data);
82819
82820 unsigned long flags;
82821 -};
82822 +} __do_const;
82823 +typedef struct irq_chip __no_const irq_chip_no_const;
82824
82825 /*
82826 * irq_chip specific flags
82827 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82828 index 13eed92..3261c86 100644
82829 --- a/include/linux/irqchip/arm-gic.h
82830 +++ b/include/linux/irqchip/arm-gic.h
82831 @@ -91,9 +91,11 @@
82832
82833 #ifndef __ASSEMBLY__
82834
82835 +#include <linux/irq.h>
82836 +
82837 struct device_node;
82838
82839 -extern struct irq_chip gic_arch_extn;
82840 +extern irq_chip_no_const gic_arch_extn;
82841
82842 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82843 u32 offset, struct device_node *);
82844 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82845 index c367cbd..c9b79e6 100644
82846 --- a/include/linux/jiffies.h
82847 +++ b/include/linux/jiffies.h
82848 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82849 /*
82850 * Convert various time units to each other:
82851 */
82852 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82853 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82854 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82855 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82856
82857 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82858 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82859 {
82860 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82861 }
82862
82863 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82864 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82865 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82866 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82867 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82868 extern void jiffies_to_timespec(const unsigned long jiffies,
82869 - struct timespec *value);
82870 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82871 + struct timespec *value) __intentional_overflow(-1);
82872 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82873 extern void jiffies_to_timeval(const unsigned long jiffies,
82874 struct timeval *value);
82875
82876 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82877 index 6883e19..e854fcb 100644
82878 --- a/include/linux/kallsyms.h
82879 +++ b/include/linux/kallsyms.h
82880 @@ -15,7 +15,8 @@
82881
82882 struct module;
82883
82884 -#ifdef CONFIG_KALLSYMS
82885 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82886 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82887 /* Lookup the address for a symbol. Returns 0 if not found. */
82888 unsigned long kallsyms_lookup_name(const char *name);
82889
82890 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82891 /* Stupid that this does nothing, but I didn't create this mess. */
82892 #define __print_symbol(fmt, addr)
82893 #endif /*CONFIG_KALLSYMS*/
82894 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82895 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82896 +extern unsigned long kallsyms_lookup_name(const char *name);
82897 +extern void __print_symbol(const char *fmt, unsigned long address);
82898 +extern int sprint_backtrace(char *buffer, unsigned long address);
82899 +extern int sprint_symbol(char *buffer, unsigned long address);
82900 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82901 +const char *kallsyms_lookup(unsigned long addr,
82902 + unsigned long *symbolsize,
82903 + unsigned long *offset,
82904 + char **modname, char *namebuf);
82905 +extern int kallsyms_lookup_size_offset(unsigned long addr,
82906 + unsigned long *symbolsize,
82907 + unsigned long *offset);
82908 +#endif
82909
82910 /* This macro allows us to keep printk typechecking */
82911 static __printf(1, 2)
82912 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82913 index ff9f1d3..6712be5 100644
82914 --- a/include/linux/key-type.h
82915 +++ b/include/linux/key-type.h
82916 @@ -152,7 +152,7 @@ struct key_type {
82917 /* internal fields */
82918 struct list_head link; /* link in types list */
82919 struct lock_class_key lock_class; /* key->sem lock class */
82920 -};
82921 +} __do_const;
82922
82923 extern struct key_type key_type_keyring;
82924
82925 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82926 index e465bb1..19f605f 100644
82927 --- a/include/linux/kgdb.h
82928 +++ b/include/linux/kgdb.h
82929 @@ -52,7 +52,7 @@ extern int kgdb_connected;
82930 extern int kgdb_io_module_registered;
82931
82932 extern atomic_t kgdb_setting_breakpoint;
82933 -extern atomic_t kgdb_cpu_doing_single_step;
82934 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82935
82936 extern struct task_struct *kgdb_usethread;
82937 extern struct task_struct *kgdb_contthread;
82938 @@ -254,7 +254,7 @@ struct kgdb_arch {
82939 void (*correct_hw_break)(void);
82940
82941 void (*enable_nmi)(bool on);
82942 -};
82943 +} __do_const;
82944
82945 /**
82946 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82947 @@ -279,7 +279,7 @@ struct kgdb_io {
82948 void (*pre_exception) (void);
82949 void (*post_exception) (void);
82950 int is_console;
82951 -};
82952 +} __do_const;
82953
82954 extern struct kgdb_arch arch_kgdb_ops;
82955
82956 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82957 index 0555cc6..40116ce 100644
82958 --- a/include/linux/kmod.h
82959 +++ b/include/linux/kmod.h
82960 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82961 * usually useless though. */
82962 extern __printf(2, 3)
82963 int __request_module(bool wait, const char *name, ...);
82964 +extern __printf(3, 4)
82965 +int ___request_module(bool wait, char *param_name, const char *name, ...);
82966 #define request_module(mod...) __request_module(true, mod)
82967 #define request_module_nowait(mod...) __request_module(false, mod)
82968 #define try_then_request_module(x, mod...) \
82969 @@ -57,6 +59,9 @@ struct subprocess_info {
82970 struct work_struct work;
82971 struct completion *complete;
82972 char *path;
82973 +#ifdef CONFIG_GRKERNSEC
82974 + char *origpath;
82975 +#endif
82976 char **argv;
82977 char **envp;
82978 int wait;
82979 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82980 index 2d61b90..a1d0a13 100644
82981 --- a/include/linux/kobject.h
82982 +++ b/include/linux/kobject.h
82983 @@ -118,7 +118,7 @@ struct kobj_type {
82984 struct attribute **default_attrs;
82985 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82986 const void *(*namespace)(struct kobject *kobj);
82987 -};
82988 +} __do_const;
82989
82990 struct kobj_uevent_env {
82991 char *argv[3];
82992 @@ -142,6 +142,7 @@ struct kobj_attribute {
82993 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82994 const char *buf, size_t count);
82995 };
82996 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82997
82998 extern const struct sysfs_ops kobj_sysfs_ops;
82999
83000 @@ -169,7 +170,7 @@ struct kset {
83001 spinlock_t list_lock;
83002 struct kobject kobj;
83003 const struct kset_uevent_ops *uevent_ops;
83004 -};
83005 +} __randomize_layout;
83006
83007 extern void kset_init(struct kset *kset);
83008 extern int __must_check kset_register(struct kset *kset);
83009 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83010 index df32d25..fb52e27 100644
83011 --- a/include/linux/kobject_ns.h
83012 +++ b/include/linux/kobject_ns.h
83013 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83014 const void *(*netlink_ns)(struct sock *sk);
83015 const void *(*initial_ns)(void);
83016 void (*drop_ns)(void *);
83017 -};
83018 +} __do_const;
83019
83020 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83021 int kobj_ns_type_registered(enum kobj_ns_type type);
83022 diff --git a/include/linux/kref.h b/include/linux/kref.h
83023 index 484604d..0f6c5b6 100644
83024 --- a/include/linux/kref.h
83025 +++ b/include/linux/kref.h
83026 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83027 static inline int kref_sub(struct kref *kref, unsigned int count,
83028 void (*release)(struct kref *kref))
83029 {
83030 - WARN_ON(release == NULL);
83031 + BUG_ON(release == NULL);
83032
83033 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83034 release(kref);
83035 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83036 index a6059bd..8126d5c 100644
83037 --- a/include/linux/kvm_host.h
83038 +++ b/include/linux/kvm_host.h
83039 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
83040 {
83041 }
83042 #endif
83043 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83044 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83045 struct module *module);
83046 void kvm_exit(void);
83047
83048 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83049 struct kvm_guest_debug *dbg);
83050 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83051
83052 -int kvm_arch_init(void *opaque);
83053 +int kvm_arch_init(const void *opaque);
83054 void kvm_arch_exit(void);
83055
83056 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83057 diff --git a/include/linux/libata.h b/include/linux/libata.h
83058 index bd5fefe..2a8a8d2 100644
83059 --- a/include/linux/libata.h
83060 +++ b/include/linux/libata.h
83061 @@ -976,7 +976,7 @@ struct ata_port_operations {
83062 * fields must be pointers.
83063 */
83064 const struct ata_port_operations *inherits;
83065 -};
83066 +} __do_const;
83067
83068 struct ata_port_info {
83069 unsigned long flags;
83070 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83071 index a6a42dd..6c5ebce 100644
83072 --- a/include/linux/linkage.h
83073 +++ b/include/linux/linkage.h
83074 @@ -36,6 +36,7 @@
83075 #endif
83076
83077 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83078 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83079 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83080
83081 /*
83082 diff --git a/include/linux/list.h b/include/linux/list.h
83083 index f33f831..1ffe5e2 100644
83084 --- a/include/linux/list.h
83085 +++ b/include/linux/list.h
83086 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83087 extern void list_del(struct list_head *entry);
83088 #endif
83089
83090 +extern void __pax_list_add(struct list_head *new,
83091 + struct list_head *prev,
83092 + struct list_head *next);
83093 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83094 +{
83095 + __pax_list_add(new, head, head->next);
83096 +}
83097 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83098 +{
83099 + __pax_list_add(new, head->prev, head);
83100 +}
83101 +extern void pax_list_del(struct list_head *entry);
83102 +
83103 /**
83104 * list_replace - replace old entry by new one
83105 * @old : the element to be replaced
83106 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83107 INIT_LIST_HEAD(entry);
83108 }
83109
83110 +extern void pax_list_del_init(struct list_head *entry);
83111 +
83112 /**
83113 * list_move - delete from one list and add as another's head
83114 * @list: the entry to move
83115 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83116 index 4bfde0e..d6e2e09 100644
83117 --- a/include/linux/lockref.h
83118 +++ b/include/linux/lockref.h
83119 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83120 return ((int)l->count < 0);
83121 }
83122
83123 +static inline unsigned int __lockref_read(struct lockref *lockref)
83124 +{
83125 + return lockref->count;
83126 +}
83127 +
83128 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83129 +{
83130 + lockref->count = count;
83131 +}
83132 +
83133 +static inline void __lockref_inc(struct lockref *lockref)
83134 +{
83135 +
83136 +#ifdef CONFIG_PAX_REFCOUNT
83137 + atomic_inc((atomic_t *)&lockref->count);
83138 +#else
83139 + lockref->count++;
83140 +#endif
83141 +
83142 +}
83143 +
83144 +static inline void __lockref_dec(struct lockref *lockref)
83145 +{
83146 +
83147 +#ifdef CONFIG_PAX_REFCOUNT
83148 + atomic_dec((atomic_t *)&lockref->count);
83149 +#else
83150 + lockref->count--;
83151 +#endif
83152 +
83153 +}
83154 +
83155 #endif /* __LINUX_LOCKREF_H */
83156 diff --git a/include/linux/math64.h b/include/linux/math64.h
83157 index c45c089..298841c 100644
83158 --- a/include/linux/math64.h
83159 +++ b/include/linux/math64.h
83160 @@ -15,7 +15,7 @@
83161 * This is commonly provided by 32bit archs to provide an optimized 64bit
83162 * divide.
83163 */
83164 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83165 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83166 {
83167 *remainder = dividend % divisor;
83168 return dividend / divisor;
83169 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83170 /**
83171 * div64_u64 - unsigned 64bit divide with 64bit divisor
83172 */
83173 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83174 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83175 {
83176 return dividend / divisor;
83177 }
83178 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83179 #define div64_ul(x, y) div_u64((x), (y))
83180
83181 #ifndef div_u64_rem
83182 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83183 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83184 {
83185 *remainder = do_div(dividend, divisor);
83186 return dividend;
83187 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83188 #endif
83189
83190 #ifndef div64_u64
83191 -extern u64 div64_u64(u64 dividend, u64 divisor);
83192 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83193 #endif
83194
83195 #ifndef div64_s64
83196 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83197 * divide.
83198 */
83199 #ifndef div_u64
83200 -static inline u64 div_u64(u64 dividend, u32 divisor)
83201 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83202 {
83203 u32 remainder;
83204 return div_u64_rem(dividend, divisor, &remainder);
83205 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83206 index 3d385c8..deacb6a 100644
83207 --- a/include/linux/mempolicy.h
83208 +++ b/include/linux/mempolicy.h
83209 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83210 }
83211
83212 #define vma_policy(vma) ((vma)->vm_policy)
83213 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83214 +{
83215 + vma->vm_policy = pol;
83216 +}
83217
83218 static inline void mpol_get(struct mempolicy *pol)
83219 {
83220 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83221 }
83222
83223 #define vma_policy(vma) NULL
83224 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83225 +{
83226 +}
83227
83228 static inline int
83229 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83230 diff --git a/include/linux/mm.h b/include/linux/mm.h
83231 index 5ab2da9..5f0b3df 100644
83232 --- a/include/linux/mm.h
83233 +++ b/include/linux/mm.h
83234 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83235 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83236 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83237 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83238 +
83239 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83240 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83241 +#endif
83242 +
83243 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83244
83245 #ifdef CONFIG_MEM_SOFT_DIRTY
83246 @@ -238,8 +243,8 @@ struct vm_operations_struct {
83247 /* called by access_process_vm when get_user_pages() fails, typically
83248 * for use by special VMAs that can switch between memory and hardware
83249 */
83250 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83251 - void *buf, int len, int write);
83252 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83253 + void *buf, size_t len, int write);
83254
83255 /* Called by the /proc/PID/maps code to ask the vma whether it
83256 * has a special name. Returning non-NULL will also cause this
83257 @@ -275,6 +280,7 @@ struct vm_operations_struct {
83258 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83259 unsigned long size, pgoff_t pgoff);
83260 };
83261 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83262
83263 struct mmu_gather;
83264 struct inode;
83265 @@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83266 unsigned long *pfn);
83267 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83268 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83269 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83270 - void *buf, int len, int write);
83271 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83272 + void *buf, size_t len, int write);
83273
83274 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83275 loff_t const holebegin, loff_t const holelen)
83276 @@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83277 }
83278 #endif
83279
83280 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83281 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83282 - void *buf, int len, int write);
83283 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83284 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83285 + void *buf, size_t len, int write);
83286
83287 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83288 unsigned long start, unsigned long nr_pages,
83289 @@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
83290 int clear_page_dirty_for_io(struct page *page);
83291 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83292
83293 -/* Is the vma a continuation of the stack vma above it? */
83294 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83295 -{
83296 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83297 -}
83298 -
83299 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83300 - unsigned long addr)
83301 -{
83302 - return (vma->vm_flags & VM_GROWSDOWN) &&
83303 - (vma->vm_start == addr) &&
83304 - !vma_growsdown(vma->vm_prev, addr);
83305 -}
83306 -
83307 -/* Is the vma a continuation of the stack vma below it? */
83308 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83309 -{
83310 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83311 -}
83312 -
83313 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83314 - unsigned long addr)
83315 -{
83316 - return (vma->vm_flags & VM_GROWSUP) &&
83317 - (vma->vm_end == addr) &&
83318 - !vma_growsup(vma->vm_next, addr);
83319 -}
83320 -
83321 extern struct task_struct *task_of_stack(struct task_struct *task,
83322 struct vm_area_struct *vma, bool in_group);
83323
83324 @@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83325 {
83326 return 0;
83327 }
83328 +
83329 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83330 + unsigned long address)
83331 +{
83332 + return 0;
83333 +}
83334 #else
83335 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83336 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83337 #endif
83338
83339 #ifdef __PAGETABLE_PMD_FOLDED
83340 @@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83341 {
83342 return 0;
83343 }
83344 +
83345 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83346 + unsigned long address)
83347 +{
83348 + return 0;
83349 +}
83350 #else
83351 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83352 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83353 #endif
83354
83355 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83356 @@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83357 NULL: pud_offset(pgd, address);
83358 }
83359
83360 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83361 +{
83362 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83363 + NULL: pud_offset(pgd, address);
83364 +}
83365 +
83366 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83367 {
83368 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83369 NULL: pmd_offset(pud, address);
83370 }
83371 +
83372 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83373 +{
83374 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83375 + NULL: pmd_offset(pud, address);
83376 +}
83377 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83378
83379 #if USE_SPLIT_PTE_PTLOCKS
83380 @@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83381 bool *need_rmap_locks);
83382 extern void exit_mmap(struct mm_struct *);
83383
83384 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83385 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83386 + const unsigned long wanted, const int gt);
83387 +#else
83388 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83389 + const unsigned long wanted, const int gt)
83390 +{
83391 +}
83392 +#endif
83393 +
83394 static inline int check_data_rlimit(unsigned long rlim,
83395 unsigned long new,
83396 unsigned long start,
83397 unsigned long end_data,
83398 unsigned long start_data)
83399 {
83400 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83401 if (rlim < RLIM_INFINITY) {
83402 if (((new - start) + (end_data - start_data)) > rlim)
83403 return -ENOSPC;
83404 @@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83405 unsigned long addr, unsigned long len,
83406 unsigned long flags, struct page **pages);
83407
83408 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83409 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83410
83411 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83412 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83413 @@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83414 unsigned long len, unsigned long prot, unsigned long flags,
83415 unsigned long pgoff, unsigned long *populate);
83416 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83417 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83418
83419 #ifdef CONFIG_MMU
83420 extern int __mm_populate(unsigned long addr, unsigned long len,
83421 @@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
83422 unsigned long high_limit;
83423 unsigned long align_mask;
83424 unsigned long align_offset;
83425 + unsigned long threadstack_offset;
83426 };
83427
83428 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83429 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83430 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83431 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83432
83433 /*
83434 * Search for an unmapped address range.
83435 @@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83436 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83437 */
83438 static inline unsigned long
83439 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83440 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83441 {
83442 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83443 return unmapped_area(info);
83444 @@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83445 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83446 struct vm_area_struct **pprev);
83447
83448 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83449 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83450 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83451 +
83452 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83453 NULL if none. Assume start_addr < end_addr. */
83454 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83455 @@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83456 }
83457
83458 #ifdef CONFIG_MMU
83459 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83460 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83461 void vma_set_page_prot(struct vm_area_struct *vma);
83462 #else
83463 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83464 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83465 {
83466 return __pgprot(0);
83467 }
83468 @@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83469 static inline void vm_stat_account(struct mm_struct *mm,
83470 unsigned long flags, struct file *file, long pages)
83471 {
83472 +
83473 +#ifdef CONFIG_PAX_RANDMMAP
83474 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83475 +#endif
83476 +
83477 mm->total_vm += pages;
83478 }
83479 #endif /* CONFIG_PROC_FS */
83480 @@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83481 extern int sysctl_memory_failure_early_kill;
83482 extern int sysctl_memory_failure_recovery;
83483 extern void shake_page(struct page *p, int access);
83484 -extern atomic_long_t num_poisoned_pages;
83485 +extern atomic_long_unchecked_t num_poisoned_pages;
83486 extern int soft_offline_page(struct page *page, int flags);
83487
83488 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83489 @@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83490 static inline void setup_nr_node_ids(void) {}
83491 #endif
83492
83493 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83494 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83495 +#else
83496 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83497 +#endif
83498 +
83499 #endif /* __KERNEL__ */
83500 #endif /* _LINUX_MM_H */
83501 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83502 index 6e0b286..90d9c0d 100644
83503 --- a/include/linux/mm_types.h
83504 +++ b/include/linux/mm_types.h
83505 @@ -308,7 +308,9 @@ struct vm_area_struct {
83506 #ifdef CONFIG_NUMA
83507 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83508 #endif
83509 -};
83510 +
83511 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83512 +} __randomize_layout;
83513
83514 struct core_thread {
83515 struct task_struct *task;
83516 @@ -454,7 +456,25 @@ struct mm_struct {
83517 bool tlb_flush_pending;
83518 #endif
83519 struct uprobes_state uprobes_state;
83520 -};
83521 +
83522 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83523 + unsigned long pax_flags;
83524 +#endif
83525 +
83526 +#ifdef CONFIG_PAX_DLRESOLVE
83527 + unsigned long call_dl_resolve;
83528 +#endif
83529 +
83530 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83531 + unsigned long call_syscall;
83532 +#endif
83533 +
83534 +#ifdef CONFIG_PAX_ASLR
83535 + unsigned long delta_mmap; /* randomized offset */
83536 + unsigned long delta_stack; /* randomized offset */
83537 +#endif
83538 +
83539 +} __randomize_layout;
83540
83541 static inline void mm_init_cpumask(struct mm_struct *mm)
83542 {
83543 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83544 index c5d5278..f0b68c8 100644
83545 --- a/include/linux/mmiotrace.h
83546 +++ b/include/linux/mmiotrace.h
83547 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83548 /* Called from ioremap.c */
83549 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83550 void __iomem *addr);
83551 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83552 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83553
83554 /* For anyone to insert markers. Remember trailing newline. */
83555 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83556 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83557 {
83558 }
83559
83560 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83561 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83562 {
83563 }
83564
83565 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83566 index ffe66e3..b310722 100644
83567 --- a/include/linux/mmzone.h
83568 +++ b/include/linux/mmzone.h
83569 @@ -527,7 +527,7 @@ struct zone {
83570
83571 ZONE_PADDING(_pad3_)
83572 /* Zone statistics */
83573 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83574 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83575 } ____cacheline_internodealigned_in_smp;
83576
83577 enum zone_flags {
83578 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83579 index 44eeef0..a92d3f9 100644
83580 --- a/include/linux/mod_devicetable.h
83581 +++ b/include/linux/mod_devicetable.h
83582 @@ -139,7 +139,7 @@ struct usb_device_id {
83583 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83584 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83585
83586 -#define HID_ANY_ID (~0)
83587 +#define HID_ANY_ID (~0U)
83588 #define HID_BUS_ANY 0xffff
83589 #define HID_GROUP_ANY 0x0000
83590
83591 @@ -475,7 +475,7 @@ struct dmi_system_id {
83592 const char *ident;
83593 struct dmi_strmatch matches[4];
83594 void *driver_data;
83595 -};
83596 +} __do_const;
83597 /*
83598 * struct dmi_device_id appears during expansion of
83599 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83600 diff --git a/include/linux/module.h b/include/linux/module.h
83601 index 71f282a..b2387e2 100644
83602 --- a/include/linux/module.h
83603 +++ b/include/linux/module.h
83604 @@ -17,9 +17,11 @@
83605 #include <linux/moduleparam.h>
83606 #include <linux/jump_label.h>
83607 #include <linux/export.h>
83608 +#include <linux/fs.h>
83609
83610 #include <linux/percpu.h>
83611 #include <asm/module.h>
83612 +#include <asm/pgtable.h>
83613
83614 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83615 #define MODULE_SIG_STRING "~Module signature appended~\n"
83616 @@ -42,7 +44,7 @@ struct module_kobject {
83617 struct kobject *drivers_dir;
83618 struct module_param_attrs *mp;
83619 struct completion *kobj_completion;
83620 -};
83621 +} __randomize_layout;
83622
83623 struct module_attribute {
83624 struct attribute attr;
83625 @@ -54,12 +56,13 @@ struct module_attribute {
83626 int (*test)(struct module *);
83627 void (*free)(struct module *);
83628 };
83629 +typedef struct module_attribute __no_const module_attribute_no_const;
83630
83631 struct module_version_attribute {
83632 struct module_attribute mattr;
83633 const char *module_name;
83634 const char *version;
83635 -} __attribute__ ((__aligned__(sizeof(void *))));
83636 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83637
83638 extern ssize_t __modver_version_show(struct module_attribute *,
83639 struct module_kobject *, char *);
83640 @@ -235,7 +238,7 @@ struct module {
83641
83642 /* Sysfs stuff. */
83643 struct module_kobject mkobj;
83644 - struct module_attribute *modinfo_attrs;
83645 + module_attribute_no_const *modinfo_attrs;
83646 const char *version;
83647 const char *srcversion;
83648 struct kobject *holders_dir;
83649 @@ -284,19 +287,16 @@ struct module {
83650 int (*init)(void);
83651
83652 /* If this is non-NULL, vfree after init() returns */
83653 - void *module_init;
83654 + void *module_init_rx, *module_init_rw;
83655
83656 /* Here is the actual code + data, vfree'd on unload. */
83657 - void *module_core;
83658 + void *module_core_rx, *module_core_rw;
83659
83660 /* Here are the sizes of the init and core sections */
83661 - unsigned int init_size, core_size;
83662 + unsigned int init_size_rw, core_size_rw;
83663
83664 /* The size of the executable code in each section. */
83665 - unsigned int init_text_size, core_text_size;
83666 -
83667 - /* Size of RO sections of the module (text+rodata) */
83668 - unsigned int init_ro_size, core_ro_size;
83669 + unsigned int init_size_rx, core_size_rx;
83670
83671 /* Arch-specific module values */
83672 struct mod_arch_specific arch;
83673 @@ -352,6 +352,10 @@ struct module {
83674 #ifdef CONFIG_EVENT_TRACING
83675 struct ftrace_event_call **trace_events;
83676 unsigned int num_trace_events;
83677 + struct file_operations trace_id;
83678 + struct file_operations trace_enable;
83679 + struct file_operations trace_format;
83680 + struct file_operations trace_filter;
83681 #endif
83682 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83683 unsigned int num_ftrace_callsites;
83684 @@ -375,7 +379,7 @@ struct module {
83685 ctor_fn_t *ctors;
83686 unsigned int num_ctors;
83687 #endif
83688 -};
83689 +} __randomize_layout;
83690 #ifndef MODULE_ARCH_INIT
83691 #define MODULE_ARCH_INIT {}
83692 #endif
83693 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83694 bool is_module_percpu_address(unsigned long addr);
83695 bool is_module_text_address(unsigned long addr);
83696
83697 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83698 +{
83699 +
83700 +#ifdef CONFIG_PAX_KERNEXEC
83701 + if (ktla_ktva(addr) >= (unsigned long)start &&
83702 + ktla_ktva(addr) < (unsigned long)start + size)
83703 + return 1;
83704 +#endif
83705 +
83706 + return ((void *)addr >= start && (void *)addr < start + size);
83707 +}
83708 +
83709 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83710 +{
83711 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83712 +}
83713 +
83714 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83715 +{
83716 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83717 +}
83718 +
83719 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83720 +{
83721 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83722 +}
83723 +
83724 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83725 +{
83726 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83727 +}
83728 +
83729 static inline bool within_module_core(unsigned long addr,
83730 const struct module *mod)
83731 {
83732 - return (unsigned long)mod->module_core <= addr &&
83733 - addr < (unsigned long)mod->module_core + mod->core_size;
83734 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83735 }
83736
83737 static inline bool within_module_init(unsigned long addr,
83738 const struct module *mod)
83739 {
83740 - return (unsigned long)mod->module_init <= addr &&
83741 - addr < (unsigned long)mod->module_init + mod->init_size;
83742 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83743 }
83744
83745 static inline bool within_module(unsigned long addr, const struct module *mod)
83746 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83747 index 7eeb9bb..68f37e0 100644
83748 --- a/include/linux/moduleloader.h
83749 +++ b/include/linux/moduleloader.h
83750 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83751 sections. Returns NULL on failure. */
83752 void *module_alloc(unsigned long size);
83753
83754 +#ifdef CONFIG_PAX_KERNEXEC
83755 +void *module_alloc_exec(unsigned long size);
83756 +#else
83757 +#define module_alloc_exec(x) module_alloc(x)
83758 +#endif
83759 +
83760 /* Free memory returned from module_alloc. */
83761 void module_free(struct module *mod, void *module_region);
83762
83763 +#ifdef CONFIG_PAX_KERNEXEC
83764 +void module_free_exec(struct module *mod, void *module_region);
83765 +#else
83766 +#define module_free_exec(x, y) module_free((x), (y))
83767 +#endif
83768 +
83769 /*
83770 * Apply the given relocation to the (simplified) ELF. Return -error
83771 * or 0.
83772 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83773 unsigned int relsec,
83774 struct module *me)
83775 {
83776 +#ifdef CONFIG_MODULES
83777 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83778 module_name(me));
83779 +#endif
83780 return -ENOEXEC;
83781 }
83782 #endif
83783 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83784 unsigned int relsec,
83785 struct module *me)
83786 {
83787 +#ifdef CONFIG_MODULES
83788 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83789 module_name(me));
83790 +#endif
83791 return -ENOEXEC;
83792 }
83793 #endif
83794 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83795 index 1c9effa..1160bdd 100644
83796 --- a/include/linux/moduleparam.h
83797 +++ b/include/linux/moduleparam.h
83798 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83799 * @len is usually just sizeof(string).
83800 */
83801 #define module_param_string(name, string, len, perm) \
83802 - static const struct kparam_string __param_string_##name \
83803 + static const struct kparam_string __param_string_##name __used \
83804 = { len, string }; \
83805 __module_param_call(MODULE_PARAM_PREFIX, name, \
83806 &param_ops_string, \
83807 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83808 */
83809 #define module_param_array_named(name, array, type, nump, perm) \
83810 param_check_##type(name, &(array)[0]); \
83811 - static const struct kparam_array __param_arr_##name \
83812 + static const struct kparam_array __param_arr_##name __used \
83813 = { .max = ARRAY_SIZE(array), .num = nump, \
83814 .ops = &param_ops_##type, \
83815 .elemsize = sizeof(array[0]), .elem = array }; \
83816 diff --git a/include/linux/mount.h b/include/linux/mount.h
83817 index c2c561d..a5f2a8c 100644
83818 --- a/include/linux/mount.h
83819 +++ b/include/linux/mount.h
83820 @@ -66,7 +66,7 @@ struct vfsmount {
83821 struct dentry *mnt_root; /* root of the mounted tree */
83822 struct super_block *mnt_sb; /* pointer to superblock */
83823 int mnt_flags;
83824 -};
83825 +} __randomize_layout;
83826
83827 struct file; /* forward dec */
83828 struct path;
83829 diff --git a/include/linux/namei.h b/include/linux/namei.h
83830 index 492de72..1bddcd4 100644
83831 --- a/include/linux/namei.h
83832 +++ b/include/linux/namei.h
83833 @@ -19,7 +19,7 @@ struct nameidata {
83834 unsigned seq, m_seq;
83835 int last_type;
83836 unsigned depth;
83837 - char *saved_names[MAX_NESTED_LINKS + 1];
83838 + const char *saved_names[MAX_NESTED_LINKS + 1];
83839 };
83840
83841 /*
83842 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83843
83844 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83845
83846 -static inline void nd_set_link(struct nameidata *nd, char *path)
83847 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83848 {
83849 nd->saved_names[nd->depth] = path;
83850 }
83851
83852 -static inline char *nd_get_link(struct nameidata *nd)
83853 +static inline const char *nd_get_link(const struct nameidata *nd)
83854 {
83855 return nd->saved_names[nd->depth];
83856 }
83857 diff --git a/include/linux/net.h b/include/linux/net.h
83858 index 17d8339..81656c0 100644
83859 --- a/include/linux/net.h
83860 +++ b/include/linux/net.h
83861 @@ -192,7 +192,7 @@ struct net_proto_family {
83862 int (*create)(struct net *net, struct socket *sock,
83863 int protocol, int kern);
83864 struct module *owner;
83865 -};
83866 +} __do_const;
83867
83868 struct iovec;
83869 struct kvec;
83870 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83871 index 22339b4..4b4d5b3 100644
83872 --- a/include/linux/netdevice.h
83873 +++ b/include/linux/netdevice.h
83874 @@ -1160,6 +1160,7 @@ struct net_device_ops {
83875 struct net_device *dev,
83876 netdev_features_t features);
83877 };
83878 +typedef struct net_device_ops __no_const net_device_ops_no_const;
83879
83880 /**
83881 * enum net_device_priv_flags - &struct net_device priv_flags
83882 @@ -1502,10 +1503,10 @@ struct net_device {
83883
83884 struct net_device_stats stats;
83885
83886 - atomic_long_t rx_dropped;
83887 - atomic_long_t tx_dropped;
83888 + atomic_long_unchecked_t rx_dropped;
83889 + atomic_long_unchecked_t tx_dropped;
83890
83891 - atomic_t carrier_changes;
83892 + atomic_unchecked_t carrier_changes;
83893
83894 #ifdef CONFIG_WIRELESS_EXT
83895 const struct iw_handler_def * wireless_handlers;
83896 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83897 index 2517ece..0bbfcfb 100644
83898 --- a/include/linux/netfilter.h
83899 +++ b/include/linux/netfilter.h
83900 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83901 #endif
83902 /* Use the module struct to lock set/get code in place */
83903 struct module *owner;
83904 -};
83905 +} __do_const;
83906
83907 /* Function to register/unregister hook points. */
83908 int nf_register_hook(struct nf_hook_ops *reg);
83909 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83910 index e955d47..04a5338 100644
83911 --- a/include/linux/netfilter/nfnetlink.h
83912 +++ b/include/linux/netfilter/nfnetlink.h
83913 @@ -19,7 +19,7 @@ struct nfnl_callback {
83914 const struct nlattr * const cda[]);
83915 const struct nla_policy *policy; /* netlink attribute policy */
83916 const u_int16_t attr_count; /* number of nlattr's */
83917 -};
83918 +} __do_const;
83919
83920 struct nfnetlink_subsystem {
83921 const char *name;
83922 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83923 new file mode 100644
83924 index 0000000..33f4af8
83925 --- /dev/null
83926 +++ b/include/linux/netfilter/xt_gradm.h
83927 @@ -0,0 +1,9 @@
83928 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
83929 +#define _LINUX_NETFILTER_XT_GRADM_H 1
83930 +
83931 +struct xt_gradm_mtinfo {
83932 + __u16 flags;
83933 + __u16 invflags;
83934 +};
83935 +
83936 +#endif
83937 diff --git a/include/linux/nls.h b/include/linux/nls.h
83938 index 520681b..2b7fabb 100644
83939 --- a/include/linux/nls.h
83940 +++ b/include/linux/nls.h
83941 @@ -31,7 +31,7 @@ struct nls_table {
83942 const unsigned char *charset2upper;
83943 struct module *owner;
83944 struct nls_table *next;
83945 -};
83946 +} __do_const;
83947
83948 /* this value hold the maximum octet of charset */
83949 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83950 @@ -46,7 +46,7 @@ enum utf16_endian {
83951 /* nls_base.c */
83952 extern int __register_nls(struct nls_table *, struct module *);
83953 extern int unregister_nls(struct nls_table *);
83954 -extern struct nls_table *load_nls(char *);
83955 +extern struct nls_table *load_nls(const char *);
83956 extern void unload_nls(struct nls_table *);
83957 extern struct nls_table *load_nls_default(void);
83958 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83959 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83960 index d14a4c3..a078786 100644
83961 --- a/include/linux/notifier.h
83962 +++ b/include/linux/notifier.h
83963 @@ -54,7 +54,8 @@ struct notifier_block {
83964 notifier_fn_t notifier_call;
83965 struct notifier_block __rcu *next;
83966 int priority;
83967 -};
83968 +} __do_const;
83969 +typedef struct notifier_block __no_const notifier_block_no_const;
83970
83971 struct atomic_notifier_head {
83972 spinlock_t lock;
83973 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83974 index b2a0f15..4d7da32 100644
83975 --- a/include/linux/oprofile.h
83976 +++ b/include/linux/oprofile.h
83977 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83978 int oprofilefs_create_ro_ulong(struct dentry * root,
83979 char const * name, ulong * val);
83980
83981 -/** Create a file for read-only access to an atomic_t. */
83982 +/** Create a file for read-only access to an atomic_unchecked_t. */
83983 int oprofilefs_create_ro_atomic(struct dentry * root,
83984 - char const * name, atomic_t * val);
83985 + char const * name, atomic_unchecked_t * val);
83986
83987 /** create a directory */
83988 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83989 diff --git a/include/linux/padata.h b/include/linux/padata.h
83990 index 4386946..f50c615 100644
83991 --- a/include/linux/padata.h
83992 +++ b/include/linux/padata.h
83993 @@ -129,7 +129,7 @@ struct parallel_data {
83994 struct padata_serial_queue __percpu *squeue;
83995 atomic_t reorder_objects;
83996 atomic_t refcnt;
83997 - atomic_t seq_nr;
83998 + atomic_unchecked_t seq_nr;
83999 struct padata_cpumask cpumask;
84000 spinlock_t lock ____cacheline_aligned;
84001 unsigned int processed;
84002 diff --git a/include/linux/path.h b/include/linux/path.h
84003 index d137218..be0c176 100644
84004 --- a/include/linux/path.h
84005 +++ b/include/linux/path.h
84006 @@ -1,13 +1,15 @@
84007 #ifndef _LINUX_PATH_H
84008 #define _LINUX_PATH_H
84009
84010 +#include <linux/compiler.h>
84011 +
84012 struct dentry;
84013 struct vfsmount;
84014
84015 struct path {
84016 struct vfsmount *mnt;
84017 struct dentry *dentry;
84018 -};
84019 +} __randomize_layout;
84020
84021 extern void path_get(const struct path *);
84022 extern void path_put(const struct path *);
84023 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84024 index 2706ee9..e691f7c 100644
84025 --- a/include/linux/pci_hotplug.h
84026 +++ b/include/linux/pci_hotplug.h
84027 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84028 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84029 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84030 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84031 -};
84032 +} __do_const;
84033 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84034
84035 /**
84036 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84037 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84038 index 893a0d0..d5f996e 100644
84039 --- a/include/linux/perf_event.h
84040 +++ b/include/linux/perf_event.h
84041 @@ -341,8 +341,8 @@ struct perf_event {
84042
84043 enum perf_event_active_state state;
84044 unsigned int attach_state;
84045 - local64_t count;
84046 - atomic64_t child_count;
84047 + local64_t count; /* PaX: fix it one day */
84048 + atomic64_unchecked_t child_count;
84049
84050 /*
84051 * These are the total time in nanoseconds that the event
84052 @@ -393,8 +393,8 @@ struct perf_event {
84053 * These accumulate total time (in nanoseconds) that children
84054 * events have been enabled and running, respectively.
84055 */
84056 - atomic64_t child_total_time_enabled;
84057 - atomic64_t child_total_time_running;
84058 + atomic64_unchecked_t child_total_time_enabled;
84059 + atomic64_unchecked_t child_total_time_running;
84060
84061 /*
84062 * Protect attach/detach and child_list:
84063 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84064 entry->ip[entry->nr++] = ip;
84065 }
84066
84067 -extern int sysctl_perf_event_paranoid;
84068 +extern int sysctl_perf_event_legitimately_concerned;
84069 extern int sysctl_perf_event_mlock;
84070 extern int sysctl_perf_event_sample_rate;
84071 extern int sysctl_perf_cpu_time_max_percent;
84072 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84073 loff_t *ppos);
84074
84075
84076 +static inline bool perf_paranoid_any(void)
84077 +{
84078 + return sysctl_perf_event_legitimately_concerned > 2;
84079 +}
84080 +
84081 static inline bool perf_paranoid_tracepoint_raw(void)
84082 {
84083 - return sysctl_perf_event_paranoid > -1;
84084 + return sysctl_perf_event_legitimately_concerned > -1;
84085 }
84086
84087 static inline bool perf_paranoid_cpu(void)
84088 {
84089 - return sysctl_perf_event_paranoid > 0;
84090 + return sysctl_perf_event_legitimately_concerned > 0;
84091 }
84092
84093 static inline bool perf_paranoid_kernel(void)
84094 {
84095 - return sysctl_perf_event_paranoid > 1;
84096 + return sysctl_perf_event_legitimately_concerned > 1;
84097 }
84098
84099 extern void perf_event_init(void);
84100 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84101 struct device_attribute attr;
84102 u64 id;
84103 const char *event_str;
84104 -};
84105 +} __do_const;
84106
84107 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84108 static struct perf_pmu_events_attr _var = { \
84109 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84110 index 1997ffc..4f1f44d 100644
84111 --- a/include/linux/pid_namespace.h
84112 +++ b/include/linux/pid_namespace.h
84113 @@ -44,7 +44,7 @@ struct pid_namespace {
84114 int hide_pid;
84115 int reboot; /* group exit code if this pidns was rebooted */
84116 unsigned int proc_inum;
84117 -};
84118 +} __randomize_layout;
84119
84120 extern struct pid_namespace init_pid_ns;
84121
84122 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84123 index eb8b8ac..62649e1 100644
84124 --- a/include/linux/pipe_fs_i.h
84125 +++ b/include/linux/pipe_fs_i.h
84126 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84127 struct mutex mutex;
84128 wait_queue_head_t wait;
84129 unsigned int nrbufs, curbuf, buffers;
84130 - unsigned int readers;
84131 - unsigned int writers;
84132 - unsigned int files;
84133 - unsigned int waiting_writers;
84134 + atomic_t readers;
84135 + atomic_t writers;
84136 + atomic_t files;
84137 + atomic_t waiting_writers;
84138 unsigned int r_counter;
84139 unsigned int w_counter;
84140 struct page *tmp_page;
84141 diff --git a/include/linux/pm.h b/include/linux/pm.h
84142 index 383fd68..7a11504 100644
84143 --- a/include/linux/pm.h
84144 +++ b/include/linux/pm.h
84145 @@ -621,6 +621,7 @@ struct dev_pm_domain {
84146 struct dev_pm_ops ops;
84147 void (*detach)(struct device *dev, bool power_off);
84148 };
84149 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84150
84151 /*
84152 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84153 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84154 index 2e0e06d..824cc9b 100644
84155 --- a/include/linux/pm_domain.h
84156 +++ b/include/linux/pm_domain.h
84157 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
84158 int (*save_state)(struct device *dev);
84159 int (*restore_state)(struct device *dev);
84160 bool (*active_wakeup)(struct device *dev);
84161 -};
84162 +} __no_const;
84163
84164 struct gpd_cpuidle_data {
84165 unsigned int saved_exit_latency;
84166 - struct cpuidle_state *idle_state;
84167 + cpuidle_state_no_const *idle_state;
84168 };
84169
84170 struct generic_pm_domain {
84171 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84172 index 367f49b..d2f5a14 100644
84173 --- a/include/linux/pm_runtime.h
84174 +++ b/include/linux/pm_runtime.h
84175 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84176
84177 static inline void pm_runtime_mark_last_busy(struct device *dev)
84178 {
84179 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84180 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84181 }
84182
84183 #else /* !CONFIG_PM_RUNTIME */
84184 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84185 index 195aafc..49a7bc2 100644
84186 --- a/include/linux/pnp.h
84187 +++ b/include/linux/pnp.h
84188 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84189 struct pnp_fixup {
84190 char id[7];
84191 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84192 -};
84193 +} __do_const;
84194
84195 /* config parameters */
84196 #define PNP_CONFIG_NORMAL 0x0001
84197 diff --git a/include/linux/poison.h b/include/linux/poison.h
84198 index 2110a81..13a11bb 100644
84199 --- a/include/linux/poison.h
84200 +++ b/include/linux/poison.h
84201 @@ -19,8 +19,8 @@
84202 * under normal circumstances, used to verify that nobody uses
84203 * non-initialized list entries.
84204 */
84205 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84206 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84207 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84208 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84209
84210 /********** include/linux/timer.h **********/
84211 /*
84212 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84213 index d8b187c3..9a9257a 100644
84214 --- a/include/linux/power/smartreflex.h
84215 +++ b/include/linux/power/smartreflex.h
84216 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84217 int (*notify)(struct omap_sr *sr, u32 status);
84218 u8 notify_flags;
84219 u8 class_type;
84220 -};
84221 +} __do_const;
84222
84223 /**
84224 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84225 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84226 index 4ea1d37..80f4b33 100644
84227 --- a/include/linux/ppp-comp.h
84228 +++ b/include/linux/ppp-comp.h
84229 @@ -84,7 +84,7 @@ struct compressor {
84230 struct module *owner;
84231 /* Extra skb space needed by the compressor algorithm */
84232 unsigned int comp_extra;
84233 -};
84234 +} __do_const;
84235
84236 /*
84237 * The return value from decompress routine is the length of the
84238 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84239 index de83b4e..c4b997d 100644
84240 --- a/include/linux/preempt.h
84241 +++ b/include/linux/preempt.h
84242 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84243 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84244 #endif
84245
84246 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84247 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84248 +
84249 #define __preempt_count_inc() __preempt_count_add(1)
84250 #define __preempt_count_dec() __preempt_count_sub(1)
84251
84252 #define preempt_count_inc() preempt_count_add(1)
84253 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84254 #define preempt_count_dec() preempt_count_sub(1)
84255 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84256
84257 #ifdef CONFIG_PREEMPT_COUNT
84258
84259 @@ -41,6 +46,12 @@ do { \
84260 barrier(); \
84261 } while (0)
84262
84263 +#define raw_preempt_disable() \
84264 +do { \
84265 + raw_preempt_count_inc(); \
84266 + barrier(); \
84267 +} while (0)
84268 +
84269 #define sched_preempt_enable_no_resched() \
84270 do { \
84271 barrier(); \
84272 @@ -49,6 +60,12 @@ do { \
84273
84274 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84275
84276 +#define raw_preempt_enable_no_resched() \
84277 +do { \
84278 + barrier(); \
84279 + raw_preempt_count_dec(); \
84280 +} while (0)
84281 +
84282 #ifdef CONFIG_PREEMPT
84283 #define preempt_enable() \
84284 do { \
84285 @@ -113,8 +130,10 @@ do { \
84286 * region.
84287 */
84288 #define preempt_disable() barrier()
84289 +#define raw_preempt_disable() barrier()
84290 #define sched_preempt_enable_no_resched() barrier()
84291 #define preempt_enable_no_resched() barrier()
84292 +#define raw_preempt_enable_no_resched() barrier()
84293 #define preempt_enable() barrier()
84294 #define preempt_check_resched() do { } while (0)
84295
84296 @@ -128,11 +147,13 @@ do { \
84297 /*
84298 * Modules have no business playing preemption tricks.
84299 */
84300 +#ifndef CONFIG_PAX_KERNEXEC
84301 #undef sched_preempt_enable_no_resched
84302 #undef preempt_enable_no_resched
84303 #undef preempt_enable_no_resched_notrace
84304 #undef preempt_check_resched
84305 #endif
84306 +#endif
84307
84308 #define preempt_set_need_resched() \
84309 do { \
84310 diff --git a/include/linux/printk.h b/include/linux/printk.h
84311 index d78125f..7f36596 100644
84312 --- a/include/linux/printk.h
84313 +++ b/include/linux/printk.h
84314 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84315 void early_printk(const char *s, ...) { }
84316 #endif
84317
84318 +extern int kptr_restrict;
84319 +
84320 #ifdef CONFIG_PRINTK
84321 asmlinkage __printf(5, 0)
84322 int vprintk_emit(int facility, int level,
84323 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84324
84325 extern int printk_delay_msec;
84326 extern int dmesg_restrict;
84327 -extern int kptr_restrict;
84328
84329 extern void wake_up_klogd(void);
84330
84331 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84332 index b97bf2e..f14c92d4 100644
84333 --- a/include/linux/proc_fs.h
84334 +++ b/include/linux/proc_fs.h
84335 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84336 extern struct proc_dir_entry *proc_symlink(const char *,
84337 struct proc_dir_entry *, const char *);
84338 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84339 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84340 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84341 struct proc_dir_entry *, void *);
84342 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84343 + struct proc_dir_entry *, void *);
84344 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84345 struct proc_dir_entry *);
84346
84347 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84348 return proc_create_data(name, mode, parent, proc_fops, NULL);
84349 }
84350
84351 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84352 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84353 +{
84354 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84355 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84356 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84357 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84358 +#else
84359 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84360 +#endif
84361 +}
84362 +
84363 +
84364 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84365 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84366 extern void *PDE_DATA(const struct inode *);
84367 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84368 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84369 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84370 struct proc_dir_entry *parent) {return NULL;}
84371 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84372 + struct proc_dir_entry *parent) { return NULL; }
84373 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84374 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84375 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84376 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84377 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84378 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84379 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84380 @@ -79,7 +99,7 @@ struct net;
84381 static inline struct proc_dir_entry *proc_net_mkdir(
84382 struct net *net, const char *name, struct proc_dir_entry *parent)
84383 {
84384 - return proc_mkdir_data(name, 0, parent, net);
84385 + return proc_mkdir_data_restrict(name, 0, parent, net);
84386 }
84387
84388 #endif /* _LINUX_PROC_FS_H */
84389 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84390 index 34a1e10..70f6bde 100644
84391 --- a/include/linux/proc_ns.h
84392 +++ b/include/linux/proc_ns.h
84393 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84394 void (*put)(void *ns);
84395 int (*install)(struct nsproxy *nsproxy, void *ns);
84396 unsigned int (*inum)(void *ns);
84397 -};
84398 +} __do_const __randomize_layout;
84399
84400 struct proc_ns {
84401 void *ns;
84402 diff --git a/include/linux/quota.h b/include/linux/quota.h
84403 index 80d345a..9e89a9a 100644
84404 --- a/include/linux/quota.h
84405 +++ b/include/linux/quota.h
84406 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84407
84408 extern bool qid_eq(struct kqid left, struct kqid right);
84409 extern bool qid_lt(struct kqid left, struct kqid right);
84410 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84411 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84412 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84413 extern bool qid_valid(struct kqid qid);
84414
84415 diff --git a/include/linux/random.h b/include/linux/random.h
84416 index b05856e..0a9f14e 100644
84417 --- a/include/linux/random.h
84418 +++ b/include/linux/random.h
84419 @@ -9,9 +9,19 @@
84420 #include <uapi/linux/random.h>
84421
84422 extern void add_device_randomness(const void *, unsigned int);
84423 +
84424 +static inline void add_latent_entropy(void)
84425 +{
84426 +
84427 +#ifdef LATENT_ENTROPY_PLUGIN
84428 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84429 +#endif
84430 +
84431 +}
84432 +
84433 extern void add_input_randomness(unsigned int type, unsigned int code,
84434 - unsigned int value);
84435 -extern void add_interrupt_randomness(int irq, int irq_flags);
84436 + unsigned int value) __latent_entropy;
84437 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84438
84439 extern void get_random_bytes(void *buf, int nbytes);
84440 extern void get_random_bytes_arch(void *buf, int nbytes);
84441 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84442 extern const struct file_operations random_fops, urandom_fops;
84443 #endif
84444
84445 -unsigned int get_random_int(void);
84446 +unsigned int __intentional_overflow(-1) get_random_int(void);
84447 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84448
84449 -u32 prandom_u32(void);
84450 +u32 prandom_u32(void) __intentional_overflow(-1);
84451 void prandom_bytes(void *buf, size_t nbytes);
84452 void prandom_seed(u32 seed);
84453 void prandom_reseed_late(void);
84454 @@ -37,6 +47,11 @@ struct rnd_state {
84455 u32 prandom_u32_state(struct rnd_state *state);
84456 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84457
84458 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84459 +{
84460 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84461 +}
84462 +
84463 /**
84464 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84465 * @ep_ro: right open interval endpoint
84466 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84467 *
84468 * Returns: pseudo-random number in interval [0, ep_ro)
84469 */
84470 -static inline u32 prandom_u32_max(u32 ep_ro)
84471 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84472 {
84473 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84474 }
84475 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84476 index 378c5ee..aa84a47 100644
84477 --- a/include/linux/rbtree_augmented.h
84478 +++ b/include/linux/rbtree_augmented.h
84479 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84480 old->rbaugmented = rbcompute(old); \
84481 } \
84482 rbstatic const struct rb_augment_callbacks rbname = { \
84483 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84484 + .propagate = rbname ## _propagate, \
84485 + .copy = rbname ## _copy, \
84486 + .rotate = rbname ## _rotate \
84487 };
84488
84489
84490 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84491 index 372ad5e..d4373f8 100644
84492 --- a/include/linux/rculist.h
84493 +++ b/include/linux/rculist.h
84494 @@ -29,8 +29,8 @@
84495 */
84496 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84497 {
84498 - ACCESS_ONCE(list->next) = list;
84499 - ACCESS_ONCE(list->prev) = list;
84500 + ACCESS_ONCE_RW(list->next) = list;
84501 + ACCESS_ONCE_RW(list->prev) = list;
84502 }
84503
84504 /*
84505 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84506 struct list_head *prev, struct list_head *next);
84507 #endif
84508
84509 +void __pax_list_add_rcu(struct list_head *new,
84510 + struct list_head *prev, struct list_head *next);
84511 +
84512 /**
84513 * list_add_rcu - add a new entry to rcu-protected list
84514 * @new: new entry to be added
84515 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84516 __list_add_rcu(new, head, head->next);
84517 }
84518
84519 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84520 +{
84521 + __pax_list_add_rcu(new, head, head->next);
84522 +}
84523 +
84524 /**
84525 * list_add_tail_rcu - add a new entry to rcu-protected list
84526 * @new: new entry to be added
84527 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84528 __list_add_rcu(new, head->prev, head);
84529 }
84530
84531 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84532 + struct list_head *head)
84533 +{
84534 + __pax_list_add_rcu(new, head->prev, head);
84535 +}
84536 +
84537 /**
84538 * list_del_rcu - deletes entry from list without re-initialization
84539 * @entry: the element to delete from the list.
84540 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84541 entry->prev = LIST_POISON2;
84542 }
84543
84544 +extern void pax_list_del_rcu(struct list_head *entry);
84545 +
84546 /**
84547 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84548 * @n: the element to delete from the hash list.
84549 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84550 index 53ff1a7..c40f0ab 100644
84551 --- a/include/linux/rcupdate.h
84552 +++ b/include/linux/rcupdate.h
84553 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84554 #define rcu_note_voluntary_context_switch(t) \
84555 do { \
84556 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84557 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84558 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84559 } while (0)
84560 #else /* #ifdef CONFIG_TASKS_RCU */
84561 #define TASKS_RCU(x) do { } while (0)
84562 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84563 index 67fc8fc..a90f7d8 100644
84564 --- a/include/linux/reboot.h
84565 +++ b/include/linux/reboot.h
84566 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84567 */
84568
84569 extern void migrate_to_reboot_cpu(void);
84570 -extern void machine_restart(char *cmd);
84571 -extern void machine_halt(void);
84572 -extern void machine_power_off(void);
84573 +extern void machine_restart(char *cmd) __noreturn;
84574 +extern void machine_halt(void) __noreturn;
84575 +extern void machine_power_off(void) __noreturn;
84576
84577 extern void machine_shutdown(void);
84578 struct pt_regs;
84579 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84580 */
84581
84582 extern void kernel_restart_prepare(char *cmd);
84583 -extern void kernel_restart(char *cmd);
84584 -extern void kernel_halt(void);
84585 -extern void kernel_power_off(void);
84586 +extern void kernel_restart(char *cmd) __noreturn;
84587 +extern void kernel_halt(void) __noreturn;
84588 +extern void kernel_power_off(void) __noreturn;
84589
84590 extern int C_A_D; /* for sysctl */
84591 void ctrl_alt_del(void);
84592 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84593 * Emergency restart, callable from an interrupt handler.
84594 */
84595
84596 -extern void emergency_restart(void);
84597 +extern void emergency_restart(void) __noreturn;
84598 #include <asm/emergency-restart.h>
84599
84600 #endif /* _LINUX_REBOOT_H */
84601 diff --git a/include/linux/regset.h b/include/linux/regset.h
84602 index 8e0c9fe..ac4d221 100644
84603 --- a/include/linux/regset.h
84604 +++ b/include/linux/regset.h
84605 @@ -161,7 +161,8 @@ struct user_regset {
84606 unsigned int align;
84607 unsigned int bias;
84608 unsigned int core_note_type;
84609 -};
84610 +} __do_const;
84611 +typedef struct user_regset __no_const user_regset_no_const;
84612
84613 /**
84614 * struct user_regset_view - available regsets
84615 diff --git a/include/linux/relay.h b/include/linux/relay.h
84616 index d7c8359..818daf5 100644
84617 --- a/include/linux/relay.h
84618 +++ b/include/linux/relay.h
84619 @@ -157,7 +157,7 @@ struct rchan_callbacks
84620 * The callback should return 0 if successful, negative if not.
84621 */
84622 int (*remove_buf_file)(struct dentry *dentry);
84623 -};
84624 +} __no_const;
84625
84626 /*
84627 * CONFIG_RELAY kernel API, kernel/relay.c
84628 diff --git a/include/linux/rio.h b/include/linux/rio.h
84629 index 6bda06f..bf39a9b 100644
84630 --- a/include/linux/rio.h
84631 +++ b/include/linux/rio.h
84632 @@ -358,7 +358,7 @@ struct rio_ops {
84633 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84634 u64 rstart, u32 size, u32 flags);
84635 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84636 -};
84637 +} __no_const;
84638
84639 #define RIO_RESOURCE_MEM 0x00000100
84640 #define RIO_RESOURCE_DOORBELL 0x00000200
84641 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84642 index c0c2bce..4813524 100644
84643 --- a/include/linux/rmap.h
84644 +++ b/include/linux/rmap.h
84645 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84646 void anon_vma_init(void); /* create anon_vma_cachep */
84647 int anon_vma_prepare(struct vm_area_struct *);
84648 void unlink_anon_vmas(struct vm_area_struct *);
84649 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84650 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84651 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84652 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84653
84654 static inline void anon_vma_merge(struct vm_area_struct *vma,
84655 struct vm_area_struct *next)
84656 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84657 index ed8f9e7..999bc96 100644
84658 --- a/include/linux/scatterlist.h
84659 +++ b/include/linux/scatterlist.h
84660 @@ -1,6 +1,7 @@
84661 #ifndef _LINUX_SCATTERLIST_H
84662 #define _LINUX_SCATTERLIST_H
84663
84664 +#include <linux/sched.h>
84665 #include <linux/string.h>
84666 #include <linux/bug.h>
84667 #include <linux/mm.h>
84668 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84669 #ifdef CONFIG_DEBUG_SG
84670 BUG_ON(!virt_addr_valid(buf));
84671 #endif
84672 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84673 + if (object_starts_on_stack(buf)) {
84674 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84675 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84676 + } else
84677 +#endif
84678 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84679 }
84680
84681 diff --git a/include/linux/sched.h b/include/linux/sched.h
84682 index 5e344bb..0743255 100644
84683 --- a/include/linux/sched.h
84684 +++ b/include/linux/sched.h
84685 @@ -133,6 +133,7 @@ struct fs_struct;
84686 struct perf_event_context;
84687 struct blk_plug;
84688 struct filename;
84689 +struct linux_binprm;
84690
84691 #define VMACACHE_BITS 2
84692 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84693 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84694 extern int in_sched_functions(unsigned long addr);
84695
84696 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84697 -extern signed long schedule_timeout(signed long timeout);
84698 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84699 extern signed long schedule_timeout_interruptible(signed long timeout);
84700 extern signed long schedule_timeout_killable(signed long timeout);
84701 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84702 @@ -387,6 +388,19 @@ struct nsproxy;
84703 struct user_namespace;
84704
84705 #ifdef CONFIG_MMU
84706 +
84707 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84708 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84709 +#else
84710 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84711 +{
84712 + return 0;
84713 +}
84714 +#endif
84715 +
84716 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84717 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84718 +
84719 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84720 extern unsigned long
84721 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84722 @@ -685,6 +699,17 @@ struct signal_struct {
84723 #ifdef CONFIG_TASKSTATS
84724 struct taskstats *stats;
84725 #endif
84726 +
84727 +#ifdef CONFIG_GRKERNSEC
84728 + u32 curr_ip;
84729 + u32 saved_ip;
84730 + u32 gr_saddr;
84731 + u32 gr_daddr;
84732 + u16 gr_sport;
84733 + u16 gr_dport;
84734 + u8 used_accept:1;
84735 +#endif
84736 +
84737 #ifdef CONFIG_AUDIT
84738 unsigned audit_tty;
84739 unsigned audit_tty_log_passwd;
84740 @@ -711,7 +736,7 @@ struct signal_struct {
84741 struct mutex cred_guard_mutex; /* guard against foreign influences on
84742 * credential calculations
84743 * (notably. ptrace) */
84744 -};
84745 +} __randomize_layout;
84746
84747 /*
84748 * Bits in flags field of signal_struct.
84749 @@ -764,6 +789,14 @@ struct user_struct {
84750 struct key *session_keyring; /* UID's default session keyring */
84751 #endif
84752
84753 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84754 + unsigned char kernel_banned;
84755 +#endif
84756 +#ifdef CONFIG_GRKERNSEC_BRUTE
84757 + unsigned char suid_banned;
84758 + unsigned long suid_ban_expires;
84759 +#endif
84760 +
84761 /* Hash table maintenance information */
84762 struct hlist_node uidhash_node;
84763 kuid_t uid;
84764 @@ -771,7 +804,7 @@ struct user_struct {
84765 #ifdef CONFIG_PERF_EVENTS
84766 atomic_long_t locked_vm;
84767 #endif
84768 -};
84769 +} __randomize_layout;
84770
84771 extern int uids_sysfs_init(void);
84772
84773 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84774 struct task_struct {
84775 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84776 void *stack;
84777 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84778 + void *lowmem_stack;
84779 +#endif
84780 atomic_t usage;
84781 unsigned int flags; /* per process flags, defined below */
84782 unsigned int ptrace;
84783 @@ -1362,8 +1398,8 @@ struct task_struct {
84784 struct list_head thread_node;
84785
84786 struct completion *vfork_done; /* for vfork() */
84787 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84788 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84789 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84790 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84791
84792 cputime_t utime, stime, utimescaled, stimescaled;
84793 cputime_t gtime;
84794 @@ -1388,11 +1424,6 @@ struct task_struct {
84795 struct task_cputime cputime_expires;
84796 struct list_head cpu_timers[3];
84797
84798 -/* process credentials */
84799 - const struct cred __rcu *real_cred; /* objective and real subjective task
84800 - * credentials (COW) */
84801 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84802 - * credentials (COW) */
84803 char comm[TASK_COMM_LEN]; /* executable name excluding path
84804 - access with [gs]et_task_comm (which lock
84805 it with task_lock())
84806 @@ -1410,6 +1441,10 @@ struct task_struct {
84807 #endif
84808 /* CPU-specific state of this task */
84809 struct thread_struct thread;
84810 +/* thread_info moved to task_struct */
84811 +#ifdef CONFIG_X86
84812 + struct thread_info tinfo;
84813 +#endif
84814 /* filesystem information */
84815 struct fs_struct *fs;
84816 /* open file information */
84817 @@ -1484,6 +1519,10 @@ struct task_struct {
84818 gfp_t lockdep_reclaim_gfp;
84819 #endif
84820
84821 +/* process credentials */
84822 + const struct cred __rcu *real_cred; /* objective and real subjective task
84823 + * credentials (COW) */
84824 +
84825 /* journalling filesystem info */
84826 void *journal_info;
84827
84828 @@ -1522,6 +1561,10 @@ struct task_struct {
84829 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84830 struct list_head cg_list;
84831 #endif
84832 +
84833 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84834 + * credentials (COW) */
84835 +
84836 #ifdef CONFIG_FUTEX
84837 struct robust_list_head __user *robust_list;
84838 #ifdef CONFIG_COMPAT
84839 @@ -1635,7 +1678,7 @@ struct task_struct {
84840 * Number of functions that haven't been traced
84841 * because of depth overrun.
84842 */
84843 - atomic_t trace_overrun;
84844 + atomic_unchecked_t trace_overrun;
84845 /* Pause for the tracing */
84846 atomic_t tracing_graph_pause;
84847 #endif
84848 @@ -1661,7 +1704,78 @@ struct task_struct {
84849 unsigned int sequential_io;
84850 unsigned int sequential_io_avg;
84851 #endif
84852 -};
84853 +
84854 +#ifdef CONFIG_GRKERNSEC
84855 + /* grsecurity */
84856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84857 + u64 exec_id;
84858 +#endif
84859 +#ifdef CONFIG_GRKERNSEC_SETXID
84860 + const struct cred *delayed_cred;
84861 +#endif
84862 + struct dentry *gr_chroot_dentry;
84863 + struct acl_subject_label *acl;
84864 + struct acl_subject_label *tmpacl;
84865 + struct acl_role_label *role;
84866 + struct file *exec_file;
84867 + unsigned long brute_expires;
84868 + u16 acl_role_id;
84869 + u8 inherited;
84870 + /* is this the task that authenticated to the special role */
84871 + u8 acl_sp_role;
84872 + u8 is_writable;
84873 + u8 brute;
84874 + u8 gr_is_chrooted;
84875 +#endif
84876 +
84877 +} __randomize_layout;
84878 +
84879 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84880 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84881 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84882 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84883 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84884 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84885 +
84886 +#ifdef CONFIG_PAX_SOFTMODE
84887 +extern int pax_softmode;
84888 +#endif
84889 +
84890 +extern int pax_check_flags(unsigned long *);
84891 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84892 +
84893 +/* if tsk != current then task_lock must be held on it */
84894 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84895 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
84896 +{
84897 + if (likely(tsk->mm))
84898 + return tsk->mm->pax_flags;
84899 + else
84900 + return 0UL;
84901 +}
84902 +
84903 +/* if tsk != current then task_lock must be held on it */
84904 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84905 +{
84906 + if (likely(tsk->mm)) {
84907 + tsk->mm->pax_flags = flags;
84908 + return 0;
84909 + }
84910 + return -EINVAL;
84911 +}
84912 +#endif
84913 +
84914 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84915 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
84916 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84917 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84918 +#endif
84919 +
84920 +struct path;
84921 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84922 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84923 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84924 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
84925
84926 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84927 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84928 @@ -1743,7 +1857,7 @@ struct pid_namespace;
84929 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84930 struct pid_namespace *ns);
84931
84932 -static inline pid_t task_pid_nr(struct task_struct *tsk)
84933 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
84934 {
84935 return tsk->pid;
84936 }
84937 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
84938
84939 extern void sched_clock_init(void);
84940
84941 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84942 +static inline void populate_stack(void)
84943 +{
84944 + struct task_struct *curtask = current;
84945 + int c;
84946 + int *ptr = curtask->stack;
84947 + int *end = curtask->stack + THREAD_SIZE;
84948 +
84949 + while (ptr < end) {
84950 + c = *(volatile int *)ptr;
84951 + ptr += PAGE_SIZE/sizeof(int);
84952 + }
84953 +}
84954 +#else
84955 +static inline void populate_stack(void)
84956 +{
84957 +}
84958 +#endif
84959 +
84960 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84961 static inline void sched_clock_tick(void)
84962 {
84963 @@ -2239,7 +2372,9 @@ void yield(void);
84964 extern struct exec_domain default_exec_domain;
84965
84966 union thread_union {
84967 +#ifndef CONFIG_X86
84968 struct thread_info thread_info;
84969 +#endif
84970 unsigned long stack[THREAD_SIZE/sizeof(long)];
84971 };
84972
84973 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
84974 */
84975
84976 extern struct task_struct *find_task_by_vpid(pid_t nr);
84977 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84978 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84979 struct pid_namespace *ns);
84980
84981 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84982 extern void exit_itimers(struct signal_struct *);
84983 extern void flush_itimer_signals(void);
84984
84985 -extern void do_group_exit(int);
84986 +extern __noreturn void do_group_exit(int);
84987
84988 extern int do_execve(struct filename *,
84989 const char __user * const __user *,
84990 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84991 #define task_stack_end_corrupted(task) \
84992 (*(end_of_stack(task)) != STACK_END_MAGIC)
84993
84994 -static inline int object_is_on_stack(void *obj)
84995 +static inline int object_starts_on_stack(const void *obj)
84996 {
84997 - void *stack = task_stack_page(current);
84998 + const void *stack = task_stack_page(current);
84999
85000 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85001 }
85002 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85003 index 596a0e0..bea77ec 100644
85004 --- a/include/linux/sched/sysctl.h
85005 +++ b/include/linux/sched/sysctl.h
85006 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85007 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85008
85009 extern int sysctl_max_map_count;
85010 +extern unsigned long sysctl_heap_stack_gap;
85011
85012 extern unsigned int sysctl_sched_latency;
85013 extern unsigned int sysctl_sched_min_granularity;
85014 diff --git a/include/linux/security.h b/include/linux/security.h
85015 index ba96471..74fb3f6 100644
85016 --- a/include/linux/security.h
85017 +++ b/include/linux/security.h
85018 @@ -27,6 +27,7 @@
85019 #include <linux/slab.h>
85020 #include <linux/err.h>
85021 #include <linux/string.h>
85022 +#include <linux/grsecurity.h>
85023
85024 struct linux_binprm;
85025 struct cred;
85026 @@ -116,8 +117,6 @@ struct seq_file;
85027
85028 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85029
85030 -void reset_security_ops(void);
85031 -
85032 #ifdef CONFIG_MMU
85033 extern unsigned long mmap_min_addr;
85034 extern unsigned long dac_mmap_min_addr;
85035 @@ -1729,7 +1728,7 @@ struct security_operations {
85036 struct audit_context *actx);
85037 void (*audit_rule_free) (void *lsmrule);
85038 #endif /* CONFIG_AUDIT */
85039 -};
85040 +} __randomize_layout;
85041
85042 /* prototypes */
85043 extern int security_init(void);
85044 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85045 index dc368b8..e895209 100644
85046 --- a/include/linux/semaphore.h
85047 +++ b/include/linux/semaphore.h
85048 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85049 }
85050
85051 extern void down(struct semaphore *sem);
85052 -extern int __must_check down_interruptible(struct semaphore *sem);
85053 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85054 extern int __must_check down_killable(struct semaphore *sem);
85055 extern int __must_check down_trylock(struct semaphore *sem);
85056 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85057 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85058 index 52e0097..383f21d 100644
85059 --- a/include/linux/seq_file.h
85060 +++ b/include/linux/seq_file.h
85061 @@ -27,6 +27,9 @@ struct seq_file {
85062 struct mutex lock;
85063 const struct seq_operations *op;
85064 int poll_event;
85065 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85066 + u64 exec_id;
85067 +#endif
85068 #ifdef CONFIG_USER_NS
85069 struct user_namespace *user_ns;
85070 #endif
85071 @@ -39,6 +42,7 @@ struct seq_operations {
85072 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85073 int (*show) (struct seq_file *m, void *v);
85074 };
85075 +typedef struct seq_operations __no_const seq_operations_no_const;
85076
85077 #define SEQ_SKIP 1
85078
85079 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85080
85081 char *mangle_path(char *s, const char *p, const char *esc);
85082 int seq_open(struct file *, const struct seq_operations *);
85083 +int seq_open_restrict(struct file *, const struct seq_operations *);
85084 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85085 loff_t seq_lseek(struct file *, loff_t, int);
85086 int seq_release(struct inode *, struct file *);
85087 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85088 }
85089
85090 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85091 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85092 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85093 int single_release(struct inode *, struct file *);
85094 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85095 diff --git a/include/linux/shm.h b/include/linux/shm.h
85096 index 6fb8016..ab4465e 100644
85097 --- a/include/linux/shm.h
85098 +++ b/include/linux/shm.h
85099 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85100 /* The task created the shm object. NULL if the task is dead. */
85101 struct task_struct *shm_creator;
85102 struct list_head shm_clist; /* list by creator */
85103 +#ifdef CONFIG_GRKERNSEC
85104 + u64 shm_createtime;
85105 + pid_t shm_lapid;
85106 +#endif
85107 };
85108
85109 /* shm_mode upper byte flags */
85110 diff --git a/include/linux/signal.h b/include/linux/signal.h
85111 index ab1e039..ad4229e 100644
85112 --- a/include/linux/signal.h
85113 +++ b/include/linux/signal.h
85114 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85115 * know it'll be handled, so that they don't get converted to
85116 * SIGKILL or just silently dropped.
85117 */
85118 - kernel_sigaction(sig, (__force __sighandler_t)2);
85119 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85120 }
85121
85122 static inline void disallow_signal(int sig)
85123 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85124 index 6c8b6f6..5a0f4bd 100644
85125 --- a/include/linux/skbuff.h
85126 +++ b/include/linux/skbuff.h
85127 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85128 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85129 int node);
85130 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85131 -static inline struct sk_buff *alloc_skb(unsigned int size,
85132 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85133 gfp_t priority)
85134 {
85135 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85136 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85137 return skb->inner_transport_header - skb->inner_network_header;
85138 }
85139
85140 -static inline int skb_network_offset(const struct sk_buff *skb)
85141 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85142 {
85143 return skb_network_header(skb) - skb->data;
85144 }
85145 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85146 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85147 */
85148 #ifndef NET_SKB_PAD
85149 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85150 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85151 #endif
85152
85153 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85154 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85155 int *err);
85156 unsigned int datagram_poll(struct file *file, struct socket *sock,
85157 struct poll_table_struct *wait);
85158 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85159 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85160 struct iovec *to, int size);
85161 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85162 struct iovec *iov);
85163 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85164 nf_bridge_put(skb->nf_bridge);
85165 skb->nf_bridge = NULL;
85166 #endif
85167 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85168 + skb->nf_trace = 0;
85169 +#endif
85170 }
85171
85172 static inline void nf_reset_trace(struct sk_buff *skb)
85173 diff --git a/include/linux/slab.h b/include/linux/slab.h
85174 index c265bec..4867d28 100644
85175 --- a/include/linux/slab.h
85176 +++ b/include/linux/slab.h
85177 @@ -14,15 +14,29 @@
85178 #include <linux/gfp.h>
85179 #include <linux/types.h>
85180 #include <linux/workqueue.h>
85181 -
85182 +#include <linux/err.h>
85183
85184 /*
85185 * Flags to pass to kmem_cache_create().
85186 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85187 */
85188 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85189 +
85190 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85191 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85192 +#else
85193 +#define SLAB_USERCOPY 0x00000000UL
85194 +#endif
85195 +
85196 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85197 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85198 +
85199 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85200 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85201 +#else
85202 +#define SLAB_NO_SANITIZE 0x00000000UL
85203 +#endif
85204 +
85205 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85206 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85207 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85208 @@ -98,10 +112,13 @@
85209 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85210 * Both make kfree a no-op.
85211 */
85212 -#define ZERO_SIZE_PTR ((void *)16)
85213 +#define ZERO_SIZE_PTR \
85214 +({ \
85215 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85216 + (void *)(-MAX_ERRNO-1L); \
85217 +})
85218
85219 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85220 - (unsigned long)ZERO_SIZE_PTR)
85221 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85222
85223 #include <linux/kmemleak.h>
85224
85225 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85226 void kfree(const void *);
85227 void kzfree(const void *);
85228 size_t ksize(const void *);
85229 +const char *check_heap_object(const void *ptr, unsigned long n);
85230 +bool is_usercopy_object(const void *ptr);
85231
85232 /*
85233 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85234 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85235 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85236 #endif
85237
85238 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85239 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85240 +#endif
85241 +
85242 /*
85243 * Figure out which kmalloc slab an allocation of a certain size
85244 * belongs to.
85245 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85246 * 2 = 120 .. 192 bytes
85247 * n = 2^(n-1) .. 2^n -1
85248 */
85249 -static __always_inline int kmalloc_index(size_t size)
85250 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85251 {
85252 if (!size)
85253 return 0;
85254 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85255 }
85256 #endif /* !CONFIG_SLOB */
85257
85258 -void *__kmalloc(size_t size, gfp_t flags);
85259 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85260 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85261
85262 #ifdef CONFIG_NUMA
85263 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85264 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85265 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85266 #else
85267 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85268 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85269 index b869d16..1453c73 100644
85270 --- a/include/linux/slab_def.h
85271 +++ b/include/linux/slab_def.h
85272 @@ -40,7 +40,7 @@ struct kmem_cache {
85273 /* 4) cache creation/removal */
85274 const char *name;
85275 struct list_head list;
85276 - int refcount;
85277 + atomic_t refcount;
85278 int object_size;
85279 int align;
85280
85281 @@ -56,10 +56,14 @@ struct kmem_cache {
85282 unsigned long node_allocs;
85283 unsigned long node_frees;
85284 unsigned long node_overflow;
85285 - atomic_t allochit;
85286 - atomic_t allocmiss;
85287 - atomic_t freehit;
85288 - atomic_t freemiss;
85289 + atomic_unchecked_t allochit;
85290 + atomic_unchecked_t allocmiss;
85291 + atomic_unchecked_t freehit;
85292 + atomic_unchecked_t freemiss;
85293 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85294 + atomic_unchecked_t sanitized;
85295 + atomic_unchecked_t not_sanitized;
85296 +#endif
85297
85298 /*
85299 * If debugging is enabled, then the allocator can add additional
85300 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85301 index d82abd4..408c3a0 100644
85302 --- a/include/linux/slub_def.h
85303 +++ b/include/linux/slub_def.h
85304 @@ -74,7 +74,7 @@ struct kmem_cache {
85305 struct kmem_cache_order_objects max;
85306 struct kmem_cache_order_objects min;
85307 gfp_t allocflags; /* gfp flags to use on each alloc */
85308 - int refcount; /* Refcount for slab cache destroy */
85309 + atomic_t refcount; /* Refcount for slab cache destroy */
85310 void (*ctor)(void *);
85311 int inuse; /* Offset to metadata */
85312 int align; /* Alignment */
85313 diff --git a/include/linux/smp.h b/include/linux/smp.h
85314 index 93dff5f..933c561 100644
85315 --- a/include/linux/smp.h
85316 +++ b/include/linux/smp.h
85317 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85318 #endif
85319
85320 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85321 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85322 #define put_cpu() preempt_enable()
85323 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85324
85325 /*
85326 * Callback to arch code if there's nosmp or maxcpus=0 on the
85327 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85328 index 46cca4c..3323536 100644
85329 --- a/include/linux/sock_diag.h
85330 +++ b/include/linux/sock_diag.h
85331 @@ -11,7 +11,7 @@ struct sock;
85332 struct sock_diag_handler {
85333 __u8 family;
85334 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85335 -};
85336 +} __do_const;
85337
85338 int sock_diag_register(const struct sock_diag_handler *h);
85339 void sock_diag_unregister(const struct sock_diag_handler *h);
85340 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85341 index 680f9a3..f13aeb0 100644
85342 --- a/include/linux/sonet.h
85343 +++ b/include/linux/sonet.h
85344 @@ -7,7 +7,7 @@
85345 #include <uapi/linux/sonet.h>
85346
85347 struct k_sonet_stats {
85348 -#define __HANDLE_ITEM(i) atomic_t i
85349 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85350 __SONET_ITEMS
85351 #undef __HANDLE_ITEM
85352 };
85353 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85354 index 07d8e53..dc934c9 100644
85355 --- a/include/linux/sunrpc/addr.h
85356 +++ b/include/linux/sunrpc/addr.h
85357 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85358 {
85359 switch (sap->sa_family) {
85360 case AF_INET:
85361 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85362 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85363 case AF_INET6:
85364 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85365 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85366 }
85367 return 0;
85368 }
85369 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85370 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85371 const struct sockaddr *src)
85372 {
85373 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85374 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85375 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85376
85377 dsin->sin_family = ssin->sin_family;
85378 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85379 if (sa->sa_family != AF_INET6)
85380 return 0;
85381
85382 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85383 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85384 }
85385
85386 #endif /* _LINUX_SUNRPC_ADDR_H */
85387 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85388 index 70736b9..37f33db 100644
85389 --- a/include/linux/sunrpc/clnt.h
85390 +++ b/include/linux/sunrpc/clnt.h
85391 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85392 unsigned int p_timer; /* Which RTT timer to use */
85393 u32 p_statidx; /* Which procedure to account */
85394 const char * p_name; /* name of procedure */
85395 -};
85396 +} __do_const;
85397
85398 #ifdef __KERNEL__
85399
85400 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85401 index 2167846..0648fc3 100644
85402 --- a/include/linux/sunrpc/svc.h
85403 +++ b/include/linux/sunrpc/svc.h
85404 @@ -416,7 +416,7 @@ struct svc_procedure {
85405 unsigned int pc_count; /* call count */
85406 unsigned int pc_cachetype; /* cache info (NFS) */
85407 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85408 -};
85409 +} __do_const;
85410
85411 /*
85412 * Function prototypes.
85413 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85414 index 975da75..318c083 100644
85415 --- a/include/linux/sunrpc/svc_rdma.h
85416 +++ b/include/linux/sunrpc/svc_rdma.h
85417 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85418 extern unsigned int svcrdma_max_requests;
85419 extern unsigned int svcrdma_max_req_size;
85420
85421 -extern atomic_t rdma_stat_recv;
85422 -extern atomic_t rdma_stat_read;
85423 -extern atomic_t rdma_stat_write;
85424 -extern atomic_t rdma_stat_sq_starve;
85425 -extern atomic_t rdma_stat_rq_starve;
85426 -extern atomic_t rdma_stat_rq_poll;
85427 -extern atomic_t rdma_stat_rq_prod;
85428 -extern atomic_t rdma_stat_sq_poll;
85429 -extern atomic_t rdma_stat_sq_prod;
85430 +extern atomic_unchecked_t rdma_stat_recv;
85431 +extern atomic_unchecked_t rdma_stat_read;
85432 +extern atomic_unchecked_t rdma_stat_write;
85433 +extern atomic_unchecked_t rdma_stat_sq_starve;
85434 +extern atomic_unchecked_t rdma_stat_rq_starve;
85435 +extern atomic_unchecked_t rdma_stat_rq_poll;
85436 +extern atomic_unchecked_t rdma_stat_rq_prod;
85437 +extern atomic_unchecked_t rdma_stat_sq_poll;
85438 +extern atomic_unchecked_t rdma_stat_sq_prod;
85439
85440 #define RPCRDMA_VERSION 1
85441
85442 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85443 index 8d71d65..f79586e 100644
85444 --- a/include/linux/sunrpc/svcauth.h
85445 +++ b/include/linux/sunrpc/svcauth.h
85446 @@ -120,7 +120,7 @@ struct auth_ops {
85447 int (*release)(struct svc_rqst *rq);
85448 void (*domain_release)(struct auth_domain *);
85449 int (*set_client)(struct svc_rqst *rq);
85450 -};
85451 +} __do_const;
85452
85453 #define SVC_GARBAGE 1
85454 #define SVC_SYSERR 2
85455 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85456 index e7a018e..49f8b17 100644
85457 --- a/include/linux/swiotlb.h
85458 +++ b/include/linux/swiotlb.h
85459 @@ -60,7 +60,8 @@ extern void
85460
85461 extern void
85462 swiotlb_free_coherent(struct device *hwdev, size_t size,
85463 - void *vaddr, dma_addr_t dma_handle);
85464 + void *vaddr, dma_addr_t dma_handle,
85465 + struct dma_attrs *attrs);
85466
85467 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85468 unsigned long offset, size_t size,
85469 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85470 index bda9b81..629e06e 100644
85471 --- a/include/linux/syscalls.h
85472 +++ b/include/linux/syscalls.h
85473 @@ -99,10 +99,16 @@ union bpf_attr;
85474 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85475
85476 #define __SC_DECL(t, a) t a
85477 +#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))
85478 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85479 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85480 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85481 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85482 +#define __SC_LONG(t, a) __typeof( \
85483 + __builtin_choose_expr( \
85484 + sizeof(t) > sizeof(int), \
85485 + (t) 0, \
85486 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85487 + )) a
85488 #define __SC_CAST(t, a) (t) a
85489 #define __SC_ARGS(t, a) a
85490 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85491 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85492 asmlinkage long sys_fsync(unsigned int fd);
85493 asmlinkage long sys_fdatasync(unsigned int fd);
85494 asmlinkage long sys_bdflush(int func, long data);
85495 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85496 - char __user *type, unsigned long flags,
85497 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85498 + const char __user *type, unsigned long flags,
85499 void __user *data);
85500 -asmlinkage long sys_umount(char __user *name, int flags);
85501 -asmlinkage long sys_oldumount(char __user *name);
85502 +asmlinkage long sys_umount(const char __user *name, int flags);
85503 +asmlinkage long sys_oldumount(const char __user *name);
85504 asmlinkage long sys_truncate(const char __user *path, long length);
85505 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85506 asmlinkage long sys_stat(const char __user *filename,
85507 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85508 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85509 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85510 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85511 - struct sockaddr __user *, int);
85512 + struct sockaddr __user *, int) __intentional_overflow(0);
85513 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85514 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85515 unsigned int vlen, unsigned flags);
85516 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85517 index 27b3b0b..e093dd9 100644
85518 --- a/include/linux/syscore_ops.h
85519 +++ b/include/linux/syscore_ops.h
85520 @@ -16,7 +16,7 @@ struct syscore_ops {
85521 int (*suspend)(void);
85522 void (*resume)(void);
85523 void (*shutdown)(void);
85524 -};
85525 +} __do_const;
85526
85527 extern void register_syscore_ops(struct syscore_ops *ops);
85528 extern void unregister_syscore_ops(struct syscore_ops *ops);
85529 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85530 index b7361f8..341a15a 100644
85531 --- a/include/linux/sysctl.h
85532 +++ b/include/linux/sysctl.h
85533 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85534
85535 extern int proc_dostring(struct ctl_table *, int,
85536 void __user *, size_t *, loff_t *);
85537 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85538 + void __user *, size_t *, loff_t *);
85539 extern int proc_dointvec(struct ctl_table *, int,
85540 void __user *, size_t *, loff_t *);
85541 extern int proc_dointvec_minmax(struct ctl_table *, int,
85542 @@ -113,7 +115,8 @@ struct ctl_table
85543 struct ctl_table_poll *poll;
85544 void *extra1;
85545 void *extra2;
85546 -};
85547 +} __do_const __randomize_layout;
85548 +typedef struct ctl_table __no_const ctl_table_no_const;
85549
85550 struct ctl_node {
85551 struct rb_node node;
85552 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85553 index f97d0db..c1187dc 100644
85554 --- a/include/linux/sysfs.h
85555 +++ b/include/linux/sysfs.h
85556 @@ -34,7 +34,8 @@ struct attribute {
85557 struct lock_class_key *key;
85558 struct lock_class_key skey;
85559 #endif
85560 -};
85561 +} __do_const;
85562 +typedef struct attribute __no_const attribute_no_const;
85563
85564 /**
85565 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85566 @@ -63,7 +64,8 @@ struct attribute_group {
85567 struct attribute *, int);
85568 struct attribute **attrs;
85569 struct bin_attribute **bin_attrs;
85570 -};
85571 +} __do_const;
85572 +typedef struct attribute_group __no_const attribute_group_no_const;
85573
85574 /**
85575 * Use these macros to make defining attributes easier. See include/linux/device.h
85576 @@ -128,7 +130,8 @@ struct bin_attribute {
85577 char *, loff_t, size_t);
85578 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85579 struct vm_area_struct *vma);
85580 -};
85581 +} __do_const;
85582 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85583
85584 /**
85585 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85586 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85587 index 387fa7d..3fcde6b 100644
85588 --- a/include/linux/sysrq.h
85589 +++ b/include/linux/sysrq.h
85590 @@ -16,6 +16,7 @@
85591
85592 #include <linux/errno.h>
85593 #include <linux/types.h>
85594 +#include <linux/compiler.h>
85595
85596 /* Possible values of bitmask for enabling sysrq functions */
85597 /* 0x0001 is reserved for enable everything */
85598 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85599 char *help_msg;
85600 char *action_msg;
85601 int enable_mask;
85602 -};
85603 +} __do_const;
85604
85605 #ifdef CONFIG_MAGIC_SYSRQ
85606
85607 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85608 index ff307b5..f1a4468 100644
85609 --- a/include/linux/thread_info.h
85610 +++ b/include/linux/thread_info.h
85611 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85612 #error "no set_restore_sigmask() provided and default one won't work"
85613 #endif
85614
85615 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85616 +
85617 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85618 +{
85619 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85620 +}
85621 +
85622 #endif /* __KERNEL__ */
85623
85624 #endif /* _LINUX_THREAD_INFO_H */
85625 diff --git a/include/linux/tty.h b/include/linux/tty.h
85626 index 5171ef8..1048d83e 100644
85627 --- a/include/linux/tty.h
85628 +++ b/include/linux/tty.h
85629 @@ -202,7 +202,7 @@ struct tty_port {
85630 const struct tty_port_operations *ops; /* Port operations */
85631 spinlock_t lock; /* Lock protecting tty field */
85632 int blocked_open; /* Waiting to open */
85633 - int count; /* Usage count */
85634 + atomic_t count; /* Usage count */
85635 wait_queue_head_t open_wait; /* Open waiters */
85636 wait_queue_head_t close_wait; /* Close waiters */
85637 wait_queue_head_t delta_msr_wait; /* Modem status change */
85638 @@ -290,7 +290,7 @@ struct tty_struct {
85639 /* If the tty has a pending do_SAK, queue it here - akpm */
85640 struct work_struct SAK_work;
85641 struct tty_port *port;
85642 -};
85643 +} __randomize_layout;
85644
85645 /* Each of a tty's open files has private_data pointing to tty_file_private */
85646 struct tty_file_private {
85647 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85648 struct tty_struct *tty, struct file *filp);
85649 static inline int tty_port_users(struct tty_port *port)
85650 {
85651 - return port->count + port->blocked_open;
85652 + return atomic_read(&port->count) + port->blocked_open;
85653 }
85654
85655 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85656 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85657 index 92e337c..f46757b 100644
85658 --- a/include/linux/tty_driver.h
85659 +++ b/include/linux/tty_driver.h
85660 @@ -291,7 +291,7 @@ struct tty_operations {
85661 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85662 #endif
85663 const struct file_operations *proc_fops;
85664 -};
85665 +} __do_const __randomize_layout;
85666
85667 struct tty_driver {
85668 int magic; /* magic number for this structure */
85669 @@ -325,7 +325,7 @@ struct tty_driver {
85670
85671 const struct tty_operations *ops;
85672 struct list_head tty_drivers;
85673 -};
85674 +} __randomize_layout;
85675
85676 extern struct list_head tty_drivers;
85677
85678 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85679 index 00c9d68..bc0188b 100644
85680 --- a/include/linux/tty_ldisc.h
85681 +++ b/include/linux/tty_ldisc.h
85682 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85683
85684 struct module *owner;
85685
85686 - int refcount;
85687 + atomic_t refcount;
85688 };
85689
85690 struct tty_ldisc {
85691 diff --git a/include/linux/types.h b/include/linux/types.h
85692 index a0bb704..f511c77 100644
85693 --- a/include/linux/types.h
85694 +++ b/include/linux/types.h
85695 @@ -177,10 +177,26 @@ typedef struct {
85696 int counter;
85697 } atomic_t;
85698
85699 +#ifdef CONFIG_PAX_REFCOUNT
85700 +typedef struct {
85701 + int counter;
85702 +} atomic_unchecked_t;
85703 +#else
85704 +typedef atomic_t atomic_unchecked_t;
85705 +#endif
85706 +
85707 #ifdef CONFIG_64BIT
85708 typedef struct {
85709 long counter;
85710 } atomic64_t;
85711 +
85712 +#ifdef CONFIG_PAX_REFCOUNT
85713 +typedef struct {
85714 + long counter;
85715 +} atomic64_unchecked_t;
85716 +#else
85717 +typedef atomic64_t atomic64_unchecked_t;
85718 +#endif
85719 #endif
85720
85721 struct list_head {
85722 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85723 index ecd3319..8a36ded 100644
85724 --- a/include/linux/uaccess.h
85725 +++ b/include/linux/uaccess.h
85726 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85727 long ret; \
85728 mm_segment_t old_fs = get_fs(); \
85729 \
85730 - set_fs(KERNEL_DS); \
85731 pagefault_disable(); \
85732 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85733 - pagefault_enable(); \
85734 + set_fs(KERNEL_DS); \
85735 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85736 set_fs(old_fs); \
85737 + pagefault_enable(); \
85738 ret; \
85739 })
85740
85741 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85742 index 2d1f9b6..d7a9fce 100644
85743 --- a/include/linux/uidgid.h
85744 +++ b/include/linux/uidgid.h
85745 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85746
85747 #endif /* CONFIG_USER_NS */
85748
85749 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85750 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85751 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85752 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85753 +
85754 #endif /* _LINUX_UIDGID_H */
85755 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85756 index baa8171..9ca98ba 100644
85757 --- a/include/linux/uio_driver.h
85758 +++ b/include/linux/uio_driver.h
85759 @@ -67,7 +67,7 @@ struct uio_device {
85760 struct module *owner;
85761 struct device *dev;
85762 int minor;
85763 - atomic_t event;
85764 + atomic_unchecked_t event;
85765 struct fasync_struct *async_queue;
85766 wait_queue_head_t wait;
85767 struct uio_info *info;
85768 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85769 index 99c1b4d..562e6f3 100644
85770 --- a/include/linux/unaligned/access_ok.h
85771 +++ b/include/linux/unaligned/access_ok.h
85772 @@ -4,34 +4,34 @@
85773 #include <linux/kernel.h>
85774 #include <asm/byteorder.h>
85775
85776 -static inline u16 get_unaligned_le16(const void *p)
85777 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85778 {
85779 - return le16_to_cpup((__le16 *)p);
85780 + return le16_to_cpup((const __le16 *)p);
85781 }
85782
85783 -static inline u32 get_unaligned_le32(const void *p)
85784 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85785 {
85786 - return le32_to_cpup((__le32 *)p);
85787 + return le32_to_cpup((const __le32 *)p);
85788 }
85789
85790 -static inline u64 get_unaligned_le64(const void *p)
85791 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85792 {
85793 - return le64_to_cpup((__le64 *)p);
85794 + return le64_to_cpup((const __le64 *)p);
85795 }
85796
85797 -static inline u16 get_unaligned_be16(const void *p)
85798 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85799 {
85800 - return be16_to_cpup((__be16 *)p);
85801 + return be16_to_cpup((const __be16 *)p);
85802 }
85803
85804 -static inline u32 get_unaligned_be32(const void *p)
85805 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85806 {
85807 - return be32_to_cpup((__be32 *)p);
85808 + return be32_to_cpup((const __be32 *)p);
85809 }
85810
85811 -static inline u64 get_unaligned_be64(const void *p)
85812 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85813 {
85814 - return be64_to_cpup((__be64 *)p);
85815 + return be64_to_cpup((const __be64 *)p);
85816 }
85817
85818 static inline void put_unaligned_le16(u16 val, void *p)
85819 diff --git a/include/linux/usb.h b/include/linux/usb.h
85820 index 447a7e2..9cea7e9 100644
85821 --- a/include/linux/usb.h
85822 +++ b/include/linux/usb.h
85823 @@ -571,7 +571,7 @@ struct usb_device {
85824 int maxchild;
85825
85826 u32 quirks;
85827 - atomic_t urbnum;
85828 + atomic_unchecked_t urbnum;
85829
85830 unsigned long active_duration;
85831
85832 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85833
85834 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85835 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85836 - void *data, __u16 size, int timeout);
85837 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85838 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85839 void *data, int len, int *actual_length, int timeout);
85840 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85841 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85842 index d5952bb..9a626d4 100644
85843 --- a/include/linux/usb/renesas_usbhs.h
85844 +++ b/include/linux/usb/renesas_usbhs.h
85845 @@ -39,7 +39,7 @@ enum {
85846 */
85847 struct renesas_usbhs_driver_callback {
85848 int (*notify_hotplug)(struct platform_device *pdev);
85849 -};
85850 +} __no_const;
85851
85852 /*
85853 * callback functions for platform
85854 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85855 index 9f3579f..3b2afa5 100644
85856 --- a/include/linux/user_namespace.h
85857 +++ b/include/linux/user_namespace.h
85858 @@ -38,7 +38,7 @@ struct user_namespace {
85859 struct key *persistent_keyring_register;
85860 struct rw_semaphore persistent_keyring_register_sem;
85861 #endif
85862 -};
85863 +} __randomize_layout;
85864
85865 extern struct user_namespace init_user_ns;
85866
85867 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85868 index 239e277..22a5cf5 100644
85869 --- a/include/linux/utsname.h
85870 +++ b/include/linux/utsname.h
85871 @@ -24,7 +24,7 @@ struct uts_namespace {
85872 struct new_utsname name;
85873 struct user_namespace *user_ns;
85874 unsigned int proc_inum;
85875 -};
85876 +} __randomize_layout;
85877 extern struct uts_namespace init_uts_ns;
85878
85879 #ifdef CONFIG_UTS_NS
85880 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85881 index 6f8fbcf..4efc177 100644
85882 --- a/include/linux/vermagic.h
85883 +++ b/include/linux/vermagic.h
85884 @@ -25,9 +25,42 @@
85885 #define MODULE_ARCH_VERMAGIC ""
85886 #endif
85887
85888 +#ifdef CONFIG_PAX_REFCOUNT
85889 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
85890 +#else
85891 +#define MODULE_PAX_REFCOUNT ""
85892 +#endif
85893 +
85894 +#ifdef CONSTIFY_PLUGIN
85895 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85896 +#else
85897 +#define MODULE_CONSTIFY_PLUGIN ""
85898 +#endif
85899 +
85900 +#ifdef STACKLEAK_PLUGIN
85901 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85902 +#else
85903 +#define MODULE_STACKLEAK_PLUGIN ""
85904 +#endif
85905 +
85906 +#ifdef RANDSTRUCT_PLUGIN
85907 +#include <generated/randomize_layout_hash.h>
85908 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85909 +#else
85910 +#define MODULE_RANDSTRUCT_PLUGIN
85911 +#endif
85912 +
85913 +#ifdef CONFIG_GRKERNSEC
85914 +#define MODULE_GRSEC "GRSEC "
85915 +#else
85916 +#define MODULE_GRSEC ""
85917 +#endif
85918 +
85919 #define VERMAGIC_STRING \
85920 UTS_RELEASE " " \
85921 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85922 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85923 - MODULE_ARCH_VERMAGIC
85924 + MODULE_ARCH_VERMAGIC \
85925 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85926 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85927
85928 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85929 index b483abd..af305ad 100644
85930 --- a/include/linux/vga_switcheroo.h
85931 +++ b/include/linux/vga_switcheroo.h
85932 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85933
85934 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85935
85936 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85937 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85938 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85939 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85940 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85941 #else
85942
85943 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85944 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85945
85946 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85947
85948 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85949 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85950 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85951 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85952 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85953
85954 #endif
85955 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85956 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85957 index b87696f..1d11de7 100644
85958 --- a/include/linux/vmalloc.h
85959 +++ b/include/linux/vmalloc.h
85960 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85961 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85962 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85963 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85964 +
85965 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85966 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85967 +#endif
85968 +
85969 /* bits [20..32] reserved for arch specific ioremap internals */
85970
85971 /*
85972 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85973 unsigned long flags, pgprot_t prot);
85974 extern void vunmap(const void *addr);
85975
85976 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85977 +extern void unmap_process_stacks(struct task_struct *task);
85978 +#endif
85979 +
85980 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85981 unsigned long uaddr, void *kaddr,
85982 unsigned long size);
85983 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85984
85985 /* for /dev/kmem */
85986 extern long vread(char *buf, char *addr, unsigned long count);
85987 -extern long vwrite(char *buf, char *addr, unsigned long count);
85988 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85989
85990 /*
85991 * Internals. Dont't use..
85992 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85993 index 82e7db7..f8ce3d0 100644
85994 --- a/include/linux/vmstat.h
85995 +++ b/include/linux/vmstat.h
85996 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85997 /*
85998 * Zone based page accounting with per cpu differentials.
85999 */
86000 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86001 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86002
86003 static inline void zone_page_state_add(long x, struct zone *zone,
86004 enum zone_stat_item item)
86005 {
86006 - atomic_long_add(x, &zone->vm_stat[item]);
86007 - atomic_long_add(x, &vm_stat[item]);
86008 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86009 + atomic_long_add_unchecked(x, &vm_stat[item]);
86010 }
86011
86012 -static inline unsigned long global_page_state(enum zone_stat_item item)
86013 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86014 {
86015 - long x = atomic_long_read(&vm_stat[item]);
86016 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86017 #ifdef CONFIG_SMP
86018 if (x < 0)
86019 x = 0;
86020 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86021 return x;
86022 }
86023
86024 -static inline unsigned long zone_page_state(struct zone *zone,
86025 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86026 enum zone_stat_item item)
86027 {
86028 - long x = atomic_long_read(&zone->vm_stat[item]);
86029 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86030 #ifdef CONFIG_SMP
86031 if (x < 0)
86032 x = 0;
86033 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86034 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86035 enum zone_stat_item item)
86036 {
86037 - long x = atomic_long_read(&zone->vm_stat[item]);
86038 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86039
86040 #ifdef CONFIG_SMP
86041 int cpu;
86042 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86043
86044 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86045 {
86046 - atomic_long_inc(&zone->vm_stat[item]);
86047 - atomic_long_inc(&vm_stat[item]);
86048 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86049 + atomic_long_inc_unchecked(&vm_stat[item]);
86050 }
86051
86052 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86053 {
86054 - atomic_long_dec(&zone->vm_stat[item]);
86055 - atomic_long_dec(&vm_stat[item]);
86056 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86057 + atomic_long_dec_unchecked(&vm_stat[item]);
86058 }
86059
86060 static inline void __inc_zone_page_state(struct page *page,
86061 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86062 index 91b0a68..0e9adf6 100644
86063 --- a/include/linux/xattr.h
86064 +++ b/include/linux/xattr.h
86065 @@ -28,7 +28,7 @@ struct xattr_handler {
86066 size_t size, int handler_flags);
86067 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86068 size_t size, int flags, int handler_flags);
86069 -};
86070 +} __do_const;
86071
86072 struct xattr {
86073 const char *name;
86074 @@ -37,6 +37,9 @@ struct xattr {
86075 };
86076
86077 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86078 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86079 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86080 +#endif
86081 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86082 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86083 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86084 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86085 index 92dbbd3..13ab0b3 100644
86086 --- a/include/linux/zlib.h
86087 +++ b/include/linux/zlib.h
86088 @@ -31,6 +31,7 @@
86089 #define _ZLIB_H
86090
86091 #include <linux/zconf.h>
86092 +#include <linux/compiler.h>
86093
86094 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86095 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86096 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86097
86098 /* basic functions */
86099
86100 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86101 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86102 /*
86103 Returns the number of bytes that needs to be allocated for a per-
86104 stream workspace with the specified parameters. A pointer to this
86105 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86106 index eb76cfd..9fd0e7c 100644
86107 --- a/include/media/v4l2-dev.h
86108 +++ b/include/media/v4l2-dev.h
86109 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86110 int (*mmap) (struct file *, struct vm_area_struct *);
86111 int (*open) (struct file *);
86112 int (*release) (struct file *);
86113 -};
86114 +} __do_const;
86115
86116 /*
86117 * Newer version of video_device, handled by videodev2.c
86118 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86119 index ffb69da..040393e 100644
86120 --- a/include/media/v4l2-device.h
86121 +++ b/include/media/v4l2-device.h
86122 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86123 this function returns 0. If the name ends with a digit (e.g. cx18),
86124 then the name will be set to cx18-0 since cx180 looks really odd. */
86125 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86126 - atomic_t *instance);
86127 + atomic_unchecked_t *instance);
86128
86129 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86130 Since the parent disappears this ensures that v4l2_dev doesn't have an
86131 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86132 index 2a25dec..bf6dd8a 100644
86133 --- a/include/net/9p/transport.h
86134 +++ b/include/net/9p/transport.h
86135 @@ -62,7 +62,7 @@ struct p9_trans_module {
86136 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86137 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86138 char *, char *, int , int, int, int);
86139 -};
86140 +} __do_const;
86141
86142 void v9fs_register_trans(struct p9_trans_module *m);
86143 void v9fs_unregister_trans(struct p9_trans_module *m);
86144 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86145 index a175ba4..196eb8242 100644
86146 --- a/include/net/af_unix.h
86147 +++ b/include/net/af_unix.h
86148 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86149 u32 secid; /* Security ID */
86150 #endif
86151 u32 consumed;
86152 -};
86153 +} __randomize_layout;
86154
86155 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86156 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86157 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86158 index ead99f0..6263c4b 100644
86159 --- a/include/net/bluetooth/l2cap.h
86160 +++ b/include/net/bluetooth/l2cap.h
86161 @@ -608,7 +608,7 @@ struct l2cap_ops {
86162 unsigned char *kdata,
86163 struct iovec *iov,
86164 int len);
86165 -};
86166 +} __do_const;
86167
86168 struct l2cap_conn {
86169 struct hci_conn *hcon;
86170 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86171 index f2ae33d..c457cf0 100644
86172 --- a/include/net/caif/cfctrl.h
86173 +++ b/include/net/caif/cfctrl.h
86174 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86175 void (*radioset_rsp)(void);
86176 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86177 struct cflayer *client_layer);
86178 -};
86179 +} __no_const;
86180
86181 /* Link Setup Parameters for CAIF-Links. */
86182 struct cfctrl_link_param {
86183 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86184 struct cfctrl {
86185 struct cfsrvl serv;
86186 struct cfctrl_rsp res;
86187 - atomic_t req_seq_no;
86188 - atomic_t rsp_seq_no;
86189 + atomic_unchecked_t req_seq_no;
86190 + atomic_unchecked_t rsp_seq_no;
86191 struct list_head list;
86192 /* Protects from simultaneous access to first_req list */
86193 spinlock_t info_list_lock;
86194 diff --git a/include/net/flow.h b/include/net/flow.h
86195 index 8109a15..504466d 100644
86196 --- a/include/net/flow.h
86197 +++ b/include/net/flow.h
86198 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86199
86200 void flow_cache_flush(struct net *net);
86201 void flow_cache_flush_deferred(struct net *net);
86202 -extern atomic_t flow_cache_genid;
86203 +extern atomic_unchecked_t flow_cache_genid;
86204
86205 #endif
86206 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86207 index af10c2c..a431cc5 100644
86208 --- a/include/net/genetlink.h
86209 +++ b/include/net/genetlink.h
86210 @@ -120,7 +120,7 @@ struct genl_ops {
86211 u8 cmd;
86212 u8 internal_flags;
86213 u8 flags;
86214 -};
86215 +} __do_const;
86216
86217 int __genl_register_family(struct genl_family *family);
86218
86219 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86220 index 734d9b5..48a9a4b 100644
86221 --- a/include/net/gro_cells.h
86222 +++ b/include/net/gro_cells.h
86223 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86224 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86225
86226 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86227 - atomic_long_inc(&dev->rx_dropped);
86228 + atomic_long_inc_unchecked(&dev->rx_dropped);
86229 kfree_skb(skb);
86230 return;
86231 }
86232 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86233 index 848e85c..051c7de 100644
86234 --- a/include/net/inet_connection_sock.h
86235 +++ b/include/net/inet_connection_sock.h
86236 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86237 int (*bind_conflict)(const struct sock *sk,
86238 const struct inet_bind_bucket *tb, bool relax);
86239 void (*mtu_reduced)(struct sock *sk);
86240 -};
86241 +} __do_const;
86242
86243 /** inet_connection_sock - INET connection oriented sock
86244 *
86245 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86246 index 80479ab..0c3f647 100644
86247 --- a/include/net/inetpeer.h
86248 +++ b/include/net/inetpeer.h
86249 @@ -47,7 +47,7 @@ struct inet_peer {
86250 */
86251 union {
86252 struct {
86253 - atomic_t rid; /* Frag reception counter */
86254 + atomic_unchecked_t rid; /* Frag reception counter */
86255 };
86256 struct rcu_head rcu;
86257 struct inet_peer *gc_next;
86258 diff --git a/include/net/ip.h b/include/net/ip.h
86259 index 0bb6207..a8878af 100644
86260 --- a/include/net/ip.h
86261 +++ b/include/net/ip.h
86262 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86263 }
86264 }
86265
86266 -u32 ip_idents_reserve(u32 hash, int segs);
86267 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86268 void __ip_select_ident(struct iphdr *iph, int segs);
86269
86270 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86271 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86272 index dc9d2a2..d985691 100644
86273 --- a/include/net/ip_fib.h
86274 +++ b/include/net/ip_fib.h
86275 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86276
86277 #define FIB_RES_SADDR(net, res) \
86278 ((FIB_RES_NH(res).nh_saddr_genid == \
86279 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86280 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86281 FIB_RES_NH(res).nh_saddr : \
86282 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86283 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86284 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86285 index 615b20b..fd4cbd8 100644
86286 --- a/include/net/ip_vs.h
86287 +++ b/include/net/ip_vs.h
86288 @@ -534,7 +534,7 @@ struct ip_vs_conn {
86289 struct ip_vs_conn *control; /* Master control connection */
86290 atomic_t n_control; /* Number of controlled ones */
86291 struct ip_vs_dest *dest; /* real server */
86292 - atomic_t in_pkts; /* incoming packet counter */
86293 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86294
86295 /* Packet transmitter for different forwarding methods. If it
86296 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86297 @@ -682,7 +682,7 @@ struct ip_vs_dest {
86298 __be16 port; /* port number of the server */
86299 union nf_inet_addr addr; /* IP address of the server */
86300 volatile unsigned int flags; /* dest status flags */
86301 - atomic_t conn_flags; /* flags to copy to conn */
86302 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86303 atomic_t weight; /* server weight */
86304
86305 atomic_t refcnt; /* reference counter */
86306 @@ -928,11 +928,11 @@ struct netns_ipvs {
86307 /* ip_vs_lblc */
86308 int sysctl_lblc_expiration;
86309 struct ctl_table_header *lblc_ctl_header;
86310 - struct ctl_table *lblc_ctl_table;
86311 + ctl_table_no_const *lblc_ctl_table;
86312 /* ip_vs_lblcr */
86313 int sysctl_lblcr_expiration;
86314 struct ctl_table_header *lblcr_ctl_header;
86315 - struct ctl_table *lblcr_ctl_table;
86316 + ctl_table_no_const *lblcr_ctl_table;
86317 /* ip_vs_est */
86318 struct list_head est_list; /* estimator list */
86319 spinlock_t est_lock;
86320 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86321 index 8d4f588..2e37ad2 100644
86322 --- a/include/net/irda/ircomm_tty.h
86323 +++ b/include/net/irda/ircomm_tty.h
86324 @@ -33,6 +33,7 @@
86325 #include <linux/termios.h>
86326 #include <linux/timer.h>
86327 #include <linux/tty.h> /* struct tty_struct */
86328 +#include <asm/local.h>
86329
86330 #include <net/irda/irias_object.h>
86331 #include <net/irda/ircomm_core.h>
86332 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86333 index 714cc9a..ea05f3e 100644
86334 --- a/include/net/iucv/af_iucv.h
86335 +++ b/include/net/iucv/af_iucv.h
86336 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86337 struct iucv_sock_list {
86338 struct hlist_head head;
86339 rwlock_t lock;
86340 - atomic_t autobind_name;
86341 + atomic_unchecked_t autobind_name;
86342 };
86343
86344 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86345 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86346 index f3be818..bf46196 100644
86347 --- a/include/net/llc_c_ac.h
86348 +++ b/include/net/llc_c_ac.h
86349 @@ -87,7 +87,7 @@
86350 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86351 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86352
86353 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86354 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86355
86356 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86357 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86358 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86359 index 3948cf1..83b28c4 100644
86360 --- a/include/net/llc_c_ev.h
86361 +++ b/include/net/llc_c_ev.h
86362 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86363 return (struct llc_conn_state_ev *)skb->cb;
86364 }
86365
86366 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86367 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86368 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86369 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86370
86371 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86372 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86373 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86374 index 0e79cfb..f46db31 100644
86375 --- a/include/net/llc_c_st.h
86376 +++ b/include/net/llc_c_st.h
86377 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86378 u8 next_state;
86379 llc_conn_ev_qfyr_t *ev_qualifiers;
86380 llc_conn_action_t *ev_actions;
86381 -};
86382 +} __do_const;
86383
86384 struct llc_conn_state {
86385 u8 current_state;
86386 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86387 index a61b98c..aade1eb 100644
86388 --- a/include/net/llc_s_ac.h
86389 +++ b/include/net/llc_s_ac.h
86390 @@ -23,7 +23,7 @@
86391 #define SAP_ACT_TEST_IND 9
86392
86393 /* All action functions must look like this */
86394 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86395 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86396
86397 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86398 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86399 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86400 index 567c681..cd73ac02 100644
86401 --- a/include/net/llc_s_st.h
86402 +++ b/include/net/llc_s_st.h
86403 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86404 llc_sap_ev_t ev;
86405 u8 next_state;
86406 llc_sap_action_t *ev_actions;
86407 -};
86408 +} __do_const;
86409
86410 struct llc_sap_state {
86411 u8 curr_state;
86412 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86413 index a9de1da..df72057 100644
86414 --- a/include/net/mac80211.h
86415 +++ b/include/net/mac80211.h
86416 @@ -4645,7 +4645,7 @@ struct rate_control_ops {
86417 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86418
86419 u32 (*get_expected_throughput)(void *priv_sta);
86420 -};
86421 +} __do_const;
86422
86423 static inline int rate_supported(struct ieee80211_sta *sta,
86424 enum ieee80211_band band,
86425 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86426 index f60558d..e5ed9bd 100644
86427 --- a/include/net/neighbour.h
86428 +++ b/include/net/neighbour.h
86429 @@ -163,7 +163,7 @@ struct neigh_ops {
86430 void (*error_report)(struct neighbour *, struct sk_buff *);
86431 int (*output)(struct neighbour *, struct sk_buff *);
86432 int (*connected_output)(struct neighbour *, struct sk_buff *);
86433 -};
86434 +} __do_const;
86435
86436 struct pneigh_entry {
86437 struct pneigh_entry *next;
86438 @@ -217,7 +217,7 @@ struct neigh_table {
86439 struct neigh_statistics __percpu *stats;
86440 struct neigh_hash_table __rcu *nht;
86441 struct pneigh_entry **phash_buckets;
86442 -};
86443 +} __randomize_layout;
86444
86445 static inline int neigh_parms_family(struct neigh_parms *p)
86446 {
86447 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86448 index e0d6466..e2f3003 100644
86449 --- a/include/net/net_namespace.h
86450 +++ b/include/net/net_namespace.h
86451 @@ -129,8 +129,8 @@ struct net {
86452 struct netns_ipvs *ipvs;
86453 #endif
86454 struct sock *diag_nlsk;
86455 - atomic_t fnhe_genid;
86456 -};
86457 + atomic_unchecked_t fnhe_genid;
86458 +} __randomize_layout;
86459
86460 #include <linux/seq_file_net.h>
86461
86462 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86463 #define __net_init __init
86464 #define __net_exit __exit_refok
86465 #define __net_initdata __initdata
86466 +#ifdef CONSTIFY_PLUGIN
86467 #define __net_initconst __initconst
86468 +#else
86469 +#define __net_initconst __initdata
86470 +#endif
86471 #endif
86472
86473 struct pernet_operations {
86474 @@ -296,7 +300,7 @@ struct pernet_operations {
86475 void (*exit_batch)(struct list_head *net_exit_list);
86476 int *id;
86477 size_t size;
86478 -};
86479 +} __do_const;
86480
86481 /*
86482 * Use these carefully. If you implement a network device and it
86483 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86484
86485 static inline int rt_genid_ipv4(struct net *net)
86486 {
86487 - return atomic_read(&net->ipv4.rt_genid);
86488 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86489 }
86490
86491 static inline void rt_genid_bump_ipv4(struct net *net)
86492 {
86493 - atomic_inc(&net->ipv4.rt_genid);
86494 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86495 }
86496
86497 extern void (*__fib6_flush_trees)(struct net *net);
86498 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86499
86500 static inline int fnhe_genid(struct net *net)
86501 {
86502 - return atomic_read(&net->fnhe_genid);
86503 + return atomic_read_unchecked(&net->fnhe_genid);
86504 }
86505
86506 static inline void fnhe_genid_bump(struct net *net)
86507 {
86508 - atomic_inc(&net->fnhe_genid);
86509 + atomic_inc_unchecked(&net->fnhe_genid);
86510 }
86511
86512 #endif /* __NET_NET_NAMESPACE_H */
86513 diff --git a/include/net/netlink.h b/include/net/netlink.h
86514 index 7b903e1..ad9ca4b 100644
86515 --- a/include/net/netlink.h
86516 +++ b/include/net/netlink.h
86517 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86518 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86519 {
86520 if (mark)
86521 - skb_trim(skb, (unsigned char *) mark - skb->data);
86522 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86523 }
86524
86525 /**
86526 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86527 index 29d6a94..235d3d84 100644
86528 --- a/include/net/netns/conntrack.h
86529 +++ b/include/net/netns/conntrack.h
86530 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86531 struct nf_proto_net {
86532 #ifdef CONFIG_SYSCTL
86533 struct ctl_table_header *ctl_table_header;
86534 - struct ctl_table *ctl_table;
86535 + ctl_table_no_const *ctl_table;
86536 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86537 struct ctl_table_header *ctl_compat_header;
86538 - struct ctl_table *ctl_compat_table;
86539 + ctl_table_no_const *ctl_compat_table;
86540 #endif
86541 #endif
86542 unsigned int users;
86543 @@ -60,7 +60,7 @@ struct nf_ip_net {
86544 struct nf_icmp_net icmpv6;
86545 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86546 struct ctl_table_header *ctl_table_header;
86547 - struct ctl_table *ctl_table;
86548 + ctl_table_no_const *ctl_table;
86549 #endif
86550 };
86551
86552 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86553 index 24945ce..f19e42f 100644
86554 --- a/include/net/netns/ipv4.h
86555 +++ b/include/net/netns/ipv4.h
86556 @@ -83,7 +83,7 @@ struct netns_ipv4 {
86557
86558 struct ping_group_range ping_group_range;
86559
86560 - atomic_t dev_addr_genid;
86561 + atomic_unchecked_t dev_addr_genid;
86562
86563 #ifdef CONFIG_SYSCTL
86564 unsigned long *sysctl_local_reserved_ports;
86565 @@ -97,6 +97,6 @@ struct netns_ipv4 {
86566 struct fib_rules_ops *mr_rules_ops;
86567 #endif
86568 #endif
86569 - atomic_t rt_genid;
86570 + atomic_unchecked_t rt_genid;
86571 };
86572 #endif
86573 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86574 index 69ae41f..4f94868 100644
86575 --- a/include/net/netns/ipv6.h
86576 +++ b/include/net/netns/ipv6.h
86577 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86578 struct fib_rules_ops *mr6_rules_ops;
86579 #endif
86580 #endif
86581 - atomic_t dev_addr_genid;
86582 - atomic_t fib6_sernum;
86583 + atomic_unchecked_t dev_addr_genid;
86584 + atomic_unchecked_t fib6_sernum;
86585 };
86586
86587 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86588 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86589 index 9da7982..099321b9 100644
86590 --- a/include/net/netns/xfrm.h
86591 +++ b/include/net/netns/xfrm.h
86592 @@ -78,7 +78,7 @@ struct netns_xfrm {
86593
86594 /* flow cache part */
86595 struct flow_cache flow_cache_global;
86596 - atomic_t flow_cache_genid;
86597 + atomic_unchecked_t flow_cache_genid;
86598 struct list_head flow_cache_gc_list;
86599 spinlock_t flow_cache_gc_lock;
86600 struct work_struct flow_cache_gc_work;
86601 diff --git a/include/net/ping.h b/include/net/ping.h
86602 index 026479b..d9b2829 100644
86603 --- a/include/net/ping.h
86604 +++ b/include/net/ping.h
86605 @@ -54,7 +54,7 @@ struct ping_iter_state {
86606
86607 extern struct proto ping_prot;
86608 #if IS_ENABLED(CONFIG_IPV6)
86609 -extern struct pingv6_ops pingv6_ops;
86610 +extern struct pingv6_ops *pingv6_ops;
86611 #endif
86612
86613 struct pingfakehdr {
86614 diff --git a/include/net/protocol.h b/include/net/protocol.h
86615 index d6fcc1f..ca277058 100644
86616 --- a/include/net/protocol.h
86617 +++ b/include/net/protocol.h
86618 @@ -49,7 +49,7 @@ struct net_protocol {
86619 * socket lookup?
86620 */
86621 icmp_strict_tag_validation:1;
86622 -};
86623 +} __do_const;
86624
86625 #if IS_ENABLED(CONFIG_IPV6)
86626 struct inet6_protocol {
86627 @@ -62,7 +62,7 @@ struct inet6_protocol {
86628 u8 type, u8 code, int offset,
86629 __be32 info);
86630 unsigned int flags; /* INET6_PROTO_xxx */
86631 -};
86632 +} __do_const;
86633
86634 #define INET6_PROTO_NOPOLICY 0x1
86635 #define INET6_PROTO_FINAL 0x2
86636 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86637 index e21b9f9..0191ef0 100644
86638 --- a/include/net/rtnetlink.h
86639 +++ b/include/net/rtnetlink.h
86640 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86641 int (*fill_slave_info)(struct sk_buff *skb,
86642 const struct net_device *dev,
86643 const struct net_device *slave_dev);
86644 -};
86645 +} __do_const;
86646
86647 int __rtnl_link_register(struct rtnl_link_ops *ops);
86648 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86649 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86650 index 4a5b9a3..ca27d73 100644
86651 --- a/include/net/sctp/checksum.h
86652 +++ b/include/net/sctp/checksum.h
86653 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86654 unsigned int offset)
86655 {
86656 struct sctphdr *sh = sctp_hdr(skb);
86657 - __le32 ret, old = sh->checksum;
86658 - const struct skb_checksum_ops ops = {
86659 + __le32 ret, old = sh->checksum;
86660 + static const struct skb_checksum_ops ops = {
86661 .update = sctp_csum_update,
86662 .combine = sctp_csum_combine,
86663 };
86664 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86665 index 72a31db..aaa63d9 100644
86666 --- a/include/net/sctp/sm.h
86667 +++ b/include/net/sctp/sm.h
86668 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86669 typedef struct {
86670 sctp_state_fn_t *fn;
86671 const char *name;
86672 -} sctp_sm_table_entry_t;
86673 +} __do_const sctp_sm_table_entry_t;
86674
86675 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86676 * currently in use.
86677 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86678 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86679
86680 /* Extern declarations for major data structures. */
86681 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86682 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86683
86684
86685 /* Get the size of a DATA chunk payload. */
86686 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86687 index 4ff3f67..89ae38e 100644
86688 --- a/include/net/sctp/structs.h
86689 +++ b/include/net/sctp/structs.h
86690 @@ -509,7 +509,7 @@ struct sctp_pf {
86691 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86692 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86693 struct sctp_af *af;
86694 -};
86695 +} __do_const;
86696
86697
86698 /* Structure to track chunk fragments that have been acked, but peer
86699 diff --git a/include/net/sock.h b/include/net/sock.h
86700 index 7db3db1..a915cca 100644
86701 --- a/include/net/sock.h
86702 +++ b/include/net/sock.h
86703 @@ -355,7 +355,7 @@ struct sock {
86704 unsigned int sk_napi_id;
86705 unsigned int sk_ll_usec;
86706 #endif
86707 - atomic_t sk_drops;
86708 + atomic_unchecked_t sk_drops;
86709 int sk_rcvbuf;
86710
86711 struct sk_filter __rcu *sk_filter;
86712 @@ -1048,7 +1048,7 @@ struct proto {
86713 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86714 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86715 #endif
86716 -};
86717 +} __randomize_layout;
86718
86719 /*
86720 * Bits in struct cg_proto.flags
86721 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86722 return ret >> PAGE_SHIFT;
86723 }
86724
86725 -static inline long
86726 +static inline long __intentional_overflow(-1)
86727 sk_memory_allocated(const struct sock *sk)
86728 {
86729 struct proto *prot = sk->sk_prot;
86730 @@ -1380,7 +1380,7 @@ struct sock_iocb {
86731 struct scm_cookie *scm;
86732 struct msghdr *msg, async_msg;
86733 struct kiocb *kiocb;
86734 -};
86735 +} __randomize_layout;
86736
86737 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86738 {
86739 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86740 }
86741
86742 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86743 - char __user *from, char *to,
86744 + char __user *from, unsigned char *to,
86745 int copy, int offset)
86746 {
86747 if (skb->ip_summed == CHECKSUM_NONE) {
86748 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86749 }
86750 }
86751
86752 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86753 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86754
86755 /**
86756 * sk_page_frag - return an appropriate page_frag
86757 diff --git a/include/net/tcp.h b/include/net/tcp.h
86758 index 4062b4f..9ff45e7 100644
86759 --- a/include/net/tcp.h
86760 +++ b/include/net/tcp.h
86761 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86762 void tcp_xmit_retransmit_queue(struct sock *);
86763 void tcp_simple_retransmit(struct sock *);
86764 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86765 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86766 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86767
86768 void tcp_send_probe0(struct sock *);
86769 void tcp_send_partial(struct sock *);
86770 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86771 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86772 */
86773 struct tcp_skb_cb {
86774 - __u32 seq; /* Starting sequence number */
86775 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86776 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86777 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86778 union {
86779 /* Note : tcp_tw_isn is used in input path only
86780 * (isn chosen by tcp_timewait_state_process())
86781 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
86782
86783 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86784 /* 1 byte hole */
86785 - __u32 ack_seq; /* Sequence number ACK'd */
86786 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86787 union {
86788 struct inet_skb_parm h4;
86789 #if IS_ENABLED(CONFIG_IPV6)
86790 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86791 index dc4865e..152ee4c 100644
86792 --- a/include/net/xfrm.h
86793 +++ b/include/net/xfrm.h
86794 @@ -285,7 +285,6 @@ struct xfrm_dst;
86795 struct xfrm_policy_afinfo {
86796 unsigned short family;
86797 struct dst_ops *dst_ops;
86798 - void (*garbage_collect)(struct net *net);
86799 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86800 const xfrm_address_t *saddr,
86801 const xfrm_address_t *daddr);
86802 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86803 struct net_device *dev,
86804 const struct flowi *fl);
86805 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86806 -};
86807 +} __do_const;
86808
86809 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86810 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86811 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86812 int (*transport_finish)(struct sk_buff *skb,
86813 int async);
86814 void (*local_error)(struct sk_buff *skb, u32 mtu);
86815 -};
86816 +} __do_const;
86817
86818 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86819 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86820 @@ -437,7 +436,7 @@ struct xfrm_mode {
86821 struct module *owner;
86822 unsigned int encap;
86823 int flags;
86824 -};
86825 +} __do_const;
86826
86827 /* Flags for xfrm_mode. */
86828 enum {
86829 @@ -534,7 +533,7 @@ struct xfrm_policy {
86830 struct timer_list timer;
86831
86832 struct flow_cache_object flo;
86833 - atomic_t genid;
86834 + atomic_unchecked_t genid;
86835 u32 priority;
86836 u32 index;
86837 struct xfrm_mark mark;
86838 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86839 }
86840
86841 void xfrm_garbage_collect(struct net *net);
86842 +void xfrm_garbage_collect_deferred(struct net *net);
86843
86844 #else
86845
86846 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86847 static inline void xfrm_garbage_collect(struct net *net)
86848 {
86849 }
86850 +static inline void xfrm_garbage_collect_deferred(struct net *net)
86851 +{
86852 +}
86853 #endif
86854
86855 static __inline__
86856 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86857 index 1017e0b..227aa4d 100644
86858 --- a/include/rdma/iw_cm.h
86859 +++ b/include/rdma/iw_cm.h
86860 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
86861 int backlog);
86862
86863 int (*destroy_listen)(struct iw_cm_id *cm_id);
86864 -};
86865 +} __no_const;
86866
86867 /**
86868 * iw_create_cm_id - Create an IW CM identifier.
86869 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86870 index 52beadf..598734c 100644
86871 --- a/include/scsi/libfc.h
86872 +++ b/include/scsi/libfc.h
86873 @@ -771,6 +771,7 @@ struct libfc_function_template {
86874 */
86875 void (*disc_stop_final) (struct fc_lport *);
86876 };
86877 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86878
86879 /**
86880 * struct fc_disc - Discovery context
86881 @@ -875,7 +876,7 @@ struct fc_lport {
86882 struct fc_vport *vport;
86883
86884 /* Operational Information */
86885 - struct libfc_function_template tt;
86886 + libfc_function_template_no_const tt;
86887 u8 link_up;
86888 u8 qfull;
86889 enum fc_lport_state state;
86890 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86891 index 27ecee7..5f42632 100644
86892 --- a/include/scsi/scsi_device.h
86893 +++ b/include/scsi/scsi_device.h
86894 @@ -186,9 +186,9 @@ struct scsi_device {
86895 unsigned int max_device_blocked; /* what device_blocked counts down from */
86896 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86897
86898 - atomic_t iorequest_cnt;
86899 - atomic_t iodone_cnt;
86900 - atomic_t ioerr_cnt;
86901 + atomic_unchecked_t iorequest_cnt;
86902 + atomic_unchecked_t iodone_cnt;
86903 + atomic_unchecked_t ioerr_cnt;
86904
86905 struct device sdev_gendev,
86906 sdev_dev;
86907 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86908 index 007a0bc..7188db8 100644
86909 --- a/include/scsi/scsi_transport_fc.h
86910 +++ b/include/scsi/scsi_transport_fc.h
86911 @@ -756,7 +756,8 @@ struct fc_function_template {
86912 unsigned long show_host_system_hostname:1;
86913
86914 unsigned long disable_target_scan:1;
86915 -};
86916 +} __do_const;
86917 +typedef struct fc_function_template __no_const fc_function_template_no_const;
86918
86919
86920 /**
86921 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86922 index ae6c3b8..fd748ac 100644
86923 --- a/include/sound/compress_driver.h
86924 +++ b/include/sound/compress_driver.h
86925 @@ -128,7 +128,7 @@ struct snd_compr_ops {
86926 struct snd_compr_caps *caps);
86927 int (*get_codec_caps) (struct snd_compr_stream *stream,
86928 struct snd_compr_codec_caps *codec);
86929 -};
86930 +} __no_const;
86931
86932 /**
86933 * struct snd_compr: Compressed device
86934 diff --git a/include/sound/soc.h b/include/sound/soc.h
86935 index 7ba7130..d46594d 100644
86936 --- a/include/sound/soc.h
86937 +++ b/include/sound/soc.h
86938 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
86939 enum snd_soc_dapm_type, int);
86940
86941 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
86942 -};
86943 +} __do_const;
86944
86945 /* SoC platform interface */
86946 struct snd_soc_platform_driver {
86947 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
86948 const struct snd_compr_ops *compr_ops;
86949
86950 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86951 -};
86952 +} __do_const;
86953
86954 struct snd_soc_dai_link_component {
86955 const char *name;
86956 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86957 index 23c518a..d6ef510 100644
86958 --- a/include/target/target_core_base.h
86959 +++ b/include/target/target_core_base.h
86960 @@ -764,7 +764,7 @@ struct se_device {
86961 atomic_long_t write_bytes;
86962 /* Active commands on this virtual SE device */
86963 atomic_t simple_cmds;
86964 - atomic_t dev_ordered_id;
86965 + atomic_unchecked_t dev_ordered_id;
86966 atomic_t dev_ordered_sync;
86967 atomic_t dev_qf_count;
86968 int export_count;
86969 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86970 new file mode 100644
86971 index 0000000..fb634b7
86972 --- /dev/null
86973 +++ b/include/trace/events/fs.h
86974 @@ -0,0 +1,53 @@
86975 +#undef TRACE_SYSTEM
86976 +#define TRACE_SYSTEM fs
86977 +
86978 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86979 +#define _TRACE_FS_H
86980 +
86981 +#include <linux/fs.h>
86982 +#include <linux/tracepoint.h>
86983 +
86984 +TRACE_EVENT(do_sys_open,
86985 +
86986 + TP_PROTO(const char *filename, int flags, int mode),
86987 +
86988 + TP_ARGS(filename, flags, mode),
86989 +
86990 + TP_STRUCT__entry(
86991 + __string( filename, filename )
86992 + __field( int, flags )
86993 + __field( int, mode )
86994 + ),
86995 +
86996 + TP_fast_assign(
86997 + __assign_str(filename, filename);
86998 + __entry->flags = flags;
86999 + __entry->mode = mode;
87000 + ),
87001 +
87002 + TP_printk("\"%s\" %x %o",
87003 + __get_str(filename), __entry->flags, __entry->mode)
87004 +);
87005 +
87006 +TRACE_EVENT(open_exec,
87007 +
87008 + TP_PROTO(const char *filename),
87009 +
87010 + TP_ARGS(filename),
87011 +
87012 + TP_STRUCT__entry(
87013 + __string( filename, filename )
87014 + ),
87015 +
87016 + TP_fast_assign(
87017 + __assign_str(filename, filename);
87018 + ),
87019 +
87020 + TP_printk("\"%s\"",
87021 + __get_str(filename))
87022 +);
87023 +
87024 +#endif /* _TRACE_FS_H */
87025 +
87026 +/* This part must be outside protection */
87027 +#include <trace/define_trace.h>
87028 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87029 index 3608beb..df39d8a 100644
87030 --- a/include/trace/events/irq.h
87031 +++ b/include/trace/events/irq.h
87032 @@ -36,7 +36,7 @@ struct softirq_action;
87033 */
87034 TRACE_EVENT(irq_handler_entry,
87035
87036 - TP_PROTO(int irq, struct irqaction *action),
87037 + TP_PROTO(int irq, const struct irqaction *action),
87038
87039 TP_ARGS(irq, action),
87040
87041 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87042 */
87043 TRACE_EVENT(irq_handler_exit,
87044
87045 - TP_PROTO(int irq, struct irqaction *action, int ret),
87046 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87047
87048 TP_ARGS(irq, action, ret),
87049
87050 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87051 index 7caf44c..23c6f27 100644
87052 --- a/include/uapi/linux/a.out.h
87053 +++ b/include/uapi/linux/a.out.h
87054 @@ -39,6 +39,14 @@ enum machine_type {
87055 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87056 };
87057
87058 +/* Constants for the N_FLAGS field */
87059 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87060 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87061 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87062 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87063 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87064 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87065 +
87066 #if !defined (N_MAGIC)
87067 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87068 #endif
87069 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87070 index 22b6ad3..aeba37e 100644
87071 --- a/include/uapi/linux/bcache.h
87072 +++ b/include/uapi/linux/bcache.h
87073 @@ -5,6 +5,7 @@
87074 * Bcache on disk data structures
87075 */
87076
87077 +#include <linux/compiler.h>
87078 #include <asm/types.h>
87079
87080 #define BITMASK(name, type, field, offset, size) \
87081 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87082 /* Btree keys - all units are in sectors */
87083
87084 struct bkey {
87085 - __u64 high;
87086 - __u64 low;
87087 + __u64 high __intentional_overflow(-1);
87088 + __u64 low __intentional_overflow(-1);
87089 __u64 ptr[];
87090 };
87091
87092 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87093 index d876736..ccce5c0 100644
87094 --- a/include/uapi/linux/byteorder/little_endian.h
87095 +++ b/include/uapi/linux/byteorder/little_endian.h
87096 @@ -42,51 +42,51 @@
87097
87098 static inline __le64 __cpu_to_le64p(const __u64 *p)
87099 {
87100 - return (__force __le64)*p;
87101 + return (__force const __le64)*p;
87102 }
87103 -static inline __u64 __le64_to_cpup(const __le64 *p)
87104 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87105 {
87106 - return (__force __u64)*p;
87107 + return (__force const __u64)*p;
87108 }
87109 static inline __le32 __cpu_to_le32p(const __u32 *p)
87110 {
87111 - return (__force __le32)*p;
87112 + return (__force const __le32)*p;
87113 }
87114 static inline __u32 __le32_to_cpup(const __le32 *p)
87115 {
87116 - return (__force __u32)*p;
87117 + return (__force const __u32)*p;
87118 }
87119 static inline __le16 __cpu_to_le16p(const __u16 *p)
87120 {
87121 - return (__force __le16)*p;
87122 + return (__force const __le16)*p;
87123 }
87124 static inline __u16 __le16_to_cpup(const __le16 *p)
87125 {
87126 - return (__force __u16)*p;
87127 + return (__force const __u16)*p;
87128 }
87129 static inline __be64 __cpu_to_be64p(const __u64 *p)
87130 {
87131 - return (__force __be64)__swab64p(p);
87132 + return (__force const __be64)__swab64p(p);
87133 }
87134 static inline __u64 __be64_to_cpup(const __be64 *p)
87135 {
87136 - return __swab64p((__u64 *)p);
87137 + return __swab64p((const __u64 *)p);
87138 }
87139 static inline __be32 __cpu_to_be32p(const __u32 *p)
87140 {
87141 - return (__force __be32)__swab32p(p);
87142 + return (__force const __be32)__swab32p(p);
87143 }
87144 -static inline __u32 __be32_to_cpup(const __be32 *p)
87145 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87146 {
87147 - return __swab32p((__u32 *)p);
87148 + return __swab32p((const __u32 *)p);
87149 }
87150 static inline __be16 __cpu_to_be16p(const __u16 *p)
87151 {
87152 - return (__force __be16)__swab16p(p);
87153 + return (__force const __be16)__swab16p(p);
87154 }
87155 static inline __u16 __be16_to_cpup(const __be16 *p)
87156 {
87157 - return __swab16p((__u16 *)p);
87158 + return __swab16p((const __u16 *)p);
87159 }
87160 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87161 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87162 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87163 index ea9bf25..5140c61 100644
87164 --- a/include/uapi/linux/elf.h
87165 +++ b/include/uapi/linux/elf.h
87166 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87167 #define PT_GNU_EH_FRAME 0x6474e550
87168
87169 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87170 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87171 +
87172 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87173 +
87174 +/* Constants for the e_flags field */
87175 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87176 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87177 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87178 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87179 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87180 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87181
87182 /*
87183 * Extended Numbering
87184 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87185 #define DT_DEBUG 21
87186 #define DT_TEXTREL 22
87187 #define DT_JMPREL 23
87188 +#define DT_FLAGS 30
87189 + #define DF_TEXTREL 0x00000004
87190 #define DT_ENCODING 32
87191 #define OLD_DT_LOOS 0x60000000
87192 #define DT_LOOS 0x6000000d
87193 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87194 #define PF_W 0x2
87195 #define PF_X 0x1
87196
87197 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87198 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87199 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87200 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87201 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87202 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87203 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87204 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87205 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87206 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87207 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87208 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87209 +
87210 typedef struct elf32_phdr{
87211 Elf32_Word p_type;
87212 Elf32_Off p_offset;
87213 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87214 #define EI_OSABI 7
87215 #define EI_PAD 8
87216
87217 +#define EI_PAX 14
87218 +
87219 #define ELFMAG0 0x7f /* EI_MAG */
87220 #define ELFMAG1 'E'
87221 #define ELFMAG2 'L'
87222 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87223 index aa169c4..6a2771d 100644
87224 --- a/include/uapi/linux/personality.h
87225 +++ b/include/uapi/linux/personality.h
87226 @@ -30,6 +30,7 @@ enum {
87227 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87228 ADDR_NO_RANDOMIZE | \
87229 ADDR_COMPAT_LAYOUT | \
87230 + ADDR_LIMIT_3GB | \
87231 MMAP_PAGE_ZERO)
87232
87233 /*
87234 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87235 index 7530e74..e714828 100644
87236 --- a/include/uapi/linux/screen_info.h
87237 +++ b/include/uapi/linux/screen_info.h
87238 @@ -43,7 +43,8 @@ struct screen_info {
87239 __u16 pages; /* 0x32 */
87240 __u16 vesa_attributes; /* 0x34 */
87241 __u32 capabilities; /* 0x36 */
87242 - __u8 _reserved[6]; /* 0x3a */
87243 + __u16 vesapm_size; /* 0x3a */
87244 + __u8 _reserved[4]; /* 0x3c */
87245 } __attribute__((packed));
87246
87247 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87248 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87249 index 0e011eb..82681b1 100644
87250 --- a/include/uapi/linux/swab.h
87251 +++ b/include/uapi/linux/swab.h
87252 @@ -43,7 +43,7 @@
87253 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87254 */
87255
87256 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87257 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87258 {
87259 #ifdef __HAVE_BUILTIN_BSWAP16__
87260 return __builtin_bswap16(val);
87261 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87262 #endif
87263 }
87264
87265 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87266 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87267 {
87268 #ifdef __HAVE_BUILTIN_BSWAP32__
87269 return __builtin_bswap32(val);
87270 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87271 #endif
87272 }
87273
87274 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87275 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87276 {
87277 #ifdef __HAVE_BUILTIN_BSWAP64__
87278 return __builtin_bswap64(val);
87279 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87280 index 43aaba1..1c30b48 100644
87281 --- a/include/uapi/linux/sysctl.h
87282 +++ b/include/uapi/linux/sysctl.h
87283 @@ -155,8 +155,6 @@ enum
87284 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87285 };
87286
87287 -
87288 -
87289 /* CTL_VM names: */
87290 enum
87291 {
87292 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87293 index 1590c49..5eab462 100644
87294 --- a/include/uapi/linux/xattr.h
87295 +++ b/include/uapi/linux/xattr.h
87296 @@ -73,5 +73,9 @@
87297 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87298 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87299
87300 +/* User namespace */
87301 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87302 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87303 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87304
87305 #endif /* _UAPI_LINUX_XATTR_H */
87306 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87307 index f9466fa..f4e2b81 100644
87308 --- a/include/video/udlfb.h
87309 +++ b/include/video/udlfb.h
87310 @@ -53,10 +53,10 @@ struct dlfb_data {
87311 u32 pseudo_palette[256];
87312 int blank_mode; /*one of FB_BLANK_ */
87313 /* blit-only rendering path metrics, exposed through sysfs */
87314 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87315 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87316 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87317 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87318 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87319 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87320 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87321 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87322 };
87323
87324 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87325 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87326 index 30f5362..8ed8ac9 100644
87327 --- a/include/video/uvesafb.h
87328 +++ b/include/video/uvesafb.h
87329 @@ -122,6 +122,7 @@ struct uvesafb_par {
87330 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87331 u8 pmi_setpal; /* PMI for palette changes */
87332 u16 *pmi_base; /* protected mode interface location */
87333 + u8 *pmi_code; /* protected mode code location */
87334 void *pmi_start;
87335 void *pmi_pal;
87336 u8 *vbe_state_orig; /*
87337 diff --git a/init/Kconfig b/init/Kconfig
87338 index 2081a4d..98d1149 100644
87339 --- a/init/Kconfig
87340 +++ b/init/Kconfig
87341 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87342
87343 config CHECKPOINT_RESTORE
87344 bool "Checkpoint/restore support" if EXPERT
87345 + depends on !GRKERNSEC
87346 default n
87347 help
87348 Enables additional kernel features in a sake of checkpoint/restore.
87349 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87350
87351 config COMPAT_BRK
87352 bool "Disable heap randomization"
87353 - default y
87354 + default n
87355 help
87356 Randomizing heap placement makes heap exploits harder, but it
87357 also breaks ancient binaries (including anything libc5 based).
87358 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87359 config STOP_MACHINE
87360 bool
87361 default y
87362 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87363 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87364 help
87365 Need stop_machine() primitive.
87366
87367 diff --git a/init/Makefile b/init/Makefile
87368 index 7bc47ee..6da2dc7 100644
87369 --- a/init/Makefile
87370 +++ b/init/Makefile
87371 @@ -2,6 +2,9 @@
87372 # Makefile for the linux kernel.
87373 #
87374
87375 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87376 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87377 +
87378 obj-y := main.o version.o mounts.o
87379 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87380 obj-y += noinitramfs.o
87381 diff --git a/init/do_mounts.c b/init/do_mounts.c
87382 index 9b3565c..3f90cf9 100644
87383 --- a/init/do_mounts.c
87384 +++ b/init/do_mounts.c
87385 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87386 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87387 {
87388 struct super_block *s;
87389 - int err = sys_mount(name, "/root", fs, flags, data);
87390 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87391 if (err)
87392 return err;
87393
87394 - sys_chdir("/root");
87395 + sys_chdir((const char __force_user *)"/root");
87396 s = current->fs->pwd.dentry->d_sb;
87397 ROOT_DEV = s->s_dev;
87398 printk(KERN_INFO
87399 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87400 va_start(args, fmt);
87401 vsprintf(buf, fmt, args);
87402 va_end(args);
87403 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87404 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87405 if (fd >= 0) {
87406 sys_ioctl(fd, FDEJECT, 0);
87407 sys_close(fd);
87408 }
87409 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87410 - fd = sys_open("/dev/console", O_RDWR, 0);
87411 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87412 if (fd >= 0) {
87413 sys_ioctl(fd, TCGETS, (long)&termios);
87414 termios.c_lflag &= ~ICANON;
87415 sys_ioctl(fd, TCSETSF, (long)&termios);
87416 - sys_read(fd, &c, 1);
87417 + sys_read(fd, (char __user *)&c, 1);
87418 termios.c_lflag |= ICANON;
87419 sys_ioctl(fd, TCSETSF, (long)&termios);
87420 sys_close(fd);
87421 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87422 mount_root();
87423 out:
87424 devtmpfs_mount("dev");
87425 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87426 - sys_chroot(".");
87427 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87428 + sys_chroot((const char __force_user *)".");
87429 }
87430
87431 static bool is_tmpfs;
87432 diff --git a/init/do_mounts.h b/init/do_mounts.h
87433 index f5b978a..69dbfe8 100644
87434 --- a/init/do_mounts.h
87435 +++ b/init/do_mounts.h
87436 @@ -15,15 +15,15 @@ extern int root_mountflags;
87437
87438 static inline int create_dev(char *name, dev_t dev)
87439 {
87440 - sys_unlink(name);
87441 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87442 + sys_unlink((char __force_user *)name);
87443 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87444 }
87445
87446 #if BITS_PER_LONG == 32
87447 static inline u32 bstat(char *name)
87448 {
87449 struct stat64 stat;
87450 - if (sys_stat64(name, &stat) != 0)
87451 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87452 return 0;
87453 if (!S_ISBLK(stat.st_mode))
87454 return 0;
87455 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87456 static inline u32 bstat(char *name)
87457 {
87458 struct stat stat;
87459 - if (sys_newstat(name, &stat) != 0)
87460 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87461 return 0;
87462 if (!S_ISBLK(stat.st_mode))
87463 return 0;
87464 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87465 index 3e0878e..8a9d7a0 100644
87466 --- a/init/do_mounts_initrd.c
87467 +++ b/init/do_mounts_initrd.c
87468 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87469 {
87470 sys_unshare(CLONE_FS | CLONE_FILES);
87471 /* stdin/stdout/stderr for /linuxrc */
87472 - sys_open("/dev/console", O_RDWR, 0);
87473 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87474 sys_dup(0);
87475 sys_dup(0);
87476 /* move initrd over / and chdir/chroot in initrd root */
87477 - sys_chdir("/root");
87478 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87479 - sys_chroot(".");
87480 + sys_chdir((const char __force_user *)"/root");
87481 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87482 + sys_chroot((const char __force_user *)".");
87483 sys_setsid();
87484 return 0;
87485 }
87486 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87487 create_dev("/dev/root.old", Root_RAM0);
87488 /* mount initrd on rootfs' /root */
87489 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87490 - sys_mkdir("/old", 0700);
87491 - sys_chdir("/old");
87492 + sys_mkdir((const char __force_user *)"/old", 0700);
87493 + sys_chdir((const char __force_user *)"/old");
87494
87495 /* try loading default modules from initrd */
87496 load_default_modules();
87497 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87498 current->flags &= ~PF_FREEZER_SKIP;
87499
87500 /* move initrd to rootfs' /old */
87501 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87502 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87503 /* switch root and cwd back to / of rootfs */
87504 - sys_chroot("..");
87505 + sys_chroot((const char __force_user *)"..");
87506
87507 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87508 - sys_chdir("/old");
87509 + sys_chdir((const char __force_user *)"/old");
87510 return;
87511 }
87512
87513 - sys_chdir("/");
87514 + sys_chdir((const char __force_user *)"/");
87515 ROOT_DEV = new_decode_dev(real_root_dev);
87516 mount_root();
87517
87518 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87519 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87520 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87521 if (!error)
87522 printk("okay\n");
87523 else {
87524 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87525 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87526 if (error == -ENOENT)
87527 printk("/initrd does not exist. Ignored.\n");
87528 else
87529 printk("failed\n");
87530 printk(KERN_NOTICE "Unmounting old root\n");
87531 - sys_umount("/old", MNT_DETACH);
87532 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87533 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87534 if (fd < 0) {
87535 error = fd;
87536 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87537 * mounted in the normal path.
87538 */
87539 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87540 - sys_unlink("/initrd.image");
87541 + sys_unlink((const char __force_user *)"/initrd.image");
87542 handle_initrd();
87543 return 1;
87544 }
87545 }
87546 - sys_unlink("/initrd.image");
87547 + sys_unlink((const char __force_user *)"/initrd.image");
87548 return 0;
87549 }
87550 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87551 index 8cb6db5..d729f50 100644
87552 --- a/init/do_mounts_md.c
87553 +++ b/init/do_mounts_md.c
87554 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87555 partitioned ? "_d" : "", minor,
87556 md_setup_args[ent].device_names);
87557
87558 - fd = sys_open(name, 0, 0);
87559 + fd = sys_open((char __force_user *)name, 0, 0);
87560 if (fd < 0) {
87561 printk(KERN_ERR "md: open failed - cannot start "
87562 "array %s\n", name);
87563 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87564 * array without it
87565 */
87566 sys_close(fd);
87567 - fd = sys_open(name, 0, 0);
87568 + fd = sys_open((char __force_user *)name, 0, 0);
87569 sys_ioctl(fd, BLKRRPART, 0);
87570 }
87571 sys_close(fd);
87572 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87573
87574 wait_for_device_probe();
87575
87576 - fd = sys_open("/dev/md0", 0, 0);
87577 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87578 if (fd >= 0) {
87579 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87580 sys_close(fd);
87581 diff --git a/init/init_task.c b/init/init_task.c
87582 index ba0a7f36..2bcf1d5 100644
87583 --- a/init/init_task.c
87584 +++ b/init/init_task.c
87585 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87586 * Initial thread structure. Alignment of this is handled by a special
87587 * linker map entry.
87588 */
87589 +#ifdef CONFIG_X86
87590 +union thread_union init_thread_union __init_task_data;
87591 +#else
87592 union thread_union init_thread_union __init_task_data =
87593 { INIT_THREAD_INFO(init_task) };
87594 +#endif
87595 diff --git a/init/initramfs.c b/init/initramfs.c
87596 index ad1bd77..dca2c1b 100644
87597 --- a/init/initramfs.c
87598 +++ b/init/initramfs.c
87599 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87600
87601 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87602 while (count) {
87603 - ssize_t rv = sys_write(fd, p, count);
87604 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87605
87606 if (rv < 0) {
87607 if (rv == -EINTR || rv == -EAGAIN)
87608 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87609 }
87610 }
87611
87612 -static long __init do_utime(char *filename, time_t mtime)
87613 +static long __init do_utime(char __force_user *filename, time_t mtime)
87614 {
87615 struct timespec t[2];
87616
87617 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87618 struct dir_entry *de, *tmp;
87619 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87620 list_del(&de->list);
87621 - do_utime(de->name, de->mtime);
87622 + do_utime((char __force_user *)de->name, de->mtime);
87623 kfree(de->name);
87624 kfree(de);
87625 }
87626 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87627 if (nlink >= 2) {
87628 char *old = find_link(major, minor, ino, mode, collected);
87629 if (old)
87630 - return (sys_link(old, collected) < 0) ? -1 : 1;
87631 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87632 }
87633 return 0;
87634 }
87635 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87636 {
87637 struct stat st;
87638
87639 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87640 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87641 if (S_ISDIR(st.st_mode))
87642 - sys_rmdir(path);
87643 + sys_rmdir((char __force_user *)path);
87644 else
87645 - sys_unlink(path);
87646 + sys_unlink((char __force_user *)path);
87647 }
87648 }
87649
87650 @@ -338,7 +338,7 @@ static int __init do_name(void)
87651 int openflags = O_WRONLY|O_CREAT;
87652 if (ml != 1)
87653 openflags |= O_TRUNC;
87654 - wfd = sys_open(collected, openflags, mode);
87655 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87656
87657 if (wfd >= 0) {
87658 sys_fchown(wfd, uid, gid);
87659 @@ -350,17 +350,17 @@ static int __init do_name(void)
87660 }
87661 }
87662 } else if (S_ISDIR(mode)) {
87663 - sys_mkdir(collected, mode);
87664 - sys_chown(collected, uid, gid);
87665 - sys_chmod(collected, mode);
87666 + sys_mkdir((char __force_user *)collected, mode);
87667 + sys_chown((char __force_user *)collected, uid, gid);
87668 + sys_chmod((char __force_user *)collected, mode);
87669 dir_add(collected, mtime);
87670 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87671 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87672 if (maybe_link() == 0) {
87673 - sys_mknod(collected, mode, rdev);
87674 - sys_chown(collected, uid, gid);
87675 - sys_chmod(collected, mode);
87676 - do_utime(collected, mtime);
87677 + sys_mknod((char __force_user *)collected, mode, rdev);
87678 + sys_chown((char __force_user *)collected, uid, gid);
87679 + sys_chmod((char __force_user *)collected, mode);
87680 + do_utime((char __force_user *)collected, mtime);
87681 }
87682 }
87683 return 0;
87684 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87685 if (xwrite(wfd, victim, body_len) != body_len)
87686 error("write error");
87687 sys_close(wfd);
87688 - do_utime(vcollected, mtime);
87689 + do_utime((char __force_user *)vcollected, mtime);
87690 kfree(vcollected);
87691 eat(body_len);
87692 state = SkipIt;
87693 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87694 {
87695 collected[N_ALIGN(name_len) + body_len] = '\0';
87696 clean_path(collected, 0);
87697 - sys_symlink(collected + N_ALIGN(name_len), collected);
87698 - sys_lchown(collected, uid, gid);
87699 - do_utime(collected, mtime);
87700 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87701 + sys_lchown((char __force_user *)collected, uid, gid);
87702 + do_utime((char __force_user *)collected, mtime);
87703 state = SkipIt;
87704 next_state = Reset;
87705 return 0;
87706 diff --git a/init/main.c b/init/main.c
87707 index 321d0ce..91b53e5 100644
87708 --- a/init/main.c
87709 +++ b/init/main.c
87710 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87711 static inline void mark_rodata_ro(void) { }
87712 #endif
87713
87714 +extern void grsecurity_init(void);
87715 +
87716 /*
87717 * Debug helper: via this flag we know that we are in 'early bootup code'
87718 * where only the boot processor is running with IRQ disabled. This means
87719 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87720
87721 __setup("reset_devices", set_reset_devices);
87722
87723 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87724 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87725 +static int __init setup_grsec_proc_gid(char *str)
87726 +{
87727 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87728 + return 1;
87729 +}
87730 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87731 +#endif
87732 +
87733 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87734 +unsigned long pax_user_shadow_base __read_only;
87735 +EXPORT_SYMBOL(pax_user_shadow_base);
87736 +extern char pax_enter_kernel_user[];
87737 +extern char pax_exit_kernel_user[];
87738 +#endif
87739 +
87740 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87741 +static int __init setup_pax_nouderef(char *str)
87742 +{
87743 +#ifdef CONFIG_X86_32
87744 + unsigned int cpu;
87745 + struct desc_struct *gdt;
87746 +
87747 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87748 + gdt = get_cpu_gdt_table(cpu);
87749 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87750 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87751 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87752 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87753 + }
87754 + loadsegment(ds, __KERNEL_DS);
87755 + loadsegment(es, __KERNEL_DS);
87756 + loadsegment(ss, __KERNEL_DS);
87757 +#else
87758 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87759 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87760 + clone_pgd_mask = ~(pgdval_t)0UL;
87761 + pax_user_shadow_base = 0UL;
87762 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87763 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87764 +#endif
87765 +
87766 + return 0;
87767 +}
87768 +early_param("pax_nouderef", setup_pax_nouderef);
87769 +
87770 +#ifdef CONFIG_X86_64
87771 +static int __init setup_pax_weakuderef(char *str)
87772 +{
87773 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87774 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87775 + return 1;
87776 +}
87777 +__setup("pax_weakuderef", setup_pax_weakuderef);
87778 +#endif
87779 +#endif
87780 +
87781 +#ifdef CONFIG_PAX_SOFTMODE
87782 +int pax_softmode;
87783 +
87784 +static int __init setup_pax_softmode(char *str)
87785 +{
87786 + get_option(&str, &pax_softmode);
87787 + return 1;
87788 +}
87789 +__setup("pax_softmode=", setup_pax_softmode);
87790 +#endif
87791 +
87792 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87793 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87794 static const char *panic_later, *panic_param;
87795 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87796 struct blacklist_entry *entry;
87797 char *fn_name;
87798
87799 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87800 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87801 if (!fn_name)
87802 return false;
87803
87804 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87805 {
87806 int count = preempt_count();
87807 int ret;
87808 - char msgbuf[64];
87809 + const char *msg1 = "", *msg2 = "";
87810
87811 if (initcall_blacklisted(fn))
87812 return -EPERM;
87813 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87814 else
87815 ret = fn();
87816
87817 - msgbuf[0] = 0;
87818 -
87819 if (preempt_count() != count) {
87820 - sprintf(msgbuf, "preemption imbalance ");
87821 + msg1 = " preemption imbalance";
87822 preempt_count_set(count);
87823 }
87824 if (irqs_disabled()) {
87825 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87826 + msg2 = " disabled interrupts";
87827 local_irq_enable();
87828 }
87829 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87830 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87831
87832 + add_latent_entropy();
87833 return ret;
87834 }
87835
87836 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
87837 {
87838 argv_init[0] = init_filename;
87839 return do_execve(getname_kernel(init_filename),
87840 - (const char __user *const __user *)argv_init,
87841 - (const char __user *const __user *)envp_init);
87842 + (const char __user *const __force_user *)argv_init,
87843 + (const char __user *const __force_user *)envp_init);
87844 }
87845
87846 static int try_to_run_init_process(const char *init_filename)
87847 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
87848 return ret;
87849 }
87850
87851 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87852 +extern int gr_init_ran;
87853 +#endif
87854 +
87855 static noinline void __init kernel_init_freeable(void);
87856
87857 static int __ref kernel_init(void *unused)
87858 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
87859 ramdisk_execute_command, ret);
87860 }
87861
87862 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87863 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
87864 + gr_init_ran = 1;
87865 +#endif
87866 +
87867 /*
87868 * We try each of these until one succeeds.
87869 *
87870 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
87871 do_basic_setup();
87872
87873 /* Open the /dev/console on the rootfs, this should never fail */
87874 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87875 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87876 pr_err("Warning: unable to open an initial console.\n");
87877
87878 (void) sys_dup(0);
87879 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
87880 if (!ramdisk_execute_command)
87881 ramdisk_execute_command = "/init";
87882
87883 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87884 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87885 ramdisk_execute_command = NULL;
87886 prepare_namespace();
87887 }
87888
87889 + grsecurity_init();
87890 +
87891 /*
87892 * Ok, we have completed the initial bootup, and
87893 * we're essentially up and running. Get rid of the
87894 diff --git a/ipc/compat.c b/ipc/compat.c
87895 index 9b3c85f..1c4d897 100644
87896 --- a/ipc/compat.c
87897 +++ b/ipc/compat.c
87898 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87899 COMPAT_SHMLBA);
87900 if (err < 0)
87901 return err;
87902 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87903 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87904 }
87905 case SHMDT:
87906 return sys_shmdt(compat_ptr(ptr));
87907 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87908 index e8075b2..76f2c6a 100644
87909 --- a/ipc/ipc_sysctl.c
87910 +++ b/ipc/ipc_sysctl.c
87911 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87912 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87913 void __user *buffer, size_t *lenp, loff_t *ppos)
87914 {
87915 - struct ctl_table ipc_table;
87916 + ctl_table_no_const ipc_table;
87917
87918 memcpy(&ipc_table, table, sizeof(ipc_table));
87919 ipc_table.data = get_ipc(table);
87920 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87921 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87922 void __user *buffer, size_t *lenp, loff_t *ppos)
87923 {
87924 - struct ctl_table ipc_table;
87925 + ctl_table_no_const ipc_table;
87926
87927 memcpy(&ipc_table, table, sizeof(ipc_table));
87928 ipc_table.data = get_ipc(table);
87929 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87930 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87931 void __user *buffer, size_t *lenp, loff_t *ppos)
87932 {
87933 - struct ctl_table ipc_table;
87934 + ctl_table_no_const ipc_table;
87935 size_t lenp_bef = *lenp;
87936 int rc;
87937
87938 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87939 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87940 void __user *buffer, size_t *lenp, loff_t *ppos)
87941 {
87942 - struct ctl_table ipc_table;
87943 + ctl_table_no_const ipc_table;
87944 memcpy(&ipc_table, table, sizeof(ipc_table));
87945 ipc_table.data = get_ipc(table);
87946
87947 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87948 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87949 void __user *buffer, size_t *lenp, loff_t *ppos)
87950 {
87951 - struct ctl_table ipc_table;
87952 + ctl_table_no_const ipc_table;
87953 int oldval;
87954 int rc;
87955
87956 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87957 index 68d4e95..1477ded 100644
87958 --- a/ipc/mq_sysctl.c
87959 +++ b/ipc/mq_sysctl.c
87960 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87961 static int proc_mq_dointvec(struct ctl_table *table, int write,
87962 void __user *buffer, size_t *lenp, loff_t *ppos)
87963 {
87964 - struct ctl_table mq_table;
87965 + ctl_table_no_const mq_table;
87966 memcpy(&mq_table, table, sizeof(mq_table));
87967 mq_table.data = get_mq(table);
87968
87969 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87970 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87971 void __user *buffer, size_t *lenp, loff_t *ppos)
87972 {
87973 - struct ctl_table mq_table;
87974 + ctl_table_no_const mq_table;
87975 memcpy(&mq_table, table, sizeof(mq_table));
87976 mq_table.data = get_mq(table);
87977
87978 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87979 index 4fcf39a..d3cc2ec 100644
87980 --- a/ipc/mqueue.c
87981 +++ b/ipc/mqueue.c
87982 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87983 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87984 info->attr.mq_msgsize);
87985
87986 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87987 spin_lock(&mq_lock);
87988 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87989 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87990 diff --git a/ipc/shm.c b/ipc/shm.c
87991 index 0145479..3d27947 100644
87992 --- a/ipc/shm.c
87993 +++ b/ipc/shm.c
87994 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87995 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87996 #endif
87997
87998 +#ifdef CONFIG_GRKERNSEC
87999 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88000 + const u64 shm_createtime, const kuid_t cuid,
88001 + const int shmid);
88002 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88003 + const u64 shm_createtime);
88004 +#endif
88005 +
88006 void shm_init_ns(struct ipc_namespace *ns)
88007 {
88008 ns->shm_ctlmax = SHMMAX;
88009 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88010 shp->shm_lprid = 0;
88011 shp->shm_atim = shp->shm_dtim = 0;
88012 shp->shm_ctim = get_seconds();
88013 +#ifdef CONFIG_GRKERNSEC
88014 + shp->shm_createtime = ktime_get_ns();
88015 +#endif
88016 shp->shm_segsz = size;
88017 shp->shm_nattch = 0;
88018 shp->shm_file = file;
88019 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88020 f_mode = FMODE_READ | FMODE_WRITE;
88021 }
88022 if (shmflg & SHM_EXEC) {
88023 +
88024 +#ifdef CONFIG_PAX_MPROTECT
88025 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88026 + goto out;
88027 +#endif
88028 +
88029 prot |= PROT_EXEC;
88030 acc_mode |= S_IXUGO;
88031 }
88032 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88033 if (err)
88034 goto out_unlock;
88035
88036 +#ifdef CONFIG_GRKERNSEC
88037 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88038 + shp->shm_perm.cuid, shmid) ||
88039 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88040 + err = -EACCES;
88041 + goto out_unlock;
88042 + }
88043 +#endif
88044 +
88045 ipc_lock_object(&shp->shm_perm);
88046
88047 /* check if shm_destroy() is tearing down shp */
88048 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88049 path = shp->shm_file->f_path;
88050 path_get(&path);
88051 shp->shm_nattch++;
88052 +#ifdef CONFIG_GRKERNSEC
88053 + shp->shm_lapid = current->pid;
88054 +#endif
88055 size = i_size_read(path.dentry->d_inode);
88056 ipc_unlock_object(&shp->shm_perm);
88057 rcu_read_unlock();
88058 diff --git a/ipc/util.c b/ipc/util.c
88059 index 88adc32..3867c68 100644
88060 --- a/ipc/util.c
88061 +++ b/ipc/util.c
88062 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88063 int (*show)(struct seq_file *, void *);
88064 };
88065
88066 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88067 +
88068 static void ipc_memory_notifier(struct work_struct *work)
88069 {
88070 ipcns_notify(IPCNS_MEMCHANGED);
88071 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88072 granted_mode >>= 6;
88073 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88074 granted_mode >>= 3;
88075 +
88076 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88077 + return -1;
88078 +
88079 /* is there some bit set in requested_mode but not in granted_mode? */
88080 if ((requested_mode & ~granted_mode & 0007) &&
88081 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88082 diff --git a/kernel/audit.c b/kernel/audit.c
88083 index c6df990..fde80b4 100644
88084 --- a/kernel/audit.c
88085 +++ b/kernel/audit.c
88086 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88087 3) suppressed due to audit_rate_limit
88088 4) suppressed due to audit_backlog_limit
88089 */
88090 -static atomic_t audit_lost = ATOMIC_INIT(0);
88091 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88092
88093 /* The netlink socket. */
88094 static struct sock *audit_sock;
88095 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88096 unsigned long now;
88097 int print;
88098
88099 - atomic_inc(&audit_lost);
88100 + atomic_inc_unchecked(&audit_lost);
88101
88102 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88103
88104 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88105 if (print) {
88106 if (printk_ratelimit())
88107 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88108 - atomic_read(&audit_lost),
88109 + atomic_read_unchecked(&audit_lost),
88110 audit_rate_limit,
88111 audit_backlog_limit);
88112 audit_panic(message);
88113 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88114 s.pid = audit_pid;
88115 s.rate_limit = audit_rate_limit;
88116 s.backlog_limit = audit_backlog_limit;
88117 - s.lost = atomic_read(&audit_lost);
88118 + s.lost = atomic_read_unchecked(&audit_lost);
88119 s.backlog = skb_queue_len(&audit_skb_queue);
88120 s.version = AUDIT_VERSION_LATEST;
88121 s.backlog_wait_time = audit_backlog_wait_time;
88122 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88123 index e420a0c..38137fa 100644
88124 --- a/kernel/auditsc.c
88125 +++ b/kernel/auditsc.c
88126 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88127 }
88128
88129 /* global counter which is incremented every time something logs in */
88130 -static atomic_t session_id = ATOMIC_INIT(0);
88131 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88132
88133 static int audit_set_loginuid_perm(kuid_t loginuid)
88134 {
88135 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88136
88137 /* are we setting or clearing? */
88138 if (uid_valid(loginuid))
88139 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88140 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88141
88142 task->sessionid = sessionid;
88143 task->loginuid = loginuid;
88144 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88145 index d6594e4..597264b 100644
88146 --- a/kernel/bpf/core.c
88147 +++ b/kernel/bpf/core.c
88148 @@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88149 * random section of illegal instructions.
88150 */
88151 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88152 - hdr = module_alloc(size);
88153 + hdr = module_alloc_exec(size);
88154 if (hdr == NULL)
88155 return NULL;
88156
88157 /* Fill space with illegal/arch-dep instructions. */
88158 bpf_fill_ill_insns(hdr, size);
88159
88160 + pax_open_kernel();
88161 hdr->pages = size / PAGE_SIZE;
88162 + pax_close_kernel();
88163 +
88164 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88165 PAGE_SIZE - sizeof(*hdr));
88166 start = (prandom_u32() % hole) & ~(alignment - 1);
88167 @@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88168
88169 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88170 {
88171 - module_free(NULL, hdr);
88172 + module_free_exec(NULL, hdr);
88173 }
88174 #endif /* CONFIG_BPF_JIT */
88175
88176 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88177 index ba61c8c..c60c486 100644
88178 --- a/kernel/bpf/syscall.c
88179 +++ b/kernel/bpf/syscall.c
88180 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88181 int err;
88182
88183 /* the syscall is limited to root temporarily. This restriction will be
88184 - * lifted when security audit is clean. Note that eBPF+tracing must have
88185 - * this restriction, since it may pass kernel data to user space
88186 + * lifted by upstream when a half-assed security audit is clean. Note
88187 + * that eBPF+tracing must have this restriction, since it may pass
88188 + * kernel data to user space
88189 */
88190 if (!capable(CAP_SYS_ADMIN))
88191 return -EPERM;
88192 +#ifdef CONFIG_GRKERNSEC
88193 + return -EPERM;
88194 +#endif
88195
88196 if (!access_ok(VERIFY_READ, uattr, 1))
88197 return -EFAULT;
88198 diff --git a/kernel/capability.c b/kernel/capability.c
88199 index 989f5bf..d317ca0 100644
88200 --- a/kernel/capability.c
88201 +++ b/kernel/capability.c
88202 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88203 * before modification is attempted and the application
88204 * fails.
88205 */
88206 + if (tocopy > ARRAY_SIZE(kdata))
88207 + return -EFAULT;
88208 +
88209 if (copy_to_user(dataptr, kdata, tocopy
88210 * sizeof(struct __user_cap_data_struct))) {
88211 return -EFAULT;
88212 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88213 int ret;
88214
88215 rcu_read_lock();
88216 - ret = security_capable(__task_cred(t), ns, cap);
88217 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88218 + gr_task_is_capable(t, __task_cred(t), cap);
88219 rcu_read_unlock();
88220
88221 - return (ret == 0);
88222 + return ret;
88223 }
88224
88225 /**
88226 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88227 int ret;
88228
88229 rcu_read_lock();
88230 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88231 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88232 rcu_read_unlock();
88233
88234 - return (ret == 0);
88235 + return ret;
88236 }
88237
88238 /**
88239 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88240 BUG();
88241 }
88242
88243 - if (security_capable(current_cred(), ns, cap) == 0) {
88244 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88245 current->flags |= PF_SUPERPRIV;
88246 return true;
88247 }
88248 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88249 }
88250 EXPORT_SYMBOL(ns_capable);
88251
88252 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88253 +{
88254 + if (unlikely(!cap_valid(cap))) {
88255 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88256 + BUG();
88257 + }
88258 +
88259 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88260 + current->flags |= PF_SUPERPRIV;
88261 + return true;
88262 + }
88263 + return false;
88264 +}
88265 +EXPORT_SYMBOL(ns_capable_nolog);
88266 +
88267 /**
88268 * file_ns_capable - Determine if the file's opener had a capability in effect
88269 * @file: The file we want to check
88270 @@ -427,6 +446,12 @@ bool capable(int cap)
88271 }
88272 EXPORT_SYMBOL(capable);
88273
88274 +bool capable_nolog(int cap)
88275 +{
88276 + return ns_capable_nolog(&init_user_ns, cap);
88277 +}
88278 +EXPORT_SYMBOL(capable_nolog);
88279 +
88280 /**
88281 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88282 * @inode: The inode in question
88283 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88284 kgid_has_mapping(ns, inode->i_gid);
88285 }
88286 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88287 +
88288 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88289 +{
88290 + struct user_namespace *ns = current_user_ns();
88291 +
88292 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88293 + kgid_has_mapping(ns, inode->i_gid);
88294 +}
88295 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88296 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88297 index 136ecea..45157a6 100644
88298 --- a/kernel/cgroup.c
88299 +++ b/kernel/cgroup.c
88300 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88301 if (!pathbuf || !agentbuf)
88302 goto out;
88303
88304 + if (agentbuf[0] == '\0')
88305 + goto out;
88306 +
88307 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88308 if (!path)
88309 goto out;
88310 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88311 struct task_struct *task;
88312 int count = 0;
88313
88314 - seq_printf(seq, "css_set %p\n", cset);
88315 + seq_printf(seq, "css_set %pK\n", cset);
88316
88317 list_for_each_entry(task, &cset->tasks, cg_list) {
88318 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88319 diff --git a/kernel/compat.c b/kernel/compat.c
88320 index ebb3c36..1df606e 100644
88321 --- a/kernel/compat.c
88322 +++ b/kernel/compat.c
88323 @@ -13,6 +13,7 @@
88324
88325 #include <linux/linkage.h>
88326 #include <linux/compat.h>
88327 +#include <linux/module.h>
88328 #include <linux/errno.h>
88329 #include <linux/time.h>
88330 #include <linux/signal.h>
88331 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88332 mm_segment_t oldfs;
88333 long ret;
88334
88335 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88336 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88337 oldfs = get_fs();
88338 set_fs(KERNEL_DS);
88339 ret = hrtimer_nanosleep_restart(restart);
88340 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88341 oldfs = get_fs();
88342 set_fs(KERNEL_DS);
88343 ret = hrtimer_nanosleep(&tu,
88344 - rmtp ? (struct timespec __user *)&rmt : NULL,
88345 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88346 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88347 set_fs(oldfs);
88348
88349 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88350 mm_segment_t old_fs = get_fs();
88351
88352 set_fs(KERNEL_DS);
88353 - ret = sys_sigpending((old_sigset_t __user *) &s);
88354 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88355 set_fs(old_fs);
88356 if (ret == 0)
88357 ret = put_user(s, set);
88358 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88359 mm_segment_t old_fs = get_fs();
88360
88361 set_fs(KERNEL_DS);
88362 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88363 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88364 set_fs(old_fs);
88365
88366 if (!ret) {
88367 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88368 set_fs (KERNEL_DS);
88369 ret = sys_wait4(pid,
88370 (stat_addr ?
88371 - (unsigned int __user *) &status : NULL),
88372 - options, (struct rusage __user *) &r);
88373 + (unsigned int __force_user *) &status : NULL),
88374 + options, (struct rusage __force_user *) &r);
88375 set_fs (old_fs);
88376
88377 if (ret > 0) {
88378 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88379 memset(&info, 0, sizeof(info));
88380
88381 set_fs(KERNEL_DS);
88382 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88383 - uru ? (struct rusage __user *)&ru : NULL);
88384 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88385 + uru ? (struct rusage __force_user *)&ru : NULL);
88386 set_fs(old_fs);
88387
88388 if ((ret < 0) || (info.si_signo == 0))
88389 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88390 oldfs = get_fs();
88391 set_fs(KERNEL_DS);
88392 err = sys_timer_settime(timer_id, flags,
88393 - (struct itimerspec __user *) &newts,
88394 - (struct itimerspec __user *) &oldts);
88395 + (struct itimerspec __force_user *) &newts,
88396 + (struct itimerspec __force_user *) &oldts);
88397 set_fs(oldfs);
88398 if (!err && old && put_compat_itimerspec(old, &oldts))
88399 return -EFAULT;
88400 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88401 oldfs = get_fs();
88402 set_fs(KERNEL_DS);
88403 err = sys_timer_gettime(timer_id,
88404 - (struct itimerspec __user *) &ts);
88405 + (struct itimerspec __force_user *) &ts);
88406 set_fs(oldfs);
88407 if (!err && put_compat_itimerspec(setting, &ts))
88408 return -EFAULT;
88409 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88410 oldfs = get_fs();
88411 set_fs(KERNEL_DS);
88412 err = sys_clock_settime(which_clock,
88413 - (struct timespec __user *) &ts);
88414 + (struct timespec __force_user *) &ts);
88415 set_fs(oldfs);
88416 return err;
88417 }
88418 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88419 oldfs = get_fs();
88420 set_fs(KERNEL_DS);
88421 err = sys_clock_gettime(which_clock,
88422 - (struct timespec __user *) &ts);
88423 + (struct timespec __force_user *) &ts);
88424 set_fs(oldfs);
88425 if (!err && compat_put_timespec(&ts, tp))
88426 return -EFAULT;
88427 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88428
88429 oldfs = get_fs();
88430 set_fs(KERNEL_DS);
88431 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88432 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88433 set_fs(oldfs);
88434
88435 err = compat_put_timex(utp, &txc);
88436 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88437 oldfs = get_fs();
88438 set_fs(KERNEL_DS);
88439 err = sys_clock_getres(which_clock,
88440 - (struct timespec __user *) &ts);
88441 + (struct timespec __force_user *) &ts);
88442 set_fs(oldfs);
88443 if (!err && tp && compat_put_timespec(&ts, tp))
88444 return -EFAULT;
88445 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88446 struct timespec tu;
88447 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88448
88449 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88450 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88451 oldfs = get_fs();
88452 set_fs(KERNEL_DS);
88453 err = clock_nanosleep_restart(restart);
88454 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88455 oldfs = get_fs();
88456 set_fs(KERNEL_DS);
88457 err = sys_clock_nanosleep(which_clock, flags,
88458 - (struct timespec __user *) &in,
88459 - (struct timespec __user *) &out);
88460 + (struct timespec __force_user *) &in,
88461 + (struct timespec __force_user *) &out);
88462 set_fs(oldfs);
88463
88464 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88465 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88466 mm_segment_t old_fs = get_fs();
88467
88468 set_fs(KERNEL_DS);
88469 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88470 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88471 set_fs(old_fs);
88472 if (compat_put_timespec(&t, interval))
88473 return -EFAULT;
88474 diff --git a/kernel/configs.c b/kernel/configs.c
88475 index c18b1f1..b9a0132 100644
88476 --- a/kernel/configs.c
88477 +++ b/kernel/configs.c
88478 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88479 struct proc_dir_entry *entry;
88480
88481 /* create the current config file */
88482 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88483 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88484 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88485 + &ikconfig_file_ops);
88486 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88487 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88488 + &ikconfig_file_ops);
88489 +#endif
88490 +#else
88491 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88492 &ikconfig_file_ops);
88493 +#endif
88494 +
88495 if (!entry)
88496 return -ENOMEM;
88497
88498 diff --git a/kernel/cred.c b/kernel/cred.c
88499 index e0573a4..26c0fd3 100644
88500 --- a/kernel/cred.c
88501 +++ b/kernel/cred.c
88502 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88503 validate_creds(cred);
88504 alter_cred_subscribers(cred, -1);
88505 put_cred(cred);
88506 +
88507 +#ifdef CONFIG_GRKERNSEC_SETXID
88508 + cred = (struct cred *) tsk->delayed_cred;
88509 + if (cred != NULL) {
88510 + tsk->delayed_cred = NULL;
88511 + validate_creds(cred);
88512 + alter_cred_subscribers(cred, -1);
88513 + put_cred(cred);
88514 + }
88515 +#endif
88516 }
88517
88518 /**
88519 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88520 * Always returns 0 thus allowing this function to be tail-called at the end
88521 * of, say, sys_setgid().
88522 */
88523 -int commit_creds(struct cred *new)
88524 +static int __commit_creds(struct cred *new)
88525 {
88526 struct task_struct *task = current;
88527 const struct cred *old = task->real_cred;
88528 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88529
88530 get_cred(new); /* we will require a ref for the subj creds too */
88531
88532 + gr_set_role_label(task, new->uid, new->gid);
88533 +
88534 /* dumpability changes */
88535 if (!uid_eq(old->euid, new->euid) ||
88536 !gid_eq(old->egid, new->egid) ||
88537 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88538 put_cred(old);
88539 return 0;
88540 }
88541 +#ifdef CONFIG_GRKERNSEC_SETXID
88542 +extern int set_user(struct cred *new);
88543 +
88544 +void gr_delayed_cred_worker(void)
88545 +{
88546 + const struct cred *new = current->delayed_cred;
88547 + struct cred *ncred;
88548 +
88549 + current->delayed_cred = NULL;
88550 +
88551 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88552 + // from doing get_cred on it when queueing this
88553 + put_cred(new);
88554 + return;
88555 + } else if (new == NULL)
88556 + return;
88557 +
88558 + ncred = prepare_creds();
88559 + if (!ncred)
88560 + goto die;
88561 + // uids
88562 + ncred->uid = new->uid;
88563 + ncred->euid = new->euid;
88564 + ncred->suid = new->suid;
88565 + ncred->fsuid = new->fsuid;
88566 + // gids
88567 + ncred->gid = new->gid;
88568 + ncred->egid = new->egid;
88569 + ncred->sgid = new->sgid;
88570 + ncred->fsgid = new->fsgid;
88571 + // groups
88572 + set_groups(ncred, new->group_info);
88573 + // caps
88574 + ncred->securebits = new->securebits;
88575 + ncred->cap_inheritable = new->cap_inheritable;
88576 + ncred->cap_permitted = new->cap_permitted;
88577 + ncred->cap_effective = new->cap_effective;
88578 + ncred->cap_bset = new->cap_bset;
88579 +
88580 + if (set_user(ncred)) {
88581 + abort_creds(ncred);
88582 + goto die;
88583 + }
88584 +
88585 + // from doing get_cred on it when queueing this
88586 + put_cred(new);
88587 +
88588 + __commit_creds(ncred);
88589 + return;
88590 +die:
88591 + // from doing get_cred on it when queueing this
88592 + put_cred(new);
88593 + do_group_exit(SIGKILL);
88594 +}
88595 +#endif
88596 +
88597 +int commit_creds(struct cred *new)
88598 +{
88599 +#ifdef CONFIG_GRKERNSEC_SETXID
88600 + int ret;
88601 + int schedule_it = 0;
88602 + struct task_struct *t;
88603 + unsigned oldsecurebits = current_cred()->securebits;
88604 +
88605 + /* we won't get called with tasklist_lock held for writing
88606 + and interrupts disabled as the cred struct in that case is
88607 + init_cred
88608 + */
88609 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88610 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88611 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88612 + schedule_it = 1;
88613 + }
88614 + ret = __commit_creds(new);
88615 + if (schedule_it) {
88616 + rcu_read_lock();
88617 + read_lock(&tasklist_lock);
88618 + for (t = next_thread(current); t != current;
88619 + t = next_thread(t)) {
88620 + /* we'll check if the thread has uid 0 in
88621 + * the delayed worker routine
88622 + */
88623 + if (task_securebits(t) == oldsecurebits &&
88624 + t->delayed_cred == NULL) {
88625 + t->delayed_cred = get_cred(new);
88626 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88627 + set_tsk_need_resched(t);
88628 + }
88629 + }
88630 + read_unlock(&tasklist_lock);
88631 + rcu_read_unlock();
88632 + }
88633 +
88634 + return ret;
88635 +#else
88636 + return __commit_creds(new);
88637 +#endif
88638 +}
88639 +
88640 EXPORT_SYMBOL(commit_creds);
88641
88642 /**
88643 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88644 index 1adf62b..7736e06 100644
88645 --- a/kernel/debug/debug_core.c
88646 +++ b/kernel/debug/debug_core.c
88647 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88648 */
88649 static atomic_t masters_in_kgdb;
88650 static atomic_t slaves_in_kgdb;
88651 -static atomic_t kgdb_break_tasklet_var;
88652 +static atomic_unchecked_t kgdb_break_tasklet_var;
88653 atomic_t kgdb_setting_breakpoint;
88654
88655 struct task_struct *kgdb_usethread;
88656 @@ -134,7 +134,7 @@ int kgdb_single_step;
88657 static pid_t kgdb_sstep_pid;
88658
88659 /* to keep track of the CPU which is doing the single stepping*/
88660 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88661 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88662
88663 /*
88664 * If you are debugging a problem where roundup (the collection of
88665 @@ -549,7 +549,7 @@ return_normal:
88666 * kernel will only try for the value of sstep_tries before
88667 * giving up and continuing on.
88668 */
88669 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88670 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88671 (kgdb_info[cpu].task &&
88672 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88673 atomic_set(&kgdb_active, -1);
88674 @@ -647,8 +647,8 @@ cpu_master_loop:
88675 }
88676
88677 kgdb_restore:
88678 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88679 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88680 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88681 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88682 if (kgdb_info[sstep_cpu].task)
88683 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88684 else
88685 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88686 static void kgdb_tasklet_bpt(unsigned long ing)
88687 {
88688 kgdb_breakpoint();
88689 - atomic_set(&kgdb_break_tasklet_var, 0);
88690 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88691 }
88692
88693 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88694
88695 void kgdb_schedule_breakpoint(void)
88696 {
88697 - if (atomic_read(&kgdb_break_tasklet_var) ||
88698 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88699 atomic_read(&kgdb_active) != -1 ||
88700 atomic_read(&kgdb_setting_breakpoint))
88701 return;
88702 - atomic_inc(&kgdb_break_tasklet_var);
88703 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88704 tasklet_schedule(&kgdb_tasklet_breakpoint);
88705 }
88706 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88707 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88708 index 379650b..30c5180 100644
88709 --- a/kernel/debug/kdb/kdb_main.c
88710 +++ b/kernel/debug/kdb/kdb_main.c
88711 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88712 continue;
88713
88714 kdb_printf("%-20s%8u 0x%p ", mod->name,
88715 - mod->core_size, (void *)mod);
88716 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88717 #ifdef CONFIG_MODULE_UNLOAD
88718 kdb_printf("%4ld ", module_refcount(mod));
88719 #endif
88720 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88721 kdb_printf(" (Loading)");
88722 else
88723 kdb_printf(" (Live)");
88724 - kdb_printf(" 0x%p", mod->module_core);
88725 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88726
88727 #ifdef CONFIG_MODULE_UNLOAD
88728 {
88729 diff --git a/kernel/events/core.c b/kernel/events/core.c
88730 index 2ab0238..bf89262f5 100644
88731 --- a/kernel/events/core.c
88732 +++ b/kernel/events/core.c
88733 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88734 * 0 - disallow raw tracepoint access for unpriv
88735 * 1 - disallow cpu events for unpriv
88736 * 2 - disallow kernel profiling for unpriv
88737 + * 3 - disallow all unpriv perf event use
88738 */
88739 -int sysctl_perf_event_paranoid __read_mostly = 1;
88740 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88741 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88742 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88743 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88744 +#else
88745 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88746 +#endif
88747
88748 /* Minimum for 512 kiB + 1 user control page */
88749 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88750 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88751
88752 tmp *= sysctl_perf_cpu_time_max_percent;
88753 do_div(tmp, 100);
88754 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88755 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88756 }
88757
88758 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88759 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88760 }
88761 }
88762
88763 -static atomic64_t perf_event_id;
88764 +static atomic64_unchecked_t perf_event_id;
88765
88766 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88767 enum event_type_t event_type);
88768 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88769
88770 static inline u64 perf_event_count(struct perf_event *event)
88771 {
88772 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88773 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88774 }
88775
88776 static u64 perf_event_read(struct perf_event *event)
88777 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88778 mutex_lock(&event->child_mutex);
88779 total += perf_event_read(event);
88780 *enabled += event->total_time_enabled +
88781 - atomic64_read(&event->child_total_time_enabled);
88782 + atomic64_read_unchecked(&event->child_total_time_enabled);
88783 *running += event->total_time_running +
88784 - atomic64_read(&event->child_total_time_running);
88785 + atomic64_read_unchecked(&event->child_total_time_running);
88786
88787 list_for_each_entry(child, &event->child_list, child_list) {
88788 total += perf_event_read(child);
88789 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88790 userpg->offset -= local64_read(&event->hw.prev_count);
88791
88792 userpg->time_enabled = enabled +
88793 - atomic64_read(&event->child_total_time_enabled);
88794 + atomic64_read_unchecked(&event->child_total_time_enabled);
88795
88796 userpg->time_running = running +
88797 - atomic64_read(&event->child_total_time_running);
88798 + atomic64_read_unchecked(&event->child_total_time_running);
88799
88800 arch_perf_update_userpage(userpg, now);
88801
88802 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88803
88804 /* Data. */
88805 sp = perf_user_stack_pointer(regs);
88806 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88807 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88808 dyn_size = dump_size - rem;
88809
88810 perf_output_skip(handle, rem);
88811 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88812 values[n++] = perf_event_count(event);
88813 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88814 values[n++] = enabled +
88815 - atomic64_read(&event->child_total_time_enabled);
88816 + atomic64_read_unchecked(&event->child_total_time_enabled);
88817 }
88818 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88819 values[n++] = running +
88820 - atomic64_read(&event->child_total_time_running);
88821 + atomic64_read_unchecked(&event->child_total_time_running);
88822 }
88823 if (read_format & PERF_FORMAT_ID)
88824 values[n++] = primary_event_id(event);
88825 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88826 event->parent = parent_event;
88827
88828 event->ns = get_pid_ns(task_active_pid_ns(current));
88829 - event->id = atomic64_inc_return(&perf_event_id);
88830 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
88831
88832 event->state = PERF_EVENT_STATE_INACTIVE;
88833
88834 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
88835 if (flags & ~PERF_FLAG_ALL)
88836 return -EINVAL;
88837
88838 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88839 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88840 + return -EACCES;
88841 +#endif
88842 +
88843 err = perf_copy_attr(attr_uptr, &attr);
88844 if (err)
88845 return err;
88846 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
88847 /*
88848 * Add back the child's count to the parent's count:
88849 */
88850 - atomic64_add(child_val, &parent_event->child_count);
88851 - atomic64_add(child_event->total_time_enabled,
88852 + atomic64_add_unchecked(child_val, &parent_event->child_count);
88853 + atomic64_add_unchecked(child_event->total_time_enabled,
88854 &parent_event->child_total_time_enabled);
88855 - atomic64_add(child_event->total_time_running,
88856 + atomic64_add_unchecked(child_event->total_time_running,
88857 &parent_event->child_total_time_running);
88858
88859 /*
88860 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88861 index 569b2187..19940d9 100644
88862 --- a/kernel/events/internal.h
88863 +++ b/kernel/events/internal.h
88864 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88865 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88866 }
88867
88868 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88869 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88870 static inline unsigned long \
88871 func_name(struct perf_output_handle *handle, \
88872 - const void *buf, unsigned long len) \
88873 + const void user *buf, unsigned long len) \
88874 { \
88875 unsigned long size, written; \
88876 \
88877 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88878 return 0;
88879 }
88880
88881 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88882 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88883
88884 static inline unsigned long
88885 memcpy_skip(void *dst, const void *src, unsigned long n)
88886 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88887 return 0;
88888 }
88889
88890 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88891 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88892
88893 #ifndef arch_perf_out_copy_user
88894 #define arch_perf_out_copy_user arch_perf_out_copy_user
88895 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88896 }
88897 #endif
88898
88899 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88900 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88901
88902 /* Callchain handling */
88903 extern struct perf_callchain_entry *
88904 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88905 index ed8f2cd..fe8030c 100644
88906 --- a/kernel/events/uprobes.c
88907 +++ b/kernel/events/uprobes.c
88908 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88909 {
88910 struct page *page;
88911 uprobe_opcode_t opcode;
88912 - int result;
88913 + long result;
88914
88915 pagefault_disable();
88916 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88917 diff --git a/kernel/exit.c b/kernel/exit.c
88918 index 2116aac..d95df2a 100644
88919 --- a/kernel/exit.c
88920 +++ b/kernel/exit.c
88921 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
88922 struct task_struct *leader;
88923 int zap_leader;
88924 repeat:
88925 +#ifdef CONFIG_NET
88926 + gr_del_task_from_ip_table(p);
88927 +#endif
88928 +
88929 /* don't need to get the RCU readlock here - the process is dead and
88930 * can't be modifying its own credentials. But shut RCU-lockdep up */
88931 rcu_read_lock();
88932 @@ -670,6 +674,8 @@ void do_exit(long code)
88933 int group_dead;
88934 TASKS_RCU(int tasks_rcu_i);
88935
88936 + set_fs(USER_DS);
88937 +
88938 profile_task_exit(tsk);
88939
88940 WARN_ON(blk_needs_flush_plug(tsk));
88941 @@ -686,7 +692,6 @@ void do_exit(long code)
88942 * mm_release()->clear_child_tid() from writing to a user-controlled
88943 * kernel address.
88944 */
88945 - set_fs(USER_DS);
88946
88947 ptrace_event(PTRACE_EVENT_EXIT, code);
88948
88949 @@ -744,6 +749,9 @@ void do_exit(long code)
88950 tsk->exit_code = code;
88951 taskstats_exit(tsk, group_dead);
88952
88953 + gr_acl_handle_psacct(tsk, code);
88954 + gr_acl_handle_exit();
88955 +
88956 exit_mm(tsk);
88957
88958 if (group_dead)
88959 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
88960 * Take down every thread in the group. This is called by fatal signals
88961 * as well as by sys_exit_group (below).
88962 */
88963 -void
88964 +__noreturn void
88965 do_group_exit(int exit_code)
88966 {
88967 struct signal_struct *sig = current->signal;
88968 diff --git a/kernel/fork.c b/kernel/fork.c
88969 index 9b7d746..5b898ab 100644
88970 --- a/kernel/fork.c
88971 +++ b/kernel/fork.c
88972 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
88973 # endif
88974 #endif
88975
88976 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88977 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88978 + int node, void **lowmem_stack)
88979 +{
88980 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
88981 + void *ret = NULL;
88982 + unsigned int i;
88983 +
88984 + *lowmem_stack = alloc_thread_info_node(tsk, node);
88985 + if (*lowmem_stack == NULL)
88986 + goto out;
88987 +
88988 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
88989 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
88990 +
88991 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
88992 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
88993 + if (ret == NULL) {
88994 + free_thread_info(*lowmem_stack);
88995 + *lowmem_stack = NULL;
88996 + }
88997 +
88998 +out:
88999 + return ret;
89000 +}
89001 +
89002 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89003 +{
89004 + unmap_process_stacks(tsk);
89005 +}
89006 +#else
89007 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89008 + int node, void **lowmem_stack)
89009 +{
89010 + return alloc_thread_info_node(tsk, node);
89011 +}
89012 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89013 +{
89014 + free_thread_info(ti);
89015 +}
89016 +#endif
89017 +
89018 /* SLAB cache for signal_struct structures (tsk->signal) */
89019 static struct kmem_cache *signal_cachep;
89020
89021 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89022 /* SLAB cache for mm_struct structures (tsk->mm) */
89023 static struct kmem_cache *mm_cachep;
89024
89025 -static void account_kernel_stack(struct thread_info *ti, int account)
89026 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89027 {
89028 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89029 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89030 +#else
89031 struct zone *zone = page_zone(virt_to_page(ti));
89032 +#endif
89033
89034 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89035 }
89036
89037 void free_task(struct task_struct *tsk)
89038 {
89039 - account_kernel_stack(tsk->stack, -1);
89040 + account_kernel_stack(tsk, tsk->stack, -1);
89041 arch_release_thread_info(tsk->stack);
89042 - free_thread_info(tsk->stack);
89043 + gr_free_thread_info(tsk, tsk->stack);
89044 rt_mutex_debug_task_free(tsk);
89045 ftrace_graph_exit_task(tsk);
89046 put_seccomp_filter(tsk);
89047 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89048 {
89049 struct task_struct *tsk;
89050 struct thread_info *ti;
89051 + void *lowmem_stack;
89052 int node = tsk_fork_get_node(orig);
89053 int err;
89054
89055 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89056 if (!tsk)
89057 return NULL;
89058
89059 - ti = alloc_thread_info_node(tsk, node);
89060 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89061 if (!ti)
89062 goto free_tsk;
89063
89064 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89065 goto free_ti;
89066
89067 tsk->stack = ti;
89068 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89069 + tsk->lowmem_stack = lowmem_stack;
89070 +#endif
89071 #ifdef CONFIG_SECCOMP
89072 /*
89073 * We must handle setting up seccomp filters once we're under
89074 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89075 set_task_stack_end_magic(tsk);
89076
89077 #ifdef CONFIG_CC_STACKPROTECTOR
89078 - tsk->stack_canary = get_random_int();
89079 + tsk->stack_canary = pax_get_random_long();
89080 #endif
89081
89082 /*
89083 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89084 tsk->splice_pipe = NULL;
89085 tsk->task_frag.page = NULL;
89086
89087 - account_kernel_stack(ti, 1);
89088 + account_kernel_stack(tsk, ti, 1);
89089
89090 return tsk;
89091
89092 free_ti:
89093 - free_thread_info(ti);
89094 + gr_free_thread_info(tsk, ti);
89095 free_tsk:
89096 free_task_struct(tsk);
89097 return NULL;
89098 }
89099
89100 #ifdef CONFIG_MMU
89101 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89102 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89103 +{
89104 + struct vm_area_struct *tmp;
89105 + unsigned long charge;
89106 + struct file *file;
89107 + int retval;
89108 +
89109 + charge = 0;
89110 + if (mpnt->vm_flags & VM_ACCOUNT) {
89111 + unsigned long len = vma_pages(mpnt);
89112 +
89113 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89114 + goto fail_nomem;
89115 + charge = len;
89116 + }
89117 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89118 + if (!tmp)
89119 + goto fail_nomem;
89120 + *tmp = *mpnt;
89121 + tmp->vm_mm = mm;
89122 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89123 + retval = vma_dup_policy(mpnt, tmp);
89124 + if (retval)
89125 + goto fail_nomem_policy;
89126 + if (anon_vma_fork(tmp, mpnt))
89127 + goto fail_nomem_anon_vma_fork;
89128 + tmp->vm_flags &= ~VM_LOCKED;
89129 + tmp->vm_next = tmp->vm_prev = NULL;
89130 + tmp->vm_mirror = NULL;
89131 + file = tmp->vm_file;
89132 + if (file) {
89133 + struct inode *inode = file_inode(file);
89134 + struct address_space *mapping = file->f_mapping;
89135 +
89136 + get_file(file);
89137 + if (tmp->vm_flags & VM_DENYWRITE)
89138 + atomic_dec(&inode->i_writecount);
89139 + mutex_lock(&mapping->i_mmap_mutex);
89140 + if (tmp->vm_flags & VM_SHARED)
89141 + atomic_inc(&mapping->i_mmap_writable);
89142 + flush_dcache_mmap_lock(mapping);
89143 + /* insert tmp into the share list, just after mpnt */
89144 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89145 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89146 + else
89147 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89148 + flush_dcache_mmap_unlock(mapping);
89149 + mutex_unlock(&mapping->i_mmap_mutex);
89150 + }
89151 +
89152 + /*
89153 + * Clear hugetlb-related page reserves for children. This only
89154 + * affects MAP_PRIVATE mappings. Faults generated by the child
89155 + * are not guaranteed to succeed, even if read-only
89156 + */
89157 + if (is_vm_hugetlb_page(tmp))
89158 + reset_vma_resv_huge_pages(tmp);
89159 +
89160 + return tmp;
89161 +
89162 +fail_nomem_anon_vma_fork:
89163 + mpol_put(vma_policy(tmp));
89164 +fail_nomem_policy:
89165 + kmem_cache_free(vm_area_cachep, tmp);
89166 +fail_nomem:
89167 + vm_unacct_memory(charge);
89168 + return NULL;
89169 +}
89170 +
89171 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89172 {
89173 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89174 struct rb_node **rb_link, *rb_parent;
89175 int retval;
89176 - unsigned long charge;
89177
89178 uprobe_start_dup_mmap();
89179 down_write(&oldmm->mmap_sem);
89180 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89181
89182 prev = NULL;
89183 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89184 - struct file *file;
89185 -
89186 if (mpnt->vm_flags & VM_DONTCOPY) {
89187 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89188 -vma_pages(mpnt));
89189 continue;
89190 }
89191 - charge = 0;
89192 - if (mpnt->vm_flags & VM_ACCOUNT) {
89193 - unsigned long len = vma_pages(mpnt);
89194 -
89195 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89196 - goto fail_nomem;
89197 - charge = len;
89198 - }
89199 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89200 - if (!tmp)
89201 - goto fail_nomem;
89202 - *tmp = *mpnt;
89203 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89204 - retval = vma_dup_policy(mpnt, tmp);
89205 - if (retval)
89206 - goto fail_nomem_policy;
89207 - tmp->vm_mm = mm;
89208 - if (anon_vma_fork(tmp, mpnt))
89209 - goto fail_nomem_anon_vma_fork;
89210 - tmp->vm_flags &= ~VM_LOCKED;
89211 - tmp->vm_next = tmp->vm_prev = NULL;
89212 - file = tmp->vm_file;
89213 - if (file) {
89214 - struct inode *inode = file_inode(file);
89215 - struct address_space *mapping = file->f_mapping;
89216 -
89217 - get_file(file);
89218 - if (tmp->vm_flags & VM_DENYWRITE)
89219 - atomic_dec(&inode->i_writecount);
89220 - mutex_lock(&mapping->i_mmap_mutex);
89221 - if (tmp->vm_flags & VM_SHARED)
89222 - atomic_inc(&mapping->i_mmap_writable);
89223 - flush_dcache_mmap_lock(mapping);
89224 - /* insert tmp into the share list, just after mpnt */
89225 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89226 - vma_nonlinear_insert(tmp,
89227 - &mapping->i_mmap_nonlinear);
89228 - else
89229 - vma_interval_tree_insert_after(tmp, mpnt,
89230 - &mapping->i_mmap);
89231 - flush_dcache_mmap_unlock(mapping);
89232 - mutex_unlock(&mapping->i_mmap_mutex);
89233 + tmp = dup_vma(mm, oldmm, mpnt);
89234 + if (!tmp) {
89235 + retval = -ENOMEM;
89236 + goto out;
89237 }
89238
89239 /*
89240 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89241 if (retval)
89242 goto out;
89243 }
89244 +
89245 +#ifdef CONFIG_PAX_SEGMEXEC
89246 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89247 + struct vm_area_struct *mpnt_m;
89248 +
89249 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89250 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89251 +
89252 + if (!mpnt->vm_mirror)
89253 + continue;
89254 +
89255 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89256 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89257 + mpnt->vm_mirror = mpnt_m;
89258 + } else {
89259 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89260 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89261 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89262 + mpnt->vm_mirror->vm_mirror = mpnt;
89263 + }
89264 + }
89265 + BUG_ON(mpnt_m);
89266 + }
89267 +#endif
89268 +
89269 /* a new mm has just been created */
89270 arch_dup_mmap(oldmm, mm);
89271 retval = 0;
89272 @@ -486,14 +589,6 @@ out:
89273 up_write(&oldmm->mmap_sem);
89274 uprobe_end_dup_mmap();
89275 return retval;
89276 -fail_nomem_anon_vma_fork:
89277 - mpol_put(vma_policy(tmp));
89278 -fail_nomem_policy:
89279 - kmem_cache_free(vm_area_cachep, tmp);
89280 -fail_nomem:
89281 - retval = -ENOMEM;
89282 - vm_unacct_memory(charge);
89283 - goto out;
89284 }
89285
89286 static inline int mm_alloc_pgd(struct mm_struct *mm)
89287 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89288 return ERR_PTR(err);
89289
89290 mm = get_task_mm(task);
89291 - if (mm && mm != current->mm &&
89292 - !ptrace_may_access(task, mode)) {
89293 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89294 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89295 mmput(mm);
89296 mm = ERR_PTR(-EACCES);
89297 }
89298 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89299 spin_unlock(&fs->lock);
89300 return -EAGAIN;
89301 }
89302 - fs->users++;
89303 + atomic_inc(&fs->users);
89304 spin_unlock(&fs->lock);
89305 return 0;
89306 }
89307 tsk->fs = copy_fs_struct(fs);
89308 if (!tsk->fs)
89309 return -ENOMEM;
89310 + /* Carry through gr_chroot_dentry and is_chrooted instead
89311 + of recomputing it here. Already copied when the task struct
89312 + is duplicated. This allows pivot_root to not be treated as
89313 + a chroot
89314 + */
89315 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89316 +
89317 return 0;
89318 }
89319
89320 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89321 * parts of the process environment (as per the clone
89322 * flags). The actual kick-off is left to the caller.
89323 */
89324 -static struct task_struct *copy_process(unsigned long clone_flags,
89325 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89326 unsigned long stack_start,
89327 unsigned long stack_size,
89328 int __user *child_tidptr,
89329 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89330 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89331 #endif
89332 retval = -EAGAIN;
89333 +
89334 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89335 +
89336 if (atomic_read(&p->real_cred->user->processes) >=
89337 task_rlimit(p, RLIMIT_NPROC)) {
89338 if (p->real_cred->user != INIT_USER &&
89339 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89340 goto bad_fork_free_pid;
89341 }
89342
89343 + /* synchronizes with gr_set_acls()
89344 + we need to call this past the point of no return for fork()
89345 + */
89346 + gr_copy_label(p);
89347 +
89348 if (likely(p->pid)) {
89349 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89350
89351 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89352 bad_fork_free:
89353 free_task(p);
89354 fork_out:
89355 + gr_log_forkfail(retval);
89356 +
89357 return ERR_PTR(retval);
89358 }
89359
89360 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89361
89362 p = copy_process(clone_flags, stack_start, stack_size,
89363 child_tidptr, NULL, trace);
89364 + add_latent_entropy();
89365 /*
89366 * Do this prior waking up the new thread - the thread pointer
89367 * might get invalid after that point, if the thread exits quickly.
89368 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89369 if (clone_flags & CLONE_PARENT_SETTID)
89370 put_user(nr, parent_tidptr);
89371
89372 + gr_handle_brute_check();
89373 +
89374 if (clone_flags & CLONE_VFORK) {
89375 p->vfork_done = &vfork;
89376 init_completion(&vfork);
89377 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89378 mm_cachep = kmem_cache_create("mm_struct",
89379 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89380 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89381 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89382 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89383 mmap_init();
89384 nsproxy_cache_init();
89385 }
89386 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89387 return 0;
89388
89389 /* don't need lock here; in the worst case we'll do useless copy */
89390 - if (fs->users == 1)
89391 + if (atomic_read(&fs->users) == 1)
89392 return 0;
89393
89394 *new_fsp = copy_fs_struct(fs);
89395 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89396 fs = current->fs;
89397 spin_lock(&fs->lock);
89398 current->fs = new_fs;
89399 - if (--fs->users)
89400 + gr_set_chroot_entries(current, &current->fs->root);
89401 + if (atomic_dec_return(&fs->users))
89402 new_fs = NULL;
89403 else
89404 new_fs = fs;
89405 diff --git a/kernel/futex.c b/kernel/futex.c
89406 index 63678b5..512f9af 100644
89407 --- a/kernel/futex.c
89408 +++ b/kernel/futex.c
89409 @@ -201,7 +201,7 @@ struct futex_pi_state {
89410 atomic_t refcount;
89411
89412 union futex_key key;
89413 -};
89414 +} __randomize_layout;
89415
89416 /**
89417 * struct futex_q - The hashed futex queue entry, one per waiting task
89418 @@ -235,7 +235,7 @@ struct futex_q {
89419 struct rt_mutex_waiter *rt_waiter;
89420 union futex_key *requeue_pi_key;
89421 u32 bitset;
89422 -};
89423 +} __randomize_layout;
89424
89425 static const struct futex_q futex_q_init = {
89426 /* list gets initialized in queue_me()*/
89427 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89428 struct page *page, *page_head;
89429 int err, ro = 0;
89430
89431 +#ifdef CONFIG_PAX_SEGMEXEC
89432 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89433 + return -EFAULT;
89434 +#endif
89435 +
89436 /*
89437 * The futex address must be "naturally" aligned.
89438 */
89439 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89440
89441 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89442 {
89443 - int ret;
89444 + unsigned long ret;
89445
89446 pagefault_disable();
89447 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89448 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89449 {
89450 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89451 u32 curval;
89452 + mm_segment_t oldfs;
89453
89454 /*
89455 * This will fail and we want it. Some arch implementations do
89456 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89457 * implementation, the non-functional ones will return
89458 * -ENOSYS.
89459 */
89460 + oldfs = get_fs();
89461 + set_fs(USER_DS);
89462 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89463 futex_cmpxchg_enabled = 1;
89464 + set_fs(oldfs);
89465 #endif
89466 }
89467
89468 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89469 index 55c8c93..9ba7ad6 100644
89470 --- a/kernel/futex_compat.c
89471 +++ b/kernel/futex_compat.c
89472 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89473 return 0;
89474 }
89475
89476 -static void __user *futex_uaddr(struct robust_list __user *entry,
89477 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89478 compat_long_t futex_offset)
89479 {
89480 compat_uptr_t base = ptr_to_compat(entry);
89481 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89482 index b358a80..fc25240 100644
89483 --- a/kernel/gcov/base.c
89484 +++ b/kernel/gcov/base.c
89485 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89486 }
89487
89488 #ifdef CONFIG_MODULES
89489 -static inline int within(void *addr, void *start, unsigned long size)
89490 -{
89491 - return ((addr >= start) && (addr < start + size));
89492 -}
89493 -
89494 /* Update list and generate events when modules are unloaded. */
89495 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89496 void *data)
89497 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89498
89499 /* Remove entries located in module from linked list. */
89500 while ((info = gcov_info_next(info))) {
89501 - if (within(info, mod->module_core, mod->core_size)) {
89502 + if (within_module_core_rw((unsigned long)info, mod)) {
89503 gcov_info_unlink(prev, info);
89504 if (gcov_events_enabled)
89505 gcov_event(GCOV_REMOVE, info);
89506 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89507 index 9019f15..9a3c42e 100644
89508 --- a/kernel/jump_label.c
89509 +++ b/kernel/jump_label.c
89510 @@ -14,6 +14,7 @@
89511 #include <linux/err.h>
89512 #include <linux/static_key.h>
89513 #include <linux/jump_label_ratelimit.h>
89514 +#include <linux/mm.h>
89515
89516 #ifdef HAVE_JUMP_LABEL
89517
89518 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89519
89520 size = (((unsigned long)stop - (unsigned long)start)
89521 / sizeof(struct jump_entry));
89522 + pax_open_kernel();
89523 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89524 + pax_close_kernel();
89525 }
89526
89527 static void jump_label_update(struct static_key *key, int enable);
89528 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89529 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89530 struct jump_entry *iter;
89531
89532 + pax_open_kernel();
89533 for (iter = iter_start; iter < iter_stop; iter++) {
89534 if (within_module_init(iter->code, mod))
89535 iter->code = 0;
89536 }
89537 + pax_close_kernel();
89538 }
89539
89540 static int
89541 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89542 index 5c5987f..bc502b0 100644
89543 --- a/kernel/kallsyms.c
89544 +++ b/kernel/kallsyms.c
89545 @@ -11,6 +11,9 @@
89546 * Changed the compression method from stem compression to "table lookup"
89547 * compression (see scripts/kallsyms.c for a more complete description)
89548 */
89549 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89550 +#define __INCLUDED_BY_HIDESYM 1
89551 +#endif
89552 #include <linux/kallsyms.h>
89553 #include <linux/module.h>
89554 #include <linux/init.h>
89555 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89556
89557 static inline int is_kernel_inittext(unsigned long addr)
89558 {
89559 + if (system_state != SYSTEM_BOOTING)
89560 + return 0;
89561 +
89562 if (addr >= (unsigned long)_sinittext
89563 && addr <= (unsigned long)_einittext)
89564 return 1;
89565 return 0;
89566 }
89567
89568 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89569 +#ifdef CONFIG_MODULES
89570 +static inline int is_module_text(unsigned long addr)
89571 +{
89572 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89573 + return 1;
89574 +
89575 + addr = ktla_ktva(addr);
89576 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89577 +}
89578 +#else
89579 +static inline int is_module_text(unsigned long addr)
89580 +{
89581 + return 0;
89582 +}
89583 +#endif
89584 +#endif
89585 +
89586 static inline int is_kernel_text(unsigned long addr)
89587 {
89588 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89589 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89590
89591 static inline int is_kernel(unsigned long addr)
89592 {
89593 +
89594 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89595 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89596 + return 1;
89597 +
89598 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89599 +#else
89600 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89601 +#endif
89602 +
89603 return 1;
89604 return in_gate_area_no_mm(addr);
89605 }
89606
89607 static int is_ksym_addr(unsigned long addr)
89608 {
89609 +
89610 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89611 + if (is_module_text(addr))
89612 + return 0;
89613 +#endif
89614 +
89615 if (all_var)
89616 return is_kernel(addr);
89617
89618 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89619
89620 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89621 {
89622 - iter->name[0] = '\0';
89623 iter->nameoff = get_symbol_offset(new_pos);
89624 iter->pos = new_pos;
89625 }
89626 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89627 {
89628 struct kallsym_iter *iter = m->private;
89629
89630 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89631 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89632 + return 0;
89633 +#endif
89634 +
89635 /* Some debugging symbols have no name. Ignore them. */
89636 if (!iter->name[0])
89637 return 0;
89638 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89639 */
89640 type = iter->exported ? toupper(iter->type) :
89641 tolower(iter->type);
89642 +
89643 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89644 type, iter->name, iter->module_name);
89645 } else
89646 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89647 index 0aa69ea..a7fcafb 100644
89648 --- a/kernel/kcmp.c
89649 +++ b/kernel/kcmp.c
89650 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89651 struct task_struct *task1, *task2;
89652 int ret;
89653
89654 +#ifdef CONFIG_GRKERNSEC
89655 + return -ENOSYS;
89656 +#endif
89657 +
89658 rcu_read_lock();
89659
89660 /*
89661 diff --git a/kernel/kexec.c b/kernel/kexec.c
89662 index 2abf9f6..c40cf85 100644
89663 --- a/kernel/kexec.c
89664 +++ b/kernel/kexec.c
89665 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89666 compat_ulong_t, flags)
89667 {
89668 struct compat_kexec_segment in;
89669 - struct kexec_segment out, __user *ksegments;
89670 + struct kexec_segment out;
89671 + struct kexec_segment __user *ksegments;
89672 unsigned long i, result;
89673
89674 /* Don't allow clients that don't understand the native
89675 diff --git a/kernel/kmod.c b/kernel/kmod.c
89676 index 80f7a6d..3c476d3 100644
89677 --- a/kernel/kmod.c
89678 +++ b/kernel/kmod.c
89679 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89680 kfree(info->argv);
89681 }
89682
89683 -static int call_modprobe(char *module_name, int wait)
89684 +static int call_modprobe(char *module_name, char *module_param, int wait)
89685 {
89686 struct subprocess_info *info;
89687 static char *envp[] = {
89688 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89689 NULL
89690 };
89691
89692 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89693 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89694 if (!argv)
89695 goto out;
89696
89697 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89698 argv[1] = "-q";
89699 argv[2] = "--";
89700 argv[3] = module_name; /* check free_modprobe_argv() */
89701 - argv[4] = NULL;
89702 + argv[4] = module_param;
89703 + argv[5] = NULL;
89704
89705 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89706 NULL, free_modprobe_argv, NULL);
89707 @@ -129,9 +130,8 @@ out:
89708 * If module auto-loading support is disabled then this function
89709 * becomes a no-operation.
89710 */
89711 -int __request_module(bool wait, const char *fmt, ...)
89712 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89713 {
89714 - va_list args;
89715 char module_name[MODULE_NAME_LEN];
89716 unsigned int max_modprobes;
89717 int ret;
89718 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89719 if (!modprobe_path[0])
89720 return 0;
89721
89722 - va_start(args, fmt);
89723 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89724 - va_end(args);
89725 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89726 if (ret >= MODULE_NAME_LEN)
89727 return -ENAMETOOLONG;
89728
89729 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89730 if (ret)
89731 return ret;
89732
89733 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89734 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89735 + /* hack to workaround consolekit/udisks stupidity */
89736 + read_lock(&tasklist_lock);
89737 + if (!strcmp(current->comm, "mount") &&
89738 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89739 + read_unlock(&tasklist_lock);
89740 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89741 + return -EPERM;
89742 + }
89743 + read_unlock(&tasklist_lock);
89744 + }
89745 +#endif
89746 +
89747 /* If modprobe needs a service that is in a module, we get a recursive
89748 * loop. Limit the number of running kmod threads to max_threads/2 or
89749 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89750 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89751
89752 trace_module_request(module_name, wait, _RET_IP_);
89753
89754 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89755 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89756
89757 atomic_dec(&kmod_concurrent);
89758 return ret;
89759 }
89760 +
89761 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89762 +{
89763 + va_list args;
89764 + int ret;
89765 +
89766 + va_start(args, fmt);
89767 + ret = ____request_module(wait, module_param, fmt, args);
89768 + va_end(args);
89769 +
89770 + return ret;
89771 +}
89772 +
89773 +int __request_module(bool wait, const char *fmt, ...)
89774 +{
89775 + va_list args;
89776 + int ret;
89777 +
89778 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89779 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89780 + char module_param[MODULE_NAME_LEN];
89781 +
89782 + memset(module_param, 0, sizeof(module_param));
89783 +
89784 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89785 +
89786 + va_start(args, fmt);
89787 + ret = ____request_module(wait, module_param, fmt, args);
89788 + va_end(args);
89789 +
89790 + return ret;
89791 + }
89792 +#endif
89793 +
89794 + va_start(args, fmt);
89795 + ret = ____request_module(wait, NULL, fmt, args);
89796 + va_end(args);
89797 +
89798 + return ret;
89799 +}
89800 +
89801 EXPORT_SYMBOL(__request_module);
89802 #endif /* CONFIG_MODULES */
89803
89804 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89805 {
89806 +#ifdef CONFIG_GRKERNSEC
89807 + kfree(info->path);
89808 + info->path = info->origpath;
89809 +#endif
89810 if (info->cleanup)
89811 (*info->cleanup)(info);
89812 kfree(info);
89813 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89814 */
89815 set_user_nice(current, 0);
89816
89817 +#ifdef CONFIG_GRKERNSEC
89818 + /* this is race-free as far as userland is concerned as we copied
89819 + out the path to be used prior to this point and are now operating
89820 + on that copy
89821 + */
89822 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89823 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89824 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89825 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89826 + retval = -EPERM;
89827 + goto out;
89828 + }
89829 +#endif
89830 +
89831 retval = -ENOMEM;
89832 new = prepare_kernel_cred(current);
89833 if (!new)
89834 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
89835 commit_creds(new);
89836
89837 retval = do_execve(getname_kernel(sub_info->path),
89838 - (const char __user *const __user *)sub_info->argv,
89839 - (const char __user *const __user *)sub_info->envp);
89840 + (const char __user *const __force_user *)sub_info->argv,
89841 + (const char __user *const __force_user *)sub_info->envp);
89842 out:
89843 sub_info->retval = retval;
89844 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
89845 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
89846 *
89847 * Thus the __user pointer cast is valid here.
89848 */
89849 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
89850 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89851
89852 /*
89853 * If ret is 0, either ____call_usermodehelper failed and the
89854 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89855 goto out;
89856
89857 INIT_WORK(&sub_info->work, __call_usermodehelper);
89858 +#ifdef CONFIG_GRKERNSEC
89859 + sub_info->origpath = path;
89860 + sub_info->path = kstrdup(path, gfp_mask);
89861 +#else
89862 sub_info->path = path;
89863 +#endif
89864 sub_info->argv = argv;
89865 sub_info->envp = envp;
89866
89867 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89868 static int proc_cap_handler(struct ctl_table *table, int write,
89869 void __user *buffer, size_t *lenp, loff_t *ppos)
89870 {
89871 - struct ctl_table t;
89872 + ctl_table_no_const t;
89873 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89874 kernel_cap_t new_cap;
89875 int err, i;
89876 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89877 index 3995f54..e247879 100644
89878 --- a/kernel/kprobes.c
89879 +++ b/kernel/kprobes.c
89880 @@ -31,6 +31,9 @@
89881 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89882 * <prasanna@in.ibm.com> added function-return probes.
89883 */
89884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89885 +#define __INCLUDED_BY_HIDESYM 1
89886 +#endif
89887 #include <linux/kprobes.h>
89888 #include <linux/hash.h>
89889 #include <linux/init.h>
89890 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
89891
89892 static void *alloc_insn_page(void)
89893 {
89894 - return module_alloc(PAGE_SIZE);
89895 + return module_alloc_exec(PAGE_SIZE);
89896 }
89897
89898 static void free_insn_page(void *page)
89899 {
89900 - module_free(NULL, page);
89901 + module_free_exec(NULL, page);
89902 }
89903
89904 struct kprobe_insn_cache kprobe_insn_slots = {
89905 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89906 kprobe_type = "k";
89907
89908 if (sym)
89909 - seq_printf(pi, "%p %s %s+0x%x %s ",
89910 + seq_printf(pi, "%pK %s %s+0x%x %s ",
89911 p->addr, kprobe_type, sym, offset,
89912 (modname ? modname : " "));
89913 else
89914 - seq_printf(pi, "%p %s %p ",
89915 + seq_printf(pi, "%pK %s %pK ",
89916 p->addr, kprobe_type, p->addr);
89917
89918 if (!pp)
89919 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89920 index 6683cce..daf8999 100644
89921 --- a/kernel/ksysfs.c
89922 +++ b/kernel/ksysfs.c
89923 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89924 {
89925 if (count+1 > UEVENT_HELPER_PATH_LEN)
89926 return -ENOENT;
89927 + if (!capable(CAP_SYS_ADMIN))
89928 + return -EPERM;
89929 memcpy(uevent_helper, buf, count);
89930 uevent_helper[count] = '\0';
89931 if (count && uevent_helper[count-1] == '\n')
89932 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89933 return count;
89934 }
89935
89936 -static struct bin_attribute notes_attr = {
89937 +static bin_attribute_no_const notes_attr __read_only = {
89938 .attr = {
89939 .name = "notes",
89940 .mode = S_IRUGO,
89941 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
89942 index 88d0d44..e9ce0ee 100644
89943 --- a/kernel/locking/lockdep.c
89944 +++ b/kernel/locking/lockdep.c
89945 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
89946 end = (unsigned long) &_end,
89947 addr = (unsigned long) obj;
89948
89949 +#ifdef CONFIG_PAX_KERNEXEC
89950 + start = ktla_ktva(start);
89951 +#endif
89952 +
89953 /*
89954 * static variable?
89955 */
89956 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
89957 if (!static_obj(lock->key)) {
89958 debug_locks_off();
89959 printk("INFO: trying to register non-static key.\n");
89960 + printk("lock:%pS key:%pS.\n", lock, lock->key);
89961 printk("the code is fine but needs lockdep annotation.\n");
89962 printk("turning off the locking correctness validator.\n");
89963 dump_stack();
89964 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
89965 if (!class)
89966 return 0;
89967 }
89968 - atomic_inc((atomic_t *)&class->ops);
89969 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
89970 if (very_verbose(class)) {
89971 printk("\nacquire class [%p] %s", class->key, class->name);
89972 if (class->name_version > 1)
89973 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
89974 index ef43ac4..2720dfa 100644
89975 --- a/kernel/locking/lockdep_proc.c
89976 +++ b/kernel/locking/lockdep_proc.c
89977 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
89978 return 0;
89979 }
89980
89981 - seq_printf(m, "%p", class->key);
89982 + seq_printf(m, "%pK", class->key);
89983 #ifdef CONFIG_DEBUG_LOCKDEP
89984 seq_printf(m, " OPS:%8ld", class->ops);
89985 #endif
89986 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
89987
89988 list_for_each_entry(entry, &class->locks_after, entry) {
89989 if (entry->distance == 1) {
89990 - seq_printf(m, " -> [%p] ", entry->class->key);
89991 + seq_printf(m, " -> [%pK] ", entry->class->key);
89992 print_name(m, entry->class);
89993 seq_puts(m, "\n");
89994 }
89995 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
89996 if (!class->key)
89997 continue;
89998
89999 - seq_printf(m, "[%p] ", class->key);
90000 + seq_printf(m, "[%pK] ", class->key);
90001 print_name(m, class);
90002 seq_puts(m, "\n");
90003 }
90004 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90005 if (!i)
90006 seq_line(m, '-', 40-namelen, namelen);
90007
90008 - snprintf(ip, sizeof(ip), "[<%p>]",
90009 + snprintf(ip, sizeof(ip), "[<%pK>]",
90010 (void *)class->contention_point[i]);
90011 seq_printf(m, "%40s %14lu %29s %pS\n",
90012 name, stats->contention_point[i],
90013 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90014 if (!i)
90015 seq_line(m, '-', 40-namelen, namelen);
90016
90017 - snprintf(ip, sizeof(ip), "[<%p>]",
90018 + snprintf(ip, sizeof(ip), "[<%pK>]",
90019 (void *)class->contending_point[i]);
90020 seq_printf(m, "%40s %14lu %29s %pS\n",
90021 name, stats->contending_point[i],
90022 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90023 index 9887a90..0cd2b1d 100644
90024 --- a/kernel/locking/mcs_spinlock.c
90025 +++ b/kernel/locking/mcs_spinlock.c
90026 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90027
90028 prev = decode_cpu(old);
90029 node->prev = prev;
90030 - ACCESS_ONCE(prev->next) = node;
90031 + ACCESS_ONCE_RW(prev->next) = node;
90032
90033 /*
90034 * Normally @prev is untouchable after the above store; because at that
90035 @@ -172,8 +172,8 @@ unqueue:
90036 * it will wait in Step-A.
90037 */
90038
90039 - ACCESS_ONCE(next->prev) = prev;
90040 - ACCESS_ONCE(prev->next) = next;
90041 + ACCESS_ONCE_RW(next->prev) = prev;
90042 + ACCESS_ONCE_RW(prev->next) = next;
90043
90044 return false;
90045 }
90046 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90047 node = this_cpu_ptr(&osq_node);
90048 next = xchg(&node->next, NULL);
90049 if (next) {
90050 - ACCESS_ONCE(next->locked) = 1;
90051 + ACCESS_ONCE_RW(next->locked) = 1;
90052 return;
90053 }
90054
90055 next = osq_wait_next(lock, node, NULL);
90056 if (next)
90057 - ACCESS_ONCE(next->locked) = 1;
90058 + ACCESS_ONCE_RW(next->locked) = 1;
90059 }
90060
90061 #endif
90062 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90063 index 4d60986..5d351c1 100644
90064 --- a/kernel/locking/mcs_spinlock.h
90065 +++ b/kernel/locking/mcs_spinlock.h
90066 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90067 */
90068 return;
90069 }
90070 - ACCESS_ONCE(prev->next) = node;
90071 + ACCESS_ONCE_RW(prev->next) = node;
90072
90073 /* Wait until the lock holder passes the lock down. */
90074 arch_mcs_spin_lock_contended(&node->locked);
90075 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90076 index 5cf6731..ce3bc5a 100644
90077 --- a/kernel/locking/mutex-debug.c
90078 +++ b/kernel/locking/mutex-debug.c
90079 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90080 }
90081
90082 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90083 - struct thread_info *ti)
90084 + struct task_struct *task)
90085 {
90086 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90087
90088 /* Mark the current thread as blocked on the lock: */
90089 - ti->task->blocked_on = waiter;
90090 + task->blocked_on = waiter;
90091 }
90092
90093 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90094 - struct thread_info *ti)
90095 + struct task_struct *task)
90096 {
90097 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90098 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90099 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90100 - ti->task->blocked_on = NULL;
90101 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90102 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90103 + task->blocked_on = NULL;
90104
90105 list_del_init(&waiter->list);
90106 waiter->task = NULL;
90107 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90108 index 0799fd3..d06ae3b 100644
90109 --- a/kernel/locking/mutex-debug.h
90110 +++ b/kernel/locking/mutex-debug.h
90111 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90112 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90113 extern void debug_mutex_add_waiter(struct mutex *lock,
90114 struct mutex_waiter *waiter,
90115 - struct thread_info *ti);
90116 + struct task_struct *task);
90117 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90118 - struct thread_info *ti);
90119 + struct task_struct *task);
90120 extern void debug_mutex_unlock(struct mutex *lock);
90121 extern void debug_mutex_init(struct mutex *lock, const char *name,
90122 struct lock_class_key *key);
90123 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90124 index dadbf88..4500507 100644
90125 --- a/kernel/locking/mutex.c
90126 +++ b/kernel/locking/mutex.c
90127 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90128 goto skip_wait;
90129
90130 debug_mutex_lock_common(lock, &waiter);
90131 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90132 + debug_mutex_add_waiter(lock, &waiter, task);
90133
90134 /* add waiting tasks to the end of the waitqueue (FIFO): */
90135 list_add_tail(&waiter.list, &lock->wait_list);
90136 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90137 schedule_preempt_disabled();
90138 spin_lock_mutex(&lock->wait_lock, flags);
90139 }
90140 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90141 + mutex_remove_waiter(lock, &waiter, task);
90142 /* set it to 0 if there are no waiters left: */
90143 if (likely(list_empty(&lock->wait_list)))
90144 atomic_set(&lock->count, 0);
90145 @@ -600,7 +600,7 @@ skip_wait:
90146 return 0;
90147
90148 err:
90149 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90150 + mutex_remove_waiter(lock, &waiter, task);
90151 spin_unlock_mutex(&lock->wait_lock, flags);
90152 debug_mutex_free_waiter(&waiter);
90153 mutex_release(&lock->dep_map, 1, ip);
90154 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90155 index 1d96dd0..994ff19 100644
90156 --- a/kernel/locking/rtmutex-tester.c
90157 +++ b/kernel/locking/rtmutex-tester.c
90158 @@ -22,7 +22,7 @@
90159 #define MAX_RT_TEST_MUTEXES 8
90160
90161 static spinlock_t rttest_lock;
90162 -static atomic_t rttest_event;
90163 +static atomic_unchecked_t rttest_event;
90164
90165 struct test_thread_data {
90166 int opcode;
90167 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90168
90169 case RTTEST_LOCKCONT:
90170 td->mutexes[td->opdata] = 1;
90171 - td->event = atomic_add_return(1, &rttest_event);
90172 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90173 return 0;
90174
90175 case RTTEST_RESET:
90176 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90177 return 0;
90178
90179 case RTTEST_RESETEVENT:
90180 - atomic_set(&rttest_event, 0);
90181 + atomic_set_unchecked(&rttest_event, 0);
90182 return 0;
90183
90184 default:
90185 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90186 return ret;
90187
90188 td->mutexes[id] = 1;
90189 - td->event = atomic_add_return(1, &rttest_event);
90190 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90191 rt_mutex_lock(&mutexes[id]);
90192 - td->event = atomic_add_return(1, &rttest_event);
90193 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90194 td->mutexes[id] = 4;
90195 return 0;
90196
90197 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90198 return ret;
90199
90200 td->mutexes[id] = 1;
90201 - td->event = atomic_add_return(1, &rttest_event);
90202 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90203 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90204 - td->event = atomic_add_return(1, &rttest_event);
90205 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90206 td->mutexes[id] = ret ? 0 : 4;
90207 return ret ? -EINTR : 0;
90208
90209 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90210 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90211 return ret;
90212
90213 - td->event = atomic_add_return(1, &rttest_event);
90214 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90215 rt_mutex_unlock(&mutexes[id]);
90216 - td->event = atomic_add_return(1, &rttest_event);
90217 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90218 td->mutexes[id] = 0;
90219 return 0;
90220
90221 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90222 break;
90223
90224 td->mutexes[dat] = 2;
90225 - td->event = atomic_add_return(1, &rttest_event);
90226 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90227 break;
90228
90229 default:
90230 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90231 return;
90232
90233 td->mutexes[dat] = 3;
90234 - td->event = atomic_add_return(1, &rttest_event);
90235 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90236 break;
90237
90238 case RTTEST_LOCKNOWAIT:
90239 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90240 return;
90241
90242 td->mutexes[dat] = 1;
90243 - td->event = atomic_add_return(1, &rttest_event);
90244 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90245 return;
90246
90247 default:
90248 diff --git a/kernel/module.c b/kernel/module.c
90249 index 88cec1d..d097c28 100644
90250 --- a/kernel/module.c
90251 +++ b/kernel/module.c
90252 @@ -60,6 +60,7 @@
90253 #include <linux/jump_label.h>
90254 #include <linux/pfn.h>
90255 #include <linux/bsearch.h>
90256 +#include <linux/grsecurity.h>
90257 #include <uapi/linux/module.h>
90258 #include "module-internal.h"
90259
90260 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90261
90262 /* Bounds of module allocation, for speeding __module_address.
90263 * Protected by module_mutex. */
90264 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90265 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90266 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90267
90268 int register_module_notifier(struct notifier_block * nb)
90269 {
90270 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90271 return true;
90272
90273 list_for_each_entry_rcu(mod, &modules, list) {
90274 - struct symsearch arr[] = {
90275 + struct symsearch modarr[] = {
90276 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90277 NOT_GPL_ONLY, false },
90278 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90279 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90280 if (mod->state == MODULE_STATE_UNFORMED)
90281 continue;
90282
90283 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90284 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90285 return true;
90286 }
90287 return false;
90288 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90289 if (!pcpusec->sh_size)
90290 return 0;
90291
90292 - if (align > PAGE_SIZE) {
90293 + if (align-1 >= PAGE_SIZE) {
90294 pr_warn("%s: per-cpu alignment %li > %li\n",
90295 mod->name, align, PAGE_SIZE);
90296 align = PAGE_SIZE;
90297 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90298 static ssize_t show_coresize(struct module_attribute *mattr,
90299 struct module_kobject *mk, char *buffer)
90300 {
90301 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90302 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90303 }
90304
90305 static struct module_attribute modinfo_coresize =
90306 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90307 static ssize_t show_initsize(struct module_attribute *mattr,
90308 struct module_kobject *mk, char *buffer)
90309 {
90310 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90311 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90312 }
90313
90314 static struct module_attribute modinfo_initsize =
90315 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90316 goto bad_version;
90317 }
90318
90319 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90320 + /*
90321 + * avoid potentially printing jibberish on attempted load
90322 + * of a module randomized with a different seed
90323 + */
90324 + pr_warn("no symbol version for %s\n", symname);
90325 +#else
90326 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90327 +#endif
90328 return 0;
90329
90330 bad_version:
90331 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90332 + /*
90333 + * avoid potentially printing jibberish on attempted load
90334 + * of a module randomized with a different seed
90335 + */
90336 + printk("attempted module disagrees about version of symbol %s\n",
90337 + symname);
90338 +#else
90339 printk("%s: disagrees about version of symbol %s\n",
90340 mod->name, symname);
90341 +#endif
90342 return 0;
90343 }
90344
90345 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90346 */
90347 #ifdef CONFIG_SYSFS
90348
90349 -#ifdef CONFIG_KALLSYMS
90350 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90351 static inline bool sect_empty(const Elf_Shdr *sect)
90352 {
90353 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90354 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90355 {
90356 unsigned int notes, loaded, i;
90357 struct module_notes_attrs *notes_attrs;
90358 - struct bin_attribute *nattr;
90359 + bin_attribute_no_const *nattr;
90360
90361 /* failed to create section attributes, so can't create notes */
90362 if (!mod->sect_attrs)
90363 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90364 static int module_add_modinfo_attrs(struct module *mod)
90365 {
90366 struct module_attribute *attr;
90367 - struct module_attribute *temp_attr;
90368 + module_attribute_no_const *temp_attr;
90369 int error = 0;
90370 int i;
90371
90372 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90373
90374 static void unset_module_core_ro_nx(struct module *mod)
90375 {
90376 - set_page_attributes(mod->module_core + mod->core_text_size,
90377 - mod->module_core + mod->core_size,
90378 + set_page_attributes(mod->module_core_rw,
90379 + mod->module_core_rw + mod->core_size_rw,
90380 set_memory_x);
90381 - set_page_attributes(mod->module_core,
90382 - mod->module_core + mod->core_ro_size,
90383 + set_page_attributes(mod->module_core_rx,
90384 + mod->module_core_rx + mod->core_size_rx,
90385 set_memory_rw);
90386 }
90387
90388 static void unset_module_init_ro_nx(struct module *mod)
90389 {
90390 - set_page_attributes(mod->module_init + mod->init_text_size,
90391 - mod->module_init + mod->init_size,
90392 + set_page_attributes(mod->module_init_rw,
90393 + mod->module_init_rw + mod->init_size_rw,
90394 set_memory_x);
90395 - set_page_attributes(mod->module_init,
90396 - mod->module_init + mod->init_ro_size,
90397 + set_page_attributes(mod->module_init_rx,
90398 + mod->module_init_rx + mod->init_size_rx,
90399 set_memory_rw);
90400 }
90401
90402 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90403 list_for_each_entry_rcu(mod, &modules, list) {
90404 if (mod->state == MODULE_STATE_UNFORMED)
90405 continue;
90406 - if ((mod->module_core) && (mod->core_text_size)) {
90407 - set_page_attributes(mod->module_core,
90408 - mod->module_core + mod->core_text_size,
90409 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90410 + set_page_attributes(mod->module_core_rx,
90411 + mod->module_core_rx + mod->core_size_rx,
90412 set_memory_rw);
90413 }
90414 - if ((mod->module_init) && (mod->init_text_size)) {
90415 - set_page_attributes(mod->module_init,
90416 - mod->module_init + mod->init_text_size,
90417 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90418 + set_page_attributes(mod->module_init_rx,
90419 + mod->module_init_rx + mod->init_size_rx,
90420 set_memory_rw);
90421 }
90422 }
90423 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90424 list_for_each_entry_rcu(mod, &modules, list) {
90425 if (mod->state == MODULE_STATE_UNFORMED)
90426 continue;
90427 - if ((mod->module_core) && (mod->core_text_size)) {
90428 - set_page_attributes(mod->module_core,
90429 - mod->module_core + mod->core_text_size,
90430 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90431 + set_page_attributes(mod->module_core_rx,
90432 + mod->module_core_rx + mod->core_size_rx,
90433 set_memory_ro);
90434 }
90435 - if ((mod->module_init) && (mod->init_text_size)) {
90436 - set_page_attributes(mod->module_init,
90437 - mod->module_init + mod->init_text_size,
90438 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90439 + set_page_attributes(mod->module_init_rx,
90440 + mod->module_init_rx + mod->init_size_rx,
90441 set_memory_ro);
90442 }
90443 }
90444 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90445
90446 /* This may be NULL, but that's OK */
90447 unset_module_init_ro_nx(mod);
90448 - module_free(mod, mod->module_init);
90449 + module_free(mod, mod->module_init_rw);
90450 + module_free_exec(mod, mod->module_init_rx);
90451 kfree(mod->args);
90452 percpu_modfree(mod);
90453
90454 /* Free lock-classes: */
90455 - lockdep_free_key_range(mod->module_core, mod->core_size);
90456 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90457 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90458
90459 /* Finally, free the core (containing the module structure) */
90460 unset_module_core_ro_nx(mod);
90461 - module_free(mod, mod->module_core);
90462 + module_free_exec(mod, mod->module_core_rx);
90463 + module_free(mod, mod->module_core_rw);
90464
90465 #ifdef CONFIG_MPU
90466 update_protections(current->mm);
90467 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90468 int ret = 0;
90469 const struct kernel_symbol *ksym;
90470
90471 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90472 + int is_fs_load = 0;
90473 + int register_filesystem_found = 0;
90474 + char *p;
90475 +
90476 + p = strstr(mod->args, "grsec_modharden_fs");
90477 + if (p) {
90478 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90479 + /* copy \0 as well */
90480 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90481 + is_fs_load = 1;
90482 + }
90483 +#endif
90484 +
90485 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90486 const char *name = info->strtab + sym[i].st_name;
90487
90488 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90489 + /* it's a real shame this will never get ripped and copied
90490 + upstream! ;(
90491 + */
90492 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90493 + register_filesystem_found = 1;
90494 +#endif
90495 +
90496 switch (sym[i].st_shndx) {
90497 case SHN_COMMON:
90498 /* Ignore common symbols */
90499 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90500 ksym = resolve_symbol_wait(mod, info, name);
90501 /* Ok if resolved. */
90502 if (ksym && !IS_ERR(ksym)) {
90503 + pax_open_kernel();
90504 sym[i].st_value = ksym->value;
90505 + pax_close_kernel();
90506 break;
90507 }
90508
90509 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90510 secbase = (unsigned long)mod_percpu(mod);
90511 else
90512 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90513 + pax_open_kernel();
90514 sym[i].st_value += secbase;
90515 + pax_close_kernel();
90516 break;
90517 }
90518 }
90519
90520 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90521 + if (is_fs_load && !register_filesystem_found) {
90522 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90523 + ret = -EPERM;
90524 + }
90525 +#endif
90526 +
90527 return ret;
90528 }
90529
90530 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90531 || s->sh_entsize != ~0UL
90532 || strstarts(sname, ".init"))
90533 continue;
90534 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90535 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90536 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90537 + else
90538 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90539 pr_debug("\t%s\n", sname);
90540 }
90541 - switch (m) {
90542 - case 0: /* executable */
90543 - mod->core_size = debug_align(mod->core_size);
90544 - mod->core_text_size = mod->core_size;
90545 - break;
90546 - case 1: /* RO: text and ro-data */
90547 - mod->core_size = debug_align(mod->core_size);
90548 - mod->core_ro_size = mod->core_size;
90549 - break;
90550 - case 3: /* whole core */
90551 - mod->core_size = debug_align(mod->core_size);
90552 - break;
90553 - }
90554 }
90555
90556 pr_debug("Init section allocation order:\n");
90557 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90558 || s->sh_entsize != ~0UL
90559 || !strstarts(sname, ".init"))
90560 continue;
90561 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90562 - | INIT_OFFSET_MASK);
90563 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90564 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90565 + else
90566 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90567 + s->sh_entsize |= INIT_OFFSET_MASK;
90568 pr_debug("\t%s\n", sname);
90569 }
90570 - switch (m) {
90571 - case 0: /* executable */
90572 - mod->init_size = debug_align(mod->init_size);
90573 - mod->init_text_size = mod->init_size;
90574 - break;
90575 - case 1: /* RO: text and ro-data */
90576 - mod->init_size = debug_align(mod->init_size);
90577 - mod->init_ro_size = mod->init_size;
90578 - break;
90579 - case 3: /* whole init */
90580 - mod->init_size = debug_align(mod->init_size);
90581 - break;
90582 - }
90583 }
90584 }
90585
90586 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90587
90588 /* Put symbol section at end of init part of module. */
90589 symsect->sh_flags |= SHF_ALLOC;
90590 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90591 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90592 info->index.sym) | INIT_OFFSET_MASK;
90593 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90594
90595 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90596 }
90597
90598 /* Append room for core symbols at end of core part. */
90599 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90600 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90601 - mod->core_size += strtab_size;
90602 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90603 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90604 + mod->core_size_rx += strtab_size;
90605
90606 /* Put string table section at end of init part of module. */
90607 strsect->sh_flags |= SHF_ALLOC;
90608 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90609 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90610 info->index.str) | INIT_OFFSET_MASK;
90611 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90612 }
90613 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90614 /* Make sure we get permanent strtab: don't use info->strtab. */
90615 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90616
90617 + pax_open_kernel();
90618 +
90619 /* Set types up while we still have access to sections. */
90620 for (i = 0; i < mod->num_symtab; i++)
90621 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90622
90623 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90624 - mod->core_strtab = s = mod->module_core + info->stroffs;
90625 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90626 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90627 src = mod->symtab;
90628 for (ndst = i = 0; i < mod->num_symtab; i++) {
90629 if (i == 0 ||
90630 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90631 }
90632 }
90633 mod->core_num_syms = ndst;
90634 +
90635 + pax_close_kernel();
90636 }
90637 #else
90638 static inline void layout_symtab(struct module *mod, struct load_info *info)
90639 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90640 return vmalloc_exec(size);
90641 }
90642
90643 -static void *module_alloc_update_bounds(unsigned long size)
90644 +static void *module_alloc_update_bounds_rw(unsigned long size)
90645 {
90646 void *ret = module_alloc(size);
90647
90648 if (ret) {
90649 mutex_lock(&module_mutex);
90650 /* Update module bounds. */
90651 - if ((unsigned long)ret < module_addr_min)
90652 - module_addr_min = (unsigned long)ret;
90653 - if ((unsigned long)ret + size > module_addr_max)
90654 - module_addr_max = (unsigned long)ret + size;
90655 + if ((unsigned long)ret < module_addr_min_rw)
90656 + module_addr_min_rw = (unsigned long)ret;
90657 + if ((unsigned long)ret + size > module_addr_max_rw)
90658 + module_addr_max_rw = (unsigned long)ret + size;
90659 + mutex_unlock(&module_mutex);
90660 + }
90661 + return ret;
90662 +}
90663 +
90664 +static void *module_alloc_update_bounds_rx(unsigned long size)
90665 +{
90666 + void *ret = module_alloc_exec(size);
90667 +
90668 + if (ret) {
90669 + mutex_lock(&module_mutex);
90670 + /* Update module bounds. */
90671 + if ((unsigned long)ret < module_addr_min_rx)
90672 + module_addr_min_rx = (unsigned long)ret;
90673 + if ((unsigned long)ret + size > module_addr_max_rx)
90674 + module_addr_max_rx = (unsigned long)ret + size;
90675 mutex_unlock(&module_mutex);
90676 }
90677 return ret;
90678 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90679 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90680
90681 if (info->index.sym == 0) {
90682 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90683 + /*
90684 + * avoid potentially printing jibberish on attempted load
90685 + * of a module randomized with a different seed
90686 + */
90687 + pr_warn("module has no symbols (stripped?)\n");
90688 +#else
90689 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90690 +#endif
90691 return ERR_PTR(-ENOEXEC);
90692 }
90693
90694 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90695 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90696 {
90697 const char *modmagic = get_modinfo(info, "vermagic");
90698 + const char *license = get_modinfo(info, "license");
90699 int err;
90700
90701 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90702 + if (!license || !license_is_gpl_compatible(license))
90703 + return -ENOEXEC;
90704 +#endif
90705 +
90706 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90707 modmagic = NULL;
90708
90709 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90710 }
90711
90712 /* Set up license info based on the info section */
90713 - set_license(mod, get_modinfo(info, "license"));
90714 + set_license(mod, license);
90715
90716 return 0;
90717 }
90718 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90719 void *ptr;
90720
90721 /* Do the allocs. */
90722 - ptr = module_alloc_update_bounds(mod->core_size);
90723 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90724 /*
90725 * The pointer to this block is stored in the module structure
90726 * which is inside the block. Just mark it as not being a
90727 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90728 if (!ptr)
90729 return -ENOMEM;
90730
90731 - memset(ptr, 0, mod->core_size);
90732 - mod->module_core = ptr;
90733 + memset(ptr, 0, mod->core_size_rw);
90734 + mod->module_core_rw = ptr;
90735
90736 - if (mod->init_size) {
90737 - ptr = module_alloc_update_bounds(mod->init_size);
90738 + if (mod->init_size_rw) {
90739 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90740 /*
90741 * The pointer to this block is stored in the module structure
90742 * which is inside the block. This block doesn't need to be
90743 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90744 */
90745 kmemleak_ignore(ptr);
90746 if (!ptr) {
90747 - module_free(mod, mod->module_core);
90748 + module_free(mod, mod->module_core_rw);
90749 return -ENOMEM;
90750 }
90751 - memset(ptr, 0, mod->init_size);
90752 - mod->module_init = ptr;
90753 + memset(ptr, 0, mod->init_size_rw);
90754 + mod->module_init_rw = ptr;
90755 } else
90756 - mod->module_init = NULL;
90757 + mod->module_init_rw = NULL;
90758 +
90759 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90760 + kmemleak_not_leak(ptr);
90761 + if (!ptr) {
90762 + if (mod->module_init_rw)
90763 + module_free(mod, mod->module_init_rw);
90764 + module_free(mod, mod->module_core_rw);
90765 + return -ENOMEM;
90766 + }
90767 +
90768 + pax_open_kernel();
90769 + memset(ptr, 0, mod->core_size_rx);
90770 + pax_close_kernel();
90771 + mod->module_core_rx = ptr;
90772 +
90773 + if (mod->init_size_rx) {
90774 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90775 + kmemleak_ignore(ptr);
90776 + if (!ptr && mod->init_size_rx) {
90777 + module_free_exec(mod, mod->module_core_rx);
90778 + if (mod->module_init_rw)
90779 + module_free(mod, mod->module_init_rw);
90780 + module_free(mod, mod->module_core_rw);
90781 + return -ENOMEM;
90782 + }
90783 +
90784 + pax_open_kernel();
90785 + memset(ptr, 0, mod->init_size_rx);
90786 + pax_close_kernel();
90787 + mod->module_init_rx = ptr;
90788 + } else
90789 + mod->module_init_rx = NULL;
90790
90791 /* Transfer each section which specifies SHF_ALLOC */
90792 pr_debug("final section addresses:\n");
90793 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90794 if (!(shdr->sh_flags & SHF_ALLOC))
90795 continue;
90796
90797 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90798 - dest = mod->module_init
90799 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90800 - else
90801 - dest = mod->module_core + shdr->sh_entsize;
90802 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90803 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90804 + dest = mod->module_init_rw
90805 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90806 + else
90807 + dest = mod->module_init_rx
90808 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90809 + } else {
90810 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90811 + dest = mod->module_core_rw + shdr->sh_entsize;
90812 + else
90813 + dest = mod->module_core_rx + shdr->sh_entsize;
90814 + }
90815 +
90816 + if (shdr->sh_type != SHT_NOBITS) {
90817 +
90818 +#ifdef CONFIG_PAX_KERNEXEC
90819 +#ifdef CONFIG_X86_64
90820 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90821 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90822 +#endif
90823 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90824 + pax_open_kernel();
90825 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90826 + pax_close_kernel();
90827 + } else
90828 +#endif
90829
90830 - if (shdr->sh_type != SHT_NOBITS)
90831 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90832 + }
90833 /* Update sh_addr to point to copy in image. */
90834 - shdr->sh_addr = (unsigned long)dest;
90835 +
90836 +#ifdef CONFIG_PAX_KERNEXEC
90837 + if (shdr->sh_flags & SHF_EXECINSTR)
90838 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
90839 + else
90840 +#endif
90841 +
90842 + shdr->sh_addr = (unsigned long)dest;
90843 pr_debug("\t0x%lx %s\n",
90844 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90845 }
90846 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90847 * Do it before processing of module parameters, so the module
90848 * can provide parameter accessor functions of its own.
90849 */
90850 - if (mod->module_init)
90851 - flush_icache_range((unsigned long)mod->module_init,
90852 - (unsigned long)mod->module_init
90853 - + mod->init_size);
90854 - flush_icache_range((unsigned long)mod->module_core,
90855 - (unsigned long)mod->module_core + mod->core_size);
90856 + if (mod->module_init_rx)
90857 + flush_icache_range((unsigned long)mod->module_init_rx,
90858 + (unsigned long)mod->module_init_rx
90859 + + mod->init_size_rx);
90860 + flush_icache_range((unsigned long)mod->module_core_rx,
90861 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
90862
90863 set_fs(old_fs);
90864 }
90865 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90866 static void module_deallocate(struct module *mod, struct load_info *info)
90867 {
90868 percpu_modfree(mod);
90869 - module_free(mod, mod->module_init);
90870 - module_free(mod, mod->module_core);
90871 + module_free_exec(mod, mod->module_init_rx);
90872 + module_free_exec(mod, mod->module_core_rx);
90873 + module_free(mod, mod->module_init_rw);
90874 + module_free(mod, mod->module_core_rw);
90875 }
90876
90877 int __weak module_finalize(const Elf_Ehdr *hdr,
90878 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90879 static int post_relocation(struct module *mod, const struct load_info *info)
90880 {
90881 /* Sort exception table now relocations are done. */
90882 + pax_open_kernel();
90883 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90884 + pax_close_kernel();
90885
90886 /* Copy relocated percpu area over. */
90887 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90888 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90889 mod->strtab = mod->core_strtab;
90890 #endif
90891 unset_module_init_ro_nx(mod);
90892 - module_free(mod, mod->module_init);
90893 - mod->module_init = NULL;
90894 - mod->init_size = 0;
90895 - mod->init_ro_size = 0;
90896 - mod->init_text_size = 0;
90897 + module_free(mod, mod->module_init_rw);
90898 + module_free_exec(mod, mod->module_init_rx);
90899 + mod->module_init_rw = NULL;
90900 + mod->module_init_rx = NULL;
90901 + mod->init_size_rw = 0;
90902 + mod->init_size_rx = 0;
90903 mutex_unlock(&module_mutex);
90904 wake_up_all(&module_wq);
90905
90906 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90907 module_bug_finalize(info->hdr, info->sechdrs, mod);
90908
90909 /* Set RO and NX regions for core */
90910 - set_section_ro_nx(mod->module_core,
90911 - mod->core_text_size,
90912 - mod->core_ro_size,
90913 - mod->core_size);
90914 + set_section_ro_nx(mod->module_core_rx,
90915 + mod->core_size_rx,
90916 + mod->core_size_rx,
90917 + mod->core_size_rx);
90918
90919 /* Set RO and NX regions for init */
90920 - set_section_ro_nx(mod->module_init,
90921 - mod->init_text_size,
90922 - mod->init_ro_size,
90923 - mod->init_size);
90924 + set_section_ro_nx(mod->module_init_rx,
90925 + mod->init_size_rx,
90926 + mod->init_size_rx,
90927 + mod->init_size_rx);
90928
90929 /* Mark state as coming so strong_try_module_get() ignores us,
90930 * but kallsyms etc. can see us. */
90931 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90932 if (err)
90933 goto free_unload;
90934
90935 + /* Now copy in args */
90936 + mod->args = strndup_user(uargs, ~0UL >> 1);
90937 + if (IS_ERR(mod->args)) {
90938 + err = PTR_ERR(mod->args);
90939 + goto free_unload;
90940 + }
90941 +
90942 /* Set up MODINFO_ATTR fields */
90943 setup_modinfo(mod, info);
90944
90945 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90946 + {
90947 + char *p, *p2;
90948 +
90949 + if (strstr(mod->args, "grsec_modharden_netdev")) {
90950 + 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);
90951 + err = -EPERM;
90952 + goto free_modinfo;
90953 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
90954 + p += sizeof("grsec_modharden_normal") - 1;
90955 + p2 = strstr(p, "_");
90956 + if (p2) {
90957 + *p2 = '\0';
90958 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
90959 + *p2 = '_';
90960 + }
90961 + err = -EPERM;
90962 + goto free_modinfo;
90963 + }
90964 + }
90965 +#endif
90966 +
90967 /* Fix up syms, so that st_value is a pointer to location. */
90968 err = simplify_symbols(mod, info);
90969 if (err < 0)
90970 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
90971
90972 flush_module_icache(mod);
90973
90974 - /* Now copy in args */
90975 - mod->args = strndup_user(uargs, ~0UL >> 1);
90976 - if (IS_ERR(mod->args)) {
90977 - err = PTR_ERR(mod->args);
90978 - goto free_arch_cleanup;
90979 - }
90980 -
90981 dynamic_debug_setup(info->debug, info->num_debug);
90982
90983 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
90984 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
90985 ddebug_cleanup:
90986 dynamic_debug_remove(info->debug);
90987 synchronize_sched();
90988 - kfree(mod->args);
90989 - free_arch_cleanup:
90990 module_arch_cleanup(mod);
90991 free_modinfo:
90992 free_modinfo(mod);
90993 + kfree(mod->args);
90994 free_unload:
90995 module_unload_free(mod);
90996 unlink_mod:
90997 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
90998 unsigned long nextval;
90999
91000 /* At worse, next value is at end of module */
91001 - if (within_module_init(addr, mod))
91002 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91003 + if (within_module_init_rx(addr, mod))
91004 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91005 + else if (within_module_init_rw(addr, mod))
91006 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91007 + else if (within_module_core_rx(addr, mod))
91008 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91009 + else if (within_module_core_rw(addr, mod))
91010 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91011 else
91012 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91013 + return NULL;
91014
91015 /* Scan for closest preceding symbol, and next symbol. (ELF
91016 starts real symbols at 1). */
91017 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91018 return 0;
91019
91020 seq_printf(m, "%s %u",
91021 - mod->name, mod->init_size + mod->core_size);
91022 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91023 print_unload_info(m, mod);
91024
91025 /* Informative for users. */
91026 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91027 mod->state == MODULE_STATE_COMING ? "Loading":
91028 "Live");
91029 /* Used by oprofile and other similar tools. */
91030 - seq_printf(m, " 0x%pK", mod->module_core);
91031 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91032
91033 /* Taints info */
91034 if (mod->taints)
91035 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91036
91037 static int __init proc_modules_init(void)
91038 {
91039 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91040 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91041 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91042 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91043 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91044 +#else
91045 proc_create("modules", 0, NULL, &proc_modules_operations);
91046 +#endif
91047 +#else
91048 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91049 +#endif
91050 return 0;
91051 }
91052 module_init(proc_modules_init);
91053 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91054 {
91055 struct module *mod;
91056
91057 - if (addr < module_addr_min || addr > module_addr_max)
91058 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91059 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91060 return NULL;
91061
91062 list_for_each_entry_rcu(mod, &modules, list) {
91063 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91064 */
91065 struct module *__module_text_address(unsigned long addr)
91066 {
91067 - struct module *mod = __module_address(addr);
91068 + struct module *mod;
91069 +
91070 +#ifdef CONFIG_X86_32
91071 + addr = ktla_ktva(addr);
91072 +#endif
91073 +
91074 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91075 + return NULL;
91076 +
91077 + mod = __module_address(addr);
91078 +
91079 if (mod) {
91080 /* Make sure it's within the text section. */
91081 - if (!within(addr, mod->module_init, mod->init_text_size)
91082 - && !within(addr, mod->module_core, mod->core_text_size))
91083 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91084 mod = NULL;
91085 }
91086 return mod;
91087 diff --git a/kernel/notifier.c b/kernel/notifier.c
91088 index 4803da6..1c5eea6 100644
91089 --- a/kernel/notifier.c
91090 +++ b/kernel/notifier.c
91091 @@ -5,6 +5,7 @@
91092 #include <linux/rcupdate.h>
91093 #include <linux/vmalloc.h>
91094 #include <linux/reboot.h>
91095 +#include <linux/mm.h>
91096
91097 /*
91098 * Notifier list for kernel code which wants to be called
91099 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91100 while ((*nl) != NULL) {
91101 if (n->priority > (*nl)->priority)
91102 break;
91103 - nl = &((*nl)->next);
91104 + nl = (struct notifier_block **)&((*nl)->next);
91105 }
91106 - n->next = *nl;
91107 + pax_open_kernel();
91108 + *(const void **)&n->next = *nl;
91109 rcu_assign_pointer(*nl, n);
91110 + pax_close_kernel();
91111 return 0;
91112 }
91113
91114 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91115 return 0;
91116 if (n->priority > (*nl)->priority)
91117 break;
91118 - nl = &((*nl)->next);
91119 + nl = (struct notifier_block **)&((*nl)->next);
91120 }
91121 - n->next = *nl;
91122 + pax_open_kernel();
91123 + *(const void **)&n->next = *nl;
91124 rcu_assign_pointer(*nl, n);
91125 + pax_close_kernel();
91126 return 0;
91127 }
91128
91129 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91130 {
91131 while ((*nl) != NULL) {
91132 if ((*nl) == n) {
91133 + pax_open_kernel();
91134 rcu_assign_pointer(*nl, n->next);
91135 + pax_close_kernel();
91136 return 0;
91137 }
91138 - nl = &((*nl)->next);
91139 + nl = (struct notifier_block **)&((*nl)->next);
91140 }
91141 return -ENOENT;
91142 }
91143 diff --git a/kernel/padata.c b/kernel/padata.c
91144 index 161402f..598814c 100644
91145 --- a/kernel/padata.c
91146 +++ b/kernel/padata.c
91147 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91148 * seq_nr mod. number of cpus in use.
91149 */
91150
91151 - seq_nr = atomic_inc_return(&pd->seq_nr);
91152 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91153 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91154
91155 return padata_index_to_cpu(pd, cpu_index);
91156 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91157 padata_init_pqueues(pd);
91158 padata_init_squeues(pd);
91159 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91160 - atomic_set(&pd->seq_nr, -1);
91161 + atomic_set_unchecked(&pd->seq_nr, -1);
91162 atomic_set(&pd->reorder_objects, 0);
91163 atomic_set(&pd->refcnt, 0);
91164 pd->pinst = pinst;
91165 diff --git a/kernel/panic.c b/kernel/panic.c
91166 index cf80672..f6771b2 100644
91167 --- a/kernel/panic.c
91168 +++ b/kernel/panic.c
91169 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91170 /*
91171 * Stop ourself in panic -- architecture code may override this
91172 */
91173 -void __weak panic_smp_self_stop(void)
91174 +void __weak __noreturn panic_smp_self_stop(void)
91175 {
91176 while (1)
91177 cpu_relax();
91178 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91179 disable_trace_on_warning();
91180
91181 pr_warn("------------[ cut here ]------------\n");
91182 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91183 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91184 raw_smp_processor_id(), current->pid, file, line, caller);
91185
91186 if (args)
91187 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91188 */
91189 __visible void __stack_chk_fail(void)
91190 {
91191 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91192 + dump_stack();
91193 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91194 __builtin_return_address(0));
91195 }
91196 EXPORT_SYMBOL(__stack_chk_fail);
91197 diff --git a/kernel/pid.c b/kernel/pid.c
91198 index 82430c8..53d7793 100644
91199 --- a/kernel/pid.c
91200 +++ b/kernel/pid.c
91201 @@ -33,6 +33,7 @@
91202 #include <linux/rculist.h>
91203 #include <linux/bootmem.h>
91204 #include <linux/hash.h>
91205 +#include <linux/security.h>
91206 #include <linux/pid_namespace.h>
91207 #include <linux/init_task.h>
91208 #include <linux/syscalls.h>
91209 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91210
91211 int pid_max = PID_MAX_DEFAULT;
91212
91213 -#define RESERVED_PIDS 300
91214 +#define RESERVED_PIDS 500
91215
91216 int pid_max_min = RESERVED_PIDS + 1;
91217 int pid_max_max = PID_MAX_LIMIT;
91218 @@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
91219 */
91220 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91221 {
91222 + struct task_struct *task;
91223 +
91224 rcu_lockdep_assert(rcu_read_lock_held(),
91225 "find_task_by_pid_ns() needs rcu_read_lock()"
91226 " protection");
91227 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91228 +
91229 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91230 +
91231 + if (gr_pid_is_chrooted(task))
91232 + return NULL;
91233 +
91234 + return task;
91235 }
91236
91237 struct task_struct *find_task_by_vpid(pid_t vnr)
91238 @@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91239 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91240 }
91241
91242 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91243 +{
91244 + rcu_lockdep_assert(rcu_read_lock_held(),
91245 + "find_task_by_pid_ns() needs rcu_read_lock()"
91246 + " protection");
91247 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91248 +}
91249 +
91250 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91251 {
91252 struct pid *pid;
91253 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91254 index db95d8e..a0ca23f 100644
91255 --- a/kernel/pid_namespace.c
91256 +++ b/kernel/pid_namespace.c
91257 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91258 void __user *buffer, size_t *lenp, loff_t *ppos)
91259 {
91260 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91261 - struct ctl_table tmp = *table;
91262 + ctl_table_no_const tmp = *table;
91263
91264 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91265 return -EPERM;
91266 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91267 index bbef57f..5f94462 100644
91268 --- a/kernel/power/Kconfig
91269 +++ b/kernel/power/Kconfig
91270 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91271 config HIBERNATION
91272 bool "Hibernation (aka 'suspend to disk')"
91273 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91274 + depends on !GRKERNSEC_KMEM
91275 + depends on !PAX_MEMORY_SANITIZE
91276 select HIBERNATE_CALLBACKS
91277 select LZO_COMPRESS
91278 select LZO_DECOMPRESS
91279 diff --git a/kernel/power/process.c b/kernel/power/process.c
91280 index 5a6ec86..3a8c884 100644
91281 --- a/kernel/power/process.c
91282 +++ b/kernel/power/process.c
91283 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91284 unsigned int elapsed_msecs;
91285 bool wakeup = false;
91286 int sleep_usecs = USEC_PER_MSEC;
91287 + bool timedout = false;
91288
91289 do_gettimeofday(&start);
91290
91291 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91292
91293 while (true) {
91294 todo = 0;
91295 + if (time_after(jiffies, end_time))
91296 + timedout = true;
91297 read_lock(&tasklist_lock);
91298 for_each_process_thread(g, p) {
91299 if (p == current || !freeze_task(p))
91300 continue;
91301
91302 - if (!freezer_should_skip(p))
91303 + if (!freezer_should_skip(p)) {
91304 todo++;
91305 + if (timedout) {
91306 + printk(KERN_ERR "Task refusing to freeze:\n");
91307 + sched_show_task(p);
91308 + }
91309 + }
91310 }
91311 read_unlock(&tasklist_lock);
91312
91313 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91314 todo += wq_busy;
91315 }
91316
91317 - if (!todo || time_after(jiffies, end_time))
91318 + if (!todo || timedout)
91319 break;
91320
91321 if (pm_wakeup_pending()) {
91322 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91323 index ced2b84..ffc4791 100644
91324 --- a/kernel/printk/printk.c
91325 +++ b/kernel/printk/printk.c
91326 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91327 if (from_file && type != SYSLOG_ACTION_OPEN)
91328 return 0;
91329
91330 +#ifdef CONFIG_GRKERNSEC_DMESG
91331 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91332 + return -EPERM;
91333 +#endif
91334 +
91335 if (syslog_action_restricted(type)) {
91336 if (capable(CAP_SYSLOG))
91337 return 0;
91338 diff --git a/kernel/profile.c b/kernel/profile.c
91339 index 54bf5ba..df6e0a2 100644
91340 --- a/kernel/profile.c
91341 +++ b/kernel/profile.c
91342 @@ -37,7 +37,7 @@ struct profile_hit {
91343 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91344 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91345
91346 -static atomic_t *prof_buffer;
91347 +static atomic_unchecked_t *prof_buffer;
91348 static unsigned long prof_len, prof_shift;
91349
91350 int prof_on __read_mostly;
91351 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91352 hits[i].pc = 0;
91353 continue;
91354 }
91355 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91356 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91357 hits[i].hits = hits[i].pc = 0;
91358 }
91359 }
91360 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91361 * Add the current hit(s) and flush the write-queue out
91362 * to the global buffer:
91363 */
91364 - atomic_add(nr_hits, &prof_buffer[pc]);
91365 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91366 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91367 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91368 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91369 hits[i].pc = hits[i].hits = 0;
91370 }
91371 out:
91372 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91373 {
91374 unsigned long pc;
91375 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91376 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91377 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91378 }
91379 #endif /* !CONFIG_SMP */
91380
91381 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91382 return -EFAULT;
91383 buf++; p++; count--; read++;
91384 }
91385 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91386 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91387 if (copy_to_user(buf, (void *)pnt, count))
91388 return -EFAULT;
91389 read += count;
91390 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91391 }
91392 #endif
91393 profile_discard_flip_buffers();
91394 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91395 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91396 return count;
91397 }
91398
91399 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91400 index 54e7522..5b82dd6 100644
91401 --- a/kernel/ptrace.c
91402 +++ b/kernel/ptrace.c
91403 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91404 if (seize)
91405 flags |= PT_SEIZED;
91406 rcu_read_lock();
91407 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91408 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91409 flags |= PT_PTRACE_CAP;
91410 rcu_read_unlock();
91411 task->ptrace = flags;
91412 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91413 break;
91414 return -EIO;
91415 }
91416 - if (copy_to_user(dst, buf, retval))
91417 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91418 return -EFAULT;
91419 copied += retval;
91420 src += retval;
91421 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91422 bool seized = child->ptrace & PT_SEIZED;
91423 int ret = -EIO;
91424 siginfo_t siginfo, *si;
91425 - void __user *datavp = (void __user *) data;
91426 + void __user *datavp = (__force void __user *) data;
91427 unsigned long __user *datalp = datavp;
91428 unsigned long flags;
91429
91430 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91431 goto out;
91432 }
91433
91434 + if (gr_handle_ptrace(child, request)) {
91435 + ret = -EPERM;
91436 + goto out_put_task_struct;
91437 + }
91438 +
91439 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91440 ret = ptrace_attach(child, request, addr, data);
91441 /*
91442 * Some architectures need to do book-keeping after
91443 * a ptrace attach.
91444 */
91445 - if (!ret)
91446 + if (!ret) {
91447 arch_ptrace_attach(child);
91448 + gr_audit_ptrace(child);
91449 + }
91450 goto out_put_task_struct;
91451 }
91452
91453 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91454 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91455 if (copied != sizeof(tmp))
91456 return -EIO;
91457 - return put_user(tmp, (unsigned long __user *)data);
91458 + return put_user(tmp, (__force unsigned long __user *)data);
91459 }
91460
91461 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91462 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91463 }
91464
91465 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91466 - compat_long_t, addr, compat_long_t, data)
91467 + compat_ulong_t, addr, compat_ulong_t, data)
91468 {
91469 struct task_struct *child;
91470 long ret;
91471 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91472 goto out;
91473 }
91474
91475 + if (gr_handle_ptrace(child, request)) {
91476 + ret = -EPERM;
91477 + goto out_put_task_struct;
91478 + }
91479 +
91480 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91481 ret = ptrace_attach(child, request, addr, data);
91482 /*
91483 * Some architectures need to do book-keeping after
91484 * a ptrace attach.
91485 */
91486 - if (!ret)
91487 + if (!ret) {
91488 arch_ptrace_attach(child);
91489 + gr_audit_ptrace(child);
91490 + }
91491 goto out_put_task_struct;
91492 }
91493
91494 diff --git a/kernel/range.c b/kernel/range.c
91495 index 322ea8e..82cfc28 100644
91496 --- a/kernel/range.c
91497 +++ b/kernel/range.c
91498 @@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
91499 {
91500 const struct range *r1 = x1;
91501 const struct range *r2 = x2;
91502 - s64 start1, start2;
91503
91504 - start1 = r1->start;
91505 - start2 = r2->start;
91506 -
91507 - return start1 - start2;
91508 + if (r1->start < r2->start)
91509 + return -1;
91510 + if (r1->start > r2->start)
91511 + return 1;
91512 + return 0;
91513 }
91514
91515 int clean_sort_range(struct range *range, int az)
91516 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91517 index 240fa90..5fa56bd 100644
91518 --- a/kernel/rcu/rcutorture.c
91519 +++ b/kernel/rcu/rcutorture.c
91520 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91521 rcu_torture_count) = { 0 };
91522 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91523 rcu_torture_batch) = { 0 };
91524 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91525 -static atomic_t n_rcu_torture_alloc;
91526 -static atomic_t n_rcu_torture_alloc_fail;
91527 -static atomic_t n_rcu_torture_free;
91528 -static atomic_t n_rcu_torture_mberror;
91529 -static atomic_t n_rcu_torture_error;
91530 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91531 +static atomic_unchecked_t n_rcu_torture_alloc;
91532 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91533 +static atomic_unchecked_t n_rcu_torture_free;
91534 +static atomic_unchecked_t n_rcu_torture_mberror;
91535 +static atomic_unchecked_t n_rcu_torture_error;
91536 static long n_rcu_torture_barrier_error;
91537 static long n_rcu_torture_boost_ktrerror;
91538 static long n_rcu_torture_boost_rterror;
91539 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91540 static long n_rcu_torture_timers;
91541 static long n_barrier_attempts;
91542 static long n_barrier_successes;
91543 -static atomic_long_t n_cbfloods;
91544 +static atomic_long_unchecked_t n_cbfloods;
91545 static struct list_head rcu_torture_removed;
91546
91547 static int rcu_torture_writer_state;
91548 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91549
91550 spin_lock_bh(&rcu_torture_lock);
91551 if (list_empty(&rcu_torture_freelist)) {
91552 - atomic_inc(&n_rcu_torture_alloc_fail);
91553 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91554 spin_unlock_bh(&rcu_torture_lock);
91555 return NULL;
91556 }
91557 - atomic_inc(&n_rcu_torture_alloc);
91558 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91559 p = rcu_torture_freelist.next;
91560 list_del_init(p);
91561 spin_unlock_bh(&rcu_torture_lock);
91562 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91563 static void
91564 rcu_torture_free(struct rcu_torture *p)
91565 {
91566 - atomic_inc(&n_rcu_torture_free);
91567 + atomic_inc_unchecked(&n_rcu_torture_free);
91568 spin_lock_bh(&rcu_torture_lock);
91569 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91570 spin_unlock_bh(&rcu_torture_lock);
91571 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91572 i = rp->rtort_pipe_count;
91573 if (i > RCU_TORTURE_PIPE_LEN)
91574 i = RCU_TORTURE_PIPE_LEN;
91575 - atomic_inc(&rcu_torture_wcount[i]);
91576 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91577 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91578 rp->rtort_mbtest = 0;
91579 return true;
91580 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91581 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91582 do {
91583 schedule_timeout_interruptible(cbflood_inter_holdoff);
91584 - atomic_long_inc(&n_cbfloods);
91585 + atomic_long_inc_unchecked(&n_cbfloods);
91586 WARN_ON(signal_pending(current));
91587 for (i = 0; i < cbflood_n_burst; i++) {
91588 for (j = 0; j < cbflood_n_per_burst; j++) {
91589 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91590 i = old_rp->rtort_pipe_count;
91591 if (i > RCU_TORTURE_PIPE_LEN)
91592 i = RCU_TORTURE_PIPE_LEN;
91593 - atomic_inc(&rcu_torture_wcount[i]);
91594 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91595 old_rp->rtort_pipe_count++;
91596 switch (synctype[torture_random(&rand) % nsynctypes]) {
91597 case RTWS_DEF_FREE:
91598 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91599 return;
91600 }
91601 if (p->rtort_mbtest == 0)
91602 - atomic_inc(&n_rcu_torture_mberror);
91603 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91604 spin_lock(&rand_lock);
91605 cur_ops->read_delay(&rand);
91606 n_rcu_torture_timers++;
91607 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91608 continue;
91609 }
91610 if (p->rtort_mbtest == 0)
91611 - atomic_inc(&n_rcu_torture_mberror);
91612 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91613 cur_ops->read_delay(&rand);
91614 preempt_disable();
91615 pipe_count = p->rtort_pipe_count;
91616 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91617 rcu_torture_current,
91618 rcu_torture_current_version,
91619 list_empty(&rcu_torture_freelist),
91620 - atomic_read(&n_rcu_torture_alloc),
91621 - atomic_read(&n_rcu_torture_alloc_fail),
91622 - atomic_read(&n_rcu_torture_free));
91623 + atomic_read_unchecked(&n_rcu_torture_alloc),
91624 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91625 + atomic_read_unchecked(&n_rcu_torture_free));
91626 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91627 - atomic_read(&n_rcu_torture_mberror),
91628 + atomic_read_unchecked(&n_rcu_torture_mberror),
91629 n_rcu_torture_boost_ktrerror,
91630 n_rcu_torture_boost_rterror);
91631 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91632 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91633 n_barrier_successes,
91634 n_barrier_attempts,
91635 n_rcu_torture_barrier_error);
91636 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91637 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91638
91639 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91640 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91641 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91642 n_rcu_torture_barrier_error != 0 ||
91643 n_rcu_torture_boost_ktrerror != 0 ||
91644 n_rcu_torture_boost_rterror != 0 ||
91645 n_rcu_torture_boost_failure != 0 ||
91646 i > 1) {
91647 pr_cont("%s", "!!! ");
91648 - atomic_inc(&n_rcu_torture_error);
91649 + atomic_inc_unchecked(&n_rcu_torture_error);
91650 WARN_ON_ONCE(1);
91651 }
91652 pr_cont("Reader Pipe: ");
91653 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91654 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91655 pr_cont("Free-Block Circulation: ");
91656 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91657 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91658 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91659 }
91660 pr_cont("\n");
91661
91662 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91663
91664 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91665
91666 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91667 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91668 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91669 else if (torture_onoff_failures())
91670 rcu_torture_print_module_parms(cur_ops,
91671 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91672
91673 rcu_torture_current = NULL;
91674 rcu_torture_current_version = 0;
91675 - atomic_set(&n_rcu_torture_alloc, 0);
91676 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91677 - atomic_set(&n_rcu_torture_free, 0);
91678 - atomic_set(&n_rcu_torture_mberror, 0);
91679 - atomic_set(&n_rcu_torture_error, 0);
91680 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91681 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91682 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91683 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91684 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91685 n_rcu_torture_barrier_error = 0;
91686 n_rcu_torture_boost_ktrerror = 0;
91687 n_rcu_torture_boost_rterror = 0;
91688 n_rcu_torture_boost_failure = 0;
91689 n_rcu_torture_boosts = 0;
91690 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91691 - atomic_set(&rcu_torture_wcount[i], 0);
91692 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91693 for_each_possible_cpu(cpu) {
91694 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91695 per_cpu(rcu_torture_count, cpu)[i] = 0;
91696 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91697 index c0623fc..329c091 100644
91698 --- a/kernel/rcu/tiny.c
91699 +++ b/kernel/rcu/tiny.c
91700 @@ -42,7 +42,7 @@
91701 /* Forward declarations for tiny_plugin.h. */
91702 struct rcu_ctrlblk;
91703 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91704 -static void rcu_process_callbacks(struct softirq_action *unused);
91705 +static void rcu_process_callbacks(void);
91706 static void __call_rcu(struct rcu_head *head,
91707 void (*func)(struct rcu_head *rcu),
91708 struct rcu_ctrlblk *rcp);
91709 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91710 false));
91711 }
91712
91713 -static void rcu_process_callbacks(struct softirq_action *unused)
91714 +static __latent_entropy void rcu_process_callbacks(void)
91715 {
91716 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91717 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91718 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91719 index 858c565..7efd915 100644
91720 --- a/kernel/rcu/tiny_plugin.h
91721 +++ b/kernel/rcu/tiny_plugin.h
91722 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91723 dump_stack();
91724 }
91725 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91726 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91727 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91728 3 * rcu_jiffies_till_stall_check() + 3;
91729 else if (ULONG_CMP_GE(j, js))
91730 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91731 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91732 }
91733
91734 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91735 {
91736 rcp->ticks_this_gp = 0;
91737 rcp->gp_start = jiffies;
91738 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91739 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91740 }
91741
91742 static void check_cpu_stalls(void)
91743 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91744 index 9815447..2cdf92a 100644
91745 --- a/kernel/rcu/tree.c
91746 +++ b/kernel/rcu/tree.c
91747 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91748 */
91749 rdtp = this_cpu_ptr(&rcu_dynticks);
91750 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91751 - atomic_add(2, &rdtp->dynticks); /* QS. */
91752 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91753 smp_mb__after_atomic(); /* Later stuff after QS. */
91754 break;
91755 }
91756 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91757 rcu_prepare_for_idle(smp_processor_id());
91758 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91759 smp_mb__before_atomic(); /* See above. */
91760 - atomic_inc(&rdtp->dynticks);
91761 + atomic_inc_unchecked(&rdtp->dynticks);
91762 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91763 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91764 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91765 rcu_dynticks_task_enter();
91766
91767 /*
91768 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91769 {
91770 rcu_dynticks_task_exit();
91771 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91772 - atomic_inc(&rdtp->dynticks);
91773 + atomic_inc_unchecked(&rdtp->dynticks);
91774 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91775 smp_mb__after_atomic(); /* See above. */
91776 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91777 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91778 rcu_cleanup_after_idle(smp_processor_id());
91779 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91780 if (!user && !is_idle_task(current)) {
91781 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91782 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91783
91784 if (rdtp->dynticks_nmi_nesting == 0 &&
91785 - (atomic_read(&rdtp->dynticks) & 0x1))
91786 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91787 return;
91788 rdtp->dynticks_nmi_nesting++;
91789 smp_mb__before_atomic(); /* Force delay from prior write. */
91790 - atomic_inc(&rdtp->dynticks);
91791 + atomic_inc_unchecked(&rdtp->dynticks);
91792 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91793 smp_mb__after_atomic(); /* See above. */
91794 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91795 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91796 }
91797
91798 /**
91799 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91800 return;
91801 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91802 smp_mb__before_atomic(); /* See above. */
91803 - atomic_inc(&rdtp->dynticks);
91804 + atomic_inc_unchecked(&rdtp->dynticks);
91805 smp_mb__after_atomic(); /* Force delay to next write. */
91806 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91807 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91808 }
91809
91810 /**
91811 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91812 */
91813 bool notrace __rcu_is_watching(void)
91814 {
91815 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91816 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91817 }
91818
91819 /**
91820 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91821 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91822 bool *isidle, unsigned long *maxj)
91823 {
91824 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91825 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91826 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91827 if ((rdp->dynticks_snap & 0x1) == 0) {
91828 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91829 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91830 int *rcrmp;
91831 unsigned int snap;
91832
91833 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91834 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91835 snap = (unsigned int)rdp->dynticks_snap;
91836
91837 /*
91838 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91839 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91840 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91841 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91842 - ACCESS_ONCE(rdp->cond_resched_completed) =
91843 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91844 ACCESS_ONCE(rdp->mynode->completed);
91845 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91846 - ACCESS_ONCE(*rcrmp) =
91847 + ACCESS_ONCE_RW(*rcrmp) =
91848 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91849 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91850 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91851 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91852 rsp->gp_start = j;
91853 smp_wmb(); /* Record start time before stall time. */
91854 j1 = rcu_jiffies_till_stall_check();
91855 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91856 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91857 rsp->jiffies_resched = j + j1 / 2;
91858 }
91859
91860 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91861 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91862 return;
91863 }
91864 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91865 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91866 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91867
91868 /*
91869 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91870
91871 raw_spin_lock_irqsave(&rnp->lock, flags);
91872 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91873 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91874 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91875 3 * rcu_jiffies_till_stall_check() + 3;
91876 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91877
91878 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
91879 struct rcu_state *rsp;
91880
91881 for_each_rcu_flavor(rsp)
91882 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91883 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91884 }
91885
91886 /*
91887 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91888 raw_spin_unlock_irq(&rnp->lock);
91889 return 0;
91890 }
91891 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91892 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91893
91894 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91895 /*
91896 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91897 rdp = this_cpu_ptr(rsp->rda);
91898 rcu_preempt_check_blocked_tasks(rnp);
91899 rnp->qsmask = rnp->qsmaskinit;
91900 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91901 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91902 WARN_ON_ONCE(rnp->completed != rsp->completed);
91903 - ACCESS_ONCE(rnp->completed) = rsp->completed;
91904 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91905 if (rnp == rdp->mynode)
91906 (void)__note_gp_changes(rsp, rnp, rdp);
91907 rcu_preempt_boost_start_gp(rnp);
91908 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91909 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91910 raw_spin_lock_irq(&rnp->lock);
91911 smp_mb__after_unlock_lock();
91912 - ACCESS_ONCE(rsp->gp_flags) =
91913 + ACCESS_ONCE_RW(rsp->gp_flags) =
91914 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
91915 raw_spin_unlock_irq(&rnp->lock);
91916 }
91917 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91918 rcu_for_each_node_breadth_first(rsp, rnp) {
91919 raw_spin_lock_irq(&rnp->lock);
91920 smp_mb__after_unlock_lock();
91921 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91922 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91923 rdp = this_cpu_ptr(rsp->rda);
91924 if (rnp == rdp->mynode)
91925 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91926 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91927 rcu_nocb_gp_set(rnp, nocb);
91928
91929 /* Declare grace period done. */
91930 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91931 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91932 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91933 rsp->fqs_state = RCU_GP_IDLE;
91934 rdp = this_cpu_ptr(rsp->rda);
91935 /* Advance CBs to reduce false positives below. */
91936 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91937 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91938 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91939 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91940 trace_rcu_grace_period(rsp->name,
91941 ACCESS_ONCE(rsp->gpnum),
91942 TPS("newreq"));
91943 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91944 */
91945 return false;
91946 }
91947 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91948 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91949 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91950 TPS("newreq"));
91951
91952 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91953 rsp->qlen += rdp->qlen;
91954 rdp->n_cbs_orphaned += rdp->qlen;
91955 rdp->qlen_lazy = 0;
91956 - ACCESS_ONCE(rdp->qlen) = 0;
91957 + ACCESS_ONCE_RW(rdp->qlen) = 0;
91958 }
91959
91960 /*
91961 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91962 }
91963 smp_mb(); /* List handling before counting for rcu_barrier(). */
91964 rdp->qlen_lazy -= count_lazy;
91965 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91966 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91967 rdp->n_cbs_invoked += count;
91968
91969 /* Reinstate batch limit if we have worked down the excess. */
91970 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91971 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91972 return; /* Someone beat us to it. */
91973 }
91974 - ACCESS_ONCE(rsp->gp_flags) =
91975 + ACCESS_ONCE_RW(rsp->gp_flags) =
91976 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
91977 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91978 rcu_gp_kthread_wake(rsp);
91979 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
91980 /*
91981 * Do RCU core processing for the current CPU.
91982 */
91983 -static void rcu_process_callbacks(struct softirq_action *unused)
91984 +static void rcu_process_callbacks(void)
91985 {
91986 struct rcu_state *rsp;
91987
91988 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91989 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
91990 if (debug_rcu_head_queue(head)) {
91991 /* Probable double call_rcu(), so leak the callback. */
91992 - ACCESS_ONCE(head->func) = rcu_leak_callback;
91993 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
91994 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
91995 return;
91996 }
91997 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91998 local_irq_restore(flags);
91999 return;
92000 }
92001 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92002 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92003 if (lazy)
92004 rdp->qlen_lazy++;
92005 else
92006 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
92007 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92008 * course be required on a 64-bit system.
92009 */
92010 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92011 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92012 (ulong)atomic_long_read(&rsp->expedited_done) +
92013 ULONG_MAX / 8)) {
92014 synchronize_sched();
92015 - atomic_long_inc(&rsp->expedited_wrap);
92016 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92017 return;
92018 }
92019
92020 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
92021 * Take a ticket. Note that atomic_inc_return() implies a
92022 * full memory barrier.
92023 */
92024 - snap = atomic_long_inc_return(&rsp->expedited_start);
92025 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92026 firstsnap = snap;
92027 if (!try_get_online_cpus()) {
92028 /* CPU hotplug operation in flight, fall back to normal GP. */
92029 wait_rcu_gp(call_rcu_sched);
92030 - atomic_long_inc(&rsp->expedited_normal);
92031 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92032 return;
92033 }
92034 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92035 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
92036 synchronize_sched_expedited_cpu_stop,
92037 NULL) == -EAGAIN) {
92038 put_online_cpus();
92039 - atomic_long_inc(&rsp->expedited_tryfail);
92040 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92041
92042 /* Check to see if someone else did our work for us. */
92043 s = atomic_long_read(&rsp->expedited_done);
92044 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92045 /* ensure test happens before caller kfree */
92046 smp_mb__before_atomic(); /* ^^^ */
92047 - atomic_long_inc(&rsp->expedited_workdone1);
92048 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92049 return;
92050 }
92051
92052 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
92053 udelay(trycount * num_online_cpus());
92054 } else {
92055 wait_rcu_gp(call_rcu_sched);
92056 - atomic_long_inc(&rsp->expedited_normal);
92057 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92058 return;
92059 }
92060
92061 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
92062 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92063 /* ensure test happens before caller kfree */
92064 smp_mb__before_atomic(); /* ^^^ */
92065 - atomic_long_inc(&rsp->expedited_workdone2);
92066 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92067 return;
92068 }
92069
92070 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
92071 if (!try_get_online_cpus()) {
92072 /* CPU hotplug operation in flight, use normal GP. */
92073 wait_rcu_gp(call_rcu_sched);
92074 - atomic_long_inc(&rsp->expedited_normal);
92075 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92076 return;
92077 }
92078 - snap = atomic_long_read(&rsp->expedited_start);
92079 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92080 smp_mb(); /* ensure read is before try_stop_cpus(). */
92081 }
92082 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92083 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92084
92085 /*
92086 * Everyone up to our most recent fetch is covered by our grace
92087 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92088 * than we did already did their update.
92089 */
92090 do {
92091 - atomic_long_inc(&rsp->expedited_done_tries);
92092 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92093 s = atomic_long_read(&rsp->expedited_done);
92094 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92095 /* ensure test happens before caller kfree */
92096 smp_mb__before_atomic(); /* ^^^ */
92097 - atomic_long_inc(&rsp->expedited_done_lost);
92098 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92099 break;
92100 }
92101 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92102 - atomic_long_inc(&rsp->expedited_done_exit);
92103 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92104
92105 put_online_cpus();
92106 }
92107 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92108 * ACCESS_ONCE() to prevent the compiler from speculating
92109 * the increment to precede the early-exit check.
92110 */
92111 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92112 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92113 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92114 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92115 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92116 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92117
92118 /* Increment ->n_barrier_done to prevent duplicate work. */
92119 smp_mb(); /* Keep increment after above mechanism. */
92120 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92121 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92122 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92123 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92124 smp_mb(); /* Keep increment before caller's subsequent code. */
92125 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92126 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92127 init_callback_list(rdp);
92128 rdp->qlen_lazy = 0;
92129 - ACCESS_ONCE(rdp->qlen) = 0;
92130 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92131 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92132 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92133 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92134 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92135 rdp->cpu = cpu;
92136 rdp->rsp = rsp;
92137 rcu_boot_init_nocb_percpu_data(rdp);
92138 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92139 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92140 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92141 rcu_sysidle_init_percpu_data(rdp->dynticks);
92142 - atomic_set(&rdp->dynticks->dynticks,
92143 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92144 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92145 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92146 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92147
92148 /* Add CPU to rcu_node bitmasks. */
92149 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92150 index bbdc45d..c882ccb 100644
92151 --- a/kernel/rcu/tree.h
92152 +++ b/kernel/rcu/tree.h
92153 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92154 long long dynticks_nesting; /* Track irq/process nesting level. */
92155 /* Process level is worth LLONG_MAX/2. */
92156 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92157 - atomic_t dynticks; /* Even value for idle, else odd. */
92158 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92159 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92160 long long dynticks_idle_nesting;
92161 /* irq/process nesting level from idle. */
92162 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92163 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92164 /* "Idle" excludes userspace execution. */
92165 unsigned long dynticks_idle_jiffies;
92166 /* End of last non-NMI non-idle period. */
92167 @@ -466,17 +466,17 @@ struct rcu_state {
92168 /* _rcu_barrier(). */
92169 /* End of fields guarded by barrier_mutex. */
92170
92171 - atomic_long_t expedited_start; /* Starting ticket. */
92172 - atomic_long_t expedited_done; /* Done ticket. */
92173 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92174 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92175 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92176 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92177 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92178 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92179 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92180 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92181 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92182 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92183 + atomic_long_t expedited_done; /* Done ticket. */
92184 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92185 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92186 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92187 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92188 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92189 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92190 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92191 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92192 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92193
92194 unsigned long jiffies_force_qs; /* Time at which to invoke */
92195 /* force_quiescent_state(). */
92196 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92197 index c1d7f27..a64bf49 100644
92198 --- a/kernel/rcu/tree_plugin.h
92199 +++ b/kernel/rcu/tree_plugin.h
92200 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92201 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92202 {
92203 return !rcu_preempted_readers_exp(rnp) &&
92204 - ACCESS_ONCE(rnp->expmask) == 0;
92205 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92206 }
92207
92208 /*
92209 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92210
92211 /* Clean up and exit. */
92212 smp_mb(); /* ensure expedited GP seen before counter increment. */
92213 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92214 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92215 sync_rcu_preempt_exp_count + 1;
92216 unlock_mb_ret:
92217 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92218 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92219 free_cpumask_var(cm);
92220 }
92221
92222 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92223 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92224 .store = &rcu_cpu_kthread_task,
92225 .thread_should_run = rcu_cpu_kthread_should_run,
92226 .thread_fn = rcu_cpu_kthread,
92227 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92228 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92229 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92230 cpu, ticks_value, ticks_title,
92231 - atomic_read(&rdtp->dynticks) & 0xfff,
92232 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92233 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92234 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92235 fast_no_hz);
92236 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92237 return;
92238 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92239 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92240 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92241 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92242 wake_up(&rdp_leader->nocb_wq);
92243 }
92244 }
92245 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92246
92247 /* Enqueue the callback on the nocb list and update counts. */
92248 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92249 - ACCESS_ONCE(*old_rhpp) = rhp;
92250 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92251 atomic_long_add(rhcount, &rdp->nocb_q_count);
92252 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92253 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92254 @@ -2286,7 +2286,7 @@ wait_again:
92255 continue; /* No CBs here, try next follower. */
92256
92257 /* Move callbacks to wait-for-GP list, which is empty. */
92258 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92259 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92260 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92261 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92262 rdp->nocb_gp_count_lazy =
92263 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92264 list = ACCESS_ONCE(rdp->nocb_follower_head);
92265 BUG_ON(!list);
92266 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92267 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92268 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92269 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92270 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92271 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92272 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92273 list = next;
92274 }
92275 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92276 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92277 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92278 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92279 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92280 rdp->nocb_p_count_lazy - cl;
92281 rdp->n_nocbs_invoked += c;
92282 }
92283 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92284 if (!rcu_nocb_need_deferred_wakeup(rdp))
92285 return;
92286 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92287 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92288 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92289 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92290 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92291 }
92292 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92293 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92294 "rcuo%c/%d", rsp->abbr, cpu);
92295 BUG_ON(IS_ERR(t));
92296 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92297 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92298 }
92299
92300 /*
92301 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92302
92303 /* Record start of fully idle period. */
92304 j = jiffies;
92305 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92306 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92307 smp_mb__before_atomic();
92308 - atomic_inc(&rdtp->dynticks_idle);
92309 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92310 smp_mb__after_atomic();
92311 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92312 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92313 }
92314
92315 /*
92316 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92317
92318 /* Record end of idle period. */
92319 smp_mb__before_atomic();
92320 - atomic_inc(&rdtp->dynticks_idle);
92321 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92322 smp_mb__after_atomic();
92323 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92324 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92325
92326 /*
92327 * If we are the timekeeping CPU, we are permitted to be non-idle
92328 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92329 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92330
92331 /* Pick up current idle and NMI-nesting counter and check. */
92332 - cur = atomic_read(&rdtp->dynticks_idle);
92333 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92334 if (cur & 0x1) {
92335 *isidle = false; /* We are not idle! */
92336 return;
92337 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92338 case RCU_SYSIDLE_NOT:
92339
92340 /* First time all are idle, so note a short idle period. */
92341 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92342 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92343 break;
92344
92345 case RCU_SYSIDLE_SHORT:
92346 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92347 {
92348 smp_mb();
92349 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92350 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92351 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92352 }
92353
92354 /*
92355 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92356 smp_mb(); /* grace period precedes setting inuse. */
92357
92358 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92359 - ACCESS_ONCE(rshp->inuse) = 0;
92360 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92361 }
92362
92363 /*
92364 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92365 static void rcu_dynticks_task_enter(void)
92366 {
92367 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92368 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92369 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92370 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92371 }
92372
92373 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92374 static void rcu_dynticks_task_exit(void)
92375 {
92376 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92377 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92378 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92379 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92380 }
92381 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92382 index 5cdc62e..cc52e88 100644
92383 --- a/kernel/rcu/tree_trace.c
92384 +++ b/kernel/rcu/tree_trace.c
92385 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92386 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92387 rdp->passed_quiesce, rdp->qs_pending);
92388 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92389 - atomic_read(&rdp->dynticks->dynticks),
92390 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92391 rdp->dynticks->dynticks_nesting,
92392 rdp->dynticks->dynticks_nmi_nesting,
92393 rdp->dynticks_fqs);
92394 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92395 struct rcu_state *rsp = (struct rcu_state *)m->private;
92396
92397 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",
92398 - atomic_long_read(&rsp->expedited_start),
92399 + atomic_long_read_unchecked(&rsp->expedited_start),
92400 atomic_long_read(&rsp->expedited_done),
92401 - atomic_long_read(&rsp->expedited_wrap),
92402 - atomic_long_read(&rsp->expedited_tryfail),
92403 - atomic_long_read(&rsp->expedited_workdone1),
92404 - atomic_long_read(&rsp->expedited_workdone2),
92405 - atomic_long_read(&rsp->expedited_normal),
92406 - atomic_long_read(&rsp->expedited_stoppedcpus),
92407 - atomic_long_read(&rsp->expedited_done_tries),
92408 - atomic_long_read(&rsp->expedited_done_lost),
92409 - atomic_long_read(&rsp->expedited_done_exit));
92410 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92411 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92412 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92413 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92414 + atomic_long_read_unchecked(&rsp->expedited_normal),
92415 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92416 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92417 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92418 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92419 return 0;
92420 }
92421
92422 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92423 index 3ef8ba5..8c5ebfb6 100644
92424 --- a/kernel/rcu/update.c
92425 +++ b/kernel/rcu/update.c
92426 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92427 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92428 */
92429 if (till_stall_check < 3) {
92430 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92431 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92432 till_stall_check = 3;
92433 } else if (till_stall_check > 300) {
92434 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92435 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92436 till_stall_check = 300;
92437 }
92438 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92439 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92440 !ACCESS_ONCE(t->on_rq) ||
92441 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92442 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92443 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92444 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92445 list_del_init(&t->rcu_tasks_holdout_list);
92446 put_task_struct(t);
92447 return;
92448 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92449 !is_idle_task(t)) {
92450 get_task_struct(t);
92451 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92452 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92453 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92454 list_add(&t->rcu_tasks_holdout_list,
92455 &rcu_tasks_holdouts);
92456 }
92457 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92458 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92459 BUG_ON(IS_ERR(t));
92460 smp_mb(); /* Ensure others see full kthread. */
92461 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92462 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92463 mutex_unlock(&rcu_tasks_kthread_mutex);
92464 }
92465
92466 diff --git a/kernel/resource.c b/kernel/resource.c
92467 index 0bcebff..e7cd5b2 100644
92468 --- a/kernel/resource.c
92469 +++ b/kernel/resource.c
92470 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92471
92472 static int __init ioresources_init(void)
92473 {
92474 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92475 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92476 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92477 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92478 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92479 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92480 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92481 +#endif
92482 +#else
92483 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92484 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92485 +#endif
92486 return 0;
92487 }
92488 __initcall(ioresources_init);
92489 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92490 index 8a2e230..6020954 100644
92491 --- a/kernel/sched/auto_group.c
92492 +++ b/kernel/sched/auto_group.c
92493 @@ -11,7 +11,7 @@
92494
92495 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92496 static struct autogroup autogroup_default;
92497 -static atomic_t autogroup_seq_nr;
92498 +static atomic_unchecked_t autogroup_seq_nr;
92499
92500 void __init autogroup_init(struct task_struct *init_task)
92501 {
92502 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92503
92504 kref_init(&ag->kref);
92505 init_rwsem(&ag->lock);
92506 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92507 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92508 ag->tg = tg;
92509 #ifdef CONFIG_RT_GROUP_SCHED
92510 /*
92511 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92512 index a63f4dc..349bbb0 100644
92513 --- a/kernel/sched/completion.c
92514 +++ b/kernel/sched/completion.c
92515 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92516 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92517 * or number of jiffies left till timeout) if completed.
92518 */
92519 -long __sched
92520 +long __sched __intentional_overflow(-1)
92521 wait_for_completion_interruptible_timeout(struct completion *x,
92522 unsigned long timeout)
92523 {
92524 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92525 *
92526 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92527 */
92528 -int __sched wait_for_completion_killable(struct completion *x)
92529 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92530 {
92531 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92532 if (t == -ERESTARTSYS)
92533 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92534 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92535 * or number of jiffies left till timeout) if completed.
92536 */
92537 -long __sched
92538 +long __sched __intentional_overflow(-1)
92539 wait_for_completion_killable_timeout(struct completion *x,
92540 unsigned long timeout)
92541 {
92542 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92543 index efdca2f..e361dfb 100644
92544 --- a/kernel/sched/core.c
92545 +++ b/kernel/sched/core.c
92546 @@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92547 int sysctl_numa_balancing(struct ctl_table *table, int write,
92548 void __user *buffer, size_t *lenp, loff_t *ppos)
92549 {
92550 - struct ctl_table t;
92551 + ctl_table_no_const t;
92552 int err;
92553 int state = numabalancing_enabled;
92554
92555 @@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92556 next->active_mm = oldmm;
92557 atomic_inc(&oldmm->mm_count);
92558 enter_lazy_tlb(oldmm, next);
92559 - } else
92560 + } else {
92561 switch_mm(oldmm, mm, next);
92562 + populate_stack();
92563 + }
92564
92565 if (!prev->mm) {
92566 prev->active_mm = NULL;
92567 @@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92568 /* convert nice value [19,-20] to rlimit style value [1,40] */
92569 int nice_rlim = nice_to_rlimit(nice);
92570
92571 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92572 +
92573 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92574 capable(CAP_SYS_NICE));
92575 }
92576 @@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92577 nice = task_nice(current) + increment;
92578
92579 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92580 - if (increment < 0 && !can_nice(current, nice))
92581 + if (increment < 0 && (!can_nice(current, nice) ||
92582 + gr_handle_chroot_nice()))
92583 return -EPERM;
92584
92585 retval = security_task_setnice(current, nice);
92586 @@ -3470,6 +3475,7 @@ recheck:
92587 if (policy != p->policy && !rlim_rtprio)
92588 return -EPERM;
92589
92590 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92591 /* can't increase priority */
92592 if (attr->sched_priority > p->rt_priority &&
92593 attr->sched_priority > rlim_rtprio)
92594 @@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92595
92596 if (mm != &init_mm) {
92597 switch_mm(mm, &init_mm, current);
92598 + populate_stack();
92599 finish_arch_post_lock_switch();
92600 }
92601 mmdrop(mm);
92602 @@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92603
92604 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92605
92606 -static struct ctl_table sd_ctl_dir[] = {
92607 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92608 {
92609 .procname = "sched_domain",
92610 .mode = 0555,
92611 @@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92612 {}
92613 };
92614
92615 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92616 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92617 {
92618 - struct ctl_table *entry =
92619 + ctl_table_no_const *entry =
92620 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92621
92622 return entry;
92623 }
92624
92625 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92626 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92627 {
92628 - struct ctl_table *entry;
92629 + ctl_table_no_const *entry;
92630
92631 /*
92632 * In the intermediate directories, both the child directory and
92633 @@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92634 * will always be set. In the lowest directory the names are
92635 * static strings and all have proc handlers.
92636 */
92637 - for (entry = *tablep; entry->mode; entry++) {
92638 - if (entry->child)
92639 - sd_free_ctl_entry(&entry->child);
92640 + for (entry = tablep; entry->mode; entry++) {
92641 + if (entry->child) {
92642 + sd_free_ctl_entry(entry->child);
92643 + pax_open_kernel();
92644 + entry->child = NULL;
92645 + pax_close_kernel();
92646 + }
92647 if (entry->proc_handler == NULL)
92648 kfree(entry->procname);
92649 }
92650
92651 - kfree(*tablep);
92652 - *tablep = NULL;
92653 + kfree(tablep);
92654 }
92655
92656 static int min_load_idx = 0;
92657 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92658
92659 static void
92660 -set_table_entry(struct ctl_table *entry,
92661 +set_table_entry(ctl_table_no_const *entry,
92662 const char *procname, void *data, int maxlen,
92663 umode_t mode, proc_handler *proc_handler,
92664 bool load_idx)
92665 @@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
92666 static struct ctl_table *
92667 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92668 {
92669 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92670 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92671
92672 if (table == NULL)
92673 return NULL;
92674 @@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92675 return table;
92676 }
92677
92678 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92679 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92680 {
92681 - struct ctl_table *entry, *table;
92682 + ctl_table_no_const *entry, *table;
92683 struct sched_domain *sd;
92684 int domain_num = 0, i;
92685 char buf[32];
92686 @@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
92687 static void register_sched_domain_sysctl(void)
92688 {
92689 int i, cpu_num = num_possible_cpus();
92690 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92691 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92692 char buf[32];
92693
92694 WARN_ON(sd_ctl_dir[0].child);
92695 + pax_open_kernel();
92696 sd_ctl_dir[0].child = entry;
92697 + pax_close_kernel();
92698
92699 if (entry == NULL)
92700 return;
92701 @@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
92702 if (sd_sysctl_header)
92703 unregister_sysctl_table(sd_sysctl_header);
92704 sd_sysctl_header = NULL;
92705 - if (sd_ctl_dir[0].child)
92706 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92707 + if (sd_ctl_dir[0].child) {
92708 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92709 + pax_open_kernel();
92710 + sd_ctl_dir[0].child = NULL;
92711 + pax_close_kernel();
92712 + }
92713 }
92714 #else
92715 static void register_sched_domain_sysctl(void)
92716 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92717 index ef2b104..69961f6 100644
92718 --- a/kernel/sched/fair.c
92719 +++ b/kernel/sched/fair.c
92720 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92721
92722 static void reset_ptenuma_scan(struct task_struct *p)
92723 {
92724 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92725 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92726 p->mm->numa_scan_offset = 0;
92727 }
92728
92729 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92730 * run_rebalance_domains is triggered when needed from the scheduler tick.
92731 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92732 */
92733 -static void run_rebalance_domains(struct softirq_action *h)
92734 +static __latent_entropy void run_rebalance_domains(void)
92735 {
92736 struct rq *this_rq = this_rq();
92737 enum cpu_idle_type idle = this_rq->idle_balance ?
92738 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92739 index 2df8ef0..aae070f 100644
92740 --- a/kernel/sched/sched.h
92741 +++ b/kernel/sched/sched.h
92742 @@ -1140,7 +1140,7 @@ struct sched_class {
92743 #ifdef CONFIG_FAIR_GROUP_SCHED
92744 void (*task_move_group) (struct task_struct *p, int on_rq);
92745 #endif
92746 -};
92747 +} __do_const;
92748
92749 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92750 {
92751 diff --git a/kernel/signal.c b/kernel/signal.c
92752 index 8f0876f..1153a5a 100644
92753 --- a/kernel/signal.c
92754 +++ b/kernel/signal.c
92755 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92756
92757 int print_fatal_signals __read_mostly;
92758
92759 -static void __user *sig_handler(struct task_struct *t, int sig)
92760 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92761 {
92762 return t->sighand->action[sig - 1].sa.sa_handler;
92763 }
92764
92765 -static int sig_handler_ignored(void __user *handler, int sig)
92766 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92767 {
92768 /* Is it explicitly or implicitly ignored? */
92769 return handler == SIG_IGN ||
92770 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92771
92772 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92773 {
92774 - void __user *handler;
92775 + __sighandler_t handler;
92776
92777 handler = sig_handler(t, sig);
92778
92779 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92780 atomic_inc(&user->sigpending);
92781 rcu_read_unlock();
92782
92783 + if (!override_rlimit)
92784 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92785 +
92786 if (override_rlimit ||
92787 atomic_read(&user->sigpending) <=
92788 task_rlimit(t, RLIMIT_SIGPENDING)) {
92789 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92790
92791 int unhandled_signal(struct task_struct *tsk, int sig)
92792 {
92793 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92794 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92795 if (is_global_init(tsk))
92796 return 1;
92797 if (handler != SIG_IGN && handler != SIG_DFL)
92798 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92799 }
92800 }
92801
92802 + /* allow glibc communication via tgkill to other threads in our
92803 + thread group */
92804 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92805 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92806 + && gr_handle_signal(t, sig))
92807 + return -EPERM;
92808 +
92809 return security_task_kill(t, info, sig, 0);
92810 }
92811
92812 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92813 return send_signal(sig, info, p, 1);
92814 }
92815
92816 -static int
92817 +int
92818 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92819 {
92820 return send_signal(sig, info, t, 0);
92821 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92822 unsigned long int flags;
92823 int ret, blocked, ignored;
92824 struct k_sigaction *action;
92825 + int is_unhandled = 0;
92826
92827 spin_lock_irqsave(&t->sighand->siglock, flags);
92828 action = &t->sighand->action[sig-1];
92829 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92830 }
92831 if (action->sa.sa_handler == SIG_DFL)
92832 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92833 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92834 + is_unhandled = 1;
92835 ret = specific_send_sig_info(sig, info, t);
92836 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92837
92838 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
92839 + normal operation */
92840 + if (is_unhandled) {
92841 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92842 + gr_handle_crash(t, sig);
92843 + }
92844 +
92845 return ret;
92846 }
92847
92848 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92849 ret = check_kill_permission(sig, info, p);
92850 rcu_read_unlock();
92851
92852 - if (!ret && sig)
92853 + if (!ret && sig) {
92854 ret = do_send_sig_info(sig, info, p, true);
92855 + if (!ret)
92856 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92857 + }
92858
92859 return ret;
92860 }
92861 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92862 int error = -ESRCH;
92863
92864 rcu_read_lock();
92865 - p = find_task_by_vpid(pid);
92866 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92867 + /* allow glibc communication via tgkill to other threads in our
92868 + thread group */
92869 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92870 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
92871 + p = find_task_by_vpid_unrestricted(pid);
92872 + else
92873 +#endif
92874 + p = find_task_by_vpid(pid);
92875 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92876 error = check_kill_permission(sig, info, p);
92877 /*
92878 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92879 }
92880 seg = get_fs();
92881 set_fs(KERNEL_DS);
92882 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92883 - (stack_t __force __user *) &uoss,
92884 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92885 + (stack_t __force_user *) &uoss,
92886 compat_user_stack_pointer());
92887 set_fs(seg);
92888 if (ret >= 0 && uoss_ptr) {
92889 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92890 index eb89e18..a4e6792 100644
92891 --- a/kernel/smpboot.c
92892 +++ b/kernel/smpboot.c
92893 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92894 }
92895 smpboot_unpark_thread(plug_thread, cpu);
92896 }
92897 - list_add(&plug_thread->list, &hotplug_threads);
92898 + pax_list_add(&plug_thread->list, &hotplug_threads);
92899 out:
92900 mutex_unlock(&smpboot_threads_lock);
92901 return ret;
92902 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92903 {
92904 get_online_cpus();
92905 mutex_lock(&smpboot_threads_lock);
92906 - list_del(&plug_thread->list);
92907 + pax_list_del(&plug_thread->list);
92908 smpboot_destroy_threads(plug_thread);
92909 mutex_unlock(&smpboot_threads_lock);
92910 put_online_cpus();
92911 diff --git a/kernel/softirq.c b/kernel/softirq.c
92912 index 0699add..d365ad8 100644
92913 --- a/kernel/softirq.c
92914 +++ b/kernel/softirq.c
92915 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92916 EXPORT_SYMBOL(irq_stat);
92917 #endif
92918
92919 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92920 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92921
92922 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92923
92924 @@ -266,7 +266,7 @@ restart:
92925 kstat_incr_softirqs_this_cpu(vec_nr);
92926
92927 trace_softirq_entry(vec_nr);
92928 - h->action(h);
92929 + h->action();
92930 trace_softirq_exit(vec_nr);
92931 if (unlikely(prev_count != preempt_count())) {
92932 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92933 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92934 or_softirq_pending(1UL << nr);
92935 }
92936
92937 -void open_softirq(int nr, void (*action)(struct softirq_action *))
92938 +void __init open_softirq(int nr, void (*action)(void))
92939 {
92940 softirq_vec[nr].action = action;
92941 }
92942 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92943 }
92944 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92945
92946 -static void tasklet_action(struct softirq_action *a)
92947 +static void tasklet_action(void)
92948 {
92949 struct tasklet_struct *list;
92950
92951 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92952 }
92953 }
92954
92955 -static void tasklet_hi_action(struct softirq_action *a)
92956 +static __latent_entropy void tasklet_hi_action(void)
92957 {
92958 struct tasklet_struct *list;
92959
92960 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92961 .notifier_call = cpu_callback
92962 };
92963
92964 -static struct smp_hotplug_thread softirq_threads = {
92965 +static struct smp_hotplug_thread softirq_threads __read_only = {
92966 .store = &ksoftirqd,
92967 .thread_should_run = ksoftirqd_should_run,
92968 .thread_fn = run_ksoftirqd,
92969 diff --git a/kernel/sys.c b/kernel/sys.c
92970 index 1eaa2f0..d80d27c 100644
92971 --- a/kernel/sys.c
92972 +++ b/kernel/sys.c
92973 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92974 error = -EACCES;
92975 goto out;
92976 }
92977 +
92978 + if (gr_handle_chroot_setpriority(p, niceval)) {
92979 + error = -EACCES;
92980 + goto out;
92981 + }
92982 +
92983 no_nice = security_task_setnice(p, niceval);
92984 if (no_nice) {
92985 error = no_nice;
92986 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92987 goto error;
92988 }
92989
92990 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92991 + goto error;
92992 +
92993 + if (!gid_eq(new->gid, old->gid)) {
92994 + /* make sure we generate a learn log for what will
92995 + end up being a role transition after a full-learning
92996 + policy is generated
92997 + CAP_SETGID is required to perform a transition
92998 + we may not log a CAP_SETGID check above, e.g.
92999 + in the case where new rgid = old egid
93000 + */
93001 + gr_learn_cap(current, new, CAP_SETGID);
93002 + }
93003 +
93004 if (rgid != (gid_t) -1 ||
93005 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93006 new->sgid = new->egid;
93007 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93008 old = current_cred();
93009
93010 retval = -EPERM;
93011 +
93012 + if (gr_check_group_change(kgid, kgid, kgid))
93013 + goto error;
93014 +
93015 if (ns_capable(old->user_ns, CAP_SETGID))
93016 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93017 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93018 @@ -405,7 +429,7 @@ error:
93019 /*
93020 * change the user struct in a credentials set to match the new UID
93021 */
93022 -static int set_user(struct cred *new)
93023 +int set_user(struct cred *new)
93024 {
93025 struct user_struct *new_user;
93026
93027 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93028 goto error;
93029 }
93030
93031 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93032 + goto error;
93033 +
93034 if (!uid_eq(new->uid, old->uid)) {
93035 + /* make sure we generate a learn log for what will
93036 + end up being a role transition after a full-learning
93037 + policy is generated
93038 + CAP_SETUID is required to perform a transition
93039 + we may not log a CAP_SETUID check above, e.g.
93040 + in the case where new ruid = old euid
93041 + */
93042 + gr_learn_cap(current, new, CAP_SETUID);
93043 retval = set_user(new);
93044 if (retval < 0)
93045 goto error;
93046 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93047 old = current_cred();
93048
93049 retval = -EPERM;
93050 +
93051 + if (gr_check_crash_uid(kuid))
93052 + goto error;
93053 + if (gr_check_user_change(kuid, kuid, kuid))
93054 + goto error;
93055 +
93056 if (ns_capable(old->user_ns, CAP_SETUID)) {
93057 new->suid = new->uid = kuid;
93058 if (!uid_eq(kuid, old->uid)) {
93059 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93060 goto error;
93061 }
93062
93063 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93064 + goto error;
93065 +
93066 if (ruid != (uid_t) -1) {
93067 new->uid = kruid;
93068 if (!uid_eq(kruid, old->uid)) {
93069 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93070 goto error;
93071 }
93072
93073 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93074 + goto error;
93075 +
93076 if (rgid != (gid_t) -1)
93077 new->gid = krgid;
93078 if (egid != (gid_t) -1)
93079 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93080 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93081 ns_capable(old->user_ns, CAP_SETUID)) {
93082 if (!uid_eq(kuid, old->fsuid)) {
93083 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93084 + goto error;
93085 +
93086 new->fsuid = kuid;
93087 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93088 goto change_okay;
93089 }
93090 }
93091
93092 +error:
93093 abort_creds(new);
93094 return old_fsuid;
93095
93096 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93097 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93098 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93099 ns_capable(old->user_ns, CAP_SETGID)) {
93100 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93101 + goto error;
93102 +
93103 if (!gid_eq(kgid, old->fsgid)) {
93104 new->fsgid = kgid;
93105 goto change_okay;
93106 }
93107 }
93108
93109 +error:
93110 abort_creds(new);
93111 return old_fsgid;
93112
93113 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93114 return -EFAULT;
93115
93116 down_read(&uts_sem);
93117 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93118 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93119 __OLD_UTS_LEN);
93120 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93121 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93122 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93123 __OLD_UTS_LEN);
93124 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93125 - error |= __copy_to_user(&name->release, &utsname()->release,
93126 + error |= __copy_to_user(name->release, &utsname()->release,
93127 __OLD_UTS_LEN);
93128 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93129 - error |= __copy_to_user(&name->version, &utsname()->version,
93130 + error |= __copy_to_user(name->version, &utsname()->version,
93131 __OLD_UTS_LEN);
93132 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93133 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93134 + error |= __copy_to_user(name->machine, &utsname()->machine,
93135 __OLD_UTS_LEN);
93136 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93137 up_read(&uts_sem);
93138 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93139 */
93140 new_rlim->rlim_cur = 1;
93141 }
93142 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93143 + is changed to a lower value. Since tasks can be created by the same
93144 + user in between this limit change and an execve by this task, force
93145 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93146 + */
93147 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93148 + tsk->flags |= PF_NPROC_EXCEEDED;
93149 }
93150 if (!retval) {
93151 if (old_rlim)
93152 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93153 index 15f2511..181b356 100644
93154 --- a/kernel/sysctl.c
93155 +++ b/kernel/sysctl.c
93156 @@ -94,7 +94,6 @@
93157
93158
93159 #if defined(CONFIG_SYSCTL)
93160 -
93161 /* External variables not in a header file. */
93162 extern int max_threads;
93163 extern int suid_dumpable;
93164 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93165
93166 /* Constants used for minimum and maximum */
93167 #ifdef CONFIG_LOCKUP_DETECTOR
93168 -static int sixty = 60;
93169 +static int sixty __read_only = 60;
93170 #endif
93171
93172 -static int __maybe_unused neg_one = -1;
93173 +static int __maybe_unused neg_one __read_only = -1;
93174
93175 -static int zero;
93176 -static int __maybe_unused one = 1;
93177 -static int __maybe_unused two = 2;
93178 -static int __maybe_unused four = 4;
93179 -static unsigned long one_ul = 1;
93180 -static int one_hundred = 100;
93181 +static int zero __read_only = 0;
93182 +static int __maybe_unused one __read_only = 1;
93183 +static int __maybe_unused two __read_only = 2;
93184 +static int __maybe_unused three __read_only = 3;
93185 +static int __maybe_unused four __read_only = 4;
93186 +static unsigned long one_ul __read_only = 1;
93187 +static int one_hundred __read_only = 100;
93188 #ifdef CONFIG_PRINTK
93189 -static int ten_thousand = 10000;
93190 +static int ten_thousand __read_only = 10000;
93191 #endif
93192
93193 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93194 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93195 void __user *buffer, size_t *lenp, loff_t *ppos);
93196 #endif
93197
93198 -#ifdef CONFIG_PRINTK
93199 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93200 void __user *buffer, size_t *lenp, loff_t *ppos);
93201 -#endif
93202
93203 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93204 void __user *buffer, size_t *lenp, loff_t *ppos);
93205 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93206
93207 #endif
93208
93209 +extern struct ctl_table grsecurity_table[];
93210 +
93211 static struct ctl_table kern_table[];
93212 static struct ctl_table vm_table[];
93213 static struct ctl_table fs_table[];
93214 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93215 int sysctl_legacy_va_layout;
93216 #endif
93217
93218 +#ifdef CONFIG_PAX_SOFTMODE
93219 +static struct ctl_table pax_table[] = {
93220 + {
93221 + .procname = "softmode",
93222 + .data = &pax_softmode,
93223 + .maxlen = sizeof(unsigned int),
93224 + .mode = 0600,
93225 + .proc_handler = &proc_dointvec,
93226 + },
93227 +
93228 + { }
93229 +};
93230 +#endif
93231 +
93232 /* The default sysctl tables: */
93233
93234 static struct ctl_table sysctl_base_table[] = {
93235 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93236 #endif
93237
93238 static struct ctl_table kern_table[] = {
93239 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93240 + {
93241 + .procname = "grsecurity",
93242 + .mode = 0500,
93243 + .child = grsecurity_table,
93244 + },
93245 +#endif
93246 +
93247 +#ifdef CONFIG_PAX_SOFTMODE
93248 + {
93249 + .procname = "pax",
93250 + .mode = 0500,
93251 + .child = pax_table,
93252 + },
93253 +#endif
93254 +
93255 {
93256 .procname = "sched_child_runs_first",
93257 .data = &sysctl_sched_child_runs_first,
93258 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93259 .data = &modprobe_path,
93260 .maxlen = KMOD_PATH_LEN,
93261 .mode = 0644,
93262 - .proc_handler = proc_dostring,
93263 + .proc_handler = proc_dostring_modpriv,
93264 },
93265 {
93266 .procname = "modules_disabled",
93267 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93268 .extra1 = &zero,
93269 .extra2 = &one,
93270 },
93271 +#endif
93272 {
93273 .procname = "kptr_restrict",
93274 .data = &kptr_restrict,
93275 .maxlen = sizeof(int),
93276 .mode = 0644,
93277 .proc_handler = proc_dointvec_minmax_sysadmin,
93278 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93279 + .extra1 = &two,
93280 +#else
93281 .extra1 = &zero,
93282 +#endif
93283 .extra2 = &two,
93284 },
93285 -#endif
93286 {
93287 .procname = "ngroups_max",
93288 .data = &ngroups_max,
93289 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93290 */
93291 {
93292 .procname = "perf_event_paranoid",
93293 - .data = &sysctl_perf_event_paranoid,
93294 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93295 + .data = &sysctl_perf_event_legitimately_concerned,
93296 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93297 .mode = 0644,
93298 - .proc_handler = proc_dointvec,
93299 + /* go ahead, be a hero */
93300 + .proc_handler = proc_dointvec_minmax_sysadmin,
93301 + .extra1 = &neg_one,
93302 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93303 + .extra2 = &three,
93304 +#else
93305 + .extra2 = &two,
93306 +#endif
93307 },
93308 {
93309 .procname = "perf_event_mlock_kb",
93310 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93311 .proc_handler = proc_dointvec_minmax,
93312 .extra1 = &zero,
93313 },
93314 + {
93315 + .procname = "heap_stack_gap",
93316 + .data = &sysctl_heap_stack_gap,
93317 + .maxlen = sizeof(sysctl_heap_stack_gap),
93318 + .mode = 0644,
93319 + .proc_handler = proc_doulongvec_minmax,
93320 + },
93321 #else
93322 {
93323 .procname = "nr_trim_pages",
93324 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93325 (char __user *)buffer, lenp, ppos);
93326 }
93327
93328 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93329 + void __user *buffer, size_t *lenp, loff_t *ppos)
93330 +{
93331 + if (write && !capable(CAP_SYS_MODULE))
93332 + return -EPERM;
93333 +
93334 + return _proc_do_string(table->data, table->maxlen, write,
93335 + buffer, lenp, ppos);
93336 +}
93337 +
93338 static size_t proc_skip_spaces(char **buf)
93339 {
93340 size_t ret;
93341 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93342 len = strlen(tmp);
93343 if (len > *size)
93344 len = *size;
93345 + if (len > sizeof(tmp))
93346 + len = sizeof(tmp);
93347 if (copy_to_user(*buf, tmp, len))
93348 return -EFAULT;
93349 *size -= len;
93350 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93351 static int proc_taint(struct ctl_table *table, int write,
93352 void __user *buffer, size_t *lenp, loff_t *ppos)
93353 {
93354 - struct ctl_table t;
93355 + ctl_table_no_const t;
93356 unsigned long tmptaint = get_taint();
93357 int err;
93358
93359 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93360 return err;
93361 }
93362
93363 -#ifdef CONFIG_PRINTK
93364 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93365 void __user *buffer, size_t *lenp, loff_t *ppos)
93366 {
93367 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93368
93369 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93370 }
93371 -#endif
93372
93373 struct do_proc_dointvec_minmax_conv_param {
93374 int *min;
93375 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93376 return -ENOSYS;
93377 }
93378
93379 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93380 + void __user *buffer, size_t *lenp, loff_t *ppos)
93381 +{
93382 + return -ENOSYS;
93383 +}
93384 +
93385 int proc_dointvec(struct ctl_table *table, int write,
93386 void __user *buffer, size_t *lenp, loff_t *ppos)
93387 {
93388 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93389 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93390 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93391 EXPORT_SYMBOL(proc_dostring);
93392 +EXPORT_SYMBOL(proc_dostring_modpriv);
93393 EXPORT_SYMBOL(proc_doulongvec_minmax);
93394 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93395 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93396 index b312fcc7..753d72d 100644
93397 --- a/kernel/taskstats.c
93398 +++ b/kernel/taskstats.c
93399 @@ -28,9 +28,12 @@
93400 #include <linux/fs.h>
93401 #include <linux/file.h>
93402 #include <linux/pid_namespace.h>
93403 +#include <linux/grsecurity.h>
93404 #include <net/genetlink.h>
93405 #include <linux/atomic.h>
93406
93407 +extern int gr_is_taskstats_denied(int pid);
93408 +
93409 /*
93410 * Maximum length of a cpumask that can be specified in
93411 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93412 @@ -576,6 +579,9 @@ err:
93413
93414 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93415 {
93416 + if (gr_is_taskstats_denied(current->pid))
93417 + return -EACCES;
93418 +
93419 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93420 return cmd_attr_register_cpumask(info);
93421 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93422 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93423 index a7077d3..dd48a49 100644
93424 --- a/kernel/time/alarmtimer.c
93425 +++ b/kernel/time/alarmtimer.c
93426 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93427 struct platform_device *pdev;
93428 int error = 0;
93429 int i;
93430 - struct k_clock alarm_clock = {
93431 + static struct k_clock alarm_clock = {
93432 .clock_getres = alarm_clock_getres,
93433 .clock_get = alarm_clock_get,
93434 .timer_create = alarm_timer_create,
93435 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93436 index 37e50aa..57a9501 100644
93437 --- a/kernel/time/hrtimer.c
93438 +++ b/kernel/time/hrtimer.c
93439 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93440 local_irq_restore(flags);
93441 }
93442
93443 -static void run_hrtimer_softirq(struct softirq_action *h)
93444 +static __latent_entropy void run_hrtimer_softirq(void)
93445 {
93446 hrtimer_peek_ahead_timers();
93447 }
93448 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93449 index a16b678..8c5bd9d 100644
93450 --- a/kernel/time/posix-cpu-timers.c
93451 +++ b/kernel/time/posix-cpu-timers.c
93452 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93453
93454 static __init int init_posix_cpu_timers(void)
93455 {
93456 - struct k_clock process = {
93457 + static struct k_clock process = {
93458 .clock_getres = process_cpu_clock_getres,
93459 .clock_get = process_cpu_clock_get,
93460 .timer_create = process_cpu_timer_create,
93461 .nsleep = process_cpu_nsleep,
93462 .nsleep_restart = process_cpu_nsleep_restart,
93463 };
93464 - struct k_clock thread = {
93465 + static struct k_clock thread = {
93466 .clock_getres = thread_cpu_clock_getres,
93467 .clock_get = thread_cpu_clock_get,
93468 .timer_create = thread_cpu_timer_create,
93469 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93470 index 31ea01f..7fc61ef 100644
93471 --- a/kernel/time/posix-timers.c
93472 +++ b/kernel/time/posix-timers.c
93473 @@ -43,6 +43,7 @@
93474 #include <linux/hash.h>
93475 #include <linux/posix-clock.h>
93476 #include <linux/posix-timers.h>
93477 +#include <linux/grsecurity.h>
93478 #include <linux/syscalls.h>
93479 #include <linux/wait.h>
93480 #include <linux/workqueue.h>
93481 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93482 * which we beg off on and pass to do_sys_settimeofday().
93483 */
93484
93485 -static struct k_clock posix_clocks[MAX_CLOCKS];
93486 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93487
93488 /*
93489 * These ones are defined below.
93490 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93491 */
93492 static __init int init_posix_timers(void)
93493 {
93494 - struct k_clock clock_realtime = {
93495 + static struct k_clock clock_realtime = {
93496 .clock_getres = hrtimer_get_res,
93497 .clock_get = posix_clock_realtime_get,
93498 .clock_set = posix_clock_realtime_set,
93499 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93500 .timer_get = common_timer_get,
93501 .timer_del = common_timer_del,
93502 };
93503 - struct k_clock clock_monotonic = {
93504 + static struct k_clock clock_monotonic = {
93505 .clock_getres = hrtimer_get_res,
93506 .clock_get = posix_ktime_get_ts,
93507 .nsleep = common_nsleep,
93508 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93509 .timer_get = common_timer_get,
93510 .timer_del = common_timer_del,
93511 };
93512 - struct k_clock clock_monotonic_raw = {
93513 + static struct k_clock clock_monotonic_raw = {
93514 .clock_getres = hrtimer_get_res,
93515 .clock_get = posix_get_monotonic_raw,
93516 };
93517 - struct k_clock clock_realtime_coarse = {
93518 + static struct k_clock clock_realtime_coarse = {
93519 .clock_getres = posix_get_coarse_res,
93520 .clock_get = posix_get_realtime_coarse,
93521 };
93522 - struct k_clock clock_monotonic_coarse = {
93523 + static struct k_clock clock_monotonic_coarse = {
93524 .clock_getres = posix_get_coarse_res,
93525 .clock_get = posix_get_monotonic_coarse,
93526 };
93527 - struct k_clock clock_tai = {
93528 + static struct k_clock clock_tai = {
93529 .clock_getres = hrtimer_get_res,
93530 .clock_get = posix_get_tai,
93531 .nsleep = common_nsleep,
93532 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93533 .timer_get = common_timer_get,
93534 .timer_del = common_timer_del,
93535 };
93536 - struct k_clock clock_boottime = {
93537 + static struct k_clock clock_boottime = {
93538 .clock_getres = hrtimer_get_res,
93539 .clock_get = posix_get_boottime,
93540 .nsleep = common_nsleep,
93541 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93542 return;
93543 }
93544
93545 - posix_clocks[clock_id] = *new_clock;
93546 + posix_clocks[clock_id] = new_clock;
93547 }
93548 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93549
93550 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93551 return (id & CLOCKFD_MASK) == CLOCKFD ?
93552 &clock_posix_dynamic : &clock_posix_cpu;
93553
93554 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93555 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93556 return NULL;
93557 - return &posix_clocks[id];
93558 + return posix_clocks[id];
93559 }
93560
93561 static int common_timer_create(struct k_itimer *new_timer)
93562 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93563 struct k_clock *kc = clockid_to_kclock(which_clock);
93564 struct k_itimer *new_timer;
93565 int error, new_timer_id;
93566 - sigevent_t event;
93567 + sigevent_t event = { };
93568 int it_id_set = IT_ID_NOT_SET;
93569
93570 if (!kc)
93571 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93572 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93573 return -EFAULT;
93574
93575 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93576 + have their clock_set fptr set to a nosettime dummy function
93577 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93578 + call common_clock_set, which calls do_sys_settimeofday, which
93579 + we hook
93580 + */
93581 +
93582 return kc->clock_set(which_clock, &new_tp);
93583 }
93584
93585 diff --git a/kernel/time/time.c b/kernel/time/time.c
93586 index a9ae20f..d3fbde7 100644
93587 --- a/kernel/time/time.c
93588 +++ b/kernel/time/time.c
93589 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93590 return error;
93591
93592 if (tz) {
93593 + /* we log in do_settimeofday called below, so don't log twice
93594 + */
93595 + if (!tv)
93596 + gr_log_timechange();
93597 +
93598 sys_tz = *tz;
93599 update_vsyscall_tz();
93600 if (firsttime) {
93601 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93602 index ec1791f..6a086cd 100644
93603 --- a/kernel/time/timekeeping.c
93604 +++ b/kernel/time/timekeeping.c
93605 @@ -15,6 +15,7 @@
93606 #include <linux/init.h>
93607 #include <linux/mm.h>
93608 #include <linux/sched.h>
93609 +#include <linux/grsecurity.h>
93610 #include <linux/syscore_ops.h>
93611 #include <linux/clocksource.h>
93612 #include <linux/jiffies.h>
93613 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93614 if (!timespec_valid_strict(tv))
93615 return -EINVAL;
93616
93617 + gr_log_timechange();
93618 +
93619 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93620 write_seqcount_begin(&tk_core.seq);
93621
93622 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93623 index 3260ffd..c93cd5e 100644
93624 --- a/kernel/time/timer.c
93625 +++ b/kernel/time/timer.c
93626 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93627 /*
93628 * This function runs timers and the timer-tq in bottom half context.
93629 */
93630 -static void run_timer_softirq(struct softirq_action *h)
93631 +static __latent_entropy void run_timer_softirq(void)
93632 {
93633 struct tvec_base *base = __this_cpu_read(tvec_bases);
93634
93635 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93636 *
93637 * In all cases the return value is guaranteed to be non-negative.
93638 */
93639 -signed long __sched schedule_timeout(signed long timeout)
93640 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93641 {
93642 struct timer_list timer;
93643 unsigned long expire;
93644 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93645 index 61ed862..3b52c65 100644
93646 --- a/kernel/time/timer_list.c
93647 +++ b/kernel/time/timer_list.c
93648 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93649
93650 static void print_name_offset(struct seq_file *m, void *sym)
93651 {
93652 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93653 + SEQ_printf(m, "<%p>", NULL);
93654 +#else
93655 char symname[KSYM_NAME_LEN];
93656
93657 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93658 SEQ_printf(m, "<%pK>", sym);
93659 else
93660 SEQ_printf(m, "%s", symname);
93661 +#endif
93662 }
93663
93664 static void
93665 @@ -119,7 +123,11 @@ next_one:
93666 static void
93667 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93668 {
93669 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93670 + SEQ_printf(m, " .base: %p\n", NULL);
93671 +#else
93672 SEQ_printf(m, " .base: %pK\n", base);
93673 +#endif
93674 SEQ_printf(m, " .index: %d\n",
93675 base->index);
93676 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93677 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93678 {
93679 struct proc_dir_entry *pe;
93680
93681 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93682 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93683 +#else
93684 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93685 +#endif
93686 if (!pe)
93687 return -ENOMEM;
93688 return 0;
93689 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93690 index 1fb08f2..ca4bb1e 100644
93691 --- a/kernel/time/timer_stats.c
93692 +++ b/kernel/time/timer_stats.c
93693 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93694 static unsigned long nr_entries;
93695 static struct entry entries[MAX_ENTRIES];
93696
93697 -static atomic_t overflow_count;
93698 +static atomic_unchecked_t overflow_count;
93699
93700 /*
93701 * The entries are in a hash-table, for fast lookup:
93702 @@ -140,7 +140,7 @@ static void reset_entries(void)
93703 nr_entries = 0;
93704 memset(entries, 0, sizeof(entries));
93705 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93706 - atomic_set(&overflow_count, 0);
93707 + atomic_set_unchecked(&overflow_count, 0);
93708 }
93709
93710 static struct entry *alloc_entry(void)
93711 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93712 if (likely(entry))
93713 entry->count++;
93714 else
93715 - atomic_inc(&overflow_count);
93716 + atomic_inc_unchecked(&overflow_count);
93717
93718 out_unlock:
93719 raw_spin_unlock_irqrestore(lock, flags);
93720 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93721
93722 static void print_name_offset(struct seq_file *m, unsigned long addr)
93723 {
93724 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93725 + seq_printf(m, "<%p>", NULL);
93726 +#else
93727 char symname[KSYM_NAME_LEN];
93728
93729 if (lookup_symbol_name(addr, symname) < 0)
93730 - seq_printf(m, "<%p>", (void *)addr);
93731 + seq_printf(m, "<%pK>", (void *)addr);
93732 else
93733 seq_printf(m, "%s", symname);
93734 +#endif
93735 }
93736
93737 static int tstats_show(struct seq_file *m, void *v)
93738 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93739
93740 seq_puts(m, "Timer Stats Version: v0.3\n");
93741 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93742 - if (atomic_read(&overflow_count))
93743 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93744 + if (atomic_read_unchecked(&overflow_count))
93745 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93746 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93747
93748 for (i = 0; i < nr_entries; i++) {
93749 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93750 {
93751 struct proc_dir_entry *pe;
93752
93753 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93754 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93755 +#else
93756 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93757 +#endif
93758 if (!pe)
93759 return -ENOMEM;
93760 return 0;
93761 diff --git a/kernel/torture.c b/kernel/torture.c
93762 index dd70993..0bf694b 100644
93763 --- a/kernel/torture.c
93764 +++ b/kernel/torture.c
93765 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93766 mutex_lock(&fullstop_mutex);
93767 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93768 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93769 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93770 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93771 } else {
93772 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93773 }
93774 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93775 if (!torture_must_stop()) {
93776 if (stutter > 1) {
93777 schedule_timeout_interruptible(stutter - 1);
93778 - ACCESS_ONCE(stutter_pause_test) = 2;
93779 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93780 }
93781 schedule_timeout_interruptible(1);
93782 - ACCESS_ONCE(stutter_pause_test) = 1;
93783 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93784 }
93785 if (!torture_must_stop())
93786 schedule_timeout_interruptible(stutter);
93787 - ACCESS_ONCE(stutter_pause_test) = 0;
93788 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93789 torture_shutdown_absorb("torture_stutter");
93790 } while (!torture_must_stop());
93791 torture_kthread_stopping("torture_stutter");
93792 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93793 schedule_timeout_uninterruptible(10);
93794 return true;
93795 }
93796 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93797 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93798 mutex_unlock(&fullstop_mutex);
93799 torture_shutdown_cleanup();
93800 torture_shuffle_cleanup();
93801 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93802 index c1bd4ad..4b861dc 100644
93803 --- a/kernel/trace/blktrace.c
93804 +++ b/kernel/trace/blktrace.c
93805 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93806 struct blk_trace *bt = filp->private_data;
93807 char buf[16];
93808
93809 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93810 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93811
93812 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93813 }
93814 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93815 return 1;
93816
93817 bt = buf->chan->private_data;
93818 - atomic_inc(&bt->dropped);
93819 + atomic_inc_unchecked(&bt->dropped);
93820 return 0;
93821 }
93822
93823 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93824
93825 bt->dir = dir;
93826 bt->dev = dev;
93827 - atomic_set(&bt->dropped, 0);
93828 + atomic_set_unchecked(&bt->dropped, 0);
93829 INIT_LIST_HEAD(&bt->running_list);
93830
93831 ret = -EIO;
93832 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93833 index 124e2c7..762ca29 100644
93834 --- a/kernel/trace/ftrace.c
93835 +++ b/kernel/trace/ftrace.c
93836 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93837 if (unlikely(ftrace_disabled))
93838 return 0;
93839
93840 + ret = ftrace_arch_code_modify_prepare();
93841 + FTRACE_WARN_ON(ret);
93842 + if (ret)
93843 + return 0;
93844 +
93845 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93846 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93847 if (ret) {
93848 ftrace_bug(ret, ip);
93849 - return 0;
93850 }
93851 - return 1;
93852 + return ret ? 0 : 1;
93853 }
93854
93855 /*
93856 @@ -4529,8 +4534,10 @@ static int ftrace_process_locs(struct module *mod,
93857 if (!count)
93858 return 0;
93859
93860 + pax_open_kernel();
93861 sort(start, count, sizeof(*start),
93862 ftrace_cmp_ips, ftrace_swap_ips);
93863 + pax_close_kernel();
93864
93865 start_pg = ftrace_allocate_pages(count);
93866 if (!start_pg)
93867 @@ -5377,7 +5384,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
93868
93869 if (t->ret_stack == NULL) {
93870 atomic_set(&t->tracing_graph_pause, 0);
93871 - atomic_set(&t->trace_overrun, 0);
93872 + atomic_set_unchecked(&t->trace_overrun, 0);
93873 t->curr_ret_stack = -1;
93874 /* Make sure the tasks see the -1 first: */
93875 smp_wmb();
93876 @@ -5590,7 +5597,7 @@ static void
93877 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
93878 {
93879 atomic_set(&t->tracing_graph_pause, 0);
93880 - atomic_set(&t->trace_overrun, 0);
93881 + atomic_set_unchecked(&t->trace_overrun, 0);
93882 t->ftrace_timestamp = 0;
93883 /* make curr_ret_stack visible before we add the ret_stack */
93884 smp_wmb();
93885 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93886 index a56e07c..d46f0ba 100644
93887 --- a/kernel/trace/ring_buffer.c
93888 +++ b/kernel/trace/ring_buffer.c
93889 @@ -352,9 +352,9 @@ struct buffer_data_page {
93890 */
93891 struct buffer_page {
93892 struct list_head list; /* list of buffer pages */
93893 - local_t write; /* index for next write */
93894 + local_unchecked_t write; /* index for next write */
93895 unsigned read; /* index for next read */
93896 - local_t entries; /* entries on this page */
93897 + local_unchecked_t entries; /* entries on this page */
93898 unsigned long real_end; /* real end of data */
93899 struct buffer_data_page *page; /* Actual data page */
93900 };
93901 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93902 unsigned long last_overrun;
93903 local_t entries_bytes;
93904 local_t entries;
93905 - local_t overrun;
93906 - local_t commit_overrun;
93907 + local_unchecked_t overrun;
93908 + local_unchecked_t commit_overrun;
93909 local_t dropped_events;
93910 local_t committing;
93911 local_t commits;
93912 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93913 *
93914 * We add a counter to the write field to denote this.
93915 */
93916 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93917 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93918 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93919 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93920
93921 /*
93922 * Just make sure we have seen our old_write and synchronize
93923 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93924 * cmpxchg to only update if an interrupt did not already
93925 * do it for us. If the cmpxchg fails, we don't care.
93926 */
93927 - (void)local_cmpxchg(&next_page->write, old_write, val);
93928 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93929 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93930 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93931
93932 /*
93933 * No need to worry about races with clearing out the commit.
93934 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93935
93936 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93937 {
93938 - return local_read(&bpage->entries) & RB_WRITE_MASK;
93939 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93940 }
93941
93942 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93943 {
93944 - return local_read(&bpage->write) & RB_WRITE_MASK;
93945 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93946 }
93947
93948 static int
93949 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93950 * bytes consumed in ring buffer from here.
93951 * Increment overrun to account for the lost events.
93952 */
93953 - local_add(page_entries, &cpu_buffer->overrun);
93954 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
93955 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93956 }
93957
93958 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93959 * it is our responsibility to update
93960 * the counters.
93961 */
93962 - local_add(entries, &cpu_buffer->overrun);
93963 + local_add_unchecked(entries, &cpu_buffer->overrun);
93964 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93965
93966 /*
93967 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93968 if (tail == BUF_PAGE_SIZE)
93969 tail_page->real_end = 0;
93970
93971 - local_sub(length, &tail_page->write);
93972 + local_sub_unchecked(length, &tail_page->write);
93973 return;
93974 }
93975
93976 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93977 rb_event_set_padding(event);
93978
93979 /* Set the write back to the previous setting */
93980 - local_sub(length, &tail_page->write);
93981 + local_sub_unchecked(length, &tail_page->write);
93982 return;
93983 }
93984
93985 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93986
93987 /* Set write to end of buffer */
93988 length = (tail + length) - BUF_PAGE_SIZE;
93989 - local_sub(length, &tail_page->write);
93990 + local_sub_unchecked(length, &tail_page->write);
93991 }
93992
93993 /*
93994 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93995 * about it.
93996 */
93997 if (unlikely(next_page == commit_page)) {
93998 - local_inc(&cpu_buffer->commit_overrun);
93999 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94000 goto out_reset;
94001 }
94002
94003 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94004 cpu_buffer->tail_page) &&
94005 (cpu_buffer->commit_page ==
94006 cpu_buffer->reader_page))) {
94007 - local_inc(&cpu_buffer->commit_overrun);
94008 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94009 goto out_reset;
94010 }
94011 }
94012 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94013 length += RB_LEN_TIME_EXTEND;
94014
94015 tail_page = cpu_buffer->tail_page;
94016 - write = local_add_return(length, &tail_page->write);
94017 + write = local_add_return_unchecked(length, &tail_page->write);
94018
94019 /* set write to only the index of the write */
94020 write &= RB_WRITE_MASK;
94021 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94022 kmemcheck_annotate_bitfield(event, bitfield);
94023 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94024
94025 - local_inc(&tail_page->entries);
94026 + local_inc_unchecked(&tail_page->entries);
94027
94028 /*
94029 * If this is the first commit on the page, then update
94030 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94031
94032 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94033 unsigned long write_mask =
94034 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94035 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94036 unsigned long event_length = rb_event_length(event);
94037 /*
94038 * This is on the tail page. It is possible that
94039 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94040 */
94041 old_index += write_mask;
94042 new_index += write_mask;
94043 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94044 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94045 if (index == old_index) {
94046 /* update counters */
94047 local_sub(event_length, &cpu_buffer->entries_bytes);
94048 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94049
94050 /* Do the likely case first */
94051 if (likely(bpage->page == (void *)addr)) {
94052 - local_dec(&bpage->entries);
94053 + local_dec_unchecked(&bpage->entries);
94054 return;
94055 }
94056
94057 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94058 start = bpage;
94059 do {
94060 if (bpage->page == (void *)addr) {
94061 - local_dec(&bpage->entries);
94062 + local_dec_unchecked(&bpage->entries);
94063 return;
94064 }
94065 rb_inc_page(cpu_buffer, &bpage);
94066 @@ -3173,7 +3173,7 @@ static inline unsigned long
94067 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94068 {
94069 return local_read(&cpu_buffer->entries) -
94070 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94071 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94072 }
94073
94074 /**
94075 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94076 return 0;
94077
94078 cpu_buffer = buffer->buffers[cpu];
94079 - ret = local_read(&cpu_buffer->overrun);
94080 + ret = local_read_unchecked(&cpu_buffer->overrun);
94081
94082 return ret;
94083 }
94084 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94085 return 0;
94086
94087 cpu_buffer = buffer->buffers[cpu];
94088 - ret = local_read(&cpu_buffer->commit_overrun);
94089 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94090
94091 return ret;
94092 }
94093 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94094 /* if you care about this being correct, lock the buffer */
94095 for_each_buffer_cpu(buffer, cpu) {
94096 cpu_buffer = buffer->buffers[cpu];
94097 - overruns += local_read(&cpu_buffer->overrun);
94098 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94099 }
94100
94101 return overruns;
94102 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94103 /*
94104 * Reset the reader page to size zero.
94105 */
94106 - local_set(&cpu_buffer->reader_page->write, 0);
94107 - local_set(&cpu_buffer->reader_page->entries, 0);
94108 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94109 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94110 local_set(&cpu_buffer->reader_page->page->commit, 0);
94111 cpu_buffer->reader_page->real_end = 0;
94112
94113 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94114 * want to compare with the last_overrun.
94115 */
94116 smp_mb();
94117 - overwrite = local_read(&(cpu_buffer->overrun));
94118 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94119
94120 /*
94121 * Here's the tricky part.
94122 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94123
94124 cpu_buffer->head_page
94125 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94126 - local_set(&cpu_buffer->head_page->write, 0);
94127 - local_set(&cpu_buffer->head_page->entries, 0);
94128 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94129 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94130 local_set(&cpu_buffer->head_page->page->commit, 0);
94131
94132 cpu_buffer->head_page->read = 0;
94133 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94134
94135 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94136 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94137 - local_set(&cpu_buffer->reader_page->write, 0);
94138 - local_set(&cpu_buffer->reader_page->entries, 0);
94139 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94140 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94141 local_set(&cpu_buffer->reader_page->page->commit, 0);
94142 cpu_buffer->reader_page->read = 0;
94143
94144 local_set(&cpu_buffer->entries_bytes, 0);
94145 - local_set(&cpu_buffer->overrun, 0);
94146 - local_set(&cpu_buffer->commit_overrun, 0);
94147 + local_set_unchecked(&cpu_buffer->overrun, 0);
94148 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94149 local_set(&cpu_buffer->dropped_events, 0);
94150 local_set(&cpu_buffer->entries, 0);
94151 local_set(&cpu_buffer->committing, 0);
94152 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94153 rb_init_page(bpage);
94154 bpage = reader->page;
94155 reader->page = *data_page;
94156 - local_set(&reader->write, 0);
94157 - local_set(&reader->entries, 0);
94158 + local_set_unchecked(&reader->write, 0);
94159 + local_set_unchecked(&reader->entries, 0);
94160 reader->read = 0;
94161 *data_page = bpage;
94162
94163 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94164 index 426962b..e8e2d9a 100644
94165 --- a/kernel/trace/trace.c
94166 +++ b/kernel/trace/trace.c
94167 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94168 return 0;
94169 }
94170
94171 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94172 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94173 {
94174 /* do nothing if flag is already set */
94175 if (!!(trace_flags & mask) == !!enabled)
94176 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94177 index 385391f..8d2250f 100644
94178 --- a/kernel/trace/trace.h
94179 +++ b/kernel/trace/trace.h
94180 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94181 void trace_printk_init_buffers(void);
94182 void trace_printk_start_comm(void);
94183 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94184 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94185 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94186
94187 /*
94188 * Normal trace_printk() and friends allocates special buffers
94189 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94190 index 57b67b1..66082a9 100644
94191 --- a/kernel/trace/trace_clock.c
94192 +++ b/kernel/trace/trace_clock.c
94193 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94194 return now;
94195 }
94196
94197 -static atomic64_t trace_counter;
94198 +static atomic64_unchecked_t trace_counter;
94199
94200 /*
94201 * trace_clock_counter(): simply an atomic counter.
94202 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94203 */
94204 u64 notrace trace_clock_counter(void)
94205 {
94206 - return atomic64_add_return(1, &trace_counter);
94207 + return atomic64_inc_return_unchecked(&trace_counter);
94208 }
94209 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94210 index 1b0df1e..4ebb965 100644
94211 --- a/kernel/trace/trace_events.c
94212 +++ b/kernel/trace/trace_events.c
94213 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94214 return 0;
94215 }
94216
94217 -struct ftrace_module_file_ops;
94218 static void __add_event_to_tracers(struct ftrace_event_call *call);
94219
94220 /* Add an additional event_call dynamically */
94221 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94222 index f0a0c98..3692dc8 100644
94223 --- a/kernel/trace/trace_functions_graph.c
94224 +++ b/kernel/trace/trace_functions_graph.c
94225 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94226
94227 /* The return trace stack is full */
94228 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94229 - atomic_inc(&current->trace_overrun);
94230 + atomic_inc_unchecked(&current->trace_overrun);
94231 return -EBUSY;
94232 }
94233
94234 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94235 *ret = current->ret_stack[index].ret;
94236 trace->func = current->ret_stack[index].func;
94237 trace->calltime = current->ret_stack[index].calltime;
94238 - trace->overrun = atomic_read(&current->trace_overrun);
94239 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94240 trace->depth = index;
94241 }
94242
94243 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94244 index 0abd9b8..6a663a2 100644
94245 --- a/kernel/trace/trace_mmiotrace.c
94246 +++ b/kernel/trace/trace_mmiotrace.c
94247 @@ -24,7 +24,7 @@ struct header_iter {
94248 static struct trace_array *mmio_trace_array;
94249 static bool overrun_detected;
94250 static unsigned long prev_overruns;
94251 -static atomic_t dropped_count;
94252 +static atomic_unchecked_t dropped_count;
94253
94254 static void mmio_reset_data(struct trace_array *tr)
94255 {
94256 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94257
94258 static unsigned long count_overruns(struct trace_iterator *iter)
94259 {
94260 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94261 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94262 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94263
94264 if (over > prev_overruns)
94265 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94266 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94267 sizeof(*entry), 0, pc);
94268 if (!event) {
94269 - atomic_inc(&dropped_count);
94270 + atomic_inc_unchecked(&dropped_count);
94271 return;
94272 }
94273 entry = ring_buffer_event_data(event);
94274 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94275 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94276 sizeof(*entry), 0, pc);
94277 if (!event) {
94278 - atomic_inc(&dropped_count);
94279 + atomic_inc_unchecked(&dropped_count);
94280 return;
94281 }
94282 entry = ring_buffer_event_data(event);
94283 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94284 index c6977d5..d243785 100644
94285 --- a/kernel/trace/trace_output.c
94286 +++ b/kernel/trace/trace_output.c
94287 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94288 goto out;
94289 }
94290
94291 + pax_open_kernel();
94292 if (event->funcs->trace == NULL)
94293 - event->funcs->trace = trace_nop_print;
94294 + *(void **)&event->funcs->trace = trace_nop_print;
94295 if (event->funcs->raw == NULL)
94296 - event->funcs->raw = trace_nop_print;
94297 + *(void **)&event->funcs->raw = trace_nop_print;
94298 if (event->funcs->hex == NULL)
94299 - event->funcs->hex = trace_nop_print;
94300 + *(void **)&event->funcs->hex = trace_nop_print;
94301 if (event->funcs->binary == NULL)
94302 - event->funcs->binary = trace_nop_print;
94303 + *(void **)&event->funcs->binary = trace_nop_print;
94304 + pax_close_kernel();
94305
94306 key = event->type & (EVENT_HASHSIZE - 1);
94307
94308 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94309 index 1f24ed9..10407ec 100644
94310 --- a/kernel/trace/trace_seq.c
94311 +++ b/kernel/trace/trace_seq.c
94312 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94313
94314 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94315 if (!IS_ERR(p)) {
94316 - p = mangle_path(s->buffer + s->len, p, "\n");
94317 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94318 if (p) {
94319 s->len = p - s->buffer;
94320 return 1;
94321 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94322 index 16eddb3..758b308 100644
94323 --- a/kernel/trace/trace_stack.c
94324 +++ b/kernel/trace/trace_stack.c
94325 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94326 return;
94327
94328 /* we do not handle interrupt stacks yet */
94329 - if (!object_is_on_stack(stack))
94330 + if (!object_starts_on_stack(stack))
94331 return;
94332
94333 local_irq_save(flags);
94334 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94335 index 29228c4..301bc8c 100644
94336 --- a/kernel/trace/trace_syscalls.c
94337 +++ b/kernel/trace/trace_syscalls.c
94338 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94339 int num;
94340
94341 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94342 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94343 + return -EINVAL;
94344
94345 mutex_lock(&syscall_trace_lock);
94346 if (!sys_perf_refcount_enter)
94347 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94348 int num;
94349
94350 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94351 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94352 + return;
94353
94354 mutex_lock(&syscall_trace_lock);
94355 sys_perf_refcount_enter--;
94356 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94357 int num;
94358
94359 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94360 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94361 + return -EINVAL;
94362
94363 mutex_lock(&syscall_trace_lock);
94364 if (!sys_perf_refcount_exit)
94365 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94366 int num;
94367
94368 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94369 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94370 + return;
94371
94372 mutex_lock(&syscall_trace_lock);
94373 sys_perf_refcount_exit--;
94374 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94375 index a2e37c5..4fa859b 100644
94376 --- a/kernel/user_namespace.c
94377 +++ b/kernel/user_namespace.c
94378 @@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
94379 !kgid_has_mapping(parent_ns, group))
94380 return -EPERM;
94381
94382 +#ifdef CONFIG_GRKERNSEC
94383 + /*
94384 + * This doesn't really inspire confidence:
94385 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94386 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94387 + * Increases kernel attack surface in areas developers
94388 + * previously cared little about ("low importance due
94389 + * to requiring "root" capability")
94390 + * To be removed when this code receives *proper* review
94391 + */
94392 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94393 + !capable(CAP_SETGID))
94394 + return -EPERM;
94395 +#endif
94396 +
94397 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94398 if (!ns)
94399 return -ENOMEM;
94400 @@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94401 if (atomic_read(&current->mm->mm_users) > 1)
94402 return -EINVAL;
94403
94404 - if (current->fs->users != 1)
94405 + if (atomic_read(&current->fs->users) != 1)
94406 return -EINVAL;
94407
94408 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94409 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94410 index c8eac43..4b5f08f 100644
94411 --- a/kernel/utsname_sysctl.c
94412 +++ b/kernel/utsname_sysctl.c
94413 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94414 static int proc_do_uts_string(struct ctl_table *table, int write,
94415 void __user *buffer, size_t *lenp, loff_t *ppos)
94416 {
94417 - struct ctl_table uts_table;
94418 + ctl_table_no_const uts_table;
94419 int r;
94420 memcpy(&uts_table, table, sizeof(uts_table));
94421 uts_table.data = get_uts(table, write);
94422 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94423 index 70bf118..4be3c37 100644
94424 --- a/kernel/watchdog.c
94425 +++ b/kernel/watchdog.c
94426 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94427 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94428 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94429
94430 -static struct smp_hotplug_thread watchdog_threads = {
94431 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94432 .store = &softlockup_watchdog,
94433 .thread_should_run = watchdog_should_run,
94434 .thread_fn = watchdog,
94435 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94436 index 09b685d..d3565e3 100644
94437 --- a/kernel/workqueue.c
94438 +++ b/kernel/workqueue.c
94439 @@ -4508,7 +4508,7 @@ static void rebind_workers(struct worker_pool *pool)
94440 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94441 worker_flags |= WORKER_REBOUND;
94442 worker_flags &= ~WORKER_UNBOUND;
94443 - ACCESS_ONCE(worker->flags) = worker_flags;
94444 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94445 }
94446
94447 spin_unlock_irq(&pool->lock);
94448 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94449 index 4e35a5d..8a1f3f0 100644
94450 --- a/lib/Kconfig.debug
94451 +++ b/lib/Kconfig.debug
94452 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94453
94454 config DEBUG_WW_MUTEX_SLOWPATH
94455 bool "Wait/wound mutex debugging: Slowpath testing"
94456 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94457 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94458 select DEBUG_LOCK_ALLOC
94459 select DEBUG_SPINLOCK
94460 select DEBUG_MUTEXES
94461 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94462
94463 config DEBUG_LOCK_ALLOC
94464 bool "Lock debugging: detect incorrect freeing of live locks"
94465 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94466 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94467 select DEBUG_SPINLOCK
94468 select DEBUG_MUTEXES
94469 select LOCKDEP
94470 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94471
94472 config PROVE_LOCKING
94473 bool "Lock debugging: prove locking correctness"
94474 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94475 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94476 select LOCKDEP
94477 select DEBUG_SPINLOCK
94478 select DEBUG_MUTEXES
94479 @@ -976,7 +976,7 @@ config LOCKDEP
94480
94481 config LOCK_STAT
94482 bool "Lock usage statistics"
94483 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94484 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94485 select LOCKDEP
94486 select DEBUG_SPINLOCK
94487 select DEBUG_MUTEXES
94488 @@ -1449,6 +1449,7 @@ config LATENCYTOP
94489 depends on DEBUG_KERNEL
94490 depends on STACKTRACE_SUPPORT
94491 depends on PROC_FS
94492 + depends on !GRKERNSEC_HIDESYM
94493 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94494 select KALLSYMS
94495 select KALLSYMS_ALL
94496 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94497 config DEBUG_STRICT_USER_COPY_CHECKS
94498 bool "Strict user copy size checks"
94499 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94500 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94501 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94502 help
94503 Enabling this option turns a certain set of sanity checks for user
94504 copy operations into compile time failures.
94505 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94506
94507 config PROVIDE_OHCI1394_DMA_INIT
94508 bool "Remote debugging over FireWire early on boot"
94509 - depends on PCI && X86
94510 + depends on PCI && X86 && !GRKERNSEC
94511 help
94512 If you want to debug problems which hang or crash the kernel early
94513 on boot and the crashing machine has a FireWire port, you can use
94514 diff --git a/lib/Makefile b/lib/Makefile
94515 index 0211d2b..93f5cc3 100644
94516 --- a/lib/Makefile
94517 +++ b/lib/Makefile
94518 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94519 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94520 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94521 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94522 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94523 +obj-y += list_debug.o
94524 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94525
94526 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94527 diff --git a/lib/average.c b/lib/average.c
94528 index 114d1be..ab0350c 100644
94529 --- a/lib/average.c
94530 +++ b/lib/average.c
94531 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94532 {
94533 unsigned long internal = ACCESS_ONCE(avg->internal);
94534
94535 - ACCESS_ONCE(avg->internal) = internal ?
94536 + ACCESS_ONCE_RW(avg->internal) = internal ?
94537 (((internal << avg->weight) - internal) +
94538 (val << avg->factor)) >> avg->weight :
94539 (val << avg->factor);
94540 diff --git a/lib/bitmap.c b/lib/bitmap.c
94541 index b499ab6..fbdb76c 100644
94542 --- a/lib/bitmap.c
94543 +++ b/lib/bitmap.c
94544 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94545 {
94546 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94547 u32 chunk;
94548 - const char __user __force *ubuf = (const char __user __force *)buf;
94549 + const char __user *ubuf = (const char __force_user *)buf;
94550
94551 bitmap_zero(maskp, nmaskbits);
94552
94553 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94554 {
94555 if (!access_ok(VERIFY_READ, ubuf, ulen))
94556 return -EFAULT;
94557 - return __bitmap_parse((const char __force *)ubuf,
94558 + return __bitmap_parse((const char __force_kernel *)ubuf,
94559 ulen, 1, maskp, nmaskbits);
94560
94561 }
94562 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94563 {
94564 unsigned a, b;
94565 int c, old_c, totaldigits;
94566 - const char __user __force *ubuf = (const char __user __force *)buf;
94567 + const char __user *ubuf = (const char __force_user *)buf;
94568 int exp_digit, in_range;
94569
94570 totaldigits = c = 0;
94571 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94572 {
94573 if (!access_ok(VERIFY_READ, ubuf, ulen))
94574 return -EFAULT;
94575 - return __bitmap_parselist((const char __force *)ubuf,
94576 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94577 ulen, 1, maskp, nmaskbits);
94578 }
94579 EXPORT_SYMBOL(bitmap_parselist_user);
94580 diff --git a/lib/bug.c b/lib/bug.c
94581 index d1d7c78..b354235 100644
94582 --- a/lib/bug.c
94583 +++ b/lib/bug.c
94584 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94585 return BUG_TRAP_TYPE_NONE;
94586
94587 bug = find_bug(bugaddr);
94588 + if (!bug)
94589 + return BUG_TRAP_TYPE_NONE;
94590
94591 file = NULL;
94592 line = 0;
94593 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94594 index 547f7f9..a6d4ba0 100644
94595 --- a/lib/debugobjects.c
94596 +++ b/lib/debugobjects.c
94597 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94598 if (limit > 4)
94599 return;
94600
94601 - is_on_stack = object_is_on_stack(addr);
94602 + is_on_stack = object_starts_on_stack(addr);
94603 if (is_on_stack == onstack)
94604 return;
94605
94606 diff --git a/lib/div64.c b/lib/div64.c
94607 index 4382ad7..08aa558 100644
94608 --- a/lib/div64.c
94609 +++ b/lib/div64.c
94610 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94611 EXPORT_SYMBOL(__div64_32);
94612
94613 #ifndef div_s64_rem
94614 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94615 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94616 {
94617 u64 quotient;
94618
94619 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94620 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94621 */
94622 #ifndef div64_u64
94623 -u64 div64_u64(u64 dividend, u64 divisor)
94624 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94625 {
94626 u32 high = divisor >> 32;
94627 u64 quot;
94628 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94629 index add80cc..0d27550 100644
94630 --- a/lib/dma-debug.c
94631 +++ b/lib/dma-debug.c
94632 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94633
94634 void dma_debug_add_bus(struct bus_type *bus)
94635 {
94636 - struct notifier_block *nb;
94637 + notifier_block_no_const *nb;
94638
94639 if (global_disable)
94640 return;
94641 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94642
94643 static void check_for_stack(struct device *dev, void *addr)
94644 {
94645 - if (object_is_on_stack(addr))
94646 + if (object_starts_on_stack(addr))
94647 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94648 "stack [addr=%p]\n", addr);
94649 }
94650 diff --git a/lib/hash.c b/lib/hash.c
94651 index fea973f..386626f 100644
94652 --- a/lib/hash.c
94653 +++ b/lib/hash.c
94654 @@ -14,7 +14,7 @@
94655 #include <linux/hash.h>
94656 #include <linux/cache.h>
94657
94658 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94659 +static struct fast_hash_ops arch_hash_ops __read_only = {
94660 .hash = jhash,
94661 .hash2 = jhash2,
94662 };
94663 diff --git a/lib/inflate.c b/lib/inflate.c
94664 index 013a761..c28f3fc 100644
94665 --- a/lib/inflate.c
94666 +++ b/lib/inflate.c
94667 @@ -269,7 +269,7 @@ static void free(void *where)
94668 malloc_ptr = free_mem_ptr;
94669 }
94670 #else
94671 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94672 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94673 #define free(a) kfree(a)
94674 #endif
94675
94676 diff --git a/lib/ioremap.c b/lib/ioremap.c
94677 index 0c9216c..863bd89 100644
94678 --- a/lib/ioremap.c
94679 +++ b/lib/ioremap.c
94680 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94681 unsigned long next;
94682
94683 phys_addr -= addr;
94684 - pmd = pmd_alloc(&init_mm, pud, addr);
94685 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94686 if (!pmd)
94687 return -ENOMEM;
94688 do {
94689 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94690 unsigned long next;
94691
94692 phys_addr -= addr;
94693 - pud = pud_alloc(&init_mm, pgd, addr);
94694 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94695 if (!pud)
94696 return -ENOMEM;
94697 do {
94698 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94699 index bd2bea9..6b3c95e 100644
94700 --- a/lib/is_single_threaded.c
94701 +++ b/lib/is_single_threaded.c
94702 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94703 struct task_struct *p, *t;
94704 bool ret;
94705
94706 + if (!mm)
94707 + return true;
94708 +
94709 if (atomic_read(&task->signal->live) != 1)
94710 return false;
94711
94712 diff --git a/lib/kobject.c b/lib/kobject.c
94713 index 58751bb..93a1853 100644
94714 --- a/lib/kobject.c
94715 +++ b/lib/kobject.c
94716 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94717
94718
94719 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94720 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94721 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94722
94723 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94724 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94725 {
94726 enum kobj_ns_type type = ops->type;
94727 int error;
94728 diff --git a/lib/list_debug.c b/lib/list_debug.c
94729 index c24c2f7..f0296f4 100644
94730 --- a/lib/list_debug.c
94731 +++ b/lib/list_debug.c
94732 @@ -11,7 +11,9 @@
94733 #include <linux/bug.h>
94734 #include <linux/kernel.h>
94735 #include <linux/rculist.h>
94736 +#include <linux/mm.h>
94737
94738 +#ifdef CONFIG_DEBUG_LIST
94739 /*
94740 * Insert a new entry between two known consecutive entries.
94741 *
94742 @@ -19,21 +21,40 @@
94743 * the prev/next entries already!
94744 */
94745
94746 +static bool __list_add_debug(struct list_head *new,
94747 + struct list_head *prev,
94748 + struct list_head *next)
94749 +{
94750 + if (unlikely(next->prev != prev)) {
94751 + printk(KERN_ERR "list_add corruption. next->prev should be "
94752 + "prev (%p), but was %p. (next=%p).\n",
94753 + prev, next->prev, next);
94754 + BUG();
94755 + return false;
94756 + }
94757 + if (unlikely(prev->next != next)) {
94758 + printk(KERN_ERR "list_add corruption. prev->next should be "
94759 + "next (%p), but was %p. (prev=%p).\n",
94760 + next, prev->next, prev);
94761 + BUG();
94762 + return false;
94763 + }
94764 + if (unlikely(new == prev || new == next)) {
94765 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94766 + new, prev, next);
94767 + BUG();
94768 + return false;
94769 + }
94770 + return true;
94771 +}
94772 +
94773 void __list_add(struct list_head *new,
94774 - struct list_head *prev,
94775 - struct list_head *next)
94776 + struct list_head *prev,
94777 + struct list_head *next)
94778 {
94779 - WARN(next->prev != prev,
94780 - "list_add corruption. next->prev should be "
94781 - "prev (%p), but was %p. (next=%p).\n",
94782 - prev, next->prev, next);
94783 - WARN(prev->next != next,
94784 - "list_add corruption. prev->next should be "
94785 - "next (%p), but was %p. (prev=%p).\n",
94786 - next, prev->next, prev);
94787 - WARN(new == prev || new == next,
94788 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94789 - new, prev, next);
94790 + if (!__list_add_debug(new, prev, next))
94791 + return;
94792 +
94793 next->prev = new;
94794 new->next = next;
94795 new->prev = prev;
94796 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94797 }
94798 EXPORT_SYMBOL(__list_add);
94799
94800 -void __list_del_entry(struct list_head *entry)
94801 +static bool __list_del_entry_debug(struct list_head *entry)
94802 {
94803 struct list_head *prev, *next;
94804
94805 prev = entry->prev;
94806 next = entry->next;
94807
94808 - if (WARN(next == LIST_POISON1,
94809 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94810 - entry, LIST_POISON1) ||
94811 - WARN(prev == LIST_POISON2,
94812 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94813 - entry, LIST_POISON2) ||
94814 - WARN(prev->next != entry,
94815 - "list_del corruption. prev->next should be %p, "
94816 - "but was %p\n", entry, prev->next) ||
94817 - WARN(next->prev != entry,
94818 - "list_del corruption. next->prev should be %p, "
94819 - "but was %p\n", entry, next->prev))
94820 + if (unlikely(next == LIST_POISON1)) {
94821 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94822 + entry, LIST_POISON1);
94823 + BUG();
94824 + return false;
94825 + }
94826 + if (unlikely(prev == LIST_POISON2)) {
94827 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94828 + entry, LIST_POISON2);
94829 + BUG();
94830 + return false;
94831 + }
94832 + if (unlikely(entry->prev->next != entry)) {
94833 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94834 + "but was %p\n", entry, prev->next);
94835 + BUG();
94836 + return false;
94837 + }
94838 + if (unlikely(entry->next->prev != entry)) {
94839 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94840 + "but was %p\n", entry, next->prev);
94841 + BUG();
94842 + return false;
94843 + }
94844 + return true;
94845 +}
94846 +
94847 +void __list_del_entry(struct list_head *entry)
94848 +{
94849 + if (!__list_del_entry_debug(entry))
94850 return;
94851
94852 - __list_del(prev, next);
94853 + __list_del(entry->prev, entry->next);
94854 }
94855 EXPORT_SYMBOL(__list_del_entry);
94856
94857 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94858 void __list_add_rcu(struct list_head *new,
94859 struct list_head *prev, struct list_head *next)
94860 {
94861 - WARN(next->prev != prev,
94862 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94863 - prev, next->prev, next);
94864 - WARN(prev->next != next,
94865 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94866 - next, prev->next, prev);
94867 + if (!__list_add_debug(new, prev, next))
94868 + return;
94869 +
94870 new->next = next;
94871 new->prev = prev;
94872 rcu_assign_pointer(list_next_rcu(prev), new);
94873 next->prev = new;
94874 }
94875 EXPORT_SYMBOL(__list_add_rcu);
94876 +#endif
94877 +
94878 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94879 +{
94880 +#ifdef CONFIG_DEBUG_LIST
94881 + if (!__list_add_debug(new, prev, next))
94882 + return;
94883 +#endif
94884 +
94885 + pax_open_kernel();
94886 + next->prev = new;
94887 + new->next = next;
94888 + new->prev = prev;
94889 + prev->next = new;
94890 + pax_close_kernel();
94891 +}
94892 +EXPORT_SYMBOL(__pax_list_add);
94893 +
94894 +void pax_list_del(struct list_head *entry)
94895 +{
94896 +#ifdef CONFIG_DEBUG_LIST
94897 + if (!__list_del_entry_debug(entry))
94898 + return;
94899 +#endif
94900 +
94901 + pax_open_kernel();
94902 + __list_del(entry->prev, entry->next);
94903 + entry->next = LIST_POISON1;
94904 + entry->prev = LIST_POISON2;
94905 + pax_close_kernel();
94906 +}
94907 +EXPORT_SYMBOL(pax_list_del);
94908 +
94909 +void pax_list_del_init(struct list_head *entry)
94910 +{
94911 + pax_open_kernel();
94912 + __list_del(entry->prev, entry->next);
94913 + INIT_LIST_HEAD(entry);
94914 + pax_close_kernel();
94915 +}
94916 +EXPORT_SYMBOL(pax_list_del_init);
94917 +
94918 +void __pax_list_add_rcu(struct list_head *new,
94919 + struct list_head *prev, struct list_head *next)
94920 +{
94921 +#ifdef CONFIG_DEBUG_LIST
94922 + if (!__list_add_debug(new, prev, next))
94923 + return;
94924 +#endif
94925 +
94926 + pax_open_kernel();
94927 + new->next = next;
94928 + new->prev = prev;
94929 + rcu_assign_pointer(list_next_rcu(prev), new);
94930 + next->prev = new;
94931 + pax_close_kernel();
94932 +}
94933 +EXPORT_SYMBOL(__pax_list_add_rcu);
94934 +
94935 +void pax_list_del_rcu(struct list_head *entry)
94936 +{
94937 +#ifdef CONFIG_DEBUG_LIST
94938 + if (!__list_del_entry_debug(entry))
94939 + return;
94940 +#endif
94941 +
94942 + pax_open_kernel();
94943 + __list_del(entry->prev, entry->next);
94944 + entry->next = LIST_POISON1;
94945 + entry->prev = LIST_POISON2;
94946 + pax_close_kernel();
94947 +}
94948 +EXPORT_SYMBOL(pax_list_del_rcu);
94949 diff --git a/lib/lockref.c b/lib/lockref.c
94950 index d2233de..fa1a2f6 100644
94951 --- a/lib/lockref.c
94952 +++ b/lib/lockref.c
94953 @@ -48,13 +48,13 @@
94954 void lockref_get(struct lockref *lockref)
94955 {
94956 CMPXCHG_LOOP(
94957 - new.count++;
94958 + __lockref_inc(&new);
94959 ,
94960 return;
94961 );
94962
94963 spin_lock(&lockref->lock);
94964 - lockref->count++;
94965 + __lockref_inc(lockref);
94966 spin_unlock(&lockref->lock);
94967 }
94968 EXPORT_SYMBOL(lockref_get);
94969 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94970 int retval;
94971
94972 CMPXCHG_LOOP(
94973 - new.count++;
94974 + __lockref_inc(&new);
94975 if (!old.count)
94976 return 0;
94977 ,
94978 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94979 spin_lock(&lockref->lock);
94980 retval = 0;
94981 if (lockref->count) {
94982 - lockref->count++;
94983 + __lockref_inc(lockref);
94984 retval = 1;
94985 }
94986 spin_unlock(&lockref->lock);
94987 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94988 int lockref_get_or_lock(struct lockref *lockref)
94989 {
94990 CMPXCHG_LOOP(
94991 - new.count++;
94992 + __lockref_inc(&new);
94993 if (!old.count)
94994 break;
94995 ,
94996 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94997 spin_lock(&lockref->lock);
94998 if (!lockref->count)
94999 return 0;
95000 - lockref->count++;
95001 + __lockref_inc(lockref);
95002 spin_unlock(&lockref->lock);
95003 return 1;
95004 }
95005 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95006 int lockref_put_or_lock(struct lockref *lockref)
95007 {
95008 CMPXCHG_LOOP(
95009 - new.count--;
95010 + __lockref_dec(&new);
95011 if (old.count <= 1)
95012 break;
95013 ,
95014 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95015 spin_lock(&lockref->lock);
95016 if (lockref->count <= 1)
95017 return 0;
95018 - lockref->count--;
95019 + __lockref_dec(lockref);
95020 spin_unlock(&lockref->lock);
95021 return 1;
95022 }
95023 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95024 int retval;
95025
95026 CMPXCHG_LOOP(
95027 - new.count++;
95028 + __lockref_inc(&new);
95029 if ((int)old.count < 0)
95030 return 0;
95031 ,
95032 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95033 spin_lock(&lockref->lock);
95034 retval = 0;
95035 if ((int) lockref->count >= 0) {
95036 - lockref->count++;
95037 + __lockref_inc(lockref);
95038 retval = 1;
95039 }
95040 spin_unlock(&lockref->lock);
95041 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95042 index 6111bcb..02e816b 100644
95043 --- a/lib/percpu-refcount.c
95044 +++ b/lib/percpu-refcount.c
95045 @@ -31,7 +31,7 @@
95046 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
95047 */
95048
95049 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
95050 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
95051
95052 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
95053
95054 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95055 index 3291a8e..346a91e 100644
95056 --- a/lib/radix-tree.c
95057 +++ b/lib/radix-tree.c
95058 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95059 int nr;
95060 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95061 };
95062 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95063 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95064
95065 static inline void *ptr_to_indirect(void *ptr)
95066 {
95067 diff --git a/lib/random32.c b/lib/random32.c
95068 index 0bee183..526f12f 100644
95069 --- a/lib/random32.c
95070 +++ b/lib/random32.c
95071 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
95072 }
95073 #endif
95074
95075 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95076 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95077
95078 /**
95079 * prandom_u32_state - seeded pseudo-random number generator.
95080 diff --git a/lib/rbtree.c b/lib/rbtree.c
95081 index c16c81a..4dcbda1 100644
95082 --- a/lib/rbtree.c
95083 +++ b/lib/rbtree.c
95084 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95085 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95086
95087 static const struct rb_augment_callbacks dummy_callbacks = {
95088 - dummy_propagate, dummy_copy, dummy_rotate
95089 + .propagate = dummy_propagate,
95090 + .copy = dummy_copy,
95091 + .rotate = dummy_rotate
95092 };
95093
95094 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95095 diff --git a/lib/show_mem.c b/lib/show_mem.c
95096 index 5e25627..3ed9d7f 100644
95097 --- a/lib/show_mem.c
95098 +++ b/lib/show_mem.c
95099 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95100 quicklist_total_size());
95101 #endif
95102 #ifdef CONFIG_MEMORY_FAILURE
95103 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95104 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95105 #endif
95106 }
95107 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95108 index bb2b201..46abaf9 100644
95109 --- a/lib/strncpy_from_user.c
95110 +++ b/lib/strncpy_from_user.c
95111 @@ -21,7 +21,7 @@
95112 */
95113 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95114 {
95115 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95116 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95117 long res = 0;
95118
95119 /*
95120 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95121 index a28df52..3d55877 100644
95122 --- a/lib/strnlen_user.c
95123 +++ b/lib/strnlen_user.c
95124 @@ -26,7 +26,7 @@
95125 */
95126 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95127 {
95128 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95129 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95130 long align, res = 0;
95131 unsigned long c;
95132
95133 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95134 index 4abda07..b9d3765 100644
95135 --- a/lib/swiotlb.c
95136 +++ b/lib/swiotlb.c
95137 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95138
95139 void
95140 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95141 - dma_addr_t dev_addr)
95142 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95143 {
95144 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95145
95146 diff --git a/lib/usercopy.c b/lib/usercopy.c
95147 index 4f5b1dd..7cab418 100644
95148 --- a/lib/usercopy.c
95149 +++ b/lib/usercopy.c
95150 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95151 WARN(1, "Buffer overflow detected!\n");
95152 }
95153 EXPORT_SYMBOL(copy_from_user_overflow);
95154 +
95155 +void copy_to_user_overflow(void)
95156 +{
95157 + WARN(1, "Buffer overflow detected!\n");
95158 +}
95159 +EXPORT_SYMBOL(copy_to_user_overflow);
95160 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95161 index ec337f6..8484eb2 100644
95162 --- a/lib/vsprintf.c
95163 +++ b/lib/vsprintf.c
95164 @@ -16,6 +16,9 @@
95165 * - scnprintf and vscnprintf
95166 */
95167
95168 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95169 +#define __INCLUDED_BY_HIDESYM 1
95170 +#endif
95171 #include <stdarg.h>
95172 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95173 #include <linux/types.h>
95174 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95175 #ifdef CONFIG_KALLSYMS
95176 if (*fmt == 'B')
95177 sprint_backtrace(sym, value);
95178 - else if (*fmt != 'f' && *fmt != 's')
95179 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95180 sprint_symbol(sym, value);
95181 else
95182 sprint_symbol_no_offset(sym, value);
95183 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95184 return number(buf, end, num, spec);
95185 }
95186
95187 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95188 +int kptr_restrict __read_mostly = 2;
95189 +#else
95190 int kptr_restrict __read_mostly;
95191 +#endif
95192
95193 /*
95194 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95195 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95196 *
95197 * - 'F' For symbolic function descriptor pointers with offset
95198 * - 'f' For simple symbolic function names without offset
95199 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95200 * - 'S' For symbolic direct pointers with offset
95201 * - 's' For symbolic direct pointers without offset
95202 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95203 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95204 * - 'B' For backtraced symbolic direct pointers with offset
95205 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95206 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95207
95208 if (!ptr && *fmt != 'K') {
95209 /*
95210 - * Print (null) with the same width as a pointer so it makes
95211 + * Print (nil) with the same width as a pointer so it makes
95212 * tabular output look nice.
95213 */
95214 if (spec.field_width == -1)
95215 spec.field_width = default_width;
95216 - return string(buf, end, "(null)", spec);
95217 + return string(buf, end, "(nil)", spec);
95218 }
95219
95220 switch (*fmt) {
95221 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95222 /* Fallthrough */
95223 case 'S':
95224 case 's':
95225 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95226 + break;
95227 +#else
95228 + return symbol_string(buf, end, ptr, spec, fmt);
95229 +#endif
95230 + case 'X':
95231 + ptr = dereference_function_descriptor(ptr);
95232 + case 'A':
95233 case 'B':
95234 return symbol_string(buf, end, ptr, spec, fmt);
95235 case 'R':
95236 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95237 va_end(va);
95238 return buf;
95239 }
95240 + case 'P':
95241 + break;
95242 case 'K':
95243 /*
95244 * %pK cannot be used in IRQ context because its test
95245 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95246 ((const struct file *)ptr)->f_path.dentry,
95247 spec, fmt);
95248 }
95249 +
95250 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95251 + /* 'P' = approved pointers to copy to userland,
95252 + as in the /proc/kallsyms case, as we make it display nothing
95253 + for non-root users, and the real contents for root users
95254 + 'X' = approved simple symbols
95255 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95256 + above
95257 + */
95258 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95259 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95260 + dump_stack();
95261 + ptr = NULL;
95262 + }
95263 +#endif
95264 +
95265 spec.flags |= SMALL;
95266 if (spec.field_width == -1) {
95267 spec.field_width = default_width;
95268 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95269 typeof(type) value; \
95270 if (sizeof(type) == 8) { \
95271 args = PTR_ALIGN(args, sizeof(u32)); \
95272 - *(u32 *)&value = *(u32 *)args; \
95273 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95274 + *(u32 *)&value = *(const u32 *)args; \
95275 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95276 } else { \
95277 args = PTR_ALIGN(args, sizeof(type)); \
95278 - value = *(typeof(type) *)args; \
95279 + value = *(const typeof(type) *)args; \
95280 } \
95281 args += sizeof(type); \
95282 value; \
95283 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95284 case FORMAT_TYPE_STR: {
95285 const char *str_arg = args;
95286 args += strlen(str_arg) + 1;
95287 - str = string(str, end, (char *)str_arg, spec);
95288 + str = string(str, end, str_arg, spec);
95289 break;
95290 }
95291
95292 diff --git a/localversion-grsec b/localversion-grsec
95293 new file mode 100644
95294 index 0000000..7cd6065
95295 --- /dev/null
95296 +++ b/localversion-grsec
95297 @@ -0,0 +1 @@
95298 +-grsec
95299 diff --git a/mm/Kconfig b/mm/Kconfig
95300 index 1d1ae6b..0f05885 100644
95301 --- a/mm/Kconfig
95302 +++ b/mm/Kconfig
95303 @@ -341,10 +341,11 @@ config KSM
95304 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95305
95306 config DEFAULT_MMAP_MIN_ADDR
95307 - int "Low address space to protect from user allocation"
95308 + int "Low address space to protect from user allocation"
95309 depends on MMU
95310 - default 4096
95311 - help
95312 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95313 + default 65536
95314 + help
95315 This is the portion of low virtual memory which should be protected
95316 from userspace allocation. Keeping a user from writing to low pages
95317 can help reduce the impact of kernel NULL pointer bugs.
95318 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
95319
95320 config HWPOISON_INJECT
95321 tristate "HWPoison pages injector"
95322 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95323 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95324 select PROC_PAGE_MONITOR
95325
95326 config NOMMU_INITIAL_TRIM_EXCESS
95327 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95328 index 0ae0df5..82ac56b 100644
95329 --- a/mm/backing-dev.c
95330 +++ b/mm/backing-dev.c
95331 @@ -12,7 +12,7 @@
95332 #include <linux/device.h>
95333 #include <trace/events/writeback.h>
95334
95335 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95336 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95337
95338 struct backing_dev_info default_backing_dev_info = {
95339 .name = "default",
95340 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95341 return err;
95342
95343 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95344 - atomic_long_inc_return(&bdi_seq));
95345 + atomic_long_inc_return_unchecked(&bdi_seq));
95346 if (err) {
95347 bdi_destroy(bdi);
95348 return err;
95349 diff --git a/mm/filemap.c b/mm/filemap.c
95350 index 14b4642..d71ba82 100644
95351 --- a/mm/filemap.c
95352 +++ b/mm/filemap.c
95353 @@ -2101,7 +2101,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95354 struct address_space *mapping = file->f_mapping;
95355
95356 if (!mapping->a_ops->readpage)
95357 - return -ENOEXEC;
95358 + return -ENODEV;
95359 file_accessed(file);
95360 vma->vm_ops = &generic_file_vm_ops;
95361 return 0;
95362 @@ -2279,6 +2279,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95363 *pos = i_size_read(inode);
95364
95365 if (limit != RLIM_INFINITY) {
95366 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95367 if (*pos >= limit) {
95368 send_sig(SIGXFSZ, current, 0);
95369 return -EFBIG;
95370 diff --git a/mm/fremap.c b/mm/fremap.c
95371 index 72b8fa3..c5b39f1 100644
95372 --- a/mm/fremap.c
95373 +++ b/mm/fremap.c
95374 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95375 retry:
95376 vma = find_vma(mm, start);
95377
95378 +#ifdef CONFIG_PAX_SEGMEXEC
95379 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95380 + goto out;
95381 +#endif
95382 +
95383 /*
95384 * Make sure the vma is shared, that it supports prefaulting,
95385 * and that the remapped range is valid and fully within
95386 diff --git a/mm/gup.c b/mm/gup.c
95387 index cd62c8c..3bb2053 100644
95388 --- a/mm/gup.c
95389 +++ b/mm/gup.c
95390 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95391 unsigned int fault_flags = 0;
95392 int ret;
95393
95394 - /* For mlock, just skip the stack guard page. */
95395 - if ((*flags & FOLL_MLOCK) &&
95396 - (stack_guard_page_start(vma, address) ||
95397 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95398 - return -ENOENT;
95399 if (*flags & FOLL_WRITE)
95400 fault_flags |= FAULT_FLAG_WRITE;
95401 if (nonblocking)
95402 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95403 if (!(gup_flags & FOLL_FORCE))
95404 gup_flags |= FOLL_NUMA;
95405
95406 - do {
95407 + while (nr_pages) {
95408 struct page *page;
95409 unsigned int foll_flags = gup_flags;
95410 unsigned int page_increm;
95411
95412 /* first iteration or cross vma bound */
95413 if (!vma || start >= vma->vm_end) {
95414 - vma = find_extend_vma(mm, start);
95415 + vma = find_vma(mm, start);
95416 if (!vma && in_gate_area(mm, start)) {
95417 int ret;
95418 ret = get_gate_page(mm, start & PAGE_MASK,
95419 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95420 goto next_page;
95421 }
95422
95423 - if (!vma || check_vma_flags(vma, gup_flags))
95424 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95425 return i ? : -EFAULT;
95426 if (is_vm_hugetlb_page(vma)) {
95427 i = follow_hugetlb_page(mm, vma, pages, vmas,
95428 @@ -518,7 +513,7 @@ next_page:
95429 i += page_increm;
95430 start += page_increm * PAGE_SIZE;
95431 nr_pages -= page_increm;
95432 - } while (nr_pages);
95433 + }
95434 return i;
95435 }
95436 EXPORT_SYMBOL(__get_user_pages);
95437 diff --git a/mm/highmem.c b/mm/highmem.c
95438 index 123bcd3..0de52ba 100644
95439 --- a/mm/highmem.c
95440 +++ b/mm/highmem.c
95441 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95442 * So no dangers, even with speculative execution.
95443 */
95444 page = pte_page(pkmap_page_table[i]);
95445 + pax_open_kernel();
95446 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95447 -
95448 + pax_close_kernel();
95449 set_page_address(page, NULL);
95450 need_flush = 1;
95451 }
95452 @@ -259,9 +260,11 @@ start:
95453 }
95454 }
95455 vaddr = PKMAP_ADDR(last_pkmap_nr);
95456 +
95457 + pax_open_kernel();
95458 set_pte_at(&init_mm, vaddr,
95459 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95460 -
95461 + pax_close_kernel();
95462 pkmap_count[last_pkmap_nr] = 1;
95463 set_page_address(page, (void *)vaddr);
95464
95465 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95466 index 9fd7227..5628939 100644
95467 --- a/mm/hugetlb.c
95468 +++ b/mm/hugetlb.c
95469 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95470 struct ctl_table *table, int write,
95471 void __user *buffer, size_t *length, loff_t *ppos)
95472 {
95473 + ctl_table_no_const t;
95474 struct hstate *h = &default_hstate;
95475 unsigned long tmp = h->max_huge_pages;
95476 int ret;
95477 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95478 if (!hugepages_supported())
95479 return -ENOTSUPP;
95480
95481 - table->data = &tmp;
95482 - table->maxlen = sizeof(unsigned long);
95483 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95484 + t = *table;
95485 + t.data = &tmp;
95486 + t.maxlen = sizeof(unsigned long);
95487 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95488 if (ret)
95489 goto out;
95490
95491 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95492 struct hstate *h = &default_hstate;
95493 unsigned long tmp;
95494 int ret;
95495 + ctl_table_no_const hugetlb_table;
95496
95497 if (!hugepages_supported())
95498 return -ENOTSUPP;
95499 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95500 if (write && hstate_is_gigantic(h))
95501 return -EINVAL;
95502
95503 - table->data = &tmp;
95504 - table->maxlen = sizeof(unsigned long);
95505 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95506 + hugetlb_table = *table;
95507 + hugetlb_table.data = &tmp;
95508 + hugetlb_table.maxlen = sizeof(unsigned long);
95509 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95510 if (ret)
95511 goto out;
95512
95513 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95514 mutex_unlock(&mapping->i_mmap_mutex);
95515 }
95516
95517 +#ifdef CONFIG_PAX_SEGMEXEC
95518 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95519 +{
95520 + struct mm_struct *mm = vma->vm_mm;
95521 + struct vm_area_struct *vma_m;
95522 + unsigned long address_m;
95523 + pte_t *ptep_m;
95524 +
95525 + vma_m = pax_find_mirror_vma(vma);
95526 + if (!vma_m)
95527 + return;
95528 +
95529 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95530 + address_m = address + SEGMEXEC_TASK_SIZE;
95531 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95532 + get_page(page_m);
95533 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95534 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95535 +}
95536 +#endif
95537 +
95538 /*
95539 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95540 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95541 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95542 make_huge_pte(vma, new_page, 1));
95543 page_remove_rmap(old_page);
95544 hugepage_add_new_anon_rmap(new_page, vma, address);
95545 +
95546 +#ifdef CONFIG_PAX_SEGMEXEC
95547 + pax_mirror_huge_pte(vma, address, new_page);
95548 +#endif
95549 +
95550 /* Make the old page be freed below */
95551 new_page = old_page;
95552 }
95553 @@ -3063,6 +3093,10 @@ retry:
95554 && (vma->vm_flags & VM_SHARED)));
95555 set_huge_pte_at(mm, address, ptep, new_pte);
95556
95557 +#ifdef CONFIG_PAX_SEGMEXEC
95558 + pax_mirror_huge_pte(vma, address, page);
95559 +#endif
95560 +
95561 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95562 /* Optimization, do the COW without a second fault */
95563 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95564 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95565 struct hstate *h = hstate_vma(vma);
95566 struct address_space *mapping;
95567
95568 +#ifdef CONFIG_PAX_SEGMEXEC
95569 + struct vm_area_struct *vma_m;
95570 +#endif
95571 +
95572 address &= huge_page_mask(h);
95573
95574 ptep = huge_pte_offset(mm, address);
95575 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95576 VM_FAULT_SET_HINDEX(hstate_index(h));
95577 }
95578
95579 +#ifdef CONFIG_PAX_SEGMEXEC
95580 + vma_m = pax_find_mirror_vma(vma);
95581 + if (vma_m) {
95582 + unsigned long address_m;
95583 +
95584 + if (vma->vm_start > vma_m->vm_start) {
95585 + address_m = address;
95586 + address -= SEGMEXEC_TASK_SIZE;
95587 + vma = vma_m;
95588 + h = hstate_vma(vma);
95589 + } else
95590 + address_m = address + SEGMEXEC_TASK_SIZE;
95591 +
95592 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95593 + return VM_FAULT_OOM;
95594 + address_m &= HPAGE_MASK;
95595 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95596 + }
95597 +#endif
95598 +
95599 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95600 if (!ptep)
95601 return VM_FAULT_OOM;
95602 diff --git a/mm/internal.h b/mm/internal.h
95603 index a4f90ba..fbdc32b 100644
95604 --- a/mm/internal.h
95605 +++ b/mm/internal.h
95606 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95607
95608 extern int __isolate_free_page(struct page *page, unsigned int order);
95609 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95610 +extern void free_compound_page(struct page *page);
95611 extern void prep_compound_page(struct page *page, unsigned long order);
95612 #ifdef CONFIG_MEMORY_FAILURE
95613 extern bool is_free_buddy_page(struct page *page);
95614 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95615
95616 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95617 unsigned long, unsigned long,
95618 - unsigned long, unsigned long);
95619 + unsigned long, unsigned long) __intentional_overflow(-1);
95620
95621 extern void set_pageblock_order(void);
95622 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95623 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95624 index e34a3cb..a810efe 100644
95625 --- a/mm/iov_iter.c
95626 +++ b/mm/iov_iter.c
95627 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95628
95629 while (bytes) {
95630 char __user *buf = iov->iov_base + base;
95631 - int copy = min(bytes, iov->iov_len - base);
95632 + size_t copy = min(bytes, iov->iov_len - base);
95633
95634 base = 0;
95635 left = __copy_from_user_inatomic(vaddr, buf, copy);
95636 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95637
95638 kaddr = kmap_atomic(page);
95639 if (likely(i->nr_segs == 1)) {
95640 - int left;
95641 + size_t left;
95642 char __user *buf = i->iov->iov_base + i->iov_offset;
95643 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95644 copied = bytes - left;
95645 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95646 * zero-length segments (without overruning the iovec).
95647 */
95648 while (bytes || unlikely(i->count && !iov->iov_len)) {
95649 - int copy;
95650 + size_t copy;
95651
95652 copy = min(bytes, iov->iov_len - base);
95653 BUG_ON(!i->count || i->count < copy);
95654 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95655 index 3cda50c..032ba634 100644
95656 --- a/mm/kmemleak.c
95657 +++ b/mm/kmemleak.c
95658 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95659
95660 for (i = 0; i < object->trace_len; i++) {
95661 void *ptr = (void *)object->trace[i];
95662 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95663 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95664 }
95665 }
95666
95667 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95668 return -ENOMEM;
95669 }
95670
95671 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95672 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95673 &kmemleak_fops);
95674 if (!dentry)
95675 pr_warning("Failed to create the debugfs kmemleak file\n");
95676 diff --git a/mm/maccess.c b/mm/maccess.c
95677 index d53adf9..03a24bf 100644
95678 --- a/mm/maccess.c
95679 +++ b/mm/maccess.c
95680 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95681 set_fs(KERNEL_DS);
95682 pagefault_disable();
95683 ret = __copy_from_user_inatomic(dst,
95684 - (__force const void __user *)src, size);
95685 + (const void __force_user *)src, size);
95686 pagefault_enable();
95687 set_fs(old_fs);
95688
95689 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95690
95691 set_fs(KERNEL_DS);
95692 pagefault_disable();
95693 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95694 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95695 pagefault_enable();
95696 set_fs(old_fs);
95697
95698 diff --git a/mm/madvise.c b/mm/madvise.c
95699 index 0938b30..199abe8 100644
95700 --- a/mm/madvise.c
95701 +++ b/mm/madvise.c
95702 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95703 pgoff_t pgoff;
95704 unsigned long new_flags = vma->vm_flags;
95705
95706 +#ifdef CONFIG_PAX_SEGMEXEC
95707 + struct vm_area_struct *vma_m;
95708 +#endif
95709 +
95710 switch (behavior) {
95711 case MADV_NORMAL:
95712 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95713 @@ -126,6 +130,13 @@ success:
95714 /*
95715 * vm_flags is protected by the mmap_sem held in write mode.
95716 */
95717 +
95718 +#ifdef CONFIG_PAX_SEGMEXEC
95719 + vma_m = pax_find_mirror_vma(vma);
95720 + if (vma_m)
95721 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95722 +#endif
95723 +
95724 vma->vm_flags = new_flags;
95725
95726 out:
95727 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95728 struct vm_area_struct **prev,
95729 unsigned long start, unsigned long end)
95730 {
95731 +
95732 +#ifdef CONFIG_PAX_SEGMEXEC
95733 + struct vm_area_struct *vma_m;
95734 +#endif
95735 +
95736 *prev = vma;
95737 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95738 return -EINVAL;
95739 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95740 zap_page_range(vma, start, end - start, &details);
95741 } else
95742 zap_page_range(vma, start, end - start, NULL);
95743 +
95744 +#ifdef CONFIG_PAX_SEGMEXEC
95745 + vma_m = pax_find_mirror_vma(vma);
95746 + if (vma_m) {
95747 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95748 + struct zap_details details = {
95749 + .nonlinear_vma = vma_m,
95750 + .last_index = ULONG_MAX,
95751 + };
95752 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95753 + } else
95754 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95755 + }
95756 +#endif
95757 +
95758 return 0;
95759 }
95760
95761 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95762 if (end < start)
95763 return error;
95764
95765 +#ifdef CONFIG_PAX_SEGMEXEC
95766 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95767 + if (end > SEGMEXEC_TASK_SIZE)
95768 + return error;
95769 + } else
95770 +#endif
95771 +
95772 + if (end > TASK_SIZE)
95773 + return error;
95774 +
95775 error = 0;
95776 if (end == start)
95777 return error;
95778 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95779 index 8639f6b..b623882a 100644
95780 --- a/mm/memory-failure.c
95781 +++ b/mm/memory-failure.c
95782 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95783
95784 int sysctl_memory_failure_recovery __read_mostly = 1;
95785
95786 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95787 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95788
95789 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95790
95791 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95792 pfn, t->comm, t->pid);
95793 si.si_signo = SIGBUS;
95794 si.si_errno = 0;
95795 - si.si_addr = (void *)addr;
95796 + si.si_addr = (void __user *)addr;
95797 #ifdef __ARCH_SI_TRAPNO
95798 si.si_trapno = trapno;
95799 #endif
95800 @@ -791,7 +791,7 @@ static struct page_state {
95801 unsigned long res;
95802 char *msg;
95803 int (*action)(struct page *p, unsigned long pfn);
95804 -} error_states[] = {
95805 +} __do_const error_states[] = {
95806 { reserved, reserved, "reserved kernel", me_kernel },
95807 /*
95808 * free pages are specially detected outside this table:
95809 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95810 nr_pages = 1 << compound_order(hpage);
95811 else /* normal page or thp */
95812 nr_pages = 1;
95813 - atomic_long_add(nr_pages, &num_poisoned_pages);
95814 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95815
95816 /*
95817 * We need/can do nothing about count=0 pages.
95818 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95819 if (PageHWPoison(hpage)) {
95820 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95821 || (p != hpage && TestSetPageHWPoison(hpage))) {
95822 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95823 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95824 unlock_page(hpage);
95825 return 0;
95826 }
95827 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95828 */
95829 if (!PageHWPoison(p)) {
95830 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95831 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95832 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95833 put_page(hpage);
95834 res = 0;
95835 goto out;
95836 }
95837 if (hwpoison_filter(p)) {
95838 if (TestClearPageHWPoison(p))
95839 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95840 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95841 unlock_page(hpage);
95842 put_page(hpage);
95843 return 0;
95844 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95845 return 0;
95846 }
95847 if (TestClearPageHWPoison(p))
95848 - atomic_long_dec(&num_poisoned_pages);
95849 + atomic_long_dec_unchecked(&num_poisoned_pages);
95850 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95851 return 0;
95852 }
95853 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95854 */
95855 if (TestClearPageHWPoison(page)) {
95856 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95857 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95858 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95859 freeit = 1;
95860 if (PageHuge(page))
95861 clear_page_hwpoison_huge_page(page);
95862 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95863 if (PageHuge(page)) {
95864 set_page_hwpoison_huge_page(hpage);
95865 dequeue_hwpoisoned_huge_page(hpage);
95866 - atomic_long_add(1 << compound_order(hpage),
95867 + atomic_long_add_unchecked(1 << compound_order(hpage),
95868 &num_poisoned_pages);
95869 } else {
95870 SetPageHWPoison(page);
95871 - atomic_long_inc(&num_poisoned_pages);
95872 + atomic_long_inc_unchecked(&num_poisoned_pages);
95873 }
95874 }
95875 return ret;
95876 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95877 put_page(page);
95878 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95879 SetPageHWPoison(page);
95880 - atomic_long_inc(&num_poisoned_pages);
95881 + atomic_long_inc_unchecked(&num_poisoned_pages);
95882 return 0;
95883 }
95884
95885 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95886 if (!is_free_buddy_page(page))
95887 pr_info("soft offline: %#lx: page leaked\n",
95888 pfn);
95889 - atomic_long_inc(&num_poisoned_pages);
95890 + atomic_long_inc_unchecked(&num_poisoned_pages);
95891 }
95892 } else {
95893 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95894 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95895 if (PageHuge(page)) {
95896 set_page_hwpoison_huge_page(hpage);
95897 dequeue_hwpoisoned_huge_page(hpage);
95898 - atomic_long_add(1 << compound_order(hpage),
95899 + atomic_long_add_unchecked(1 << compound_order(hpage),
95900 &num_poisoned_pages);
95901 } else {
95902 SetPageHWPoison(page);
95903 - atomic_long_inc(&num_poisoned_pages);
95904 + atomic_long_inc_unchecked(&num_poisoned_pages);
95905 }
95906 }
95907 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95908 diff --git a/mm/memory.c b/mm/memory.c
95909 index 7f86cf6..0600e22 100644
95910 --- a/mm/memory.c
95911 +++ b/mm/memory.c
95912 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95913 free_pte_range(tlb, pmd, addr);
95914 } while (pmd++, addr = next, addr != end);
95915
95916 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95917 start &= PUD_MASK;
95918 if (start < floor)
95919 return;
95920 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95921 pmd = pmd_offset(pud, start);
95922 pud_clear(pud);
95923 pmd_free_tlb(tlb, pmd, start);
95924 +#endif
95925 +
95926 }
95927
95928 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95929 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95930 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95931 } while (pud++, addr = next, addr != end);
95932
95933 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95934 start &= PGDIR_MASK;
95935 if (start < floor)
95936 return;
95937 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95938 pud = pud_offset(pgd, start);
95939 pgd_clear(pgd);
95940 pud_free_tlb(tlb, pud, start);
95941 +#endif
95942 +
95943 }
95944
95945 /*
95946 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95947 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95948 */
95949 if (vma->vm_ops)
95950 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95951 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95952 vma->vm_ops->fault);
95953 if (vma->vm_file)
95954 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95955 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95956 vma->vm_file->f_op->mmap);
95957 dump_stack();
95958 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95959 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95960 page_add_file_rmap(page);
95961 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95962
95963 +#ifdef CONFIG_PAX_SEGMEXEC
95964 + pax_mirror_file_pte(vma, addr, page, ptl);
95965 +#endif
95966 +
95967 retval = 0;
95968 pte_unmap_unlock(pte, ptl);
95969 return retval;
95970 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95971 if (!page_count(page))
95972 return -EINVAL;
95973 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95974 +
95975 +#ifdef CONFIG_PAX_SEGMEXEC
95976 + struct vm_area_struct *vma_m;
95977 +#endif
95978 +
95979 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95980 BUG_ON(vma->vm_flags & VM_PFNMAP);
95981 vma->vm_flags |= VM_MIXEDMAP;
95982 +
95983 +#ifdef CONFIG_PAX_SEGMEXEC
95984 + vma_m = pax_find_mirror_vma(vma);
95985 + if (vma_m)
95986 + vma_m->vm_flags |= VM_MIXEDMAP;
95987 +#endif
95988 +
95989 }
95990 return insert_page(vma, addr, page, vma->vm_page_prot);
95991 }
95992 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95993 unsigned long pfn)
95994 {
95995 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95996 + BUG_ON(vma->vm_mirror);
95997
95998 if (addr < vma->vm_start || addr >= vma->vm_end)
95999 return -EFAULT;
96000 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96001
96002 BUG_ON(pud_huge(*pud));
96003
96004 - pmd = pmd_alloc(mm, pud, addr);
96005 + pmd = (mm == &init_mm) ?
96006 + pmd_alloc_kernel(mm, pud, addr) :
96007 + pmd_alloc(mm, pud, addr);
96008 if (!pmd)
96009 return -ENOMEM;
96010 do {
96011 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96012 unsigned long next;
96013 int err;
96014
96015 - pud = pud_alloc(mm, pgd, addr);
96016 + pud = (mm == &init_mm) ?
96017 + pud_alloc_kernel(mm, pgd, addr) :
96018 + pud_alloc(mm, pgd, addr);
96019 if (!pud)
96020 return -ENOMEM;
96021 do {
96022 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96023 return ret;
96024 }
96025
96026 +#ifdef CONFIG_PAX_SEGMEXEC
96027 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96028 +{
96029 + struct mm_struct *mm = vma->vm_mm;
96030 + spinlock_t *ptl;
96031 + pte_t *pte, entry;
96032 +
96033 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96034 + entry = *pte;
96035 + if (!pte_present(entry)) {
96036 + if (!pte_none(entry)) {
96037 + BUG_ON(pte_file(entry));
96038 + free_swap_and_cache(pte_to_swp_entry(entry));
96039 + pte_clear_not_present_full(mm, address, pte, 0);
96040 + }
96041 + } else {
96042 + struct page *page;
96043 +
96044 + flush_cache_page(vma, address, pte_pfn(entry));
96045 + entry = ptep_clear_flush(vma, address, pte);
96046 + BUG_ON(pte_dirty(entry));
96047 + page = vm_normal_page(vma, address, entry);
96048 + if (page) {
96049 + update_hiwater_rss(mm);
96050 + if (PageAnon(page))
96051 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96052 + else
96053 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96054 + page_remove_rmap(page);
96055 + page_cache_release(page);
96056 + }
96057 + }
96058 + pte_unmap_unlock(pte, ptl);
96059 +}
96060 +
96061 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96062 + *
96063 + * the ptl of the lower mapped page is held on entry and is not released on exit
96064 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96065 + */
96066 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96067 +{
96068 + struct mm_struct *mm = vma->vm_mm;
96069 + unsigned long address_m;
96070 + spinlock_t *ptl_m;
96071 + struct vm_area_struct *vma_m;
96072 + pmd_t *pmd_m;
96073 + pte_t *pte_m, entry_m;
96074 +
96075 + BUG_ON(!page_m || !PageAnon(page_m));
96076 +
96077 + vma_m = pax_find_mirror_vma(vma);
96078 + if (!vma_m)
96079 + return;
96080 +
96081 + BUG_ON(!PageLocked(page_m));
96082 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96083 + address_m = address + SEGMEXEC_TASK_SIZE;
96084 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96085 + pte_m = pte_offset_map(pmd_m, address_m);
96086 + ptl_m = pte_lockptr(mm, pmd_m);
96087 + if (ptl != ptl_m) {
96088 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96089 + if (!pte_none(*pte_m))
96090 + goto out;
96091 + }
96092 +
96093 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96094 + page_cache_get(page_m);
96095 + page_add_anon_rmap(page_m, vma_m, address_m);
96096 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96097 + set_pte_at(mm, address_m, pte_m, entry_m);
96098 + update_mmu_cache(vma_m, address_m, pte_m);
96099 +out:
96100 + if (ptl != ptl_m)
96101 + spin_unlock(ptl_m);
96102 + pte_unmap(pte_m);
96103 + unlock_page(page_m);
96104 +}
96105 +
96106 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96107 +{
96108 + struct mm_struct *mm = vma->vm_mm;
96109 + unsigned long address_m;
96110 + spinlock_t *ptl_m;
96111 + struct vm_area_struct *vma_m;
96112 + pmd_t *pmd_m;
96113 + pte_t *pte_m, entry_m;
96114 +
96115 + BUG_ON(!page_m || PageAnon(page_m));
96116 +
96117 + vma_m = pax_find_mirror_vma(vma);
96118 + if (!vma_m)
96119 + return;
96120 +
96121 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96122 + address_m = address + SEGMEXEC_TASK_SIZE;
96123 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96124 + pte_m = pte_offset_map(pmd_m, address_m);
96125 + ptl_m = pte_lockptr(mm, pmd_m);
96126 + if (ptl != ptl_m) {
96127 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96128 + if (!pte_none(*pte_m))
96129 + goto out;
96130 + }
96131 +
96132 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96133 + page_cache_get(page_m);
96134 + page_add_file_rmap(page_m);
96135 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96136 + set_pte_at(mm, address_m, pte_m, entry_m);
96137 + update_mmu_cache(vma_m, address_m, pte_m);
96138 +out:
96139 + if (ptl != ptl_m)
96140 + spin_unlock(ptl_m);
96141 + pte_unmap(pte_m);
96142 +}
96143 +
96144 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96145 +{
96146 + struct mm_struct *mm = vma->vm_mm;
96147 + unsigned long address_m;
96148 + spinlock_t *ptl_m;
96149 + struct vm_area_struct *vma_m;
96150 + pmd_t *pmd_m;
96151 + pte_t *pte_m, entry_m;
96152 +
96153 + vma_m = pax_find_mirror_vma(vma);
96154 + if (!vma_m)
96155 + return;
96156 +
96157 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96158 + address_m = address + SEGMEXEC_TASK_SIZE;
96159 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96160 + pte_m = pte_offset_map(pmd_m, address_m);
96161 + ptl_m = pte_lockptr(mm, pmd_m);
96162 + if (ptl != ptl_m) {
96163 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96164 + if (!pte_none(*pte_m))
96165 + goto out;
96166 + }
96167 +
96168 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96169 + set_pte_at(mm, address_m, pte_m, entry_m);
96170 +out:
96171 + if (ptl != ptl_m)
96172 + spin_unlock(ptl_m);
96173 + pte_unmap(pte_m);
96174 +}
96175 +
96176 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96177 +{
96178 + struct page *page_m;
96179 + pte_t entry;
96180 +
96181 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96182 + goto out;
96183 +
96184 + entry = *pte;
96185 + page_m = vm_normal_page(vma, address, entry);
96186 + if (!page_m)
96187 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96188 + else if (PageAnon(page_m)) {
96189 + if (pax_find_mirror_vma(vma)) {
96190 + pte_unmap_unlock(pte, ptl);
96191 + lock_page(page_m);
96192 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96193 + if (pte_same(entry, *pte))
96194 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96195 + else
96196 + unlock_page(page_m);
96197 + }
96198 + } else
96199 + pax_mirror_file_pte(vma, address, page_m, ptl);
96200 +
96201 +out:
96202 + pte_unmap_unlock(pte, ptl);
96203 +}
96204 +#endif
96205 +
96206 /*
96207 * This routine handles present pages, when users try to write
96208 * to a shared page. It is done by copying the page to a new address
96209 @@ -2225,6 +2432,12 @@ gotten:
96210 */
96211 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96212 if (likely(pte_same(*page_table, orig_pte))) {
96213 +
96214 +#ifdef CONFIG_PAX_SEGMEXEC
96215 + if (pax_find_mirror_vma(vma))
96216 + BUG_ON(!trylock_page(new_page));
96217 +#endif
96218 +
96219 if (old_page) {
96220 if (!PageAnon(old_page)) {
96221 dec_mm_counter_fast(mm, MM_FILEPAGES);
96222 @@ -2278,6 +2491,10 @@ gotten:
96223 page_remove_rmap(old_page);
96224 }
96225
96226 +#ifdef CONFIG_PAX_SEGMEXEC
96227 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96228 +#endif
96229 +
96230 /* Free the old page.. */
96231 new_page = old_page;
96232 ret |= VM_FAULT_WRITE;
96233 @@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96234 swap_free(entry);
96235 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96236 try_to_free_swap(page);
96237 +
96238 +#ifdef CONFIG_PAX_SEGMEXEC
96239 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96240 +#endif
96241 +
96242 unlock_page(page);
96243 if (page != swapcache) {
96244 /*
96245 @@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96246
96247 /* No need to invalidate - it was non-present before */
96248 update_mmu_cache(vma, address, page_table);
96249 +
96250 +#ifdef CONFIG_PAX_SEGMEXEC
96251 + pax_mirror_anon_pte(vma, address, page, ptl);
96252 +#endif
96253 +
96254 unlock:
96255 pte_unmap_unlock(page_table, ptl);
96256 out:
96257 @@ -2594,40 +2821,6 @@ out_release:
96258 }
96259
96260 /*
96261 - * This is like a special single-page "expand_{down|up}wards()",
96262 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96263 - * doesn't hit another vma.
96264 - */
96265 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96266 -{
96267 - address &= PAGE_MASK;
96268 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96269 - struct vm_area_struct *prev = vma->vm_prev;
96270 -
96271 - /*
96272 - * Is there a mapping abutting this one below?
96273 - *
96274 - * That's only ok if it's the same stack mapping
96275 - * that has gotten split..
96276 - */
96277 - if (prev && prev->vm_end == address)
96278 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96279 -
96280 - return expand_downwards(vma, address - PAGE_SIZE);
96281 - }
96282 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96283 - struct vm_area_struct *next = vma->vm_next;
96284 -
96285 - /* As VM_GROWSDOWN but s/below/above/ */
96286 - if (next && next->vm_start == address + PAGE_SIZE)
96287 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96288 -
96289 - return expand_upwards(vma, address + PAGE_SIZE);
96290 - }
96291 - return 0;
96292 -}
96293 -
96294 -/*
96295 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96296 * but allow concurrent faults), and pte mapped but not yet locked.
96297 * We return with mmap_sem still held, but pte unmapped and unlocked.
96298 @@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96299 unsigned int flags)
96300 {
96301 struct mem_cgroup *memcg;
96302 - struct page *page;
96303 + struct page *page = NULL;
96304 spinlock_t *ptl;
96305 pte_t entry;
96306
96307 - pte_unmap(page_table);
96308 -
96309 - /* Check if we need to add a guard page to the stack */
96310 - if (check_stack_guard_page(vma, address) < 0)
96311 - return VM_FAULT_SIGBUS;
96312 -
96313 - /* Use the zero-page for reads */
96314 if (!(flags & FAULT_FLAG_WRITE)) {
96315 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96316 vma->vm_page_prot));
96317 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96318 + ptl = pte_lockptr(mm, pmd);
96319 + spin_lock(ptl);
96320 if (!pte_none(*page_table))
96321 goto unlock;
96322 goto setpte;
96323 }
96324
96325 /* Allocate our own private page. */
96326 + pte_unmap(page_table);
96327 +
96328 if (unlikely(anon_vma_prepare(vma)))
96329 goto oom;
96330 page = alloc_zeroed_user_highpage_movable(vma, address);
96331 @@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96332 if (!pte_none(*page_table))
96333 goto release;
96334
96335 +#ifdef CONFIG_PAX_SEGMEXEC
96336 + if (pax_find_mirror_vma(vma))
96337 + BUG_ON(!trylock_page(page));
96338 +#endif
96339 +
96340 inc_mm_counter_fast(mm, MM_ANONPAGES);
96341 page_add_new_anon_rmap(page, vma, address);
96342 mem_cgroup_commit_charge(page, memcg, false);
96343 @@ -2690,6 +2884,12 @@ setpte:
96344
96345 /* No need to invalidate - it was non-present before */
96346 update_mmu_cache(vma, address, page_table);
96347 +
96348 +#ifdef CONFIG_PAX_SEGMEXEC
96349 + if (page)
96350 + pax_mirror_anon_pte(vma, address, page, ptl);
96351 +#endif
96352 +
96353 unlock:
96354 pte_unmap_unlock(page_table, ptl);
96355 return 0;
96356 @@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96357 return ret;
96358 }
96359 do_set_pte(vma, address, fault_page, pte, false, false);
96360 +
96361 +#ifdef CONFIG_PAX_SEGMEXEC
96362 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96363 +#endif
96364 +
96365 unlock_page(fault_page);
96366 unlock_out:
96367 pte_unmap_unlock(pte, ptl);
96368 @@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96369 page_cache_release(fault_page);
96370 goto uncharge_out;
96371 }
96372 +
96373 +#ifdef CONFIG_PAX_SEGMEXEC
96374 + if (pax_find_mirror_vma(vma))
96375 + BUG_ON(!trylock_page(new_page));
96376 +#endif
96377 +
96378 do_set_pte(vma, address, new_page, pte, true, true);
96379 +
96380 +#ifdef CONFIG_PAX_SEGMEXEC
96381 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96382 +#endif
96383 +
96384 mem_cgroup_commit_charge(new_page, memcg, false);
96385 lru_cache_add_active_or_unevictable(new_page, vma);
96386 pte_unmap_unlock(pte, ptl);
96387 @@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96388 return ret;
96389 }
96390 do_set_pte(vma, address, fault_page, pte, true, false);
96391 +
96392 +#ifdef CONFIG_PAX_SEGMEXEC
96393 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96394 +#endif
96395 +
96396 pte_unmap_unlock(pte, ptl);
96397
96398 if (set_page_dirty(fault_page))
96399 @@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96400 if (flags & FAULT_FLAG_WRITE)
96401 flush_tlb_fix_spurious_fault(vma, address);
96402 }
96403 +
96404 +#ifdef CONFIG_PAX_SEGMEXEC
96405 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96406 + return 0;
96407 +#endif
96408 +
96409 unlock:
96410 pte_unmap_unlock(pte, ptl);
96411 return 0;
96412 @@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96413 pmd_t *pmd;
96414 pte_t *pte;
96415
96416 +#ifdef CONFIG_PAX_SEGMEXEC
96417 + struct vm_area_struct *vma_m;
96418 +#endif
96419 +
96420 if (unlikely(is_vm_hugetlb_page(vma)))
96421 return hugetlb_fault(mm, vma, address, flags);
96422
96423 +#ifdef CONFIG_PAX_SEGMEXEC
96424 + vma_m = pax_find_mirror_vma(vma);
96425 + if (vma_m) {
96426 + unsigned long address_m;
96427 + pgd_t *pgd_m;
96428 + pud_t *pud_m;
96429 + pmd_t *pmd_m;
96430 +
96431 + if (vma->vm_start > vma_m->vm_start) {
96432 + address_m = address;
96433 + address -= SEGMEXEC_TASK_SIZE;
96434 + vma = vma_m;
96435 + } else
96436 + address_m = address + SEGMEXEC_TASK_SIZE;
96437 +
96438 + pgd_m = pgd_offset(mm, address_m);
96439 + pud_m = pud_alloc(mm, pgd_m, address_m);
96440 + if (!pud_m)
96441 + return VM_FAULT_OOM;
96442 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96443 + if (!pmd_m)
96444 + return VM_FAULT_OOM;
96445 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96446 + return VM_FAULT_OOM;
96447 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96448 + }
96449 +#endif
96450 +
96451 pgd = pgd_offset(mm, address);
96452 pud = pud_alloc(mm, pgd, address);
96453 if (!pud)
96454 @@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96455 spin_unlock(&mm->page_table_lock);
96456 return 0;
96457 }
96458 +
96459 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96460 +{
96461 + pud_t *new = pud_alloc_one(mm, address);
96462 + if (!new)
96463 + return -ENOMEM;
96464 +
96465 + smp_wmb(); /* See comment in __pte_alloc */
96466 +
96467 + spin_lock(&mm->page_table_lock);
96468 + if (pgd_present(*pgd)) /* Another has populated it */
96469 + pud_free(mm, new);
96470 + else
96471 + pgd_populate_kernel(mm, pgd, new);
96472 + spin_unlock(&mm->page_table_lock);
96473 + return 0;
96474 +}
96475 #endif /* __PAGETABLE_PUD_FOLDED */
96476
96477 #ifndef __PAGETABLE_PMD_FOLDED
96478 @@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96479 spin_unlock(&mm->page_table_lock);
96480 return 0;
96481 }
96482 +
96483 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96484 +{
96485 + pmd_t *new = pmd_alloc_one(mm, address);
96486 + if (!new)
96487 + return -ENOMEM;
96488 +
96489 + smp_wmb(); /* See comment in __pte_alloc */
96490 +
96491 + spin_lock(&mm->page_table_lock);
96492 +#ifndef __ARCH_HAS_4LEVEL_HACK
96493 + if (pud_present(*pud)) /* Another has populated it */
96494 + pmd_free(mm, new);
96495 + else
96496 + pud_populate_kernel(mm, pud, new);
96497 +#else
96498 + if (pgd_present(*pud)) /* Another has populated it */
96499 + pmd_free(mm, new);
96500 + else
96501 + pgd_populate_kernel(mm, pud, new);
96502 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96503 + spin_unlock(&mm->page_table_lock);
96504 + return 0;
96505 +}
96506 #endif /* __PAGETABLE_PMD_FOLDED */
96507
96508 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96509 @@ -3547,8 +3847,8 @@ out:
96510 return ret;
96511 }
96512
96513 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96514 - void *buf, int len, int write)
96515 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96516 + void *buf, size_t len, int write)
96517 {
96518 resource_size_t phys_addr;
96519 unsigned long prot = 0;
96520 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96521 * Access another process' address space as given in mm. If non-NULL, use the
96522 * given task for page fault accounting.
96523 */
96524 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96525 - unsigned long addr, void *buf, int len, int write)
96526 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96527 + unsigned long addr, void *buf, size_t len, int write)
96528 {
96529 struct vm_area_struct *vma;
96530 void *old_buf = buf;
96531 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96532 down_read(&mm->mmap_sem);
96533 /* ignore errors, just check how much was successfully transferred */
96534 while (len) {
96535 - int bytes, ret, offset;
96536 + ssize_t bytes, ret, offset;
96537 void *maddr;
96538 struct page *page = NULL;
96539
96540 @@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96541 *
96542 * The caller must hold a reference on @mm.
96543 */
96544 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96545 - void *buf, int len, int write)
96546 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96547 + void *buf, size_t len, int write)
96548 {
96549 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96550 }
96551 @@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96552 * Source/target buffer must be kernel space,
96553 * Do not walk the page table directly, use get_user_pages
96554 */
96555 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96556 - void *buf, int len, int write)
96557 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96558 + void *buf, size_t len, int write)
96559 {
96560 struct mm_struct *mm;
96561 - int ret;
96562 + ssize_t ret;
96563
96564 mm = get_task_mm(tsk);
96565 if (!mm)
96566 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96567 index e58725a..e0be017 100644
96568 --- a/mm/mempolicy.c
96569 +++ b/mm/mempolicy.c
96570 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96571 unsigned long vmstart;
96572 unsigned long vmend;
96573
96574 +#ifdef CONFIG_PAX_SEGMEXEC
96575 + struct vm_area_struct *vma_m;
96576 +#endif
96577 +
96578 vma = find_vma(mm, start);
96579 if (!vma || vma->vm_start > start)
96580 return -EFAULT;
96581 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96582 err = vma_replace_policy(vma, new_pol);
96583 if (err)
96584 goto out;
96585 +
96586 +#ifdef CONFIG_PAX_SEGMEXEC
96587 + vma_m = pax_find_mirror_vma(vma);
96588 + if (vma_m) {
96589 + err = vma_replace_policy(vma_m, new_pol);
96590 + if (err)
96591 + goto out;
96592 + }
96593 +#endif
96594 +
96595 }
96596
96597 out:
96598 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96599
96600 if (end < start)
96601 return -EINVAL;
96602 +
96603 +#ifdef CONFIG_PAX_SEGMEXEC
96604 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96605 + if (end > SEGMEXEC_TASK_SIZE)
96606 + return -EINVAL;
96607 + } else
96608 +#endif
96609 +
96610 + if (end > TASK_SIZE)
96611 + return -EINVAL;
96612 +
96613 if (end == start)
96614 return 0;
96615
96616 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96617 */
96618 tcred = __task_cred(task);
96619 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96620 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96621 - !capable(CAP_SYS_NICE)) {
96622 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96623 rcu_read_unlock();
96624 err = -EPERM;
96625 goto out_put;
96626 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96627 goto out;
96628 }
96629
96630 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96631 + if (mm != current->mm &&
96632 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96633 + mmput(mm);
96634 + err = -EPERM;
96635 + goto out;
96636 + }
96637 +#endif
96638 +
96639 err = do_migrate_pages(mm, old, new,
96640 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96641
96642 diff --git a/mm/migrate.c b/mm/migrate.c
96643 index 0143995..b294728 100644
96644 --- a/mm/migrate.c
96645 +++ b/mm/migrate.c
96646 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96647 */
96648 tcred = __task_cred(task);
96649 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96650 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96651 - !capable(CAP_SYS_NICE)) {
96652 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96653 rcu_read_unlock();
96654 err = -EPERM;
96655 goto out;
96656 diff --git a/mm/mlock.c b/mm/mlock.c
96657 index 73cf098..ab547c7 100644
96658 --- a/mm/mlock.c
96659 +++ b/mm/mlock.c
96660 @@ -14,6 +14,7 @@
96661 #include <linux/pagevec.h>
96662 #include <linux/mempolicy.h>
96663 #include <linux/syscalls.h>
96664 +#include <linux/security.h>
96665 #include <linux/sched.h>
96666 #include <linux/export.h>
96667 #include <linux/rmap.h>
96668 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96669 {
96670 unsigned long nstart, end, tmp;
96671 struct vm_area_struct * vma, * prev;
96672 - int error;
96673 + int error = 0;
96674
96675 VM_BUG_ON(start & ~PAGE_MASK);
96676 VM_BUG_ON(len != PAGE_ALIGN(len));
96677 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96678 return -EINVAL;
96679 if (end == start)
96680 return 0;
96681 + if (end > TASK_SIZE)
96682 + return -EINVAL;
96683 +
96684 vma = find_vma(current->mm, start);
96685 if (!vma || vma->vm_start > start)
96686 return -ENOMEM;
96687 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96688 for (nstart = start ; ; ) {
96689 vm_flags_t newflags;
96690
96691 +#ifdef CONFIG_PAX_SEGMEXEC
96692 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96693 + break;
96694 +#endif
96695 +
96696 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96697
96698 newflags = vma->vm_flags & ~VM_LOCKED;
96699 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96700 locked += current->mm->locked_vm;
96701
96702 /* check against resource limits */
96703 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96704 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96705 error = do_mlock(start, len, 1);
96706
96707 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96708 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96709 vm_flags_t newflags;
96710
96711 +#ifdef CONFIG_PAX_SEGMEXEC
96712 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96713 + break;
96714 +#endif
96715 +
96716 newflags = vma->vm_flags & ~VM_LOCKED;
96717 if (flags & MCL_CURRENT)
96718 newflags |= VM_LOCKED;
96719 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96720 lock_limit >>= PAGE_SHIFT;
96721
96722 ret = -ENOMEM;
96723 +
96724 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96725 +
96726 down_write(&current->mm->mmap_sem);
96727 -
96728 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96729 capable(CAP_IPC_LOCK))
96730 ret = do_mlockall(flags);
96731 diff --git a/mm/mmap.c b/mm/mmap.c
96732 index 1620adb..348da48 100644
96733 --- a/mm/mmap.c
96734 +++ b/mm/mmap.c
96735 @@ -41,6 +41,7 @@
96736 #include <linux/notifier.h>
96737 #include <linux/memory.h>
96738 #include <linux/printk.h>
96739 +#include <linux/random.h>
96740
96741 #include <asm/uaccess.h>
96742 #include <asm/cacheflush.h>
96743 @@ -57,6 +58,16 @@
96744 #define arch_rebalance_pgtables(addr, len) (addr)
96745 #endif
96746
96747 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96748 +{
96749 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96750 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96751 + up_read(&mm->mmap_sem);
96752 + BUG();
96753 + }
96754 +#endif
96755 +}
96756 +
96757 static void unmap_region(struct mm_struct *mm,
96758 struct vm_area_struct *vma, struct vm_area_struct *prev,
96759 unsigned long start, unsigned long end);
96760 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96761 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96762 *
96763 */
96764 -pgprot_t protection_map[16] = {
96765 +pgprot_t protection_map[16] __read_only = {
96766 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96767 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96768 };
96769
96770 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96771 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96772 {
96773 - return __pgprot(pgprot_val(protection_map[vm_flags &
96774 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96775 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96776 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96777 +
96778 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96779 + if (!(__supported_pte_mask & _PAGE_NX) &&
96780 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96781 + (vm_flags & (VM_READ | VM_WRITE)))
96782 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96783 +#endif
96784 +
96785 + return prot;
96786 }
96787 EXPORT_SYMBOL(vm_get_page_prot);
96788
96789 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96790 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96791 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96792 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96793 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96794 /*
96795 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96796 * other variables. It can be updated by several CPUs frequently.
96797 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96798 struct vm_area_struct *next = vma->vm_next;
96799
96800 might_sleep();
96801 + BUG_ON(vma->vm_mirror);
96802 if (vma->vm_ops && vma->vm_ops->close)
96803 vma->vm_ops->close(vma);
96804 if (vma->vm_file)
96805 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96806
96807 SYSCALL_DEFINE1(brk, unsigned long, brk)
96808 {
96809 + unsigned long rlim;
96810 unsigned long retval;
96811 unsigned long newbrk, oldbrk;
96812 struct mm_struct *mm = current->mm;
96813 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96814 * segment grow beyond its set limit the in case where the limit is
96815 * not page aligned -Ram Gupta
96816 */
96817 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
96818 + rlim = rlimit(RLIMIT_DATA);
96819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96820 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
96821 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96822 + rlim = 4096 * PAGE_SIZE;
96823 +#endif
96824 + if (check_data_rlimit(rlim, brk, mm->start_brk,
96825 mm->end_data, mm->start_data))
96826 goto out;
96827
96828 @@ -976,6 +1005,12 @@ static int
96829 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96830 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96831 {
96832 +
96833 +#ifdef CONFIG_PAX_SEGMEXEC
96834 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96835 + return 0;
96836 +#endif
96837 +
96838 if (is_mergeable_vma(vma, file, vm_flags) &&
96839 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96840 if (vma->vm_pgoff == vm_pgoff)
96841 @@ -995,6 +1030,12 @@ static int
96842 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96843 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96844 {
96845 +
96846 +#ifdef CONFIG_PAX_SEGMEXEC
96847 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96848 + return 0;
96849 +#endif
96850 +
96851 if (is_mergeable_vma(vma, file, vm_flags) &&
96852 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96853 pgoff_t vm_pglen;
96854 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96855 struct vm_area_struct *area, *next;
96856 int err;
96857
96858 +#ifdef CONFIG_PAX_SEGMEXEC
96859 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96860 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96861 +
96862 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96863 +#endif
96864 +
96865 /*
96866 * We later require that vma->vm_flags == vm_flags,
96867 * so this tests vma->vm_flags & VM_SPECIAL, too.
96868 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96869 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96870 next = next->vm_next;
96871
96872 +#ifdef CONFIG_PAX_SEGMEXEC
96873 + if (prev)
96874 + prev_m = pax_find_mirror_vma(prev);
96875 + if (area)
96876 + area_m = pax_find_mirror_vma(area);
96877 + if (next)
96878 + next_m = pax_find_mirror_vma(next);
96879 +#endif
96880 +
96881 /*
96882 * Can it merge with the predecessor?
96883 */
96884 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96885 /* cases 1, 6 */
96886 err = vma_adjust(prev, prev->vm_start,
96887 next->vm_end, prev->vm_pgoff, NULL);
96888 - } else /* cases 2, 5, 7 */
96889 +
96890 +#ifdef CONFIG_PAX_SEGMEXEC
96891 + if (!err && prev_m)
96892 + err = vma_adjust(prev_m, prev_m->vm_start,
96893 + next_m->vm_end, prev_m->vm_pgoff, NULL);
96894 +#endif
96895 +
96896 + } else { /* cases 2, 5, 7 */
96897 err = vma_adjust(prev, prev->vm_start,
96898 end, prev->vm_pgoff, NULL);
96899 +
96900 +#ifdef CONFIG_PAX_SEGMEXEC
96901 + if (!err && prev_m)
96902 + err = vma_adjust(prev_m, prev_m->vm_start,
96903 + end_m, prev_m->vm_pgoff, NULL);
96904 +#endif
96905 +
96906 + }
96907 if (err)
96908 return NULL;
96909 khugepaged_enter_vma_merge(prev, vm_flags);
96910 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96911 mpol_equal(policy, vma_policy(next)) &&
96912 can_vma_merge_before(next, vm_flags,
96913 anon_vma, file, pgoff+pglen)) {
96914 - if (prev && addr < prev->vm_end) /* case 4 */
96915 + if (prev && addr < prev->vm_end) { /* case 4 */
96916 err = vma_adjust(prev, prev->vm_start,
96917 addr, prev->vm_pgoff, NULL);
96918 - else /* cases 3, 8 */
96919 +
96920 +#ifdef CONFIG_PAX_SEGMEXEC
96921 + if (!err && prev_m)
96922 + err = vma_adjust(prev_m, prev_m->vm_start,
96923 + addr_m, prev_m->vm_pgoff, NULL);
96924 +#endif
96925 +
96926 + } else { /* cases 3, 8 */
96927 err = vma_adjust(area, addr, next->vm_end,
96928 next->vm_pgoff - pglen, NULL);
96929 +
96930 +#ifdef CONFIG_PAX_SEGMEXEC
96931 + if (!err && area_m)
96932 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
96933 + next_m->vm_pgoff - pglen, NULL);
96934 +#endif
96935 +
96936 + }
96937 if (err)
96938 return NULL;
96939 khugepaged_enter_vma_merge(area, vm_flags);
96940 @@ -1208,8 +1295,10 @@ none:
96941 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96942 struct file *file, long pages)
96943 {
96944 - const unsigned long stack_flags
96945 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96946 +
96947 +#ifdef CONFIG_PAX_RANDMMAP
96948 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96949 +#endif
96950
96951 mm->total_vm += pages;
96952
96953 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96954 mm->shared_vm += pages;
96955 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96956 mm->exec_vm += pages;
96957 - } else if (flags & stack_flags)
96958 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96959 mm->stack_vm += pages;
96960 }
96961 #endif /* CONFIG_PROC_FS */
96962 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96963 locked += mm->locked_vm;
96964 lock_limit = rlimit(RLIMIT_MEMLOCK);
96965 lock_limit >>= PAGE_SHIFT;
96966 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96967 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96968 return -EAGAIN;
96969 }
96970 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96971 * (the exception is when the underlying filesystem is noexec
96972 * mounted, in which case we dont add PROT_EXEC.)
96973 */
96974 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96975 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96976 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96977 prot |= PROT_EXEC;
96978
96979 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96980 /* Obtain the address to map to. we verify (or select) it and ensure
96981 * that it represents a valid section of the address space.
96982 */
96983 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
96984 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96985 if (addr & ~PAGE_MASK)
96986 return addr;
96987
96988 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96989 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96990 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96991
96992 +#ifdef CONFIG_PAX_MPROTECT
96993 + if (mm->pax_flags & MF_PAX_MPROTECT) {
96994 +
96995 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96996 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96997 + mm->binfmt->handle_mmap)
96998 + mm->binfmt->handle_mmap(file);
96999 +#endif
97000 +
97001 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97002 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97003 + gr_log_rwxmmap(file);
97004 +
97005 +#ifdef CONFIG_PAX_EMUPLT
97006 + vm_flags &= ~VM_EXEC;
97007 +#else
97008 + return -EPERM;
97009 +#endif
97010 +
97011 + }
97012 +
97013 + if (!(vm_flags & VM_EXEC))
97014 + vm_flags &= ~VM_MAYEXEC;
97015 +#else
97016 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97017 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97018 +#endif
97019 + else
97020 + vm_flags &= ~VM_MAYWRITE;
97021 + }
97022 +#endif
97023 +
97024 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97025 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97026 + vm_flags &= ~VM_PAGEEXEC;
97027 +#endif
97028 +
97029 if (flags & MAP_LOCKED)
97030 if (!can_do_mlock())
97031 return -EPERM;
97032 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97033 vm_flags |= VM_NORESERVE;
97034 }
97035
97036 + if (!gr_acl_handle_mmap(file, prot))
97037 + return -EACCES;
97038 +
97039 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97040 if (!IS_ERR_VALUE(addr) &&
97041 ((vm_flags & VM_LOCKED) ||
97042 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97043 vm_flags_t vm_flags = vma->vm_flags;
97044
97045 /* If it was private or non-writable, the write bit is already clear */
97046 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97047 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97048 return 0;
97049
97050 /* The backer wishes to know when pages are first written to? */
97051 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97052 struct rb_node **rb_link, *rb_parent;
97053 unsigned long charged = 0;
97054
97055 +#ifdef CONFIG_PAX_SEGMEXEC
97056 + struct vm_area_struct *vma_m = NULL;
97057 +#endif
97058 +
97059 + /*
97060 + * mm->mmap_sem is required to protect against another thread
97061 + * changing the mappings in case we sleep.
97062 + */
97063 + verify_mm_writelocked(mm);
97064 +
97065 /* Check against address space limit. */
97066 +
97067 +#ifdef CONFIG_PAX_RANDMMAP
97068 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97069 +#endif
97070 +
97071 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97072 unsigned long nr_pages;
97073
97074 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97075
97076 /* Clear old maps */
97077 error = -ENOMEM;
97078 -munmap_back:
97079 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97080 if (do_munmap(mm, addr, len))
97081 return -ENOMEM;
97082 - goto munmap_back;
97083 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97084 }
97085
97086 /*
97087 @@ -1595,6 +1739,16 @@ munmap_back:
97088 goto unacct_error;
97089 }
97090
97091 +#ifdef CONFIG_PAX_SEGMEXEC
97092 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97093 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97094 + if (!vma_m) {
97095 + error = -ENOMEM;
97096 + goto free_vma;
97097 + }
97098 + }
97099 +#endif
97100 +
97101 vma->vm_mm = mm;
97102 vma->vm_start = addr;
97103 vma->vm_end = addr + len;
97104 @@ -1625,6 +1779,13 @@ munmap_back:
97105 if (error)
97106 goto unmap_and_free_vma;
97107
97108 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97109 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97110 + vma->vm_flags |= VM_PAGEEXEC;
97111 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97112 + }
97113 +#endif
97114 +
97115 /* Can addr have changed??
97116 *
97117 * Answer: Yes, several device drivers can do it in their
97118 @@ -1643,6 +1804,12 @@ munmap_back:
97119 }
97120
97121 vma_link(mm, vma, prev, rb_link, rb_parent);
97122 +
97123 +#ifdef CONFIG_PAX_SEGMEXEC
97124 + if (vma_m)
97125 + BUG_ON(pax_mirror_vma(vma_m, vma));
97126 +#endif
97127 +
97128 /* Once vma denies write, undo our temporary denial count */
97129 if (file) {
97130 if (vm_flags & VM_SHARED)
97131 @@ -1655,6 +1822,7 @@ out:
97132 perf_event_mmap(vma);
97133
97134 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97135 + track_exec_limit(mm, addr, addr + len, vm_flags);
97136 if (vm_flags & VM_LOCKED) {
97137 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97138 vma == get_gate_vma(current->mm)))
97139 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97140 if (vm_flags & VM_DENYWRITE)
97141 allow_write_access(file);
97142 free_vma:
97143 +
97144 +#ifdef CONFIG_PAX_SEGMEXEC
97145 + if (vma_m)
97146 + kmem_cache_free(vm_area_cachep, vma_m);
97147 +#endif
97148 +
97149 kmem_cache_free(vm_area_cachep, vma);
97150 unacct_error:
97151 if (charged)
97152 @@ -1699,7 +1873,63 @@ unacct_error:
97153 return error;
97154 }
97155
97156 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97157 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97158 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97159 +{
97160 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97161 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97162 +
97163 + return 0;
97164 +}
97165 +#endif
97166 +
97167 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97168 +{
97169 + if (!vma) {
97170 +#ifdef CONFIG_STACK_GROWSUP
97171 + if (addr > sysctl_heap_stack_gap)
97172 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97173 + else
97174 + vma = find_vma(current->mm, 0);
97175 + if (vma && (vma->vm_flags & VM_GROWSUP))
97176 + return false;
97177 +#endif
97178 + return true;
97179 + }
97180 +
97181 + if (addr + len > vma->vm_start)
97182 + return false;
97183 +
97184 + if (vma->vm_flags & VM_GROWSDOWN)
97185 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97186 +#ifdef CONFIG_STACK_GROWSUP
97187 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97188 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97189 +#endif
97190 + else if (offset)
97191 + return offset <= vma->vm_start - addr - len;
97192 +
97193 + return true;
97194 +}
97195 +
97196 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97197 +{
97198 + if (vma->vm_start < len)
97199 + return -ENOMEM;
97200 +
97201 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97202 + if (offset <= vma->vm_start - len)
97203 + return vma->vm_start - len - offset;
97204 + else
97205 + return -ENOMEM;
97206 + }
97207 +
97208 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97209 + return vma->vm_start - len - sysctl_heap_stack_gap;
97210 + return -ENOMEM;
97211 +}
97212 +
97213 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97214 {
97215 /*
97216 * We implement the search by looking for an rbtree node that
97217 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97218 }
97219 }
97220
97221 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97222 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97223 check_current:
97224 /* Check if current node has a suitable gap */
97225 if (gap_start > high_limit)
97226 return -ENOMEM;
97227 +
97228 + if (gap_end - gap_start > info->threadstack_offset)
97229 + gap_start += info->threadstack_offset;
97230 + else
97231 + gap_start = gap_end;
97232 +
97233 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97234 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97235 + gap_start += sysctl_heap_stack_gap;
97236 + else
97237 + gap_start = gap_end;
97238 + }
97239 + if (vma->vm_flags & VM_GROWSDOWN) {
97240 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97241 + gap_end -= sysctl_heap_stack_gap;
97242 + else
97243 + gap_end = gap_start;
97244 + }
97245 if (gap_end >= low_limit && gap_end - gap_start >= length)
97246 goto found;
97247
97248 @@ -1801,7 +2049,7 @@ found:
97249 return gap_start;
97250 }
97251
97252 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97253 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97254 {
97255 struct mm_struct *mm = current->mm;
97256 struct vm_area_struct *vma;
97257 @@ -1855,6 +2103,24 @@ check_current:
97258 gap_end = vma->vm_start;
97259 if (gap_end < low_limit)
97260 return -ENOMEM;
97261 +
97262 + if (gap_end - gap_start > info->threadstack_offset)
97263 + gap_end -= info->threadstack_offset;
97264 + else
97265 + gap_end = gap_start;
97266 +
97267 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97268 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97269 + gap_start += sysctl_heap_stack_gap;
97270 + else
97271 + gap_start = gap_end;
97272 + }
97273 + if (vma->vm_flags & VM_GROWSDOWN) {
97274 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97275 + gap_end -= sysctl_heap_stack_gap;
97276 + else
97277 + gap_end = gap_start;
97278 + }
97279 if (gap_start <= high_limit && gap_end - gap_start >= length)
97280 goto found;
97281
97282 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97283 struct mm_struct *mm = current->mm;
97284 struct vm_area_struct *vma;
97285 struct vm_unmapped_area_info info;
97286 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97287
97288 if (len > TASK_SIZE - mmap_min_addr)
97289 return -ENOMEM;
97290 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97291 if (flags & MAP_FIXED)
97292 return addr;
97293
97294 +#ifdef CONFIG_PAX_RANDMMAP
97295 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97296 +#endif
97297 +
97298 if (addr) {
97299 addr = PAGE_ALIGN(addr);
97300 vma = find_vma(mm, addr);
97301 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97302 - (!vma || addr + len <= vma->vm_start))
97303 + check_heap_stack_gap(vma, addr, len, offset))
97304 return addr;
97305 }
97306
97307 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97308 info.low_limit = mm->mmap_base;
97309 info.high_limit = TASK_SIZE;
97310 info.align_mask = 0;
97311 + info.threadstack_offset = offset;
97312 return vm_unmapped_area(&info);
97313 }
97314 #endif
97315 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97316 struct mm_struct *mm = current->mm;
97317 unsigned long addr = addr0;
97318 struct vm_unmapped_area_info info;
97319 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97320
97321 /* requested length too big for entire address space */
97322 if (len > TASK_SIZE - mmap_min_addr)
97323 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97324 if (flags & MAP_FIXED)
97325 return addr;
97326
97327 +#ifdef CONFIG_PAX_RANDMMAP
97328 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97329 +#endif
97330 +
97331 /* requesting a specific address */
97332 if (addr) {
97333 addr = PAGE_ALIGN(addr);
97334 vma = find_vma(mm, addr);
97335 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97336 - (!vma || addr + len <= vma->vm_start))
97337 + check_heap_stack_gap(vma, addr, len, offset))
97338 return addr;
97339 }
97340
97341 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97342 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97343 info.high_limit = mm->mmap_base;
97344 info.align_mask = 0;
97345 + info.threadstack_offset = offset;
97346 addr = vm_unmapped_area(&info);
97347
97348 /*
97349 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97350 VM_BUG_ON(addr != -ENOMEM);
97351 info.flags = 0;
97352 info.low_limit = TASK_UNMAPPED_BASE;
97353 +
97354 +#ifdef CONFIG_PAX_RANDMMAP
97355 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97356 + info.low_limit += mm->delta_mmap;
97357 +#endif
97358 +
97359 info.high_limit = TASK_SIZE;
97360 addr = vm_unmapped_area(&info);
97361 }
97362 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97363 return vma;
97364 }
97365
97366 +#ifdef CONFIG_PAX_SEGMEXEC
97367 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97368 +{
97369 + struct vm_area_struct *vma_m;
97370 +
97371 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97372 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97373 + BUG_ON(vma->vm_mirror);
97374 + return NULL;
97375 + }
97376 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97377 + vma_m = vma->vm_mirror;
97378 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97379 + BUG_ON(vma->vm_file != vma_m->vm_file);
97380 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97381 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97382 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97383 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97384 + return vma_m;
97385 +}
97386 +#endif
97387 +
97388 /*
97389 * Verify that the stack growth is acceptable and
97390 * update accounting. This is shared with both the
97391 @@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97392
97393 /* Stack limit test */
97394 actual_size = size;
97395 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
97396 - actual_size -= PAGE_SIZE;
97397 + gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
97398 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97399 return -ENOMEM;
97400
97401 @@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97402 locked = mm->locked_vm + grow;
97403 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97404 limit >>= PAGE_SHIFT;
97405 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97406 if (locked > limit && !capable(CAP_IPC_LOCK))
97407 return -ENOMEM;
97408 }
97409 @@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97410 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97411 * vma is the last one with address > vma->vm_end. Have to extend vma.
97412 */
97413 +#ifndef CONFIG_IA64
97414 +static
97415 +#endif
97416 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97417 {
97418 int error;
97419 + bool locknext;
97420
97421 if (!(vma->vm_flags & VM_GROWSUP))
97422 return -EFAULT;
97423
97424 + /* Also guard against wrapping around to address 0. */
97425 + if (address < PAGE_ALIGN(address+1))
97426 + address = PAGE_ALIGN(address+1);
97427 + else
97428 + return -ENOMEM;
97429 +
97430 /*
97431 * We must make sure the anon_vma is allocated
97432 * so that the anon_vma locking is not a noop.
97433 */
97434 if (unlikely(anon_vma_prepare(vma)))
97435 return -ENOMEM;
97436 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97437 + if (locknext && anon_vma_prepare(vma->vm_next))
97438 + return -ENOMEM;
97439 vma_lock_anon_vma(vma);
97440 + if (locknext)
97441 + vma_lock_anon_vma(vma->vm_next);
97442
97443 /*
97444 * vma->vm_start/vm_end cannot change under us because the caller
97445 * is required to hold the mmap_sem in read mode. We need the
97446 - * anon_vma lock to serialize against concurrent expand_stacks.
97447 - * Also guard against wrapping around to address 0.
97448 + * anon_vma locks to serialize against concurrent expand_stacks
97449 + * and expand_upwards.
97450 */
97451 - if (address < PAGE_ALIGN(address+4))
97452 - address = PAGE_ALIGN(address+4);
97453 - else {
97454 - vma_unlock_anon_vma(vma);
97455 - return -ENOMEM;
97456 - }
97457 error = 0;
97458
97459 /* Somebody else might have raced and expanded it already */
97460 - if (address > vma->vm_end) {
97461 + 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)
97462 + error = -ENOMEM;
97463 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97464 unsigned long size, grow;
97465
97466 size = address - vma->vm_start;
97467 @@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97468 }
97469 }
97470 }
97471 + if (locknext)
97472 + vma_unlock_anon_vma(vma->vm_next);
97473 vma_unlock_anon_vma(vma);
97474 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97475 validate_mm(vma->vm_mm);
97476 @@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97477 unsigned long address)
97478 {
97479 int error;
97480 + bool lockprev = false;
97481 + struct vm_area_struct *prev;
97482
97483 /*
97484 * We must make sure the anon_vma is allocated
97485 @@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97486 if (error)
97487 return error;
97488
97489 + prev = vma->vm_prev;
97490 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97491 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97492 +#endif
97493 + if (lockprev && anon_vma_prepare(prev))
97494 + return -ENOMEM;
97495 + if (lockprev)
97496 + vma_lock_anon_vma(prev);
97497 +
97498 vma_lock_anon_vma(vma);
97499
97500 /*
97501 @@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97502 */
97503
97504 /* Somebody else might have raced and expanded it already */
97505 - if (address < vma->vm_start) {
97506 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97507 + error = -ENOMEM;
97508 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97509 unsigned long size, grow;
97510
97511 +#ifdef CONFIG_PAX_SEGMEXEC
97512 + struct vm_area_struct *vma_m;
97513 +
97514 + vma_m = pax_find_mirror_vma(vma);
97515 +#endif
97516 +
97517 size = vma->vm_end - address;
97518 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97519
97520 @@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97521 vma->vm_pgoff -= grow;
97522 anon_vma_interval_tree_post_update_vma(vma);
97523 vma_gap_update(vma);
97524 +
97525 +#ifdef CONFIG_PAX_SEGMEXEC
97526 + if (vma_m) {
97527 + anon_vma_interval_tree_pre_update_vma(vma_m);
97528 + vma_m->vm_start -= grow << PAGE_SHIFT;
97529 + vma_m->vm_pgoff -= grow;
97530 + anon_vma_interval_tree_post_update_vma(vma_m);
97531 + vma_gap_update(vma_m);
97532 + }
97533 +#endif
97534 +
97535 spin_unlock(&vma->vm_mm->page_table_lock);
97536
97537 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97538 perf_event_mmap(vma);
97539 }
97540 }
97541 }
97542 vma_unlock_anon_vma(vma);
97543 + if (lockprev)
97544 + vma_unlock_anon_vma(prev);
97545 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97546 validate_mm(vma->vm_mm);
97547 return error;
97548 @@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97549 do {
97550 long nrpages = vma_pages(vma);
97551
97552 +#ifdef CONFIG_PAX_SEGMEXEC
97553 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97554 + vma = remove_vma(vma);
97555 + continue;
97556 + }
97557 +#endif
97558 +
97559 if (vma->vm_flags & VM_ACCOUNT)
97560 nr_accounted += nrpages;
97561 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97562 @@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97563 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97564 vma->vm_prev = NULL;
97565 do {
97566 +
97567 +#ifdef CONFIG_PAX_SEGMEXEC
97568 + if (vma->vm_mirror) {
97569 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97570 + vma->vm_mirror->vm_mirror = NULL;
97571 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97572 + vma->vm_mirror = NULL;
97573 + }
97574 +#endif
97575 +
97576 vma_rb_erase(vma, &mm->mm_rb);
97577 mm->map_count--;
97578 tail_vma = vma;
97579 @@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97580 struct vm_area_struct *new;
97581 int err = -ENOMEM;
97582
97583 +#ifdef CONFIG_PAX_SEGMEXEC
97584 + struct vm_area_struct *vma_m, *new_m = NULL;
97585 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97586 +#endif
97587 +
97588 if (is_vm_hugetlb_page(vma) && (addr &
97589 ~(huge_page_mask(hstate_vma(vma)))))
97590 return -EINVAL;
97591
97592 +#ifdef CONFIG_PAX_SEGMEXEC
97593 + vma_m = pax_find_mirror_vma(vma);
97594 +#endif
97595 +
97596 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97597 if (!new)
97598 goto out_err;
97599
97600 +#ifdef CONFIG_PAX_SEGMEXEC
97601 + if (vma_m) {
97602 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97603 + if (!new_m) {
97604 + kmem_cache_free(vm_area_cachep, new);
97605 + goto out_err;
97606 + }
97607 + }
97608 +#endif
97609 +
97610 /* most fields are the same, copy all, and then fixup */
97611 *new = *vma;
97612
97613 @@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97614 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97615 }
97616
97617 +#ifdef CONFIG_PAX_SEGMEXEC
97618 + if (vma_m) {
97619 + *new_m = *vma_m;
97620 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97621 + new_m->vm_mirror = new;
97622 + new->vm_mirror = new_m;
97623 +
97624 + if (new_below)
97625 + new_m->vm_end = addr_m;
97626 + else {
97627 + new_m->vm_start = addr_m;
97628 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97629 + }
97630 + }
97631 +#endif
97632 +
97633 err = vma_dup_policy(vma, new);
97634 if (err)
97635 goto out_free_vma;
97636 @@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97637 else
97638 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97639
97640 +#ifdef CONFIG_PAX_SEGMEXEC
97641 + if (!err && vma_m) {
97642 + struct mempolicy *pol = vma_policy(new);
97643 +
97644 + if (anon_vma_clone(new_m, vma_m))
97645 + goto out_free_mpol;
97646 +
97647 + mpol_get(pol);
97648 + set_vma_policy(new_m, pol);
97649 +
97650 + if (new_m->vm_file)
97651 + get_file(new_m->vm_file);
97652 +
97653 + if (new_m->vm_ops && new_m->vm_ops->open)
97654 + new_m->vm_ops->open(new_m);
97655 +
97656 + if (new_below)
97657 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97658 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97659 + else
97660 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97661 +
97662 + if (err) {
97663 + if (new_m->vm_ops && new_m->vm_ops->close)
97664 + new_m->vm_ops->close(new_m);
97665 + if (new_m->vm_file)
97666 + fput(new_m->vm_file);
97667 + mpol_put(pol);
97668 + }
97669 + }
97670 +#endif
97671 +
97672 /* Success. */
97673 if (!err)
97674 return 0;
97675 @@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97676 new->vm_ops->close(new);
97677 if (new->vm_file)
97678 fput(new->vm_file);
97679 - unlink_anon_vmas(new);
97680 out_free_mpol:
97681 mpol_put(vma_policy(new));
97682 out_free_vma:
97683 +
97684 +#ifdef CONFIG_PAX_SEGMEXEC
97685 + if (new_m) {
97686 + unlink_anon_vmas(new_m);
97687 + kmem_cache_free(vm_area_cachep, new_m);
97688 + }
97689 +#endif
97690 +
97691 + unlink_anon_vmas(new);
97692 kmem_cache_free(vm_area_cachep, new);
97693 out_err:
97694 return err;
97695 @@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97696 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97697 unsigned long addr, int new_below)
97698 {
97699 +
97700 +#ifdef CONFIG_PAX_SEGMEXEC
97701 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97702 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97703 + if (mm->map_count >= sysctl_max_map_count-1)
97704 + return -ENOMEM;
97705 + } else
97706 +#endif
97707 +
97708 if (mm->map_count >= sysctl_max_map_count)
97709 return -ENOMEM;
97710
97711 @@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97712 * work. This now handles partial unmappings.
97713 * Jeremy Fitzhardinge <jeremy@goop.org>
97714 */
97715 +#ifdef CONFIG_PAX_SEGMEXEC
97716 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97717 {
97718 + int ret = __do_munmap(mm, start, len);
97719 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97720 + return ret;
97721 +
97722 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97723 +}
97724 +
97725 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97726 +#else
97727 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97728 +#endif
97729 +{
97730 unsigned long end;
97731 struct vm_area_struct *vma, *prev, *last;
97732
97733 + /*
97734 + * mm->mmap_sem is required to protect against another thread
97735 + * changing the mappings in case we sleep.
97736 + */
97737 + verify_mm_writelocked(mm);
97738 +
97739 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97740 return -EINVAL;
97741
97742 @@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97743 /* Fix up all other VM information */
97744 remove_vma_list(mm, vma);
97745
97746 + track_exec_limit(mm, start, end, 0UL);
97747 +
97748 return 0;
97749 }
97750
97751 @@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
97752 int ret;
97753 struct mm_struct *mm = current->mm;
97754
97755 +
97756 +#ifdef CONFIG_PAX_SEGMEXEC
97757 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97758 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97759 + return -EINVAL;
97760 +#endif
97761 +
97762 down_write(&mm->mmap_sem);
97763 ret = do_munmap(mm, start, len);
97764 up_write(&mm->mmap_sem);
97765 @@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97766 return vm_munmap(addr, len);
97767 }
97768
97769 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97770 -{
97771 -#ifdef CONFIG_DEBUG_VM
97772 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97773 - WARN_ON(1);
97774 - up_read(&mm->mmap_sem);
97775 - }
97776 -#endif
97777 -}
97778 -
97779 /*
97780 * this is really a simplified "do_mmap". it only handles
97781 * anonymous maps. eventually we may be able to do some
97782 @@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97783 struct rb_node **rb_link, *rb_parent;
97784 pgoff_t pgoff = addr >> PAGE_SHIFT;
97785 int error;
97786 + unsigned long charged;
97787
97788 len = PAGE_ALIGN(len);
97789 if (!len)
97790 @@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97791
97792 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97793
97794 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97795 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97796 + flags &= ~VM_EXEC;
97797 +
97798 +#ifdef CONFIG_PAX_MPROTECT
97799 + if (mm->pax_flags & MF_PAX_MPROTECT)
97800 + flags &= ~VM_MAYEXEC;
97801 +#endif
97802 +
97803 + }
97804 +#endif
97805 +
97806 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97807 if (error & ~PAGE_MASK)
97808 return error;
97809
97810 + charged = len >> PAGE_SHIFT;
97811 +
97812 error = mlock_future_check(mm, mm->def_flags, len);
97813 if (error)
97814 return error;
97815 @@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97816 /*
97817 * Clear old maps. this also does some error checking for us
97818 */
97819 - munmap_back:
97820 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97821 if (do_munmap(mm, addr, len))
97822 return -ENOMEM;
97823 - goto munmap_back;
97824 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97825 }
97826
97827 /* Check against address space limits *after* clearing old maps... */
97828 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97829 + if (!may_expand_vm(mm, charged))
97830 return -ENOMEM;
97831
97832 if (mm->map_count > sysctl_max_map_count)
97833 return -ENOMEM;
97834
97835 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97836 + if (security_vm_enough_memory_mm(mm, charged))
97837 return -ENOMEM;
97838
97839 /* Can we just expand an old private anonymous mapping? */
97840 @@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97841 */
97842 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97843 if (!vma) {
97844 - vm_unacct_memory(len >> PAGE_SHIFT);
97845 + vm_unacct_memory(charged);
97846 return -ENOMEM;
97847 }
97848
97849 @@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97850 vma_link(mm, vma, prev, rb_link, rb_parent);
97851 out:
97852 perf_event_mmap(vma);
97853 - mm->total_vm += len >> PAGE_SHIFT;
97854 + mm->total_vm += charged;
97855 if (flags & VM_LOCKED)
97856 - mm->locked_vm += (len >> PAGE_SHIFT);
97857 + mm->locked_vm += charged;
97858 vma->vm_flags |= VM_SOFTDIRTY;
97859 + track_exec_limit(mm, addr, addr + len, flags);
97860 return addr;
97861 }
97862
97863 @@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
97864 while (vma) {
97865 if (vma->vm_flags & VM_ACCOUNT)
97866 nr_accounted += vma_pages(vma);
97867 + vma->vm_mirror = NULL;
97868 vma = remove_vma(vma);
97869 }
97870 vm_unacct_memory(nr_accounted);
97871 @@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97872 struct vm_area_struct *prev;
97873 struct rb_node **rb_link, *rb_parent;
97874
97875 +#ifdef CONFIG_PAX_SEGMEXEC
97876 + struct vm_area_struct *vma_m = NULL;
97877 +#endif
97878 +
97879 + if (security_mmap_addr(vma->vm_start))
97880 + return -EPERM;
97881 +
97882 /*
97883 * The vm_pgoff of a purely anonymous vma should be irrelevant
97884 * until its first write fault, when page's anon_vma and index
97885 @@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97886 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97887 return -ENOMEM;
97888
97889 +#ifdef CONFIG_PAX_SEGMEXEC
97890 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97891 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97892 + if (!vma_m)
97893 + return -ENOMEM;
97894 + }
97895 +#endif
97896 +
97897 vma_link(mm, vma, prev, rb_link, rb_parent);
97898 +
97899 +#ifdef CONFIG_PAX_SEGMEXEC
97900 + if (vma_m)
97901 + BUG_ON(pax_mirror_vma(vma_m, vma));
97902 +#endif
97903 +
97904 return 0;
97905 }
97906
97907 @@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97908 struct rb_node **rb_link, *rb_parent;
97909 bool faulted_in_anon_vma = true;
97910
97911 + BUG_ON(vma->vm_mirror);
97912 +
97913 /*
97914 * If anonymous vma has not yet been faulted, update new pgoff
97915 * to match new location, to increase its chance of merging.
97916 @@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97917 return NULL;
97918 }
97919
97920 +#ifdef CONFIG_PAX_SEGMEXEC
97921 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97922 +{
97923 + struct vm_area_struct *prev_m;
97924 + struct rb_node **rb_link_m, *rb_parent_m;
97925 + struct mempolicy *pol_m;
97926 +
97927 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97928 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97929 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97930 + *vma_m = *vma;
97931 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97932 + if (anon_vma_clone(vma_m, vma))
97933 + return -ENOMEM;
97934 + pol_m = vma_policy(vma_m);
97935 + mpol_get(pol_m);
97936 + set_vma_policy(vma_m, pol_m);
97937 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97938 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97939 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97940 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97941 + if (vma_m->vm_file)
97942 + get_file(vma_m->vm_file);
97943 + if (vma_m->vm_ops && vma_m->vm_ops->open)
97944 + vma_m->vm_ops->open(vma_m);
97945 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97946 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97947 + vma_m->vm_mirror = vma;
97948 + vma->vm_mirror = vma_m;
97949 + return 0;
97950 +}
97951 +#endif
97952 +
97953 /*
97954 * Return true if the calling process may expand its vm space by the passed
97955 * number of pages
97956 @@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97957
97958 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97959
97960 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97961 if (cur + npages > lim)
97962 return 0;
97963 return 1;
97964 @@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
97965 vma->vm_start = addr;
97966 vma->vm_end = addr + len;
97967
97968 +#ifdef CONFIG_PAX_MPROTECT
97969 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97970 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97971 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97972 + return ERR_PTR(-EPERM);
97973 + if (!(vm_flags & VM_EXEC))
97974 + vm_flags &= ~VM_MAYEXEC;
97975 +#else
97976 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97977 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97978 +#endif
97979 + else
97980 + vm_flags &= ~VM_MAYWRITE;
97981 + }
97982 +#endif
97983 +
97984 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97985 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97986
97987 diff --git a/mm/mprotect.c b/mm/mprotect.c
97988 index ace9345..63320dc 100644
97989 --- a/mm/mprotect.c
97990 +++ b/mm/mprotect.c
97991 @@ -24,10 +24,18 @@
97992 #include <linux/migrate.h>
97993 #include <linux/perf_event.h>
97994 #include <linux/ksm.h>
97995 +#include <linux/sched/sysctl.h>
97996 +
97997 +#ifdef CONFIG_PAX_MPROTECT
97998 +#include <linux/elf.h>
97999 +#include <linux/binfmts.h>
98000 +#endif
98001 +
98002 #include <asm/uaccess.h>
98003 #include <asm/pgtable.h>
98004 #include <asm/cacheflush.h>
98005 #include <asm/tlbflush.h>
98006 +#include <asm/mmu_context.h>
98007
98008 /*
98009 * For a prot_numa update we only hold mmap_sem for read so there is a
98010 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98011 return pages;
98012 }
98013
98014 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98015 +/* called while holding the mmap semaphor for writing except stack expansion */
98016 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98017 +{
98018 + unsigned long oldlimit, newlimit = 0UL;
98019 +
98020 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98021 + return;
98022 +
98023 + spin_lock(&mm->page_table_lock);
98024 + oldlimit = mm->context.user_cs_limit;
98025 + if ((prot & VM_EXEC) && oldlimit < end)
98026 + /* USER_CS limit moved up */
98027 + newlimit = end;
98028 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98029 + /* USER_CS limit moved down */
98030 + newlimit = start;
98031 +
98032 + if (newlimit) {
98033 + mm->context.user_cs_limit = newlimit;
98034 +
98035 +#ifdef CONFIG_SMP
98036 + wmb();
98037 + cpus_clear(mm->context.cpu_user_cs_mask);
98038 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98039 +#endif
98040 +
98041 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98042 + }
98043 + spin_unlock(&mm->page_table_lock);
98044 + if (newlimit == end) {
98045 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98046 +
98047 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98048 + if (is_vm_hugetlb_page(vma))
98049 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98050 + else
98051 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98052 + }
98053 +}
98054 +#endif
98055 +
98056 int
98057 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98058 unsigned long start, unsigned long end, unsigned long newflags)
98059 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98060 int error;
98061 int dirty_accountable = 0;
98062
98063 +#ifdef CONFIG_PAX_SEGMEXEC
98064 + struct vm_area_struct *vma_m = NULL;
98065 + unsigned long start_m, end_m;
98066 +
98067 + start_m = start + SEGMEXEC_TASK_SIZE;
98068 + end_m = end + SEGMEXEC_TASK_SIZE;
98069 +#endif
98070 +
98071 if (newflags == oldflags) {
98072 *pprev = vma;
98073 return 0;
98074 }
98075
98076 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98077 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98078 +
98079 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98080 + return -ENOMEM;
98081 +
98082 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98083 + return -ENOMEM;
98084 + }
98085 +
98086 /*
98087 * If we make a private mapping writable we increase our commit;
98088 * but (without finer accounting) cannot reduce our commit if we
98089 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98090 }
98091 }
98092
98093 +#ifdef CONFIG_PAX_SEGMEXEC
98094 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98095 + if (start != vma->vm_start) {
98096 + error = split_vma(mm, vma, start, 1);
98097 + if (error)
98098 + goto fail;
98099 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98100 + *pprev = (*pprev)->vm_next;
98101 + }
98102 +
98103 + if (end != vma->vm_end) {
98104 + error = split_vma(mm, vma, end, 0);
98105 + if (error)
98106 + goto fail;
98107 + }
98108 +
98109 + if (pax_find_mirror_vma(vma)) {
98110 + error = __do_munmap(mm, start_m, end_m - start_m);
98111 + if (error)
98112 + goto fail;
98113 + } else {
98114 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98115 + if (!vma_m) {
98116 + error = -ENOMEM;
98117 + goto fail;
98118 + }
98119 + vma->vm_flags = newflags;
98120 + error = pax_mirror_vma(vma_m, vma);
98121 + if (error) {
98122 + vma->vm_flags = oldflags;
98123 + goto fail;
98124 + }
98125 + }
98126 + }
98127 +#endif
98128 +
98129 /*
98130 * First try to merge with previous and/or next vma.
98131 */
98132 @@ -314,7 +418,19 @@ success:
98133 * vm_flags and vm_page_prot are protected by the mmap_sem
98134 * held in write mode.
98135 */
98136 +
98137 +#ifdef CONFIG_PAX_SEGMEXEC
98138 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98139 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98140 +#endif
98141 +
98142 vma->vm_flags = newflags;
98143 +
98144 +#ifdef CONFIG_PAX_MPROTECT
98145 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98146 + mm->binfmt->handle_mprotect(vma, newflags);
98147 +#endif
98148 +
98149 dirty_accountable = vma_wants_writenotify(vma);
98150 vma_set_page_prot(vma);
98151
98152 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98153 end = start + len;
98154 if (end <= start)
98155 return -ENOMEM;
98156 +
98157 +#ifdef CONFIG_PAX_SEGMEXEC
98158 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98159 + if (end > SEGMEXEC_TASK_SIZE)
98160 + return -EINVAL;
98161 + } else
98162 +#endif
98163 +
98164 + if (end > TASK_SIZE)
98165 + return -EINVAL;
98166 +
98167 if (!arch_validate_prot(prot))
98168 return -EINVAL;
98169
98170 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98171 /*
98172 * Does the application expect PROT_READ to imply PROT_EXEC:
98173 */
98174 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98175 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98176 prot |= PROT_EXEC;
98177
98178 vm_flags = calc_vm_prot_bits(prot);
98179 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98180 if (start > vma->vm_start)
98181 prev = vma;
98182
98183 +#ifdef CONFIG_PAX_MPROTECT
98184 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98185 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98186 +#endif
98187 +
98188 for (nstart = start ; ; ) {
98189 unsigned long newflags;
98190
98191 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98192
98193 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98194 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98195 + if (prot & (PROT_WRITE | PROT_EXEC))
98196 + gr_log_rwxmprotect(vma);
98197 +
98198 + error = -EACCES;
98199 + goto out;
98200 + }
98201 +
98202 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98203 error = -EACCES;
98204 goto out;
98205 }
98206 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98207 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98208 if (error)
98209 goto out;
98210 +
98211 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98212 +
98213 nstart = tmp;
98214
98215 if (nstart < prev->vm_end)
98216 diff --git a/mm/mremap.c b/mm/mremap.c
98217 index b147f66..98a695a 100644
98218 --- a/mm/mremap.c
98219 +++ b/mm/mremap.c
98220 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98221 continue;
98222 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98223 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98224 +
98225 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98226 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98227 + pte = pte_exprotect(pte);
98228 +#endif
98229 +
98230 pte = move_soft_dirty_pte(pte);
98231 set_pte_at(mm, new_addr, new_pte, pte);
98232 }
98233 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98234 if (is_vm_hugetlb_page(vma))
98235 goto Einval;
98236
98237 +#ifdef CONFIG_PAX_SEGMEXEC
98238 + if (pax_find_mirror_vma(vma))
98239 + goto Einval;
98240 +#endif
98241 +
98242 /* We can't remap across vm area boundaries */
98243 if (old_len > vma->vm_end - addr)
98244 goto Efault;
98245 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98246 unsigned long ret = -EINVAL;
98247 unsigned long charged = 0;
98248 unsigned long map_flags;
98249 + unsigned long pax_task_size = TASK_SIZE;
98250
98251 if (new_addr & ~PAGE_MASK)
98252 goto out;
98253
98254 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98255 +#ifdef CONFIG_PAX_SEGMEXEC
98256 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98257 + pax_task_size = SEGMEXEC_TASK_SIZE;
98258 +#endif
98259 +
98260 + pax_task_size -= PAGE_SIZE;
98261 +
98262 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98263 goto out;
98264
98265 /* Check if the location we're moving into overlaps the
98266 * old location at all, and fail if it does.
98267 */
98268 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98269 - goto out;
98270 -
98271 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98272 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98273 goto out;
98274
98275 ret = do_munmap(mm, new_addr, new_len);
98276 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98277 unsigned long ret = -EINVAL;
98278 unsigned long charged = 0;
98279 bool locked = false;
98280 + unsigned long pax_task_size = TASK_SIZE;
98281
98282 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98283 return ret;
98284 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98285 if (!new_len)
98286 return ret;
98287
98288 +#ifdef CONFIG_PAX_SEGMEXEC
98289 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98290 + pax_task_size = SEGMEXEC_TASK_SIZE;
98291 +#endif
98292 +
98293 + pax_task_size -= PAGE_SIZE;
98294 +
98295 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98296 + old_len > pax_task_size || addr > pax_task_size-old_len)
98297 + return ret;
98298 +
98299 down_write(&current->mm->mmap_sem);
98300
98301 if (flags & MREMAP_FIXED) {
98302 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98303 new_addr = addr;
98304 }
98305 ret = addr;
98306 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98307 goto out;
98308 }
98309 }
98310 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98311 goto out;
98312 }
98313
98314 + map_flags = vma->vm_flags;
98315 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98316 + if (!(ret & ~PAGE_MASK)) {
98317 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98318 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98319 + }
98320 }
98321 out:
98322 if (ret & ~PAGE_MASK)
98323 diff --git a/mm/nommu.c b/mm/nommu.c
98324 index bd1808e..b63d87c 100644
98325 --- a/mm/nommu.c
98326 +++ b/mm/nommu.c
98327 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98328 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98329 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98330 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98331 -int heap_stack_gap = 0;
98332
98333 atomic_long_t mmap_pages_allocated;
98334
98335 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98336 EXPORT_SYMBOL(find_vma);
98337
98338 /*
98339 - * find a VMA
98340 - * - we don't extend stack VMAs under NOMMU conditions
98341 - */
98342 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98343 -{
98344 - return find_vma(mm, addr);
98345 -}
98346 -
98347 -/*
98348 * expand a stack to a given address
98349 * - not supported under NOMMU conditions
98350 */
98351 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98352
98353 /* most fields are the same, copy all, and then fixup */
98354 *new = *vma;
98355 + INIT_LIST_HEAD(&new->anon_vma_chain);
98356 *region = *vma->vm_region;
98357 new->vm_region = region;
98358
98359 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98360 }
98361 EXPORT_SYMBOL(generic_file_remap_pages);
98362
98363 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98364 - unsigned long addr, void *buf, int len, int write)
98365 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98366 + unsigned long addr, void *buf, size_t len, int write)
98367 {
98368 struct vm_area_struct *vma;
98369
98370 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98371 *
98372 * The caller must hold a reference on @mm.
98373 */
98374 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98375 - void *buf, int len, int write)
98376 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98377 + void *buf, size_t len, int write)
98378 {
98379 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98380 }
98381 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98382 * Access another process' address space.
98383 * - source/target buffer must be kernel space
98384 */
98385 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98386 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98387 {
98388 struct mm_struct *mm;
98389
98390 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98391 index 437174a..8b86707 100644
98392 --- a/mm/page-writeback.c
98393 +++ b/mm/page-writeback.c
98394 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98395 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98396 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98397 */
98398 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98399 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98400 unsigned long thresh,
98401 unsigned long bg_thresh,
98402 unsigned long dirty,
98403 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98404 index 616a2c9..0e755f6 100644
98405 --- a/mm/page_alloc.c
98406 +++ b/mm/page_alloc.c
98407 @@ -59,6 +59,7 @@
98408 #include <linux/page-debug-flags.h>
98409 #include <linux/hugetlb.h>
98410 #include <linux/sched/rt.h>
98411 +#include <linux/random.h>
98412
98413 #include <asm/sections.h>
98414 #include <asm/tlbflush.h>
98415 @@ -356,7 +357,7 @@ out:
98416 * This usage means that zero-order pages may not be compound.
98417 */
98418
98419 -static void free_compound_page(struct page *page)
98420 +void free_compound_page(struct page *page)
98421 {
98422 __free_pages_ok(page, compound_order(page));
98423 }
98424 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98425 int i;
98426 int bad = 0;
98427
98428 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98429 + unsigned long index = 1UL << order;
98430 +#endif
98431 +
98432 trace_mm_page_free(page, order);
98433 kmemcheck_free_shadow(page, order);
98434
98435 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98436 debug_check_no_obj_freed(page_address(page),
98437 PAGE_SIZE << order);
98438 }
98439 +
98440 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98441 + for (; index; --index)
98442 + sanitize_highpage(page + index - 1);
98443 +#endif
98444 +
98445 arch_free_page(page, order);
98446 kernel_map_pages(page, 1 << order, 0);
98447
98448 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98449 local_irq_restore(flags);
98450 }
98451
98452 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98453 +bool __meminitdata extra_latent_entropy;
98454 +
98455 +static int __init setup_pax_extra_latent_entropy(char *str)
98456 +{
98457 + extra_latent_entropy = true;
98458 + return 0;
98459 +}
98460 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98461 +
98462 +volatile u64 latent_entropy __latent_entropy;
98463 +EXPORT_SYMBOL(latent_entropy);
98464 +#endif
98465 +
98466 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98467 {
98468 unsigned int nr_pages = 1 << order;
98469 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98470 __ClearPageReserved(p);
98471 set_page_count(p, 0);
98472
98473 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98474 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98475 + u64 hash = 0;
98476 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98477 + const u64 *data = lowmem_page_address(page);
98478 +
98479 + for (index = 0; index < end; index++)
98480 + hash ^= hash + data[index];
98481 + latent_entropy ^= hash;
98482 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98483 + }
98484 +#endif
98485 +
98486 page_zone(page)->managed_pages += nr_pages;
98487 set_page_refcounted(page);
98488 __free_pages(page, order);
98489 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98490 arch_alloc_page(page, order);
98491 kernel_map_pages(page, 1 << order, 1);
98492
98493 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98494 if (gfp_flags & __GFP_ZERO)
98495 prep_zero_page(page, order, gfp_flags);
98496 +#endif
98497
98498 if (order && (gfp_flags & __GFP_COMP))
98499 prep_compound_page(page, order);
98500 @@ -1602,7 +1642,7 @@ again:
98501 }
98502
98503 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98504 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98505 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98506 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98507 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98508
98509 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98510 do {
98511 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98512 high_wmark_pages(zone) - low_wmark_pages(zone) -
98513 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98514 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98515 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98516 } while (zone++ != preferred_zone);
98517 }
98518 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98519
98520 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98521 high_wmark_pages(zone) - low_wmark_pages(zone) -
98522 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98523 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98524
98525 setup_zone_migrate_reserve(zone);
98526 spin_unlock_irqrestore(&zone->lock, flags);
98527 diff --git a/mm/percpu.c b/mm/percpu.c
98528 index 014bab6..db5a76f 100644
98529 --- a/mm/percpu.c
98530 +++ b/mm/percpu.c
98531 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98532 static unsigned int pcpu_high_unit_cpu __read_mostly;
98533
98534 /* the address of the first chunk which starts with the kernel static area */
98535 -void *pcpu_base_addr __read_mostly;
98536 +void *pcpu_base_addr __read_only;
98537 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98538
98539 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98540 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98541 index 5077afc..846c9ef 100644
98542 --- a/mm/process_vm_access.c
98543 +++ b/mm/process_vm_access.c
98544 @@ -13,6 +13,7 @@
98545 #include <linux/uio.h>
98546 #include <linux/sched.h>
98547 #include <linux/highmem.h>
98548 +#include <linux/security.h>
98549 #include <linux/ptrace.h>
98550 #include <linux/slab.h>
98551 #include <linux/syscalls.h>
98552 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98553 ssize_t iov_len;
98554 size_t total_len = iov_iter_count(iter);
98555
98556 + return -ENOSYS; // PaX: until properly audited
98557 +
98558 /*
98559 * Work out how many pages of struct pages we're going to need
98560 * when eventually calling get_user_pages
98561 */
98562 for (i = 0; i < riovcnt; i++) {
98563 iov_len = rvec[i].iov_len;
98564 - if (iov_len > 0) {
98565 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98566 - + iov_len)
98567 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98568 - / PAGE_SIZE + 1;
98569 - nr_pages = max(nr_pages, nr_pages_iov);
98570 - }
98571 + if (iov_len <= 0)
98572 + continue;
98573 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98574 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98575 + nr_pages = max(nr_pages, nr_pages_iov);
98576 }
98577
98578 if (nr_pages == 0)
98579 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98580 goto free_proc_pages;
98581 }
98582
98583 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98584 + rc = -EPERM;
98585 + goto put_task_struct;
98586 + }
98587 +
98588 mm = mm_access(task, PTRACE_MODE_ATTACH);
98589 if (!mm || IS_ERR(mm)) {
98590 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98591 diff --git a/mm/rmap.c b/mm/rmap.c
98592 index 3e4c721..a5e3e39 100644
98593 --- a/mm/rmap.c
98594 +++ b/mm/rmap.c
98595 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98596 struct anon_vma *anon_vma = vma->anon_vma;
98597 struct anon_vma_chain *avc;
98598
98599 +#ifdef CONFIG_PAX_SEGMEXEC
98600 + struct anon_vma_chain *avc_m = NULL;
98601 +#endif
98602 +
98603 might_sleep();
98604 if (unlikely(!anon_vma)) {
98605 struct mm_struct *mm = vma->vm_mm;
98606 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98607 if (!avc)
98608 goto out_enomem;
98609
98610 +#ifdef CONFIG_PAX_SEGMEXEC
98611 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98612 + if (!avc_m)
98613 + goto out_enomem_free_avc;
98614 +#endif
98615 +
98616 anon_vma = find_mergeable_anon_vma(vma);
98617 allocated = NULL;
98618 if (!anon_vma) {
98619 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98620 /* page_table_lock to protect against threads */
98621 spin_lock(&mm->page_table_lock);
98622 if (likely(!vma->anon_vma)) {
98623 +
98624 +#ifdef CONFIG_PAX_SEGMEXEC
98625 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98626 +
98627 + if (vma_m) {
98628 + BUG_ON(vma_m->anon_vma);
98629 + vma_m->anon_vma = anon_vma;
98630 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98631 + avc_m = NULL;
98632 + }
98633 +#endif
98634 +
98635 vma->anon_vma = anon_vma;
98636 anon_vma_chain_link(vma, avc, anon_vma);
98637 allocated = NULL;
98638 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98639
98640 if (unlikely(allocated))
98641 put_anon_vma(allocated);
98642 +
98643 +#ifdef CONFIG_PAX_SEGMEXEC
98644 + if (unlikely(avc_m))
98645 + anon_vma_chain_free(avc_m);
98646 +#endif
98647 +
98648 if (unlikely(avc))
98649 anon_vma_chain_free(avc);
98650 }
98651 return 0;
98652
98653 out_enomem_free_avc:
98654 +
98655 +#ifdef CONFIG_PAX_SEGMEXEC
98656 + if (avc_m)
98657 + anon_vma_chain_free(avc_m);
98658 +#endif
98659 +
98660 anon_vma_chain_free(avc);
98661 out_enomem:
98662 return -ENOMEM;
98663 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98664 * Attach the anon_vmas from src to dst.
98665 * Returns 0 on success, -ENOMEM on failure.
98666 */
98667 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98668 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98669 {
98670 struct anon_vma_chain *avc, *pavc;
98671 struct anon_vma *root = NULL;
98672 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98673 * the corresponding VMA in the parent process is attached to.
98674 * Returns 0 on success, non-zero on failure.
98675 */
98676 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98677 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98678 {
98679 struct anon_vma_chain *avc;
98680 struct anon_vma *anon_vma;
98681 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98682 void __init anon_vma_init(void)
98683 {
98684 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98685 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98686 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98687 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98688 + anon_vma_ctor);
98689 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98690 + SLAB_PANIC|SLAB_NO_SANITIZE);
98691 }
98692
98693 /*
98694 diff --git a/mm/shmem.c b/mm/shmem.c
98695 index 185836b..d7255a1 100644
98696 --- a/mm/shmem.c
98697 +++ b/mm/shmem.c
98698 @@ -33,7 +33,7 @@
98699 #include <linux/swap.h>
98700 #include <linux/aio.h>
98701
98702 -static struct vfsmount *shm_mnt;
98703 +struct vfsmount *shm_mnt;
98704
98705 #ifdef CONFIG_SHMEM
98706 /*
98707 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98708 #define BOGO_DIRENT_SIZE 20
98709
98710 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98711 -#define SHORT_SYMLINK_LEN 128
98712 +#define SHORT_SYMLINK_LEN 64
98713
98714 /*
98715 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98716 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98717 static int shmem_xattr_validate(const char *name)
98718 {
98719 struct { const char *prefix; size_t len; } arr[] = {
98720 +
98721 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98722 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98723 +#endif
98724 +
98725 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98726 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98727 };
98728 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98729 if (err)
98730 return err;
98731
98732 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98733 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98734 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98735 + return -EOPNOTSUPP;
98736 + if (size > 8)
98737 + return -EINVAL;
98738 + }
98739 +#endif
98740 +
98741 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98742 }
98743
98744 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98745 int err = -ENOMEM;
98746
98747 /* Round up to L1_CACHE_BYTES to resist false sharing */
98748 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98749 - L1_CACHE_BYTES), GFP_KERNEL);
98750 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98751 if (!sbinfo)
98752 return -ENOMEM;
98753
98754 diff --git a/mm/slab.c b/mm/slab.c
98755 index f34e053..78a3839 100644
98756 --- a/mm/slab.c
98757 +++ b/mm/slab.c
98758 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98759 if ((x)->max_freeable < i) \
98760 (x)->max_freeable = i; \
98761 } while (0)
98762 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98763 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98764 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98765 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98766 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98767 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98768 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98769 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98770 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98771 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98772 #else
98773 #define STATS_INC_ACTIVE(x) do { } while (0)
98774 #define STATS_DEC_ACTIVE(x) do { } while (0)
98775 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98776 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98777 #define STATS_INC_FREEHIT(x) do { } while (0)
98778 #define STATS_INC_FREEMISS(x) do { } while (0)
98779 +#define STATS_INC_SANITIZED(x) do { } while (0)
98780 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98781 #endif
98782
98783 #if DEBUG
98784 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98785 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98786 */
98787 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98788 - const struct page *page, void *obj)
98789 + const struct page *page, const void *obj)
98790 {
98791 u32 offset = (obj - page->s_mem);
98792 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98793 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98794 * structures first. Without this, further allocations will bug.
98795 */
98796 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98797 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98798 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98799 slab_state = PARTIAL_NODE;
98800
98801 slab_early_init = 0;
98802 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98803
98804 cachep = find_mergeable(size, align, flags, name, ctor);
98805 if (cachep) {
98806 - cachep->refcount++;
98807 + atomic_inc(&cachep->refcount);
98808
98809 /*
98810 * Adjust the object sizes so that we clear
98811 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98812 struct array_cache *ac = cpu_cache_get(cachep);
98813
98814 check_irq_off();
98815 +
98816 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98817 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98818 + STATS_INC_NOT_SANITIZED(cachep);
98819 + else {
98820 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98821 +
98822 + if (cachep->ctor)
98823 + cachep->ctor(objp);
98824 +
98825 + STATS_INC_SANITIZED(cachep);
98826 + }
98827 +#endif
98828 +
98829 kmemleak_free_recursive(objp, cachep->flags);
98830 objp = cache_free_debugcheck(cachep, objp, caller);
98831
98832 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
98833
98834 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98835 return;
98836 + VM_BUG_ON(!virt_addr_valid(objp));
98837 local_irq_save(flags);
98838 kfree_debugcheck(objp);
98839 c = virt_to_cache(objp);
98840 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98841 }
98842 /* cpu stats */
98843 {
98844 - unsigned long allochit = atomic_read(&cachep->allochit);
98845 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98846 - unsigned long freehit = atomic_read(&cachep->freehit);
98847 - unsigned long freemiss = atomic_read(&cachep->freemiss);
98848 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98849 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98850 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98851 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98852
98853 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98854 allochit, allocmiss, freehit, freemiss);
98855 }
98856 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98857 + {
98858 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98859 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98860 +
98861 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98862 + }
98863 +#endif
98864 #endif
98865 }
98866
98867 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
98868 static int __init slab_proc_init(void)
98869 {
98870 #ifdef CONFIG_DEBUG_SLAB_LEAK
98871 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98872 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98873 #endif
98874 return 0;
98875 }
98876 module_init(slab_proc_init);
98877 #endif
98878
98879 +bool is_usercopy_object(const void *ptr)
98880 +{
98881 + struct page *page;
98882 + struct kmem_cache *cachep;
98883 +
98884 + if (ZERO_OR_NULL_PTR(ptr))
98885 + return false;
98886 +
98887 + if (!slab_is_available())
98888 + return false;
98889 +
98890 + if (!virt_addr_valid(ptr))
98891 + return false;
98892 +
98893 + page = virt_to_head_page(ptr);
98894 +
98895 + if (!PageSlab(page))
98896 + return false;
98897 +
98898 + cachep = page->slab_cache;
98899 + return cachep->flags & SLAB_USERCOPY;
98900 +}
98901 +
98902 +#ifdef CONFIG_PAX_USERCOPY
98903 +const char *check_heap_object(const void *ptr, unsigned long n)
98904 +{
98905 + struct page *page;
98906 + struct kmem_cache *cachep;
98907 + unsigned int objnr;
98908 + unsigned long offset;
98909 +
98910 + if (ZERO_OR_NULL_PTR(ptr))
98911 + return "<null>";
98912 +
98913 + if (!virt_addr_valid(ptr))
98914 + return NULL;
98915 +
98916 + page = virt_to_head_page(ptr);
98917 +
98918 + if (!PageSlab(page))
98919 + return NULL;
98920 +
98921 + cachep = page->slab_cache;
98922 + if (!(cachep->flags & SLAB_USERCOPY))
98923 + return cachep->name;
98924 +
98925 + objnr = obj_to_index(cachep, page, ptr);
98926 + BUG_ON(objnr >= cachep->num);
98927 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98928 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98929 + return NULL;
98930 +
98931 + return cachep->name;
98932 +}
98933 +#endif
98934 +
98935 /**
98936 * ksize - get the actual amount of memory allocated for a given object
98937 * @objp: Pointer to the object
98938 diff --git a/mm/slab.h b/mm/slab.h
98939 index ab019e6..fbcac34 100644
98940 --- a/mm/slab.h
98941 +++ b/mm/slab.h
98942 @@ -22,7 +22,7 @@ struct kmem_cache {
98943 unsigned int align; /* Alignment as calculated */
98944 unsigned long flags; /* Active flags on the slab */
98945 const char *name; /* Slab name for sysfs */
98946 - int refcount; /* Use counter */
98947 + atomic_t refcount; /* Use counter */
98948 void (*ctor)(void *); /* Called on object slot creation */
98949 struct list_head list; /* List of all slab caches on the system */
98950 };
98951 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
98952 /* The slab cache that manages slab cache information */
98953 extern struct kmem_cache *kmem_cache;
98954
98955 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98956 +#ifdef CONFIG_X86_64
98957 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98958 +#else
98959 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98960 +#endif
98961 +enum pax_sanitize_mode {
98962 + PAX_SANITIZE_SLAB_OFF = 0,
98963 + PAX_SANITIZE_SLAB_FAST,
98964 + PAX_SANITIZE_SLAB_FULL,
98965 +};
98966 +extern enum pax_sanitize_mode pax_sanitize_slab;
98967 +#endif
98968 +
98969 unsigned long calculate_alignment(unsigned long flags,
98970 unsigned long align, unsigned long size);
98971
98972 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
98973
98974 /* Legal flag mask for kmem_cache_create(), for various configurations */
98975 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98976 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98977 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98978 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
98979
98980 #if defined(CONFIG_DEBUG_SLAB)
98981 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98982 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98983 return s;
98984
98985 page = virt_to_head_page(x);
98986 +
98987 + BUG_ON(!PageSlab(page));
98988 +
98989 cachep = page->slab_cache;
98990 if (slab_equal_or_root(cachep, s))
98991 return cachep;
98992 diff --git a/mm/slab_common.c b/mm/slab_common.c
98993 index dcdab81..3576646 100644
98994 --- a/mm/slab_common.c
98995 +++ b/mm/slab_common.c
98996 @@ -25,11 +25,35 @@
98997
98998 #include "slab.h"
98999
99000 -enum slab_state slab_state;
99001 +enum slab_state slab_state __read_only;
99002 LIST_HEAD(slab_caches);
99003 DEFINE_MUTEX(slab_mutex);
99004 struct kmem_cache *kmem_cache;
99005
99006 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99007 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99008 +static int __init pax_sanitize_slab_setup(char *str)
99009 +{
99010 + if (!str)
99011 + return 0;
99012 +
99013 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99014 + pr_info("PaX slab sanitization: %s\n", "disabled");
99015 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99016 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99017 + pr_info("PaX slab sanitization: %s\n", "fast");
99018 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99019 + } else if (!strcmp(str, "full")) {
99020 + pr_info("PaX slab sanitization: %s\n", "full");
99021 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99022 + } else
99023 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99024 +
99025 + return 0;
99026 +}
99027 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99028 +#endif
99029 +
99030 /*
99031 * Set of flags that will prevent slab merging
99032 */
99033 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
99034 * Merge control. If this is set then no merging of slab caches will occur.
99035 * (Could be removed. This was introduced to pacify the merge skeptics.)
99036 */
99037 -static int slab_nomerge;
99038 +static int slab_nomerge = 1;
99039
99040 static int __init setup_slab_nomerge(char *str)
99041 {
99042 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
99043 /*
99044 * We may have set a slab to be unmergeable during bootstrap.
99045 */
99046 - if (s->refcount < 0)
99047 + if (atomic_read(&s->refcount) < 0)
99048 return 1;
99049
99050 return 0;
99051 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99052 if (err)
99053 goto out_free_cache;
99054
99055 - s->refcount = 1;
99056 + atomic_set(&s->refcount, 1);
99057 list_add(&s->list, &slab_caches);
99058 out:
99059 if (err)
99060 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99061 */
99062 flags &= CACHE_CREATE_MASK;
99063
99064 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99065 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99066 + flags |= SLAB_NO_SANITIZE;
99067 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99068 + flags &= ~SLAB_NO_SANITIZE;
99069 +#endif
99070 +
99071 s = __kmem_cache_alias(name, size, align, flags, ctor);
99072 if (s)
99073 goto out_unlock;
99074 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99075
99076 mutex_lock(&slab_mutex);
99077
99078 - s->refcount--;
99079 - if (s->refcount)
99080 + if (!atomic_dec_and_test(&s->refcount))
99081 goto out_unlock;
99082
99083 if (memcg_cleanup_cache_params(s) != 0)
99084 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99085 rcu_barrier();
99086
99087 memcg_free_cache_params(s);
99088 -#ifdef SLAB_SUPPORTS_SYSFS
99089 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99090 sysfs_slab_remove(s);
99091 #else
99092 slab_kmem_cache_release(s);
99093 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99094 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99095 name, size, err);
99096
99097 - s->refcount = -1; /* Exempt from merging for now */
99098 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99099 }
99100
99101 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99102 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99103
99104 create_boot_cache(s, name, size, flags);
99105 list_add(&s->list, &slab_caches);
99106 - s->refcount = 1;
99107 + atomic_set(&s->refcount, 1);
99108 return s;
99109 }
99110
99111 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99112 EXPORT_SYMBOL(kmalloc_dma_caches);
99113 #endif
99114
99115 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99116 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99117 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99118 +#endif
99119 +
99120 /*
99121 * Conversion table for small slabs sizes / 8 to the index in the
99122 * kmalloc array. This is necessary for slabs < 192 since we have non power
99123 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99124 return kmalloc_dma_caches[index];
99125
99126 #endif
99127 +
99128 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99129 + if (unlikely((flags & GFP_USERCOPY)))
99130 + return kmalloc_usercopy_caches[index];
99131 +
99132 +#endif
99133 +
99134 return kmalloc_caches[index];
99135 }
99136
99137 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99138 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99139 if (!kmalloc_caches[i]) {
99140 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99141 - 1 << i, flags);
99142 + 1 << i, SLAB_USERCOPY | flags);
99143 }
99144
99145 /*
99146 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99147 * earlier power of two caches
99148 */
99149 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99150 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99151 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99152
99153 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99154 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99155 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99156 }
99157
99158 /* Kmalloc array is now usable */
99159 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99160 }
99161 }
99162 #endif
99163 +
99164 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99165 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99166 + struct kmem_cache *s = kmalloc_caches[i];
99167 +
99168 + if (s) {
99169 + int size = kmalloc_size(i);
99170 + char *n = kasprintf(GFP_NOWAIT,
99171 + "usercopy-kmalloc-%d", size);
99172 +
99173 + BUG_ON(!n);
99174 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99175 + size, SLAB_USERCOPY | flags);
99176 + }
99177 + }
99178 +#endif
99179 +
99180 }
99181 #endif /* !CONFIG_SLOB */
99182
99183 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99184 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99185 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99186 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99187 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99188 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99189 +#endif
99190 #endif
99191 seq_putc(m, '\n');
99192 }
99193 diff --git a/mm/slob.c b/mm/slob.c
99194 index 96a8620..3e7e663 100644
99195 --- a/mm/slob.c
99196 +++ b/mm/slob.c
99197 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99198 /*
99199 * Return the size of a slob block.
99200 */
99201 -static slobidx_t slob_units(slob_t *s)
99202 +static slobidx_t slob_units(const slob_t *s)
99203 {
99204 if (s->units > 0)
99205 return s->units;
99206 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99207 /*
99208 * Return the next free slob block pointer after this one.
99209 */
99210 -static slob_t *slob_next(slob_t *s)
99211 +static slob_t *slob_next(const slob_t *s)
99212 {
99213 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99214 slobidx_t next;
99215 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99216 /*
99217 * Returns true if s is the last free block in its page.
99218 */
99219 -static int slob_last(slob_t *s)
99220 +static int slob_last(const slob_t *s)
99221 {
99222 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99223 }
99224
99225 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99226 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99227 {
99228 - void *page;
99229 + struct page *page;
99230
99231 #ifdef CONFIG_NUMA
99232 if (node != NUMA_NO_NODE)
99233 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99234 if (!page)
99235 return NULL;
99236
99237 - return page_address(page);
99238 + __SetPageSlab(page);
99239 + return page;
99240 }
99241
99242 -static void slob_free_pages(void *b, int order)
99243 +static void slob_free_pages(struct page *sp, int order)
99244 {
99245 if (current->reclaim_state)
99246 current->reclaim_state->reclaimed_slab += 1 << order;
99247 - free_pages((unsigned long)b, order);
99248 + __ClearPageSlab(sp);
99249 + page_mapcount_reset(sp);
99250 + sp->private = 0;
99251 + __free_pages(sp, order);
99252 }
99253
99254 /*
99255 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99256
99257 /* Not enough space: must allocate a new page */
99258 if (!b) {
99259 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99260 - if (!b)
99261 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99262 + if (!sp)
99263 return NULL;
99264 - sp = virt_to_page(b);
99265 - __SetPageSlab(sp);
99266 + b = page_address(sp);
99267
99268 spin_lock_irqsave(&slob_lock, flags);
99269 sp->units = SLOB_UNITS(PAGE_SIZE);
99270 sp->freelist = b;
99271 + sp->private = 0;
99272 INIT_LIST_HEAD(&sp->lru);
99273 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99274 set_slob_page_free(sp, slob_list);
99275 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99276 /*
99277 * slob_free: entry point into the slob allocator.
99278 */
99279 -static void slob_free(void *block, int size)
99280 +static void slob_free(struct kmem_cache *c, void *block, int size)
99281 {
99282 struct page *sp;
99283 slob_t *prev, *next, *b = (slob_t *)block;
99284 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99285 if (slob_page_free(sp))
99286 clear_slob_page_free(sp);
99287 spin_unlock_irqrestore(&slob_lock, flags);
99288 - __ClearPageSlab(sp);
99289 - page_mapcount_reset(sp);
99290 - slob_free_pages(b, 0);
99291 + slob_free_pages(sp, 0);
99292 return;
99293 }
99294
99295 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99296 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99297 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99298 +#endif
99299 +
99300 if (!slob_page_free(sp)) {
99301 /* This slob page is about to become partially free. Easy! */
99302 sp->units = units;
99303 @@ -424,11 +431,10 @@ out:
99304 */
99305
99306 static __always_inline void *
99307 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99308 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99309 {
99310 - unsigned int *m;
99311 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99312 - void *ret;
99313 + slob_t *m;
99314 + void *ret = NULL;
99315
99316 gfp &= gfp_allowed_mask;
99317
99318 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99319
99320 if (!m)
99321 return NULL;
99322 - *m = size;
99323 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99324 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99325 + m[0].units = size;
99326 + m[1].units = align;
99327 ret = (void *)m + align;
99328
99329 trace_kmalloc_node(caller, ret,
99330 size, size + align, gfp, node);
99331 } else {
99332 unsigned int order = get_order(size);
99333 + struct page *page;
99334
99335 if (likely(order))
99336 gfp |= __GFP_COMP;
99337 - ret = slob_new_pages(gfp, order, node);
99338 + page = slob_new_pages(gfp, order, node);
99339 + if (page) {
99340 + ret = page_address(page);
99341 + page->private = size;
99342 + }
99343
99344 trace_kmalloc_node(caller, ret,
99345 size, PAGE_SIZE << order, gfp, node);
99346 }
99347
99348 - kmemleak_alloc(ret, size, 1, gfp);
99349 + return ret;
99350 +}
99351 +
99352 +static __always_inline void *
99353 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99354 +{
99355 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99356 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99357 +
99358 + if (!ZERO_OR_NULL_PTR(ret))
99359 + kmemleak_alloc(ret, size, 1, gfp);
99360 return ret;
99361 }
99362
99363 @@ -491,34 +515,112 @@ void kfree(const void *block)
99364 return;
99365 kmemleak_free(block);
99366
99367 + VM_BUG_ON(!virt_addr_valid(block));
99368 sp = virt_to_page(block);
99369 - if (PageSlab(sp)) {
99370 + VM_BUG_ON(!PageSlab(sp));
99371 + if (!sp->private) {
99372 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99373 - unsigned int *m = (unsigned int *)(block - align);
99374 - slob_free(m, *m + align);
99375 - } else
99376 + slob_t *m = (slob_t *)(block - align);
99377 + slob_free(NULL, m, m[0].units + align);
99378 + } else {
99379 + __ClearPageSlab(sp);
99380 + page_mapcount_reset(sp);
99381 + sp->private = 0;
99382 __free_pages(sp, compound_order(sp));
99383 + }
99384 }
99385 EXPORT_SYMBOL(kfree);
99386
99387 +bool is_usercopy_object(const void *ptr)
99388 +{
99389 + if (!slab_is_available())
99390 + return false;
99391 +
99392 + // PAX: TODO
99393 +
99394 + return false;
99395 +}
99396 +
99397 +#ifdef CONFIG_PAX_USERCOPY
99398 +const char *check_heap_object(const void *ptr, unsigned long n)
99399 +{
99400 + struct page *page;
99401 + const slob_t *free;
99402 + const void *base;
99403 + unsigned long flags;
99404 +
99405 + if (ZERO_OR_NULL_PTR(ptr))
99406 + return "<null>";
99407 +
99408 + if (!virt_addr_valid(ptr))
99409 + return NULL;
99410 +
99411 + page = virt_to_head_page(ptr);
99412 + if (!PageSlab(page))
99413 + return NULL;
99414 +
99415 + if (page->private) {
99416 + base = page;
99417 + if (base <= ptr && n <= page->private - (ptr - base))
99418 + return NULL;
99419 + return "<slob>";
99420 + }
99421 +
99422 + /* some tricky double walking to find the chunk */
99423 + spin_lock_irqsave(&slob_lock, flags);
99424 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99425 + free = page->freelist;
99426 +
99427 + while (!slob_last(free) && (void *)free <= ptr) {
99428 + base = free + slob_units(free);
99429 + free = slob_next(free);
99430 + }
99431 +
99432 + while (base < (void *)free) {
99433 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99434 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99435 + int offset;
99436 +
99437 + if (ptr < base + align)
99438 + break;
99439 +
99440 + offset = ptr - base - align;
99441 + if (offset >= m) {
99442 + base += size;
99443 + continue;
99444 + }
99445 +
99446 + if (n > m - offset)
99447 + break;
99448 +
99449 + spin_unlock_irqrestore(&slob_lock, flags);
99450 + return NULL;
99451 + }
99452 +
99453 + spin_unlock_irqrestore(&slob_lock, flags);
99454 + return "<slob>";
99455 +}
99456 +#endif
99457 +
99458 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99459 size_t ksize(const void *block)
99460 {
99461 struct page *sp;
99462 int align;
99463 - unsigned int *m;
99464 + slob_t *m;
99465
99466 BUG_ON(!block);
99467 if (unlikely(block == ZERO_SIZE_PTR))
99468 return 0;
99469
99470 sp = virt_to_page(block);
99471 - if (unlikely(!PageSlab(sp)))
99472 - return PAGE_SIZE << compound_order(sp);
99473 + VM_BUG_ON(!PageSlab(sp));
99474 + if (sp->private)
99475 + return sp->private;
99476
99477 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99478 - m = (unsigned int *)(block - align);
99479 - return SLOB_UNITS(*m) * SLOB_UNIT;
99480 + m = (slob_t *)(block - align);
99481 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99482 }
99483 EXPORT_SYMBOL(ksize);
99484
99485 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99486
99487 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99488 {
99489 - void *b;
99490 + void *b = NULL;
99491
99492 flags &= gfp_allowed_mask;
99493
99494 lockdep_trace_alloc(flags);
99495
99496 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99497 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99498 +#else
99499 if (c->size < PAGE_SIZE) {
99500 b = slob_alloc(c->size, flags, c->align, node);
99501 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99502 SLOB_UNITS(c->size) * SLOB_UNIT,
99503 flags, node);
99504 } else {
99505 - b = slob_new_pages(flags, get_order(c->size), node);
99506 + struct page *sp;
99507 +
99508 + sp = slob_new_pages(flags, get_order(c->size), node);
99509 + if (sp) {
99510 + b = page_address(sp);
99511 + sp->private = c->size;
99512 + }
99513 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99514 PAGE_SIZE << get_order(c->size),
99515 flags, node);
99516 }
99517 +#endif
99518
99519 if (b && c->ctor)
99520 c->ctor(b);
99521 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99522 EXPORT_SYMBOL(kmem_cache_alloc_node);
99523 #endif
99524
99525 -static void __kmem_cache_free(void *b, int size)
99526 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99527 {
99528 - if (size < PAGE_SIZE)
99529 - slob_free(b, size);
99530 + struct page *sp;
99531 +
99532 + sp = virt_to_page(b);
99533 + BUG_ON(!PageSlab(sp));
99534 + if (!sp->private)
99535 + slob_free(c, b, size);
99536 else
99537 - slob_free_pages(b, get_order(size));
99538 + slob_free_pages(sp, get_order(size));
99539 }
99540
99541 static void kmem_rcu_free(struct rcu_head *head)
99542 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99543 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99544 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99545
99546 - __kmem_cache_free(b, slob_rcu->size);
99547 + __kmem_cache_free(NULL, b, slob_rcu->size);
99548 }
99549
99550 void kmem_cache_free(struct kmem_cache *c, void *b)
99551 {
99552 + int size = c->size;
99553 +
99554 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99555 + if (size + c->align < PAGE_SIZE) {
99556 + size += c->align;
99557 + b -= c->align;
99558 + }
99559 +#endif
99560 +
99561 kmemleak_free_recursive(b, c->flags);
99562 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99563 struct slob_rcu *slob_rcu;
99564 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99565 - slob_rcu->size = c->size;
99566 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99567 + slob_rcu->size = size;
99568 call_rcu(&slob_rcu->head, kmem_rcu_free);
99569 } else {
99570 - __kmem_cache_free(b, c->size);
99571 + __kmem_cache_free(c, b, size);
99572 }
99573
99574 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99575 + trace_kfree(_RET_IP_, b);
99576 +#else
99577 trace_kmem_cache_free(_RET_IP_, b);
99578 +#endif
99579 +
99580 }
99581 EXPORT_SYMBOL(kmem_cache_free);
99582
99583 diff --git a/mm/slub.c b/mm/slub.c
99584 index ae7b9f1..7b3fdbe 100644
99585 --- a/mm/slub.c
99586 +++ b/mm/slub.c
99587 @@ -197,7 +197,7 @@ struct track {
99588
99589 enum track_item { TRACK_ALLOC, TRACK_FREE };
99590
99591 -#ifdef CONFIG_SYSFS
99592 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99593 static int sysfs_slab_add(struct kmem_cache *);
99594 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99595 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99596 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99597 if (!t->addr)
99598 return;
99599
99600 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99601 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99602 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99603 #ifdef CONFIG_STACKTRACE
99604 {
99605 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99606
99607 slab_free_hook(s, x);
99608
99609 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99610 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99611 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99612 + if (s->ctor)
99613 + s->ctor(x);
99614 + }
99615 +#endif
99616 +
99617 redo:
99618 /*
99619 * Determine the currently cpus per cpu slab.
99620 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99621 s->inuse = size;
99622
99623 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99624 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99625 + (!(flags & SLAB_NO_SANITIZE)) ||
99626 +#endif
99627 s->ctor)) {
99628 /*
99629 * Relocate free pointer after the object if it is not
99630 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99631 EXPORT_SYMBOL(__kmalloc_node);
99632 #endif
99633
99634 +bool is_usercopy_object(const void *ptr)
99635 +{
99636 + struct page *page;
99637 + struct kmem_cache *s;
99638 +
99639 + if (ZERO_OR_NULL_PTR(ptr))
99640 + return false;
99641 +
99642 + if (!slab_is_available())
99643 + return false;
99644 +
99645 + if (!virt_addr_valid(ptr))
99646 + return false;
99647 +
99648 + page = virt_to_head_page(ptr);
99649 +
99650 + if (!PageSlab(page))
99651 + return false;
99652 +
99653 + s = page->slab_cache;
99654 + return s->flags & SLAB_USERCOPY;
99655 +}
99656 +
99657 +#ifdef CONFIG_PAX_USERCOPY
99658 +const char *check_heap_object(const void *ptr, unsigned long n)
99659 +{
99660 + struct page *page;
99661 + struct kmem_cache *s;
99662 + unsigned long offset;
99663 +
99664 + if (ZERO_OR_NULL_PTR(ptr))
99665 + return "<null>";
99666 +
99667 + if (!virt_addr_valid(ptr))
99668 + return NULL;
99669 +
99670 + page = virt_to_head_page(ptr);
99671 +
99672 + if (!PageSlab(page))
99673 + return NULL;
99674 +
99675 + s = page->slab_cache;
99676 + if (!(s->flags & SLAB_USERCOPY))
99677 + return s->name;
99678 +
99679 + offset = (ptr - page_address(page)) % s->size;
99680 + if (offset <= s->object_size && n <= s->object_size - offset)
99681 + return NULL;
99682 +
99683 + return s->name;
99684 +}
99685 +#endif
99686 +
99687 size_t ksize(const void *object)
99688 {
99689 struct page *page;
99690 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
99691 if (unlikely(ZERO_OR_NULL_PTR(x)))
99692 return;
99693
99694 + VM_BUG_ON(!virt_addr_valid(x));
99695 page = virt_to_head_page(x);
99696 if (unlikely(!PageSlab(page))) {
99697 BUG_ON(!PageCompound(page));
99698 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99699 int i;
99700 struct kmem_cache *c;
99701
99702 - s->refcount++;
99703 + atomic_inc(&s->refcount);
99704
99705 /*
99706 * Adjust the object sizes so that we clear
99707 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99708 }
99709
99710 if (sysfs_slab_alias(s, name)) {
99711 - s->refcount--;
99712 + atomic_dec(&s->refcount);
99713 s = NULL;
99714 }
99715 }
99716 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99717 }
99718 #endif
99719
99720 -#ifdef CONFIG_SYSFS
99721 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99722 static int count_inuse(struct page *page)
99723 {
99724 return page->inuse;
99725 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99726 len += sprintf(buf + len, "%7ld ", l->count);
99727
99728 if (l->addr)
99729 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99730 + len += sprintf(buf + len, "%pS", NULL);
99731 +#else
99732 len += sprintf(buf + len, "%pS", (void *)l->addr);
99733 +#endif
99734 else
99735 len += sprintf(buf + len, "<not-available>");
99736
99737 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99738 validate_slab_cache(kmalloc_caches[9]);
99739 }
99740 #else
99741 -#ifdef CONFIG_SYSFS
99742 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99743 static void resiliency_test(void) {};
99744 #endif
99745 #endif
99746
99747 -#ifdef CONFIG_SYSFS
99748 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99749 enum slab_stat_type {
99750 SL_ALL, /* All slabs */
99751 SL_PARTIAL, /* Only partially allocated slabs */
99752 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99753 {
99754 if (!s->ctor)
99755 return 0;
99756 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99757 + return sprintf(buf, "%pS\n", NULL);
99758 +#else
99759 return sprintf(buf, "%pS\n", s->ctor);
99760 +#endif
99761 }
99762 SLAB_ATTR_RO(ctor);
99763
99764 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99765 {
99766 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99767 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99768 }
99769 SLAB_ATTR_RO(aliases);
99770
99771 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99772 SLAB_ATTR_RO(cache_dma);
99773 #endif
99774
99775 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99776 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99777 +{
99778 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99779 +}
99780 +SLAB_ATTR_RO(usercopy);
99781 +#endif
99782 +
99783 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99784 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99785 +{
99786 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99787 +}
99788 +SLAB_ATTR_RO(sanitize);
99789 +#endif
99790 +
99791 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99792 {
99793 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99794 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99795 * as well as cause other issues like converting a mergeable
99796 * cache into an umergeable one.
99797 */
99798 - if (s->refcount > 1)
99799 + if (atomic_read(&s->refcount) > 1)
99800 return -EINVAL;
99801
99802 s->flags &= ~SLAB_TRACE;
99803 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99804 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99805 size_t length)
99806 {
99807 - if (s->refcount > 1)
99808 + if (atomic_read(&s->refcount) > 1)
99809 return -EINVAL;
99810
99811 s->flags &= ~SLAB_FAILSLAB;
99812 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99813 #ifdef CONFIG_ZONE_DMA
99814 &cache_dma_attr.attr,
99815 #endif
99816 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99817 + &usercopy_attr.attr,
99818 +#endif
99819 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99820 + &sanitize_attr.attr,
99821 +#endif
99822 #ifdef CONFIG_NUMA
99823 &remote_node_defrag_ratio_attr.attr,
99824 #endif
99825 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
99826 return name;
99827 }
99828
99829 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99830 static int sysfs_slab_add(struct kmem_cache *s)
99831 {
99832 int err;
99833 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99834 kobject_del(&s->kobj);
99835 kobject_put(&s->kobj);
99836 }
99837 +#endif
99838
99839 /*
99840 * Need to buffer aliases during bootup until sysfs becomes
99841 @@ -5154,6 +5251,7 @@ struct saved_alias {
99842
99843 static struct saved_alias *alias_list;
99844
99845 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99846 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99847 {
99848 struct saved_alias *al;
99849 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99850 alias_list = al;
99851 return 0;
99852 }
99853 +#endif
99854
99855 static int __init slab_sysfs_init(void)
99856 {
99857 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99858 index 4cba9c2..b4f9fcc 100644
99859 --- a/mm/sparse-vmemmap.c
99860 +++ b/mm/sparse-vmemmap.c
99861 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99862 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99863 if (!p)
99864 return NULL;
99865 - pud_populate(&init_mm, pud, p);
99866 + pud_populate_kernel(&init_mm, pud, p);
99867 }
99868 return pud;
99869 }
99870 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99871 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99872 if (!p)
99873 return NULL;
99874 - pgd_populate(&init_mm, pgd, p);
99875 + pgd_populate_kernel(&init_mm, pgd, p);
99876 }
99877 return pgd;
99878 }
99879 diff --git a/mm/sparse.c b/mm/sparse.c
99880 index d1b48b6..6e8590e 100644
99881 --- a/mm/sparse.c
99882 +++ b/mm/sparse.c
99883 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99884
99885 for (i = 0; i < PAGES_PER_SECTION; i++) {
99886 if (PageHWPoison(&memmap[i])) {
99887 - atomic_long_sub(1, &num_poisoned_pages);
99888 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
99889 ClearPageHWPoison(&memmap[i]);
99890 }
99891 }
99892 diff --git a/mm/swap.c b/mm/swap.c
99893 index 8a12b33..7068e78 100644
99894 --- a/mm/swap.c
99895 +++ b/mm/swap.c
99896 @@ -31,6 +31,7 @@
99897 #include <linux/memcontrol.h>
99898 #include <linux/gfp.h>
99899 #include <linux/uio.h>
99900 +#include <linux/hugetlb.h>
99901
99902 #include "internal.h"
99903
99904 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99905
99906 __page_cache_release(page);
99907 dtor = get_compound_page_dtor(page);
99908 + if (!PageHuge(page))
99909 + BUG_ON(dtor != free_compound_page);
99910 (*dtor)(page);
99911 }
99912
99913 diff --git a/mm/swapfile.c b/mm/swapfile.c
99914 index 8798b2e..348f9dd 100644
99915 --- a/mm/swapfile.c
99916 +++ b/mm/swapfile.c
99917 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99918
99919 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99920 /* Activity counter to indicate that a swapon or swapoff has occurred */
99921 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
99922 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99923
99924 static inline unsigned char swap_count(unsigned char ent)
99925 {
99926 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99927 spin_unlock(&swap_lock);
99928
99929 err = 0;
99930 - atomic_inc(&proc_poll_event);
99931 + atomic_inc_unchecked(&proc_poll_event);
99932 wake_up_interruptible(&proc_poll_wait);
99933
99934 out_dput:
99935 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99936
99937 poll_wait(file, &proc_poll_wait, wait);
99938
99939 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
99940 - seq->poll_event = atomic_read(&proc_poll_event);
99941 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99942 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99943 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99944 }
99945
99946 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99947 return ret;
99948
99949 seq = file->private_data;
99950 - seq->poll_event = atomic_read(&proc_poll_event);
99951 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99952 return 0;
99953 }
99954
99955 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99956 (frontswap_map) ? "FS" : "");
99957
99958 mutex_unlock(&swapon_mutex);
99959 - atomic_inc(&proc_poll_event);
99960 + atomic_inc_unchecked(&proc_poll_event);
99961 wake_up_interruptible(&proc_poll_wait);
99962
99963 if (S_ISREG(inode->i_mode))
99964 diff --git a/mm/util.c b/mm/util.c
99965 index fec39d4..3e60325 100644
99966 --- a/mm/util.c
99967 +++ b/mm/util.c
99968 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
99969 void arch_pick_mmap_layout(struct mm_struct *mm)
99970 {
99971 mm->mmap_base = TASK_UNMAPPED_BASE;
99972 +
99973 +#ifdef CONFIG_PAX_RANDMMAP
99974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
99975 + mm->mmap_base += mm->delta_mmap;
99976 +#endif
99977 +
99978 mm->get_unmapped_area = arch_get_unmapped_area;
99979 }
99980 #endif
99981 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99982 if (!mm->arg_end)
99983 goto out_mm; /* Shh! No looking before we're done */
99984
99985 + if (gr_acl_handle_procpidmem(task))
99986 + goto out_mm;
99987 +
99988 len = mm->arg_end - mm->arg_start;
99989
99990 if (len > buflen)
99991 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99992 index 90520af..24231aa 100644
99993 --- a/mm/vmalloc.c
99994 +++ b/mm/vmalloc.c
99995 @@ -40,6 +40,21 @@ struct vfree_deferred {
99996 };
99997 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99998
99999 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100000 +struct stack_deferred_llist {
100001 + struct llist_head list;
100002 + void *stack;
100003 + void *lowmem_stack;
100004 +};
100005 +
100006 +struct stack_deferred {
100007 + struct stack_deferred_llist list;
100008 + struct work_struct wq;
100009 +};
100010 +
100011 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100012 +#endif
100013 +
100014 static void __vunmap(const void *, int);
100015
100016 static void free_work(struct work_struct *w)
100017 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100018 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100019 struct llist_node *llnode = llist_del_all(&p->list);
100020 while (llnode) {
100021 - void *p = llnode;
100022 + void *x = llnode;
100023 llnode = llist_next(llnode);
100024 - __vunmap(p, 1);
100025 + __vunmap(x, 1);
100026 }
100027 }
100028
100029 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100030 +static void unmap_work(struct work_struct *w)
100031 +{
100032 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100033 + struct llist_node *llnode = llist_del_all(&p->list.list);
100034 + while (llnode) {
100035 + struct stack_deferred_llist *x =
100036 + llist_entry((struct llist_head *)llnode,
100037 + struct stack_deferred_llist, list);
100038 + void *stack = ACCESS_ONCE(x->stack);
100039 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100040 + llnode = llist_next(llnode);
100041 + __vunmap(stack, 0);
100042 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100043 + }
100044 +}
100045 +#endif
100046 +
100047 /*** Page table manipulation functions ***/
100048
100049 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100050 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100051
100052 pte = pte_offset_kernel(pmd, addr);
100053 do {
100054 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100055 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100056 +
100057 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100058 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100059 + BUG_ON(!pte_exec(*pte));
100060 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100061 + continue;
100062 + }
100063 +#endif
100064 +
100065 + {
100066 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100067 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100068 + }
100069 } while (pte++, addr += PAGE_SIZE, addr != end);
100070 }
100071
100072 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100073 pte = pte_alloc_kernel(pmd, addr);
100074 if (!pte)
100075 return -ENOMEM;
100076 +
100077 + pax_open_kernel();
100078 do {
100079 struct page *page = pages[*nr];
100080
100081 - if (WARN_ON(!pte_none(*pte)))
100082 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100083 + if (pgprot_val(prot) & _PAGE_NX)
100084 +#endif
100085 +
100086 + if (!pte_none(*pte)) {
100087 + pax_close_kernel();
100088 + WARN_ON(1);
100089 return -EBUSY;
100090 - if (WARN_ON(!page))
100091 + }
100092 + if (!page) {
100093 + pax_close_kernel();
100094 + WARN_ON(1);
100095 return -ENOMEM;
100096 + }
100097 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100098 (*nr)++;
100099 } while (pte++, addr += PAGE_SIZE, addr != end);
100100 + pax_close_kernel();
100101 return 0;
100102 }
100103
100104 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100105 pmd_t *pmd;
100106 unsigned long next;
100107
100108 - pmd = pmd_alloc(&init_mm, pud, addr);
100109 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100110 if (!pmd)
100111 return -ENOMEM;
100112 do {
100113 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100114 pud_t *pud;
100115 unsigned long next;
100116
100117 - pud = pud_alloc(&init_mm, pgd, addr);
100118 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100119 if (!pud)
100120 return -ENOMEM;
100121 do {
100122 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100123 if (addr >= MODULES_VADDR && addr < MODULES_END)
100124 return 1;
100125 #endif
100126 +
100127 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100128 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100129 + return 1;
100130 +#endif
100131 +
100132 return is_vmalloc_addr(x);
100133 }
100134
100135 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100136
100137 if (!pgd_none(*pgd)) {
100138 pud_t *pud = pud_offset(pgd, addr);
100139 +#ifdef CONFIG_X86
100140 + if (!pud_large(*pud))
100141 +#endif
100142 if (!pud_none(*pud)) {
100143 pmd_t *pmd = pmd_offset(pud, addr);
100144 +#ifdef CONFIG_X86
100145 + if (!pmd_large(*pmd))
100146 +#endif
100147 if (!pmd_none(*pmd)) {
100148 pte_t *ptep, pte;
100149
100150 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100151 for_each_possible_cpu(i) {
100152 struct vmap_block_queue *vbq;
100153 struct vfree_deferred *p;
100154 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100155 + struct stack_deferred *p2;
100156 +#endif
100157
100158 vbq = &per_cpu(vmap_block_queue, i);
100159 spin_lock_init(&vbq->lock);
100160 INIT_LIST_HEAD(&vbq->free);
100161 +
100162 p = &per_cpu(vfree_deferred, i);
100163 init_llist_head(&p->list);
100164 INIT_WORK(&p->wq, free_work);
100165 +
100166 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100167 + p2 = &per_cpu(stack_deferred, i);
100168 + init_llist_head(&p2->list.list);
100169 + INIT_WORK(&p2->wq, unmap_work);
100170 +#endif
100171 }
100172
100173 /* Import existing vmlist entries. */
100174 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100175 struct vm_struct *area;
100176
100177 BUG_ON(in_interrupt());
100178 +
100179 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100180 + if (flags & VM_KERNEXEC) {
100181 + if (start != VMALLOC_START || end != VMALLOC_END)
100182 + return NULL;
100183 + start = (unsigned long)MODULES_EXEC_VADDR;
100184 + end = (unsigned long)MODULES_EXEC_END;
100185 + }
100186 +#endif
100187 +
100188 if (flags & VM_IOREMAP)
100189 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100190
100191 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100192 }
100193 EXPORT_SYMBOL(vunmap);
100194
100195 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100196 +void unmap_process_stacks(struct task_struct *task)
100197 +{
100198 + if (unlikely(in_interrupt())) {
100199 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100200 + struct stack_deferred_llist *list = task->stack;
100201 + list->stack = task->stack;
100202 + list->lowmem_stack = task->lowmem_stack;
100203 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100204 + schedule_work(&p->wq);
100205 + } else {
100206 + __vunmap(task->stack, 0);
100207 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100208 + }
100209 +}
100210 +#endif
100211 +
100212 /**
100213 * vmap - map an array of pages into virtually contiguous space
100214 * @pages: array of page pointers
100215 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100216 if (count > totalram_pages)
100217 return NULL;
100218
100219 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100220 + if (!(pgprot_val(prot) & _PAGE_NX))
100221 + flags |= VM_KERNEXEC;
100222 +#endif
100223 +
100224 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100225 __builtin_return_address(0));
100226 if (!area)
100227 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100228 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100229 goto fail;
100230
100231 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100232 + if (!(pgprot_val(prot) & _PAGE_NX))
100233 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100234 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100235 + else
100236 +#endif
100237 +
100238 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100239 start, end, node, gfp_mask, caller);
100240 if (!area)
100241 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100242 * For tight control over page level allocator and protection flags
100243 * use __vmalloc() instead.
100244 */
100245 -
100246 void *vmalloc_exec(unsigned long size)
100247 {
100248 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100249 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100250 NUMA_NO_NODE, __builtin_return_address(0));
100251 }
100252
100253 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100254 {
100255 struct vm_struct *area;
100256
100257 + BUG_ON(vma->vm_mirror);
100258 +
100259 size = PAGE_ALIGN(size);
100260
100261 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100262 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100263 v->addr, v->addr + v->size, v->size);
100264
100265 if (v->caller)
100266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100267 + seq_printf(m, " %pK", v->caller);
100268 +#else
100269 seq_printf(m, " %pS", v->caller);
100270 +#endif
100271
100272 if (v->nr_pages)
100273 seq_printf(m, " pages=%d", v->nr_pages);
100274 diff --git a/mm/vmstat.c b/mm/vmstat.c
100275 index 1b12d39..57b29b2 100644
100276 --- a/mm/vmstat.c
100277 +++ b/mm/vmstat.c
100278 @@ -22,6 +22,7 @@
100279 #include <linux/writeback.h>
100280 #include <linux/compaction.h>
100281 #include <linux/mm_inline.h>
100282 +#include <linux/grsecurity.h>
100283
100284 #include "internal.h"
100285
100286 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100287 *
100288 * vm_stat contains the global counters
100289 */
100290 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100291 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100292 EXPORT_SYMBOL(vm_stat);
100293
100294 #ifdef CONFIG_SMP
100295 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100296
100297 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100298 if (diff[i]) {
100299 - atomic_long_add(diff[i], &vm_stat[i]);
100300 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100301 changes++;
100302 }
100303 return changes;
100304 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100305 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100306 if (v) {
100307
100308 - atomic_long_add(v, &zone->vm_stat[i]);
100309 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100310 global_diff[i] += v;
100311 #ifdef CONFIG_NUMA
100312 /* 3 seconds idle till flush */
100313 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100314
100315 v = p->vm_stat_diff[i];
100316 p->vm_stat_diff[i] = 0;
100317 - atomic_long_add(v, &zone->vm_stat[i]);
100318 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100319 global_diff[i] += v;
100320 }
100321 }
100322 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100323 if (pset->vm_stat_diff[i]) {
100324 int v = pset->vm_stat_diff[i];
100325 pset->vm_stat_diff[i] = 0;
100326 - atomic_long_add(v, &zone->vm_stat[i]);
100327 - atomic_long_add(v, &vm_stat[i]);
100328 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100329 + atomic_long_add_unchecked(v, &vm_stat[i]);
100330 }
100331 }
100332 #endif
100333 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100334 stat_items_size += sizeof(struct vm_event_state);
100335 #endif
100336
100337 - v = kmalloc(stat_items_size, GFP_KERNEL);
100338 + v = kzalloc(stat_items_size, GFP_KERNEL);
100339 m->private = v;
100340 if (!v)
100341 return ERR_PTR(-ENOMEM);
100342 +
100343 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100344 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100345 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100346 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100347 + && !in_group_p(grsec_proc_gid)
100348 +#endif
100349 + )
100350 + return (unsigned long *)m->private + *pos;
100351 +#endif
100352 +#endif
100353 +
100354 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100355 v[i] = global_page_state(i);
100356 v += NR_VM_ZONE_STAT_ITEMS;
100357 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100358 cpu_notifier_register_done();
100359 #endif
100360 #ifdef CONFIG_PROC_FS
100361 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100362 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100363 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100364 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100365 + {
100366 + mode_t gr_mode = S_IRUGO;
100367 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100368 + gr_mode = S_IRUSR;
100369 +#endif
100370 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100371 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100372 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100373 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100374 + }
100375 #endif
100376 return 0;
100377 }
100378 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100379 index 64c6bed..b79a5de 100644
100380 --- a/net/8021q/vlan.c
100381 +++ b/net/8021q/vlan.c
100382 @@ -481,7 +481,7 @@ out:
100383 return NOTIFY_DONE;
100384 }
100385
100386 -static struct notifier_block vlan_notifier_block __read_mostly = {
100387 +static struct notifier_block vlan_notifier_block = {
100388 .notifier_call = vlan_device_event,
100389 };
100390
100391 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100392 err = -EPERM;
100393 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100394 break;
100395 - if ((args.u.name_type >= 0) &&
100396 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100397 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100398 struct vlan_net *vn;
100399
100400 vn = net_generic(net, vlan_net_id);
100401 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100402 index 8ac8a5c..991defc 100644
100403 --- a/net/8021q/vlan_netlink.c
100404 +++ b/net/8021q/vlan_netlink.c
100405 @@ -238,7 +238,7 @@ nla_put_failure:
100406 return -EMSGSIZE;
100407 }
100408
100409 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100410 +struct rtnl_link_ops vlan_link_ops = {
100411 .kind = "vlan",
100412 .maxtype = IFLA_VLAN_MAX,
100413 .policy = vlan_policy,
100414 diff --git a/net/9p/client.c b/net/9p/client.c
100415 index e86a9bea..e91f70e 100644
100416 --- a/net/9p/client.c
100417 +++ b/net/9p/client.c
100418 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100419 len - inline_len);
100420 } else {
100421 err = copy_from_user(ename + inline_len,
100422 - uidata, len - inline_len);
100423 + (char __force_user *)uidata, len - inline_len);
100424 if (err) {
100425 err = -EFAULT;
100426 goto out_err;
100427 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100428 kernel_buf = 1;
100429 indata = data;
100430 } else
100431 - indata = (__force char *)udata;
100432 + indata = (__force_kernel char *)udata;
100433 /*
100434 * response header len is 11
100435 * PDU Header(7) + IO Size (4)
100436 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100437 kernel_buf = 1;
100438 odata = data;
100439 } else
100440 - odata = (char *)udata;
100441 + odata = (char __force_kernel *)udata;
100442 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100443 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100444 fid->fid, offset, rsize);
100445 diff --git a/net/9p/mod.c b/net/9p/mod.c
100446 index 6ab36ae..6f1841b 100644
100447 --- a/net/9p/mod.c
100448 +++ b/net/9p/mod.c
100449 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100450 void v9fs_register_trans(struct p9_trans_module *m)
100451 {
100452 spin_lock(&v9fs_trans_lock);
100453 - list_add_tail(&m->list, &v9fs_trans_list);
100454 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100455 spin_unlock(&v9fs_trans_lock);
100456 }
100457 EXPORT_SYMBOL(v9fs_register_trans);
100458 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100459 void v9fs_unregister_trans(struct p9_trans_module *m)
100460 {
100461 spin_lock(&v9fs_trans_lock);
100462 - list_del_init(&m->list);
100463 + pax_list_del_init((struct list_head *)&m->list);
100464 spin_unlock(&v9fs_trans_lock);
100465 }
100466 EXPORT_SYMBOL(v9fs_unregister_trans);
100467 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100468 index 80d08f6..de63fd1 100644
100469 --- a/net/9p/trans_fd.c
100470 +++ b/net/9p/trans_fd.c
100471 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100472 oldfs = get_fs();
100473 set_fs(get_ds());
100474 /* The cast to a user pointer is valid due to the set_fs() */
100475 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100476 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100477 set_fs(oldfs);
100478
100479 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100480 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100481 index af46bc4..f9adfcd 100644
100482 --- a/net/appletalk/atalk_proc.c
100483 +++ b/net/appletalk/atalk_proc.c
100484 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100485 struct proc_dir_entry *p;
100486 int rc = -ENOMEM;
100487
100488 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100489 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100490 if (!atalk_proc_dir)
100491 goto out;
100492
100493 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100494 index 876fbe8..8bbea9f 100644
100495 --- a/net/atm/atm_misc.c
100496 +++ b/net/atm/atm_misc.c
100497 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100498 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100499 return 1;
100500 atm_return(vcc, truesize);
100501 - atomic_inc(&vcc->stats->rx_drop);
100502 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100503 return 0;
100504 }
100505 EXPORT_SYMBOL(atm_charge);
100506 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100507 }
100508 }
100509 atm_return(vcc, guess);
100510 - atomic_inc(&vcc->stats->rx_drop);
100511 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100512 return NULL;
100513 }
100514 EXPORT_SYMBOL(atm_alloc_charge);
100515 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100516
100517 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100518 {
100519 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100520 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100521 __SONET_ITEMS
100522 #undef __HANDLE_ITEM
100523 }
100524 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100525
100526 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100527 {
100528 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100529 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100530 __SONET_ITEMS
100531 #undef __HANDLE_ITEM
100532 }
100533 diff --git a/net/atm/lec.c b/net/atm/lec.c
100534 index 4b98f89..5a2f6cb 100644
100535 --- a/net/atm/lec.c
100536 +++ b/net/atm/lec.c
100537 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100538 }
100539
100540 static struct lane2_ops lane2_ops = {
100541 - lane2_resolve, /* resolve, spec 3.1.3 */
100542 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100543 - NULL /* associate indicator, spec 3.1.5 */
100544 + .resolve = lane2_resolve,
100545 + .associate_req = lane2_associate_req,
100546 + .associate_indicator = NULL
100547 };
100548
100549 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100550 diff --git a/net/atm/lec.h b/net/atm/lec.h
100551 index 4149db1..f2ab682 100644
100552 --- a/net/atm/lec.h
100553 +++ b/net/atm/lec.h
100554 @@ -48,7 +48,7 @@ struct lane2_ops {
100555 const u8 *tlvs, u32 sizeoftlvs);
100556 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100557 const u8 *tlvs, u32 sizeoftlvs);
100558 -};
100559 +} __no_const;
100560
100561 /*
100562 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100563 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100564 index d1b2d9a..d549f7f 100644
100565 --- a/net/atm/mpoa_caches.c
100566 +++ b/net/atm/mpoa_caches.c
100567 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100568
100569
100570 static struct in_cache_ops ingress_ops = {
100571 - in_cache_add_entry, /* add_entry */
100572 - in_cache_get, /* get */
100573 - in_cache_get_with_mask, /* get_with_mask */
100574 - in_cache_get_by_vcc, /* get_by_vcc */
100575 - in_cache_put, /* put */
100576 - in_cache_remove_entry, /* remove_entry */
100577 - cache_hit, /* cache_hit */
100578 - clear_count_and_expired, /* clear_count */
100579 - check_resolving_entries, /* check_resolving */
100580 - refresh_entries, /* refresh */
100581 - in_destroy_cache /* destroy_cache */
100582 + .add_entry = in_cache_add_entry,
100583 + .get = in_cache_get,
100584 + .get_with_mask = in_cache_get_with_mask,
100585 + .get_by_vcc = in_cache_get_by_vcc,
100586 + .put = in_cache_put,
100587 + .remove_entry = in_cache_remove_entry,
100588 + .cache_hit = cache_hit,
100589 + .clear_count = clear_count_and_expired,
100590 + .check_resolving = check_resolving_entries,
100591 + .refresh = refresh_entries,
100592 + .destroy_cache = in_destroy_cache
100593 };
100594
100595 static struct eg_cache_ops egress_ops = {
100596 - eg_cache_add_entry, /* add_entry */
100597 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100598 - eg_cache_get_by_tag, /* get_by_tag */
100599 - eg_cache_get_by_vcc, /* get_by_vcc */
100600 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100601 - eg_cache_put, /* put */
100602 - eg_cache_remove_entry, /* remove_entry */
100603 - update_eg_cache_entry, /* update */
100604 - clear_expired, /* clear_expired */
100605 - eg_destroy_cache /* destroy_cache */
100606 + .add_entry = eg_cache_add_entry,
100607 + .get_by_cache_id = eg_cache_get_by_cache_id,
100608 + .get_by_tag = eg_cache_get_by_tag,
100609 + .get_by_vcc = eg_cache_get_by_vcc,
100610 + .get_by_src_ip = eg_cache_get_by_src_ip,
100611 + .put = eg_cache_put,
100612 + .remove_entry = eg_cache_remove_entry,
100613 + .update = update_eg_cache_entry,
100614 + .clear_expired = clear_expired,
100615 + .destroy_cache = eg_destroy_cache
100616 };
100617
100618
100619 diff --git a/net/atm/proc.c b/net/atm/proc.c
100620 index bbb6461..cf04016 100644
100621 --- a/net/atm/proc.c
100622 +++ b/net/atm/proc.c
100623 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100624 const struct k_atm_aal_stats *stats)
100625 {
100626 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100627 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100628 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100629 - atomic_read(&stats->rx_drop));
100630 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100631 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100632 + atomic_read_unchecked(&stats->rx_drop));
100633 }
100634
100635 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100636 diff --git a/net/atm/resources.c b/net/atm/resources.c
100637 index 0447d5d..3cf4728 100644
100638 --- a/net/atm/resources.c
100639 +++ b/net/atm/resources.c
100640 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100641 static void copy_aal_stats(struct k_atm_aal_stats *from,
100642 struct atm_aal_stats *to)
100643 {
100644 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100645 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100646 __AAL_STAT_ITEMS
100647 #undef __HANDLE_ITEM
100648 }
100649 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100650 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100651 struct atm_aal_stats *to)
100652 {
100653 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100654 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100655 __AAL_STAT_ITEMS
100656 #undef __HANDLE_ITEM
100657 }
100658 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100659 index 919a5ce..cc6b444 100644
100660 --- a/net/ax25/sysctl_net_ax25.c
100661 +++ b/net/ax25/sysctl_net_ax25.c
100662 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100663 {
100664 char path[sizeof("net/ax25/") + IFNAMSIZ];
100665 int k;
100666 - struct ctl_table *table;
100667 + ctl_table_no_const *table;
100668
100669 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100670 if (!table)
100671 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100672 index 1e80539..676c37a 100644
100673 --- a/net/batman-adv/bat_iv_ogm.c
100674 +++ b/net/batman-adv/bat_iv_ogm.c
100675 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100676
100677 /* randomize initial seqno to avoid collision */
100678 get_random_bytes(&random_seqno, sizeof(random_seqno));
100679 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100680 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100681
100682 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100683 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100684 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100685 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100686
100687 /* change sequence number to network order */
100688 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100689 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100690 batadv_ogm_packet->seqno = htonl(seqno);
100691 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100692 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100693
100694 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100695
100696 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100697 return;
100698
100699 /* could be changed by schedule_own_packet() */
100700 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100701 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100702
100703 if (ogm_packet->flags & BATADV_DIRECTLINK)
100704 has_directlink_flag = true;
100705 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100706 index 00f9e14..e1c7203 100644
100707 --- a/net/batman-adv/fragmentation.c
100708 +++ b/net/batman-adv/fragmentation.c
100709 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100710 frag_header.packet_type = BATADV_UNICAST_FRAG;
100711 frag_header.version = BATADV_COMPAT_VERSION;
100712 frag_header.ttl = BATADV_TTL;
100713 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100714 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100715 frag_header.reserved = 0;
100716 frag_header.no = 0;
100717 frag_header.total_size = htons(skb->len);
100718 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100719 index 5467955..75ad4e3 100644
100720 --- a/net/batman-adv/soft-interface.c
100721 +++ b/net/batman-adv/soft-interface.c
100722 @@ -296,7 +296,7 @@ send:
100723 primary_if->net_dev->dev_addr);
100724
100725 /* set broadcast sequence number */
100726 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100727 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100728 bcast_packet->seqno = htonl(seqno);
100729
100730 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100731 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100732 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100733
100734 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100735 - atomic_set(&bat_priv->bcast_seqno, 1);
100736 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100737 atomic_set(&bat_priv->tt.vn, 0);
100738 atomic_set(&bat_priv->tt.local_changes, 0);
100739 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100740 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100741
100742 /* randomize initial seqno to avoid collision */
100743 get_random_bytes(&random_seqno, sizeof(random_seqno));
100744 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100745 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100746
100747 bat_priv->primary_if = NULL;
100748 bat_priv->num_ifaces = 0;
100749 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100750 return 0;
100751 }
100752
100753 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
100754 +struct rtnl_link_ops batadv_link_ops = {
100755 .kind = "batadv",
100756 .priv_size = sizeof(struct batadv_priv),
100757 .setup = batadv_softif_init_early,
100758 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100759 index 8854c05..ee5d5497 100644
100760 --- a/net/batman-adv/types.h
100761 +++ b/net/batman-adv/types.h
100762 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100763 struct batadv_hard_iface_bat_iv {
100764 unsigned char *ogm_buff;
100765 int ogm_buff_len;
100766 - atomic_t ogm_seqno;
100767 + atomic_unchecked_t ogm_seqno;
100768 };
100769
100770 /**
100771 @@ -768,7 +768,7 @@ struct batadv_priv {
100772 atomic_t bonding;
100773 atomic_t fragmentation;
100774 atomic_t packet_size_max;
100775 - atomic_t frag_seqno;
100776 + atomic_unchecked_t frag_seqno;
100777 #ifdef CONFIG_BATMAN_ADV_BLA
100778 atomic_t bridge_loop_avoidance;
100779 #endif
100780 @@ -787,7 +787,7 @@ struct batadv_priv {
100781 #endif
100782 uint32_t isolation_mark;
100783 uint32_t isolation_mark_mask;
100784 - atomic_t bcast_seqno;
100785 + atomic_unchecked_t bcast_seqno;
100786 atomic_t bcast_queue_left;
100787 atomic_t batman_queue_left;
100788 char num_ifaces;
100789 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100790 index cfbb39e..0bbfc9d 100644
100791 --- a/net/bluetooth/6lowpan.c
100792 +++ b/net/bluetooth/6lowpan.c
100793 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100794
100795 drop:
100796 dev->stats.rx_dropped++;
100797 - kfree_skb(skb);
100798 return NET_RX_DROP;
100799 }
100800
100801 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100802 index 85bcc21..ce82722d 100644
100803 --- a/net/bluetooth/bnep/core.c
100804 +++ b/net/bluetooth/bnep/core.c
100805 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100806
100807 BT_DBG("");
100808
100809 + if (!l2cap_is_socket(sock))
100810 + return -EBADFD;
100811 +
100812 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100813 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100814
100815 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
100816 index 67fe5e8..278a194 100644
100817 --- a/net/bluetooth/cmtp/core.c
100818 +++ b/net/bluetooth/cmtp/core.c
100819 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
100820
100821 BT_DBG("");
100822
100823 + if (!l2cap_is_socket(sock))
100824 + return -EBADFD;
100825 +
100826 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
100827 if (!session)
100828 return -ENOMEM;
100829 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100830 index 115f149..f0ba286 100644
100831 --- a/net/bluetooth/hci_sock.c
100832 +++ b/net/bluetooth/hci_sock.c
100833 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100834 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100835 }
100836
100837 - len = min_t(unsigned int, len, sizeof(uf));
100838 + len = min((size_t)len, sizeof(uf));
100839 if (copy_from_user(&uf, optval, len)) {
100840 err = -EFAULT;
100841 break;
100842 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
100843 index 1b7d605..02ebd10 100644
100844 --- a/net/bluetooth/hidp/core.c
100845 +++ b/net/bluetooth/hidp/core.c
100846 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
100847 {
100848 struct hidp_session *session;
100849 struct l2cap_conn *conn;
100850 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
100851 + struct l2cap_chan *chan;
100852 int ret;
100853
100854 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
100855 if (ret)
100856 return ret;
100857
100858 + chan = l2cap_pi(ctrl_sock->sk)->chan;
100859 conn = NULL;
100860 l2cap_chan_lock(chan);
100861 if (chan->conn)
100862 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100863 index b6f9777..36d3039 100644
100864 --- a/net/bluetooth/l2cap_core.c
100865 +++ b/net/bluetooth/l2cap_core.c
100866 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100867 break;
100868
100869 case L2CAP_CONF_RFC:
100870 - if (olen == sizeof(rfc))
100871 - memcpy(&rfc, (void *)val, olen);
100872 + if (olen != sizeof(rfc))
100873 + break;
100874 +
100875 + memcpy(&rfc, (void *)val, olen);
100876
100877 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100878 rfc.mode != chan->mode)
100879 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100880 index 31f106e..323f606 100644
100881 --- a/net/bluetooth/l2cap_sock.c
100882 +++ b/net/bluetooth/l2cap_sock.c
100883 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100884 struct sock *sk = sock->sk;
100885 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100886 struct l2cap_options opts;
100887 - int len, err = 0;
100888 + int err = 0;
100889 + size_t len = optlen;
100890 u32 opt;
100891
100892 BT_DBG("sk %p", sk);
100893 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100894 opts.max_tx = chan->max_tx;
100895 opts.txwin_size = chan->tx_win;
100896
100897 - len = min_t(unsigned int, sizeof(opts), optlen);
100898 + len = min(sizeof(opts), len);
100899 if (copy_from_user((char *) &opts, optval, len)) {
100900 err = -EFAULT;
100901 break;
100902 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100903 struct bt_security sec;
100904 struct bt_power pwr;
100905 struct l2cap_conn *conn;
100906 - int len, err = 0;
100907 + int err = 0;
100908 + size_t len = optlen;
100909 u32 opt;
100910
100911 BT_DBG("sk %p", sk);
100912 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100913
100914 sec.level = BT_SECURITY_LOW;
100915
100916 - len = min_t(unsigned int, sizeof(sec), optlen);
100917 + len = min(sizeof(sec), len);
100918 if (copy_from_user((char *) &sec, optval, len)) {
100919 err = -EFAULT;
100920 break;
100921 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100922
100923 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100924
100925 - len = min_t(unsigned int, sizeof(pwr), optlen);
100926 + len = min(sizeof(pwr), len);
100927 if (copy_from_user((char *) &pwr, optval, len)) {
100928 err = -EFAULT;
100929 break;
100930 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100931 index 8bbbb5e..6fc0950 100644
100932 --- a/net/bluetooth/rfcomm/sock.c
100933 +++ b/net/bluetooth/rfcomm/sock.c
100934 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100935 struct sock *sk = sock->sk;
100936 struct bt_security sec;
100937 int err = 0;
100938 - size_t len;
100939 + size_t len = optlen;
100940 u32 opt;
100941
100942 BT_DBG("sk %p", sk);
100943 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100944
100945 sec.level = BT_SECURITY_LOW;
100946
100947 - len = min_t(unsigned int, sizeof(sec), optlen);
100948 + len = min(sizeof(sec), len);
100949 if (copy_from_user((char *) &sec, optval, len)) {
100950 err = -EFAULT;
100951 break;
100952 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100953 index 8e385a0..a5bdd8e 100644
100954 --- a/net/bluetooth/rfcomm/tty.c
100955 +++ b/net/bluetooth/rfcomm/tty.c
100956 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100957 BT_DBG("tty %p id %d", tty, tty->index);
100958
100959 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100960 - dev->channel, dev->port.count);
100961 + dev->channel, atomic_read(&dev->port.count));
100962
100963 err = tty_port_open(&dev->port, tty, filp);
100964 if (err)
100965 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100966 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100967
100968 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100969 - dev->port.count);
100970 + atomic_read(&dev->port.count));
100971
100972 tty_port_close(&dev->port, tty, filp);
100973 }
100974 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
100975 index e5ec470..cbfabd1 100644
100976 --- a/net/bridge/br_netlink.c
100977 +++ b/net/bridge/br_netlink.c
100978 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
100979 .get_link_af_size = br_get_link_af_size,
100980 };
100981
100982 -struct rtnl_link_ops br_link_ops __read_mostly = {
100983 +struct rtnl_link_ops br_link_ops = {
100984 .kind = "bridge",
100985 .priv_size = sizeof(struct net_bridge),
100986 .setup = br_dev_setup,
100987 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100988 index d9a8c05..8dadc6c6 100644
100989 --- a/net/bridge/netfilter/ebtables.c
100990 +++ b/net/bridge/netfilter/ebtables.c
100991 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100992 tmp.valid_hooks = t->table->valid_hooks;
100993 }
100994 mutex_unlock(&ebt_mutex);
100995 - if (copy_to_user(user, &tmp, *len) != 0) {
100996 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100997 BUGPRINT("c2u Didn't work\n");
100998 ret = -EFAULT;
100999 break;
101000 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101001 goto out;
101002 tmp.valid_hooks = t->valid_hooks;
101003
101004 - if (copy_to_user(user, &tmp, *len) != 0) {
101005 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101006 ret = -EFAULT;
101007 break;
101008 }
101009 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101010 tmp.entries_size = t->table->entries_size;
101011 tmp.valid_hooks = t->table->valid_hooks;
101012
101013 - if (copy_to_user(user, &tmp, *len) != 0) {
101014 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101015 ret = -EFAULT;
101016 break;
101017 }
101018 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101019 index f5afda1..dcf770a 100644
101020 --- a/net/caif/cfctrl.c
101021 +++ b/net/caif/cfctrl.c
101022 @@ -10,6 +10,7 @@
101023 #include <linux/spinlock.h>
101024 #include <linux/slab.h>
101025 #include <linux/pkt_sched.h>
101026 +#include <linux/sched.h>
101027 #include <net/caif/caif_layer.h>
101028 #include <net/caif/cfpkt.h>
101029 #include <net/caif/cfctrl.h>
101030 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101031 memset(&dev_info, 0, sizeof(dev_info));
101032 dev_info.id = 0xff;
101033 cfsrvl_init(&this->serv, 0, &dev_info, false);
101034 - atomic_set(&this->req_seq_no, 1);
101035 - atomic_set(&this->rsp_seq_no, 1);
101036 + atomic_set_unchecked(&this->req_seq_no, 1);
101037 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101038 this->serv.layer.receive = cfctrl_recv;
101039 sprintf(this->serv.layer.name, "ctrl");
101040 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101041 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101042 struct cfctrl_request_info *req)
101043 {
101044 spin_lock_bh(&ctrl->info_list_lock);
101045 - atomic_inc(&ctrl->req_seq_no);
101046 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101047 + atomic_inc_unchecked(&ctrl->req_seq_no);
101048 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101049 list_add_tail(&req->list, &ctrl->list);
101050 spin_unlock_bh(&ctrl->info_list_lock);
101051 }
101052 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101053 if (p != first)
101054 pr_warn("Requests are not received in order\n");
101055
101056 - atomic_set(&ctrl->rsp_seq_no,
101057 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101058 p->sequence_no);
101059 list_del(&p->list);
101060 goto out;
101061 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101062 index 4589ff67..46d6b8f 100644
101063 --- a/net/caif/chnl_net.c
101064 +++ b/net/caif/chnl_net.c
101065 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101066 };
101067
101068
101069 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101070 +static struct rtnl_link_ops ipcaif_link_ops = {
101071 .kind = "caif",
101072 .priv_size = sizeof(struct chnl_net),
101073 .setup = ipcaif_net_setup,
101074 diff --git a/net/can/af_can.c b/net/can/af_can.c
101075 index ce82337..5d17b4d 100644
101076 --- a/net/can/af_can.c
101077 +++ b/net/can/af_can.c
101078 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101079 };
101080
101081 /* notifier block for netdevice event */
101082 -static struct notifier_block can_netdev_notifier __read_mostly = {
101083 +static struct notifier_block can_netdev_notifier = {
101084 .notifier_call = can_notifier,
101085 };
101086
101087 diff --git a/net/can/bcm.c b/net/can/bcm.c
101088 index dcb75c0..24b1b43 100644
101089 --- a/net/can/bcm.c
101090 +++ b/net/can/bcm.c
101091 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101092 }
101093
101094 /* create /proc/net/can-bcm directory */
101095 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101096 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101097 return 0;
101098 }
101099
101100 diff --git a/net/can/gw.c b/net/can/gw.c
101101 index 050a211..bb9fe33 100644
101102 --- a/net/can/gw.c
101103 +++ b/net/can/gw.c
101104 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101105 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101106
101107 static HLIST_HEAD(cgw_list);
101108 -static struct notifier_block notifier;
101109
101110 static struct kmem_cache *cgw_cache __read_mostly;
101111
101112 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101113 return err;
101114 }
101115
101116 +static struct notifier_block notifier = {
101117 + .notifier_call = cgw_notifier
101118 +};
101119 +
101120 static __init int cgw_module_init(void)
101121 {
101122 /* sanitize given module parameter */
101123 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101124 return -ENOMEM;
101125
101126 /* set notifier */
101127 - notifier.notifier_call = cgw_notifier;
101128 register_netdevice_notifier(&notifier);
101129
101130 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101131 diff --git a/net/can/proc.c b/net/can/proc.c
101132 index 1a19b98..df2b4ec 100644
101133 --- a/net/can/proc.c
101134 +++ b/net/can/proc.c
101135 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101136 void can_init_proc(void)
101137 {
101138 /* create /proc/net/can directory */
101139 - can_dir = proc_mkdir("can", init_net.proc_net);
101140 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101141
101142 if (!can_dir) {
101143 printk(KERN_INFO "can: failed to create /proc/net/can . "
101144 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101145 index 8d1653c..77ad145 100644
101146 --- a/net/ceph/messenger.c
101147 +++ b/net/ceph/messenger.c
101148 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101149 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101150
101151 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101152 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101153 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101154
101155 static struct page *zero_page; /* used in certain error cases */
101156
101157 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101158 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101159 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101160
101161 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101162 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101163 s = addr_str[i];
101164
101165 switch (ss->ss_family) {
101166 diff --git a/net/compat.c b/net/compat.c
101167 index bc8aeef..f9c070c 100644
101168 --- a/net/compat.c
101169 +++ b/net/compat.c
101170 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101171 return -EFAULT;
101172 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101173 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101174 - kmsg->msg_name = compat_ptr(tmp1);
101175 - kmsg->msg_iov = compat_ptr(tmp2);
101176 - kmsg->msg_control = compat_ptr(tmp3);
101177 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101178 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101179 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101180 return 0;
101181 }
101182
101183 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101184
101185 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101186 if (mode == VERIFY_READ) {
101187 - int err = move_addr_to_kernel(kern_msg->msg_name,
101188 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101189 kern_msg->msg_namelen,
101190 kern_address);
101191 if (err < 0)
101192 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101193 }
101194
101195 tot_len = iov_from_user_compat_to_kern(kern_iov,
101196 - (struct compat_iovec __user *)kern_msg->msg_iov,
101197 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101198 kern_msg->msg_iovlen);
101199 if (tot_len >= 0)
101200 kern_msg->msg_iov = kern_iov;
101201 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101202
101203 #define CMSG_COMPAT_FIRSTHDR(msg) \
101204 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101205 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101206 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101207 (struct compat_cmsghdr __user *)NULL)
101208
101209 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101210 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101211 (ucmlen) <= (unsigned long) \
101212 ((mhdr)->msg_controllen - \
101213 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101214 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101215
101216 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101217 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101218 {
101219 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101220 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101221 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101222 msg->msg_controllen)
101223 return NULL;
101224 return (struct compat_cmsghdr __user *)ptr;
101225 @@ -223,7 +223,7 @@ Efault:
101226
101227 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101228 {
101229 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101230 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101231 struct compat_cmsghdr cmhdr;
101232 struct compat_timeval ctv;
101233 struct compat_timespec cts[3];
101234 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101235
101236 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101237 {
101238 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101239 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101240 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101241 int fdnum = scm->fp->count;
101242 struct file **fp = scm->fp->fp;
101243 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101244 return -EFAULT;
101245 old_fs = get_fs();
101246 set_fs(KERNEL_DS);
101247 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101248 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101249 set_fs(old_fs);
101250
101251 return err;
101252 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101253 len = sizeof(ktime);
101254 old_fs = get_fs();
101255 set_fs(KERNEL_DS);
101256 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101257 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101258 set_fs(old_fs);
101259
101260 if (!err) {
101261 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101262 case MCAST_JOIN_GROUP:
101263 case MCAST_LEAVE_GROUP:
101264 {
101265 - struct compat_group_req __user *gr32 = (void *)optval;
101266 + struct compat_group_req __user *gr32 = (void __user *)optval;
101267 struct group_req __user *kgr =
101268 compat_alloc_user_space(sizeof(struct group_req));
101269 u32 interface;
101270 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101271 case MCAST_BLOCK_SOURCE:
101272 case MCAST_UNBLOCK_SOURCE:
101273 {
101274 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101275 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101276 struct group_source_req __user *kgsr = compat_alloc_user_space(
101277 sizeof(struct group_source_req));
101278 u32 interface;
101279 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101280 }
101281 case MCAST_MSFILTER:
101282 {
101283 - struct compat_group_filter __user *gf32 = (void *)optval;
101284 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101285 struct group_filter __user *kgf;
101286 u32 interface, fmode, numsrc;
101287
101288 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101289 char __user *optval, int __user *optlen,
101290 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101291 {
101292 - struct compat_group_filter __user *gf32 = (void *)optval;
101293 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101294 struct group_filter __user *kgf;
101295 int __user *koptlen;
101296 u32 interface, fmode, numsrc;
101297 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101298
101299 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101300 return -EINVAL;
101301 - if (copy_from_user(a, args, nas[call]))
101302 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101303 return -EFAULT;
101304 a0 = a[0];
101305 a1 = a[1];
101306 diff --git a/net/core/datagram.c b/net/core/datagram.c
101307 index fdbc9a8..cd6972c 100644
101308 --- a/net/core/datagram.c
101309 +++ b/net/core/datagram.c
101310 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101311 }
101312
101313 kfree_skb(skb);
101314 - atomic_inc(&sk->sk_drops);
101315 + atomic_inc_unchecked(&sk->sk_drops);
101316 sk_mem_reclaim_partial(sk);
101317
101318 return err;
101319 diff --git a/net/core/dev.c b/net/core/dev.c
101320 index 8440968..d1d6bea 100644
101321 --- a/net/core/dev.c
101322 +++ b/net/core/dev.c
101323 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101324 {
101325 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101326 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101327 - atomic_long_inc(&dev->rx_dropped);
101328 + atomic_long_inc_unchecked(&dev->rx_dropped);
101329 kfree_skb(skb);
101330 return NET_RX_DROP;
101331 }
101332 }
101333
101334 if (unlikely(!is_skb_forwardable(dev, skb))) {
101335 - atomic_long_inc(&dev->rx_dropped);
101336 + atomic_long_inc_unchecked(&dev->rx_dropped);
101337 kfree_skb(skb);
101338 return NET_RX_DROP;
101339 }
101340 @@ -2994,7 +2994,7 @@ recursion_alert:
101341 drop:
101342 rcu_read_unlock_bh();
101343
101344 - atomic_long_inc(&dev->tx_dropped);
101345 + atomic_long_inc_unchecked(&dev->tx_dropped);
101346 kfree_skb_list(skb);
101347 return rc;
101348 out:
101349 @@ -3337,7 +3337,7 @@ enqueue:
101350
101351 local_irq_restore(flags);
101352
101353 - atomic_long_inc(&skb->dev->rx_dropped);
101354 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101355 kfree_skb(skb);
101356 return NET_RX_DROP;
101357 }
101358 @@ -3414,7 +3414,7 @@ int netif_rx_ni(struct sk_buff *skb)
101359 }
101360 EXPORT_SYMBOL(netif_rx_ni);
101361
101362 -static void net_tx_action(struct softirq_action *h)
101363 +static __latent_entropy void net_tx_action(void)
101364 {
101365 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101366
101367 @@ -3747,7 +3747,7 @@ ncls:
101368 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101369 } else {
101370 drop:
101371 - atomic_long_inc(&skb->dev->rx_dropped);
101372 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101373 kfree_skb(skb);
101374 /* Jamal, now you will not able to escape explaining
101375 * me how you were going to use this. :-)
101376 @@ -4511,7 +4511,7 @@ void netif_napi_del(struct napi_struct *napi)
101377 }
101378 EXPORT_SYMBOL(netif_napi_del);
101379
101380 -static void net_rx_action(struct softirq_action *h)
101381 +static __latent_entropy void net_rx_action(void)
101382 {
101383 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101384 unsigned long time_limit = jiffies + 2;
101385 @@ -6557,8 +6557,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101386 } else {
101387 netdev_stats_to_stats64(storage, &dev->stats);
101388 }
101389 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101390 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101391 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101392 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101393 return storage;
101394 }
101395 EXPORT_SYMBOL(dev_get_stats);
101396 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101397 index 72e899a..79a9409 100644
101398 --- a/net/core/dev_ioctl.c
101399 +++ b/net/core/dev_ioctl.c
101400 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101401 no_module = !dev;
101402 if (no_module && capable(CAP_NET_ADMIN))
101403 no_module = request_module("netdev-%s", name);
101404 - if (no_module && capable(CAP_SYS_MODULE))
101405 + if (no_module && capable(CAP_SYS_MODULE)) {
101406 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101407 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101408 +#else
101409 request_module("%s", name);
101410 +#endif
101411 + }
101412 }
101413 EXPORT_SYMBOL(dev_load);
101414
101415 diff --git a/net/core/filter.c b/net/core/filter.c
101416 index 647b122..18a7ff6 100644
101417 --- a/net/core/filter.c
101418 +++ b/net/core/filter.c
101419 @@ -532,7 +532,11 @@ do_pass:
101420
101421 /* Unkown instruction. */
101422 default:
101423 - goto err;
101424 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101425 + fp->code, fp->jt, fp->jf, fp->k);
101426 + kfree(addrs);
101427 + BUG();
101428 + return -EINVAL;
101429 }
101430
101431 insn++;
101432 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101433 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101434 int pc, ret = 0;
101435
101436 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101437 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101438
101439 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101440 if (!masks)
101441 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101442 if (!fp)
101443 return -ENOMEM;
101444
101445 - memcpy(fp->insns, fprog->filter, fsize);
101446 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101447
101448 fp->len = fprog->len;
101449 /* Since unattached filters are not copied back to user
101450 diff --git a/net/core/flow.c b/net/core/flow.c
101451 index a0348fd..6951c76 100644
101452 --- a/net/core/flow.c
101453 +++ b/net/core/flow.c
101454 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101455 static int flow_entry_valid(struct flow_cache_entry *fle,
101456 struct netns_xfrm *xfrm)
101457 {
101458 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101459 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101460 return 0;
101461 if (fle->object && !fle->object->ops->check(fle->object))
101462 return 0;
101463 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101464 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101465 fcp->hash_count++;
101466 }
101467 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101468 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101469 flo = fle->object;
101470 if (!flo)
101471 goto ret_object;
101472 @@ -263,7 +263,7 @@ nocache:
101473 }
101474 flo = resolver(net, key, family, dir, flo, ctx);
101475 if (fle) {
101476 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101477 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101478 if (!IS_ERR(flo))
101479 fle->object = flo;
101480 else
101481 diff --git a/net/core/iovec.c b/net/core/iovec.c
101482 index e1ec45a..e5c6f16 100644
101483 --- a/net/core/iovec.c
101484 +++ b/net/core/iovec.c
101485 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101486 if (m->msg_name && m->msg_namelen) {
101487 if (mode == VERIFY_READ) {
101488 void __user *namep;
101489 - namep = (void __user __force *) m->msg_name;
101490 + namep = (void __force_user *) m->msg_name;
101491 err = move_addr_to_kernel(namep, m->msg_namelen,
101492 address);
101493 if (err < 0)
101494 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101495 }
101496
101497 size = m->msg_iovlen * sizeof(struct iovec);
101498 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101499 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101500 return -EFAULT;
101501
101502 m->msg_iov = iov;
101503 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101504 index ef31fef..8be66d9 100644
101505 --- a/net/core/neighbour.c
101506 +++ b/net/core/neighbour.c
101507 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101508 void __user *buffer, size_t *lenp, loff_t *ppos)
101509 {
101510 int size, ret;
101511 - struct ctl_table tmp = *ctl;
101512 + ctl_table_no_const tmp = *ctl;
101513
101514 tmp.extra1 = &zero;
101515 tmp.extra2 = &unres_qlen_max;
101516 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101517 void __user *buffer,
101518 size_t *lenp, loff_t *ppos)
101519 {
101520 - struct ctl_table tmp = *ctl;
101521 + ctl_table_no_const tmp = *ctl;
101522 int ret;
101523
101524 tmp.extra1 = &zero;
101525 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101526 index 2bf8329..2eb1423 100644
101527 --- a/net/core/net-procfs.c
101528 +++ b/net/core/net-procfs.c
101529 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101530 struct rtnl_link_stats64 temp;
101531 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101532
101533 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101534 + if (gr_proc_is_restricted())
101535 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101536 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101537 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101538 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101539 + else
101540 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101541 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101542 dev->name, stats->rx_bytes, stats->rx_packets,
101543 stats->rx_errors,
101544 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101545 return 0;
101546 }
101547
101548 -static const struct seq_operations dev_seq_ops = {
101549 +const struct seq_operations dev_seq_ops = {
101550 .start = dev_seq_start,
101551 .next = dev_seq_next,
101552 .stop = dev_seq_stop,
101553 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101554
101555 static int softnet_seq_open(struct inode *inode, struct file *file)
101556 {
101557 - return seq_open(file, &softnet_seq_ops);
101558 + return seq_open_restrict(file, &softnet_seq_ops);
101559 }
101560
101561 static const struct file_operations softnet_seq_fops = {
101562 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101563 else
101564 seq_printf(seq, "%04x", ntohs(pt->type));
101565
101566 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101567 + seq_printf(seq, " %-8s %pf\n",
101568 + pt->dev ? pt->dev->name : "", NULL);
101569 +#else
101570 seq_printf(seq, " %-8s %pf\n",
101571 pt->dev ? pt->dev->name : "", pt->func);
101572 +#endif
101573 }
101574
101575 return 0;
101576 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101577 index 9dd0669..c52fb1b 100644
101578 --- a/net/core/net-sysfs.c
101579 +++ b/net/core/net-sysfs.c
101580 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101581 {
101582 struct net_device *netdev = to_net_dev(dev);
101583 return sprintf(buf, fmt_dec,
101584 - atomic_read(&netdev->carrier_changes));
101585 + atomic_read_unchecked(&netdev->carrier_changes));
101586 }
101587 static DEVICE_ATTR_RO(carrier_changes);
101588
101589 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101590 index 7f15517..f7d65c0 100644
101591 --- a/net/core/net_namespace.c
101592 +++ b/net/core/net_namespace.c
101593 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101594 int error;
101595 LIST_HEAD(net_exit_list);
101596
101597 - list_add_tail(&ops->list, list);
101598 + pax_list_add_tail((struct list_head *)&ops->list, list);
101599 if (ops->init || (ops->id && ops->size)) {
101600 for_each_net(net) {
101601 error = ops_init(ops, net);
101602 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101603
101604 out_undo:
101605 /* If I have an error cleanup all namespaces I initialized */
101606 - list_del(&ops->list);
101607 + pax_list_del((struct list_head *)&ops->list);
101608 ops_exit_list(ops, &net_exit_list);
101609 ops_free_list(ops, &net_exit_list);
101610 return error;
101611 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101612 struct net *net;
101613 LIST_HEAD(net_exit_list);
101614
101615 - list_del(&ops->list);
101616 + pax_list_del((struct list_head *)&ops->list);
101617 for_each_net(net)
101618 list_add_tail(&net->exit_list, &net_exit_list);
101619 ops_exit_list(ops, &net_exit_list);
101620 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101621 mutex_lock(&net_mutex);
101622 error = register_pernet_operations(&pernet_list, ops);
101623 if (!error && (first_device == &pernet_list))
101624 - first_device = &ops->list;
101625 + first_device = (struct list_head *)&ops->list;
101626 mutex_unlock(&net_mutex);
101627 return error;
101628 }
101629 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101630 index e6645b4..43e1af9 100644
101631 --- a/net/core/netpoll.c
101632 +++ b/net/core/netpoll.c
101633 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101634 struct udphdr *udph;
101635 struct iphdr *iph;
101636 struct ethhdr *eth;
101637 - static atomic_t ip_ident;
101638 + static atomic_unchecked_t ip_ident;
101639 struct ipv6hdr *ip6h;
101640
101641 udp_len = len + sizeof(*udph);
101642 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101643 put_unaligned(0x45, (unsigned char *)iph);
101644 iph->tos = 0;
101645 put_unaligned(htons(ip_len), &(iph->tot_len));
101646 - iph->id = htons(atomic_inc_return(&ip_ident));
101647 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101648 iph->frag_off = 0;
101649 iph->ttl = 64;
101650 iph->protocol = IPPROTO_UDP;
101651 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101652 index 443256b..bbff424 100644
101653 --- a/net/core/pktgen.c
101654 +++ b/net/core/pktgen.c
101655 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101656 pn->net = net;
101657 INIT_LIST_HEAD(&pn->pktgen_threads);
101658 pn->pktgen_exiting = false;
101659 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101660 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101661 if (!pn->proc_dir) {
101662 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101663 return -ENODEV;
101664 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101665 index 76321ea..3129bd6 100644
101666 --- a/net/core/rtnetlink.c
101667 +++ b/net/core/rtnetlink.c
101668 @@ -58,7 +58,7 @@ struct rtnl_link {
101669 rtnl_doit_func doit;
101670 rtnl_dumpit_func dumpit;
101671 rtnl_calcit_func calcit;
101672 -};
101673 +} __no_const;
101674
101675 static DEFINE_MUTEX(rtnl_mutex);
101676
101677 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101678 * to use the ops for creating device. So do not
101679 * fill up dellink as well. That disables rtnl_dellink.
101680 */
101681 - if (ops->setup && !ops->dellink)
101682 - ops->dellink = unregister_netdevice_queue;
101683 + if (ops->setup && !ops->dellink) {
101684 + pax_open_kernel();
101685 + *(void **)&ops->dellink = unregister_netdevice_queue;
101686 + pax_close_kernel();
101687 + }
101688
101689 - list_add_tail(&ops->list, &link_ops);
101690 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101691 return 0;
101692 }
101693 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101694 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101695 for_each_net(net) {
101696 __rtnl_kill_links(net, ops);
101697 }
101698 - list_del(&ops->list);
101699 + pax_list_del((struct list_head *)&ops->list);
101700 }
101701 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101702
101703 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101704 (dev->ifalias &&
101705 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101706 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101707 - atomic_read(&dev->carrier_changes)))
101708 + atomic_read_unchecked(&dev->carrier_changes)))
101709 goto nla_put_failure;
101710
101711 if (1) {
101712 diff --git a/net/core/scm.c b/net/core/scm.c
101713 index b442e7e..6f5b5a2 100644
101714 --- a/net/core/scm.c
101715 +++ b/net/core/scm.c
101716 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101717 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101718 {
101719 struct cmsghdr __user *cm
101720 - = (__force struct cmsghdr __user *)msg->msg_control;
101721 + = (struct cmsghdr __force_user *)msg->msg_control;
101722 struct cmsghdr cmhdr;
101723 int cmlen = CMSG_LEN(len);
101724 int err;
101725 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101726 err = -EFAULT;
101727 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101728 goto out;
101729 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101730 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101731 goto out;
101732 cmlen = CMSG_SPACE(len);
101733 if (msg->msg_controllen < cmlen)
101734 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101735 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101736 {
101737 struct cmsghdr __user *cm
101738 - = (__force struct cmsghdr __user*)msg->msg_control;
101739 + = (struct cmsghdr __force_user *)msg->msg_control;
101740
101741 int fdmax = 0;
101742 int fdnum = scm->fp->count;
101743 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101744 if (fdnum < fdmax)
101745 fdmax = fdnum;
101746
101747 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101748 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101749 i++, cmfptr++)
101750 {
101751 struct socket *sock;
101752 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101753 index d7543d0..ff96aec 100644
101754 --- a/net/core/skbuff.c
101755 +++ b/net/core/skbuff.c
101756 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101757 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101758 int len, __wsum csum)
101759 {
101760 - const struct skb_checksum_ops ops = {
101761 + static const struct skb_checksum_ops ops = {
101762 .update = csum_partial_ext,
101763 .combine = csum_block_add_ext,
101764 };
101765 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
101766 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101767 sizeof(struct sk_buff),
101768 0,
101769 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101770 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101771 + SLAB_NO_SANITIZE,
101772 NULL);
101773 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101774 sizeof(struct sk_buff_fclones),
101775 0,
101776 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101777 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101778 + SLAB_NO_SANITIZE,
101779 NULL);
101780 }
101781
101782 diff --git a/net/core/sock.c b/net/core/sock.c
101783 index 15e0c67..0310f4a 100644
101784 --- a/net/core/sock.c
101785 +++ b/net/core/sock.c
101786 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101787 struct sk_buff_head *list = &sk->sk_receive_queue;
101788
101789 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101790 - atomic_inc(&sk->sk_drops);
101791 + atomic_inc_unchecked(&sk->sk_drops);
101792 trace_sock_rcvqueue_full(sk, skb);
101793 return -ENOMEM;
101794 }
101795 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101796 return err;
101797
101798 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101799 - atomic_inc(&sk->sk_drops);
101800 + atomic_inc_unchecked(&sk->sk_drops);
101801 return -ENOBUFS;
101802 }
101803
101804 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101805 skb_dst_force(skb);
101806
101807 spin_lock_irqsave(&list->lock, flags);
101808 - skb->dropcount = atomic_read(&sk->sk_drops);
101809 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101810 __skb_queue_tail(list, skb);
101811 spin_unlock_irqrestore(&list->lock, flags);
101812
101813 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101814 skb->dev = NULL;
101815
101816 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101817 - atomic_inc(&sk->sk_drops);
101818 + atomic_inc_unchecked(&sk->sk_drops);
101819 goto discard_and_relse;
101820 }
101821 if (nested)
101822 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101823 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101824 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101825 bh_unlock_sock(sk);
101826 - atomic_inc(&sk->sk_drops);
101827 + atomic_inc_unchecked(&sk->sk_drops);
101828 goto discard_and_relse;
101829 }
101830
101831 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101832 struct timeval tm;
101833 } v;
101834
101835 - int lv = sizeof(int);
101836 - int len;
101837 + unsigned int lv = sizeof(int);
101838 + unsigned int len;
101839
101840 if (get_user(len, optlen))
101841 return -EFAULT;
101842 - if (len < 0)
101843 + if (len > INT_MAX)
101844 return -EINVAL;
101845
101846 memset(&v, 0, sizeof(v));
101847 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101848
101849 case SO_PEERNAME:
101850 {
101851 - char address[128];
101852 + char address[_K_SS_MAXSIZE];
101853
101854 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101855 return -ENOTCONN;
101856 - if (lv < len)
101857 + if (lv < len || sizeof address < len)
101858 return -EINVAL;
101859 if (copy_to_user(optval, address, len))
101860 return -EFAULT;
101861 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101862
101863 if (len > lv)
101864 len = lv;
101865 - if (copy_to_user(optval, &v, len))
101866 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
101867 return -EFAULT;
101868 lenout:
101869 if (put_user(len, optlen))
101870 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101871 */
101872 smp_wmb();
101873 atomic_set(&sk->sk_refcnt, 1);
101874 - atomic_set(&sk->sk_drops, 0);
101875 + atomic_set_unchecked(&sk->sk_drops, 0);
101876 }
101877 EXPORT_SYMBOL(sock_init_data);
101878
101879 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101880 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101881 int level, int type)
101882 {
101883 + struct sock_extended_err ee;
101884 struct sock_exterr_skb *serr;
101885 struct sk_buff *skb;
101886 int copied, err;
101887 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101888 sock_recv_timestamp(msg, sk, skb);
101889
101890 serr = SKB_EXT_ERR(skb);
101891 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101892 + ee = serr->ee;
101893 + put_cmsg(msg, level, type, sizeof ee, &ee);
101894
101895 msg->msg_flags |= MSG_ERRQUEUE;
101896 err = copied;
101897 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101898 index ad704c7..ca48aff 100644
101899 --- a/net/core/sock_diag.c
101900 +++ b/net/core/sock_diag.c
101901 @@ -9,26 +9,33 @@
101902 #include <linux/inet_diag.h>
101903 #include <linux/sock_diag.h>
101904
101905 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101906 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101907 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101908 static DEFINE_MUTEX(sock_diag_table_mutex);
101909
101910 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101911 {
101912 +#ifndef CONFIG_GRKERNSEC_HIDESYM
101913 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101914 cookie[1] != INET_DIAG_NOCOOKIE) &&
101915 ((u32)(unsigned long)sk != cookie[0] ||
101916 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101917 return -ESTALE;
101918 else
101919 +#endif
101920 return 0;
101921 }
101922 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101923
101924 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101925 {
101926 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101927 + cookie[0] = 0;
101928 + cookie[1] = 0;
101929 +#else
101930 cookie[0] = (u32)(unsigned long)sk;
101931 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101932 +#endif
101933 }
101934 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101935
101936 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101937 mutex_lock(&sock_diag_table_mutex);
101938 if (sock_diag_handlers[hndl->family])
101939 err = -EBUSY;
101940 - else
101941 + else {
101942 + pax_open_kernel();
101943 sock_diag_handlers[hndl->family] = hndl;
101944 + pax_close_kernel();
101945 + }
101946 mutex_unlock(&sock_diag_table_mutex);
101947
101948 return err;
101949 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101950
101951 mutex_lock(&sock_diag_table_mutex);
101952 BUG_ON(sock_diag_handlers[family] != hnld);
101953 + pax_open_kernel();
101954 sock_diag_handlers[family] = NULL;
101955 + pax_close_kernel();
101956 mutex_unlock(&sock_diag_table_mutex);
101957 }
101958 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101959 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101960 index cf9cd13..50683950 100644
101961 --- a/net/core/sysctl_net_core.c
101962 +++ b/net/core/sysctl_net_core.c
101963 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101964 {
101965 unsigned int orig_size, size;
101966 int ret, i;
101967 - struct ctl_table tmp = {
101968 + ctl_table_no_const tmp = {
101969 .data = &size,
101970 .maxlen = sizeof(size),
101971 .mode = table->mode
101972 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101973 void __user *buffer, size_t *lenp, loff_t *ppos)
101974 {
101975 char id[IFNAMSIZ];
101976 - struct ctl_table tbl = {
101977 + ctl_table_no_const tbl = {
101978 .data = id,
101979 .maxlen = IFNAMSIZ,
101980 };
101981 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101982 .mode = 0644,
101983 .proc_handler = proc_dointvec
101984 },
101985 -#ifdef CONFIG_BPF_JIT
101986 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101987 {
101988 .procname = "bpf_jit_enable",
101989 .data = &bpf_jit_enable,
101990 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101991
101992 static __net_init int sysctl_core_net_init(struct net *net)
101993 {
101994 - struct ctl_table *tbl;
101995 + ctl_table_no_const *tbl = NULL;
101996
101997 net->core.sysctl_somaxconn = SOMAXCONN;
101998
101999 - tbl = netns_core_table;
102000 if (!net_eq(net, &init_net)) {
102001 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102002 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102003 if (tbl == NULL)
102004 goto err_dup;
102005
102006 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102007 if (net->user_ns != &init_user_ns) {
102008 tbl[0].procname = NULL;
102009 }
102010 - }
102011 -
102012 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102013 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102014 + } else
102015 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102016 if (net->core.sysctl_hdr == NULL)
102017 goto err_reg;
102018
102019 return 0;
102020
102021 err_reg:
102022 - if (tbl != netns_core_table)
102023 - kfree(tbl);
102024 + kfree(tbl);
102025 err_dup:
102026 return -ENOMEM;
102027 }
102028 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102029 kfree(tbl);
102030 }
102031
102032 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102033 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102034 .init = sysctl_core_net_init,
102035 .exit = sysctl_core_net_exit,
102036 };
102037 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102038 index 25733d5..b9360f0 100644
102039 --- a/net/decnet/af_decnet.c
102040 +++ b/net/decnet/af_decnet.c
102041 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
102042 .sysctl_rmem = sysctl_decnet_rmem,
102043 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102044 .obj_size = sizeof(struct dn_sock),
102045 + .slab_flags = SLAB_USERCOPY,
102046 };
102047
102048 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102049 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102050 index 4400da7..3429972 100644
102051 --- a/net/decnet/dn_dev.c
102052 +++ b/net/decnet/dn_dev.c
102053 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
102054 .extra1 = &min_t3,
102055 .extra2 = &max_t3
102056 },
102057 - {0}
102058 + { }
102059 },
102060 };
102061
102062 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102063 index 5325b54..a0d4d69 100644
102064 --- a/net/decnet/sysctl_net_decnet.c
102065 +++ b/net/decnet/sysctl_net_decnet.c
102066 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102067
102068 if (len > *lenp) len = *lenp;
102069
102070 - if (copy_to_user(buffer, addr, len))
102071 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102072 return -EFAULT;
102073
102074 *lenp = len;
102075 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102076
102077 if (len > *lenp) len = *lenp;
102078
102079 - if (copy_to_user(buffer, devname, len))
102080 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102081 return -EFAULT;
102082
102083 *lenp = len;
102084 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102085 index a2c7e4c..3dc9f67 100644
102086 --- a/net/hsr/hsr_netlink.c
102087 +++ b/net/hsr/hsr_netlink.c
102088 @@ -102,7 +102,7 @@ nla_put_failure:
102089 return -EMSGSIZE;
102090 }
102091
102092 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102093 +static struct rtnl_link_ops hsr_link_ops = {
102094 .kind = "hsr",
102095 .maxtype = IFLA_HSR_MAX,
102096 .policy = hsr_policy,
102097 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102098 index 4413629..dea596a 100644
102099 --- a/net/ieee802154/6lowpan_rtnl.c
102100 +++ b/net/ieee802154/6lowpan_rtnl.c
102101 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102102 dev_put(real_dev);
102103 }
102104
102105 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102106 +static struct rtnl_link_ops lowpan_link_ops = {
102107 .kind = "lowpan",
102108 .priv_size = sizeof(struct lowpan_dev_info),
102109 .setup = lowpan_setup,
102110 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102111 index 7cfcd68..84ca5b7 100644
102112 --- a/net/ieee802154/reassembly.c
102113 +++ b/net/ieee802154/reassembly.c
102114 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102115
102116 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102117 {
102118 - struct ctl_table *table;
102119 + ctl_table_no_const *table = NULL;
102120 struct ctl_table_header *hdr;
102121 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102122 net_ieee802154_lowpan(net);
102123
102124 - table = lowpan_frags_ns_ctl_table;
102125 if (!net_eq(net, &init_net)) {
102126 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102127 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102128 GFP_KERNEL);
102129 if (table == NULL)
102130 goto err_alloc;
102131 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102132 /* Don't export sysctls to unprivileged users */
102133 if (net->user_ns != &init_user_ns)
102134 table[0].procname = NULL;
102135 - }
102136 -
102137 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102138 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102139 + } else
102140 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102141 if (hdr == NULL)
102142 goto err_reg;
102143
102144 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102145 return 0;
102146
102147 err_reg:
102148 - if (!net_eq(net, &init_net))
102149 - kfree(table);
102150 + kfree(table);
102151 err_alloc:
102152 return -ENOMEM;
102153 }
102154 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102155 index e67da4e..da217942 100644
102156 --- a/net/ipv4/af_inet.c
102157 +++ b/net/ipv4/af_inet.c
102158 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102159 return ip_recv_error(sk, msg, len, addr_len);
102160 #if IS_ENABLED(CONFIG_IPV6)
102161 if (sk->sk_family == AF_INET6)
102162 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102163 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102164 #endif
102165 return -EINVAL;
102166 }
102167 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102168 index 214882e..ec032f6 100644
102169 --- a/net/ipv4/devinet.c
102170 +++ b/net/ipv4/devinet.c
102171 @@ -69,7 +69,8 @@
102172
102173 static struct ipv4_devconf ipv4_devconf = {
102174 .data = {
102175 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102176 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102177 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102178 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102179 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102180 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102181 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102182
102183 static struct ipv4_devconf ipv4_devconf_dflt = {
102184 .data = {
102185 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102186 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102187 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102188 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102189 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102190 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102191 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102192 idx = 0;
102193 head = &net->dev_index_head[h];
102194 rcu_read_lock();
102195 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102196 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102197 net->dev_base_seq;
102198 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102199 if (idx < s_idx)
102200 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102201 idx = 0;
102202 head = &net->dev_index_head[h];
102203 rcu_read_lock();
102204 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102205 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102206 net->dev_base_seq;
102207 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102208 if (idx < s_idx)
102209 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102210 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102211 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102212
102213 -static struct devinet_sysctl_table {
102214 +static const struct devinet_sysctl_table {
102215 struct ctl_table_header *sysctl_header;
102216 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102217 } devinet_sysctl = {
102218 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102219 int err;
102220 struct ipv4_devconf *all, *dflt;
102221 #ifdef CONFIG_SYSCTL
102222 - struct ctl_table *tbl = ctl_forward_entry;
102223 + ctl_table_no_const *tbl = NULL;
102224 struct ctl_table_header *forw_hdr;
102225 #endif
102226
102227 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102228 goto err_alloc_dflt;
102229
102230 #ifdef CONFIG_SYSCTL
102231 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102232 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102233 if (tbl == NULL)
102234 goto err_alloc_ctl;
102235
102236 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102237 goto err_reg_dflt;
102238
102239 err = -ENOMEM;
102240 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102241 + if (!net_eq(net, &init_net))
102242 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102243 + else
102244 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102245 if (forw_hdr == NULL)
102246 goto err_reg_ctl;
102247 net->ipv4.forw_hdr = forw_hdr;
102248 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102249 err_reg_dflt:
102250 __devinet_sysctl_unregister(all);
102251 err_reg_all:
102252 - if (tbl != ctl_forward_entry)
102253 - kfree(tbl);
102254 + kfree(tbl);
102255 err_alloc_ctl:
102256 #endif
102257 if (dflt != &ipv4_devconf_dflt)
102258 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102259 index 23104a3..9f5570b 100644
102260 --- a/net/ipv4/fib_frontend.c
102261 +++ b/net/ipv4/fib_frontend.c
102262 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102263 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102264 fib_sync_up(dev);
102265 #endif
102266 - atomic_inc(&net->ipv4.dev_addr_genid);
102267 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102268 rt_cache_flush(dev_net(dev));
102269 break;
102270 case NETDEV_DOWN:
102271 fib_del_ifaddr(ifa, NULL);
102272 - atomic_inc(&net->ipv4.dev_addr_genid);
102273 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102274 if (ifa->ifa_dev->ifa_list == NULL) {
102275 /* Last address was deleted from this interface.
102276 * Disable IP.
102277 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102278 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102279 fib_sync_up(dev);
102280 #endif
102281 - atomic_inc(&net->ipv4.dev_addr_genid);
102282 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102283 rt_cache_flush(net);
102284 break;
102285 case NETDEV_DOWN:
102286 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102287 index f99f41b..1879da9 100644
102288 --- a/net/ipv4/fib_semantics.c
102289 +++ b/net/ipv4/fib_semantics.c
102290 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102291 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102292 nh->nh_gw,
102293 nh->nh_parent->fib_scope);
102294 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102295 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102296
102297 return nh->nh_saddr;
102298 }
102299 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102300 index 9111a4e..3576905 100644
102301 --- a/net/ipv4/inet_hashtables.c
102302 +++ b/net/ipv4/inet_hashtables.c
102303 @@ -18,6 +18,7 @@
102304 #include <linux/sched.h>
102305 #include <linux/slab.h>
102306 #include <linux/wait.h>
102307 +#include <linux/security.h>
102308
102309 #include <net/inet_connection_sock.h>
102310 #include <net/inet_hashtables.h>
102311 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102312 return inet_ehashfn(net, laddr, lport, faddr, fport);
102313 }
102314
102315 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102316 +
102317 /*
102318 * Allocate and initialize a new local port bind bucket.
102319 * The bindhash mutex for snum's hash chain must be held here.
102320 @@ -554,6 +557,8 @@ ok:
102321 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102322 spin_unlock(&head->lock);
102323
102324 + gr_update_task_in_ip_table(inet_sk(sk));
102325 +
102326 if (tw) {
102327 inet_twsk_deschedule(tw, death_row);
102328 while (twrefcnt) {
102329 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102330 index 241afd7..31b95d5 100644
102331 --- a/net/ipv4/inetpeer.c
102332 +++ b/net/ipv4/inetpeer.c
102333 @@ -461,7 +461,7 @@ relookup:
102334 if (p) {
102335 p->daddr = *daddr;
102336 atomic_set(&p->refcnt, 1);
102337 - atomic_set(&p->rid, 0);
102338 + atomic_set_unchecked(&p->rid, 0);
102339 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102340 p->rate_tokens = 0;
102341 /* 60*HZ is arbitrary, but chosen enough high so that the first
102342 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102343 index 2811cc1..ad5a534 100644
102344 --- a/net/ipv4/ip_fragment.c
102345 +++ b/net/ipv4/ip_fragment.c
102346 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102347 return 0;
102348
102349 start = qp->rid;
102350 - end = atomic_inc_return(&peer->rid);
102351 + end = atomic_inc_return_unchecked(&peer->rid);
102352 qp->rid = end;
102353
102354 rc = qp->q.fragments && (end - start) > max;
102355 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102356
102357 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102358 {
102359 - struct ctl_table *table;
102360 + ctl_table_no_const *table = NULL;
102361 struct ctl_table_header *hdr;
102362
102363 - table = ip4_frags_ns_ctl_table;
102364 if (!net_eq(net, &init_net)) {
102365 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102366 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102367 if (table == NULL)
102368 goto err_alloc;
102369
102370 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102371 /* Don't export sysctls to unprivileged users */
102372 if (net->user_ns != &init_user_ns)
102373 table[0].procname = NULL;
102374 - }
102375 + hdr = register_net_sysctl(net, "net/ipv4", table);
102376 + } else
102377 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102378
102379 - hdr = register_net_sysctl(net, "net/ipv4", table);
102380 if (hdr == NULL)
102381 goto err_reg;
102382
102383 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102384 return 0;
102385
102386 err_reg:
102387 - if (!net_eq(net, &init_net))
102388 - kfree(table);
102389 + kfree(table);
102390 err_alloc:
102391 return -ENOMEM;
102392 }
102393 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102394 index 69aaf0a..8298c029 100644
102395 --- a/net/ipv4/ip_gre.c
102396 +++ b/net/ipv4/ip_gre.c
102397 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102398 module_param(log_ecn_error, bool, 0644);
102399 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102400
102401 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102402 +static struct rtnl_link_ops ipgre_link_ops;
102403 static int ipgre_tunnel_init(struct net_device *dev);
102404
102405 static int ipgre_net_id __read_mostly;
102406 @@ -816,7 +816,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102407 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102408 };
102409
102410 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102411 +static struct rtnl_link_ops ipgre_link_ops = {
102412 .kind = "gre",
102413 .maxtype = IFLA_GRE_MAX,
102414 .policy = ipgre_policy,
102415 @@ -830,7 +830,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102416 .fill_info = ipgre_fill_info,
102417 };
102418
102419 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102420 +static struct rtnl_link_ops ipgre_tap_ops = {
102421 .kind = "gretap",
102422 .maxtype = IFLA_GRE_MAX,
102423 .policy = ipgre_policy,
102424 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102425 index 3d4da2c..40f9c29 100644
102426 --- a/net/ipv4/ip_input.c
102427 +++ b/net/ipv4/ip_input.c
102428 @@ -147,6 +147,10 @@
102429 #include <linux/mroute.h>
102430 #include <linux/netlink.h>
102431
102432 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102433 +extern int grsec_enable_blackhole;
102434 +#endif
102435 +
102436 /*
102437 * Process Router Attention IP option (RFC 2113)
102438 */
102439 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102440 if (!raw) {
102441 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102442 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102443 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102444 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102445 +#endif
102446 icmp_send(skb, ICMP_DEST_UNREACH,
102447 ICMP_PROT_UNREACH, 0);
102448 }
102449 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102450 index 9daf217..373d454 100644
102451 --- a/net/ipv4/ip_sockglue.c
102452 +++ b/net/ipv4/ip_sockglue.c
102453 @@ -443,15 +443,12 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102454
102455 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
102456 sin = &errhdr.offender;
102457 - sin->sin_family = AF_UNSPEC;
102458 + memset(sin, 0, sizeof(*sin));
102459 +
102460 if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
102461 - struct inet_sock *inet = inet_sk(sk);
102462 -
102463 sin->sin_family = AF_INET;
102464 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
102465 - sin->sin_port = 0;
102466 - memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
102467 - if (inet->cmsg_flags)
102468 + if (inet_sk(sk)->cmsg_flags)
102469 ip_cmsg_recv(msg, skb);
102470 }
102471
102472 @@ -1177,7 +1174,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102473 len = min_t(unsigned int, len, opt->optlen);
102474 if (put_user(len, optlen))
102475 return -EFAULT;
102476 - if (copy_to_user(optval, opt->__data, len))
102477 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102478 + copy_to_user(optval, opt->__data, len))
102479 return -EFAULT;
102480 return 0;
102481 }
102482 @@ -1308,7 +1306,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102483 if (sk->sk_type != SOCK_STREAM)
102484 return -ENOPROTOOPT;
102485
102486 - msg.msg_control = (__force void *) optval;
102487 + msg.msg_control = (__force_kernel void *) optval;
102488 msg.msg_controllen = len;
102489 msg.msg_flags = flags;
102490
102491 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102492 index 1a7e979..fd05aa4 100644
102493 --- a/net/ipv4/ip_vti.c
102494 +++ b/net/ipv4/ip_vti.c
102495 @@ -45,7 +45,7 @@
102496 #include <net/net_namespace.h>
102497 #include <net/netns/generic.h>
102498
102499 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102500 +static struct rtnl_link_ops vti_link_ops;
102501
102502 static int vti_net_id __read_mostly;
102503 static int vti_tunnel_init(struct net_device *dev);
102504 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102505 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102506 };
102507
102508 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102509 +static struct rtnl_link_ops vti_link_ops = {
102510 .kind = "vti",
102511 .maxtype = IFLA_VTI_MAX,
102512 .policy = vti_policy,
102513 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102514 index 648fa14..97864d0 100644
102515 --- a/net/ipv4/ipconfig.c
102516 +++ b/net/ipv4/ipconfig.c
102517 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102518
102519 mm_segment_t oldfs = get_fs();
102520 set_fs(get_ds());
102521 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102522 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102523 set_fs(oldfs);
102524 return res;
102525 }
102526 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102527
102528 mm_segment_t oldfs = get_fs();
102529 set_fs(get_ds());
102530 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102531 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102532 set_fs(oldfs);
102533 return res;
102534 }
102535 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102536
102537 mm_segment_t oldfs = get_fs();
102538 set_fs(get_ds());
102539 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102540 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102541 set_fs(oldfs);
102542 return res;
102543 }
102544 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102545 index 37096d6..86abb03 100644
102546 --- a/net/ipv4/ipip.c
102547 +++ b/net/ipv4/ipip.c
102548 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102549 static int ipip_net_id __read_mostly;
102550
102551 static int ipip_tunnel_init(struct net_device *dev);
102552 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102553 +static struct rtnl_link_ops ipip_link_ops;
102554
102555 static int ipip_err(struct sk_buff *skb, u32 info)
102556 {
102557 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102558 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102559 };
102560
102561 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102562 +static struct rtnl_link_ops ipip_link_ops = {
102563 .kind = "ipip",
102564 .maxtype = IFLA_IPTUN_MAX,
102565 .policy = ipip_policy,
102566 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102567 index f95b6f9..2ee2097 100644
102568 --- a/net/ipv4/netfilter/arp_tables.c
102569 +++ b/net/ipv4/netfilter/arp_tables.c
102570 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102571 #endif
102572
102573 static int get_info(struct net *net, void __user *user,
102574 - const int *len, int compat)
102575 + int len, int compat)
102576 {
102577 char name[XT_TABLE_MAXNAMELEN];
102578 struct xt_table *t;
102579 int ret;
102580
102581 - if (*len != sizeof(struct arpt_getinfo)) {
102582 - duprintf("length %u != %Zu\n", *len,
102583 + if (len != sizeof(struct arpt_getinfo)) {
102584 + duprintf("length %u != %Zu\n", len,
102585 sizeof(struct arpt_getinfo));
102586 return -EINVAL;
102587 }
102588 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102589 info.size = private->size;
102590 strcpy(info.name, name);
102591
102592 - if (copy_to_user(user, &info, *len) != 0)
102593 + if (copy_to_user(user, &info, len) != 0)
102594 ret = -EFAULT;
102595 else
102596 ret = 0;
102597 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102598
102599 switch (cmd) {
102600 case ARPT_SO_GET_INFO:
102601 - ret = get_info(sock_net(sk), user, len, 1);
102602 + ret = get_info(sock_net(sk), user, *len, 1);
102603 break;
102604 case ARPT_SO_GET_ENTRIES:
102605 ret = compat_get_entries(sock_net(sk), user, len);
102606 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102607
102608 switch (cmd) {
102609 case ARPT_SO_GET_INFO:
102610 - ret = get_info(sock_net(sk), user, len, 0);
102611 + ret = get_info(sock_net(sk), user, *len, 0);
102612 break;
102613
102614 case ARPT_SO_GET_ENTRIES:
102615 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102616 index 99e810f..3711b81 100644
102617 --- a/net/ipv4/netfilter/ip_tables.c
102618 +++ b/net/ipv4/netfilter/ip_tables.c
102619 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102620 #endif
102621
102622 static int get_info(struct net *net, void __user *user,
102623 - const int *len, int compat)
102624 + int len, int compat)
102625 {
102626 char name[XT_TABLE_MAXNAMELEN];
102627 struct xt_table *t;
102628 int ret;
102629
102630 - if (*len != sizeof(struct ipt_getinfo)) {
102631 - duprintf("length %u != %zu\n", *len,
102632 + if (len != sizeof(struct ipt_getinfo)) {
102633 + duprintf("length %u != %zu\n", len,
102634 sizeof(struct ipt_getinfo));
102635 return -EINVAL;
102636 }
102637 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102638 info.size = private->size;
102639 strcpy(info.name, name);
102640
102641 - if (copy_to_user(user, &info, *len) != 0)
102642 + if (copy_to_user(user, &info, len) != 0)
102643 ret = -EFAULT;
102644 else
102645 ret = 0;
102646 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102647
102648 switch (cmd) {
102649 case IPT_SO_GET_INFO:
102650 - ret = get_info(sock_net(sk), user, len, 1);
102651 + ret = get_info(sock_net(sk), user, *len, 1);
102652 break;
102653 case IPT_SO_GET_ENTRIES:
102654 ret = compat_get_entries(sock_net(sk), user, len);
102655 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102656
102657 switch (cmd) {
102658 case IPT_SO_GET_INFO:
102659 - ret = get_info(sock_net(sk), user, len, 0);
102660 + ret = get_info(sock_net(sk), user, *len, 0);
102661 break;
102662
102663 case IPT_SO_GET_ENTRIES:
102664 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102665 index e90f83a..3e6acca 100644
102666 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102667 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102668 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102669 spin_lock_init(&cn->lock);
102670
102671 #ifdef CONFIG_PROC_FS
102672 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102673 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102674 if (!cn->procdir) {
102675 pr_err("Unable to proc dir entry\n");
102676 return -ENOMEM;
102677 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102678 index 5d740cc..22c8e65 100644
102679 --- a/net/ipv4/ping.c
102680 +++ b/net/ipv4/ping.c
102681 @@ -59,7 +59,7 @@ struct ping_table {
102682 };
102683
102684 static struct ping_table ping_table;
102685 -struct pingv6_ops pingv6_ops;
102686 +struct pingv6_ops *pingv6_ops;
102687 EXPORT_SYMBOL_GPL(pingv6_ops);
102688
102689 static u16 ping_port_rover;
102690 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102691 return -ENODEV;
102692 }
102693 }
102694 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102695 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102696 scoped);
102697 rcu_read_unlock();
102698
102699 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102700 }
102701 #if IS_ENABLED(CONFIG_IPV6)
102702 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102703 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102704 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102705 #endif
102706 }
102707
102708 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102709 info, (u8 *)icmph);
102710 #if IS_ENABLED(CONFIG_IPV6)
102711 } else if (family == AF_INET6) {
102712 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102713 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102714 info, (u8 *)icmph);
102715 #endif
102716 }
102717 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102718 }
102719
102720 if (inet6_sk(sk)->rxopt.all)
102721 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102722 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102723 if (skb->protocol == htons(ETH_P_IPV6) &&
102724 inet6_sk(sk)->rxopt.all)
102725 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102726 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102727 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102728 ip_cmsg_recv(msg, skb);
102729 #endif
102730 @@ -965,8 +965,11 @@ void ping_rcv(struct sk_buff *skb)
102731
102732 sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
102733 if (sk != NULL) {
102734 + struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
102735 +
102736 pr_debug("rcv on socket %p\n", sk);
102737 - ping_queue_rcv_skb(sk, skb_get(skb));
102738 + if (skb2)
102739 + ping_queue_rcv_skb(sk, skb2);
102740 sock_put(sk);
102741 return;
102742 }
102743 @@ -1105,7 +1108,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102744 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102745 0, sock_i_ino(sp),
102746 atomic_read(&sp->sk_refcnt), sp,
102747 - atomic_read(&sp->sk_drops));
102748 + atomic_read_unchecked(&sp->sk_drops));
102749 }
102750
102751 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102752 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102753 index 739db31..74f0210 100644
102754 --- a/net/ipv4/raw.c
102755 +++ b/net/ipv4/raw.c
102756 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102757 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102758 {
102759 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102760 - atomic_inc(&sk->sk_drops);
102761 + atomic_inc_unchecked(&sk->sk_drops);
102762 kfree_skb(skb);
102763 return NET_RX_DROP;
102764 }
102765 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102766
102767 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102768 {
102769 + struct icmp_filter filter;
102770 +
102771 if (optlen > sizeof(struct icmp_filter))
102772 optlen = sizeof(struct icmp_filter);
102773 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102774 + if (copy_from_user(&filter, optval, optlen))
102775 return -EFAULT;
102776 + raw_sk(sk)->filter = filter;
102777 return 0;
102778 }
102779
102780 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102781 {
102782 int len, ret = -EFAULT;
102783 + struct icmp_filter filter;
102784
102785 if (get_user(len, optlen))
102786 goto out;
102787 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102788 if (len > sizeof(struct icmp_filter))
102789 len = sizeof(struct icmp_filter);
102790 ret = -EFAULT;
102791 - if (put_user(len, optlen) ||
102792 - copy_to_user(optval, &raw_sk(sk)->filter, len))
102793 + filter = raw_sk(sk)->filter;
102794 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102795 goto out;
102796 ret = 0;
102797 out: return ret;
102798 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102799 0, 0L, 0,
102800 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102801 0, sock_i_ino(sp),
102802 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102803 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102804 }
102805
102806 static int raw_seq_show(struct seq_file *seq, void *v)
102807 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102808 index 6a2155b..d426880 100644
102809 --- a/net/ipv4/route.c
102810 +++ b/net/ipv4/route.c
102811 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102812
102813 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102814 {
102815 - return seq_open(file, &rt_cache_seq_ops);
102816 + return seq_open_restrict(file, &rt_cache_seq_ops);
102817 }
102818
102819 static const struct file_operations rt_cache_seq_fops = {
102820 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102821
102822 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102823 {
102824 - return seq_open(file, &rt_cpu_seq_ops);
102825 + return seq_open_restrict(file, &rt_cpu_seq_ops);
102826 }
102827
102828 static const struct file_operations rt_cpu_seq_fops = {
102829 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102830
102831 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102832 {
102833 - return single_open(file, rt_acct_proc_show, NULL);
102834 + return single_open_restrict(file, rt_acct_proc_show, NULL);
102835 }
102836
102837 static const struct file_operations rt_acct_proc_fops = {
102838 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102839
102840 #define IP_IDENTS_SZ 2048u
102841 struct ip_ident_bucket {
102842 - atomic_t id;
102843 + atomic_unchecked_t id;
102844 u32 stamp32;
102845 };
102846
102847 -static struct ip_ident_bucket *ip_idents __read_mostly;
102848 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102849
102850 /* In order to protect privacy, we add a perturbation to identifiers
102851 * if one generator is seldom used. This makes hard for an attacker
102852 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102853 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102854 delta = prandom_u32_max(now - old);
102855
102856 - return atomic_add_return(segs + delta, &bucket->id) - segs;
102857 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102858 }
102859 EXPORT_SYMBOL(ip_idents_reserve);
102860
102861 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102862 .maxlen = sizeof(int),
102863 .mode = 0200,
102864 .proc_handler = ipv4_sysctl_rtcache_flush,
102865 + .extra1 = &init_net,
102866 },
102867 { },
102868 };
102869
102870 static __net_init int sysctl_route_net_init(struct net *net)
102871 {
102872 - struct ctl_table *tbl;
102873 + ctl_table_no_const *tbl = NULL;
102874
102875 - tbl = ipv4_route_flush_table;
102876 if (!net_eq(net, &init_net)) {
102877 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102878 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102879 if (tbl == NULL)
102880 goto err_dup;
102881
102882 /* Don't export sysctls to unprivileged users */
102883 if (net->user_ns != &init_user_ns)
102884 tbl[0].procname = NULL;
102885 - }
102886 - tbl[0].extra1 = net;
102887 + tbl[0].extra1 = net;
102888 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102889 + } else
102890 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102891
102892 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102893 if (net->ipv4.route_hdr == NULL)
102894 goto err_reg;
102895 return 0;
102896
102897 err_reg:
102898 - if (tbl != ipv4_route_flush_table)
102899 - kfree(tbl);
102900 + kfree(tbl);
102901 err_dup:
102902 return -ENOMEM;
102903 }
102904 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102905
102906 static __net_init int rt_genid_init(struct net *net)
102907 {
102908 - atomic_set(&net->ipv4.rt_genid, 0);
102909 - atomic_set(&net->fnhe_genid, 0);
102910 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102911 + atomic_set_unchecked(&net->fnhe_genid, 0);
102912 get_random_bytes(&net->ipv4.dev_addr_genid,
102913 sizeof(net->ipv4.dev_addr_genid));
102914 return 0;
102915 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102916 {
102917 int rc = 0;
102918
102919 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102920 - if (!ip_idents)
102921 - panic("IP: failed to allocate ip_idents\n");
102922 -
102923 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102924 + prandom_bytes(ip_idents, sizeof(ip_idents));
102925
102926 #ifdef CONFIG_IP_ROUTE_CLASSID
102927 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102928 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102929 index b3c53c8..35cc18d 100644
102930 --- a/net/ipv4/sysctl_net_ipv4.c
102931 +++ b/net/ipv4/sysctl_net_ipv4.c
102932 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102933 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102934 int ret;
102935 int range[2];
102936 - struct ctl_table tmp = {
102937 + ctl_table_no_const tmp = {
102938 .data = &range,
102939 .maxlen = sizeof(range),
102940 .mode = table->mode,
102941 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102942 int ret;
102943 gid_t urange[2];
102944 kgid_t low, high;
102945 - struct ctl_table tmp = {
102946 + ctl_table_no_const tmp = {
102947 .data = &urange,
102948 .maxlen = sizeof(urange),
102949 .mode = table->mode,
102950 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102951 void __user *buffer, size_t *lenp, loff_t *ppos)
102952 {
102953 char val[TCP_CA_NAME_MAX];
102954 - struct ctl_table tbl = {
102955 + ctl_table_no_const tbl = {
102956 .data = val,
102957 .maxlen = TCP_CA_NAME_MAX,
102958 };
102959 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102960 void __user *buffer, size_t *lenp,
102961 loff_t *ppos)
102962 {
102963 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102964 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102965 int ret;
102966
102967 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102968 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102969 void __user *buffer, size_t *lenp,
102970 loff_t *ppos)
102971 {
102972 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102973 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102974 int ret;
102975
102976 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102977 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102978 void __user *buffer, size_t *lenp,
102979 loff_t *ppos)
102980 {
102981 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102982 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102983 struct tcp_fastopen_context *ctxt;
102984 int ret;
102985 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102986 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
102987
102988 static __net_init int ipv4_sysctl_init_net(struct net *net)
102989 {
102990 - struct ctl_table *table;
102991 + ctl_table_no_const *table = NULL;
102992
102993 - table = ipv4_net_table;
102994 if (!net_eq(net, &init_net)) {
102995 int i;
102996
102997 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102998 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102999 if (table == NULL)
103000 goto err_alloc;
103001
103002 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103003 table[i].data += (void *)net - (void *)&init_net;
103004 }
103005
103006 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103007 + if (!net_eq(net, &init_net))
103008 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103009 + else
103010 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103011 if (net->ipv4.ipv4_hdr == NULL)
103012 goto err_reg;
103013
103014 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103015 index d107ee2..bcebf11 100644
103016 --- a/net/ipv4/tcp_input.c
103017 +++ b/net/ipv4/tcp_input.c
103018 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103019 * without any lock. We want to make sure compiler wont store
103020 * intermediate values in this location.
103021 */
103022 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103023 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103024 sk->sk_max_pacing_rate);
103025 }
103026
103027 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103028 * simplifies code)
103029 */
103030 static void
103031 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103032 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103033 struct sk_buff *head, struct sk_buff *tail,
103034 u32 start, u32 end)
103035 {
103036 @@ -5506,6 +5506,7 @@ discard:
103037 tcp_paws_reject(&tp->rx_opt, 0))
103038 goto discard_and_undo;
103039
103040 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103041 if (th->syn) {
103042 /* We see SYN without ACK. It is attempt of
103043 * simultaneous connect with crossed SYNs.
103044 @@ -5556,6 +5557,7 @@ discard:
103045 goto discard;
103046 #endif
103047 }
103048 +#endif
103049 /* "fifth, if neither of the SYN or RST bits is set then
103050 * drop the segment and return."
103051 */
103052 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103053 goto discard;
103054
103055 if (th->syn) {
103056 - if (th->fin)
103057 + if (th->fin || th->urg || th->psh)
103058 goto discard;
103059 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103060 return 1;
103061 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103062 index ef7089c..a3e65fb 100644
103063 --- a/net/ipv4/tcp_ipv4.c
103064 +++ b/net/ipv4/tcp_ipv4.c
103065 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
103066 int sysctl_tcp_low_latency __read_mostly;
103067 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103068
103069 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103070 +extern int grsec_enable_blackhole;
103071 +#endif
103072 +
103073 #ifdef CONFIG_TCP_MD5SIG
103074 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103075 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103076 @@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103077 return 0;
103078
103079 reset:
103080 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103081 + if (!grsec_enable_blackhole)
103082 +#endif
103083 tcp_v4_send_reset(rsk, skb);
103084 discard:
103085 kfree_skb(skb);
103086 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103087 TCP_SKB_CB(skb)->sacked = 0;
103088
103089 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103090 - if (!sk)
103091 + if (!sk) {
103092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103093 + ret = 1;
103094 +#endif
103095 goto no_tcp_socket;
103096 -
103097 + }
103098 process:
103099 - if (sk->sk_state == TCP_TIME_WAIT)
103100 + if (sk->sk_state == TCP_TIME_WAIT) {
103101 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103102 + ret = 2;
103103 +#endif
103104 goto do_time_wait;
103105 + }
103106
103107 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103108 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103109 @@ -1694,6 +1708,10 @@ csum_error:
103110 bad_packet:
103111 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103112 } else {
103113 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103114 + if (!grsec_enable_blackhole || (ret == 1 &&
103115 + (skb->dev->flags & IFF_LOOPBACK)))
103116 +#endif
103117 tcp_v4_send_reset(NULL, skb);
103118 }
103119
103120 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103121 index 63d2680..2db9d6b 100644
103122 --- a/net/ipv4/tcp_minisocks.c
103123 +++ b/net/ipv4/tcp_minisocks.c
103124 @@ -27,6 +27,10 @@
103125 #include <net/inet_common.h>
103126 #include <net/xfrm.h>
103127
103128 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103129 +extern int grsec_enable_blackhole;
103130 +#endif
103131 +
103132 int sysctl_tcp_syncookies __read_mostly = 1;
103133 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103134
103135 @@ -739,7 +743,10 @@ embryonic_reset:
103136 * avoid becoming vulnerable to outside attack aiming at
103137 * resetting legit local connections.
103138 */
103139 - req->rsk_ops->send_reset(sk, skb);
103140 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103141 + if (!grsec_enable_blackhole)
103142 +#endif
103143 + req->rsk_ops->send_reset(sk, skb);
103144 } else if (fastopen) { /* received a valid RST pkt */
103145 reqsk_fastopen_remove(sk, req, true);
103146 tcp_reset(sk);
103147 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103148 index ebf5ff5..4d1ff32 100644
103149 --- a/net/ipv4/tcp_probe.c
103150 +++ b/net/ipv4/tcp_probe.c
103151 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103152 if (cnt + width >= len)
103153 break;
103154
103155 - if (copy_to_user(buf + cnt, tbuf, width))
103156 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103157 return -EFAULT;
103158 cnt += width;
103159 }
103160 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103161 index 9b21ae8..4eb67df 100644
103162 --- a/net/ipv4/tcp_timer.c
103163 +++ b/net/ipv4/tcp_timer.c
103164 @@ -22,6 +22,10 @@
103165 #include <linux/gfp.h>
103166 #include <net/tcp.h>
103167
103168 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103169 +extern int grsec_lastack_retries;
103170 +#endif
103171 +
103172 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103173 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103174 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103175 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103176 }
103177 }
103178
103179 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103180 + if ((sk->sk_state == TCP_LAST_ACK) &&
103181 + (grsec_lastack_retries > 0) &&
103182 + (grsec_lastack_retries < retry_until))
103183 + retry_until = grsec_lastack_retries;
103184 +#endif
103185 +
103186 if (retransmits_timed_out(sk, retry_until,
103187 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103188 /* Has it gone just too far? */
103189 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103190 index cd0db54..93a6518 100644
103191 --- a/net/ipv4/udp.c
103192 +++ b/net/ipv4/udp.c
103193 @@ -87,6 +87,7 @@
103194 #include <linux/types.h>
103195 #include <linux/fcntl.h>
103196 #include <linux/module.h>
103197 +#include <linux/security.h>
103198 #include <linux/socket.h>
103199 #include <linux/sockios.h>
103200 #include <linux/igmp.h>
103201 @@ -114,6 +115,10 @@
103202 #include <net/busy_poll.h>
103203 #include "udp_impl.h"
103204
103205 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103206 +extern int grsec_enable_blackhole;
103207 +#endif
103208 +
103209 struct udp_table udp_table __read_mostly;
103210 EXPORT_SYMBOL(udp_table);
103211
103212 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103213 return true;
103214 }
103215
103216 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103217 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103218 +
103219 /*
103220 * This routine is called by the ICMP module when it gets some
103221 * sort of error condition. If err < 0 then the socket should
103222 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103223 dport = usin->sin_port;
103224 if (dport == 0)
103225 return -EINVAL;
103226 +
103227 + err = gr_search_udp_sendmsg(sk, usin);
103228 + if (err)
103229 + return err;
103230 } else {
103231 if (sk->sk_state != TCP_ESTABLISHED)
103232 return -EDESTADDRREQ;
103233 +
103234 + err = gr_search_udp_sendmsg(sk, NULL);
103235 + if (err)
103236 + return err;
103237 +
103238 daddr = inet->inet_daddr;
103239 dport = inet->inet_dport;
103240 /* Open fast path for connected socket.
103241 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103242 IS_UDPLITE(sk));
103243 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103244 IS_UDPLITE(sk));
103245 - atomic_inc(&sk->sk_drops);
103246 + atomic_inc_unchecked(&sk->sk_drops);
103247 __skb_unlink(skb, rcvq);
103248 __skb_queue_tail(&list_kill, skb);
103249 }
103250 @@ -1262,6 +1279,10 @@ try_again:
103251 if (!skb)
103252 goto out;
103253
103254 + err = gr_search_udp_recvmsg(sk, skb);
103255 + if (err)
103256 + goto out_free;
103257 +
103258 ulen = skb->len - sizeof(struct udphdr);
103259 copied = len;
103260 if (copied > ulen)
103261 @@ -1295,7 +1316,7 @@ try_again:
103262 if (unlikely(err)) {
103263 trace_kfree_skb(skb, udp_recvmsg);
103264 if (!peeked) {
103265 - atomic_inc(&sk->sk_drops);
103266 + atomic_inc_unchecked(&sk->sk_drops);
103267 UDP_INC_STATS_USER(sock_net(sk),
103268 UDP_MIB_INERRORS, is_udplite);
103269 }
103270 @@ -1592,7 +1613,7 @@ csum_error:
103271 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103272 drop:
103273 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103274 - atomic_inc(&sk->sk_drops);
103275 + atomic_inc_unchecked(&sk->sk_drops);
103276 kfree_skb(skb);
103277 return -1;
103278 }
103279 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103280 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103281
103282 if (!skb1) {
103283 - atomic_inc(&sk->sk_drops);
103284 + atomic_inc_unchecked(&sk->sk_drops);
103285 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103286 IS_UDPLITE(sk));
103287 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103288 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103289 goto csum_error;
103290
103291 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103292 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103293 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103294 +#endif
103295 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103296
103297 /*
103298 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103299 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103300 0, sock_i_ino(sp),
103301 atomic_read(&sp->sk_refcnt), sp,
103302 - atomic_read(&sp->sk_drops));
103303 + atomic_read_unchecked(&sp->sk_drops));
103304 }
103305
103306 int udp4_seq_show(struct seq_file *seq, void *v)
103307 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103308 index 6156f68..d6ab46d 100644
103309 --- a/net/ipv4/xfrm4_policy.c
103310 +++ b/net/ipv4/xfrm4_policy.c
103311 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103312 fl4->flowi4_tos = iph->tos;
103313 }
103314
103315 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103316 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103317 {
103318 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103319
103320 - xfrm4_policy_afinfo.garbage_collect(net);
103321 + xfrm_garbage_collect_deferred(net);
103322 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103323 }
103324
103325 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103326
103327 static int __net_init xfrm4_net_init(struct net *net)
103328 {
103329 - struct ctl_table *table;
103330 + ctl_table_no_const *table = NULL;
103331 struct ctl_table_header *hdr;
103332
103333 - table = xfrm4_policy_table;
103334 if (!net_eq(net, &init_net)) {
103335 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103336 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103337 if (!table)
103338 goto err_alloc;
103339
103340 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103341 - }
103342 -
103343 - hdr = register_net_sysctl(net, "net/ipv4", table);
103344 + hdr = register_net_sysctl(net, "net/ipv4", table);
103345 + } else
103346 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103347 if (!hdr)
103348 goto err_reg;
103349
103350 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103351 return 0;
103352
103353 err_reg:
103354 - if (!net_eq(net, &init_net))
103355 - kfree(table);
103356 + kfree(table);
103357 err_alloc:
103358 return -ENOMEM;
103359 }
103360 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103361 index 0169ccf..50d7b04 100644
103362 --- a/net/ipv6/addrconf.c
103363 +++ b/net/ipv6/addrconf.c
103364 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103365 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103366 .mtu6 = IPV6_MIN_MTU,
103367 .accept_ra = 1,
103368 - .accept_redirects = 1,
103369 + .accept_redirects = 0,
103370 .autoconf = 1,
103371 .force_mld_version = 0,
103372 .mldv1_unsolicited_report_interval = 10 * HZ,
103373 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103374 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103375 .mtu6 = IPV6_MIN_MTU,
103376 .accept_ra = 1,
103377 - .accept_redirects = 1,
103378 + .accept_redirects = 0,
103379 .autoconf = 1,
103380 .force_mld_version = 0,
103381 .mldv1_unsolicited_report_interval = 10 * HZ,
103382 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103383 idx = 0;
103384 head = &net->dev_index_head[h];
103385 rcu_read_lock();
103386 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103387 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103388 net->dev_base_seq;
103389 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103390 if (idx < s_idx)
103391 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103392 p.iph.ihl = 5;
103393 p.iph.protocol = IPPROTO_IPV6;
103394 p.iph.ttl = 64;
103395 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103396 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103397
103398 if (ops->ndo_do_ioctl) {
103399 mm_segment_t oldfs = get_fs();
103400 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103401 .release = seq_release_net,
103402 };
103403
103404 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103405 +extern void unregister_ipv6_seq_ops_addr(void);
103406 +
103407 static int __net_init if6_proc_net_init(struct net *net)
103408 {
103409 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103410 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103411 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103412 + unregister_ipv6_seq_ops_addr();
103413 return -ENOMEM;
103414 + }
103415 return 0;
103416 }
103417
103418 static void __net_exit if6_proc_net_exit(struct net *net)
103419 {
103420 remove_proc_entry("if_inet6", net->proc_net);
103421 + unregister_ipv6_seq_ops_addr();
103422 }
103423
103424 static struct pernet_operations if6_proc_net_ops = {
103425 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103426 s_ip_idx = ip_idx = cb->args[2];
103427
103428 rcu_read_lock();
103429 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103430 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103431 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103432 idx = 0;
103433 head = &net->dev_index_head[h];
103434 @@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103435 rt_genid_bump_ipv6(net);
103436 break;
103437 }
103438 - atomic_inc(&net->ipv6.dev_addr_genid);
103439 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103440 }
103441
103442 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103443 @@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103444 int *valp = ctl->data;
103445 int val = *valp;
103446 loff_t pos = *ppos;
103447 - struct ctl_table lctl;
103448 + ctl_table_no_const lctl;
103449 int ret;
103450
103451 /*
103452 @@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103453 int *valp = ctl->data;
103454 int val = *valp;
103455 loff_t pos = *ppos;
103456 - struct ctl_table lctl;
103457 + ctl_table_no_const lctl;
103458 int ret;
103459
103460 /*
103461 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103462 index e8c4400..a4cd5da 100644
103463 --- a/net/ipv6/af_inet6.c
103464 +++ b/net/ipv6/af_inet6.c
103465 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103466 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103467 net->ipv6.sysctl.flowlabel_consistency = 1;
103468 net->ipv6.sysctl.auto_flowlabels = 0;
103469 - atomic_set(&net->ipv6.fib6_sernum, 1);
103470 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103471
103472 err = ipv6_init_mibs(net);
103473 if (err)
103474 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103475 index 2cdc383..4f1b785 100644
103476 --- a/net/ipv6/datagram.c
103477 +++ b/net/ipv6/datagram.c
103478 @@ -383,11 +383,10 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103479
103480 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
103481 sin = &errhdr.offender;
103482 - sin->sin6_family = AF_UNSPEC;
103483 + memset(sin, 0, sizeof(*sin));
103484 +
103485 if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
103486 sin->sin6_family = AF_INET6;
103487 - sin->sin6_flowinfo = 0;
103488 - sin->sin6_port = 0;
103489 if (np->rxopt.all)
103490 ip6_datagram_recv_common_ctl(sk, msg, skb);
103491 if (skb->protocol == htons(ETH_P_IPV6)) {
103492 @@ -398,12 +397,9 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
103493 ipv6_iface_scope_id(&sin->sin6_addr,
103494 IP6CB(skb)->iif);
103495 } else {
103496 - struct inet_sock *inet = inet_sk(sk);
103497 -
103498 ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
103499 &sin->sin6_addr);
103500 - sin->sin6_scope_id = 0;
103501 - if (inet->cmsg_flags)
103502 + if (inet_sk(sk)->cmsg_flags)
103503 ip_cmsg_recv(msg, skb);
103504 }
103505 }
103506 @@ -928,5 +924,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103507 0,
103508 sock_i_ino(sp),
103509 atomic_read(&sp->sk_refcnt), sp,
103510 - atomic_read(&sp->sk_drops));
103511 + atomic_read_unchecked(&sp->sk_drops));
103512 }
103513 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103514 index 97ae700..18dcae0 100644
103515 --- a/net/ipv6/icmp.c
103516 +++ b/net/ipv6/icmp.c
103517 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103518
103519 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103520 {
103521 - struct ctl_table *table;
103522 + ctl_table_no_const *table;
103523
103524 table = kmemdup(ipv6_icmp_table_template,
103525 sizeof(ipv6_icmp_table_template),
103526 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103527 index b2d1838..0194c04 100644
103528 --- a/net/ipv6/ip6_fib.c
103529 +++ b/net/ipv6/ip6_fib.c
103530 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103531 int new, old;
103532
103533 do {
103534 - old = atomic_read(&net->ipv6.fib6_sernum);
103535 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103536 new = old < INT_MAX ? old + 1 : 1;
103537 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103538 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103539 old, new) != old);
103540 return new;
103541 }
103542 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103543 index 0e32d2e..98cbe65 100644
103544 --- a/net/ipv6/ip6_gre.c
103545 +++ b/net/ipv6/ip6_gre.c
103546 @@ -71,8 +71,8 @@ struct ip6gre_net {
103547 struct net_device *fb_tunnel_dev;
103548 };
103549
103550 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103551 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103552 +static struct rtnl_link_ops ip6gre_link_ops;
103553 +static struct rtnl_link_ops ip6gre_tap_ops;
103554 static int ip6gre_tunnel_init(struct net_device *dev);
103555 static void ip6gre_tunnel_setup(struct net_device *dev);
103556 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103557 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103558 }
103559
103560
103561 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103562 +static struct inet6_protocol ip6gre_protocol = {
103563 .handler = ip6gre_rcv,
103564 .err_handler = ip6gre_err,
103565 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103566 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103567 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103568 };
103569
103570 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103571 +static struct rtnl_link_ops ip6gre_link_ops = {
103572 .kind = "ip6gre",
103573 .maxtype = IFLA_GRE_MAX,
103574 .policy = ip6gre_policy,
103575 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103576 .fill_info = ip6gre_fill_info,
103577 };
103578
103579 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103580 +static struct rtnl_link_ops ip6gre_tap_ops = {
103581 .kind = "ip6gretap",
103582 .maxtype = IFLA_GRE_MAX,
103583 .policy = ip6gre_policy,
103584 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103585 index 9cb94cf..5678108 100644
103586 --- a/net/ipv6/ip6_tunnel.c
103587 +++ b/net/ipv6/ip6_tunnel.c
103588 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103589
103590 static int ip6_tnl_dev_init(struct net_device *dev);
103591 static void ip6_tnl_dev_setup(struct net_device *dev);
103592 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103593 +static struct rtnl_link_ops ip6_link_ops;
103594
103595 static int ip6_tnl_net_id __read_mostly;
103596 struct ip6_tnl_net {
103597 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103598 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103599 };
103600
103601 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103602 +static struct rtnl_link_ops ip6_link_ops = {
103603 .kind = "ip6tnl",
103604 .maxtype = IFLA_IPTUN_MAX,
103605 .policy = ip6_tnl_policy,
103606 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103607 index bcda14d..49378c9 100644
103608 --- a/net/ipv6/ip6_vti.c
103609 +++ b/net/ipv6/ip6_vti.c
103610 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103611
103612 static int vti6_dev_init(struct net_device *dev);
103613 static void vti6_dev_setup(struct net_device *dev);
103614 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103615 +static struct rtnl_link_ops vti6_link_ops;
103616
103617 static int vti6_net_id __read_mostly;
103618 struct vti6_net {
103619 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103620 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103621 };
103622
103623 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103624 +static struct rtnl_link_ops vti6_link_ops = {
103625 .kind = "vti6",
103626 .maxtype = IFLA_VTI_MAX,
103627 .policy = vti6_policy,
103628 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103629 index e1a9583..7dd8f4d 100644
103630 --- a/net/ipv6/ipv6_sockglue.c
103631 +++ b/net/ipv6/ipv6_sockglue.c
103632 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103633 if (sk->sk_type != SOCK_STREAM)
103634 return -ENOPROTOOPT;
103635
103636 - msg.msg_control = optval;
103637 + msg.msg_control = (void __force_kernel *)optval;
103638 msg.msg_controllen = len;
103639 msg.msg_flags = flags;
103640
103641 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103642 index e080fbb..412b3cf 100644
103643 --- a/net/ipv6/netfilter/ip6_tables.c
103644 +++ b/net/ipv6/netfilter/ip6_tables.c
103645 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103646 #endif
103647
103648 static int get_info(struct net *net, void __user *user,
103649 - const int *len, int compat)
103650 + int len, int compat)
103651 {
103652 char name[XT_TABLE_MAXNAMELEN];
103653 struct xt_table *t;
103654 int ret;
103655
103656 - if (*len != sizeof(struct ip6t_getinfo)) {
103657 - duprintf("length %u != %zu\n", *len,
103658 + if (len != sizeof(struct ip6t_getinfo)) {
103659 + duprintf("length %u != %zu\n", len,
103660 sizeof(struct ip6t_getinfo));
103661 return -EINVAL;
103662 }
103663 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103664 info.size = private->size;
103665 strcpy(info.name, name);
103666
103667 - if (copy_to_user(user, &info, *len) != 0)
103668 + if (copy_to_user(user, &info, len) != 0)
103669 ret = -EFAULT;
103670 else
103671 ret = 0;
103672 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103673
103674 switch (cmd) {
103675 case IP6T_SO_GET_INFO:
103676 - ret = get_info(sock_net(sk), user, len, 1);
103677 + ret = get_info(sock_net(sk), user, *len, 1);
103678 break;
103679 case IP6T_SO_GET_ENTRIES:
103680 ret = compat_get_entries(sock_net(sk), user, len);
103681 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103682
103683 switch (cmd) {
103684 case IP6T_SO_GET_INFO:
103685 - ret = get_info(sock_net(sk), user, len, 0);
103686 + ret = get_info(sock_net(sk), user, *len, 0);
103687 break;
103688
103689 case IP6T_SO_GET_ENTRIES:
103690 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103691 index 6f187c8..34b367f 100644
103692 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103693 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103694 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103695
103696 static int nf_ct_frag6_sysctl_register(struct net *net)
103697 {
103698 - struct ctl_table *table;
103699 + ctl_table_no_const *table = NULL;
103700 struct ctl_table_header *hdr;
103701
103702 - table = nf_ct_frag6_sysctl_table;
103703 if (!net_eq(net, &init_net)) {
103704 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103705 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103706 GFP_KERNEL);
103707 if (table == NULL)
103708 goto err_alloc;
103709 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103710 table[2].data = &net->nf_frag.frags.high_thresh;
103711 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103712 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103713 - }
103714 -
103715 - hdr = register_net_sysctl(net, "net/netfilter", table);
103716 + hdr = register_net_sysctl(net, "net/netfilter", table);
103717 + } else
103718 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103719 if (hdr == NULL)
103720 goto err_reg;
103721
103722 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103723 return 0;
103724
103725 err_reg:
103726 - if (!net_eq(net, &init_net))
103727 - kfree(table);
103728 + kfree(table);
103729 err_alloc:
103730 return -ENOMEM;
103731 }
103732 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103733 index 5b7a1ed..d9da205 100644
103734 --- a/net/ipv6/ping.c
103735 +++ b/net/ipv6/ping.c
103736 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103737 };
103738 #endif
103739
103740 +static struct pingv6_ops real_pingv6_ops = {
103741 + .ipv6_recv_error = ipv6_recv_error,
103742 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103743 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103744 + .icmpv6_err_convert = icmpv6_err_convert,
103745 + .ipv6_icmp_error = ipv6_icmp_error,
103746 + .ipv6_chk_addr = ipv6_chk_addr,
103747 +};
103748 +
103749 +static struct pingv6_ops dummy_pingv6_ops = {
103750 + .ipv6_recv_error = dummy_ipv6_recv_error,
103751 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103752 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103753 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
103754 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
103755 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
103756 +};
103757 +
103758 int __init pingv6_init(void)
103759 {
103760 #ifdef CONFIG_PROC_FS
103761 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
103762 if (ret)
103763 return ret;
103764 #endif
103765 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103766 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103767 - pingv6_ops.ip6_datagram_recv_specific_ctl =
103768 - ip6_datagram_recv_specific_ctl;
103769 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103770 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103771 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103772 + pingv6_ops = &real_pingv6_ops;
103773 return inet6_register_protosw(&pingv6_protosw);
103774 }
103775
103776 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
103777 */
103778 void pingv6_exit(void)
103779 {
103780 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103781 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103782 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103783 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103784 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103785 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103786 #ifdef CONFIG_PROC_FS
103787 unregister_pernet_subsys(&ping_v6_net_ops);
103788 #endif
103789 + pingv6_ops = &dummy_pingv6_ops;
103790 inet6_unregister_protosw(&pingv6_protosw);
103791 }
103792 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103793 index 1752cd0..3c6af41 100644
103794 --- a/net/ipv6/proc.c
103795 +++ b/net/ipv6/proc.c
103796 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103797 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103798 goto proc_snmp6_fail;
103799
103800 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103801 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103802 if (!net->mib.proc_net_devsnmp6)
103803 goto proc_dev_snmp6_fail;
103804 return 0;
103805 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103806 index 896af88..6e2ba628 100644
103807 --- a/net/ipv6/raw.c
103808 +++ b/net/ipv6/raw.c
103809 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103810 {
103811 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103812 skb_checksum_complete(skb)) {
103813 - atomic_inc(&sk->sk_drops);
103814 + atomic_inc_unchecked(&sk->sk_drops);
103815 kfree_skb(skb);
103816 return NET_RX_DROP;
103817 }
103818 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103819 struct raw6_sock *rp = raw6_sk(sk);
103820
103821 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103822 - atomic_inc(&sk->sk_drops);
103823 + atomic_inc_unchecked(&sk->sk_drops);
103824 kfree_skb(skb);
103825 return NET_RX_DROP;
103826 }
103827 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103828
103829 if (inet->hdrincl) {
103830 if (skb_checksum_complete(skb)) {
103831 - atomic_inc(&sk->sk_drops);
103832 + atomic_inc_unchecked(&sk->sk_drops);
103833 kfree_skb(skb);
103834 return NET_RX_DROP;
103835 }
103836 @@ -608,7 +608,7 @@ out:
103837 return err;
103838 }
103839
103840 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103841 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103842 struct flowi6 *fl6, struct dst_entry **dstp,
103843 unsigned int flags)
103844 {
103845 @@ -914,12 +914,15 @@ do_confirm:
103846 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103847 char __user *optval, int optlen)
103848 {
103849 + struct icmp6_filter filter;
103850 +
103851 switch (optname) {
103852 case ICMPV6_FILTER:
103853 if (optlen > sizeof(struct icmp6_filter))
103854 optlen = sizeof(struct icmp6_filter);
103855 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103856 + if (copy_from_user(&filter, optval, optlen))
103857 return -EFAULT;
103858 + raw6_sk(sk)->filter = filter;
103859 return 0;
103860 default:
103861 return -ENOPROTOOPT;
103862 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103863 char __user *optval, int __user *optlen)
103864 {
103865 int len;
103866 + struct icmp6_filter filter;
103867
103868 switch (optname) {
103869 case ICMPV6_FILTER:
103870 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103871 len = sizeof(struct icmp6_filter);
103872 if (put_user(len, optlen))
103873 return -EFAULT;
103874 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103875 + filter = raw6_sk(sk)->filter;
103876 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
103877 return -EFAULT;
103878 return 0;
103879 default:
103880 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103881 index 1a157ca..9fc05f4 100644
103882 --- a/net/ipv6/reassembly.c
103883 +++ b/net/ipv6/reassembly.c
103884 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103885
103886 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103887 {
103888 - struct ctl_table *table;
103889 + ctl_table_no_const *table = NULL;
103890 struct ctl_table_header *hdr;
103891
103892 - table = ip6_frags_ns_ctl_table;
103893 if (!net_eq(net, &init_net)) {
103894 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103895 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103896 if (table == NULL)
103897 goto err_alloc;
103898
103899 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103900 /* Don't export sysctls to unprivileged users */
103901 if (net->user_ns != &init_user_ns)
103902 table[0].procname = NULL;
103903 - }
103904 + hdr = register_net_sysctl(net, "net/ipv6", table);
103905 + } else
103906 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103907
103908 - hdr = register_net_sysctl(net, "net/ipv6", table);
103909 if (hdr == NULL)
103910 goto err_reg;
103911
103912 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103913 return 0;
103914
103915 err_reg:
103916 - if (!net_eq(net, &init_net))
103917 - kfree(table);
103918 + kfree(table);
103919 err_alloc:
103920 return -ENOMEM;
103921 }
103922 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103923 index a318dd89..42a612c 100644
103924 --- a/net/ipv6/route.c
103925 +++ b/net/ipv6/route.c
103926 @@ -1150,12 +1150,9 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
103927 struct net *net = dev_net(dst->dev);
103928
103929 rt6->rt6i_flags |= RTF_MODIFIED;
103930 - if (mtu < IPV6_MIN_MTU) {
103931 - u32 features = dst_metric(dst, RTAX_FEATURES);
103932 + if (mtu < IPV6_MIN_MTU)
103933 mtu = IPV6_MIN_MTU;
103934 - features |= RTAX_FEATURE_ALLFRAG;
103935 - dst_metric_set(dst, RTAX_FEATURES, features);
103936 - }
103937 +
103938 dst_metric_set(dst, RTAX_MTU, mtu);
103939 rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
103940 }
103941 @@ -2965,7 +2962,7 @@ struct ctl_table ipv6_route_table_template[] = {
103942
103943 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103944 {
103945 - struct ctl_table *table;
103946 + ctl_table_no_const *table;
103947
103948 table = kmemdup(ipv6_route_table_template,
103949 sizeof(ipv6_route_table_template),
103950 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103951 index a24557a..00a9ed1 100644
103952 --- a/net/ipv6/sit.c
103953 +++ b/net/ipv6/sit.c
103954 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103955 static void ipip6_dev_free(struct net_device *dev);
103956 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103957 __be32 *v4dst);
103958 -static struct rtnl_link_ops sit_link_ops __read_mostly;
103959 +static struct rtnl_link_ops sit_link_ops;
103960
103961 static int sit_net_id __read_mostly;
103962 struct sit_net {
103963 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103964 unregister_netdevice_queue(dev, head);
103965 }
103966
103967 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
103968 +static struct rtnl_link_ops sit_link_ops = {
103969 .kind = "sit",
103970 .maxtype = IFLA_IPTUN_MAX,
103971 .policy = ipip6_policy,
103972 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103973 index c5c10fa..2577d51 100644
103974 --- a/net/ipv6/sysctl_net_ipv6.c
103975 +++ b/net/ipv6/sysctl_net_ipv6.c
103976 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
103977
103978 static int __net_init ipv6_sysctl_net_init(struct net *net)
103979 {
103980 - struct ctl_table *ipv6_table;
103981 + ctl_table_no_const *ipv6_table;
103982 struct ctl_table *ipv6_route_table;
103983 struct ctl_table *ipv6_icmp_table;
103984 int err;
103985 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103986 index c113602..0cccb46 100644
103987 --- a/net/ipv6/tcp_ipv6.c
103988 +++ b/net/ipv6/tcp_ipv6.c
103989 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103990 }
103991 }
103992
103993 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103994 +extern int grsec_enable_blackhole;
103995 +#endif
103996 +
103997 static void tcp_v6_hash(struct sock *sk)
103998 {
103999 if (sk->sk_state != TCP_CLOSE) {
104000 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104001 return 0;
104002
104003 reset:
104004 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104005 + if (!grsec_enable_blackhole)
104006 +#endif
104007 tcp_v6_send_reset(sk, skb);
104008 discard:
104009 if (opt_skb)
104010 @@ -1441,12 +1448,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104011
104012 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
104013 inet6_iif(skb));
104014 - if (!sk)
104015 + if (!sk) {
104016 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104017 + ret = 1;
104018 +#endif
104019 goto no_tcp_socket;
104020 + }
104021
104022 process:
104023 - if (sk->sk_state == TCP_TIME_WAIT)
104024 + if (sk->sk_state == TCP_TIME_WAIT) {
104025 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104026 + ret = 2;
104027 +#endif
104028 goto do_time_wait;
104029 + }
104030
104031 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104032 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104033 @@ -1497,6 +1512,10 @@ csum_error:
104034 bad_packet:
104035 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104036 } else {
104037 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104038 + if (!grsec_enable_blackhole || (ret == 1 &&
104039 + (skb->dev->flags & IFF_LOOPBACK)))
104040 +#endif
104041 tcp_v6_send_reset(NULL, skb);
104042 }
104043
104044 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104045 index f6ba535..b41033f 100644
104046 --- a/net/ipv6/udp.c
104047 +++ b/net/ipv6/udp.c
104048 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104049 udp_ipv6_hash_secret + net_hash_mix(net));
104050 }
104051
104052 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104053 +extern int grsec_enable_blackhole;
104054 +#endif
104055 +
104056 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104057 {
104058 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104059 @@ -434,7 +438,7 @@ try_again:
104060 if (unlikely(err)) {
104061 trace_kfree_skb(skb, udpv6_recvmsg);
104062 if (!peeked) {
104063 - atomic_inc(&sk->sk_drops);
104064 + atomic_inc_unchecked(&sk->sk_drops);
104065 if (is_udp4)
104066 UDP_INC_STATS_USER(sock_net(sk),
104067 UDP_MIB_INERRORS,
104068 @@ -701,7 +705,7 @@ csum_error:
104069 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104070 drop:
104071 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104072 - atomic_inc(&sk->sk_drops);
104073 + atomic_inc_unchecked(&sk->sk_drops);
104074 kfree_skb(skb);
104075 return -1;
104076 }
104077 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104078 if (likely(skb1 == NULL))
104079 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104080 if (!skb1) {
104081 - atomic_inc(&sk->sk_drops);
104082 + atomic_inc_unchecked(&sk->sk_drops);
104083 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104084 IS_UDPLITE(sk));
104085 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104086 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104087 goto csum_error;
104088
104089 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104090 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104091 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104092 +#endif
104093 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104094
104095 kfree_skb(skb);
104096 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104097 index 5f98364..691985a 100644
104098 --- a/net/ipv6/xfrm6_policy.c
104099 +++ b/net/ipv6/xfrm6_policy.c
104100 @@ -130,12 +130,18 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104101 {
104102 struct flowi6 *fl6 = &fl->u.ip6;
104103 int onlyproto = 0;
104104 - u16 offset = skb_network_header_len(skb);
104105 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104106 + u16 offset = sizeof(*hdr);
104107 struct ipv6_opt_hdr *exthdr;
104108 const unsigned char *nh = skb_network_header(skb);
104109 - u8 nexthdr = nh[IP6CB(skb)->nhoff];
104110 + u16 nhoff = IP6CB(skb)->nhoff;
104111 int oif = 0;
104112 + u8 nexthdr;
104113 +
104114 + if (!nhoff)
104115 + nhoff = offsetof(struct ipv6hdr, nexthdr);
104116 +
104117 + nexthdr = nh[nhoff];
104118
104119 if (skb_dst(skb))
104120 oif = skb_dst(skb)->dev->ifindex;
104121 @@ -217,11 +223,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104122 }
104123 }
104124
104125 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104126 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104127 {
104128 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104129
104130 - xfrm6_policy_afinfo.garbage_collect(net);
104131 + xfrm_garbage_collect_deferred(net);
104132 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104133 }
104134
104135 @@ -334,19 +340,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104136
104137 static int __net_init xfrm6_net_init(struct net *net)
104138 {
104139 - struct ctl_table *table;
104140 + ctl_table_no_const *table = NULL;
104141 struct ctl_table_header *hdr;
104142
104143 - table = xfrm6_policy_table;
104144 if (!net_eq(net, &init_net)) {
104145 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104146 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104147 if (!table)
104148 goto err_alloc;
104149
104150 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104151 - }
104152 + hdr = register_net_sysctl(net, "net/ipv6", table);
104153 + } else
104154 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104155
104156 - hdr = register_net_sysctl(net, "net/ipv6", table);
104157 if (!hdr)
104158 goto err_reg;
104159
104160 @@ -354,8 +360,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104161 return 0;
104162
104163 err_reg:
104164 - if (!net_eq(net, &init_net))
104165 - kfree(table);
104166 + kfree(table);
104167 err_alloc:
104168 return -ENOMEM;
104169 }
104170 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104171 index e15c16a..7cf07aa 100644
104172 --- a/net/ipx/ipx_proc.c
104173 +++ b/net/ipx/ipx_proc.c
104174 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104175 struct proc_dir_entry *p;
104176 int rc = -ENOMEM;
104177
104178 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104179 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104180
104181 if (!ipx_proc_dir)
104182 goto out;
104183 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104184 index 61ceb4c..e788eb8 100644
104185 --- a/net/irda/ircomm/ircomm_tty.c
104186 +++ b/net/irda/ircomm/ircomm_tty.c
104187 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104188 add_wait_queue(&port->open_wait, &wait);
104189
104190 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104191 - __FILE__, __LINE__, tty->driver->name, port->count);
104192 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104193
104194 spin_lock_irqsave(&port->lock, flags);
104195 - port->count--;
104196 + atomic_dec(&port->count);
104197 port->blocked_open++;
104198 spin_unlock_irqrestore(&port->lock, flags);
104199
104200 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104201 }
104202
104203 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104204 - __FILE__, __LINE__, tty->driver->name, port->count);
104205 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104206
104207 schedule();
104208 }
104209 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104210
104211 spin_lock_irqsave(&port->lock, flags);
104212 if (!tty_hung_up_p(filp))
104213 - port->count++;
104214 + atomic_inc(&port->count);
104215 port->blocked_open--;
104216 spin_unlock_irqrestore(&port->lock, flags);
104217
104218 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104219 - __FILE__, __LINE__, tty->driver->name, port->count);
104220 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104221
104222 if (!retval)
104223 port->flags |= ASYNC_NORMAL_ACTIVE;
104224 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104225
104226 /* ++ is not atomic, so this should be protected - Jean II */
104227 spin_lock_irqsave(&self->port.lock, flags);
104228 - self->port.count++;
104229 + atomic_inc(&self->port.count);
104230 spin_unlock_irqrestore(&self->port.lock, flags);
104231 tty_port_tty_set(&self->port, tty);
104232
104233 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104234 - self->line, self->port.count);
104235 + self->line, atomic_read(&self->port.count));
104236
104237 /* Not really used by us, but lets do it anyway */
104238 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104239 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104240 tty_kref_put(port->tty);
104241 }
104242 port->tty = NULL;
104243 - port->count = 0;
104244 + atomic_set(&port->count, 0);
104245 spin_unlock_irqrestore(&port->lock, flags);
104246
104247 wake_up_interruptible(&port->open_wait);
104248 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104249 seq_putc(m, '\n');
104250
104251 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104252 - seq_printf(m, "Open count: %d\n", self->port.count);
104253 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104254 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104255 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104256
104257 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104258 index b9ac598..f88cc56 100644
104259 --- a/net/irda/irproc.c
104260 +++ b/net/irda/irproc.c
104261 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104262 {
104263 int i;
104264
104265 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104266 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104267 if (proc_irda == NULL)
104268 return;
104269
104270 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104271 index a089b6b..3ca3b60 100644
104272 --- a/net/iucv/af_iucv.c
104273 +++ b/net/iucv/af_iucv.c
104274 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104275 {
104276 char name[12];
104277
104278 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104279 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104280 while (__iucv_get_sock_by_name(name)) {
104281 sprintf(name, "%08x",
104282 - atomic_inc_return(&iucv_sk_list.autobind_name));
104283 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104284 }
104285 memcpy(iucv->src_name, name, 8);
104286 }
104287 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104288 index 2a6a1fd..6c112b0 100644
104289 --- a/net/iucv/iucv.c
104290 +++ b/net/iucv/iucv.c
104291 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104292 return NOTIFY_OK;
104293 }
104294
104295 -static struct notifier_block __refdata iucv_cpu_notifier = {
104296 +static struct notifier_block iucv_cpu_notifier = {
104297 .notifier_call = iucv_cpu_notify,
104298 };
104299
104300 diff --git a/net/key/af_key.c b/net/key/af_key.c
104301 index 1847ec4..26ef732 100644
104302 --- a/net/key/af_key.c
104303 +++ b/net/key/af_key.c
104304 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104305 static u32 get_acqseq(void)
104306 {
104307 u32 res;
104308 - static atomic_t acqseq;
104309 + static atomic_unchecked_t acqseq;
104310
104311 do {
104312 - res = atomic_inc_return(&acqseq);
104313 + res = atomic_inc_return_unchecked(&acqseq);
104314 } while (!res);
104315 return res;
104316 }
104317 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104318 index edb78e6..8dc654a 100644
104319 --- a/net/l2tp/l2tp_eth.c
104320 +++ b/net/l2tp/l2tp_eth.c
104321 @@ -42,12 +42,12 @@ struct l2tp_eth {
104322 struct sock *tunnel_sock;
104323 struct l2tp_session *session;
104324 struct list_head list;
104325 - atomic_long_t tx_bytes;
104326 - atomic_long_t tx_packets;
104327 - atomic_long_t tx_dropped;
104328 - atomic_long_t rx_bytes;
104329 - atomic_long_t rx_packets;
104330 - atomic_long_t rx_errors;
104331 + atomic_long_unchecked_t tx_bytes;
104332 + atomic_long_unchecked_t tx_packets;
104333 + atomic_long_unchecked_t tx_dropped;
104334 + atomic_long_unchecked_t rx_bytes;
104335 + atomic_long_unchecked_t rx_packets;
104336 + atomic_long_unchecked_t rx_errors;
104337 };
104338
104339 /* via l2tp_session_priv() */
104340 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104341 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104342
104343 if (likely(ret == NET_XMIT_SUCCESS)) {
104344 - atomic_long_add(len, &priv->tx_bytes);
104345 - atomic_long_inc(&priv->tx_packets);
104346 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104347 + atomic_long_inc_unchecked(&priv->tx_packets);
104348 } else {
104349 - atomic_long_inc(&priv->tx_dropped);
104350 + atomic_long_inc_unchecked(&priv->tx_dropped);
104351 }
104352 return NETDEV_TX_OK;
104353 }
104354 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104355 {
104356 struct l2tp_eth *priv = netdev_priv(dev);
104357
104358 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104359 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104360 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104361 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104362 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104363 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104364 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104365 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104366 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104367 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104368 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104369 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104370 return stats;
104371 }
104372
104373 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104374 nf_reset(skb);
104375
104376 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104377 - atomic_long_inc(&priv->rx_packets);
104378 - atomic_long_add(data_len, &priv->rx_bytes);
104379 + atomic_long_inc_unchecked(&priv->rx_packets);
104380 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104381 } else {
104382 - atomic_long_inc(&priv->rx_errors);
104383 + atomic_long_inc_unchecked(&priv->rx_errors);
104384 }
104385 return;
104386
104387 error:
104388 - atomic_long_inc(&priv->rx_errors);
104389 + atomic_long_inc_unchecked(&priv->rx_errors);
104390 kfree_skb(skb);
104391 }
104392
104393 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104394 index 1a3c7e0..80f8b0c 100644
104395 --- a/net/llc/llc_proc.c
104396 +++ b/net/llc/llc_proc.c
104397 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104398 int rc = -ENOMEM;
104399 struct proc_dir_entry *p;
104400
104401 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104402 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104403 if (!llc_proc_dir)
104404 goto out;
104405
104406 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104407 index 343da1e..509873f 100644
104408 --- a/net/mac80211/cfg.c
104409 +++ b/net/mac80211/cfg.c
104410 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104411 ret = ieee80211_vif_use_channel(sdata, chandef,
104412 IEEE80211_CHANCTX_EXCLUSIVE);
104413 }
104414 - } else if (local->open_count == local->monitors) {
104415 + } else if (local_read(&local->open_count) == local->monitors) {
104416 local->_oper_chandef = *chandef;
104417 ieee80211_hw_config(local, 0);
104418 }
104419 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104420 else
104421 local->probe_req_reg--;
104422
104423 - if (!local->open_count)
104424 + if (!local_read(&local->open_count))
104425 break;
104426
104427 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104428 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104429 if (chanctx_conf) {
104430 *chandef = sdata->vif.bss_conf.chandef;
104431 ret = 0;
104432 - } else if (local->open_count > 0 &&
104433 - local->open_count == local->monitors &&
104434 + } else if (local_read(&local->open_count) > 0 &&
104435 + local_read(&local->open_count) == local->monitors &&
104436 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104437 if (local->use_chanctx)
104438 *chandef = local->monitor_chandef;
104439 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104440 index 8c68da3..0695016 100644
104441 --- a/net/mac80211/ieee80211_i.h
104442 +++ b/net/mac80211/ieee80211_i.h
104443 @@ -29,6 +29,7 @@
104444 #include <net/ieee80211_radiotap.h>
104445 #include <net/cfg80211.h>
104446 #include <net/mac80211.h>
104447 +#include <asm/local.h>
104448 #include "key.h"
104449 #include "sta_info.h"
104450 #include "debug.h"
104451 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
104452 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104453 spinlock_t queue_stop_reason_lock;
104454
104455 - int open_count;
104456 + local_t open_count;
104457 int monitors, cooked_mntrs;
104458 /* number of interfaces with corresponding FIF_ flags */
104459 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104460 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104461 index eeae0ab..0f24585 100644
104462 --- a/net/mac80211/iface.c
104463 +++ b/net/mac80211/iface.c
104464 @@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104465 break;
104466 }
104467
104468 - if (local->open_count == 0) {
104469 + if (local_read(&local->open_count) == 0) {
104470 res = drv_start(local);
104471 if (res)
104472 goto err_del_bss;
104473 @@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104474 res = drv_add_interface(local, sdata);
104475 if (res)
104476 goto err_stop;
104477 - } else if (local->monitors == 0 && local->open_count == 0) {
104478 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104479 res = ieee80211_add_virtual_monitor(local);
104480 if (res)
104481 goto err_stop;
104482 @@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104483 atomic_inc(&local->iff_promiscs);
104484
104485 if (coming_up)
104486 - local->open_count++;
104487 + local_inc(&local->open_count);
104488
104489 if (hw_reconf_flags)
104490 ieee80211_hw_config(local, hw_reconf_flags);
104491 @@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104492 err_del_interface:
104493 drv_remove_interface(local, sdata);
104494 err_stop:
104495 - if (!local->open_count)
104496 + if (!local_read(&local->open_count))
104497 drv_stop(local);
104498 err_del_bss:
104499 sdata->bss = NULL;
104500 @@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104501 }
104502
104503 if (going_down)
104504 - local->open_count--;
104505 + local_dec(&local->open_count);
104506
104507 switch (sdata->vif.type) {
104508 case NL80211_IFTYPE_AP_VLAN:
104509 @@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104510 }
104511 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104512
104513 - if (local->open_count == 0)
104514 + if (local_read(&local->open_count) == 0)
104515 ieee80211_clear_tx_pending(local);
104516
104517 /*
104518 @@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104519 if (cancel_scan)
104520 flush_delayed_work(&local->scan_work);
104521
104522 - if (local->open_count == 0) {
104523 + if (local_read(&local->open_count) == 0) {
104524 ieee80211_stop_device(local);
104525
104526 /* no reconfiguring after stop! */
104527 @@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104528 ieee80211_configure_filter(local);
104529 ieee80211_hw_config(local, hw_reconf_flags);
104530
104531 - if (local->monitors == local->open_count)
104532 + if (local->monitors == local_read(&local->open_count))
104533 ieee80211_add_virtual_monitor(local);
104534 }
104535
104536 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104537 index 0de7c93..884b2ca 100644
104538 --- a/net/mac80211/main.c
104539 +++ b/net/mac80211/main.c
104540 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104541 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104542 IEEE80211_CONF_CHANGE_POWER);
104543
104544 - if (changed && local->open_count) {
104545 + if (changed && local_read(&local->open_count)) {
104546 ret = drv_config(local, changed);
104547 /*
104548 * Goal:
104549 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104550 index 4c5192e..04cc0d8 100644
104551 --- a/net/mac80211/pm.c
104552 +++ b/net/mac80211/pm.c
104553 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104554 struct ieee80211_sub_if_data *sdata;
104555 struct sta_info *sta;
104556
104557 - if (!local->open_count)
104558 + if (!local_read(&local->open_count))
104559 goto suspend;
104560
104561 ieee80211_scan_cancel(local);
104562 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104563 cancel_work_sync(&local->dynamic_ps_enable_work);
104564 del_timer_sync(&local->dynamic_ps_timer);
104565
104566 - local->wowlan = wowlan && local->open_count;
104567 + local->wowlan = wowlan && local_read(&local->open_count);
104568 if (local->wowlan) {
104569 int err = drv_suspend(local, wowlan);
104570 if (err < 0) {
104571 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104572 WARN_ON(!list_empty(&local->chanctx_list));
104573
104574 /* stop hardware - this must stop RX */
104575 - if (local->open_count)
104576 + if (local_read(&local->open_count))
104577 ieee80211_stop_device(local);
104578
104579 suspend:
104580 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104581 index 6081329..ab23834 100644
104582 --- a/net/mac80211/rate.c
104583 +++ b/net/mac80211/rate.c
104584 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104585
104586 ASSERT_RTNL();
104587
104588 - if (local->open_count)
104589 + if (local_read(&local->open_count))
104590 return -EBUSY;
104591
104592 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104593 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104594 index 3c61060..7bed2e3 100644
104595 --- a/net/mac80211/util.c
104596 +++ b/net/mac80211/util.c
104597 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104598 }
104599 #endif
104600 /* everything else happens only if HW was up & running */
104601 - if (!local->open_count)
104602 + if (!local_read(&local->open_count))
104603 goto wake_up;
104604
104605 /*
104606 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104607 local->in_reconfig = false;
104608 barrier();
104609
104610 - if (local->monitors == local->open_count && local->monitors > 0)
104611 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104612 ieee80211_add_virtual_monitor(local);
104613
104614 /*
104615 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104616 index ae5096ab..e5aa70a 100644
104617 --- a/net/netfilter/Kconfig
104618 +++ b/net/netfilter/Kconfig
104619 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104620
104621 To compile it as a module, choose M here. If unsure, say N.
104622
104623 +config NETFILTER_XT_MATCH_GRADM
104624 + tristate '"gradm" match support'
104625 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104626 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104627 + ---help---
104628 + The gradm match allows to match on grsecurity RBAC being enabled.
104629 + It is useful when iptables rules are applied early on bootup to
104630 + prevent connections to the machine (except from a trusted host)
104631 + while the RBAC system is disabled.
104632 +
104633 config NETFILTER_XT_MATCH_HASHLIMIT
104634 tristate '"hashlimit" match support'
104635 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104636 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104637 index a9571be..c59e173 100644
104638 --- a/net/netfilter/Makefile
104639 +++ b/net/netfilter/Makefile
104640 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104641 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104642 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104643 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104644 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104645 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104646 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104647 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104648 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104649 index d259da3..6a32b2c 100644
104650 --- a/net/netfilter/ipset/ip_set_core.c
104651 +++ b/net/netfilter/ipset/ip_set_core.c
104652 @@ -1952,7 +1952,7 @@ done:
104653 return ret;
104654 }
104655
104656 -static struct nf_sockopt_ops so_set __read_mostly = {
104657 +static struct nf_sockopt_ops so_set = {
104658 .pf = PF_INET,
104659 .get_optmin = SO_IP_SET,
104660 .get_optmax = SO_IP_SET + 1,
104661 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104662 index b0f7b62..0541842 100644
104663 --- a/net/netfilter/ipvs/ip_vs_conn.c
104664 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104665 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104666 /* Increase the refcnt counter of the dest */
104667 ip_vs_dest_hold(dest);
104668
104669 - conn_flags = atomic_read(&dest->conn_flags);
104670 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104671 if (cp->protocol != IPPROTO_UDP)
104672 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104673 flags = cp->flags;
104674 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104675
104676 cp->control = NULL;
104677 atomic_set(&cp->n_control, 0);
104678 - atomic_set(&cp->in_pkts, 0);
104679 + atomic_set_unchecked(&cp->in_pkts, 0);
104680
104681 cp->packet_xmit = NULL;
104682 cp->app = NULL;
104683 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104684
104685 /* Don't drop the entry if its number of incoming packets is not
104686 located in [0, 8] */
104687 - i = atomic_read(&cp->in_pkts);
104688 + i = atomic_read_unchecked(&cp->in_pkts);
104689 if (i > 8 || i < 0) return 0;
104690
104691 if (!todrop_rate[i]) return 0;
104692 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104693 index 990decb..5075248 100644
104694 --- a/net/netfilter/ipvs/ip_vs_core.c
104695 +++ b/net/netfilter/ipvs/ip_vs_core.c
104696 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104697 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104698 /* do not touch skb anymore */
104699
104700 - atomic_inc(&cp->in_pkts);
104701 + atomic_inc_unchecked(&cp->in_pkts);
104702 ip_vs_conn_put(cp);
104703 return ret;
104704 }
104705 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104706 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104707 pkts = sysctl_sync_threshold(ipvs);
104708 else
104709 - pkts = atomic_add_return(1, &cp->in_pkts);
104710 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104711
104712 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104713 ip_vs_sync_conn(net, cp, pkts);
104714 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104715 index ac7ba68..9735acb9 100644
104716 --- a/net/netfilter/ipvs/ip_vs_ctl.c
104717 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
104718 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104719 */
104720 ip_vs_rs_hash(ipvs, dest);
104721 }
104722 - atomic_set(&dest->conn_flags, conn_flags);
104723 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
104724
104725 /* bind the service */
104726 old_svc = rcu_dereference_protected(dest->svc, 1);
104727 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104728 * align with netns init in ip_vs_control_net_init()
104729 */
104730
104731 -static struct ctl_table vs_vars[] = {
104732 +static ctl_table_no_const vs_vars[] __read_only = {
104733 {
104734 .procname = "amemthresh",
104735 .maxlen = sizeof(int),
104736 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104737 " %-7s %-6d %-10d %-10d\n",
104738 &dest->addr.in6,
104739 ntohs(dest->port),
104740 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104741 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104742 atomic_read(&dest->weight),
104743 atomic_read(&dest->activeconns),
104744 atomic_read(&dest->inactconns));
104745 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104746 "%-7s %-6d %-10d %-10d\n",
104747 ntohl(dest->addr.ip),
104748 ntohs(dest->port),
104749 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104750 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104751 atomic_read(&dest->weight),
104752 atomic_read(&dest->activeconns),
104753 atomic_read(&dest->inactconns));
104754 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104755
104756 entry.addr = dest->addr.ip;
104757 entry.port = dest->port;
104758 - entry.conn_flags = atomic_read(&dest->conn_flags);
104759 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104760 entry.weight = atomic_read(&dest->weight);
104761 entry.u_threshold = dest->u_threshold;
104762 entry.l_threshold = dest->l_threshold;
104763 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104764 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104765 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104766 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104767 - (atomic_read(&dest->conn_flags) &
104768 + (atomic_read_unchecked(&dest->conn_flags) &
104769 IP_VS_CONN_F_FWD_MASK)) ||
104770 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104771 atomic_read(&dest->weight)) ||
104772 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104773 {
104774 int idx;
104775 struct netns_ipvs *ipvs = net_ipvs(net);
104776 - struct ctl_table *tbl;
104777 + ctl_table_no_const *tbl;
104778
104779 atomic_set(&ipvs->dropentry, 0);
104780 spin_lock_init(&ipvs->dropentry_lock);
104781 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104782 index 127f140..553d652 100644
104783 --- a/net/netfilter/ipvs/ip_vs_lblc.c
104784 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
104785 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104786 * IPVS LBLC sysctl table
104787 */
104788 #ifdef CONFIG_SYSCTL
104789 -static struct ctl_table vs_vars_table[] = {
104790 +static ctl_table_no_const vs_vars_table[] __read_only = {
104791 {
104792 .procname = "lblc_expiration",
104793 .data = NULL,
104794 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104795 index 2229d2d..b32b785 100644
104796 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
104797 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104798 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104799 * IPVS LBLCR sysctl table
104800 */
104801
104802 -static struct ctl_table vs_vars_table[] = {
104803 +static ctl_table_no_const vs_vars_table[] __read_only = {
104804 {
104805 .procname = "lblcr_expiration",
104806 .data = NULL,
104807 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104808 index 7162c86..9eeb60e 100644
104809 --- a/net/netfilter/ipvs/ip_vs_sync.c
104810 +++ b/net/netfilter/ipvs/ip_vs_sync.c
104811 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104812 cp = cp->control;
104813 if (cp) {
104814 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104815 - pkts = atomic_add_return(1, &cp->in_pkts);
104816 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104817 else
104818 pkts = sysctl_sync_threshold(ipvs);
104819 ip_vs_sync_conn(net, cp->control, pkts);
104820 @@ -771,7 +771,7 @@ control:
104821 if (!cp)
104822 return;
104823 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104824 - pkts = atomic_add_return(1, &cp->in_pkts);
104825 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104826 else
104827 pkts = sysctl_sync_threshold(ipvs);
104828 goto sloop;
104829 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104830
104831 if (opt)
104832 memcpy(&cp->in_seq, opt, sizeof(*opt));
104833 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104834 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104835 cp->state = state;
104836 cp->old_state = cp->state;
104837 /*
104838 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104839 index bd90bf8..816a020d 100644
104840 --- a/net/netfilter/ipvs/ip_vs_xmit.c
104841 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
104842 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104843 else
104844 rc = NF_ACCEPT;
104845 /* do not touch skb anymore */
104846 - atomic_inc(&cp->in_pkts);
104847 + atomic_inc_unchecked(&cp->in_pkts);
104848 goto out;
104849 }
104850
104851 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104852 else
104853 rc = NF_ACCEPT;
104854 /* do not touch skb anymore */
104855 - atomic_inc(&cp->in_pkts);
104856 + atomic_inc_unchecked(&cp->in_pkts);
104857 goto out;
104858 }
104859
104860 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104861 index a4b5e2a..13b1de3 100644
104862 --- a/net/netfilter/nf_conntrack_acct.c
104863 +++ b/net/netfilter/nf_conntrack_acct.c
104864 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104865 #ifdef CONFIG_SYSCTL
104866 static int nf_conntrack_acct_init_sysctl(struct net *net)
104867 {
104868 - struct ctl_table *table;
104869 + ctl_table_no_const *table;
104870
104871 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104872 GFP_KERNEL);
104873 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104874 index 5016a69..594f8e9 100644
104875 --- a/net/netfilter/nf_conntrack_core.c
104876 +++ b/net/netfilter/nf_conntrack_core.c
104877 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104878 #define DYING_NULLS_VAL ((1<<30)+1)
104879 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104880
104881 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104882 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104883 +#endif
104884 +
104885 int nf_conntrack_init_net(struct net *net)
104886 {
104887 int ret = -ENOMEM;
104888 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104889 if (!net->ct.stat)
104890 goto err_pcpu_lists;
104891
104892 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104893 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104894 +#else
104895 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104896 +#endif
104897 if (!net->ct.slabname)
104898 goto err_slabname;
104899
104900 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104901 index 4e78c57..ec8fb74 100644
104902 --- a/net/netfilter/nf_conntrack_ecache.c
104903 +++ b/net/netfilter/nf_conntrack_ecache.c
104904 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104905 #ifdef CONFIG_SYSCTL
104906 static int nf_conntrack_event_init_sysctl(struct net *net)
104907 {
104908 - struct ctl_table *table;
104909 + ctl_table_no_const *table;
104910
104911 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104912 GFP_KERNEL);
104913 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104914 index 5b3eae7..dd4b8fe 100644
104915 --- a/net/netfilter/nf_conntrack_helper.c
104916 +++ b/net/netfilter/nf_conntrack_helper.c
104917 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104918
104919 static int nf_conntrack_helper_init_sysctl(struct net *net)
104920 {
104921 - struct ctl_table *table;
104922 + ctl_table_no_const *table;
104923
104924 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104925 GFP_KERNEL);
104926 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104927 index b65d586..beec902 100644
104928 --- a/net/netfilter/nf_conntrack_proto.c
104929 +++ b/net/netfilter/nf_conntrack_proto.c
104930 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104931
104932 static void
104933 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104934 - struct ctl_table **table,
104935 + ctl_table_no_const **table,
104936 unsigned int users)
104937 {
104938 if (users > 0)
104939 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104940 index cf65a1e..2f291e9 100644
104941 --- a/net/netfilter/nf_conntrack_standalone.c
104942 +++ b/net/netfilter/nf_conntrack_standalone.c
104943 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104944
104945 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104946 {
104947 - struct ctl_table *table;
104948 + ctl_table_no_const *table;
104949
104950 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104951 GFP_KERNEL);
104952 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104953 index 7a394df..bd91a8a 100644
104954 --- a/net/netfilter/nf_conntrack_timestamp.c
104955 +++ b/net/netfilter/nf_conntrack_timestamp.c
104956 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104957 #ifdef CONFIG_SYSCTL
104958 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104959 {
104960 - struct ctl_table *table;
104961 + ctl_table_no_const *table;
104962
104963 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104964 GFP_KERNEL);
104965 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104966 index d719764..311bc60 100644
104967 --- a/net/netfilter/nf_log.c
104968 +++ b/net/netfilter/nf_log.c
104969 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104970
104971 #ifdef CONFIG_SYSCTL
104972 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104973 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104974 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104975
104976 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104977 void __user *buffer, size_t *lenp, loff_t *ppos)
104978 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104979 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104980 mutex_unlock(&nf_log_mutex);
104981 } else {
104982 + ctl_table_no_const nf_log_table = *table;
104983 +
104984 mutex_lock(&nf_log_mutex);
104985 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104986 lockdep_is_held(&nf_log_mutex));
104987 if (!logger)
104988 - table->data = "NONE";
104989 + nf_log_table.data = "NONE";
104990 else
104991 - table->data = logger->name;
104992 - r = proc_dostring(table, write, buffer, lenp, ppos);
104993 + nf_log_table.data = logger->name;
104994 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104995 mutex_unlock(&nf_log_mutex);
104996 }
104997
104998 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104999 index c68c1e5..8b5d670 100644
105000 --- a/net/netfilter/nf_sockopt.c
105001 +++ b/net/netfilter/nf_sockopt.c
105002 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105003 }
105004 }
105005
105006 - list_add(&reg->list, &nf_sockopts);
105007 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105008 out:
105009 mutex_unlock(&nf_sockopt_mutex);
105010 return ret;
105011 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105012 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105013 {
105014 mutex_lock(&nf_sockopt_mutex);
105015 - list_del(&reg->list);
105016 + pax_list_del((struct list_head *)&reg->list);
105017 mutex_unlock(&nf_sockopt_mutex);
105018 }
105019 EXPORT_SYMBOL(nf_unregister_sockopt);
105020 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105021 index 5f1be5b..2cba8cd 100644
105022 --- a/net/netfilter/nfnetlink_log.c
105023 +++ b/net/netfilter/nfnetlink_log.c
105024 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105025 struct nfnl_log_net {
105026 spinlock_t instances_lock;
105027 struct hlist_head instance_table[INSTANCE_BUCKETS];
105028 - atomic_t global_seq;
105029 + atomic_unchecked_t global_seq;
105030 };
105031
105032 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105033 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105034 /* global sequence number */
105035 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105036 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105037 - htonl(atomic_inc_return(&log->global_seq))))
105038 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105039 goto nla_put_failure;
105040
105041 if (data_len) {
105042 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105043 new file mode 100644
105044 index 0000000..c566332
105045 --- /dev/null
105046 +++ b/net/netfilter/xt_gradm.c
105047 @@ -0,0 +1,51 @@
105048 +/*
105049 + * gradm match for netfilter
105050 + * Copyright © Zbigniew Krzystolik, 2010
105051 + *
105052 + * This program is free software; you can redistribute it and/or modify
105053 + * it under the terms of the GNU General Public License; either version
105054 + * 2 or 3 as published by the Free Software Foundation.
105055 + */
105056 +#include <linux/module.h>
105057 +#include <linux/moduleparam.h>
105058 +#include <linux/skbuff.h>
105059 +#include <linux/netfilter/x_tables.h>
105060 +#include <linux/grsecurity.h>
105061 +#include <linux/netfilter/xt_gradm.h>
105062 +
105063 +static bool
105064 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105065 +{
105066 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105067 + bool retval = false;
105068 + if (gr_acl_is_enabled())
105069 + retval = true;
105070 + return retval ^ info->invflags;
105071 +}
105072 +
105073 +static struct xt_match gradm_mt_reg __read_mostly = {
105074 + .name = "gradm",
105075 + .revision = 0,
105076 + .family = NFPROTO_UNSPEC,
105077 + .match = gradm_mt,
105078 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105079 + .me = THIS_MODULE,
105080 +};
105081 +
105082 +static int __init gradm_mt_init(void)
105083 +{
105084 + return xt_register_match(&gradm_mt_reg);
105085 +}
105086 +
105087 +static void __exit gradm_mt_exit(void)
105088 +{
105089 + xt_unregister_match(&gradm_mt_reg);
105090 +}
105091 +
105092 +module_init(gradm_mt_init);
105093 +module_exit(gradm_mt_exit);
105094 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105095 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105096 +MODULE_LICENSE("GPL");
105097 +MODULE_ALIAS("ipt_gradm");
105098 +MODULE_ALIAS("ip6t_gradm");
105099 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105100 index 05fbc2a..4424b5c 100644
105101 --- a/net/netfilter/xt_hashlimit.c
105102 +++ b/net/netfilter/xt_hashlimit.c
105103 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105104 {
105105 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105106
105107 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105108 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105109 if (!hashlimit_net->ipt_hashlimit)
105110 return -ENOMEM;
105111 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105112 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105113 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105114 if (!hashlimit_net->ip6t_hashlimit) {
105115 remove_proc_entry("ipt_hashlimit", net->proc_net);
105116 return -ENOMEM;
105117 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105118 index a9faae8..1ea30e0 100644
105119 --- a/net/netfilter/xt_recent.c
105120 +++ b/net/netfilter/xt_recent.c
105121 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105122 {
105123 struct recent_net *recent_net = recent_pernet(net);
105124
105125 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105126 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105127 if (!recent_net->xt_recent)
105128 return -ENOMEM;
105129 return 0;
105130 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105131 index 11de55e..f25e448 100644
105132 --- a/net/netfilter/xt_statistic.c
105133 +++ b/net/netfilter/xt_statistic.c
105134 @@ -19,7 +19,7 @@
105135 #include <linux/module.h>
105136
105137 struct xt_statistic_priv {
105138 - atomic_t count;
105139 + atomic_unchecked_t count;
105140 } ____cacheline_aligned_in_smp;
105141
105142 MODULE_LICENSE("GPL");
105143 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105144 break;
105145 case XT_STATISTIC_MODE_NTH:
105146 do {
105147 - oval = atomic_read(&info->master->count);
105148 + oval = atomic_read_unchecked(&info->master->count);
105149 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105150 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105151 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105152 if (nval == 0)
105153 ret = !ret;
105154 break;
105155 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105156 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105157 if (info->master == NULL)
105158 return -ENOMEM;
105159 - atomic_set(&info->master->count, info->u.nth.count);
105160 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105161
105162 return 0;
105163 }
105164 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105165 index 79c965a..ee2b76d 100644
105166 --- a/net/netlink/af_netlink.c
105167 +++ b/net/netlink/af_netlink.c
105168 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105169 sk->sk_error_report(sk);
105170 }
105171 }
105172 - atomic_inc(&sk->sk_drops);
105173 + atomic_inc_unchecked(&sk->sk_drops);
105174 }
105175
105176 static void netlink_rcv_wake(struct sock *sk)
105177 @@ -2990,7 +2990,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105178 sk_wmem_alloc_get(s),
105179 nlk->cb_running,
105180 atomic_read(&s->sk_refcnt),
105181 - atomic_read(&s->sk_drops),
105182 + atomic_read_unchecked(&s->sk_drops),
105183 sock_i_ino(s)
105184 );
105185
105186 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105187 index 8451612..c8872bc 100644
105188 --- a/net/openvswitch/vport-internal_dev.c
105189 +++ b/net/openvswitch/vport-internal_dev.c
105190 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105191 .ndo_get_stats64 = internal_dev_get_stats,
105192 };
105193
105194 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105195 +static struct rtnl_link_ops internal_dev_link_ops = {
105196 .kind = "openvswitch",
105197 };
105198
105199 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
105200 index 6015802..e81e8bf 100644
105201 --- a/net/openvswitch/vport.c
105202 +++ b/net/openvswitch/vport.c
105203 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
105204 * netdev-stats can be directly read over netlink-ioctl.
105205 */
105206
105207 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
105208 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
105209 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
105210 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
105211 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
105212 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
105213 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
105214 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
105215
105216 for_each_possible_cpu(i) {
105217 const struct pcpu_sw_netstats *percpu_stats;
105218 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
105219 {
105220 switch (err_type) {
105221 case VPORT_E_RX_DROPPED:
105222 - atomic_long_inc(&vport->err_stats.rx_dropped);
105223 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
105224 break;
105225
105226 case VPORT_E_RX_ERROR:
105227 - atomic_long_inc(&vport->err_stats.rx_errors);
105228 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
105229 break;
105230
105231 case VPORT_E_TX_DROPPED:
105232 - atomic_long_inc(&vport->err_stats.tx_dropped);
105233 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
105234 break;
105235
105236 case VPORT_E_TX_ERROR:
105237 - atomic_long_inc(&vport->err_stats.tx_errors);
105238 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
105239 break;
105240 }
105241
105242 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
105243 index 8942125..03ed887 100644
105244 --- a/net/openvswitch/vport.h
105245 +++ b/net/openvswitch/vport.h
105246 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
105247 /* The following definitions are for implementers of vport devices: */
105248
105249 struct vport_err_stats {
105250 - atomic_long_t rx_dropped;
105251 - atomic_long_t rx_errors;
105252 - atomic_long_t tx_dropped;
105253 - atomic_long_t tx_errors;
105254 + atomic_long_unchecked_t rx_dropped;
105255 + atomic_long_unchecked_t rx_errors;
105256 + atomic_long_unchecked_t tx_dropped;
105257 + atomic_long_unchecked_t tx_errors;
105258 };
105259 /**
105260 * struct vport_portids - array of netlink portids of a vport.
105261 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105262 index 07c04a8..3ca11eb 100644
105263 --- a/net/packet/af_packet.c
105264 +++ b/net/packet/af_packet.c
105265 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105266
105267 return ret;
105268 drop:
105269 - atomic_long_inc(&dev->tx_dropped);
105270 + atomic_long_inc_unchecked(&dev->tx_dropped);
105271 kfree_skb(skb);
105272 return NET_XMIT_DROP;
105273 }
105274 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105275
105276 spin_lock(&sk->sk_receive_queue.lock);
105277 po->stats.stats1.tp_packets++;
105278 - skb->dropcount = atomic_read(&sk->sk_drops);
105279 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105280 __skb_queue_tail(&sk->sk_receive_queue, skb);
105281 spin_unlock(&sk->sk_receive_queue.lock);
105282 sk->sk_data_ready(sk);
105283 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105284 drop_n_acct:
105285 spin_lock(&sk->sk_receive_queue.lock);
105286 po->stats.stats1.tp_drops++;
105287 - atomic_inc(&sk->sk_drops);
105288 + atomic_inc_unchecked(&sk->sk_drops);
105289 spin_unlock(&sk->sk_receive_queue.lock);
105290
105291 drop_n_restore:
105292 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105293 case PACKET_HDRLEN:
105294 if (len > sizeof(int))
105295 len = sizeof(int);
105296 - if (copy_from_user(&val, optval, len))
105297 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105298 return -EFAULT;
105299 switch (val) {
105300 case TPACKET_V1:
105301 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105302 len = lv;
105303 if (put_user(len, optlen))
105304 return -EFAULT;
105305 - if (copy_to_user(optval, data, len))
105306 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105307 return -EFAULT;
105308 return 0;
105309 }
105310 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105311 index 70a547e..23477fe 100644
105312 --- a/net/phonet/pep.c
105313 +++ b/net/phonet/pep.c
105314 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105315
105316 case PNS_PEP_CTRL_REQ:
105317 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105318 - atomic_inc(&sk->sk_drops);
105319 + atomic_inc_unchecked(&sk->sk_drops);
105320 break;
105321 }
105322 __skb_pull(skb, 4);
105323 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105324 }
105325
105326 if (pn->rx_credits == 0) {
105327 - atomic_inc(&sk->sk_drops);
105328 + atomic_inc_unchecked(&sk->sk_drops);
105329 err = -ENOBUFS;
105330 break;
105331 }
105332 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105333 }
105334
105335 if (pn->rx_credits == 0) {
105336 - atomic_inc(&sk->sk_drops);
105337 + atomic_inc_unchecked(&sk->sk_drops);
105338 err = NET_RX_DROP;
105339 break;
105340 }
105341 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105342 index 008214a..bb68240 100644
105343 --- a/net/phonet/socket.c
105344 +++ b/net/phonet/socket.c
105345 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105346 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105347 sock_i_ino(sk),
105348 atomic_read(&sk->sk_refcnt), sk,
105349 - atomic_read(&sk->sk_drops));
105350 + atomic_read_unchecked(&sk->sk_drops));
105351 }
105352 seq_pad(seq, '\n');
105353 return 0;
105354 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105355 index c02a8c4..3c5b600 100644
105356 --- a/net/phonet/sysctl.c
105357 +++ b/net/phonet/sysctl.c
105358 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105359 {
105360 int ret;
105361 int range[2] = {local_port_range[0], local_port_range[1]};
105362 - struct ctl_table tmp = {
105363 + ctl_table_no_const tmp = {
105364 .data = &range,
105365 .maxlen = sizeof(range),
105366 .mode = table->mode,
105367 diff --git a/net/rds/cong.c b/net/rds/cong.c
105368 index e5b65ac..f3b6fb7 100644
105369 --- a/net/rds/cong.c
105370 +++ b/net/rds/cong.c
105371 @@ -78,7 +78,7 @@
105372 * finds that the saved generation number is smaller than the global generation
105373 * number, it wakes up the process.
105374 */
105375 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105376 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105377
105378 /*
105379 * Congestion monitoring
105380 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105381 rdsdebug("waking map %p for %pI4\n",
105382 map, &map->m_addr);
105383 rds_stats_inc(s_cong_update_received);
105384 - atomic_inc(&rds_cong_generation);
105385 + atomic_inc_unchecked(&rds_cong_generation);
105386 if (waitqueue_active(&map->m_waitq))
105387 wake_up(&map->m_waitq);
105388 if (waitqueue_active(&rds_poll_waitq))
105389 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105390
105391 int rds_cong_updated_since(unsigned long *recent)
105392 {
105393 - unsigned long gen = atomic_read(&rds_cong_generation);
105394 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105395
105396 if (likely(*recent == gen))
105397 return 0;
105398 diff --git a/net/rds/ib.h b/net/rds/ib.h
105399 index 7280ab8..e04f4ea 100644
105400 --- a/net/rds/ib.h
105401 +++ b/net/rds/ib.h
105402 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105403 /* sending acks */
105404 unsigned long i_ack_flags;
105405 #ifdef KERNEL_HAS_ATOMIC64
105406 - atomic64_t i_ack_next; /* next ACK to send */
105407 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105408 #else
105409 spinlock_t i_ack_lock; /* protect i_ack_next */
105410 u64 i_ack_next; /* next ACK to send */
105411 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105412 index 31b74f5..dc1fbfa 100644
105413 --- a/net/rds/ib_cm.c
105414 +++ b/net/rds/ib_cm.c
105415 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105416 /* Clear the ACK state */
105417 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105418 #ifdef KERNEL_HAS_ATOMIC64
105419 - atomic64_set(&ic->i_ack_next, 0);
105420 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105421 #else
105422 ic->i_ack_next = 0;
105423 #endif
105424 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105425 index d67de45..73dbf51 100644
105426 --- a/net/rds/ib_recv.c
105427 +++ b/net/rds/ib_recv.c
105428 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105429 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105430 int ack_required)
105431 {
105432 - atomic64_set(&ic->i_ack_next, seq);
105433 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105434 if (ack_required) {
105435 smp_mb__before_atomic();
105436 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105437 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105438 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105439 smp_mb__after_atomic();
105440
105441 - return atomic64_read(&ic->i_ack_next);
105442 + return atomic64_read_unchecked(&ic->i_ack_next);
105443 }
105444 #endif
105445
105446 diff --git a/net/rds/iw.h b/net/rds/iw.h
105447 index 04ce3b1..48119a6 100644
105448 --- a/net/rds/iw.h
105449 +++ b/net/rds/iw.h
105450 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105451 /* sending acks */
105452 unsigned long i_ack_flags;
105453 #ifdef KERNEL_HAS_ATOMIC64
105454 - atomic64_t i_ack_next; /* next ACK to send */
105455 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105456 #else
105457 spinlock_t i_ack_lock; /* protect i_ack_next */
105458 u64 i_ack_next; /* next ACK to send */
105459 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105460 index a91e1db..cf3053f 100644
105461 --- a/net/rds/iw_cm.c
105462 +++ b/net/rds/iw_cm.c
105463 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105464 /* Clear the ACK state */
105465 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105466 #ifdef KERNEL_HAS_ATOMIC64
105467 - atomic64_set(&ic->i_ack_next, 0);
105468 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105469 #else
105470 ic->i_ack_next = 0;
105471 #endif
105472 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105473 index aa8bf67..b70133c 100644
105474 --- a/net/rds/iw_recv.c
105475 +++ b/net/rds/iw_recv.c
105476 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105477 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105478 int ack_required)
105479 {
105480 - atomic64_set(&ic->i_ack_next, seq);
105481 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105482 if (ack_required) {
105483 smp_mb__before_atomic();
105484 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105485 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105486 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105487 smp_mb__after_atomic();
105488
105489 - return atomic64_read(&ic->i_ack_next);
105490 + return atomic64_read_unchecked(&ic->i_ack_next);
105491 }
105492 #endif
105493
105494 diff --git a/net/rds/rds.h b/net/rds/rds.h
105495 index 48f8ffc..0ef3eec 100644
105496 --- a/net/rds/rds.h
105497 +++ b/net/rds/rds.h
105498 @@ -449,7 +449,7 @@ struct rds_transport {
105499 void (*sync_mr)(void *trans_private, int direction);
105500 void (*free_mr)(void *trans_private, int invalidate);
105501 void (*flush_mrs)(void);
105502 -};
105503 +} __do_const;
105504
105505 struct rds_sock {
105506 struct sock rs_sk;
105507 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105508 index edac9ef..16bcb98 100644
105509 --- a/net/rds/tcp.c
105510 +++ b/net/rds/tcp.c
105511 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105512 int val = 1;
105513
105514 set_fs(KERNEL_DS);
105515 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105516 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105517 sizeof(val));
105518 set_fs(oldfs);
105519 }
105520 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105521 index 53b17ca..45463e7 100644
105522 --- a/net/rds/tcp_send.c
105523 +++ b/net/rds/tcp_send.c
105524 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105525
105526 oldfs = get_fs();
105527 set_fs(KERNEL_DS);
105528 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105529 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105530 sizeof(val));
105531 set_fs(oldfs);
105532 }
105533 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105534 index 7b16704..9628ec6 100644
105535 --- a/net/rxrpc/af_rxrpc.c
105536 +++ b/net/rxrpc/af_rxrpc.c
105537 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105538 __be32 rxrpc_epoch;
105539
105540 /* current debugging ID */
105541 -atomic_t rxrpc_debug_id;
105542 +atomic_unchecked_t rxrpc_debug_id;
105543
105544 /* count of skbs currently in use */
105545 atomic_t rxrpc_n_skbs;
105546 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105547 index c6be17a..2a6200a 100644
105548 --- a/net/rxrpc/ar-ack.c
105549 +++ b/net/rxrpc/ar-ack.c
105550 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105551
105552 _enter("{%d,%d,%d,%d},",
105553 call->acks_hard, call->acks_unacked,
105554 - atomic_read(&call->sequence),
105555 + atomic_read_unchecked(&call->sequence),
105556 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105557
105558 stop = 0;
105559 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105560
105561 /* each Tx packet has a new serial number */
105562 sp->hdr.serial =
105563 - htonl(atomic_inc_return(&call->conn->serial));
105564 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105565
105566 hdr = (struct rxrpc_header *) txb->head;
105567 hdr->serial = sp->hdr.serial;
105568 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
105569 */
105570 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
105571 {
105572 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
105573 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
105574 }
105575
105576 /*
105577 @@ -677,7 +677,7 @@ process_further:
105578
105579 latest = ntohl(sp->hdr.serial);
105580 hard = ntohl(ack.firstPacket);
105581 - tx = atomic_read(&call->sequence);
105582 + tx = atomic_read_unchecked(&call->sequence);
105583
105584 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105585 latest,
105586 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105587 goto maybe_reschedule;
105588
105589 send_ACK_with_skew:
105590 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105591 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105592 ntohl(ack.serial));
105593 send_ACK:
105594 mtu = call->conn->trans->peer->if_mtu;
105595 @@ -1221,7 +1221,7 @@ send_ACK:
105596 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105597 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105598
105599 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105600 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105601 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105602 ntohl(hdr.serial),
105603 ntohs(ack.maxSkew),
105604 @@ -1239,7 +1239,7 @@ send_ACK:
105605 send_message:
105606 _debug("send message");
105607
105608 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105609 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105610 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105611 send_message_2:
105612
105613 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105614 index a9e05db..194e793 100644
105615 --- a/net/rxrpc/ar-call.c
105616 +++ b/net/rxrpc/ar-call.c
105617 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105618 spin_lock_init(&call->lock);
105619 rwlock_init(&call->state_lock);
105620 atomic_set(&call->usage, 1);
105621 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105622 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105623 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105624
105625 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105626 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105627 index 6631f4f..bfdf056 100644
105628 --- a/net/rxrpc/ar-connection.c
105629 +++ b/net/rxrpc/ar-connection.c
105630 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105631 rwlock_init(&conn->lock);
105632 spin_lock_init(&conn->state_lock);
105633 atomic_set(&conn->usage, 1);
105634 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105635 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105636 conn->avail_calls = RXRPC_MAXCALLS;
105637 conn->size_align = 4;
105638 conn->header_size = sizeof(struct rxrpc_header);
105639 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105640 index e7ed43a..6afa140 100644
105641 --- a/net/rxrpc/ar-connevent.c
105642 +++ b/net/rxrpc/ar-connevent.c
105643 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105644
105645 len = iov[0].iov_len + iov[1].iov_len;
105646
105647 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105648 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105649 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
105650
105651 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105652 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
105653 index 481f89f..ceeaf8d 100644
105654 --- a/net/rxrpc/ar-input.c
105655 +++ b/net/rxrpc/ar-input.c
105656 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
105657 /* track the latest serial number on this connection for ACK packet
105658 * information */
105659 serial = ntohl(sp->hdr.serial);
105660 - hi_serial = atomic_read(&call->conn->hi_serial);
105661 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
105662 while (serial > hi_serial)
105663 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
105664 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
105665 serial);
105666
105667 /* request ACK generation for any ACK or DATA packet that requests
105668 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
105669 index ba9fd36..9bbfe01 100644
105670 --- a/net/rxrpc/ar-internal.h
105671 +++ b/net/rxrpc/ar-internal.h
105672 @@ -272,8 +272,8 @@ struct rxrpc_connection {
105673 int error; /* error code for local abort */
105674 int debug_id; /* debug ID for printks */
105675 unsigned int call_counter; /* call ID counter */
105676 - atomic_t serial; /* packet serial number counter */
105677 - atomic_t hi_serial; /* highest serial number received */
105678 + atomic_unchecked_t serial; /* packet serial number counter */
105679 + atomic_unchecked_t hi_serial; /* highest serial number received */
105680 u8 avail_calls; /* number of calls available */
105681 u8 size_align; /* data size alignment (for security) */
105682 u8 header_size; /* rxrpc + security header size */
105683 @@ -346,7 +346,7 @@ struct rxrpc_call {
105684 spinlock_t lock;
105685 rwlock_t state_lock; /* lock for state transition */
105686 atomic_t usage;
105687 - atomic_t sequence; /* Tx data packet sequence counter */
105688 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
105689 u32 abort_code; /* local/remote abort code */
105690 enum { /* current state of call */
105691 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
105692 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
105693 */
105694 extern atomic_t rxrpc_n_skbs;
105695 extern __be32 rxrpc_epoch;
105696 -extern atomic_t rxrpc_debug_id;
105697 +extern atomic_unchecked_t rxrpc_debug_id;
105698 extern struct workqueue_struct *rxrpc_workqueue;
105699
105700 /*
105701 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
105702 index 87f7135..74d3703 100644
105703 --- a/net/rxrpc/ar-local.c
105704 +++ b/net/rxrpc/ar-local.c
105705 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
105706 spin_lock_init(&local->lock);
105707 rwlock_init(&local->services_lock);
105708 atomic_set(&local->usage, 1);
105709 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
105710 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105711 memcpy(&local->srx, srx, sizeof(*srx));
105712 }
105713
105714 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
105715 index 0b4b9a7..966ffbb 100644
105716 --- a/net/rxrpc/ar-output.c
105717 +++ b/net/rxrpc/ar-output.c
105718 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
105719 memset(skb_put(skb, pad), 0, pad);
105720 }
105721
105722 - seq = atomic_inc_return(&call->sequence);
105723 + seq = atomic_inc_return_unchecked(&call->sequence);
105724
105725 sp->hdr.epoch = conn->epoch;
105726 sp->hdr.cid = call->cid;
105727 sp->hdr.callNumber = call->call_id;
105728 sp->hdr.seq = htonl(seq);
105729 sp->hdr.serial =
105730 - htonl(atomic_inc_return(&conn->serial));
105731 + htonl(atomic_inc_return_unchecked(&conn->serial));
105732 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
105733 sp->hdr.userStatus = 0;
105734 sp->hdr.securityIndex = conn->security_ix;
105735 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
105736 index bebaa43..2644591 100644
105737 --- a/net/rxrpc/ar-peer.c
105738 +++ b/net/rxrpc/ar-peer.c
105739 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
105740 INIT_LIST_HEAD(&peer->error_targets);
105741 spin_lock_init(&peer->lock);
105742 atomic_set(&peer->usage, 1);
105743 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
105744 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105745 memcpy(&peer->srx, srx, sizeof(*srx));
105746
105747 rxrpc_assess_MTU_size(peer);
105748 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
105749 index 38047f7..9f48511 100644
105750 --- a/net/rxrpc/ar-proc.c
105751 +++ b/net/rxrpc/ar-proc.c
105752 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
105753 atomic_read(&conn->usage),
105754 rxrpc_conn_states[conn->state],
105755 key_serial(conn->key),
105756 - atomic_read(&conn->serial),
105757 - atomic_read(&conn->hi_serial));
105758 + atomic_read_unchecked(&conn->serial),
105759 + atomic_read_unchecked(&conn->hi_serial));
105760
105761 return 0;
105762 }
105763 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
105764 index 1976dec..aa70be5 100644
105765 --- a/net/rxrpc/ar-transport.c
105766 +++ b/net/rxrpc/ar-transport.c
105767 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
105768 spin_lock_init(&trans->client_lock);
105769 rwlock_init(&trans->conn_lock);
105770 atomic_set(&trans->usage, 1);
105771 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
105772 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105773
105774 if (peer->srx.transport.family == AF_INET) {
105775 switch (peer->srx.transport_type) {
105776 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
105777 index f226709..0e735a8 100644
105778 --- a/net/rxrpc/rxkad.c
105779 +++ b/net/rxrpc/rxkad.c
105780 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
105781
105782 len = iov[0].iov_len + iov[1].iov_len;
105783
105784 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105785 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105786 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
105787
105788 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105789 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
105790
105791 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
105792
105793 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
105794 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105795 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
105796
105797 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
105798 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
105799 index eed49d1..ce22514 100644
105800 --- a/net/sched/cls_bpf.c
105801 +++ b/net/sched/cls_bpf.c
105802 @@ -191,6 +191,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
105803 }
105804
105805 bpf_size = bpf_len * sizeof(*bpf_ops);
105806 + if (bpf_size != nla_len(tb[TCA_BPF_OPS])) {
105807 + ret = -EINVAL;
105808 + goto errout;
105809 + }
105810 +
105811 bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
105812 if (bpf_ops == NULL) {
105813 ret = -ENOMEM;
105814 @@ -226,15 +231,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
105815 struct cls_bpf_head *head)
105816 {
105817 unsigned int i = 0x80000000;
105818 + u32 handle;
105819
105820 do {
105821 if (++head->hgen == 0x7FFFFFFF)
105822 head->hgen = 1;
105823 } while (--i > 0 && cls_bpf_get(tp, head->hgen));
105824 - if (i == 0)
105825 +
105826 + if (unlikely(i == 0)) {
105827 pr_err("Insufficient number of handles\n");
105828 + handle = 0;
105829 + } else {
105830 + handle = head->hgen;
105831 + }
105832
105833 - return i;
105834 + return handle;
105835 }
105836
105837 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
105838 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
105839 index 6efca30..1259f82 100644
105840 --- a/net/sched/sch_generic.c
105841 +++ b/net/sched/sch_generic.c
105842 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
105843 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105844 if (dev->reg_state == NETREG_UNINITIALIZED)
105845 return;
105846 - atomic_inc(&dev->carrier_changes);
105847 + atomic_inc_unchecked(&dev->carrier_changes);
105848 linkwatch_fire_event(dev);
105849 if (netif_running(dev))
105850 __netdev_watchdog_up(dev);
105851 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
105852 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105853 if (dev->reg_state == NETREG_UNINITIALIZED)
105854 return;
105855 - atomic_inc(&dev->carrier_changes);
105856 + atomic_inc_unchecked(&dev->carrier_changes);
105857 linkwatch_fire_event(dev);
105858 }
105859 }
105860 diff --git a/net/sctp/associola.c b/net/sctp/associola.c
105861 index f791edd..26d06db 100644
105862 --- a/net/sctp/associola.c
105863 +++ b/net/sctp/associola.c
105864 @@ -1182,7 +1182,6 @@ void sctp_assoc_update(struct sctp_association *asoc,
105865 asoc->peer.peer_hmacs = new->peer.peer_hmacs;
105866 new->peer.peer_hmacs = NULL;
105867
105868 - sctp_auth_key_put(asoc->asoc_shared_key);
105869 sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
105870 }
105871
105872 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
105873 index 0e4198e..f94193e 100644
105874 --- a/net/sctp/ipv6.c
105875 +++ b/net/sctp/ipv6.c
105876 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
105877 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
105878 };
105879
105880 -static struct sctp_af sctp_af_inet6 = {
105881 +static struct sctp_af sctp_af_inet6 __read_only = {
105882 .sa_family = AF_INET6,
105883 .sctp_xmit = sctp_v6_xmit,
105884 .setsockopt = ipv6_setsockopt,
105885 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
105886 #endif
105887 };
105888
105889 -static struct sctp_pf sctp_pf_inet6 = {
105890 +static struct sctp_pf sctp_pf_inet6 __read_only = {
105891 .event_msgname = sctp_inet6_event_msgname,
105892 .skb_msgname = sctp_inet6_skb_msgname,
105893 .af_supported = sctp_inet6_af_supported,
105894 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
105895
105896 void sctp_v6_pf_exit(void)
105897 {
105898 - list_del(&sctp_af_inet6.list);
105899 + pax_list_del(&sctp_af_inet6.list);
105900 }
105901
105902 /* Initialize IPv6 support and register with socket layer. */
105903 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
105904 index 8f34b27..b105385 100644
105905 --- a/net/sctp/protocol.c
105906 +++ b/net/sctp/protocol.c
105907 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
105908 return 0;
105909 }
105910
105911 + pax_open_kernel();
105912 INIT_LIST_HEAD(&af->list);
105913 - list_add_tail(&af->list, &sctp_address_families);
105914 + pax_close_kernel();
105915 + pax_list_add_tail(&af->list, &sctp_address_families);
105916 return 1;
105917 }
105918
105919 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
105920
105921 static struct sctp_af sctp_af_inet;
105922
105923 -static struct sctp_pf sctp_pf_inet = {
105924 +static struct sctp_pf sctp_pf_inet __read_only = {
105925 .event_msgname = sctp_inet_event_msgname,
105926 .skb_msgname = sctp_inet_skb_msgname,
105927 .af_supported = sctp_inet_af_supported,
105928 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
105929 };
105930
105931 /* IPv4 address related functions. */
105932 -static struct sctp_af sctp_af_inet = {
105933 +static struct sctp_af sctp_af_inet __read_only = {
105934 .sa_family = AF_INET,
105935 .sctp_xmit = sctp_v4_xmit,
105936 .setsockopt = ip_setsockopt,
105937 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
105938
105939 static void sctp_v4_pf_exit(void)
105940 {
105941 - list_del(&sctp_af_inet.list);
105942 + pax_list_del(&sctp_af_inet.list);
105943 }
105944
105945 static int sctp_v4_protosw_init(void)
105946 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
105947 index fef2acd..c705c4f 100644
105948 --- a/net/sctp/sm_sideeffect.c
105949 +++ b/net/sctp/sm_sideeffect.c
105950 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
105951 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
105952 }
105953
105954 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105955 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105956 NULL,
105957 sctp_generate_t1_cookie_event,
105958 sctp_generate_t1_init_event,
105959 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
105960 index 634a2ab..8e93929 100644
105961 --- a/net/sctp/socket.c
105962 +++ b/net/sctp/socket.c
105963 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
105964 {
105965 struct sctp_association *asoc;
105966 struct sctp_ulpevent *event;
105967 + struct sctp_event_subscribe subscribe;
105968
105969 if (optlen > sizeof(struct sctp_event_subscribe))
105970 return -EINVAL;
105971 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
105972 + if (copy_from_user(&subscribe, optval, optlen))
105973 return -EFAULT;
105974 + sctp_sk(sk)->subscribe = subscribe;
105975
105976 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
105977 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
105978 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
105979 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105980 int __user *optlen)
105981 {
105982 + struct sctp_event_subscribe subscribe;
105983 +
105984 if (len <= 0)
105985 return -EINVAL;
105986 if (len > sizeof(struct sctp_event_subscribe))
105987 len = sizeof(struct sctp_event_subscribe);
105988 if (put_user(len, optlen))
105989 return -EFAULT;
105990 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
105991 + subscribe = sctp_sk(sk)->subscribe;
105992 + if (copy_to_user(optval, &subscribe, len))
105993 return -EFAULT;
105994 return 0;
105995 }
105996 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105997 */
105998 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
105999 {
106000 + __u32 autoclose;
106001 +
106002 /* Applicable to UDP-style socket only */
106003 if (sctp_style(sk, TCP))
106004 return -EOPNOTSUPP;
106005 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106006 len = sizeof(int);
106007 if (put_user(len, optlen))
106008 return -EFAULT;
106009 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106010 + autoclose = sctp_sk(sk)->autoclose;
106011 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106012 return -EFAULT;
106013 return 0;
106014 }
106015 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106016 */
106017 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106018 {
106019 + struct sctp_initmsg initmsg;
106020 +
106021 if (len < sizeof(struct sctp_initmsg))
106022 return -EINVAL;
106023 len = sizeof(struct sctp_initmsg);
106024 if (put_user(len, optlen))
106025 return -EFAULT;
106026 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106027 + initmsg = sctp_sk(sk)->initmsg;
106028 + if (copy_to_user(optval, &initmsg, len))
106029 return -EFAULT;
106030 return 0;
106031 }
106032 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106033 ->addr_to_user(sp, &temp);
106034 if (space_left < addrlen)
106035 return -ENOMEM;
106036 + if (addrlen > sizeof(temp) || addrlen < 0)
106037 + return -EFAULT;
106038 if (copy_to_user(to, &temp, addrlen))
106039 return -EFAULT;
106040 to += addrlen;
106041 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106042 index 2e9ada1..40f425d 100644
106043 --- a/net/sctp/sysctl.c
106044 +++ b/net/sctp/sysctl.c
106045 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106046 loff_t *ppos)
106047 {
106048 struct net *net = current->nsproxy->net_ns;
106049 - struct ctl_table tbl;
106050 + ctl_table_no_const tbl;
106051 bool changed = false;
106052 char *none = "none";
106053 char tmp[8];
106054 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106055 struct net *net = current->nsproxy->net_ns;
106056 unsigned int min = *(unsigned int *) ctl->extra1;
106057 unsigned int max = *(unsigned int *) ctl->extra2;
106058 - struct ctl_table tbl;
106059 + ctl_table_no_const tbl;
106060 int ret, new_value;
106061
106062 memset(&tbl, 0, sizeof(struct ctl_table));
106063 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106064 struct net *net = current->nsproxy->net_ns;
106065 unsigned int min = *(unsigned int *) ctl->extra1;
106066 unsigned int max = *(unsigned int *) ctl->extra2;
106067 - struct ctl_table tbl;
106068 + ctl_table_no_const tbl;
106069 int ret, new_value;
106070
106071 memset(&tbl, 0, sizeof(struct ctl_table));
106072 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106073 loff_t *ppos)
106074 {
106075 struct net *net = current->nsproxy->net_ns;
106076 - struct ctl_table tbl;
106077 + ctl_table_no_const tbl;
106078 int new_value, ret;
106079
106080 memset(&tbl, 0, sizeof(struct ctl_table));
106081 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106082
106083 int sctp_sysctl_net_register(struct net *net)
106084 {
106085 - struct ctl_table *table;
106086 + ctl_table_no_const *table;
106087 int i;
106088
106089 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106090 diff --git a/net/socket.c b/net/socket.c
106091 index fe20c31..83a0ed6 100644
106092 --- a/net/socket.c
106093 +++ b/net/socket.c
106094 @@ -89,6 +89,7 @@
106095 #include <linux/magic.h>
106096 #include <linux/slab.h>
106097 #include <linux/xattr.h>
106098 +#include <linux/in.h>
106099
106100 #include <asm/uaccess.h>
106101 #include <asm/unistd.h>
106102 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106103 unsigned int sysctl_net_busy_poll __read_mostly;
106104 #endif
106105
106106 +#include <linux/grsock.h>
106107 +
106108 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106109 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106110 unsigned long nr_segs, loff_t pos);
106111 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106112 */
106113
106114 static DEFINE_SPINLOCK(net_family_lock);
106115 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106116 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106117
106118 /*
106119 * Statistics counters of the socket lists
106120 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106121 &sockfs_dentry_operations, SOCKFS_MAGIC);
106122 }
106123
106124 -static struct vfsmount *sock_mnt __read_mostly;
106125 +struct vfsmount *sock_mnt __read_mostly;
106126
106127 static struct file_system_type sock_fs_type = {
106128 .name = "sockfs",
106129 @@ -1263,6 +1266,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106130 return -EAFNOSUPPORT;
106131 if (type < 0 || type >= SOCK_MAX)
106132 return -EINVAL;
106133 + if (protocol < 0)
106134 + return -EINVAL;
106135
106136 /* Compatibility.
106137
106138 @@ -1283,6 +1288,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106139 if (err)
106140 return err;
106141
106142 + if(!kern && !gr_search_socket(family, type, protocol)) {
106143 + if (rcu_access_pointer(net_families[family]) == NULL)
106144 + return -EAFNOSUPPORT;
106145 + else
106146 + return -EACCES;
106147 + }
106148 +
106149 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106150 + if (rcu_access_pointer(net_families[family]) == NULL)
106151 + return -EAFNOSUPPORT;
106152 + else
106153 + return -EACCES;
106154 + }
106155 +
106156 /*
106157 * Allocate the socket and allow the family to set things up. if
106158 * the protocol is 0, the family is instructed to select an appropriate
106159 @@ -1534,6 +1553,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106160 if (sock) {
106161 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106162 if (err >= 0) {
106163 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106164 + err = -EACCES;
106165 + goto error;
106166 + }
106167 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106168 + if (err)
106169 + goto error;
106170 +
106171 err = security_socket_bind(sock,
106172 (struct sockaddr *)&address,
106173 addrlen);
106174 @@ -1542,6 +1569,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106175 (struct sockaddr *)
106176 &address, addrlen);
106177 }
106178 +error:
106179 fput_light(sock->file, fput_needed);
106180 }
106181 return err;
106182 @@ -1565,10 +1593,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106183 if ((unsigned int)backlog > somaxconn)
106184 backlog = somaxconn;
106185
106186 + if (gr_handle_sock_server_other(sock->sk)) {
106187 + err = -EPERM;
106188 + goto error;
106189 + }
106190 +
106191 + err = gr_search_listen(sock);
106192 + if (err)
106193 + goto error;
106194 +
106195 err = security_socket_listen(sock, backlog);
106196 if (!err)
106197 err = sock->ops->listen(sock, backlog);
106198
106199 +error:
106200 fput_light(sock->file, fput_needed);
106201 }
106202 return err;
106203 @@ -1612,6 +1650,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106204 newsock->type = sock->type;
106205 newsock->ops = sock->ops;
106206
106207 + if (gr_handle_sock_server_other(sock->sk)) {
106208 + err = -EPERM;
106209 + sock_release(newsock);
106210 + goto out_put;
106211 + }
106212 +
106213 + err = gr_search_accept(sock);
106214 + if (err) {
106215 + sock_release(newsock);
106216 + goto out_put;
106217 + }
106218 +
106219 /*
106220 * We don't need try_module_get here, as the listening socket (sock)
106221 * has the protocol module (sock->ops->owner) held.
106222 @@ -1657,6 +1707,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106223 fd_install(newfd, newfile);
106224 err = newfd;
106225
106226 + gr_attach_curr_ip(newsock->sk);
106227 +
106228 out_put:
106229 fput_light(sock->file, fput_needed);
106230 out:
106231 @@ -1689,6 +1741,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106232 int, addrlen)
106233 {
106234 struct socket *sock;
106235 + struct sockaddr *sck;
106236 struct sockaddr_storage address;
106237 int err, fput_needed;
106238
106239 @@ -1699,6 +1752,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106240 if (err < 0)
106241 goto out_put;
106242
106243 + sck = (struct sockaddr *)&address;
106244 +
106245 + if (gr_handle_sock_client(sck)) {
106246 + err = -EACCES;
106247 + goto out_put;
106248 + }
106249 +
106250 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106251 + if (err)
106252 + goto out_put;
106253 +
106254 err =
106255 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106256 if (err)
106257 @@ -1780,6 +1844,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106258 * the protocol.
106259 */
106260
106261 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106262 +
106263 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106264 unsigned int, flags, struct sockaddr __user *, addr,
106265 int, addr_len)
106266 @@ -1846,7 +1912,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106267 struct socket *sock;
106268 struct iovec iov;
106269 struct msghdr msg;
106270 - struct sockaddr_storage address;
106271 + struct sockaddr_storage address = { };
106272 int err, err2;
106273 int fput_needed;
106274
106275 @@ -2075,7 +2141,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106276 * checking falls down on this.
106277 */
106278 if (copy_from_user(ctl_buf,
106279 - (void __user __force *)msg_sys->msg_control,
106280 + (void __force_user *)msg_sys->msg_control,
106281 ctl_len))
106282 goto out_freectl;
106283 msg_sys->msg_control = ctl_buf;
106284 @@ -2226,7 +2292,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106285 int err, total_len, len;
106286
106287 /* kernel mode address */
106288 - struct sockaddr_storage addr;
106289 + struct sockaddr_storage addr = { };
106290
106291 /* user mode address pointers */
106292 struct sockaddr __user *uaddr;
106293 @@ -2255,7 +2321,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106294 /* Save the user-mode address (verify_iovec will change the
106295 * kernel msghdr to use the kernel address space)
106296 */
106297 - uaddr = (__force void __user *)msg_sys->msg_name;
106298 + uaddr = (void __force_user *)msg_sys->msg_name;
106299 uaddr_len = COMPAT_NAMELEN(msg);
106300 if (MSG_CMSG_COMPAT & flags)
106301 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106302 @@ -2896,7 +2962,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106303 ifr = compat_alloc_user_space(buf_size);
106304 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106305
106306 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106307 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106308 return -EFAULT;
106309
106310 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106311 @@ -3007,7 +3073,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106312 old_fs = get_fs();
106313 set_fs(KERNEL_DS);
106314 err = dev_ioctl(net, cmd,
106315 - (struct ifreq __user __force *) &kifr);
106316 + (struct ifreq __force_user *) &kifr);
106317 set_fs(old_fs);
106318
106319 return err;
106320 @@ -3100,7 +3166,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106321
106322 old_fs = get_fs();
106323 set_fs(KERNEL_DS);
106324 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106325 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106326 set_fs(old_fs);
106327
106328 if (cmd == SIOCGIFMAP && !err) {
106329 @@ -3184,7 +3250,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106330 ret |= get_user(rtdev, &(ur4->rt_dev));
106331 if (rtdev) {
106332 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106333 - r4.rt_dev = (char __user __force *)devname;
106334 + r4.rt_dev = (char __force_user *)devname;
106335 devname[15] = 0;
106336 } else
106337 r4.rt_dev = NULL;
106338 @@ -3411,8 +3477,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106339 int __user *uoptlen;
106340 int err;
106341
106342 - uoptval = (char __user __force *) optval;
106343 - uoptlen = (int __user __force *) optlen;
106344 + uoptval = (char __force_user *) optval;
106345 + uoptlen = (int __force_user *) optlen;
106346
106347 set_fs(KERNEL_DS);
106348 if (level == SOL_SOCKET)
106349 @@ -3432,7 +3498,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106350 char __user *uoptval;
106351 int err;
106352
106353 - uoptval = (char __user __force *) optval;
106354 + uoptval = (char __force_user *) optval;
106355
106356 set_fs(KERNEL_DS);
106357 if (level == SOL_SOCKET)
106358 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106359 index c548ab2..4e1b68b 100644
106360 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106361 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106362 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106363 uint64_t *handle)
106364 {
106365 struct rsc rsci, *rscp = NULL;
106366 - static atomic64_t ctxhctr;
106367 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106368 long long ctxh;
106369 struct gss_api_mech *gm = NULL;
106370 time_t expiry;
106371 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106372 status = -ENOMEM;
106373 /* the handle needs to be just a unique id,
106374 * use a static counter */
106375 - ctxh = atomic64_inc_return(&ctxhctr);
106376 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106377
106378 /* make a copy for the caller */
106379 *handle = ctxh;
106380 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106381 index 0663621..c4928d4 100644
106382 --- a/net/sunrpc/cache.c
106383 +++ b/net/sunrpc/cache.c
106384 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106385 struct sunrpc_net *sn;
106386
106387 sn = net_generic(net, sunrpc_net_id);
106388 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106389 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106390 if (cd->u.procfs.proc_ent == NULL)
106391 goto out_nomem;
106392 cd->u.procfs.channel_ent = NULL;
106393 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106394 index 9acd6ce..4353a72 100644
106395 --- a/net/sunrpc/clnt.c
106396 +++ b/net/sunrpc/clnt.c
106397 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106398 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106399
106400 /* Increment call count */
106401 - task->tk_msg.rpc_proc->p_count++;
106402 + pax_open_kernel();
106403 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106404 + pax_close_kernel();
106405 clnt->cl_stats->rpccnt++;
106406 task->tk_action = call_reserve;
106407 }
106408 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106409 index fe3441a..922c29e 100644
106410 --- a/net/sunrpc/sched.c
106411 +++ b/net/sunrpc/sched.c
106412 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106413 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106414 static void rpc_task_set_debuginfo(struct rpc_task *task)
106415 {
106416 - static atomic_t rpc_pid;
106417 + static atomic_unchecked_t rpc_pid;
106418
106419 - task->tk_pid = atomic_inc_return(&rpc_pid);
106420 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106421 }
106422 #else
106423 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106424 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106425 index 5453049..465669a 100644
106426 --- a/net/sunrpc/stats.c
106427 +++ b/net/sunrpc/stats.c
106428 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106429
106430 dprintk("RPC: registering /proc/net/rpc\n");
106431 sn = net_generic(net, sunrpc_net_id);
106432 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106433 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106434 if (sn->proc_net_rpc == NULL)
106435 return -ENOMEM;
106436
106437 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106438 index ca8a795..ddfc41b 100644
106439 --- a/net/sunrpc/svc.c
106440 +++ b/net/sunrpc/svc.c
106441 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106442 svc_putnl(resv, RPC_SUCCESS);
106443
106444 /* Bump per-procedure stats counter */
106445 - procp->pc_count++;
106446 + pax_open_kernel();
106447 + (*(unsigned int *)&procp->pc_count)++;
106448 + pax_close_kernel();
106449
106450 /* Initialize storage for argp and resp */
106451 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106452 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106453 index 621ca7b..59421dd 100644
106454 --- a/net/sunrpc/svcauth_unix.c
106455 +++ b/net/sunrpc/svcauth_unix.c
106456 @@ -414,7 +414,7 @@ struct unix_gid {
106457 struct group_info *gi;
106458 };
106459
106460 -static int unix_gid_hash(kuid_t uid)
106461 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106462 {
106463 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106464 }
106465 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106466 (*bpp)[-1] = '\n';
106467 }
106468
106469 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106470 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106471
106472 static int unix_gid_parse(struct cache_detail *cd,
106473 char *mesg, int mlen)
106474 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106475 index c1b6270..05089c1 100644
106476 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106477 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106478 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106479 static unsigned int min_max_inline = 4096;
106480 static unsigned int max_max_inline = 65536;
106481
106482 -atomic_t rdma_stat_recv;
106483 -atomic_t rdma_stat_read;
106484 -atomic_t rdma_stat_write;
106485 -atomic_t rdma_stat_sq_starve;
106486 -atomic_t rdma_stat_rq_starve;
106487 -atomic_t rdma_stat_rq_poll;
106488 -atomic_t rdma_stat_rq_prod;
106489 -atomic_t rdma_stat_sq_poll;
106490 -atomic_t rdma_stat_sq_prod;
106491 +atomic_unchecked_t rdma_stat_recv;
106492 +atomic_unchecked_t rdma_stat_read;
106493 +atomic_unchecked_t rdma_stat_write;
106494 +atomic_unchecked_t rdma_stat_sq_starve;
106495 +atomic_unchecked_t rdma_stat_rq_starve;
106496 +atomic_unchecked_t rdma_stat_rq_poll;
106497 +atomic_unchecked_t rdma_stat_rq_prod;
106498 +atomic_unchecked_t rdma_stat_sq_poll;
106499 +atomic_unchecked_t rdma_stat_sq_prod;
106500
106501 /* Temporary NFS request map and context caches */
106502 struct kmem_cache *svc_rdma_map_cachep;
106503 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106504 len -= *ppos;
106505 if (len > *lenp)
106506 len = *lenp;
106507 - if (len && copy_to_user(buffer, str_buf, len))
106508 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106509 return -EFAULT;
106510 *lenp = len;
106511 *ppos += len;
106512 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
106513 {
106514 .procname = "rdma_stat_read",
106515 .data = &rdma_stat_read,
106516 - .maxlen = sizeof(atomic_t),
106517 + .maxlen = sizeof(atomic_unchecked_t),
106518 .mode = 0644,
106519 .proc_handler = read_reset_stat,
106520 },
106521 {
106522 .procname = "rdma_stat_recv",
106523 .data = &rdma_stat_recv,
106524 - .maxlen = sizeof(atomic_t),
106525 + .maxlen = sizeof(atomic_unchecked_t),
106526 .mode = 0644,
106527 .proc_handler = read_reset_stat,
106528 },
106529 {
106530 .procname = "rdma_stat_write",
106531 .data = &rdma_stat_write,
106532 - .maxlen = sizeof(atomic_t),
106533 + .maxlen = sizeof(atomic_unchecked_t),
106534 .mode = 0644,
106535 .proc_handler = read_reset_stat,
106536 },
106537 {
106538 .procname = "rdma_stat_sq_starve",
106539 .data = &rdma_stat_sq_starve,
106540 - .maxlen = sizeof(atomic_t),
106541 + .maxlen = sizeof(atomic_unchecked_t),
106542 .mode = 0644,
106543 .proc_handler = read_reset_stat,
106544 },
106545 {
106546 .procname = "rdma_stat_rq_starve",
106547 .data = &rdma_stat_rq_starve,
106548 - .maxlen = sizeof(atomic_t),
106549 + .maxlen = sizeof(atomic_unchecked_t),
106550 .mode = 0644,
106551 .proc_handler = read_reset_stat,
106552 },
106553 {
106554 .procname = "rdma_stat_rq_poll",
106555 .data = &rdma_stat_rq_poll,
106556 - .maxlen = sizeof(atomic_t),
106557 + .maxlen = sizeof(atomic_unchecked_t),
106558 .mode = 0644,
106559 .proc_handler = read_reset_stat,
106560 },
106561 {
106562 .procname = "rdma_stat_rq_prod",
106563 .data = &rdma_stat_rq_prod,
106564 - .maxlen = sizeof(atomic_t),
106565 + .maxlen = sizeof(atomic_unchecked_t),
106566 .mode = 0644,
106567 .proc_handler = read_reset_stat,
106568 },
106569 {
106570 .procname = "rdma_stat_sq_poll",
106571 .data = &rdma_stat_sq_poll,
106572 - .maxlen = sizeof(atomic_t),
106573 + .maxlen = sizeof(atomic_unchecked_t),
106574 .mode = 0644,
106575 .proc_handler = read_reset_stat,
106576 },
106577 {
106578 .procname = "rdma_stat_sq_prod",
106579 .data = &rdma_stat_sq_prod,
106580 - .maxlen = sizeof(atomic_t),
106581 + .maxlen = sizeof(atomic_unchecked_t),
106582 .mode = 0644,
106583 .proc_handler = read_reset_stat,
106584 },
106585 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106586 index e011027..9d3c4e1 100644
106587 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106588 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106589 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
106590 *page_no = pg_no;
106591 *page_offset = pg_off;
106592 ret = read;
106593 - atomic_inc(&rdma_stat_read);
106594 + atomic_inc_unchecked(&rdma_stat_read);
106595 return ret;
106596 err:
106597 svc_rdma_unmap_dma(ctxt);
106598 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
106599 *page_no = pg_no;
106600 *page_offset = pg_off;
106601 ret = read;
106602 - atomic_inc(&rdma_stat_read);
106603 + atomic_inc_unchecked(&rdma_stat_read);
106604 return ret;
106605 err:
106606 svc_rdma_unmap_dma(ctxt);
106607 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106608 dto_q);
106609 list_del_init(&ctxt->dto_q);
106610 } else {
106611 - atomic_inc(&rdma_stat_rq_starve);
106612 + atomic_inc_unchecked(&rdma_stat_rq_starve);
106613 clear_bit(XPT_DATA, &xprt->xpt_flags);
106614 ctxt = NULL;
106615 }
106616 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106617 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
106618 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
106619 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
106620 - atomic_inc(&rdma_stat_recv);
106621 + atomic_inc_unchecked(&rdma_stat_recv);
106622
106623 /* Build up the XDR from the receive buffers. */
106624 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
106625 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106626 index 9f1b506..2e0b321 100644
106627 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106628 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106629 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
106630 write_wr.wr.rdma.remote_addr = to;
106631
106632 /* Post It */
106633 - atomic_inc(&rdma_stat_write);
106634 + atomic_inc_unchecked(&rdma_stat_write);
106635 if (svc_rdma_send(xprt, &write_wr))
106636 goto err;
106637 return write_len - bc;
106638 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106639 index 4e61880..1f0d963 100644
106640 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
106641 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106642 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106643 return;
106644
106645 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
106646 - atomic_inc(&rdma_stat_rq_poll);
106647 + atomic_inc_unchecked(&rdma_stat_rq_poll);
106648
106649 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
106650 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
106651 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106652 }
106653
106654 if (ctxt)
106655 - atomic_inc(&rdma_stat_rq_prod);
106656 + atomic_inc_unchecked(&rdma_stat_rq_prod);
106657
106658 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
106659 /*
106660 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106661 return;
106662
106663 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
106664 - atomic_inc(&rdma_stat_sq_poll);
106665 + atomic_inc_unchecked(&rdma_stat_sq_poll);
106666 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
106667 int i;
106668
106669 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106670 }
106671
106672 if (ctxt)
106673 - atomic_inc(&rdma_stat_sq_prod);
106674 + atomic_inc_unchecked(&rdma_stat_sq_prod);
106675 }
106676
106677 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
106678 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
106679 spin_lock_bh(&xprt->sc_lock);
106680 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
106681 spin_unlock_bh(&xprt->sc_lock);
106682 - atomic_inc(&rdma_stat_sq_starve);
106683 + atomic_inc_unchecked(&rdma_stat_sq_starve);
106684
106685 /* See if we can opportunistically reap SQ WR to make room */
106686 sq_cq_reap(xprt);
106687 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
106688 index e7000be..e3b0ba7 100644
106689 --- a/net/sysctl_net.c
106690 +++ b/net/sysctl_net.c
106691 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
106692 kgid_t root_gid = make_kgid(net->user_ns, 0);
106693
106694 /* Allow network administrator to have same access as root. */
106695 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
106696 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
106697 uid_eq(root_uid, current_euid())) {
106698 int mode = (table->mode >> 6) & 7;
106699 return (mode << 6) | (mode << 3) | mode;
106700 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
106701 index 31b5cb2..566ff01 100644
106702 --- a/net/tipc/subscr.c
106703 +++ b/net/tipc/subscr.c
106704 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
106705 struct tipc_subscriber *subscriber = sub->subscriber;
106706 struct kvec msg_sect;
106707
106708 - msg_sect.iov_base = (void *)&sub->evt;
106709 + msg_sect.iov_base = &sub->evt;
106710 msg_sect.iov_len = sizeof(struct tipc_event);
106711 sub->evt.event = htohl(event, sub->swap);
106712 sub->evt.found_lower = htohl(found_lower, sub->swap);
106713 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
106714 index e968843..bc95776 100644
106715 --- a/net/unix/af_unix.c
106716 +++ b/net/unix/af_unix.c
106717 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
106718 err = -ECONNREFUSED;
106719 if (!S_ISSOCK(inode->i_mode))
106720 goto put_fail;
106721 +
106722 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
106723 + err = -EACCES;
106724 + goto put_fail;
106725 + }
106726 +
106727 u = unix_find_socket_byinode(inode);
106728 if (!u)
106729 goto put_fail;
106730 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
106731 if (u) {
106732 struct dentry *dentry;
106733 dentry = unix_sk(u)->path.dentry;
106734 +
106735 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
106736 + err = -EPERM;
106737 + sock_put(u);
106738 + goto fail;
106739 + }
106740 +
106741 if (dentry)
106742 touch_atime(&unix_sk(u)->path);
106743 } else
106744 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
106745 */
106746 err = security_path_mknod(&path, dentry, mode, 0);
106747 if (!err) {
106748 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
106749 + err = -EACCES;
106750 + goto out;
106751 + }
106752 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
106753 if (!err) {
106754 res->mnt = mntget(path.mnt);
106755 res->dentry = dget(dentry);
106756 + gr_handle_create(dentry, path.mnt);
106757 }
106758 }
106759 +out:
106760 done_path_create(&path, dentry);
106761 return err;
106762 }
106763 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106764 seq_puts(seq, "Num RefCount Protocol Flags Type St "
106765 "Inode Path\n");
106766 else {
106767 - struct sock *s = v;
106768 + struct sock *s = v, *peer;
106769 struct unix_sock *u = unix_sk(s);
106770 unix_state_lock(s);
106771 + peer = unix_peer(s);
106772 + unix_state_unlock(s);
106773 +
106774 + unix_state_double_lock(s, peer);
106775
106776 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
106777 s,
106778 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106779 }
106780 for ( ; i < len; i++)
106781 seq_putc(seq, u->addr->name->sun_path[i]);
106782 - }
106783 - unix_state_unlock(s);
106784 + } else if (peer)
106785 + seq_printf(seq, " P%lu", sock_i_ino(peer));
106786 +
106787 + unix_state_double_unlock(s, peer);
106788 seq_putc(seq, '\n');
106789 }
106790
106791 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
106792 index b3d5150..ff3a837 100644
106793 --- a/net/unix/sysctl_net_unix.c
106794 +++ b/net/unix/sysctl_net_unix.c
106795 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
106796
106797 int __net_init unix_sysctl_register(struct net *net)
106798 {
106799 - struct ctl_table *table;
106800 + ctl_table_no_const *table;
106801
106802 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
106803 if (table == NULL)
106804 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
106805 index 9b7f207..2596621 100644
106806 --- a/net/vmw_vsock/vmci_transport_notify.c
106807 +++ b/net/vmw_vsock/vmci_transport_notify.c
106808 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
106809
106810 /* Socket control packet based operations. */
106811 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
106812 - vmci_transport_notify_pkt_socket_init,
106813 - vmci_transport_notify_pkt_socket_destruct,
106814 - vmci_transport_notify_pkt_poll_in,
106815 - vmci_transport_notify_pkt_poll_out,
106816 - vmci_transport_notify_pkt_handle_pkt,
106817 - vmci_transport_notify_pkt_recv_init,
106818 - vmci_transport_notify_pkt_recv_pre_block,
106819 - vmci_transport_notify_pkt_recv_pre_dequeue,
106820 - vmci_transport_notify_pkt_recv_post_dequeue,
106821 - vmci_transport_notify_pkt_send_init,
106822 - vmci_transport_notify_pkt_send_pre_block,
106823 - vmci_transport_notify_pkt_send_pre_enqueue,
106824 - vmci_transport_notify_pkt_send_post_enqueue,
106825 - vmci_transport_notify_pkt_process_request,
106826 - vmci_transport_notify_pkt_process_negotiate,
106827 + .socket_init = vmci_transport_notify_pkt_socket_init,
106828 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106829 + .poll_in = vmci_transport_notify_pkt_poll_in,
106830 + .poll_out = vmci_transport_notify_pkt_poll_out,
106831 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106832 + .recv_init = vmci_transport_notify_pkt_recv_init,
106833 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106834 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106835 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106836 + .send_init = vmci_transport_notify_pkt_send_init,
106837 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106838 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106839 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106840 + .process_request = vmci_transport_notify_pkt_process_request,
106841 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106842 };
106843 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
106844 index dc9c792..3089de0 100644
106845 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
106846 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
106847 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
106848
106849 /* Socket always on control packet based operations. */
106850 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
106851 - vmci_transport_notify_pkt_socket_init,
106852 - vmci_transport_notify_pkt_socket_destruct,
106853 - vmci_transport_notify_pkt_poll_in,
106854 - vmci_transport_notify_pkt_poll_out,
106855 - vmci_transport_notify_pkt_handle_pkt,
106856 - vmci_transport_notify_pkt_recv_init,
106857 - vmci_transport_notify_pkt_recv_pre_block,
106858 - vmci_transport_notify_pkt_recv_pre_dequeue,
106859 - vmci_transport_notify_pkt_recv_post_dequeue,
106860 - vmci_transport_notify_pkt_send_init,
106861 - vmci_transport_notify_pkt_send_pre_block,
106862 - vmci_transport_notify_pkt_send_pre_enqueue,
106863 - vmci_transport_notify_pkt_send_post_enqueue,
106864 - vmci_transport_notify_pkt_process_request,
106865 - vmci_transport_notify_pkt_process_negotiate,
106866 + .socket_init = vmci_transport_notify_pkt_socket_init,
106867 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106868 + .poll_in = vmci_transport_notify_pkt_poll_in,
106869 + .poll_out = vmci_transport_notify_pkt_poll_out,
106870 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106871 + .recv_init = vmci_transport_notify_pkt_recv_init,
106872 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106873 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106874 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106875 + .send_init = vmci_transport_notify_pkt_send_init,
106876 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106877 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106878 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106879 + .process_request = vmci_transport_notify_pkt_process_request,
106880 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106881 };
106882 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
106883 index c8717c1..08539f5 100644
106884 --- a/net/wireless/wext-core.c
106885 +++ b/net/wireless/wext-core.c
106886 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106887 */
106888
106889 /* Support for very large requests */
106890 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
106891 - (user_length > descr->max_tokens)) {
106892 + if (user_length > descr->max_tokens) {
106893 /* Allow userspace to GET more than max so
106894 * we can support any size GET requests.
106895 * There is still a limit : -ENOMEM.
106896 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106897 }
106898 }
106899
106900 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
106901 - /*
106902 - * If this is a GET, but not NOMAX, it means that the extra
106903 - * data is not bounded by userspace, but by max_tokens. Thus
106904 - * set the length to max_tokens. This matches the extra data
106905 - * allocation.
106906 - * The driver should fill it with the number of tokens it
106907 - * provided, and it may check iwp->length rather than having
106908 - * knowledge of max_tokens. If the driver doesn't change the
106909 - * iwp->length, this ioctl just copies back max_token tokens
106910 - * filled with zeroes. Hopefully the driver isn't claiming
106911 - * them to be valid data.
106912 - */
106913 - iwp->length = descr->max_tokens;
106914 - }
106915 -
106916 err = handler(dev, info, (union iwreq_data *) iwp, extra);
106917
106918 iwp->length += essid_compat;
106919 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
106920 index 4323952..a06dfe1 100644
106921 --- a/net/x25/sysctl_net_x25.c
106922 +++ b/net/x25/sysctl_net_x25.c
106923 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
106924 .mode = 0644,
106925 .proc_handler = proc_dointvec,
106926 },
106927 - { 0, },
106928 + { },
106929 };
106930
106931 void __init x25_register_sysctl(void)
106932 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
106933 index 0917f04..f4e3d8c 100644
106934 --- a/net/x25/x25_proc.c
106935 +++ b/net/x25/x25_proc.c
106936 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
106937
106938 int __init x25_proc_init(void)
106939 {
106940 - if (!proc_mkdir("x25", init_net.proc_net))
106941 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
106942 return -ENOMEM;
106943
106944 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
106945 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
106946 index 88bf289..7b0741b 100644
106947 --- a/net/xfrm/xfrm_policy.c
106948 +++ b/net/xfrm/xfrm_policy.c
106949 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
106950 {
106951 policy->walk.dead = 1;
106952
106953 - atomic_inc(&policy->genid);
106954 + atomic_inc_unchecked(&policy->genid);
106955
106956 if (del_timer(&policy->polq.hold_timer))
106957 xfrm_pol_put(policy);
106958 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
106959 hlist_add_head(&policy->bydst, chain);
106960 xfrm_pol_hold(policy);
106961 net->xfrm.policy_count[dir]++;
106962 - atomic_inc(&net->xfrm.flow_cache_genid);
106963 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106964
106965 /* After previous checking, family can either be AF_INET or AF_INET6 */
106966 if (policy->family == AF_INET)
106967 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
106968
106969 xdst->num_pols = num_pols;
106970 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
106971 - xdst->policy_genid = atomic_read(&pols[0]->genid);
106972 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
106973
106974 return xdst;
106975 }
106976 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
106977 }
106978 EXPORT_SYMBOL(xfrm_garbage_collect);
106979
106980 -static void xfrm_garbage_collect_deferred(struct net *net)
106981 +void xfrm_garbage_collect_deferred(struct net *net)
106982 {
106983 flow_cache_flush_deferred(net);
106984 }
106985 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
106986
106987 static void xfrm_init_pmtu(struct dst_entry *dst)
106988 {
106989 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
106990 if (xdst->xfrm_genid != dst->xfrm->genid)
106991 return 0;
106992 if (xdst->num_pols > 0 &&
106993 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
106994 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
106995 return 0;
106996
106997 mtu = dst_mtu(dst->child);
106998 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
106999 dst_ops->link_failure = xfrm_link_failure;
107000 if (likely(dst_ops->neigh_lookup == NULL))
107001 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107002 - if (likely(afinfo->garbage_collect == NULL))
107003 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107004 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107005 }
107006 spin_unlock(&xfrm_policy_afinfo_lock);
107007 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107008 dst_ops->check = NULL;
107009 dst_ops->negative_advice = NULL;
107010 dst_ops->link_failure = NULL;
107011 - afinfo->garbage_collect = NULL;
107012 }
107013 return err;
107014 }
107015 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107016 sizeof(pol->xfrm_vec[i].saddr));
107017 pol->xfrm_vec[i].encap_family = mp->new_family;
107018 /* flush bundles */
107019 - atomic_inc(&pol->genid);
107020 + atomic_inc_unchecked(&pol->genid);
107021 }
107022 }
107023
107024 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107025 index de971b6..b843409 100644
107026 --- a/net/xfrm/xfrm_state.c
107027 +++ b/net/xfrm/xfrm_state.c
107028 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107029
107030 if (unlikely(afinfo == NULL))
107031 return -EAFNOSUPPORT;
107032 - typemap = afinfo->type_map;
107033 + typemap = (const struct xfrm_type **)afinfo->type_map;
107034 spin_lock_bh(&xfrm_type_lock);
107035
107036 - if (likely(typemap[type->proto] == NULL))
107037 + if (likely(typemap[type->proto] == NULL)) {
107038 + pax_open_kernel();
107039 typemap[type->proto] = type;
107040 - else
107041 + pax_close_kernel();
107042 + } else
107043 err = -EEXIST;
107044 spin_unlock_bh(&xfrm_type_lock);
107045 xfrm_state_put_afinfo(afinfo);
107046 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107047
107048 if (unlikely(afinfo == NULL))
107049 return -EAFNOSUPPORT;
107050 - typemap = afinfo->type_map;
107051 + typemap = (const struct xfrm_type **)afinfo->type_map;
107052 spin_lock_bh(&xfrm_type_lock);
107053
107054 if (unlikely(typemap[type->proto] != type))
107055 err = -ENOENT;
107056 - else
107057 + else {
107058 + pax_open_kernel();
107059 typemap[type->proto] = NULL;
107060 + pax_close_kernel();
107061 + }
107062 spin_unlock_bh(&xfrm_type_lock);
107063 xfrm_state_put_afinfo(afinfo);
107064 return err;
107065 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107066 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107067 {
107068 struct xfrm_state_afinfo *afinfo;
107069 - const struct xfrm_type **typemap;
107070 const struct xfrm_type *type;
107071 int modload_attempted = 0;
107072
107073 @@ -211,9 +215,8 @@ retry:
107074 afinfo = xfrm_state_get_afinfo(family);
107075 if (unlikely(afinfo == NULL))
107076 return NULL;
107077 - typemap = afinfo->type_map;
107078
107079 - type = typemap[proto];
107080 + type = afinfo->type_map[proto];
107081 if (unlikely(type && !try_module_get(type->owner)))
107082 type = NULL;
107083 if (!type && !modload_attempted) {
107084 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107085 return -EAFNOSUPPORT;
107086
107087 err = -EEXIST;
107088 - modemap = afinfo->mode_map;
107089 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107090 spin_lock_bh(&xfrm_mode_lock);
107091 if (modemap[mode->encap])
107092 goto out;
107093 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107094 if (!try_module_get(afinfo->owner))
107095 goto out;
107096
107097 - mode->afinfo = afinfo;
107098 + pax_open_kernel();
107099 + *(const void **)&mode->afinfo = afinfo;
107100 modemap[mode->encap] = mode;
107101 + pax_close_kernel();
107102 err = 0;
107103
107104 out:
107105 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107106 return -EAFNOSUPPORT;
107107
107108 err = -ENOENT;
107109 - modemap = afinfo->mode_map;
107110 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107111 spin_lock_bh(&xfrm_mode_lock);
107112 if (likely(modemap[mode->encap] == mode)) {
107113 + pax_open_kernel();
107114 modemap[mode->encap] = NULL;
107115 + pax_close_kernel();
107116 module_put(mode->afinfo->owner);
107117 err = 0;
107118 }
107119 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107120 u32 xfrm_get_acqseq(void)
107121 {
107122 u32 res;
107123 - static atomic_t acqseq;
107124 + static atomic_unchecked_t acqseq;
107125
107126 do {
107127 - res = atomic_inc_return(&acqseq);
107128 + res = atomic_inc_return_unchecked(&acqseq);
107129 } while (!res);
107130
107131 return res;
107132 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107133 index 05a6e3d..6716ec9 100644
107134 --- a/net/xfrm/xfrm_sysctl.c
107135 +++ b/net/xfrm/xfrm_sysctl.c
107136 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107137
107138 int __net_init xfrm_sysctl_init(struct net *net)
107139 {
107140 - struct ctl_table *table;
107141 + ctl_table_no_const *table;
107142
107143 __xfrm_sysctl_init(net);
107144
107145 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107146 index 649ce68..f6bc05c 100644
107147 --- a/scripts/Makefile.build
107148 +++ b/scripts/Makefile.build
107149 @@ -60,7 +60,7 @@ endif
107150 endif
107151
107152 # Do not include host rules unless needed
107153 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107154 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107155 include scripts/Makefile.host
107156 endif
107157
107158 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107159 index a609552..fde19cd 100644
107160 --- a/scripts/Makefile.clean
107161 +++ b/scripts/Makefile.clean
107162 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107163 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107164 $(always) $(targets) $(clean-files) \
107165 $(host-progs) \
107166 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107167 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107168 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107169
107170 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107171
107172 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107173 index 133edfa..c9aa07f 100644
107174 --- a/scripts/Makefile.host
107175 +++ b/scripts/Makefile.host
107176 @@ -20,7 +20,19 @@
107177 # Will compile qconf as a C++ program, and menu as a C program.
107178 # They are linked as C++ code to the executable qconf
107179
107180 +# hostprogs-y := conf
107181 +# conf-objs := conf.o libkconfig.so
107182 +# libkconfig-objs := expr.o type.o
107183 +# Will create a shared library named libkconfig.so that consists of
107184 +# expr.o and type.o (they are both compiled as C code and the object files
107185 +# are made as position independent code).
107186 +# conf.c is compiled as a C program, and conf.o is linked together with
107187 +# libkconfig.so as the executable conf.
107188 +# Note: Shared libraries consisting of C++ files are not supported
107189 +
107190 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107191 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107192 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107193
107194 # C code
107195 # Executables compiled from a single .c file
107196 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107197 # C++ Object (.o) files compiled from .cc files
107198 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107199
107200 +# Shared libaries (only .c supported)
107201 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107202 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107203 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107204 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107205 +# Remove .so files from "xxx-objs"
107206 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107207 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107208 +
107209 +# Object (.o) files used by the shared libaries
107210 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107211 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107212 +
107213 # output directory for programs/.o files
107214 # hostprogs-y := tools/build may have been specified.
107215 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107216 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107217 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107218 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107219 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107220 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107221 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107222 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107223 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107224 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107225
107226 obj-dirs += $(host-objdirs)
107227 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107228 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107229 $(call if_changed_dep,host-cxxobjs)
107230
107231 +# Compile .c file, create position independent .o file
107232 +# host-cshobjs -> .o
107233 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107234 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107235 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107236 + $(call if_changed_dep,host-cshobjs)
107237 +
107238 +# Compile .c file, create position independent .o file
107239 +# host-cxxshobjs -> .o
107240 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107241 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107242 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107243 + $(call if_changed_dep,host-cxxshobjs)
107244 +
107245 +# Link a shared library, based on position independent .o files
107246 +# *.o -> .so shared library (host-cshlib)
107247 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107248 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107249 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107250 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107251 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107252 + $(call if_changed,host-cshlib)
107253 +
107254 +# Link a shared library, based on position independent .o files
107255 +# *.o -> .so shared library (host-cxxshlib)
107256 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107257 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107258 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107259 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107260 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107261 + $(call if_changed,host-cxxshlib)
107262 +
107263 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107264 - $(host-cxxmulti) $(host-cxxobjs)
107265 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107266 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107267 index b304068..462d24e 100644
107268 --- a/scripts/basic/fixdep.c
107269 +++ b/scripts/basic/fixdep.c
107270 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107271 /*
107272 * Lookup a value in the configuration string.
107273 */
107274 -static int is_defined_config(const char *name, int len, unsigned int hash)
107275 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107276 {
107277 struct item *aux;
107278
107279 @@ -211,10 +211,10 @@ static void clear_config(void)
107280 /*
107281 * Record the use of a CONFIG_* word.
107282 */
107283 -static void use_config(const char *m, int slen)
107284 +static void use_config(const char *m, unsigned int slen)
107285 {
107286 unsigned int hash = strhash(m, slen);
107287 - int c, i;
107288 + unsigned int c, i;
107289
107290 if (is_defined_config(m, slen, hash))
107291 return;
107292 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107293
107294 static void parse_config_file(const char *map, size_t len)
107295 {
107296 - const int *end = (const int *) (map + len);
107297 + const unsigned int *end = (const unsigned int *) (map + len);
107298 /* start at +1, so that p can never be < map */
107299 - const int *m = (const int *) map + 1;
107300 + const unsigned int *m = (const unsigned int *) map + 1;
107301 const char *p, *q;
107302
107303 for (; m < end; m++) {
107304 @@ -435,7 +435,7 @@ static void print_deps(void)
107305 static void traps(void)
107306 {
107307 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107308 - int *p = (int *)test;
107309 + unsigned int *p = (unsigned int *)test;
107310
107311 if (*p != INT_CONF) {
107312 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107313 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107314 new file mode 100644
107315 index 0000000..42018ed
107316 --- /dev/null
107317 +++ b/scripts/gcc-plugin.sh
107318 @@ -0,0 +1,51 @@
107319 +#!/bin/sh
107320 +srctree=$(dirname "$0")
107321 +gccplugins_dir=$($3 -print-file-name=plugin)
107322 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107323 +#include "gcc-common.h"
107324 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107325 +#warning $2 CXX
107326 +#else
107327 +#warning $1 CC
107328 +#endif
107329 +EOF
107330 +)
107331 +
107332 +if [ $? -ne 0 ]
107333 +then
107334 + exit 1
107335 +fi
107336 +
107337 +case "$plugincc" in
107338 + *"$1 CC"*)
107339 + echo "$1"
107340 + exit 0
107341 + ;;
107342 +
107343 + *"$2 CXX"*)
107344 + # the c++ compiler needs another test, see below
107345 + ;;
107346 +
107347 + *)
107348 + exit 1
107349 + ;;
107350 +esac
107351 +
107352 +# we need a c++ compiler that supports the designated initializer GNU extension
107353 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107354 +#include "gcc-common.h"
107355 +class test {
107356 +public:
107357 + int test;
107358 +} test = {
107359 + .test = 1
107360 +};
107361 +EOF
107362 +)
107363 +
107364 +if [ $? -eq 0 ]
107365 +then
107366 + echo "$2"
107367 + exit 0
107368 +fi
107369 +exit 1
107370 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107371 index fdebd66..a349e33 100755
107372 --- a/scripts/headers_install.sh
107373 +++ b/scripts/headers_install.sh
107374 @@ -32,6 +32,7 @@ do
107375 FILE="$(basename "$i")"
107376 sed -r \
107377 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107378 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107379 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107380 -e 's@^#include <linux/compiler.h>@@' \
107381 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107382 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107383 index 86a4fe7..99e91f9 100755
107384 --- a/scripts/link-vmlinux.sh
107385 +++ b/scripts/link-vmlinux.sh
107386 @@ -166,7 +166,7 @@ else
107387 fi;
107388
107389 # final build of init/
107390 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107391 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107392
107393 kallsymso=""
107394 kallsyms_vmlinux=""
107395 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107396 index e614ef6..d9d2b01 100644
107397 --- a/scripts/mod/file2alias.c
107398 +++ b/scripts/mod/file2alias.c
107399 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107400 unsigned long size, unsigned long id_size,
107401 void *symval)
107402 {
107403 - int i;
107404 + unsigned int i;
107405
107406 if (size % id_size || size < id_size) {
107407 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107408 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107409 /* USB is special because the bcdDevice can be matched against a numeric range */
107410 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107411 static void do_usb_entry(void *symval,
107412 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107413 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107414 unsigned char range_lo, unsigned char range_hi,
107415 unsigned char max, struct module *mod)
107416 {
107417 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107418 {
107419 unsigned int devlo, devhi;
107420 unsigned char chi, clo, max;
107421 - int ndigits;
107422 + unsigned int ndigits;
107423
107424 DEF_FIELD(symval, usb_device_id, match_flags);
107425 DEF_FIELD(symval, usb_device_id, idVendor);
107426 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107427 for (i = 0; i < count; i++) {
107428 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107429 char acpi_id[sizeof(*id)];
107430 - int j;
107431 + unsigned int j;
107432
107433 buf_printf(&mod->dev_table_buf,
107434 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107435 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107436
107437 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107438 const char *id = (char *)(*devs)[j].id;
107439 - int i2, j2;
107440 + unsigned int i2, j2;
107441 int dup = 0;
107442
107443 if (!id[0])
107444 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107445 /* add an individual alias for every device entry */
107446 if (!dup) {
107447 char acpi_id[PNP_ID_LEN];
107448 - int k;
107449 + unsigned int k;
107450
107451 buf_printf(&mod->dev_table_buf,
107452 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107453 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107454 static int do_dmi_entry(const char *filename, void *symval,
107455 char *alias)
107456 {
107457 - int i, j;
107458 + unsigned int i, j;
107459 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107460 sprintf(alias, "dmi*");
107461
107462 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107463 index d439856..10c1eac 100644
107464 --- a/scripts/mod/modpost.c
107465 +++ b/scripts/mod/modpost.c
107466 @@ -921,6 +921,7 @@ enum mismatch {
107467 ANY_INIT_TO_ANY_EXIT,
107468 ANY_EXIT_TO_ANY_INIT,
107469 EXPORT_TO_INIT_EXIT,
107470 + DATA_TO_TEXT
107471 };
107472
107473 struct sectioncheck {
107474 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
107475 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107476 .mismatch = EXPORT_TO_INIT_EXIT,
107477 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107478 +},
107479 +/* Do not reference code from writable data */
107480 +{
107481 + .fromsec = { DATA_SECTIONS, NULL },
107482 + .tosec = { TEXT_SECTIONS, NULL },
107483 + .mismatch = DATA_TO_TEXT
107484 }
107485 };
107486
107487 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107488 continue;
107489 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107490 continue;
107491 - if (sym->st_value == addr)
107492 - return sym;
107493 /* Find a symbol nearby - addr are maybe negative */
107494 d = sym->st_value - addr;
107495 + if (d == 0)
107496 + return sym;
107497 if (d < 0)
107498 d = addr - sym->st_value;
107499 if (d < distance) {
107500 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
107501 tosym, prl_to, prl_to, tosym);
107502 free(prl_to);
107503 break;
107504 + case DATA_TO_TEXT:
107505 +#if 0
107506 + fprintf(stderr,
107507 + "The %s %s:%s references\n"
107508 + "the %s %s:%s%s\n",
107509 + from, fromsec, fromsym, to, tosec, tosym, to_p);
107510 +#endif
107511 + break;
107512 }
107513 fprintf(stderr, "\n");
107514 }
107515 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
107516 static void check_sec_ref(struct module *mod, const char *modname,
107517 struct elf_info *elf)
107518 {
107519 - int i;
107520 + unsigned int i;
107521 Elf_Shdr *sechdrs = elf->sechdrs;
107522
107523 /* Walk through all sections */
107524 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
107525 va_end(ap);
107526 }
107527
107528 -void buf_write(struct buffer *buf, const char *s, int len)
107529 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
107530 {
107531 if (buf->size - buf->pos < len) {
107532 buf->size += len + SZ;
107533 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
107534 if (fstat(fileno(file), &st) < 0)
107535 goto close_write;
107536
107537 - if (st.st_size != b->pos)
107538 + if (st.st_size != (off_t)b->pos)
107539 goto close_write;
107540
107541 tmp = NOFAIL(malloc(b->pos));
107542 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
107543 index 168b43d..77914bf 100644
107544 --- a/scripts/mod/modpost.h
107545 +++ b/scripts/mod/modpost.h
107546 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
107547
107548 struct buffer {
107549 char *p;
107550 - int pos;
107551 - int size;
107552 + unsigned int pos;
107553 + unsigned int size;
107554 };
107555
107556 void __attribute__((format(printf, 2, 3)))
107557 buf_printf(struct buffer *buf, const char *fmt, ...);
107558
107559 void
107560 -buf_write(struct buffer *buf, const char *s, int len);
107561 +buf_write(struct buffer *buf, const char *s, unsigned int len);
107562
107563 struct module {
107564 struct module *next;
107565 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
107566 index 944418d..15291e4 100644
107567 --- a/scripts/mod/sumversion.c
107568 +++ b/scripts/mod/sumversion.c
107569 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
107570 goto out;
107571 }
107572
107573 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
107574 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
107575 warn("writing sum in %s failed: %s\n",
107576 filename, strerror(errno));
107577 goto out;
107578 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
107579 index 0865b3e..7235dd4 100644
107580 --- a/scripts/module-common.lds
107581 +++ b/scripts/module-common.lds
107582 @@ -6,6 +6,10 @@
107583 SECTIONS {
107584 /DISCARD/ : { *(.discard) }
107585
107586 + .rodata : {
107587 + *(.rodata) *(.rodata.*)
107588 + *(.data..read_only)
107589 + }
107590 __ksymtab : { *(SORT(___ksymtab+*)) }
107591 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
107592 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
107593 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
107594 index 99ca6e7..3a1a1a1 100644
107595 --- a/scripts/package/Makefile
107596 +++ b/scripts/package/Makefile
107597 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
107598 ln -sf $(srctree) $(KERNELPATH)
107599 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
107600 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
107601 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
107602 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
107603 rm $(KERNELPATH)
107604 rm -f $(objtree)/.scmversion
107605 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
107606 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
107607 index 5972624..4028795 100755
107608 --- a/scripts/package/builddeb
107609 +++ b/scripts/package/builddeb
107610 @@ -293,6 +293,7 @@ fi
107611 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
107612 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
107613 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
107614 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
107615 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
107616 mkdir -p "$destdir"
107617 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
107618 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
107619 index 1395760..bca2734 100755
107620 --- a/scripts/package/mkspec
107621 +++ b/scripts/package/mkspec
107622 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
107623 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
107624 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\""
107625 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
107626 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
107627 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
107628 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
107629
107630 echo ""
107631 echo "%clean"
107632 echo 'rm -rf $RPM_BUILD_ROOT'
107633 echo ""
107634 +echo "%pre"
107635 +echo 'chmod -f 0500 /boot'
107636 +echo 'if [ -d /lib/modules ]; then'
107637 +echo 'chmod -f 0500 /lib/modules'
107638 +echo 'fi'
107639 +echo 'if [ -d /lib32/modules ]; then'
107640 +echo 'chmod -f 0500 /lib32/modules'
107641 +echo 'fi'
107642 +echo 'if [ -d /lib64/modules ]; then'
107643 +echo 'chmod -f 0500 /lib64/modules'
107644 +echo 'fi'
107645 +echo ""
107646 +echo "%post devel"
107647 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
107648 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
107649 +echo ""
107650 echo "%post"
107651 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
107652 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
107653 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
107654 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
107655 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
107656 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
107657 +echo "if [ -x /sbin/dracut ]; then"
107658 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
107659 +echo "else"
107660 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
107661 echo "fi"
107662 echo ""
107663 echo "%files"
107664 -echo '%defattr (-, root, root)'
107665 +echo '%defattr (400, root, root, 500)'
107666 echo "%dir /lib/modules"
107667 -echo "/lib/modules/$KERNELRELEASE"
107668 echo "%exclude /lib/modules/$KERNELRELEASE/build"
107669 echo "%exclude /lib/modules/$KERNELRELEASE/source"
107670 +echo "/lib/modules/$KERNELRELEASE"
107671 echo "/lib/firmware/$KERNELRELEASE"
107672 echo "/boot/*"
107673 echo ""
107674 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
107675 echo "/usr/include"
107676 echo ""
107677 echo "%files devel"
107678 -echo '%defattr (-, root, root)'
107679 +echo '%defattr (400, root, root, 500)'
107680 +echo "%dir /lib/modules/$KERNELRELEASE"
107681 echo "/usr/src/kernels/$KERNELRELEASE"
107682 -echo "/lib/modules/$KERNELRELEASE/build"
107683 -echo "/lib/modules/$KERNELRELEASE/source"
107684 echo ""
107685 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
107686 index 4718d78..9220d58 100644
107687 --- a/scripts/pnmtologo.c
107688 +++ b/scripts/pnmtologo.c
107689 @@ -244,14 +244,14 @@ static void write_header(void)
107690 fprintf(out, " * Linux logo %s\n", logoname);
107691 fputs(" */\n\n", out);
107692 fputs("#include <linux/linux_logo.h>\n\n", out);
107693 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
107694 + fprintf(out, "static unsigned char %s_data[] = {\n",
107695 logoname);
107696 }
107697
107698 static void write_footer(void)
107699 {
107700 fputs("\n};\n\n", out);
107701 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
107702 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
107703 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
107704 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
107705 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
107706 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
107707 fputs("\n};\n\n", out);
107708
107709 /* write logo clut */
107710 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
107711 + fprintf(out, "static unsigned char %s_clut[] = {\n",
107712 logoname);
107713 write_hex_cnt = 0;
107714 for (i = 0; i < logo_clutsize; i++) {
107715 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
107716 index ba87004..3f4852c 100644
107717 --- a/scripts/sortextable.h
107718 +++ b/scripts/sortextable.h
107719 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
107720 const char *secstrtab;
107721 const char *strtab;
107722 char *extab_image;
107723 - int extab_index = 0;
107724 - int i;
107725 - int idx;
107726 + unsigned int extab_index = 0;
107727 + unsigned int i;
107728 + unsigned int idx;
107729 unsigned int num_sections;
107730 unsigned int secindex_strings;
107731
107732 diff --git a/scripts/tags.sh b/scripts/tags.sh
107733 index cdb491d..8d32bfc 100755
107734 --- a/scripts/tags.sh
107735 +++ b/scripts/tags.sh
107736 @@ -26,7 +26,7 @@ else
107737 fi
107738
107739 # ignore userspace tools
107740 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
107741 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
107742
107743 # Find all available archs
107744 find_all_archs()
107745 diff --git a/security/Kconfig b/security/Kconfig
107746 index beb86b5..1a953b1 100644
107747 --- a/security/Kconfig
107748 +++ b/security/Kconfig
107749 @@ -4,6 +4,974 @@
107750
107751 menu "Security options"
107752
107753 +menu "Grsecurity"
107754 +
107755 + config ARCH_TRACK_EXEC_LIMIT
107756 + bool
107757 +
107758 + config PAX_KERNEXEC_PLUGIN
107759 + bool
107760 +
107761 + config PAX_PER_CPU_PGD
107762 + bool
107763 +
107764 + config TASK_SIZE_MAX_SHIFT
107765 + int
107766 + depends on X86_64
107767 + default 47 if !PAX_PER_CPU_PGD
107768 + default 42 if PAX_PER_CPU_PGD
107769 +
107770 + config PAX_ENABLE_PAE
107771 + bool
107772 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
107773 +
107774 + config PAX_USERCOPY_SLABS
107775 + bool
107776 +
107777 +config GRKERNSEC
107778 + bool "Grsecurity"
107779 + select CRYPTO
107780 + select CRYPTO_SHA256
107781 + select PROC_FS
107782 + select STOP_MACHINE
107783 + select TTY
107784 + select DEBUG_KERNEL
107785 + select DEBUG_LIST
107786 + help
107787 + If you say Y here, you will be able to configure many features
107788 + that will enhance the security of your system. It is highly
107789 + recommended that you say Y here and read through the help
107790 + for each option so that you fully understand the features and
107791 + can evaluate their usefulness for your machine.
107792 +
107793 +choice
107794 + prompt "Configuration Method"
107795 + depends on GRKERNSEC
107796 + default GRKERNSEC_CONFIG_CUSTOM
107797 + help
107798 +
107799 +config GRKERNSEC_CONFIG_AUTO
107800 + bool "Automatic"
107801 + help
107802 + If you choose this configuration method, you'll be able to answer a small
107803 + number of simple questions about how you plan to use this kernel.
107804 + The settings of grsecurity and PaX will be automatically configured for
107805 + the highest commonly-used settings within the provided constraints.
107806 +
107807 + If you require additional configuration, custom changes can still be made
107808 + from the "custom configuration" menu.
107809 +
107810 +config GRKERNSEC_CONFIG_CUSTOM
107811 + bool "Custom"
107812 + help
107813 + If you choose this configuration method, you'll be able to configure all
107814 + grsecurity and PaX settings manually. Via this method, no options are
107815 + automatically enabled.
107816 +
107817 +endchoice
107818 +
107819 +choice
107820 + prompt "Usage Type"
107821 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107822 + default GRKERNSEC_CONFIG_SERVER
107823 + help
107824 +
107825 +config GRKERNSEC_CONFIG_SERVER
107826 + bool "Server"
107827 + help
107828 + Choose this option if you plan to use this kernel on a server.
107829 +
107830 +config GRKERNSEC_CONFIG_DESKTOP
107831 + bool "Desktop"
107832 + help
107833 + Choose this option if you plan to use this kernel on a desktop.
107834 +
107835 +endchoice
107836 +
107837 +choice
107838 + prompt "Virtualization Type"
107839 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
107840 + default GRKERNSEC_CONFIG_VIRT_NONE
107841 + help
107842 +
107843 +config GRKERNSEC_CONFIG_VIRT_NONE
107844 + bool "None"
107845 + help
107846 + Choose this option if this kernel will be run on bare metal.
107847 +
107848 +config GRKERNSEC_CONFIG_VIRT_GUEST
107849 + bool "Guest"
107850 + help
107851 + Choose this option if this kernel will be run as a VM guest.
107852 +
107853 +config GRKERNSEC_CONFIG_VIRT_HOST
107854 + bool "Host"
107855 + help
107856 + Choose this option if this kernel will be run as a VM host.
107857 +
107858 +endchoice
107859 +
107860 +choice
107861 + prompt "Virtualization Hardware"
107862 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107863 + help
107864 +
107865 +config GRKERNSEC_CONFIG_VIRT_EPT
107866 + bool "EPT/RVI Processor Support"
107867 + depends on X86
107868 + help
107869 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
107870 + hardware virtualization. This allows for additional kernel hardening protections
107871 + to operate without additional performance impact.
107872 +
107873 + To see if your Intel processor supports EPT, see:
107874 + http://ark.intel.com/Products/VirtualizationTechnology
107875 + (Most Core i3/5/7 support EPT)
107876 +
107877 + To see if your AMD processor supports RVI, see:
107878 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
107879 +
107880 +config GRKERNSEC_CONFIG_VIRT_SOFT
107881 + bool "First-gen/No Hardware Virtualization"
107882 + help
107883 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
107884 + support hardware virtualization or doesn't support the EPT/RVI extensions.
107885 +
107886 +endchoice
107887 +
107888 +choice
107889 + prompt "Virtualization Software"
107890 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107891 + help
107892 +
107893 +config GRKERNSEC_CONFIG_VIRT_XEN
107894 + bool "Xen"
107895 + help
107896 + Choose this option if this kernel is running as a Xen guest or host.
107897 +
107898 +config GRKERNSEC_CONFIG_VIRT_VMWARE
107899 + bool "VMWare"
107900 + help
107901 + Choose this option if this kernel is running as a VMWare guest or host.
107902 +
107903 +config GRKERNSEC_CONFIG_VIRT_KVM
107904 + bool "KVM"
107905 + help
107906 + Choose this option if this kernel is running as a KVM guest or host.
107907 +
107908 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
107909 + bool "VirtualBox"
107910 + help
107911 + Choose this option if this kernel is running as a VirtualBox guest or host.
107912 +
107913 +config GRKERNSEC_CONFIG_VIRT_HYPERV
107914 + bool "Hyper-V"
107915 + help
107916 + Choose this option if this kernel is running as a Hyper-V guest.
107917 +
107918 +endchoice
107919 +
107920 +choice
107921 + prompt "Required Priorities"
107922 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107923 + default GRKERNSEC_CONFIG_PRIORITY_PERF
107924 + help
107925 +
107926 +config GRKERNSEC_CONFIG_PRIORITY_PERF
107927 + bool "Performance"
107928 + help
107929 + Choose this option if performance is of highest priority for this deployment
107930 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
107931 + clearing of structures intended for userland, and freed memory sanitizing will
107932 + be disabled.
107933 +
107934 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
107935 + bool "Security"
107936 + help
107937 + Choose this option if security is of highest priority for this deployment of
107938 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
107939 + for userland, and freed memory sanitizing will be enabled for this kernel.
107940 + In a worst-case scenario, these features can introduce a 20% performance hit
107941 + (UDEREF on x64 contributing half of this hit).
107942 +
107943 +endchoice
107944 +
107945 +menu "Default Special Groups"
107946 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107947 +
107948 +config GRKERNSEC_PROC_GID
107949 + int "GID exempted from /proc restrictions"
107950 + default 1001
107951 + help
107952 + Setting this GID determines which group will be exempted from
107953 + grsecurity's /proc restrictions, allowing users of the specified
107954 + group to view network statistics and the existence of other users'
107955 + processes on the system. This GID may also be chosen at boot time
107956 + via "grsec_proc_gid=" on the kernel commandline.
107957 +
107958 +config GRKERNSEC_TPE_UNTRUSTED_GID
107959 + int "GID for TPE-untrusted users"
107960 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
107961 + default 1005
107962 + help
107963 + Setting this GID determines which group untrusted users should
107964 + be added to. These users will be placed under grsecurity's Trusted Path
107965 + Execution mechanism, preventing them from executing their own binaries.
107966 + The users will only be able to execute binaries in directories owned and
107967 + writable only by the root user. If the sysctl option is enabled, a sysctl
107968 + option with name "tpe_gid" is created.
107969 +
107970 +config GRKERNSEC_TPE_TRUSTED_GID
107971 + int "GID for TPE-trusted users"
107972 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
107973 + default 1005
107974 + help
107975 + Setting this GID determines what group TPE restrictions will be
107976 + *disabled* for. If the sysctl option is enabled, a sysctl option
107977 + with name "tpe_gid" is created.
107978 +
107979 +config GRKERNSEC_SYMLINKOWN_GID
107980 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
107981 + depends on GRKERNSEC_CONFIG_SERVER
107982 + default 1006
107983 + help
107984 + Setting this GID determines what group kernel-enforced
107985 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
107986 + is enabled, a sysctl option with name "symlinkown_gid" is created.
107987 +
107988 +
107989 +endmenu
107990 +
107991 +menu "Customize Configuration"
107992 +depends on GRKERNSEC
107993 +
107994 +menu "PaX"
107995 +
107996 +config PAX
107997 + bool "Enable various PaX features"
107998 + default y if GRKERNSEC_CONFIG_AUTO
107999 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108000 + help
108001 + This allows you to enable various PaX features. PaX adds
108002 + intrusion prevention mechanisms to the kernel that reduce
108003 + the risks posed by exploitable memory corruption bugs.
108004 +
108005 +menu "PaX Control"
108006 + depends on PAX
108007 +
108008 +config PAX_SOFTMODE
108009 + bool 'Support soft mode'
108010 + help
108011 + Enabling this option will allow you to run PaX in soft mode, that
108012 + is, PaX features will not be enforced by default, only on executables
108013 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108014 + support as they are the only way to mark executables for soft mode use.
108015 +
108016 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108017 + line option on boot. Furthermore you can control various PaX features
108018 + at runtime via the entries in /proc/sys/kernel/pax.
108019 +
108020 +config PAX_EI_PAX
108021 + bool 'Use legacy ELF header marking'
108022 + default y if GRKERNSEC_CONFIG_AUTO
108023 + help
108024 + Enabling this option will allow you to control PaX features on
108025 + a per executable basis via the 'chpax' utility available at
108026 + http://pax.grsecurity.net/. The control flags will be read from
108027 + an otherwise reserved part of the ELF header. This marking has
108028 + numerous drawbacks (no support for soft-mode, toolchain does not
108029 + know about the non-standard use of the ELF header) therefore it
108030 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108031 + support.
108032 +
108033 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108034 + support as well, they will override the legacy EI_PAX marks.
108035 +
108036 + If you enable none of the marking options then all applications
108037 + will run with PaX enabled on them by default.
108038 +
108039 +config PAX_PT_PAX_FLAGS
108040 + bool 'Use ELF program header marking'
108041 + default y if GRKERNSEC_CONFIG_AUTO
108042 + help
108043 + Enabling this option will allow you to control PaX features on
108044 + a per executable basis via the 'paxctl' utility available at
108045 + http://pax.grsecurity.net/. The control flags will be read from
108046 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108047 + has the benefits of supporting both soft mode and being fully
108048 + integrated into the toolchain (the binutils patch is available
108049 + from http://pax.grsecurity.net).
108050 +
108051 + Note that if you enable the legacy EI_PAX marking support as well,
108052 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108053 +
108054 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108055 + must make sure that the marks are the same if a binary has both marks.
108056 +
108057 + If you enable none of the marking options then all applications
108058 + will run with PaX enabled on them by default.
108059 +
108060 +config PAX_XATTR_PAX_FLAGS
108061 + bool 'Use filesystem extended attributes marking'
108062 + default y if GRKERNSEC_CONFIG_AUTO
108063 + select CIFS_XATTR if CIFS
108064 + select F2FS_FS_XATTR if F2FS_FS
108065 + select EXT2_FS_XATTR if EXT2_FS
108066 + select EXT3_FS_XATTR if EXT3_FS
108067 + select JFFS2_FS_XATTR if JFFS2_FS
108068 + select REISERFS_FS_XATTR if REISERFS_FS
108069 + select SQUASHFS_XATTR if SQUASHFS
108070 + select TMPFS_XATTR if TMPFS
108071 + help
108072 + Enabling this option will allow you to control PaX features on
108073 + a per executable basis via the 'setfattr' utility. The control
108074 + flags will be read from the user.pax.flags extended attribute of
108075 + the file. This marking has the benefit of supporting binary-only
108076 + applications that self-check themselves (e.g., skype) and would
108077 + not tolerate chpax/paxctl changes. The main drawback is that
108078 + extended attributes are not supported by some filesystems (e.g.,
108079 + isofs, udf, vfat) so copying files through such filesystems will
108080 + lose the extended attributes and these PaX markings.
108081 +
108082 + Note that if you enable the legacy EI_PAX marking support as well,
108083 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108084 +
108085 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108086 + must make sure that the marks are the same if a binary has both marks.
108087 +
108088 + If you enable none of the marking options then all applications
108089 + will run with PaX enabled on them by default.
108090 +
108091 +choice
108092 + prompt 'MAC system integration'
108093 + default PAX_HAVE_ACL_FLAGS
108094 + help
108095 + Mandatory Access Control systems have the option of controlling
108096 + PaX flags on a per executable basis, choose the method supported
108097 + by your particular system.
108098 +
108099 + - "none": if your MAC system does not interact with PaX,
108100 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108101 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108102 +
108103 + NOTE: this option is for developers/integrators only.
108104 +
108105 + config PAX_NO_ACL_FLAGS
108106 + bool 'none'
108107 +
108108 + config PAX_HAVE_ACL_FLAGS
108109 + bool 'direct'
108110 +
108111 + config PAX_HOOK_ACL_FLAGS
108112 + bool 'hook'
108113 +endchoice
108114 +
108115 +endmenu
108116 +
108117 +menu "Non-executable pages"
108118 + depends on PAX
108119 +
108120 +config PAX_NOEXEC
108121 + bool "Enforce non-executable pages"
108122 + default y if GRKERNSEC_CONFIG_AUTO
108123 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108124 + help
108125 + By design some architectures do not allow for protecting memory
108126 + pages against execution or even if they do, Linux does not make
108127 + use of this feature. In practice this means that if a page is
108128 + readable (such as the stack or heap) it is also executable.
108129 +
108130 + There is a well known exploit technique that makes use of this
108131 + fact and a common programming mistake where an attacker can
108132 + introduce code of his choice somewhere in the attacked program's
108133 + memory (typically the stack or the heap) and then execute it.
108134 +
108135 + If the attacked program was running with different (typically
108136 + higher) privileges than that of the attacker, then he can elevate
108137 + his own privilege level (e.g. get a root shell, write to files for
108138 + which he does not have write access to, etc).
108139 +
108140 + Enabling this option will let you choose from various features
108141 + that prevent the injection and execution of 'foreign' code in
108142 + a program.
108143 +
108144 + This will also break programs that rely on the old behaviour and
108145 + expect that dynamically allocated memory via the malloc() family
108146 + of functions is executable (which it is not). Notable examples
108147 + are the XFree86 4.x server, the java runtime and wine.
108148 +
108149 +config PAX_PAGEEXEC
108150 + bool "Paging based non-executable pages"
108151 + default y if GRKERNSEC_CONFIG_AUTO
108152 + 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)
108153 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108154 + help
108155 + This implementation is based on the paging feature of the CPU.
108156 + On i386 without hardware non-executable bit support there is a
108157 + variable but usually low performance impact, however on Intel's
108158 + P4 core based CPUs it is very high so you should not enable this
108159 + for kernels meant to be used on such CPUs.
108160 +
108161 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108162 + with hardware non-executable bit support there is no performance
108163 + impact, on ppc the impact is negligible.
108164 +
108165 + Note that several architectures require various emulations due to
108166 + badly designed userland ABIs, this will cause a performance impact
108167 + but will disappear as soon as userland is fixed. For example, ppc
108168 + userland MUST have been built with secure-plt by a recent toolchain.
108169 +
108170 +config PAX_SEGMEXEC
108171 + bool "Segmentation based non-executable pages"
108172 + default y if GRKERNSEC_CONFIG_AUTO
108173 + depends on PAX_NOEXEC && X86_32
108174 + help
108175 + This implementation is based on the segmentation feature of the
108176 + CPU and has a very small performance impact, however applications
108177 + will be limited to a 1.5 GB address space instead of the normal
108178 + 3 GB.
108179 +
108180 +config PAX_EMUTRAMP
108181 + bool "Emulate trampolines"
108182 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108183 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108184 + help
108185 + There are some programs and libraries that for one reason or
108186 + another attempt to execute special small code snippets from
108187 + non-executable memory pages. Most notable examples are the
108188 + signal handler return code generated by the kernel itself and
108189 + the GCC trampolines.
108190 +
108191 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108192 + such programs will no longer work under your kernel.
108193 +
108194 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108195 + utilities to enable trampoline emulation for the affected programs
108196 + yet still have the protection provided by the non-executable pages.
108197 +
108198 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108199 + your system will not even boot.
108200 +
108201 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108202 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108203 + for the affected files.
108204 +
108205 + NOTE: enabling this feature *may* open up a loophole in the
108206 + protection provided by non-executable pages that an attacker
108207 + could abuse. Therefore the best solution is to not have any
108208 + files on your system that would require this option. This can
108209 + be achieved by not using libc5 (which relies on the kernel
108210 + signal handler return code) and not using or rewriting programs
108211 + that make use of the nested function implementation of GCC.
108212 + Skilled users can just fix GCC itself so that it implements
108213 + nested function calls in a way that does not interfere with PaX.
108214 +
108215 +config PAX_EMUSIGRT
108216 + bool "Automatically emulate sigreturn trampolines"
108217 + depends on PAX_EMUTRAMP && PARISC
108218 + default y
108219 + help
108220 + Enabling this option will have the kernel automatically detect
108221 + and emulate signal return trampolines executing on the stack
108222 + that would otherwise lead to task termination.
108223 +
108224 + This solution is intended as a temporary one for users with
108225 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108226 + Modula-3 runtime, etc) or executables linked to such, basically
108227 + everything that does not specify its own SA_RESTORER function in
108228 + normal executable memory like glibc 2.1+ does.
108229 +
108230 + On parisc you MUST enable this option, otherwise your system will
108231 + not even boot.
108232 +
108233 + NOTE: this feature cannot be disabled on a per executable basis
108234 + and since it *does* open up a loophole in the protection provided
108235 + by non-executable pages, the best solution is to not have any
108236 + files on your system that would require this option.
108237 +
108238 +config PAX_MPROTECT
108239 + bool "Restrict mprotect()"
108240 + default y if GRKERNSEC_CONFIG_AUTO
108241 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108242 + help
108243 + Enabling this option will prevent programs from
108244 + - changing the executable status of memory pages that were
108245 + not originally created as executable,
108246 + - making read-only executable pages writable again,
108247 + - creating executable pages from anonymous memory,
108248 + - making read-only-after-relocations (RELRO) data pages writable again.
108249 +
108250 + You should say Y here to complete the protection provided by
108251 + the enforcement of non-executable pages.
108252 +
108253 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108254 + this feature on a per file basis.
108255 +
108256 +config PAX_MPROTECT_COMPAT
108257 + bool "Use legacy/compat protection demoting (read help)"
108258 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108259 + depends on PAX_MPROTECT
108260 + help
108261 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108262 + by sending the proper error code to the application. For some broken
108263 + userland, this can cause problems with Python or other applications. The
108264 + current implementation however allows for applications like clamav to
108265 + detect if JIT compilation/execution is allowed and to fall back gracefully
108266 + to an interpreter-based mode if it does not. While we encourage everyone
108267 + to use the current implementation as-is and push upstream to fix broken
108268 + userland (note that the RWX logging option can assist with this), in some
108269 + environments this may not be possible. Having to disable MPROTECT
108270 + completely on certain binaries reduces the security benefit of PaX,
108271 + so this option is provided for those environments to revert to the old
108272 + behavior.
108273 +
108274 +config PAX_ELFRELOCS
108275 + bool "Allow ELF text relocations (read help)"
108276 + depends on PAX_MPROTECT
108277 + default n
108278 + help
108279 + Non-executable pages and mprotect() restrictions are effective
108280 + in preventing the introduction of new executable code into an
108281 + attacked task's address space. There remain only two venues
108282 + for this kind of attack: if the attacker can execute already
108283 + existing code in the attacked task then he can either have it
108284 + create and mmap() a file containing his code or have it mmap()
108285 + an already existing ELF library that does not have position
108286 + independent code in it and use mprotect() on it to make it
108287 + writable and copy his code there. While protecting against
108288 + the former approach is beyond PaX, the latter can be prevented
108289 + by having only PIC ELF libraries on one's system (which do not
108290 + need to relocate their code). If you are sure this is your case,
108291 + as is the case with all modern Linux distributions, then leave
108292 + this option disabled. You should say 'n' here.
108293 +
108294 +config PAX_ETEXECRELOCS
108295 + bool "Allow ELF ET_EXEC text relocations"
108296 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108297 + select PAX_ELFRELOCS
108298 + default y
108299 + help
108300 + On some architectures there are incorrectly created applications
108301 + that require text relocations and would not work without enabling
108302 + this option. If you are an alpha, ia64 or parisc user, you should
108303 + enable this option and disable it once you have made sure that
108304 + none of your applications need it.
108305 +
108306 +config PAX_EMUPLT
108307 + bool "Automatically emulate ELF PLT"
108308 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108309 + default y
108310 + help
108311 + Enabling this option will have the kernel automatically detect
108312 + and emulate the Procedure Linkage Table entries in ELF files.
108313 + On some architectures such entries are in writable memory, and
108314 + become non-executable leading to task termination. Therefore
108315 + it is mandatory that you enable this option on alpha, parisc,
108316 + sparc and sparc64, otherwise your system would not even boot.
108317 +
108318 + NOTE: this feature *does* open up a loophole in the protection
108319 + provided by the non-executable pages, therefore the proper
108320 + solution is to modify the toolchain to produce a PLT that does
108321 + not need to be writable.
108322 +
108323 +config PAX_DLRESOLVE
108324 + bool 'Emulate old glibc resolver stub'
108325 + depends on PAX_EMUPLT && SPARC
108326 + default n
108327 + help
108328 + This option is needed if userland has an old glibc (before 2.4)
108329 + that puts a 'save' instruction into the runtime generated resolver
108330 + stub that needs special emulation.
108331 +
108332 +config PAX_KERNEXEC
108333 + bool "Enforce non-executable kernel pages"
108334 + 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))
108335 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108336 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108337 + select PAX_KERNEXEC_PLUGIN if X86_64
108338 + help
108339 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108340 + that is, enabling this option will make it harder to inject
108341 + and execute 'foreign' code in kernel memory itself.
108342 +
108343 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108344 + the kernel command-line will result in an RWX physical map.
108345 +
108346 + Likewise, the EFI runtime services are necessarily mapped as
108347 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108348 + is recommended that you boot with "noefi" on the kernel
108349 + command-line if possible to eliminate the mapping.
108350 +
108351 +choice
108352 + prompt "Return Address Instrumentation Method"
108353 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108354 + depends on PAX_KERNEXEC_PLUGIN
108355 + help
108356 + Select the method used to instrument function pointer dereferences.
108357 + Note that binary modules cannot be instrumented by this approach.
108358 +
108359 + Note that the implementation requires a gcc with plugin support,
108360 + i.e., gcc 4.5 or newer. You may need to install the supporting
108361 + headers explicitly in addition to the normal gcc package.
108362 +
108363 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108364 + bool "bts"
108365 + help
108366 + This method is compatible with binary only modules but has
108367 + a higher runtime overhead.
108368 +
108369 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108370 + bool "or"
108371 + depends on !PARAVIRT
108372 + help
108373 + This method is incompatible with binary only modules but has
108374 + a lower runtime overhead.
108375 +endchoice
108376 +
108377 +config PAX_KERNEXEC_PLUGIN_METHOD
108378 + string
108379 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108380 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108381 + default ""
108382 +
108383 +config PAX_KERNEXEC_MODULE_TEXT
108384 + int "Minimum amount of memory reserved for module code"
108385 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108386 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108387 + depends on PAX_KERNEXEC && X86_32
108388 + help
108389 + Due to implementation details the kernel must reserve a fixed
108390 + amount of memory for runtime allocated code (such as modules)
108391 + at compile time that cannot be changed at runtime. Here you
108392 + can specify the minimum amount in MB that will be reserved.
108393 + Due to the same implementation details this size will always
108394 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108395 + the actually available memory for runtime allocated code will
108396 + usually be more than this minimum.
108397 +
108398 + The default 4 MB should be enough for most users but if you have
108399 + an excessive number of modules (e.g., most distribution configs
108400 + compile many drivers as modules) or use huge modules such as
108401 + nvidia's kernel driver, you will need to adjust this amount.
108402 + A good rule of thumb is to look at your currently loaded kernel
108403 + modules and add up their sizes.
108404 +
108405 +endmenu
108406 +
108407 +menu "Address Space Layout Randomization"
108408 + depends on PAX
108409 +
108410 +config PAX_ASLR
108411 + bool "Address Space Layout Randomization"
108412 + default y if GRKERNSEC_CONFIG_AUTO
108413 + help
108414 + Many if not most exploit techniques rely on the knowledge of
108415 + certain addresses in the attacked program. The following options
108416 + will allow the kernel to apply a certain amount of randomization
108417 + to specific parts of the program thereby forcing an attacker to
108418 + guess them in most cases. Any failed guess will most likely crash
108419 + the attacked program which allows the kernel to detect such attempts
108420 + and react on them. PaX itself provides no reaction mechanisms,
108421 + instead it is strongly encouraged that you make use of grsecurity's
108422 + (http://www.grsecurity.net/) built-in crash detection features or
108423 + develop one yourself.
108424 +
108425 + By saying Y here you can choose to randomize the following areas:
108426 + - top of the task's kernel stack
108427 + - top of the task's userland stack
108428 + - base address for mmap() requests that do not specify one
108429 + (this includes all libraries)
108430 + - base address of the main executable
108431 +
108432 + It is strongly recommended to say Y here as address space layout
108433 + randomization has negligible impact on performance yet it provides
108434 + a very effective protection.
108435 +
108436 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108437 + this feature on a per file basis.
108438 +
108439 +config PAX_RANDKSTACK
108440 + bool "Randomize kernel stack base"
108441 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108442 + depends on X86_TSC && X86
108443 + help
108444 + By saying Y here the kernel will randomize every task's kernel
108445 + stack on every system call. This will not only force an attacker
108446 + to guess it but also prevent him from making use of possible
108447 + leaked information about it.
108448 +
108449 + Since the kernel stack is a rather scarce resource, randomization
108450 + may cause unexpected stack overflows, therefore you should very
108451 + carefully test your system. Note that once enabled in the kernel
108452 + configuration, this feature cannot be disabled on a per file basis.
108453 +
108454 +config PAX_RANDUSTACK
108455 + bool
108456 +
108457 +config PAX_RANDMMAP
108458 + bool "Randomize user stack and mmap() bases"
108459 + default y if GRKERNSEC_CONFIG_AUTO
108460 + depends on PAX_ASLR
108461 + select PAX_RANDUSTACK
108462 + help
108463 + By saying Y here the kernel will randomize every task's userland
108464 + stack and use a randomized base address for mmap() requests that
108465 + do not specify one themselves.
108466 +
108467 + The stack randomization is done in two steps where the second
108468 + one may apply a big amount of shift to the top of the stack and
108469 + cause problems for programs that want to use lots of memory (more
108470 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108471 +
108472 + As a result of mmap randomization all dynamically loaded libraries
108473 + will appear at random addresses and therefore be harder to exploit
108474 + by a technique where an attacker attempts to execute library code
108475 + for his purposes (e.g. spawn a shell from an exploited program that
108476 + is running at an elevated privilege level).
108477 +
108478 + Furthermore, if a program is relinked as a dynamic ELF file, its
108479 + base address will be randomized as well, completing the full
108480 + randomization of the address space layout. Attacking such programs
108481 + becomes a guess game. You can find an example of doing this at
108482 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108483 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108484 +
108485 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108486 + feature on a per file basis.
108487 +
108488 +endmenu
108489 +
108490 +menu "Miscellaneous hardening features"
108491 +
108492 +config PAX_MEMORY_SANITIZE
108493 + bool "Sanitize all freed memory"
108494 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108495 + help
108496 + By saying Y here the kernel will erase memory pages and slab objects
108497 + as soon as they are freed. This in turn reduces the lifetime of data
108498 + stored in them, making it less likely that sensitive information such
108499 + as passwords, cryptographic secrets, etc stay in memory for too long.
108500 +
108501 + This is especially useful for programs whose runtime is short, long
108502 + lived processes and the kernel itself benefit from this as long as
108503 + they ensure timely freeing of memory that may hold sensitive
108504 + information.
108505 +
108506 + A nice side effect of the sanitization of slab objects is the
108507 + reduction of possible info leaks caused by padding bytes within the
108508 + leaky structures. Use-after-free bugs for structures containing
108509 + pointers can also be detected as dereferencing the sanitized pointer
108510 + will generate an access violation.
108511 +
108512 + The tradeoff is performance impact, on a single CPU system kernel
108513 + compilation sees a 3% slowdown, other systems and workloads may vary
108514 + and you are advised to test this feature on your expected workload
108515 + before deploying it.
108516 +
108517 + The slab sanitization feature excludes a few slab caches per default
108518 + for performance reasons. To extend the feature to cover those as
108519 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
108520 +
108521 + To reduce the performance penalty by sanitizing pages only, albeit
108522 + limiting the effectiveness of this feature at the same time, slab
108523 + sanitization can be disabled with the kernel command line parameter
108524 + "pax_sanitize_slab=off".
108525 +
108526 + Note that this feature does not protect data stored in live pages,
108527 + e.g., process memory swapped to disk may stay there for a long time.
108528 +
108529 +config PAX_MEMORY_STACKLEAK
108530 + bool "Sanitize kernel stack"
108531 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108532 + depends on X86
108533 + help
108534 + By saying Y here the kernel will erase the kernel stack before it
108535 + returns from a system call. This in turn reduces the information
108536 + that a kernel stack leak bug can reveal.
108537 +
108538 + Note that such a bug can still leak information that was put on
108539 + the stack by the current system call (the one eventually triggering
108540 + the bug) but traces of earlier system calls on the kernel stack
108541 + cannot leak anymore.
108542 +
108543 + The tradeoff is performance impact: on a single CPU system kernel
108544 + compilation sees a 1% slowdown, other systems and workloads may vary
108545 + and you are advised to test this feature on your expected workload
108546 + before deploying it.
108547 +
108548 + Note that the full feature requires a gcc with plugin support,
108549 + i.e., gcc 4.5 or newer. You may need to install the supporting
108550 + headers explicitly in addition to the normal gcc package. Using
108551 + older gcc versions means that functions with large enough stack
108552 + frames may leave uninitialized memory behind that may be exposed
108553 + to a later syscall leaking the stack.
108554 +
108555 +config PAX_MEMORY_STRUCTLEAK
108556 + bool "Forcibly initialize local variables copied to userland"
108557 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108558 + help
108559 + By saying Y here the kernel will zero initialize some local
108560 + variables that are going to be copied to userland. This in
108561 + turn prevents unintended information leakage from the kernel
108562 + stack should later code forget to explicitly set all parts of
108563 + the copied variable.
108564 +
108565 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
108566 + at a much smaller coverage.
108567 +
108568 + Note that the implementation requires a gcc with plugin support,
108569 + i.e., gcc 4.5 or newer. You may need to install the supporting
108570 + headers explicitly in addition to the normal gcc package.
108571 +
108572 +config PAX_MEMORY_UDEREF
108573 + bool "Prevent invalid userland pointer dereference"
108574 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
108575 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
108576 + select PAX_PER_CPU_PGD if X86_64
108577 + help
108578 + By saying Y here the kernel will be prevented from dereferencing
108579 + userland pointers in contexts where the kernel expects only kernel
108580 + pointers. This is both a useful runtime debugging feature and a
108581 + security measure that prevents exploiting a class of kernel bugs.
108582 +
108583 + The tradeoff is that some virtualization solutions may experience
108584 + a huge slowdown and therefore you should not enable this feature
108585 + for kernels meant to run in such environments. Whether a given VM
108586 + solution is affected or not is best determined by simply trying it
108587 + out, the performance impact will be obvious right on boot as this
108588 + mechanism engages from very early on. A good rule of thumb is that
108589 + VMs running on CPUs without hardware virtualization support (i.e.,
108590 + the majority of IA-32 CPUs) will likely experience the slowdown.
108591 +
108592 + On X86_64 the kernel will make use of PCID support when available
108593 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
108594 + or performance impact. Pass pax_weakuderef on the kernel command
108595 + line to choose the latter.
108596 +
108597 +config PAX_REFCOUNT
108598 + bool "Prevent various kernel object reference counter overflows"
108599 + default y if GRKERNSEC_CONFIG_AUTO
108600 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
108601 + help
108602 + By saying Y here the kernel will detect and prevent overflowing
108603 + various (but not all) kinds of object reference counters. Such
108604 + overflows can normally occur due to bugs only and are often, if
108605 + not always, exploitable.
108606 +
108607 + The tradeoff is that data structures protected by an overflowed
108608 + refcount will never be freed and therefore will leak memory. Note
108609 + that this leak also happens even without this protection but in
108610 + that case the overflow can eventually trigger the freeing of the
108611 + data structure while it is still being used elsewhere, resulting
108612 + in the exploitable situation that this feature prevents.
108613 +
108614 + Since this has a negligible performance impact, you should enable
108615 + this feature.
108616 +
108617 +config PAX_CONSTIFY_PLUGIN
108618 + bool "Automatically constify eligible structures"
108619 + default y
108620 + depends on !UML && PAX_KERNEXEC
108621 + help
108622 + By saying Y here the compiler will automatically constify a class
108623 + of types that contain only function pointers. This reduces the
108624 + kernel's attack surface and also produces a better memory layout.
108625 +
108626 + Note that the implementation requires a gcc with plugin support,
108627 + i.e., gcc 4.5 or newer. You may need to install the supporting
108628 + headers explicitly in addition to the normal gcc package.
108629 +
108630 + Note that if some code really has to modify constified variables
108631 + then the source code will have to be patched to allow it. Examples
108632 + can be found in PaX itself (the no_const attribute) and for some
108633 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
108634 +
108635 +config PAX_USERCOPY
108636 + bool "Harden heap object copies between kernel and userland"
108637 + default y if GRKERNSEC_CONFIG_AUTO
108638 + depends on ARM || IA64 || PPC || SPARC || X86
108639 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
108640 + select PAX_USERCOPY_SLABS
108641 + help
108642 + By saying Y here the kernel will enforce the size of heap objects
108643 + when they are copied in either direction between the kernel and
108644 + userland, even if only a part of the heap object is copied.
108645 +
108646 + Specifically, this checking prevents information leaking from the
108647 + kernel heap during kernel to userland copies (if the kernel heap
108648 + object is otherwise fully initialized) and prevents kernel heap
108649 + overflows during userland to kernel copies.
108650 +
108651 + Note that the current implementation provides the strictest bounds
108652 + checks for the SLUB allocator.
108653 +
108654 + Enabling this option also enables per-slab cache protection against
108655 + data in a given cache being copied into/out of via userland
108656 + accessors. Though the whitelist of regions will be reduced over
108657 + time, it notably protects important data structures like task structs.
108658 +
108659 + If frame pointers are enabled on x86, this option will also restrict
108660 + copies into and out of the kernel stack to local variables within a
108661 + single frame.
108662 +
108663 + Since this has a negligible performance impact, you should enable
108664 + this feature.
108665 +
108666 +config PAX_USERCOPY_DEBUG
108667 + bool
108668 + depends on X86 && PAX_USERCOPY
108669 + default n
108670 +
108671 +config PAX_SIZE_OVERFLOW
108672 + bool "Prevent various integer overflows in function size parameters"
108673 + default y if GRKERNSEC_CONFIG_AUTO
108674 + depends on X86
108675 + help
108676 + By saying Y here the kernel recomputes expressions of function
108677 + arguments marked by a size_overflow attribute with double integer
108678 + precision (DImode/TImode for 32/64 bit integer types).
108679 +
108680 + The recomputed argument is checked against TYPE_MAX and an event
108681 + is logged on overflow and the triggering process is killed.
108682 +
108683 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
108684 +
108685 + Note that the implementation requires a gcc with plugin support,
108686 + i.e., gcc 4.5 or newer. You may need to install the supporting
108687 + headers explicitly in addition to the normal gcc package.
108688 +
108689 +config PAX_LATENT_ENTROPY
108690 + bool "Generate some entropy during boot and runtime"
108691 + default y if GRKERNSEC_CONFIG_AUTO
108692 + help
108693 + By saying Y here the kernel will instrument some kernel code to
108694 + extract some entropy from both original and artificially created
108695 + program state. This will help especially embedded systems where
108696 + there is little 'natural' source of entropy normally. The cost
108697 + is some slowdown of the boot process and fork and irq processing.
108698 +
108699 + When pax_extra_latent_entropy is passed on the kernel command line,
108700 + entropy will be extracted from up to the first 4GB of RAM while the
108701 + runtime memory allocator is being initialized. This costs even more
108702 + slowdown of the boot process.
108703 +
108704 + Note that the implementation requires a gcc with plugin support,
108705 + i.e., gcc 4.5 or newer. You may need to install the supporting
108706 + headers explicitly in addition to the normal gcc package.
108707 +
108708 + Note that entropy extracted this way is not cryptographically
108709 + secure!
108710 +
108711 +endmenu
108712 +
108713 +endmenu
108714 +
108715 +source grsecurity/Kconfig
108716 +
108717 +endmenu
108718 +
108719 +endmenu
108720 +
108721 source security/keys/Kconfig
108722
108723 config SECURITY_DMESG_RESTRICT
108724 @@ -103,7 +1071,7 @@ config INTEL_TXT
108725 config LSM_MMAP_MIN_ADDR
108726 int "Low address space for LSM to protect from user allocation"
108727 depends on SECURITY && SECURITY_SELINUX
108728 - default 32768 if ARM || (ARM64 && COMPAT)
108729 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
108730 default 65536
108731 help
108732 This is the portion of low virtual memory which should be protected
108733 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
108734 index fdaa50c..2761dcb 100644
108735 --- a/security/apparmor/file.c
108736 +++ b/security/apparmor/file.c
108737 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
108738 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
108739 struct path *new_dir, struct dentry *new_dentry)
108740 {
108741 - struct path link = { new_dir->mnt, new_dentry };
108742 - struct path target = { new_dir->mnt, old_dentry };
108743 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
108744 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
108745 struct path_cond cond = {
108746 old_dentry->d_inode->i_uid,
108747 old_dentry->d_inode->i_mode
108748 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
108749 index 65ca451..ad6f22d 100644
108750 --- a/security/apparmor/lsm.c
108751 +++ b/security/apparmor/lsm.c
108752 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108753 struct dentry *dentry, u32 mask,
108754 struct path_cond *cond)
108755 {
108756 - struct path path = { dir->mnt, dentry };
108757 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
108758
108759 return common_perm(op, &path, mask, cond);
108760 }
108761 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108762 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
108763 struct dentry *dentry, u32 mask)
108764 {
108765 - struct path path = { mnt, dentry };
108766 + struct path path = { .mnt = mnt, .dentry = dentry };
108767 struct path_cond cond = { dentry->d_inode->i_uid,
108768 dentry->d_inode->i_mode
108769 };
108770 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
108771
108772 profile = aa_current_profile();
108773 if (!unconfined(profile)) {
108774 - struct path old_path = { old_dir->mnt, old_dentry };
108775 - struct path new_path = { new_dir->mnt, new_dentry };
108776 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
108777 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
108778 struct path_cond cond = { old_dentry->d_inode->i_uid,
108779 old_dentry->d_inode->i_mode
108780 };
108781 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
108782 return error;
108783 }
108784
108785 -static struct security_operations apparmor_ops = {
108786 +static struct security_operations apparmor_ops __read_only = {
108787 .name = "apparmor",
108788
108789 .ptrace_access_check = apparmor_ptrace_access_check,
108790 diff --git a/security/commoncap.c b/security/commoncap.c
108791 index bab0611..f9a0ff5 100644
108792 --- a/security/commoncap.c
108793 +++ b/security/commoncap.c
108794 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
108795 return 0;
108796 }
108797
108798 +/* returns:
108799 + 1 for suid privilege
108800 + 2 for sgid privilege
108801 + 3 for fscap privilege
108802 +*/
108803 +int is_privileged_binary(const struct dentry *dentry)
108804 +{
108805 + struct cpu_vfs_cap_data capdata;
108806 + struct inode *inode = dentry->d_inode;
108807 +
108808 + if (!inode || S_ISDIR(inode->i_mode))
108809 + return 0;
108810 +
108811 + if (inode->i_mode & S_ISUID)
108812 + return 1;
108813 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
108814 + return 2;
108815 +
108816 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
108817 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
108818 + return 3;
108819 + }
108820 +
108821 + return 0;
108822 +}
108823 +
108824 /*
108825 * Attempt to get the on-exec apply capability sets for an executable file from
108826 * its xattrs and, if present, apply them to the proposed credentials being
108827 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
108828 const struct cred *cred = current_cred();
108829 kuid_t root_uid = make_kuid(cred->user_ns, 0);
108830
108831 + if (gr_acl_enable_at_secure())
108832 + return 1;
108833 +
108834 if (!uid_eq(cred->uid, root_uid)) {
108835 if (bprm->cap_effective)
108836 return 1;
108837 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
108838 index 8ee997d..24c174b 100644
108839 --- a/security/integrity/ima/ima.h
108840 +++ b/security/integrity/ima/ima.h
108841 @@ -116,8 +116,8 @@ int ima_init_template(void);
108842 extern spinlock_t ima_queue_lock;
108843
108844 struct ima_h_table {
108845 - atomic_long_t len; /* number of stored measurements in the list */
108846 - atomic_long_t violations;
108847 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
108848 + atomic_long_unchecked_t violations;
108849 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
108850 };
108851 extern struct ima_h_table ima_htable;
108852 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
108853 index 8688597..9fa80d2 100644
108854 --- a/security/integrity/ima/ima_api.c
108855 +++ b/security/integrity/ima/ima_api.c
108856 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
108857 int result;
108858
108859 /* can overflow, only indicator */
108860 - atomic_long_inc(&ima_htable.violations);
108861 + atomic_long_inc_unchecked(&ima_htable.violations);
108862
108863 result = ima_alloc_init_template(NULL, file, filename,
108864 NULL, 0, &entry);
108865 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
108866 index da92fcc..8a5d390 100644
108867 --- a/security/integrity/ima/ima_fs.c
108868 +++ b/security/integrity/ima/ima_fs.c
108869 @@ -28,12 +28,12 @@
108870 static int valid_policy = 1;
108871 #define TMPBUFLEN 12
108872 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
108873 - loff_t *ppos, atomic_long_t *val)
108874 + loff_t *ppos, atomic_long_unchecked_t *val)
108875 {
108876 char tmpbuf[TMPBUFLEN];
108877 ssize_t len;
108878
108879 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
108880 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
108881 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
108882 }
108883
108884 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
108885 index 552705d..9920f4fb 100644
108886 --- a/security/integrity/ima/ima_queue.c
108887 +++ b/security/integrity/ima/ima_queue.c
108888 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
108889 INIT_LIST_HEAD(&qe->later);
108890 list_add_tail_rcu(&qe->later, &ima_measurements);
108891
108892 - atomic_long_inc(&ima_htable.len);
108893 + atomic_long_inc_unchecked(&ima_htable.len);
108894 key = ima_hash_key(entry->digest);
108895 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
108896 return 0;
108897 diff --git a/security/keys/compat.c b/security/keys/compat.c
108898 index 3478965..ec7bb9e 100644
108899 --- a/security/keys/compat.c
108900 +++ b/security/keys/compat.c
108901 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
108902 if (ret == 0)
108903 goto no_payload_free;
108904
108905 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
108906 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
108907 err:
108908 if (iov != iovstack)
108909 kfree(iov);
108910 diff --git a/security/keys/internal.h b/security/keys/internal.h
108911 index 200e378..cdc74b5 100644
108912 --- a/security/keys/internal.h
108913 +++ b/security/keys/internal.h
108914 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
108915 extern long keyctl_invalidate_key(key_serial_t);
108916
108917 extern long keyctl_instantiate_key_common(key_serial_t,
108918 - const struct iovec *,
108919 + const struct iovec __user *,
108920 unsigned, size_t, key_serial_t);
108921 #ifdef CONFIG_PERSISTENT_KEYRINGS
108922 extern long keyctl_get_persistent(uid_t, key_serial_t);
108923 diff --git a/security/keys/key.c b/security/keys/key.c
108924 index e17ba6a..2cc04a6 100644
108925 --- a/security/keys/key.c
108926 +++ b/security/keys/key.c
108927 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
108928
108929 atomic_set(&key->usage, 1);
108930 init_rwsem(&key->sem);
108931 - lockdep_set_class(&key->sem, &type->lock_class);
108932 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
108933 key->index_key.type = type;
108934 key->user = user;
108935 key->quotalen = quotalen;
108936 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
108937 struct key_type *p;
108938 int ret;
108939
108940 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
108941 + pax_open_kernel();
108942 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
108943 + pax_close_kernel();
108944
108945 ret = -EEXIST;
108946 down_write(&key_types_sem);
108947 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
108948 }
108949
108950 /* store the type */
108951 - list_add(&ktype->link, &key_types_list);
108952 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
108953
108954 pr_notice("Key type %s registered\n", ktype->name);
108955 ret = 0;
108956 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
108957 void unregister_key_type(struct key_type *ktype)
108958 {
108959 down_write(&key_types_sem);
108960 - list_del_init(&ktype->link);
108961 + pax_list_del_init((struct list_head *)&ktype->link);
108962 downgrade_write(&key_types_sem);
108963 key_gc_keytype(ktype);
108964 pr_notice("Key type %s unregistered\n", ktype->name);
108965 @@ -1127,10 +1129,10 @@ void __init key_init(void)
108966 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
108967
108968 /* add the special key types */
108969 - list_add_tail(&key_type_keyring.link, &key_types_list);
108970 - list_add_tail(&key_type_dead.link, &key_types_list);
108971 - list_add_tail(&key_type_user.link, &key_types_list);
108972 - list_add_tail(&key_type_logon.link, &key_types_list);
108973 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
108974 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
108975 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
108976 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
108977
108978 /* record the root user tracking */
108979 rb_link_node(&root_key_user.node,
108980 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
108981 index 4743d71..170a185 100644
108982 --- a/security/keys/keyctl.c
108983 +++ b/security/keys/keyctl.c
108984 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
108985 /*
108986 * Copy the iovec data from userspace
108987 */
108988 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108989 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
108990 unsigned ioc)
108991 {
108992 for (; ioc > 0; ioc--) {
108993 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108994 * If successful, 0 will be returned.
108995 */
108996 long keyctl_instantiate_key_common(key_serial_t id,
108997 - const struct iovec *payload_iov,
108998 + const struct iovec __user *payload_iov,
108999 unsigned ioc,
109000 size_t plen,
109001 key_serial_t ringid)
109002 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
109003 [0].iov_len = plen
109004 };
109005
109006 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109007 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109008 }
109009
109010 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109011 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109012 if (ret == 0)
109013 goto no_payload_free;
109014
109015 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109016 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109017 err:
109018 if (iov != iovstack)
109019 kfree(iov);
109020 diff --git a/security/min_addr.c b/security/min_addr.c
109021 index f728728..6457a0c 100644
109022 --- a/security/min_addr.c
109023 +++ b/security/min_addr.c
109024 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109025 */
109026 static void update_mmap_min_addr(void)
109027 {
109028 +#ifndef SPARC
109029 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109030 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109031 mmap_min_addr = dac_mmap_min_addr;
109032 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109033 #else
109034 mmap_min_addr = dac_mmap_min_addr;
109035 #endif
109036 +#endif
109037 }
109038
109039 /*
109040 diff --git a/security/security.c b/security/security.c
109041 index 18b35c6..c9fbc92 100644
109042 --- a/security/security.c
109043 +++ b/security/security.c
109044 @@ -33,8 +33,8 @@
109045 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109046 CONFIG_DEFAULT_SECURITY;
109047
109048 -static struct security_operations *security_ops;
109049 -static struct security_operations default_security_ops = {
109050 +struct security_operations *security_ops __read_only;
109051 +struct security_operations default_security_ops __read_only = {
109052 .name = "default",
109053 };
109054
109055 @@ -73,11 +73,6 @@ int __init security_init(void)
109056 return 0;
109057 }
109058
109059 -void reset_security_ops(void)
109060 -{
109061 - security_ops = &default_security_ops;
109062 -}
109063 -
109064 /* Save user chosen LSM */
109065 static int __init choose_lsm(char *str)
109066 {
109067 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109068 index a18f1fa..c9b9fc4 100644
109069 --- a/security/selinux/avc.c
109070 +++ b/security/selinux/avc.c
109071 @@ -59,7 +59,7 @@ struct avc_node {
109072 struct avc_cache {
109073 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109074 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109075 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109076 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109077 atomic_t active_nodes;
109078 u32 latest_notif; /* latest revocation notification */
109079 };
109080 @@ -167,7 +167,7 @@ void __init avc_init(void)
109081 spin_lock_init(&avc_cache.slots_lock[i]);
109082 }
109083 atomic_set(&avc_cache.active_nodes, 0);
109084 - atomic_set(&avc_cache.lru_hint, 0);
109085 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109086
109087 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109088 0, SLAB_PANIC, NULL);
109089 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109090 spinlock_t *lock;
109091
109092 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109093 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109094 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109095 head = &avc_cache.slots[hvalue];
109096 lock = &avc_cache.slots_lock[hvalue];
109097
109098 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109099 index c603b20..8716ec9 100644
109100 --- a/security/selinux/hooks.c
109101 +++ b/security/selinux/hooks.c
109102 @@ -95,8 +95,6 @@
109103 #include "audit.h"
109104 #include "avc_ss.h"
109105
109106 -extern struct security_operations *security_ops;
109107 -
109108 /* SECMARK reference count */
109109 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109110
109111 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109112
109113 #endif
109114
109115 -static struct security_operations selinux_ops = {
109116 +static struct security_operations selinux_ops __read_only = {
109117 .name = "selinux",
109118
109119 .ptrace_access_check = selinux_ptrace_access_check,
109120 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
109121 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109122 static int selinux_disabled;
109123
109124 +extern struct security_operations *security_ops;
109125 +extern struct security_operations default_security_ops;
109126 +
109127 int selinux_disable(void)
109128 {
109129 if (ss_initialized) {
109130 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
109131 selinux_disabled = 1;
109132 selinux_enabled = 0;
109133
109134 - reset_security_ops();
109135 + pax_open_kernel();
109136 + security_ops = &default_security_ops;
109137 + pax_close_kernel();
109138
109139 /* Try to destroy the avc node cache */
109140 avc_disable();
109141 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109142 index 1450f85..a91e0bc 100644
109143 --- a/security/selinux/include/xfrm.h
109144 +++ b/security/selinux/include/xfrm.h
109145 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109146
109147 rtnl_lock();
109148 for_each_net(net) {
109149 - atomic_inc(&net->xfrm.flow_cache_genid);
109150 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109151 rt_genid_bump_all(net);
109152 }
109153 rtnl_unlock();
109154 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109155 index d515ec2..8a4ca71 100644
109156 --- a/security/smack/smack_lsm.c
109157 +++ b/security/smack/smack_lsm.c
109158 @@ -4079,7 +4079,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109159 return 0;
109160 }
109161
109162 -struct security_operations smack_ops = {
109163 +struct security_operations smack_ops __read_only = {
109164 .name = "smack",
109165
109166 .ptrace_access_check = smack_ptrace_access_check,
109167 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109168 index 4003907..13a2b55 100644
109169 --- a/security/tomoyo/file.c
109170 +++ b/security/tomoyo/file.c
109171 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109172 {
109173 struct tomoyo_request_info r;
109174 struct tomoyo_obj_info obj = {
109175 - .path1 = *path,
109176 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109177 };
109178 int error = -ENOMEM;
109179 struct tomoyo_path_info buf;
109180 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109181 struct tomoyo_path_info buf;
109182 struct tomoyo_request_info r;
109183 struct tomoyo_obj_info obj = {
109184 - .path1 = *path,
109185 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109186 };
109187 int idx;
109188
109189 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109190 {
109191 struct tomoyo_request_info r;
109192 struct tomoyo_obj_info obj = {
109193 - .path1 = *path,
109194 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109195 };
109196 int error;
109197 struct tomoyo_path_info buf;
109198 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109199 {
109200 struct tomoyo_request_info r;
109201 struct tomoyo_obj_info obj = {
109202 - .path1 = *path,
109203 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109204 };
109205 int error = -ENOMEM;
109206 struct tomoyo_path_info buf;
109207 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109208 struct tomoyo_path_info buf2;
109209 struct tomoyo_request_info r;
109210 struct tomoyo_obj_info obj = {
109211 - .path1 = *path1,
109212 - .path2 = *path2,
109213 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109214 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109215 };
109216 int idx;
109217
109218 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109219 index 390c646..f2f8db3 100644
109220 --- a/security/tomoyo/mount.c
109221 +++ b/security/tomoyo/mount.c
109222 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109223 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109224 need_dev = -1; /* dev_name is a directory */
109225 } else {
109226 + if (!capable(CAP_SYS_ADMIN)) {
109227 + error = -EPERM;
109228 + goto out;
109229 + }
109230 fstype = get_fs_type(type);
109231 if (!fstype) {
109232 error = -ENODEV;
109233 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109234 index f0b756e..8aa497b 100644
109235 --- a/security/tomoyo/tomoyo.c
109236 +++ b/security/tomoyo/tomoyo.c
109237 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109238 */
109239 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109240 {
109241 - struct path path = { mnt, dentry };
109242 + struct path path = { .mnt = mnt, .dentry = dentry };
109243 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109244 }
109245
109246 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109247 */
109248 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109249 {
109250 - struct path path = { parent->mnt, dentry };
109251 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109252 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109253 }
109254
109255 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109256 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109257 umode_t mode)
109258 {
109259 - struct path path = { parent->mnt, dentry };
109260 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109261 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109262 mode & S_IALLUGO);
109263 }
109264 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109265 */
109266 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109267 {
109268 - struct path path = { parent->mnt, dentry };
109269 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109270 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109271 }
109272
109273 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109274 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109275 const char *old_name)
109276 {
109277 - struct path path = { parent->mnt, dentry };
109278 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109279 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109280 }
109281
109282 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109283 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109284 umode_t mode, unsigned int dev)
109285 {
109286 - struct path path = { parent->mnt, dentry };
109287 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109288 int type = TOMOYO_TYPE_CREATE;
109289 const unsigned int perm = mode & S_IALLUGO;
109290
109291 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109292 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109293 struct dentry *new_dentry)
109294 {
109295 - struct path path1 = { new_dir->mnt, old_dentry };
109296 - struct path path2 = { new_dir->mnt, new_dentry };
109297 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109298 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109299 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109300 }
109301
109302 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109303 struct path *new_parent,
109304 struct dentry *new_dentry)
109305 {
109306 - struct path path1 = { old_parent->mnt, old_dentry };
109307 - struct path path2 = { new_parent->mnt, new_dentry };
109308 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109309 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109310 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109311 }
109312
109313 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109314 */
109315 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109316 {
109317 - struct path path = { mnt, mnt->mnt_root };
109318 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109319 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109320 }
109321
109322 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109323 * tomoyo_security_ops is a "struct security_operations" which is used for
109324 * registering TOMOYO.
109325 */
109326 -static struct security_operations tomoyo_security_ops = {
109327 +static struct security_operations tomoyo_security_ops __read_only = {
109328 .name = "tomoyo",
109329 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109330 .cred_prepare = tomoyo_cred_prepare,
109331 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109332 index 20ef514..4182bed 100644
109333 --- a/security/yama/Kconfig
109334 +++ b/security/yama/Kconfig
109335 @@ -1,6 +1,6 @@
109336 config SECURITY_YAMA
109337 bool "Yama support"
109338 - depends on SECURITY
109339 + depends on SECURITY && !GRKERNSEC
109340 select SECURITYFS
109341 select SECURITY_PATH
109342 default n
109343 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109344 index 13c88fbc..f8c115e 100644
109345 --- a/security/yama/yama_lsm.c
109346 +++ b/security/yama/yama_lsm.c
109347 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109348 }
109349
109350 #ifndef CONFIG_SECURITY_YAMA_STACKED
109351 -static struct security_operations yama_ops = {
109352 +static struct security_operations yama_ops __read_only = {
109353 .name = "yama",
109354
109355 .ptrace_access_check = yama_ptrace_access_check,
109356 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109357 #endif
109358
109359 #ifdef CONFIG_SYSCTL
109360 +static int zero __read_only;
109361 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109362 +
109363 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109364 void __user *buffer, size_t *lenp, loff_t *ppos)
109365 {
109366 - int rc;
109367 + ctl_table_no_const yama_table;
109368
109369 if (write && !capable(CAP_SYS_PTRACE))
109370 return -EPERM;
109371
109372 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109373 - if (rc)
109374 - return rc;
109375 -
109376 + yama_table = *table;
109377 /* Lock the max value if it ever gets set. */
109378 - if (write && *(int *)table->data == *(int *)table->extra2)
109379 - table->extra1 = table->extra2;
109380 -
109381 - return rc;
109382 + if (ptrace_scope == max_scope)
109383 + yama_table.extra1 = &max_scope;
109384 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109385 }
109386
109387 -static int zero;
109388 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109389 -
109390 struct ctl_path yama_sysctl_path[] = {
109391 { .procname = "kernel", },
109392 { .procname = "yama", },
109393 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109394 index 401107b..b9c47c6 100644
109395 --- a/sound/aoa/codecs/onyx.c
109396 +++ b/sound/aoa/codecs/onyx.c
109397 @@ -54,7 +54,7 @@ struct onyx {
109398 spdif_locked:1,
109399 analog_locked:1,
109400 original_mute:2;
109401 - int open_count;
109402 + local_t open_count;
109403 struct codec_info *codec_info;
109404
109405 /* mutex serializes concurrent access to the device
109406 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109407 struct onyx *onyx = cii->codec_data;
109408
109409 mutex_lock(&onyx->mutex);
109410 - onyx->open_count++;
109411 + local_inc(&onyx->open_count);
109412 mutex_unlock(&onyx->mutex);
109413
109414 return 0;
109415 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109416 struct onyx *onyx = cii->codec_data;
109417
109418 mutex_lock(&onyx->mutex);
109419 - onyx->open_count--;
109420 - if (!onyx->open_count)
109421 + if (local_dec_and_test(&onyx->open_count))
109422 onyx->spdif_locked = onyx->analog_locked = 0;
109423 mutex_unlock(&onyx->mutex);
109424
109425 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109426 index ffd2025..df062c9 100644
109427 --- a/sound/aoa/codecs/onyx.h
109428 +++ b/sound/aoa/codecs/onyx.h
109429 @@ -11,6 +11,7 @@
109430 #include <linux/i2c.h>
109431 #include <asm/pmac_low_i2c.h>
109432 #include <asm/prom.h>
109433 +#include <asm/local.h>
109434
109435 /* PCM3052 register definitions */
109436
109437 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109438 index ada69d7..5f65386 100644
109439 --- a/sound/core/oss/pcm_oss.c
109440 +++ b/sound/core/oss/pcm_oss.c
109441 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109442 if (in_kernel) {
109443 mm_segment_t fs;
109444 fs = snd_enter_user();
109445 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109446 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109447 snd_leave_user(fs);
109448 } else {
109449 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109450 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109451 }
109452 if (ret != -EPIPE && ret != -ESTRPIPE)
109453 break;
109454 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109455 if (in_kernel) {
109456 mm_segment_t fs;
109457 fs = snd_enter_user();
109458 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109459 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109460 snd_leave_user(fs);
109461 } else {
109462 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109463 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109464 }
109465 if (ret == -EPIPE) {
109466 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109467 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109468 struct snd_pcm_plugin_channel *channels;
109469 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109470 if (!in_kernel) {
109471 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109472 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109473 return -EFAULT;
109474 buf = runtime->oss.buffer;
109475 }
109476 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109477 }
109478 } else {
109479 tmp = snd_pcm_oss_write2(substream,
109480 - (const char __force *)buf,
109481 + (const char __force_kernel *)buf,
109482 runtime->oss.period_bytes, 0);
109483 if (tmp <= 0)
109484 goto err;
109485 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109486 struct snd_pcm_runtime *runtime = substream->runtime;
109487 snd_pcm_sframes_t frames, frames1;
109488 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
109489 - char __user *final_dst = (char __force __user *)buf;
109490 + char __user *final_dst = (char __force_user *)buf;
109491 if (runtime->oss.plugin_first) {
109492 struct snd_pcm_plugin_channel *channels;
109493 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
109494 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
109495 xfer += tmp;
109496 runtime->oss.buffer_used -= tmp;
109497 } else {
109498 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
109499 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
109500 runtime->oss.period_bytes, 0);
109501 if (tmp <= 0)
109502 goto err;
109503 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
109504 size1);
109505 size1 /= runtime->channels; /* frames */
109506 fs = snd_enter_user();
109507 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
109508 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
109509 snd_leave_user(fs);
109510 }
109511 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
109512 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
109513 index 2d957ba..fda022c 100644
109514 --- a/sound/core/pcm_compat.c
109515 +++ b/sound/core/pcm_compat.c
109516 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
109517 int err;
109518
109519 fs = snd_enter_user();
109520 - err = snd_pcm_delay(substream, &delay);
109521 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
109522 snd_leave_user(fs);
109523 if (err < 0)
109524 return err;
109525 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
109526 index 166d59c..89e3889 100644
109527 --- a/sound/core/pcm_native.c
109528 +++ b/sound/core/pcm_native.c
109529 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
109530 switch (substream->stream) {
109531 case SNDRV_PCM_STREAM_PLAYBACK:
109532 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
109533 - (void __user *)arg);
109534 + (void __force_user *)arg);
109535 break;
109536 case SNDRV_PCM_STREAM_CAPTURE:
109537 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
109538 - (void __user *)arg);
109539 + (void __force_user *)arg);
109540 break;
109541 default:
109542 result = -EINVAL;
109543 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
109544 index 16d4267..fe8b49b 100644
109545 --- a/sound/core/seq/oss/seq_oss.c
109546 +++ b/sound/core/seq/oss/seq_oss.c
109547 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
109548 {
109549 int rc;
109550 static struct snd_seq_dev_ops ops = {
109551 - snd_seq_oss_synth_register,
109552 - snd_seq_oss_synth_unregister,
109553 + .init_device = snd_seq_oss_synth_register,
109554 + .free_device = snd_seq_oss_synth_unregister,
109555 };
109556
109557 snd_seq_autoload_lock();
109558 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
109559 index 91a786a..4c07ed4 100644
109560 --- a/sound/core/seq/seq_device.c
109561 +++ b/sound/core/seq/seq_device.c
109562 @@ -64,7 +64,7 @@ struct ops_list {
109563 int argsize; /* argument size */
109564
109565 /* operators */
109566 - struct snd_seq_dev_ops ops;
109567 + struct snd_seq_dev_ops *ops;
109568
109569 /* registered devices */
109570 struct list_head dev_list; /* list of devices */
109571 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
109572
109573 mutex_lock(&ops->reg_mutex);
109574 /* copy driver operators */
109575 - ops->ops = *entry;
109576 + ops->ops = entry;
109577 ops->driver |= DRIVER_LOADED;
109578 ops->argsize = argsize;
109579
109580 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
109581 dev->name, ops->id, ops->argsize, dev->argsize);
109582 return -EINVAL;
109583 }
109584 - if (ops->ops.init_device(dev) >= 0) {
109585 + if (ops->ops->init_device(dev) >= 0) {
109586 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
109587 ops->num_init_devices++;
109588 } else {
109589 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
109590 dev->name, ops->id, ops->argsize, dev->argsize);
109591 return -EINVAL;
109592 }
109593 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
109594 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
109595 dev->status = SNDRV_SEQ_DEVICE_FREE;
109596 dev->driver_data = NULL;
109597 ops->num_init_devices--;
109598 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
109599 index a1fd77a..69cd659 100644
109600 --- a/sound/core/seq/seq_midi.c
109601 +++ b/sound/core/seq/seq_midi.c
109602 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
109603 static int __init alsa_seq_midi_init(void)
109604 {
109605 static struct snd_seq_dev_ops ops = {
109606 - snd_seq_midisynth_register_port,
109607 - snd_seq_midisynth_unregister_port,
109608 + .init_device = snd_seq_midisynth_register_port,
109609 + .free_device = snd_seq_midisynth_unregister_port,
109610 };
109611 memset(&synths, 0, sizeof(synths));
109612 snd_seq_autoload_lock();
109613 diff --git a/sound/core/sound.c b/sound/core/sound.c
109614 index 38ad1a0..5010a40 100644
109615 --- a/sound/core/sound.c
109616 +++ b/sound/core/sound.c
109617 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
109618 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
109619 default: return;
109620 }
109621 - request_module(str);
109622 + request_module("%s", str);
109623 }
109624
109625 #endif /* modular kernel */
109626 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
109627 index f5fd448..6ae276da 100644
109628 --- a/sound/drivers/mts64.c
109629 +++ b/sound/drivers/mts64.c
109630 @@ -29,6 +29,7 @@
109631 #include <sound/initval.h>
109632 #include <sound/rawmidi.h>
109633 #include <sound/control.h>
109634 +#include <asm/local.h>
109635
109636 #define CARD_NAME "Miditerminal 4140"
109637 #define DRIVER_NAME "MTS64"
109638 @@ -67,7 +68,7 @@ struct mts64 {
109639 struct pardevice *pardev;
109640 int pardev_claimed;
109641
109642 - int open_count;
109643 + local_t open_count;
109644 int current_midi_output_port;
109645 int current_midi_input_port;
109646 u8 mode[MTS64_NUM_INPUT_PORTS];
109647 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109648 {
109649 struct mts64 *mts = substream->rmidi->private_data;
109650
109651 - if (mts->open_count == 0) {
109652 + if (local_read(&mts->open_count) == 0) {
109653 /* We don't need a spinlock here, because this is just called
109654 if the device has not been opened before.
109655 So there aren't any IRQs from the device */
109656 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109657
109658 msleep(50);
109659 }
109660 - ++(mts->open_count);
109661 + local_inc(&mts->open_count);
109662
109663 return 0;
109664 }
109665 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109666 struct mts64 *mts = substream->rmidi->private_data;
109667 unsigned long flags;
109668
109669 - --(mts->open_count);
109670 - if (mts->open_count == 0) {
109671 + if (local_dec_return(&mts->open_count) == 0) {
109672 /* We need the spinlock_irqsave here because we can still
109673 have IRQs at this point */
109674 spin_lock_irqsave(&mts->lock, flags);
109675 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109676
109677 msleep(500);
109678
109679 - } else if (mts->open_count < 0)
109680 - mts->open_count = 0;
109681 + } else if (local_read(&mts->open_count) < 0)
109682 + local_set(&mts->open_count, 0);
109683
109684 return 0;
109685 }
109686 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
109687 index 6839953..7a0f4b9 100644
109688 --- a/sound/drivers/opl3/opl3_seq.c
109689 +++ b/sound/drivers/opl3/opl3_seq.c
109690 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
109691 {
109692 static struct snd_seq_dev_ops ops =
109693 {
109694 - snd_opl3_seq_new_device,
109695 - snd_opl3_seq_delete_device
109696 + .init_device = snd_opl3_seq_new_device,
109697 + .free_device = snd_opl3_seq_delete_device
109698 };
109699
109700 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
109701 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
109702 index b953fb4..1999c01 100644
109703 --- a/sound/drivers/opl4/opl4_lib.c
109704 +++ b/sound/drivers/opl4/opl4_lib.c
109705 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
109706 MODULE_DESCRIPTION("OPL4 driver");
109707 MODULE_LICENSE("GPL");
109708
109709 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
109710 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
109711 {
109712 int timeout = 10;
109713 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
109714 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
109715 index 9919769..d7de36c 100644
109716 --- a/sound/drivers/opl4/opl4_seq.c
109717 +++ b/sound/drivers/opl4/opl4_seq.c
109718 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
109719 static int __init alsa_opl4_synth_init(void)
109720 {
109721 static struct snd_seq_dev_ops ops = {
109722 - snd_opl4_seq_new_device,
109723 - snd_opl4_seq_delete_device
109724 + .init_device = snd_opl4_seq_new_device,
109725 + .free_device = snd_opl4_seq_delete_device
109726 };
109727
109728 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
109729 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
109730 index 78ccfa4..7a0857b 100644
109731 --- a/sound/drivers/portman2x4.c
109732 +++ b/sound/drivers/portman2x4.c
109733 @@ -48,6 +48,7 @@
109734 #include <sound/initval.h>
109735 #include <sound/rawmidi.h>
109736 #include <sound/control.h>
109737 +#include <asm/local.h>
109738
109739 #define CARD_NAME "Portman 2x4"
109740 #define DRIVER_NAME "portman"
109741 @@ -85,7 +86,7 @@ struct portman {
109742 struct pardevice *pardev;
109743 int pardev_claimed;
109744
109745 - int open_count;
109746 + local_t open_count;
109747 int mode[PORTMAN_NUM_INPUT_PORTS];
109748 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
109749 };
109750 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
109751 index 95fc2eaf..ea5d6a7 100644
109752 --- a/sound/firewire/amdtp.c
109753 +++ b/sound/firewire/amdtp.c
109754 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
109755 ptr = s->pcm_buffer_pointer + frames;
109756 if (ptr >= pcm->runtime->buffer_size)
109757 ptr -= pcm->runtime->buffer_size;
109758 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
109759 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
109760
109761 s->pcm_period_pointer += frames;
109762 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
109763 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
109764 */
109765 void amdtp_stream_update(struct amdtp_stream *s)
109766 {
109767 - ACCESS_ONCE(s->source_node_id_field) =
109768 + ACCESS_ONCE_RW(s->source_node_id_field) =
109769 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
109770 }
109771 EXPORT_SYMBOL(amdtp_stream_update);
109772 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
109773 index 4823c08..47a5f7c 100644
109774 --- a/sound/firewire/amdtp.h
109775 +++ b/sound/firewire/amdtp.h
109776 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
109777 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
109778 struct snd_pcm_substream *pcm)
109779 {
109780 - ACCESS_ONCE(s->pcm) = pcm;
109781 + ACCESS_ONCE_RW(s->pcm) = pcm;
109782 }
109783
109784 /**
109785 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
109786 struct snd_rawmidi_substream *midi)
109787 {
109788 if (port < s->midi_ports)
109789 - ACCESS_ONCE(s->midi[port]) = midi;
109790 + ACCESS_ONCE_RW(s->midi[port]) = midi;
109791 }
109792
109793 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
109794 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
109795 index 7ac9443..0ec6274 100644
109796 --- a/sound/firewire/isight.c
109797 +++ b/sound/firewire/isight.c
109798 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
109799 ptr += count;
109800 if (ptr >= runtime->buffer_size)
109801 ptr -= runtime->buffer_size;
109802 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
109803 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
109804
109805 isight->period_counter += count;
109806 if (isight->period_counter >= runtime->period_size) {
109807 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
109808 if (err < 0)
109809 return err;
109810
109811 - ACCESS_ONCE(isight->pcm_active) = true;
109812 + ACCESS_ONCE_RW(isight->pcm_active) = true;
109813
109814 return 0;
109815 }
109816 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
109817 {
109818 struct isight *isight = substream->private_data;
109819
109820 - ACCESS_ONCE(isight->pcm_active) = false;
109821 + ACCESS_ONCE_RW(isight->pcm_active) = false;
109822
109823 mutex_lock(&isight->mutex);
109824 isight_stop_streaming(isight);
109825 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
109826
109827 switch (cmd) {
109828 case SNDRV_PCM_TRIGGER_START:
109829 - ACCESS_ONCE(isight->pcm_running) = true;
109830 + ACCESS_ONCE_RW(isight->pcm_running) = true;
109831 break;
109832 case SNDRV_PCM_TRIGGER_STOP:
109833 - ACCESS_ONCE(isight->pcm_running) = false;
109834 + ACCESS_ONCE_RW(isight->pcm_running) = false;
109835 break;
109836 default:
109837 return -EINVAL;
109838 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
109839 index 2dba848..c682aef 100644
109840 --- a/sound/firewire/scs1x.c
109841 +++ b/sound/firewire/scs1x.c
109842 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
109843 {
109844 struct scs *scs = stream->rmidi->private_data;
109845
109846 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
109847 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
109848 if (up) {
109849 scs->output_idle = false;
109850 tasklet_schedule(&scs->tasklet);
109851 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
109852 {
109853 struct scs *scs = stream->rmidi->private_data;
109854
109855 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
109856 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
109857 }
109858
109859 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
109860 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
109861
109862 snd_card_disconnect(scs->card);
109863
109864 - ACCESS_ONCE(scs->output) = NULL;
109865 - ACCESS_ONCE(scs->input) = NULL;
109866 + ACCESS_ONCE_RW(scs->output) = NULL;
109867 + ACCESS_ONCE_RW(scs->input) = NULL;
109868
109869 wait_event(scs->idle_wait, scs->output_idle);
109870
109871 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
109872 index 4e3fcfb..ab45a9d 100644
109873 --- a/sound/isa/sb/emu8000_synth.c
109874 +++ b/sound/isa/sb/emu8000_synth.c
109875 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
109876 {
109877
109878 static struct snd_seq_dev_ops ops = {
109879 - snd_emu8000_new_device,
109880 - snd_emu8000_delete_device,
109881 + .init_device = snd_emu8000_new_device,
109882 + .free_device = snd_emu8000_delete_device,
109883 };
109884 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
109885 sizeof(struct snd_emu8000*));
109886 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
109887 index 048439a..3be9f6f 100644
109888 --- a/sound/oss/sb_audio.c
109889 +++ b/sound/oss/sb_audio.c
109890 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
109891 buf16 = (signed short *)(localbuf + localoffs);
109892 while (c)
109893 {
109894 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109895 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109896 if (copy_from_user(lbuf8,
109897 userbuf+useroffs + p,
109898 locallen))
109899 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
109900 index a33e8ce..2262303 100644
109901 --- a/sound/oss/swarm_cs4297a.c
109902 +++ b/sound/oss/swarm_cs4297a.c
109903 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
109904 {
109905 struct cs4297a_state *s;
109906 u32 pwr, id;
109907 - mm_segment_t fs;
109908 int rval;
109909 u64 cfg;
109910 int mdio_val;
109911 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
109912 if (!rval) {
109913 char *sb1250_duart_present;
109914
109915 +#if 0
109916 + mm_segment_t fs;
109917 fs = get_fs();
109918 set_fs(KERNEL_DS);
109919 -#if 0
109920 val = SOUND_MASK_LINE;
109921 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
109922 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
109923 val = initvol[i].vol;
109924 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
109925 }
109926 + set_fs(fs);
109927 // cs4297a_write_ac97(s, 0x18, 0x0808);
109928 #else
109929 // cs4297a_write_ac97(s, 0x5e, 0x180);
109930 cs4297a_write_ac97(s, 0x02, 0x0808);
109931 cs4297a_write_ac97(s, 0x18, 0x0808);
109932 #endif
109933 - set_fs(fs);
109934
109935 list_add(&s->list, &cs4297a_devs);
109936
109937 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
109938 index 4c41c90..37f3631 100644
109939 --- a/sound/pci/emu10k1/emu10k1_synth.c
109940 +++ b/sound/pci/emu10k1/emu10k1_synth.c
109941 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
109942 {
109943
109944 static struct snd_seq_dev_ops ops = {
109945 - snd_emu10k1_synth_new_device,
109946 - snd_emu10k1_synth_delete_device,
109947 + .init_device = snd_emu10k1_synth_new_device,
109948 + .free_device = snd_emu10k1_synth_delete_device,
109949 };
109950 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
109951 sizeof(struct snd_emu10k1_synth_arg));
109952 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
109953 index e708368..764dffe 100644
109954 --- a/sound/pci/hda/hda_codec.c
109955 +++ b/sound/pci/hda/hda_codec.c
109956 @@ -968,14 +968,10 @@ find_codec_preset(struct hda_codec *codec)
109957 mutex_unlock(&preset_mutex);
109958
109959 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
109960 - char name[32];
109961 if (!mod_requested)
109962 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
109963 - codec->vendor_id);
109964 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
109965 else
109966 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
109967 - (codec->vendor_id >> 16) & 0xffff);
109968 - request_module(name);
109969 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
109970 mod_requested++;
109971 goto again;
109972 }
109973 @@ -2802,7 +2798,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
109974 /* FIXME: set_fs() hack for obtaining user-space TLV data */
109975 mm_segment_t fs = get_fs();
109976 set_fs(get_ds());
109977 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
109978 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
109979 tlv = _tlv;
109980 set_fs(fs);
109981 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
109982 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
109983 index 4631a23..001ae57 100644
109984 --- a/sound/pci/ymfpci/ymfpci.h
109985 +++ b/sound/pci/ymfpci/ymfpci.h
109986 @@ -358,7 +358,7 @@ struct snd_ymfpci {
109987 spinlock_t reg_lock;
109988 spinlock_t voice_lock;
109989 wait_queue_head_t interrupt_sleep;
109990 - atomic_t interrupt_sleep_count;
109991 + atomic_unchecked_t interrupt_sleep_count;
109992 struct snd_info_entry *proc_entry;
109993 const struct firmware *dsp_microcode;
109994 const struct firmware *controller_microcode;
109995 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
109996 index 81c916a..516f0bf 100644
109997 --- a/sound/pci/ymfpci/ymfpci_main.c
109998 +++ b/sound/pci/ymfpci/ymfpci_main.c
109999 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110000 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110001 break;
110002 }
110003 - if (atomic_read(&chip->interrupt_sleep_count)) {
110004 - atomic_set(&chip->interrupt_sleep_count, 0);
110005 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110006 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110007 wake_up(&chip->interrupt_sleep);
110008 }
110009 __end:
110010 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110011 continue;
110012 init_waitqueue_entry(&wait, current);
110013 add_wait_queue(&chip->interrupt_sleep, &wait);
110014 - atomic_inc(&chip->interrupt_sleep_count);
110015 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110016 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110017 remove_wait_queue(&chip->interrupt_sleep, &wait);
110018 }
110019 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110020 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110021 spin_unlock(&chip->reg_lock);
110022
110023 - if (atomic_read(&chip->interrupt_sleep_count)) {
110024 - atomic_set(&chip->interrupt_sleep_count, 0);
110025 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110026 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110027 wake_up(&chip->interrupt_sleep);
110028 }
110029 }
110030 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110031 spin_lock_init(&chip->reg_lock);
110032 spin_lock_init(&chip->voice_lock);
110033 init_waitqueue_head(&chip->interrupt_sleep);
110034 - atomic_set(&chip->interrupt_sleep_count, 0);
110035 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110036 chip->card = card;
110037 chip->pci = pci;
110038 chip->irq = -1;
110039 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110040 index b60ff56..7307f0f 100644
110041 --- a/sound/soc/soc-core.c
110042 +++ b/sound/soc/soc-core.c
110043 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110044 if (ret)
110045 return ret;
110046
110047 - ops->warm_reset = snd_soc_ac97_warm_reset;
110048 - ops->reset = snd_soc_ac97_reset;
110049 + pax_open_kernel();
110050 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110051 + *(void **)&ops->reset = snd_soc_ac97_reset;
110052 + pax_close_kernel();
110053
110054 snd_ac97_rst_cfg = cfg;
110055 return 0;
110056 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110057 index 7778b8e..3d619fc 100644
110058 --- a/sound/synth/emux/emux_seq.c
110059 +++ b/sound/synth/emux/emux_seq.c
110060 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110061 * MIDI emulation operators
110062 */
110063 static struct snd_midi_op emux_ops = {
110064 - snd_emux_note_on,
110065 - snd_emux_note_off,
110066 - snd_emux_key_press,
110067 - snd_emux_terminate_note,
110068 - snd_emux_control,
110069 - snd_emux_nrpn,
110070 - snd_emux_sysex,
110071 + .note_on = snd_emux_note_on,
110072 + .note_off = snd_emux_note_off,
110073 + .key_press = snd_emux_key_press,
110074 + .note_terminate = snd_emux_terminate_note,
110075 + .control = snd_emux_control,
110076 + .nrpn = snd_emux_nrpn,
110077 + .sysex = snd_emux_sysex,
110078 };
110079
110080
110081 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110082 new file mode 100644
110083 index 0000000..de92ed9
110084 --- /dev/null
110085 +++ b/tools/gcc/.gitignore
110086 @@ -0,0 +1 @@
110087 +randomize_layout_seed.h
110088 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110089 new file mode 100644
110090 index 0000000..7b8921f
110091 --- /dev/null
110092 +++ b/tools/gcc/Makefile
110093 @@ -0,0 +1,52 @@
110094 +#CC := gcc
110095 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110096 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110097 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110098 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110099 +
110100 +ifeq ($(PLUGINCC),$(HOSTCC))
110101 +HOSTLIBS := hostlibs
110102 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110103 +export HOST_EXTRACFLAGS
110104 +else
110105 +HOSTLIBS := hostcxxlibs
110106 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110107 +export HOST_EXTRACXXFLAGS
110108 +endif
110109 +
110110 +export GCCPLUGINS_DIR HOSTLIBS
110111 +
110112 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110113 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110114 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110115 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110116 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110117 +$(HOSTLIBS)-y += colorize_plugin.so
110118 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110119 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110120 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110121 +
110122 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110123 +subdir- += size_overflow_plugin
110124 +
110125 +always := $($(HOSTLIBS)-y)
110126 +
110127 +constify_plugin-objs := constify_plugin.o
110128 +stackleak_plugin-objs := stackleak_plugin.o
110129 +kallocstat_plugin-objs := kallocstat_plugin.o
110130 +kernexec_plugin-objs := kernexec_plugin.o
110131 +checker_plugin-objs := checker_plugin.o
110132 +colorize_plugin-objs := colorize_plugin.o
110133 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110134 +structleak_plugin-objs := structleak_plugin.o
110135 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110136 +
110137 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110138 +
110139 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110140 + cmd_create_randomize_layout_seed = \
110141 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110142 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110143 + $(call if_changed,create_randomize_layout_seed)
110144 +
110145 +targets += randomize_layout_seed.h randomize_layout_hash.h
110146 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110147 new file mode 100644
110148 index 0000000..5452feea
110149 --- /dev/null
110150 +++ b/tools/gcc/checker_plugin.c
110151 @@ -0,0 +1,150 @@
110152 +/*
110153 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110154 + * Licensed under the GPL v2
110155 + *
110156 + * Note: the choice of the license means that the compilation process is
110157 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110158 + * but for the kernel it doesn't matter since it doesn't link against
110159 + * any of the gcc libraries
110160 + *
110161 + * gcc plugin to implement various sparse (source code checker) features
110162 + *
110163 + * TODO:
110164 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110165 + *
110166 + * BUGS:
110167 + * - none known
110168 + */
110169 +
110170 +#include "gcc-common.h"
110171 +
110172 +extern void c_register_addr_space (const char *str, addr_space_t as);
110173 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110174 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110175 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110176 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110177 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110178 +
110179 +int plugin_is_GPL_compatible;
110180 +
110181 +static struct plugin_info checker_plugin_info = {
110182 + .version = "201304082245",
110183 + .help = NULL,
110184 +};
110185 +
110186 +#define ADDR_SPACE_KERNEL 0
110187 +#define ADDR_SPACE_FORCE_KERNEL 1
110188 +#define ADDR_SPACE_USER 2
110189 +#define ADDR_SPACE_FORCE_USER 3
110190 +#define ADDR_SPACE_IOMEM 0
110191 +#define ADDR_SPACE_FORCE_IOMEM 0
110192 +#define ADDR_SPACE_PERCPU 0
110193 +#define ADDR_SPACE_FORCE_PERCPU 0
110194 +#define ADDR_SPACE_RCU 0
110195 +#define ADDR_SPACE_FORCE_RCU 0
110196 +
110197 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110198 +{
110199 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110200 +}
110201 +
110202 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110203 +{
110204 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110205 +}
110206 +
110207 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110208 +{
110209 + return default_addr_space_valid_pointer_mode(mode, as);
110210 +}
110211 +
110212 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110213 +{
110214 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110215 +}
110216 +
110217 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110218 +{
110219 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110220 +}
110221 +
110222 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110223 +{
110224 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110225 + return true;
110226 +
110227 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110228 + return true;
110229 +
110230 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110231 + return true;
110232 +
110233 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110234 + return true;
110235 +
110236 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110237 + return true;
110238 +
110239 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110240 + return true;
110241 +
110242 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110243 + return true;
110244 +
110245 + return subset == superset;
110246 +}
110247 +
110248 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110249 +{
110250 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110251 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110252 +
110253 + return op;
110254 +}
110255 +
110256 +static void register_checker_address_spaces(void *event_data, void *data)
110257 +{
110258 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110259 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110260 + c_register_addr_space("__user", ADDR_SPACE_USER);
110261 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110262 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110263 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110264 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110265 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110266 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110267 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110268 +
110269 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110270 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110271 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110272 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110273 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110274 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110275 + targetm.addr_space.convert = checker_addr_space_convert;
110276 +}
110277 +
110278 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110279 +{
110280 + const char * const plugin_name = plugin_info->base_name;
110281 + const int argc = plugin_info->argc;
110282 + const struct plugin_argument * const argv = plugin_info->argv;
110283 + int i;
110284 +
110285 + if (!plugin_default_version_check(version, &gcc_version)) {
110286 + error(G_("incompatible gcc/plugin versions"));
110287 + return 1;
110288 + }
110289 +
110290 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110291 +
110292 + for (i = 0; i < argc; ++i)
110293 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110294 +
110295 + if (TARGET_64BIT == 0)
110296 + return 0;
110297 +
110298 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110299 +
110300 + return 0;
110301 +}
110302 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110303 new file mode 100644
110304 index 0000000..54461af
110305 --- /dev/null
110306 +++ b/tools/gcc/colorize_plugin.c
110307 @@ -0,0 +1,210 @@
110308 +/*
110309 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110310 + * Licensed under the GPL v2
110311 + *
110312 + * Note: the choice of the license means that the compilation process is
110313 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110314 + * but for the kernel it doesn't matter since it doesn't link against
110315 + * any of the gcc libraries
110316 + *
110317 + * gcc plugin to colorize diagnostic output
110318 + *
110319 + */
110320 +
110321 +#include "gcc-common.h"
110322 +
110323 +int plugin_is_GPL_compatible;
110324 +
110325 +static struct plugin_info colorize_plugin_info = {
110326 + .version = "201404202350",
110327 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110328 +};
110329 +
110330 +#define GREEN "\033[32m\033[K"
110331 +#define LIGHTGREEN "\033[1;32m\033[K"
110332 +#define YELLOW "\033[33m\033[K"
110333 +#define LIGHTYELLOW "\033[1;33m\033[K"
110334 +#define RED "\033[31m\033[K"
110335 +#define LIGHTRED "\033[1;31m\033[K"
110336 +#define BLUE "\033[34m\033[K"
110337 +#define LIGHTBLUE "\033[1;34m\033[K"
110338 +#define BRIGHT "\033[1;m\033[K"
110339 +#define NORMAL "\033[m\033[K"
110340 +
110341 +static diagnostic_starter_fn old_starter;
110342 +static diagnostic_finalizer_fn old_finalizer;
110343 +
110344 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110345 +{
110346 + const char *color;
110347 + char *newprefix;
110348 +
110349 + switch (diagnostic->kind) {
110350 + case DK_NOTE:
110351 + color = LIGHTBLUE;
110352 + break;
110353 +
110354 + case DK_PEDWARN:
110355 + case DK_WARNING:
110356 + color = LIGHTYELLOW;
110357 + break;
110358 +
110359 + case DK_ERROR:
110360 + case DK_FATAL:
110361 + case DK_ICE:
110362 + case DK_PERMERROR:
110363 + case DK_SORRY:
110364 + color = LIGHTRED;
110365 + break;
110366 +
110367 + default:
110368 + color = NORMAL;
110369 + }
110370 +
110371 + old_starter(context, diagnostic);
110372 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110373 + return;
110374 + pp_destroy_prefix(context->printer);
110375 + pp_set_prefix(context->printer, newprefix);
110376 +}
110377 +
110378 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110379 +{
110380 + old_finalizer(context, diagnostic);
110381 +}
110382 +
110383 +static void colorize_arm(void)
110384 +{
110385 + old_starter = diagnostic_starter(global_dc);
110386 + old_finalizer = diagnostic_finalizer(global_dc);
110387 +
110388 + diagnostic_starter(global_dc) = start_colorize;
110389 + diagnostic_finalizer(global_dc) = finalize_colorize;
110390 +}
110391 +
110392 +static unsigned int execute_colorize_rearm(void)
110393 +{
110394 + if (diagnostic_starter(global_dc) == start_colorize)
110395 + return 0;
110396 +
110397 + colorize_arm();
110398 + return 0;
110399 +}
110400 +
110401 +#if BUILDING_GCC_VERSION >= 4009
110402 +static const struct pass_data colorize_rearm_pass_data = {
110403 +#else
110404 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110405 + .pass = {
110406 +#endif
110407 + .type = SIMPLE_IPA_PASS,
110408 + .name = "colorize_rearm",
110409 +#if BUILDING_GCC_VERSION >= 4008
110410 + .optinfo_flags = OPTGROUP_NONE,
110411 +#endif
110412 +#if BUILDING_GCC_VERSION >= 4009
110413 + .has_gate = false,
110414 + .has_execute = true,
110415 +#else
110416 + .gate = NULL,
110417 + .execute = execute_colorize_rearm,
110418 + .sub = NULL,
110419 + .next = NULL,
110420 + .static_pass_number = 0,
110421 +#endif
110422 + .tv_id = TV_NONE,
110423 + .properties_required = 0,
110424 + .properties_provided = 0,
110425 + .properties_destroyed = 0,
110426 + .todo_flags_start = 0,
110427 + .todo_flags_finish = 0
110428 +#if BUILDING_GCC_VERSION < 4009
110429 + }
110430 +#endif
110431 +};
110432 +
110433 +#if BUILDING_GCC_VERSION >= 4009
110434 +namespace {
110435 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110436 +public:
110437 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110438 + unsigned int execute() { return execute_colorize_rearm(); }
110439 +};
110440 +}
110441 +
110442 +static opt_pass *make_colorize_rearm_pass(void)
110443 +{
110444 + return new colorize_rearm_pass();
110445 +}
110446 +#else
110447 +static struct opt_pass *make_colorize_rearm_pass(void)
110448 +{
110449 + return &colorize_rearm_pass.pass;
110450 +}
110451 +#endif
110452 +
110453 +static void colorize_start_unit(void *gcc_data, void *user_data)
110454 +{
110455 + colorize_arm();
110456 +}
110457 +
110458 +static bool should_colorize(void)
110459 +{
110460 +#if BUILDING_GCC_VERSION >= 4009
110461 + return false;
110462 +#else
110463 + char const *t = getenv("TERM");
110464 +
110465 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110466 +#endif
110467 +}
110468 +
110469 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110470 +{
110471 + const char * const plugin_name = plugin_info->base_name;
110472 + const int argc = plugin_info->argc;
110473 + const struct plugin_argument * const argv = plugin_info->argv;
110474 + int i;
110475 + struct register_pass_info colorize_rearm_pass_info;
110476 + bool colorize;
110477 +
110478 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110479 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110480 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110481 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110482 +
110483 + if (!plugin_default_version_check(version, &gcc_version)) {
110484 + error(G_("incompatible gcc/plugin versions"));
110485 + return 1;
110486 + }
110487 +
110488 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
110489 +
110490 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
110491 +
110492 + for (i = 0; i < argc; ++i) {
110493 + if (!strcmp(argv[i].key, "color")) {
110494 + if (!argv[i].value) {
110495 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110496 + continue;
110497 + }
110498 + if (!strcmp(argv[i].value, "always"))
110499 + colorize = true;
110500 + else if (!strcmp(argv[i].value, "never"))
110501 + colorize = false;
110502 + else if (!strcmp(argv[i].value, "auto"))
110503 + colorize = should_colorize();
110504 + else
110505 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
110506 + continue;
110507 + }
110508 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110509 + }
110510 +
110511 + if (colorize) {
110512 + // TODO: parse GCC_COLORS as used by gcc 4.9+
110513 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
110514 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
110515 + }
110516 + return 0;
110517 +}
110518 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
110519 new file mode 100644
110520 index 0000000..82bc5a8
110521 --- /dev/null
110522 +++ b/tools/gcc/constify_plugin.c
110523 @@ -0,0 +1,557 @@
110524 +/*
110525 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
110526 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
110527 + * Licensed under the GPL v2, or (at your option) v3
110528 + *
110529 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
110530 + *
110531 + * Homepage:
110532 + * http://www.grsecurity.net/~ephox/const_plugin/
110533 + *
110534 + * Usage:
110535 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
110536 + * $ gcc -fplugin=constify_plugin.so test.c -O2
110537 + */
110538 +
110539 +#include "gcc-common.h"
110540 +
110541 +// unused C type flag in all versions 4.5-4.9
110542 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
110543 +
110544 +int plugin_is_GPL_compatible;
110545 +
110546 +static struct plugin_info const_plugin_info = {
110547 + .version = "201401270210",
110548 + .help = "no-constify\tturn off constification\n",
110549 +};
110550 +
110551 +typedef struct {
110552 + bool has_fptr_field;
110553 + bool has_writable_field;
110554 + bool has_do_const_field;
110555 + bool has_no_const_field;
110556 +} constify_info;
110557 +
110558 +static const_tree get_field_type(const_tree field)
110559 +{
110560 + return strip_array_types(TREE_TYPE(field));
110561 +}
110562 +
110563 +static bool is_fptr(const_tree field)
110564 +{
110565 + const_tree ptr = get_field_type(field);
110566 +
110567 + if (TREE_CODE(ptr) != POINTER_TYPE)
110568 + return false;
110569 +
110570 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
110571 +}
110572 +
110573 +/*
110574 + * determine whether the given structure type meets the requirements for automatic constification,
110575 + * including the constification attributes on nested structure types
110576 + */
110577 +static void constifiable(const_tree node, constify_info *cinfo)
110578 +{
110579 + const_tree field;
110580 +
110581 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110582 +
110583 + // e.g., pointer to structure fields while still constructing the structure type
110584 + if (TYPE_FIELDS(node) == NULL_TREE)
110585 + return;
110586 +
110587 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110588 + const_tree type = get_field_type(field);
110589 + enum tree_code code = TREE_CODE(type);
110590 +
110591 + if (node == type)
110592 + continue;
110593 +
110594 + if (is_fptr(field))
110595 + cinfo->has_fptr_field = true;
110596 + else if (!TREE_READONLY(field))
110597 + cinfo->has_writable_field = true;
110598 +
110599 + if (code == RECORD_TYPE || code == UNION_TYPE) {
110600 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110601 + cinfo->has_do_const_field = true;
110602 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
110603 + cinfo->has_no_const_field = true;
110604 + else
110605 + constifiable(type, cinfo);
110606 + }
110607 + }
110608 +}
110609 +
110610 +static bool constified(const_tree node)
110611 +{
110612 + constify_info cinfo = {
110613 + .has_fptr_field = false,
110614 + .has_writable_field = false,
110615 + .has_do_const_field = false,
110616 + .has_no_const_field = false
110617 + };
110618 +
110619 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110620 +
110621 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
110622 +// gcc_assert(!TYPE_READONLY(node));
110623 + return false;
110624 + }
110625 +
110626 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
110627 + gcc_assert(TYPE_READONLY(node));
110628 + return true;
110629 + }
110630 +
110631 + constifiable(node, &cinfo);
110632 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
110633 + return false;
110634 +
110635 + return TYPE_READONLY(node);
110636 +}
110637 +
110638 +static void deconstify_tree(tree node);
110639 +
110640 +static void deconstify_type(tree type)
110641 +{
110642 + tree field;
110643 +
110644 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
110645 +
110646 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
110647 + const_tree fieldtype = get_field_type(field);
110648 +
110649 + // special case handling of simple ptr-to-same-array-type members
110650 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
110651 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
110652 +
110653 + if (TREE_TYPE(TREE_TYPE(field)) == type)
110654 + continue;
110655 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
110656 + continue;
110657 + if (!constified(ptrtype))
110658 + continue;
110659 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
110660 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
110661 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
110662 + }
110663 + continue;
110664 + }
110665 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
110666 + continue;
110667 + if (!constified(fieldtype))
110668 + continue;
110669 +
110670 + deconstify_tree(field);
110671 + TREE_READONLY(field) = 0;
110672 + }
110673 + TYPE_READONLY(type) = 0;
110674 + C_TYPE_FIELDS_READONLY(type) = 0;
110675 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110676 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110677 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
110678 + }
110679 +}
110680 +
110681 +static void deconstify_tree(tree node)
110682 +{
110683 + tree old_type, new_type, field;
110684 +
110685 + old_type = TREE_TYPE(node);
110686 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
110687 + node = TREE_TYPE(node) = copy_node(old_type);
110688 + old_type = TREE_TYPE(old_type);
110689 + }
110690 +
110691 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
110692 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
110693 +
110694 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
110695 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
110696 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
110697 + DECL_FIELD_CONTEXT(field) = new_type;
110698 +
110699 + deconstify_type(new_type);
110700 +
110701 + TREE_TYPE(node) = new_type;
110702 +}
110703 +
110704 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110705 +{
110706 + tree type;
110707 + constify_info cinfo = {
110708 + .has_fptr_field = false,
110709 + .has_writable_field = false,
110710 + .has_do_const_field = false,
110711 + .has_no_const_field = false
110712 + };
110713 +
110714 + *no_add_attrs = true;
110715 + if (TREE_CODE(*node) == FUNCTION_DECL) {
110716 + error("%qE attribute does not apply to functions (%qF)", name, *node);
110717 + return NULL_TREE;
110718 + }
110719 +
110720 + if (TREE_CODE(*node) == PARM_DECL) {
110721 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
110722 + return NULL_TREE;
110723 + }
110724 +
110725 + if (TREE_CODE(*node) == VAR_DECL) {
110726 + error("%qE attribute does not apply to variables (%qD)", name, *node);
110727 + return NULL_TREE;
110728 + }
110729 +
110730 + if (TYPE_P(*node)) {
110731 + type = *node;
110732 + } else {
110733 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
110734 + type = TREE_TYPE(*node);
110735 + }
110736 +
110737 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
110738 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
110739 + return NULL_TREE;
110740 + }
110741 +
110742 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
110743 + error("%qE attribute is already applied to the type %qT", name, type);
110744 + return NULL_TREE;
110745 + }
110746 +
110747 + if (TYPE_P(*node)) {
110748 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110749 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
110750 + else
110751 + *no_add_attrs = false;
110752 + return NULL_TREE;
110753 + }
110754 +
110755 + constifiable(type, &cinfo);
110756 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110757 + deconstify_tree(*node);
110758 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
110759 + return NULL_TREE;
110760 + }
110761 +
110762 + error("%qE attribute used on type %qT that is not constified", name, type);
110763 + return NULL_TREE;
110764 +}
110765 +
110766 +static void constify_type(tree type)
110767 +{
110768 + TYPE_READONLY(type) = 1;
110769 + C_TYPE_FIELDS_READONLY(type) = 1;
110770 + TYPE_CONSTIFY_VISITED(type) = 1;
110771 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110772 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
110773 +}
110774 +
110775 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110776 +{
110777 + *no_add_attrs = true;
110778 + if (!TYPE_P(*node)) {
110779 + error("%qE attribute applies to types only (%qD)", name, *node);
110780 + return NULL_TREE;
110781 + }
110782 +
110783 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
110784 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
110785 + return NULL_TREE;
110786 + }
110787 +
110788 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
110789 + error("%qE attribute used on %qT is already applied to the type", name, *node);
110790 + return NULL_TREE;
110791 + }
110792 +
110793 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
110794 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
110795 + return NULL_TREE;
110796 + }
110797 +
110798 + *no_add_attrs = false;
110799 + return NULL_TREE;
110800 +}
110801 +
110802 +static struct attribute_spec no_const_attr = {
110803 + .name = "no_const",
110804 + .min_length = 0,
110805 + .max_length = 0,
110806 + .decl_required = false,
110807 + .type_required = false,
110808 + .function_type_required = false,
110809 + .handler = handle_no_const_attribute,
110810 +#if BUILDING_GCC_VERSION >= 4007
110811 + .affects_type_identity = true
110812 +#endif
110813 +};
110814 +
110815 +static struct attribute_spec do_const_attr = {
110816 + .name = "do_const",
110817 + .min_length = 0,
110818 + .max_length = 0,
110819 + .decl_required = false,
110820 + .type_required = false,
110821 + .function_type_required = false,
110822 + .handler = handle_do_const_attribute,
110823 +#if BUILDING_GCC_VERSION >= 4007
110824 + .affects_type_identity = true
110825 +#endif
110826 +};
110827 +
110828 +static void register_attributes(void *event_data, void *data)
110829 +{
110830 + register_attribute(&no_const_attr);
110831 + register_attribute(&do_const_attr);
110832 +}
110833 +
110834 +static void finish_type(void *event_data, void *data)
110835 +{
110836 + tree type = (tree)event_data;
110837 + constify_info cinfo = {
110838 + .has_fptr_field = false,
110839 + .has_writable_field = false,
110840 + .has_do_const_field = false,
110841 + .has_no_const_field = false
110842 + };
110843 +
110844 + if (type == NULL_TREE || type == error_mark_node)
110845 + return;
110846 +
110847 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
110848 + return;
110849 +
110850 + constifiable(type, &cinfo);
110851 +
110852 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
110853 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
110854 + deconstify_type(type);
110855 + TYPE_CONSTIFY_VISITED(type) = 1;
110856 + } else
110857 + error("'no_const' attribute used on type %qT that is not constified", type);
110858 + return;
110859 + }
110860 +
110861 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110862 + if (!cinfo.has_writable_field) {
110863 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
110864 + return;
110865 + }
110866 + constify_type(type);
110867 + return;
110868 + }
110869 +
110870 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
110871 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110872 + error("'do_const' attribute used on type %qT that is constified", type);
110873 + return;
110874 + }
110875 + constify_type(type);
110876 + return;
110877 + }
110878 +
110879 + deconstify_type(type);
110880 + TYPE_CONSTIFY_VISITED(type) = 1;
110881 +}
110882 +
110883 +static void check_global_variables(void *event_data, void *data)
110884 +{
110885 +#if BUILDING_GCC_VERSION >= 4009
110886 + varpool_node *node;
110887 +#else
110888 + struct varpool_node *node;
110889 +#endif
110890 +
110891 + FOR_EACH_VARIABLE(node) {
110892 + tree var = NODE_DECL(node);
110893 + tree type = TREE_TYPE(var);
110894 +
110895 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110896 + continue;
110897 +
110898 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110899 + continue;
110900 +
110901 + if (!TYPE_CONSTIFY_VISITED(type))
110902 + continue;
110903 +
110904 + if (DECL_EXTERNAL(var))
110905 + continue;
110906 +
110907 + if (DECL_INITIAL(var))
110908 + continue;
110909 +
110910 + // this works around a gcc bug/feature where uninitialized globals
110911 + // are moved into the .bss section regardless of any constification
110912 + DECL_INITIAL(var) = build_constructor(type, NULL);
110913 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
110914 + }
110915 +}
110916 +
110917 +static unsigned int check_local_variables(void)
110918 +{
110919 + unsigned int ret = 0;
110920 + tree var;
110921 +
110922 + unsigned int i;
110923 +
110924 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110925 + tree type = TREE_TYPE(var);
110926 +
110927 + gcc_assert(DECL_P(var));
110928 + if (is_global_var(var))
110929 + continue;
110930 +
110931 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110932 + continue;
110933 +
110934 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110935 + continue;
110936 +
110937 + if (!TYPE_CONSTIFY_VISITED(type))
110938 + continue;
110939 +
110940 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
110941 + ret = 1;
110942 + }
110943 + return ret;
110944 +}
110945 +
110946 +#if BUILDING_GCC_VERSION >= 4009
110947 +static const struct pass_data check_local_variables_pass_data = {
110948 +#else
110949 +static struct gimple_opt_pass check_local_variables_pass = {
110950 + .pass = {
110951 +#endif
110952 + .type = GIMPLE_PASS,
110953 + .name = "check_local_variables",
110954 +#if BUILDING_GCC_VERSION >= 4008
110955 + .optinfo_flags = OPTGROUP_NONE,
110956 +#endif
110957 +#if BUILDING_GCC_VERSION >= 4009
110958 + .has_gate = false,
110959 + .has_execute = true,
110960 +#else
110961 + .gate = NULL,
110962 + .execute = check_local_variables,
110963 + .sub = NULL,
110964 + .next = NULL,
110965 + .static_pass_number = 0,
110966 +#endif
110967 + .tv_id = TV_NONE,
110968 + .properties_required = 0,
110969 + .properties_provided = 0,
110970 + .properties_destroyed = 0,
110971 + .todo_flags_start = 0,
110972 + .todo_flags_finish = 0
110973 +#if BUILDING_GCC_VERSION < 4009
110974 + }
110975 +#endif
110976 +};
110977 +
110978 +#if BUILDING_GCC_VERSION >= 4009
110979 +namespace {
110980 +class check_local_variables_pass : public gimple_opt_pass {
110981 +public:
110982 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
110983 + unsigned int execute() { return check_local_variables(); }
110984 +};
110985 +}
110986 +
110987 +static opt_pass *make_check_local_variables_pass(void)
110988 +{
110989 + return new check_local_variables_pass();
110990 +}
110991 +#else
110992 +static struct opt_pass *make_check_local_variables_pass(void)
110993 +{
110994 + return &check_local_variables_pass.pass;
110995 +}
110996 +#endif
110997 +
110998 +static struct {
110999 + const char *name;
111000 + const char *asm_op;
111001 +} sections[] = {
111002 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111003 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111004 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111005 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111006 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111007 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111008 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111009 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111010 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111011 +};
111012 +
111013 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111014 +
111015 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111016 +{
111017 + size_t i;
111018 +
111019 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111020 + if (!strcmp(sections[i].name, name))
111021 + return 0;
111022 + return old_section_type_flags(decl, name, reloc);
111023 +}
111024 +
111025 +static void constify_start_unit(void *gcc_data, void *user_data)
111026 +{
111027 +// size_t i;
111028 +
111029 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111030 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111031 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111032 +
111033 + old_section_type_flags = targetm.section_type_flags;
111034 + targetm.section_type_flags = constify_section_type_flags;
111035 +}
111036 +
111037 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111038 +{
111039 + const char * const plugin_name = plugin_info->base_name;
111040 + const int argc = plugin_info->argc;
111041 + const struct plugin_argument * const argv = plugin_info->argv;
111042 + int i;
111043 + bool constify = true;
111044 +
111045 + struct register_pass_info check_local_variables_pass_info;
111046 +
111047 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111048 + check_local_variables_pass_info.reference_pass_name = "ssa";
111049 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111050 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111051 +
111052 + if (!plugin_default_version_check(version, &gcc_version)) {
111053 + error(G_("incompatible gcc/plugin versions"));
111054 + return 1;
111055 + }
111056 +
111057 + for (i = 0; i < argc; ++i) {
111058 + if (!(strcmp(argv[i].key, "no-constify"))) {
111059 + constify = false;
111060 + continue;
111061 + }
111062 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111063 + }
111064 +
111065 + if (strcmp(lang_hooks.name, "GNU C")) {
111066 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
111067 + constify = false;
111068 + }
111069 +
111070 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111071 + if (constify) {
111072 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111073 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111074 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111075 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111076 + }
111077 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111078 +
111079 + return 0;
111080 +}
111081 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111082 new file mode 100644
111083 index 0000000..e90c205
111084 --- /dev/null
111085 +++ b/tools/gcc/gcc-common.h
111086 @@ -0,0 +1,295 @@
111087 +#ifndef GCC_COMMON_H_INCLUDED
111088 +#define GCC_COMMON_H_INCLUDED
111089 +
111090 +#include "plugin.h"
111091 +#include "bversion.h"
111092 +#include "plugin-version.h"
111093 +#include "config.h"
111094 +#include "system.h"
111095 +#include "coretypes.h"
111096 +#include "tm.h"
111097 +#include "line-map.h"
111098 +#include "input.h"
111099 +#include "tree.h"
111100 +
111101 +#include "tree-inline.h"
111102 +#include "version.h"
111103 +#include "rtl.h"
111104 +#include "tm_p.h"
111105 +#include "flags.h"
111106 +//#include "insn-attr.h"
111107 +//#include "insn-config.h"
111108 +//#include "insn-flags.h"
111109 +#include "hard-reg-set.h"
111110 +//#include "recog.h"
111111 +#include "output.h"
111112 +#include "except.h"
111113 +#include "function.h"
111114 +#include "toplev.h"
111115 +//#include "expr.h"
111116 +#include "basic-block.h"
111117 +#include "intl.h"
111118 +#include "ggc.h"
111119 +//#include "regs.h"
111120 +#include "timevar.h"
111121 +
111122 +#include "params.h"
111123 +#include "pointer-set.h"
111124 +#include "emit-rtl.h"
111125 +//#include "reload.h"
111126 +//#include "ira.h"
111127 +//#include "dwarf2asm.h"
111128 +#include "debug.h"
111129 +#include "target.h"
111130 +#include "langhooks.h"
111131 +#include "cfgloop.h"
111132 +//#include "hosthooks.h"
111133 +#include "cgraph.h"
111134 +#include "opts.h"
111135 +//#include "coverage.h"
111136 +//#include "value-prof.h"
111137 +
111138 +#if BUILDING_GCC_VERSION >= 4007
111139 +#include "tree-pretty-print.h"
111140 +#include "gimple-pretty-print.h"
111141 +#include "c-tree.h"
111142 +//#include "alloc-pool.h"
111143 +#endif
111144 +
111145 +#if BUILDING_GCC_VERSION <= 4008
111146 +#include "tree-flow.h"
111147 +#else
111148 +#include "tree-cfgcleanup.h"
111149 +#endif
111150 +
111151 +#include "diagnostic.h"
111152 +//#include "tree-diagnostic.h"
111153 +#include "tree-dump.h"
111154 +#include "tree-pass.h"
111155 +//#include "df.h"
111156 +#include "predict.h"
111157 +#include "ipa-utils.h"
111158 +
111159 +#if BUILDING_GCC_VERSION >= 4009
111160 +#include "varasm.h"
111161 +#include "stor-layout.h"
111162 +#include "internal-fn.h"
111163 +#include "gimple-expr.h"
111164 +//#include "diagnostic-color.h"
111165 +#include "context.h"
111166 +#include "tree-ssa-alias.h"
111167 +#include "stringpool.h"
111168 +#include "tree-ssanames.h"
111169 +#include "print-tree.h"
111170 +#include "tree-eh.h"
111171 +#include "stmt.h"
111172 +#endif
111173 +
111174 +#include "gimple.h"
111175 +
111176 +#if BUILDING_GCC_VERSION >= 4009
111177 +#include "tree-ssa-operands.h"
111178 +#include "tree-phinodes.h"
111179 +#include "tree-cfg.h"
111180 +#include "gimple-iterator.h"
111181 +#include "gimple-ssa.h"
111182 +#include "ssa-iterators.h"
111183 +#endif
111184 +
111185 +//#include "lto/lto.h"
111186 +//#include "data-streamer.h"
111187 +//#include "lto-compress.h"
111188 +
111189 +//#include "expr.h" where are you...
111190 +extern rtx emit_move_insn(rtx x, rtx y);
111191 +
111192 +// missing from basic_block.h...
111193 +extern void debug_dominance_info(enum cdi_direction dir);
111194 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111195 +
111196 +#define __unused __attribute__((__unused__))
111197 +
111198 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111199 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111200 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111201 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111202 +
111203 +#if BUILDING_GCC_VERSION == 4005
111204 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111205 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111206 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111207 +#define TODO_rebuild_cgraph_edges 0
111208 +
111209 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111210 +{
111211 + tree fndecl;
111212 +
111213 + if (!is_gimple_call(stmt))
111214 + return false;
111215 + fndecl = gimple_call_fndecl(stmt);
111216 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111217 + return false;
111218 +// print_node(stderr, "pax", fndecl, 4);
111219 + return DECL_FUNCTION_CODE(fndecl) == code;
111220 +}
111221 +
111222 +static inline bool is_simple_builtin(tree decl)
111223 +{
111224 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111225 + return false;
111226 +
111227 + switch (DECL_FUNCTION_CODE(decl)) {
111228 + /* Builtins that expand to constants. */
111229 + case BUILT_IN_CONSTANT_P:
111230 + case BUILT_IN_EXPECT:
111231 + case BUILT_IN_OBJECT_SIZE:
111232 + case BUILT_IN_UNREACHABLE:
111233 + /* Simple register moves or loads from stack. */
111234 + case BUILT_IN_RETURN_ADDRESS:
111235 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111236 + case BUILT_IN_FROB_RETURN_ADDR:
111237 + case BUILT_IN_RETURN:
111238 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111239 + case BUILT_IN_FRAME_ADDRESS:
111240 + case BUILT_IN_VA_END:
111241 + case BUILT_IN_STACK_SAVE:
111242 + case BUILT_IN_STACK_RESTORE:
111243 + /* Exception state returns or moves registers around. */
111244 + case BUILT_IN_EH_FILTER:
111245 + case BUILT_IN_EH_POINTER:
111246 + case BUILT_IN_EH_COPY_VALUES:
111247 + return true;
111248 +
111249 + default:
111250 + return false;
111251 + }
111252 +}
111253 +#endif
111254 +
111255 +#if BUILDING_GCC_VERSION <= 4006
111256 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111257 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111258 +
111259 +// should come from c-tree.h if only it were installed for gcc 4.5...
111260 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111261 +
111262 +#define get_random_seed(noinit) ({ \
111263 + unsigned HOST_WIDE_INT seed; \
111264 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111265 + seed * seed; })
111266 +
111267 +static inline bool gimple_clobber_p(gimple s)
111268 +{
111269 + return false;
111270 +}
111271 +
111272 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111273 +{
111274 + return implicit_built_in_decls[fncode];
111275 +}
111276 +
111277 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111278 +{
111279 + struct cgraph_node *node = cgraph_get_node(decl);
111280 +
111281 + return node ? node : cgraph_node(decl);
111282 +}
111283 +
111284 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111285 +{
111286 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111287 +}
111288 +
111289 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111290 +{
111291 + struct cgraph_node *node;
111292 +
111293 + for (node = cgraph_nodes; node; node = node->next)
111294 + if (cgraph_function_with_gimple_body_p(node))
111295 + return node;
111296 + return NULL;
111297 +}
111298 +
111299 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111300 +{
111301 + for (node = node->next; node; node = node->next)
111302 + if (cgraph_function_with_gimple_body_p(node))
111303 + return node;
111304 + return NULL;
111305 +}
111306 +
111307 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111308 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111309 + (node) = cgraph_next_function_with_gimple_body(node))
111310 +#endif
111311 +
111312 +#if BUILDING_GCC_VERSION == 4006
111313 +extern void debug_gimple_stmt(gimple);
111314 +extern void debug_gimple_seq(gimple_seq);
111315 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111316 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111317 +extern void print_gimple_expr(FILE *, gimple, int, int);
111318 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111319 +#endif
111320 +
111321 +#if BUILDING_GCC_VERSION <= 4007
111322 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111323 +#define PROP_loops 0
111324 +
111325 +static inline int bb_loop_depth(const_basic_block bb)
111326 +{
111327 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111328 +}
111329 +
111330 +static inline bool gimple_store_p(gimple gs)
111331 +{
111332 + tree lhs = gimple_get_lhs(gs);
111333 + return lhs && !is_gimple_reg(lhs);
111334 +}
111335 +#endif
111336 +
111337 +#if BUILDING_GCC_VERSION >= 4007
111338 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111339 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111340 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111341 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111342 +#endif
111343 +
111344 +#if BUILDING_GCC_VERSION <= 4008
111345 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111346 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111347 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111348 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111349 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111350 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111351 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111352 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111353 +
111354 +static inline const char *get_tree_code_name(enum tree_code code)
111355 +{
111356 + gcc_assert(code < MAX_TREE_CODES);
111357 + return tree_code_name[code];
111358 +}
111359 +
111360 +#define ipa_remove_stmt_references(cnode, stmt)
111361 +#endif
111362 +
111363 +#if BUILDING_GCC_VERSION == 4008
111364 +#define NODE_DECL(node) node->symbol.decl
111365 +#else
111366 +#define NODE_DECL(node) node->decl
111367 +#endif
111368 +
111369 +#if BUILDING_GCC_VERSION >= 4008
111370 +#define add_referenced_var(var)
111371 +#define mark_sym_for_renaming(var)
111372 +#define varpool_mark_needed_node(node)
111373 +#define TODO_dump_func 0
111374 +#define TODO_dump_cgraph 0
111375 +#endif
111376 +
111377 +#if BUILDING_GCC_VERSION >= 4009
111378 +#define TODO_ggc_collect 0
111379 +#endif
111380 +
111381 +#endif
111382 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111383 new file mode 100644
111384 index 0000000..7514850
111385 --- /dev/null
111386 +++ b/tools/gcc/gen-random-seed.sh
111387 @@ -0,0 +1,8 @@
111388 +#!/bin/sh
111389 +
111390 +if [ ! -f "$1" ]; then
111391 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111392 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111393 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111394 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111395 +fi
111396 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111397 new file mode 100644
111398 index 0000000..d81c094
111399 --- /dev/null
111400 +++ b/tools/gcc/kallocstat_plugin.c
111401 @@ -0,0 +1,183 @@
111402 +/*
111403 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111404 + * Licensed under the GPL v2
111405 + *
111406 + * Note: the choice of the license means that the compilation process is
111407 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111408 + * but for the kernel it doesn't matter since it doesn't link against
111409 + * any of the gcc libraries
111410 + *
111411 + * gcc plugin to find the distribution of k*alloc sizes
111412 + *
111413 + * TODO:
111414 + *
111415 + * BUGS:
111416 + * - none known
111417 + */
111418 +
111419 +#include "gcc-common.h"
111420 +
111421 +int plugin_is_GPL_compatible;
111422 +
111423 +static struct plugin_info kallocstat_plugin_info = {
111424 + .version = "201401260140",
111425 + .help = NULL
111426 +};
111427 +
111428 +static const char * const kalloc_functions[] = {
111429 + "__kmalloc",
111430 + "kmalloc",
111431 + "kmalloc_large",
111432 + "kmalloc_node",
111433 + "kmalloc_order",
111434 + "kmalloc_order_trace",
111435 + "kmalloc_slab",
111436 + "kzalloc",
111437 + "kzalloc_node",
111438 +};
111439 +
111440 +static bool is_kalloc(const char *fnname)
111441 +{
111442 + size_t i;
111443 +
111444 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111445 + if (!strcmp(fnname, kalloc_functions[i]))
111446 + return true;
111447 + return false;
111448 +}
111449 +
111450 +static unsigned int execute_kallocstat(void)
111451 +{
111452 + basic_block bb;
111453 +
111454 + // 1. loop through BBs and GIMPLE statements
111455 + FOR_EACH_BB_FN(bb, cfun) {
111456 + gimple_stmt_iterator gsi;
111457 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111458 + // gimple match:
111459 + tree fndecl, size;
111460 + gimple stmt;
111461 + const char *fnname;
111462 +
111463 + // is it a call
111464 + stmt = gsi_stmt(gsi);
111465 + if (!is_gimple_call(stmt))
111466 + continue;
111467 + fndecl = gimple_call_fndecl(stmt);
111468 + if (fndecl == NULL_TREE)
111469 + continue;
111470 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111471 + continue;
111472 +
111473 + // is it a call to k*alloc
111474 + fnname = DECL_NAME_POINTER(fndecl);
111475 + if (!is_kalloc(fnname))
111476 + continue;
111477 +
111478 + // is the size arg const or the result of a simple const assignment
111479 + size = gimple_call_arg(stmt, 0);
111480 + while (true) {
111481 + expanded_location xloc;
111482 + size_t size_val;
111483 +
111484 + if (TREE_CONSTANT(size)) {
111485 + xloc = expand_location(gimple_location(stmt));
111486 + if (!xloc.file)
111487 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111488 + size_val = TREE_INT_CST_LOW(size);
111489 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
111490 + break;
111491 + }
111492 +
111493 + if (TREE_CODE(size) != SSA_NAME)
111494 + break;
111495 + stmt = SSA_NAME_DEF_STMT(size);
111496 +//debug_gimple_stmt(stmt);
111497 +//debug_tree(size);
111498 + if (!stmt || !is_gimple_assign(stmt))
111499 + break;
111500 + if (gimple_num_ops(stmt) != 2)
111501 + break;
111502 + size = gimple_assign_rhs1(stmt);
111503 + }
111504 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111505 +//debug_tree(gimple_call_fn(call_stmt));
111506 +//print_node(stderr, "pax", fndecl, 4);
111507 + }
111508 + }
111509 +
111510 + return 0;
111511 +}
111512 +
111513 +#if BUILDING_GCC_VERSION >= 4009
111514 +static const struct pass_data kallocstat_pass_data = {
111515 +#else
111516 +static struct gimple_opt_pass kallocstat_pass = {
111517 + .pass = {
111518 +#endif
111519 + .type = GIMPLE_PASS,
111520 + .name = "kallocstat",
111521 +#if BUILDING_GCC_VERSION >= 4008
111522 + .optinfo_flags = OPTGROUP_NONE,
111523 +#endif
111524 +#if BUILDING_GCC_VERSION >= 4009
111525 + .has_gate = false,
111526 + .has_execute = true,
111527 +#else
111528 + .gate = NULL,
111529 + .execute = execute_kallocstat,
111530 + .sub = NULL,
111531 + .next = NULL,
111532 + .static_pass_number = 0,
111533 +#endif
111534 + .tv_id = TV_NONE,
111535 + .properties_required = 0,
111536 + .properties_provided = 0,
111537 + .properties_destroyed = 0,
111538 + .todo_flags_start = 0,
111539 + .todo_flags_finish = 0
111540 +#if BUILDING_GCC_VERSION < 4009
111541 + }
111542 +#endif
111543 +};
111544 +
111545 +#if BUILDING_GCC_VERSION >= 4009
111546 +namespace {
111547 +class kallocstat_pass : public gimple_opt_pass {
111548 +public:
111549 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
111550 + unsigned int execute() { return execute_kallocstat(); }
111551 +};
111552 +}
111553 +
111554 +static opt_pass *make_kallocstat_pass(void)
111555 +{
111556 + return new kallocstat_pass();
111557 +}
111558 +#else
111559 +static struct opt_pass *make_kallocstat_pass(void)
111560 +{
111561 + return &kallocstat_pass.pass;
111562 +}
111563 +#endif
111564 +
111565 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111566 +{
111567 + const char * const plugin_name = plugin_info->base_name;
111568 + struct register_pass_info kallocstat_pass_info;
111569 +
111570 + kallocstat_pass_info.pass = make_kallocstat_pass();
111571 + kallocstat_pass_info.reference_pass_name = "ssa";
111572 + kallocstat_pass_info.ref_pass_instance_number = 1;
111573 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111574 +
111575 + if (!plugin_default_version_check(version, &gcc_version)) {
111576 + error(G_("incompatible gcc/plugin versions"));
111577 + return 1;
111578 + }
111579 +
111580 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
111581 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
111582 +
111583 + return 0;
111584 +}
111585 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
111586 new file mode 100644
111587 index 0000000..89f256d
111588 --- /dev/null
111589 +++ b/tools/gcc/kernexec_plugin.c
111590 @@ -0,0 +1,522 @@
111591 +/*
111592 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111593 + * Licensed under the GPL v2
111594 + *
111595 + * Note: the choice of the license means that the compilation process is
111596 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111597 + * but for the kernel it doesn't matter since it doesn't link against
111598 + * any of the gcc libraries
111599 + *
111600 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
111601 + *
111602 + * TODO:
111603 + *
111604 + * BUGS:
111605 + * - none known
111606 + */
111607 +
111608 +#include "gcc-common.h"
111609 +
111610 +int plugin_is_GPL_compatible;
111611 +
111612 +static struct plugin_info kernexec_plugin_info = {
111613 + .version = "201401260140",
111614 + .help = "method=[bts|or]\tinstrumentation method\n"
111615 +};
111616 +
111617 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
111618 +static void (*kernexec_instrument_retaddr)(rtx);
111619 +
111620 +/*
111621 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
111622 + */
111623 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
111624 +{
111625 + gimple asm_movabs_stmt;
111626 +
111627 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
111628 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
111629 + gimple_asm_set_volatile(asm_movabs_stmt, true);
111630 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
111631 + update_stmt(asm_movabs_stmt);
111632 +}
111633 +
111634 +/*
111635 + * find all asm() stmts that clobber r12 and add a reload of r12
111636 + */
111637 +static unsigned int execute_kernexec_reload(void)
111638 +{
111639 + basic_block bb;
111640 +
111641 + // 1. loop through BBs and GIMPLE statements
111642 + FOR_EACH_BB_FN(bb, cfun) {
111643 + gimple_stmt_iterator gsi;
111644 +
111645 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111646 + // gimple match: __asm__ ("" : : : "r12");
111647 + gimple asm_stmt;
111648 + size_t nclobbers;
111649 +
111650 + // is it an asm ...
111651 + asm_stmt = gsi_stmt(gsi);
111652 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
111653 + continue;
111654 +
111655 + // ... clobbering r12
111656 + nclobbers = gimple_asm_nclobbers(asm_stmt);
111657 + while (nclobbers--) {
111658 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
111659 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
111660 + continue;
111661 + kernexec_reload_fptr_mask(&gsi);
111662 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
111663 + break;
111664 + }
111665 + }
111666 + }
111667 +
111668 + return 0;
111669 +}
111670 +
111671 +/*
111672 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
111673 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
111674 + */
111675 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
111676 +{
111677 + gimple assign_intptr, assign_new_fptr, call_stmt;
111678 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
111679 +
111680 + call_stmt = gsi_stmt(*gsi);
111681 + old_fptr = gimple_call_fn(call_stmt);
111682 +
111683 + // create temporary unsigned long variable used for bitops and cast fptr to it
111684 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
111685 + add_referenced_var(intptr);
111686 + intptr = make_ssa_name(intptr, NULL);
111687 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
111688 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111689 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111690 + update_stmt(assign_intptr);
111691 +
111692 + // apply logical or to temporary unsigned long and bitmask
111693 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
111694 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
111695 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
111696 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
111697 + assign_intptr = gimple_build_assign(intptr, orptr);
111698 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111699 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111700 + update_stmt(assign_intptr);
111701 +
111702 + // cast temporary unsigned long back to a temporary fptr variable
111703 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
111704 + add_referenced_var(new_fptr);
111705 + new_fptr = make_ssa_name(new_fptr, NULL);
111706 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
111707 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
111708 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
111709 + update_stmt(assign_new_fptr);
111710 +
111711 + // replace call stmt fn with the new fptr
111712 + gimple_call_set_fn(call_stmt, new_fptr);
111713 + update_stmt(call_stmt);
111714 +}
111715 +
111716 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
111717 +{
111718 + gimple asm_or_stmt, call_stmt;
111719 + tree old_fptr, new_fptr, input, output;
111720 +#if BUILDING_GCC_VERSION <= 4007
111721 + VEC(tree, gc) *inputs = NULL;
111722 + VEC(tree, gc) *outputs = NULL;
111723 +#else
111724 + vec<tree, va_gc> *inputs = NULL;
111725 + vec<tree, va_gc> *outputs = NULL;
111726 +#endif
111727 +
111728 + call_stmt = gsi_stmt(*gsi);
111729 + old_fptr = gimple_call_fn(call_stmt);
111730 +
111731 + // create temporary fptr variable
111732 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
111733 + add_referenced_var(new_fptr);
111734 + new_fptr = make_ssa_name(new_fptr, NULL);
111735 +
111736 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
111737 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
111738 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
111739 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
111740 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
111741 +#if BUILDING_GCC_VERSION <= 4007
111742 + VEC_safe_push(tree, gc, inputs, input);
111743 + VEC_safe_push(tree, gc, outputs, output);
111744 +#else
111745 + vec_safe_push(inputs, input);
111746 + vec_safe_push(outputs, output);
111747 +#endif
111748 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
111749 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
111750 + gimple_asm_set_volatile(asm_or_stmt, true);
111751 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
111752 + update_stmt(asm_or_stmt);
111753 +
111754 + // replace call stmt fn with the new fptr
111755 + gimple_call_set_fn(call_stmt, new_fptr);
111756 + update_stmt(call_stmt);
111757 +}
111758 +
111759 +/*
111760 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
111761 + */
111762 +static unsigned int execute_kernexec_fptr(void)
111763 +{
111764 + basic_block bb;
111765 +
111766 + // 1. loop through BBs and GIMPLE statements
111767 + FOR_EACH_BB_FN(bb, cfun) {
111768 + gimple_stmt_iterator gsi;
111769 +
111770 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111771 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
111772 + tree fn;
111773 + gimple call_stmt;
111774 +
111775 + // is it a call ...
111776 + call_stmt = gsi_stmt(gsi);
111777 + if (!is_gimple_call(call_stmt))
111778 + continue;
111779 + fn = gimple_call_fn(call_stmt);
111780 + if (TREE_CODE(fn) == ADDR_EXPR)
111781 + continue;
111782 + if (TREE_CODE(fn) != SSA_NAME)
111783 + gcc_unreachable();
111784 +
111785 + // ... through a function pointer
111786 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
111787 + fn = SSA_NAME_VAR(fn);
111788 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
111789 + debug_tree(fn);
111790 + gcc_unreachable();
111791 + }
111792 + }
111793 + fn = TREE_TYPE(fn);
111794 + if (TREE_CODE(fn) != POINTER_TYPE)
111795 + continue;
111796 + fn = TREE_TYPE(fn);
111797 + if (TREE_CODE(fn) != FUNCTION_TYPE)
111798 + continue;
111799 +
111800 + kernexec_instrument_fptr(&gsi);
111801 +
111802 +//debug_tree(gimple_call_fn(call_stmt));
111803 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111804 + }
111805 + }
111806 +
111807 + return 0;
111808 +}
111809 +
111810 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
111811 +static void kernexec_instrument_retaddr_bts(rtx insn)
111812 +{
111813 + rtx btsq;
111814 + rtvec argvec, constraintvec, labelvec;
111815 + int line;
111816 +
111817 + // create asm volatile("btsq $63,(%%rsp)":::)
111818 + argvec = rtvec_alloc(0);
111819 + constraintvec = rtvec_alloc(0);
111820 + labelvec = rtvec_alloc(0);
111821 + line = expand_location(RTL_LOCATION(insn)).line;
111822 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111823 + MEM_VOLATILE_P(btsq) = 1;
111824 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
111825 + emit_insn_before(btsq, insn);
111826 +}
111827 +
111828 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
111829 +static void kernexec_instrument_retaddr_or(rtx insn)
111830 +{
111831 + rtx orq;
111832 + rtvec argvec, constraintvec, labelvec;
111833 + int line;
111834 +
111835 + // create asm volatile("orq %%r12,(%%rsp)":::)
111836 + argvec = rtvec_alloc(0);
111837 + constraintvec = rtvec_alloc(0);
111838 + labelvec = rtvec_alloc(0);
111839 + line = expand_location(RTL_LOCATION(insn)).line;
111840 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111841 + MEM_VOLATILE_P(orq) = 1;
111842 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
111843 + emit_insn_before(orq, insn);
111844 +}
111845 +
111846 +/*
111847 + * find all asm level function returns and forcibly set the highest bit of the return address
111848 + */
111849 +static unsigned int execute_kernexec_retaddr(void)
111850 +{
111851 + rtx insn;
111852 +
111853 +// if (stack_realign_drap)
111854 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
111855 +
111856 + // 1. find function returns
111857 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
111858 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
111859 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
111860 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
111861 + rtx body;
111862 +
111863 + // is it a retn
111864 + if (!JUMP_P(insn))
111865 + continue;
111866 + body = PATTERN(insn);
111867 + if (GET_CODE(body) == PARALLEL)
111868 + body = XVECEXP(body, 0, 0);
111869 + if (!ANY_RETURN_P(body))
111870 + continue;
111871 + kernexec_instrument_retaddr(insn);
111872 + }
111873 +
111874 +// print_simple_rtl(stderr, get_insns());
111875 +// print_rtl(stderr, get_insns());
111876 +
111877 + return 0;
111878 +}
111879 +
111880 +static bool kernexec_cmodel_check(void)
111881 +{
111882 + tree section;
111883 +
111884 + if (ix86_cmodel != CM_KERNEL)
111885 + return false;
111886 +
111887 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
111888 + if (!section || !TREE_VALUE(section))
111889 + return true;
111890 +
111891 + section = TREE_VALUE(TREE_VALUE(section));
111892 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
111893 + return true;
111894 +
111895 + return false;
111896 +}
111897 +
111898 +#if BUILDING_GCC_VERSION >= 4009
111899 +static const struct pass_data kernexec_reload_pass_data = {
111900 +#else
111901 +static struct gimple_opt_pass kernexec_reload_pass = {
111902 + .pass = {
111903 +#endif
111904 + .type = GIMPLE_PASS,
111905 + .name = "kernexec_reload",
111906 +#if BUILDING_GCC_VERSION >= 4008
111907 + .optinfo_flags = OPTGROUP_NONE,
111908 +#endif
111909 +#if BUILDING_GCC_VERSION >= 4009
111910 + .has_gate = true,
111911 + .has_execute = true,
111912 +#else
111913 + .gate = kernexec_cmodel_check,
111914 + .execute = execute_kernexec_reload,
111915 + .sub = NULL,
111916 + .next = NULL,
111917 + .static_pass_number = 0,
111918 +#endif
111919 + .tv_id = TV_NONE,
111920 + .properties_required = 0,
111921 + .properties_provided = 0,
111922 + .properties_destroyed = 0,
111923 + .todo_flags_start = 0,
111924 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111925 +#if BUILDING_GCC_VERSION < 4009
111926 + }
111927 +#endif
111928 +};
111929 +
111930 +#if BUILDING_GCC_VERSION >= 4009
111931 +static const struct pass_data kernexec_fptr_pass_data = {
111932 +#else
111933 +static struct gimple_opt_pass kernexec_fptr_pass = {
111934 + .pass = {
111935 +#endif
111936 + .type = GIMPLE_PASS,
111937 + .name = "kernexec_fptr",
111938 +#if BUILDING_GCC_VERSION >= 4008
111939 + .optinfo_flags = OPTGROUP_NONE,
111940 +#endif
111941 +#if BUILDING_GCC_VERSION >= 4009
111942 + .has_gate = true,
111943 + .has_execute = true,
111944 +#else
111945 + .gate = kernexec_cmodel_check,
111946 + .execute = execute_kernexec_fptr,
111947 + .sub = NULL,
111948 + .next = NULL,
111949 + .static_pass_number = 0,
111950 +#endif
111951 + .tv_id = TV_NONE,
111952 + .properties_required = 0,
111953 + .properties_provided = 0,
111954 + .properties_destroyed = 0,
111955 + .todo_flags_start = 0,
111956 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111957 +#if BUILDING_GCC_VERSION < 4009
111958 + }
111959 +#endif
111960 +};
111961 +
111962 +#if BUILDING_GCC_VERSION >= 4009
111963 +static const struct pass_data kernexec_retaddr_pass_data = {
111964 +#else
111965 +static struct rtl_opt_pass kernexec_retaddr_pass = {
111966 + .pass = {
111967 +#endif
111968 + .type = RTL_PASS,
111969 + .name = "kernexec_retaddr",
111970 +#if BUILDING_GCC_VERSION >= 4008
111971 + .optinfo_flags = OPTGROUP_NONE,
111972 +#endif
111973 +#if BUILDING_GCC_VERSION >= 4009
111974 + .has_gate = true,
111975 + .has_execute = true,
111976 +#else
111977 + .gate = kernexec_cmodel_check,
111978 + .execute = execute_kernexec_retaddr,
111979 + .sub = NULL,
111980 + .next = NULL,
111981 + .static_pass_number = 0,
111982 +#endif
111983 + .tv_id = TV_NONE,
111984 + .properties_required = 0,
111985 + .properties_provided = 0,
111986 + .properties_destroyed = 0,
111987 + .todo_flags_start = 0,
111988 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
111989 +#if BUILDING_GCC_VERSION < 4009
111990 + }
111991 +#endif
111992 +};
111993 +
111994 +#if BUILDING_GCC_VERSION >= 4009
111995 +namespace {
111996 +class kernexec_reload_pass : public gimple_opt_pass {
111997 +public:
111998 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
111999 + bool gate() { return kernexec_cmodel_check(); }
112000 + unsigned int execute() { return execute_kernexec_reload(); }
112001 +};
112002 +
112003 +class kernexec_fptr_pass : public gimple_opt_pass {
112004 +public:
112005 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112006 + bool gate() { return kernexec_cmodel_check(); }
112007 + unsigned int execute() { return execute_kernexec_fptr(); }
112008 +};
112009 +
112010 +class kernexec_retaddr_pass : public rtl_opt_pass {
112011 +public:
112012 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112013 + bool gate() { return kernexec_cmodel_check(); }
112014 + unsigned int execute() { return execute_kernexec_retaddr(); }
112015 +};
112016 +}
112017 +
112018 +static opt_pass *make_kernexec_reload_pass(void)
112019 +{
112020 + return new kernexec_reload_pass();
112021 +}
112022 +
112023 +static opt_pass *make_kernexec_fptr_pass(void)
112024 +{
112025 + return new kernexec_fptr_pass();
112026 +}
112027 +
112028 +static opt_pass *make_kernexec_retaddr_pass(void)
112029 +{
112030 + return new kernexec_retaddr_pass();
112031 +}
112032 +#else
112033 +static struct opt_pass *make_kernexec_reload_pass(void)
112034 +{
112035 + return &kernexec_reload_pass.pass;
112036 +}
112037 +
112038 +static struct opt_pass *make_kernexec_fptr_pass(void)
112039 +{
112040 + return &kernexec_fptr_pass.pass;
112041 +}
112042 +
112043 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112044 +{
112045 + return &kernexec_retaddr_pass.pass;
112046 +}
112047 +#endif
112048 +
112049 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112050 +{
112051 + const char * const plugin_name = plugin_info->base_name;
112052 + const int argc = plugin_info->argc;
112053 + const struct plugin_argument * const argv = plugin_info->argv;
112054 + int i;
112055 + struct register_pass_info kernexec_reload_pass_info;
112056 + struct register_pass_info kernexec_fptr_pass_info;
112057 + struct register_pass_info kernexec_retaddr_pass_info;
112058 +
112059 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112060 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112061 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112062 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112063 +
112064 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112065 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112066 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112067 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112068 +
112069 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112070 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112071 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112072 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112073 +
112074 + if (!plugin_default_version_check(version, &gcc_version)) {
112075 + error(G_("incompatible gcc/plugin versions"));
112076 + return 1;
112077 + }
112078 +
112079 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112080 +
112081 + if (TARGET_64BIT == 0)
112082 + return 0;
112083 +
112084 + for (i = 0; i < argc; ++i) {
112085 + if (!strcmp(argv[i].key, "method")) {
112086 + if (!argv[i].value) {
112087 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112088 + continue;
112089 + }
112090 + if (!strcmp(argv[i].value, "bts")) {
112091 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112092 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112093 + } else if (!strcmp(argv[i].value, "or")) {
112094 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112095 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112096 + fix_register("r12", 1, 1);
112097 + } else
112098 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112099 + continue;
112100 + }
112101 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112102 + }
112103 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112104 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112105 +
112106 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112107 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112108 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112109 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112110 +
112111 + return 0;
112112 +}
112113 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112114 new file mode 100644
112115 index 0000000..e48b323
112116 --- /dev/null
112117 +++ b/tools/gcc/latent_entropy_plugin.c
112118 @@ -0,0 +1,466 @@
112119 +/*
112120 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112121 + * Licensed under the GPL v2
112122 + *
112123 + * Note: the choice of the license means that the compilation process is
112124 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112125 + * but for the kernel it doesn't matter since it doesn't link against
112126 + * any of the gcc libraries
112127 + *
112128 + * gcc plugin to help generate a little bit of entropy from program state,
112129 + * used throughout the uptime of the kernel
112130 + *
112131 + * TODO:
112132 + * - add ipa pass to identify not explicitly marked candidate functions
112133 + * - mix in more program state (function arguments/return values, loop variables, etc)
112134 + * - more instrumentation control via attribute parameters
112135 + *
112136 + * BUGS:
112137 + * - LTO needs -flto-partition=none for now
112138 + */
112139 +
112140 +#include "gcc-common.h"
112141 +
112142 +int plugin_is_GPL_compatible;
112143 +
112144 +static tree latent_entropy_decl;
112145 +
112146 +static struct plugin_info latent_entropy_plugin_info = {
112147 + .version = "201409101820",
112148 + .help = NULL
112149 +};
112150 +
112151 +static unsigned HOST_WIDE_INT seed;
112152 +static unsigned HOST_WIDE_INT get_random_const(void)
112153 +{
112154 + unsigned int i;
112155 + unsigned HOST_WIDE_INT ret = 0;
112156 +
112157 + for (i = 0; i < 8 * sizeof ret; i++) {
112158 + ret = (ret << 1) | (seed & 1);
112159 + seed >>= 1;
112160 + if (ret & 1)
112161 + seed ^= 0xD800000000000000ULL;
112162 + }
112163 +
112164 + return ret;
112165 +}
112166 +
112167 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112168 +{
112169 + tree type;
112170 + unsigned long long mask;
112171 +#if BUILDING_GCC_VERSION <= 4007
112172 + VEC(constructor_elt, gc) *vals;
112173 +#else
112174 + vec<constructor_elt, va_gc> *vals;
112175 +#endif
112176 +
112177 + switch (TREE_CODE(*node)) {
112178 + default:
112179 + *no_add_attrs = true;
112180 + error("%qE attribute only applies to functions and variables", name);
112181 + break;
112182 +
112183 + case VAR_DECL:
112184 + if (DECL_INITIAL(*node)) {
112185 + *no_add_attrs = true;
112186 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112187 + break;
112188 + }
112189 +
112190 + if (!TREE_STATIC(*node)) {
112191 + *no_add_attrs = true;
112192 + error("variable %qD with %qE attribute must not be local", *node, name);
112193 + break;
112194 + }
112195 +
112196 + type = TREE_TYPE(*node);
112197 + switch (TREE_CODE(type)) {
112198 + default:
112199 + *no_add_attrs = true;
112200 + 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);
112201 + break;
112202 +
112203 + case RECORD_TYPE: {
112204 + tree field;
112205 + unsigned int nelt = 0;
112206 +
112207 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112208 + tree fieldtype;
112209 +
112210 + fieldtype = TREE_TYPE(field);
112211 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112212 + *no_add_attrs = true;
112213 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112214 + break;
112215 + }
112216 + }
112217 +
112218 + if (field)
112219 + break;
112220 +
112221 +#if BUILDING_GCC_VERSION <= 4007
112222 + vals = VEC_alloc(constructor_elt, gc, nelt);
112223 +#else
112224 + vec_alloc(vals, nelt);
112225 +#endif
112226 +
112227 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112228 + tree fieldtype;
112229 +
112230 + fieldtype = TREE_TYPE(field);
112231 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112232 + mask = 2 * (mask - 1) + 1;
112233 +
112234 + if (TYPE_UNSIGNED(fieldtype))
112235 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112236 + else
112237 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112238 + }
112239 +
112240 + DECL_INITIAL(*node) = build_constructor(type, vals);
112241 +//debug_tree(DECL_INITIAL(*node));
112242 + break;
112243 + }
112244 +
112245 + case INTEGER_TYPE:
112246 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112247 + mask = 2 * (mask - 1) + 1;
112248 +
112249 + if (TYPE_UNSIGNED(type))
112250 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112251 + else
112252 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112253 + break;
112254 +
112255 + case ARRAY_TYPE: {
112256 + tree elt_type, array_size, elt_size;
112257 + unsigned int i, nelt;
112258 +
112259 + elt_type = TREE_TYPE(type);
112260 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112261 + array_size = TYPE_SIZE_UNIT(type);
112262 +
112263 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112264 + *no_add_attrs = true;
112265 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112266 + break;
112267 + }
112268 +
112269 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112270 +#if BUILDING_GCC_VERSION <= 4007
112271 + vals = VEC_alloc(constructor_elt, gc, nelt);
112272 +#else
112273 + vec_alloc(vals, nelt);
112274 +#endif
112275 +
112276 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112277 + mask = 2 * (mask - 1) + 1;
112278 +
112279 + for (i = 0; i < nelt; i++)
112280 + if (TYPE_UNSIGNED(elt_type))
112281 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112282 + else
112283 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112284 +
112285 + DECL_INITIAL(*node) = build_constructor(type, vals);
112286 +//debug_tree(DECL_INITIAL(*node));
112287 + break;
112288 + }
112289 + }
112290 + break;
112291 +
112292 + case FUNCTION_DECL:
112293 + break;
112294 + }
112295 +
112296 + return NULL_TREE;
112297 +}
112298 +
112299 +static struct attribute_spec latent_entropy_attr = {
112300 + .name = "latent_entropy",
112301 + .min_length = 0,
112302 + .max_length = 0,
112303 + .decl_required = true,
112304 + .type_required = false,
112305 + .function_type_required = false,
112306 + .handler = handle_latent_entropy_attribute,
112307 +#if BUILDING_GCC_VERSION >= 4007
112308 + .affects_type_identity = false
112309 +#endif
112310 +};
112311 +
112312 +static void register_attributes(void *event_data, void *data)
112313 +{
112314 + register_attribute(&latent_entropy_attr);
112315 +}
112316 +
112317 +static bool gate_latent_entropy(void)
112318 +{
112319 + // don't bother with noreturn functions for now
112320 + if (TREE_THIS_VOLATILE(current_function_decl))
112321 + return false;
112322 +
112323 + // gcc-4.5 doesn't discover some trivial noreturn functions
112324 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112325 + return false;
112326 +
112327 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112328 +}
112329 +
112330 +static enum tree_code get_op(tree *rhs)
112331 +{
112332 + static enum tree_code op;
112333 + unsigned HOST_WIDE_INT random_const;
112334 +
112335 + random_const = get_random_const();
112336 +
112337 + switch (op) {
112338 + case BIT_XOR_EXPR:
112339 + op = PLUS_EXPR;
112340 + break;
112341 +
112342 + case PLUS_EXPR:
112343 + if (rhs) {
112344 + op = LROTATE_EXPR;
112345 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112346 + break;
112347 + }
112348 +
112349 + case LROTATE_EXPR:
112350 + default:
112351 + op = BIT_XOR_EXPR;
112352 + break;
112353 + }
112354 + if (rhs)
112355 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112356 + return op;
112357 +}
112358 +
112359 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112360 +{
112361 + gimple_stmt_iterator gsi;
112362 + gimple assign;
112363 + tree addxorrol, rhs;
112364 + enum tree_code op;
112365 +
112366 + op = get_op(&rhs);
112367 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112368 + assign = gimple_build_assign(local_entropy, addxorrol);
112369 + gsi = gsi_after_labels(bb);
112370 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112371 + update_stmt(assign);
112372 +//debug_bb(bb);
112373 +}
112374 +
112375 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112376 +{
112377 + gimple_stmt_iterator gsi;
112378 + gimple assign;
112379 + tree addxorrol, temp;
112380 +
112381 + // 1. create temporary copy of latent_entropy
112382 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112383 + add_referenced_var(temp);
112384 +
112385 + // 2. read...
112386 + temp = make_ssa_name(temp, NULL);
112387 + assign = gimple_build_assign(temp, latent_entropy_decl);
112388 + SSA_NAME_DEF_STMT(temp) = assign;
112389 + add_referenced_var(latent_entropy_decl);
112390 + gsi = gsi_after_labels(bb);
112391 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112392 + update_stmt(assign);
112393 +
112394 + // 3. ...modify...
112395 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112396 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112397 + assign = gimple_build_assign(temp, addxorrol);
112398 + SSA_NAME_DEF_STMT(temp) = assign;
112399 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112400 + update_stmt(assign);
112401 +
112402 + // 4. ...write latent_entropy
112403 + assign = gimple_build_assign(latent_entropy_decl, temp);
112404 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112405 + update_stmt(assign);
112406 +}
112407 +
112408 +static unsigned int execute_latent_entropy(void)
112409 +{
112410 + basic_block bb;
112411 + gimple assign;
112412 + gimple_stmt_iterator gsi;
112413 + tree local_entropy;
112414 +
112415 + if (!latent_entropy_decl) {
112416 +#if BUILDING_GCC_VERSION >= 4009
112417 + varpool_node *node;
112418 +#else
112419 + struct varpool_node *node;
112420 +#endif
112421 +
112422 + FOR_EACH_VARIABLE(node) {
112423 + tree var = NODE_DECL(node);
112424 +
112425 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112426 + continue;
112427 + latent_entropy_decl = var;
112428 +// debug_tree(var);
112429 + break;
112430 + }
112431 + if (!latent_entropy_decl) {
112432 +// debug_tree(current_function_decl);
112433 + return 0;
112434 + }
112435 + }
112436 +
112437 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112438 +
112439 + // 1. create local entropy variable
112440 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112441 + add_referenced_var(local_entropy);
112442 + mark_sym_for_renaming(local_entropy);
112443 +
112444 + // 2. initialize local entropy variable
112445 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112446 + if (dom_info_available_p(CDI_DOMINATORS))
112447 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112448 + gsi = gsi_start_bb(bb);
112449 +
112450 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112451 +// gimple_set_location(assign, loc);
112452 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112453 + update_stmt(assign);
112454 +//debug_bb(bb);
112455 + gcc_assert(single_succ_p(bb));
112456 + bb = single_succ(bb);
112457 +
112458 + // 3. instrument each BB with an operation on the local entropy variable
112459 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112460 + perturb_local_entropy(bb, local_entropy);
112461 +//debug_bb(bb);
112462 + bb = bb->next_bb;
112463 + };
112464 +
112465 + // 4. mix local entropy into the global entropy variable
112466 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112467 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112468 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112469 + return 0;
112470 +}
112471 +
112472 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112473 +{
112474 + tree latent_entropy_type;
112475 +
112476 + seed = get_random_seed(false);
112477 +
112478 + if (in_lto_p)
112479 + return;
112480 +
112481 + // extern volatile u64 latent_entropy
112482 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112483 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112484 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112485 +
112486 + TREE_STATIC(latent_entropy_decl) = 1;
112487 + TREE_PUBLIC(latent_entropy_decl) = 1;
112488 + TREE_USED(latent_entropy_decl) = 1;
112489 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
112490 + DECL_EXTERNAL(latent_entropy_decl) = 1;
112491 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
112492 + lang_hooks.decls.pushdecl(latent_entropy_decl);
112493 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
112494 +// varpool_finalize_decl(latent_entropy_decl);
112495 +// varpool_mark_needed_node(latent_entropy_decl);
112496 +}
112497 +
112498 +#if BUILDING_GCC_VERSION >= 4009
112499 +static const struct pass_data latent_entropy_pass_data = {
112500 +#else
112501 +static struct gimple_opt_pass latent_entropy_pass = {
112502 + .pass = {
112503 +#endif
112504 + .type = GIMPLE_PASS,
112505 + .name = "latent_entropy",
112506 +#if BUILDING_GCC_VERSION >= 4008
112507 + .optinfo_flags = OPTGROUP_NONE,
112508 +#endif
112509 +#if BUILDING_GCC_VERSION >= 4009
112510 + .has_gate = true,
112511 + .has_execute = true,
112512 +#else
112513 + .gate = gate_latent_entropy,
112514 + .execute = execute_latent_entropy,
112515 + .sub = NULL,
112516 + .next = NULL,
112517 + .static_pass_number = 0,
112518 +#endif
112519 + .tv_id = TV_NONE,
112520 + .properties_required = PROP_gimple_leh | PROP_cfg,
112521 + .properties_provided = 0,
112522 + .properties_destroyed = 0,
112523 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
112524 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
112525 +#if BUILDING_GCC_VERSION < 4009
112526 + }
112527 +#endif
112528 +};
112529 +
112530 +#if BUILDING_GCC_VERSION >= 4009
112531 +namespace {
112532 +class latent_entropy_pass : public gimple_opt_pass {
112533 +public:
112534 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
112535 + bool gate() { return gate_latent_entropy(); }
112536 + unsigned int execute() { return execute_latent_entropy(); }
112537 +};
112538 +}
112539 +
112540 +static opt_pass *make_latent_entropy_pass(void)
112541 +{
112542 + return new latent_entropy_pass();
112543 +}
112544 +#else
112545 +static struct opt_pass *make_latent_entropy_pass(void)
112546 +{
112547 + return &latent_entropy_pass.pass;
112548 +}
112549 +#endif
112550 +
112551 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112552 +{
112553 + const char * const plugin_name = plugin_info->base_name;
112554 + struct register_pass_info latent_entropy_pass_info;
112555 +
112556 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
112557 + latent_entropy_pass_info.reference_pass_name = "optimized";
112558 + latent_entropy_pass_info.ref_pass_instance_number = 1;
112559 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112560 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
112561 + {
112562 + .base = &latent_entropy_decl,
112563 + .nelt = 1,
112564 + .stride = sizeof(latent_entropy_decl),
112565 + .cb = &gt_ggc_mx_tree_node,
112566 + .pchw = &gt_pch_nx_tree_node
112567 + },
112568 + LAST_GGC_ROOT_TAB
112569 + };
112570 +
112571 + if (!plugin_default_version_check(version, &gcc_version)) {
112572 + error(G_("incompatible gcc/plugin versions"));
112573 + return 1;
112574 + }
112575 +
112576 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
112577 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
112578 + if (!in_lto_p)
112579 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
112580 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
112581 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112582 +
112583 + return 0;
112584 +}
112585 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
112586 new file mode 100644
112587 index 0000000..a5cb46b
112588 --- /dev/null
112589 +++ b/tools/gcc/randomize_layout_plugin.c
112590 @@ -0,0 +1,915 @@
112591 +/*
112592 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
112593 + * and PaX Team <pageexec@freemail.hu>
112594 + * Licensed under the GPL v2
112595 + *
112596 + * Usage:
112597 + * $ # for 4.5/4.6/C based 4.7
112598 + * $ 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
112599 + * $ # for C++ based 4.7/4.8+
112600 + * $ 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
112601 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
112602 + */
112603 +
112604 +#include "gcc-common.h"
112605 +#include "randomize_layout_seed.h"
112606 +
112607 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
112608 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
112609 +#endif
112610 +
112611 +#define ORIG_TYPE_NAME(node) \
112612 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
112613 +
112614 +int plugin_is_GPL_compatible;
112615 +
112616 +static int performance_mode;
112617 +
112618 +static struct plugin_info randomize_layout_plugin_info = {
112619 + .version = "201402201816",
112620 + .help = "disable\t\t\tdo not activate plugin\n"
112621 + "performance-mode\tenable cacheline-aware layout randomization\n"
112622 +};
112623 +
112624 +/* from old Linux dcache.h */
112625 +static inline unsigned long
112626 +partial_name_hash(unsigned long c, unsigned long prevhash)
112627 +{
112628 + return (prevhash + (c << 4) + (c >> 4)) * 11;
112629 +}
112630 +static inline unsigned int
112631 +name_hash(const unsigned char *name)
112632 +{
112633 + unsigned long hash = 0;
112634 + unsigned int len = strlen((const char *)name);
112635 + while (len--)
112636 + hash = partial_name_hash(*name++, hash);
112637 + return (unsigned int)hash;
112638 +}
112639 +
112640 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112641 +{
112642 + tree type;
112643 +
112644 + *no_add_attrs = true;
112645 + if (TREE_CODE(*node) == FUNCTION_DECL) {
112646 + error("%qE attribute does not apply to functions (%qF)", name, *node);
112647 + return NULL_TREE;
112648 + }
112649 +
112650 + if (TREE_CODE(*node) == PARM_DECL) {
112651 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
112652 + return NULL_TREE;
112653 + }
112654 +
112655 + if (TREE_CODE(*node) == VAR_DECL) {
112656 + error("%qE attribute does not apply to variables (%qD)", name, *node);
112657 + return NULL_TREE;
112658 + }
112659 +
112660 + if (TYPE_P(*node)) {
112661 + type = *node;
112662 + } else {
112663 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
112664 + type = TREE_TYPE(*node);
112665 + }
112666 +
112667 + if (TREE_CODE(type) != RECORD_TYPE) {
112668 + error("%qE attribute used on %qT applies to struct types only", name, type);
112669 + return NULL_TREE;
112670 + }
112671 +
112672 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
112673 + error("%qE attribute is already applied to the type %qT", name, type);
112674 + return NULL_TREE;
112675 + }
112676 +
112677 + *no_add_attrs = false;
112678 +
112679 + return NULL_TREE;
112680 +}
112681 +
112682 +/* set on complete types that we don't need to inspect further at all */
112683 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112684 +{
112685 + *no_add_attrs = false;
112686 + return NULL_TREE;
112687 +}
112688 +
112689 +/*
112690 + * set on types that we've performed a shuffle on, to prevent re-shuffling
112691 + * this does not preclude us from inspecting its fields for potential shuffles
112692 + */
112693 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112694 +{
112695 + *no_add_attrs = false;
112696 + return NULL_TREE;
112697 +}
112698 +
112699 +/*
112700 + * 64bit variant of Bob Jenkins' public domain PRNG
112701 + * 256 bits of internal state
112702 + */
112703 +
112704 +typedef unsigned long long u64;
112705 +
112706 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
112707 +
112708 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
112709 +static u64 ranval(ranctx *x) {
112710 + u64 e = x->a - rot(x->b, 7);
112711 + x->a = x->b ^ rot(x->c, 13);
112712 + x->b = x->c + rot(x->d, 37);
112713 + x->c = x->d + e;
112714 + x->d = e + x->a;
112715 + return x->d;
112716 +}
112717 +
112718 +static void raninit(ranctx *x, u64 *seed) {
112719 + int i;
112720 +
112721 + x->a = seed[0];
112722 + x->b = seed[1];
112723 + x->c = seed[2];
112724 + x->d = seed[3];
112725 +
112726 + for (i=0; i < 30; ++i)
112727 + (void)ranval(x);
112728 +}
112729 +
112730 +static u64 shuffle_seed[4];
112731 +
112732 +struct partition_group {
112733 + tree tree_start;
112734 + unsigned long start;
112735 + unsigned long length;
112736 +};
112737 +
112738 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
112739 +{
112740 + unsigned long i;
112741 + unsigned long accum_size = 0;
112742 + unsigned long accum_length = 0;
112743 + unsigned long group_idx = 0;
112744 +
112745 + gcc_assert(length < INT_MAX);
112746 +
112747 + memset(size_groups, 0, sizeof(struct partition_group) * length);
112748 +
112749 + for (i = 0; i < length; i++) {
112750 + if (size_groups[group_idx].tree_start == NULL_TREE) {
112751 + size_groups[group_idx].tree_start = fields[i];
112752 + size_groups[group_idx].start = i;
112753 + accum_length = 0;
112754 + accum_size = 0;
112755 + }
112756 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
112757 + accum_length++;
112758 + if (accum_size >= 64) {
112759 + size_groups[group_idx].length = accum_length;
112760 + accum_length = 0;
112761 + group_idx++;
112762 + }
112763 + }
112764 +
112765 + if (size_groups[group_idx].tree_start != NULL_TREE &&
112766 + !size_groups[group_idx].length) {
112767 + size_groups[group_idx].length = accum_length;
112768 + group_idx++;
112769 + }
112770 +
112771 + *num_groups = group_idx;
112772 +}
112773 +
112774 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112775 +{
112776 + unsigned long i, x;
112777 + struct partition_group size_group[length];
112778 + unsigned long num_groups = 0;
112779 + unsigned long randnum;
112780 +
112781 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
112782 + for (i = num_groups - 1; i > 0; i--) {
112783 + struct partition_group tmp;
112784 + randnum = ranval(prng_state) % (i + 1);
112785 + tmp = size_group[i];
112786 + size_group[i] = size_group[randnum];
112787 + size_group[randnum] = tmp;
112788 + }
112789 +
112790 + for (x = 0; x < num_groups; x++) {
112791 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
112792 + tree tmp;
112793 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
112794 + continue;
112795 + randnum = ranval(prng_state) % (i + 1);
112796 + // we could handle this case differently if desired
112797 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
112798 + continue;
112799 + tmp = newtree[i];
112800 + newtree[i] = newtree[randnum];
112801 + newtree[randnum] = tmp;
112802 + }
112803 + }
112804 +}
112805 +
112806 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112807 +{
112808 + unsigned long i, randnum;
112809 +
112810 + for (i = length - 1; i > 0; i--) {
112811 + tree tmp;
112812 + randnum = ranval(prng_state) % (i + 1);
112813 + tmp = newtree[i];
112814 + newtree[i] = newtree[randnum];
112815 + newtree[randnum] = tmp;
112816 + }
112817 +}
112818 +
112819 +/* modern in-place Fisher-Yates shuffle */
112820 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
112821 +{
112822 + unsigned long i;
112823 + u64 seed[4];
112824 + ranctx prng_state;
112825 + const unsigned char *structname;
112826 +
112827 + if (length == 0)
112828 + return;
112829 +
112830 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112831 +
112832 + structname = ORIG_TYPE_NAME(type);
112833 +
112834 +#ifdef __DEBUG_PLUGIN
112835 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
112836 +#ifdef __DEBUG_VERBOSE
112837 + debug_tree((tree)type);
112838 +#endif
112839 +#endif
112840 +
112841 + for (i = 0; i < 4; i++) {
112842 + seed[i] = shuffle_seed[i];
112843 + seed[i] ^= name_hash(structname);
112844 + }
112845 +
112846 + raninit(&prng_state, (u64 *)&seed);
112847 +
112848 + if (performance_mode)
112849 + performance_shuffle(newtree, length, &prng_state);
112850 + else
112851 + full_shuffle(newtree, length, &prng_state);
112852 +}
112853 +
112854 +static bool is_flexible_array(const_tree field)
112855 +{
112856 + const_tree fieldtype;
112857 + const_tree typesize;
112858 + const_tree elemtype;
112859 + const_tree elemsize;
112860 +
112861 + fieldtype = TREE_TYPE(field);
112862 + typesize = TYPE_SIZE(fieldtype);
112863 +
112864 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
112865 + return false;
112866 +
112867 + elemtype = TREE_TYPE(fieldtype);
112868 + elemsize = TYPE_SIZE(elemtype);
112869 +
112870 + /* size of type is represented in bits */
112871 +
112872 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
112873 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
112874 + return true;
112875 +
112876 + if (typesize != NULL_TREE &&
112877 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
112878 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
112879 + return true;
112880 +
112881 + return false;
112882 +}
112883 +
112884 +static int relayout_struct(tree type)
112885 +{
112886 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
112887 + unsigned long shuffle_length = num_fields;
112888 + tree field;
112889 + tree newtree[num_fields];
112890 + unsigned long i;
112891 + tree list;
112892 + tree variant;
112893 + expanded_location xloc;
112894 +
112895 + if (TYPE_FIELDS(type) == NULL_TREE)
112896 + return 0;
112897 +
112898 + if (num_fields < 2)
112899 + return 0;
112900 +
112901 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112902 +
112903 + gcc_assert(num_fields < INT_MAX);
112904 +
112905 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
112906 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
112907 + return 0;
112908 +
112909 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
112910 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
112911 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
112912 + return 0;
112913 +
112914 + /* throw out any structs in uapi */
112915 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
112916 +
112917 + if (strstr(xloc.file, "/uapi/"))
112918 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
112919 +
112920 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
112921 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
112922 + newtree[i] = field;
112923 + }
112924 +
112925 + /*
112926 + * enforce that we don't randomize the layout of the last
112927 + * element of a struct if it's a 0 or 1-length array
112928 + * or a proper flexible array
112929 + */
112930 + if (is_flexible_array(newtree[num_fields - 1]))
112931 + shuffle_length--;
112932 +
112933 + shuffle(type, (tree *)newtree, shuffle_length);
112934 +
112935 + /*
112936 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
112937 + * as gcc provides no other way to detect such code
112938 + */
112939 + list = make_node(FIELD_DECL);
112940 + TREE_CHAIN(list) = newtree[0];
112941 + TREE_TYPE(list) = void_type_node;
112942 + DECL_SIZE(list) = bitsize_zero_node;
112943 + DECL_NONADDRESSABLE_P(list) = 1;
112944 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
112945 + DECL_SIZE_UNIT(list) = size_zero_node;
112946 + DECL_FIELD_OFFSET(list) = size_zero_node;
112947 + // to satisfy the constify plugin
112948 + TREE_READONLY(list) = 1;
112949 +
112950 + for (i = 0; i < num_fields - 1; i++)
112951 + TREE_CHAIN(newtree[i]) = newtree[i+1];
112952 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
112953 +
112954 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
112955 + TYPE_FIELDS(variant) = list;
112956 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
112957 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
112958 + // force a re-layout
112959 + TYPE_SIZE(variant) = NULL_TREE;
112960 + layout_type(variant);
112961 + }
112962 +
112963 + return 1;
112964 +}
112965 +
112966 +/* from constify plugin */
112967 +static const_tree get_field_type(const_tree field)
112968 +{
112969 + return strip_array_types(TREE_TYPE(field));
112970 +}
112971 +
112972 +/* from constify plugin */
112973 +static bool is_fptr(const_tree fieldtype)
112974 +{
112975 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
112976 + return false;
112977 +
112978 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
112979 +}
112980 +
112981 +/* derived from constify plugin */
112982 +static int is_pure_ops_struct(const_tree node)
112983 +{
112984 + const_tree field;
112985 +
112986 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
112987 +
112988 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
112989 + const_tree fieldtype = get_field_type(field);
112990 + enum tree_code code = TREE_CODE(fieldtype);
112991 +
112992 + if (node == fieldtype)
112993 + continue;
112994 +
112995 + if (!is_fptr(fieldtype))
112996 + return 0;
112997 +
112998 + if (code != RECORD_TYPE && code != UNION_TYPE)
112999 + continue;
113000 +
113001 + if (!is_pure_ops_struct(fieldtype))
113002 + return 0;
113003 + }
113004 +
113005 + return 1;
113006 +}
113007 +
113008 +static void randomize_type(tree type)
113009 +{
113010 + tree variant;
113011 +
113012 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113013 +
113014 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113015 + return;
113016 +
113017 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113018 + relayout_struct(type);
113019 +
113020 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113021 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113022 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113023 + }
113024 +#ifdef __DEBUG_PLUGIN
113025 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113026 +#ifdef __DEBUG_VERBOSE
113027 + debug_tree(type);
113028 +#endif
113029 +#endif
113030 +}
113031 +
113032 +static void randomize_layout_finish_decl(void *event_data, void *data)
113033 +{
113034 + tree decl = (tree)event_data;
113035 + tree type;
113036 +
113037 + if (decl == NULL_TREE || decl == error_mark_node)
113038 + return;
113039 +
113040 + type = TREE_TYPE(decl);
113041 +
113042 + if (TREE_CODE(decl) != VAR_DECL)
113043 + return;
113044 +
113045 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113046 + return;
113047 +
113048 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113049 + return;
113050 +
113051 + relayout_decl(decl);
113052 +}
113053 +
113054 +static void finish_type(void *event_data, void *data)
113055 +{
113056 + tree type = (tree)event_data;
113057 +
113058 + if (type == NULL_TREE || type == error_mark_node)
113059 + return;
113060 +
113061 + if (TREE_CODE(type) != RECORD_TYPE)
113062 + return;
113063 +
113064 + if (TYPE_FIELDS(type) == NULL_TREE)
113065 + return;
113066 +
113067 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113068 + return;
113069 +
113070 +#ifdef __DEBUG_PLUGIN
113071 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113072 +#endif
113073 +#ifdef __DEBUG_VERBOSE
113074 + debug_tree(type);
113075 +#endif
113076 + randomize_type(type);
113077 +
113078 + return;
113079 +}
113080 +
113081 +static struct attribute_spec randomize_layout_attr = {
113082 + .name = "randomize_layout",
113083 + // related to args
113084 + .min_length = 0,
113085 + .max_length = 0,
113086 + .decl_required = false,
113087 + // need type declaration
113088 + .type_required = true,
113089 + .function_type_required = false,
113090 + .handler = handle_randomize_layout_attr,
113091 +#if BUILDING_GCC_VERSION >= 4007
113092 + .affects_type_identity = true
113093 +#endif
113094 +};
113095 +
113096 +static struct attribute_spec no_randomize_layout_attr = {
113097 + .name = "no_randomize_layout",
113098 + // related to args
113099 + .min_length = 0,
113100 + .max_length = 0,
113101 + .decl_required = false,
113102 + // need type declaration
113103 + .type_required = true,
113104 + .function_type_required = false,
113105 + .handler = handle_randomize_layout_attr,
113106 +#if BUILDING_GCC_VERSION >= 4007
113107 + .affects_type_identity = true
113108 +#endif
113109 +};
113110 +
113111 +static struct attribute_spec randomize_considered_attr = {
113112 + .name = "randomize_considered",
113113 + // related to args
113114 + .min_length = 0,
113115 + .max_length = 0,
113116 + .decl_required = false,
113117 + // need type declaration
113118 + .type_required = true,
113119 + .function_type_required = false,
113120 + .handler = handle_randomize_considered_attr,
113121 +#if BUILDING_GCC_VERSION >= 4007
113122 + .affects_type_identity = false
113123 +#endif
113124 +};
113125 +
113126 +static struct attribute_spec randomize_performed_attr = {
113127 + .name = "randomize_performed",
113128 + // related to args
113129 + .min_length = 0,
113130 + .max_length = 0,
113131 + .decl_required = false,
113132 + // need type declaration
113133 + .type_required = true,
113134 + .function_type_required = false,
113135 + .handler = handle_randomize_performed_attr,
113136 +#if BUILDING_GCC_VERSION >= 4007
113137 + .affects_type_identity = false
113138 +#endif
113139 +};
113140 +
113141 +static void register_attributes(void *event_data, void *data)
113142 +{
113143 + register_attribute(&randomize_layout_attr);
113144 + register_attribute(&no_randomize_layout_attr);
113145 + register_attribute(&randomize_considered_attr);
113146 + register_attribute(&randomize_performed_attr);
113147 +}
113148 +
113149 +static void check_bad_casts_in_constructor(tree var, tree init)
113150 +{
113151 + unsigned HOST_WIDE_INT idx;
113152 + tree field, val;
113153 + tree field_type, val_type;
113154 +
113155 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113156 + if (TREE_CODE(val) == CONSTRUCTOR) {
113157 + check_bad_casts_in_constructor(var, val);
113158 + continue;
113159 + }
113160 +
113161 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113162 + normal code which all have valid 'field' trees. work around this */
113163 + if (field == NULL_TREE)
113164 + continue;
113165 + field_type = TREE_TYPE(field);
113166 + val_type = TREE_TYPE(val);
113167 +
113168 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113169 + continue;
113170 +
113171 + if (field_type == val_type)
113172 + continue;
113173 +
113174 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113175 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113176 +
113177 + if (field_type == void_type_node)
113178 + continue;
113179 + if (field_type == val_type)
113180 + continue;
113181 + if (TREE_CODE(val_type) != RECORD_TYPE)
113182 + continue;
113183 +
113184 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113185 + continue;
113186 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113187 + }
113188 +}
113189 +
113190 +/* derived from the constify plugin */
113191 +static void check_global_variables(void *event_data, void *data)
113192 +{
113193 + struct varpool_node *node;
113194 + tree init;
113195 +
113196 + FOR_EACH_VARIABLE(node) {
113197 + tree var = NODE_DECL(node);
113198 + init = DECL_INITIAL(var);
113199 + if (init == NULL_TREE)
113200 + continue;
113201 +
113202 + if (TREE_CODE(init) != CONSTRUCTOR)
113203 + continue;
113204 +
113205 + check_bad_casts_in_constructor(var, init);
113206 + }
113207 +}
113208 +
113209 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113210 +{
113211 + basic_block dom;
113212 + gimple dom_stmt;
113213 + gimple call_stmt;
113214 + const_tree dom_lhs;
113215 + const_tree poss_is_err_cond;
113216 + const_tree poss_is_err_func;
113217 + const_tree is_err_arg;
113218 +
113219 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113220 + if (!dom)
113221 + return false;
113222 +
113223 + dom_stmt = last_stmt(dom);
113224 + if (!dom_stmt)
113225 + return false;
113226 +
113227 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113228 + return false;
113229 +
113230 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113231 + return false;
113232 +
113233 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113234 + return false;
113235 +
113236 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113237 +
113238 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113239 + return false;
113240 +
113241 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113242 +
113243 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113244 + return false;
113245 +
113246 + dom_lhs = gimple_get_lhs(call_stmt);
113247 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113248 + if (!poss_is_err_func)
113249 + return false;
113250 + if (dom_lhs != poss_is_err_cond)
113251 + return false;
113252 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113253 + return false;
113254 +
113255 + is_err_arg = gimple_call_arg(call_stmt, 0);
113256 + if (!is_err_arg)
113257 + return false;
113258 +
113259 + if (is_err_arg != rhs)
113260 + return false;
113261 +
113262 + return true;
113263 +}
113264 +
113265 +static void handle_local_var_initializers(void)
113266 +{
113267 + tree var;
113268 + unsigned int i;
113269 +
113270 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113271 + tree init = DECL_INITIAL(var);
113272 + if (!init)
113273 + continue;
113274 + if (TREE_CODE(init) != CONSTRUCTOR)
113275 + continue;
113276 + check_bad_casts_in_constructor(var, init);
113277 + }
113278 +}
113279 +
113280 +/*
113281 + * iterate over all statements to find "bad" casts:
113282 + * those where the address of the start of a structure is cast
113283 + * to a pointer of a structure of a different type, or a
113284 + * structure pointer type is cast to a different structure pointer type
113285 + */
113286 +static unsigned int find_bad_casts(void)
113287 +{
113288 + basic_block bb;
113289 +
113290 + handle_local_var_initializers();
113291 +
113292 + FOR_ALL_BB_FN(bb, cfun) {
113293 + gimple_stmt_iterator gsi;
113294 +
113295 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113296 + gimple stmt;
113297 + const_tree lhs;
113298 + const_tree lhs_type;
113299 + const_tree rhs1;
113300 + const_tree rhs_type;
113301 + const_tree ptr_lhs_type;
113302 + const_tree ptr_rhs_type;
113303 + const_tree op0;
113304 + const_tree op0_type;
113305 + enum tree_code rhs_code;
113306 +
113307 + stmt = gsi_stmt(gsi);
113308 +
113309 +#ifdef __DEBUG_PLUGIN
113310 +#ifdef __DEBUG_VERBOSE
113311 + debug_gimple_stmt(stmt);
113312 + debug_tree(gimple_get_lhs(stmt));
113313 +#endif
113314 +#endif
113315 +
113316 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113317 + continue;
113318 +
113319 +#ifdef __DEBUG_PLUGIN
113320 +#ifdef __DEBUG_VERBOSE
113321 + debug_tree(gimple_assign_rhs1(stmt));
113322 +#endif
113323 +#endif
113324 +
113325 + rhs_code = gimple_assign_rhs_code(stmt);
113326 +
113327 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113328 + continue;
113329 +
113330 + lhs = gimple_get_lhs(stmt);
113331 + lhs_type = TREE_TYPE(lhs);
113332 + rhs1 = gimple_assign_rhs1(stmt);
113333 + rhs_type = TREE_TYPE(rhs1);
113334 +
113335 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113336 + TREE_CODE(lhs_type) != POINTER_TYPE)
113337 + continue;
113338 +
113339 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113340 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113341 +
113342 + if (ptr_rhs_type == void_type_node)
113343 + continue;
113344 +
113345 + if (ptr_lhs_type == void_type_node)
113346 + continue;
113347 +
113348 + if (dominated_by_is_err(rhs1, bb))
113349 + continue;
113350 +
113351 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113352 +#ifndef __DEBUG_PLUGIN
113353 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113354 +#endif
113355 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113356 + continue;
113357 + }
113358 +
113359 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113360 + continue;
113361 +
113362 + if (rhs_code == ADDR_EXPR) {
113363 + op0 = TREE_OPERAND(rhs1, 0);
113364 +
113365 + if (op0 == NULL_TREE)
113366 + continue;
113367 +
113368 + if (TREE_CODE(op0) != VAR_DECL)
113369 + continue;
113370 +
113371 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113372 + if (op0_type == ptr_lhs_type)
113373 + continue;
113374 +
113375 +#ifndef __DEBUG_PLUGIN
113376 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113377 +#endif
113378 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113379 + } else {
113380 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113381 + /* skip bogus type casts introduced by container_of */
113382 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113383 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113384 + continue;
113385 +#ifndef __DEBUG_PLUGIN
113386 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113387 +#endif
113388 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113389 + }
113390 +
113391 + }
113392 + }
113393 + return 0;
113394 +}
113395 +
113396 +#if BUILDING_GCC_VERSION >= 4009
113397 +static const struct pass_data randomize_layout_bad_cast_data = {
113398 +#else
113399 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113400 + .pass = {
113401 +#endif
113402 + .type = GIMPLE_PASS,
113403 + .name = "randomize_layout_bad_cast",
113404 +#if BUILDING_GCC_VERSION >= 4008
113405 + .optinfo_flags = OPTGROUP_NONE,
113406 +#endif
113407 +#if BUILDING_GCC_VERSION >= 4009
113408 + .has_gate = false,
113409 + .has_execute = true,
113410 +#else
113411 + .gate = NULL,
113412 + .execute = find_bad_casts,
113413 + .sub = NULL,
113414 + .next = NULL,
113415 + .static_pass_number = 0,
113416 +#endif
113417 + .tv_id = TV_NONE,
113418 + .properties_required = PROP_cfg,
113419 + .properties_provided = 0,
113420 + .properties_destroyed = 0,
113421 + .todo_flags_start = 0,
113422 + .todo_flags_finish = TODO_dump_func
113423 +#if BUILDING_GCC_VERSION < 4009
113424 + }
113425 +#endif
113426 +};
113427 +
113428 +#if BUILDING_GCC_VERSION >= 4009
113429 +namespace {
113430 +class randomize_layout_bad_cast : public gimple_opt_pass {
113431 +public:
113432 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113433 + unsigned int execute() { return find_bad_casts(); }
113434 +};
113435 +}
113436 +#endif
113437 +
113438 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113439 +{
113440 +#if BUILDING_GCC_VERSION >= 4009
113441 + return new randomize_layout_bad_cast();
113442 +#else
113443 + return &randomize_layout_bad_cast.pass;
113444 +#endif
113445 +}
113446 +
113447 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113448 +{
113449 + int i;
113450 + const char * const plugin_name = plugin_info->base_name;
113451 + const int argc = plugin_info->argc;
113452 + const struct plugin_argument * const argv = plugin_info->argv;
113453 + bool enable = true;
113454 + int obtained_seed = 0;
113455 + struct register_pass_info randomize_layout_bad_cast_info;
113456 +
113457 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113458 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113459 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113460 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113461 +
113462 + if (!plugin_default_version_check(version, &gcc_version)) {
113463 + error(G_("incompatible gcc/plugin versions"));
113464 + return 1;
113465 + }
113466 +
113467 + if (strcmp(lang_hooks.name, "GNU C")) {
113468 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113469 + enable = false;
113470 + }
113471 +
113472 + for (i = 0; i < argc; ++i) {
113473 + if (!strcmp(argv[i].key, "disable")) {
113474 + enable = false;
113475 + continue;
113476 + }
113477 + if (!strcmp(argv[i].key, "performance-mode")) {
113478 + performance_mode = 1;
113479 + continue;
113480 + }
113481 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113482 + }
113483 +
113484 + if (strlen(randstruct_seed) != 64) {
113485 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
113486 + return 1;
113487 + }
113488 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
113489 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
113490 + if (obtained_seed != 4) {
113491 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
113492 + return 1;
113493 + }
113494 +
113495 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
113496 + if (enable) {
113497 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
113498 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
113499 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
113500 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
113501 + }
113502 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113503 +
113504 + return 0;
113505 +}
113506 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
113507 new file mode 100644
113508 index 0000000..1f0214f
113509 --- /dev/null
113510 +++ b/tools/gcc/size_overflow_plugin/.gitignore
113511 @@ -0,0 +1,3 @@
113512 +randomize_layout_seed.h
113513 +size_overflow_hash.h
113514 +size_overflow_hash_aux.h
113515 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
113516 new file mode 100644
113517 index 0000000..1ae2ed5
113518 --- /dev/null
113519 +++ b/tools/gcc/size_overflow_plugin/Makefile
113520 @@ -0,0 +1,20 @@
113521 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
113522 +always := $($(HOSTLIBS)-y)
113523 +
113524 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
113525 +
113526 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
113527 +
113528 +quiet_cmd_build_size_overflow_hash = GENHASH $@
113529 + cmd_build_size_overflow_hash = \
113530 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
113531 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
113532 + $(call if_changed,build_size_overflow_hash)
113533 +
113534 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
113535 + cmd_build_size_overflow_hash_aux = \
113536 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
113537 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
113538 + $(call if_changed,build_size_overflow_hash_aux)
113539 +
113540 +targets += size_overflow_hash.h size_overflow_hash_aux.h
113541 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113542 new file mode 100644
113543 index 0000000..12b1e3b
113544 --- /dev/null
113545 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113546 @@ -0,0 +1,102 @@
113547 +#!/bin/bash
113548 +
113549 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
113550 +
113551 +header1="size_overflow_hash.h"
113552 +database="size_overflow_hash.data"
113553 +n=65536
113554 +hashtable_name="size_overflow_hash"
113555 +
113556 +usage() {
113557 +cat <<EOF
113558 +usage: $0 options
113559 +OPTIONS:
113560 + -h|--help help
113561 + -o header file
113562 + -d database file
113563 + -n hash array size
113564 + -s name of the hash table
113565 +EOF
113566 + return 0
113567 +}
113568 +
113569 +while true
113570 +do
113571 + case "$1" in
113572 + -h|--help) usage && exit 0;;
113573 + -n) n=$2; shift 2;;
113574 + -o) header1="$2"; shift 2;;
113575 + -d) database="$2"; shift 2;;
113576 + -s) hashtable_name="$2"; shift 2;;
113577 + --) shift 1; break ;;
113578 + *) break ;;
113579 + esac
113580 +done
113581 +
113582 +create_defines() {
113583 + for i in `seq 0 31`
113584 + do
113585 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
113586 + done
113587 + echo >> "$header1"
113588 +}
113589 +
113590 +create_structs() {
113591 + rm -f "$header1"
113592 +
113593 + create_defines
113594 +
113595 + cat "$database" | while read data
113596 + do
113597 + data_array=($data)
113598 + struct_hash_name="${data_array[0]}"
113599 + funcn="${data_array[1]}"
113600 + params="${data_array[2]}"
113601 + next="${data_array[4]}"
113602 +
113603 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
113604 +
113605 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
113606 + echo -en "\t.param\t= " >> "$header1"
113607 + line=
113608 + for param_num in ${params//-/ };
113609 + do
113610 + line="${line}PARAM"$param_num"|"
113611 + done
113612 +
113613 + echo -e "${line%?},\n};\n" >> "$header1"
113614 + done
113615 +}
113616 +
113617 +create_headers() {
113618 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
113619 +}
113620 +
113621 +create_array_elements() {
113622 + index=0
113623 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
113624 + do
113625 + data_array=($data)
113626 + i="${data_array[3]}"
113627 + hash="${data_array[0]}"
113628 + while [[ $index -lt $i ]]
113629 + do
113630 + echo -e "\t["$index"]\t= NULL," >> "$header1"
113631 + index=$(($index + 1))
113632 + done
113633 + index=$(($index + 1))
113634 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
113635 + done
113636 + echo '};' >> $header1
113637 +}
113638 +
113639 +size_overflow_plugin_dir=`dirname $header1`
113640 +if [ "$size_overflow_plugin_dir" != '.' ]; then
113641 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
113642 +fi
113643 +
113644 +create_structs
113645 +create_headers
113646 +create_array_elements
113647 +
113648 +exit 0
113649 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113650 new file mode 100644
113651 index 0000000..c43901f
113652 --- /dev/null
113653 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113654 @@ -0,0 +1,748 @@
113655 +/*
113656 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113657 + * Licensed under the GPL v2, or (at your option) v3
113658 + *
113659 + * Homepage:
113660 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113661 + *
113662 + * Documentation:
113663 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113664 + *
113665 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113666 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113667 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113668 + *
113669 + * Usage:
113670 + * $ make
113671 + * $ make run
113672 + */
113673 +
113674 +#include "gcc-common.h"
113675 +#include "size_overflow.h"
113676 +
113677 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
113678 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
113679 +
113680 +// data for the size_overflow asm stmt
113681 +struct asm_data {
113682 + gimple def_stmt;
113683 + tree input;
113684 + tree output;
113685 +};
113686 +
113687 +#if BUILDING_GCC_VERSION <= 4007
113688 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
113689 +#else
113690 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
113691 +#endif
113692 +{
113693 + tree list;
113694 +#if BUILDING_GCC_VERSION <= 4007
113695 + VEC(tree, gc) *vec_list = NULL;
113696 +#else
113697 + vec<tree, va_gc> *vec_list = NULL;
113698 +#endif
113699 +
113700 + list = build_tree_list(NULL_TREE, string);
113701 + list = chainon(NULL_TREE, build_tree_list(list, io));
113702 +#if BUILDING_GCC_VERSION <= 4007
113703 + VEC_safe_push(tree, gc, vec_list, list);
113704 +#else
113705 + vec_safe_push(vec_list, list);
113706 +#endif
113707 + return vec_list;
113708 +}
113709 +
113710 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
113711 +{
113712 + gimple asm_stmt;
113713 + gimple_stmt_iterator gsi;
113714 +#if BUILDING_GCC_VERSION <= 4007
113715 + VEC(tree, gc) *input, *output = NULL;
113716 +#else
113717 + vec<tree, va_gc> *input, *output = NULL;
113718 +#endif
113719 +
113720 + input = create_asm_io_list(str_input, asm_data->input);
113721 +
113722 + if (asm_data->output)
113723 + output = create_asm_io_list(str_output, asm_data->output);
113724 +
113725 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
113726 + gsi = gsi_for_stmt(asm_data->def_stmt);
113727 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
113728 +
113729 + if (asm_data->output)
113730 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
113731 +}
113732 +
113733 +static void replace_call_lhs(const struct asm_data *asm_data)
113734 +{
113735 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
113736 + update_stmt(asm_data->def_stmt);
113737 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
113738 +}
113739 +
113740 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
113741 +{
113742 + enum mark cur_fndecl_attr;
113743 + gimple phi = get_def_stmt(result);
113744 + unsigned int i, n = gimple_phi_num_args(phi);
113745 +
113746 + pointer_set_insert(visited, phi);
113747 + for (i = 0; i < n; i++) {
113748 + tree arg = gimple_phi_arg_def(phi, i);
113749 +
113750 + cur_fndecl_attr = search_intentional(visited, arg);
113751 + if (cur_fndecl_attr != MARK_NO)
113752 + return cur_fndecl_attr;
113753 + }
113754 + return MARK_NO;
113755 +}
113756 +
113757 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
113758 +{
113759 + enum mark cur_fndecl_attr;
113760 + const_tree rhs1, rhs2;
113761 + gimple def_stmt = get_def_stmt(lhs);
113762 +
113763 + rhs1 = gimple_assign_rhs1(def_stmt);
113764 + rhs2 = gimple_assign_rhs2(def_stmt);
113765 +
113766 + cur_fndecl_attr = search_intentional(visited, rhs1);
113767 + if (cur_fndecl_attr != MARK_NO)
113768 + return cur_fndecl_attr;
113769 + return search_intentional(visited, rhs2);
113770 +}
113771 +
113772 +// Look up the intentional_overflow attribute on the caller and the callee functions.
113773 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
113774 +{
113775 + const_gimple def_stmt;
113776 +
113777 + if (TREE_CODE(lhs) != SSA_NAME)
113778 + return get_intentional_attr_type(lhs);
113779 +
113780 + def_stmt = get_def_stmt(lhs);
113781 + if (!def_stmt)
113782 + return MARK_NO;
113783 +
113784 + if (pointer_set_contains(visited, def_stmt))
113785 + return MARK_NO;
113786 +
113787 + switch (gimple_code(def_stmt)) {
113788 + case GIMPLE_NOP:
113789 + return search_intentional(visited, SSA_NAME_VAR(lhs));
113790 + case GIMPLE_ASM:
113791 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
113792 + return MARK_TURN_OFF;
113793 + return MARK_NO;
113794 + case GIMPLE_CALL:
113795 + return MARK_NO;
113796 + case GIMPLE_PHI:
113797 + return search_intentional_phi(visited, lhs);
113798 + case GIMPLE_ASSIGN:
113799 + switch (gimple_num_ops(def_stmt)) {
113800 + case 2:
113801 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
113802 + case 3:
113803 + return search_intentional_binary(visited, lhs);
113804 + }
113805 + case GIMPLE_RETURN:
113806 + return MARK_NO;
113807 + default:
113808 + debug_gimple_stmt((gimple)def_stmt);
113809 + error("%s: unknown gimple code", __func__);
113810 + gcc_unreachable();
113811 + }
113812 +}
113813 +
113814 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
113815 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
113816 +{
113817 + const_tree fndecl;
113818 + struct pointer_set_t *visited;
113819 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
113820 +
113821 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
113822 + if (is_end_intentional_intentional_attr(fndecl, argnum))
113823 + decl_attr = MARK_NOT_INTENTIONAL;
113824 + else if (is_yes_intentional_attr(fndecl, argnum))
113825 + decl_attr = MARK_YES;
113826 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113827 + return MARK_TURN_OFF;
113828 + }
113829 +
113830 + visited = pointer_set_create();
113831 + cur_fndecl_attr = search_intentional(visited, arg);
113832 + pointer_set_destroy(visited);
113833 +
113834 + switch (cur_fndecl_attr) {
113835 + case MARK_NO:
113836 + case MARK_TURN_OFF:
113837 + return cur_fndecl_attr;
113838 + default:
113839 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
113840 + return MARK_YES;
113841 + }
113842 +}
113843 +
113844 +static void check_missing_size_overflow_attribute(tree var)
113845 +{
113846 + tree orig_fndecl;
113847 + unsigned int num;
113848 +
113849 + if (is_a_return_check(var))
113850 + orig_fndecl = DECL_ORIGIN(var);
113851 + else
113852 + orig_fndecl = DECL_ORIGIN(current_function_decl);
113853 +
113854 + num = get_function_num(var, orig_fndecl);
113855 + if (num == CANNOT_FIND_ARG)
113856 + return;
113857 +
113858 + is_missing_function(orig_fndecl, num);
113859 +}
113860 +
113861 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
113862 +{
113863 + gimple phi = get_def_stmt(result);
113864 + unsigned int i, n = gimple_phi_num_args(phi);
113865 +
113866 + pointer_set_insert(visited, phi);
113867 + for (i = 0; i < n; i++) {
113868 + tree arg = gimple_phi_arg_def(phi, i);
113869 +
113870 + search_size_overflow_attribute(visited, arg);
113871 + }
113872 +}
113873 +
113874 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
113875 +{
113876 + const_gimple def_stmt = get_def_stmt(lhs);
113877 + tree rhs1, rhs2;
113878 +
113879 + rhs1 = gimple_assign_rhs1(def_stmt);
113880 + rhs2 = gimple_assign_rhs2(def_stmt);
113881 +
113882 + search_size_overflow_attribute(visited, rhs1);
113883 + search_size_overflow_attribute(visited, rhs2);
113884 +}
113885 +
113886 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
113887 +{
113888 + const_gimple def_stmt;
113889 +
113890 + if (TREE_CODE(lhs) == PARM_DECL) {
113891 + check_missing_size_overflow_attribute(lhs);
113892 + return;
113893 + }
113894 +
113895 + def_stmt = get_def_stmt(lhs);
113896 + if (!def_stmt)
113897 + return;
113898 +
113899 + if (pointer_set_insert(visited, def_stmt))
113900 + return;
113901 +
113902 + switch (gimple_code(def_stmt)) {
113903 + case GIMPLE_NOP:
113904 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
113905 + case GIMPLE_ASM:
113906 + return;
113907 + case GIMPLE_CALL: {
113908 + tree fndecl = gimple_call_fndecl(def_stmt);
113909 +
113910 + if (fndecl == NULL_TREE)
113911 + return;
113912 + check_missing_size_overflow_attribute(fndecl);
113913 + return;
113914 + }
113915 + case GIMPLE_PHI:
113916 + return search_size_overflow_attribute_phi(visited, lhs);
113917 + case GIMPLE_ASSIGN:
113918 + switch (gimple_num_ops(def_stmt)) {
113919 + case 2:
113920 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
113921 + case 3:
113922 + return search_size_overflow_attribute_binary(visited, lhs);
113923 + }
113924 + default:
113925 + debug_gimple_stmt((gimple)def_stmt);
113926 + error("%s: unknown gimple code", __func__);
113927 + gcc_unreachable();
113928 + }
113929 +}
113930 +
113931 +// Search missing entries in the hash table (invoked from the gimple pass)
113932 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
113933 +{
113934 + tree fndecl = NULL_TREE;
113935 + tree lhs;
113936 + struct pointer_set_t *visited;
113937 +
113938 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
113939 + return;
113940 +
113941 + if (num == 0) {
113942 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
113943 + lhs = gimple_return_retval(stmt);
113944 + } else {
113945 + gcc_assert(is_gimple_call(stmt));
113946 + lhs = gimple_call_arg(stmt, num - 1);
113947 + fndecl = gimple_call_fndecl(stmt);
113948 + }
113949 +
113950 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
113951 + return;
113952 +
113953 + visited = pointer_set_create();
113954 + search_size_overflow_attribute(visited, lhs);
113955 + pointer_set_destroy(visited);
113956 +}
113957 +
113958 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
113959 +{
113960 + gimple_stmt_iterator gsi;
113961 + gimple assign;
113962 +
113963 + assign = gimple_build_assign(asm_data->input, asm_data->output);
113964 + gsi = gsi_for_stmt(stmt);
113965 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113966 + asm_data->def_stmt = assign;
113967 +
113968 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
113969 + asm_data->output = make_ssa_name(asm_data->output, stmt);
113970 + if (gimple_code(stmt) == GIMPLE_RETURN)
113971 + gimple_return_set_retval(stmt, asm_data->output);
113972 + else
113973 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
113974 + update_stmt(stmt);
113975 +}
113976 +
113977 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
113978 +{
113979 + const char *fn_name;
113980 + char *asm_comment;
113981 + unsigned int len;
113982 +
113983 + if (argnum == 0)
113984 + fn_name = DECL_NAME_POINTER(current_function_decl);
113985 + else
113986 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
113987 +
113988 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
113989 + gcc_assert(len > 0);
113990 +
113991 + return asm_comment;
113992 +}
113993 +
113994 +static const char *convert_mark_to_str(enum mark mark)
113995 +{
113996 + switch (mark) {
113997 + case MARK_NO:
113998 + return OK_ASM_STR;
113999 + case MARK_YES:
114000 + case MARK_NOT_INTENTIONAL:
114001 + return YES_ASM_STR;
114002 + case MARK_TURN_OFF:
114003 + return TURN_OFF_ASM_STR;
114004 + }
114005 +
114006 + gcc_unreachable();
114007 +}
114008 +
114009 +/* Create the input of the size_overflow asm stmt.
114010 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114011 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114012 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114013 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114014 + */
114015 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114016 +{
114017 + if (!asm_data->def_stmt) {
114018 + asm_data->input = NULL_TREE;
114019 + return;
114020 + }
114021 +
114022 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114023 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114024 +
114025 + switch (gimple_code(asm_data->def_stmt)) {
114026 + case GIMPLE_ASSIGN:
114027 + case GIMPLE_CALL:
114028 + replace_call_lhs(asm_data);
114029 + break;
114030 + case GIMPLE_PHI:
114031 + create_output_from_phi(stmt, argnum, asm_data);
114032 + break;
114033 + case GIMPLE_NOP: {
114034 + enum mark mark;
114035 + const char *mark_str;
114036 + char *asm_comment;
114037 +
114038 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114039 +
114040 + asm_data->input = asm_data->output;
114041 + asm_data->output = NULL;
114042 + asm_data->def_stmt = stmt;
114043 +
114044 + mark_str = convert_mark_to_str(mark);
114045 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114046 +
114047 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114048 + free(asm_comment);
114049 + asm_data->input = NULL_TREE;
114050 + break;
114051 + }
114052 + case GIMPLE_ASM:
114053 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114054 + asm_data->input = NULL_TREE;
114055 + break;
114056 + }
114057 + default:
114058 + debug_gimple_stmt(asm_data->def_stmt);
114059 + gcc_unreachable();
114060 + }
114061 +}
114062 +
114063 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114064 + * is of the right kind create the appropriate size_overflow asm stmts:
114065 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114066 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114067 + */
114068 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114069 +{
114070 + struct asm_data asm_data;
114071 + const char *mark_str;
114072 + char *asm_comment;
114073 + enum mark mark;
114074 +
114075 + if (is_gimple_constant(output_node))
114076 + return;
114077 +
114078 + asm_data.output = output_node;
114079 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114080 + if (mark != MARK_TURN_OFF)
114081 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114082 +
114083 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114084 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114085 + return;
114086 +
114087 + create_asm_input(stmt, argnum, &asm_data);
114088 + if (asm_data.input == NULL_TREE)
114089 + return;
114090 +
114091 + mark_str = convert_mark_to_str(mark);
114092 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114093 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114094 + free(asm_comment);
114095 +}
114096 +
114097 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114098 +static bool create_mark_asm(gimple stmt, enum mark mark)
114099 +{
114100 + struct asm_data asm_data;
114101 + const char *asm_str;
114102 +
114103 + switch (mark) {
114104 + case MARK_TURN_OFF:
114105 + asm_str = TURN_OFF_ASM_STR;
114106 + break;
114107 + case MARK_NOT_INTENTIONAL:
114108 + case MARK_YES:
114109 + asm_str = YES_ASM_STR;
114110 + break;
114111 + default:
114112 + gcc_unreachable();
114113 + }
114114 +
114115 + asm_data.def_stmt = stmt;
114116 + asm_data.output = gimple_call_lhs(stmt);
114117 +
114118 + if (asm_data.output == NULL_TREE) {
114119 + asm_data.input = gimple_call_arg(stmt, 0);
114120 + if (is_gimple_constant(asm_data.input))
114121 + return false;
114122 + asm_data.output = NULL;
114123 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114124 + return true;
114125 + }
114126 +
114127 + create_asm_input(stmt, 0, &asm_data);
114128 + gcc_assert(asm_data.input != NULL_TREE);
114129 +
114130 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114131 + return true;
114132 +}
114133 +
114134 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114135 +{
114136 + gimple def_stmt;
114137 +
114138 + def_stmt = get_def_stmt(lhs);
114139 + if (!def_stmt)
114140 + return;
114141 +
114142 + if (pointer_set_insert(visited, def_stmt))
114143 + return;
114144 +
114145 + switch (gimple_code(def_stmt)) {
114146 + case GIMPLE_NOP:
114147 + case GIMPLE_ASM:
114148 + case GIMPLE_CALL:
114149 + break;
114150 + case GIMPLE_PHI: {
114151 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114152 +
114153 + pointer_set_insert(visited, def_stmt);
114154 +
114155 + for (i = 0; i < n; i++) {
114156 + tree arg = gimple_phi_arg_def(def_stmt, i);
114157 +
114158 + walk_use_def_ptr(visited, arg);
114159 + }
114160 + }
114161 + case GIMPLE_ASSIGN:
114162 + switch (gimple_num_ops(def_stmt)) {
114163 + case 2:
114164 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114165 + return;
114166 + case 3:
114167 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114168 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114169 + return;
114170 + default:
114171 + return;
114172 + }
114173 + default:
114174 + debug_gimple_stmt((gimple)def_stmt);
114175 + error("%s: unknown gimple code", __func__);
114176 + gcc_unreachable();
114177 + }
114178 +}
114179 +
114180 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114181 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114182 +{
114183 + struct pointer_set_t *visited;
114184 +
114185 + visited = pointer_set_create();
114186 + walk_use_def_ptr(visited, arg);
114187 + pointer_set_destroy(visited);
114188 +}
114189 +
114190 +// Determine the return value and insert the asm stmt to mark the return stmt.
114191 +static void insert_asm_ret(gimple stmt)
114192 +{
114193 + tree ret;
114194 +
114195 + ret = gimple_return_retval(stmt);
114196 + create_size_overflow_asm(stmt, ret, 0);
114197 +}
114198 +
114199 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114200 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114201 +{
114202 + tree arg;
114203 + unsigned int argnum;
114204 +
114205 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114206 + gcc_assert(argnum != 0);
114207 + if (argnum == CANNOT_FIND_ARG)
114208 + return;
114209 +
114210 + arg = gimple_call_arg(stmt, argnum - 1);
114211 + gcc_assert(arg != NULL_TREE);
114212 +
114213 + // skip all ptr - ptr expressions
114214 + insert_mark_not_intentional_asm_at_ptr(arg);
114215 +
114216 + create_size_overflow_asm(stmt, arg, argnum);
114217 +}
114218 +
114219 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114220 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114221 +{
114222 + unsigned int argnum;
114223 + tree attr_value;
114224 +
114225 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114226 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114227 + argnums[argnum] = true;
114228 + }
114229 +}
114230 +
114231 +// If a function arg or the return value is in the hash table then set its index in the array.
114232 +static void set_argnum_hash(tree fndecl, bool *argnums)
114233 +{
114234 + unsigned int num;
114235 + const struct size_overflow_hash *hash;
114236 +
114237 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114238 + if (!hash)
114239 + return;
114240 +
114241 + for (num = 0; num <= MAX_PARAM; num++) {
114242 + if (!(hash->param & (1U << num)))
114243 + continue;
114244 +
114245 + argnums[num] = true;
114246 + }
114247 +}
114248 +
114249 +static bool is_all_the_argnums_empty(bool *argnums)
114250 +{
114251 + unsigned int i;
114252 +
114253 + for (i = 0; i <= MAX_PARAM; i++)
114254 + if (argnums[i])
114255 + return false;
114256 + return true;
114257 +}
114258 +
114259 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114260 +static void search_interesting_args(tree fndecl, bool *argnums)
114261 +{
114262 + const_tree attr;
114263 +
114264 + set_argnum_hash(fndecl, argnums);
114265 + if (!is_all_the_argnums_empty(argnums))
114266 + return;
114267 +
114268 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114269 + if (attr && TREE_VALUE(attr))
114270 + set_argnum_attribute(attr, argnums);
114271 +}
114272 +
114273 +/*
114274 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114275 + * on the callee function.
114276 + */
114277 +static bool is_mark_turn_off_attribute(gimple stmt)
114278 +{
114279 + enum mark mark;
114280 + const_tree fndecl = gimple_call_fndecl(stmt);
114281 +
114282 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114283 + if (mark == MARK_TURN_OFF)
114284 + return true;
114285 + return false;
114286 +}
114287 +
114288 +// 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
114289 +static void handle_interesting_function(gimple stmt)
114290 +{
114291 + unsigned int argnum;
114292 + tree fndecl;
114293 + bool orig_argnums[MAX_PARAM + 1] = {false};
114294 +
114295 + if (gimple_call_num_args(stmt) == 0)
114296 + return;
114297 + fndecl = gimple_call_fndecl(stmt);
114298 + if (fndecl == NULL_TREE)
114299 + return;
114300 + fndecl = DECL_ORIGIN(fndecl);
114301 +
114302 + if (is_mark_turn_off_attribute(stmt)) {
114303 + create_mark_asm(stmt, MARK_TURN_OFF);
114304 + return;
114305 + }
114306 +
114307 + search_interesting_args(fndecl, orig_argnums);
114308 +
114309 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114310 + if (orig_argnums[argnum])
114311 + insert_asm_arg(stmt, argnum);
114312 +}
114313 +
114314 +// 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
114315 +static void handle_interesting_ret(gimple stmt)
114316 +{
114317 + bool orig_argnums[MAX_PARAM + 1] = {false};
114318 +
114319 + search_interesting_args(current_function_decl, orig_argnums);
114320 +
114321 + if (orig_argnums[0])
114322 + insert_asm_ret(stmt);
114323 +}
114324 +
114325 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114326 +static unsigned int search_interesting_functions(void)
114327 +{
114328 + basic_block bb;
114329 +
114330 + FOR_ALL_BB_FN(bb, cfun) {
114331 + gimple_stmt_iterator gsi;
114332 +
114333 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114334 + gimple stmt = gsi_stmt(gsi);
114335 +
114336 + if (is_size_overflow_asm(stmt))
114337 + continue;
114338 +
114339 + if (is_gimple_call(stmt))
114340 + handle_interesting_function(stmt);
114341 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114342 + handle_interesting_ret(stmt);
114343 + }
114344 + }
114345 + return 0;
114346 +}
114347 +
114348 +/*
114349 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114350 + * this pass inserts asm stmts to mark the interesting args
114351 + * that the ipa pass will detect and insert the size overflow checks for.
114352 + */
114353 +#if BUILDING_GCC_VERSION >= 4009
114354 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114355 +#else
114356 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114357 + .pass = {
114358 +#endif
114359 + .type = GIMPLE_PASS,
114360 + .name = "insert_size_overflow_asm",
114361 +#if BUILDING_GCC_VERSION >= 4008
114362 + .optinfo_flags = OPTGROUP_NONE,
114363 +#endif
114364 +#if BUILDING_GCC_VERSION >= 4009
114365 + .has_gate = false,
114366 + .has_execute = true,
114367 +#else
114368 + .gate = NULL,
114369 + .execute = search_interesting_functions,
114370 + .sub = NULL,
114371 + .next = NULL,
114372 + .static_pass_number = 0,
114373 +#endif
114374 + .tv_id = TV_NONE,
114375 + .properties_required = PROP_cfg,
114376 + .properties_provided = 0,
114377 + .properties_destroyed = 0,
114378 + .todo_flags_start = 0,
114379 + .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
114380 +#if BUILDING_GCC_VERSION < 4009
114381 + }
114382 +#endif
114383 +};
114384 +
114385 +#if BUILDING_GCC_VERSION >= 4009
114386 +namespace {
114387 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114388 +public:
114389 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114390 + unsigned int execute() { return search_interesting_functions(); }
114391 +};
114392 +}
114393 +#endif
114394 +
114395 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114396 +{
114397 +#if BUILDING_GCC_VERSION >= 4009
114398 + return new insert_size_overflow_asm_pass();
114399 +#else
114400 + return &insert_size_overflow_asm_pass.pass;
114401 +#endif
114402 +}
114403 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
114404 new file mode 100644
114405 index 0000000..73f0a12
114406 --- /dev/null
114407 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114408 @@ -0,0 +1,943 @@
114409 +/*
114410 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114411 + * Licensed under the GPL v2, or (at your option) v3
114412 + *
114413 + * Homepage:
114414 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114415 + *
114416 + * Documentation:
114417 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114418 + *
114419 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114420 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114421 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114422 + *
114423 + * Usage:
114424 + * $ make
114425 + * $ make run
114426 + */
114427 +
114428 +#include "gcc-common.h"
114429 +#include "size_overflow.h"
114430 +
114431 +#define MIN_CHECK true
114432 +#define MAX_CHECK false
114433 +
114434 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114435 +{
114436 + const_tree type;
114437 + tree new_type;
114438 +
114439 + gcc_assert(node != NULL_TREE);
114440 +
114441 + type = TREE_TYPE(node);
114442 +
114443 + if (pointer_set_contains(visited->my_stmts, stmt))
114444 + return TREE_TYPE(node);
114445 +
114446 + switch (TYPE_MODE(type)) {
114447 + case QImode:
114448 + new_type = size_overflow_type_HI;
114449 + break;
114450 + case HImode:
114451 + new_type = size_overflow_type_SI;
114452 + break;
114453 + case SImode:
114454 + new_type = size_overflow_type_DI;
114455 + break;
114456 + case DImode:
114457 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114458 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114459 + else
114460 + new_type = size_overflow_type_TI;
114461 + break;
114462 + case TImode:
114463 + gcc_assert(!TYPE_UNSIGNED(type));
114464 + new_type = size_overflow_type_TI;
114465 + break;
114466 + default:
114467 + debug_tree((tree)node);
114468 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114469 + gcc_unreachable();
114470 + }
114471 +
114472 + if (TYPE_QUALS(type) != 0)
114473 + return build_qualified_type(new_type, TYPE_QUALS(type));
114474 + return new_type;
114475 +}
114476 +
114477 +static tree get_lhs(const_gimple stmt)
114478 +{
114479 + switch (gimple_code(stmt)) {
114480 + case GIMPLE_ASSIGN:
114481 + case GIMPLE_CALL:
114482 + return gimple_get_lhs(stmt);
114483 + case GIMPLE_PHI:
114484 + return gimple_phi_result(stmt);
114485 + default:
114486 + return NULL_TREE;
114487 + }
114488 +}
114489 +
114490 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
114491 +{
114492 + gimple_stmt_iterator gsi;
114493 + tree lhs;
114494 + gimple new_stmt;
114495 +
114496 + if (rhs == NULL_TREE)
114497 + return NULL_TREE;
114498 +
114499 + gsi = gsi_for_stmt(stmt);
114500 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114501 + pointer_set_insert(visited->my_stmts, new_stmt);
114502 +
114503 + lhs = get_lhs(new_stmt);
114504 + gcc_assert(lhs != NULL_TREE);
114505 + return lhs;
114506 +}
114507 +
114508 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
114509 +{
114510 + tree lhs, dst_type;
114511 + gimple_stmt_iterator gsi;
114512 +
114513 + if (rhs1 == NULL_TREE) {
114514 + debug_gimple_stmt(oldstmt);
114515 + error("%s: rhs1 is NULL_TREE", __func__);
114516 + gcc_unreachable();
114517 + }
114518 +
114519 + switch (gimple_code(oldstmt)) {
114520 + case GIMPLE_ASM:
114521 + lhs = rhs1;
114522 + break;
114523 + case GIMPLE_CALL:
114524 + case GIMPLE_ASSIGN:
114525 + lhs = gimple_get_lhs(oldstmt);
114526 + break;
114527 + default:
114528 + debug_gimple_stmt(oldstmt);
114529 + gcc_unreachable();
114530 + }
114531 +
114532 + gsi = gsi_for_stmt(oldstmt);
114533 + pointer_set_insert(visited->stmts, oldstmt);
114534 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114535 + basic_block next_bb, cur_bb;
114536 + const_edge e;
114537 +
114538 + gcc_assert(before == false);
114539 + gcc_assert(stmt_can_throw_internal(oldstmt));
114540 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114541 + gcc_assert(!gsi_end_p(gsi));
114542 +
114543 + cur_bb = gimple_bb(oldstmt);
114544 + next_bb = cur_bb->next_bb;
114545 + e = find_edge(cur_bb, next_bb);
114546 + gcc_assert(e != NULL);
114547 + gcc_assert(e->flags & EDGE_FALLTHRU);
114548 +
114549 + gsi = gsi_after_labels(next_bb);
114550 + gcc_assert(!gsi_end_p(gsi));
114551 +
114552 + before = true;
114553 + oldstmt = gsi_stmt(gsi);
114554 + }
114555 +
114556 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
114557 +
114558 + if (is_gimple_constant(rhs1))
114559 + return cast_a_tree(dst_type, rhs1);
114560 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
114561 +}
114562 +
114563 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114564 +{
114565 + gimple stmt;
114566 + gimple_stmt_iterator gsi;
114567 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114568 +
114569 + if (pointer_set_contains(visited->my_stmts, oldstmt))
114570 + return lhs;
114571 +
114572 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114573 + rhs1 = gimple_assign_rhs1(oldstmt);
114574 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114575 + }
114576 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114577 + rhs2 = gimple_assign_rhs2(oldstmt);
114578 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114579 + }
114580 +
114581 + stmt = gimple_copy(oldstmt);
114582 + gimple_set_location(stmt, gimple_location(oldstmt));
114583 + pointer_set_insert(visited->my_stmts, stmt);
114584 +
114585 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
114586 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
114587 +
114588 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
114589 +
114590 + new_var = create_new_var(size_overflow_type);
114591 + new_var = make_ssa_name(new_var, stmt);
114592 + gimple_assign_set_lhs(stmt, new_var);
114593 +
114594 + if (rhs1 != NULL_TREE)
114595 + gimple_assign_set_rhs1(stmt, rhs1);
114596 +
114597 + if (rhs2 != NULL_TREE)
114598 + gimple_assign_set_rhs2(stmt, rhs2);
114599 +#if BUILDING_GCC_VERSION >= 4006
114600 + if (rhs3 != NULL_TREE)
114601 + gimple_assign_set_rhs3(stmt, rhs3);
114602 +#endif
114603 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
114604 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
114605 +
114606 + gsi = gsi_for_stmt(oldstmt);
114607 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
114608 + update_stmt(stmt);
114609 + pointer_set_insert(visited->stmts, oldstmt);
114610 + return gimple_assign_lhs(stmt);
114611 +}
114612 +
114613 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
114614 +{
114615 + gimple assign;
114616 + gimple_stmt_iterator gsi;
114617 + basic_block first_bb;
114618 +
114619 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
114620 +
114621 + if (bb->index == 0) {
114622 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
114623 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114624 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
114625 + bb = first_bb;
114626 + }
114627 +
114628 + gsi = gsi_after_labels(bb);
114629 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
114630 + pointer_set_insert(visited->my_stmts, assign);
114631 +
114632 + return gimple_assign_lhs(assign);
114633 +}
114634 +
114635 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
114636 +{
114637 + gimple_stmt_iterator gsi;
114638 + gimple assign, def_stmt = get_def_stmt(new_arg);
114639 +
114640 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114641 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114642 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114643 + } else {
114644 + gsi = gsi_for_stmt(def_stmt);
114645 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114646 + }
114647 +
114648 + pointer_set_insert(visited->my_stmts, assign);
114649 + return gimple_assign_lhs(assign);
114650 +}
114651 +
114652 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
114653 +{
114654 + basic_block bb;
114655 + gimple_stmt_iterator gsi;
114656 + const_gimple def_stmt;
114657 + gimple assign;
114658 +
114659 + def_stmt = get_def_stmt(arg);
114660 + bb = gimple_bb(def_stmt);
114661 + gcc_assert(bb->index != 0);
114662 + gsi = gsi_after_labels(bb);
114663 +
114664 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114665 + pointer_set_insert(visited->my_stmts, assign);
114666 + return gimple_assign_lhs(assign);
114667 +}
114668 +
114669 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114670 +{
114671 + tree size_overflow_type;
114672 + tree arg;
114673 + const_gimple def_stmt;
114674 +
114675 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114676 + return new_arg;
114677 +
114678 + arg = gimple_phi_arg_def(oldstmt, i);
114679 + def_stmt = get_def_stmt(arg);
114680 + gcc_assert(def_stmt != NULL);
114681 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114682 +
114683 + switch (gimple_code(def_stmt)) {
114684 + case GIMPLE_PHI:
114685 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
114686 + case GIMPLE_NOP: {
114687 + basic_block bb;
114688 +
114689 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114690 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
114691 + }
114692 + case GIMPLE_ASM: {
114693 + gimple_stmt_iterator gsi;
114694 + gimple assign, stmt = get_def_stmt(arg);
114695 +
114696 + gsi = gsi_for_stmt(stmt);
114697 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114698 + pointer_set_insert(visited->my_stmts, assign);
114699 + return gimple_assign_lhs(assign);
114700 + }
114701 + default:
114702 + gcc_assert(new_arg != NULL_TREE);
114703 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114704 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
114705 + }
114706 +}
114707 +
114708 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
114709 +{
114710 + basic_block bb;
114711 + gimple phi;
114712 + gimple_seq seq;
114713 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114714 +
114715 + bb = gsi_bb(gsi);
114716 +
114717 + if (result == NULL_TREE) {
114718 + tree old_result = gimple_phi_result(oldstmt);
114719 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
114720 +
114721 + result = create_new_var(size_overflow_type);
114722 + }
114723 +
114724 + phi = create_phi_node(result, bb);
114725 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114726 + seq = phi_nodes(bb);
114727 + gsi = gsi_last(seq);
114728 + gsi_remove(&gsi, false);
114729 +
114730 + gsi = gsi_for_stmt(oldstmt);
114731 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114732 + gimple_set_bb(phi, bb);
114733 + return phi;
114734 +}
114735 +
114736 +#if BUILDING_GCC_VERSION <= 4007
114737 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114738 +#else
114739 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114740 +#endif
114741 +{
114742 + gimple new_phi;
114743 + unsigned int i;
114744 + tree arg, result;
114745 + location_t loc = gimple_location(oldstmt);
114746 +
114747 +#if BUILDING_GCC_VERSION <= 4007
114748 + gcc_assert(!VEC_empty(tree, *args));
114749 +#else
114750 + gcc_assert(!args->is_empty());
114751 +#endif
114752 +
114753 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
114754 + result = gimple_phi_result(new_phi);
114755 + ssa_name_var = SSA_NAME_VAR(result);
114756 +
114757 +#if BUILDING_GCC_VERSION <= 4007
114758 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114759 +#else
114760 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114761 +#endif
114762 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
114763 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114764 + }
114765 +
114766 +#if BUILDING_GCC_VERSION <= 4007
114767 + VEC_free(tree, heap, *args);
114768 +#else
114769 + vec_free(args);
114770 +#endif
114771 + update_stmt(new_phi);
114772 + pointer_set_insert(visited->my_stmts, new_phi);
114773 + return result;
114774 +}
114775 +
114776 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
114777 +{
114778 + tree ssa_name_var = NULL_TREE;
114779 +#if BUILDING_GCC_VERSION <= 4007
114780 + VEC(tree, heap) *args = NULL;
114781 +#else
114782 + vec<tree, va_heap, vl_embed> *args = NULL;
114783 +#endif
114784 + gimple oldstmt = get_def_stmt(orig_result);
114785 + unsigned int i, len = gimple_phi_num_args(oldstmt);
114786 +
114787 + pointer_set_insert(visited->stmts, oldstmt);
114788 + for (i = 0; i < len; i++) {
114789 + tree arg, new_arg;
114790 +
114791 + arg = gimple_phi_arg_def(oldstmt, i);
114792 + new_arg = expand(visited, caller_node, arg);
114793 +
114794 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
114795 + ssa_name_var = SSA_NAME_VAR(new_arg);
114796 +
114797 + if (is_gimple_constant(arg)) {
114798 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114799 +
114800 + new_arg = cast_a_tree(size_overflow_type, arg);
114801 + }
114802 +
114803 +#if BUILDING_GCC_VERSION <= 4007
114804 + VEC_safe_push(tree, heap, args, new_arg);
114805 +#else
114806 + vec_safe_push(args, new_arg);
114807 +#endif
114808 + }
114809 +
114810 +#if BUILDING_GCC_VERSION <= 4007
114811 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
114812 +#else
114813 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
114814 +#endif
114815 +}
114816 +
114817 +static tree create_cast_assign(struct visited *visited, gimple stmt)
114818 +{
114819 + tree rhs1 = gimple_assign_rhs1(stmt);
114820 + tree lhs = gimple_assign_lhs(stmt);
114821 + const_tree rhs1_type = TREE_TYPE(rhs1);
114822 + const_tree lhs_type = TREE_TYPE(lhs);
114823 +
114824 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
114825 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114826 +
114827 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
114828 +}
114829 +
114830 +static bool skip_lhs_cast_check(const_gimple stmt)
114831 +{
114832 + const_tree rhs = gimple_assign_rhs1(stmt);
114833 + const_gimple def_stmt = get_def_stmt(rhs);
114834 +
114835 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
114836 + if (gimple_code(def_stmt) == GIMPLE_ASM)
114837 + return true;
114838 +
114839 + if (is_const_plus_unsigned_signed_truncation(rhs))
114840 + return true;
114841 +
114842 + return false;
114843 +}
114844 +
114845 +static tree create_string_param(tree string)
114846 +{
114847 + tree i_type, a_type;
114848 + const int length = TREE_STRING_LENGTH(string);
114849 +
114850 + gcc_assert(length > 0);
114851 +
114852 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
114853 + a_type = build_array_type(char_type_node, i_type);
114854 +
114855 + TREE_TYPE(string) = a_type;
114856 + TREE_CONSTANT(string) = 1;
114857 + TREE_READONLY(string) = 1;
114858 +
114859 + return build1(ADDR_EXPR, ptr_type_node, string);
114860 +}
114861 +
114862 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
114863 +{
114864 + gimple cond_stmt;
114865 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
114866 +
114867 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
114868 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
114869 + update_stmt(cond_stmt);
114870 +}
114871 +
114872 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
114873 +{
114874 + gimple func_stmt;
114875 + const_gimple def_stmt;
114876 + const_tree loc_line;
114877 + tree loc_file, ssa_name, current_func;
114878 + expanded_location xloc;
114879 + char *ssa_name_buf;
114880 + int len;
114881 + struct cgraph_edge *edge;
114882 + struct cgraph_node *callee_node;
114883 + int frequency;
114884 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
114885 +
114886 + def_stmt = get_def_stmt(arg);
114887 + xloc = expand_location(gimple_location(def_stmt));
114888 +
114889 + if (!gimple_has_location(def_stmt)) {
114890 + xloc = expand_location(gimple_location(stmt));
114891 + if (!gimple_has_location(stmt))
114892 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
114893 + }
114894 +
114895 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
114896 +
114897 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
114898 + loc_file = create_string_param(loc_file);
114899 +
114900 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
114901 + current_func = create_string_param(current_func);
114902 +
114903 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
114904 + call_count++;
114905 + 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);
114906 + gcc_assert(len > 0);
114907 + ssa_name = build_string(len + 1, ssa_name_buf);
114908 + free(ssa_name_buf);
114909 + ssa_name = create_string_param(ssa_name);
114910 +
114911 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
114912 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
114913 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
114914 +
114915 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
114916 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
114917 +
114918 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
114919 + gcc_assert(edge != NULL);
114920 +}
114921 +
114922 +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)
114923 +{
114924 + basic_block cond_bb, join_bb, bb_true;
114925 + edge e;
114926 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114927 +
114928 + cond_bb = gimple_bb(stmt);
114929 + if (before)
114930 + gsi_prev(&gsi);
114931 + if (gsi_end_p(gsi))
114932 + e = split_block_after_labels(cond_bb);
114933 + else
114934 + e = split_block(cond_bb, gsi_stmt(gsi));
114935 + cond_bb = e->src;
114936 + join_bb = e->dest;
114937 + e->flags = EDGE_FALSE_VALUE;
114938 + e->probability = REG_BR_PROB_BASE;
114939 +
114940 + bb_true = create_empty_bb(cond_bb);
114941 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
114942 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
114943 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
114944 +
114945 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114946 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
114947 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
114948 +
114949 + if (current_loops != NULL) {
114950 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
114951 + add_bb_to_loop(bb_true, cond_bb->loop_father);
114952 + }
114953 +
114954 + insert_cond(cond_bb, arg, cond_code, type_value);
114955 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
114956 +
114957 +// print_the_code_insertions(stmt);
114958 +}
114959 +
114960 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
114961 +{
114962 + const_tree rhs_type = TREE_TYPE(rhs);
114963 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
114964 +
114965 + gcc_assert(rhs_type != NULL_TREE);
114966 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
114967 + return;
114968 +
114969 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
114970 +
114971 + if (is_const_plus_unsigned_signed_truncation(rhs))
114972 + return;
114973 +
114974 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
114975 + // typemax (-1) < typemin (0)
114976 + if (TREE_OVERFLOW(type_max))
114977 + return;
114978 +
114979 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
114980 +
114981 + cast_rhs_type = TREE_TYPE(cast_rhs);
114982 + type_max_type = TREE_TYPE(type_max);
114983 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
114984 +
114985 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
114986 +
114987 + // special case: get_size_overflow_type(), 32, u64->s
114988 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
114989 + return;
114990 +
114991 + type_min_type = TREE_TYPE(type_min);
114992 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
114993 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
114994 +}
114995 +
114996 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
114997 +{
114998 + bool cast_lhs, cast_rhs;
114999 + tree lhs = gimple_assign_lhs(stmt);
115000 + tree rhs = gimple_assign_rhs1(stmt);
115001 + const_tree lhs_type = TREE_TYPE(lhs);
115002 + const_tree rhs_type = TREE_TYPE(rhs);
115003 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115004 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115005 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115006 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115007 +
115008 + static bool check_lhs[3][4] = {
115009 + // ss su us uu
115010 + { false, true, true, false }, // lhs > rhs
115011 + { false, false, false, false }, // lhs = rhs
115012 + { true, true, true, true }, // lhs < rhs
115013 + };
115014 +
115015 + static bool check_rhs[3][4] = {
115016 + // ss su us uu
115017 + { true, false, true, true }, // lhs > rhs
115018 + { true, false, true, true }, // lhs = rhs
115019 + { true, false, true, true }, // lhs < rhs
115020 + };
115021 +
115022 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115023 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115024 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115025 +
115026 + if (lhs_size > rhs_size) {
115027 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115028 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115029 + } else if (lhs_size == rhs_size) {
115030 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115031 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115032 + } else {
115033 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115034 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115035 + }
115036 +
115037 + if (!cast_lhs && !cast_rhs)
115038 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115039 +
115040 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115041 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115042 +
115043 + if (cast_rhs)
115044 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115045 +
115046 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115047 +}
115048 +
115049 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115050 +{
115051 + enum tree_code rhs_code;
115052 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115053 +
115054 + if (pointer_set_contains(visited->my_stmts, stmt))
115055 + return lhs;
115056 +
115057 + rhs1 = gimple_assign_rhs1(stmt);
115058 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115059 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115060 +
115061 + new_rhs1 = expand(visited, caller_node, rhs1);
115062 +
115063 + if (new_rhs1 == NULL_TREE)
115064 + return create_cast_assign(visited, stmt);
115065 +
115066 + if (pointer_set_contains(visited->no_cast_check, stmt))
115067 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115068 +
115069 + rhs_code = gimple_assign_rhs_code(stmt);
115070 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115071 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115072 +
115073 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115074 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115075 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115076 + }
115077 +
115078 + if (!gimple_assign_cast_p(stmt))
115079 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115080 +
115081 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115082 +}
115083 +
115084 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115085 +{
115086 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115087 + gimple def_stmt = get_def_stmt(lhs);
115088 +
115089 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115090 + rhs1 = gimple_assign_rhs1(def_stmt);
115091 +
115092 + if (is_gimple_constant(rhs1))
115093 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115094 +
115095 + switch (TREE_CODE(rhs1)) {
115096 + case SSA_NAME: {
115097 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115098 +
115099 + if (gimple_assign_cast_p(stmt))
115100 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115101 + return ret;
115102 + }
115103 + case ARRAY_REF:
115104 + case BIT_FIELD_REF:
115105 + case ADDR_EXPR:
115106 + case COMPONENT_REF:
115107 + case INDIRECT_REF:
115108 +#if BUILDING_GCC_VERSION >= 4006
115109 + case MEM_REF:
115110 +#endif
115111 + case TARGET_MEM_REF:
115112 + case VIEW_CONVERT_EXPR:
115113 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115114 + case PARM_DECL:
115115 + case VAR_DECL:
115116 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115117 +
115118 + default:
115119 + debug_gimple_stmt(def_stmt);
115120 + debug_tree(rhs1);
115121 + gcc_unreachable();
115122 + }
115123 +}
115124 +
115125 +static void __unused print_the_code_insertions(const_gimple stmt)
115126 +{
115127 + location_t loc = gimple_location(stmt);
115128 +
115129 + inform(loc, "Integer size_overflow check applied here.");
115130 +}
115131 +
115132 +static bool is_from_cast(const_tree node)
115133 +{
115134 + gimple def_stmt = get_def_stmt(node);
115135 +
115136 + if (!def_stmt)
115137 + return false;
115138 +
115139 + if (gimple_assign_cast_p(def_stmt))
115140 + return true;
115141 +
115142 + return false;
115143 +}
115144 +
115145 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115146 +static bool is_a_ptr_minus(gimple stmt)
115147 +{
115148 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115149 +
115150 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115151 + return false;
115152 +
115153 + rhs1 = gimple_assign_rhs1(stmt);
115154 + if (!is_from_cast(rhs1))
115155 + return false;
115156 +
115157 + rhs2 = gimple_assign_rhs2(stmt);
115158 + if (!is_from_cast(rhs2))
115159 + return false;
115160 +
115161 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115162 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115163 +
115164 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115165 + return false;
115166 +
115167 + return true;
115168 +}
115169 +
115170 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115171 +{
115172 + enum intentional_overflow_type res;
115173 + tree rhs1, rhs2, new_lhs;
115174 + gimple def_stmt = get_def_stmt(lhs);
115175 + tree new_rhs1 = NULL_TREE;
115176 + tree new_rhs2 = NULL_TREE;
115177 +
115178 + if (is_a_ptr_minus(def_stmt))
115179 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115180 +
115181 + rhs1 = gimple_assign_rhs1(def_stmt);
115182 + rhs2 = gimple_assign_rhs2(def_stmt);
115183 +
115184 + /* no DImode/TImode division in the 32/64 bit kernel */
115185 + switch (gimple_assign_rhs_code(def_stmt)) {
115186 + case RDIV_EXPR:
115187 + case TRUNC_DIV_EXPR:
115188 + case CEIL_DIV_EXPR:
115189 + case FLOOR_DIV_EXPR:
115190 + case ROUND_DIV_EXPR:
115191 + case TRUNC_MOD_EXPR:
115192 + case CEIL_MOD_EXPR:
115193 + case FLOOR_MOD_EXPR:
115194 + case ROUND_MOD_EXPR:
115195 + case EXACT_DIV_EXPR:
115196 + case POINTER_PLUS_EXPR:
115197 + case BIT_AND_EXPR:
115198 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115199 + default:
115200 + break;
115201 + }
115202 +
115203 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115204 + if (new_lhs != NULL_TREE)
115205 + return new_lhs;
115206 +
115207 + if (TREE_CODE(rhs1) == SSA_NAME)
115208 + new_rhs1 = expand(visited, caller_node, rhs1);
115209 + if (TREE_CODE(rhs2) == SSA_NAME)
115210 + new_rhs2 = expand(visited, caller_node, rhs2);
115211 +
115212 + res = add_mul_intentional_overflow(def_stmt);
115213 + if (res != NO_INTENTIONAL_OVERFLOW) {
115214 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115215 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115216 + return new_lhs;
115217 + }
115218 +
115219 + if (skip_expr_on_double_type(def_stmt)) {
115220 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115221 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115222 + return new_lhs;
115223 + }
115224 +
115225 + if (is_a_neg_overflow(def_stmt, rhs2))
115226 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115227 + if (is_a_neg_overflow(def_stmt, rhs1))
115228 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115229 +
115230 +
115231 + if (is_a_constant_overflow(def_stmt, rhs2))
115232 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115233 + if (is_a_constant_overflow(def_stmt, rhs1))
115234 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115235 +
115236 + // the const is between 0 and (signed) MAX
115237 + if (is_gimple_constant(rhs1))
115238 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115239 + if (is_gimple_constant(rhs2))
115240 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115241 +
115242 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115243 +}
115244 +
115245 +#if BUILDING_GCC_VERSION >= 4006
115246 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115247 +{
115248 + if (is_gimple_constant(rhs))
115249 + return cast_a_tree(size_overflow_type, rhs);
115250 + if (TREE_CODE(rhs) != SSA_NAME)
115251 + return NULL_TREE;
115252 + return expand(visited, caller_node, rhs);
115253 +}
115254 +
115255 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115256 +{
115257 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115258 + gimple def_stmt = get_def_stmt(lhs);
115259 +
115260 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115261 +
115262 + rhs1 = gimple_assign_rhs1(def_stmt);
115263 + rhs2 = gimple_assign_rhs2(def_stmt);
115264 + rhs3 = gimple_assign_rhs3(def_stmt);
115265 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115266 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115267 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115268 +
115269 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115270 +}
115271 +#endif
115272 +
115273 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115274 +{
115275 + gimple_stmt_iterator gsi;
115276 + gimple next_stmt = NULL;
115277 +
115278 + gsi = gsi_for_stmt(stmt);
115279 +
115280 + do {
115281 + gsi_next(&gsi);
115282 + next_stmt = gsi_stmt(gsi);
115283 +
115284 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115285 + return NULL_TREE;
115286 +
115287 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115288 + break;
115289 +
115290 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115291 + } while (!gsi_end_p(gsi));
115292 +
115293 + gcc_assert(next_stmt);
115294 + return get_lhs(next_stmt);
115295 +}
115296 +
115297 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115298 +{
115299 + gimple_stmt_iterator gsi;
115300 + enum gimple_code code = gimple_code(def_stmt);
115301 +
115302 + if (code == GIMPLE_ASM)
115303 + return NULL_TREE;
115304 +
115305 + gsi = gsi_for_stmt(def_stmt);
115306 + gsi_next(&gsi);
115307 +
115308 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115309 + return NULL_TREE;
115310 + return get_my_stmt_lhs(visited, def_stmt);
115311 +}
115312 +
115313 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115314 +{
115315 + gimple def_stmt;
115316 +
115317 + def_stmt = get_def_stmt(lhs);
115318 +
115319 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115320 + return NULL_TREE;
115321 +
115322 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115323 + return lhs;
115324 +
115325 + if (pointer_set_contains(visited->stmts, def_stmt))
115326 + return expand_visited(visited, def_stmt);
115327 +
115328 + switch (gimple_code(def_stmt)) {
115329 + case GIMPLE_PHI:
115330 + return handle_phi(visited, caller_node, lhs);
115331 + case GIMPLE_CALL:
115332 + case GIMPLE_ASM:
115333 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115334 + case GIMPLE_ASSIGN:
115335 + switch (gimple_num_ops(def_stmt)) {
115336 + case 2:
115337 + return handle_unary_ops(visited, caller_node, def_stmt);
115338 + case 3:
115339 + return handle_binary_ops(visited, caller_node, lhs);
115340 +#if BUILDING_GCC_VERSION >= 4006
115341 + case 4:
115342 + return handle_ternary_ops(visited, caller_node, lhs);
115343 +#endif
115344 + }
115345 + default:
115346 + debug_gimple_stmt(def_stmt);
115347 + error("%s: unknown gimple code", __func__);
115348 + gcc_unreachable();
115349 + }
115350 +}
115351 +
115352 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
115353 new file mode 100644
115354 index 0000000..df50164
115355 --- /dev/null
115356 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115357 @@ -0,0 +1,1141 @@
115358 +/*
115359 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115360 + * Licensed under the GPL v2, or (at your option) v3
115361 + *
115362 + * Homepage:
115363 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115364 + *
115365 + * Documentation:
115366 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115367 + *
115368 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115369 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115370 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115371 + *
115372 + * Usage:
115373 + * $ make
115374 + * $ make run
115375 + */
115376 +
115377 +#include "gcc-common.h"
115378 +#include "size_overflow.h"
115379 +
115380 +#define VEC_LEN 128
115381 +#define RET_CHECK NULL_TREE
115382 +#define WRONG_NODE 32
115383 +#define NOT_INTENTIONAL_ASM NULL
115384 +
115385 +unsigned int call_count;
115386 +
115387 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115388 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115389 +
115390 +struct visited_fns {
115391 + struct visited_fns *next;
115392 + const_tree fndecl;
115393 + unsigned int num;
115394 + const_gimple first_stmt;
115395 +};
115396 +
115397 +struct next_cgraph_node {
115398 + struct next_cgraph_node *next;
115399 + struct cgraph_node *current_function;
115400 + tree callee_fndecl;
115401 + unsigned int num;
115402 +};
115403 +
115404 +// Don't want to duplicate entries in next_cgraph_node
115405 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115406 +{
115407 + const_tree new_callee_fndecl;
115408 + struct next_cgraph_node *cur_node;
115409 +
115410 + if (fndecl == RET_CHECK)
115411 + new_callee_fndecl = NODE_DECL(node);
115412 + else
115413 + new_callee_fndecl = fndecl;
115414 +
115415 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115416 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115417 + continue;
115418 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115419 + continue;
115420 + if (num == cur_node->num)
115421 + return true;
115422 + }
115423 + return false;
115424 +}
115425 +
115426 +/* Add a next_cgraph_node into the list for handle_function().
115427 + * handle_function() iterates over all the next cgraph nodes and
115428 + * starts the overflow check insertion process.
115429 + */
115430 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115431 +{
115432 + struct next_cgraph_node *new_node;
115433 +
115434 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115435 + return head;
115436 +
115437 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115438 + new_node->current_function = node;
115439 + new_node->next = NULL;
115440 + new_node->num = num;
115441 + if (fndecl == RET_CHECK)
115442 + new_node->callee_fndecl = NODE_DECL(node);
115443 + else
115444 + new_node->callee_fndecl = fndecl;
115445 +
115446 + if (!head)
115447 + return new_node;
115448 +
115449 + new_node->next = head;
115450 + return new_node;
115451 +}
115452 +
115453 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115454 +{
115455 + struct cgraph_edge *e;
115456 +
115457 + if (num == 0)
115458 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115459 +
115460 + for (e = node->callers; e; e = e->next_caller) {
115461 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115462 +
115463 + gcc_assert(fndecl != NULL_TREE);
115464 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115465 + }
115466 +
115467 + return head;
115468 +}
115469 +
115470 +struct missing_functions {
115471 + struct missing_functions *next;
115472 + const_tree node;
115473 + tree fndecl;
115474 +};
115475 +
115476 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115477 +{
115478 + struct missing_functions *new_function;
115479 +
115480 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115481 + new_function->node = node;
115482 + new_function->next = NULL;
115483 +
115484 + if (TREE_CODE(node) == FUNCTION_DECL)
115485 + new_function->fndecl = node;
115486 + else
115487 + new_function->fndecl = current_function_decl;
115488 + gcc_assert(new_function->fndecl);
115489 +
115490 + if (!missing_fn_head)
115491 + return new_function;
115492 +
115493 + new_function->next = missing_fn_head;
115494 + return new_function;
115495 +}
115496 +
115497 +/* If the function is missing from the hash table and it is a static function
115498 + * then create a next_cgraph_node from it for handle_function()
115499 + */
115500 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115501 +{
115502 + unsigned int num;
115503 + const_tree orig_fndecl;
115504 + struct cgraph_node *next_node = NULL;
115505 +
115506 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115507 +
115508 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115509 + if (num == CANNOT_FIND_ARG)
115510 + return cnodes;
115511 +
115512 + if (!is_missing_function(orig_fndecl, num))
115513 + return cnodes;
115514 +
115515 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115516 + if (next_node && next_node->local.local)
115517 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115518 + return cnodes;
115519 +}
115520 +
115521 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115522 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115523 + */
115524 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115525 +{
115526 + unsigned int i;
115527 + tree node;
115528 + struct missing_functions *cur, *missing_fn_head = NULL;
115529 +
115530 +#if BUILDING_GCC_VERSION <= 4007
115531 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115532 +#else
115533 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115534 +#endif
115535 + switch (TREE_CODE(node)) {
115536 + case PARM_DECL:
115537 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115538 + break;
115539 + case FUNCTION_DECL:
115540 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115541 + break;
115542 + default:
115543 + break;
115544 + }
115545 + }
115546 +
115547 + while (missing_fn_head) {
115548 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115549 +
115550 + cur = missing_fn_head->next;
115551 + free(missing_fn_head);
115552 + missing_fn_head = cur;
115553 + }
115554 +
115555 + return cnodes;
115556 +}
115557 +
115558 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115559 +{
115560 + gimple phi = get_def_stmt(result);
115561 + unsigned int i, n = gimple_phi_num_args(phi);
115562 +
115563 + pointer_set_insert(visited, phi);
115564 + for (i = 0; i < n; i++) {
115565 + const_tree arg = gimple_phi_arg_def(phi, i);
115566 +
115567 + set_conditions(visited, interesting_conditions, arg);
115568 + }
115569 +}
115570 +
115571 +enum conditions {
115572 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
115573 +};
115574 +
115575 +// Search for constants, cast assignments and binary/ternary assignments
115576 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
115577 +{
115578 + gimple def_stmt = get_def_stmt(lhs);
115579 +
115580 + if (is_gimple_constant(lhs)) {
115581 + interesting_conditions[FROM_CONST] = true;
115582 + return;
115583 + }
115584 +
115585 + if (!def_stmt)
115586 + return;
115587 +
115588 + if (pointer_set_contains(visited, def_stmt))
115589 + return;
115590 +
115591 + switch (gimple_code(def_stmt)) {
115592 + case GIMPLE_CALL:
115593 + if (lhs == gimple_call_lhs(def_stmt))
115594 + interesting_conditions[RET] = true;
115595 + return;
115596 + case GIMPLE_NOP:
115597 + case GIMPLE_ASM:
115598 + return;
115599 + case GIMPLE_PHI:
115600 + interesting_conditions[PHI] = true;
115601 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
115602 + case GIMPLE_ASSIGN:
115603 + if (gimple_num_ops(def_stmt) == 2) {
115604 + const_tree rhs = gimple_assign_rhs1(def_stmt);
115605 +
115606 + if (gimple_assign_cast_p(def_stmt))
115607 + interesting_conditions[CAST] = true;
115608 +
115609 + return set_conditions(visited, interesting_conditions, rhs);
115610 + } else {
115611 + interesting_conditions[NOT_UNARY] = true;
115612 + return;
115613 + }
115614 + default:
115615 + debug_gimple_stmt(def_stmt);
115616 + gcc_unreachable();
115617 + }
115618 +}
115619 +
115620 +// determine whether duplication will be necessary or not.
115621 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
115622 +{
115623 + struct pointer_set_t *visited;
115624 +
115625 + if (gimple_assign_cast_p(cur_node->first_stmt))
115626 + interesting_conditions[CAST] = true;
115627 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
115628 + interesting_conditions[NOT_UNARY] = true;
115629 +
115630 + visited = pointer_set_create();
115631 + set_conditions(visited, interesting_conditions, cur_node->node);
115632 + pointer_set_destroy(visited);
115633 +}
115634 +
115635 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
115636 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
115637 +{
115638 + gimple assign;
115639 + gimple_stmt_iterator gsi;
115640 +
115641 + // already removed
115642 + if (gimple_bb(asm_stmt) == NULL)
115643 + return;
115644 + gsi = gsi_for_stmt(asm_stmt);
115645 +
115646 + assign = gimple_build_assign(lhs, rhs);
115647 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
115648 + SSA_NAME_DEF_STMT(lhs) = assign;
115649 +
115650 + gsi_remove(&gsi, true);
115651 +}
115652 +
115653 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
115654 + * stmt is a return otherwise it is the callee function.
115655 + */
115656 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
115657 +{
115658 + const_tree fndecl;
115659 +
115660 + if (argnum == 0)
115661 + fndecl = current_function_decl;
115662 + else
115663 + fndecl = gimple_call_fndecl(stmt);
115664 +
115665 + if (fndecl == NULL_TREE)
115666 + return NULL_TREE;
115667 +
115668 + return DECL_ORIGIN(fndecl);
115669 +}
115670 +
115671 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115672 +static bool skip_asm(const_tree arg)
115673 +{
115674 + gimple def_stmt = get_def_stmt(arg);
115675 +
115676 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115677 + return false;
115678 +
115679 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115680 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115681 +}
115682 +
115683 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115684 +{
115685 + gimple phi = get_def_stmt(result);
115686 + unsigned int i, n = gimple_phi_num_args(phi);
115687 +
115688 + pointer_set_insert(visited, phi);
115689 + for (i = 0; i < n; i++) {
115690 + tree arg = gimple_phi_arg_def(phi, i);
115691 +
115692 + walk_use_def(visited, cur_node, arg);
115693 + }
115694 +}
115695 +
115696 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115697 +{
115698 + gimple def_stmt = get_def_stmt(lhs);
115699 + tree rhs1, rhs2;
115700 +
115701 + rhs1 = gimple_assign_rhs1(def_stmt);
115702 + rhs2 = gimple_assign_rhs2(def_stmt);
115703 +
115704 + walk_use_def(visited, cur_node, rhs1);
115705 + walk_use_def(visited, cur_node, rhs2);
115706 +}
115707 +
115708 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115709 +{
115710 + unsigned int i;
115711 + tree element;
115712 + enum tree_code code;
115713 +
115714 + gcc_assert(node != NULL_TREE);
115715 +
115716 + if (is_gimple_constant(node))
115717 + return;
115718 +
115719 + code = TREE_CODE(node);
115720 + if (code == VAR_DECL) {
115721 + node = DECL_ORIGIN(node);
115722 + code = TREE_CODE(node);
115723 + }
115724 +
115725 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115726 + return;
115727 +
115728 +#if BUILDING_GCC_VERSION <= 4007
115729 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115730 +#else
115731 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115732 +#endif
115733 + if (operand_equal_p(node, element, 0))
115734 + return;
115735 + }
115736 +
115737 +#if BUILDING_GCC_VERSION <= 4007
115738 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115739 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115740 +#else
115741 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115742 + vec_safe_push(cur_node->last_nodes, node);
115743 +#endif
115744 +}
115745 +
115746 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115747 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115748 +{
115749 + if (!is_size_overflow_asm(stmt))
115750 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115751 +}
115752 +
115753 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115754 + * and component refs (for checking the intentional_overflow attribute).
115755 + */
115756 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115757 +{
115758 + const_gimple def_stmt;
115759 +
115760 + if (TREE_CODE(lhs) != SSA_NAME) {
115761 + insert_last_node(cur_node, lhs);
115762 + return;
115763 + }
115764 +
115765 + def_stmt = get_def_stmt(lhs);
115766 + if (!def_stmt)
115767 + return;
115768 +
115769 + if (pointer_set_insert(visited, def_stmt))
115770 + return;
115771 +
115772 + switch (gimple_code(def_stmt)) {
115773 + case GIMPLE_NOP:
115774 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115775 + case GIMPLE_ASM:
115776 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115777 + case GIMPLE_CALL: {
115778 + tree fndecl = gimple_call_fndecl(def_stmt);
115779 +
115780 + if (fndecl == NULL_TREE)
115781 + return;
115782 + insert_last_node(cur_node, fndecl);
115783 + return;
115784 + }
115785 + case GIMPLE_PHI:
115786 + return walk_use_def_phi(visited, cur_node, lhs);
115787 + case GIMPLE_ASSIGN:
115788 + switch (gimple_num_ops(def_stmt)) {
115789 + case 2:
115790 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115791 + case 3:
115792 + return walk_use_def_binary(visited, cur_node, lhs);
115793 + }
115794 + default:
115795 + debug_gimple_stmt((gimple)def_stmt);
115796 + error("%s: unknown gimple code", __func__);
115797 + gcc_unreachable();
115798 + }
115799 +}
115800 +
115801 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115802 +static void set_last_nodes(struct interesting_node *cur_node)
115803 +{
115804 + struct pointer_set_t *visited;
115805 +
115806 + visited = pointer_set_create();
115807 + walk_use_def(visited, cur_node, cur_node->node);
115808 + pointer_set_destroy(visited);
115809 +}
115810 +
115811 +enum precond {
115812 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115813 +};
115814 +
115815 +/* 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.
115816 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115817 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115818 + * It skips the possible error codes too.
115819 + */
115820 +static enum precond check_preconditions(struct interesting_node *cur_node)
115821 +{
115822 + bool interesting_conditions[5] = {false, false, false, false, false};
115823 +
115824 + set_last_nodes(cur_node);
115825 +
115826 + check_intentional_attribute_ipa(cur_node);
115827 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115828 + return NO_ATTRIBUTE_SEARCH;
115829 +
115830 + search_interesting_conditions(cur_node, interesting_conditions);
115831 +
115832 + // error code: a phi, unary assign (not cast) and returns only
115833 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
115834 + return NO_ATTRIBUTE_SEARCH;
115835 +
115836 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
115837 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115838 + return NO_ATTRIBUTE_SEARCH;
115839 +
115840 + // unnecessary overflow check
115841 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115842 + return NO_CHECK_INSERT;
115843 +
115844 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115845 + return NO_CHECK_INSERT;
115846 +
115847 + return NONE;
115848 +}
115849 +
115850 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
115851 +{
115852 + const_gimple assign;
115853 + tree orig_type = TREE_TYPE(orig_node);
115854 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115855 +
115856 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115857 + return gimple_assign_lhs(assign);
115858 +}
115859 +
115860 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
115861 +{
115862 + void (*set_rhs)(gimple, tree);
115863 + gimple stmt = cur_node->first_stmt;
115864 + const_tree orig_node = cur_node->node;
115865 +
115866 + switch (gimple_code(stmt)) {
115867 + case GIMPLE_RETURN:
115868 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115869 + break;
115870 + case GIMPLE_CALL:
115871 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
115872 + break;
115873 + case GIMPLE_ASSIGN:
115874 + switch (cur_node->num) {
115875 + case 1:
115876 + set_rhs = &gimple_assign_set_rhs1;
115877 + break;
115878 + case 2:
115879 + set_rhs = &gimple_assign_set_rhs2;
115880 + break;
115881 +#if BUILDING_GCC_VERSION >= 4006
115882 + case 3:
115883 + set_rhs = &gimple_assign_set_rhs3;
115884 + break;
115885 +#endif
115886 + default:
115887 + gcc_unreachable();
115888 + }
115889 +
115890 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115891 + break;
115892 + default:
115893 + debug_gimple_stmt(stmt);
115894 + gcc_unreachable();
115895 + }
115896 +
115897 + update_stmt(stmt);
115898 +}
115899 +
115900 +static struct visited *create_visited(void)
115901 +{
115902 + struct visited *new_node;
115903 +
115904 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
115905 + new_node->stmts = pointer_set_create();
115906 + new_node->my_stmts = pointer_set_create();
115907 + new_node->skip_expr_casts = pointer_set_create();
115908 + new_node->no_cast_check = pointer_set_create();
115909 + return new_node;
115910 +}
115911 +
115912 +static void free_visited(struct visited *visited)
115913 +{
115914 + pointer_set_destroy(visited->stmts);
115915 + pointer_set_destroy(visited->my_stmts);
115916 + pointer_set_destroy(visited->skip_expr_casts);
115917 + pointer_set_destroy(visited->no_cast_check);
115918 +
115919 + free(visited);
115920 +}
115921 +
115922 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115923 + * 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
115924 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115925 + */
115926 +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)
115927 +{
115928 + enum precond ret;
115929 + tree new_node, orig_node = cur_node->node;
115930 +
115931 + ret = check_preconditions(cur_node);
115932 + if (ret == NO_ATTRIBUTE_SEARCH)
115933 + return cnodes;
115934 +
115935 + cnodes = search_overflow_attribute(cnodes, cur_node);
115936 +
115937 + if (ret == NO_CHECK_INSERT)
115938 + return cnodes;
115939 +
115940 + new_node = expand(visited, caller_node, orig_node);
115941 + if (new_node == NULL_TREE)
115942 + return cnodes;
115943 +
115944 + change_orig_node(visited, cur_node, new_node);
115945 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115946 +
115947 + return cnodes;
115948 +}
115949 +
115950 +// Check visited_fns interesting nodes.
115951 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115952 +{
115953 + struct interesting_node *cur;
115954 +
115955 + for (cur = head; cur; cur = cur->next) {
115956 + if (!operand_equal_p(node, cur->node, 0))
115957 + continue;
115958 + if (num != cur->num)
115959 + continue;
115960 + if (first_stmt == cur->first_stmt)
115961 + return true;
115962 + }
115963 + return false;
115964 +}
115965 +
115966 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115967 + 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
115968 + 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
115969 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115970 + num: arg count of a call stmt or 0 when it is a ret
115971 + node: the recursion starts from here, it is a call arg or a return value
115972 + 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.
115973 + intentional_attr_decl: intentional_overflow attribute of the callee function
115974 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115975 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115976 + */
115977 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115978 +{
115979 + struct interesting_node *new_node;
115980 + tree fndecl;
115981 + enum gimple_code code;
115982 +
115983 + gcc_assert(node != NULL_TREE);
115984 + code = gimple_code(first_stmt);
115985 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115986 +
115987 + if (num == CANNOT_FIND_ARG)
115988 + return head;
115989 +
115990 + if (skip_types(node))
115991 + return head;
115992 +
115993 + if (skip_asm(node))
115994 + return head;
115995 +
115996 + if (is_gimple_call(first_stmt))
115997 + fndecl = gimple_call_fndecl(first_stmt);
115998 + else
115999 + fndecl = current_function_decl;
116000 +
116001 + if (fndecl == NULL_TREE)
116002 + return head;
116003 +
116004 + if (is_in_interesting_node(head, first_stmt, node, num))
116005 + return head;
116006 +
116007 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116008 +
116009 + new_node->next = NULL;
116010 + new_node->first_stmt = first_stmt;
116011 +#if BUILDING_GCC_VERSION <= 4007
116012 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116013 +#else
116014 + vec_alloc(new_node->last_nodes, VEC_LEN);
116015 +#endif
116016 + new_node->num = num;
116017 + new_node->node = node;
116018 + new_node->fndecl = fndecl;
116019 + new_node->intentional_attr_decl = MARK_NO;
116020 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116021 + new_node->intentional_mark_from_gimple = asm_stmt;
116022 +
116023 + if (!head)
116024 + return new_node;
116025 +
116026 + new_node->next = head;
116027 + return new_node;
116028 +}
116029 +
116030 +/* 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).
116031 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116032 + */
116033 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116034 +{
116035 + struct next_cgraph_node *cur_node;
116036 + tree ret = gimple_return_retval(stmt);
116037 +
116038 + if (ret == NULL_TREE)
116039 + return head;
116040 +
116041 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116042 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116043 + continue;
116044 + if (cur_node->num == 0)
116045 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116046 + }
116047 +
116048 + return head;
116049 +}
116050 +
116051 +/* 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).
116052 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116053 + */
116054 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116055 +{
116056 + unsigned int argnum;
116057 + tree arg;
116058 + const_tree fndecl;
116059 + struct next_cgraph_node *cur_node;
116060 +
116061 + fndecl = gimple_call_fndecl(stmt);
116062 + if (fndecl == NULL_TREE)
116063 + return head;
116064 +
116065 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116066 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116067 + continue;
116068 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116069 + gcc_assert(argnum != CANNOT_FIND_ARG);
116070 + if (argnum == 0)
116071 + continue;
116072 +
116073 + arg = gimple_call_arg(stmt, argnum - 1);
116074 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116075 + }
116076 +
116077 + return head;
116078 +}
116079 +
116080 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116081 +{
116082 + if (!operand_equal_p(orig_node, node, 0))
116083 + return WRONG_NODE;
116084 + if (skip_types(node))
116085 + return WRONG_NODE;
116086 + return ret_count;
116087 +}
116088 +
116089 +// Get the index of the rhs node in an assignment
116090 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116091 +{
116092 + const_tree rhs1, rhs2;
116093 + unsigned int ret;
116094 +
116095 + gcc_assert(stmt);
116096 + gcc_assert(is_gimple_assign(stmt));
116097 +
116098 + rhs1 = gimple_assign_rhs1(stmt);
116099 + gcc_assert(rhs1 != NULL_TREE);
116100 +
116101 + switch (gimple_num_ops(stmt)) {
116102 + case 2:
116103 + return check_ops(node, rhs1, 1);
116104 + case 3:
116105 + ret = check_ops(node, rhs1, 1);
116106 + if (ret != WRONG_NODE)
116107 + return ret;
116108 +
116109 + rhs2 = gimple_assign_rhs2(stmt);
116110 + gcc_assert(rhs2 != NULL_TREE);
116111 + return check_ops(node, rhs2, 2);
116112 + default:
116113 + gcc_unreachable();
116114 + }
116115 +}
116116 +
116117 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116118 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116119 +{
116120 + unsigned int i;
116121 +
116122 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116123 + return CANNOT_FIND_ARG;
116124 +
116125 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116126 + tree node;
116127 +
116128 + node = gimple_call_arg(stmt, i);
116129 + if (!operand_equal_p(arg, node, 0))
116130 + continue;
116131 + if (!skip_types(node))
116132 + return i + 1;
116133 + }
116134 +
116135 + return CANNOT_FIND_ARG;
116136 +}
116137 +
116138 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116139 + * any of return, call or assignment stmts (because of inlining).
116140 + */
116141 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116142 +{
116143 + use_operand_p use_p;
116144 + imm_use_iterator imm_iter;
116145 + unsigned int argnum;
116146 +
116147 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116148 +
116149 + if (pointer_set_insert(visited, node))
116150 + return head;
116151 +
116152 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116153 + gimple stmt = USE_STMT(use_p);
116154 +
116155 + if (stmt == NULL)
116156 + return head;
116157 + if (is_gimple_debug(stmt))
116158 + continue;
116159 +
116160 + switch (gimple_code(stmt)) {
116161 + case GIMPLE_CALL:
116162 + argnum = find_arg_number_gimple(node, stmt);
116163 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116164 + break;
116165 + case GIMPLE_RETURN:
116166 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116167 + break;
116168 + case GIMPLE_ASSIGN:
116169 + argnum = get_assign_ops_count(stmt, node);
116170 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116171 + break;
116172 + case GIMPLE_PHI: {
116173 + tree result = gimple_phi_result(stmt);
116174 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116175 + break;
116176 + }
116177 + case GIMPLE_ASM:
116178 + if (gimple_asm_noutputs(stmt) != 0)
116179 + break;
116180 + if (!is_size_overflow_asm(stmt))
116181 + break;
116182 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116183 + break;
116184 + case GIMPLE_COND:
116185 + case GIMPLE_SWITCH:
116186 + break;
116187 + default:
116188 + debug_gimple_stmt(stmt);
116189 + gcc_unreachable();
116190 + break;
116191 + }
116192 + }
116193 + return head;
116194 +}
116195 +
116196 +static void remove_size_overflow_asm(gimple stmt)
116197 +{
116198 + gimple_stmt_iterator gsi;
116199 + tree input, output;
116200 +
116201 + if (!is_size_overflow_asm(stmt))
116202 + return;
116203 +
116204 + if (gimple_asm_noutputs(stmt) == 0) {
116205 + gsi = gsi_for_stmt(stmt);
116206 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116207 + gsi_remove(&gsi, true);
116208 + return;
116209 + }
116210 +
116211 + input = gimple_asm_input_op(stmt, 0);
116212 + output = gimple_asm_output_op(stmt, 0);
116213 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116214 +}
116215 +
116216 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116217 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116218 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116219 + */
116220 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116221 +{
116222 + const_tree output;
116223 + struct pointer_set_t *visited;
116224 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116225 +
116226 + if (!is_size_overflow_asm(stmt))
116227 + return head;
116228 +
116229 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116230 + intentional_asm = stmt;
116231 +
116232 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116233 +
116234 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116235 + return head;
116236 +
116237 + if (gimple_asm_noutputs(stmt) == 0) {
116238 + const_tree input;
116239 +
116240 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116241 + return head;
116242 +
116243 + input = gimple_asm_input_op(stmt, 0);
116244 + remove_size_overflow_asm(stmt);
116245 + if (is_gimple_constant(TREE_VALUE(input)))
116246 + return head;
116247 + visited = pointer_set_create();
116248 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116249 + pointer_set_destroy(visited);
116250 + return head;
116251 + }
116252 +
116253 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116254 + remove_size_overflow_asm(stmt);
116255 +
116256 + visited = pointer_set_create();
116257 + output = gimple_asm_output_op(stmt, 0);
116258 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116259 + pointer_set_destroy(visited);
116260 + return head;
116261 +}
116262 +
116263 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116264 + * or a call stmt or a return stmt and store them in the interesting_node list
116265 + */
116266 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116267 +{
116268 + basic_block bb;
116269 + struct interesting_node *head = NULL;
116270 +
116271 + FOR_ALL_BB_FN(bb, cfun) {
116272 + gimple_stmt_iterator gsi;
116273 +
116274 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116275 + enum gimple_code code;
116276 + gimple stmt = gsi_stmt(gsi);
116277 +
116278 + code = gimple_code(stmt);
116279 +
116280 + if (code == GIMPLE_ASM)
116281 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116282 +
116283 + if (!next_node)
116284 + continue;
116285 + if (code == GIMPLE_CALL)
116286 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116287 + if (code == GIMPLE_RETURN)
116288 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116289 + }
116290 + }
116291 + return head;
116292 +}
116293 +
116294 +static void free_interesting_node(struct interesting_node *head)
116295 +{
116296 + struct interesting_node *cur;
116297 +
116298 + while (head) {
116299 + cur = head->next;
116300 +#if BUILDING_GCC_VERSION <= 4007
116301 + VEC_free(tree, gc, head->last_nodes);
116302 +#else
116303 + vec_free(head->last_nodes);
116304 +#endif
116305 + free(head);
116306 + head = cur;
116307 + }
116308 +}
116309 +
116310 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116311 +{
116312 + struct visited_fns *new_visited_fns;
116313 +
116314 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116315 + new_visited_fns->fndecl = cur_node->fndecl;
116316 + new_visited_fns->num = cur_node->num;
116317 + new_visited_fns->first_stmt = cur_node->first_stmt;
116318 + new_visited_fns->next = NULL;
116319 +
116320 + if (!head)
116321 + return new_visited_fns;
116322 +
116323 + new_visited_fns->next = head;
116324 + return new_visited_fns;
116325 +}
116326 +
116327 +/* 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
116328 + * it is a visited_fns function.
116329 + */
116330 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116331 +{
116332 + struct visited_fns *cur;
116333 +
116334 + if (!head)
116335 + return false;
116336 +
116337 + for (cur = head; cur; cur = cur->next) {
116338 + if (cur_node->first_stmt != cur->first_stmt)
116339 + continue;
116340 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116341 + continue;
116342 + if (cur_node->num == cur->num)
116343 + return true;
116344 + }
116345 + return false;
116346 +}
116347 +
116348 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116349 +{
116350 + struct next_cgraph_node *cur;
116351 +
116352 + while (head) {
116353 + cur = head->next;
116354 + free(head);
116355 + head = cur;
116356 + }
116357 +}
116358 +
116359 +static void remove_all_size_overflow_asm(void)
116360 +{
116361 + basic_block bb;
116362 +
116363 + FOR_ALL_BB_FN(bb, cfun) {
116364 + gimple_stmt_iterator si;
116365 +
116366 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116367 + remove_size_overflow_asm(gsi_stmt(si));
116368 + }
116369 +}
116370 +
116371 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116372 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116373 + * the newly collected interesting functions (they are interesting if there is control flow between
116374 + * the interesting stmts and them).
116375 + */
116376 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116377 +{
116378 + struct visited *visited;
116379 + struct interesting_node *head, *cur_node;
116380 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116381 +
116382 + set_current_function_decl(NODE_DECL(node));
116383 + call_count = 0;
116384 +
116385 + head = collect_interesting_stmts(next_node);
116386 +
116387 + visited = create_visited();
116388 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116389 + if (is_visited_fns_function(visited_fns, cur_node))
116390 + continue;
116391 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116392 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116393 + }
116394 +
116395 + free_visited(visited);
116396 + free_interesting_node(head);
116397 + remove_all_size_overflow_asm();
116398 + unset_current_function_decl();
116399 +
116400 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116401 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116402 +
116403 + free_next_cgraph_node(cnodes_head);
116404 + return visited_fns;
116405 +}
116406 +
116407 +static void free_visited_fns(struct visited_fns *head)
116408 +{
116409 + struct visited_fns *cur;
116410 +
116411 + while (head) {
116412 + cur = head->next;
116413 + free(head);
116414 + head = cur;
116415 + }
116416 +}
116417 +
116418 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116419 +unsigned int search_function(void)
116420 +{
116421 + struct cgraph_node *node;
116422 + struct visited_fns *visited_fns = NULL;
116423 +
116424 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116425 + gcc_assert(cgraph_function_flags_ready);
116426 +#if BUILDING_GCC_VERSION <= 4007
116427 + gcc_assert(node->reachable);
116428 +#endif
116429 +
116430 + visited_fns = handle_function(node, NULL, visited_fns);
116431 + }
116432 +
116433 + free_visited_fns(visited_fns);
116434 + return 0;
116435 +}
116436 +
116437 +#if BUILDING_GCC_VERSION >= 4009
116438 +static const struct pass_data insert_size_overflow_check_data = {
116439 +#else
116440 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116441 + .pass = {
116442 +#endif
116443 + .type = SIMPLE_IPA_PASS,
116444 + .name = "size_overflow",
116445 +#if BUILDING_GCC_VERSION >= 4008
116446 + .optinfo_flags = OPTGROUP_NONE,
116447 +#endif
116448 +#if BUILDING_GCC_VERSION >= 4009
116449 + .has_gate = false,
116450 + .has_execute = true,
116451 +#else
116452 + .gate = NULL,
116453 + .execute = search_function,
116454 + .sub = NULL,
116455 + .next = NULL,
116456 + .static_pass_number = 0,
116457 +#endif
116458 + .tv_id = TV_NONE,
116459 + .properties_required = 0,
116460 + .properties_provided = 0,
116461 + .properties_destroyed = 0,
116462 + .todo_flags_start = 0,
116463 + .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,
116464 +#if BUILDING_GCC_VERSION < 4009
116465 + },
116466 + .generate_summary = NULL,
116467 + .write_summary = NULL,
116468 + .read_summary = NULL,
116469 +#if BUILDING_GCC_VERSION >= 4006
116470 + .write_optimization_summary = NULL,
116471 + .read_optimization_summary = NULL,
116472 +#endif
116473 + .stmt_fixup = NULL,
116474 + .function_transform_todo_flags_start = 0,
116475 + .function_transform = NULL,
116476 + .variable_transform = NULL,
116477 +#endif
116478 +};
116479 +
116480 +#if BUILDING_GCC_VERSION >= 4009
116481 +namespace {
116482 +class insert_size_overflow_check : public ipa_opt_pass_d {
116483 +public:
116484 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116485 + unsigned int execute() { return search_function(); }
116486 +};
116487 +}
116488 +#endif
116489 +
116490 +struct opt_pass *make_insert_size_overflow_check(void)
116491 +{
116492 +#if BUILDING_GCC_VERSION >= 4009
116493 + return new insert_size_overflow_check();
116494 +#else
116495 + return &insert_size_overflow_check.pass;
116496 +#endif
116497 +}
116498 +
116499 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116500 new file mode 100644
116501 index 0000000..d71d72a
116502 --- /dev/null
116503 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116504 @@ -0,0 +1,736 @@
116505 +/*
116506 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116507 + * Licensed under the GPL v2, or (at your option) v3
116508 + *
116509 + * Homepage:
116510 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116511 + *
116512 + * Documentation:
116513 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116514 + *
116515 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116516 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116517 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116518 + *
116519 + * Usage:
116520 + * $ make
116521 + * $ make run
116522 + */
116523 +
116524 +#include "gcc-common.h"
116525 +#include "size_overflow.h"
116526 +
116527 +/* Get the param of the intentional_overflow attribute.
116528 + * * 0: MARK_NOT_INTENTIONAL
116529 + * * 1..MAX_PARAM: MARK_YES
116530 + * * -1: MARK_TURN_OFF
116531 + */
116532 +static tree get_attribute_param(const_tree decl)
116533 +{
116534 + const_tree attr;
116535 +
116536 + if (decl == NULL_TREE)
116537 + return NULL_TREE;
116538 +
116539 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116540 + if (!attr || !TREE_VALUE(attr))
116541 + return NULL_TREE;
116542 +
116543 + return TREE_VALUE(attr);
116544 +}
116545 +
116546 +// MARK_TURN_OFF
116547 +bool is_turn_off_intentional_attr(const_tree decl)
116548 +{
116549 + const_tree param_head;
116550 +
116551 + param_head = get_attribute_param(decl);
116552 + if (param_head == NULL_TREE)
116553 + return false;
116554 +
116555 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116556 + return true;
116557 + return false;
116558 +}
116559 +
116560 +// MARK_NOT_INTENTIONAL
116561 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116562 +{
116563 + const_tree param_head;
116564 +
116565 + if (argnum == 0)
116566 + return false;
116567 +
116568 + param_head = get_attribute_param(decl);
116569 + if (param_head == NULL_TREE)
116570 + return false;
116571 +
116572 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116573 + return true;
116574 + return false;
116575 +}
116576 +
116577 +// MARK_YES
116578 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116579 +{
116580 + tree param, param_head;
116581 +
116582 + if (argnum == 0)
116583 + return false;
116584 +
116585 + param_head = get_attribute_param(decl);
116586 + for (param = param_head; param; param = TREE_CHAIN(param))
116587 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116588 + return true;
116589 + return false;
116590 +}
116591 +
116592 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116593 +{
116594 + location_t loc;
116595 +
116596 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116597 + return;
116598 +
116599 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116600 + return;
116601 +
116602 + loc = DECL_SOURCE_LOCATION(decl);
116603 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116604 +}
116605 +
116606 +// Get the field decl of a component ref for intentional_overflow checking
116607 +static const_tree search_field_decl(const_tree comp_ref)
116608 +{
116609 + const_tree field = NULL_TREE;
116610 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116611 +
116612 + for (i = 0; i < len; i++) {
116613 + field = TREE_OPERAND(comp_ref, i);
116614 + if (TREE_CODE(field) == FIELD_DECL)
116615 + break;
116616 + }
116617 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116618 + return field;
116619 +}
116620 +
116621 +/* Get the type of the intentional_overflow attribute of a node
116622 + * * MARK_TURN_OFF
116623 + * * MARK_YES
116624 + * * MARK_NO
116625 + * * MARK_NOT_INTENTIONAL
116626 + */
116627 +enum mark get_intentional_attr_type(const_tree node)
116628 +{
116629 + const_tree cur_decl;
116630 +
116631 + if (node == NULL_TREE)
116632 + return MARK_NO;
116633 +
116634 + switch (TREE_CODE(node)) {
116635 + case COMPONENT_REF:
116636 + cur_decl = search_field_decl(node);
116637 + if (is_turn_off_intentional_attr(cur_decl))
116638 + return MARK_TURN_OFF;
116639 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116640 + return MARK_YES;
116641 + break;
116642 + case PARM_DECL: {
116643 + unsigned int argnum;
116644 +
116645 + cur_decl = DECL_ORIGIN(current_function_decl);
116646 + argnum = find_arg_number_tree(node, cur_decl);
116647 + if (argnum == CANNOT_FIND_ARG)
116648 + return MARK_NO;
116649 + if (is_yes_intentional_attr(cur_decl, argnum))
116650 + return MARK_YES;
116651 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116652 + return MARK_NOT_INTENTIONAL;
116653 + break;
116654 + }
116655 + case FUNCTION_DECL:
116656 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116657 + return MARK_TURN_OFF;
116658 + break;
116659 + default:
116660 + break;
116661 + }
116662 + return MARK_NO;
116663 +}
116664 +
116665 +// Search for the intentional_overflow attribute on the last nodes
116666 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116667 +{
116668 + unsigned int i;
116669 + tree last_node;
116670 + enum mark mark = MARK_NO;
116671 +
116672 +#if BUILDING_GCC_VERSION <= 4007
116673 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116674 +#else
116675 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116676 +#endif
116677 + mark = get_intentional_attr_type(last_node);
116678 + if (mark != MARK_NO)
116679 + break;
116680 + }
116681 + return mark;
116682 +}
116683 +
116684 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116685 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116686 + */
116687 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116688 +{
116689 + if (!cur_node->intentional_mark_from_gimple)
116690 + return false;
116691 +
116692 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116693 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116694 + else
116695 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116696 +
116697 + // skip param decls
116698 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116699 + return true;
116700 + return true;
116701 +}
116702 +
116703 +/* Search intentional_overflow attribute on caller and on callee too.
116704 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116705 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116706 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116707 +*/
116708 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116709 +{
116710 + const_tree fndecl;
116711 +
116712 + if (is_intentional_attribute_from_gimple(cur_node))
116713 + return;
116714 +
116715 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116716 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116717 + return;
116718 + }
116719 +
116720 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116721 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116722 + return;
116723 + }
116724 +
116725 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116726 + return;
116727 +
116728 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116729 + if (is_turn_off_intentional_attr(fndecl)) {
116730 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116731 + return;
116732 + }
116733 +
116734 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116735 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116736 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116737 + cur_node->intentional_attr_decl = MARK_YES;
116738 +
116739 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116740 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116741 +}
116742 +
116743 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
116744 +{
116745 + const_tree rhs1, lhs, rhs1_type, lhs_type;
116746 + enum machine_mode lhs_mode, rhs_mode;
116747 + gimple def_stmt = get_def_stmt(no_const_rhs);
116748 +
116749 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116750 + return false;
116751 +
116752 + rhs1 = gimple_assign_rhs1(def_stmt);
116753 + lhs = gimple_assign_lhs(def_stmt);
116754 + rhs1_type = TREE_TYPE(rhs1);
116755 + lhs_type = TREE_TYPE(lhs);
116756 + rhs_mode = TYPE_MODE(rhs1_type);
116757 + lhs_mode = TYPE_MODE(lhs_type);
116758 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
116759 + return false;
116760 +
116761 + return true;
116762 +}
116763 +
116764 +static unsigned int uses_num(tree node)
116765 +{
116766 + imm_use_iterator imm_iter;
116767 + use_operand_p use_p;
116768 + unsigned int num = 0;
116769 +
116770 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116771 + gimple use_stmt = USE_STMT(use_p);
116772 +
116773 + if (use_stmt == NULL)
116774 + return num;
116775 + if (is_gimple_debug(use_stmt))
116776 + continue;
116777 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
116778 + continue;
116779 + num++;
116780 + }
116781 + return num;
116782 +}
116783 +
116784 +static bool no_uses(tree node)
116785 +{
116786 + return !uses_num(node);
116787 +}
116788 +
116789 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
116790 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
116791 +{
116792 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
116793 + gimple def_stmt = get_def_stmt(lhs);
116794 +
116795 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116796 + return false;
116797 +
116798 + rhs1 = gimple_assign_rhs1(def_stmt);
116799 + rhs_type = TREE_TYPE(rhs1);
116800 + lhs_type = TREE_TYPE(lhs);
116801 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
116802 + return false;
116803 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
116804 + return false;
116805 +
116806 + def_stmt = get_def_stmt(rhs1);
116807 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
116808 + return false;
116809 +
116810 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
116811 + return false;
116812 +
116813 + rhs1 = gimple_assign_rhs1(def_stmt);
116814 + rhs2 = gimple_assign_rhs2(def_stmt);
116815 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
116816 + return false;
116817 +
116818 + if (is_gimple_constant(rhs2))
116819 + not_const_rhs = rhs1;
116820 + else
116821 + not_const_rhs = rhs2;
116822 +
116823 + return no_uses(not_const_rhs);
116824 +}
116825 +
116826 +static bool is_lt_signed_type_max(const_tree rhs)
116827 +{
116828 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
116829 +
116830 + if (!TYPE_UNSIGNED(type))
116831 + return true;
116832 +
116833 + switch (TYPE_MODE(type)) {
116834 + case QImode:
116835 + new_type = intQI_type_node;
116836 + break;
116837 + case HImode:
116838 + new_type = intHI_type_node;
116839 + break;
116840 + case SImode:
116841 + new_type = intSI_type_node;
116842 + break;
116843 + case DImode:
116844 + new_type = intDI_type_node;
116845 + break;
116846 + default:
116847 + debug_tree((tree)type);
116848 + gcc_unreachable();
116849 + }
116850 +
116851 + type_max = TYPE_MAX_VALUE(new_type);
116852 + if (!tree_int_cst_lt(type_max, rhs))
116853 + return true;
116854 +
116855 + return false;
116856 +}
116857 +
116858 +static bool is_gt_zero(const_tree rhs)
116859 +{
116860 + const_tree type = TREE_TYPE(rhs);
116861 +
116862 + if (TYPE_UNSIGNED(type))
116863 + return true;
116864 +
116865 + if (!tree_int_cst_lt(rhs, integer_zero_node))
116866 + return true;
116867 +
116868 + return false;
116869 +}
116870 +
116871 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
116872 +{
116873 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
116874 + return false;
116875 + if (!is_gimple_constant(rhs))
116876 + return false;
116877 +
116878 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
116879 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
116880 + return false;
116881 +
116882 + return true;
116883 +}
116884 +
116885 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
116886 +{
116887 + gimple assign;
116888 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116889 + tree origtype = TREE_TYPE(orig_rhs);
116890 +
116891 + gcc_assert(is_gimple_assign(stmt));
116892 +
116893 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116894 + pointer_set_insert(visited->my_stmts, assign);
116895 + return gimple_assign_lhs(assign);
116896 +}
116897 +
116898 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
116899 +{
116900 + tree new_rhs, orig_rhs;
116901 + void (*gimple_assign_set_rhs)(gimple, tree);
116902 + tree rhs1 = gimple_assign_rhs1(stmt);
116903 + tree rhs2 = gimple_assign_rhs2(stmt);
116904 + tree lhs = gimple_assign_lhs(stmt);
116905 +
116906 + if (!check_overflow)
116907 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116908 +
116909 + if (change_rhs == NULL_TREE)
116910 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116911 +
116912 + if (new_rhs2 == NULL_TREE) {
116913 + orig_rhs = rhs1;
116914 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116915 + } else {
116916 + orig_rhs = rhs2;
116917 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116918 + }
116919 +
116920 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116921 +
116922 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
116923 + gimple_assign_set_rhs(stmt, new_rhs);
116924 + update_stmt(stmt);
116925 +
116926 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116927 +}
116928 +
116929 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
116930 +{
116931 + gimple rhs1_def_stmt, rhs2_def_stmt;
116932 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116933 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116934 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116935 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116936 +
116937 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116938 + return false;
116939 +
116940 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116941 +
116942 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116943 + return false;
116944 +
116945 + rhs1_def_stmt = get_def_stmt(rhs1);
116946 + rhs2_def_stmt = get_def_stmt(rhs2);
116947 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116948 + return false;
116949 +
116950 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116951 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116952 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116953 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116954 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116955 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116956 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116957 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116958 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116959 + return false;
116960 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116961 + return false;
116962 +
116963 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
116964 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
116965 + return true;
116966 +}
116967 +
116968 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
116969 +{
116970 + gimple assign;
116971 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116972 + tree type = TREE_TYPE(rhs1);
116973 + tree lhs = create_new_var(type);
116974 +
116975 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
116976 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
116977 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
116978 +
116979 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116980 + update_stmt(assign);
116981 + pointer_set_insert(visited->my_stmts, assign);
116982 + return assign;
116983 +}
116984 +
116985 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
116986 +{
116987 + gimple_stmt_iterator gsi;
116988 + gimple cast_stmt;
116989 + tree type = TREE_TYPE(node);
116990 +
116991 + if (types_compatible_p(type, intTI_type_node))
116992 + return node;
116993 +
116994 + gsi = gsi_for_stmt(stmt);
116995 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116996 + pointer_set_insert(visited->my_stmts, cast_stmt);
116997 + return gimple_assign_lhs(cast_stmt);
116998 +}
116999 +
117000 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117001 +{
117002 + tree rhs1, def_stmt_rhs1;
117003 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117004 +
117005 + def_stmt = get_def_stmt(var);
117006 + if (!gimple_assign_cast_p(def_stmt))
117007 + return NULL_TREE;
117008 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117009 +
117010 + rhs1 = gimple_assign_rhs1(def_stmt);
117011 + rhs1_def_stmt = get_def_stmt(rhs1);
117012 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117013 + return rhs1;
117014 +
117015 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117016 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117017 +
117018 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117019 + case GIMPLE_CALL:
117020 + case GIMPLE_NOP:
117021 + case GIMPLE_ASM:
117022 + case GIMPLE_PHI:
117023 + return def_stmt_rhs1;
117024 + case GIMPLE_ASSIGN:
117025 + return rhs1;
117026 + default:
117027 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117028 + gcc_unreachable();
117029 + }
117030 +}
117031 +
117032 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117033 +{
117034 + tree new_rhs1, new_rhs2;
117035 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117036 + gimple assign, stmt = get_def_stmt(lhs);
117037 + tree rhs1 = gimple_assign_rhs1(stmt);
117038 + tree rhs2 = gimple_assign_rhs2(stmt);
117039 +
117040 + if (!is_subtraction_special(visited, stmt))
117041 + return NULL_TREE;
117042 +
117043 + new_rhs1 = expand(visited, caller_node, rhs1);
117044 + new_rhs2 = expand(visited, caller_node, rhs2);
117045 +
117046 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117047 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117048 +
117049 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117050 + return NULL_TREE;
117051 +
117052 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117053 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117054 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117055 + }
117056 +
117057 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117058 + new_lhs = gimple_assign_lhs(assign);
117059 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117060 +
117061 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117062 +}
117063 +
117064 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117065 +{
117066 + const_gimple def_stmt;
117067 +
117068 + if (TREE_CODE(rhs) != SSA_NAME)
117069 + return false;
117070 +
117071 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117072 + return false;
117073 +
117074 + def_stmt = get_def_stmt(rhs);
117075 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117076 + return false;
117077 +
117078 + return true;
117079 +}
117080 +
117081 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117082 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117083 + * fffffff * 16 > signed max -> truncate
117084 + */
117085 +static bool look_for_mult_and_add(const_gimple stmt)
117086 +{
117087 + const_tree res;
117088 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117089 + const_gimple def_stmt;
117090 +
117091 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117092 + return false;
117093 + if (!is_gimple_assign(stmt))
117094 + return false;
117095 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117096 + return false;
117097 +
117098 + rhs1 = gimple_assign_rhs1(stmt);
117099 + rhs2 = gimple_assign_rhs2(stmt);
117100 + if (is_gimple_constant(rhs1)) {
117101 + const_rhs = rhs1;
117102 + def_stmt = get_def_stmt(rhs2);
117103 + } else if (is_gimple_constant(rhs2)) {
117104 + const_rhs = rhs2;
117105 + def_stmt = get_def_stmt(rhs1);
117106 + } else
117107 + return false;
117108 +
117109 + if (!is_gimple_assign(def_stmt))
117110 + return false;
117111 +
117112 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117113 + return false;
117114 +
117115 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117116 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117117 + if (is_gimple_constant(def_rhs1))
117118 + def_const_rhs = def_rhs1;
117119 + else if (is_gimple_constant(def_rhs2))
117120 + def_const_rhs = def_rhs2;
117121 + else
117122 + return false;
117123 +
117124 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117125 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117126 + return false;
117127 + return true;
117128 +}
117129 +
117130 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117131 +{
117132 + const_gimple def_stmt_1, def_stmt_2;
117133 + const_tree rhs1, rhs2;
117134 + bool add_mul_rhs1, add_mul_rhs2;
117135 +
117136 + rhs1 = gimple_assign_rhs1(stmt);
117137 + def_stmt_1 = get_def_stmt(rhs1);
117138 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117139 +
117140 + rhs2 = gimple_assign_rhs2(stmt);
117141 + def_stmt_2 = get_def_stmt(rhs2);
117142 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117143 +
117144 + if (add_mul_rhs1)
117145 + return RHS1_INTENTIONAL_OVERFLOW;
117146 + if (add_mul_rhs2)
117147 + return RHS2_INTENTIONAL_OVERFLOW;
117148 + return NO_INTENTIONAL_OVERFLOW;
117149 +}
117150 +
117151 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117152 +{
117153 + gimple my_stmt;
117154 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117155 +
117156 + gsi_next(&gsi);
117157 + my_stmt = gsi_stmt(gsi);
117158 +
117159 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117160 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117161 +
117162 + return my_stmt;
117163 +}
117164 +
117165 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117166 + * unsigned type cast to signed type, unsigned type: no more uses
117167 + * e.g., lib/vsprintf.c:simple_strtol()
117168 + * _10 = (unsigned long int) _9
117169 + * _11 = -_10;
117170 + * _12 = (long int) _11; (_11_ no more uses)
117171 + */
117172 +static bool is_call_or_cast(gimple stmt)
117173 +{
117174 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117175 +}
117176 +
117177 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117178 +{
117179 + const_tree rhs;
117180 + gimple def_stmt;
117181 +
117182 + if (node == NULL_TREE)
117183 + return true;
117184 + if (is_gimple_constant(node))
117185 + return true;
117186 +
117187 + def_stmt = get_def_stmt(node);
117188 + if (!def_stmt)
117189 + return false;
117190 +
117191 + if (is_call_or_cast(def_stmt))
117192 + return true;
117193 +
117194 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117195 + return false;
117196 + rhs = gimple_assign_rhs1(def_stmt);
117197 + def_stmt = get_def_stmt(rhs);
117198 + if (!def_stmt)
117199 + return false;
117200 + return is_call_or_cast(def_stmt);
117201 +}
117202 +
117203 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117204 +{
117205 + unsigned int use_num;
117206 + gimple so_stmt;
117207 + const_gimple def_stmt;
117208 + const_tree rhs1, rhs2;
117209 + tree rhs = gimple_assign_rhs1(stmt);
117210 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117211 + const_tree rhs_type = TREE_TYPE(rhs);
117212 +
117213 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117214 + return;
117215 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117216 + return;
117217 + use_num = uses_num(rhs);
117218 + if (use_num != 1)
117219 + return;
117220 +
117221 + def_stmt = get_def_stmt(rhs);
117222 + if (!def_stmt)
117223 + return;
117224 + if (!is_gimple_assign(def_stmt))
117225 + return;
117226 +
117227 + rhs1 = gimple_assign_rhs1(def_stmt);
117228 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117229 + return;
117230 +
117231 + rhs2 = gimple_assign_rhs2(def_stmt);
117232 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117233 + return;
117234 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117235 + return;
117236 +
117237 + so_stmt = get_dup_stmt(visited, stmt);
117238 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117239 +}
117240 +
117241 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117242 new file mode 100644
117243 index 0000000..4bddad2
117244 --- /dev/null
117245 +++ b/tools/gcc/size_overflow_plugin/misc.c
117246 @@ -0,0 +1,203 @@
117247 +/*
117248 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117249 + * Licensed under the GPL v2, or (at your option) v3
117250 + *
117251 + * Homepage:
117252 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117253 + *
117254 + * Documentation:
117255 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117256 + *
117257 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117258 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117259 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117260 + *
117261 + * Usage:
117262 + * $ make
117263 + * $ make run
117264 + */
117265 +
117266 +#include "gcc-common.h"
117267 +#include "size_overflow.h"
117268 +
117269 +void set_current_function_decl(tree fndecl)
117270 +{
117271 + gcc_assert(fndecl != NULL_TREE);
117272 +
117273 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117274 + calculate_dominance_info(CDI_DOMINATORS);
117275 + current_function_decl = fndecl;
117276 +}
117277 +
117278 +void unset_current_function_decl(void)
117279 +{
117280 + free_dominance_info(CDI_DOMINATORS);
117281 + pop_cfun();
117282 + current_function_decl = NULL_TREE;
117283 +}
117284 +
117285 +static bool is_bool(const_tree node)
117286 +{
117287 + const_tree type;
117288 +
117289 + if (node == NULL_TREE)
117290 + return false;
117291 +
117292 + type = TREE_TYPE(node);
117293 + if (!INTEGRAL_TYPE_P(type))
117294 + return false;
117295 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117296 + return true;
117297 + if (TYPE_PRECISION(type) == 1)
117298 + return true;
117299 + return false;
117300 +}
117301 +
117302 +bool skip_types(const_tree var)
117303 +{
117304 + tree type;
117305 + enum tree_code code;
117306 +
117307 + if (is_gimple_constant(var))
117308 + return true;
117309 +
117310 + switch (TREE_CODE(var)) {
117311 + case ADDR_EXPR:
117312 +#if BUILDING_GCC_VERSION >= 4006
117313 + case MEM_REF:
117314 +#endif
117315 + case ARRAY_REF:
117316 + case BIT_FIELD_REF:
117317 + case INDIRECT_REF:
117318 + case TARGET_MEM_REF:
117319 + case COMPONENT_REF:
117320 + case VAR_DECL:
117321 + case VIEW_CONVERT_EXPR:
117322 + return true;
117323 + default:
117324 + break;
117325 + }
117326 +
117327 + code = TREE_CODE(var);
117328 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117329 +
117330 + type = TREE_TYPE(var);
117331 + switch (TREE_CODE(type)) {
117332 + case INTEGER_TYPE:
117333 + case ENUMERAL_TYPE:
117334 + return false;
117335 + case BOOLEAN_TYPE:
117336 + return is_bool(var);
117337 + default:
117338 + return true;
117339 + }
117340 +}
117341 +
117342 +gimple get_def_stmt(const_tree node)
117343 +{
117344 + gcc_assert(node != NULL_TREE);
117345 +
117346 + if (skip_types(node))
117347 + return NULL;
117348 +
117349 + if (TREE_CODE(node) != SSA_NAME)
117350 + return NULL;
117351 + return SSA_NAME_DEF_STMT(node);
117352 +}
117353 +
117354 +tree create_new_var(tree type)
117355 +{
117356 + tree new_var = create_tmp_var(type, "cicus");
117357 +
117358 + add_referenced_var(new_var);
117359 + return new_var;
117360 +}
117361 +
117362 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117363 +{
117364 + const_gimple def_stmt = get_def_stmt(rhs);
117365 +
117366 + if (force)
117367 + return false;
117368 +
117369 + if (is_gimple_constant(rhs))
117370 + return false;
117371 +
117372 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117373 + return false;
117374 +
117375 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117376 + return false;
117377 +
117378 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117379 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117380 + return false;
117381 +
117382 + return true;
117383 +}
117384 +
117385 +tree cast_a_tree(tree type, tree var)
117386 +{
117387 + gcc_assert(type != NULL_TREE);
117388 + gcc_assert(var != NULL_TREE);
117389 + gcc_assert(fold_convertible_p(type, var));
117390 +
117391 + return fold_convert(type, var);
117392 +}
117393 +
117394 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117395 +{
117396 + gimple assign, def_stmt;
117397 +
117398 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117399 + gcc_assert(!is_gimple_constant(rhs));
117400 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117401 + gcc_unreachable();
117402 +
117403 + def_stmt = get_def_stmt(rhs);
117404 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117405 + return def_stmt;
117406 +
117407 + if (lhs == CREATE_NEW_VAR)
117408 + lhs = create_new_var(dst_type);
117409 +
117410 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117411 +
117412 + if (!gsi_end_p(*gsi)) {
117413 + location_t loc = gimple_location(gsi_stmt(*gsi));
117414 + gimple_set_location(assign, loc);
117415 + }
117416 +
117417 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117418 +
117419 + if (before)
117420 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117421 + else
117422 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117423 + update_stmt(assign);
117424 + return assign;
117425 +}
117426 +
117427 +bool is_size_overflow_type(const_tree var)
117428 +{
117429 + const char *name;
117430 + const_tree type_name, type;
117431 +
117432 + if (var == NULL_TREE)
117433 + return false;
117434 +
117435 + type = TREE_TYPE(var);
117436 + type_name = TYPE_NAME(type);
117437 + if (type_name == NULL_TREE)
117438 + return false;
117439 +
117440 + if (DECL_P(type_name))
117441 + name = DECL_NAME_POINTER(type_name);
117442 + else
117443 + name = IDENTIFIER_POINTER(type_name);
117444 +
117445 + if (!strncmp(name, "size_overflow_type", 18))
117446 + return true;
117447 + return false;
117448 +}
117449 +
117450 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117451 new file mode 100644
117452 index 0000000..7c9e6d1
117453 --- /dev/null
117454 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117455 @@ -0,0 +1,138 @@
117456 +/*
117457 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117458 + * Licensed under the GPL v2, or (at your option) v3
117459 + *
117460 + * Homepage:
117461 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117462 + *
117463 + * Documentation:
117464 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117465 + *
117466 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117467 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117468 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117469 + *
117470 + * Usage:
117471 + * $ make
117472 + * $ make run
117473 + */
117474 +
117475 +#include "gcc-common.h"
117476 +#include "size_overflow.h"
117477 +
117478 +bool skip_expr_on_double_type(const_gimple stmt)
117479 +{
117480 + enum tree_code code = gimple_assign_rhs_code(stmt);
117481 +
117482 + switch (code) {
117483 + case RSHIFT_EXPR:
117484 + case TRUNC_DIV_EXPR:
117485 + case CEIL_DIV_EXPR:
117486 + case FLOOR_DIV_EXPR:
117487 + case ROUND_DIV_EXPR:
117488 + case EXACT_DIV_EXPR:
117489 + case RDIV_EXPR:
117490 + case TRUNC_MOD_EXPR:
117491 + case CEIL_MOD_EXPR:
117492 + case FLOOR_MOD_EXPR:
117493 + case ROUND_MOD_EXPR:
117494 + return true;
117495 + default:
117496 + return false;
117497 + }
117498 +}
117499 +
117500 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
117501 +{
117502 + const_tree orig_rhs1;
117503 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
117504 + gimple down_cast, up_cast;
117505 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
117506 +
117507 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117508 + down_lhs = gimple_assign_lhs(down_cast);
117509 +
117510 + gsi = gsi_for_stmt(use_stmt);
117511 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117512 + new_lhs = gimple_assign_lhs(up_cast);
117513 +
117514 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
117515 + if (operand_equal_p(orig_rhs1, rhs, 0))
117516 + gimple_assign_set_rhs1(use_stmt, new_lhs);
117517 + else
117518 + gimple_assign_set_rhs2(use_stmt, new_lhs);
117519 + update_stmt(use_stmt);
117520 +
117521 + pointer_set_insert(visited->my_stmts, up_cast);
117522 + pointer_set_insert(visited->my_stmts, down_cast);
117523 + pointer_set_insert(visited->skip_expr_casts, up_cast);
117524 + pointer_set_insert(visited->skip_expr_casts, down_cast);
117525 +}
117526 +
117527 +static tree get_proper_unsigned_half_type(const_tree node)
117528 +{
117529 + tree new_type, type;
117530 +
117531 + gcc_assert(is_size_overflow_type(node));
117532 +
117533 + type = TREE_TYPE(node);
117534 + switch (TYPE_MODE(type)) {
117535 + case HImode:
117536 + new_type = unsigned_intQI_type_node;
117537 + break;
117538 + case SImode:
117539 + new_type = unsigned_intHI_type_node;
117540 + break;
117541 + case DImode:
117542 + new_type = unsigned_intSI_type_node;
117543 + break;
117544 + case TImode:
117545 + new_type = unsigned_intDI_type_node;
117546 + break;
117547 + default:
117548 + gcc_unreachable();
117549 + }
117550 +
117551 + if (TYPE_QUALS(type) != 0)
117552 + return build_qualified_type(new_type, TYPE_QUALS(type));
117553 + return new_type;
117554 +}
117555 +
117556 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
117557 +{
117558 + tree type;
117559 +
117560 + if (rhs == NULL_TREE)
117561 + return;
117562 + if (!is_size_overflow_type(rhs))
117563 + return;
117564 +
117565 + type = get_proper_unsigned_half_type(rhs);
117566 + if (is_gimple_constant(rhs))
117567 + return;
117568 + create_up_and_down_cast(visited, stmt, type, rhs);
117569 +}
117570 +
117571 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
117572 +{
117573 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
117574 + return;
117575 + gcc_assert(is_size_overflow_type(rhs));
117576 + insert_cast_rhs(visited, stmt, rhs);
117577 +}
117578 +
117579 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
117580 +{
117581 + tree rhs1, rhs2;
117582 +
117583 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
117584 + rhs1 = gimple_assign_rhs1(stmt);
117585 + insert_cast(visited, stmt, rhs1);
117586 + }
117587 +
117588 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
117589 + rhs2 = gimple_assign_rhs2(stmt);
117590 + insert_cast(visited, stmt, rhs2);
117591 + }
117592 +}
117593 +
117594 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
117595 new file mode 100644
117596 index 0000000..e5b4e50
117597 --- /dev/null
117598 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
117599 @@ -0,0 +1,127 @@
117600 +#ifndef SIZE_OVERFLOW_H
117601 +#define SIZE_OVERFLOW_H
117602 +
117603 +#define CREATE_NEW_VAR NULL_TREE
117604 +#define CANNOT_FIND_ARG 32
117605 +#define MAX_PARAM 31
117606 +#define BEFORE_STMT true
117607 +#define AFTER_STMT false
117608 +
117609 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
117610 +#define YES_ASM_STR "# size_overflow MARK_YES "
117611 +#define OK_ASM_STR "# size_overflow "
117612 +
117613 +enum mark {
117614 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
117615 +};
117616 +
117617 +enum intentional_overflow_type {
117618 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
117619 +};
117620 +
117621 +struct visited {
117622 + struct pointer_set_t *stmts;
117623 + struct pointer_set_t *my_stmts;
117624 + struct pointer_set_t *skip_expr_casts;
117625 + struct pointer_set_t *no_cast_check;
117626 +};
117627 +
117628 +// size_overflow_plugin.c
117629 +extern tree report_size_overflow_decl;
117630 +extern tree size_overflow_type_HI;
117631 +extern tree size_overflow_type_SI;
117632 +extern tree size_overflow_type_DI;
117633 +extern tree size_overflow_type_TI;
117634 +
117635 +
117636 +// size_overflow_plugin_hash.c
117637 +struct size_overflow_hash {
117638 + const struct size_overflow_hash * const next;
117639 + const char * const name;
117640 + const unsigned int param;
117641 +};
117642 +
117643 +struct interesting_node {
117644 + struct interesting_node *next;
117645 + gimple first_stmt;
117646 + const_tree fndecl;
117647 + tree node;
117648 +#if BUILDING_GCC_VERSION <= 4007
117649 + VEC(tree, gc) *last_nodes;
117650 +#else
117651 + vec<tree, va_gc> *last_nodes;
117652 +#endif
117653 + unsigned int num;
117654 + enum mark intentional_attr_decl;
117655 + enum mark intentional_attr_cur_fndecl;
117656 + gimple intentional_mark_from_gimple;
117657 +};
117658 +
117659 +extern bool is_size_overflow_asm(const_gimple stmt);
117660 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
117661 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
117662 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
117663 +extern bool is_a_return_check(const_tree node);
117664 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
117665 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
117666 +
117667 +
117668 +// size_overflow_debug.c
117669 +extern struct opt_pass *make_dump_pass(void);
117670 +
117671 +
117672 +// intentional_overflow.c
117673 +extern enum mark get_intentional_attr_type(const_tree node);
117674 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
117675 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
117676 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
117677 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
117678 +extern bool is_turn_off_intentional_attr(const_tree decl);
117679 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
117680 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
117681 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
117682 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
117683 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
117684 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
117685 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
117686 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
117687 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
117688 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
117689 +
117690 +
117691 +// insert_size_overflow_check_ipa.c
117692 +extern unsigned int search_function(void);
117693 +extern unsigned int call_count;
117694 +extern struct opt_pass *make_insert_size_overflow_check(void);
117695 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
117696 +
117697 +
117698 +// insert_size_overflow_asm.c
117699 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
117700 +
117701 +
117702 +// misc.c
117703 +extern void set_current_function_decl(tree fndecl);
117704 +extern void unset_current_function_decl(void);
117705 +extern gimple get_def_stmt(const_tree node);
117706 +extern tree create_new_var(tree type);
117707 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
117708 +extern bool skip_types(const_tree var);
117709 +extern tree cast_a_tree(tree type, tree var);
117710 +extern bool is_size_overflow_type(const_tree var);
117711 +
117712 +
117713 +// insert_size_overflow_check_core.c
117714 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
117715 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
117716 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
117717 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
117718 +
117719 +
117720 +// remove_unnecessary_dup.c
117721 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
117722 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
117723 +extern bool skip_expr_on_double_type(const_gimple stmt);
117724 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
117725 +
117726 +#endif
117727 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117728 new file mode 100644
117729 index 0000000..4378111
117730 --- /dev/null
117731 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117732 @@ -0,0 +1,116 @@
117733 +/*
117734 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117735 + * Licensed under the GPL v2, or (at your option) v3
117736 + *
117737 + * Homepage:
117738 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117739 + *
117740 + * Documentation:
117741 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117742 + *
117743 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117744 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117745 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117746 + *
117747 + * Usage:
117748 + * $ make
117749 + * $ make run
117750 + */
117751 +
117752 +#include "gcc-common.h"
117753 +
117754 +static unsigned int dump_functions(void)
117755 +{
117756 + struct cgraph_node *node;
117757 +
117758 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117759 + basic_block bb;
117760 +
117761 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117762 + current_function_decl = NODE_DECL(node);
117763 +
117764 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117765 +
117766 + FOR_ALL_BB_FN(bb, cfun) {
117767 + gimple_stmt_iterator si;
117768 +
117769 + fprintf(stderr, "<bb %u>:\n", bb->index);
117770 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117771 + debug_gimple_stmt(gsi_stmt(si));
117772 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117773 + debug_gimple_stmt(gsi_stmt(si));
117774 + fprintf(stderr, "\n");
117775 + }
117776 +
117777 + fprintf(stderr, "-------------------------------------------------------------------------\n");
117778 +
117779 + pop_cfun();
117780 + current_function_decl = NULL_TREE;
117781 + }
117782 +
117783 + fprintf(stderr, "###############################################################################\n");
117784 +
117785 + return 0;
117786 +}
117787 +
117788 +#if BUILDING_GCC_VERSION >= 4009
117789 +static const struct pass_data dump_pass_data = {
117790 +#else
117791 +static struct ipa_opt_pass_d dump_pass = {
117792 + .pass = {
117793 +#endif
117794 + .type = SIMPLE_IPA_PASS,
117795 + .name = "dump",
117796 +#if BUILDING_GCC_VERSION >= 4008
117797 + .optinfo_flags = OPTGROUP_NONE,
117798 +#endif
117799 +#if BUILDING_GCC_VERSION >= 4009
117800 + .has_gate = false,
117801 + .has_execute = true,
117802 +#else
117803 + .gate = NULL,
117804 + .execute = dump_functions,
117805 + .sub = NULL,
117806 + .next = NULL,
117807 + .static_pass_number = 0,
117808 +#endif
117809 + .tv_id = TV_NONE,
117810 + .properties_required = 0,
117811 + .properties_provided = 0,
117812 + .properties_destroyed = 0,
117813 + .todo_flags_start = 0,
117814 + .todo_flags_finish = 0,
117815 +#if BUILDING_GCC_VERSION < 4009
117816 + },
117817 + .generate_summary = NULL,
117818 + .write_summary = NULL,
117819 + .read_summary = NULL,
117820 +#if BUILDING_GCC_VERSION >= 4006
117821 + .write_optimization_summary = NULL,
117822 + .read_optimization_summary = NULL,
117823 +#endif
117824 + .stmt_fixup = NULL,
117825 + .function_transform_todo_flags_start = 0,
117826 + .function_transform = NULL,
117827 + .variable_transform = NULL,
117828 +#endif
117829 +};
117830 +
117831 +#if BUILDING_GCC_VERSION >= 4009
117832 +namespace {
117833 +class dump_pass : public ipa_opt_pass_d {
117834 +public:
117835 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117836 + unsigned int execute() { return dump_functions(); }
117837 +};
117838 +}
117839 +#endif
117840 +
117841 +struct opt_pass *make_dump_pass(void)
117842 +{
117843 +#if BUILDING_GCC_VERSION >= 4009
117844 + return new dump_pass();
117845 +#else
117846 + return &dump_pass.pass;
117847 +#endif
117848 +}
117849 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117850 new file mode 100644
117851 index 0000000..f2bd55d
117852 --- /dev/null
117853 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117854 @@ -0,0 +1,6031 @@
117855 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
117856 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
117857 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
117858 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
117859 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
117860 +padzero_55 padzero 1 55 &sel_read_policyvers_55
117861 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
117862 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
117863 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
117864 +load_msg_95 load_msg 2 95 NULL
117865 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
117866 +init_q_132 init_q 4 132 NULL
117867 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
117868 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
117869 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
117870 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
117871 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
117872 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
117873 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
117874 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
117875 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
117876 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
117877 +br_port_info_size_268 br_port_info_size 0 268 NULL
117878 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
117879 +SYSC_connect_304 SYSC_connect 3 304 NULL
117880 +syslog_print_307 syslog_print 2 307 NULL
117881 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
117882 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
117883 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
117884 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
117885 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
117886 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
117887 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
117888 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
117889 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
117890 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
117891 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
117892 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
117893 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
117894 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
117895 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
117896 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
117897 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
117898 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
117899 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
117900 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
117901 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
117902 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
117903 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
117904 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
117905 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
117906 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
117907 +unlink_queued_645 unlink_queued 4 645 NULL
117908 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
117909 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
117910 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
117911 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
117912 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
117913 +dvb_video_write_754 dvb_video_write 3 754 NULL
117914 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
117915 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
117916 +if_writecmd_815 if_writecmd 2 815 NULL
117917 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
117918 +error_state_read_859 error_state_read 6 859 NULL
117919 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
117920 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
117921 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
117922 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
117923 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
117924 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
117925 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
117926 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
117927 +readreg_1017 readreg 0-1 1017 NULL
117928 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
117929 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
117930 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
117931 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
117932 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
117933 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
117934 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
117935 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
117936 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
117937 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
117938 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
117939 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
117940 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
117941 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
117942 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
117943 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
117944 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
117945 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
117946 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
117947 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
117948 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
117949 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
117950 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
117951 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
117952 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
117953 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
117954 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
117955 +ffs_1322 ffs 0 1322 NULL
117956 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
117957 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
117958 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
117959 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
117960 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
117961 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
117962 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
117963 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
117964 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
117965 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
117966 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
117967 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
117968 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
117969 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
117970 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
117971 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
117972 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
117973 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
117974 +fpregs_set_1497 fpregs_set 4 1497 NULL
117975 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
117976 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
117977 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
117978 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
117979 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
117980 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
117981 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
117982 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
117983 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
117984 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
117985 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
117986 +rmap_add_1677 rmap_add 3 1677 NULL
117987 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
117988 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
117989 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
117990 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
117991 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
117992 +internal_create_group_1733 internal_create_group 0 1733 NULL
117993 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
117994 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
117995 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
117996 +cosa_write_1774 cosa_write 3 1774 NULL
117997 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
117998 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
117999 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118000 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118001 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118002 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118003 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118004 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118005 +azx_get_position_1927 azx_get_position 0 1927 NULL
118006 +bdev_erase_1933 bdev_erase 3 1933 NULL
118007 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118008 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118009 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118010 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118011 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118012 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
118013 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118014 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118015 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118016 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118017 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118018 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118019 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118020 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118021 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118022 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118023 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118024 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118025 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118026 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118027 +audit_expand_2098 audit_expand 0 2098 NULL
118028 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118029 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118030 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118031 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118032 +enable_read_2117 enable_read 3 2117 NULL
118033 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118034 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118035 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118036 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118037 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118038 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118039 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118040 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118041 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118042 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118043 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118044 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118045 +do_update_counters_2259 do_update_counters 4 2259 NULL
118046 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118047 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
118048 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118049 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118050 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118051 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118052 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118053 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118054 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118055 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118056 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118057 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118058 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118059 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118060 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118061 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118062 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118063 +raid1_size_2419 raid1_size 0-2 2419 NULL
118064 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118065 +wiphy_new_2482 wiphy_new 2 2482 NULL
118066 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118067 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118068 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118069 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118070 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118071 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118072 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118073 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118074 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118075 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118076 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118077 +slot_bytes_2609 slot_bytes 0 2609 NULL
118078 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118079 +switch_status_2629 switch_status 5 2629 NULL
118080 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118081 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118082 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118083 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118084 +oti6858_write_2692 oti6858_write 4 2692 NULL
118085 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
118086 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118087 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118088 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118089 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118090 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118091 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118092 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118093 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118094 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118095 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118096 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118097 +sock_create_2838 sock_create 0 2838 NULL
118098 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118099 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118100 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118101 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118102 +nla_padlen_2883 nla_padlen 1 2883 NULL
118103 +cmm_write_2896 cmm_write 3 2896 NULL
118104 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118105 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118106 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118107 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118108 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118109 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118110 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118111 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118112 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118113 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118114 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118115 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118116 +depth_write_3021 depth_write 3 3021 NULL
118117 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118118 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118119 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118120 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118121 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118122 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118123 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118124 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118125 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118126 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118127 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118128 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118129 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118130 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
118131 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118132 +rb_alloc_3102 rb_alloc 1 3102 NULL
118133 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118134 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118135 +print_time_3132 print_time 0 3132 NULL
118136 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118137 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118138 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118139 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118140 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118141 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118142 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118143 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118144 +alloc_context_3194 alloc_context 1 3194 NULL
118145 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
118146 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118147 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118148 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118149 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118150 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118151 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118152 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118153 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118154 +key_key_read_3241 key_key_read 3 3241 NULL
118155 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118156 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118157 +cgroup_name_3300 cgroup_name 3 3300 NULL
118158 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118159 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118160 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118161 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118162 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118163 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118164 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118165 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118166 +scnprintf_3360 scnprintf 0-2 3360 NULL
118167 +sr_read_3366 sr_read 3 3366 NULL
118168 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118169 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118170 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118171 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118172 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118173 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118174 +softsynth_write_3455 softsynth_write 3 3455 NULL
118175 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118176 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118177 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118178 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118179 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118180 +SyS_readv_3539 SyS_readv 3 3539 NULL
118181 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
118182 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118183 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118184 +evtchn_read_3569 evtchn_read 3 3569 NULL
118185 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118186 +vc_resize_3585 vc_resize 3-2 3585 NULL
118187 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118188 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118189 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118190 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118191 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118192 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
118193 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118194 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118195 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118196 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118197 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118198 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118199 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118200 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118201 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118202 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
118203 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118204 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118205 +get_fd_set_3866 get_fd_set 1 3866 NULL
118206 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118207 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118208 +nvram_write_3894 nvram_write 3 3894 NULL
118209 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118210 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118211 +vcs_write_3910 vcs_write 3 3910 NULL
118212 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118213 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118214 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118215 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118216 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118217 +do_add_counters_3992 do_add_counters 3 3992 NULL
118218 +userspace_status_4004 userspace_status 4 4004 NULL
118219 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118220 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118221 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118222 +blk_end_request_4024 blk_end_request 3 4024 NULL
118223 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118224 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118225 +read_file_queues_4078 read_file_queues 3 4078 NULL
118226 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118227 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118228 +tm6000_read_4151 tm6000_read 3 4151 NULL
118229 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118230 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118231 +get_alua_req_4166 get_alua_req 3 4166 NULL
118232 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118233 +read_file_bool_4180 read_file_bool 3 4180 NULL
118234 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118235 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118236 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118237 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118238 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118239 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118240 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118241 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118242 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118243 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118244 +count_strings_4315 count_strings 0 4315 NULL nohasharray
118245 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
118246 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118247 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118248 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118249 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118250 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118251 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118252 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118253 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118254 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118255 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118256 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118257 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118258 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118259 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118260 +set_link_security_4502 set_link_security 4 4502 NULL
118261 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118262 +tty_register_device_4544 tty_register_device 2 4544 NULL
118263 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118264 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118265 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118266 +bch_alloc_4593 bch_alloc 1 4593 NULL
118267 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118268 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118269 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118270 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118271 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118272 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118273 +kone_receive_4690 kone_receive 4 4690 NULL
118274 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118275 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118276 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118277 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118278 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118279 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118280 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118281 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118282 +create_subvol_4791 create_subvol 4 4791 NULL
118283 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118284 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118285 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118286 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118287 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118288 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118289 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118290 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118291 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118292 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118293 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118294 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118295 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118296 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118297 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118298 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118299 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118300 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118301 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118302 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118303 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118304 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118305 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118306 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118307 +sound_write_5102 sound_write 3 5102 NULL
118308 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118309 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118310 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118311 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118312 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118313 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118314 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118315 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118316 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118317 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118318 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
118319 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
118320 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118321 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118322 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118323 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118324 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118325 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118326 +cq_free_res_5355 cq_free_res 5 5355 NULL
118327 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118328 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118329 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118330 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118331 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118332 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118333 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
118334 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118335 +tty_write_5494 tty_write 3 5494 NULL
118336 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118337 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118338 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118339 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118340 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118341 +le_readq_5557 le_readq 0 5557 NULL
118342 +inw_5558 inw 0 5558 NULL
118343 +bioset_create_5580 bioset_create 1 5580 NULL
118344 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118345 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118346 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118347 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118348 +get_arg_5694 get_arg 3 5694 NULL
118349 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118350 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118351 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118352 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118353 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118354 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
118355 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
118356 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118357 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118358 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118359 +setup_req_5848 setup_req 3 5848 NULL
118360 +ria_page_count_5849 ria_page_count 0 5849 NULL
118361 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118362 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118363 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118364 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118365 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118366 +port_show_regs_5904 port_show_regs 3 5904 NULL
118367 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118368 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118369 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118370 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118371 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118372 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118373 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118374 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118375 +SyS_semop_5980 SyS_semop 3 5980 NULL
118376 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118377 +alloc_msg_6072 alloc_msg 1 6072 NULL
118378 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118379 +_random_read_6098 _random_read 3 6098 NULL
118380 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118381 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118382 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118383 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118384 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118385 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118386 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118387 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118388 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118389 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118390 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118391 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118392 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118393 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118394 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118395 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118396 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118397 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118398 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118399 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118400 +serial_port_in_6291 serial_port_in 0 6291 NULL
118401 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118402 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118403 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118404 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118405 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118406 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118407 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118408 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118409 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118410 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118411 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118412 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118413 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118414 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118415 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118416 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118417 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118418 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118419 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118420 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118421 +mei_read_6507 mei_read 3 6507 NULL
118422 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118423 +wdm_read_6549 wdm_read 3 6549 NULL
118424 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118425 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118426 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118427 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118428 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118429 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118430 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118431 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118432 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118433 +mpeg_read_6708 mpeg_read 3 6708 NULL
118434 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118435 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118436 +video_proc_write_6724 video_proc_write 3 6724 NULL
118437 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118438 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
118439 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118440 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118441 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118442 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118443 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118444 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118445 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118446 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
118447 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118448 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118449 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
118450 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118451 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118452 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118453 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118454 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118455 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118456 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118457 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118458 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118459 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118460 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118461 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118462 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118463 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118464 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118465 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118466 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118467 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118468 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118469 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118470 +request_key_async_6990 request_key_async 4 6990 NULL
118471 +tpl_write_6998 tpl_write 3 6998 NULL
118472 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118473 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118474 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118475 +wimax_msg_7030 wimax_msg 4 7030 NULL
118476 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118477 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118478 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118479 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118480 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118481 +event_enable_read_7074 event_enable_read 3 7074 NULL
118482 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118483 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118484 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118485 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
118486 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
118487 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
118488 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
118489 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
118490 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
118491 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
118492 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
118493 +get_string_7302 get_string 0 7302 NULL
118494 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
118495 +mgmt_control_7349 mgmt_control 3 7349 NULL
118496 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
118497 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
118498 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
118499 +hweight_long_7388 hweight_long 0-1 7388 NULL
118500 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
118501 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
118502 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
118503 +readb_7401 readb 0 7401 NULL
118504 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
118505 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
118506 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
118507 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
118508 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
118509 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
118510 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
118511 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
118512 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
118513 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
118514 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
118515 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
118516 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
118517 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
118518 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
118519 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
118520 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
118521 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
118522 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
118523 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
118524 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
118525 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
118526 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
118527 +dev_write_7708 dev_write 3 7708 NULL
118528 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
118529 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
118530 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
118531 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
118532 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
118533 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
118534 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
118535 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
118536 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
118537 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
118538 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
118539 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
118540 +config_desc_7878 config_desc 0 7878 NULL
118541 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
118542 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
118543 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
118544 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
118545 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
118546 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
118547 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
118548 +vcs_read_8017 vcs_read 3 8017 NULL
118549 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
118550 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
118551 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
118552 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
118553 +venus_lookup_8121 venus_lookup 4 8121 NULL
118554 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
118555 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
118556 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
118557 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
118558 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
118559 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
118560 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
118561 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
118562 +play_iframe_8219 play_iframe 3 8219 NULL
118563 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
118564 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
118565 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
118566 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
118567 +init_cdev_8274 init_cdev 1 8274 NULL
118568 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
118569 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
118570 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
118571 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
118572 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
118573 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
118574 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
118575 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
118576 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
118577 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
118578 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
118579 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
118580 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
118581 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
118582 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
118583 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
118584 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
118585 +dev_config_8506 dev_config 3 8506 NULL
118586 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
118587 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
118588 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
118589 +user_on_off_8552 user_on_off 2 8552 NULL
118590 +profile_remove_8556 profile_remove 3 8556 NULL
118591 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
118592 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
118593 +tower_write_8580 tower_write 3 8580 NULL
118594 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
118595 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
118596 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
118597 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
118598 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
118599 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
118600 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
118601 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
118602 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
118603 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
118604 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
118605 +arcfb_write_8702 arcfb_write 3 8702 NULL
118606 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
118607 +init_header_8703 init_header 0 8703 &i_size_read_8703
118608 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
118609 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
118610 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
118611 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
118612 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
118613 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
118614 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
118615 +compound_order_8750 compound_order 0 8750 NULL
118616 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
118617 +yurex_write_8761 yurex_write 3 8761 NULL
118618 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
118619 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
118620 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
118621 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
118622 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
118623 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
118624 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
118625 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
118626 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
118627 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
118628 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
118629 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
118630 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
118631 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
118632 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
118633 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
118634 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
118635 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
118636 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
118637 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
118638 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
118639 +write_file_ani_8918 write_file_ani 3 8918 NULL
118640 +layout_commit_8926 layout_commit 3 8926 NULL
118641 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
118642 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
118643 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
118644 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
118645 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
118646 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
118647 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
118648 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
118649 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
118650 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
118651 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
118652 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
118653 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
118654 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
118655 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
118656 +nla_put_9042 nla_put 3 9042 NULL
118657 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
118658 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
118659 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
118660 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
118661 +create_queues_9088 create_queues 2-3 9088 NULL
118662 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
118663 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
118664 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
118665 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
118666 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
118667 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
118668 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
118669 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
118670 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
118671 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
118672 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
118673 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
118674 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
118675 +card_send_command_9215 card_send_command 3 9215 NULL
118676 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
118677 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
118678 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
118679 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
118680 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
118681 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
118682 +flakey_status_9274 flakey_status 5 9274 NULL
118683 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
118684 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
118685 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
118686 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
118687 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
118688 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
118689 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
118690 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
118691 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
118692 +read_9397 read 3 9397 NULL
118693 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
118694 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
118695 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
118696 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
118697 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
118698 +get_registers_9470 get_registers 4 9470 NULL nohasharray
118699 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
118700 +crypt_status_9492 crypt_status 5 9492 NULL
118701 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
118702 +lp_write_9511 lp_write 3 9511 NULL
118703 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
118704 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
118705 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
118706 +read_file_dma_9530 read_file_dma 3 9530 NULL
118707 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
118708 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
118709 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
118710 +fw_node_create_9559 fw_node_create 2 9559 NULL
118711 +kobj_map_9566 kobj_map 2-3 9566 NULL
118712 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
118713 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
118714 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
118715 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
118716 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
118717 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
118718 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
118719 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
118720 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
118721 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
118722 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
118723 +dns_query_9676 dns_query 3 9676 NULL
118724 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
118725 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
118726 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
118727 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
118728 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
118729 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
118730 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
118731 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
118732 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
118733 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
118734 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
118735 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
118736 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
118737 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
118738 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
118739 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
118740 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
118741 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
118742 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
118743 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
118744 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
118745 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
118746 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
118747 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
118748 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
118749 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
118750 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
118751 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
118752 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
118753 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
118754 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
118755 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
118756 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
118757 +read_file_misc_9948 read_file_misc 3 9948 NULL
118758 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
118759 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
118760 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
118761 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
118762 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
118763 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
118764 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
118765 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
118766 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
118767 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
118768 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
118769 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
118770 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
118771 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
118772 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
118773 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
118774 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
118775 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
118776 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
118777 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
118778 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
118779 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
118780 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
118781 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
118782 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
118783 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
118784 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
118785 +read_emulate_10310 read_emulate 2-4 10310 NULL
118786 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
118787 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
118788 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
118789 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
118790 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
118791 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
118792 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
118793 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
118794 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
118795 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
118796 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
118797 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
118798 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
118799 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
118800 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
118801 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
118802 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
118803 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
118804 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
118805 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
118806 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
118807 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
118808 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
118809 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
118810 +otp_read_10594 otp_read 2-4-5 10594 NULL
118811 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
118812 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
118813 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
118814 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
118815 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
118816 +parport_write_10669 parport_write 0 10669 NULL
118817 +edge_write_10692 edge_write 4 10692 NULL
118818 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
118819 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
118820 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
118821 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
118822 +spi_sync_10731 spi_sync 0 10731 NULL
118823 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
118824 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
118825 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
118826 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
118827 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
118828 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
118829 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
118830 +ttm_dma_page_pool_free_10796 ttm_dma_page_pool_free 2-0 10796 NULL
118831 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
118832 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
118833 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
118834 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
118835 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
118836 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
118837 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
118838 +get_scq_10897 get_scq 2 10897 NULL
118839 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
118840 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
118841 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
118842 +kobject_add_10919 kobject_add 0 10919 NULL
118843 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
118844 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
118845 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
118846 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
118847 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
118848 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
118849 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
118850 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
118851 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
118852 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
118853 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
118854 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
118855 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
118856 +count_argc_11083 count_argc 0 11083 NULL
118857 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
118858 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
118859 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
118860 +page_offset_11120 page_offset 0 11120 NULL
118861 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
118862 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
118863 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
118864 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
118865 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
118866 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
118867 +of_irq_count_11253 of_irq_count 0 11253 NULL
118868 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
118869 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
118870 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
118871 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
118872 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
118873 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
118874 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
118875 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
118876 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
118877 +construct_key_11329 construct_key 3 11329 NULL nohasharray
118878 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
118879 +next_segment_11330 next_segment 0-2-1 11330 NULL
118880 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
118881 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
118882 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
118883 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
118884 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
118885 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
118886 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
118887 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
118888 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
118889 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
118890 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
118891 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
118892 +str_to_user_11411 str_to_user 2 11411 NULL
118893 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
118894 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
118895 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
118896 +trace_options_read_11419 trace_options_read 3 11419 NULL
118897 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
118898 +bttv_read_11432 bttv_read 3 11432 NULL
118899 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
118900 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
118901 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
118902 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
118903 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
118904 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
118905 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
118906 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
118907 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
118908 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
118909 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
118910 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
118911 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
118912 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
118913 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
118914 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
118915 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
118916 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
118917 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
118918 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
118919 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
118920 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
118921 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
118922 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
118923 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
118924 +split_11691 split 2 11691 NULL
118925 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
118926 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
118927 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
118928 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
118929 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
118930 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
118931 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
118932 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
118933 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
118934 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
118935 +umc_device_register_11824 umc_device_register 0 11824 NULL
118936 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
118937 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
118938 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
118939 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
118940 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
118941 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
118942 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
118943 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
118944 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
118945 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
118946 +ti_write_11916 ti_write 4 11916 NULL
118947 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
118948 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
118949 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
118950 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
118951 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
118952 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
118953 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
118954 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
118955 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
118956 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
118957 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
118958 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
118959 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
118960 +set_powered_12129 set_powered 4 12129 NULL
118961 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
118962 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
118963 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
118964 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
118965 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
118966 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
118967 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
118968 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
118969 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
118970 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
118971 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
118972 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
118973 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
118974 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
118975 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
118976 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
118977 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
118978 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
118979 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
118980 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
118981 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
118982 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
118983 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
118984 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
118985 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
118986 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
118987 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
118988 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
118989 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
118990 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
118991 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
118992 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
118993 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
118994 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
118995 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
118996 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
118997 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
118998 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
118999 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119000 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119001 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119002 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119003 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119004 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119005 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119006 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119007 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119008 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119009 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119010 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119011 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119012 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119013 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119014 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119015 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119016 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119017 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119018 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119019 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119020 +ivtv_write_12721 ivtv_write 3 12721 NULL
119021 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119022 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119023 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119024 +listxattr_12769 listxattr 3 12769 NULL
119025 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119026 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119027 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119028 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119029 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119030 +spidev_sync_12842 spidev_sync 0 12842 NULL
119031 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119032 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119033 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119034 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119035 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119036 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119037 +bm_status_write_12964 bm_status_write 3 12964 NULL
119038 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119039 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119040 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119041 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119042 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119043 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119044 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119045 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119046 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119047 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119048 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119049 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119050 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119051 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119052 +blk_update_request_13146 blk_update_request 3 13146 NULL
119053 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119054 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119055 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119056 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119057 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119058 +comedi_read_13199 comedi_read 3 13199 NULL
119059 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119060 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119061 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119062 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119063 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119064 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119065 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119066 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119067 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119068 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119069 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119070 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119071 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119072 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119073 +sd_major_13294 sd_major 0-1 13294 NULL
119074 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119075 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119076 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119077 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119078 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119079 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119080 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119081 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119082 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119083 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119084 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119085 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119086 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119087 +data_read_13494 data_read 3 13494 NULL nohasharray
119088 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119089 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119090 +core_status_13515 core_status 4 13515 NULL
119091 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119092 +bm_init_13529 bm_init 2 13529 NULL
119093 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119094 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119095 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119096 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119097 +cache_write_13589 cache_write 3 13589 NULL
119098 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119099 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119100 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119101 +packet_snd_13634 packet_snd 3 13634 NULL
119102 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119103 +cache_downcall_13666 cache_downcall 3 13666 NULL
119104 +usb_get_string_13693 usb_get_string 0 13693 NULL
119105 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119106 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119107 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119108 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119109 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119110 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
119111 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119112 +random_read_13815 random_read 3 13815 NULL
119113 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119114 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119115 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119116 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119117 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119118 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119119 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119120 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119121 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119122 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119123 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119124 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119125 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119126 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119127 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119128 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119129 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119130 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119131 +qcam_read_13977 qcam_read 3 13977 NULL
119132 +dsp_read_13980 dsp_read 2 13980 NULL
119133 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119134 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119135 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119136 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119137 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119138 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119139 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119140 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119141 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119142 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119143 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119144 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119145 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119146 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119147 +em_canid_change_14150 em_canid_change 3 14150 NULL
119148 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119149 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119150 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119151 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119152 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119153 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119154 +alloc_async_14208 alloc_async 1 14208 NULL
119155 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119156 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119157 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119158 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119159 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119160 +rr_status_14293 rr_status 5 14293 NULL
119161 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119162 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119163 +oo_objects_14319 oo_objects 0 14319 NULL
119164 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119165 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119166 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119167 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119168 +lowpan_read_14369 lowpan_read 3 14369 NULL
119169 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119170 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119171 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119172 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119173 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119174 +block_size_14443 block_size 0 14443 NULL
119175 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119176 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119177 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119178 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119179 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119180 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119181 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119182 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119183 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119184 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119185 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119186 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119187 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119188 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119189 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119190 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119191 +dbJoin_14644 dbJoin 0 14644 NULL
119192 +profile_replace_14652 profile_replace 3 14652 NULL
119193 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119194 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119195 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119196 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119197 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119198 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119199 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119200 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119201 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119202 +vfd_write_14717 vfd_write 3 14717 NULL
119203 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119204 +raid1_resize_14740 raid1_resize 2 14740 NULL
119205 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119206 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119207 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119208 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119209 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119210 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119211 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119212 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119213 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119214 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119215 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119216 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119217 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119218 +lcd_write_14857 lcd_write 3 14857 NULL
119219 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119220 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119221 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119222 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119223 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119224 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119225 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119226 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119227 +queue_cnt_14951 queue_cnt 0 14951 NULL
119228 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119229 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119230 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119231 +setkey_14987 setkey 3 14987 NULL nohasharray
119232 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119233 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119234 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119235 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119236 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119237 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119238 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119239 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119240 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119241 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119242 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119243 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119244 +start_port_15124 start_port 0 15124 NULL
119245 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119246 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119247 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119248 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119249 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119250 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119251 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119252 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119253 +simple_strtol_15273 simple_strtol 0 15273 NULL
119254 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119255 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119256 +ioread16_15342 ioread16 0 15342 NULL
119257 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119258 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
119259 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119260 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119261 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119262 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119263 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119264 +get_modalias_15406 get_modalias 2 15406 NULL
119265 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119266 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119267 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119268 +memweight_15450 memweight 2 15450 NULL
119269 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119270 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119271 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119272 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119273 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119274 +persistent_status_15574 persistent_status 4 15574 NULL
119275 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119276 +vme_user_write_15587 vme_user_write 3 15587 NULL
119277 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119278 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119279 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119280 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119281 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119282 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119283 +fs_path_add_15648 fs_path_add 3 15648 NULL
119284 +xsd_read_15653 xsd_read 3 15653 NULL
119285 +unix_bind_15668 unix_bind 3 15668 NULL
119286 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119287 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119288 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119289 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119290 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119291 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119292 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119293 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119294 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119295 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119296 +table_size_15851 table_size 0-1-2 15851 NULL
119297 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119298 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119299 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119300 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119301 +power_read_15939 power_read 3 15939 NULL
119302 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119303 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119304 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119305 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119306 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119307 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119308 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119309 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119310 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119311 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119312 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119313 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119314 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119315 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119316 +fsm_init_16134 fsm_init 2 16134 NULL
119317 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119318 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119319 +mapping_level_16188 mapping_level 2-0 16188 NULL
119320 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119321 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119322 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119323 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119324 +create_table_16213 create_table 2 16213 NULL
119325 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119326 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119327 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119328 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119329 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119330 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119331 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119332 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119333 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119334 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119335 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119336 +account_16283 account 0-4-2 16283 NULL nohasharray
119337 +mirror_status_16283 mirror_status 5 16283 &account_16283
119338 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119339 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119340 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119341 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119342 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119343 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119344 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119345 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119346 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119347 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119348 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119349 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119350 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119351 +cmdline_store_16442 cmdline_store 4 16442 NULL
119352 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119353 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119354 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119355 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119356 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119357 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119358 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119359 +raid10_resize_16537 raid10_resize 2 16537 NULL
119360 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119361 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119362 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119363 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119364 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119365 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119366 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119367 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119368 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119369 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119370 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119371 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119372 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119373 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119374 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119375 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119376 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119377 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119378 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119379 +st_write_16874 st_write 3 16874 NULL
119380 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119381 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119382 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119383 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119384 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119385 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119386 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119387 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119388 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119389 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119390 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119391 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119392 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119393 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119394 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119395 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119396 +entry_length_17093 entry_length 0 17093 NULL
119397 +write_mem_17114 write_mem 3 17114 NULL
119398 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119399 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119400 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119401 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119402 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119403 +sep_read_17161 sep_read 3 17161 NULL
119404 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119405 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119406 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119407 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119408 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119409 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119410 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119411 +sync_request_17208 sync_request 2 17208 NULL
119412 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119413 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119414 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119415 +alloc_ep_17269 alloc_ep 1 17269 NULL
119416 +pg_read_17276 pg_read 3 17276 NULL
119417 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119418 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119419 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119420 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119421 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119422 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119423 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119424 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119425 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119426 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119427 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119428 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119429 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
119430 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119431 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119432 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119433 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119434 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119435 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119436 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119437 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119438 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119439 +qp_free_res_17541 qp_free_res 5 17541 NULL
119440 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119441 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119442 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119443 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119444 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119445 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119446 +osst_execute_17607 osst_execute 7-6 17607 NULL
119447 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119448 +dma_map_page_17628 dma_map_page 0 17628 NULL
119449 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119450 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119451 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119452 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119453 +venus_rename_17707 venus_rename 4-5 17707 NULL
119454 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119455 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119456 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119457 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119458 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119459 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
119460 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119461 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119462 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119463 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119464 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119465 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119466 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119467 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119468 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119469 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119470 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119471 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119472 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119473 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119474 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119475 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119476 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119477 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119478 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119479 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119480 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119481 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119482 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119483 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119484 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119485 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119486 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119487 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
119488 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
119489 +fpregs_get_18066 fpregs_get 4 18066 NULL
119490 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
119491 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
119492 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
119493 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
119494 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
119495 +svc_getnl_18120 svc_getnl 0 18120 NULL
119496 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
119497 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
119498 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
119499 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
119500 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
119501 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
119502 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
119503 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
119504 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
119505 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
119506 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
119507 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
119508 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
119509 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
119510 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
119511 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
119512 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
119513 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
119514 +um_idi_write_18293 um_idi_write 3 18293 NULL
119515 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
119516 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
119517 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
119518 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
119519 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
119520 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
119521 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
119522 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
119523 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
119524 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
119525 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
119526 +ep_io_18367 ep_io 0 18367 NULL
119527 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
119528 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
119529 +ci_role_write_18388 ci_role_write 3 18388 NULL
119530 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
119531 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
119532 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
119533 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
119534 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
119535 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
119536 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
119537 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
119538 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
119539 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
119540 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
119541 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
119542 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
119543 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
119544 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
119545 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
119546 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
119547 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
119548 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
119549 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
119550 +debug_output_18575 debug_output 3 18575 NULL
119551 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
119552 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
119553 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
119554 +from_buffer_18625 from_buffer 3 18625 NULL
119555 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
119556 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
119557 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
119558 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
119559 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
119560 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
119561 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
119562 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
119563 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
119564 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
119565 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
119566 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
119567 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
119568 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
119569 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
119570 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
119571 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
119572 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
119573 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
119574 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
119575 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
119576 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
119577 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
119578 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
119579 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
119580 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
119581 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
119582 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
119583 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
119584 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
119585 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
119586 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
119587 +huge_page_size_19008 huge_page_size 0 19008 NULL
119588 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
119589 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
119590 +revalidate_19043 revalidate 2 19043 NULL
119591 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
119592 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
119593 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
119594 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
119595 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
119596 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
119597 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
119598 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
119599 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
119600 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
119601 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
119602 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
119603 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
119604 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
119605 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
119606 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
119607 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
119608 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
119609 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
119610 +ucma_query_19260 ucma_query 4 19260 NULL
119611 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
119612 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
119613 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
119614 +qc_capture_19298 qc_capture 3 19298 NULL
119615 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
119616 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
119617 +debug_read_19322 debug_read 3 19322 NULL
119618 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
119619 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
119620 +closure_sub_19359 closure_sub 2 19359 NULL
119621 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
119622 +read_zero_19366 read_zero 3 19366 NULL
119623 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
119624 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
119625 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
119626 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
119627 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
119628 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
119629 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
119630 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
119631 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
119632 +sky2_read16_19475 sky2_read16 0 19475 NULL
119633 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
119634 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
119635 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
119636 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
119637 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
119638 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
119639 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
119640 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
119641 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
119642 +nfsd_read_19568 nfsd_read 5 19568 NULL
119643 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
119644 +bm_status_read_19583 bm_status_read 3 19583 NULL
119645 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
119646 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
119647 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
119648 +parser_init_19651 parser_init 2 19651 NULL
119649 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
119650 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
119651 +read_reg_19723 read_reg 0 19723 NULL
119652 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
119653 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
119654 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
119655 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
119656 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
119657 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
119658 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
119659 +readhscx_19769 readhscx 0 19769 NULL
119660 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
119661 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
119662 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
119663 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
119664 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
119665 +__nla_put_19857 __nla_put 3 19857 NULL
119666 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
119667 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
119668 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
119669 +mangle_name_19923 mangle_name 0 19923 NULL
119670 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
119671 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
119672 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
119673 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
119674 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
119675 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
119676 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
119677 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
119678 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
119679 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
119680 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
119681 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
119682 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
119683 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
119684 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
119685 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
119686 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
119687 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
119688 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
119689 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
119690 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
119691 +target_message_20072 target_message 2 20072 NULL
119692 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
119693 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
119694 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
119695 +team_options_register_20091 team_options_register 3 20091 NULL
119696 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
119697 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
119698 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
119699 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
119700 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
119701 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
119702 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
119703 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
119704 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
119705 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
119706 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
119707 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
119708 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
119709 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
119710 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
119711 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
119712 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
119713 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
119714 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
119715 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
119716 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
119717 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
119718 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
119719 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
119720 +read_buf_20469 read_buf 2 20469 NULL
119721 +bio_trim_20472 bio_trim 2 20472 NULL
119722 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
119723 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
119724 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
119725 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
119726 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
119727 +venus_create_20555 venus_create 4 20555 NULL
119728 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
119729 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
119730 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
119731 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
119732 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
119733 +lirc_write_20604 lirc_write 3 20604 NULL
119734 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
119735 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
119736 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
119737 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
119738 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
119739 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
119740 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
119741 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
119742 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
119743 +cpumask_size_20683 cpumask_size 0 20683 NULL
119744 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
119745 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
119746 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
119747 +__maestro_read_20700 __maestro_read 0 20700 NULL
119748 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
119749 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
119750 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
119751 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
119752 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
119753 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
119754 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
119755 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
119756 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
119757 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
119758 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
119759 +edid_write_20797 edid_write 3 20797 NULL
119760 +lowpan_write_20800 lowpan_write 3 20800 NULL
119761 +strndup_user_20819 strndup_user 2 20819 NULL
119762 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
119763 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
119764 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
119765 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
119766 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
119767 +get_name_20855 get_name 4 20855 NULL
119768 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
119769 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
119770 +srq_free_res_20868 srq_free_res 5 20868 NULL
119771 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
119772 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
119773 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
119774 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
119775 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
119776 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
119777 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
119778 +htable_bits_20933 htable_bits 0 20933 NULL
119779 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
119780 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
119781 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
119782 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
119783 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
119784 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
119785 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
119786 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
119787 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
119788 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
119789 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
119790 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
119791 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
119792 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
119793 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
119794 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
119795 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
119796 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
119797 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
119798 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
119799 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
119800 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
119801 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
119802 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
119803 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
119804 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
119805 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
119806 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
119807 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
119808 +input_ff_create_21240 input_ff_create 2 21240 NULL
119809 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
119810 +fru_length_21257 fru_length 0 21257 NULL
119811 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
119812 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
119813 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
119814 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
119815 +add_res_range_21310 add_res_range 4 21310 NULL
119816 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
119817 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
119818 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
119819 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
119820 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
119821 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
119822 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
119823 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
119824 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
119825 +insert_ptr_21386 insert_ptr 6 21386 NULL
119826 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
119827 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
119828 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
119829 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
119830 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
119831 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
119832 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
119833 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
119834 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
119835 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
119836 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
119837 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
119838 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
119839 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
119840 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
119841 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
119842 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
119843 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
119844 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
119845 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
119846 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
119847 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
119848 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
119849 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
119850 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
119851 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
119852 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
119853 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
119854 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
119855 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
119856 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
119857 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
119858 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
119859 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
119860 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
119861 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
119862 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
119863 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
119864 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
119865 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
119866 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
119867 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
119868 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
119869 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
119870 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
119871 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
119872 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
119873 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
119874 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
119875 +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
119876 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
119877 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
119878 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
119879 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
119880 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
119881 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
119882 +mem_rw_22085 mem_rw 3 22085 NULL
119883 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
119884 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
119885 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
119886 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
119887 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
119888 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
119889 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
119890 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
119891 +mem_write_22232 mem_write 3 22232 NULL
119892 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
119893 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
119894 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
119895 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
119896 +add_res_tree_22263 add_res_tree 7 22263 NULL
119897 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
119898 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
119899 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
119900 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
119901 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
119902 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
119903 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
119904 +atomic_read_22342 atomic_read 0 22342 NULL
119905 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
119906 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
119907 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
119908 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
119909 +zoran_write_22404 zoran_write 3 22404 NULL
119910 +queue_reply_22416 queue_reply 3 22416 NULL
119911 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
119912 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
119913 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
119914 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
119915 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
119916 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
119917 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
119918 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
119919 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
119920 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
119921 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
119922 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
119923 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
119924 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
119925 +snapshot_read_22601 snapshot_read 3 22601 NULL
119926 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
119927 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
119928 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
119929 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
119930 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
119931 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
119932 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
119933 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
119934 +reg_umr_22686 reg_umr 5 22686 NULL
119935 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
119936 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
119937 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
119938 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
119939 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
119940 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
119941 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
119942 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
119943 +print_frame_22769 print_frame 0 22769 NULL
119944 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
119945 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
119946 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
119947 +create_attr_set_22861 create_attr_set 1 22861 NULL
119948 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
119949 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
119950 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
119951 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
119952 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
119953 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
119954 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
119955 +__set_xattr_22923 __set_xattr 0 22923 NULL
119956 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
119957 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
119958 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
119959 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
119960 +vme_get_size_22964 vme_get_size 0 22964 NULL
119961 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
119962 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
119963 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
119964 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
119965 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
119966 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
119967 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
119968 +st_status_23032 st_status 5 23032 NULL
119969 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
119970 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
119971 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
119972 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
119973 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
119974 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
119975 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
119976 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
119977 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
119978 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
119979 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
119980 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
119981 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
119982 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
119983 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
119984 +__clear_user_23118 __clear_user 0-2 23118 NULL
119985 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
119986 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
119987 +read_file_ani_23161 read_file_ani 3 23161 NULL
119988 +usblp_write_23178 usblp_write 3 23178 NULL
119989 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
119990 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
119991 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
119992 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
119993 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
119994 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
119995 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
119996 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
119997 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
119998 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
119999 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120000 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120001 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120002 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120003 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120004 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120005 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120006 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120007 +page_readlink_23346 page_readlink 3 23346 NULL
120008 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120009 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120010 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120011 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120012 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120013 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120014 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120015 +linear_conf_23485 linear_conf 2 23485 NULL
120016 +event_filter_read_23494 event_filter_read 3 23494 NULL
120017 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120018 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120019 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120020 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120021 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120022 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120023 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120024 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120025 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120026 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120027 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120028 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120029 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120030 +sInW_23663 sInW 0 23663 NULL
120031 +SyS_connect_23669 SyS_connect 3 23669 NULL
120032 +cx18_read_23699 cx18_read 3 23699 NULL
120033 +at_get_23708 at_get 0 23708 NULL
120034 +get_conn_info_23723 get_conn_info 4 23723 NULL
120035 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120036 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120037 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120038 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120039 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120040 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120041 +map_write_23795 map_write 3 23795 NULL
120042 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120043 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120044 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120045 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120046 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120047 +p54_init_common_23850 p54_init_common 1 23850 NULL
120048 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120049 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120050 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120051 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120052 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120053 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120054 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120055 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120056 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120057 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120058 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120059 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120060 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120061 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120062 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120063 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120064 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
120065 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120066 +give_pages_24021 give_pages 3 24021 NULL
120067 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120068 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120069 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120070 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120071 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120072 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120073 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120074 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120075 +lov_brw_24122 lov_brw 4 24122 NULL
120076 +mpu401_read_24126 mpu401_read 3 24126 NULL
120077 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120078 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120079 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120080 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120081 +adu_read_24177 adu_read 3 24177 NULL
120082 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120083 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120084 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120085 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
120086 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120087 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120088 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120089 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120090 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120091 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120092 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120093 +thin_status_24278 thin_status 5 24278 NULL
120094 +msg_size_24288 msg_size 0 24288 NULL
120095 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120096 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120097 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120098 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120099 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120100 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120101 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120102 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120103 +igetword_24373 igetword 0 24373 NULL
120104 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120105 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120106 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120107 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120108 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
120109 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120110 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120111 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120112 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120113 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120114 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120115 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120116 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120117 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120118 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120119 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120120 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120121 +ttm_page_pool_free_24486 ttm_page_pool_free 2-0 24486 NULL
120122 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120123 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120124 +pd_video_read_24510 pd_video_read 3 24510 NULL
120125 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120126 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120127 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120128 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120129 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120130 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120131 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120132 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
120133 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
120134 +SyS_poll_24620 SyS_poll 2 24620 NULL
120135 +context_alloc_24645 context_alloc 3 24645 NULL
120136 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120137 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120138 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120139 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120140 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120141 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120142 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120143 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120144 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120145 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120146 +cache_read_24790 cache_read 3 24790 NULL
120147 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120148 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120149 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120150 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120151 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120152 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120153 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120154 +queues_read_24877 queues_read 3 24877 NULL
120155 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120156 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120157 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120158 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120159 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120160 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120161 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120162 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
120163 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
120164 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120165 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120166 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120167 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120168 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120169 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120170 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120171 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120172 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120173 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
120174 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120175 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120176 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120177 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120178 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120179 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120180 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120181 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120182 +stripe_status_25259 stripe_status 5 25259 NULL
120183 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120184 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120185 +vfs_writev_25278 vfs_writev 3 25278 NULL
120186 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120187 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
120188 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120189 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120190 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120191 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120192 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120193 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120194 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120195 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120196 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120197 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120198 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120199 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120200 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120201 +sb_permission_25523 sb_permission 0 25523 NULL
120202 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120203 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120204 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120205 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120206 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120207 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120208 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120209 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120210 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120211 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120212 +__direct_map_25647 __direct_map 6-5 25647 NULL
120213 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120214 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120215 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120216 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120217 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120218 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120219 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120220 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120221 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120222 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120223 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120224 +sg_read_25799 sg_read 3 25799 NULL
120225 +system_enable_read_25815 system_enable_read 3 25815 NULL
120226 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120227 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120228 +parport_read_25855 parport_read 0 25855 NULL
120229 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120230 +key_attr_size_25865 key_attr_size 0 25865 NULL
120231 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120232 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120233 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120234 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120235 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120236 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120237 +rcname_read_25919 rcname_read 3 25919 NULL
120238 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120239 +key_flags_read_25931 key_flags_read 3 25931 NULL
120240 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120241 +flush_25957 flush 2 25957 NULL
120242 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120243 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120244 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120245 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120246 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120247 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120248 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120249 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120250 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120251 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120252 +read_sb_page_26119 read_sb_page 5 26119 NULL
120253 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120254 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120255 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120256 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120257 +disk_devt_26180 disk_devt 0 26180 NULL
120258 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120259 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120260 +mce_write_26201 mce_write 3 26201 NULL
120261 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120262 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120263 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120264 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
120265 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120266 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120267 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120268 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120269 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120270 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120271 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120272 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120273 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120274 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120275 +ntty_write_26404 ntty_write 3 26404 NULL
120276 +firmware_store_26408 firmware_store 4 26408 NULL
120277 +pagemap_read_26441 pagemap_read 3 26441 NULL
120278 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120279 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120280 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120281 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120282 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
120283 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
120284 +read_vmcore_26501 read_vmcore 3 26501 NULL
120285 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120286 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120287 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120288 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120289 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120290 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120291 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120292 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120293 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120294 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120295 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120296 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120297 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120298 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120299 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120300 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120301 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120302 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120303 +bos_desc_26752 bos_desc 0 26752 NULL
120304 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120305 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120306 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120307 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120308 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120309 +smk_write_load_26829 smk_write_load 3 26829 NULL
120310 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
120311 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120312 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120313 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120314 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120315 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120316 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120317 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120318 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120319 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120320 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120321 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120322 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120323 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120324 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120325 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120326 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120327 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120328 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120329 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120330 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120331 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120332 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120333 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120334 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120335 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120336 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120337 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120338 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120339 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120340 +pms_capture_27142 pms_capture 4 27142 NULL
120341 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120342 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120343 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120344 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120345 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120346 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120347 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120348 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120349 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120350 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120351 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120352 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120353 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120354 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120355 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120356 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120357 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120358 +seq_read_27411 seq_read 3 27411 NULL
120359 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120360 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120361 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120362 +cypress_write_27423 cypress_write 4 27423 NULL
120363 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120364 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120365 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120366 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120367 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120368 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
120369 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
120370 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120371 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120372 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120373 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120374 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120375 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120376 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120377 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120378 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120379 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120380 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120381 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120382 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120383 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120384 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120385 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120386 +evm_write_key_27715 evm_write_key 3 27715 NULL
120387 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120388 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120389 +load_scode_27738 load_scode 2 27738 NULL
120390 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120391 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120392 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120393 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120394 +SyS_readv_27804 SyS_readv 3 27804 NULL
120395 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120396 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120397 +init_header_complete_27833 init_header_complete 0 27833 NULL
120398 +read_profile_27859 read_profile 3 27859 NULL
120399 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120400 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120401 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120402 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120403 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120404 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120405 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120406 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120407 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120408 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120409 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120410 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120411 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120412 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120413 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120414 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120415 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120416 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120417 +pool_status_28055 pool_status 5 28055 NULL
120418 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120419 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120420 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120421 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120422 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120423 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120424 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120425 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120426 +video_read_28148 video_read 3 28148 NULL
120427 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120428 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120429 +vread_28173 vread 0-3 28173 NULL
120430 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120431 +counter_free_res_28187 counter_free_res 5 28187 NULL
120432 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120433 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120434 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120435 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120436 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120437 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120438 +usemap_size_28281 usemap_size 0 28281 NULL
120439 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120440 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120441 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120442 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120443 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120444 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120445 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120446 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120447 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120448 +snapshot_write_28351 snapshot_write 3 28351 NULL
120449 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120450 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120451 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120452 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120453 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120454 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120455 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120456 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120457 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120458 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120459 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120460 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120461 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120462 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120463 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120464 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120465 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120466 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120467 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120468 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120469 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120470 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120471 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120472 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120473 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120474 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120475 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120476 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120477 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120478 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120479 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120480 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120481 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
120482 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120483 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120484 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120485 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120486 +spi_execute_28736 spi_execute 5 28736 NULL
120487 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120488 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120489 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120490 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120491 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120492 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120493 +sel_write_member_28800 sel_write_member 3 28800 NULL
120494 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120495 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120496 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120497 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120498 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120499 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120500 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120501 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120502 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120503 +push_rx_28939 push_rx 3 28939 NULL
120504 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120505 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120506 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120507 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120508 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120509 +bin_uuid_28999 bin_uuid 3 28999 NULL
120510 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120511 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
120512 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
120513 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
120514 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
120515 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
120516 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
120517 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
120518 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
120519 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
120520 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
120521 +snprintf_29125 snprintf 0 29125 NULL
120522 +iov_shorten_29130 iov_shorten 0 29130 NULL
120523 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
120524 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
120525 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
120526 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
120527 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
120528 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
120529 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
120530 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
120531 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
120532 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
120533 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
120534 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
120535 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
120536 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
120537 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
120538 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
120539 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
120540 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
120541 +tun_put_user_29337 tun_put_user 5 29337 NULL
120542 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
120543 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
120544 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
120545 +mempool_create_29437 mempool_create 1 29437 NULL
120546 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
120547 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
120548 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
120549 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
120550 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
120551 +do_register_entry_29478 do_register_entry 4 29478 NULL
120552 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
120553 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
120554 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
120555 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
120556 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
120557 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
120558 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
120559 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
120560 +ftrace_write_29551 ftrace_write 3 29551 NULL
120561 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
120562 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
120563 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
120564 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
120565 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
120566 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
120567 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
120568 +slots_per_page_29601 slots_per_page 0 29601 NULL
120569 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
120570 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
120571 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
120572 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
120573 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
120574 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
120575 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
120576 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
120577 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
120578 +probes_write_29711 probes_write 3 29711 NULL
120579 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
120580 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
120581 +std_nic_write_29752 std_nic_write 3 29752 NULL
120582 +static_key_count_29771 static_key_count 0 29771 NULL
120583 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
120584 +dbAlloc_29794 dbAlloc 0 29794 NULL
120585 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
120586 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
120587 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
120588 +count_partial_29850 count_partial 0 29850 NULL
120589 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
120590 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
120591 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
120592 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
120593 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
120594 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
120595 +write_file_queue_29922 write_file_queue 3 29922 NULL
120596 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
120597 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
120598 +zero_iovec_29955 zero_iovec 1 29955 NULL
120599 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
120600 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
120601 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
120602 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
120603 +drp_wmove_30043 drp_wmove 4 30043 NULL
120604 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
120605 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
120606 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
120607 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
120608 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
120609 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
120610 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
120611 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
120612 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
120613 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
120614 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
120615 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
120616 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
120617 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
120618 +SyS_semop_30227 SyS_semop 3 30227 NULL
120619 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
120620 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
120621 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
120622 +compat_readv_30273 compat_readv 3 30273 NULL
120623 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
120624 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
120625 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
120626 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
120627 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
120628 +i8254_read_30330 i8254_read 0 30330 NULL
120629 +resource_from_user_30341 resource_from_user 3 30341 NULL
120630 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
120631 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
120632 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
120633 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
120634 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
120635 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
120636 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
120637 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
120638 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
120639 +enable_write_30456 enable_write 3 30456 NULL
120640 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
120641 +urandom_read_30462 urandom_read 3 30462 NULL
120642 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
120643 +adu_write_30487 adu_write 3 30487 NULL
120644 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
120645 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
120646 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
120647 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
120648 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
120649 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
120650 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
120651 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
120652 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
120653 +set_le_30581 set_le 4 30581 NULL
120654 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
120655 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
120656 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
120657 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
120658 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
120659 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
120660 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
120661 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
120662 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
120663 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
120664 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
120665 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
120666 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
120667 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
120668 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
120669 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
120670 +snapshot_status_30744 snapshot_status 5 30744 NULL
120671 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
120672 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
120673 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
120674 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
120675 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
120676 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
120677 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
120678 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
120679 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
120680 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
120681 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
120682 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
120683 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
120684 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
120685 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
120686 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
120687 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
120688 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
120689 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
120690 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
120691 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
120692 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
120693 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
120694 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
120695 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
120696 +depth_read_31112 depth_read 3 31112 NULL
120697 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
120698 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
120699 +size_inside_page_31141 size_inside_page 0 31141 NULL
120700 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
120701 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
120702 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
120703 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
120704 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
120705 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
120706 +__read_reg_31216 __read_reg 0 31216 NULL
120707 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
120708 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
120709 +cyy_readb_31240 cyy_readb 0 31240 NULL
120710 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
120711 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
120712 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
120713 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
120714 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
120715 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
120716 +command_file_write_31318 command_file_write 3 31318 NULL
120717 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
120718 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
120719 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
120720 +outlen_write_31358 outlen_write 3 31358 NULL
120721 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
120722 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
120723 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
120724 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
120725 +inb_31388 inb 0 31388 NULL
120726 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
120727 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
120728 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
120729 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
120730 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
120731 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
120732 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
120733 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
120734 +alg_setkey_31485 alg_setkey 3 31485 NULL
120735 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
120736 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
120737 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
120738 +hidraw_write_31536 hidraw_write 3 31536 NULL
120739 +usbvision_read_31555 usbvision_read 3 31555 NULL
120740 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
120741 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
120742 +osst_write_31581 osst_write 3 31581 NULL
120743 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
120744 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
120745 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
120746 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
120747 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
120748 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
120749 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
120750 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
120751 +__lgread_31668 __lgread 4 31668 NULL
120752 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
120753 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
120754 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
120755 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
120756 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
120757 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
120758 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
120759 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
120760 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
120761 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
120762 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
120763 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
120764 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
120765 +get_count_order_31800 get_count_order 0 31800 NULL
120766 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
120767 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
120768 +data_write_31805 data_write 3 31805 NULL
120769 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
120770 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
120771 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
120772 +clone_bio_31854 clone_bio 4-3 31854 NULL
120773 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
120774 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
120775 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
120776 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
120777 +xattr_permission_31907 xattr_permission 0 31907 NULL
120778 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
120779 +new_dir_31919 new_dir 3 31919 NULL
120780 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
120781 +era_status_31934 era_status 5 31934 NULL
120782 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
120783 +read_mem_31942 read_mem 3 31942 NULL
120784 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
120785 +vb2_write_31948 vb2_write 3 31948 NULL
120786 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
120787 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
120788 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
120789 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
120790 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
120791 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
120792 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
120793 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
120794 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
120795 +calc_hmac_32010 calc_hmac 3 32010 NULL
120796 +aead_len_32021 aead_len 0 32021 NULL
120797 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
120798 +stk_read_32038 stk_read 3 32038 NULL
120799 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
120800 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
120801 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
120802 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
120803 +bio_alloc_32095 bio_alloc 2 32095 NULL
120804 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
120805 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
120806 +disk_status_32120 disk_status 4 32120 NULL
120807 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
120808 +venus_link_32165 venus_link 5 32165 NULL
120809 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
120810 +do_writepages_32173 do_writepages 0 32173 NULL
120811 +del_ptr_32197 del_ptr 4 32197 NULL
120812 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
120813 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
120814 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
120815 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
120816 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
120817 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
120818 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
120819 +SyS_select_32319 SyS_select 1 32319 NULL
120820 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
120821 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
120822 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
120823 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
120824 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
120825 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
120826 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
120827 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
120828 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
120829 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
120830 +cache_status_32462 cache_status 5 32462 NULL
120831 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
120832 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
120833 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
120834 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
120835 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
120836 +disconnect_32521 disconnect 4 32521 NULL
120837 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
120838 +ilo_read_32531 ilo_read 3 32531 NULL
120839 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
120840 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
120841 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
120842 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
120843 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
120844 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
120845 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
120846 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
120847 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
120848 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
120849 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
120850 +kvmalloc_32646 kvmalloc 1 32646 NULL
120851 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
120852 +generic_readlink_32654 generic_readlink 3 32654 NULL
120853 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
120854 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
120855 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
120856 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
120857 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
120858 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
120859 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
120860 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
120861 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
120862 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
120863 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
120864 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
120865 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
120866 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
120867 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
120868 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
120869 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
120870 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
120871 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
120872 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
120873 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
120874 +compat_filldir_32999 compat_filldir 3 32999 NULL
120875 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
120876 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
120877 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
120878 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
120879 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
120880 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
120881 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
120882 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
120883 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
120884 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
120885 +alloc_tio_33077 alloc_tio 3 33077 NULL
120886 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
120887 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
120888 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
120889 +SyS_poll_33152 SyS_poll 2 33152 NULL
120890 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
120891 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
120892 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
120893 +pp_read_33210 pp_read 3 33210 NULL
120894 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
120895 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
120896 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
120897 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
120898 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
120899 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
120900 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
120901 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
120902 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
120903 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
120904 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
120905 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
120906 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
120907 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
120908 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
120909 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
120910 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
120911 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
120912 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
120913 +message_stats_list_33440 message_stats_list 5 33440 NULL
120914 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
120915 +create_entry_33479 create_entry 2 33479 NULL
120916 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
120917 +res_counter_read_33499 res_counter_read 4 33499 NULL
120918 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
120919 +fb_read_33506 fb_read 3 33506 NULL
120920 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
120921 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
120922 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
120923 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
120924 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
120925 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
120926 +count_subheaders_33591 count_subheaders 0 33591 NULL
120927 +scsi_execute_33596 scsi_execute 5 33596 NULL
120928 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
120929 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
120930 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
120931 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
120932 +stride_page_count_33641 stride_page_count 2 33641 NULL
120933 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
120934 +inw_p_33668 inw_p 0 33668 NULL
120935 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
120936 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
120937 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
120938 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
120939 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
120940 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
120941 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
120942 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
120943 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
120944 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
120945 +hashtab_create_33769 hashtab_create 3 33769 NULL
120946 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
120947 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
120948 +filter_write_33819 filter_write 3 33819 NULL
120949 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
120950 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
120951 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
120952 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
120953 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
120954 +get_user_pages_33908 get_user_pages 0 33908 NULL
120955 +sg_nents_33909 sg_nents 0 33909 NULL
120956 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
120957 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
120958 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
120959 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
120960 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
120961 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
120962 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
120963 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
120964 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
120965 +ppp_write_34034 ppp_write 3 34034 NULL
120966 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
120967 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
120968 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
120969 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
120970 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
120971 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
120972 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
120973 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
120974 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
120975 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
120976 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
120977 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
120978 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
120979 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
120980 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
120981 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
120982 +device_private_init_34279 device_private_init 0 34279 NULL
120983 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
120984 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
120985 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
120986 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
120987 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
120988 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
120989 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
120990 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
120991 +ea_read_34378 ea_read 0 34378 NULL nohasharray
120992 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
120993 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
120994 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
120995 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
120996 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
120997 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
120998 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
120999 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121000 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121001 +security_socket_create_34439 security_socket_create 0 34439 NULL
121002 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121003 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121004 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121005 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121006 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121007 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121008 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121009 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121010 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121011 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121012 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121013 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121014 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121015 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121016 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121017 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121018 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121019 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121020 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121021 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121022 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121023 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121024 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121025 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121026 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121027 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121028 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121029 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121030 +port_print_34704 port_print 3 34704 NULL
121031 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121032 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121033 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121034 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121035 +bootmode_store_34762 bootmode_store 4 34762 NULL
121036 +device_add_34766 device_add 0 34766 NULL
121037 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121038 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121039 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121040 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121041 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121042 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121043 +file_page_index_34820 file_page_index 0-2 34820 NULL
121044 +bio_segments_34832 bio_segments 0 34832 NULL
121045 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121046 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121047 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121048 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121049 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121050 +msg_print_text_34889 msg_print_text 0 34889 NULL
121051 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121052 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121053 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121054 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121055 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121056 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121057 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121058 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121059 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121060 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121061 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121062 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121063 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121064 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121065 +proc_setgroups_write_35039 proc_setgroups_write 3 35039 NULL
121066 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121067 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121068 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121069 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121070 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121071 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121072 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121073 +message_stats_print_35158 message_stats_print 6 35158 NULL
121074 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121075 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121076 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121077 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121078 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121079 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121080 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121081 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121082 +set_fd_set_35249 set_fd_set 1 35249 NULL
121083 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121084 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121085 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121086 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121087 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121088 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
121089 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
121090 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121091 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121092 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121093 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121094 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121095 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121096 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121097 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121098 +read_kmem_35372 read_kmem 3 35372 NULL
121099 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121100 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121101 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121102 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121103 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121104 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121105 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121106 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121107 +async_setkey_35521 async_setkey 3 35521 NULL
121108 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121109 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121110 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121111 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121112 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121113 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121114 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121115 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121116 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121117 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121118 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121119 +kernel_readv_35617 kernel_readv 3 35617 NULL
121120 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121121 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121122 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121123 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121124 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121125 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121126 +md_super_write_35703 md_super_write 4 35703 NULL
121127 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121128 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121129 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121130 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121131 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121132 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121133 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121134 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121135 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121136 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121137 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121138 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121139 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121140 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121141 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121142 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121143 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121144 +acl_alloc_35979 acl_alloc 1 35979 NULL
121145 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121146 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121147 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121148 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121149 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121150 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121151 +account_shadowed_36048 account_shadowed 2 36048 NULL
121152 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121153 +write_emulate_36065 write_emulate 2-4 36065 NULL
121154 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121155 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121156 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121157 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121158 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121159 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121160 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121161 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121162 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121163 +twl_set_36154 twl_set 2 36154 NULL
121164 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121165 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121166 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121167 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121168 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121169 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121170 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121171 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121172 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121173 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121174 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121175 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121176 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121177 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121178 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121179 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121180 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121181 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121182 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121183 +lc_create_36332 lc_create 4 36332 NULL
121184 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121185 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121186 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121187 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121188 +to_sector_36361 to_sector 0-1 36361 NULL
121189 +tunables_read_36385 tunables_read 3 36385 NULL
121190 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121191 +sierra_write_36402 sierra_write 4 36402 NULL
121192 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121193 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121194 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121195 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121196 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121197 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121198 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121199 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121200 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121201 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121202 +cmd_loop_36491 cmd_loop 0 36491 NULL
121203 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121204 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121205 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121206 +get_param_l_36518 get_param_l 0 36518 NULL
121207 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121208 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121209 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121210 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121211 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121212 +__erst_read_36579 __erst_read 0 36579 NULL
121213 +put_cmsg_36589 put_cmsg 4 36589 NULL
121214 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121215 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121216 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121217 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121218 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121219 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121220 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121221 +xillybus_read_36678 xillybus_read 3 36678 NULL
121222 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121223 +path_getxattr_36717 path_getxattr 4 36717 NULL
121224 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121225 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121226 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121227 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121228 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121229 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121230 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121231 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121232 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121233 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121234 +cm_write_36858 cm_write 3 36858 NULL
121235 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121236 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121237 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121238 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121239 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121240 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121241 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121242 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121243 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121244 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121245 +setxattr_37006 setxattr 4 37006 NULL
121246 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121247 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121248 +command_file_read_37038 command_file_read 3 37038 NULL
121249 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121250 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121251 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121252 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121253 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121254 +parse_command_37079 parse_command 2 37079 NULL
121255 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121256 +tun_get_user_37094 tun_get_user 5 37094 NULL
121257 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121258 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121259 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121260 +msg_word_37164 msg_word 0 37164 NULL
121261 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121262 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121263 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121264 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121265 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121266 +__do_replace_37227 __do_replace 5 37227 NULL
121267 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121268 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121269 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121270 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121271 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121272 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121273 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121274 +tipc_send_37315 tipc_send 3 37315 NULL
121275 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121276 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121277 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121278 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121279 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121280 +seek_firmware_37372 seek_firmware 2 37372 NULL
121281 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121282 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121283 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121284 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121285 +fru_alloc_37442 fru_alloc 1 37442 NULL
121286 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121287 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121288 +get_est_timing_37484 get_est_timing 0 37484 NULL
121289 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121290 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121291 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121292 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121293 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121294 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121295 +hdr_size_37536 hdr_size 0 37536 NULL
121296 +extent_map_end_37550 extent_map_end 0 37550 NULL
121297 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121298 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121299 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121300 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121301 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121302 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121303 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121304 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121305 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121306 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121307 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121308 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121309 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121310 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121311 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121312 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121313 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121314 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121315 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121316 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121317 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121318 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121319 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121320 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121321 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121322 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121323 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121324 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121325 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121326 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121327 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121328 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121329 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121330 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121331 +write_file_bool_37957 write_file_bool 3 37957 NULL
121332 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121333 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121334 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121335 +vfs_readv_38011 vfs_readv 3 38011 NULL
121336 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121337 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121338 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121339 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121340 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121341 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121342 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121343 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121344 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121345 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121346 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121347 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121348 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121349 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121350 +ep0_read_38095 ep0_read 3 38095 NULL
121351 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121352 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121353 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121354 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121355 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121356 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121357 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121358 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121359 +cdev_add_38176 cdev_add 2-3 38176 NULL
121360 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121361 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121362 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121363 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121364 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121365 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121366 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121367 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121368 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121369 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121370 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121371 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121372 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121373 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121374 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121375 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121376 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121377 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121378 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121379 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121380 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121381 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121382 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121383 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121384 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121385 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121386 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121387 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121388 +dev_names_read_38509 dev_names_read 3 38509 NULL
121389 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121390 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121391 +set_queue_count_38519 set_queue_count 0 38519 NULL
121392 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121393 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121394 +kuc_len_38557 kuc_len 0-1 38557 NULL
121395 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121396 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121397 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121398 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121399 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121400 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121401 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121402 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121403 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121404 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121405 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121406 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121407 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121408 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121409 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121410 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121411 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121412 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121413 +udf_readpages_38761 udf_readpages 4 38761 NULL
121414 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121415 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121416 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121417 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121418 +err_decode_38804 err_decode 2 38804 NULL
121419 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121420 +direct_entry_38836 direct_entry 3 38836 NULL
121421 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121422 +interfaces_38859 interfaces 2 38859 NULL
121423 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121424 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121425 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121426 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121427 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121428 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121429 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121430 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121431 +get_nodes_39012 get_nodes 3 39012 NULL
121432 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121433 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121434 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121435 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121436 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121437 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121438 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121439 +ea_foreach_39133 ea_foreach 0 39133 NULL
121440 +generic_permission_39150 generic_permission 0 39150 NULL
121441 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121442 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121443 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121444 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121445 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
121446 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121447 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121448 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121449 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121450 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121451 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121452 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121453 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121454 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121455 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121456 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121457 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121458 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121459 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121460 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121461 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121462 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121463 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121464 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121465 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121466 +__send_to_port_39386 __send_to_port 3 39386 NULL
121467 +user_power_read_39414 user_power_read 3 39414 NULL
121468 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121469 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121470 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121471 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121472 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121473 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121474 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121475 +int_proc_write_39542 int_proc_write 3 39542 NULL
121476 +pp_write_39554 pp_write 3 39554 NULL
121477 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121478 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121479 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121480 +ext_depth_39607 ext_depth 0 39607 NULL
121481 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121482 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121483 +sdio_readb_39618 sdio_readb 0 39618 NULL
121484 +set_dev_class_39645 set_dev_class 4 39645 NULL
121485 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121486 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121487 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121488 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121489 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121490 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121491 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121492 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121493 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121494 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121495 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121496 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121497 +pkt_add_39897 pkt_add 3 39897 NULL
121498 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121499 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121500 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121501 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121502 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121503 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121504 +__spi_async_39932 __spi_async 0 39932 NULL
121505 +__get_order_39935 __get_order 0 39935 NULL
121506 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121507 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121508 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121509 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121510 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121511 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121512 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121513 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121514 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121515 +server_name2svname_39998 server_name2svname 4 39998 NULL
121516 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121517 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121518 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121519 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121520 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121521 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121522 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121523 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121524 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121525 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121526 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121527 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
121528 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
121529 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
121530 +pt_write_40159 pt_write 3 40159 NULL
121531 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
121532 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
121533 +allocate_probes_40204 allocate_probes 1 40204 NULL
121534 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
121535 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
121536 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
121537 +osst_read_40237 osst_read 3 40237 NULL
121538 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
121539 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
121540 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
121541 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
121542 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
121543 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
121544 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
121545 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
121546 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
121547 +SyS_bind_40303 SyS_bind 3 40303 NULL
121548 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
121549 +mmio_read_40348 mmio_read 4 40348 NULL
121550 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
121551 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
121552 +get_chars_40373 get_chars 3 40373 NULL
121553 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
121554 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
121555 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
121556 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
121557 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
121558 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
121559 +SyS_writev_40467 SyS_writev 3 40467 NULL
121560 +SyS_select_40473 SyS_select 1 40473 NULL
121561 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
121562 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
121563 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
121564 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
121565 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
121566 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
121567 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
121568 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
121569 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
121570 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
121571 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
121572 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
121573 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
121574 +fops_read_40672 fops_read 3 40672 NULL
121575 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
121576 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
121577 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
121578 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
121579 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
121580 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
121581 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
121582 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
121583 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
121584 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
121585 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
121586 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
121587 +card_send_command_40757 card_send_command 3 40757 NULL
121588 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
121589 +pg_write_40766 pg_write 3 40766 NULL
121590 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
121591 +show_list_40775 show_list 3-0 40775 NULL
121592 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
121593 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
121594 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
121595 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
121596 +add_action_40811 add_action 4 40811 NULL
121597 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
121598 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
121599 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
121600 +read_file_queue_40895 read_file_queue 3 40895 NULL
121601 +waiters_read_40902 waiters_read 3 40902 NULL
121602 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
121603 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
121604 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
121605 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
121606 +path_listxattr_40949 path_listxattr 3 40949 NULL
121607 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
121608 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
121609 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
121610 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
121611 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
121612 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
121613 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
121614 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
121615 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
121616 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
121617 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
121618 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
121619 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
121620 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
121621 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
121622 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
121623 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
121624 +dma_attach_41094 dma_attach 5-6 41094 NULL
121625 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
121626 +provide_user_output_41105 provide_user_output 3 41105 NULL
121627 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
121628 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
121629 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
121630 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
121631 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
121632 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
121633 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
121634 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
121635 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
121636 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
121637 +erst_read_41260 erst_read 0 41260 NULL
121638 +alloc_context_41283 alloc_context 1 41283 NULL
121639 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
121640 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
121641 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
121642 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
121643 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
121644 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
121645 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
121646 +kmp_init_41373 kmp_init 2 41373 NULL
121647 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
121648 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
121649 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
121650 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
121651 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
121652 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
121653 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
121654 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
121655 +se_io_cb_41461 se_io_cb 3 41461 NULL
121656 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
121657 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
121658 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
121659 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
121660 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
121661 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
121662 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
121663 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
121664 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
121665 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
121666 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
121667 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
121668 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
121669 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
121670 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
121671 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
121672 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
121673 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
121674 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
121675 +a2mp_send_41615 a2mp_send 4 41615 NULL
121676 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
121677 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
121678 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
121679 +get_std_timing_41654 get_std_timing 0 41654 NULL
121680 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
121681 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
121682 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
121683 +connector_write_41709 connector_write 3 41709 NULL
121684 +fillonedir_41746 fillonedir 3 41746 NULL
121685 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
121686 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
121687 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
121688 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
121689 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
121690 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
121691 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
121692 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
121693 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
121694 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
121695 +pci_map_single_41869 pci_map_single 0 41869 NULL
121696 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
121697 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
121698 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
121699 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
121700 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
121701 +read_gssp_41947 read_gssp 3 41947 NULL
121702 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
121703 +portnames_read_41958 portnames_read 3 41958 NULL
121704 +dst_mtu_41969 dst_mtu 0 41969 NULL
121705 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
121706 +pool_allocate_42012 pool_allocate 3 42012 NULL
121707 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
121708 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
121709 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
121710 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
121711 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
121712 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
121713 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
121714 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
121715 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
121716 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
121717 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
121718 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
121719 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
121720 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
121721 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
121722 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
121723 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
121724 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
121725 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
121726 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
121727 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
121728 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
121729 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
121730 +find_last_bit_42260 find_last_bit 0 42260 NULL
121731 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
121732 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
121733 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
121734 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
121735 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
121736 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
121737 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
121738 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
121739 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
121740 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
121741 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
121742 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
121743 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
121744 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
121745 +krng_get_random_42420 krng_get_random 3 42420 NULL
121746 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
121747 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
121748 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
121749 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
121750 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
121751 +kuc_free_42455 kuc_free 2 42455 NULL
121752 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
121753 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
121754 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
121755 +bypass_write_42498 bypass_write 3 42498 NULL
121756 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
121757 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
121758 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
121759 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
121760 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
121761 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
121762 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
121763 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
121764 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
121765 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
121766 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
121767 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
121768 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
121769 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
121770 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
121771 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
121772 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
121773 +vb2_read_42703 vb2_read 3 42703 NULL
121774 +read_status_42722 read_status 0 42722 NULL
121775 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
121776 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
121777 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
121778 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
121779 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
121780 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
121781 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
121782 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
121783 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
121784 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
121785 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
121786 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
121787 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
121788 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
121789 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
121790 +set_arg_42824 set_arg 3 42824 NULL
121791 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
121792 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
121793 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
121794 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
121795 +hd_end_request_42904 hd_end_request 2 42904 NULL
121796 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
121797 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
121798 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
121799 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
121800 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
121801 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
121802 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
121803 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
121804 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
121805 +__bioset_create_43059 __bioset_create 1 43059 NULL
121806 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
121807 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
121808 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
121809 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
121810 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
121811 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
121812 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
121813 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
121814 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
121815 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
121816 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
121817 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
121818 +uio_write_43202 uio_write 3 43202 NULL
121819 +iso_callback_43208 iso_callback 3 43208 NULL
121820 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
121821 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
121822 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
121823 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
121824 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
121825 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
121826 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
121827 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
121828 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
121829 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
121830 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
121831 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
121832 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
121833 +xenfb_write_43412 xenfb_write 3 43412 NULL
121834 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
121835 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
121836 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
121837 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
121838 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
121839 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
121840 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
121841 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
121842 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
121843 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
121844 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
121845 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
121846 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
121847 +read_events_43534 read_events 3 43534 NULL
121848 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
121849 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
121850 +request_resource_43548 request_resource 0 43548 NULL
121851 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
121852 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
121853 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
121854 +proc_read_43614 proc_read 3 43614 NULL
121855 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
121856 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
121857 +random_write_43656 random_write 3 43656 NULL
121858 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
121859 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
121860 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
121861 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
121862 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
121863 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
121864 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
121865 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
121866 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
121867 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
121868 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
121869 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
121870 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
121871 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
121872 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
121873 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
121874 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
121875 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
121876 +read_flush_43851 read_flush 3 43851 NULL
121877 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
121878 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
121879 +SendString_43928 SendString 3 43928 NULL
121880 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
121881 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
121882 +nla_reserve_43984 nla_reserve 3 43984 NULL
121883 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
121884 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
121885 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
121886 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
121887 +emit_flags_44006 emit_flags 4-3 44006 NULL
121888 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
121889 +fru_strlen_44046 fru_strlen 0 44046 NULL
121890 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
121891 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
121892 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
121893 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
121894 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
121895 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
121896 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
121897 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
121898 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
121899 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
121900 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
121901 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
121902 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
121903 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
121904 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
121905 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
121906 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
121907 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
121908 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
121909 +device_create_file_44285 device_create_file 0 44285 NULL
121910 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
121911 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
121912 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
121913 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
121914 +rs_init_44327 rs_init 1 44327 NULL
121915 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
121916 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
121917 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
121918 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
121919 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
121920 +strlcpy_44400 strlcpy 3 44400 NULL
121921 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
121922 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
121923 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
121924 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
121925 +write_file_debug_44476 write_file_debug 3 44476 NULL
121926 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
121927 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
121928 +bio_advance_44496 bio_advance 2 44496 NULL
121929 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
121930 +ac_register_board_44504 ac_register_board 3 44504 NULL
121931 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
121932 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
121933 +spidev_write_44510 spidev_write 3 44510 NULL
121934 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
121935 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
121936 +comm_write_44537 comm_write 3 44537 NULL
121937 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
121938 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
121939 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
121940 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
121941 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
121942 +mpi_resize_44674 mpi_resize 2 44674 NULL
121943 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
121944 +ts_read_44687 ts_read 3 44687 NULL
121945 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
121946 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
121947 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
121948 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
121949 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
121950 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
121951 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
121952 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
121953 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
121954 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
121955 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
121956 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
121957 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
121958 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
121959 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
121960 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
121961 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
121962 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
121963 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
121964 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
121965 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
121966 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
121967 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
121968 +sisusb_write_44834 sisusb_write 3 44834 NULL
121969 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
121970 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
121971 +copydesc_user_44855 copydesc_user 3 44855 NULL
121972 +set_advertising_44870 set_advertising 4 44870 NULL
121973 +init_rs_44873 init_rs 1 44873 NULL
121974 +skb_availroom_44883 skb_availroom 0 44883 NULL
121975 +do_tty_write_44896 do_tty_write 5 44896 NULL
121976 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
121977 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
121978 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
121979 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
121980 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
121981 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
121982 +sel_write_user_45060 sel_write_user 3 45060 NULL
121983 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
121984 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
121985 +snd_card_new_45104 snd_card_new 5 45104 NULL
121986 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
121987 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
121988 +usbdev_read_45114 usbdev_read 3 45114 NULL
121989 +send_to_tty_45141 send_to_tty 3 45141 NULL
121990 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
121991 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
121992 +device_write_45156 device_write 3 45156 NULL nohasharray
121993 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
121994 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
121995 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
121996 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
121997 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
121998 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
121999 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122000 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122001 +event_enable_write_45238 event_enable_write 3 45238 NULL
122002 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122003 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122004 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122005 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122006 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122007 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122008 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122009 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122010 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122011 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122012 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122013 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122014 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122015 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122016 +__node_remap_45458 __node_remap 4 45458 NULL
122017 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122018 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122019 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122020 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122021 +copy_macs_45534 copy_macs 4 45534 NULL
122022 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122023 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122024 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122025 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122026 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122027 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122028 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122029 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122030 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122031 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122032 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122033 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122034 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122035 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122036 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122037 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122038 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122039 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122040 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122041 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122042 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122043 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122044 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122045 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122046 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122047 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122048 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122049 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122050 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122051 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122052 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122053 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122054 +isdn_write_45863 isdn_write 3 45863 NULL
122055 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122056 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122057 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122058 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122059 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122060 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122061 +alloc_mr_45935 alloc_mr 1 45935 NULL
122062 +copy_to_45969 copy_to 3 45969 NULL
122063 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122064 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122065 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122066 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122067 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122068 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122069 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122070 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122071 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122072 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122073 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122074 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122075 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122076 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122077 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122078 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122079 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122080 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122081 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122082 +fq_resize_46195 fq_resize 2 46195 NULL
122083 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122084 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122085 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122086 +dsp_write_46218 dsp_write 2 46218 NULL
122087 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122088 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122089 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122090 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122091 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122092 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122093 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122094 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122095 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122096 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122097 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122098 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122099 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122100 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122101 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122102 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122103 +filldir64_46469 filldir64 3 46469 NULL
122104 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122105 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122106 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122107 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122108 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122109 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
122110 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122111 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122112 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122113 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122114 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122115 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122116 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122117 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122118 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122119 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122120 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122121 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122122 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122123 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122124 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122125 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122126 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122127 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122128 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122129 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122130 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122131 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122132 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122133 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122134 +readreg_46845 readreg 0 46845 NULL
122135 +spi_async_46857 spi_async 0 46857 NULL
122136 +vsnprintf_46863 vsnprintf 0 46863 NULL
122137 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122138 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122139 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122140 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122141 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122142 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
122143 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122144 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122145 +fb_write_46924 fb_write 3 46924 NULL
122146 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122147 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122148 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122149 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122150 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122151 +strlcat_46985 strlcat 3 46985 NULL
122152 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122153 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122154 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122155 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122156 +fs_path_len_47060 fs_path_len 0 47060 NULL
122157 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122158 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122159 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122160 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122161 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122162 +mousedev_read_47123 mousedev_read 3 47123 NULL
122163 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122164 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122165 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122166 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122167 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122168 +options_write_47243 options_write 3 47243 NULL
122169 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122170 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122171 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122172 +vsnprintf_47291 vsnprintf 0 47291 NULL
122173 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122174 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122175 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
122176 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122177 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122178 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
122179 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122180 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122181 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122182 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122183 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122184 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122185 +nametbl_list_47391 nametbl_list 2 47391 NULL
122186 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122187 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122188 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122189 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122190 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122191 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122192 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122193 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122194 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122195 +newpart_47485 newpart 6-4 47485 NULL
122196 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122197 +core_sys_select_47494 core_sys_select 1 47494 NULL
122198 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122199 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122200 +unlink_simple_47506 unlink_simple 3 47506 NULL
122201 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122202 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122203 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122204 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122205 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122206 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122207 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122208 +read_ldt_47570 read_ldt 2 47570 NULL
122209 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122210 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122211 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122212 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122213 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122214 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122215 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122216 +get_size_47644 get_size 1-2 47644 NULL
122217 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122218 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122219 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122220 +save_microcode_47717 save_microcode 3 47717 NULL
122221 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122222 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122223 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122224 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122225 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122226 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122227 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122228 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122229 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122230 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122231 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122232 +lov_packmd_47810 lov_packmd 0 47810 NULL
122233 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122234 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
122235 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122236 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122237 +vhci_read_47878 vhci_read 3 47878 NULL
122238 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122239 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122240 +comedi_write_47926 comedi_write 3 47926 NULL
122241 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122242 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
122243 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122244 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122245 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122246 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122247 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122248 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122249 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122250 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122251 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122252 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122253 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122254 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122255 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122256 +disc_write_48070 disc_write 3 48070 NULL
122257 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122258 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122259 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122260 +load_firmware_48128 load_firmware 2 48128 NULL
122261 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122262 +set_discoverable_48141 set_discoverable 4 48141 NULL
122263 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122264 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122265 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122266 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122267 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122268 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122269 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122270 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122271 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122272 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122273 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122274 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122275 +read_file_recv_48232 read_file_recv 3 48232 NULL
122276 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122277 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122278 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122279 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122280 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122281 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122282 +trace_options_write_48275 trace_options_write 3 48275 NULL
122283 +send_set_info_48288 send_set_info 7 48288 NULL
122284 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122285 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122286 +hash_setkey_48310 hash_setkey 3 48310 NULL
122287 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122288 +skb_add_data_48363 skb_add_data 3 48363 NULL
122289 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122290 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122291 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122292 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122293 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122294 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122295 +print_filtered_48442 print_filtered 2-0 48442 NULL
122296 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122297 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122298 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122299 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122300 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122301 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122302 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122303 +send_control_msg_48498 send_control_msg 6 48498 NULL
122304 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122305 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122306 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122307 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122308 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122309 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122310 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122311 +llog_data_len_48607 llog_data_len 1 48607 NULL
122312 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122313 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122314 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122315 +mtd_read_48655 mtd_read 0 48655 NULL
122316 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122317 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122318 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122319 +altera_drscan_48698 altera_drscan 2 48698 NULL
122320 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122321 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122322 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122323 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122324 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122325 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122326 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122327 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122328 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122329 +azx_get_position_48841 azx_get_position 0 48841 NULL
122330 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122331 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122332 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122333 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122334 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122335 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122336 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122337 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122338 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122339 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122340 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122341 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122342 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122343 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122344 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122345 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122346 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122347 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122348 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122349 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122350 +transient_status_49027 transient_status 4 49027 NULL
122351 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122352 +scsi_register_49094 scsi_register 2 49094 NULL
122353 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122354 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122355 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122356 +pt_read_49136 pt_read 3 49136 NULL nohasharray
122357 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
122358 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122359 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122360 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122361 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122362 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122363 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122364 +print_queue_49191 print_queue 0-4 49191 NULL
122365 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122366 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122367 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122368 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122369 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122370 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122371 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122372 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122373 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122374 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122375 +uio_read_49300 uio_read 3 49300 NULL
122376 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122377 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122378 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122379 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122380 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122381 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122382 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122383 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122384 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122385 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122386 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122387 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122388 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122389 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122390 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122391 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122392 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122393 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122394 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122395 +smk_write_access_49561 smk_write_access 3 49561 NULL
122396 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122397 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122398 +readfifo_49583 readfifo 1 49583 NULL
122399 +tap_write_49595 tap_write 3 49595 NULL
122400 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122401 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122402 +heap_init_49617 heap_init 2 49617 NULL
122403 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122404 +port_fops_read_49626 port_fops_read 3 49626 NULL
122405 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122406 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122407 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122408 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122409 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122410 +write_pool_49718 write_pool 3 49718 NULL
122411 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122412 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122413 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122414 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122415 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122416 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122417 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122418 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122419 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122420 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122421 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122422 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122423 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122424 +add_uuid_49831 add_uuid 4 49831 NULL
122425 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122426 +twl4030_write_49846 twl4030_write 2 49846 NULL
122427 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122428 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122429 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122430 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122431 +osc_brw_49896 osc_brw 4 49896 NULL
122432 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122433 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122434 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122435 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122436 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122437 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122438 +isdn_read_50021 isdn_read 3 50021 NULL
122439 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122440 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
122441 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122442 +ioread8_50049 ioread8 0 50049 NULL
122443 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122444 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122445 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122446 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122447 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122448 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122449 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122450 +read_file_slot_50111 read_file_slot 3 50111 NULL
122451 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122452 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122453 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122454 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122455 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122456 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122457 +odev_update_50169 odev_update 2 50169 NULL
122458 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122459 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122460 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122461 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122462 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122463 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122464 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122465 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122466 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122467 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122468 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122469 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122470 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122471 +do_launder_page_50329 do_launder_page 0 50329 NULL
122472 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122473 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122474 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122475 +tpm_read_50344 tpm_read 3 50344 NULL
122476 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122477 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122478 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122479 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122480 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122481 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122482 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122483 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122484 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122485 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122486 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122487 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122488 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122489 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122490 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122491 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122492 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122493 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122494 +fat_readpages_50582 fat_readpages 4 50582 NULL
122495 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122496 +xillybus_write_50605 xillybus_write 3 50605 NULL
122497 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122498 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122499 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122500 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122501 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122502 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122503 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122504 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122505 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122506 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122507 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122508 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122509 +tpm_write_50798 tpm_write 3 50798 NULL
122510 +tun_do_read_50800 tun_do_read 4 50800 NULL
122511 +write_flush_50803 write_flush 3 50803 NULL
122512 +dvb_play_50814 dvb_play 3 50814 NULL
122513 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122514 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122515 +SetArea_50835 SetArea 4 50835 NULL
122516 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122517 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122518 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122519 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122520 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122521 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122522 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122523 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122524 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122525 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122526 +show_device_status_50947 show_device_status 0 50947 NULL
122527 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122528 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122529 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122530 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122531 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122532 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122533 +timeout_write_50991 timeout_write 3 50991 NULL
122534 +proc_write_51003 proc_write 3 51003 NULL
122535 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122536 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122537 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122538 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122539 +dump_midi_51040 dump_midi 3 51040 NULL
122540 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122541 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122542 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122543 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122544 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
122545 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122546 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
122547 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122548 +ti_recv_51110 ti_recv 3 51110 NULL
122549 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
122550 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
122551 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
122552 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
122553 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
122554 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
122555 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
122556 +drm_property_create_51239 drm_property_create 4 51239 NULL
122557 +st_read_51251 st_read 3 51251 NULL
122558 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
122559 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
122560 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
122561 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
122562 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
122563 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
122564 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
122565 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
122566 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
122567 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
122568 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
122569 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
122570 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
122571 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
122572 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
122573 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
122574 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
122575 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
122576 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
122577 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
122578 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
122579 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
122580 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
122581 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
122582 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
122583 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
122584 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
122585 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
122586 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
122587 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
122588 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
122589 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
122590 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
122591 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
122592 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
122593 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
122594 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
122595 +sel_write_access_51704 sel_write_access 3 51704 NULL
122596 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
122597 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
122598 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
122599 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
122600 +str_read_51731 str_read 4 51731 NULL
122601 +cm4040_read_51732 cm4040_read 3 51732 NULL
122602 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
122603 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
122604 +if_write_51756 if_write 3 51756 NULL
122605 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
122606 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
122607 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
122608 +ioread32_51847 ioread32 0 51847 NULL nohasharray
122609 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
122610 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
122611 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
122612 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
122613 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
122614 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
122615 +user_read_51881 user_read 3 51881 NULL
122616 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
122617 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
122618 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
122619 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
122620 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
122621 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
122622 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
122623 +get_clock_info_51952 get_clock_info 4 51952 NULL
122624 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
122625 +get_zone_51981 get_zone 0-1 51981 NULL
122626 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
122627 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
122628 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
122629 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
122630 +rdmalt_52022 rdmalt 0 52022 NULL
122631 +override_release_52032 override_release 2 52032 NULL
122632 +end_port_52042 end_port 0 52042 NULL
122633 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
122634 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
122635 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
122636 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
122637 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
122638 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
122639 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
122640 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
122641 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
122642 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
122643 +retry_count_read_52129 retry_count_read 3 52129 NULL
122644 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
122645 +sub_alloc_52140 sub_alloc 0 52140 NULL
122646 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
122647 +htable_size_52148 htable_size 0-1 52148 NULL
122648 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
122649 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
122650 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
122651 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
122652 +print_prefix_52176 print_prefix 0 52176 NULL
122653 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
122654 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
122655 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
122656 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
122657 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
122658 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
122659 +shrink_slab_52261 shrink_slab 2 52261 NULL
122660 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
122661 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
122662 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
122663 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
122664 +read_file_reset_52310 read_file_reset 3 52310 NULL
122665 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
122666 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
122667 +hwflags_read_52318 hwflags_read 3 52318 NULL
122668 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
122669 +hur_len_52339 hur_len 0 52339 NULL
122670 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
122671 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
122672 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
122673 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
122674 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
122675 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
122676 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
122677 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
122678 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
122679 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
122680 +delay_status_52431 delay_status 5 52431 NULL
122681 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
122682 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
122683 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
122684 +bt_alloc_52457 bt_alloc 2 52457 NULL
122685 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
122686 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
122687 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
122688 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
122689 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
122690 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
122691 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
122692 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
122693 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
122694 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
122695 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
122696 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
122697 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
122698 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
122699 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
122700 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
122701 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
122702 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
122703 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
122704 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
122705 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
122706 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
122707 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
122708 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
122709 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
122710 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
122711 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
122712 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
122713 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
122714 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
122715 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
122716 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
122717 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
122718 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
122719 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
122720 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
122721 +twlreg_write_52880 twlreg_write 3 52880 NULL
122722 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
122723 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
122724 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
122725 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
122726 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
122727 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
122728 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
122729 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
122730 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
122731 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
122732 +num_node_state_52989 num_node_state 0 52989 NULL
122733 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
122734 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
122735 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
122736 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
122737 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
122738 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
122739 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
122740 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
122741 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
122742 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
122743 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
122744 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
122745 +verity_status_53120 verity_status 5 53120 NULL
122746 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
122747 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
122748 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
122749 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
122750 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
122751 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
122752 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
122753 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
122754 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
122755 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
122756 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
122757 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
122758 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
122759 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
122760 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
122761 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
122762 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
122763 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
122764 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
122765 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
122766 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
122767 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
122768 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
122769 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
122770 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
122771 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
122772 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
122773 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
122774 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
122775 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
122776 +check_acl_53512 check_acl 0 53512 NULL nohasharray
122777 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
122778 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
122779 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
122780 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
122781 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
122782 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
122783 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
122784 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
122785 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
122786 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
122787 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
122788 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
122789 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
122790 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
122791 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
122792 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
122793 +wdm_write_53735 wdm_write 3 53735 NULL
122794 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
122795 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
122796 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
122797 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
122798 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
122799 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
122800 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
122801 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
122802 +setup_data_read_53822 setup_data_read 3 53822 NULL
122803 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
122804 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
122805 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
122806 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
122807 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
122808 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
122809 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
122810 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
122811 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
122812 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
122813 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
122814 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
122815 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
122816 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
122817 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
122818 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
122819 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
122820 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
122821 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
122822 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
122823 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
122824 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
122825 +strn_len_54122 strn_len 0 54122 NULL
122826 +isku_receive_54130 isku_receive 4 54130 NULL
122827 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
122828 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
122829 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
122830 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
122831 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
122832 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
122833 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
122834 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
122835 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
122836 +reada_add_block_54247 reada_add_block 2 54247 NULL
122837 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
122838 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
122839 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
122840 +audio_write_54261 audio_write 4 54261 NULL nohasharray
122841 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
122842 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
122843 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
122844 +sizeof_long_54276 sizeof_long 0 54276 NULL
122845 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
122846 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
122847 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
122848 +sprintf_54306 sprintf 0 54306 NULL
122849 +path_setxattr_54308 path_setxattr 4 54308 NULL
122850 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
122851 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
122852 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
122853 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
122854 +readlink_copy_54366 readlink_copy 2 54366 NULL
122855 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
122856 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
122857 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
122858 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
122859 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
122860 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
122861 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
122862 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
122863 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
122864 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
122865 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
122866 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
122867 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
122868 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
122869 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
122870 +viacam_read_54526 viacam_read 3 54526 NULL
122871 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
122872 +setsockopt_54539 setsockopt 5 54539 NULL
122873 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
122874 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
122875 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
122876 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
122877 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
122878 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
122879 +port_fops_write_54627 port_fops_write 3 54627 NULL
122880 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
122881 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
122882 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
122883 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
122884 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
122885 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
122886 +bus_add_device_54665 bus_add_device 0 54665 NULL
122887 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
122888 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
122889 +evm_read_key_54674 evm_read_key 3 54674 NULL
122890 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
122891 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
122892 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
122893 +kzalloc_54740 kzalloc 1 54740 NULL
122894 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
122895 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
122896 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
122897 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
122898 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
122899 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
122900 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
122901 +nfsd_write_54809 nfsd_write 6 54809 NULL
122902 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
122903 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
122904 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
122905 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
122906 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
122907 +write_rio_54837 write_rio 3 54837 NULL
122908 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
122909 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
122910 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
122911 +printer_read_54851 printer_read 3 54851 NULL
122912 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
122913 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
122914 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
122915 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
122916 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
122917 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
122918 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
122919 +add_port_54941 add_port 2 54941 NULL
122920 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
122921 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
122922 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
122923 +c4_add_card_54968 c4_add_card 3 54968 NULL
122924 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
122925 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
122926 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
122927 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
122928 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
122929 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
122930 +read_dma_55086 read_dma 3 55086 NULL
122931 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
122932 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
122933 +filldir_55137 filldir 3 55137 NULL
122934 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
122935 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
122936 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
122937 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
122938 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
122939 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
122940 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
122941 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
122942 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
122943 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
122944 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
122945 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
122946 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
122947 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
122948 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
122949 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
122950 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
122951 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
122952 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
122953 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
122954 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
122955 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
122956 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
122957 +vme_user_read_55338 vme_user_read 3 55338 NULL
122958 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
122959 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
122960 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
122961 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
122962 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
122963 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
122964 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
122965 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
122966 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
122967 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
122968 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
122969 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
122970 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
122971 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
122972 +ea_get_55522 ea_get 3-0 55522 NULL
122973 +buffer_size_55534 buffer_size 0 55534 NULL
122974 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
122975 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
122976 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
122977 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
122978 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
122979 +add_partition_55588 add_partition 2 55588 NULL
122980 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
122981 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
122982 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
122983 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
122984 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
122985 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
122986 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
122987 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
122988 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
122989 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
122990 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
122991 +get_info_55681 get_info 3 55681 NULL
122992 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
122993 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
122994 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
122995 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
122996 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
122997 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
122998 +set_local_name_55757 set_local_name 4 55757 NULL
122999 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123000 +strlen_55778 strlen 0 55778 NULL
123001 +set_spte_55783 set_spte 4-5 55783 NULL
123002 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123003 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123004 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123005 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123006 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123007 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123008 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123009 +hsc_write_55875 hsc_write 3 55875 NULL
123010 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123011 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123012 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123013 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123014 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123015 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123016 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123017 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123018 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123019 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123020 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123021 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123022 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123023 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123024 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123025 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123026 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123027 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123028 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123029 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123030 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123031 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123032 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123033 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123034 +fd_copyin_56247 fd_copyin 3 56247 NULL
123035 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123036 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123037 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123038 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123039 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123040 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123041 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123042 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123043 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123044 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123045 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123046 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123047 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123048 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123049 +dev_read_56369 dev_read 3 56369 NULL
123050 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123051 +lnet_ping_56378 lnet_ping 4 56378 NULL
123052 +write_gssp_56404 write_gssp 3 56404 NULL
123053 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123054 +store_msg_56417 store_msg 3 56417 NULL
123055 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123056 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
123057 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
123058 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123059 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123060 +fl_create_56435 fl_create 5 56435 NULL
123061 +gnttab_map_56439 gnttab_map 2 56439 NULL
123062 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123063 +set_connectable_56458 set_connectable 4 56458 NULL
123064 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123065 +putused_user_56467 putused_user 3 56467 NULL
123066 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123067 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123068 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123069 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123070 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123071 +init_map_ip_56508 init_map_ip 5 56508 NULL
123072 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123073 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123074 +ip_options_get_56538 ip_options_get 4 56538 NULL
123075 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123076 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123077 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123078 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123079 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123080 +event_filter_write_56609 event_filter_write 3 56609 NULL
123081 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123082 +gather_array_56641 gather_array 3 56641 NULL
123083 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123084 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123085 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123086 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123087 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123088 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123089 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123090 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123091 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123092 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123093 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123094 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123095 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123096 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123097 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123098 +do_syslog_56807 do_syslog 3 56807 NULL
123099 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123100 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123101 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123102 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123103 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123104 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123105 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123106 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123107 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123108 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123109 +strcspn_56913 strcspn 0 56913 NULL
123110 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123111 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123112 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123113 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123114 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123115 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123116 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123117 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123118 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123119 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123120 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123121 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123122 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123123 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123124 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123125 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123126 +altera_get_note_57099 altera_get_note 6 57099 NULL
123127 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123128 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123129 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123130 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123131 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123132 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123133 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123134 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123135 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123136 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123137 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123138 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123139 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123140 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123141 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123142 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123143 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123144 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123145 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123146 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123147 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123148 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123149 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123150 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123151 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123152 +write_file_regval_57313 write_file_regval 3 57313 NULL
123153 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123154 +usblp_read_57342 usblp_read 3 57342 NULL
123155 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123156 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123157 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123158 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123159 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123160 +read_file_blob_57406 read_file_blob 3 57406 NULL
123161 +enclosure_register_57412 enclosure_register 3 57412 NULL
123162 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
123163 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123164 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123165 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123166 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123167 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123168 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123169 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123170 +skb_headlen_57501 skb_headlen 0 57501 NULL
123171 +copy_in_user_57502 copy_in_user 3 57502 NULL
123172 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123173 +init_tag_map_57515 init_tag_map 3 57515 NULL
123174 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123175 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123176 +cmm_read_57520 cmm_read 3 57520 NULL
123177 +inode_permission_57531 inode_permission 0 57531 NULL
123178 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123179 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123180 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123181 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123182 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123183 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123184 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123185 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123186 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123187 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
123188 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123189 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123190 +mem_read_57631 mem_read 3 57631 NULL
123191 +r3964_write_57662 r3964_write 4 57662 NULL
123192 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123193 +__lgwrite_57669 __lgwrite 4 57669 NULL
123194 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123195 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123196 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123197 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123198 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123199 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123200 +ld2_57794 ld2 0 57794 NULL
123201 +ivtv_read_57796 ivtv_read 3 57796 NULL
123202 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123203 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123204 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123205 +flash_read_57843 flash_read 3 57843 NULL
123206 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123207 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123208 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123209 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123210 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123211 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123212 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123213 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123214 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123215 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123216 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123217 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123218 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123219 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123220 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123221 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123222 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123223 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123224 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123225 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123226 +mce_async_out_58056 mce_async_out 3 58056 NULL
123227 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123228 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123229 +cm4040_write_58079 cm4040_write 3 58079 NULL
123230 +savemem_58129 savemem 3 58129 NULL
123231 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123232 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123233 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123234 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123235 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123236 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123237 +read_file_debug_58256 read_file_debug 3 58256 NULL
123238 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123239 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123240 +profile_load_58267 profile_load 3 58267 NULL
123241 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123242 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123243 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123244 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123245 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123246 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123247 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123248 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123249 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123250 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123251 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123252 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123253 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123254 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123255 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123256 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123257 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123258 +capabilities_read_58457 capabilities_read 3 58457 NULL
123259 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123260 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123261 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123262 +nv_rd08_58472 nv_rd08 0 58472 NULL
123263 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123264 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123265 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
123266 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123267 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123268 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123269 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123270 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123271 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123272 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123273 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123274 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123275 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123276 +xip_file_read_58592 xip_file_read 3 58592 NULL
123277 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123278 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123279 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123280 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123281 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123282 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123283 +find_zero_58685 find_zero 0-1 58685 NULL
123284 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123285 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123286 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123287 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123288 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123289 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123290 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123291 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123292 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123293 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123294 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123295 +ep_read_58813 ep_read 3 58813 NULL
123296 +command_write_58841 command_write 3 58841 NULL
123297 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123298 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123299 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123300 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123301 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123302 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123303 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123304 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123305 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123306 +init_list_set_59005 init_list_set 3 59005 NULL
123307 +ep_write_59008 ep_write 3 59008 NULL
123308 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123309 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123310 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123311 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123312 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123313 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123314 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123315 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123316 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123317 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123318 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123319 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123320 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123321 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123322 +ksize_59176 ksize 0 59176 NULL
123323 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123324 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123325 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123326 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123327 +dt3155_read_59226 dt3155_read 3 59226 NULL
123328 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123329 +nla_len_59258 nla_len 0 59258 NULL
123330 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123331 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123332 +fd_copyout_59323 fd_copyout 3 59323 NULL
123333 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123334 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123335 +__map_request_59350 __map_request 0 59350 NULL
123336 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123337 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123338 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123339 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123340 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123341 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123342 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123343 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123344 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123345 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123346 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123347 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123348 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123349 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123350 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
123351 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123352 +tunables_write_59563 tunables_write 3 59563 NULL
123353 +bio_split_59564 bio_split 2 59564 NULL
123354 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123355 +write_pbl_59583 write_pbl 4 59583 NULL
123356 +memdup_user_59590 memdup_user 2 59590 NULL
123357 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123358 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123359 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123360 +mtrr_write_59622 mtrr_write 3 59622 NULL
123361 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123362 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123363 +hidraw_read_59650 hidraw_read 3 59650 NULL
123364 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123365 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123366 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123367 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123368 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123369 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123370 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123371 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123372 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123373 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123374 +strnlen_59746 strnlen 0 59746 NULL
123375 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123376 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123377 +venus_remove_59781 venus_remove 4 59781 NULL
123378 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123379 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123380 +ipw_write_59807 ipw_write 3 59807 NULL
123381 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123382 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123383 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123384 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123385 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123386 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123387 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123388 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123389 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123390 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123391 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123392 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123393 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123394 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123395 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123396 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123397 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123398 +copy_items_60009 copy_items 7 60009 NULL
123399 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123400 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123401 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123402 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123403 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123404 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123405 +vcs_size_60050 vcs_size 0 60050 NULL
123406 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123407 +compat_writev_60063 compat_writev 3 60063 NULL
123408 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123409 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123410 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123411 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123412 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123413 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123414 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123415 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
123416 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123417 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123418 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123419 +init_state_60165 init_state 2 60165 NULL
123420 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123421 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123422 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123423 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
123424 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
123425 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123426 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123427 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123428 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123429 +printer_write_60276 printer_write 3 60276 NULL
123430 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123431 +getDataLength_60301 getDataLength 0 60301 NULL
123432 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123433 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123434 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123435 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123436 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123437 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123438 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123439 +driver_names_read_60399 driver_names_read 3 60399 NULL
123440 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123441 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123442 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123443 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123444 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123445 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123446 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123447 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123448 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123449 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123450 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123451 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123452 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123453 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123454 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123455 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123456 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123457 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123458 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123459 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123460 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123461 +raid_status_60755 raid_status 5 60755 NULL
123462 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123463 +opticon_write_60775 opticon_write 4 60775 NULL
123464 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123465 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123466 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123467 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123468 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123469 +generic_writepages_60871 generic_writepages 0 60871 NULL
123470 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123471 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123472 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123473 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123474 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123475 +pti_char_write_60960 pti_char_write 3 60960 NULL
123476 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123477 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123478 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123479 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123480 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123481 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123482 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123483 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
123484 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123485 +symtab_init_61050 symtab_init 2 61050 NULL
123486 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123487 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123488 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123489 +get_derived_key_61100 get_derived_key 4 61100 NULL
123490 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123491 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123492 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123493 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123494 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123495 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123496 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123497 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123498 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123499 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123500 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123501 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123502 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123503 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
123504 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123505 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123506 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123507 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123508 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123509 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123510 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123511 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123512 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123513 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123514 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123515 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123516 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123517 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123518 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
123519 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123520 +system_enable_write_61396 system_enable_write 3 61396 NULL
123521 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
123522 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123523 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123524 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123525 +erst_errno_61526 erst_errno 0 61526 NULL
123526 +proc_write_device_61541 proc_write_device 3 61541 NULL
123527 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123528 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123529 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123530 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123531 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123532 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123533 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123534 +seq_open_private_61589 seq_open_private 3 61589 NULL
123535 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123536 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123537 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123538 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123539 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123540 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123541 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123542 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123543 +resize_stripes_61650 resize_stripes 2 61650 NULL
123544 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123545 +insert_one_name_61668 insert_one_name 7 61668 NULL
123546 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123547 +lock_loop_61681 lock_loop 1 61681 NULL
123548 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
123549 +filter_read_61692 filter_read 3 61692 NULL
123550 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
123551 +iov_length_61716 iov_length 0 61716 NULL
123552 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123553 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123554 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123555 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123556 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123557 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123558 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123559 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123560 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123561 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
123562 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123563 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123564 +get_fw_name_61874 get_fw_name 3 61874 NULL
123565 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123566 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123567 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123568 +kernfs_name_61910 kernfs_name 3 61910 NULL
123569 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
123570 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
123571 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
123572 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
123573 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
123574 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
123575 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
123576 +fix_read_error_61965 fix_read_error 4 61965 NULL
123577 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
123578 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
123579 +cow_file_range_61979 cow_file_range 3 61979 NULL
123580 +dequeue_event_62000 dequeue_event 3 62000 NULL
123581 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
123582 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
123583 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
123584 +SYSC_select_62024 SYSC_select 1 62024 NULL
123585 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
123586 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
123587 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
123588 +do_pselect_62061 do_pselect 1 62061 NULL
123589 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
123590 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
123591 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
123592 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
123593 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
123594 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
123595 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
123596 +ql_status_62135 ql_status 5 62135 NULL nohasharray
123597 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
123598 +video_usercopy_62151 video_usercopy 2 62151 NULL
123599 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
123600 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
123601 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
123602 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
123603 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
123604 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
123605 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
123606 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
123607 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
123608 +get_random_int_62279 get_random_int 0 62279 NULL
123609 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
123610 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
123611 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
123612 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
123613 +subseq_list_62332 subseq_list 3-0 62332 NULL
123614 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
123615 +flash_write_62354 flash_write 3 62354 NULL
123616 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
123617 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
123618 +altera_irscan_62396 altera_irscan 2 62396 NULL
123619 +set_ssp_62411 set_ssp 4 62411 NULL
123620 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
123621 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
123622 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
123623 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
123624 +debugfs_read_62535 debugfs_read 3 62535 NULL
123625 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
123626 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
123627 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
123628 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
123629 +get_subdir_62581 get_subdir 3 62581 NULL
123630 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
123631 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
123632 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
123633 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
123634 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
123635 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
123636 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
123637 +rdm_62719 rdm 0 62719 NULL
123638 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
123639 +key_replays_read_62746 key_replays_read 3 62746 NULL
123640 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
123641 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
123642 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
123643 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
123644 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
123645 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
123646 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
123647 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
123648 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
123649 +__add_action_62798 __add_action 4 62798 NULL
123650 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
123651 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
123652 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
123653 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
123654 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
123655 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
123656 +aoechr_write_62883 aoechr_write 3 62883 NULL
123657 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
123658 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
123659 +getdqbuf_62908 getdqbuf 1 62908 NULL
123660 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
123661 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
123662 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
123663 +hwdep_read_62992 hwdep_read 3 62992 NULL
123664 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
123665 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
123666 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
123667 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
123668 +unlink1_63059 unlink1 3 63059 NULL
123669 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
123670 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
123671 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
123672 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
123673 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
123674 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
123675 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
123676 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
123677 +vme_master_read_63221 vme_master_read 0 63221 NULL
123678 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
123679 +ptp_read_63251 ptp_read 4 63251 NULL
123680 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
123681 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
123682 +raid5_resize_63306 raid5_resize 2 63306 NULL
123683 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
123684 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
123685 +proc_info_read_63344 proc_info_read 3 63344 NULL
123686 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
123687 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
123688 +idmouse_read_63374 idmouse_read 3 63374 NULL
123689 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
123690 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
123691 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
123692 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
123693 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
123694 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
123695 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
123696 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
123697 +read_kcore_63488 read_kcore 3 63488 NULL
123698 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
123699 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
123700 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
123701 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
123702 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
123703 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
123704 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
123705 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
123706 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
123707 +write_debug_level_63613 write_debug_level 3 63613 NULL
123708 +__spi_validate_63618 __spi_validate 0 63618 NULL
123709 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
123710 +hid_report_len_63637 hid_report_len 0 63637 NULL
123711 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
123712 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
123713 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
123714 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
123715 +vbi_read_63673 vbi_read 3 63673 NULL
123716 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
123717 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
123718 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
123719 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
123720 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
123721 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
123722 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
123723 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
123724 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
123725 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
123726 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
123727 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
123728 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
123729 +sel_write_load_63830 sel_write_load 3 63830 NULL
123730 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
123731 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
123732 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
123733 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
123734 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
123735 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
123736 +__team_options_register_63941 __team_options_register 3 63941 NULL
123737 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
123738 +set_bredr_63975 set_bredr 4 63975 NULL
123739 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
123740 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
123741 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
123742 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
123743 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
123744 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
123745 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
123746 +__sock_create_64069 __sock_create 0 64069 NULL
123747 +get_u8_64076 get_u8 0 64076 NULL
123748 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
123749 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
123750 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
123751 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
123752 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
123753 +to_bytes_64103 to_bytes 0-1 64103 NULL
123754 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
123755 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
123756 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
123757 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
123758 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
123759 +init_bch_64130 init_bch 1-2 64130 NULL
123760 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
123761 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
123762 +number_of_tds_64156 number_of_tds 0 64156 NULL
123763 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
123764 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
123765 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
123766 +read_pulse_64227 read_pulse 0-3 64227 NULL
123767 +ea_len_64229 ea_len 0 64229 NULL
123768 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
123769 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
123770 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
123771 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
123772 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
123773 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
123774 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
123775 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
123776 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
123777 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
123778 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
123779 +ts_write_64336 ts_write 3 64336 NULL
123780 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
123781 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
123782 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
123783 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
123784 +reg_create_64372 reg_create 5 64372 NULL nohasharray
123785 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
123786 +ilo_write_64378 ilo_write 3 64378 NULL
123787 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
123788 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
123789 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
123790 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
123791 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
123792 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
123793 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
123794 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
123795 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
123796 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
123797 +single_open_size_64483 single_open_size 4 64483 NULL
123798 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
123799 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
123800 +remove_uuid_64505 remove_uuid 4 64505 NULL
123801 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
123802 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
123803 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
123804 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
123805 +SyS_bind_64544 SyS_bind 3 64544 NULL
123806 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
123807 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
123808 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
123809 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
123810 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
123811 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
123812 +do_erase_64574 do_erase 4 64574 NULL
123813 +fanotify_write_64623 fanotify_write 3 64623 NULL
123814 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
123815 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
123816 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
123817 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
123818 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
123819 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
123820 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
123821 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
123822 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
123823 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
123824 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
123825 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
123826 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
123827 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
123828 +hwdep_write_64776 hwdep_write 3 64776 NULL
123829 +message_for_md_64777 message_for_md 5 64777 NULL
123830 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
123831 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
123832 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
123833 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
123834 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
123835 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
123836 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
123837 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
123838 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
123839 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
123840 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
123841 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
123842 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
123843 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
123844 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
123845 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
123846 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
123847 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
123848 +insert_dent_65034 insert_dent 7 65034 NULL
123849 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
123850 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
123851 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
123852 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
123853 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
123854 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
123855 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
123856 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
123857 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
123858 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
123859 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
123860 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
123861 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
123862 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
123863 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
123864 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
123865 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
123866 +get_var_len_65304 get_var_len 0 65304 NULL
123867 +unpack_array_65318 unpack_array 0 65318 NULL
123868 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
123869 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
123870 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
123871 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
123872 +SyS_writev_65372 SyS_writev 3 65372 NULL
123873 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
123874 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
123875 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
123876 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
123877 +device_add_groups_65423 device_add_groups 0 65423 NULL
123878 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
123879 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
123880 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
123881 +clear_user_65470 clear_user 2 65470 NULL
123882 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
123883 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
123884 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
123885 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
123886 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123887 new file mode 100644
123888 index 0000000..560cd7b
123889 --- /dev/null
123890 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123891 @@ -0,0 +1,92 @@
123892 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
123893 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
123894 +mappedread_2627 mappedread 2 2627 NULL
123895 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
123896 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
123897 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
123898 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
123899 +dmu_write_6048 dmu_write 4-3 6048 NULL
123900 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
123901 +update_pages_6225 update_pages 2-3 6225 NULL
123902 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
123903 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
123904 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
123905 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
123906 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
123907 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
123908 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
123909 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
123910 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
123911 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
123912 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
123913 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
123914 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
123915 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
123916 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
123917 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
123918 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
123919 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
123920 +uiocopy_18680 uiocopy 2 18680 NULL
123921 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
123922 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
123923 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
123924 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
123925 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
123926 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
123927 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
123928 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
123929 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
123930 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
123931 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
123932 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
123933 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
123934 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
123935 +splat_write_30943 splat_write 3 30943 NULL
123936 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
123937 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
123938 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
123939 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
123940 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
123941 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
123942 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
123943 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
123944 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
123945 +copyinstr_36980 copyinstr 3 36980 NULL
123946 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
123947 +splat_read_38116 splat_read 3 38116 NULL
123948 +sa_setup_38756 sa_setup 4 38756 NULL
123949 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
123950 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
123951 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
123952 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
123953 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
123954 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
123955 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
123956 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
123957 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
123958 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
123959 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
123960 +kcopy_write_43683 kcopy_write 3 43683 NULL
123961 +uiomove_44355 uiomove 2 44355 NULL
123962 +dmu_read_44418 dmu_read 4-3 44418 NULL
123963 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
123964 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
123965 +copyin_45945 copyin 3 45945 NULL
123966 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
123967 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
123968 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
123969 +spa_history_write_49650 spa_history_write 3 49650 NULL
123970 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
123971 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
123972 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
123973 +copyout_51409 copyout 3 51409 NULL
123974 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
123975 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
123976 +get_nvlist_56685 get_nvlist 2 56685 NULL
123977 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
123978 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
123979 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
123980 +zpios_write_61823 zpios_write 3 61823 NULL
123981 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
123982 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
123983 +zpios_read_64734 zpios_read 3 64734 NULL
123984 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123985 new file mode 100644
123986 index 0000000..95f7abd
123987 --- /dev/null
123988 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123989 @@ -0,0 +1,259 @@
123990 +/*
123991 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123992 + * Licensed under the GPL v2, or (at your option) v3
123993 + *
123994 + * Homepage:
123995 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123996 + *
123997 + * Documentation:
123998 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123999 + *
124000 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124001 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124002 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124003 + *
124004 + * Usage:
124005 + * $ make
124006 + * $ make run
124007 + */
124008 +
124009 +#include "gcc-common.h"
124010 +#include "size_overflow.h"
124011 +
124012 +int plugin_is_GPL_compatible;
124013 +
124014 +tree report_size_overflow_decl;
124015 +
124016 +tree size_overflow_type_HI;
124017 +tree size_overflow_type_SI;
124018 +tree size_overflow_type_DI;
124019 +tree size_overflow_type_TI;
124020 +
124021 +static struct plugin_info size_overflow_plugin_info = {
124022 + .version = "20140725",
124023 + .help = "no-size-overflow\tturn off size overflow checking\n",
124024 +};
124025 +
124026 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124027 +{
124028 + unsigned int arg_count;
124029 + enum tree_code code = TREE_CODE(*node);
124030 +
124031 + switch (code) {
124032 + case FUNCTION_DECL:
124033 + arg_count = type_num_arguments(TREE_TYPE(*node));
124034 + break;
124035 + case FUNCTION_TYPE:
124036 + case METHOD_TYPE:
124037 + arg_count = type_num_arguments(*node);
124038 + break;
124039 + default:
124040 + *no_add_attrs = true;
124041 + error("%s: %qE attribute only applies to functions", __func__, name);
124042 + return NULL_TREE;
124043 + }
124044 +
124045 + for (; args; args = TREE_CHAIN(args)) {
124046 + tree position = TREE_VALUE(args);
124047 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124048 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124049 + *no_add_attrs = true;
124050 + }
124051 + }
124052 + return NULL_TREE;
124053 +}
124054 +
124055 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124056 +{
124057 + unsigned int arg_count;
124058 + enum tree_code code = TREE_CODE(*node);
124059 +
124060 + switch (code) {
124061 + case FUNCTION_DECL:
124062 + arg_count = type_num_arguments(TREE_TYPE(*node));
124063 + break;
124064 + case FUNCTION_TYPE:
124065 + case METHOD_TYPE:
124066 + arg_count = type_num_arguments(*node);
124067 + break;
124068 + case FIELD_DECL:
124069 + return NULL_TREE;
124070 + default:
124071 + *no_add_attrs = true;
124072 + error("%qE attribute only applies to functions", name);
124073 + return NULL_TREE;
124074 + }
124075 +
124076 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124077 + return NULL_TREE;
124078 +
124079 + for (; args; args = TREE_CHAIN(args)) {
124080 + tree position = TREE_VALUE(args);
124081 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124082 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124083 + *no_add_attrs = true;
124084 + }
124085 + }
124086 + return NULL_TREE;
124087 +}
124088 +
124089 +static struct attribute_spec size_overflow_attr = {
124090 + .name = "size_overflow",
124091 + .min_length = 1,
124092 + .max_length = -1,
124093 + .decl_required = true,
124094 + .type_required = false,
124095 + .function_type_required = false,
124096 + .handler = handle_size_overflow_attribute,
124097 +#if BUILDING_GCC_VERSION >= 4007
124098 + .affects_type_identity = false
124099 +#endif
124100 +};
124101 +
124102 +static struct attribute_spec intentional_overflow_attr = {
124103 + .name = "intentional_overflow",
124104 + .min_length = 1,
124105 + .max_length = -1,
124106 + .decl_required = true,
124107 + .type_required = false,
124108 + .function_type_required = false,
124109 + .handler = handle_intentional_overflow_attribute,
124110 +#if BUILDING_GCC_VERSION >= 4007
124111 + .affects_type_identity = false
124112 +#endif
124113 +};
124114 +
124115 +static void register_attributes(void __unused *event_data, void __unused *data)
124116 +{
124117 + register_attribute(&size_overflow_attr);
124118 + register_attribute(&intentional_overflow_attr);
124119 +}
124120 +
124121 +static tree create_typedef(tree type, const char* ident)
124122 +{
124123 + tree new_type, decl;
124124 +
124125 + new_type = build_variant_type_copy(type);
124126 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124127 + DECL_ORIGINAL_TYPE(decl) = type;
124128 + TYPE_NAME(new_type) = decl;
124129 + return new_type;
124130 +}
124131 +
124132 +// Create the noreturn report_size_overflow() function decl.
124133 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124134 +{
124135 + tree const_char_ptr_type_node;
124136 + tree fntype;
124137 +
124138 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124139 +
124140 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124141 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124142 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124143 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124144 +
124145 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124146 + fntype = build_function_type_list(void_type_node,
124147 + const_char_ptr_type_node,
124148 + unsigned_type_node,
124149 + const_char_ptr_type_node,
124150 + const_char_ptr_type_node,
124151 + NULL_TREE);
124152 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124153 +
124154 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124155 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124156 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124157 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124158 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124159 +}
124160 +
124161 +
124162 +extern struct gimple_opt_pass pass_dce;
124163 +
124164 +static struct opt_pass *make_dce_pass(void)
124165 +{
124166 +#if BUILDING_GCC_VERSION >= 4009
124167 + return make_pass_dce(g);
124168 +#else
124169 + return &pass_dce.pass;
124170 +#endif
124171 +}
124172 +
124173 +
124174 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124175 +{
124176 + int i;
124177 + const char * const plugin_name = plugin_info->base_name;
124178 + const int argc = plugin_info->argc;
124179 + const struct plugin_argument * const argv = plugin_info->argv;
124180 + bool enable = true;
124181 + struct register_pass_info insert_size_overflow_asm_pass_info;
124182 + struct register_pass_info __unused dump_before_pass_info;
124183 + struct register_pass_info __unused dump_after_pass_info;
124184 + struct register_pass_info insert_size_overflow_check_info;
124185 + struct register_pass_info dce_pass_info;
124186 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124187 + {
124188 + .base = &report_size_overflow_decl,
124189 + .nelt = 1,
124190 + .stride = sizeof(report_size_overflow_decl),
124191 + .cb = &gt_ggc_mx_tree_node,
124192 + .pchw = &gt_pch_nx_tree_node
124193 + },
124194 + LAST_GGC_ROOT_TAB
124195 + };
124196 +
124197 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124198 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124199 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124200 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124201 +
124202 + dump_before_pass_info.pass = make_dump_pass();
124203 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124204 + dump_before_pass_info.ref_pass_instance_number = 1;
124205 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124206 +
124207 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124208 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124209 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124210 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124211 +
124212 + dump_after_pass_info.pass = make_dump_pass();
124213 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124214 + dump_after_pass_info.ref_pass_instance_number = 1;
124215 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124216 +
124217 + dce_pass_info.pass = make_dce_pass();
124218 + dce_pass_info.reference_pass_name = "vrp";
124219 + dce_pass_info.ref_pass_instance_number = 1;
124220 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124221 +
124222 + if (!plugin_default_version_check(version, &gcc_version)) {
124223 + error(G_("incompatible gcc/plugin versions"));
124224 + return 1;
124225 + }
124226 +
124227 + for (i = 0; i < argc; ++i) {
124228 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124229 + enable = false;
124230 + continue;
124231 + }
124232 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124233 + }
124234 +
124235 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124236 + if (enable) {
124237 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124238 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124239 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124240 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124241 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124242 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124243 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124244 + }
124245 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124246 +
124247 + return 0;
124248 +}
124249 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124250 new file mode 100644
124251 index 0000000..0888f6c
124252 --- /dev/null
124253 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124254 @@ -0,0 +1,364 @@
124255 +/*
124256 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124257 + * Licensed under the GPL v2, or (at your option) v3
124258 + *
124259 + * Homepage:
124260 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124261 + *
124262 + * Documentation:
124263 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124264 + *
124265 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124266 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124267 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124268 + *
124269 + * Usage:
124270 + * $ make
124271 + * $ make run
124272 + */
124273 +
124274 +#include "gcc-common.h"
124275 +#include "size_overflow.h"
124276 +
124277 +#include "size_overflow_hash.h"
124278 +#include "size_overflow_hash_aux.h"
124279 +
124280 +#define CODES_LIMIT 32
124281 +
124282 +static unsigned char get_tree_code(const_tree type)
124283 +{
124284 + switch (TREE_CODE(type)) {
124285 + case ARRAY_TYPE:
124286 + return 0;
124287 + case BOOLEAN_TYPE:
124288 + return 1;
124289 + case ENUMERAL_TYPE:
124290 + return 2;
124291 + case FUNCTION_TYPE:
124292 + return 3;
124293 + case INTEGER_TYPE:
124294 + return 4;
124295 + case POINTER_TYPE:
124296 + return 5;
124297 + case RECORD_TYPE:
124298 + return 6;
124299 + case UNION_TYPE:
124300 + return 7;
124301 + case VOID_TYPE:
124302 + return 8;
124303 + case REAL_TYPE:
124304 + return 9;
124305 + case VECTOR_TYPE:
124306 + return 10;
124307 + case REFERENCE_TYPE:
124308 + return 11;
124309 + case OFFSET_TYPE:
124310 + return 12;
124311 + case COMPLEX_TYPE:
124312 + return 13;
124313 + default:
124314 + debug_tree((tree)type);
124315 + gcc_unreachable();
124316 + }
124317 +}
124318 +
124319 +struct function_hash {
124320 + size_t tree_codes_len;
124321 + unsigned char tree_codes[CODES_LIMIT];
124322 + const_tree fndecl;
124323 + unsigned int hash;
124324 +};
124325 +
124326 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124327 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124328 +{
124329 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124330 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124331 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124332 +
124333 + unsigned int m = 0x57559429;
124334 + unsigned int n = 0x5052acdb;
124335 + const unsigned int *key4 = (const unsigned int *)key;
124336 + unsigned int h = len;
124337 + unsigned int k = len + seed + n;
124338 + unsigned long long p;
124339 +
124340 + while (len >= 8) {
124341 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124342 + len -= 8;
124343 + }
124344 + if (len >= 4) {
124345 + cwmixb(key4[0]) key4 += 1;
124346 + len -= 4;
124347 + }
124348 + if (len)
124349 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124350 + cwmixb(h ^ (k + n));
124351 + return k ^ h;
124352 +
124353 +#undef cwfold
124354 +#undef cwmixa
124355 +#undef cwmixb
124356 +}
124357 +
124358 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124359 +{
124360 + unsigned int fn, codes, seed = 0;
124361 +
124362 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124363 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124364 +
124365 + fn_hash_data->hash = fn ^ codes;
124366 +}
124367 +
124368 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124369 +{
124370 + gcc_assert(type != NULL_TREE);
124371 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124372 +
124373 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124374 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124375 + fn_hash_data->tree_codes_len++;
124376 + type = TREE_TYPE(type);
124377 + }
124378 +}
124379 +
124380 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124381 +{
124382 + const_tree result;
124383 +
124384 + gcc_assert(node != NULL_TREE);
124385 +
124386 + if (DECL_P(node)) {
124387 + result = DECL_RESULT(node);
124388 + if (result != NULL_TREE)
124389 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124390 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124391 + }
124392 +
124393 + gcc_assert(TYPE_P(node));
124394 +
124395 + if (TREE_CODE(node) == FUNCTION_TYPE)
124396 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124397 +
124398 + return set_node_codes(node, fn_hash_data);
124399 +}
124400 +
124401 +static void set_function_codes(struct function_hash *fn_hash_data)
124402 +{
124403 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124404 + enum tree_code code = TREE_CODE(type);
124405 +
124406 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124407 +
124408 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124409 +
124410 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124411 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124412 +}
124413 +
124414 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124415 +{
124416 + while (entry) {
124417 + if (!strcmp(entry->name, func_name))
124418 + return entry;
124419 + entry = entry->next;
124420 + }
124421 + return NULL;
124422 +}
124423 +
124424 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124425 +{
124426 + const struct size_overflow_hash *entry;
124427 + struct function_hash fn_hash_data;
124428 + const char *func_name;
124429 +
124430 + // skip builtins __builtin_constant_p
124431 + if (DECL_BUILT_IN(fndecl))
124432 + return NULL;
124433 +
124434 + fn_hash_data.fndecl = fndecl;
124435 + fn_hash_data.tree_codes_len = 0;
124436 +
124437 + set_function_codes(&fn_hash_data);
124438 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124439 +
124440 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124441 + set_hash(func_name, &fn_hash_data);
124442 +
124443 + entry = size_overflow_hash[fn_hash_data.hash];
124444 + entry = get_proper_hash_chain(entry, func_name);
124445 + if (entry)
124446 + return entry;
124447 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124448 + return get_proper_hash_chain(entry, func_name);
124449 +}
124450 +
124451 +static void print_missing_msg(const_tree func, unsigned int argnum)
124452 +{
124453 + location_t loc;
124454 + const char *curfunc;
124455 + struct function_hash fn_hash_data;
124456 +
124457 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124458 + fn_hash_data.tree_codes_len = 0;
124459 +
124460 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124461 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124462 +
124463 + set_function_codes(&fn_hash_data);
124464 + set_hash(curfunc, &fn_hash_data);
124465 +
124466 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124467 +}
124468 +
124469 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124470 +{
124471 + tree var;
124472 + unsigned int argnum = 1;
124473 +
124474 + if (TREE_CODE(arg) == SSA_NAME)
124475 + arg = SSA_NAME_VAR(arg);
124476 +
124477 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124478 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124479 + continue;
124480 + if (!skip_types(var))
124481 + return argnum;
124482 + }
124483 +
124484 + return CANNOT_FIND_ARG;
124485 +}
124486 +
124487 +static const char *get_asm_string(const_gimple stmt)
124488 +{
124489 + if (!stmt)
124490 + return NULL;
124491 + if (gimple_code(stmt) != GIMPLE_ASM)
124492 + return NULL;
124493 +
124494 + return gimple_asm_string(stmt);
124495 +}
124496 +
124497 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124498 +{
124499 + const char *str;
124500 +
124501 + str = get_asm_string(stmt);
124502 + if (!str)
124503 + return false;
124504 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124505 +}
124506 +
124507 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124508 +{
124509 + const char *str;
124510 +
124511 + str = get_asm_string(stmt);
124512 + if (!str)
124513 + return false;
124514 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124515 +}
124516 +
124517 +bool is_size_overflow_asm(const_gimple stmt)
124518 +{
124519 + const char *str;
124520 +
124521 + str = get_asm_string(stmt);
124522 + if (!str)
124523 + return false;
124524 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124525 +}
124526 +
124527 +bool is_a_return_check(const_tree node)
124528 +{
124529 + if (TREE_CODE(node) == FUNCTION_DECL)
124530 + return true;
124531 +
124532 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124533 + return false;
124534 +}
124535 +
124536 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124537 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124538 +{
124539 + if (is_a_return_check(node))
124540 + return 0;
124541 + else
124542 + return find_arg_number_tree(node, orig_fndecl);
124543 +}
124544 +
124545 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124546 +{
124547 + const struct size_overflow_hash *hash;
124548 + unsigned int new_argnum;
124549 + tree arg;
124550 + const_tree origarg;
124551 +
124552 + if (argnum == 0)
124553 + return argnum;
124554 +
124555 + hash = get_function_hash(fndecl);
124556 + if (hash && hash->param & (1U << argnum))
124557 + return argnum;
124558 +
124559 + if (DECL_EXTERNAL(fndecl))
124560 + return argnum;
124561 +
124562 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124563 + argnum--;
124564 + while (origarg && argnum) {
124565 + origarg = TREE_CHAIN(origarg);
124566 + argnum--;
124567 + }
124568 + gcc_assert(argnum == 0);
124569 + gcc_assert(origarg != NULL_TREE);
124570 +
124571 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124572 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124573 + return new_argnum;
124574 +
124575 + return CANNOT_FIND_ARG;
124576 +}
124577 +
124578 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
124579 +{
124580 + const struct size_overflow_hash *hash;
124581 +
124582 + hash = get_function_hash(fndecl);
124583 + if (hash && (hash->param & (1U << num)))
124584 + return true;
124585 + return false;
124586 +}
124587 +
124588 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
124589 + * If the function is missing everywhere then print the missing message into stderr.
124590 + */
124591 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
124592 +{
124593 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
124594 +#if BUILDING_GCC_VERSION >= 4008
124595 + case BUILT_IN_BSWAP16:
124596 +#endif
124597 + case BUILT_IN_BSWAP32:
124598 + case BUILT_IN_BSWAP64:
124599 + case BUILT_IN_EXPECT:
124600 + case BUILT_IN_MEMCMP:
124601 + return false;
124602 + default:
124603 + break;
124604 + }
124605 +
124606 + // skip test.c
124607 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
124608 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
124609 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
124610 + }
124611 +
124612 + if (is_in_hash_table(orig_fndecl, num))
124613 + return false;
124614 +
124615 + print_missing_msg(orig_fndecl, num);
124616 + return true;
124617 +}
124618 +
124619 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
124620 new file mode 100644
124621 index 0000000..924652b
124622 --- /dev/null
124623 +++ b/tools/gcc/stackleak_plugin.c
124624 @@ -0,0 +1,395 @@
124625 +/*
124626 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
124627 + * Licensed under the GPL v2
124628 + *
124629 + * Note: the choice of the license means that the compilation process is
124630 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124631 + * but for the kernel it doesn't matter since it doesn't link against
124632 + * any of the gcc libraries
124633 + *
124634 + * gcc plugin to help implement various PaX features
124635 + *
124636 + * - track lowest stack pointer
124637 + *
124638 + * TODO:
124639 + * - initialize all local variables
124640 + *
124641 + * BUGS:
124642 + * - none known
124643 + */
124644 +
124645 +#include "gcc-common.h"
124646 +
124647 +int plugin_is_GPL_compatible;
124648 +
124649 +static int track_frame_size = -1;
124650 +static const char track_function[] = "pax_track_stack";
124651 +static const char check_function[] = "pax_check_alloca";
124652 +static tree track_function_decl, check_function_decl;
124653 +static bool init_locals;
124654 +
124655 +static struct plugin_info stackleak_plugin_info = {
124656 + .version = "201408011900",
124657 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
124658 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
124659 +};
124660 +
124661 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
124662 +{
124663 + gimple check_alloca;
124664 + tree alloca_size;
124665 +
124666 + // insert call to void pax_check_alloca(unsigned long size)
124667 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
124668 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
124669 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
124670 +}
124671 +
124672 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
124673 +{
124674 + gimple track_stack;
124675 +
124676 + // insert call to void pax_track_stack(void)
124677 + track_stack = gimple_build_call(track_function_decl, 0);
124678 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
124679 +}
124680 +
124681 +static bool is_alloca(gimple stmt)
124682 +{
124683 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
124684 + return true;
124685 +
124686 +#if BUILDING_GCC_VERSION >= 4007
124687 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
124688 + return true;
124689 +#endif
124690 +
124691 + return false;
124692 +}
124693 +
124694 +static unsigned int execute_stackleak_tree_instrument(void)
124695 +{
124696 + basic_block bb, entry_bb;
124697 + bool prologue_instrumented = false, is_leaf = true;
124698 +
124699 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
124700 +
124701 + // 1. loop through BBs and GIMPLE statements
124702 + FOR_EACH_BB_FN(bb, cfun) {
124703 + gimple_stmt_iterator gsi;
124704 +
124705 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124706 + gimple stmt;
124707 +
124708 + stmt = gsi_stmt(gsi);
124709 +
124710 + if (is_gimple_call(stmt))
124711 + is_leaf = false;
124712 +
124713 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
124714 + if (!is_alloca(stmt))
124715 + continue;
124716 +
124717 + // 2. insert stack overflow check before each __builtin_alloca call
124718 + stackleak_check_alloca(&gsi);
124719 +
124720 + // 3. insert track call after each __builtin_alloca call
124721 + stackleak_add_instrumentation(&gsi);
124722 + if (bb == entry_bb)
124723 + prologue_instrumented = true;
124724 + }
124725 + }
124726 +
124727 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
124728 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
124729 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
124730 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
124731 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
124732 + return 0;
124733 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
124734 + return 0;
124735 +
124736 + // 4. insert track call at the beginning
124737 + if (!prologue_instrumented) {
124738 + gimple_stmt_iterator gsi;
124739 +
124740 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124741 + if (dom_info_available_p(CDI_DOMINATORS))
124742 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124743 + gsi = gsi_start_bb(bb);
124744 + stackleak_add_instrumentation(&gsi);
124745 + }
124746 +
124747 + return 0;
124748 +}
124749 +
124750 +static unsigned int execute_stackleak_final(void)
124751 +{
124752 + rtx insn, next;
124753 +
124754 + if (cfun->calls_alloca)
124755 + return 0;
124756 +
124757 + // keep calls only if function frame is big enough
124758 + if (get_frame_size() >= track_frame_size)
124759 + return 0;
124760 +
124761 + // 1. find pax_track_stack calls
124762 + for (insn = get_insns(); insn; insn = next) {
124763 + // 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))
124764 + rtx body;
124765 +
124766 + next = NEXT_INSN(insn);
124767 + if (!CALL_P(insn))
124768 + continue;
124769 + body = PATTERN(insn);
124770 + if (GET_CODE(body) != CALL)
124771 + continue;
124772 + body = XEXP(body, 0);
124773 + if (GET_CODE(body) != MEM)
124774 + continue;
124775 + body = XEXP(body, 0);
124776 + if (GET_CODE(body) != SYMBOL_REF)
124777 + continue;
124778 +// if (strcmp(XSTR(body, 0), track_function))
124779 + if (SYMBOL_REF_DECL(body) != track_function_decl)
124780 + continue;
124781 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124782 + // 2. delete call
124783 + delete_insn_and_edges(insn);
124784 +#if BUILDING_GCC_VERSION >= 4007
124785 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
124786 + insn = next;
124787 + next = NEXT_INSN(insn);
124788 + delete_insn_and_edges(insn);
124789 + }
124790 +#endif
124791 + }
124792 +
124793 +// print_simple_rtl(stderr, get_insns());
124794 +// print_rtl(stderr, get_insns());
124795 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124796 +
124797 + return 0;
124798 +}
124799 +
124800 +static bool gate_stackleak_track_stack(void)
124801 +{
124802 + tree section;
124803 +
124804 + if (ix86_cmodel != CM_KERNEL)
124805 + return false;
124806 +
124807 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
124808 + if (section && TREE_VALUE(section)) {
124809 + section = TREE_VALUE(TREE_VALUE(section));
124810 +
124811 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
124812 + return false;
124813 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
124814 + return false;
124815 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
124816 + return false;
124817 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
124818 + return false;
124819 + }
124820 +
124821 + return track_frame_size >= 0;
124822 +}
124823 +
124824 +static void stackleak_start_unit(void *gcc_data, void *user_data)
124825 +{
124826 + tree fntype;
124827 +
124828 + // void pax_track_stack(void)
124829 + fntype = build_function_type_list(void_type_node, NULL_TREE);
124830 + track_function_decl = build_fn_decl(track_function, fntype);
124831 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
124832 + TREE_PUBLIC(track_function_decl) = 1;
124833 + DECL_EXTERNAL(track_function_decl) = 1;
124834 + DECL_ARTIFICIAL(track_function_decl) = 1;
124835 +
124836 + // void pax_check_alloca(unsigned long)
124837 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
124838 + check_function_decl = build_fn_decl(check_function, fntype);
124839 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
124840 + TREE_PUBLIC(check_function_decl) = 1;
124841 + DECL_EXTERNAL(check_function_decl) = 1;
124842 + DECL_ARTIFICIAL(check_function_decl) = 1;
124843 +}
124844 +
124845 +#if BUILDING_GCC_VERSION >= 4009
124846 +static const struct pass_data stackleak_tree_instrument_pass_data = {
124847 +#else
124848 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
124849 + .pass = {
124850 +#endif
124851 + .type = GIMPLE_PASS,
124852 + .name = "stackleak_tree_instrument",
124853 +#if BUILDING_GCC_VERSION >= 4008
124854 + .optinfo_flags = OPTGROUP_NONE,
124855 +#endif
124856 +#if BUILDING_GCC_VERSION >= 4009
124857 + .has_gate = true,
124858 + .has_execute = true,
124859 +#else
124860 + .gate = gate_stackleak_track_stack,
124861 + .execute = execute_stackleak_tree_instrument,
124862 + .sub = NULL,
124863 + .next = NULL,
124864 + .static_pass_number = 0,
124865 +#endif
124866 + .tv_id = TV_NONE,
124867 + .properties_required = PROP_gimple_leh | PROP_cfg,
124868 + .properties_provided = 0,
124869 + .properties_destroyed = 0,
124870 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
124871 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
124872 +#if BUILDING_GCC_VERSION < 4009
124873 + }
124874 +#endif
124875 +};
124876 +
124877 +#if BUILDING_GCC_VERSION >= 4009
124878 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
124879 +#else
124880 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
124881 + .pass = {
124882 +#endif
124883 + .type = RTL_PASS,
124884 + .name = "stackleak_final",
124885 +#if BUILDING_GCC_VERSION >= 4008
124886 + .optinfo_flags = OPTGROUP_NONE,
124887 +#endif
124888 +#if BUILDING_GCC_VERSION >= 4009
124889 + .has_gate = true,
124890 + .has_execute = true,
124891 +#else
124892 + .gate = gate_stackleak_track_stack,
124893 + .execute = execute_stackleak_final,
124894 + .sub = NULL,
124895 + .next = NULL,
124896 + .static_pass_number = 0,
124897 +#endif
124898 + .tv_id = TV_NONE,
124899 + .properties_required = 0,
124900 + .properties_provided = 0,
124901 + .properties_destroyed = 0,
124902 + .todo_flags_start = 0,
124903 + .todo_flags_finish = TODO_dump_func
124904 +#if BUILDING_GCC_VERSION < 4009
124905 + }
124906 +#endif
124907 +};
124908 +
124909 +#if BUILDING_GCC_VERSION >= 4009
124910 +namespace {
124911 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
124912 +public:
124913 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
124914 + bool gate() { return gate_stackleak_track_stack(); }
124915 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
124916 +};
124917 +
124918 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
124919 +public:
124920 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
124921 + bool gate() { return gate_stackleak_track_stack(); }
124922 + unsigned int execute() { return execute_stackleak_final(); }
124923 +};
124924 +}
124925 +
124926 +static opt_pass *make_stackleak_tree_instrument_pass(void)
124927 +{
124928 + return new stackleak_tree_instrument_pass();
124929 +}
124930 +
124931 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
124932 +{
124933 + return new stackleak_final_rtl_opt_pass();
124934 +}
124935 +#else
124936 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
124937 +{
124938 + return &stackleak_tree_instrument_pass.pass;
124939 +}
124940 +
124941 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
124942 +{
124943 + return &stackleak_final_rtl_opt_pass.pass;
124944 +}
124945 +#endif
124946 +
124947 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124948 +{
124949 + const char * const plugin_name = plugin_info->base_name;
124950 + const int argc = plugin_info->argc;
124951 + const struct plugin_argument * const argv = plugin_info->argv;
124952 + int i;
124953 + struct register_pass_info stackleak_tree_instrument_pass_info;
124954 + struct register_pass_info stackleak_final_pass_info;
124955 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
124956 + {
124957 + .base = &track_function_decl,
124958 + .nelt = 1,
124959 + .stride = sizeof(track_function_decl),
124960 + .cb = &gt_ggc_mx_tree_node,
124961 + .pchw = &gt_pch_nx_tree_node
124962 + },
124963 + {
124964 + .base = &check_function_decl,
124965 + .nelt = 1,
124966 + .stride = sizeof(check_function_decl),
124967 + .cb = &gt_ggc_mx_tree_node,
124968 + .pchw = &gt_pch_nx_tree_node
124969 + },
124970 + LAST_GGC_ROOT_TAB
124971 + };
124972 +
124973 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
124974 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
124975 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
124976 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
124977 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124978 +
124979 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
124980 + stackleak_final_pass_info.reference_pass_name = "final";
124981 + stackleak_final_pass_info.ref_pass_instance_number = 1;
124982 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124983 +
124984 + if (!plugin_default_version_check(version, &gcc_version)) {
124985 + error(G_("incompatible gcc/plugin versions"));
124986 + return 1;
124987 + }
124988 +
124989 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
124990 +
124991 + for (i = 0; i < argc; ++i) {
124992 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
124993 + if (!argv[i].value) {
124994 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124995 + continue;
124996 + }
124997 + track_frame_size = atoi(argv[i].value);
124998 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
124999 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125000 + continue;
125001 + }
125002 + if (!strcmp(argv[i].key, "initialize-locals")) {
125003 + if (argv[i].value) {
125004 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125005 + continue;
125006 + }
125007 + init_locals = true;
125008 + continue;
125009 + }
125010 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125011 + }
125012 +
125013 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125014 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125015 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125016 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125017 +
125018 + return 0;
125019 +}
125020 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125021 new file mode 100644
125022 index 0000000..4ee2231
125023 --- /dev/null
125024 +++ b/tools/gcc/structleak_plugin.c
125025 @@ -0,0 +1,274 @@
125026 +/*
125027 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125028 + * Licensed under the GPL v2
125029 + *
125030 + * Note: the choice of the license means that the compilation process is
125031 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125032 + * but for the kernel it doesn't matter since it doesn't link against
125033 + * any of the gcc libraries
125034 + *
125035 + * gcc plugin to forcibly initialize certain local variables that could
125036 + * otherwise leak kernel stack to userland if they aren't properly initialized
125037 + * by later code
125038 + *
125039 + * Homepage: http://pax.grsecurity.net/
125040 + *
125041 + * Usage:
125042 + * $ # for 4.5/4.6/C based 4.7
125043 + * $ 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
125044 + * $ # for C++ based 4.7/4.8+
125045 + * $ 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
125046 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125047 + *
125048 + * TODO: eliminate redundant initializers
125049 + * increase type coverage
125050 + */
125051 +
125052 +#include "gcc-common.h"
125053 +
125054 +// unused C type flag in all versions 4.5-4.9
125055 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125056 +
125057 +int plugin_is_GPL_compatible;
125058 +
125059 +static struct plugin_info structleak_plugin_info = {
125060 + .version = "201401260140",
125061 + .help = "disable\tdo not activate plugin\n",
125062 +};
125063 +
125064 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125065 +{
125066 + *no_add_attrs = true;
125067 +
125068 + // check for types? for now accept everything linux has to offer
125069 + if (TREE_CODE(*node) != FIELD_DECL)
125070 + return NULL_TREE;
125071 +
125072 + *no_add_attrs = false;
125073 + return NULL_TREE;
125074 +}
125075 +
125076 +static struct attribute_spec user_attr = {
125077 + .name = "user",
125078 + .min_length = 0,
125079 + .max_length = 0,
125080 + .decl_required = false,
125081 + .type_required = false,
125082 + .function_type_required = false,
125083 + .handler = handle_user_attribute,
125084 +#if BUILDING_GCC_VERSION >= 4007
125085 + .affects_type_identity = true
125086 +#endif
125087 +};
125088 +
125089 +static void register_attributes(void *event_data, void *data)
125090 +{
125091 + register_attribute(&user_attr);
125092 +// register_attribute(&force_attr);
125093 +}
125094 +
125095 +static tree get_field_type(tree field)
125096 +{
125097 + return strip_array_types(TREE_TYPE(field));
125098 +}
125099 +
125100 +static bool is_userspace_type(tree type)
125101 +{
125102 + tree field;
125103 +
125104 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125105 + tree fieldtype = get_field_type(field);
125106 + enum tree_code code = TREE_CODE(fieldtype);
125107 +
125108 + if (code == RECORD_TYPE || code == UNION_TYPE)
125109 + if (is_userspace_type(fieldtype))
125110 + return true;
125111 +
125112 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125113 + return true;
125114 + }
125115 + return false;
125116 +}
125117 +
125118 +static void finish_type(void *event_data, void *data)
125119 +{
125120 + tree type = (tree)event_data;
125121 +
125122 + if (TYPE_USERSPACE(type))
125123 + return;
125124 +
125125 + if (is_userspace_type(type))
125126 + TYPE_USERSPACE(type) = 1;
125127 +}
125128 +
125129 +static void initialize(tree var)
125130 +{
125131 + basic_block bb;
125132 + gimple_stmt_iterator gsi;
125133 + tree initializer;
125134 + gimple init_stmt;
125135 +
125136 + // this is the original entry bb before the forced split
125137 + // TODO: check further BBs in case more splits occured before us
125138 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125139 +
125140 + // first check if the variable is already initialized, warn otherwise
125141 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125142 + gimple stmt = gsi_stmt(gsi);
125143 + tree rhs1;
125144 +
125145 + // we're looking for an assignment of a single rhs...
125146 + if (!gimple_assign_single_p(stmt))
125147 + continue;
125148 + rhs1 = gimple_assign_rhs1(stmt);
125149 +#if BUILDING_GCC_VERSION >= 4007
125150 + // ... of a non-clobbering expression...
125151 + if (TREE_CLOBBER_P(rhs1))
125152 + continue;
125153 +#endif
125154 + // ... to our variable...
125155 + if (gimple_get_lhs(stmt) != var)
125156 + continue;
125157 + // if it's an initializer then we're good
125158 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125159 + return;
125160 + }
125161 +
125162 + // these aren't the 0days you're looking for
125163 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125164 +
125165 + // build the initializer expression
125166 + initializer = build_constructor(TREE_TYPE(var), NULL);
125167 +
125168 + // build the initializer stmt
125169 + init_stmt = gimple_build_assign(var, initializer);
125170 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125171 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125172 + update_stmt(init_stmt);
125173 +}
125174 +
125175 +static unsigned int handle_function(void)
125176 +{
125177 + basic_block bb;
125178 + unsigned int ret = 0;
125179 + tree var;
125180 + unsigned int i;
125181 +
125182 + // split the first bb where we can put the forced initializers
125183 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125184 + if (dom_info_available_p(CDI_DOMINATORS))
125185 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125186 +
125187 + // enumarate all local variables and forcibly initialize our targets
125188 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125189 + tree type = TREE_TYPE(var);
125190 +
125191 + gcc_assert(DECL_P(var));
125192 + if (!auto_var_in_fn_p(var, current_function_decl))
125193 + continue;
125194 +
125195 + // only care about structure types
125196 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125197 + continue;
125198 +
125199 + // if the type is of interest, examine the variable
125200 + if (TYPE_USERSPACE(type))
125201 + initialize(var);
125202 + }
125203 +
125204 + return ret;
125205 +}
125206 +
125207 +#if BUILDING_GCC_VERSION >= 4009
125208 +static const struct pass_data structleak_pass_data = {
125209 +#else
125210 +static struct gimple_opt_pass structleak_pass = {
125211 + .pass = {
125212 +#endif
125213 + .type = GIMPLE_PASS,
125214 + .name = "structleak",
125215 +#if BUILDING_GCC_VERSION >= 4008
125216 + .optinfo_flags = OPTGROUP_NONE,
125217 +#endif
125218 +#if BUILDING_GCC_VERSION >= 4009
125219 + .has_gate = false,
125220 + .has_execute = true,
125221 +#else
125222 + .gate = NULL,
125223 + .execute = handle_function,
125224 + .sub = NULL,
125225 + .next = NULL,
125226 + .static_pass_number = 0,
125227 +#endif
125228 + .tv_id = TV_NONE,
125229 + .properties_required = PROP_cfg,
125230 + .properties_provided = 0,
125231 + .properties_destroyed = 0,
125232 + .todo_flags_start = 0,
125233 + .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
125234 +#if BUILDING_GCC_VERSION < 4009
125235 + }
125236 +#endif
125237 +};
125238 +
125239 +#if BUILDING_GCC_VERSION >= 4009
125240 +namespace {
125241 +class structleak_pass : public gimple_opt_pass {
125242 +public:
125243 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125244 + unsigned int execute() { return handle_function(); }
125245 +};
125246 +}
125247 +
125248 +static opt_pass *make_structleak_pass(void)
125249 +{
125250 + return new structleak_pass();
125251 +}
125252 +#else
125253 +static struct opt_pass *make_structleak_pass(void)
125254 +{
125255 + return &structleak_pass.pass;
125256 +}
125257 +#endif
125258 +
125259 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125260 +{
125261 + int i;
125262 + const char * const plugin_name = plugin_info->base_name;
125263 + const int argc = plugin_info->argc;
125264 + const struct plugin_argument * const argv = plugin_info->argv;
125265 + bool enable = true;
125266 + struct register_pass_info structleak_pass_info;
125267 +
125268 + structleak_pass_info.pass = make_structleak_pass();
125269 + structleak_pass_info.reference_pass_name = "ssa";
125270 + structleak_pass_info.ref_pass_instance_number = 1;
125271 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125272 +
125273 + if (!plugin_default_version_check(version, &gcc_version)) {
125274 + error(G_("incompatible gcc/plugin versions"));
125275 + return 1;
125276 + }
125277 +
125278 + if (strcmp(lang_hooks.name, "GNU C")) {
125279 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125280 + enable = false;
125281 + }
125282 +
125283 + for (i = 0; i < argc; ++i) {
125284 + if (!strcmp(argv[i].key, "disable")) {
125285 + enable = false;
125286 + continue;
125287 + }
125288 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125289 + }
125290 +
125291 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125292 + if (enable) {
125293 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125294 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125295 + }
125296 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125297 +
125298 + return 0;
125299 +}
125300 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125301 index 88461f0..6fb70a0 100644
125302 --- a/tools/include/linux/compiler.h
125303 +++ b/tools/include/linux/compiler.h
125304 @@ -35,6 +35,14 @@
125305 # define unlikely(x) __builtin_expect(!!(x), 0)
125306 #endif
125307
125308 +#ifndef __size_overflow
125309 +# define __size_overflow(...)
125310 +#endif
125311 +
125312 +#ifndef __intentional_overflow
125313 +# define __intentional_overflow(...)
125314 +#endif
125315 +
125316 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125317
125318 #endif /* _TOOLS_LINUX_COMPILER_H */
125319 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125320 index 36c08b1..87c72d1 100644
125321 --- a/tools/lib/api/Makefile
125322 +++ b/tools/lib/api/Makefile
125323 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
125324
125325 LIBFILE = libapikfs.a
125326
125327 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125328 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125329 EXTLIBS = -lelf -lpthread -lrt -lm
125330 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125331 ALL_LDFLAGS = $(LDFLAGS)
125332 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125333 index 6789d788..4afd019e 100644
125334 --- a/tools/perf/util/include/asm/alternative-asm.h
125335 +++ b/tools/perf/util/include/asm/alternative-asm.h
125336 @@ -5,4 +5,7 @@
125337
125338 #define altinstruction_entry #
125339
125340 + .macro pax_force_retaddr rip=0, reload=0
125341 + .endm
125342 +
125343 #endif
125344 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125345 index 0a578fe..b81f62d 100644
125346 --- a/tools/virtio/linux/uaccess.h
125347 +++ b/tools/virtio/linux/uaccess.h
125348 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125349 ({ \
125350 typeof(ptr) __pu_ptr = (ptr); \
125351 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125352 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125353 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125354 0; \
125355 })
125356
125357 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125358 index 3cee7b1..29cb7d8 100644
125359 --- a/virt/kvm/kvm_main.c
125360 +++ b/virt/kvm/kvm_main.c
125361 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
125362
125363 static cpumask_var_t cpus_hardware_enabled;
125364 static int kvm_usage_count = 0;
125365 -static atomic_t hardware_enable_failed;
125366 +static atomic_unchecked_t hardware_enable_failed;
125367
125368 struct kmem_cache *kvm_vcpu_cache;
125369 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125370
125371 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125372 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125373 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125374 +static struct preempt_ops kvm_preempt_ops = {
125375 + .sched_in = kvm_sched_in,
125376 + .sched_out = kvm_sched_out,
125377 +};
125378
125379 struct dentry *kvm_debugfs_dir;
125380
125381 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125382 /* We can read the guest memory with __xxx_user() later on. */
125383 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125384 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125385 - !access_ok(VERIFY_WRITE,
125386 + !access_ok_noprefault(VERIFY_WRITE,
125387 (void __user *)(unsigned long)mem->userspace_addr,
125388 mem->memory_size)))
125389 goto out;
125390 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125391
125392 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125393 {
125394 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125395 + int r;
125396 + unsigned long addr;
125397
125398 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125399 + addr = gfn_to_hva(kvm, gfn);
125400 + if (kvm_is_error_hva(addr))
125401 + return -EFAULT;
125402 + r = __clear_user((void __user *)addr + offset, len);
125403 + if (r)
125404 + return -EFAULT;
125405 + mark_page_dirty(kvm, gfn);
125406 + return 0;
125407 }
125408 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125409
125410 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125411 return 0;
125412 }
125413
125414 -static struct file_operations kvm_vcpu_fops = {
125415 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125416 .release = kvm_vcpu_release,
125417 .unlocked_ioctl = kvm_vcpu_ioctl,
125418 #ifdef CONFIG_COMPAT
125419 @@ -2650,7 +2663,7 @@ out:
125420 }
125421 #endif
125422
125423 -static struct file_operations kvm_vm_fops = {
125424 +static file_operations_no_const kvm_vm_fops __read_only = {
125425 .release = kvm_vm_release,
125426 .unlocked_ioctl = kvm_vm_ioctl,
125427 #ifdef CONFIG_COMPAT
125428 @@ -2721,7 +2734,7 @@ out:
125429 return r;
125430 }
125431
125432 -static struct file_operations kvm_chardev_ops = {
125433 +static file_operations_no_const kvm_chardev_ops __read_only = {
125434 .unlocked_ioctl = kvm_dev_ioctl,
125435 .compat_ioctl = kvm_dev_ioctl,
125436 .llseek = noop_llseek,
125437 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
125438
125439 if (r) {
125440 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125441 - atomic_inc(&hardware_enable_failed);
125442 + atomic_inc_unchecked(&hardware_enable_failed);
125443 printk(KERN_INFO "kvm: enabling virtualization on "
125444 "CPU%d failed\n", cpu);
125445 }
125446 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
125447
125448 kvm_usage_count++;
125449 if (kvm_usage_count == 1) {
125450 - atomic_set(&hardware_enable_failed, 0);
125451 + atomic_set_unchecked(&hardware_enable_failed, 0);
125452 on_each_cpu(hardware_enable_nolock, NULL, 1);
125453
125454 - if (atomic_read(&hardware_enable_failed)) {
125455 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125456 hardware_disable_all_nolock();
125457 r = -EBUSY;
125458 }
125459 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125460 kvm_arch_vcpu_put(vcpu);
125461 }
125462
125463 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125464 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125465 struct module *module)
125466 {
125467 int r;
125468 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125469 if (!vcpu_align)
125470 vcpu_align = __alignof__(struct kvm_vcpu);
125471 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125472 - 0, NULL);
125473 + SLAB_USERCOPY, NULL);
125474 if (!kvm_vcpu_cache) {
125475 r = -ENOMEM;
125476 goto out_free_3;
125477 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125478 if (r)
125479 goto out_free;
125480
125481 + pax_open_kernel();
125482 kvm_chardev_ops.owner = module;
125483 kvm_vm_fops.owner = module;
125484 kvm_vcpu_fops.owner = module;
125485 + pax_close_kernel();
125486
125487 r = misc_register(&kvm_dev);
125488 if (r) {
125489 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125490
125491 register_syscore_ops(&kvm_syscore_ops);
125492
125493 - kvm_preempt_ops.sched_in = kvm_sched_in;
125494 - kvm_preempt_ops.sched_out = kvm_sched_out;
125495 -
125496 r = kvm_init_debug();
125497 if (r) {
125498 printk(KERN_ERR "kvm: create debugfs files failed\n");